Examples Documentation

This page contains the Examples Package documentation.

The quadtank_static_opt Module

jmodelica.examples.quadtank_static_opt.run_demo(with_plots=True)[source]

Static calibration of the quad tank model.

The cstr2 Module

jmodelica.examples.cstr2.run_demo(with_plots=True)[source]

This example is based on a system composed of two Continously Stirred Tank Reactors (CSTRs) in series. The example demonstrates the following steps:

  1. How to solve a DAE initialization problem. The initialization model have equations specifying that all derivatives should be identically zero, which implies that a stationary solution is obtained. Two stationary points, corresponding to different inputs, are computed. We call the stationary points A and B respectively. For more information about the DAE initialization algorithm, see http://www.jmodelica.org/page/10.
  2. An optimal control problem is solved where the objective is to transfer the state of the system from stationary point A to point B. Here, it is also demonstrated how to set parameter values in a model. More information about the simultaneous optimization algorithm can be found at http://www.jmodelica.org/page/10.
  3. The optimization result is saved to file and then the important variables are plotted.

The pendulum Module

jmodelica.examples.pendulum.run_demo(with_plots=True)[source]

Demonstrate how to solve a dynamic optimization problem based on an inverted pendulum system.

The crane Module

jmodelica.examples.crane.run_demo(with_plots=True)[source]

An example on how to simulate a model using the DAE simulator. Also writes information to a file.

NOTICE: The script does not run since the compiler does not support all constructs needed.

The fmi_bouncing_ball_native Module

jmodelica.examples.fmi_bouncing_ball_native.run_demo(with_plots=True)[source]

This example shows how to use the raw (JModelica.org) FMI interface for simulation of an FMU.

FMU = bouncingBall.fmu (Generated using Qtronic FMU SDK (http://www.qtronic.de/en/fmusdk.html) )

This example is written similair to the example in the documentation of the ‘Functional Mock-up Interface for Model Exchange’ version 1.0 (http://www.functional-mockup-interface.org/)

The cstr Module

jmodelica.examples.cstr.run_demo(with_plots=True)[source]

This example is based on the Hicks-Ray Continuously Stirred Tank Reactors (CSTR) system. The system has two states, the concentration and the temperature. The control input to the system is the temperature of the cooling flow in the reactor jacket. The chemical reaction in the reactor is exothermic, and also temperature dependent; high temperature results in high reaction rate.

The example demonstrates the following steps:

  1. How to solve a DAE initialization problem. The initialization model have equations specifying that all derivatives should be identically zero, which implies that a stationary solution is obtained. Two stationary points, corresponding to different inputs, are computed. We call the stationary points A and B respectively. point A corresponds to operating conditions where the reactor is cold and the reaction rate is low, whereas point B corresponds to a higher temperature where the reaction rate is high.

    For more information about the DAE initialization algorithm, see http://www.jmodelica.org/page/10.

  2. How to generate an initial guess for a direct collocation method by means of simulation. The trajectories resulting from simulation are used to initialize the variables in the transcribed NLP.

  3. An optimal control problem is solved where the objective Is to transfer the state of the system from stationary point A to point B. The challenge is to ignite the reactor while avoiding uncontrolled temperature increase. It is also demonstrated how to set parameter and variable values in a model.

    More information about the simultaneous optimization algorithm can be found at http://www.jmodelica.org/page/10.

  4. The optimization result is saved to file and then the important variables are plotted.

  5. Simulate the system with the optimal control profile. This step is important in order to verify that the approximation in the transcription step is valid.

The blt_example Module

jmodelica.examples.blt_example.run_demo(with_plots=True)[source]

Example demonstrating how to use BLT.

The parameter_estimation_1 Module

jmodelica.examples.parameter_estimation_1.run_demo(with_plots=True)[source]

Demonstrate how to solve a simple parameter estimation problem.

The if_example_1 Module

jmodelica.examples.if_example_1.run_demo(with_plots=True)[source]

Simulation of a model containing if expressions. The relational expressions in the model does not, however, generate events since they are contained inside the noEvent(.) operator.

The vdp Module

jmodelica.examples.vdp.run_demo(with_plots=True)[source]

Demonstrate how to solve a dynamic optimization problem based on a Van der Pol oscillator system.

The lagrange_cost Module

jmodelica.examples.lagrange_cost.run_demo(with_plots=True)[source]

This example demonstrates how to solve optimization problems with a Lagrange cost term encoded using the Optimica attribute objectiveIntegrand.

The simulation_with_input Module

jmodelica.examples.simulation_with_input.run_demo(with_plots=True)[source]

Demonstrates how to simulate with inputs.

The SolAng Module

jmodelica.examples.SolAng.run_demo(with_plots=True)[source]

An example on how to simulate a model using a DAE simulator with Assimulo. The model used is made by Maja Djačić.

The fmi_bouncing_ball Module

jmodelica.examples.fmi_bouncing_ball.run_demo(with_plots=True)[source]

Demonstrates how to use JModelica.org for simulation of FMUs.

The VDP_sim Module

jmodelica.examples.VDP_sim.run_demo(with_plots=True)[source]

An example on how to simulate a model using the ODE simulator.

The quadtank Module

jmodelica.examples.quadtank.run_demo(with_plots=True)[source]

Optimal control of the quadruple tank process.

The ast_example Module

jmodelica.examples.ast_example.run_demo(with_plots=True)[source]

This example demonstrates how the Python interface to the three different ASTs in the compiler can be used. The JPype package is used to create Java objects in a Java Virtual Machine which is seamlessly integrated with the Python shell. The Java objects can be accessed interactively and methods of the object can be invoked.

For more information about the Java classes and their methods used in this example, please consult the API documentation for the Modelica compiler, <a href=http://www.jmodelica.org/page/22>. Notice however that the documentation for the compiler front-ends is still very rudimentary. Also, the interfaces to the source and instance AST will be made more user friendly in upcoming versions.

Three different usages of ASTs are shown:

  1. Count the number of classes in the Modelica standard library. In this example, a Python function is defined to traverse the source AST which results from parsing of the Modelica standard library.
  2. Instantiate the CauerLowPassAnalog model. The instance AST for this model is dumped and it is demonstrated how the merged modification environments can be accessed.
  3. Flatten the CauerLowPassAnalog model instance and print some statistics of the flattened Model.

The vdp_pp Module

jmodelica.examples.vdp_pp.run_demo(with_plots=True)[source]

Demonstrate how to do batch simulations

The extfunctions Module

jmodelica.examples.extfunctions.run_demo(with_plots=True)[source]

The RLC_linearization Module

jmodelica.examples.RLC_linearization.run_demo(with_plots=True)[source]

An example on how to simulate a model using the DAE simulator. The result can be compared with that of sim_rlc.py which has solved the same problem using dymola. Also writes information to a file.

The vdp_minimum_time Module

jmodelica.examples.vdp_minimum_time.run_demo(with_plots=True)[source]

Demonstrate how to solve a minimum time dynamic optimization problem based on a Van der Pol oscillator system.

The robertson Module

The RLC Module

jmodelica.examples.RLC.run_demo(with_plots=True)[source]

An example on how to simulate a model using the DAE simulator. The result can be compared with that of sim_rlc.py which has solved the same problem using dymola. Also writes information to a file.

The index_reduction_example Module

jmodelica.examples.index_reduction_example.run_demo(with_plots=True)[source]

Example demonstrating how to use index reduction.

The qt_par_est Module

jmodelica.examples.qt_par_est.run_demo(with_plots=True)[source]

This example demonstrates how to solve parameter estimation problmes.

The data used in the example was recorded by Kristian Soltesz at the Department of Automatic Control.

The if_example_2 Module

jmodelica.examples.if_example_2.run_demo(with_plots=True)[source]

This example shows how to simulate a system that contains switches. The example model is simple in the sense that no reinitialization of the variables is needed at the event points.

The cstr_mpc Module

jmodelica.examples.cstr_mpc.run_demo(with_plots=True)[source]

Model predicitve control of the Hicks-Ray CSTR reactor. This example demonstrates how to use the blocking factor feature of the collocation algorithm.

This example also shows how to use classes for initialization, simulation and optimization directly rather than calling then through the high-level classes ‘initialialize’, ‘simulate’ and ‘optimize’.

The distillation Module

jmodelica.examples.distillation.run_demo(with_plots=True, with_blocking_factors=False)[source]

Load change of a distillation column. The distillation column model is documented in the paper:

@Article{hahn+02, title={An improved method for nonlinear model reduction using balancing of

empirical gramians},

author={Hahn, J. and Edgar, T.F.}, journal={Computers and Chemical Engineering}, volume={26}, number={10}, pages={1379-1397}, year={2002} }