Class StateSpaceExporter
java.lang.Object
neqsim.process.mpc.StateSpaceExporter
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a discrete-time state-space model. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LinearizationResultThe linearization result to export.private static final longGenerated state-space model.Step response matrix for more detailed model. -
Constructor Summary
ConstructorsConstructorDescriptionStateSpaceExporter(LinearizationResult linearizationResult) Construct an exporter from a linearization result.StateSpaceExporter(StepResponseGenerator.StepResponseMatrix stepResponseMatrix) Construct an exporter from a step response matrix. -
Method Summary
Modifier and TypeMethodDescriptionvoidExport the model to CSV format.voidexportJSON(String filename) Export the model to JSON format.voidexportMATLAB(String filename) Export the model to MATLAB .m file format.private voidexportMatrix(double[][] matrix, String filename) voidexportStepCoefficients(String filename, int numCoefficients) Export step response coefficients for DMC-style controllers.Get the last generated state-space model.Set the step response matrix for detailed model generation.toDiscreteStateSpace(double sampleTimeSeconds) Generate a discrete-time state-space model.private voidwriteMatrixMATLAB(BufferedWriter writer, double[][] matrix)
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
linearizationResult
The linearization result to export. -
stepResponseMatrix
Step response matrix for more detailed model. -
stateSpaceModel
Generated state-space model.
-
-
Constructor Details
-
StateSpaceExporter
Construct an exporter from a linearization result.- Parameters:
linearizationResult- the linearization to export
-
StateSpaceExporter
Construct an exporter from a step response matrix.- Parameters:
stepResponseMatrix- the step responses to export
-
-
Method Details
-
setStepResponseMatrix
Set the step response matrix for detailed model generation.- Parameters:
matrix- the step response matrix- Returns:
- this exporter for method chaining
-
toDiscreteStateSpace
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
Get the last generated state-space model.- Returns:
- the state-space model, or null if not yet generated
-
exportJSON
Export the model to JSON format.- Parameters:
filename- the output filename- Throws:
IOException- if writing fails
-
exportCSV
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
- Throws:
IOException
-
exportMATLAB
Export the model to MATLAB .m file format.- Parameters:
filename- the output filename- Throws:
IOException- if writing fails
-
writeMatrixMATLAB
- Throws:
IOException
-
exportStepCoefficients
Export step response coefficients for DMC-style controllers.- Parameters:
filename- the output filenamenumCoefficients- number of step coefficients per MV-CV pair- Throws:
IOException- if writing fails
-