List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
casadi::DaeBuilder Class Reference

A symbolic representation of a differential-algebraic equations model. More...

#include <dae_builder.hpp>

Detailed Description

A DaeBuilder holds a list of uniquely named model variables with FMI-style meta data (causality, variability, type, start value, bounds, unit, ...) together with the model equations. The model is either built symbolically with add, eq, when and friends, or imported from an FMU / modelDescription.xml (constructor with a path, load_fmi_description). Numerical evaluation goes through the function factory create, which returns differentiable Function objects.

Every variable belongs to at most one CasADi category, derived from its causality, variability and defining equation:

Variables:

t:      independent variable (usually time)
c:      constants
p:      parameters
d:      dependent parameters (time independent)
u:      controls
w:      dependent variables  (time dependent)
x:      differential states
z:      algebraic variables
q:      quadrature states
y:      outputs

Equations:

differential equations: \dot{x} ==  ode(...)
algebraic equations:          0 ==  alg(...)
quadrature equations:   \dot{q} == quad(...)
dependent parameters:         d == ddef(d_prev,p)
dependent variables:          w == wdef(w_prev,x,z,u,p,t)
output equations:             y == ydef(...)
initial equations:     init_lhs == init_rhs(...)
events:      when when_cond < 0: when_lhs := when_rhs

The category names ("x", "ode", ...) are the strings accepted by all, inputs, outputs, create and the other category-based members. Internal helper variables (named der(x), __alg__0, __assign__.., __when__0, ...) are created as equations are added; they show up in all().

>>> dae = DaeBuilder("rocket")
>>> a = dae.add("a", "parameter", "tunable")
>>> u = dae.add("u", "input")
>>> h = dae.add("h", dict(start=0))
>>> v = dae.add("v", dict(start=0, unit="m/s"))
>>> m = dae.add("m", dict(start=1))
>>> dae.eq(dae.der(h), v)
>>> dae.eq(dae.der(v), (u - a*v**2)/m - 9.81)
>>> dae.eq(dae.der(m), -u**2)
>>> dae.x(), dae.u(), dae.p()
(['h', 'v', 'm'], ['u'], ['a'])
>>> f = dae.create("f", ["x", "u", "p"], ["ode"])
>>> f
Function(f:(x[3],u,p)->(ode[3]) MXFunction)
>>> f([0, 0, 1], 1, 0.5)
DM([0, -8.81, -1])

>> dae = DaeBuilder('rocket');
>> a = dae.add('a', 'parameter', 'tunable'); u = dae.add('u', 'input');
>> h = dae.add('h', struct('start', 0)); v = dae.add('v', struct('start', 0, 'unit', 'm/s'));
>> m = dae.add('m', struct('start', 1));
>> dae.eq(dae.der(h), v); dae.eq(dae.der(v), (u - a*v^2)/m - 9.81); dae.eq(dae.der(m), -u^2);
>> dae.x()
h
v
m
>> dae.u(), dae.p()
u
a
>> f = dae.create('f', {'x', 'u', 'p'}, {'ode'}); disp(f)
f:(x[3],u,p)->(ode[3]) MXFunction
>> f([0; 0; 1], 1, 0.5)
[0, -8.81, -1]

julia> dae = ca.DaeBuilder("rocket");
julia> a = ca.add(dae, "a", "parameter", "tunable");
julia> u = ca.add(dae, "u", "input");
julia> h = ca.add(dae, "h", Dict("start" => 0));
julia> v = ca.add(dae, "v", Dict("start" => 0, "unit" => "m/s"));
julia> m = ca.add(dae, "m", Dict("start" => 1));
julia> ca.eq(dae, ca.der(dae, h), v)
julia> ca.eq(dae, ca.der(dae, v), (u - a*v^2)/m - 9.81)
julia> ca.eq(dae, ca.der(dae, m), -u^2)
julia> ca.x(dae), ca.u(dae), ca.p(dae)
(["h", "v", "m"], ["u"], ["a"])
julia> f = ca.create(dae, "f", ["x", "u", "p"], ["ode"])
Function(f:(x[3],u,p)->(ode[3]) MXFunction)
julia> f([0, 0, 1], 1, 0.5)
DM([0, -8.81, -1])

Date
2012-2021
Author
Joel Andersson

Extra doc: https://github.com/casadi/casadi/wiki/L_5c

Definition at line 145 of file dae_builder.hpp.

Inheritance diagram for casadi::DaeBuilder:
Inheritance graph
[legend]
Collaboration diagram for casadi::DaeBuilder:
Collaboration graph
[legend]

Public Types

using internal_base_type = SharedObjectInternal
 
using base_type = SharedObject
 

Public Member Functions

std::string type_name () const
 Readable name of the class. More...
 
 DaeBuilder ()
 Default constructor: a null instance, not usable until assigned. More...
 
 DaeBuilder (const std::string &name, const std::string &path="", const Dict &opts=Dict())
 Construct a DaeBuilder instance. More...
 
const std::string & name () const
 Name of instance. More...
 
void reorder (const std::string &cat, const std::vector< std::string > &v)
 Reorder variables in a category. More...
 
void set_all (const std::string &v, const std::vector< std::string > &name)
 Set all variables within a a category. More...
 
Function create (const std::string &fname, const Dict &opts=Dict()) const
 Create a function with standard integrator DAE signature. More...
 
Function create () const
 Create a function with standard integrator DAE signature, default naming. More...
 
Function dependent_fun (const std::string &fname, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out) const
 Construct a function for evaluating dependent parameters. More...
 
Function transition (const std::string &fname, casadi_int index) const
 Construct a function describing transition at a specific events. More...
 
Function transition (const std::string &fname) const
 Construct a function describing transition at any events. More...
 
Function transition () const
 Construct an event transition function, default naming. More...
 
std::vector< std::string > der () const
 Model structure: All time derivatives. More...
 
std::vector< std::string > der (const std::vector< std::string > &name) const
 Get the time derivative of model variables. More...
 
std::vector< std::string > pre (const std::vector< std::string > &name) const
 Get the pre-variables of model variables. More...
 
MX pre (const MX &v) const
 Get the pre-expression given variable expression. More...
 
bool has_beq (const std::string &name) const
 Does a variable have a binding equation? More...
 
MX beq (const std::string &name) const
 Get the binding equation for a variable. More...
 
std::string causality (const std::string &name) const
 Get the causality. More...
 
std::vector< std::string > categories (const std::string &name) const
 Which categories are possible for a variable? More...
 
void set_causality (const std::string &name, const std::string &val)
 Set the causality, if permitted. More...
 
std::string variability (const std::string &name) const
 Get the variability. More...
 
void set_variability (const std::string &name, const std::string &val)
 Set the variability, if permitted. More...
 
std::string category (const std::string &name) const
 Get the variable category. More...
 
void set_category (const std::string &name, const std::string &val)
 Set the variable category, if permitted. More...
 
casadi_int numel (const std::string &name) const
 Get the number of elements of a variable. More...
 
std::vector< casadi_int > dimension (const std::string &name) const
 Get the dimensions of a variable. More...
 
double start_time () const
 Get the start time. More...
 
void set_start_time (double val)
 Set the start time of the default experiment. More...
 
double stop_time () const
 Get the stop time of the default experiment, nan when unknown. More...
 
void set_stop_time (double val)
 Set the stop time of the default experiment. More...
 
double tolerance () const
 Get the tolerance of the default experiment, nan when unknown. More...
 
void set_tolerance (double val)
 Set the tolerance of the default experiment. More...
 
double step_size () const
 Get the step size of the default experiment, nan when unknown. More...
 
void set_step_size (double val)
 Set the step size of the default experiment. More...
 
std::string der (const std::string &name) const
 Get the time derivative of model variables, single variable. More...
 
std::string pre (const std::string &name) const
 Get the pre-variables of model variables, single variable (not implemented) More...
 
double attribute (const std::string &a, const std::string &name) const
 Get an attribute, single variable. More...
 
void set_attribute (const std::string &a, const std::string &name, double val)
 Set an attribute, single variable (vector-valued variables get all elements set) More...
 
double min (const std::string &name) const
 Get the lower bound, single variable. More...
 
void set_min (const std::string &name, double val)
 Set the lower bound, single variable. More...
 
double max (const std::string &name) const
 Get the upper bound, single variable (inf by default) More...
 
void set_max (const std::string &name, double val)
 Set the upper bound, single variable. More...
 
double nominal (const std::string &name) const
 Get the nominal value, single variable (1 by default) More...
 
void set_nominal (const std::string &name, double val)
 Set the nominal value, single variable. More...
 
std::vector< double > start (const std::string &name) const
 Get the start attribute, single variable. More...
 
void set_start (const std::string &name, double val)
 Set the start attribute, single variable (all elements for a vector-valued variable) More...
 
void set_start (const std::string &name, const std::vector< double > &val)
 Set the start attribute, vector argument (length numel, or 1 to broadcast) More...
 
void reset ()
 Clear all set values. More...
 
void set (const std::string &name, double val)
 Set the current value, single value. More...
 
void set (const std::string &name, const std::string &val)
 Set the current value, single value (string), for variables of type "String" More...
 
GenericType get (const std::string &name) const
 Evaluate the values for a set of variables at the initial time, single value. More...
 
bool symbolic () const
 Symbolic DAE instance? More...
 
std::vector< double > attribute (const std::string &a, const std::vector< std::string > &name) const
 Get an attribute for several variables, concatenated ("start"/"value" per element) More...
 
void set_attribute (const std::string &a, const std::vector< std::string > &name, const std::vector< double > &val)
 Set an attribute, one value per variable or one value per element. More...
 
std::vector< double > min (const std::vector< std::string > &name) const
 Get the lower bound for several (scalar) variables. More...
 
void set_min (const std::vector< std::string > &name, const std::vector< double > &val)
 Set the lower bound for several variables. More...
 
std::vector< double > max (const std::vector< std::string > &name) const
 Get the upper bound for several (scalar) variables. More...
 
void set_max (const std::vector< std::string > &name, const std::vector< double > &val)
 Set the upper bound for several variables. More...
 
std::vector< double > nominal (const std::vector< std::string > &name) const
 Get the nominal value for several (scalar) variables. More...
 
void set_nominal (const std::vector< std::string > &name, const std::vector< double > &val)
 Set the nominal value for several variables. More...
 
std::vector< double > start (const std::vector< std::string > &name) const
 Get the start attribute for several variables, concatenated. More...
 
void set_start (const std::vector< std::string > &name, const std::vector< double > &val)
 Set the start attribute for several variables. More...
 
void set (const std::vector< std::string > &name, const std::vector< double > &val)
 Set the current value for several variables (one per variable or one per element) More...
 
void set (const std::vector< std::string > &name, const std::vector< std::string > &val)
 Set the current value (string) for several string variables. More...
 
std::vector< GenericType > get (const std::vector< std::string > &name) const
 Evaluate the values for a set of variables at the initial time, one entry per name. More...
 
bool has (const std::string &name) const
 Check if a particular variable exists. More...
 
std::vector< std::string > all () const
 Get a list of all variables. More...
 
std::vector< std::string > all (const std::string &cat) const
 Get a list of all variables of a particular category. More...
 
Function oracle (bool sx=false, bool elim_w=false, bool lifted_calls=false) const
 Get the (cached) oracle, SX or MX. More...
 
Sparsity jac_sparsity (const std::vector< std::string > &onames, const std::vector< std::string > &inames) const
 Get Jacobian sparsity. More...
 
const DaeBuilderInternal * operator-> () const
 Access a member function or object. More...
 
DaeBuilderInternal * operator-> ()
 Access a member function or object. More...
 
std::string class_name () const
 Get class name. More...
 
void disp (std::ostream &stream, bool more=false) const
 Print a description of the object. More...
 
std::string get_str (bool more=false) const
 Get string representation. More...
 
void print_ptr (std::ostream &stream=casadi::uout()) const
 
void own (SharedObjectInternal *node)
 
void assign (SharedObjectInternal *node)
 Assign the node to a node class pointer without reference counting. More...
 
SharedObjectInternal * get () const
 Get a const pointer to the node. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
void swap (GenericShared &other)
 Swap content with another instance. More...
 
std::string debug_repr () const
 
bool is_null () const
 Is a null pointer? More...
 
casadi_int __hash__ () const
 Returns a number that is unique for a given Node. More...
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 
Variables and equations
const MX & time () const
 Expression for independent variable (usually time) More...
 
std::vector< std::string > t_new () const
 Independent variable (usually time) More...
 
std::vector< std::string > x () const
 Differential states. More...
 
std::vector< std::string > y () const
 Outputs. More...
 
std::vector< std::string > z () const
 Algebraic variables. More...
 
std::vector< std::string > q () const
 Quadrature states. More...
 
std::vector< MX > inputs (const std::string &cat) const
 Input expressions for a specific category. More...
 
std::vector< MX > outputs (const std::string &cat) const
 Output expressions for a specific category. More...
 
std::vector< MX > ode () const
 [DEPRECATED] Replaced with outputs("ode") More...
 
std::vector< MX > alg () const
 [DEPRECATED] Replaced with outputs("alg") More...
 
std::vector< MX > quad () const
 [DEPRECATED] Replaced with outputs("quad") More...
 
std::vector< MX > zero () const
 [DEPRECATED] Replaced with outputs("zero") More...
 
std::vector< MX > ydef () const
 [DEPRECATED] Replaced with outputs("y") More...
 
void set_y (const std::vector< std::string > &name)
 [DEPRECATED] Replaced with set_all("y", name) More...
 
std::vector< std::string > u () const
 Free controls. More...
 
std::vector< std::string > p () const
 Parameters. More...
 
std::vector< std::string > c () const
 Named constants. More...
 
std::vector< MX > cdef () const
 Definitions of named constants. More...
 
std::vector< std::string > d () const
 Dependent parameters. More...
 
std::vector< MX > ddef () const
 Definitions of dependent parameters. More...
 
std::vector< std::string > w () const
 Dependent variables. More...
 
std::vector< MX > wdef () const
 Dependent variables and corresponding definitions. More...
 
std::vector< MX > init_lhs () const
 Initial conditions, left-hand-side. More...
 
std::vector< MX > init_rhs () const
 Initial conditions, right-hand-side. More...
 
std::vector< std::string > outputs () const
 [DEPRECATED] Renamed "y" More...
 
std::vector< std::string > derivatives () const
 [DEPRECATED] Renamed "der" More...
 
std::vector< std::string > initial_unknowns () const
 Model structure: initial unknowns. More...
 
bool has_t () const
 Is there a time variable? More...
 
casadi_int nx () const
 Differential states. More...
 
casadi_int nz () const
 Algebraic variables. More...
 
casadi_int nq () const
 Quadrature states. More...
 
casadi_int nzero () const
 Zero-crossing functions. More...
 
casadi_int ny () const
 Output variables. More...
 
casadi_int nu () const
 Free controls. More...
 
casadi_int np () const
 Parameters. More...
 
casadi_int nc () const
 Named constants. More...
 
casadi_int nd () const
 Dependent parameters. More...
 
casadi_int nw () const
 Dependent variables. More...
 
Symbolic modeling

Formulate a dynamic system model

MX add (const std::string &name, const std::string &causality, const std::string &variability, const Dict &opts=Dict())
 Add a new model variable. More...
 
MX add (const std::string &name, const std::string &causality, const Dict &opts=Dict())
 Add a new model variable, default variability. More...
 
MX add (const std::string &name, const Dict &opts=Dict())
 Add a new model variable, default variability and causality. More...
 
void add (const std::string &name, const std::string &causality, const std::string &variability, const MX &expr, const Dict &opts=Dict())
 Add a new model variable, symbolic expression already available. More...
 
void eq (const MX &lhs, const MX &rhs, const Dict &opts=Dict())
 Add a simple equation. More...
 
void when (const MX &cond, const std::vector< std::string > &eqs, const Dict &opts=Dict())
 Add when equations. More...
 
std::string assign (const std::string &name, const MX &val)
 Assignment inside a when-equation or if-else equation. More...
 
std::string reinit (const std::string &name, const MX &val)
 Reinitialize a state inside when-equations. More...
 
void set_init (const std::string &name, const MX &init_rhs)
 Specify the initial equation for a variable. More...
 
void sanity_check () const
 Check if dimensions match. More...
 
Manipulation

Reformulate the dynamic optimization problem.

void eliminate (const std::string &cat)
 Eliminate all dependent parameters. More...
 
void sort (const std::string &cat)
 Sort dependent parameters. More...
 
void lift (bool lift_shared=true, bool lift_calls=true)
 Lift problem formulation by extracting shared subexpressions. More...
 
void prune (bool prune_p=true, bool prune_u=true)
 Prune unused controls. More...
 
void tear ()
 Identify iteration variables and residual equations using naming convention. More...
 
Functions

Add or load auxiliary functions

Function add_fun (const std::string &name, const std::vector< std::string > &arg, const std::vector< std::string > &res, const Dict &opts=Dict())
 Add a function from loaded expressions. More...
 
Function add_fun (const Function &f)
 Add an already existing function. More...
 
Function add_fun (const std::string &name, const Importer &compiler, const Dict &opts=Dict())
 Add an external function. More...
 
bool has_fun (const std::string &name) const
 Does a particular function already exist? More...
 
Function fun (const std::string &name) const
 Get function by name. More...
 
std::vector< Function > fun () const
 Get all functions. More...
 
void gather_fun (casadi_int max_depth=-1)
 Collect embedded functions from the expression graph. More...
 
Import and export
void parse_fmi (const std::string &filename)
 
bool provides_directional_derivatives () const
 Does the FMU provide support for analytic derivatives. More...
 
bool provides_directional_derivative () const
 Does the FMU provide support for analytic derivatives (FMI 2 naming) More...
 
void load_fmi_description (const std::string &filename)
 Import problem description from FMI or XML. More...
 
Dict export_fmu (const Dict &opts=Dict())
 Export instance into an FMU. More...
 
Dict compile_fmu (const Dict &files, const Dict &opts=Dict())
 Compile the sources produced by export_fmu. More...
 
std::string pack_fmu (const Dict &files, const Dict &opts=Dict())
 Pack files from export_fmu / compile_fmu into a single .fmu archive. More...
 
void add_lc (const std::string &name, const std::vector< std::string > &f_out)
 Add a named linear combination of output expressions. More...
 
Function create (const std::string &fname, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, bool sx, bool lifted_calls=false) const
 Construct a function object, legacy syntax. More...
 
Function create (const std::string &name, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts=Dict()) const
 Construct a function object, names provided. More...
 
MX var (const std::string &name) const
 Get variable expression by name. More...
 
MX operator() (const std::string &name) const
 Get variable expression by name. More...
 
MX der (const MX &v) const
 Differentiate an expression with respect to time. More...
 
MX der (const MX &v)
 Differentiate an expression with respect to time. More...
 
casadi_int value_reference (const std::string &name) const
 Get/set value reference. More...
 
void set_value_reference (const std::string &name, casadi_int val)
 Get/set value reference. More...
 
std::string description (const std::string &name) const
 Get/set description. More...
 
void set_description (const std::string &name, const std::string &val)
 Get/set description. More...
 
std::string type (const std::string &name, casadi_int fmi_version=3) const
 Get/set the type. More...
 
void set_type (const std::string &name, const std::string &val)
 Get/set the type. More...
 
std::string initial (const std::string &name) const
 Get/set the initial property. More...
 
void set_initial (const std::string &name, const std::string &val)
 Get/set the initial property. More...
 
std::string unit (const std::string &name) const
 Get/set the unit. More...
 
void set_unit (const std::string &name, const std::string &val)
 Get/set the unit. More...
 
std::string display_unit (const std::string &name) const
 Get/set the display unit. More...
 
void set_display_unit (const std::string &name, const std::string &val)
 Get/set the display unit. More...
 

Static Public Member Functions

static bool test_cast (const SharedObjectInternal *ptr)
 Check if a particular cast is allowed. More...
 

Protected Member Functions

void count_up ()
 
void count_down ()
 

Member Typedef Documentation

◆ base_type

Definition at line 103 of file shared_object.hpp.

◆ internal_base_type

Definition at line 102 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ DaeBuilder() [1/2]

casadi::DaeBuilder::DaeBuilder ( )

Definition at line 51 of file dae_builder.cpp.

51  {
52 }

◆ DaeBuilder() [2/2]

casadi::DaeBuilder::DaeBuilder ( const std::string &  name,
const std::string &  path = "",
const Dict &  opts = Dict() 
)
explicit

Without path, the instance starts empty and the model is built symbolically with add and eq. With path, the model description is imported immediately:

  • a directory containing modelDescription.xml (an unzipped FMU),
  • a .fmu archive (requires a build with WITH_GHC_FILESYSTEM=ON; it is unzipped to a temporary directory that is removed once nothing references it any more),
  • a .bmo Base Modelica file (requires the lacemodelica ModelicaParser plugin).

An imported standard FMU is not symbolic (symbolic() is false): equations are evaluated by calling the FMU binary, so create is available but oracle, eq, eliminate etc. are not.

Parameters
nameInstance name; used as default function name prefix by create(), transition() and export_fmu
pathModel to import, see above; empty for a symbolic model
optsOptions (any other key is an error):
  • "debug" (bool, false): print debug information during import and enable FMU logging
  • "fmutol" (double, 0): tolerance passed to the FMU
  • "ignore_time" (bool, false): do not expose the hidden time variable of an imported model that declares no independent variable
  • "detect_quad" (bool, false): classify differential states that do not appear in any right-hand side as quadrature states q
  • "resource_serialize_mode" (string): how an imported FMU is serialized with functions created from it, "link" or "embed"
  • "enable_ls_dae" (bool, true): honour the DAE layered standard of an FMU
  • "enable_ls_serialization" (bool, true): honour the serialization layered standard of an FMU

>>> dae = DaeBuilder("rocket")
>>> dae.name(), dae.symbolic(), dae.all()
('rocket', True, [])
>>> try:
...   DaeBuilder("m", "/nonexistent/path")
... except RuntimeError:
...   print("import failed")
import failed
>>> try:
...   DaeBuilder("m", "", dict(foo=True))
... except Exception as e:
...   print("No such option" in str(e))
True

>> dae = DaeBuilder('rocket');
>> dae.name(), isempty(dae.all())
rocket
1
>> try, DaeBuilder('m', '/nonexistent/path'); failed = false; catch e, failed = true; end
>> failed
1
>> try, DaeBuilder('m', '', struct('foo', true)); catch e, msg = e.message; end
>> contains(msg, 'No such option')
1

julia> dae = ca.DaeBuilder("rocket");
julia> ca.name(dae), ca.symbolic(dae), ca.all(dae)
("rocket", true, String[])
julia> try
           ca.DaeBuilder("m", "/nonexistent/path")
       catch e
           println("import failed")
       end
import failed
julia> try
           ca.DaeBuilder("m", "", Dict("foo" => true))
       catch e
           println(occursin("No such option", sprint(showerror, e)))
       end
true

See also
load_fmi_description, symbolic

Extra doc: https://github.com/casadi/casadi/wiki/L_2ko

Definition at line 54 of file dae_builder.cpp.

54  {
55  own(new DaeBuilderInternal(name, path, opts));
56  if (!path.empty()) load_fmi_description((*this)->resource_.path() + "/modelDescription.xml");
57 }
const std::string & name() const
Name of instance.
Definition: dae_builder.cpp:59
void load_fmi_description(const std::string &filename)
Import problem description from FMI or XML.
std::vector< casadi_int > path(const std::vector< casadi_int > &map, casadi_int i_start)

References load_fmi_description(), name(), casadi::GenericShared< SharedObject, SharedObjectInternal >::own(), and casadi::path().

Member Function Documentation

◆ __hash__()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::__hash__
inherited

If the Object does not point to any node, "0" is returned.

Extra doc: https://github.com/casadi/casadi/wiki/L_av

Definition at line 123 of file generic_shared_impl.hpp.

148  {
149  return reinterpret_cast<casadi_int>(get());
150  }

◆ add() [1/4]

MX casadi::DaeBuilder::add ( const std::string &  name,
const Dict &  opts = Dict() 
)

The causality defaults to "local"; the variability follows from the type as above, so a plain add(name) gives a continuous local variable of category z.

Extra doc: https://github.com/casadi/casadi/wiki/L_2kr

Definition at line 361 of file dae_builder.cpp.

361  {
362  try {
363  return (*this)->add(name, opts).v;
364  } catch (std::exception& e) {
365  THROW_ERROR("add", e.what());
366  return MX();
367  }
368 }

References name().

◆ add() [2/4]

MX casadi::DaeBuilder::add ( const std::string &  name,
const std::string &  causality,
const Dict &  opts = Dict() 
)

The variability follows the FMI 3.0 default: "fixed" for parameters and calculated parameters, "continuous" for floating-point variables and "discrete" for any other type (see the "type" option).

Extra doc: https://github.com/casadi/casadi/wiki/L_2kq

Definition at line 352 of file dae_builder.cpp.

352  {
353  try {
354  return (*this)->add(name, to_enum<Causality>(causality), opts).v;
355  } catch (std::exception& e) {
356  THROW_ERROR("add", e.what());
357  return MX();
358  }
359 }
std::string causality(const std::string &name) const
Get the causality.

References causality(), and name().

◆ add() [3/4]

MX casadi::DaeBuilder::add ( const std::string &  name,
const std::string &  causality,
const std::string &  variability,
const Dict &  opts = Dict() 
)

Creates a variable with FMI 3.0 causality and variability and returns its symbolic expression, a dense column vector with numel elements (the product of the dimensions). The category follows from causality and variability and may change later when equations are added:

  • "parameter": "tunable" gives p (c for non-floating-point types), "fixed" gives c; other variabilities are an error
  • "calculatedParameter": d; requires "fixed" or "tunable"
  • "input": u; requires "continuous" or "discrete"
  • "output" and "local": "constant" gives c, "discrete" gives a state x with zero derivative, "continuous" gives z until an equation defines the variable (w) or its derivative (x); "local" also accepts "fixed" and "tunable" (d)
  • "independent": t; requires "continuous", at most one per model

Variables with causality "output" are additionally listed in y(). Unless the first variable is the independent one, a hidden variable "time" is created first.

Parameters
nameUnique variable name; reusing a name is an error
causality"parameter", "calculatedParameter", "input", "output", "local" or "independent"
variability"constant", "fixed", "tunable", "discrete" or "continuous"
optsAttributes (any other key is an error):
  • "dimension" (list of int, [1]): shape; all entries must be positive
  • "type" (string, "Float64"): FMI 3 type, e.g. "Float32", "Int32", "Boolean", "String"
  • "start" (double or list): start value, scalar is broadcast; also sets the current value, see get
  • "min", "max", "nominal" (double): bounds and scaling
  • "initial" (string): "exact", "approx", "calculated" or "na"; default per FMI from causality and variability
  • "description", "unit", "display_unit" (string): meta data
