Model Analysis Execution
- Last UpdatedNov 18, 2025
- 4 minute read
- PI System
- AF SDK 2024 R2
- Developer
An analysis with an AFModel as its target is an AFModelAnalysis. This type of analysis will execute on the entire AFModel to produce results.
The time rule configured for the AFAnalysis is used to determine time range for the next execution of the analysis. This time range is used to create an AFCase to be used as the context for the analysis execution. The case will hold the input values used during the execution of the analysis as well as the resulting output values. The analysis rule configured for the analysis provides the logic to execute the analysis on a set of data values for its target. After executing an analysis, the case can be saved to the server so that its results can be kept for future reference.
Execution Steps
Create new AFCase
A new AFCase is created using the AFAnalysisAddCase method which will be used as the context for the analysis execution. This method will use the previous case as the parameter when calling the AFTimeRuleGetNextEvent(AFTimeRuleEvent) method of the time rule configured for the analysis to generate a new AFTimeRuleEvent. If the previous case does not exist, then the time rule is used to select a start time where the end time will be before the current time. This new AFTimeRuleEvent is then used to create the new case. The case's generated start and end times can be modified by specifying different values for the StartTime and/or EndTime of the case.
When a case is created, the AFCasePreviousCase is automatically set to the latest case of the analysis. The initial list of active layers is copied from the previous case if one exists. If a previous case does not exist (because it is the first case) and the Target of the analysis is an AFModel, then the list of active layers is set to all current layers of the target model.
Collect Elements
With the AFCase created, the next step is to get the elements that will be used for the analysis by calling the AFCaseCollectElements method. This will call the configured analysis rule's AFAnalysisRuleCollectElements method which allows the analysis rule to determine which elements are included in the analysis.
The default implementation provided by the SDK will use the layers that are active for the case determine which AFElement objects of the target model are active for the case. If the analysis target is not a model or the target model does not have any layers defined, then all elements are considered active for the case.
Collect Transfers
Next the transfers that will be used for the analysis are added to the AFCase by calling the AFCaseCollectTransfers method. This will call the configured analysis rule's AFAnalysisRuleCollectTransfers method which allows the analysis rule to determine which transfers are included in the analysis.
The default implementation provided by the SDK will include any transfers where its source or destination are included in the model within the case's start and end times.
Collect Inputs
After getting the elements and transfers, the inputs must be added to the AFCase by calling the AFCaseCollectInputs method. This will call the configured analysis rule's AFAnalysisRuleCollectInputs method which allows the analysis rule to determine which inputs are included in the analysis.
Adjust Input Values
Next, you make any needed adjustments to the values using the AFAdjustmentsAdd(String, String, Object, UOM) method of the AFResultAdjustments collection.
Run Case
The analysis is now ready to executed by calling the AFCaseRun method which will generate output values that are stored in the case AFCaseResults collection. This will call the configured analysis rule's AFAnalysisRuleRun method which allows the analysis rule to provide the logic to determine the output results of the analysis.
If the analysis needs to be run again, you can reset the case's result values (either all or selected attribute values) by calling one of the AFCaseReset methods. Every time you run the same case, the outputs for the case results are overwritten.
Publish Case Results
After generating the case output results of the analysis, the output values can be published to the locations specified by the attribute's data reference configuration by calling the AFCasePublish method. This will call the configured analysis rule's AFAnalysisRulePublish method which allows the analysis rule to determine how to publish the output results of the analysis.
The default implementation provided by the SDK will write all output values.
CheckIn Case
When finished, the case should be checked in to the server so that its results are preserved for future reference.