Class ProcessLinearizer
java.lang.Object
neqsim.process.mpc.ProcessLinearizer
Computes linearized process models from NeqSim ProcessSystem using finite differences.
The ProcessLinearizer automatically calculates the Jacobian matrices (gain matrices) that describe how controlled variables respond to changes in manipulated variables around an operating point. These matrices are essential for linear MPC algorithms.
The linearization uses central finite differences for improved accuracy:
∂CV[i]/∂MV[j] ≈ (CV[i](MV[j]+δ) - CV[i](MV[j]-δ)) / (2δ)
Example usage:
// Create linearizer for a process
ProcessLinearizer linearizer = new ProcessLinearizer(processSystem);
// Define inputs and outputs
linearizer.addMV(new ManipulatedVariable("ValveOpening", valve, "opening"));
linearizer.addMV(new ManipulatedVariable("HeaterDuty", heater, "duty", "kW"));
linearizer.addCV(new ControlledVariable("Pressure", separator, "pressure", "bara"));
linearizer.addCV(new ControlledVariable("Temperature", outlet, "temperature", "C"));
// Compute linearization
LinearizationResult result = linearizer.linearize(0.01); // 1% perturbation
// Access gains
double[][] gains = result.getGainMatrix();
double dPressure_dValve = gains[0][0];
double dPressure_dHeater = gains[0][1];
- Since:
- 3.0
- Version:
- 1.0
- Author:
- Even Solbraa
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<ControlledVariable> List of controlled variables.private doubleDefault perturbation size as fraction of variable range.private final List<DisturbanceVariable> List of disturbance variables.private final List<ManipulatedVariable> List of manipulated variables.private doubleMinimum absolute perturbation to avoid numerical issues.private final ProcessSystemThe process system to linearize.private booleanWhether to use central differences (more accurate) or forward differences (faster). -
Constructor Summary
ConstructorsConstructorDescriptionProcessLinearizer(ProcessSystem processSystem) Construct a linearizer for a ProcessSystem. -
Method Summary
Modifier and TypeMethodDescriptionAdd a controlled variable to the linearization.Add a disturbance variable to the linearization.Add a manipulated variable to the linearization.private doublecalculatePerturbation(ManipulatedVariable mv, double currentValue, double perturbationFraction) Calculate the perturbation delta for a variable.clear()Clear all variable definitions.Get the list of controlled variables.Get the list of disturbance variables.Get the list of manipulated variables.booleanisApproximatelyLinear(double perturbationSize1, double perturbationSize2, double tolerance) Check if the process is approximately linear within a range.Perform linearization with the default perturbation size.linearize(double perturbationSize) Perform linearization with a specified perturbation size.linearizeMultiplePoints(int numPoints, double perturbationSize) Perform linearization at multiple operating points for validation.private double[]Read all CV values.setDefaultPerturbationSize(double perturbation) Set the default perturbation size.setMinimumAbsolutePerturbation(double minPerturbation) Set the minimum absolute perturbation.setUseCentralDifferences(boolean useCentral) Set whether to use central differences.
-
Field Details
-
processSystem
The process system to linearize. -
manipulatedVariables
List of manipulated variables. -
controlledVariables
List of controlled variables. -
disturbanceVariables
List of disturbance variables. -
defaultPerturbationSize
private double defaultPerturbationSizeDefault perturbation size as fraction of variable range. -
minimumAbsolutePerturbation
private double minimumAbsolutePerturbationMinimum absolute perturbation to avoid numerical issues. -
useCentralDifferences
private boolean useCentralDifferencesWhether to use central differences (more accurate) or forward differences (faster).
-
-
Constructor Details
-
ProcessLinearizer
Construct a linearizer for a ProcessSystem.- Parameters:
processSystem- the NeqSim process to linearize
-
-
Method Details
-
addMV
Add a manipulated variable to the linearization.- Parameters:
mv- the manipulated variable- Returns:
- this linearizer for method chaining
-
addCV
Add a controlled variable to the linearization.- Parameters:
cv- the controlled variable- Returns:
- this linearizer for method chaining
-
addDV
Add a disturbance variable to the linearization.- Parameters:
dv- the disturbance variable- Returns:
- this linearizer for method chaining
-
getManipulatedVariables
Get the list of manipulated variables.- Returns:
- unmodifiable list of MVs
-
getControlledVariables
Get the list of controlled variables.- Returns:
- unmodifiable list of CVs
-
getDisturbanceVariables
Get the list of disturbance variables.- Returns:
- unmodifiable list of DVs
-
setDefaultPerturbationSize
Set the default perturbation size.- Parameters:
perturbation- the perturbation as a fraction (0.01 = 1%)- Returns:
- this linearizer for method chaining
-
setMinimumAbsolutePerturbation
Set the minimum absolute perturbation.- Parameters:
minPerturbation- the minimum perturbation value- Returns:
- this linearizer for method chaining
-
setUseCentralDifferences
Set whether to use central differences.- Parameters:
useCentral- true for central differences (more accurate), false for forward differences (faster)- Returns:
- this linearizer for method chaining
-
clear
Clear all variable definitions.- Returns:
- this linearizer for method chaining
-
linearize
Perform linearization with the default perturbation size.- Returns:
- the linearization result containing gain matrices
-
linearize
Perform linearization with a specified perturbation size.The linearization process:
- Read baseline CV values at current operating point
- For each MV, perturb and run simulation to measure CV changes
- Calculate gain as ΔCV/ΔMV
- Restore MV to original value
- Repeat for all MV-CV pairs
- Parameters:
perturbationSize- perturbation as fraction of variable range- Returns:
- the linearization result
-
calculatePerturbation
private double calculatePerturbation(ManipulatedVariable mv, double currentValue, double perturbationFraction) Calculate the perturbation delta for a variable.- Parameters:
mv- the manipulated variablecurrentValue- the current valueperturbationFraction- the perturbation as a fraction- Returns:
- the perturbation delta
-
readAllCVs
private double[] readAllCVs()Read all CV values.- Returns:
- array of current CV values
-
linearizeMultiplePoints
Perform linearization at multiple operating points for validation.- Parameters:
numPoints- number of operating points to testperturbationSize- perturbation for each linearization- Returns:
- list of linearization results at different operating points
-
isApproximatelyLinear
public boolean isApproximatelyLinear(double perturbationSize1, double perturbationSize2, double tolerance) Check if the process is approximately linear within a range.- Parameters:
perturbationSize1- first perturbation sizeperturbationSize2- second perturbation size (should be different)tolerance- acceptable relative difference in gains- Returns:
- true if gains are consistent (linear behavior)
-