Class SensitivityAnalysis

java.lang.Object
neqsim.process.util.optimizer.SensitivityAnalysis
All Implemented Interfaces:
Serializable

public class SensitivityAnalysis extends Object implements 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:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization version.
      See Also:
    • logger

      private static final org.apache.logging.log4j.Logger logger
      Logger object for class.
    • baseProcess

      private final ProcessSystem baseProcess
      Base process system to clone for each evaluation.
    • parameterName

      private String parameterName
      Name of the varied parameter.
    • minValue

      private double minValue
      Minimum value of the parameter range.
    • maxValue

      private double maxValue
      Maximum value of the parameter range.
    • steps

      private int steps
      Number of steps in the parameter sweep (inclusive of endpoints).
    • parameterSetter

      private transient Consumer<ProcessSystem> parameterSetter
      Action to apply the parameter value to a process copy.
    • currentValue

      private double currentValue
      Current parameter value being set (for use by setter lambda).
    • outputExtractors

      private final transient Map<String, Function<ProcessSystem, Double>> outputExtractors
      Named output extractors.
  • Constructor Details

    • SensitivityAnalysis

      public SensitivityAnalysis(ProcessSystem baseProcess)
      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 parameter
      minValue - minimum value of the sweep range
      maxValue - maximum value of the sweep range
      steps - number of evaluation points (inclusive of endpoints)
      setter - action that applies the current parameter value to a process system copy; use getCurrentValue() 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 parameter
      minValue - minimum value of the sweep range
      maxValue - maximum value of the sweep range
      steps - 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

      public SensitivityAnalysis addOutput(String name, Function<ProcessSystem, Double> extractor)
      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