26 #ifndef CASADI_DAE_BUILDER_HPP
27 #define CASADI_DAE_BUILDER_HPP
29 #include "function.hpp"
34 class DaeBuilderInternal;
147 public SWIG_IF_ELSE(PrintableCommon, Printable<DaeBuilder>) {
243 explicit DaeBuilder(
const std::string& name,
const std::string& path =
"",
279 const std::string&
name()
const;
360 std::vector<std::string>
t_new()
const {
return all(
"t");}
412 std::vector<std::string>
x()
const {
return all(
"x");}
486 std::vector<std::string>
y()
const {
return all(
"y");}
497 std::vector<std::string>
z()
const {
return all(
"z");}
555 std::vector<std::string>
q()
const {
return all(
"q");}
621 std::vector<MX>
inputs(
const std::string& cat)
const;
688 std::vector<MX>
outputs(
const std::string& cat)
const;
690 #ifdef WITH_DEPRECATED_FEATURES
692 std::vector<MX>
ode()
const {
return outputs(
"ode");}
695 std::vector<MX>
alg()
const {
return outputs(
"alg");}
698 std::vector<MX>
quad()
const {
return outputs(
"quad");}
701 std::vector<MX>
zero()
const {
return outputs(
"zero");}
704 std::vector<MX>
ydef()
const {
return outputs(
"y");}
707 void set_y(
const std::vector<std::string>& name) {set_all(
"y", name);}
718 std::vector<std::string>
u()
const {
return all(
"u");}
761 std::vector<std::string>
p()
const {
return all(
"p");}
772 std::vector<std::string>
c()
const {
return all(
"c");}
795 std::vector<std::string>
d()
const {
return all(
"d");}
863 std::vector<std::string>
w()
const {
return all(
"w");}
928 #ifdef WITH_DEPRECATED_FEATURES
930 std::vector<std::string>
outputs()
const {
return y();}
997 casadi_int
nx()
const;
1219 const std::string& causality,
1220 const std::string& variability,
1231 const std::string& causality,
1250 void add(
const std::string& name,
1251 const std::string& causality,
1252 const std::string& variability,
1483 void when(
const MX& cond,
const std::vector<std::string>& eqs,
const Dict& opts=
Dict());
1573 std::string
assign(
const std::string& name,
const MX& val);
1633 std::string
reinit(
const std::string& name,
const MX& val);
1803 void reorder(
const std::string& cat,
const std::vector<std::string>& v);
1899 void set_all(
const std::string& v,
const std::vector<std::string>& name);
2143 void lift(
bool lift_shared =
true,
bool lift_calls =
true);
2156 void prune(
bool prune_p =
true,
bool prune_u =
true);
2247 const std::vector<std::string>& arg,
2248 const std::vector<std::string>& res,
const Dict& opts=
Dict());
2363 std::vector<Function>
fun()
const;
2427 void parse_fmi(
const std::string& filename) {load_fmi_description(filename); }
2571 void add_lc(
const std::string& name,
const std::vector<std::string>& f_out);
2581 const std::vector<std::string>& name_in,
2582 const std::vector<std::string>& name_out,
bool sx,
bool lifted_calls =
false)
const;
2718 const std::vector<std::string>& name_in,
2719 const std::vector<std::string>& name_out,
2866 const std::vector<std::string>& s_in,
2867 const std::vector<std::string>& s_out)
const;
3114 std::vector<std::string>
der()
const;
3173 std::vector<std::string>
der(
const std::vector<std::string>& name)
const;
3288 std::vector<std::string>
pre(
const std::vector<std::string>& name)
const;
3512 std::string
type(
const std::string& name, casadi_int fmi_version = 3)
const;
3513 void set_type(
const std::string& name,
const std::string& val);
3609 std::vector<std::string>
categories(
const std::string& name)
const;
3926 std::string
initial(
const std::string& name)
const;
3972 std::string
unit(
const std::string& name)
const;
3973 void set_unit(
const std::string& name,
const std::string& val);
4027 casadi_int
numel(
const std::string& name)
const;
4037 std::vector<casadi_int>
dimension(
const std::string& name)
const;
4112 #if !(defined(SWIG) && defined(SWIGMATLAB))
4118 std::string
der(
const std::string& name)
const;
4121 std::string
pre(
const std::string& name)
const;
4194 double attribute(
const std::string& a,
const std::string& name)
const;
4249 double min(
const std::string& name)
const;
4252 void set_min(
const std::string& name,
double val);
4255 double max(
const std::string& name)
const;
4258 void set_max(
const std::string& name,
double val);
4345 std::vector<double>
start(
const std::string& name)
const;
4351 void set_start(
const std::string& name,
const std::vector<double>& val);
4489 void set(
const std::string& name,
double val);
4492 void set(
const std::string& name,
const std::string& val);
4532 std::vector<double>
attribute(
const std::string& a,
const std::vector<std::string>& name)
const;
4536 const std::vector<double>& val);
4539 std::vector<double>
min(
const std::vector<std::string>& name)
const;
4542 void set_min(
const std::vector<std::string>& name,
const std::vector<double>& val);
4545 std::vector<double>
max(
const std::vector<std::string>& name)
const;
4548 void set_max(
const std::vector<std::string>& name,
const std::vector<double>& val);
4551 std::vector<double>
nominal(
const std::vector<std::string>& name)
const;
4554 void set_nominal(
const std::vector<std::string>& name,
const std::vector<double>& val);
4557 std::vector<double>
start(
const std::vector<std::string>& name)
const;
4565 void set_start(
const std::vector<std::string>& name,
const std::vector<double>& val);
4568 void set(
const std::vector<std::string>& name,
const std::vector<double>& val);
4571 void set(
const std::vector<std::string>& name,
const std::vector<std::string>& val);
4574 std::vector<GenericType>
get(
const std::vector<std::string>& name)
const;
4616 bool has(
const std::string& name)
const;
4669 std::vector<std::string>
all()
const;
4677 std::vector<std::string>
all(
const std::string& cat)
const;
4760 Function oracle(
bool sx =
false,
bool elim_w =
false,
bool lifted_calls =
false)
const;
4809 const std::vector<std::string>& inames)
const;
4813 const DaeBuilderInternal* operator->()
const;
4816 DaeBuilderInternal* operator->();
4819 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 (length numel, or 1 to broadcast)
void set(const std::vector< std::string > &name, const std::vector< std::string > &val)
Set the current value (string) for several string variables.
void set_stop_time(double val)
Set the stop time of the default experiment.
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 (1 by default)
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 for several (scalar) variables.
void set_value_reference(const std::string &name, casadi_int val)
Get/set value reference.
casadi_int nx() const
Differential states.
void set_start(const std::string &name, double val)
Set the start attribute, single variable (all elements for a vector-valued 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 of the default experiment, nan when unknown.
std::string initial(const std::string &name) const
Get/set the initial property.
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)
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 (inf by default)
std::vector< MX > cdef() const
Definitions of named constants.
void set(const std::string &name, const std::string &val)
Set the current value, single value (string), for variables of type "String"
std::string unit(const std::string &name) const
Get/set the unit.
MX der(const MX &v)
Differentiate an expression with respect to time.
void set_min(const std::vector< std::string > &name, const std::vector< double > &val)
Set the lower bound for several variables.
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 (vector-valued variables get all elements set)
void reorder(const std::string &cat, const std::vector< std::string > &v)
Reorder variables in a category.
MX der(const MX &v) const
Differentiate an expression with respect to time.
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 of the default experiment, nan when unknown.
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, single variable (not implemented)
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 for several variables, concatenated.
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 of the default experiment.
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)
Get/set the type.
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)
Get/set the unit.
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 of the default experiment, nan when unknown.
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 for several variables.
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)
Get/set the display unit.
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 for several (scalar) variables.
MX operator()(const std::string &name) const
Get variable expression by name.
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 for several (scalar) variables.
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
Get/set the display unit.
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, one value per variable or one value per element.
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 of the default experiment.
DaeBuilder()
Default constructor: a null instance, not usable until assigned.
void set(const std::string &name, double val)
Set the current value, single value.
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.
void reset()
Clear all set values.
std::vector< MX > init_lhs() const
Initial conditions, left-hand-side.
casadi_int value_reference(const std::string &name) const
Get/set value reference.
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
Get variable expression by name.
casadi_int ny() const
Output variables.
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)
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, one entry per name.
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 of the default experiment.
casadi_int nzero() const
Zero-crossing functions.
std::string description(const std::string &name) const
Get/set description.
void set_initial(const std::string &name, const std::string &val)
Get/set the initial property.
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 for several variables.
void set_start(const std::vector< std::string > &name, const std::vector< double > &val)
Set the start attribute for several variables.
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
Get/set the type.
void set_description(const std::string &name, const std::string &val)
Get/set description.
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.