Package neqsim.process.mpc
package neqsim.process.mpc
Model Predictive Control (MPC) integration package for NeqSim ProcessSystem.
This package provides seamless integration between NeqSim's rigorous thermodynamic process
simulation and industrial Model Predictive Control (MPC) systems. It bridges the gap between the
physical simulation in ProcessSystem and the control
algorithms in ModelPredictiveController.
Key Classes
Variable Definitions
MPCVariable- Base class for MPC variablesManipulatedVariable- Manipulated Variables (MVs) - what the controller adjustsControlledVariable- Controlled Variables (CVs) - what we want to controlDisturbanceVariable- Disturbance Variables (DVs) - measured but uncontrolled
Model Identification
ProcessLinearizer- Automatic Jacobian calculation using finite differencesLinearizationResult- Container for gain matrices and operating point dataStepResponseGenerator- Automated step testing frameworkStepResponse- Single MV-CV step response with FOPDT fitting
Prediction and Control
NonlinearPredictor- Multi-step prediction using full NeqSim simulationProcessLinkedMPC- Bridge class connecting ProcessSystem to MPC
Export and Integration
StateSpaceExporter- Export models to JSON/CSV/MATLAB for external MPC
Industrial Control System Integration
IndustrialMPCExporter- Export step-response models, gain matrices, and configurations in formats compatible with industrial MPC platformsControllerDataExchange- Real-time bidirectional data exchange interface with quality flags and execution status for PCS integrationSoftSensorExporter- Export soft-sensor and estimator configurations for industrial calculation enginesSubrModlExporter- Export nonlinear models in SubrModl format with SubrXvr definitions and DtaIx mappingsStateVariable- State variable (SVR) for nonlinear MPC with bias tracking and prediction
Usage Patterns
Basic MPC Setup
// Build process system
ProcessSystem process = new ProcessSystem();
Stream feed = new Stream("feed", fluid);
Valve valve = new Valve("inlet_valve", feed);
Separator separator = new Separator("separator", valve.getOutletStream());
process.add(feed);
process.add(valve);
process.add(separator);
process.run();
// Create linked MPC
ProcessLinkedMPC mpc = new ProcessLinkedMPC("pressureController", process);
// Define variables
mpc.addMV("inlet_valve", "opening", 0.0, 1.0); // Valve opening 0-100%
mpc.addCV("separator", "pressure", 50.0); // Control to 50 bar
mpc.setConstraint("separator", "pressure", 40.0, 60.0); // Hard limits
// Identify model and configure
mpc.setSampleTime(60.0);
mpc.setPredictionHorizon(20);
mpc.setControlHorizon(5);
mpc.identifyModel(60.0);
// Control loop
while (running) {
double[] moves = mpc.step(); // Calculate, apply, run
System.out.println("MV=" + moves[0] + " CV=" + mpc.getCurrentCVs()[0]);
Thread.sleep((long) (mpc.getSampleTime() * 1000));
}
Model Export for External MPC
// After linearization
StateSpaceExporter exporter = mpc.exportModel();
StateSpaceExporter.StateSpaceModel ssModel = exporter.toDiscreteStateSpace(60.0);
// Export to various formats
exporter.exportJSON("process_model.json"); // For Python
exporter.exportMATLAB("process_model.m"); // For MATLAB MPC Toolbox
exporter.exportCSV("model_"); // CSV files
Advanced: Nonlinear Prediction
// Enable nonlinear prediction for highly nonlinear processes
mpc.setUseNonlinearPrediction(true);
mpc.identifyModel(60.0);
// Predictions now use full NeqSim simulation
double[] moves = mpc.calculate();
Integration with Existing MPC
This package is designed to work with the existing
ModelPredictiveController. The
ProcessLinkedMPC class automatically configures the underlying MPC
from the ProcessSystem linearization.
AI Platform Integration
The package is designed for integration with AI/ML platforms that require process models for optimization and control. Key integration points:
- JSON export for Python-based MPC implementations
- Step response coefficients for DMC-style controllers
- State-space models for Kalman filtering and state estimation
- Nonlinear predictions for training machine learning models
Industrial MPC Integration
The package provides seamless integration with industrial control systems through standard interfaces and export formats:
Step Response Model Export
// Export for industrial MPC systems using linear step-response models
IndustrialMPCExporter exporter = mpc.createIndustrialExporter();
exporter.setTagPrefix("UNIT1.separator");
exporter.setApplicationName("GasProcessing");
// Export step response coefficients in CSV format
exporter.exportStepResponseCSV("step_responses.csv");
// Export complete object structure for core configuration
exporter.exportObjectStructure("controller_config.json");
// Export comprehensive configuration with all model data
exporter.exportComprehensiveConfiguration("mpc_config.json");
Real-Time Data Exchange
// Create data exchange interface for PCS integration
ControllerDataExchange exchange = mpc.createDataExchange();
exchange.setTagPrefix("UNIT1.MPC");
// Control loop with external controller
while (running) {
// Update inputs from process measurements
exchange.updateInputs(mvValues, cvValues, dvValues);
exchange.updateSetpoints(setpoints);
exchange.updateLimits(cvLowLimits, cvHighLimits, mvLowLimits, mvHighLimits);
// Execute and get outputs
exchange.execute();
ControllerDataExchange.ControllerOutput output = exchange.getOutputs();
// Apply to process
if (output.getStatus() == ControllerDataExchange.ExecutionStatus.SUCCESS) {
applyMVs(output.getMvTargets());
}
}
Soft Sensor Export
// Export soft-sensor configurations for calculation engines
SoftSensorExporter softExporter = new SoftSensorExporter(process);
softExporter.setTagPrefix("UNIT1");
// Add sensors for key properties
softExporter.addDensitySensor("sep_gas_density", "separator", "gas outlet");
softExporter.addViscositySensor("sep_oil_visc", "separator", "oil outlet");
softExporter.addPhaseFractionSensor("sep_gas_frac", "separator");
softExporter.addCompositionEstimator("sep_comp", "separator", "gas outlet",
new String[] {"methane", "ethane", "propane"});
// Export in JSON and CVT formats
softExporter.exportConfiguration("soft_sensors.json");
softExporter.exportCVTFormat("soft_sensors.cvt");
Nonlinear MPC with SubrModl Export
// Create MPC with state variables for nonlinear model
ProcessLinkedMPC mpc = new ProcessLinkedMPC("wellController", process);
mpc.addMV("choke", "opening", 0.0, 1.0);
mpc.addCV("well", "pressure", 50.0);
mpc.addDV("reservoir", "pressure");
// Add state variables (SVR) for internal model states
mpc.addSVR("well", "flowIn", "qin");
mpc.addSVR("well", "flowOut", "qout");
mpc.addSVR("choke", "cv", "cv");
// Export for nonlinear MPC system
SubrModlExporter exporter = mpc.createSubrModlExporter();
exporter.setModelName("WellModel");
exporter.addParameter("Volume", 100.0, "m3");
exporter.addParameter("Height", 2000.0, "m");
exporter.addParameter("Density", 700.0, "kg/m3");
// Export configuration files
exporter.exportConfiguration("well_config.txt");
exporter.exportMPCConfiguration("mpc_config.txt", true); // true = SQP solver
exporter.exportIndexTable("well_ixid.cpp");
- Since:
- 3.0
- Version:
- 1.0
- Author:
- Even Solbraa
- See Also:
-
ClassDescriptionRepresents a controlled variable (CV) in an MPC formulation.Provides a real-time data exchange interface between NeqSim MPC and external control systems.Container for controller output data.Execution status.Quality status flags.Represents a disturbance variable (DV) in an MPC formulation.Exports MPC models and configurations in formats compatible with industrial control systems.Result of a linearization operation containing the gain matrix and metadata.Represents a manipulated variable (MV) in an MPC formulation.Base class for MPC variables (manipulated, controlled, or disturbance).Enumeration of MPC variable types.Performs multi-step ahead prediction using full NeqSim nonlinear simulation.Represents a trajectory of MV values over time.Result of a prediction containing CV and MV trajectories.Efficient derivative calculator for NeqSim process simulations.Derivative calculation methods.Result container for derivative calculations with error estimates.Specification for an input or output variable.Variable types for optimal step size calculation.Computes linearized process models from NeqSim ProcessSystem using finite differences.Bridge class that auto-configures and links MPC to a ProcessSystem.Accessor for reading and writing process variables by path.Exports soft-sensor and estimator configurations for integration with external calculation engines.Soft-sensor types.Definition of a soft-sensor.Exports process models in state-space form for use with external MPC solvers.Represents a discrete-time state-space model.Represents a state variable (SVR) in a nonlinear MPC system.Represents a step response from a single input to a single output.Generates step response models by running NeqSim simulations.Matrix container for step responses from all MV-CV pairs.Exports NeqSim process models in SubrModl format for nonlinear MPC integration.Model parameter definition.State variable (SVR) definition.SubrXvr definition for variable linking.