Search code examples
modelicajmodelica

Optimal control of a boiler: using Fluid Library w. the DynamicPipe component using JModelica


Im interested in using JModelica together with a model I have constructed in Dymola.

Specifically, I have a model of a boiler using the DynamicPipe component, and I then just transfer heat to the pipe to warm up the water inside it, and employ a pump component to control the pressure difference over the entire boiler. The model compiles just fine to an FMU using JModelica and I am able to simulate it without any problems.

However, I now wan't to find an optimal control sequence to bring the boiler into a certain operating point and here things stop working.

I have written a .mop file with an optimization problem, but when I call transfer_optimization_problem, I get the following error:

Warning: Ignored enumeration typed variable:
eval parameter Modelica.Fluid.Types.ModelStructure boiler.boilerFMU.boiler.pipe.modelStructure = Modelica.Fluid.Types.ModelStructure.av_b "Determines whether flow or volume models are present at the ports" /* Modelica.Fluid.Types.ModelStructure.av_b */
Java error occurred:
Exception in thread "main" java.lang.UnsupportedOperationException: Cannot convert expression to MX: size(A, 1)
at org.jmodelica.optimica.compiler.FExp.toMX(FExp.java:4516)
at org.jmodelica.optimica.compiler.FMaxExp.toMX(FMaxExp.java:560)
at org.jmodelica.optimica.compiler.FExp.toMXVector(FExp.java:4497)
at org.jmodelica.optimica.compiler.FAssignStmt.updateExpressionsAccordingToStatement(FAssignStmt.java:385)
at org.jmodelica.optimica.compiler.FFunctionDecl.generateFinalExpressionVector(FFunctionDecl.java:1365)
at org.jmodelica.optimica.compiler.FFunctionDecl.toMXFunction_compute(FFunctionDecl.java:2878)
at org.jmodelica.optimica.compiler.FFunctionDecl.toMXFunction(FFunctionDecl.java:2865)
at org.jmodelica.optimica.compiler.FFunctionCall.toMXVector(FFunctionCall.java:1578)
at org.jmodelica.optimica.compiler.FFunctionCallStmt.updateExpressionsAccordingToStatement(FFunctionCallStmt.java:391)
at org.jmodelica.optimica.compiler.FFunctionDecl.generateFinalExpressionVector(FFunctionDecl.java:1365)
at org.jmodelica.optimica.compiler.FFunctionDecl.toMXFunction_compute(FFunctionDecl.java:2878)
at org.jmodelica.optimica.compiler.FFunctionDecl.toMXFunction(FFunctionDecl.java:2865)
at org.jmodelica.optimica.compiler.FFunctionCall.toMXVector(FFunctionCall.java:1578)
at org.jmodelica.optimica.compiler.FFunctionCallStmt.updateExpressionsAccordingToStatement(FFunctionCallStmt.java:391)
at org.jmodelica.optimica.compiler.FFunctionDecl.generateFinalExpressionVector(FFunctionDecl.java:1365)
at org.jmodelica.optimica.compiler.FFunctionDecl.toMXFunction_compute(FFunctionDecl.java:2878)
at org.jmodelica.optimica.compiler.FFunctionDecl.toMXFunction(FFunctionDecl.java:2865)
at org.jmodelica.optimica.compiler.FFunctionCall.toMXVector(FFunctionCall.java:1578)
at org.jmodelica.optimica.compiler.FFunctionCall.toMX(FFunctionCall.java:1562)
at org.jmodelica.optimica.compiler.FDotSubExp.toMX(FDotSubExp.java:544)
at org.jmodelica.optimica.compiler.FVariable.parameterEquationToMXBindingExpression(FVariable.java:3807)
at org.jmodelica.optimica.compiler.FVariable.findMXBindingExpressionIfPresent(FVariable.java:3770)
Traceback (most recent call last):
File "boiler_opt.py", line 89, in <module>
op = transfer_optimization_problem("BoilerOptimization.Opt", paths, compiler_log_level='error')
File "/opt/jmodelica/Python/pyjmi/casadi_interface.py", line 171, in transfer_optimization_problem
accept_model=accept_model)
File "/opt/jmodelica/Python/modelicacasadi_transfer/modelica_casadi_transfer_wrapper.py", line 156, in transfer_optimization_problem
_get_options(compiler_options), compiler_log_level)
File "/opt/jmodelica/Python/modelicacasadi_transfer/modelica_casadi_transfer_wrapper.py", line 179, in _transfer_optimica
return modelicacasadi_wrapper._transferOptimizationProblem(ocp, class_name, files, options, log_level)
File "/opt/jmodelica/Python/modelicacasadi_wrapper/modelicacasadi_wrapper.py", line 3417, in _transferOptimizationProblem
return _modelicacasadi_wrapper._transferOptimizationProblem(*args)
RuntimeError: a java error occurred; details were printed

Apparently, it is not so happy about an enumerate type in the DynamicPipe model which specifies the model structure.

To check that it is indeed my model that was the problem, I linearized it and used the linearised version in the optimization problem; this ran perfectly.

Any idea on how to handle this? :-)

Regards,

Joakim

UPDATE: I asked the same question on the JModelica forums, with the following response. However, I have not yet found a solution to circumvent the errors: http://www.jmodelica.org/27776#comment-6467


Solution

  • So an acceptable answer was provided on the JModelica forums by Fredrik: http://www.jmodelica.org/27776#comment-6468

    Simply put: The MSL Media Library is not supported.

    My solution was to instead built my own small fluid library specifically for my use case - this was a no-brainer in the case of single-phase water, and it works perfectly. But I must admit, that it would have been nice to be able to use the MSL Fluid Library, to not lock myself in with my own fluid interface.