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

Model Identification

Prediction and Control

Export and Integration

Industrial Control System Integration

  • IndustrialMPCExporter - Export step-response models, gain matrices, and configurations in formats compatible with industrial MPC platforms
  • ControllerDataExchange - Real-time bidirectional data exchange interface with quality flags and execution status for PCS integration
  • SoftSensorExporter - Export soft-sensor and estimator configurations for industrial calculation engines
  • SubrModlExporter - Export nonlinear models in SubrModl format with SubrXvr definitions and DtaIx mappings
  • StateVariable - 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: