Class SubrModlExporter

java.lang.Object
neqsim.process.mpc.SubrModlExporter
All Implemented Interfaces:
Serializable

public class SubrModlExporter extends Object implements Serializable
Exports NeqSim process models in SubrModl format for nonlinear MPC integration.

This class generates configuration files compatible with industrial nonlinear MPC systems that use programmed model objects (SubrModl). The export includes:

  • Model parameters (constants like volume, height, density)
  • SubrXvr definitions with DtaIx mappings for variable linking
  • State variables (SVR) for internal model states
  • Initial values and engineering unit specifications

The SubrModl format supports nonlinear dynamic equations with commands like INIT, STEP, STDSTEP for steady-state, UPDT for state updates, and SAVE for persistence.

Example usage:


ProcessSystem process = new ProcessSystem();
// ... add equipment ...

SubrModlExporter exporter = new SubrModlExporter(process);
exporter.setModelName("WellModel");
exporter.addParameter("Volume", 100.0, "m3");
exporter.addParameter("Height", 2000.0, "m");

// Add SubrXvr definitions
exporter.addSubrXvr("Pdownhole", "pdh", "Downhole pressure", 147.7);
exporter.addSubrXvr("Pwellhead", "pwh", "Wellhead pressure", 10.4);

// Export configuration
exporter.exportConfiguration("wellmodel_config.txt");

Since:
3.0
Version:
1.0
Author:
Even Solbraa
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • processSystem

      private final ProcessSystem processSystem
      The process system to export.
    • modelName

      private String modelName
      Model name for SubrModl/SubrProc.
    • applicationName

      private String applicationName
      Application name for the configuration.
    • parameters

      private final List<SubrModlExporter.ModelParameter> parameters
      Model parameters (constants).
    • subrXvrs

      private final List<SubrModlExporter.SubrXvr> subrXvrs
      SubrXvr definitions.
    • stateVariables

      private final List<SubrModlExporter.StateVariable> stateVariables
      State variables (SVR).
    • indexTable

      private final List<String> indexTable
      Index table entries.
    • sampleTime

      private double sampleTime
      Sample time for the model (seconds).
  • Constructor Details

    • SubrModlExporter

      public SubrModlExporter(ProcessSystem processSystem)
      Construct a SubrModl exporter.
      Parameters:
      processSystem - the process system to export
  • Method Details

    • setModelName

      public SubrModlExporter setModelName(String modelName)
      Set the model name.
      Parameters:
      modelName - the model name
      Returns:
      this exporter for chaining
    • setApplicationName

      public SubrModlExporter setApplicationName(String applicationName)
      Set the application name.
      Parameters:
      applicationName - the application name
      Returns:
      this exporter for chaining
    • setSampleTime

      public SubrModlExporter setSampleTime(double sampleTime)
      Set the sample time.
      Parameters:
      sampleTime - sample time in seconds
      Returns:
      this exporter for chaining
    • addParameter

      public SubrModlExporter addParameter(String name, double value, String unit)
      Add a model parameter (constant).
      Parameters:
      name - parameter name
      value - parameter value
      unit - engineering unit
      Returns:
      this exporter for chaining
    • addParameter

      public SubrModlExporter addParameter(String name, double value, String unit, String description)
      Add a model parameter with description.
      Parameters:
      name - parameter name
      value - parameter value
      unit - engineering unit
      description - parameter description
      Returns:
      this exporter for chaining
    • addSubrXvr

      public SubrModlExporter addSubrXvr(String name, String dtaIx, String description, double init)
      Add a SubrXvr definition.
      Parameters:
      name - variable name
      dtaIx - data index for C++ linking
      description - variable description
      init - initial value
      Returns:
      this exporter for chaining
    • addStateVariable

      public SubrModlExporter addStateVariable(String name, String dtaIx, String description, double modelValue)
      Add a state variable (SVR).
      Parameters:
      name - variable name
      dtaIx - data index
      description - variable description
      modelValue - initial model value
      Returns:
      this exporter for chaining
    • addIndexEntry

      public SubrModlExporter addIndexEntry(String dtaIx)
      Add an index table entry.
      Parameters:
      dtaIx - data index to add
      Returns:
      this exporter for chaining
    • exportConfiguration

      public void exportConfiguration(String filename) throws IOException
      Export the model configuration in SubrModl format.

      This generates a configuration file compatible with industrial nonlinear MPC systems using the SubrProc/SubrModl pattern.

      Parameters:
      filename - the output filename
      Throws:
      IOException - if writing fails
    • exportMPCConfiguration

      public void exportMPCConfiguration(String filename, boolean useNonlinear) throws IOException
      Export MPC configuration with nonlinear parameters.

      This generates the SmpcAppl configuration section with tuning parameters for nonlinear MPC.

      Parameters:
      filename - the output filename
      useNonlinear - whether to use nonlinear (SQP) or linear (QP) solver
      Throws:
      IOException - if writing fails
    • exportIndexTable

      public void exportIndexTable(String filename) throws IOException
      Export the index table (IxId) for C++ code generation.
      Parameters:
      filename - the output filename
      Throws:
      IOException - if writing fails
    • exportJSON

      public void exportJSON(String filename) throws IOException
      Export as JSON for programmatic use.
      Parameters:
      filename - the output filename
      Throws:
      IOException - if writing fails
    • populateFromMPC

      public SubrModlExporter populateFromMPC(ProcessLinkedMPC controller)
      Auto-populate from ProcessLinkedMPC controller.

      This automatically extracts MVs, CVs, DVs from the MPC controller and creates corresponding SubrXvr definitions.

      Parameters:
      controller - the MPC controller
      Returns:
      this exporter for chaining
    • generateDtaIx

      private String generateDtaIx(String name)
      Generate a data index from a variable name.
      Parameters:
      name - the variable name
      Returns:
      the data index (lowercase, no spaces)
    • formatValue

      private String formatValue(double value)
      Format a numeric value for output.
      Parameters:
      value - the value
      Returns:
      formatted string
    • getParameters

      public List<SubrModlExporter.ModelParameter> getParameters()
      Get the model parameters.
      Returns:
      list of parameters
    • getSubrXvrs

      public List<SubrModlExporter.SubrXvr> getSubrXvrs()
      Get the SubrXvr definitions.
      Returns:
      list of SubrXvrs
    • getStateVariables

      public List<SubrModlExporter.StateVariable> getStateVariables()
      Get the state variables.
      Returns:
      list of state variables
    • getIndexTable

      public List<String> getIndexTable()
      Get the index table.
      Returns:
      list of index entries