Class ProcessSensitivityAnalyzer
java.lang.Object
neqsim.process.util.sensitivity.ProcessSensitivityAnalyzer
- All Implemented Interfaces:
Serializable
Comprehensive sensitivity analyzer for process simulations.
This class provides a fluent API for computing sensitivities of any output property with respect to any input property. It intelligently leverages available Jacobians from Broyden convergence when possible, falling back to finite differences only when necessary.
Key Features:
- Fluent API for defining input/output pairs
- Automatic integration with Broyden convergence Jacobians (FREE sensitivities)
- Chain rule optimization through tear stream structure
- Direct property access for any equipment via reflection
Usage Example:
ProcessSensitivityAnalyzer analyzer = new ProcessSensitivityAnalyzer(process);
// Define what we want to compute
analyzer.withInput("feed", "flowRate").withInput("feed", "temperature")
.withOutput("product", "temperature").withOutput("product", "pressure");
// Compute sensitivities (uses Broyden Jacobian if available)
SensitivityMatrix result = analyzer.compute();
// Query specific sensitivity
double dT_dFlow = result.getSensitivity("product.temperature", "feed.flowRate");
- Version:
- 1.0
- Author:
- ESOL
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSpecification of a variable (equipment + property). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate double[][]Cached Broyden Jacobian from last convergence.Cached tear stream variable names.private final List<ProcessSensitivityAnalyzer.VariableSpec> Input variable specifications.(package private) static org.apache.logging.log4j.LoggerLogger object for class.private doubleMinimum absolute perturbation.private final List<ProcessSensitivityAnalyzer.VariableSpec> Output variable specifications.private final ProcessSystemThe process system to analyze.private doubleRelative perturbation size for finite differences.private static final longSerialization version UID.private booleanWhether to use central differences (more accurate but 2x cost). -
Constructor Summary
ConstructorsConstructorDescriptionProcessSensitivityAnalyzer(ProcessSystem processSystem) Creates a new sensitivity analyzer for a process system. -
Method Summary
Modifier and TypeMethodDescriptionprivate doublecallMethodWithOptionalUnit(ProcessEquipmentInterface equipment, String methodName, String unit, String defaultUnit) Calls a method with optional unit parameter.private voidcallSetterWithOptionalUnit(ProcessEquipmentInterface equipment, String methodName, double value, String unit, String defaultUnit) Calls a setter with optional unit parameter.compute()Computes the sensitivity matrix using the most efficient available method.Forces computation using only finite differences.private voidcomputeFromBroyden(SensitivityMatrix result, boolean[][] computed) Computes sensitivities directly from Broyden Jacobian.private doublecomputePerturbation(double baseValue) private voidcomputeViaChainRule(SensitivityMatrix result, boolean[][] computed) Computes sensitivities using chain rule through tear streams.private voidcomputeViaFiniteDifferences(SensitivityMatrix result, boolean[][] computed) Computes remaining sensitivities via finite differences.private RecycleControllerCreates a RecycleController from recycles in the process.private ProcessEquipmentInterfacefindEquipment(String name) Finds equipment by name in the process system.private MethodfindMethod(Class<?> clazz, String name, Class<?>... paramTypes) Finds a method on a class, searching up the hierarchy.private RecycleControllerFinds the RecycleController for this process system.generateReport(SensitivityMatrix matrix) Generates a human-readable report of the sensitivity analysis.private doublegetPropertyFromEquipment(ProcessEquipmentInterface equipment, String property, String unit) Gets a property value from equipment using reflection.private doubleGets a property value from equipment using reflection.private doublegetStandardProperty(ProcessEquipmentInterface equipment, String property, String unit) Gets standard properties that are common across equipment types.private voidLoads Broyden Jacobian from RecycleController if available.reset()Clears all input/output specifications.private voidsetPropertyOnEquipment(ProcessEquipmentInterface equipment, String property, double value, String unit) Sets a property value on equipment using reflection.private voidsetPropertyValue(ProcessSensitivityAnalyzer.VariableSpec spec, double value) Sets a property value on equipment using reflection.private voidsetStandardProperty(ProcessEquipmentInterface equipment, String property, double value, String unit) Sets standard properties common across equipment types.private StringwithCentralDifferences(boolean useCentral) Sets whether to use central differences (default: false).Adds an input variable for sensitivity analysis.Adds an input variable with unit specification.withOutput(String equipmentName, String propertyName) Adds an output variable for sensitivity analysis.withOutput(String equipmentName, String propertyName, String unit) Adds an output variable with unit specification.withPerturbation(double relativePert) Sets the relative perturbation size for finite differences.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization version UID.- See Also:
-
logger
static org.apache.logging.log4j.Logger loggerLogger object for class. -
processSystem
The process system to analyze. -
inputSpecs
Input variable specifications. -
outputSpecs
Output variable specifications. -
relativePerturbation
private double relativePerturbationRelative perturbation size for finite differences. -
minimumPerturbation
private double minimumPerturbationMinimum absolute perturbation. -
useCentralDifferences
private boolean useCentralDifferencesWhether to use central differences (more accurate but 2x cost). -
cachedBroydenJacobian
private transient double[][] cachedBroydenJacobianCached Broyden Jacobian from last convergence. -
cachedTearStreamVars
-
-
Constructor Details
-
ProcessSensitivityAnalyzer
Creates a new sensitivity analyzer for a process system.- Parameters:
processSystem- the process system to analyze
-
-
Method Details
-
withInput
Adds an input variable for sensitivity analysis.- Parameters:
equipmentName- name of the equipmentpropertyName- name of the property to perturb- Returns:
- this analyzer for chaining
-
withInput
Adds an input variable with unit specification.- Parameters:
equipmentName- name of the equipmentpropertyName- name of the propertyunit- unit for the property- Returns:
- this analyzer for chaining
-
withOutput
Adds an output variable for sensitivity analysis.- Parameters:
equipmentName- name of the equipmentpropertyName- name of the property to monitor- Returns:
- this analyzer for chaining
-
withOutput
public ProcessSensitivityAnalyzer withOutput(String equipmentName, String propertyName, String unit) Adds an output variable with unit specification.- Parameters:
equipmentName- name of the equipmentpropertyName- name of the propertyunit- unit for the property- Returns:
- this analyzer for chaining
-
withCentralDifferences
Sets whether to use central differences (default: false).- Parameters:
useCentral- true for central differences (more accurate, 2x cost)- Returns:
- this analyzer for chaining
-
withPerturbation
Sets the relative perturbation size for finite differences.- Parameters:
relativePert- relative perturbation (default: 0.001 = 0.1%)- Returns:
- this analyzer for chaining
-
reset
Clears all input/output specifications.- Returns:
- this analyzer for chaining
-
compute
Computes the sensitivity matrix using the most efficient available method.This method automatically:
- Checks if Broyden Jacobian is available for tear stream variables
- Uses chain rule to extend to non-tear variables where possible
- Falls back to finite differences only for variables not covered
- Returns:
- the computed sensitivity matrix
-
computeFiniteDifferencesOnly
Forces computation using only finite differences.- Returns:
- the computed sensitivity matrix
-
loadBroydenJacobian
private void loadBroydenJacobian()Loads Broyden Jacobian from RecycleController if available. -
findRecycleController
Finds the RecycleController for this process system. -
createRecycleController
Creates a RecycleController from recycles in the process. -
computeFromBroyden
Computes sensitivities directly from Broyden Jacobian. -
computeViaChainRule
Computes sensitivities using chain rule through tear streams. -
computeViaFiniteDifferences
Computes remaining sensitivities via finite differences. -
computePerturbation
private double computePerturbation(double baseValue) -
getPropertyValue
Gets a property value from equipment using reflection.- Parameters:
spec- the variable specification- Returns:
- the property value
-
setPropertyValue
Sets a property value on equipment using reflection.- Parameters:
spec- the variable specificationvalue- the value to set
-
findEquipment
Finds equipment by name in the process system. -
getPropertyFromEquipment
private double getPropertyFromEquipment(ProcessEquipmentInterface equipment, String property, String unit) Gets a property value from equipment using reflection. -
getStandardProperty
private double getStandardProperty(ProcessEquipmentInterface equipment, String property, String unit) Gets standard properties that are common across equipment types. -
callMethodWithOptionalUnit
-
setPropertyOnEquipment
private void setPropertyOnEquipment(ProcessEquipmentInterface equipment, String property, double value, String unit) Sets a property value on equipment using reflection. -
setStandardProperty
private void setStandardProperty(ProcessEquipmentInterface equipment, String property, double value, String unit) Sets standard properties common across equipment types. -
callSetterWithOptionalUnit
-
findMethod
-
generateReport
Generates a human-readable report of the sensitivity analysis.- Parameters:
matrix- the computed sensitivity matrix- Returns:
- formatted report string
-
truncate
-