Returns
Symbolic expression of the new variable, named like the variable

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> x, x.shape, dae.category("x"), dae.causality("x"), dae.variability("x")
(MX(x), (1, 1), 'z', 'local', 'continuous')
>>> p = dae.add("p", "parameter", "tunable")
>>> dae.category("p"), dae.variability("p")
('p', 'tunable')
>>> b = dae.add("b", "input", dict(type="Boolean", start=False))
>>> dae.category("b"), dae.variability("b"), dae.type("b")
('u', 'discrete', 'Boolean')
>>> r = dae.add("r", dict(dimension=[3], start=[1, 2, 3], min=0, unit="m"))
>>> r.shape, dae.start("r"), dae.min("r"), dae.unit("r")
((3, 1), [1.0, 2.0, 3.0], 0.0, 'm')
>>> try:
...   dae.add("x")
... except Exception as e:
...   print("already exists" in str(e))
True
>>> try:
...   dae.add("q", "parameter", "continuous")
... except Exception as e:
...   print("requires 'fixed' or 'tunable'" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x');
>> x, size(x), dae.category('x'), dae.causality('x')
x
1 1
z
local
>> dae.variability('x')
continuous
>> p = dae.add('p', 'parameter', 'tunable');
>> dae.category('p'), dae.variability('p')
p
tunable
>> b = dae.add('b', 'input', struct('type', 'Boolean', 'start', false));
>> dae.category('b'), dae.variability('b'), dae.type('b')
u
discrete
Boolean
>> r = dae.add('r', struct('dimension', 3, 'start', [1 2 3], 'min', 0, 'unit', 'm'));
>> size(r), dae.start('r'), dae.unit('r')
3 1
1 2 3
m
>> try, dae.add('x'); catch e, disp(contains(e.message, 'already exists')); end
1
>> try, dae.add('q', 'parameter', 'continuous'); catch e, msg = e.message; end
>> contains(msg, 'requires ''fixed'' or ''tunable''')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> x, size(x), ca.category(dae, "x"), ca.causality(dae, "x"), ca.variability(dae, "x")
(x, (1, 1), "z", "local", "continuous")
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> ca.category(dae, "p"), ca.variability(dae, "p")
("p", "tunable")
julia> b = ca.add(dae, "b", "input", Dict("type" => "Boolean", "start" => false));
julia> ca.category(dae, "b"), ca.variability(dae, "b"), ca.type(dae, "b")
("u", "discrete", "Boolean")
julia> opts = Dict("dimension" => [3], "start" => [1, 2, 3], "min" => 0, "unit" => "m");
julia> r = ca.add(dae, "r", opts);
julia> size(r), ca.start(dae, "r"), dae.min("r"), ca.unit(dae, "r")
((3, 1), [1.0, 2.0, 3.0], 0.0, "m")
julia> try
           ca.add(dae, "x")
       catch e
           println(occursin("already exists", sprint(showerror, e)))
       end
true
julia> try
           ca.add(dae, "q", "parameter", "continuous")
       catch e
           println(occursin("requires 'fixed' or 'tunable'", sprint(showerror, e)))
       end
true

See also
eq, der, var, category, set_category

Extra doc: https://github.com/casadi/casadi/wiki/L_2kp

Definition at line 341 of file dae_builder.cpp.

342  {
343  try {
344  return (*this)->add(name, to_enum<Causality>(causality),
345  to_enum<Variability>(variability), opts).v;
346  } catch (std::exception& e) {
347  THROW_ERROR("add", e.what());
348  return MX();
349  }
350 }
std::string variability(const std::string &name) const
Get the variability.

References causality(), name(), and variability().

◆ add() [4/4]

void casadi::DaeBuilder::add ( const std::string &  name,
const std::string &  causality,
const std::string &  variability,
const MX &  expr,
const Dict &  opts = Dict() 
)

Registers an existing symbolic primitive instead of creating a new one. expr must be a pure symbol (is_symbolic()) whose name equals name; anything else is an error. The dimension attribute is not taken from the expression.

Extra doc: https://github.com/casadi/casadi/wiki/L_2ks

Definition at line 370 of file dae_builder.cpp.

371  {
372  try {
373  // Ensure pure symbolic expression
374  casadi_assert(expr.is_symbolic(), "Expression must be symbolic");
375  // Make sure name matches expression
376  casadi_assert(name == expr.name(), "Name must match expression");
377  // Add variable
378  (*this)->add(name, to_enum<Causality>(causality), to_enum<Variability>(variability),
379  expr, opts);
380  } catch (std::exception& e) {
381  THROW_ERROR("add", e.what());
382  }
383 }

References causality(), casadi::MX::is_symbolic(), name(), casadi::MX::name(), and variability().

◆ add_fun() [1/3]

Function casadi::DaeBuilder::add_fun ( const Function &  f)

Stores f under its own name; a stored function with the same name is an error.

>>> a = MX.sym("a")
>>> F = Function("F", [a], [a**2])
>>> dae = DaeBuilder("m")
>>> dae.add_fun(F)
Function(F:(i0)->(o0) MXFunction)
>>> [g.name() for g in dae.fun()]
['F']

>> a = MX.sym('a'); F = Function('F', {a}, {a^2});
>> dae = DaeBuilder('m');
>> dae.add_fun(F)
F:(i0)->(o0) MXFunction
>> cellfun(@(g) disp(g.name()), dae.fun())
F

julia> a = ca.MX.sym("a");
julia> F = ca.Function("F", [a], [a^2]);
julia> dae = ca.DaeBuilder("m");
julia> ca.add_fun(dae, F)
Function(F:(i0)->(o0) MXFunction)
julia> [ca.name(g) for g in ca.fun(dae)]
1-element Vector{String}:
 "F"

Extra doc: https://github.com/casadi/casadi/wiki/L_2l7

Definition at line 795 of file dae_builder.cpp.

795  {
796  try {
797  return (*this)->add_fun(f);
798  } catch (std::exception& e) {
799  THROW_ERROR("add_fun", e.what());
800  return Function(); // never reached
801  }
802 }

◆ add_fun() [2/3]

Function casadi::DaeBuilder::add_fun ( const std::string &  name,
const Importer &  compiler,
const Dict &  opts = Dict() 
)

Loads the function name from the compiled sources or shared library behind compiler (see external) and stores it.

Extra doc: https://github.com/casadi/casadi/wiki/L_2l8

Definition at line 814 of file dae_builder.cpp.

814  {
815  casadi_assert(!has_fun(name), "Function '" + name + "' already exists");
816  return add_fun(external(name, compiler, opts));
817 }
bool has_fun(const std::string &name) const
Does a particular function already exist?
Function add_fun(const std::string &name, const std::vector< std::string > &arg, const std::vector< std::string > &res, const Dict &opts=Dict())
Add a function from loaded expressions.
Function external(const std::string &name, const Importer &li, const Dict &opts)
Load a just-in-time compiled external function.
Definition: external.cpp:42

References add_fun(), casadi::external(), has_fun(), and name().

◆ add_fun() [3/3]

Function casadi::DaeBuilder::add_fun ( const std::string &  name,
const std::vector< std::string > &  arg,
const std::vector< std::string > &  res,
const Dict &  opts = Dict() 
)

Creates a Function mapping the model variables arg to the binding expressions of the dependent variables res and stores it in the instance. Stored functions are listed by disp and retrieved with fun.

Parameters
nameFunction name; must not exist yet
argNames of model variables used as inputs
resNames of dependent variables w, whose definitions become the outputs; any other name is an error
optsFunction options
Returns
The created function

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> w = dae.add("w")
>>> dae.eq(w, sin(x))
>>> dae.eq(dae.der(x), -w)
>>> f = dae.add_fun("wfun", ["x"], ["w"])
>>> f
Function(wfun:(x)->(w) MXFunction)
>>> dae.has_fun("wfun"), dae.has_fun("nope")
(True, False)
>>> try:
...   dae.add_fun("bad", ["x"], ["x"])
... except Exception as e:
...   print("Cannot find dependent" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); w = dae.add('w');
>> dae.eq(w, sin(x)); dae.eq(dae.der(x), -w);
>> f = dae.add_fun('wfun', {'x'}, {'w'}); disp(f)
wfun:(x)->(w) MXFunction
>> dae.has_fun('wfun'), dae.has_fun('nope')
1
0
>> try, dae.add_fun('bad', {'x'}, {'x'}); catch e, msg = e.message; end
>> contains(msg, 'Cannot find dependent')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> w = ca.add(dae, "w");
julia> ca.eq(dae, w, sin(x))
julia> f = ca.add_fun(dae, "wfun", ["x"], ["w"])
Function(wfun:(x)->(w) MXFunction)
julia> ca.has_fun(dae, "wfun"), ca.has_fun(dae, "nope")
(true, false)
julia> try
           ca.add_fun(dae, "bad", ["x"], ["x"])
       catch e
           println(occursin("Cannot find dependent", sprint(showerror, e)))
       end
true

See also
fun, has_fun, gather_fun

Extra doc: https://github.com/casadi/casadi/wiki/L_2l6

Definition at line 804 of file dae_builder.cpp.

805  {
806  try {
807  return (*this)->add_fun(name, arg, res, opts);
808  } catch (std::exception& e) {
809  THROW_ERROR("add_fun", e.what());
810  return Function(); // never reached
811  }
812 }

References name().

Referenced by add_fun(), and gather_fun().

◆ add_lc()

void casadi::DaeBuilder::add_lc ( const std::string &  name,
const std::vector< std::string > &  f_out 
)

Declares the name of a linear combination of output categories, so that create can produce its Hessian blocks hess_<name>_<in1>_<in2> with the multipliers lam_<out> as extra inputs.

Parameters
nameAlphanumeric name
f_outOutput categories in the combination, e.g. ["ode", "alg"]; must be non-empty without duplicates

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> z = dae.add("z")
>>> dae.eq(dae.der(x), -x*z)
>>> dae.eq(0, z - x**2)
>>> dae.add_lc("gamma", ["ode", "alg"])
>>> H = dae.create("H", ["x", "z", "lam_ode", "lam_alg"],
...                ["hess_gamma_x_x", "hess_gamma_x_z"])
>>> H
Function(H:(x,z,lam_ode,lam_alg)->(hess_gamma_x_x,hess_gamma_x_z) MXFunction)
>>> H(1, 2, 1, 1)
(DM(2), DM(-1))

>> dae = DaeBuilder('m'); x = dae.add('x'); z = dae.add('z');
>> dae.eq(dae.der(x), -x*z); dae.eq(0, z - x^2);
>> dae.add_lc('gamma', {'ode', 'alg'});
>> out = {'hess_gamma_x_x', 'hess_gamma_x_z'};
>> H = dae.create('H', {'x', 'z', 'lam_ode', 'lam_alg'}, out); disp(H)
H:(x,z,lam_ode,lam_alg)->(hess_gamma_x_x,hess_gamma_x_z) MXFunction
>> [Hxx, Hxz] = H(1, 2, 1, 1); disp(Hxx), disp(Hxz)
2
-1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> z = ca.add(dae, "z");
julia> ca.eq(dae, ca.der(dae, x), -x*z)
julia> ca.eq(dae, 0, z - x^2)
julia> ca.add_lc(dae, "gamma", ["ode", "alg"])
julia> H = ca.create(dae, "H", ["x", "z", "lam_ode", "lam_alg"],
                     ["hess_gamma_x_x", "hess_gamma_x_z"])
Function(H:(x,z,lam_ode,lam_alg)->(hess_gamma_x_x,hess_gamma_x_z) MXFunction)
julia> H(1, 2, 1, 1)
(2, -1)

See also
create

Extra doc: https://github.com/casadi/casadi/wiki/L_2lf

Definition at line 755 of file dae_builder.cpp.

756  {
757  try {
758  (*this)->add_lc(name, f_out);
759  } catch (std::exception& e) {
760  THROW_ERROR("add_lc", e.what());
761  }
762 }

References name().

◆ alg()

std::vector<MX> casadi::DaeBuilder::alg ( ) const
inline

Definition at line 695 of file dae_builder.hpp.

695 {return outputs("alg");}
std::vector< std::string > outputs() const
[DEPRECATED] Renamed "y"

◆ all() [1/2]

std::vector< std::string > casadi::DaeBuilder::all ( ) const

Names of all variables in creation order, including the hidden "time" variable and the internal helper variables created by eq, when, assign and reinit.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> dae.eq(dae.der(x), -x)
>>> dae.all()
['time', 'x', 'der(x)', '__assign__der(x)__']
>>> dae.all("x"), dae.all("w"), dae.all("calculated")
(['x'], ['der(x)'], ['__assign__der(x)__'])

>> dae = DaeBuilder('m'); x = dae.add('x'); dae.eq(dae.der(x), -x);
>> dae.all()
time
x
der(x)
__assign__der(x)__
>> dae.all('x'), dae.all('w'), dae.all('calculated')
x
der(x)
__assign__der(x)__

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> ca.eq(dae, ca.der(dae, x), -x)
julia> ca.all(dae)
4-element Vector{String}:
 "time"
 "x"
 "der(x)"
 "__assign__der(x)__"
julia> ca.all(dae, "x"), ca.all(dae, "w"), ca.all(dae, "calculated")
(["x"], ["der(x)"], ["__assign__der(x)__"])

See also
has, x, w

Extra doc: https://github.com/casadi/casadi/wiki/L_2mf

Definition at line 263 of file dae_builder.cpp.

263  {
264  try {
265  return (*this)->all();
266  } catch (std::exception& e) {
267  THROW_ERROR("all", e.what());
268  return {}; // never reached
269  }
270 }

Referenced by set_all().

◆ all() [2/2]

std::vector< std::string > casadi::DaeBuilder::all ( const std::string &  cat) const

Names of the members of a category in category order; empty for an empty category, an unknown category name is an error. x(), z(), u() etc. are shorthands.

Extra doc: https://github.com/casadi/casadi/wiki/L_2mg

Definition at line 272 of file dae_builder.cpp.

272  {
273  try {
274  return (*this)->all(to_enum<Category>(cat));
275  } catch (std::exception& e) {
276  THROW_ERROR("all", e.what());
277  return {}; // never reached
278  }
279 }

◆ assign() [1/2]

std::string casadi::DaeBuilder::assign ( const std::string &  name,
const MX &  val 
)

Creates a helper variable holding the expression val assigned to the variable name when the event fires, and returns the helper's name for use in when. Intended for discrete-valued variables; reinit is the counterpart for continuous states.

Parameters
nameModel variable that receives the value
valExpression in model variables
Returns
Name of the created assignment variable, e.g. __assign__b__

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(start=0))
>>> b = dae.add("b", dict(type="Boolean", start=False))
>>> dae.eq(dae.der(x), 1)
>>> dae.assign("b", True)
'__assign__b__'
>>> dae.when(x > 1, [dae.assign("b", True)])
>>> dae.disp(True)
nt = 0, nx = 2, nz = 0, nq = 0, ny = 0, np = 0, nc = 0, nd = 0, nw = 1, nu = 0
Model variables:
  x = [x, b]
  w = [der(x)]
List of dependent variables (w):
  der(x) := 1
Time derivatives of differential states (x):
  x: der(x)
  b: 0
When equations:
  when (1-x) < 0 :
    b := 1

>> dae = DaeBuilder('m'); x = dae.add('x', struct('start', 0));
>> b = dae.add('b', struct('type', 'Boolean', 'start', false));
>> dae.eq(dae.der(x), 1);
>> dae.assign('b', true)
__assign__b__
>> dae.when(x > 1, {dae.assign('b', true)});
>> dae.disp(true)
nt = 0, nx = 2, nz = 0, nq = 0, ny = 0, np = 0, nc = 0, nd = 0, nw = 1, nu = 0
Model variables:
  x = [x, b]
  w = [der(x)]
List of dependent variables (w):
  der(x) := 1
Time derivatives of differential states (x):
  x: der(x)
  b: 0
When equations:
  when (1-x) < 0 :
    b := 1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("start" => 0));
julia> b = ca.add(dae, "b", Dict("type" => "Boolean", "start" => false));
julia> ca.eq(dae, ca.der(dae, x), 1)
julia> ca.assign(dae, "b", true)
"__assign__b__"
julia> ca.when(dae, x > 1, [ca.assign(dae, "b", true)])
julia> ca.disp(dae, true)
nt = 0, nx = 2, nz = 0, nq = 0, ny = 0, np = 0, nc = 0, nd = 0, nw = 1, nu = 0
Model variables:
  x = [x, b]
  w = [der(x)]
List of dependent variables (w):
  der(x) := 1
Time derivatives of differential states (x):
  x: der(x)
  b: 0
When equations:
  when (1-x) < 0 :
    b := 1

See also
when, reinit

Extra doc: https://github.com/casadi/casadi/wiki/L_2kv

Definition at line 401 of file dae_builder.cpp.

401  {
402  try {
403  return (*this)->assign(name, val).name;
404  } catch (std::exception& e) {
405  THROW_ERROR("assign", e.what());
406  return std::string(); // never reached
407  }
408 }

References name().

◆ assign() [2/2]

void casadi::GenericShared< SharedObject , SharedObjectInternal >::assign ( Internal *  node)
inherited

improper use will cause memory leaks!

Extra doc: https://github.com/casadi/casadi/wiki/L_at

Definition at line 96 of file generic_shared_impl.hpp.

86  {
87  node = node_;
88  }

◆ attribute() [1/2]

double casadi::DaeBuilder::attribute ( const std::string &  a,
const std::string &  name 
) const

