Class SensitivityAnalysis
java.lang.Object
neqsim.process.util.optimizer.SensitivityAnalysis
- All Implemented Interfaces:
Serializable
One-dimensional parameter sensitivity analysis for process simulations.
Varies a single process parameter across a range while tracking one or more output variables. Each evaluation runs a fresh copy of the process system to avoid state contamination. This is the workhorse utility for "what-if" engineering studies.
Usage:
ProcessSystem process = ...;
process.run(); // establish base case
SensitivityAnalysis sa = new SensitivityAnalysis(process);
sa.setParameter("feed pressure", 30.0, 100.0, 8,
p -> p.getUnit("feed").getOutletStream().setPressure(sa.getCurrentValue(), "bara"));
sa.addOutput("compressor power (kW)",
p -> ((Compressor) p.getUnit("Compressor")).getPower("kW"));
sa.addOutput("outlet temperature (C)",
p -> p.getUnit("Compressor").getOutletStream().getTemperature("C"));
SensitivityResult result = sa.run();
System.out.println(result.toJson());
String csv = result.toCSV();
- Version:
- 1.0
- Author:
- Even Solbraa
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResults of a sensitivity analysis sweep. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ProcessSystemBase process system to clone for each evaluation.private doubleCurrent parameter value being set (for use by setter lambda).private static final org.apache.logging.log4j.LoggerLogger object for class.private doubleMaximum value of the parameter range.private doubleMinimum value of the parameter range.private final Map<String, Function<ProcessSystem, Double>> Named output extractors.private StringName of the varied parameter.private Consumer<ProcessSystem> Action to apply the parameter value to a process copy.private static final longSerialization version.private intNumber of steps in the parameter sweep (inclusive of endpoints). -
Constructor Summary
ConstructorsConstructorDescriptionSensitivityAnalysis(ProcessSystem baseProcess) Creates a SensitivityAnalysis for the given base process. -
Method Summary
Modifier and TypeMethodDescriptionaddOutput(String name, Function<ProcessSystem, Double> extractor) Adds an output variable to track during the sweep.doubleGets the current parameter value being evaluated.run()Runs the sensitivity analysis.setParameter(String name, double minValue, double maxValue, int steps, BiConsumer<ProcessSystem, Double> setter) Defines the parameter to vary, with the value passed directly to the setter.setParameter(String name, double minValue, double maxValue, int steps, Consumer<ProcessSystem> setter) Defines the parameter to vary.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization version.- See Also:
-
logger
private static final org.apache.logging.log4j.Logger loggerLogger object for class. -
baseProcess
Base process system to clone for each evaluation. -
parameterName
Name of the varied parameter. -
minValue
private double minValueMinimum value of the parameter range. -
maxValue
private double maxValueMaximum value of the parameter range. -
steps
private int stepsNumber of steps in the parameter sweep (inclusive of endpoints). -
parameterSetter
Action to apply the parameter value to a process copy. -
currentValue
private double currentValueCurrent parameter value being set (for use by setter lambda). -
outputExtractors
Named output extractors.
-
-
Constructor Details
-
SensitivityAnalysis
Creates a SensitivityAnalysis for the given base process.- Parameters:
baseProcess- the process system to use as a template (will be cloned for each run)
-
-
Method Details
-
setParameter
public SensitivityAnalysis setParameter(String name, double minValue, double maxValue, int steps, Consumer<ProcessSystem> setter) Defines the parameter to vary.- Parameters:
name- descriptive name of the parameterminValue- minimum value of the sweep rangemaxValue- maximum value of the sweep rangesteps- number of evaluation points (inclusive of endpoints)setter- action that applies the current parameter value to a process system copy; usegetCurrentValue()to get the value inside the setter- Returns:
- this for chaining
-
setParameter
public SensitivityAnalysis setParameter(String name, double minValue, double maxValue, int steps, BiConsumer<ProcessSystem, Double> setter) Defines the parameter to vary, with the value passed directly to the setter.This is a convenience overload that passes the current parameter value as the second argument to the setter, avoiding the need to call
getCurrentValue().- Parameters:
name- descriptive name of the parameterminValue- minimum value of the sweep rangemaxValue- maximum value of the sweep rangesteps- number of evaluation points (inclusive of endpoints)setter- action that receives the process copy and parameter value- Returns:
- this for chaining
-
getCurrentValue
public double getCurrentValue()Gets the current parameter value being evaluated.Use this inside the parameter setter lambda to get the value to apply.
- Returns:
- the current parameter value
-
addOutput
Adds an output variable to track during the sweep.- Parameters:
name- descriptive name of the output (e.g., "power (kW)")extractor- function that extracts the output value from a process system after it runs- Returns:
- this for chaining
-
run
Runs the sensitivity analysis.- Returns:
- the results containing parameter values and all tracked outputs
-