Class StateSpaceExporter

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

public class StateSpaceExporter extends Object implements Serializable
Exports process models in state-space form for use with external MPC solvers.

The StateSpaceExporter converts linearization results into standard state-space representation (A, B, C, D matrices) and exports them in various formats for integration with industrial MPC packages and control libraries.

State-space representation:

x(k+1) = A * x(k) + B * u(k)
y(k) = C * x(k) + D * u(k)

Supported export formats:

  • JSON - for Python control libraries
  • CSV - for spreadsheet analysis
  • MATLAB .m file - for MATLAB MPC Toolbox

Example usage:


// Create exporter from linearization result
StateSpaceExporter exporter = new StateSpaceExporter(linearizationResult);

// Generate discrete-time state-space model
StateSpaceModel model = exporter.toDiscreteStateSpace(60.0); // 60s sample time

// Export to various formats
exporter.exportJSON("model.json");
exporter.exportMATLAB("model.m");
exporter.exportCSV("model_"); // Creates model_A.csv, model_B.csv, etc.

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

  • Constructor Details

    • StateSpaceExporter

      public StateSpaceExporter(LinearizationResult linearizationResult)
      Construct an exporter from a linearization result.
      Parameters:
      linearizationResult - the linearization to export
    • StateSpaceExporter

      public StateSpaceExporter(StepResponseGenerator.StepResponseMatrix stepResponseMatrix)
      Construct an exporter from a step response matrix.
      Parameters:
      stepResponseMatrix - the step responses to export
  • Method Details

    • setStepResponseMatrix

      public StateSpaceExporter setStepResponseMatrix(StepResponseGenerator.StepResponseMatrix matrix)
      Set the step response matrix for detailed model generation.
      Parameters:
      matrix - the step response matrix
      Returns:
      this exporter for method chaining
    • toDiscreteStateSpace

      public StateSpaceExporter.StateSpaceModel toDiscreteStateSpace(double sampleTimeSeconds)
      Generate a discrete-time state-space model.

      For a first-order system with gain K and time constant τ, the discrete-time state-space representation with sample time Ts is:

      A = exp(-Ts/τ)
      B = K * (1 - exp(-Ts/τ))
      C = 1
      D = 0
      
      Parameters:
      sampleTimeSeconds - the sample time in seconds
      Returns:
      the state-space model
    • getStateSpaceModel

      public StateSpaceExporter.StateSpaceModel getStateSpaceModel()
      Get the last generated state-space model.
      Returns:
      the state-space model, or null if not yet generated
    • exportJSON

      public void exportJSON(String filename) throws IOException
      Export the model to JSON format.
      Parameters:
      filename - the output filename
      Throws:
      IOException - if writing fails
    • exportCSV

      public void exportCSV(String filenamePrefix) throws IOException
      Export the model to CSV format.

      Creates multiple files: prefix_A.csv, prefix_B.csv, prefix_C.csv, prefix_D.csv

      Parameters:
      filenamePrefix - the output filename prefix
      Throws:
      IOException - if writing fails
    • exportMatrix

      private void exportMatrix(double[][] matrix, String filename) throws IOException
      Throws:
      IOException
    • exportMATLAB

      public void exportMATLAB(String filename) throws IOException
      Export the model to MATLAB .m file format.
      Parameters:
      filename - the output filename
      Throws:
      IOException - if writing fails
    • writeMatrixMATLAB

      private void writeMatrixMATLAB(BufferedWriter writer, double[][] matrix) throws IOException
      Throws:
      IOException
    • exportStepCoefficients

      public void exportStepCoefficients(String filename, int numCoefficients) throws IOException
      Export step response coefficients for DMC-style controllers.
      Parameters:
      filename - the output filename
      numCoefficients - number of step coefficients per MV-CV pair
      Throws:
      IOException - if writing fails