Numerical attribute of a scalar variable, selected by name: "min", "max", "nominal", "start" or "value" (the current value, see get). Any other attribute name, or a non-scalar variable, is an error.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(start=1, min=-2, nominal=10))
>>> v = dae.add("v", dict(dimension=[2], start=[1, 2]))
>>> dae.attribute("start", "x"), dae.attribute("min", "x")
(1.0, -2.0)
>>> dae.attribute("start", ["x", "v"]), dae.attribute("nominal", ["x"])
([1.0, 1.0, 2.0], [10.0])
>>> dae.set_attribute("min", "x", -1)
>>> dae.set_attribute("start", ["x", "v"], [9, 8, 7])
>>> dae.min("x"), dae.start("v")
(-1.0, [8.0, 7.0])
>>> try:
...   dae.attribute("unit", "x")
... except Exception as e:
...   print("No such enum" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x', struct('start', 1, 'min', -2, 'nominal', 10));
>> v = dae.add('v', struct('dimension', 2, 'start', [1 2]));
>> dae.attribute('start', 'x'), dae.attribute('min', 'x')
1
-2
>> dae.attribute('start', {'x', 'v'}), dae.attribute('nominal', {'x'})
1 1 2
10
>> dae.set_attribute('min', 'x', -1); dae.set_attribute('start', {'x', 'v'}, [9 8 7]);
>> dae.min('x'), dae.start('v')
-1
8 7
>> try, dae.attribute('unit', 'x'); catch e, disp(contains(e.message, 'No such enum')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("start" => 1, "min" => -2, "nominal" => 10));
julia> v = ca.add(dae, "v", Dict("dimension" => [2], "start" => [1, 2]));
julia> ca.attribute(dae, "start", "x"), ca.attribute(dae, "min", "x")
(1.0, -2.0)
julia> ca.attribute(dae, "start", ["x", "v"]), ca.attribute(dae, "nominal", ["x"])
([1.0, 1.0, 2.0], [10.0])
julia> ca.set_attribute(dae, "min", "x", -1)
julia> ca.set_attribute(dae, "start", ["x", "v"], [9, 8, 7])
julia> dae.min("x"), ca.start(dae, "v")
(-1.0, [8.0, 7.0])
julia> try
           ca.attribute(dae, "unit", "x")
       catch e
           println(occursin("No such enum", sprint(showerror, e)))
       end
true

See also
min, max, nominal, start, get

Extra doc: https://github.com/casadi/casadi/wiki/L_2m6

Definition at line 930 of file dae_builder.cpp.

930  {
931  try {
932  return (*this)->attribute(to_enum<Attribute>(a), name);
933  } catch (std::exception& e) {
934  THROW_ERROR("attribute", e.what());
935  return 0; // never reached
936  }
937 }

References name().

◆ attribute() [2/2]

std::vector< double > casadi::DaeBuilder::attribute ( const std::string &  a,
const std::vector< std::string > &  name 
) const

Definition at line 939 of file dae_builder.cpp.

940  {
941  try {
942  return (*this)->attribute(to_enum<Attribute>(a), name);
943  } catch (std::exception& e) {
944  THROW_ERROR("attribute", e.what());
945  return {}; // never reached
946  }
947 }

References name().

◆ beq()

MX casadi::DaeBuilder::beq ( const std::string &  name) const

The right-hand side of the explicit equation defining the variable; a variable without binding equation is an error.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> w = dae.add("w")
>>> dae.eq(w, sin(x))
>>> dae.eq(dae.der(x), -w)
>>> dae.beq("w"), dae.beq("der(x)")
(MX(sin(x)), MX((-w)))

>> dae = DaeBuilder('m'); x = dae.add('x'); w = dae.add('w');
>> dae.eq(w, sin(x)); dae.eq(dae.der(x), -w);
>> dae.beq('w'), dae.beq('der(x)')
sin(x)
(-w)

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> w = ca.add(dae, "w");
julia> ca.eq(dae, w, sin(x))
julia> ca.beq(dae, "w")
MX(sin(x))

See also
has_beq, wdef

Extra doc: https://github.com/casadi/casadi/wiki/L_2lr

Definition at line 520 of file dae_builder.cpp.

520  {
521  try {
522  const Variable& v = (*this)->variable(name);
523  return (*this)->variable(v.bind).v;
524  } catch (std::exception& e) {
525  THROW_ERROR("beq", e.what());
526  return MX(); // never reached
527  }
528 }
struct VariableStruct Variable

References casadi::Variable::bind, name(), and casadi::Variable::v.

◆ c()

std::vector<std::string> casadi::DaeBuilder::c ( ) const
inline

Names of the variables of category c (fixed parameters and constants), in category order. Equivalent to all("c"). Constants are never function inputs: create substitutes their current value, see set.

See also
p, cdef, set, nc

Extra doc: https://github.com/casadi/casadi/wiki/L_5p

Definition at line 772 of file dae_builder.hpp.

772 {return all("c");}
std::vector< std::string > all() const
Get a list of all variables.

References casadi::all().

◆ categories()

std::vector< std::string > casadi::DaeBuilder::categories ( const std::string &  name) const

The categories set_category accepts for the variable given its current category and usage; an empty string stands for "no category". Controls, parameters and constants can be exchanged freely; states not used in any right-hand side can become quadrature states or lose their category.

>>> dae = DaeBuilder("m")
>>> u = dae.add("u", "input")
>>> x = dae.add("x")
>>> q = dae.add("q")
>>> dae.eq(dae.der(x), -x)
>>> dae.eq(dae.der(q), x**2)
>>> dae.categories("u"), dae.categories("x"), dae.categories("q")
(['p', 'u', 'c'], ['x'], ['x', 'q', ''])

>> dae = DaeBuilder('m'); u = dae.add('u', 'input'); x = dae.add('x'); q = dae.add('q');
>> dae.eq(dae.der(x), -x); dae.eq(dae.der(q), x^2);
>> dae.categories('u'), dae.categories('x')
p
u
c
x
>> strjoin(cellstr(dae.categories('q')), ',')
x,q,

julia> dae = ca.DaeBuilder("m");
julia> u = ca.add(dae, "u", "input");
julia> x = ca.add(dae, "x");
julia> q = ca.add(dae, "q");
julia> ca.eq(dae, ca.der(dae, x), -x)
julia> ca.eq(dae, ca.der(dae, q), x^2)
julia> ca.categories(dae, "u"), ca.categories(dae, "x"), ca.categories(dae, "q")
(["p", "u", "c"], ["x"], ["x", "q", ""])

See also
category, set_category

Extra doc: https://github.com/casadi/casadi/wiki/L_2lw

Definition at line 599 of file dae_builder.cpp.

599  {
600  try {
601  std::vector<std::string> ret;
602  for (auto&& cat : (*this)->variable(name).categories()) {
603  ret.push_back(to_string(cat));
604  }
605  return ret;
606  } catch (std::exception& e) {
607  THROW_ERROR("categories", e.what());
608  return {}; // never reached
609  }
610 }
std::string to_string(TypeFmi2 v)

References name(), and casadi::to_string().

◆ category()

std::string casadi::DaeBuilder::category ( const std::string &  name) const

One of "t", "c", "p", "d", "w", "u", "x", "z", "q", "calculated" (internal helper variables), or an empty string for no category.

See also
categories, set_category, causality, variability

Extra doc: https://github.com/casadi/casadi/wiki/L_2ly

Definition at line 637 of file dae_builder.cpp.

637  {
638  try {
639  return to_string((*this)->category((*this)->find(name)));
640  } catch (std::exception& e) {
641  THROW_ERROR("category", e.what());
642  return std::string(); // never reached
643  }
644 }

References name(), and casadi::to_string().

◆ causality()

std::string casadi::DaeBuilder::causality ( const std::string &  name) const

One of "parameter", "calculatedParameter", "input", "output", "local", "independent".

>>> dae = DaeBuilder("m")
>>> t = dae.add("t", "independent")
>>> u = dae.add("u", "input")
>>> x = dae.add("x")
>>> dae.causality("t"), dae.causality("u"), dae.causality("x")
('independent', 'input', 'local')

>> dae = DaeBuilder('m'); t = dae.add('t', 'independent'); u = dae.add('u', 'input');
>> x = dae.add('x');
>> dae.causality('t'), dae.causality('u'), dae.causality('x')
independent
input
local

julia> dae = ca.DaeBuilder("m");
julia> t = ca.add(dae, "t", "independent");
julia> u = ca.add(dae, "u", "input");
julia> x = ca.add(dae, "x");
julia> ca.causality(dae, "t"), ca.causality(dae, "u"), ca.causality(dae, "x")
("independent", "input", "local")

See also
set_causality, variability, category

Extra doc: https://github.com/casadi/casadi/wiki/L_2lv

Definition at line 590 of file dae_builder.cpp.

590  {
591  try {
592  return to_string((*this)->causality((*this)->find(name)));
593  } catch (std::exception& e) {
594  THROW_ERROR("causality", e.what());
595  return std::string(); // never reached
596  }
597 }

References name(), and casadi::to_string().

Referenced by add().

◆ cdef()

std::vector< MX > casadi::DaeBuilder::cdef ( ) const

The binding expressions of the constants c, one per entry of c(). Only constants that have a binding equation (imported from a symbolic model description) are supported; a constant without one raises an error.

See also
c, ddef, wdef

Extra doc: https://github.com/casadi/casadi/wiki/L_5q

Definition at line 91 of file dae_builder.cpp.

91  {
92  try {
93  return (*this)->cdef();
94  } catch (std::exception& e) {
95  THROW_ERROR("cdef", e.what());
96  return {}; // never reached
97  }
98 }

◆ class_name()

std::string casadi::SharedObject::class_name ( ) const
inherited

◆ compile_fmu()

Dict casadi::DaeBuilder::compile_fmu ( const Dict &  files,
const Dict &  opts = Dict() 
)

Compiles all .c entries of files (through one amalgamation translation unit) into a shared library <name>.<ext> in the current directory using an Importer plugin, and returns the map extended with the binary at its FMI 3 archive location binaries/<platform>/. The FMI 3 headers must be on the include path.

Parameters
filesthe {local_file -> archive path} map returned by export_fmu
optscompile options: "compiler" (Importer plugin, default "shell"), "compiler_options" (options for that plugin), "include_dirs" (list of directories)
Returns
the file map augmented with the amalgamation source and compiled binary
See also
export_fmu, pack_fmu

Extra doc: https://github.com/casadi/casadi/wiki/L_2iq

Definition at line 220 of file dae_builder.cpp.

220  {
221  try {
222  return (*this)->compile_fmu(files, opts);
223  } catch (std::exception& e) {
224  THROW_ERROR("compile_fmu", e.what());
225  return Dict(); // never reached
226  }
227 }
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.

◆ count_down()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_down
protectedinherited

Definition at line 133 of file generic_shared_impl.hpp.

46  {
47 #ifdef WITH_EXTRA_CHECKS
48  casadi_assert_dev(Function::call_depth_==0);
49 #endif // WITH_EXTRA_CHECKS
50  if (!node) return;
51 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
52  GenericWeakRef<Shared, Internal>* weak_ref =
53  node->weak_ref_.load(std::memory_order_acquire);
54 #else
55  GenericWeakRef<Shared, Internal>* weak_ref = node->weak_ref_;
56 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
57  if (weak_ref) {
58 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
59  // get_mutex() returns a shared_ptr copy, so the mutex outlives this lock
60  // even if delete node (below) destroys the WeakRefInternal holding it
61  auto mutex = weak_ref->get_mutex();
62  // Avoid triggering a delete while a weak_ref.shared_if_alive is being called
63  std::lock_guard<std::mutex> lock(*mutex);
64 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
65 
66  if (--static_cast<Internal*>(node)->count == 0) {
67  delete node;
68  node = nullptr;
69  }
70  } else {
71  if (--static_cast<Internal*>(node)->count == 0) {
72  delete node;
73  node = nullptr;
74  }
75  }
76  }

◆ count_up()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_up
protectedinherited

Definition at line 132 of file generic_shared_impl.hpp.

36  {
37 #ifdef WITH_EXTRA_CHECKS
38  casadi_assert_dev(Function::call_depth_==0);
39 #endif // WITH_EXTRA_CHECKS
40 
41  if (node) static_cast<Internal*>(node)->count++;
42 
43  }

◆ create() [1/4]

Function casadi::DaeBuilder::create ( ) const
inline

The function is named <name>_dae.

Extra doc: https://github.com/casadi/casadi/wiki/L_2c1

Definition at line 2787 of file dae_builder.hpp.

2787 {return create(name() + "_dae");}
Function create() const
Create a function with standard integrator DAE signature, default naming.

References create().

Referenced by create(), and get().

◆ create() [2/4]

Function casadi::DaeBuilder::create ( const std::string &  fname,
const Dict &  opts = Dict() 
) const

Shorthand for create(fname, ["t", "x", "z", "p", "u"], ["ode", "alg", "quad", "zero"], opts): a function that can be passed directly to integrator. Empty categories give empty inputs or outputs.

Parameters
nameName assigned to the resulting function object
optsOptional settings

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> u = dae.add("u", "input")
>>> dae.eq(dae.der(x), -x + u)
>>> f = dae.create("mydae")
>>> f
Function(mydae:(t[0],x,z[0],p[0],u)->(ode,alg[0],quad[0],zero[0]) MXFunction)
>>> f(0, 1, [], [], 3)
(DM(2), DM(0x1), DM(0x1), DM(0x1))

>> dae = DaeBuilder('m'); x = dae.add('x'); u = dae.add('u', 'input');
>> dae.eq(dae.der(x), -x + u);
>> f = dae.create('mydae'); disp(f)
mydae:(t[0],x,z[0],p[0],u)->(ode,alg[0],quad[0],zero[0]) MXFunction
>> [ode, alg, quad, zero] = f(0, 1, [], [], 3); disp(ode), disp(alg), disp(quad), disp(zero)
2
0x1
0x1
0x1
>> res = f('t', 0, 'x', 1, 'u', 3); disp(res.ode)
2

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> u = ca.add(dae, "u", "input");
julia> ca.eq(dae, ca.der(dae, x), -x + u)
julia> f = ca.create(dae, "mydae")
Function(mydae:(t[0],x,z[0],p[0],u)->(ode,alg[0],quad[0],zero[0]) MXFunction)
julia> f(0, 1, [], [], 3)
(2, 0x1, 0x1, 0x1)
julia> f(t=0, x=1, u=3)["ode"]
DM(2)

See also
transition

Extra doc: https://github.com/casadi/casadi/wiki/L_2c0

Definition at line 786 of file dae_builder.cpp.

786  {
787  try {
788  return (*this)->create(name, dyn_in(), dyn_out(), opts, false, false);
789  } catch (std::exception& e) {
790  THROW_ERROR("create", e.what());
791  return Function(); // never reached
792  }
793 }
std::vector< std::string > dyn_out()
Get the output scheme of a DAE function.
Definition: integrator.cpp:236
std::vector< std::string > dyn_in()
Get the input scheme of a DAE function.
Definition: integrator.cpp:232

References casadi::dyn_in(), casadi::dyn_out(), and name().

◆ create() [3/4]

Function casadi::DaeBuilder::create ( const std::string &  fname,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out,
bool  sx,
bool  lifted_calls = false 
) const

Same as the overload with options, but with the flags sx (expand to an SX function) and lifted_calls (account for function calls lifted into w, see lift) instead; neither is available for an imported FMU.

Extra doc: https://github.com/casadi/casadi/wiki/L_2lg

Definition at line 764 of file dae_builder.cpp.

766  {
767  try {
768  return (*this)->create(fname, name_in, name_out, Dict(), sx, lifted_calls);
769  } catch (std::exception& e) {
770  THROW_ERROR("create", e.what());
771  return Function(); // never reached
772  }
773 }

◆ create() [4/4]

Function casadi::DaeBuilder::create ( const std::string &  name,
const std::vector< std::string > &  name_in,
const std::vector< std::string > &  name_out,
const Dict &  opts = Dict() 
) const

The function factory: builds a Function whose inputs are variable categories and whose outputs are equation categories or derivatives of them. Inputs are any of t, p, d, u, x, z, q, w; constants c are never inputs, their current values (see set) are substituted. Outputs are ode, alg, quad, zero, ddef, wdef, y. Dependent variables w and parameters d not given as inputs are substituted out. Derivative outputs use the Function factory naming with underscores: jac_ode_x (Jacobian block) or hess_<lc>_x_x for a linear combination declared with add_lc, with the multipliers lam_ode, lam_alg, ... as inputs. The created function is a snapshot: later changes to the instance do not affect it. For an imported FMU the function evaluates the FMU binary.

Parameters
nameName assigned to the resulting function object
name_inNames of all the inputs
name_outNames of all the outputs
optsOptional settings: Function options for a symbolic model; for an FMU also "aux" (names of variables reported in stats() after evaluation), "enable_ad", "parallelization" and the other FmuFunction options

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> z = dae.add("z")
>>> u = dae.add("u", "input")
>>> p = dae.add("p", "parameter", "tunable")
>>> c = dae.add("c", "parameter", "fixed", dict(start=3))
>>> w = dae.add("w")
>>> y = dae.add("y", "output")
>>> dae.eq(dae.der(x), -c*x + z*u)
>>> dae.eq(0, x - p*z**2)
>>> dae.eq(w, x + z)
>>> dae.eq(y, w**2)
>>> f = dae.create("f", ["x", "z", "u", "p"], ["ode", "alg", "y"])
>>> f
Function(f:(x,z,u,p)->(ode,alg,y) MXFunction)
>>> f(1, 2, 3, 4)
(DM(3), DM(15), DM(9))
>>> J = dae.create("J", ["x", "z", "u", "p"], ["jac_ode_x", "jac_alg_z"])
>>> J(1, 2, 3, 4)
(DM(-3), DM(16))
>>> dae.create("g", ["x", "z", "w"], ["ode", "wdef"])
Function(g:(x,z,w[3])->(ode,wdef[3]) MXFunction)
>>> dae.create("s", ["x", "z", "u", "p"], ["ode"], True)
Function(s:(x,z,u,p)->(ode) SXFunction)
>>> try:
...   dae.create("f", ["x", "z", "c"], ["ode"])
... except Exception as e:
...   print('Cannot process "c" as input' in str(e))
True
>>> try:
...   dae.create("f", ["x", "z"], ["w"])
... except Exception as e:
...   print('Cannot process "w" as output' in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); z = dae.add('z'); u = dae.add('u', 'input');
>> p = dae.add('p', 'parameter', 'tunable');
>> c = dae.add('c', 'parameter', 'fixed', struct('start', 3));
>> w = dae.add('w'); y = dae.add('y', 'output');
>> dae.eq(dae.der(x), -c*x + z*u); dae.eq(0, x - p*z^2);
>> dae.eq(w, x + z); dae.eq(y, w^2);
>> f = dae.create('f', {'x', 'z', 'u', 'p'}, {'ode', 'alg', 'y'}); disp(f)
f:(x,z,u,p)->(ode,alg,y) MXFunction
>> [ode, alg, yval] = f(1, 2, 3, 4); disp(ode), disp(alg), disp(yval)
3
15
9
>> J = dae.create('J', {'x', 'z', 'u', 'p'}, {'jac_ode_x', 'jac_alg_z'});
>> [J_ode_x, J_alg_z] = J(1, 2, 3, 4); disp(J_ode_x), disp(J_alg_z)
-3
16
>> dae.create('g', {'x', 'z', 'w'}, {'ode', 'wdef'})
g:(x,z,w[3])->(ode,wdef[3]) MXFunction
>> dae.create('s', {'x', 'z', 'u', 'p'}, {'ode'}, true)
s:(x,z,u,p)->(ode) SXFunction
>> try, dae.create('f', {'x', 'z', 'c'}, {'ode'}); catch e, msg = e.message; end
>> contains(msg, 'Cannot process "c" as input')
1
>> try, dae.create('f', {'x', 'z'}, {'w'}); catch e, msg = e.message; end
>> contains(msg, 'Cannot process "w" as output')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> z = ca.add(dae, "z");
julia> u = ca.add(dae, "u", "input");
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> c = ca.add(dae, "c", "parameter", "fixed", Dict("start" => 3));
julia> w = ca.add(dae, "w");
julia> y = ca.add(dae, "y", "output");
julia> ca.eq(dae, ca.der(dae, x), -c*x + z*u)
julia> ca.eq(dae, 0, x - p*z^2)
julia> ca.eq(dae, w, x + z)
julia> ca.eq(dae, y, w^2)
julia> f = ca.create(dae, "f", ["x", "z", "u", "p"], ["ode", "alg", "y"])
Function(f:(x,z,u,p)->(ode,alg,y) MXFunction)
julia> f(1, 2, 3, 4)
(3, 15, 9)
julia> J = ca.create(dae, "J", ["x", "z", "u", "p"], ["jac_ode_x", "jac_alg_z"]);
julia> J(1, 2, 3, 4)
(-3, 16)
julia> ca.create(dae, "g", ["x", "z", "w"], ["ode", "wdef"])
Function(g:(x,z,w[3])->(ode,wdef[3]) MXFunction)
julia> ca.create(dae, "s", ["x", "z", "u", "p"], ["ode"], true)
Function(s:(x,z,u,p)->(ode) SXFunction)
julia> try
           ca.create(dae, "f", ["x", "z", "c"], ["ode"])
       catch e
           println(occursin("Cannot process \"c\" as input", sprint(showerror, e)))
       end
true
julia> try
           ca.create(dae, "f", ["x", "z"], ["w"])
       catch e
           println(occursin("Cannot process \"w\" as output", sprint(showerror, e)))
       end
true

See also
oracle, add_lc, dependent_fun, transition

Extra doc: https://github.com/casadi/casadi/wiki/L_6e

Definition at line 775 of file dae_builder.cpp.

777  {
778  try {
779  return (*this)->create(fname, name_in, name_out, opts, false, false);
780  } catch (std::exception& e) {
781  THROW_ERROR("create", e.what());
782  return Function(); // never reached
783  }
784 }

◆ d()

std::vector<std::string> casadi::DaeBuilder::d ( ) const
inline

Names of the variables of category d (causality "calculatedParameter", or "local" with "fixed"/"tunable" variability), in category order. Equivalent to all("d"). They are defined by binding equations and are calculated by dependent_fun.

See also
ddef, dependent_fun, nd

Extra doc: https://github.com/casadi/casadi/wiki/L_5r

Definition at line 795 of file dae_builder.hpp.

795 {return all("d");}

References casadi::all().

◆ ddef()

std::vector< MX > casadi::DaeBuilder::ddef ( ) const

The binding expressions of the dependent parameters, one per entry of d(). Interdependencies are allowed but must be non-cyclic (see sort). Equivalent to outputs("ddef"). A dependent parameter without a binding equation raises an error.

See also
d, wdef, sort, eliminate

Extra doc: https://github.com/casadi/casadi/wiki/L_5s

Definition at line 100 of file dae_builder.cpp.

100  {
101  try {
102  return (*this)->outputs(Category::DDEF);
103  } catch (std::exception& e) {
104  THROW_ERROR("ddef", e.what());
105  return {}; // never reached
106  }
107 }

References casadi::DDEF.

◆ debug_repr()

std::string casadi::GenericShared< SharedObject , SharedObjectInternal >::debug_repr
inherited

Definition at line 112 of file generic_shared_impl.hpp.

91  {
92  if (node) {
93  return node->debug_repr(node);
94  } else {
95  return "NULL";
96  }
97  }
std::string debug_repr(const Internal *) const

◆ dependent_fun()

Function casadi::DaeBuilder::dependent_fun ( const std::string &  fname,
const std::vector< std::string > &  s_in,
const std::vector< std::string > &  s_out 
) const

Builds a Function that calculates the dependent parameters d and/or dependent variables w from their binding equations, substituting the interdependencies out, with the given categories as inputs.

Parameters
fnameFunction name
s_inInput categories; a category that is also an output is an error, and every variable the definitions depend on must be covered
s_out"d", "w" or both; anything else is an error
Returns
Function with one (concatenated) output per entry of s_out

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> w1 = dae.add("w1")
>>> w2 = dae.add("w2")
>>> p = dae.add("p", "parameter", "tunable")
>>> dae.eq(w1, 2*x)
>>> dae.eq(w2, w1**2 + p)
>>> dae.eq(dae.der(x), -w2)
>>> f = dae.dependent_fun("f", ["x", "p"], ["w"])
>>> f
Function(f:(x,p)->(w[3]) MXFunction)
>>> f(1, 3)
DM([2, 7, -7])
>>> try:
...   dae.dependent_fun("f", ["x", "w"], ["w"])
... except Exception as e:
...   print("cannot be both input and output" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); w1 = dae.add('w1'); w2 = dae.add('w2');
>> p = dae.add('p', 'parameter', 'tunable');
>> dae.eq(w1, 2*x); dae.eq(w2, w1^2 + p); dae.eq(dae.der(x), -w2);
>> f = dae.dependent_fun('f', {'x', 'p'}, {'w'}); disp(f)
f:(x,p)->(w[3]) MXFunction
>> f(1, 3)
[2, 7, -7]
>> try, dae.dependent_fun('f', {'x', 'w'}, {'w'}); catch e, msg = e.message; end
>> contains(msg, 'cannot be both input and output')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> w1 = ca.add(dae, "w1");
julia> w2 = ca.add(dae, "w2");
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> ca.eq(dae, w1, 2*x)
julia> ca.eq(dae, w2, w1^2 + p)
julia> ca.eq(dae, ca.der(dae, x), -w2)
julia> f = ca.dependent_fun(dae, "f", ["x", "p"], ["w"])
Function(f:(x,p)->(w[3]) MXFunction)
julia> f(1, 3)
DM([2, 7, -7])
julia> try
           ca.dependent_fun(dae, "f", ["x", "w"], ["w"])
       catch e
           println(occursin("cannot be both input and output", sprint(showerror, e)))
       end
true

See also
w, d, create, eliminate

Extra doc: https://github.com/casadi/casadi/wiki/L_2lh

Definition at line 871 of file dae_builder.cpp.

873  {
874  try {
875  return (*this)->dependent_fun(fname, s_in, s_out);
876  } catch (std::exception& e) {
877  THROW_ERROR("dependent_fun", e.what());
878  return Function(); // never reached
879  }
880 }

◆ der() [1/5]

std::vector< std::string > casadi::DaeBuilder::der ( ) const

Names of all derivative variables, in creation order: the der(x) variables created by der for a symbolic model, or the variables marked as derivatives in an imported model structure.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> dae.der()
[]
>>> dae.eq(dae.der(x), -y)
>>> dae.eq(dae.der(y), x)
>>> dae.der()
['der(x)', 'der(y)']

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> isempty(dae.der())
1
>> dae.eq(dae.der(x), -y); dae.eq(dae.der(y), x);
>> dae.der()
der(x)
der(y)

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> ca.der(dae)
String[]
julia> ca.eq(dae, ca.der(dae, x), -y)
julia> ca.eq(dae, ca.der(dae, y), x)
julia> ca.der(dae)
2-element Vector{String}:
 "der(x)"
 "der(y)"

Extra doc: https://github.com/casadi/casadi/wiki/L_2fz

Definition at line 126 of file dae_builder.cpp.

126  {
127  try {
128  return (*this)->name((*this)->der_);
129  } catch (std::exception& e) {
130  THROW_ERROR("der", e.what());
131  return {}; // never reached
132  }
133 }

Referenced by der().

◆ der() [2/5]

MX casadi::DaeBuilder::der ( const MX &  v)

For a model variable x the derivative variable der(x) is returned, created on first use (as an algebraic variable until eq gives it a defining equation). For a concatenation of variables the derivatives are concatenated; for a general expression the chain rule is applied through the derivatives of the variables it depends on. The derivative of the independent variable is 1 and that of parameters, constants, inputs and discrete variables is 0. The expression must be a column vector in model variables.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> p = dae.add("p", "parameter", "tunable")
>>> dae.der(x)
MX(der(x))
>>> dae.der(vertcat(x, y))
MX(vertcat(der(x), der(y)))
>>> dae.der(x*y + p)
MX(((y*der(x))+(x*der(y))))
>>> dae.der(p)
MX(0)
>>> dae.z()
['x', 'y', 'der(x)', 'der(y)']
>>> try:
...   dae.der(vertcat(x, y).T)
... except Exception as e:
...   print("must be a vector" in str(e))
True
>>> try:
...   dae.der(MX.sym("foo"))
... except Exception as e:
...   print("No such variable" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> p = dae.add('p', 'parameter', 'tunable');
>> dae.der(x)
der(x)
>> dae.der([x; y])
vertcat(der(x), der(y))
>> dae.der(x*y + p)
((y*der(x))+(x*der(y)))
>> dae.der(p)
0
>> dae.z()
x
y
der(x)
der(y)
>> try, dae.der([x; y]'); catch e, disp(contains(e.message, 'must be a vector')); end
1
>> try, dae.der(MX.sym('foo')); catch e, disp(contains(e.message, 'No such variable')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> ca.der(dae, x)
MX(der(x))
julia> ca.der(dae, [x; y])
MX(vertcat(der(x), der(y)))
julia> ca.der(dae, x*y + p)
MX(((y*der(x))+(x*der(y))))
julia> ca.der(dae, p)
MX(0)
julia> ca.z(dae)
4-element Vector{String}:
 "x"
 "y"
 "der(x)"
 "der(y)"
julia> try
           ca.der(dae, [x; y]')
       catch e
           println(occursin("must be a vector", sprint(showerror, e)))
       end
true
julia> try
           ca.der(dae, ca.MX.sym("foo"))
       catch e
           println(occursin("No such variable", sprint(showerror, e)))
       end
true

See also
eq, der, var

Extra doc: https://github.com/casadi/casadi/wiki/L_2ln

Definition at line 921 of file dae_builder.cpp.

921  {
922  try {
923  return (*this)->der(v);
924  } catch (std::exception& e) {
925  THROW_ERROR("der", e.what());
926  return MX(); // never reached
927  }
928 }

◆ der() [3/5]

MX casadi::DaeBuilder::der ( const MX &  v) const

For a model variable x the derivative variable der(x) is returned, created on first use (as an algebraic variable until eq gives it a defining equation). For a concatenation of variables the derivatives are concatenated; for a general expression the chain rule is applied through the derivatives of the variables it depends on. The derivative of the independent variable is 1 and that of parameters, constants, inputs and discrete variables is 0. The expression must be a column vector in model variables.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> p = dae.add("p", "parameter", "tunable")
>>> dae.der(x)
MX(der(x))
>>> dae.der(vertcat(x, y))
MX(vertcat(der(x), der(y)))
>>> dae.der(x*y + p)
MX(((y*der(x))+(x*der(y))))
>>> dae.der(p)
MX(0)
>>> dae.z()
['x', 'y', 'der(x)', 'der(y)']
>>> try:
...   dae.der(vertcat(x, y).T)
... except Exception as e:
...   print("must be a vector" in str(e))
True
>>> try:
...   dae.der(MX.sym("foo"))
... except Exception as e:
...   print("No such variable" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> p = dae.add('p', 'parameter', 'tunable');
>> dae.der(x)
der(x)
>> dae.der([x; y])
vertcat(der(x), der(y))
>> dae.der(x*y + p)
((y*der(x))+(x*der(y)))
>> dae.der(p)
0
>> dae.z()
x
y
der(x)
der(y)
>> try, dae.der([x; y]'); catch e, disp(contains(e.message, 'must be a vector')); end
1
>> try, dae.der(MX.sym('foo')); catch e, disp(contains(e.message, 'No such variable')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> ca.der(dae, x)
MX(der(x))
julia> ca.der(dae, [x; y])
MX(vertcat(der(x), der(y)))
julia> ca.der(dae, x*y + p)
MX(((y*der(x))+(x*der(y))))
julia> ca.der(dae, p)
MX(0)
julia> ca.z(dae)
4-element Vector{String}:
 "x"
 "y"
 "der(x)"
 "der(y)"
julia> try
           ca.der(dae, [x; y]')
       catch e
           println(occursin("must be a vector", sprint(showerror, e)))
       end
true
julia> try
           ca.der(dae, ca.MX.sym("foo"))
       catch e
           println(occursin("No such variable", sprint(showerror, e)))
       end
true

See also
eq, der, var

Extra doc: https://github.com/casadi/casadi/wiki/L_2ln

Definition at line 912 of file dae_builder.cpp.

912  {
913  try {
914  return (*this)->der(v);
915  } catch (std::exception& e) {
916  THROW_ERROR("der", e.what());
917  return MX(); // never reached
918  }
919 }

◆ der() [4/5]

std::string casadi::DaeBuilder::der ( const std::string &  name) const

The name of the derivative variable of a single variable, e.g. der(x) for x.

Extra doc: https://github.com/casadi/casadi/wiki/L_2m5

Definition at line 444 of file dae_builder.cpp.

444  {
445  try {
446  // Get variable index
447  size_t ind = (*this)->find(name);
448  // Differentiate
449  ind = (*this)->variable(ind).der;
450  casadi_assert(ind != size_t(-1), "No derivative expression for " + name);
451  // Return name
452  return (*this)->variable(ind).name;
453  } catch (std::exception& e) {
454  THROW_ERROR("der", e.what());
455  return std::string(); // never reached
456  }
457 }

References name().

◆ der() [5/5]

std::vector< std::string > casadi::DaeBuilder::der ( const std::vector< std::string > &  name) const

The names of the derivative variables of the given variables; a variable without a derivative variable is an error.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> p = dae.add("p", "parameter", "tunable")
>>> dae.eq(dae.der(x), -y)
>>> dae.eq(dae.der(y), x)
>>> dae.der("x"), dae.der(["x", "y"])
('der(x)', ['der(x)', 'der(y)'])
>>> try:
...   dae.der("p")
... except Exception as e:
...   print("No derivative expression" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> p = dae.add('p', 'parameter', 'tunable');
>> dae.eq(dae.der(x), -y); dae.eq(dae.der(y), x);
>> dae.der('x'), dae.der({'x', 'y'})
der(x)
der(x)
der(y)
>> try, dae.der('p'); catch e, disp(contains(e.message, 'No derivative expression')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> ca.eq(dae, ca.der(dae, x), -y)
julia> ca.eq(dae, ca.der(dae, y), x)
julia> ca.der(dae, "x"), ca.der(dae, ["x", "y"])
("der(x)", ["der(x)", "der(y)"])
julia> try
           ca.der(dae, "p")
       catch e
           println(occursin("No derivative expression", sprint(showerror, e)))
       end
true

Extra doc: https://github.com/casadi/casadi/wiki/L_2lm

Definition at line 489 of file dae_builder.cpp.

489  {
490  try {
491  std::vector<std::string> r(name.size());
492  for (size_t i = 0; i < r.size(); ++i) r[i] = der(name[i]);
493  return r;
494  } catch (std::exception& e) {
495  THROW_ERROR("der", e.what());
496  return {}; // never reached
497  }
498 }
std::vector< std::string > der() const
Model structure: All time derivatives.

References der(), and name().

◆ derivatives()

std::vector<std::string> casadi::DaeBuilder::derivatives ( ) const
inline

Definition at line 933 of file dae_builder.hpp.

933 {return der();}

◆ description()

std::string casadi::DaeBuilder::description ( const std::string &  name) const

Free-text description of a variable, also settable with the "description" option of add.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(description="position"))
>>> dae.description("x")
'position'
>>> dae.set_description("x", "height")
>>> dae.description("x")
'height'

>> dae = DaeBuilder('m'); x = dae.add('x', struct('description', 'position'));
>> dae.description('x')
position
>> dae.set_description('x', 'height');
>> dae.description('x')
height

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("description" => "position"));
julia> ca.description(dae, "x")
"position"
julia> ca.set_description(dae, "x", "height")
julia> ca.description(dae, "x")
"height"

Extra doc: https://github.com/casadi/casadi/wiki/L_2lt

Definition at line 562 of file dae_builder.cpp.

562  {
563  return (*this)->variable(name).description;
564 }

References name().

◆ dimension()

std::vector< casadi_int > casadi::DaeBuilder::dimension ( const std::string &  name) const

The "dimension" list given to add (default [1]). The expression is always flattened to a column vector.

See also
numel

Extra doc: https://github.com/casadi/casadi/wiki/L_2m3

Definition at line 683 of file dae_builder.cpp.

683  {
684  return (*this)->variable(name).dimension;
685 }

References name().

◆ disp()

void casadi::SharedObject::disp ( std::ostream &  stream,
bool  more = false 
) const
inherited

Definition at line 35 of file shared_object.cpp.

35  {
36  if (is_null()) {
37  stream << "NULL";
38  } else {
39  (*this)->disp(stream, more);
40  }
41  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

Referenced by casadi::WeakRefInternal::disp(), casadi::Nlpsol::disp_more(), and casadi::CsparseInterface::nfact().

◆ display_unit()

std::string casadi::DaeBuilder::display_unit ( const std::string &  name) const

Display unit string of a variable; empty by default. Also settable with the "display_unit" option of add.

Extra doc: https://github.com/casadi/casadi/wiki/L_2m1

Definition at line 671 of file dae_builder.cpp.

671  {
672  return (*this)->variable(name).display_unit;
673 }

References name().

◆ eliminate()

void casadi::DaeBuilder::eliminate ( const std::string &  cat)

Substitutes the variables of an acyclic category out of all model expressions: "c", "d" or "w" (sorted first with sort). The variables keep existing but become calculated and the category is left empty. For "q" the quadrature states are turned into regular states x instead. Any other category is an error.

Parameters
cat"c", "d", "w" or "q"

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> w1 = dae.add("w1")
>>> w2 = dae.add("w2")
>>> dae.eq(w2, w1**2)
>>> dae.eq(w1, 2*x)
>>> dae.eq(dae.der(x), -w2)
>>> dae.eliminate("w")
>>> dae.w(), dae.outputs("ode"), dae.category("w1")
([], [MX((-sq((2.*x))))], 'calculated')
>>> try:
...   dae.eliminate("x")
... except Exception as e:
...   print("Elimination not supported" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); w1 = dae.add('w1'); w2 = dae.add('w2');
>> dae.eq(w2, w1^2); dae.eq(w1, 2*x); dae.eq(dae.der(x), -w2);
>> dae.eliminate('w');
>> disp(isempty(dae.w())), cellfun(@disp, dae.outputs('ode')), disp(dae.category('w1'))
1
(-sq((2.*x)))
calculated
>> try, dae.eliminate('x'); catch e, msg = e.message; end
>> contains(msg, 'Elimination not supported')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> w1 = ca.add(dae, "w1");
julia> w2 = ca.add(dae, "w2");
julia> ca.eq(dae, w2, w1^2)
julia> ca.eq(dae, w1, 2*x)
julia> ca.eq(dae, ca.der(dae, x), -w2)
julia> ca.eliminate(dae, "w")
julia> ca.w(dae), ca.outputs(dae, "ode"), ca.category(dae, "w1")
(String[], MX[(-sq((2.*x)))], "calculated")
julia> try
           ca.eliminate(dae, "x")
       catch e
           println(occursin("Elimination not supported", sprint(showerror, e)))
       end
true

See also
sort, dependent_fun, lift

Extra doc: https://github.com/casadi/casadi/wiki/L_2l1

Definition at line 530 of file dae_builder.cpp.

530  {
531  try {
532  (*this)->eliminate(to_enum<Category>(cat));
533  } catch (std::exception& e) {
534  THROW_ERROR("eliminate", e.what());
535  }
536 }

◆ eq()

void casadi::DaeBuilder::eq ( const MX &  lhs,
const MX &  rhs,
const Dict &  opts = Dict() 
)

Adds the equation lhs == rhs and reclassifies variables accordingly:

  • lhs is the derivative of a state (der(x)): the equation becomes the ODE of x, which moves from z to x; der(x) becomes a dependent variable w
  • lhs is a variable of category z: the equation is its binding equation and the variable moves to w; it must not have a binding equation already
  • lhs is a concatenation of such variables: split into one equation per component
  • lhs is anything else, typically 0: an implicit (algebraic) equation 0 == lhs - rhs is added to outputs("alg"); a second equation for a variable that already has a binding equation is treated this way too

A derivative der(x) that appears in rhs before it was defined is replaced by a new algebraic variable der_x with the trivial ODE der(x) == der_x, keeping the DAE semi-explicit. Scalar sides are broadcast to the length of the other side; sparse sides are densified. Variables appearing in rhs are marked as used, so a quadrature state q referenced there becomes a regular state x.

Parameters
lhsColumn vector expression; a parameter, constant or state as left-hand side is an error
rhsColumn vector expression in model variables only; dimensions must match after broadcasting
optsMust be empty

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> z = dae.add("z")
>>> w = dae.add("w")
>>> dae.x(), dae.z(), dae.w()
([], ['x', 'y', 'z', 'w'], [])
>>> dae.eq(dae.der(x), -x + z)
>>> dae.x(), dae.z(), dae.w()
(['x'], ['y', 'z', 'w'], ['der(x)'])
>>> dae.eq(0, x - 2*z)
>>> dae.z(), dae.outputs("alg")
(['y', 'z', 'w'], [MX((-(x-(2.*z))))])
>>> dae.eq(w, x*z)
>>> dae.w(), dae.wdef()
(['der(x)', 'w'], [MX((z-x)), MX((x*z))])
>>> dae.eq(vertcat(dae.der(y), w), vertcat(w, 1))
>>> dae.x(), dae.outputs("ode"), dae.outputs("alg")
(['x', 'y'], [MX((z-x)), MX(w)], [MX((-(x-(2.*z)))), MX((-(w-1)))])
>>> try:
...   dae.eq(x, 1)
... except Exception as e:
...   print("Cannot handle left-hand-side" in str(e))
True
>>> try:
...   dae.eq(vertcat(dae.der(x), dae.der(y)), vertcat(1, 2, 3))
... except Exception as e:
...   print("Mismatched dimensions" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> z = dae.add('z'); w = dae.add('w');
>> isempty(dae.x()), dae.z(), isempty(dae.w())
1
x
y
z
w
1
>> dae.eq(dae.der(x), -x + z);
>> dae.x(), dae.z(), dae.w()
x
y
z
w
der(x)
>> dae.eq(0, x - 2*z);
>> disp(dae.z()), cellfun(@disp, dae.outputs('alg'))
y
z
w
(-(x-(2.*z)))
>> dae.eq(w, x*z);
>> disp(dae.w()), cellfun(@disp, dae.wdef())
der(x)
w
(z-x)
(x*z)
>> dae.eq([dae.der(y); w], [w; 1]);
>> disp(dae.x()), cellfun(@disp, dae.outputs('ode')), cellfun(@disp, dae.outputs('alg'))
x
y
(z-x)
w
(-(x-(2.*z)))
(-(w-1))
>> try, dae.eq(x, 1); catch e, disp(contains(e.message, 'Cannot handle left-hand-side')); end
1
>> try, dae.eq([dae.der(x); dae.der(y)], [1; 2; 3]); catch e, msg = e.message; end
>> contains(msg, 'Mismatched dimensions')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> z = ca.add(dae, "z");
julia> w = ca.add(dae, "w");
julia> ca.x(dae), ca.z(dae), ca.w(dae)
(String[], ["x", "y", "z", "w"], String[])
julia> ca.eq(dae, ca.der(dae, x), -x + z)
julia> ca.x(dae), ca.z(dae), ca.w(dae)
(["x"], ["y", "z", "w"], ["der(x)"])
julia> ca.eq(dae, 0, x - 2*z)
julia> ca.z(dae), ca.outputs(dae, "alg")
(["y", "z", "w"], MX[(-(x-(2.*z)))])
julia> ca.eq(dae, w, x*z)
julia> ca.w(dae), ca.wdef(dae)
(["der(x)", "w"], MX[(z-x), (x*z)])
julia> ca.eq(dae, [ca.der(dae, y); w], [w; 1])
julia> ca.x(dae), ca.outputs(dae, "ode"), ca.outputs(dae, "alg")
(["x", "y"], MX[(z-x), w], MX[(-(x-(2.*z))), (-(w-1))])
julia> try
           ca.eq(dae, x, 1)
       catch e
           println(occursin("Cannot handle left-hand-side", sprint(showerror, e)))
       end
true
julia> try
           ca.eq(dae, [ca.der(dae, x); ca.der(dae, y)], [1, 2, 3])
       catch e
           println(occursin("Mismatched dimensions", sprint(showerror, e)))
       end
true

See also
der, when, set_init, add

Extra doc: https://github.com/casadi/casadi/wiki/L_2kt

Definition at line 385 of file dae_builder.cpp.

385  {
386  try {
387  (*this)->eq(lhs, rhs, opts);
388  } catch (std::exception& e) {
389  THROW_ERROR("eq", e.what());
390  }
391 }

◆ export_fmu()

Dict casadi::DaeBuilder::export_fmu ( const Dict &  opts = Dict())

Generates the files of an FMI 3.0 model exchange FMU in the current directory: C code for the model equations and their derivatives (<name>.c, <name>.h), the FMI wrapper <name>_wrap.c, buildDescription.xml, modelDescription.xml and, with serialization, the oracle as oracle.casadi plus a layered-standard manifest. Quadrature states are not supported. The result maps each local file name to its path inside the FMU archive, ready for compile_fmu and pack_fmu.

Parameters
optsOptions (any other key is an error):
  • "no_warning" (bool, false): suppress the "experimental" warning
  • "with_serialization" (bool, true): include the serialized oracle
Returns
Map local file name to archive path
See also
compile_fmu, pack_fmu, oracle

Extra doc: https://github.com/casadi/casadi/wiki/L_2le

Definition at line 211 of file dae_builder.cpp.

211  {
212  try {
213  return (*this)->export_fmu(opts);
214  } catch (std::exception& e) {
215  THROW_ERROR("export_fmu", e.what());
216  return Dict(); // never reached
217  }
218 }

◆ fun() [1/2]

std::vector< Function > casadi::DaeBuilder::fun ( ) const

Definition at line 858 of file dae_builder.cpp.

858  {
859  return (*this)->fun_;
860 }

◆ fun() [2/2]

Function casadi::DaeBuilder::fun ( const std::string &  name) const

Returns the stored function with this name; an unknown name is an error.

>>> a = MX.sym("a")
>>> dae = DaeBuilder("m")
>>> f = dae.add_fun(Function("F", [a], [a**2]))
>>> dae.fun("F")
Function(F:(i0)->(o0) MXFunction)
>>> try:
...   dae.fun("nope")
... except Exception as e:
...   print("No such function" in str(e))
True

>> a = MX.sym('a'); dae = DaeBuilder('m');
>> f = dae.add_fun(Function('F', {a}, {a^2}));
>> dae.fun('F')
F:(i0)->(o0) MXFunction
>> try, dae.fun('nope'); catch e, disp(contains(e.message, 'No such function')); end
1

julia> a = ca.MX.sym("a");
julia> dae = ca.DaeBuilder("m");
julia> f = ca.add_fun(dae, ca.Function("F", [a], [a^2]));
julia> ca.fun(dae, "F")
Function(F:(i0)->(o0) MXFunction)
julia> try
           ca.fun(dae, "nope")
       catch e
           println(occursin("No such function", sprint(showerror, e)))
       end
true

See also
has_fun, add_fun

Extra doc: https://github.com/casadi/casadi/wiki/L_2la

Definition at line 828 of file dae_builder.cpp.

828  {
829  try {
830  return (*this)->fun(name);
831  } catch (std::exception& e) {
832  THROW_ERROR("fun", e.what());
833  return Function(); // never reached
834  }
835 }

References name().

◆ gather_fun()

void casadi::DaeBuilder::gather_fun ( casadi_int  max_depth = -1)

Finds the Function objects called inside the model equations and stores them, so that they are listed by fun(). Functions whose name is already stored are skipped with a warning.

Parameters
max_depthHow deep to look into nested function calls; -1 for unlimited

>>> a = MX.sym("a")
>>> F = Function("F", [a], [a**2])
>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> dae.eq(dae.der(x), F(x))
>>> [g.name() for g in dae.fun()]
[]
>>> dae.gather_fun()
>>> [g.name() for g in dae.fun()]
['F']

>> a = MX.sym('a'); F = Function('F', {a}, {a^2});
>> dae = DaeBuilder('m'); x = dae.add('x');
>> dae.eq(dae.der(x), F(x));
>> numel(dae.fun())
0
>> dae.gather_fun();
>> cellfun(@(g) disp(g.name()), dae.fun())
F

julia> a = ca.MX.sym("a");
julia> F = ca.Function("F", [a], [a^2]);
julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> ca.eq(dae, ca.der(dae, x), F(x))
julia> [ca.name(g) for g in ca.fun(dae)]
String[]
julia> ca.gather_fun(dae)
julia> [ca.name(g) for g in ca.fun(dae)]
1-element Vector{String}:
 "F"

See also
fun, add_fun

Extra doc: https://github.com/casadi/casadi/wiki/L_2lb

Definition at line 837 of file dae_builder.cpp.

837  {
838  try {
839  // Get a function corresponding to all equations (no inputs)
840  Function all_eq = (*this)->gather_eq();
841  // Gather all functions
842  std::vector<Function> allfun = all_eq.find_functions(max_depth);
843  // Add to list of functions
844  for (const Function& f : allfun) {
845  if (has_fun(f.name())) {
846  // Skip functions with duplicate names
847  casadi_warning("Duplicate function: '" + f.name() + "', ignored");
848  } else {
849  // Add to list of functions
850  add_fun(f);
851  }
852  }
853  } catch (std::exception& e) {
854  THROW_ERROR("gather_fun", e.what());
855  }
856 }

References add_fun(), casadi::Function::find_functions(), and has_fun().

◆ get() [1/3]

Definition at line 99 of file generic_shared_impl.hpp.

115  {
116  return node;
117  }

◆ get() [2/3]

GenericType casadi::DaeBuilder::get ( const std::string &  name) const

For a symbolic model the current value (see set): a number for a scalar, a list for a vector-valued variable, a string for a string variable; nan when unset. For an imported FMU the value is obtained by evaluating the FMU.

See also
set, start

Extra doc: https://github.com/casadi/casadi/wiki/L_2mb

Definition at line 1151 of file dae_builder.cpp.

1151  {
1152  return get(std::vector<std::string>{name}).front();
1153 }
SharedObjectInternal * get() const
Get a const pointer to the node.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get(), and name().

◆ get() [3/3]

std::vector< GenericType > casadi::DaeBuilder::get ( const std::vector< std::string > &  name) const

Definition at line 1155 of file dae_builder.cpp.

1155  {
1156  try {
1157  // Allocate return value
1158  std::vector<GenericType> ret;
1159  ret.reserve(name.size());
1160  // For symbolic FMUs, we can just retrieve the values
1161  if (symbolic()) {
1162  // Retrieve the attributes
1163  for (const auto& n : name) {
1164  // Get the variable
1165  const Variable& v = (*this)->variable(n);
1166  if (v.type == Type::STRING) {
1167  // Attribute is a string
1168  std::string val;
1169  v.get_attribute(Attribute::STRINGVALUE, &val);
1170  ret.push_back(val);
1171  } else if (v.numel == 1) {
1172  // Attribute is numerical scalar
1173  double val;
1174  v.get_attribute(Attribute::VALUE, &val);
1175  ret.push_back(val);
1176  } else {
1177  // Attribute is a vector
1178  std::vector<double> val;
1179  v.get_attribute(Attribute::VALUE, &val);
1180  ret.push_back(val);
1181  }
1182  }
1183  } else {
1184  // Create a temporary FmuFunction instance
1185  Function f = create(this->name() + "_get", {}, {}, Dict{{"aux", name}});
1186  // Get the stats
1187  Dict stats = f.stats().at("aux");
1188  // Return in the same order as inputs
1189  for (const std::string& n : name) ret.push_back(stats.at(n));
1190  }
1191  return ret;
1192  } catch (std::exception& e) {
1193  THROW_ERROR("get", e.what());
1194  return {};
1195  }
1196 }
bool symbolic() const
Symbolic DAE instance?

References create(), casadi::Variable::get_attribute(), name(), casadi::Variable::numel, casadi::Function::stats(), casadi::STRING, casadi::STRINGVALUE, symbolic(), casadi::Variable::type, and casadi::VALUE.

◆ get_str()

std::string casadi::SharedObject::get_str ( bool  more = false) const
inlineinherited

Definition at line 91 of file shared_object.hpp.

91  {
92  std::stringstream ss;
93  disp(ss, more);
94  return ss.str();
95  }
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.

◆ getCount()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::getCount
inherited

Definition at line 102 of file generic_shared_impl.hpp.

138  {
139  return (*this)->getCount();
140  }

◆ has()

bool casadi::DaeBuilder::has ( const std::string &  name) const

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> dae.has("x"), dae.has("der(x)"), dae.has("time")
(True, False, True)
>>> dae.der(x), dae.has("der(x)")
(MX(der(x)), True)

>> dae = DaeBuilder('m'); x = dae.add('x');
>> dae.has('x'), dae.has('der(x)'), dae.has('time')
1
0
1
>> dae.der(x), dae.has('der(x)')
der(x)
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> ca.has(dae, "x"), ca.has(dae, "der(x)"), ca.has(dae, "time")
(true, false, true)
julia> ca.der(dae, x), ca.has(dae, "der(x)")
(der(x), true)

See also
all, var

Extra doc: https://github.com/casadi/casadi/wiki/L_2me

Definition at line 254 of file dae_builder.cpp.

254  {
255  try {
256  return (*this)->has(name);
257  } catch (std::exception& e) {
258  THROW_ERROR("has", e.what());
259  return false; // never reached
260  }
261 }

References name().

◆ has_beq()

bool casadi::DaeBuilder::has_beq ( const std::string &  name) const

A binding equation is the right-hand side of an explicit equation eq(v, expr) (or an imported one); dependent variables, dependent parameters and defined derivatives have one.

See also
beq, eq

Extra doc: https://github.com/casadi/casadi/wiki/L_2lq

Definition at line 511 of file dae_builder.cpp.

511  {
512  try {
513  return !(*this)->variable(name).has_beq();
514  } catch (std::exception& e) {
515  THROW_ERROR("has_beq", e.what());
516  return false; // never reached
517  }
518 }

References name().

◆ has_fun()

bool casadi::DaeBuilder::has_fun ( const std::string &  name) const

True when a function with this name has been stored with add_fun or gather_fun.

See also
fun, add_fun

Extra doc: https://github.com/casadi/casadi/wiki/L_2l9

Definition at line 819 of file dae_builder.cpp.

819  {
820  try {
821  return (*this)->has_fun(name);
822  } catch (std::exception& e) {
823  THROW_ERROR("has_fun", e.what());
824  return false; // never reached
825  }
826 }

References name().

Referenced by add_fun(), and gather_fun().

◆ has_t()

bool casadi::DaeBuilder::has_t ( ) const

True when an independent variable has been declared explicitly (or imported), i.e. when t_new() is non-empty.

See also
time, t_new

Extra doc: https://github.com/casadi/casadi/wiki/L_64

Definition at line 144 of file dae_builder.cpp.

144  {
145  try {
146  return (*this)->has_t();
147  } catch (std::exception& e) {
148  THROW_ERROR("has_t", e.what());
149  return false; // never reached
150  }
151 }

◆ init_lhs()

std::vector< MX > casadi::DaeBuilder::init_lhs ( ) const

The variable expressions that have an initial equation, in the order the equations were set with set_init; init_rhs() holds the matching right-hand sides.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> p = dae.add("p", "parameter", "tunable")
>>> dae.eq(dae.der(x), -x)
>>> dae.set_init("x", 2*p)
>>> dae.init_lhs(), dae.init_rhs()
([MX(x)], [MX((2.*p))])

>> dae = DaeBuilder('m'); x = dae.add('x'); p = dae.add('p', 'parameter', 'tunable');
>> dae.eq(dae.der(x), -x); dae.set_init('x', 2*p);
>> cellfun(@disp, dae.init_lhs()), cellfun(@disp, dae.init_rhs())
x
(2.*p)

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> ca.set_init(dae, "x", 2*p)
julia> ca.init_lhs(dae), ca.init_rhs(dae)
(MX[x], MX[(2.*p)])

See also
init_rhs, set_init

Extra doc: https://github.com/casadi/casadi/wiki/L_2b1

Definition at line 118 of file dae_builder.cpp.

118  {
119  return (*this)->init_lhs();
120 }

◆ init_rhs()

std::vector< MX > casadi::DaeBuilder::init_rhs ( ) const

The right-hand sides of the initial equations, matching init_lhs().

See also
init_lhs, set_init

Extra doc: https://github.com/casadi/casadi/wiki/L_2b2

Definition at line 122 of file dae_builder.cpp.

122  {
123  return (*this)->init_rhs();
124 }

Referenced by set_init().

◆ initial()

std::string casadi::DaeBuilder::initial ( const std::string &  name) const

The FMI initial attribute: "exact", "approx", "calculated" or "na". The default follows from causality and variability per the FMI specification; it can be given with the "initial" option of add. Other values are an error.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(initial="approx"))
>>> p = dae.add("p", "parameter", "tunable")
>>> u = dae.add("u", "input")
>>> dae.initial("x"), dae.initial("p"), dae.initial("u")
('approx', 'exact', 'na')
>>> dae.set_initial("x", "exact")
>>> dae.initial("x")
'exact'

>> dae = DaeBuilder('m'); x = dae.add('x', struct('initial', 'approx'));
>> p = dae.add('p', 'parameter', 'tunable'); u = dae.add('u', 'input');
>> dae.initial('x'), dae.initial('p'), dae.initial('u')
approx
exact
na
>> dae.set_initial('x', 'exact');
>> dae.initial('x')
exact

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("initial" => "approx"));
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> u = ca.add(dae, "u", "input");
julia> ca.initial(dae, "x"), ca.initial(dae, "p"), ca.initial(dae, "u")
("approx", "exact", "na")
julia> dae.set_initial("x", "exact")
julia> ca.initial(dae, "x")
"exact"

Extra doc: https://github.com/casadi/casadi/wiki/L_2lz

Definition at line 655 of file dae_builder.cpp.

655  {
656  return to_string((*this)->variable(name).initial);
657 }

References name(), and casadi::to_string().

◆ initial_unknowns()

std::vector< std::string > casadi::DaeBuilder::initial_unknowns ( ) const

Names of the variables listed under InitialUnknowns in the model structure of an imported model description. Empty for a symbolically constructed model.

See also
load_fmi_description, der

Extra doc: https://github.com/casadi/casadi/wiki/L_63

Definition at line 135 of file dae_builder.cpp.

135  {
136  try {
137  return (*this)->name((*this)->initial_unknowns_);
138  } catch (std::exception& e) {
139  THROW_ERROR("initial_unknowns", e.what());
140  return {}; // never reached
141  }
142 }

◆ inputs()

std::vector< MX > casadi::DaeBuilder::inputs ( const std::string &  cat) const

The symbolic expressions of the variables of an input category, in category order.

Parameters
catOne of "t", "c", "p", "d", "w", "u", "x", "z", "q"; an output category such as "ode" is an error
Returns
List of (column vector) expressions, one per variable; empty when the category is empty

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> z = dae.add("z")
>>> u = dae.add("u", "input")
>>> dae.eq(dae.der(x), -x + z*u)
>>> dae.eq(0, x - 2*z)
>>> dae.inputs("x"), dae.inputs("z"), dae.inputs("u"), dae.inputs("p")
([MX(x)], [MX(z)], [MX(u)], [])
>>> try:
...   dae.inputs("ode")
... except Exception as e:
...   print("not an input category" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); z = dae.add('z'); u = dae.add('u', 'input');
>> dae.eq(dae.der(x), -x + z*u); dae.eq(0, x - 2*z);
>> cellfun(@disp, dae.inputs('x')), cellfun(@disp, dae.inputs('z'))
x
z
>> cellfun(@disp, dae.inputs('u')), disp(numel(dae.inputs('p')))
u
0
>> try, dae.inputs('ode'); catch e, disp(contains(e.message, 'not an input category')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> z = ca.add(dae, "z");
julia> u = ca.add(dae, "u", "input");
julia> ca.eq(dae, ca.der(dae, x), -x + z*u)
julia> ca.eq(dae, 0, x - 2*z)
julia> ca.inputs(dae, "x"), ca.inputs(dae, "z"), ca.inputs(dae, "u"), ca.inputs(dae, "p")
(MX[x], MX[z], MX[u], MX[])
julia> try
           ca.inputs(dae, "ode")
       catch e
           println(occursin("not an input category", sprint(showerror, e)))
       end
true

See also
outputs, var, all

Extra doc: https://github.com/casadi/casadi/wiki/L_2fx

Definition at line 73 of file dae_builder.cpp.

73  {
74  try {
75  return (*this)->inputs(to_enum<Category>(cat));
76  } catch (std::exception& e) {
77  THROW_ERROR("inputs", e.what());
78  return {}; // never reached
79  }
80 }

◆ is_null()

Definition at line 116 of file generic_shared_impl.hpp.

120  {
121  return node==nullptr;
122  }

◆ jac_sparsity()

Sparsity casadi::DaeBuilder::jac_sparsity ( const std::vector< std::string > &  onames,
const std::vector< std::string > &  inames 
) const

Structural dependency pattern of the variables onames with respect to inames, one row per output name and one column per input name, taken from the dependency information of the model structure. This information comes from an imported model description or is computed by export_fmu; for a symbolically constructed model it is otherwise absent and the pattern has no nonzeros.

Parameters
onamesNames of (derivative or output) variables
inamesNames of variables to differentiate with respect to
Returns
Sparsity pattern of size len(onames) by len(inames)

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> u = dae.add("u", "input")
>>> dae.eq(dae.der(x), -x*u)
>>> dae.jac_sparsity(["der(x)"], ["x", "u"])
Sparsity(1x2,0nz)

>> dae = DaeBuilder('m'); x = dae.add('x'); u = dae.add('u', 'input');
>> dae.eq(dae.der(x), -x*u);
>> dae.jac_sparsity({'der(x)'}, {'x', 'u'})
1x2,0nz

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> u = ca.add(dae, "u", "input");
julia> ca.eq(dae, ca.der(dae, x), -x*u)
julia> ca.jac_sparsity(dae, ["der(x)"], ["x", "u"])
Sparsity(1x2,0nz)

See also
load_fmi_description, export_fmu

Extra doc: https://github.com/casadi/casadi/wiki/L_6g

Definition at line 1207 of file dae_builder.cpp.

1208  {
1209  try {
1210  return (*this)->jac_sparsity((*this)->find(onames), (*this)->find(inames));
1211  } catch (std::exception& e) {
1212  THROW_ERROR("jac_sparsity", e.what());
1213  return Sparsity(); // never reached
1214  }
1215 }

◆ lift()

void casadi::DaeBuilder::lift ( bool  lift_shared = true,
bool  lift_calls = true 
)

Scans the right-hand sides of the ODEs, quadratures and algebraic equations and replaces shared subexpressions and/or embedded function calls by new dependent variables named w_<k>, appended to w with their definitions. The lifted definitions become part of wdef; create with "w" as input then exposes them, and create with lifted_calls accounts for the calls in jac_wdef_w and Hessians. A warning is issued when w is non-empty already, which is the case as soon as a state has an ODE.

Parameters
lift_sharedLift subexpressions that are used more than once
lift_callsLift calls to embedded Function objects, including their arguments

>>> a = MX.sym("a")
>>> F = Function("F", [a], [sin(a) + a**2])
>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> dae.eq(0, x - F(y))
>>> dae.eq(0, y - F(x)**2 - F(y))
>>> dae.lift()
>>> dae.w()
['w_0', 'w_1', 'w_2', 'w_3', 'w_4']
>>> dae.wdef()
[MX(x), MX(y), MX(F(w_1){0}), MX(F(w_0){0}), MX(F(w_1){0})]
>>> dae.outputs("alg")
[MX((-(w_0-w_2))), MX((-((w_1-sq(w_3))-w_4)))]
>>> dae.create("f", ["z", "w"], ["alg", "wdef"])
Function(f:(z[2],w[5])->(alg[2],wdef[5]) MXFunction)

>> a = MX.sym('a'); F = Function('F', {a}, {sin(a) + a^2});
>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> dae.eq(0, x - F(y)); dae.eq(0, y - F(x)^2 - F(y));
>> dae.lift();
>> dae.w()
w_0
w_1
w_2
w_3
w_4
>> cellfun(@disp, dae.wdef())
x
y
F(w_1){0}
F(w_0){0}
F(w_1){0}
>> cellfun(@disp, dae.outputs('alg'))
(-(w_0-w_2))
(-((w_1-sq(w_3))-w_4))
>> dae.create('f', {'z', 'w'}, {'alg', 'wdef'})
f:(z[2],w[5])->(alg[2],wdef[5]) MXFunction

julia> a = ca.MX.sym("a");
julia> F = ca.Function("F", [a], [sin(a) + a^2]);
julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> ca.eq(dae, 0, x - F(y))
julia> ca.eq(dae, 0, y - F(x)^2 - F(y))
julia> ca.lift(dae)
julia> ca.w(dae)
5-element Vector{String}:
 "w_0"
 "w_1"
 "w_2"
 "w_3"
 "w_4"
julia> ca.wdef(dae)
5-element Vector{MX}:
 MX(x)
 MX(y)
 MX(F(w_1){0})
 MX(F(w_0){0})
 MX(F(w_1){0})
julia> ca.outputs(dae, "alg")
2-element Vector{MX}:
 MX((-(w_0-w_2)))
 MX((-((w_1-sq(w_3))-w_4)))
julia> ca.create(dae, "f", ["z", "w"], ["alg", "wdef"])
Function(f:(z[2],w[5])->(alg[2],wdef[5]) MXFunction)

See also
eliminate, w, wdef

Extra doc: https://github.com/casadi/casadi/wiki/L_2l3

Definition at line 546 of file dae_builder.cpp.

546  {
547  try {
548  (*this)->lift(lift_shared, lift_calls);
549  } catch (std::exception& e) {
550  THROW_ERROR("lift", e.what());
551  }
552 }

◆ load_fmi_description()

void casadi::DaeBuilder::load_fmi_description ( const std::string &  filename)

Reads a modelDescription.xml (FMI 1.0, 2.0 or 3.0) into an empty instance: model variables with their attributes, the default experiment (start_time etc.), the model structure (der, initial_unknowns, dependencies used by jac_sparsity) and, for symbolic model descriptions, the equations. A standard FMU results in a non-symbolic instance whose functions call the FMU binary found in the FMU directory. The constructor with a path calls this for <path>/modelDescription.xml. An instance that already has variables, or a missing file, is an error.

Parameters
filenamePath to the XML file
See also
DaeBuilder, symbolic, provides_directional_derivatives

Extra doc: https://github.com/casadi/casadi/wiki/L_2ld

Definition at line 193 of file dae_builder.cpp.

193  {
194  try {
195  (*this)->load_fmi_description(filename);
196  } catch (std::exception& e) {
197  THROW_ERROR("load_fmi_description", e.what());
198  }
199 }
std::string filename(const std::string &path)
Definition: ghc.cpp:55

References casadi::filename().

Referenced by DaeBuilder().

◆ max() [1/2]

double casadi::DaeBuilder::max ( const std::string &  name) const

Definition at line 1000 of file dae_builder.cpp.

1000  {
1001  try {
1002  return (*this)->variable(name).max;
1003  } catch (std::exception& e) {
1004  THROW_ERROR("max", e.what());
1005  return 0; // never reached
1006  }
1007 }

References name().

◆ max() [2/2]

std::vector< double > casadi::DaeBuilder::max ( const std::vector< std::string > &  name) const

Definition at line 1009 of file dae_builder.cpp.

1009  {
1010  try {
1011  return (*this)->attribute(Attribute::MAX, name);
1012  } catch (std::exception& e) {
1013  THROW_ERROR("max", e.what());
1014  return {}; // never reached
1015  }
1016 }

References casadi::MAX, and name().

◆ min() [1/2]

double casadi::DaeBuilder::min ( const std::string &  name) const

The "min" attribute; -inf by default. Only scalar variables are supported.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(min=-2, max=2, nominal=10))
>>> dae.min("x"), dae.max("x"), dae.nominal("x")
(-2.0, 2.0, 10.0)
>>> dae.set_min("x", 0)
>>> dae.set_max(["x"], [5])
>>> dae.set_nominal("x", 2)
>>> dae.min(["x"]), dae.max("x"), dae.nominal(["x"])
([0.0], 5.0, [2.0])

>> dae = DaeBuilder('m'); x = dae.add('x', struct('min', -2, 'max', 2, 'nominal', 10));
>> dae.min('x'), dae.max('x'), dae.nominal('x')
-2
2
10
>> dae.set_min('x', 0); dae.set_max({'x'}, 5); dae.set_nominal('x', 2);
>> dae.min({'x'}), dae.max('x'), dae.nominal({'x'})
0
5
2

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("min" => -2, "max" => 2, "nominal" => 10));
julia> dae.min("x"), dae.max("x"), ca.nominal(dae, "x")
(-2.0, 2.0, 10.0)
julia> ca.set_min(dae, "x", 0)
julia> ca.set_max(dae, ["x"], [5])
julia> ca.set_nominal(dae, "x", 2)
julia> dae.min(["x"]), dae.max("x"), ca.nominal(dae, ["x"])
([0.0], 5.0, [2.0])

See also
set_min, max, nominal

Extra doc: https://github.com/casadi/casadi/wiki/L_2m7

Definition at line 966 of file dae_builder.cpp.

966  {
967  try {
968  return (*this)->variable(name).min;
969  } catch (std::exception& e) {
970  THROW_ERROR("min", e.what());
971  return 0; // never reached
972  }
973 }

References name().

◆ min() [2/2]

std::vector< double > casadi::DaeBuilder::min ( const std::vector< std::string > &  name) const

Definition at line 975 of file dae_builder.cpp.

975  {
976  try {
977  return (*this)->attribute(Attribute::MIN, name);
978  } catch (std::exception& e) {
979  THROW_ERROR("min", e.what());
980  return {}; // never reached
981  }
982 }

References casadi::MIN, and name().

◆ name()

const std::string & casadi::DaeBuilder::name ( ) const

>>> dae = DaeBuilder("rocket")
>>> dae.name()
'rocket'
>>> dae.create()
Function(rocket_dae:(t[0],x[0],z[0],p[0],u[0])->(ode[0],alg[0],quad[0],zero[0]) MXFunction)

>> dae = DaeBuilder('rocket');
>> dae.name()
rocket
>> dae.create()
rocket_dae:(t[0],x[0],z[0],p[0],u[0])->(ode[0],alg[0],quad[0],zero[0]) MXFunction

julia> dae = ca.DaeBuilder("rocket");
julia> ca.name(dae)
"rocket"
julia> ca.create(dae)
Function(rocket_dae:(t[0],x[0],z[0],p[0],u[0])->(ode[0],alg[0],quad[0],zero[0]) MXFunction)

Extra doc: https://github.com/casadi/casadi/wiki/L_5d

Definition at line 59 of file dae_builder.cpp.

59  {
60  return (*this)->name_;
61 }

Referenced by add(), add_fun(), add_lc(), assign(), attribute(), beq(), categories(), category(), causality(), create(), DaeBuilder(), der(), description(), dimension(), display_unit(), fun(), get(), has(), has_beq(), has_fun(), initial(), max(), min(), nominal(), numel(), pre(), reinit(), set(), set_all(), set_attribute(), set_category(), set_causality(), set_description(), set_display_unit(), set_init(), set_initial(), set_max(), set_min(), set_nominal(), set_start(), set_type(), set_unit(), set_value_reference(), set_variability(), start(), type(), unit(), value_reference(), var(), and variability().

◆ nc()

casadi_int casadi::DaeBuilder::nc ( ) const

Number of variables of category c, i.e. the length of c().

See also
c

Extra doc: https://github.com/casadi/casadi/wiki/L_6b

Definition at line 181 of file dae_builder.cpp.

181  {
182  return (*this)->size(Category::C);
183 }

References casadi::C.

◆ nd()

casadi_int casadi::DaeBuilder::nd ( ) const

Number of variables of category d, i.e. the length of d().

See also
d

Extra doc: https://github.com/casadi/casadi/wiki/L_6c

Definition at line 185 of file dae_builder.cpp.

185  {
186  return (*this)->size(Category::D);
187 }

References casadi::D.

◆ nominal() [1/2]

double casadi::DaeBuilder::nominal ( const std::string &  name) const

Definition at line 1034 of file dae_builder.cpp.

1034  {
1035  try {
1036  return (*this)->variable(name).nominal;
1037  } catch (std::exception& e) {
1038  THROW_ERROR("nominal", e.what());
1039  return 0; // never reached
1040  }
1041 }

References name().

◆ nominal() [2/2]

std::vector< double > casadi::DaeBuilder::nominal ( const std::vector< std::string > &  name) const

Definition at line 1043 of file dae_builder.cpp.

1043  {
1044  try {
1045  return (*this)->attribute(Attribute::NOMINAL, name);
1046  } catch (std::exception& e) {
1047  THROW_ERROR("nominal", e.what());
1048  return {}; // never reached
1049  }
1050 }

References name(), and casadi::NOMINAL.

◆ np()

casadi_int casadi::DaeBuilder::np ( ) const

Number of variables of category p, i.e. the length of p().

See also
p

Extra doc: https://github.com/casadi/casadi/wiki/L_6a

Definition at line 177 of file dae_builder.cpp.

177  {
178  return (*this)->size(Category::P);
179 }

References casadi::P.

◆ nq()

casadi_int casadi::DaeBuilder::nq ( ) const

Number of variables of category q, i.e. the length of q().

See also
q

Extra doc: https://github.com/casadi/casadi/wiki/L_67

Definition at line 161 of file dae_builder.cpp.

161  {
162  return (*this)->size(Category::Q);
163 }

References casadi::Q.

◆ nu()

casadi_int casadi::DaeBuilder::nu ( ) const

Number of variables of category u, i.e. the length of u().

See also
u

Extra doc: https://github.com/casadi/casadi/wiki/L_69

Definition at line 173 of file dae_builder.cpp.

173  {
174  return (*this)->size(Category::U);
175 }

References casadi::U.

◆ numel()

casadi_int casadi::DaeBuilder::numel ( const std::string &  name) const

Product of the dimensions, i.e. the length of the variable's column vector expression.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> m = dae.add("m", dict(dimension=[2, 3]))
>>> dae.numel("x"), dae.numel("m"), dae.dimension("m"), dae.var("m").shape
(1, 6, [2, 3], (6, 1))

>> dae = DaeBuilder('m'); x = dae.add('x'); m = dae.add('m', struct('dimension', [2 3]));
>> dae.numel('x'), dae.numel('m')
1
6
>> dae.dimension('m'), size(dae.var('m'))
2 3
6 1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> m = ca.add(dae, "m", Dict("dimension" => [2, 3]));
julia> ca.numel(dae, "x"), ca.numel(dae, "m"), ca.dimension(dae, "m"), size(ca.var(dae, "m"))
(1, 6, [2, 3], (6, 1))

See also
dimension, var

Extra doc: https://github.com/casadi/casadi/wiki/L_2m2

Definition at line 679 of file dae_builder.cpp.

679  {
680  return (*this)->variable(name).numel;
681 }

References name().

◆ nw()

casadi_int casadi::DaeBuilder::nw ( ) const

Number of variables of category w, i.e. the length of w().

See also
w

Extra doc: https://github.com/casadi/casadi/wiki/L_6d

Definition at line 189 of file dae_builder.cpp.

189  {
190  return (*this)->size(Category::W);
191 }

References casadi::W.

◆ nx()

casadi_int casadi::DaeBuilder::nx ( ) const

Number of variables of category x, i.e. the length of x(). Vector-valued variables count once.

>>> dae = DaeBuilder("m")
>>> pos = dae.add("pos", dict(dimension=[3]))
>>> dae.eq(dae.der(pos), -pos)
>>> dae.nx(), dae.create()
(1, Function(m_dae:(t[0],x[3],z[0],p[0],u[0])->(ode[3],alg[0],quad[0],zero[0]) MXFunction))

>> dae = DaeBuilder('m'); pos = dae.add('pos', struct('dimension', 3));
>> dae.eq(dae.der(pos), -pos);
>> dae.nx(), dae.create()
1
m_dae:(t[0],x[3],z[0],p[0],u[0])->(ode[3],alg[0],quad[0],zero[0]) MXFunction

julia> dae = ca.DaeBuilder("m");
julia> pos = ca.add(dae, "pos", Dict("dimension" => [3]));
julia> ca.eq(dae, ca.der(dae, pos), -pos)
julia> ca.nx(dae), ca.create(dae)
(1, m_dae:(t[0],x[3],z[0],p[0],u[0])->(ode[3],alg[0],quad[0],zero[0]) MXFunction)

See also
x

Extra doc: https://github.com/casadi/casadi/wiki/L_65

Definition at line 153 of file dae_builder.cpp.

153  {
154  return (*this)->size(Category::X);
155 }

References casadi::X.

◆ ny()

casadi_int casadi::DaeBuilder::ny ( ) const

Number of output variables, i.e. the length of y().

See also
y

Extra doc: https://github.com/casadi/casadi/wiki/L_68

Definition at line 169 of file dae_builder.cpp.

169  {
170  return (*this)->size(Category::Y);
171 }

References casadi::Y.

Referenced by set_all().

◆ nz()

casadi_int casadi::DaeBuilder::nz ( ) const

Number of variables of category z, i.e. the length of z().

See also
z

Extra doc: https://github.com/casadi/casadi/wiki/L_66

Definition at line 157 of file dae_builder.cpp.

157  {
158  return (*this)->size(Category::Z);
159 }

References casadi::Z.

◆ nzero()

casadi_int casadi::DaeBuilder::nzero ( ) const

Number of event indicators, one per when equation; the length of outputs("zero").

See also
when, transition

Extra doc: https://github.com/casadi/casadi/wiki/L_2cb

Definition at line 165 of file dae_builder.cpp.

165  {
166  return (*this)->size(Category::ZERO);
167 }

References casadi::ZERO.

◆ ode()

std::vector<MX> casadi::DaeBuilder::ode ( ) const
inline

Definition at line 692 of file dae_builder.hpp.

692 {return outputs("ode");}

◆ operator()()

MX casadi::DaeBuilder::operator() ( const std::string &  name) const
inline

The symbolic expression of a model variable: a dense column vector with numel entries, named after the variable. An unknown name is an error. Also available via the call operator.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(dimension=[2]))
>>> dae.var("x"), dae.var("x").shape
(MX(x), (2, 1))
>>> dae.has("x"), dae.has("y")
(True, False)
>>> try:
...   dae.var("y")
... except Exception as e:
...   print("No such variable" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x', struct('dimension', 2));
>> dae.var('x'), size(dae.var('x'))
x
2 1
>> dae.has('x'), dae.has('y')
1
0
>> try, dae.var('y'); catch e, disp(contains(e.message, 'No such variable')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("dimension" => [2]));
julia> ca.var(dae, "x"), size(ca.var(dae, "x"))
(x, (2, 1))
julia> ca.has(dae, "x"), ca.has(dae, "y")
(true, false)
julia> try
           ca.var(dae, "y")
       catch e
           println(occursin("No such variable", sprint(showerror, e)))
       end
true

See also
has, all, inputs

Extra doc: https://github.com/casadi/casadi/wiki/L_2ll

Definition at line 3062 of file dae_builder.hpp.

3062 {return var(name);}
MX var(const std::string &name) const
Get variable expression by name.

◆ operator->() [1/2]

DaeBuilderInternal * casadi::DaeBuilder::operator-> ( )

Definition at line 904 of file dae_builder.cpp.

904  {
905  return static_cast<DaeBuilderInternal*>(SharedObject::operator->());
906 }
SharedObjectInternal * operator->() const
Access a member function or object.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ operator->() [2/2]

const DaeBuilderInternal * casadi::DaeBuilder::operator-> ( ) const

Definition at line 908 of file dae_builder.cpp.

908  {
909  return static_cast<const DaeBuilderInternal*>(SharedObject::operator->());
910 }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ oracle()

Function casadi::DaeBuilder::oracle ( bool  sx = false,
bool  elim_w = false,
bool  lifted_calls = false 
) const

The Function behind create for a symbolic model: inputs are all input categories except c (whose current values are substituted), outputs are all output categories, each as one concatenated vector (empty vectors for empty categories). The oracle is cached and rebuilt when variables or equations change. Not available for an imported FMU.

Parameters
sxReturn the SX expansion of the oracle instead of the MX graph
elim_wSubstitute the dependent variables w out and drop them as input
lifted_callsReplace embedded function calls in wdef by zeros, for use with create with lifted_calls; incompatible with elim_w

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> w = dae.add("w")
>>> dae.eq(w, sin(x))
>>> dae.eq(dae.der(x), -w)
>>> f = dae.oracle()
>>> f.name(), f.name_in()
('mx_oracle', ['t', 'p', 'd', 'w', 'u', 'x', 'z', 'q'])
>>> f.name_out()
['ode', 'alg', 'quad', 'zero', 'ddef', 'wdef', 'y']
>>> f.size1_in("w"), f.size1_in("p")
(2, 0)
>>> dae.oracle(True).class_name(), dae.oracle(False, True).name_in()
('SXFunction', ['t', 'p', 'd', 'u', 'x', 'z', 'q'])

>> dae = DaeBuilder('m'); x = dae.add('x'); w = dae.add('w');
>> dae.eq(w, sin(x)); dae.eq(dae.der(x), -w);
>> f = dae.oracle();
>> f.name(), strjoin(cellstr(f.name_in()), ' ')
mx_oracle
t p d w u x z q
>> strjoin(cellstr(f.name_out()), ' ')
ode alg quad zero ddef wdef y
>> f.size1_in('w'), f.size1_in('p')
2
0
>> g = dae.oracle(true); disp(g.class_name())
SXFunction
>> g = dae.oracle(false, true); disp(strjoin(cellstr(g.name_in()), ' '))
t p d u x z q

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> w = ca.add(dae, "w");
julia> ca.eq(dae, w, sin(x))
julia> ca.eq(dae, ca.der(dae, x), -w)
julia> f = ca.oracle(dae);
julia> ca.name(f), ca.name_in(f)
("mx_oracle", ["t", "p", "d", "w", "u", "x", "z", "q"])
julia> ca.name_out(f)
7-element Vector{String}:
 "ode"
 "alg"
 "quad"
 "zero"
 "ddef"
 "wdef"
 "y"
julia> ca.size1_in(f, "w"), ca.size1_in(f, "p")
(2, 0)
julia> ca.class_name(ca.oracle(dae, true)), ca.name_in(ca.oracle(dae, false, true))
("SXFunction", ["t", "p", "d", "u", "x", "z", "q"])

See also
create, symbolic

Extra doc: https://github.com/casadi/casadi/wiki/L_2mh

Definition at line 862 of file dae_builder.cpp.

862  {
863  try {
864  return (*this)->oracle(sx, elim_w, lifted_calls);
865  } catch (std::exception& e) {
866  THROW_ERROR("oracle", e.what());
867  return Function(); // never reached
868  }
869 }

References casadi::FunctionInternal::oracle().

◆ outputs() [1/2]

std::vector<std::string> casadi::DaeBuilder::outputs ( ) const
inline

Definition at line 930 of file dae_builder.hpp.

930 {return y();}
std::vector< std::string > y() const
Outputs.

◆ outputs() [2/2]

std::vector< MX > casadi::DaeBuilder::outputs ( const std::string &  cat) const

The defining expressions of an equation category, in the order of the corresponding input category: "ode" (right-hand sides of the states x), "alg" (residuals), "quad" (right-hand sides of q), "zero" (zero-crossing functions of the when equations), "ddef" and "wdef" (binding expressions of d and w), "y" (expressions of the outputs).

Parameters
catOne of the output categories above; an input category is an error
Returns
List of expressions, empty when the category is empty

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> z = dae.add("z")
>>> u = dae.add("u", "input")
>>> dae.eq(dae.der(x), -x + z*u)
>>> dae.eq(0, x - 2*z)
>>> dae.outputs("ode"), dae.outputs("alg"), dae.outputs("y")
([MX(((z*u)-x))], [MX((-(x-(2.*z))))], [])
>>> try:
...   dae.outputs("x")
... except Exception as e:
...   print("No input category" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); z = dae.add('z'); u = dae.add('u', 'input');
>> dae.eq(dae.der(x), -x + z*u); dae.eq(0, x - 2*z);
>> cellfun(@disp, dae.outputs('ode')), cellfun(@disp, dae.outputs('alg'))
((z*u)-x)
(-(x-(2.*z)))
>> numel(dae.outputs('y'))
0
>> try, dae.outputs('x'); catch e, disp(contains(e.message, 'No input category')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> z = ca.add(dae, "z");
julia> u = ca.add(dae, "u", "input");
julia> ca.eq(dae, ca.der(dae, x), -x + z*u)
julia> ca.eq(dae, 0, x - 2*z)
julia> ca.outputs(dae, "ode"), ca.outputs(dae, "alg"), ca.outputs(dae, "y")
(MX[((z*u)-x)], MX[(-(x-(2.*z)))], MX[])
julia> try
           ca.outputs(dae, "x")
       catch e
           println(occursin("No input category", sprint(showerror, e)))
       end
true

See also
inputs, wdef, ddef, create

Extra doc: https://github.com/casadi/casadi/wiki/L_2fy

Definition at line 82 of file dae_builder.cpp.

82  {
83  try {
84  return (*this)->outputs(to_enum<Category>(cat));
85  } catch (std::exception& e) {
86  THROW_ERROR("outputs", e.what());
87  return {}; // never reached
88  }
89 }

◆ own()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::own ( Internal *  node)
inherited

Assign the node to a node class pointer (or null)

Definition at line 89 of file generic_shared_impl.hpp.

◆ p()

std::vector<std::string> casadi::DaeBuilder::p ( ) const
inline

Names of the variables of category p (causality "parameter", variability "tunable", floating-point type), in category order. Equivalent to all("p").

>>> dae = DaeBuilder("m")
>>> p = dae.add("p", "parameter", "tunable")
>>> c = dae.add("c", "parameter", "fixed")
>>> u = dae.add("u", "input")
>>> dae.p(), dae.c(), dae.u()
(['p'], ['c'], ['u'])

>> dae = DaeBuilder('m'); p = dae.add('p', 'parameter', 'tunable');
>> c = dae.add('c', 'parameter', 'fixed'); u = dae.add('u', 'input');
>> dae.p(), dae.c(), dae.u()
p
c
u

julia> dae = ca.DaeBuilder("m");
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> c = ca.add(dae, "c", "parameter", "fixed");
julia> u = ca.add(dae, "u", "input");
julia> ca.p(dae), ca.c(dae), ca.u(dae)
(["p"], ["c"], ["u"])

See also
c, u, np, set_variability

Extra doc: https://github.com/casadi/casadi/wiki/L_5o

Definition at line 761 of file dae_builder.hpp.

761 {return all("p");}

References casadi::all().

◆ pack_fmu()

std::string casadi::DaeBuilder::pack_fmu ( const Dict &  files,
const Dict &  opts = Dict() 
)

Zips the entries of files at their archive paths and removes the local files afterwards. Requires a build with WITH_LIBZIP=ON.

Parameters
filesthe {local_file -> archive path} map to pack
optspackaging options: path (default '<name>.fmu')
Returns
Path of the created archive
See also
export_fmu, compile_fmu

Extra doc: https://github.com/casadi/casadi/wiki/L_2ir

Definition at line 229 of file dae_builder.cpp.

229  {
230  try {
231  return (*this)->pack_fmu(files, opts);
232  } catch (std::exception& e) {
233  THROW_ERROR("pack_fmu", e.what());
234  return std::string(); // never reached
235  }
236 }

◆ parse_fmi()

void casadi::DaeBuilder::parse_fmi ( const std::string &  filename)
inline

Import existing problem from FMI/XML, alias of load_fmi_description

Definition at line 2427 of file dae_builder.hpp.

References casadi::filename().

◆ pre() [1/3]

MX casadi::DaeBuilder::pre ( const MX &  v) const

Not implemented: returns the expression unchanged, with a warning the first time. Meant for the value of a variable just before an event, as in reinit("v", -0.8*pre(v)).

See also
reinit, when

Extra doc: https://github.com/casadi/casadi/wiki/L_2lp

Definition at line 474 of file dae_builder.cpp.

474  {
475  try {
476  // Not implemented
477  static bool warned = false;
478  if (!warned) {
479  casadi_warning("DaeBuilder::pre has not been implemented: Returning identity mapping");
480  warned = true;
481  }
482  return v;
483  } catch (std::exception& e) {
484  THROW_ERROR("pre", e.what());
485  return MX(); // never reached
486  }
487 }

◆ pre() [2/3]

std::string casadi::DaeBuilder::pre ( const std::string &  name) const

Definition at line 459 of file dae_builder.cpp.

459  {
460  try {
461  // Not implemented
462  static bool warned = false;
463  if (!warned) {
464  casadi_warning("DaeBuilder::pre has not been implemented: Returning identity mapping");
465  warned = true;
466  }
467  return name;
468  } catch (std::exception& e) {
469  THROW_ERROR("pre", e.what());
470  return std::string(); // never reached
471  }
472 }

References name().

◆ pre() [3/3]

std::vector< std::string > casadi::DaeBuilder::pre ( const std::vector< std::string > &  name) const

Not implemented: returns the names unchanged, with a warning the first time.

See also
reinit

Extra doc: https://github.com/casadi/casadi/wiki/L_2lo

Definition at line 500 of file dae_builder.cpp.

500  {
501  try {
502  std::vector<std::string> r(name.size());
503  for (size_t i = 0; i < r.size(); ++i) r[i] = pre(name[i]);
504  return r;
505  } catch (std::exception& e) {
506  THROW_ERROR("pre", e.what());
507  return {}; // never reached
508  }
509 }
std::vector< std::string > pre(const std::vector< std::string > &name) const
Get the pre-variables of model variables.

References name().

◆ print_ptr()

void casadi::SharedObject::print_ptr ( std::ostream &  stream = casadi::uout()) const
inherited

Print the pointer to the internal class

Definition at line 43 of file shared_object.cpp.

43  {
44  stream << get();
45  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

◆ provides_directional_derivative()

bool casadi::DaeBuilder::provides_directional_derivative ( ) const
inline

Definition at line 2440 of file dae_builder.hpp.

bool provides_directional_derivatives() const
Does the FMU provide support for analytic derivatives.

◆ provides_directional_derivatives()

bool casadi::DaeBuilder::provides_directional_derivatives ( ) const

Reads the providesDirectionalDerivatives flag of an imported FMU. Calling it on a symbolic instance is an error.

See also
symbolic, load_fmi_description

Extra doc: https://github.com/casadi/casadi/wiki/L_2lc

Definition at line 201 of file dae_builder.cpp.

201  {
202  try {
203  casadi_assert(!symbolic(), "Functionality only applies to imported standard FMUs");
204  return (*this)->provides_directional_derivatives_;
205  } catch (std::exception& e) {
206  THROW_ERROR("provides_directional_derivatives", e.what());
207  return false;
208  }
209 }

References symbolic().

◆ prune()

void casadi::DaeBuilder::prune ( bool  prune_p = true,
bool  prune_u = true 
)

Intended to drop the parameters p and/or controls u that do not appear in any model equation from their categories (the variables themselves remain).

Parameters
prune_pConsider the parameters p
prune_uConsider the controls u
See also
p, u

Extra doc: https://github.com/casadi/casadi/wiki/L_2l4

Definition at line 238 of file dae_builder.cpp.

238  {
239  try {
240  (*this)->prune(prune_p, prune_u);
241  } catch (std::exception& e) {
242  THROW_ERROR("prune", e.what());
243  }
244 }

◆ q()

std::vector<std::string> casadi::DaeBuilder::q ( ) const
inline

Names of the variables of category q: differential states that do not appear in any right-hand side. Equivalent to all("q"). A state is only placed here by set_category(name, "q") or automatically with the constructor option "detect_quad".

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> q = dae.add("q")
>>> dae.eq(dae.der(x), -x)
>>> dae.eq(dae.der(q), x**2)
>>> dae.x(), dae.q()
(['x', 'q'], [])
>>> dae.set_category("q", "q")
>>> dae.x(), dae.q(), dae.outputs("quad")
(['x'], ['q'], [MX(sq(x))])

>> dae = DaeBuilder('m'); x = dae.add('x'); q = dae.add('q');
>> dae.eq(dae.der(x), -x); dae.eq(dae.der(q), x^2);
>> dae.x(), isempty(dae.q())
x
q
1
>> dae.set_category('q', 'q');
>> disp(dae.x()), disp(dae.q()), cellfun(@disp, dae.outputs('quad'))
x
q
sq(x)

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> q = ca.add(dae, "q");
julia> ca.eq(dae, ca.der(dae, x), -x)
julia> ca.eq(dae, ca.der(dae, q), x^2)
julia> ca.x(dae), ca.q(dae)
(["x", "q"], String[])
julia> ca.set_category(dae, "q", "q")
julia> ca.x(dae), ca.q(dae), ca.outputs(dae, "quad")
(["x"], ["q"], MX[sq(x)])

See also
set_category, x, nq

Extra doc: https://github.com/casadi/casadi/wiki/L_2fw

Definition at line 555 of file dae_builder.hpp.

555 {return all("q");}

References casadi::all().

◆ quad()

std::vector<MX> casadi::DaeBuilder::quad ( ) const
inline

Definition at line 698 of file dae_builder.hpp.

698 {return outputs("quad");}

◆ reinit()

std::string casadi::DaeBuilder::reinit ( const std::string &  name,
const MX &  val 
)

Creates a helper variable holding the new value val of the state name after the event, and returns the helper's name for use in when. Use pre(v) for the value before the event (currently an identity mapping).

Parameters
nameModel variable that is reinitialized
valExpression in model variables
Returns
Name of the created variable, e.g. __reinit__v__0

>>> dae = DaeBuilder("ball")
>>> h = dae.add("h", dict(start=5))
>>> v = dae.add("v", dict(start=0))
>>> dae.eq(dae.der(h), v)
>>> dae.eq(dae.der(v), -9.81)
>>> r = dae.reinit("v", -0.8*v)
>>> r, dae.category(r)
('__reinit__v__0', 'calculated')
>>> dae.when(h < 0, [r])
>>> dae.nzero()
1

>> dae = DaeBuilder('ball');
>> h = dae.add('h', struct('start', 5)); v = dae.add('v', struct('start', 0));
>> dae.eq(dae.der(h), v); dae.eq(dae.der(v), -9.81);
>> r = dae.reinit('v', -0.8*v); disp(r), disp(dae.category(r))
__reinit__v__0
calculated
>> dae.when(h < 0, {r}); disp(dae.nzero())
1

julia> dae = ca.DaeBuilder("ball");
julia> h = ca.add(dae, "h", Dict("start" => 5));
julia> v = ca.add(dae, "v", Dict("start" => 0));
julia> ca.eq(dae, ca.der(dae, h), v)
julia> ca.eq(dae, ca.der(dae, v), -9.81)
julia> r = ca.reinit(dae, "v", -0.8*v);
julia> r, ca.category(dae, r)
("__reinit__v__0", "calculated")
julia> ca.when(dae, h < 0, [r])
julia> ca.nzero(dae)
1

See also
when, assign, pre

Extra doc: https://github.com/casadi/casadi/wiki/L_2kw

Definition at line 410 of file dae_builder.cpp.

410  {
411  try {
412  return (*this)->reinit(name, val).name;
413  } catch (std::exception& e) {
414  THROW_ERROR("reinit", e.what());
415  return std::string(); // never reached
416  }
417 }

References name().

◆ reorder()

void casadi::DaeBuilder::reorder ( const std::string &  cat,
const std::vector< std::string > &  v 
)

Replaces the ordering of a category by v, which must be a permutation of the current members: a missing or extra name is an error. The ordering determines the order of the entries in the vectors used by create (e.g. of x and ode).

Parameters
catCategory name, e.g. "x"
vAll current members of the category, in the new order

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> dae.eq(dae.der(x), -y)
>>> dae.eq(dae.der(y), x)
>>> dae.x(), dae.outputs("ode")
(['x', 'y'], [MX((-y)), MX(x)])
>>> dae.reorder("x", ["y", "x"])
>>> dae.x(), dae.outputs("ode")
(['y', 'x'], [MX(x), MX((-y))])
>>> try:
...   dae.reorder("x", ["y"])
... except Exception as e:
...   print("1 elements provided for 2 components" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> dae.eq(dae.der(x), -y); dae.eq(dae.der(y), x);
>> disp(dae.x()), cellfun(@disp, dae.outputs('ode'))
x
y
(-y)
x
>> dae.reorder('x', {'y', 'x'});
>> disp(dae.x()), cellfun(@disp, dae.outputs('ode'))
y
x
x
(-y)
>> try, dae.reorder('x', {'y'}); catch e, msg = e.message; end
>> contains(msg, '1 elements provided for 2 components')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> ca.eq(dae, ca.der(dae, x), -y)
julia> ca.eq(dae, ca.der(dae, y), x)
julia> ca.x(dae), ca.outputs(dae, "ode")
(["x", "y"], MX[(-y), x])
julia> ca.reorder(dae, "x", ["y", "x"])
julia> ca.x(dae), ca.outputs(dae, "ode")
(["y", "x"], MX[x, (-y)])
julia> try
           ca.reorder(dae, "x", ["y"])
       catch e
           println(occursin("1 elements provided for 2 components", sprint(showerror, e)))
       end
true

See also
set_all, all

Extra doc: https://github.com/casadi/casadi/wiki/L_2kz

Definition at line 333 of file dae_builder.cpp.

333  {
334  try {
335  (*this)->reorder(to_enum<Category>(cat), (*this)->find(v));
336  } catch (std::exception& e) {
337  THROW_ERROR("reorder", e.what());
338  }
339 }

Referenced by set_all().

◆ reset()

void casadi::DaeBuilder::reset ( )

Resets the current value of every variable to nan (empty for string variables); the start attributes are kept.

See also
set, get

Extra doc: https://github.com/casadi/casadi/wiki/L_2m9

Definition at line 1110 of file dae_builder.cpp.

1110  {
1111  try {
1112  (*this)->reset();
1113  } catch (std::exception& e) {
1114  THROW_ERROR("reset", e.what());
1115  }
1116 }

◆ sanity_check()

void casadi::DaeBuilder::sanity_check ( ) const

Raises an error if there is more than one independent variable or if it is not scalar. Called by disp with more set and by add_lc.

>>> dae = DaeBuilder("m")
>>> dae.sanity_check()

>> dae = DaeBuilder('m');
>> dae.sanity_check()

julia> dae = ca.DaeBuilder("m");
julia> ca.sanity_check(dae)

Extra doc: https://github.com/casadi/casadi/wiki/L_2ky

Definition at line 427 of file dae_builder.cpp.

427  {
428  try {
429  (*this)->sanity_check();
430  } catch (std::exception& e) {
431  THROW_ERROR("sanity_check", e.what());
432  }
433 }

◆ set() [1/4]

void casadi::DaeBuilder::set ( const std::string &  name,
const std::string &  val 
)

Definition at line 1126 of file dae_builder.cpp.

1126  {
1127  try {
1128  (*this)->set_string_attribute(Attribute::STRINGVALUE, name, val);
1129  } catch (std::exception& e) {
1130  THROW_ERROR("set", e.what());
1131  }
1132 }

References name(), and casadi::STRINGVALUE.

◆ set() [2/4]

void casadi::DaeBuilder::set ( const std::string &  name,
double  val 
)

The current value is what get returns and what create substitutes for the constants c; set it before creating functions. A variable's current value is initialized from its "start" option and is nan when unset. A vector-valued variable gets all elements set.

>>> dae = DaeBuilder("m")
>>> c = dae.add("c", "parameter", "fixed")
>>> x = dae.add("x", dict(start=1))
>>> v = dae.add("v", dict(dimension=[2]))
>>> s = dae.add("s", dict(type="String"))
>>> dae.get("c"), dae.get("x"), dae.get("v"), repr(dae.get("s"))
(nan, 1.0, [nan, nan], "''")
>>> dae.set("c", 2.5)
>>> dae.set("v", 1)
>>> dae.set("s", "hello")
>>> dae.get(["c", "v", "s"])
[2.5, [1.0, 1.0], 'hello']
>>> dae.set(["c", "x"], [3, 4])
>>> dae.set(["v"], [5, 6])
>>> dae.get(["c", "x", "v"])
[3.0, 4.0, [5.0, 6.0]]
>>> dae.reset()
>>> dae.get(["c", "x"])
[nan, nan]

>> dae = DaeBuilder('m'); c = dae.add('c', 'parameter', 'fixed');
>> x = dae.add('x', struct('start', 1)); v = dae.add('v', struct('dimension', 2));
>> s = dae.add('s', struct('type', 'String'));
>> val = dae.get({'c', 'x', 'v', 's'});
>> val{1}, val{2}, val{3}, isempty(val{4})
NaN
1
NaN NaN
1
>> dae.set('c', 2.5); dae.set('v', 1); dae.set('s', 'hello');
>> val = dae.get({'c', 'v', 's'}); disp(val{1}), disp(val{2}), disp(val{3})
2.5000
1 1
hello
>> dae.set({'c', 'x'}, [3 4]); dae.set({'v'}, [5 6]);
>> val = dae.get({'c', 'x', 'v'}); disp(val{1}), disp(val{2}), disp(val{3})
3
4
5 6

julia> dae = ca.DaeBuilder("m");
julia> c = ca.add(dae, "c", "parameter", "fixed");
julia> x = ca.add(dae, "x", Dict("start" => 1));
julia> v = ca.add(dae, "v", Dict("dimension" => [2]));
julia> s = ca.add(dae, "s", Dict("type" => "String"));
julia> ca.get(dae, "c"), ca.get(dae, "x"), ca.get(dae, "v"), ca.get(dae, "s")
(NaN, 1.0, [NaN, NaN], "")
julia> ca.set(dae, "c", 2.5)
julia> ca.set(dae, "v", 1)
julia> ca.set(dae, "s", "hello")
julia> ca.get(dae, ["c", "v", "s"])
3-element Vector{Any}:
 2.5
  [1.0, 1.0]
  "hello"
julia> ca.set(dae, ["c", "x"], [3, 4])
julia> ca.set(dae, ["v"], [5, 6])
julia> ca.get(dae, ["c", "x", "v"])
3-element Vector{Any}:
 3.0
 4.0
  [5.0, 6.0]
julia> ca.reset(dae)
julia> ca.get(dae, ["c", "x"])
2-element Vector{Any}:
 NaN
 NaN

The value of a constant is baked into the functions created afterwards:

>>> dae = DaeBuilder("m")
>>> c = dae.add("c", "parameter", "fixed")
>>> x = dae.add("x")
>>> dae.eq(dae.der(x), -c*x)
>>> dae.set("c", 3)
>>> dae.create("f", ["x"], ["ode"])(2)
DM(-6)

>> dae = DaeBuilder('m'); c = dae.add('c', 'parameter', 'fixed'); x = dae.add('x');
>> dae.eq(dae.der(x), -c*x);
>> dae.set('c', 3);
>> f = dae.create('f', {'x'}, {'ode'}); disp(f(2))
-6

julia> dae = ca.DaeBuilder("m");
julia> c = ca.add(dae, "c", "parameter", "fixed");
julia> x = ca.add(dae, "x");
julia> ca.eq(dae, ca.der(dae, x), -c*x)
julia> ca.set(dae, "c", 3)
julia> ca.create(dae, "f", ["x"], ["ode"])(2)
DM(-6)

See also
get, reset, start, c

Extra doc: https://github.com/casadi/casadi/wiki/L_2ma

Definition at line 1118 of file dae_builder.cpp.

1118  {
1119  try {
1120  (*this)->set_attribute(Attribute::VALUE, name, val);
1121  } catch (std::exception& e) {
1122  THROW_ERROR("set", e.what());
1123  }
1124 }

References name(), and casadi::VALUE.

◆ set() [3/4]

void casadi::DaeBuilder::set ( const std::vector< std::string > &  name,
const std::vector< double > &  val 
)

Definition at line 1134 of file dae_builder.cpp.

1134  {
1135  try {
1136  (*this)->set_attribute(Attribute::VALUE, name, val);
1137  } catch (std::exception& e) {
1138  THROW_ERROR("set", e.what());
1139  }
1140 }

References name(), and casadi::VALUE.

◆ set() [4/4]

void casadi::DaeBuilder::set ( const std::vector< std::string > &  name,
const std::vector< std::string > &  val 
)

Definition at line 1142 of file dae_builder.cpp.

1143  {
1144  try {
1145  (*this)->set_string_attribute(Attribute::STRINGVALUE, name, val);
1146  } catch (std::exception& e) {
1147  THROW_ERROR("set", e.what());
1148  }
1149 }

References name(), and casadi::STRINGVALUE.

◆ set_all()

void casadi::DaeBuilder::set_all ( const std::string &  v,
const std::vector< std::string > &  name 
)

Makes name the complete, ordered content of category v, moving variables in and out as needed:

  • "y": the listed variables get causality "output", all other outputs become "local"
  • "u", "p", "c": the listed variables are moved into the category with set_category; members not listed become constants c (for "u" and "p")
  • "x", "q": the listed states are moved in; members not listed lose their category (they must not appear in any right-hand side)

Other categories and duplicate names are an error. Names not permitted in the category raise the error of set_category.

Parameters
vCategory name
nameVariables that should form the category, in order

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> u1 = dae.add("u1", "input")
>>> p1 = dae.add("p1", "parameter", "tunable")
>>> dae.eq(dae.der(x), -x + u1*p1)
>>> dae.set_all("u", ["p1", "u1"])
>>> dae.u(), dae.p(), dae.c()
(['p1', 'u1'], [], [])
>>> dae.set_all("p", ["u1"])
>>> dae.u(), dae.p(), dae.c()
(['p1'], ['u1'], [])
>>> dae.set_all("y", ["x"])
>>> dae.y(), dae.causality("x")
(['x'], 'output')
>>> try:
...   dae.set_all("x", ["x", "x"])
... except Exception as e:
...   print("Duplicate names" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); u1 = dae.add('u1', 'input');
>> p1 = dae.add('p1', 'parameter', 'tunable');
>> dae.eq(dae.der(x), -x + u1*p1);
>> dae.set_all('u', {'p1', 'u1'});
>> dae.u(), isempty(dae.p()), isempty(dae.c())
p1
u1
1
1
>> dae.set_all('p', {'u1'});
>> dae.u(), dae.p()
p1
u1
>> dae.set_all('y', {'x'});
>> dae.y(), dae.causality('x')
x
output
>> try, dae.set_all('x', {'x', 'x'}); catch e, msg = e.message; end
>> contains(msg, 'Duplicate names')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> u1 = ca.add(dae, "u1", "input");
julia> p1 = ca.add(dae, "p1", "parameter", "tunable");
julia> ca.set_all(dae, "u", ["p1", "u1"])
julia> ca.u(dae), ca.p(dae), ca.c(dae)
(["p1", "u1"], String[], String[])
julia> ca.set_all(dae, "p", ["u1"])
julia> ca.u(dae), ca.p(dae), ca.c(dae)
(["p1"], ["u1"], String[])
julia> ca.set_all(dae, "y", ["x"])
julia> ca.y(dae), ca.causality(dae, "x")
(["x"], "output")
julia> try
           ca.set_all(dae, "x", ["x", "x"])
       catch e
           println(occursin("Duplicate names", sprint(showerror, e)))
       end
true

See also
reorder, set_category, set_causality

Extra doc: https://github.com/casadi/casadi/wiki/L_2l0

Definition at line 281 of file dae_builder.cpp.

281  {
282  try {
283  // Get category enum
284  auto cat = to_enum<Category>(v);
285 
286  // Make sure no duplicate names
287  std::set<std::string> name_set(name.begin(), name.end());
288  casadi_assert(name_set.size() == name.size(), "Duplicate names");
289 
290  // For outputs, update causality
291  if (is_output_category(cat)) {
292  if (cat == Category::Y) {
293  for (auto&& n : name) set_causality(n, "output");
294  if (ny() != name.size()) {
295  for (auto&& n : y()) {
296  if (name_set.find(n) == name_set.end()) set_causality(n, "local");
297  }
298  }
299  } else {
300  casadi_error("Setting category '" + v + "' not supported");
301  }
302  } else if (is_input_category(cat)) {
303  // Update category
304  for (auto&& n : name) set_category(n, v);
305  // Remove any variables not in name from the category
306  auto all_in_cat = all(v);
307  if (all_in_cat.size() != name.size()) {
308  std::set<std::string> name_set(name.begin(), name.end());
309  for (auto&& n : all_in_cat) {
310  if (name_set.find(n) == name_set.end()) {
311  if (v == "x" || v == "q") {
312  // Move to unused derivatives
313  set_category(n, "");
314  } else if (v == "u" || v == "p") {
315  // Make constant
316  set_category(n, "c");
317  } else {
318  casadi_error("Cannot automatically remove '" + n + "' from category '" + v + "'");
319  }
320  }
321  }
322  }
323  } else {
324  casadi_error("Cannot set variables of category '" + v + "'");
325  }
326  // Make sure ordering is correct
327  reorder(v, name);
328  } catch (std::exception& e) {
329  THROW_ERROR("set_all", e.what());
330  }
331 }
void reorder(const std::string &cat, const std::vector< std::string > &v)
Reorder variables in a category.
void set_category(const std::string &name, const std::string &val)
Set the variable category, if permitted.
void set_causality(const std::string &name, const std::string &val)
Set the causality, if permitted.
casadi_int ny() const
Output variables.
bool is_input_category(Category cat)
bool is_output_category(Category cat)

References all(), casadi::is_input_category(), casadi::is_output_category(), name(), ny(), reorder(), set_category(), set_causality(), y(), and casadi::Y.

◆ set_attribute() [1/2]

void casadi::DaeBuilder::set_attribute ( const std::string &  a,
const std::string &  name,
double  val 
)

Definition at line 949 of file dae_builder.cpp.

949  {
950  try {
951  (*this)->set_attribute(to_enum<Attribute>(a), name, val);
952  } catch (std::exception& e) {
953  THROW_ERROR("set_attribute", e.what());
954  }
955 }

References name().

◆ set_attribute() [2/2]

void casadi::DaeBuilder::set_attribute ( const std::string &  a,
const std::vector< std::string > &  name,
const std::vector< double > &  val 
)

Definition at line 957 of file dae_builder.cpp.

958  {
959  try {
960  (*this)->set_attribute(to_enum<Attribute>(a), name, val);
961  } catch (std::exception& e) {
962  THROW_ERROR("set_attribute", e.what());
963  }
964 }

References name().

◆ set_category()

void casadi::DaeBuilder::set_category ( const std::string &  name,
const std::string &  val 
)

The following changes are permitted:

  • Controls u can be changed to/from tunable parameters p or fixed parameters c
  • Differential states that do not appear in the right-hand-sides can be changed between regular states x, quadrature states q and no category (empty string)
  • A state can be made the independent variable t, replacing the current one

Other changes are not permitted. Causality and variability is updated accordingly.

>>> dae = DaeBuilder("m")
>>> u = dae.add("u", "input")
>>> x = dae.add("x")
>>> q = dae.add("q")
>>> dae.eq(dae.der(x), -x)
>>> dae.eq(dae.der(q), x**2)
>>> dae.set_category("q", "q")
>>> dae.x(), dae.q()
(['x'], ['q'])
>>> dae.set_category("q", "")
>>> dae.x(), dae.q(), dae.category("q")
(['x'], [], '')
>>> dae.set_category("u", "p")
>>> dae.u(), dae.p(), dae.causality("u"), dae.variability("u")
([], ['u'], 'parameter', 'tunable')
>>> try:
...   dae.set_category("x", "q")
... except Exception as e:
...   print("Cannot change category of x from 'x' to 'q'" in str(e))
True

>> dae = DaeBuilder('m'); u = dae.add('u', 'input'); x = dae.add('x'); q = dae.add('q');
>> dae.eq(dae.der(x), -x); dae.eq(dae.der(q), x^2);
>> dae.set_category('q', 'q');
>> dae.x(), dae.q()
x
q
>> dae.set_category('q', '');
>> dae.x(), isempty(dae.q()), isempty(dae.category('q'))
x
1
1
>> dae.set_category('u', 'p');
>> isempty(dae.u()), dae.p()
1
u
>> dae.causality('u'), dae.variability('u')
parameter
tunable
>> try, dae.set_category('x', 'q'); catch e, msg = e.message; end
>> contains(msg, 'Cannot change category of x from ''x'' to ''q''')
1

julia> dae = ca.DaeBuilder("m");
julia> u = ca.add(dae, "u", "input");
julia> x = ca.add(dae, "x");
julia> q = ca.add(dae, "q");
julia> ca.eq(dae, ca.der(dae, x), -x)
julia> ca.eq(dae, ca.der(dae, q), x^2)
julia> ca.set_category(dae, "q", "q")
julia> ca.x(dae), ca.q(dae)
(["x"], ["q"])
julia> ca.set_category(dae, "q", "")
julia> ca.x(dae), ca.q(dae), ca.category(dae, "q")
(["x"], String[], "")
julia> ca.set_category(dae, "u", "p")
julia> ca.u(dae), ca.p(dae), ca.causality(dae, "u"), ca.variability(dae, "u")
(String[], ["u"], "parameter", "tunable")
julia> try
           ca.set_category(dae, "x", "q")
       catch e
           println(occursin("Cannot change category of x from 'x' to 'q'", sprint(showerror, e)))
       end
true

See also
category, categories, set_all

Extra doc: https://github.com/casadi/casadi/wiki/L_2c4

Definition at line 646 of file dae_builder.cpp.

646  {
647  try {
648  (*this)->set_category((*this)->find(name),
649  val.empty() ? Category::NUMEL : to_enum<Category>(val));
650  } catch (std::exception& e) {
651  THROW_ERROR("set_category", e.what());
652  }
653 }

References name(), and casadi::NUMEL.

Referenced by set_all().

◆ set_causality()

void casadi::DaeBuilder::set_causality ( const std::string &  name,
const std::string &  val 
)

The following changes are permitted:

  • For controls u (variability "continuous", causality "input"), free parameters p (variability "tunable", causality "parameter") and fixed parameters c (variability "fixed", causality "parameter"), causality can only be changed indirectly, by updating the variability
  • Add or remove an output y by setting the causality to "output" or "local", respectively

No other changes are permitted.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y", "output")
>>> dae.eq(dae.der(x), -x)
>>> dae.eq(y, 2*x)
>>> dae.set_causality("y", "local")
>>> dae.set_causality("x", "output")
>>> dae.y(), dae.causality("y")
(['x'], 'local')
>>> try:
...   dae.set_causality("x", "input")
... except Exception as e:
...   print("Cannot change causality" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y', 'output');
>> dae.eq(dae.der(x), -x); dae.eq(y, 2*x);
>> dae.set_causality('y', 'local'); dae.set_causality('x', 'output');
>> dae.y(), dae.causality('y')
x
local
>> try, dae.set_causality('x', 'input'); catch e, msg = e.message; end
>> contains(msg, 'Cannot change causality')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y", "output");
julia> ca.eq(dae, y, 2*x)
julia> ca.set_causality(dae, "y", "local")
julia> ca.set_causality(dae, "x", "output")
julia> ca.y(dae), ca.causality(dae, "y")
(["x"], "local")
julia> try
           ca.set_causality(dae, "x", "input")
       catch e
           println(occursin("Cannot change causality", sprint(showerror, e)))
       end
true

See also
causality, set_variability, set_category, set_all

Extra doc: https://github.com/casadi/casadi/wiki/L_2c2

Definition at line 612 of file dae_builder.cpp.

612  {
613  try {
614  (*this)->set_causality((*this)->find(name), to_enum<Causality>(val));
615  } catch (std::exception& e) {
616  THROW_ERROR("set_causality", e.what());
617  }
618 }

References name().

Referenced by set_all().

◆ set_description()

void casadi::DaeBuilder::set_description ( const std::string &  name,
const std::string &  val 
)

Free-text description of a variable, also settable with the "description" option of add.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(description="position"))
>>> dae.description("x")
'position'
>>> dae.set_description("x", "height")
>>> dae.description("x")
'height'

>> dae = DaeBuilder('m'); x = dae.add('x', struct('description', 'position'));
>> dae.description('x')
position
>> dae.set_description('x', 'height');
>> dae.description('x')
height

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("description" => "position"));
julia> ca.description(dae, "x")
"position"
julia> ca.set_description(dae, "x", "height")
julia> ca.description(dae, "x")
"height"

Extra doc: https://github.com/casadi/casadi/wiki/L_2lt

Definition at line 566 of file dae_builder.cpp.

566  {
567  (*this)->variable(name).description = val;
568 }

References name().

◆ set_display_unit()

void casadi::DaeBuilder::set_display_unit ( const std::string &  name,
const std::string &  val 
)

Display unit string of a variable; empty by default. Also settable with the "display_unit" option of add.

Extra doc: https://github.com/casadi/casadi/wiki/L_2m1

Definition at line 675 of file dae_builder.cpp.

675  {
676  (*this)->variable(name).display_unit = val;
677 }

References name().

◆ set_init()

void casadi::DaeBuilder::set_init ( const std::string &  name,
const MX &  init_rhs 
)

Sets name == init_rhs as initial equation, replacing any previous one for the same variable. An empty init_rhs removes the initial equation.

Parameters
nameModel variable
init_rhsExpression in model variables, or an empty expression to remove

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> p = dae.add("p", "parameter", "tunable")
>>> dae.eq(dae.der(x), -x)
>>> dae.init_lhs(), dae.init_rhs()
([], [])
>>> dae.set_init("x", 2*p)
>>> dae.init_lhs(), dae.init_rhs()
([MX(x)], [MX((2.*p))])
>>> dae.set_init("x", MX())
>>> dae.init_lhs(), dae.init_rhs()
([], [])

>> dae = DaeBuilder('m'); x = dae.add('x'); p = dae.add('p', 'parameter', 'tunable');
>> dae.eq(dae.der(x), -x);
>> numel(dae.init_lhs()), numel(dae.init_rhs())
0
0
>> dae.set_init('x', 2*p);
>> cellfun(@disp, dae.init_lhs()), cellfun(@disp, dae.init_rhs())
x
(2.*p)
>> dae.set_init('x', MX());
>> numel(dae.init_lhs()), numel(dae.init_rhs())
0
0

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> ca.init_lhs(dae), ca.init_rhs(dae)
(MX[], MX[])
julia> ca.set_init(dae, "x", 2*p)
julia> ca.init_lhs(dae), ca.init_rhs(dae)
(MX[x], MX[(2.*p)])
julia> ca.set_init(dae, "x", ca.MX())
julia> ca.init_lhs(dae), ca.init_rhs(dae)
(MX[], MX[])

See also
init_lhs, init_rhs

Extra doc: https://github.com/casadi/casadi/wiki/L_2kx

Definition at line 419 of file dae_builder.cpp.

419  {
420  try {
421  (*this)->set_init(name, init_rhs);
422  } catch (std::exception& e) {
423  THROW_ERROR("set_init", e.what());
424  }
425 }
std::vector< MX > init_rhs() const
Initial conditions, right-hand-side.

References init_rhs(), and name().

◆ set_initial()

void casadi::DaeBuilder::set_initial ( const std::string &  name,
const std::string &  val 
)

The FMI initial attribute: "exact", "approx", "calculated" or "na". The default follows from causality and variability per the FMI specification; it can be given with the "initial" option of add. Other values are an error.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(initial="approx"))
>>> p = dae.add("p", "parameter", "tunable")
>>> u = dae.add("u", "input")
>>> dae.initial("x"), dae.initial("p"), dae.initial("u")
('approx', 'exact', 'na')
>>> dae.set_initial("x", "exact")
>>> dae.initial("x")
'exact'

>> dae = DaeBuilder('m'); x = dae.add('x', struct('initial', 'approx'));
>> p = dae.add('p', 'parameter', 'tunable'); u = dae.add('u', 'input');
>> dae.initial('x'), dae.initial('p'), dae.initial('u')
approx
exact
na
>> dae.set_initial('x', 'exact');
>> dae.initial('x')
exact

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("initial" => "approx"));
julia> p = ca.add(dae, "p", "parameter", "tunable");
julia> u = ca.add(dae, "u", "input");
julia> ca.initial(dae, "x"), ca.initial(dae, "p"), ca.initial(dae, "u")
("approx", "exact", "na")
julia> dae.set_initial("x", "exact")
julia> ca.initial(dae, "x")
"exact"

Extra doc: https://github.com/casadi/casadi/wiki/L_2lz

Definition at line 659 of file dae_builder.cpp.

659  {
660  (*this)->variable(name).initial = to_enum<Initial>(val);
661 }

References name().

◆ set_max() [1/2]

void casadi::DaeBuilder::set_max ( const std::string &  name,
double  val 
)

Definition at line 1018 of file dae_builder.cpp.

1018  {
1019  try {
1020  (*this)->variable(name).max = val;
1021  } catch (std::exception& e) {
1022  THROW_ERROR("set_max", e.what());
1023  }
1024 }

References name().

◆ set_max() [2/2]

void casadi::DaeBuilder::set_max ( const std::vector< std::string > &  name,
const std::vector< double > &  val 
)

Definition at line 1026 of file dae_builder.cpp.

1026  {
1027  try {
1028  (*this)->set_attribute(Attribute::MAX, name, val);
1029  } catch (std::exception& e) {
1030  THROW_ERROR("set_max", e.what());
1031  }
1032 }

References casadi::MAX, and name().

◆ set_min() [1/2]

void casadi::DaeBuilder::set_min ( const std::string &  name,
double  val 
)

Definition at line 984 of file dae_builder.cpp.

984  {
985  try {
986  (*this)->variable(name).min = val;
987  } catch (std::exception& e) {
988  THROW_ERROR("set_min", e.what());
989  }
990 }

References name().

◆ set_min() [2/2]

void casadi::DaeBuilder::set_min ( const std::vector< std::string > &  name,
const std::vector< double > &  val 
)

Definition at line 992 of file dae_builder.cpp.

992  {
993  try {
994  (*this)->set_attribute(Attribute::MIN, name, val);
995  } catch (std::exception& e) {
996  THROW_ERROR("set_min", e.what());
997  }
998 }

References casadi::MIN, and name().

◆ set_nominal() [1/2]

void casadi::DaeBuilder::set_nominal ( const std::string &  name,
double  val 
)

Definition at line 1052 of file dae_builder.cpp.

1052  {
1053  try {
1054  (*this)->variable(name).nominal = val;
1055  } catch (std::exception& e) {
1056  THROW_ERROR("set_nominal", e.what());
1057  }
1058 }

References name().

◆ set_nominal() [2/2]

void casadi::DaeBuilder::set_nominal ( const std::vector< std::string > &  name,
const std::vector< double > &  val 
)

Definition at line 1060 of file dae_builder.cpp.

1060  {
1061  try {
1062  (*this)->set_attribute(Attribute::NOMINAL, name, val);
1063  } catch (std::exception& e) {
1064  THROW_ERROR("set_mininal", e.what());
1065  }
1066 }

References name(), and casadi::NOMINAL.

◆ set_start() [1/3]

void casadi::DaeBuilder::set_start ( const std::string &  name,
const std::vector< double > &  val 
)

Definition at line 1094 of file dae_builder.cpp.

1094  {
1095  try {
1096  (*this)->set_attribute(Attribute::START, std::vector<std::string>{name}, val);
1097  } catch (std::exception& e) {
1098  THROW_ERROR("set_start", e.what());
1099  }
1100 }

References name(), and casadi::START.

◆ set_start() [2/3]

void casadi::DaeBuilder::set_start ( const std::string &  name,
double  val 
)

Definition at line 1086 of file dae_builder.cpp.

1086  {
1087  try {
1088  (*this)->set_attribute(Attribute::START, name, val);
1089  } catch (std::exception& e) {
1090  THROW_ERROR("set_start", e.what());
1091  }
1092 }

References name(), and casadi::START.

◆ set_start() [3/3]

void casadi::DaeBuilder::set_start ( const std::vector< std::string > &  name,
const std::vector< double > &  val 
)

val holds either one value per variable (broadcast over the elements) or one value per element of all variables concatenated; any other length is an error.

Extra doc: https://github.com/casadi/casadi/wiki/L_2md

Definition at line 1102 of file dae_builder.cpp.

1102  {
1103  try {
1104  (*this)->set_attribute(Attribute::START, name, val);
1105  } catch (std::exception& e) {
1106  THROW_ERROR("set_start", e.what());
1107  }
1108 }

References name(), and casadi::START.

◆ set_start_time()

void casadi::DaeBuilder::set_start_time ( double  val)

Definition at line 696 of file dae_builder.cpp.

696  {
697  try {
698  (*this)->start_time_ = val;
699  } catch (std::exception& e) {
700  THROW_ERROR("set_start_time", e.what());
701  }
702 }

◆ set_step_size()

void casadi::DaeBuilder::set_step_size ( double  val)

Definition at line 747 of file dae_builder.cpp.

747  {
748  try {
749  (*this)->step_size_ = val;
750  } catch (std::exception& e) {
751  THROW_ERROR("set_step_size", e.what());
752  }
753 }

◆ set_stop_time()

void casadi::DaeBuilder::set_stop_time ( double  val)

Definition at line 713 of file dae_builder.cpp.

713  {
714  try {
715  (*this)->stop_time_ = val;
716  } catch (std::exception& e) {
717  THROW_ERROR("set_stop_time", e.what());
718  }
719 }

◆ set_tolerance()

void casadi::DaeBuilder::set_tolerance ( double  val)

Definition at line 730 of file dae_builder.cpp.

730  {
731  try {
732  (*this)->tolerance_ = val;
733  } catch (std::exception& e) {
734  THROW_ERROR("set_tolerance", e.what());
735  }
736 }

◆ set_type()

void casadi::DaeBuilder::set_type ( const std::string &  name,
const std::string &  val 
)

The variable type in FMI 3 naming ("Float64", "Float32", "Int32", "Boolean", "String", ...) or, with fmi_version 2, in FMI 2 naming ("real", "integer", "boolean", "string", "enum"). Setting accepts FMI 3 names; other versions or names are an error.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> n = dae.add("n", dict(type="Int32"))
>>> dae.type("x"), dae.type("x", 2), dae.type("n"), dae.type("n", 2)
('Float64', 'real', 'Int32', 'integer')
>>> dae.set_type("x", "Float32")
>>> dae.type("x")
'Float32'
>>> try:
...   dae.set_type("x", "bogus")
... except Exception as e:
...   print("No such enum" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); n = dae.add('n', struct('type', 'Int32'));
>> dae.type('x'), dae.type('x', 2), dae.type('n'), dae.type('n', 2)
Float64
real
Int32
integer
>> dae.set_type('x', 'Float32');
>> dae.type('x')
Float32
>> try, dae.set_type('x', 'bogus'); catch e, disp(contains(e.message, 'No such enum')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> n = ca.add(dae, "n", Dict("type" => "Int32"));
julia> ca.type(dae, "x"), ca.type(dae, "x", 2), ca.type(dae, "n"), ca.type(dae, "n", 2)
("Float64", "real", "Int32", "integer")
julia> ca.set_type(dae, "x", "Float32")
julia> ca.type(dae, "x")
"Float32"
julia> try
           ca.set_type(dae, "x", "bogus")
       catch e
           println(occursin("No such enum", sprint(showerror, e)))
       end
true

Extra doc: https://github.com/casadi/casadi/wiki/L_2lu

Definition at line 581 of file dae_builder.cpp.

581  {
582  // Fallback to FMI 2, if necessary
583  if (has_enum<TypeFmi2>(val) && !has_enum<Type>(val)) {
584  (*this)->variable(name).type = from_fmi2(to_enum<TypeFmi2>(val));
585  }
586  // Assume FMI 3
587  (*this)->variable(name).type = to_enum<Type>(val);
588 }
Type from_fmi2(TypeFmi2 v)

References casadi::from_fmi2(), and name().

◆ set_unit()

void casadi::DaeBuilder::set_unit ( const std::string &  name,
const std::string &  val 
)

Unit string of a variable, e.g. "m/s"; empty by default. Also settable with the "unit" option of add.

>>> dae = DaeBuilder("m")
>>> v = dae.add("v", dict(unit="m/s"))
>>> dae.unit("v")
'm/s'
>>> dae.set_unit("v", "km/h")
>>> dae.unit("v")
'km/h'

>> dae = DaeBuilder('m'); v = dae.add('v', struct('unit', 'm/s'));
>> dae.unit('v')
m/s
>> dae.set_unit('v', 'km/h');
>> dae.unit('v')
km/h

julia> dae = ca.DaeBuilder("m");
julia> v = ca.add(dae, "v", Dict("unit" => "m/s"));
julia> ca.unit(dae, "v")
"m/s"
julia> ca.set_unit(dae, "v", "km/h")
julia> ca.unit(dae, "v")
"km/h"

Extra doc: https://github.com/casadi/casadi/wiki/L_2m0

Definition at line 667 of file dae_builder.cpp.

667  {
668  (*this)->variable(name).unit = val;
669 }

References name().

◆ set_value_reference()

void casadi::DaeBuilder::set_value_reference ( const std::string &  name,
casadi_int  val 
)

The FMI value reference of a variable: imported from the model description, or by default the index of the variable in the instance.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> dae.value_reference("x"), dae.value_reference("y")
(1, 2)
>>> dae.set_value_reference("x", 100)
>>> dae.value_reference("x")
100

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> dae.value_reference('x'), dae.value_reference('y')
1
2
>> dae.set_value_reference('x', 100);
>> dae.value_reference('x')
100

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> ca.value_reference(dae, "x"), ca.value_reference(dae, "y")
(1, 2)
julia> ca.set_value_reference(dae, "x", 100)
julia> ca.value_reference(dae, "x")
100

Extra doc: https://github.com/casadi/casadi/wiki/L_2ls

Definition at line 558 of file dae_builder.cpp.

558  {
559  (*this)->variable(name).value_reference = val;
560 }

References name().

◆ set_variability()

void casadi::DaeBuilder::set_variability ( const std::string &  name,
const std::string &  val 
)

For controls u (variability "continuous", causality "input"), free parameters p (variability "tunable", causality "parameter") and fixed parameters c (variability "fixed", causality "parameter"), update variability in order to change the category. Causality is updated accordingly.

Other changes are not permitted.

>>> dae = DaeBuilder("m")
>>> u = dae.add("u", "input")
>>> x = dae.add("x")
>>> dae.eq(dae.der(x), -u*x)
>>> dae.set_variability("u", "fixed")
>>> dae.u(), dae.c(), dae.causality("u")
([], ['u'], 'parameter')
>>> dae.set_variability("u", "tunable")
>>> dae.p(), dae.causality("u")
(['u'], 'parameter')
>>> dae.set_variability("u", "continuous")
>>> dae.u(), dae.causality("u")
(['u'], 'input')
>>> try:
...   dae.set_variability("x", "discrete")
... except Exception as e:
...   print("Cannot change variability" in str(e))
True

>> dae = DaeBuilder('m'); u = dae.add('u', 'input'); x = dae.add('x');
>> dae.eq(dae.der(x), -u*x);
>> dae.set_variability('u', 'fixed');
>> isempty(dae.u()), dae.c(), dae.causality('u')
1
u
parameter
>> dae.set_variability('u', 'tunable');
>> dae.p(), dae.causality('u')
u
parameter
>> dae.set_variability('u', 'continuous');
>> dae.u(), dae.causality('u')
u
input
>> try, dae.set_variability('x', 'discrete'); catch e, msg = e.message; end
>> contains(msg, 'Cannot change variability')
1

julia> dae = ca.DaeBuilder("m");
julia> u = ca.add(dae, "u", "input");
julia> x = ca.add(dae, "x");
julia> ca.set_variability(dae, "u", "fixed")
julia> ca.u(dae), ca.c(dae), ca.causality(dae, "u")
(String[], ["u"], "parameter")
julia> ca.set_variability(dae, "u", "tunable")
julia> ca.p(dae), ca.causality(dae, "u")
(["u"], "parameter")
julia> ca.set_variability(dae, "u", "continuous")
julia> ca.u(dae), ca.causality(dae, "u")
(["u"], "input")
julia> try
           ca.set_variability(dae, "x", "discrete")
       catch e
           println(occursin("Cannot change variability", sprint(showerror, e)))
       end
true

See also
variability, set_causality, set_category

Extra doc: https://github.com/casadi/casadi/wiki/L_2c3

Definition at line 629 of file dae_builder.cpp.

629  {
630  try {
631  (*this)->set_variability((*this)->find(name), to_enum<Variability>(val));
632  } catch (std::exception& e) {
633  THROW_ERROR("set_variability", e.what());
634  }
635 }

References name().

◆ set_y()

void casadi::DaeBuilder::set_y ( const std::vector< std::string > &  name)
inline

Definition at line 707 of file dae_builder.hpp.

707 {set_all("y", name);}
void set_all(const std::string &v, const std::vector< std::string > &name)
Set all variables within a a category.

◆ sort()

void casadi::DaeBuilder::sort ( const std::string &  cat)

Reorders an acyclic category ("c", "d" or "w") so that every variable comes after the ones it depends on, using a block triangular (Dulmage-Mendelsohn) decomposition of the dependency pattern. Vector-valued variables are treated as a unit. Other categories are an error.

Parameters
cat"c", "d" or "w"

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> w1 = dae.add("w1")
>>> w2 = dae.add("w2")
>>> dae.eq(w2, w1**2)
>>> dae.eq(w1, 2*x)
>>> dae.eq(dae.der(x), -w2)
>>> dae.w(), dae.wdef()
(['w2', 'w1', 'der(x)'], [MX(sq(w1)), MX((2.*x)), MX((-w2))])
>>> dae.sort("w")
>>> dae.w(), dae.wdef()
(['w1', 'w2', 'der(x)'], [MX((2.*x)), MX(sq(w1)), MX((-w2))])

>> dae = DaeBuilder('m'); x = dae.add('x'); w1 = dae.add('w1'); w2 = dae.add('w2');
>> dae.eq(w2, w1^2); dae.eq(w1, 2*x); dae.eq(dae.der(x), -w2);
>> disp(dae.w()), cellfun(@disp, dae.wdef())
w2
w1
der(x)
sq(w1)
(2.*x)
(-w2)
>> dae.sort('w');
>> disp(dae.w()), cellfun(@disp, dae.wdef())
w1
w2
der(x)
(2.*x)
sq(w1)
(-w2)

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> w1 = ca.add(dae, "w1");
julia> w2 = ca.add(dae, "w2");
julia> ca.eq(dae, w2, w1^2)
julia> ca.eq(dae, w1, 2*x)
julia> ca.eq(dae, ca.der(dae, x), -w2)
julia> ca.w(dae), ca.wdef(dae)
(["w2", "w1", "der(x)"], MX[sq(w1), (2.*x), (-w2)])
julia> ca.sort(dae, "w")
julia> ca.w(dae), ca.wdef(dae)
(["w1", "w2", "der(x)"], MX[(2.*x), sq(w1), (-w2)])

See also
eliminate, reorder

Extra doc: https://github.com/casadi/casadi/wiki/L_2l2

Definition at line 538 of file dae_builder.cpp.

538  {
539  try {
540  (*this)->sort(to_enum<Category>(cat));
541  } catch (std::exception& e) {
542  THROW_ERROR("sort", e.what());
543  }
544 }

◆ start() [1/2]

std::vector< double > casadi::DaeBuilder::start ( const std::string &  name) const

The start values of a variable as a list with numel entries, also for scalars.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(start=1))
>>> v = dae.add("v", dict(dimension=[2]))
>>> dae.start("x"), dae.start("v"), dae.start(["x", "v"])
([1.0], [0.0, 0.0], [1.0, 0.0, 0.0])
>>> dae.set_start("v", [3, 4])
>>> dae.set_start(["x", "v"], [0, 1])
>>> dae.start(["x", "v"])
[0.0, 1.0, 1.0]
>>> dae.set_start(["x", "v"], [1, 2, 3])
>>> dae.start(["x", "v"])
[1.0, 2.0, 3.0]
>>> try:
...   dae.set_start("v", [1, 2, 3])
... except Exception as e:
...   print("expected number of elements (2) or number of variables (1)" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x', struct('start', 1));
>> v = dae.add('v', struct('dimension', 2));
>> dae.start('x'), dae.start('v'), dae.start({'x', 'v'})
1
0 0
1 0 0
>> dae.set_start('v', [3 4]); dae.set_start({'x', 'v'}, [0 1]);
>> dae.start({'x', 'v'})
0 1 1
>> dae.set_start({'x', 'v'}, [1 2 3]);
>> dae.start({'x', 'v'})
1 2 3
>> try, dae.set_start('v', [1 2 3]); catch e, msg = e.message; end
>> contains(msg, 'expected number of elements (2) or number of variables (1)')
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("start" => 1));
julia> v = ca.add(dae, "v", Dict("dimension" => [2]));
julia> ca.start(dae, "x"), ca.start(dae, "v"), ca.start(dae, ["x", "v"])
([1.0], [0.0, 0.0], [1.0, 0.0, 0.0])
julia> ca.set_start(dae, "v", [3, 4])
julia> ca.set_start(dae, ["x", "v"], [0, 1])
julia> ca.start(dae, ["x", "v"])
3-element Vector{Float64}:
 0.0
 1.0
 1.0
julia> ca.set_start(dae, ["x", "v"], [1, 2, 3])
julia> ca.start(dae, ["x", "v"])
3-element Vector{Float64}:
 1.0
 2.0
 3.0
julia> try
           ca.set_start(dae, "v", [1, 2, 3])
       catch e
           msg = "expected number of elements (2) or number of variables (1)"
           println(occursin(msg, sprint(showerror, e)))
       end
true

See also
set_start, get

Extra doc: https://github.com/casadi/casadi/wiki/L_2m8

Definition at line 1068 of file dae_builder.cpp.

1068  {
1069  try {
1070  return (*this)->attribute(Attribute::START, std::vector<std::string>{name});
1071  } catch (std::exception& e) {
1072  THROW_ERROR("start", e.what());
1073  return {}; // never reached
1074  }
1075 }

References casadi::START.

◆ start() [2/2]

std::vector< double > casadi::DaeBuilder::start ( const std::vector< std::string > &  name) const

Definition at line 1077 of file dae_builder.cpp.

1077  {
1078  try {
1079  return (*this)->attribute(Attribute::START, name);
1080  } catch (std::exception& e) {
1081  THROW_ERROR("start", e.what());
1082  return {}; // never reached
1083  }
1084 }

References name(), and casadi::START.

◆ start_time()

double casadi::DaeBuilder::start_time ( ) const

Start time of the default experiment: imported from the model description or set with set_start_time; nan when unknown.

>>> dae = DaeBuilder("m")
>>> dae.start_time(), dae.stop_time(), dae.tolerance(), dae.step_size()
(nan, nan, nan, nan)
>>> dae.set_start_time(0)
>>> dae.set_stop_time(10)
>>> dae.set_tolerance(1e-6)
>>> dae.set_step_size(0.01)
>>> dae.start_time(), dae.stop_time(), dae.tolerance(), dae.step_size()
(0.0, 10.0, 1e-06, 0.01)

>> dae = DaeBuilder('m');
>> fprintf('%g %g %g %g\n', dae.start_time, dae.stop_time, dae.tolerance, dae.step_size)
NaN NaN NaN NaN
>> dae.set_start_time(0); dae.set_stop_time(10);
>> dae.set_tolerance(1e-6); dae.set_step_size(0.01);
>> fprintf('%g %g %g %g\n', dae.start_time, dae.stop_time, dae.tolerance, dae.step_size)
0 10 1e-06 0.01

julia> dae = ca.DaeBuilder("m");
julia> ca.start_time(dae), ca.stop_time(dae), ca.tolerance(dae), ca.step_size(dae)
(NaN, NaN, NaN, NaN)
julia> ca.set_start_time(dae, 0)
julia> ca.set_stop_time(dae, 10)
julia> ca.set_tolerance(dae, 1e-6)
julia> ca.set_step_size(dae, 0.01)
julia> ca.start_time(dae), ca.stop_time(dae), ca.tolerance(dae), ca.step_size(dae)
(0.0, 10.0, 1.0e-6, 0.01)

See also
set_start_time, stop_time

Extra doc: https://github.com/casadi/casadi/wiki/L_2m4

Definition at line 687 of file dae_builder.cpp.

687  {
688  try {
689  return (*this)->start_time_;
690  } catch (std::exception& e) {
691  THROW_ERROR("start_time", e.what());
692  return nan;
693  }
694 }
const double nan
Not a number.
Definition: calculus.hpp:53

References casadi::nan.

◆ step_size()

double casadi::DaeBuilder::step_size ( ) const

Definition at line 738 of file dae_builder.cpp.

738  {
739  try {
740  return (*this)->step_size_;
741  } catch (std::exception& e) {
742  THROW_ERROR("step_size", e.what());
743  return nan;
744  }
745 }

References casadi::nan.

◆ stop_time()

double casadi::DaeBuilder::stop_time ( ) const

Definition at line 704 of file dae_builder.cpp.

704  {
705  try {
706  return (*this)->stop_time_;
707  } catch (std::exception& e) {
708  THROW_ERROR("stop_time", e.what());
709  return nan;
710  }
711 }

References casadi::nan.

◆ swap()

Definition at line 105 of file generic_shared_impl.hpp.

131  {
132  GenericShared<Shared, Internal> temp = *this;
133  *this = other;
134  other = temp;
135  }

◆ symbolic()

bool casadi::DaeBuilder::symbolic ( ) const

True for a symbolically constructed model (or a symbolic model description), false for an imported standard FMU whose equations live in a binary.

>>> DaeBuilder("m").symbolic()
True

julia> ca.symbolic(ca.DaeBuilder("m"))
true

See also
load_fmi_description, oracle

Extra doc: https://github.com/casadi/casadi/wiki/L_2mc

Definition at line 1198 of file dae_builder.cpp.

1198  {
1199  try {
1200  return (*this)->symbolic_;
1201  } catch (std::exception& e) {
1202  THROW_ERROR("symbolic", e.what());
1203  return false; // never reached
1204  }
1205 }

Referenced by get(), and provides_directional_derivatives().

◆ t_new()

std::vector<std::string> casadi::DaeBuilder::t_new ( ) const
inline

Name of the independent variable as a list: empty when none has been declared, otherwise a single name. Equivalent to all("t").

See also
time, has_t

Extra doc: https://github.com/casadi/casadi/wiki/L_2bz

Definition at line 360 of file dae_builder.hpp.

360 {return all("t");}

References casadi::all().

◆ tear()

void casadi::DaeBuilder::tear ( )

Variables named res__<iv> are interpreted as residual equations with iteration variable <iv> (optionally followed by __<hold> markers). The iteration variables are removed from z and u and appended to z, so that z and alg match up. Hold markers are not implemented and only produce a warning.

See also
z, sort

Extra doc: https://github.com/casadi/casadi/wiki/L_2l5

Definition at line 246 of file dae_builder.cpp.

246  {
247  try {
248  (*this)->tear();
249  } catch (std::exception& e) {
250  THROW_ERROR("tear", e.what());
251  }
252 }

◆ test_cast()

bool casadi::DaeBuilder::test_cast ( const SharedObjectInternal *  ptr)
static

Definition at line 900 of file dae_builder.cpp.

900  {
901  return dynamic_cast<const DaeBuilderInternal*>(ptr) != nullptr;
902 }

◆ time()

const MX & casadi::DaeBuilder::time ( ) const

Only available when an independent variable has been declared explicitly with add(name, "independent") or imported from the model description; otherwise an error is raised. Without an explicit declaration a hidden variable named "time" exists in all() but is not categorized as t.

>>> dae = DaeBuilder("m")
>>> t = dae.add("t", "independent")
>>> x = dae.add("x")
>>> dae.time(), dae.has_t(), dae.t_new()
(MX(t), True, ['t'])
>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> dae.all(), dae.has_t(), dae.t_new()
(['time', 'x'], False, [])
>>> try:
...   dae.time()
... except Exception as e:
...   print("No explicit time variable" in str(e))
True

>> dae = DaeBuilder('m'); t = dae.add('t', 'independent'); x = dae.add('x');
>> dae.time(), dae.has_t(), dae.t_new()
t
1
t
>> dae = DaeBuilder('m'); x = dae.add('x');
>> dae.all(), dae.has_t(), isempty(dae.t_new())
time
x
0
1
>> try, dae.time(); catch e, disp(contains(e.message, 'No explicit time variable')); end
1

julia> dae = ca.DaeBuilder("m");
julia> t = ca.add(dae, "t", "independent");
julia> x = ca.add(dae, "x");
julia> dae.time(), ca.has_t(dae), ca.t_new(dae)
(t, true, ["t"])
julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> ca.all(dae), ca.has_t(dae), ca.t_new(dae)
(["time", "x"], false, String[])
julia> try
           dae.time()
       catch e
           println(occursin("No explicit time variable", sprint(showerror, e)))
       end
true

See also
has_t, t_new

Extra doc: https://github.com/casadi/casadi/wiki/L_2by

Definition at line 63 of file dae_builder.cpp.

63  {
64  try {
65  return (*this)->time();
66  } catch (std::exception& e) {
67  THROW_ERROR("time", e.what());
68  static const MX t;
69  return t; // never reached
70  }
71 }

◆ tolerance()

double casadi::DaeBuilder::tolerance ( ) const

Definition at line 721 of file dae_builder.cpp.

721  {
722  try {
723  return (*this)->tolerance_;
724  } catch (std::exception& e) {
725  THROW_ERROR("tolerance", e.what());
726  return nan;
727  }
728 }

References casadi::nan.

◆ transition() [1/3]

Function casadi::DaeBuilder::transition ( ) const
inline

The function is named <name>_transition.

Extra doc: https://github.com/casadi/casadi/wiki/L_2lk

Definition at line 3002 of file dae_builder.hpp.

3002 {return transition(name() + "_transition");}
Function transition() const
Construct an event transition function, default naming.

References transition().

Referenced by transition().

◆ transition() [2/3]

Function casadi::DaeBuilder::transition ( const std::string &  fname) const

Builds the event function expected by the "transition" option of integrator, with an event index as first input: for a single event the function of transition(fname, 0) with a dummy index input, for several events a switch over the per-event functions. Without when equations a null Function is returned.

>>> dae = DaeBuilder("ball")
>>> h = dae.add("h", dict(start=5))
>>> v = dae.add("v", dict(start=0))
>>> dae.eq(dae.der(h), v)
>>> dae.eq(dae.der(v), -9.81)
>>> dae.transition().is_null()
True
>>> dae.when(h < 0, [dae.reinit("v", -0.8*v)])
>>> dae.transition("tr")
Function(tr:(index[],t[0],x[2],z[0],p[0],u[0])->(post_x[2],post_z[0]) MXFunction)

>> dae = DaeBuilder('ball');
>> h = dae.add('h', struct('start', 5)); v = dae.add('v', struct('start', 0));
>> dae.eq(dae.der(h), v); dae.eq(dae.der(v), -9.81);
>> dae.transition().is_null()
1
>> dae.when(h < 0, {dae.reinit('v', -0.8*v)});
>> dae.transition('tr')
tr:(index[],t[0],x[2],z[0],p[0],u[0])->(post_x[2],post_z[0]) MXFunction

julia> dae = ca.DaeBuilder("ball");
julia> h = ca.add(dae, "h", Dict("start" => 5));
julia> v = ca.add(dae, "v", Dict("start" => 0));
julia> ca.eq(dae, ca.der(dae, h), v)
julia> ca.eq(dae, ca.der(dae, v), -9.81)
julia> ca.is_null(ca.transition(dae))
true
julia> ca.when(dae, h < 0, [ca.reinit(dae, "v", -0.8*v)])
julia> ca.transition(dae, "tr")
Function(tr:(index[],t[0],x[2],z[0],p[0],u[0])->(post_x[2],post_z[0]) MXFunction)

See also
when, create

Extra doc: https://github.com/casadi/casadi/wiki/L_2lj

Definition at line 891 of file dae_builder.cpp.

891  {
892  try {
893  return (*this)->transition(fname);
894  } catch (std::exception& e) {
895  THROW_ERROR("transition", e.what());
896  return Function(); // never reached
897  }
898 }

◆ transition() [3/3]

Function casadi::DaeBuilder::transition ( const std::string &  fname,
casadi_int  index 
) const

Builds a Function with inputs t, x, z, p, u and outputs post_x, post_z: the states after the event with index index (0-based, in the order the when equations were added). Dependent variables are substituted out.

Parameters
fnameFunction name
indexEvent index; out of range is an error

>>> dae = DaeBuilder("ball")
>>> h = dae.add("h", dict(start=5))
>>> v = dae.add("v", dict(start=0))
>>> dae.eq(dae.der(h), v)
>>> dae.eq(dae.der(v), -9.81)
>>> dae.when(h < 0, [dae.reinit("v", -0.8*v)])
>>> T = dae.transition("tr", 0)
>>> T
Function(tr:(t[0],x[2],z[0],p[0],u[0])->(post_x[2],post_z[0]) MXFunction)
>>> T(0, [-0.1, -3], [], [], [])
(DM([-0.1, 2.4]), DM(0x1))
>>> try:
...   dae.transition("tr", 1)
... except Exception as e:
...   print("Illegal event index" in str(e))
True

>> dae = DaeBuilder('ball');
>> h = dae.add('h', struct('start', 5)); v = dae.add('v', struct('start', 0));
>> dae.eq(dae.der(h), v); dae.eq(dae.der(v), -9.81);
>> dae.when(h < 0, {dae.reinit('v', -0.8*v)});
>> T = dae.transition('tr', 0); disp(T)
tr:(t[0],x[2],z[0],p[0],u[0])->(post_x[2],post_z[0]) MXFunction
>> [post_x, post_z] = T(0, [-0.1; -3], [], [], []); disp(post_x), disp(post_z)
[-0.1, 2.4]
0x1
>> try, dae.transition('tr', 1); catch e, msg = e.message; end
>> contains(msg, 'Illegal event index')
1

julia> dae = ca.DaeBuilder("ball");
julia> h = ca.add(dae, "h", Dict("start" => 5));
julia> v = ca.add(dae, "v", Dict("start" => 0));
julia> ca.eq(dae, ca.der(dae, h), v)
julia> ca.eq(dae, ca.der(dae, v), -9.81)
julia> ca.when(dae, h < 0, [ca.reinit(dae, "v", -0.8*v)])
julia> T = ca.transition(dae, "tr", 0)
Function(tr:(t[0],x[2],z[0],p[0],u[0])->(post_x[2],post_z[0]) MXFunction)
julia> T(0, [-0.1, -3], [], [], [])
([-0.1, 2.4], 0x1)
julia> try
           ca.transition(dae, "tr", 1)
       catch e
           println(occursin("Illegal event index", sprint(showerror, e)))
       end
true

See also
when, create

Extra doc: https://github.com/casadi/casadi/wiki/L_2li

Definition at line 882 of file dae_builder.cpp.

882  {
883  try {
884  return (*this)->transition(fname, index);
885  } catch (std::exception& e) {
886  THROW_ERROR("transition", e.what());
887  return Function(); // never reached
888  }
889 }

◆ type()

std::string casadi::DaeBuilder::type ( const std::string &  name,
casadi_int  fmi_version = 3 
) const

The variable type in FMI 3 naming ("Float64", "Float32", "Int32", "Boolean", "String", ...) or, with fmi_version 2, in FMI 2 naming ("real", "integer", "boolean", "string", "enum"). Setting accepts FMI 3 names; other versions or names are an error.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> n = dae.add("n", dict(type="Int32"))
>>> dae.type("x"), dae.type("x", 2), dae.type("n"), dae.type("n", 2)
('Float64', 'real', 'Int32', 'integer')
>>> dae.set_type("x", "Float32")
>>> dae.type("x")
'Float32'
>>> try:
...   dae.set_type("x", "bogus")
... except Exception as e:
...   print("No such enum" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x'); n = dae.add('n', struct('type', 'Int32'));
>> dae.type('x'), dae.type('x', 2), dae.type('n'), dae.type('n', 2)
Float64
real
Int32
integer
>> dae.set_type('x', 'Float32');
>> dae.type('x')
Float32
>> try, dae.set_type('x', 'bogus'); catch e, disp(contains(e.message, 'No such enum')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> n = ca.add(dae, "n", Dict("type" => "Int32"));
julia> ca.type(dae, "x"), ca.type(dae, "x", 2), ca.type(dae, "n"), ca.type(dae, "n", 2)
("Float64", "real", "Int32", "integer")
julia> ca.set_type(dae, "x", "Float32")
julia> ca.type(dae, "x")
"Float32"
julia> try
           ca.set_type(dae, "x", "bogus")
       catch e
           println(occursin("No such enum", sprint(showerror, e)))
       end
true

Extra doc: https://github.com/casadi/casadi/wiki/L_2lu

Definition at line 570 of file dae_builder.cpp.

570  {
571  // Check version
572  casadi_assert(fmi_version == 2 || fmi_version == 3, "Only FMI version 2 or 3 supported");
573  // Handle FMI 2
574  if (fmi_version == 2) {
575  return to_string(to_fmi2((*this)->variable(name).type));
576  }
577  // Assume FMI 3
578  return to_string((*this)->variable(name).type);
579 }
TypeFmi2 to_fmi2(Type v)

References name(), casadi::to_fmi2(), and casadi::to_string().

◆ type_name()

std::string casadi::DaeBuilder::type_name ( ) const
inline

Definition at line 151 of file dae_builder.hpp.

151 {return "DaeBuilder";}

◆ u()

std::vector<std::string> casadi::DaeBuilder::u ( ) const
inline

Names of the variables of category u (causality "input"), in category order. Equivalent to all("u").

See also
p, nu, set_category

Extra doc: https://github.com/casadi/casadi/wiki/L_5n

Definition at line 718 of file dae_builder.hpp.

718 {return all("u");}

References casadi::all().

◆ unit()

std::string casadi::DaeBuilder::unit ( const std::string &  name) const

Unit string of a variable, e.g. "m/s"; empty by default. Also settable with the "unit" option of add.

>>> dae = DaeBuilder("m")
>>> v = dae.add("v", dict(unit="m/s"))
>>> dae.unit("v")
'm/s'
>>> dae.set_unit("v", "km/h")
>>> dae.unit("v")
'km/h'

>> dae = DaeBuilder('m'); v = dae.add('v', struct('unit', 'm/s'));
>> dae.unit('v')
m/s
>> dae.set_unit('v', 'km/h');
>> dae.unit('v')
km/h

julia> dae = ca.DaeBuilder("m");
julia> v = ca.add(dae, "v", Dict("unit" => "m/s"));
julia> ca.unit(dae, "v")
"m/s"
julia> ca.set_unit(dae, "v", "km/h")
julia> ca.unit(dae, "v")
"km/h"

Extra doc: https://github.com/casadi/casadi/wiki/L_2m0

Definition at line 663 of file dae_builder.cpp.

663  {
664  return (*this)->variable(name).unit;
665 }

References name().

◆ value_reference()

casadi_int casadi::DaeBuilder::value_reference ( const std::string &  name) const

The FMI value reference of a variable: imported from the model description, or by default the index of the variable in the instance.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> dae.value_reference("x"), dae.value_reference("y")
(1, 2)
>>> dae.set_value_reference("x", 100)
>>> dae.value_reference("x")
100

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> dae.value_reference('x'), dae.value_reference('y')
1
2
>> dae.set_value_reference('x', 100);
>> dae.value_reference('x')
100

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> ca.value_reference(dae, "x"), ca.value_reference(dae, "y")
(1, 2)
julia> ca.set_value_reference(dae, "x", 100)
julia> ca.value_reference(dae, "x")
100

Extra doc: https://github.com/casadi/casadi/wiki/L_2ls

Definition at line 554 of file dae_builder.cpp.

554  {
555  return (*this)->variable(name).value_reference;
556 }

References name().

◆ var()

MX casadi::DaeBuilder::var ( const std::string &  name) const

The symbolic expression of a model variable: a dense column vector with numel entries, named after the variable. An unknown name is an error. Also available via the call operator.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", dict(dimension=[2]))
>>> dae.var("x"), dae.var("x").shape
(MX(x), (2, 1))
>>> dae.has("x"), dae.has("y")
(True, False)
>>> try:
...   dae.var("y")
... except Exception as e:
...   print("No such variable" in str(e))
True

>> dae = DaeBuilder('m'); x = dae.add('x', struct('dimension', 2));
>> dae.var('x'), size(dae.var('x'))
x
2 1
>> dae.has('x'), dae.has('y')
1
0
>> try, dae.var('y'); catch e, disp(contains(e.message, 'No such variable')); end
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", Dict("dimension" => [2]));
julia> ca.var(dae, "x"), size(ca.var(dae, "x"))
(x, (2, 1))
julia> ca.has(dae, "x"), ca.has(dae, "y")
(true, false)
julia> try
           ca.var(dae, "y")
       catch e
           println(occursin("No such variable", sprint(showerror, e)))
       end
true

See also
has, all, inputs

Extra doc: https://github.com/casadi/casadi/wiki/L_2ll

Definition at line 435 of file dae_builder.cpp.

435  {
436  try {
437  return (*this)->variable(name).v;
438  } catch (std::exception& e) {
439  THROW_ERROR("var", e.what());
440  return MX(); // never reached
441  }
442 }

References name().

◆ variability()

std::string casadi::DaeBuilder::variability ( const std::string &  name) const

One of "constant", "fixed", "tunable", "discrete", "continuous".

See also
set_variability, causality

Extra doc: https://github.com/casadi/casadi/wiki/L_2lx

Definition at line 620 of file dae_builder.cpp.

620  {
621  try {
622  return to_string((*this)->variability((*this)->find(name)));
623  } catch (std::exception& e) {
624  THROW_ERROR("variability", e.what());
625  return std::string(); // never reached
626  }
627 }

References name(), and casadi::to_string().

Referenced by add().

◆ w()

std::vector<std::string> casadi::DaeBuilder::w ( ) const
inline

Names of the variables of category w, in category order. Equivalent to all("w"). A variable becomes dependent when it is the left-hand side of an explicit equation eq(v, expr); the derivative variables der(x) of the states are dependent variables too.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> w = dae.add("w")
>>> dae.eq(w, sin(x))
>>> dae.eq(dae.der(x), -w)
>>> dae.w()
['w', 'der(x)']
>>> dae.wdef()
[MX(sin(x)), MX((-w))]

>> dae = DaeBuilder('m'); x = dae.add('x'); w = dae.add('w');
>> dae.eq(w, sin(x)); dae.eq(dae.der(x), -w);
>> dae.w()
w
der(x)
>> cellfun(@disp, dae.wdef())
sin(x)
(-w)

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> w = ca.add(dae, "w");
julia> ca.eq(dae, w, sin(x))
julia> ca.eq(dae, ca.der(dae, x), -w)
julia> ca.w(dae)
2-element Vector{String}:
 "w"
 "der(x)"
julia> ca.wdef(dae)
2-element Vector{MX}:
 MX(sin(x))
 MX((-w))

See also
wdef, dependent_fun, eliminate, nw

Extra doc: https://github.com/casadi/casadi/wiki/L_5t

Definition at line 863 of file dae_builder.hpp.

863 {return all("w");}

References casadi::all().

◆ wdef()

std::vector< MX > casadi::DaeBuilder::wdef ( ) const

The binding expressions of the dependent variables, one per entry of w(). Interdependencies are allowed but must be non-cyclic (see sort). Equivalent to outputs("wdef").

See also
w, ddef, sort, eliminate

Extra doc: https://github.com/casadi/casadi/wiki/L_5u

Definition at line 109 of file dae_builder.cpp.

109  {
110  try {
111  return (*this)->outputs(Category::WDEF);
112  } catch (std::exception& e) {
113  THROW_ERROR("wdef", e.what());
114  return {}; // never reached
115  }
116 }

References casadi::WDEF.

◆ weak()

Extra doc: https://github.com/casadi/casadi/wiki/L_aw

Definition at line 130 of file generic_shared_impl.hpp.

143  {
144  return (*this)->weak();
145  }

◆ when()

void casadi::DaeBuilder::when ( const MX &  cond,
const std::vector< std::string > &  eqs,
const Dict &  opts = Dict() 
)

Adds an event: whenever the zero-crossing function of cond becomes negative, the assignments in eqs are executed. The condition must be a strict inequality a < b (or a > b); it is stored as the zero-crossing function a - b in outputs("zero"). The event transition can be obtained with transition.

Parameters
condStrict inequality between model expressions; <= or any other expression is an error
eqsNames returned by reinit or assign; may be empty
optsMust be empty

>>> dae = DaeBuilder("ball")
>>> h = dae.add("h", dict(start=5))
>>> v = dae.add("v", dict(start=0))
>>> dae.eq(dae.der(h), v)
>>> dae.eq(dae.der(v), -9.81)
>>> dae.when(h < 0, [dae.reinit("v", -0.8*v)])
>>> dae.nzero(), dae.outputs("zero")
(1, [MX(h)])
>>> T = dae.transition()
>>> T
Function(ball_transition:(index[],t[0],x[2],z[0],p[0],u[0])->(post_x[2],post_z[0]) MXFunction)
>>> T(0, 0, [-0.1, -3], [], [], [])
(DM([-0.1, 2.4]), DM(0x1))
>>> try:
...   dae.when(h <= 0, [])
... except Exception as e:
...   print("Only strict inequality" in str(e))
True

>> dae = DaeBuilder('ball');
>> h = dae.add('h', struct('start', 5)); v = dae.add('v', struct('start', 0));
>> dae.eq(dae.der(h), v); dae.eq(dae.der(v), -9.81);
>> dae.when(h < 0, {dae.reinit('v', -0.8*v)});
>> disp(dae.nzero()), cellfun(@disp, dae.outputs('zero'))
1
h
>> T = dae.transition(); disp(T)
ball_transition:(index[],t[0],x[2],z[0],p[0],u[0])->(post_x[2],post_z[0]) MXFunction
>> [post_x, post_z] = T(0, 0, [-0.1; -3], [], [], []); disp(post_x), disp(post_z)
[-0.1, 2.4]
0x1
>> try, dae.when(h <= 0, {}); catch e, msg = e.message; end
>> contains(msg, 'Only strict inequality')
1

julia> dae = ca.DaeBuilder("ball");
julia> h = ca.add(dae, "h", Dict("start" => 5));
julia> v = ca.add(dae, "v", Dict("start" => 0));
julia> ca.eq(dae, ca.der(dae, h), v)
julia> ca.eq(dae, ca.der(dae, v), -9.81)
julia> ca.when(dae, h < 0, [ca.reinit(dae, "v", -0.8*v)])
julia> ca.nzero(dae), ca.outputs(dae, "zero")
(1, MX[h])
julia> T = ca.transition(dae)
Function(ball_transition:(index[],t[0],x[2],z[0],p[0],u[0])->(post_x[2],post_z[0]) MXFunction)
julia> T(0, 0, [-0.1, -3], [], [], [])
([-0.1, 2.4], 0x1)
julia> try
           ca.when(dae, h <= 0, String[])
       catch e
           println(occursin("Only strict inequality", sprint(showerror, e)))
       end
true

See also
reinit, assign, transition, nzero

Extra doc: https://github.com/casadi/casadi/wiki/L_2ku

Definition at line 393 of file dae_builder.cpp.

393  {
394  try {
395  (*this)->when(cond, eqs, opts);
396  } catch (std::exception& e) {
397  THROW_ERROR("when", e.what());
398  }
399 }

◆ x()

std::vector<std::string> casadi::DaeBuilder::x ( ) const
inline

Names of the variables of category x, in category order. Equivalent to all("x"). A continuous variable becomes a differential state once its time derivative is given a defining equation with eq; it is an algebraic variable z before that.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x")
>>> y = dae.add("y")
>>> dae.x(), dae.z()
([], ['x', 'y'])
>>> dae.eq(dae.der(x), -y)
>>> dae.x(), dae.z(), dae.nx()
(['x'], ['y'], 1)

>> dae = DaeBuilder('m'); x = dae.add('x'); y = dae.add('y');
>> isempty(dae.x()), dae.z()
1
x
y
>> dae.eq(dae.der(x), -y);
>> dae.x(), dae.z(), dae.nx()
x
y
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x");
julia> y = ca.add(dae, "y");
julia> ca.x(dae), ca.z(dae)
(String[], ["x", "y"])
julia> ca.eq(dae, ca.der(dae, x), -y)
julia> ca.x(dae), ca.z(dae), ca.nx(dae)
(["x"], ["y"], 1)

See also
z, q, nx, all, inputs

Extra doc: https://github.com/casadi/casadi/wiki/L_5f

Definition at line 412 of file dae_builder.hpp.

412 {return all("x");}

References casadi::all().

◆ y()

std::vector<std::string> casadi::DaeBuilder::y ( ) const
inline

Names of the variables with causality "output", in category order. Equivalent to all("y"). Outputs are also members of another category (x, w, z, ...); outputs("y") gives their expressions.

>>> dae = DaeBuilder("m")
>>> x = dae.add("x", "output")
>>> y = dae.add("y", "output")
>>> w = dae.add("w")
>>> dae.eq(dae.der(x), -w)
>>> dae.eq(w, x**2)
>>> dae.eq(y, 2*x)
>>> dae.y(), dae.x(), dae.w()
(['x', 'y'], ['x'], ['der(x)', 'w', 'y'])
>>> dae.outputs("y")
[MX(x), MX(y)]
>>> dae.set_causality("y", "local")
>>> dae.y(), dae.ny()
(['x'], 1)

>> dae = DaeBuilder('m'); x = dae.add('x', 'output'); y = dae.add('y', 'output');
>> w = dae.add('w');
>> dae.eq(dae.der(x), -w); dae.eq(w, x^2); dae.eq(y, 2*x);
>> dae.y()
x
y
>> dae.x(), dae.w()
x
der(x)
w
y
>> cellfun(@disp, dae.outputs('y'))
x
y
>> dae.set_causality('y', 'local');
>> dae.y(), dae.ny()
x
1

julia> dae = ca.DaeBuilder("m");
julia> x = ca.add(dae, "x", "output");
julia> y = ca.add(dae, "y", "output");
julia> w = ca.add(dae, "w");
julia> ca.eq(dae, ca.der(dae, x), -w)
julia> ca.eq(dae, w, x^2)
julia> ca.eq(dae, y, 2*x)
julia> ca.y(dae), ca.x(dae), ca.w(dae)
(["x", "y"], ["x"], ["der(x)", "w", "y"])
julia> ca.outputs(dae, "y")
2-element Vector{MX}:
 MX(x)
 MX(y)
julia> ca.set_causality(dae, "y", "local")
julia> ca.y(dae), ca.ny(dae)
(["x"], 1)

See also
set_causality, set_all, ny, outputs

Extra doc: https://github.com/casadi/casadi/wiki/L_2fu

Definition at line 486 of file dae_builder.hpp.

486 {return all("y");}

References casadi::all().

Referenced by set_all().

◆ ydef()

std::vector<MX> casadi::DaeBuilder::ydef ( ) const
inline

Definition at line 704 of file dae_builder.hpp.

704 {return outputs("y");}

◆ z()

std::vector<std::string> casadi::DaeBuilder::z ( ) const
inline

Names of the variables of category z, in category order. Equivalent to all("z"). Every continuous local or output variable starts in this category and leaves it when it gets a defining equation (w) or an equation for its derivative (x).

See also
x, w, nz, eq

Extra doc: https://github.com/casadi/casadi/wiki/L_2fv

Definition at line 497 of file dae_builder.hpp.

497 {return all("z");}

References casadi::all().

◆ zero()

std::vector<MX> casadi::DaeBuilder::zero ( ) const
inline

Definition at line 701 of file dae_builder.hpp.

701 {return outputs("zero");}

The documentation for this class was generated from the following files: