HyperX.Solver.Api 1.23.0
The HyperX Solver Application Programming Interface
Loading...
Searching...
No Matches
Preprocessing

Often, several criteria may require the same preprocessing steps before performing their margin checks.

When criteria are grouped into the same 'Pre-Processing Set', the set's 'Preprocessing' function is guaranteed to be called before any of the AnalyzeFuncs of the criteria in the set. The result of the preprocessing step is available to each criterion.

Note
As of Solver API 1.23.0, it is not safe to store an entire IPlateRep, IBeamRep, or IAnalyzable as pre-processed data. Extract the pieces of data you wish to to use and store that instead.

The following code demonstrates how two or more criterion might share the same preprocessing step.

namespace Solver.Criteria.Sample;
public class PreProcessSample : CriterionModule
{
public override CriteriaConfig GetCriteria()
{
var config = new CriteriaConfig();
var definition1 = new CriterionDefinitionConfig()
.WithName("First")
.WithVersion(1, 0, 0)
.WithUid("00000000-0000-0000-0000-REPLACEME001")
.WithAnalyzeFunc(x => Compute(x, CriterionId.First));
var definition2 = new CriterionDefinitionConfig()
.WithName("Second")
.WithVersion(1, 0, 0)
.WithUid("00000000-0000-0000-0000-REPLACEME002")
.WithAnalyzeFunc(x => Compute(x, CriterionId.Second));
_ = config.AddSet([definition1, definition2], PreProcess);
return config;
}
private void PreProcess(ICriterionInput input, IPreProcessedData outData)
{
outData.AddData("load_scenario_uid", input.Analyzable.LoadId);
outData.AddData(1, "hello");
_ = input.Details.Add("Module", $"From {nameof(PreProcessSample)}");
_ = input.Details.Add("Analyzable", $"{input.Analyzable}");
_ = input.Details.Add("Scenario", $"{input.Analyzable.LoadId}");
Dictionary<CriterionId, AnalysisResult> results = new()
{
{ CriterionId.First, new AnalysisResult(0.06, input.Details) },
{ CriterionId.Second, new AnalysisResult(0.07, input.Details) },
};
outData.AddData("results", results);
}
private static AnalysisResult Compute(ICriterionInput input, CriterionId id)
{
var data = input.PreprocessedData;
if (data.GetData("results") is not Dictionary<CriterionId, AnalysisResult> results)
{
throw new InvalidOperationException("No preprocessed results found");
}
var result = results[id];
_ = result.SingleLoadResult?.Details.Add("criterion scenario", $"{input.Analyzable.LoadId}");
return result;
}
}
internal enum CriterionId
{
First,
Second,
}
A single analysis result. Use this to return the analysis result from a criterion that does not use b...
Definition Public.cs:3509
Definition Public.cs:3315
CriterionDefinitionConfig WithVersion(Version version)
Definition Public.cs:4484
CriterionDefinitionConfig WithAnalyzeFunc(Func< ICriterionInput, ICriterionResult > analyzeFunc)
Definition Public.cs:4694
CriterionDefinitionConfig WithUid(Guid uid)
Definition Public.cs:4497
CriterionDefinitionConfig WithReferenceId(int referenceId)
Definition Public.cs:4523
CriterionDefinitionConfig WithName(string name)
Definition Public.cs:4470
ENTRY POINT.
Definition Public.cs:3189
ILoadScenarioId LoadId
The load scenario id.
Definition Public.cs:1665
Definition Public.cs:2689
IReadOnlyPreProcessedData PreprocessedData
If this criterion is part of a set, the preprocessor function (which runs before any criteria in the ...
Definition Public.cs:2699
IAnalyzable Analyzable
The object to be analyzed. Contains loading information, element information, materials,...
Definition Public.cs:2694
IDetailTree Details
Store intermediate details calculated by your method here and return it alongside the margin in your ...
Definition Public.cs:2704
IDetailTree Add(string name, double value, Unit unit)
Captures a value as a detail. The 'unit' field allows HyperX to convert this number to display units ...
Definition Public.cs:3291
void AddData(string key, object value)
Store data for later use by a criterion.
Definition Margin.cs:3