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>
t_new()
const {
return all(
"t");}
103 std::vector<std::string>
x()
const {
return all(
"x");}
108 std::vector<std::string>
y()
const {
return all(
"y");}
113 std::vector<std::string>
z()
const {
return all(
"z");}
118 std::vector<std::string>
q()
const {
return all(
"q");}
123 std::vector<MX>
inputs(
const std::string& cat)
const;
128 std::vector<MX>
outputs(
const std::string& cat)
const;
130 #ifdef WITH_DEPRECATED_FEATURES
132 std::vector<MX>
ode()
const {
return outputs(
"ode");}
135 std::vector<MX>
alg()
const {
return outputs(
"alg");}
138 std::vector<MX>
quad()
const {
return outputs(
"quad");}
141 std::vector<MX>
zero()
const {
return outputs(
"zero");}
144 std::vector<MX>
ydef()
const {
return outputs(
"y");}
147 void set_y(
const std::vector<std::string>& name) {set_all(
"y", name);}
153 std::vector<std::string>
u()
const {
return all(
"u");}
158 std::vector<std::string>
p()
const {
return all(
"p");}
163 std::vector<std::string>
c()
const {
return all(
"c");}
173 std::vector<std::string>
d()
const {
return all(
"d");}
185 std::vector<std::string>
w()
const {
return all(
"w");}
204 #ifdef WITH_DEPRECATED_FEATURES
206 std::vector<std::string>
outputs()
const {
return y();}
228 casadi_int
nx()
const;
233 casadi_int
nz()
const;
238 casadi_int
nq()
const;
248 casadi_int
ny()
const;
253 casadi_int
nu()
const;
258 casadi_int
np()
const;
263 casadi_int
nc()
const;
268 casadi_int
nd()
const;
273 casadi_int
nw()
const;
283 const std::string& causality,
284 const std::string& variability,
289 const std::string& causality,
297 void add(
const std::string& name,
298 const std::string& causality,
299 const std::string& variability,
307 void when(
const MX& cond,
const std::vector<std::string>& eqs,
const Dict& opts=
Dict());
310 std::string
assign(
const std::string& name,
const MX& val);
313 std::string
reinit(
const std::string& name,
const MX& val);
323 void reorder(
const std::string& cat,
const std::vector<std::string>& v);
326 void set_all(
const std::string& v,
const std::vector<std::string>& name);
338 void sort(
const std::string& cat);
341 void lift(
bool lift_shared =
true,
bool lift_calls =
true);
344 void prune(
bool prune_p =
true,
bool prune_u =
true);
357 const std::vector<std::string>& arg,
358 const std::vector<std::string>& res,
const Dict& opts=
Dict());
374 std::vector<Function>
fun()
const;
384 void parse_fmi(
const std::string& filename) {load_fmi_description(filename); }
416 void add_lc(
const std::string& name,
const std::vector<std::string>& f_out);
420 const std::vector<std::string>& name_in,
421 const std::vector<std::string>& name_out,
bool sx,
bool lifted_calls =
false)
const;
432 const std::vector<std::string>& name_in,
433 const std::vector<std::string>& name_out,
452 const std::vector<std::string>& s_in,
453 const std::vector<std::string>& s_out)
const;
466 MX var(
const std::string& name)
const;
473 std::vector<std::string>
der()
const;
476 std::vector<std::string>
der(
const std::vector<std::string>& name)
const;
485 std::vector<std::string>
pre(
const std::vector<std::string>& name)
const;
494 MX beq(
const std::string& name)
const;
510 std::string
type(
const std::string& name, casadi_int fmi_version = 3)
const;
511 void set_type(
const std::string& name,
const std::string& val);
518 std::vector<std::string>
categories(
const std::string& name)
const;
551 std::string
category(
const std::string& name)
const;
567 std::string
initial(
const std::string& name)
const;
568 void set_initial(
const std::string& name,
const std::string& val);
573 std::string
unit(
const std::string& name)
const;
574 void set_unit(
const std::string& name,
const std::string& val);
584 casadi_int
numel(
const std::string& name)
const;
587 std::vector<casadi_int>
dimension(
const std::string& name)
const;
615 #if !(defined(SWIG) && defined(SWIGMATLAB))
617 std::string
der(
const std::string& name)
const;
620 std::string
pre(
const std::string& name)
const;
623 double attribute(
const std::string& a,
const std::string& name)
const;
626 void set_attribute(
const std::string& a,
const std::string& name,
double val);
629 double min(
const std::string& name)
const;
632 void set_min(
const std::string& name,
double val);
635 double max(
const std::string& name)
const;
638 void set_max(
const std::string& name,
double val);
641 double nominal(
const std::string& name)
const;
647 std::vector<double>
start(
const std::string& name)
const;
653 void set_start(
const std::string& name,
const std::vector<double>& val);
659 void set(
const std::string& name,
double val);
662 void set(
const std::string& name,
const std::string& val);
673 std::vector<double>
attribute(
const std::string& a,
const std::vector<std::string>& name)
const;
676 void set_attribute(
const std::string& a,
const std::vector<std::string>& name,
677 const std::vector<double>& val);
680 std::vector<double>
min(
const std::vector<std::string>& name)
const;
683 void set_min(
const std::vector<std::string>& name,
const std::vector<double>& val);
686 std::vector<double>
max(
const std::vector<std::string>& name)
const;
689 void set_max(
const std::vector<std::string>& name,
const std::vector<double>& val);
692 std::vector<double>
nominal(
const std::vector<std::string>& name)
const;
695 void set_nominal(
const std::vector<std::string>& name,
const std::vector<double>& val);
698 std::vector<double>
start(
const std::vector<std::string>& name)
const;
701 void set_start(
const std::vector<std::string>& name,
const std::vector<double>& val);
704 void set(
const std::vector<std::string>& name,
const std::vector<double>& val);
707 void set(
const std::vector<std::string>& name,
const std::vector<std::string>& val);
710 std::vector<GenericType>
get(
const std::vector<std::string>& name)
const;
713 bool has(
const std::string& name)
const;
716 std::vector<std::string>
all()
const;
719 std::vector<std::string>
all(
const std::string& cat)
const;
722 Function oracle(
bool sx =
false,
bool elim_w =
false,
bool lifted_calls =
false)
const;
728 const std::vector<std::string>& inames)
const;
732 const DaeBuilderInternal* operator->()
const;
735 DaeBuilderInternal* operator->();
738 static bool test_cast(
const SharedObjectInternal* ptr);
A symbolic representation of a differential-algebraic equations model.
double start_time() const
Get the start time.
const MX & time() const
Expression for independent variable (usually time)
std::vector< MX > outputs(const std::string &cat) const
Output expressions for a specific category.
DaeBuilder(const std::string &name, const std::string &path="", const Dict &opts=Dict())
Construct a DaeBuilder instance.
void when(const MX &cond, const std::vector< std::string > &eqs, const Dict &opts=Dict())
Add when equations.
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.
void set_start(const std::string &name, const std::vector< double > &val)
Set the start attribute, vector argument.
void set(const std::vector< std::string > &name, const std::vector< std::string > &val)
Set the current value (string)
void set_stop_time(double val)
Set the stop time.
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.
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.
bool has(const std::string &name) const
Check if a particular variable exists.
std::string variability(const std::string &name) const
Get the variability.
std::vector< double > min(const std::vector< std::string > &name) const
Get the lower bound.
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.
Function transition(const std::string &fname, casadi_int index) const
Construct a function describing transition at a specific events.
double tolerance() const
Get the tolerance.
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 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 model variables, single variable.
Function oracle(bool sx=false, bool elim_w=false, bool lifted_calls=false) const
Get the (cached) oracle, SX or MX.
Function fun(const std::string &name) const
Get function by name.
std::vector< std::string > c() const
Named constants.
std::string category(const std::string &name) const
Get the variable category.
casadi_int nd() const
Dependent parameters.
void set_attribute(const std::string &a, const std::string &name, double val)
Set an attribute, single variable.
void reorder(const std::string &cat, const std::vector< std::string > &v)
Reorder variables in a category.
MX der(const MX &v) const
std::vector< double > start(const std::string &name) const
Get the start attribute, single variable.
std::vector< std::string > der(const std::vector< std::string > &name) const
Get the time derivative of model variables.
double step_size() const
Get the step size.
void parse_fmi(const std::string &filename)
void gather_fun(casadi_int max_depth=-1)
Collect embedded functions from the expression graph.
const std::string & name() const
Name of instance.
std::string pre(const std::string &name) const
Get the pre-variables of model variables.
std::string causality(const std::string &name) const
Get the causality.
std::vector< double > start(const std::vector< std::string > &name) const
Get the start attribute.
casadi_int nc() const
Named constants.
bool provides_directional_derivatives() const
Does the FMU provide support for analytic derivatives.
MX add(const std::string &name, const Dict &opts=Dict())
Add a new model variable, default variability and causality.
void set_tolerance(double val)
Set the tolerance.
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.
std::string assign(const std::string &name, const MX &val)
Assignment inside a when-equation or if-else equation.
void tear()
Identify iteration variables and residual equations using naming convention.
Function transition() const
Construct an event transition function, default naming.
Function create(const std::string &fname, const Dict &opts=Dict()) const
Create a function with standard integrator DAE signature.
std::string type_name() const
Readable name of the class.
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)
void sort(const std::string &cat)
Sort dependent parameters.
std::vector< std::string > derivatives() const
[DEPRECATED] Renamed "der"
bool provides_directional_derivative() const
Does the FMU provide support for analytic derivatives (FMI 2 naming)
double stop_time() const
Get the stop time.
Function create() const
Create a function with standard integrator DAE signature, default naming.
std::vector< Function > fun() const
Get all functions.
double min(const std::string &name) const
Get the lower bound, single variable.
std::vector< std::string > all() const
Get a list of all variables.
void set_max(const std::vector< std::string > &name, const std::vector< double > &val)
Set the upper bound.
Function add_fun(const Function &f)
Add an already existing function.
Function transition(const std::string &fname) const
Construct a function describing transition at any events.
std::vector< std::string > all(const std::string &cat) const
Get a list of all variables of a particular category.
void set_display_unit(const std::string &name, const std::string &val)
std::string reinit(const std::string &name, const MX &val)
Reinitialize a state inside when-equations.
std::vector< double > max(const std::vector< std::string > &name) const
Get the upper bound.
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.
std::vector< double > nominal(const std::vector< std::string > &name) const
Get the nominal value.
std::vector< MX > alg() const
[DEPRECATED] Replaced with outputs("alg")
void set_init(const std::string &name, const MX &init_rhs)
Specify the initial equation for a variable.
void add_lc(const std::string &name, const std::vector< std::string > &f_out)
Add a named linear combination of output expressions.
void eq(const MX &lhs, const MX &rhs, const Dict &opts=Dict())
Add a simple equation.
void set_y(const std::vector< std::string > &name)
[DEPRECATED] Replaced with set_all("y", name)
std::vector< std::string > x() const
Differential states.
void set_category(const std::string &name, const std::string &val)
Set the variable category, if permitted.
casadi_int nz() const
Algebraic variables.
std::vector< std::string > y() const
Outputs.
bool has_beq(const std::string &name) const
Does a variable have a binding equation?
std::string display_unit(const std::string &name) const
MX add(const std::string &name, const std::string &causality, const Dict &opts=Dict())
Add a new model variable, default variability.
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.
MX pre(const MX &v) const
Get the pre-expression given variable expression.
void set_causality(const std::string &name, const std::string &val)
Set the causality, if permitted.
void prune(bool prune_p=true, bool prune_u=true)
Prune unused controls.
casadi_int nq() const
Quadrature states.
std::string pack_fmu(const Dict &files, const Dict &opts=Dict())
Pack files from export_fmu / compile_fmu into a single .fmu archive.
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.
std::vector< std::string > z() const
Algebraic variables.
void set_attribute(const std::string &a, const std::vector< std::string > &name, const std::vector< double > &val)
Set an attribute.
void set_variability(const std::string &name, const std::string &val)
Set the variability, if permitted.
MX add(const std::string &name, const std::string &causality, const std::string &variability, const Dict &opts=Dict())
Add a new model variable.
std::vector< MX > ode() const
[DEPRECATED] Replaced with outputs("ode")
std::vector< std::string > der() const
Model structure: All time derivatives.
bool has_t() const
Is there a time variable?
void set_start_time(double val)
Set the start time.
DaeBuilder()
Default constructor.
void set(const std::string &name, double val)
std::vector< std::string > t_new() const
Independent variable (usually time)
void eliminate(const std::string &cat)
Eliminate all dependent parameters.
std::vector< std::string > initial_unknowns() const
Model structure: initial unknowns.
std::vector< MX > init_lhs() const
Initial conditions, left-hand-side.
casadi_int value_reference(const std::string &name) const
std::vector< MX > ydef() const
[DEPRECATED] Replaced with outputs("y")
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.
std::vector< std::string > categories(const std::string &name) const
Which categories are possible for a variable?
std::vector< std::string > pre(const std::vector< std::string > &name) const
Get the pre-variables of model variables.
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.
MX var(const std::string &name) const
casadi_int ny() const
Output variables.
void set(const std::vector< std::string > &name, const std::vector< double > &val)
Set the current value.
Dict compile_fmu(const Dict &files, const Dict &opts=Dict())
Compile the sources produced by export_fmu.
std::vector< MX > zero() const
[DEPRECATED] Replaced with outputs("zero")
void set_all(const std::string &v, const std::vector< std::string > &name)
Set all variables within a a category.
std::vector< std::string > outputs() const
[DEPRECATED] Renamed "y"
void load_fmi_description(const std::string &filename)
Import problem description from FMI or XML.
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.
Dict export_fmu(const Dict &opts=Dict())
Export instance into an FMU.
std::vector< MX > ddef() const
Definitions of dependent parameters.
casadi_int nw() const
Dependent variables.
bool symbolic() const
Symbolic DAE instance?
std::vector< MX > init_rhs() const
Initial conditions, right-hand-side.
std::vector< MX > inputs(const std::string &cat) const
Input expressions for a specific category.
void set_step_size(double val)
Set the step size.
casadi_int nzero() const
Zero-crossing functions.
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
[DEPRECATED] Replaced with outputs("quad")
MX beq(const std::string &name) const
Get the binding equation for a variable.
std::string type(const std::string &name, casadi_int fmi_version=3) const
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.
GenericShared implements a reference counting framework similar for efficient and.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.