26 #ifndef CASADI_DAE_BUILDER_HPP
27 #define CASADI_DAE_BUILDER_HPP
29 #include "function.hpp"
34 class DaeBuilderInternal;
70 public SWIG_IF_ELSE(PrintableCommon, Printable<DaeBuilder>) {
74 std::string
type_name()
const {
return "DaeBuilder";}
80 explicit DaeBuilder(
const std::string& name,
const std::string& path =
"",
86 const std::string&
name()
const;
98 std::vector<std::string>
x()
const;
103 std::vector<MX>
ode()
const;
108 std::vector<std::string>
z()
const;
113 std::vector<MX>
alg()
const;
118 std::vector<std::string>
q()
const;
128 std::vector<std::string>
y()
const;
138 std::vector<std::string>
u()
const;
143 std::vector<std::string>
p()
const;
148 std::vector<std::string>
c()
const;
158 std::vector<std::string>
d()
const;
170 std::vector<std::string>
w()
const;
182 const std::vector<MX>&
aux()
const;
236 casadi_int
nx()
const;
241 casadi_int
nz()
const;
246 casadi_int
nq()
const;
251 casadi_int
ny()
const;
256 casadi_int
nu()
const;
261 casadi_int
np()
const;
266 casadi_int
nc()
const;
271 casadi_int
nd()
const;
276 casadi_int
nw()
const;
287 MX add_p(
const std::string& name=std::string());
290 MX add_u(
const std::string& name=std::string());
293 MX add_x(
const std::string& name=std::string());
296 MX add_z(
const std::string& name=std::string());
299 MX add_q(
const std::string& name=std::string());
314 void set_ode(
const std::string& name,
const MX& ode_rhs);
317 void set_alg(
const std::string& name,
const MX& alg_rhs);
320 MX add_aux(
const std::string& name=std::string(), casadi_int n=1);
336 void set_all(
const std::string& v,
const std::vector<std::string>& name);
352 #ifdef WITH_DEPRECATED_FEATURES
355 void set_u(
const std::vector<std::string>& name) { set_all(
"u", name);}
356 void set_x(
const std::vector<std::string>& name) { set_all(
"x", name);}
357 void set_z(
const std::vector<std::string>& name,
358 const std::vector<std::string>& alg = std::vector<std::string>());
359 void set_q(
const std::vector<std::string>& name) { set_all(
"q", name);}
360 void set_y(
const std::vector<std::string>& name) { set_all(
"y", name);}
369 #ifdef WITH_DEPRECATED_FEATURES
371 void clear_in(
const std::string& v) { clear_all(v);}
378 void lift(
bool lift_shared =
true,
bool lift_calls =
true);
390 void sort_z(
const std::vector<std::string>& z_order);
393 void prune(
bool prune_p =
true,
bool prune_u =
true);
406 const std::vector<std::string>& arg,
407 const std::vector<std::string>& res,
const Dict& opts=
Dict());
423 std::vector<Function>
fun()
const;
433 void parse_fmi(
const std::string& filename) {load_fmi_description(filename); }
445 void add_lc(
const std::string& name,
const std::vector<std::string>& f_out);
449 const std::vector<std::string>& name_in,
450 const std::vector<std::string>& name_out,
bool sx,
bool lifted_calls =
false)
const;
461 const std::vector<std::string>& name_in,
462 const std::vector<std::string>& name_out,
476 const std::vector<std::string>& s_in,
477 const std::vector<std::string>& s_out)
const;
481 MX var(
const std::string& name)
const;
486 std::vector<std::string>
der(
const std::vector<std::string>& name)
const;
490 MX beq(
const std::string& name)
const;
508 std::string
type(
const std::string& name, casadi_int fmi_version = 3)
const;
509 void set_type(
const std::string& name,
const std::string& val);
526 std::string
initial(
const std::string& name)
const;
527 void set_initial(
const std::string& name,
const std::string& val);
532 std::string
unit(
const std::string& name)
const;
533 void set_unit(
const std::string& name,
const std::string& val);
543 casadi_int
numel(
const std::string& name)
const;
546 std::vector<casadi_int>
dimension(
const std::string& name)
const;
550 #if !(defined(SWIG) && defined(SWIGMATLAB))
552 std::string
der(
const std::string& name)
const;
555 double attribute(
const std::string& a,
const std::string& name)
const;
558 void set_attribute(
const std::string& a,
const std::string& name,
double val);
561 double min(
const std::string& name)
const;
564 void set_min(
const std::string& name,
double val);
567 double max(
const std::string& name)
const;
570 void set_max(
const std::string& name,
double val);
573 double nominal(
const std::string& name)
const;
579 double start(
const std::string& name)
const;
588 void set(
const std::string& name,
double val);
591 void set(
const std::string& name,
const std::string& val);
599 std::vector<double>
attribute(
const std::string& a,
const std::vector<std::string>& name)
const;
602 void set_attribute(
const std::string& a,
const std::vector<std::string>& name,
603 const std::vector<double>& val);
606 std::vector<double>
min(
const std::vector<std::string>& name)
const;
609 void set_min(
const std::vector<std::string>& name,
const std::vector<double>& val);
612 std::vector<double>
max(
const std::vector<std::string>& name)
const;
615 void set_max(
const std::vector<std::string>& name,
const std::vector<double>& val);
618 std::vector<double>
nominal(
const std::vector<std::string>& name)
const;
621 void set_nominal(
const std::vector<std::string>& name,
const std::vector<double>& val);
624 std::vector<double>
start(
const std::vector<std::string>& name)
const;
627 void set_start(
const std::vector<std::string>& name,
const std::vector<double>& val);
630 void set(
const std::vector<std::string>& name,
const std::vector<double>& val);
633 void set(
const std::vector<std::string>& name,
const std::vector<std::string>& val);
636 std::vector<GenericType>
get(
const std::vector<std::string>& name)
const;
663 Function oracle(
bool sx =
false,
bool elim_w =
false,
bool lifted_calls =
false)
const;
669 const std::vector<std::string>& inames)
const;
673 Variable& new_variable(
const std::string& name, casadi_int numel = 1);
677 Variable& variable(
const std::string& name);
678 const Variable& variable(
const std::string& name)
const;
684 const Variable& variable(
size_t ind)
const;
688 const DaeBuilderInternal* operator->()
const;
691 DaeBuilderInternal* operator->();
694 static bool test_cast(
const SharedObjectInternal* ptr);
697 const MX& var(
size_t ind)
const;
700 std::vector<MX> var(
const std::vector<size_t>& ind)
const;
703 size_t find(
const std::string& name)
const;
706 std::vector<size_t> find(
const std::vector<std::string>& name)
const;
711 const std::string& name(
size_t ind)
const;
716 std::vector<std::string> name(
const std::vector<size_t>& ind)
const;
A symbolic representation of a differential-algebraic equations model.
DaeBuilder(const std::string &name, const std::string &path="", const Dict &opts=Dict())
Construct a DaeBuilder instance.
bool has_fun(const std::string &name) const
Does a particular function already exist?
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.
std::vector< std::string > export_fmu(const Dict &opts=Dict())
Export instance into an FMU.
void register_w(const std::string &name)
void set(const std::vector< std::string > &name, const std::vector< std::string > &val)
Set the current value (string)
std::vector< std::string > q() const
Quadrature states.
casadi_int nu() const
Free controls.
double nominal(const std::string &name) const
Get the nominal value, single variable.
void set_beq(const std::string &name, const MX &val)
void sort_z(const std::vector< std::string > &z_order)
Sort algebraic variables.
Function add_fun(const std::string &name, const Importer &compiler, const Dict &opts=Dict())
Add an external function.
void sanity_check() const
Check if dimensions match.
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.
MX add_variable(const std::string &name, casadi_int n=1)
Add a new variable: returns corresponding symbolic expression.
std::string variability(const std::string &name) const
void set_alg(const std::string &name, const MX &alg_rhs)
Specificy the residual equation for an algebraic variable.
std::vector< double > min(const std::vector< std::string > &name) const
Get the lower bound.
const std::vector< MX > & when_cond() const
When statement: triggering condition.
void set_value_reference(const std::string &name, casadi_int val)
casadi_int nx() const
Differential states.
void set_start(const std::string &name, double val)
Set the start attribute, single variable.
double start(const std::string &name) const
Get the start attribute, single variable.
void sort_d()
Sort dependent parameters.
std::string initial(const std::string &name) const
std::vector< double > attribute(const std::string &a, const std::vector< std::string > &name) const
Get an attribute.
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.
double max(const std::string &name) const
Get the upper bound, single variable.
std::vector< MX > cdef() const
Definitions of named constants.
void set(const std::string &name, const std::string &val)
std::string unit(const std::string &name) const
void clear_all(const std::string &v)
Clear all variables of a type.
void set_min(const std::vector< std::string > &name, const std::vector< double > &val)
Set the lower bound.
void set_max(const std::string &name, double val)
Set the upper bound, single variable.
std::string der(const std::string &name) const
Get the time derivative of an expression, single variable.
Function oracle(bool sx=false, bool elim_w=false, bool lifted_calls=false) const
Get the (cached) oracle, SX or MX.
const MX & t() const
Independent variable (usually time)
MX add_t(const std::string &name="t")
void set_ode(const std::string &name, const MX &ode_rhs)
Specify the ordinary differential equation for a state.
Function fun(const std::string &name) const
Get function by name.
std::vector< std::string > c() const
Named constants.
const std::vector< MX > & init_rhs() const
Initial conditions, right-hand-side.
MX add_p(const std::string &name=std::string())
Add a new parameter.
casadi_int nd() const
Dependent parameters.
void set_attribute(const std::string &a, const std::string &name, double val)
Set an attribute, single variable.
std::vector< std::string > der(const std::vector< std::string > &name) const
Get the time derivative of an expression.
MX add_c(const std::string &name, const MX &new_cdef)
Add a new constant.
void parse_fmi(const std::string &filename)
void gather_fun(casadi_int max_depth=-1)
Collect embedded functions from the expression graph.
MX add_variable(const std::string &name, const Sparsity &sp)
Add a new variable: returns corresponding symbolic expression.
const std::string & name() const
Name of instance.
std::string causality(const std::string &name) const
std::vector< double > start(const std::vector< std::string > &name) const
Get the start attribute.
casadi_int nc() const
Named constants.
void register_c(const std::string &name)
void eliminate_w()
Eliminate all dependent variables.
void set_min(const std::string &name, double val)
Set the lower bound, single variable.
std::vector< MX > wdef() const
Dependent variables and corresponding definitions.
bool has_variable(const std::string &name) const
Check if a particular variable exists.
void tear()
Identify iteration variables and residual equations using naming convention.
std::string type_name() const
Readable name of the class.
void eliminate_quad()
Eliminate quadrature states and turn them into ODE states.
void set_type(const std::string &name, const std::string &val)
double attribute(const std::string &a, const std::string &name) const
Get an attribute, single variable.
void set_unit(const std::string &name, const std::string &val)
std::vector< std::string > derivatives() const
Model structure: derivatives.
bool provides_directional_derivative() const
Does the FMU provide support for analytic derivatives.
std::vector< Function > fun() const
Get all functions.
double min(const std::string &name) const
Get the lower bound, single variable.
void add_when(const MX &cond, const MX &lhs, const MX &rhs)
Add a when statement.
void set_max(const std::vector< std::string > &name, const std::vector< double > &val)
Set the upper bound.
void set_x(const std::vector< std::string > &name)
Function add_fun(const Function &f)
Add an already existing function.
void set_display_unit(const std::string &name, const std::string &val)
std::vector< double > max(const std::vector< std::string > &name) const
Get the upper bound.
size_t add_variable_new(const std::string &name, const Sparsity &sp)
Add a new variable: returns corresponding symbolic expression.
MX operator()(const std::string &name) const
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.
void register_z(const std::string &name)
std::vector< double > nominal(const std::vector< std::string > &name) const
Get the nominal value.
std::vector< MX > alg() const
Algebraic equations.
void add_lc(const std::string &name, const std::vector< std::string > &f_out)
Add a named linear combination of output expressions.
void set_y(const std::vector< std::string > &name)
MX add_u(const std::string &name=std::string())
Add a new control.
std::vector< std::string > x() const
Differential states.
casadi_int nz() const
Algebraic variables.
std::vector< std::string > y() const
Output variables.
size_t add_variable_new(const MX &new_v)
Add a new variable from symbolic expressions.
std::string display_unit(const std::string &name) const
void register_u(const std::string &name)
void set_nominal(const std::string &name, double val)
Set the nominal value, single variable.
std::vector< casadi_int > dimension(const std::string &name) const
Get the dimensions of a variable.
Function create(const std::string &name, const Dict &opts=Dict()) const
Load a function from an FMU DLL, standard IO conforming with simulator.
const std::vector< MX > & aux() const
Auxiliary variables: Used e.g. to define functions.
void set_causality(const std::string &name, const std::string &val)
void prune(bool prune_p=true, bool prune_u=true)
Prune unused controls.
casadi_int nq() const
Quadrature states.
void set_q(const std::vector< std::string > &name)
std::vector< std::string > z() const
Algebraic variables.
MX add_q(const std::string &name=std::string())
Add a new quadrature state.
void set_attribute(const std::string &a, const std::vector< std::string > &name, const std::vector< double > &val)
Set an attribute.
MX add_y(const std::string &name, const MX &new_ydef)
Add a new output.
const std::vector< MX > & when_lhs() const
When statement: left-hand-side.
void set_variability(const std::string &name, const std::string &val)
const std::vector< MX > & when_rhs() const
When statement: right-hand-side.
void set_u(const std::vector< std::string > &name)
std::vector< MX > ode() const
Ordinary differential equations (ODE)
void clear_in(const std::string &v)
[DEPRECATED] Clear input variable: Replaced by clear_all
bool has_t() const
Is there a time variable?
DaeBuilder()
Default constructor.
void set(const std::string &name, double val)
std::vector< std::string > initial_unknowns() const
Model structure: initial unknowns.
void add_init(const MX &lhs, const MX &rhs)
Add an initial equation.
casadi_int value_reference(const std::string &name) const
MX add_z(const std::string &name=std::string())
Add a new algebraic variable.
std::vector< MX > ydef() const
Definitions of output variables.
std::vector< std::string > p() const
Parameters.
Sparsity jac_sparsity(const std::vector< std::string > &onames, const std::vector< std::string > &inames) const
Get Jacobian sparsity.
casadi_int np() const
Parameters.
void set_z(const std::vector< std::string > &name, const std::vector< std::string > &alg=std::vector< std::string >())
std::vector< std::string > d() const
Dependent parameters.
void lift(bool lift_shared=true, bool lift_calls=true)
Lift problem formulation by extracting shared subexpressions.
void sort_w()
Sort dependent variables.
MX var(const std::string &name) const
void register_y(const std::string &name)
MX add_x(const std::string &name=std::string())
Add a new differential state.
void register_q(const std::string &name)
size_t add_variable_new(const std::string &name, casadi_int n=1)
Add a new variable: returns corresponding symbolic expression.
casadi_int ny() const
Output variables.
void set(const std::vector< std::string > &name, const std::vector< double > &val)
Set the current value.
MX add_aux(const std::string &name=std::string(), casadi_int n=1)
Add an auxiliary variable.
void set_all(const std::string &v, const std::vector< std::string > &name)
Set all variables of a type.
const std::vector< MX > & init_lhs() const
Initial conditions, left-hand-side.
void register_t(const std::string &name)
std::vector< std::string > outputs() const
Model structure: outputs.
void load_fmi_description(const std::string &filename)
Import problem description from FMI or XML.
void register_x(const std::string &name)
std::vector< GenericType > get(const std::vector< std::string > &name) const
Evaluate the values for a set of variables at the initial time.
casadi_int numel(const std::string &name) const
Get the number of elements of a variable.
GenericType get(const std::string &name) const
Evaluate the values for a set of variables at the initial time, single value.
std::vector< std::string > w() const
Dependent variables.
std::vector< std::string > all_variables() const
Get a list of all variables.
std::vector< MX > ddef() const
Definitions of dependent parameters.
void register_p(const std::string &name)
casadi_int nw() const
Dependent variables.
MX add_w(const std::string &name, const MX &new_wdef)
Add a new dependent variable.
void register_d(const std::string &name)
void add_variable(const MX &new_v)
Add a new variable from symbolic expressions.
std::string description(const std::string &name) const
void set_initial(const std::string &name, const std::string &val)
std::vector< std::string > u() const
Free controls.
void set_nominal(const std::vector< std::string > &name, const std::vector< double > &val)
Set the nominal value.
void set_start(const std::vector< std::string > &name, const std::vector< double > &val)
Set the start attribute.
std::vector< MX > quad() const
Quadrature equations.
MX beq(const std::string &name) const
std::string type(const std::string &name, casadi_int fmi_version=3) const
MX add_d(const std::string &name, const MX &new_ddef)
Add a new dependent parameter.
void set_description(const std::string &name, const std::string &val)
Generic data type, can hold different types such as bool, casadi_int, std::string etc.
SharedObject implements a reference counting framework similar for efficient and.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
Holds expressions and meta-data corresponding to a physical quantity evolving in time.