Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release-3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillis committed Apr 4, 2023
2 parents 4dd6b6d + 3e8db86 commit 6e362d7
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 115 deletions.
59 changes: 38 additions & 21 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,11 @@
{
"name": "core",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}"
},
{
"name": "common",
"hidden": true,
"cacheVariables": {
"WITH_IPOPT": "ON",
"WITH_OPENMP": "ON",
"WITH_QPOASES": "ON",
"WITH_LAPACK": "ON"
}
},
{
"name": "devel",
"name": "debug",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
Expand All @@ -39,16 +28,10 @@
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "python",
"hidden": true,
"cacheVariables": {
"WITH_PYTHON": "ON"
}
},
{
"name": "mingw",
"hidden": true,
"generator": "Ninja",
"cacheVariables": {
"WITH_THREAD_MINGW": "ON",
"CMAKE_C_COMPILER": "gcc",
Expand All @@ -58,6 +41,7 @@
{
"name": "cl",
"hidden": true,
"generator": "Ninja",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
Expand All @@ -66,6 +50,7 @@
{
"name": "clang-cl",
"hidden": true,
"generator": "Ninja",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl"
Expand All @@ -76,14 +61,46 @@
}
}
},
{
"name": "python",
"hidden": true,
"cacheVariables": {
"WITH_PYTHON": "ON"
}
},
{
"name": "common",
"hidden": true,
"cacheVariables": {
"WITH_IPOPT": "ON",
"WITH_OPENMP": "ON",
"WITH_QPOASES": "ON",
"WITH_LAPACK": "ON"
}
},
{
"name": "devel",
"displayName": "Linux developer",
"inherits": [
"debug",
"python",
"core",
"common"
],
"cacheVariables": {
"PYTHON_PREFIX": "${sourceDir}/out/install/${presetName}/python",
"WITH_CLANG": "ON",
"WITH_BUILD_REQUIRED": "ON"
}
},
{
"name": "windevel",
"displayName": "Windows developer (MinGW)",
"inherits": [
"common",
"mingw",
"core",
"devel",
"debug",
"python"
]
},
Expand All @@ -93,7 +110,7 @@
"inherits": [
"cl",
"core",
"devel"
"debug"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/cplusplus/multiple_shooting_from_scratch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(){
SXDict dae = {{"x", x}, {"p", u}, {"ode", ode}, {"quad", quad}};

// Create an integrator (CVodes)
Function F = integrator("integrator", "cvodes", dae, {{"t0", 0}, {"tf", tf/ns}});
Function F = integrator("integrator", "cvodes", dae, 0, tf/ns);

// Total number of NLP variables
int NV = nx*(ns+1) + nu*ns;
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/cplusplus/rocket_single_shooting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ int main(){
opts["interpolation_order"] = 1;
opts["number_of_finite_elements"] = 1000;
}
opts["t0"] = t0;
opts["tf"] = tf;

// Create integrator
Function F = integrator("integrator", plugin, dae, opts);
Function F = integrator("integrator", plugin, dae, t0, tf, opts);

// control for all segments
MX U = MX::sym("U",nu);
Expand Down
168 changes: 86 additions & 82 deletions docs/users_guide/source/daebuilder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,99 +7,95 @@ The |DaeBuilder| class

The |DaeBuilder| class in |casadi| is an auxiliary class intended to
facilitate the modeling complex dynamical systems for later use with optimal
control algorithms. This class can be seen as a low-level alternative to
control algorithms. This class has lower level of abstraction than
a physical modeling language such as Modelica (cf. :numref:`sec-modelica`),
while still being higher level than working directly with |casadi| symbolic
expressions. Another important usage it to provide an interface to
physical modeling languages and software and be a building blocks for
developing domain specific modeling environments.
expressions. In particular, it can be used to interface physical models
available in the Functional Mock-up Interface (FMI) format or be used
as a building block for constructing a domain specific modeling environments.

Using the |DaeBuilder| class consists of the following steps:

* Step-by-step constructing a structured system of differential-algebraic equations (DAE) or, alternatively, importing an existing model from Modelica
* Symbolically reformulate the DAE
* Generate a chosen set of |casadi| functions to be used for e.g. optimal control or C code generation

In the following sections, we describe the mathematical formulation of the class
and its intended usage.
There are in principle three different ways to use |DaeBuilder|:
* One can use the class to step-by-step construct a structured system of differential-algebraic equations (DAE), which can then be used to interface to simulation or optimization in CasADi. There is also experimental support for exporting the models in the FMI format for use in other tools.
* One can use the class to import existing models available in the FMI format. As of CasADi 3.6, we support import of standard FMUs, where the model equations are available only by calls to DLLs. The FMU import support has been tested for challenging FMUs, but is still under development as of this writing.
* One can use the class to import existing models in a symbolic XML format. This format was supported in the JModelica.org tool and has experimental support in OpenModelica. This format is not in active development due to the limited availability of tools to generate models in the format.

.. _sec-daebuilder_io:

Mathematical formulation
------------------------
.. Mathematical formulation
.. ------------------------
The |DaeBuilder| class uses a relatively rich problem formulation that
consists of a set of input expressions and a set of output expressions, each
defined by a string identifier. The choice of expressions was inspired by the
*functional mock-up interface* (FMI) version 2.0
[#f3]_
.. The |DaeBuilder| class uses a relatively rich problem formulation that
.. consists of a set of input expressions and a set of output expressions, each
.. defined by a string identifier. The choice of expressions was inspired by the
.. *functional mock-up interface* (FMI) version 2.0
.. [#f3]_
Input expressions
^^^^^^^^^^^^^^^^^
.. Input expressions
.. ^^^^^^^^^^^^^^^^^
't'
Time :math:`t`
.. 't'
.. Time :math:`t`
'c'
Named constants :math:`c`
.. 'c'
.. Named constants :math:`c`
'p'
Independent parameters :math:`p`
.. 'p'
.. Independent parameters :math:`p`
'v'
Dependent variables :math:`v`, depends on other variables and, acyclically, on other :math:`v`
.. 'v'
.. Dependent variables :math:`v`, depends on other variables and, acyclically, on other :math:`v`
'x'
Differential state :math:`x`, defined by an explicit ODE
.. 'x'
.. Differential state :math:`x`, defined by an explicit ODE
's'
Differential state :math:`s`, defined by an implicit ODE
.. 's'
.. Differential state :math:`s`, defined by an implicit ODE
'sdot'
Time derivatives implicitly defined differential state :math:`\dot{s}`
.. 'sdot'
.. Time derivatives implicitly defined differential state :math:`\dot{s}`
'z'
Algebraic variable, defined by an algebraic equation
.. 'z'
.. Algebraic variable, defined by an algebraic equation
'q'
Quadrature state :math:`q`. A differential state that may not appear in
the right-hand-side and hence can be calculated by quadrature formulas.
.. 'q'
.. Quadrature state :math:`q`. A differential state that may not appear in
.. the right-hand-side and hence can be calculated by quadrature formulas.
'y'
Output variables :math:`y`
.. 'y'
.. Output variables :math:`y`
'u'
Input variables :math:`u`
.. 'u'
.. Input variables :math:`u`
Output expressions
^^^^^^^^^^^^^^^^^^
.. Output expressions
.. ^^^^^^^^^^^^^^^^^^
The above input expressions are used to define the following output expressions:
.. The above input expressions are used to define the following output expressions:
'vdef'
Explicit expression for calculating :math:`v`
.. 'vdef'
.. Explicit expression for calculating :math:`v`
'ode'
The explicit ODE right-hand-side:
:math:`\dot{x} = \text{ode}(t,v,x,s,z,u,p)`
.. 'ode'
.. The explicit ODE right-hand-side:
.. :math:`\dot{x} = \text{ode}(t,v,x,s,z,u,p)`
'dae'
The implicit ODE right-hand-side:
:math:`\text{dae}(t,v,x,s,z,u,p,\dot{s}) =0`
.. 'dae'
.. The implicit ODE right-hand-side:
.. :math:`\text{dae}(t,v,x,s,z,u,p,\dot{s}) =0`
'alg'
The algebraic equations:
:math:`\text{alg}(t,v,x,s,z,u,p) = 0`
.. 'alg'
.. The algebraic equations:
.. :math:`\text{alg}(t,v,x,s,z,u,p) = 0`
'quad'
The quadrature equations:
:math:`\dot{q} = \text{quad}(t,v,x,s,z,u,p)`
.. 'quad'
.. The quadrature equations:
.. :math:`\dot{q} = \text{quad}(t,v,x,s,z,u,p)`
'ydef'
Explicit expressions for calculating :math:`y`
.. 'ydef'
.. Explicit expressions for calculating :math:`y`
.. _sec-daebuilder_syntax:

Expand Down Expand Up @@ -188,9 +184,17 @@ list of functions, see the C++ API documentation for |DaeBuilder|.

.. _sec-modelica:

Import of OCPs from Modelica
Symbolic import of OCPs from Modelica
----------------------------

Note: JModelica.org is no longer offered by Modelon. Its closed-source successor code, OCT,
does retain CasADi interoperability however. Details of how to use OCT to generate CasADi
expressions is best described in OCT's user guide. The text in the following refers to the
legacy Modelica interoperability support.

Legacy symbolic import from XML files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

An alternative to model directly in |casadi|, as above, is to use an advanced
physical modeling language such as Modelica to specify the model. For this,
|casadi| offers interoperability with the open-source `JModelica.org <http://www.jmodelica.org/}>`_ compiler, which
Expand Down Expand Up @@ -237,35 +241,35 @@ using the ``parse_fmi`` command:
ocp.parse_fmi('modelDescription.xml')
Symbolic reformulation
----------------------
.. Symbolic reformulation
.. ----------------------
One of the original purposes of the |DaeBuilder| class was to reformulate
a *fully-implicit DAE*, typically coming from Modelica, to a semi-explicit
DAE that can be used more readily in optimal control algorithms.
.. One of the original purposes of the |DaeBuilder| class was to reformulate
.. a *fully-implicit DAE*, typically coming from Modelica, to a semi-explicit
.. DAE that can be used more readily in optimal control algorithms.
This can be done by the \python{make_implicit} command:
.. This can be done by the \python{make_implicit} command:
.. side-by-side::
.. code-block:: python
.. .. side-by-side::
.. .. code-block:: python
ocp.make_explicit()
.. ocp.make_explicit()
&&
.. &&
.. code-block:: octave
.. .. code-block:: octave
ocp.make_explicit();
.. ocp.make_explicit();
Other useful commands available for an instance ``ocp`` of |DaeBuilder| include:
.. Other useful commands available for an instance ``ocp`` of |DaeBuilder| include:
* ``print ocp`` Print the optimal optimal control problem to screen
* ``ocp.scale_variables()`` Scale all variables using the *nominal* attribute for each variable
* ``ocp.eliminate_d()`` Eliminate all independent parameters from the symbolic expressions
.. * ``print ocp`` Print the optimal optimal control problem to screen
.. * ``ocp.scale_variables()`` Scale all variables using the *nominal* attribute for each variable
.. * ``ocp.eliminate_d()`` Eliminate all independent parameters from the symbolic expressions
For a more detailed description of this class and its functionalities, we again
refer to the API documentation.
.. For a more detailed description of this class and its functionalities, we again
.. refer to the API documentation.
Function factory
----------------
Expand Down
Loading

0 comments on commit 6e362d7

Please sign in to comment.