26 #include "fmu_impl.hpp"
27 #include "fmu_function.hpp"
28 #include "dae_builder_internal.hpp"
29 #include "filesystem_impl.hpp"
42 #define THROW_ERROR(FNAME, WHAT) \
43 throw CasadiException("Error in Fmu::" FNAME " for '" + this->name() + "' "\
44 "[" + this->class_name() + "] at " + CASADI_WHERE + ":\n"\
52 const std::vector<std::string>& scheme_in,
53 const std::vector<std::string>& scheme_out,
54 const std::map<std::string, std::vector<size_t>>& scheme,
55 const std::vector<std::string>& aux) {
59 own(
new Fmu2(
name, scheme_in, scheme_out, scheme, aux));
62 casadi_error(
"CasADi was not compiled with WITH_FMI2=ON.");
67 own(
new Fmu3(
name, scheme_in, scheme_out, scheme, aux));
70 casadi_error(
"CasADi was not compiled with WITH_FMI3=ON.");
74 casadi_error(
"Unsupported FMU API: " +
to_string(api));
80 }
catch(std::exception& e) {
81 THROW_ERROR(
"init", e.what());
99 static std::string
null =
"null";
102 return (*this)->name_;
108 static std::string
null =
"null";
111 return (*this)->instance_name_;
117 return (*this)->n_in();
118 }
catch(std::exception& e) {
119 THROW_ERROR(
"n_in", e.what());
125 return (*this)->n_out();
126 }
catch(std::exception& e) {
127 THROW_ERROR(
"n_out", e.what());
133 return (*this)->index_in(n);
134 }
catch(std::exception& e) {
135 THROW_ERROR(
"index_in", e.what());
141 return (*this)->index_out(n);
142 }
catch(std::exception& e) {
143 THROW_ERROR(
"index_out", e.what());
147 const std::vector<size_t>&
Fmu::ired(
size_t ind)
const {
149 return (*this)->ired_.at(ind);
150 }
catch(std::exception& e) {
151 THROW_ERROR(
"ired", e.what());
155 const std::vector<size_t>&
Fmu::ored(
size_t ind)
const {
157 return (*this)->ored_.at(ind);
158 }
catch(std::exception& e) {
159 THROW_ERROR(
"ored", e.what());
165 return (*this)->nominal_in_.at(ind);
166 }
catch(std::exception& e) {
167 THROW_ERROR(
"nominal_in", e.what());
173 return (*this)->nominal_out_.at(ind);
174 }
catch(std::exception& e) {
175 THROW_ERROR(
"nominal_out", e.what());
181 return (*this)->min_in_.at(ind);
182 }
catch(std::exception& e) {
183 THROW_ERROR(
"min_in", e.what());
189 return (*this)->max_in_.at(ind);
190 }
catch(std::exception& e) {
191 THROW_ERROR(
"max_in", e.what());
197 return (*this)->all_nominal_in(ind);
198 }
catch(std::exception& e) {
199 THROW_ERROR(
"all_nominal_in", e.what());
205 return (*this)->all_nominal_out(ind);
206 }
catch(std::exception& e) {
207 THROW_ERROR(
"all_nominal_out", e.what());
213 return (*this)->desc_in(m,
id, more);
214 }
catch(std::exception& e) {
215 THROW_ERROR(
"desc_in", e.what());
221 return (*this)->provides_directional_derivatives_;
222 }
catch(std::exception& e) {
223 THROW_ERROR(
"provides_directional_derivatives", e.what());
229 return (*this)->provides_adjoint_derivatives_;
230 }
catch(std::exception& e) {
231 THROW_ERROR(
"provides_adjoint_derivatives", e.what());
237 return (*this)->can_be_instantiated_only_once_per_process_;
238 }
catch(std::exception& e) {
239 THROW_ERROR(
"can_be_instantiated_only_once_per_process", e.what());
244 const std::vector<size_t>& isub)
const {
246 return (*this)->jac_sparsity(osub, isub);
247 }
catch(std::exception& e) {
248 THROW_ERROR(
"jac_sparsity", e.what());
254 return (*this)->hess_sparsity(r, c);
255 }
catch(std::exception& e) {
256 THROW_ERROR(
"hess_sparsity", e.what());
262 return (*this)->init_mem(m);
263 }
catch(std::exception& e) {
264 THROW_ERROR(
"init_mem", e.what());
271 return (*this)->free_instance(instance);
272 }
catch(std::exception& e) {
273 THROW_ERROR(
"free_instance", e.what());
279 return (*this)->set(m, ind, value);
280 }
catch(std::exception& e) {
281 THROW_ERROR(
"set", e.what());
287 return (*this)->request(m, ind);
288 }
catch(std::exception& e) {
289 THROW_ERROR(
"request", e.what());
295 return (*this)->eval(m);
296 }
catch(std::exception& e) {
297 THROW_ERROR(
"eval", e.what());
303 return (*this)->
get(m,
id, value);
304 }
catch(std::exception& e) {
305 THROW_ERROR(
"get", e.what());
311 return (*this)->set_fwd(m, nseed,
id, v);
312 }
catch(std::exception& e) {
313 THROW_ERROR(
"set_fwd", e.what());
319 return (*this)->set_fwd(m, ind, v);
320 }
catch(std::exception& e) {
321 THROW_ERROR(
"set_fwd", e.what());
326 const casadi_int* wrt_id)
const {
328 return (*this)->request_fwd(m, nsens,
id, wrt_id);
329 }
catch(std::exception& e) {
330 THROW_ERROR(
"request_fwd", e.what());
336 return (*this)->request_fwd(m, ind);
337 }
catch(std::exception& e) {
338 THROW_ERROR(
"request_fwd", e.what());
344 return (*this)->eval_fwd(m, independent_seeds);
345 }
catch(std::exception& e) {
346 THROW_ERROR(
"eval_fwd", e.what());
352 return (*this)->get_fwd(m, nsens,
id, v);
353 }
catch(std::exception& e) {
354 THROW_ERROR(
"get_fwd", e.what());
360 return (*this)->get_fwd(m, ind, v);
361 }
catch(std::exception& e) {
362 THROW_ERROR(
"get_fwd", e.what());
368 return (*this)->set_adj(m, nseed,
id, v);
369 }
catch(std::exception& e) {
370 THROW_ERROR(
"set_adj", e.what());
376 return (*this)->set_adj(m, ind, v);
377 }
catch(std::exception& e) {
378 THROW_ERROR(
"set_adj", e.what());
383 const casadi_int* wrt_id)
const {
385 return (*this)->request_adj(m, nsens,
id, wrt_id);
386 }
catch(std::exception& e) {
387 THROW_ERROR(
"request_adj", e.what());
393 return (*this)->request_adj(m, ind);
394 }
catch(std::exception& e) {
395 THROW_ERROR(
"request_adj", e.what());
401 return (*this)->eval_adj(m);
402 }
catch(std::exception& e) {
403 THROW_ERROR(
"eval_adj", e.what());
409 return (*this)->get_adj(m, nsens,
id, v);
410 }
catch(std::exception& e) {
411 THROW_ERROR(
"get_adj", e.what());
417 return (*this)->get_adj(m, ind, v);
418 }
catch(std::exception& e) {
419 THROW_ERROR(
"get_adj", e.what());
424 const std::vector<std::string>& name_in,
const InputStruct* in)
const {
426 return (*this)->get_stats(m, stats, name_in, in);
427 }
catch(std::exception& e) {
428 THROW_ERROR(
"get_stats", e.what());
433 const std::vector<std::string>& scheme_in,
434 const std::vector<std::string>& scheme_out,
435 const std::map<std::string, std::vector<size_t>>& scheme,
436 const std::vector<std::string>& aux)
437 : name_(name), scheme_in_(scheme_in), scheme_out_(scheme_out), scheme_(scheme), aux_(aux) {
457 std::vector<bool> lookup(dae->
n_variables(),
false);
459 for (
size_t i :
scheme_.at(n)) {
460 casadi_assert(!lookup.at(i),
"Duplicate variable: " + dae->
variable(i).
name);
466 iind_.reserve(numel);
468 for (
size_t k = 0; k < lookup.size(); ++k) {
478 std::fill(lookup.begin(), lookup.end(),
false);
480 for (
size_t i :
scheme_.at(n)) {
481 casadi_assert(!lookup.at(i),
"Duplicate variable: " + dae->
variable(i).
name);
487 oind_.reserve(numel);
489 for (
size_t k = 0; k < lookup.size(); ++k) {
499 for (
size_t i = 0; i <
ired_.size(); ++i) {
501 ired_[i].resize(s.size());
502 for (
size_t k = 0; k < s.size(); ++k) {
508 for (
size_t i = 0; i <
ored_.size(); ++i) {
510 ored_[i].resize(s.size());
511 for (
size_t k = 0; k < s.size(); ++k) {
525 for (
size_t i :
iind_) {
533 if (i != 0) casadi_error(
"Independent variable must be first input of FMU");
543 for (
size_t i :
oind_) {
563 const unsigned int* vr_in,
size_t n_in,
const double* seed,
size_t n_seed,
564 double* sensitivity,
size_t n_sensitivity)
const {
565 casadi_error(
"Adjoint derivatives not supported for " +
class_name());
572 std::replace(instance_name_no_dot.begin(), instance_name_no_dot.end(),
'.',
'_');
591 casadi_error(
"FmuInternal::set_values failed");
595 casadi_error(
"FmuInternal::enter_initialization_mode failed");
599 casadi_error(
"FmuInternal::get_in failed");
603 casadi_error(
"FmuInternal::get_aux failed");
625 for (
size_t i = 0; i <
scheme_in_.size(); ++i) {
629 casadi_error(
"No such input: " + n);
639 casadi_error(
"No such output: " + n);
644 const std::vector<size_t>& isub)
const {
646 std::vector<casadi_int> osub1(osub.begin(), osub.end());
647 std::vector<casadi_int> isub1(isub.begin(), isub.end());
649 std::vector<casadi_int> mapping;
655 const std::vector<size_t>& c)
const {
657 std::vector<casadi_int> r1(r.begin(), r.end());
658 std::vector<casadi_int> c1(c.begin(), c.end());
660 std::vector<casadi_int> mapping;
666 auto&& ind =
ired_.at(i);
667 std::vector<double> n;
668 n.reserve(ind.size());
669 for (
size_t k : ind) n.push_back(
nominal_in_.at(k));
674 auto&& ind =
ored_.at(i);
675 std::vector<double> n;
676 n.reserve(ind.size());
685 #elif defined(__APPLE__)
698 std::stringstream ss;
718 if (
eval_fd(m, independent_seeds))
return 1;
727 if (m->
id_in_.size() == 0)
return 0;
734 casadi_warning(
"FMU adjoint derivative failed");
738 auto it = m->
d_in_.begin();
739 for (
size_t id : m->
id_in_) {
748 size_t n_known = m->
id_in_.size();
749 size_t n_unknown = m->
id_out_.size();
751 if (n_unknown == 0)
return 0;
754 casadi_warning(
"FMU evaluation failed");
763 casadi_warning(
"FMU directional derivative failed");
767 auto it = m->
d_out_.begin();
777 size_t n_known = m->
id_in_.size();
778 size_t n_unknown = m->
id_out_.size();
780 if (n_unknown == 0)
return 0;
783 casadi_warning(
"Evaluating FMU failed");
793 m->
fd_out_.resize(n_points * n_unknown);
799 m->
flip_.resize(n_known);
800 size_t first_flip = -1;
801 for (
size_t i = 0; i < n_known; ++i) {
816 if (first_flip ==
size_t(-1)) first_flip = i;
820 if (first_flip !=
size_t(-1) && !independent_seeds) {
822 for (
size_t i = 0; i < n_known; ++i) {
828 "Cannot perturb both " +
vn_in_[
id] +
" and " +
vn_in_[first_flip]);
835 const double* yk_all[5] = {0};
838 for (casadi_int k = 0; k < n_points; ++k) {
840 double* yk = &m->
fd_out_[n_unknown * k];
841 casadi_assert_dev(k < 5);
849 double pert = (k - offset) * m->
self.
step_;
851 for (
size_t i = 0; i < n_known; ++i) {
863 casadi_warning(
"Setting FMU variables failed");
868 casadi_warning(
"Evaluation failed");
872 if (independent_seeds) {
873 for (
size_t i = 0; i < n_unknown; ++i) {
877 size_t wrt_id = m->
wrt_.at(
id);
880 for (wrt_i = 0; wrt_i < n_known; ++wrt_i) {
881 if (m->
id_in_[wrt_i] == wrt_id)
break;
896 casadi_warning(
"Setting FMU variables failed");
906 if (!independent_seeds) {
908 for (
size_t ind = 0; ind < m->
id_out_.size(); ++ind) {
915 for (
size_t ind = 0; ind < m->
id_out_.size(); ++ind) {
919 size_t wrt = m->
wrt_[id];
922 for (wrt_i = 0; wrt_i < n_known; ++wrt_i) {
923 if (m->
id_in_[wrt_i] == wrt)
break;
928 double d_fd = m->
d_out_[ind] * n;
930 if (m->
flip_[wrt_i]) d_fd = -d_fd;
934 double d_ad = m->
osens_[id];
939 bool d_is_nan = d_ad != d_ad;
941 double d_max = std::fmax(std::fabs(d_fd), std::fabs(d_ad));
944 && std::fabs(d_ad - d_fd) > d_max * m->
self.
reltol_)) {
946 double off = m->
fd_out_.at(ind + offset * n_unknown);
948 std::stringstream ss;
951 ss << (d_is_nan ?
"NaN" :
"Inconsistent") <<
" derivatives of " <<
vn_out_[
id]
952 <<
" w.r.t. " <<
desc_in(m, wrt) <<
", got " << d_ad
955 ss <<
"\nValues for step size " << h <<
": " << (n * off) <<
" + [";
956 for (casadi_int k = 0; k < n_points; ++k) {
957 if (k > 0) ss <<
", ";
958 ss << (n * (m->
fd_out_.at(ind + k * n_unknown) - off));
962 casadi_warning(ss.str());
969 ss << m->
ibuf_[wrt] <<
" ";
986 for (casadi_int k = 0; k < n_points; ++k) {
987 if (k > 0) ss <<
",";
988 ss << (n * (m->
fd_out_.at(ind + k * n_unknown) - off));
990 ss <<
"]" << std::endl;
992 std::ofstream valfile;
1007 for (casadi_int i = 0; i < nsens; ++i) {
1008 *v++ = m->
osens_.at(*
id++);
1016 for (
size_t id :
ored_[ind]) {
1017 casadi_int id2 = id;
1023 const casadi_int*
id,
const double* v)
const {
1024 for (casadi_int i = 0; i < nseed; ++i) {
1025 m->
osens_.at(*
id) = *v++;
1035 for (
size_t id :
ored_[ind]) {
1036 casadi_int id2 = id;
1042 const casadi_int* wrt_id)
const {
1043 for (casadi_int i = 0; i < nsens; ++i) {
1045 m->
wrt_.at(*
id) = *wrt_id++;
1052 casadi_int wrt_id = -1;
1053 for (
size_t id :
ired_[ind]) {
1054 casadi_int id2 = id;
1060 for (casadi_int i = 0; i < nsens; ++i) {
1061 *v++ = m->
isens_.at(*
id++);
1069 for (
size_t id :
ired_[ind]) {
1070 casadi_int id2 = id;
1078 const size_t max_update_iter = 10;
1079 for (
size_t update_iter = 0; update_iter < max_update_iter; ++update_iter) {
1081 casadi_warning(
"update_discrete_states");
1086 casadi_warning(
"Discrete state update not implemented");
1088 casadi_warning(
"Terminate solution not implemented");
1090 casadi_warning(
"Update of nominals of states not implemented");
1092 casadi_warning(
"Update of values of continuous states not implemented");
1094 casadi_warning(
"Ignoring next time defined: " + std::to_string(eventmem.
next_event_time));
1101 casadi_warning(
"Discrete state update failed");
1107 casadi_assert(m->
instance == 0,
"Already instantiated");
1112 casadi_warning(
"FmuInternal::set_values failed");
1130 size_t max_io = std::max(
iind_.size(),
oind_.size());
1132 m->
isens_.resize(max_io);
1135 m->
osens_.resize(max_io);
1144 m->
wrt_.resize(max_io);
1152 for (
size_t id :
ired_[ind]) {
1153 if (*value != m->
ibuf_.at(
id)) {
1154 m->
ibuf_.at(
id) = *value;
1161 for (
size_t id :
ired_[ind]) {
1162 if (0 != m->
ibuf_.at(
id)) {
1163 m->
ibuf_.at(
id) = 0;
1171 for (
size_t id :
ored_[ind]) {
1175 m->
wrt_.at(
id) = -1;
1183 size_t n_set = m->
id_in_.size();
1187 casadi_warning(
"Setting FMU variables failed");
1191 if (
n_out == 0)
return 0;
1195 casadi_warning(
"Evaluation failed");
1199 auto it = m->
v_out_.begin();
1200 for (
size_t id : m->
id_out_) {
1201 m->
obuf_[id] = *it++;
1209 for (
size_t id :
ored_[ind]) {
1210 *value++ = m->
obuf_.at(
id);
1215 const casadi_int*
id,
const double* v)
const {
1216 for (casadi_int i = 0; i < nseed; ++i) {
1217 m->
isens_.at(*
id) = *v++;
1227 for (
size_t id :
ired_[ind]) {
1228 casadi_int id2 = id;
1234 const casadi_int* wrt_id)
const {
1235 for (casadi_int i = 0; i < nsens; ++i) {
1237 m->
wrt_.at(*
id) = *wrt_id++;
1244 casadi_int wrt_id = -1;
1245 for (
size_t id :
ored_[ind]) {
1246 casadi_int id2 = id;
1256 for (
size_t id = 0;
id < m->
imarked_.size(); ++id) {
1267 for (
size_t id = 0;
id < m->
omarked_.size(); ++id) {
1280 size_t n_known = m->
id_in_.size();
1281 size_t n_unknown = m->
id_out_.size();
1284 for (
size_t id : m->
id_in_) {
1289 casadi_assert(n_known != 0,
"No seeds");
1291 m->
v_out_.resize(n_unknown);
1292 m->
d_out_.resize(n_unknown);
1299 size_t n_known = m->
id_in_.size();
1300 size_t n_unknown = m->
id_out_.size();
1303 for (
size_t id : m->
id_out_) {
1308 casadi_assert(n_unknown != 0,
"No seeds");
1310 m->
v_in_.resize(n_known);
1311 m->
d_in_.resize(n_known);
1315 return (*this)->serialize(s);
1373 s.
pack(
"FmuInternal::can_be_instantiated_only_once_per_process",
1413 s.
unpack(
"FmuInternal::can_be_instantiated_only_once_per_process",
1424 casadi_error(
"CasADi was not compiled with WITH_FMI2=ON.");
1428 casadi_error(
"Not implemented");
1430 casadi_error(
"CasADi was not compiled with WITH_FMI2=ON.");
1433 casadi_error(
"Cannot deserialize type '" +
class_name +
"'");
Sparsity jac_sparsity(const std::vector< size_t > &oind, const std::vector< size_t > &iind) const
Get Jacobian sparsity.
size_t n_variables() const
Length of variables array.
bool provides_directional_derivatives_
std::string instantiation_token_
std::string model_identifier_
Variable & variable(size_t ind)
bool can_be_instantiated_only_once_per_process_
bool provides_adjoint_derivatives_
Sparsity hess_sparsity(const std::vector< size_t > &oind, const std::vector< size_t > &iind) const
Get what is known of the Hessian sparsity.
casadi_int number_of_event_indicators_
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
void version(const std::string &name, int v)
static std::string absolute(const std::string &path)
Interface to a binary FMU, adhering to FMI version 2.0.
static Fmu2 * deserialize(DeserializingStream &s)
Interface to a binary FMU, adhering to FMI version 2.0.
std::string validate_ad_file_
bool uses_directional_derivatives_
std::vector< std::string > scheme_out_
std::string instantiation_token_
std::vector< double > max_in_
std::string name_
Instance name.
virtual int get_directional_derivative(void *instance, const unsigned int *vr_out, size_t n_out, const unsigned int *vr_in, size_t n_in, const double *seed, size_t n_seed, double *sensitivity, size_t n_sensitivity) const =0
bool provides_adjoint_derivatives_
std::vector< double > all_nominal_in(size_t i) const
Retreive nominal values.
std::vector< unsigned int > vr_out_
std::string desc_in(FmuMemory *m, size_t id, bool more=true) const
virtual void free_instance(void *c) const =0
std::vector< std::string > vn_out_
void set(FmuMemory *m, size_t ind, const double *value) const
std::vector< size_t > iind_
void serialize(SerializingStream &s) const
void disp(std::ostream &stream, bool more) const override
Print.
FmuInternal(const std::string &name, const std::vector< std::string > &scheme_in, const std::vector< std::string > &scheme_out, const std::map< std::string, std::vector< size_t >> &scheme, const std::vector< std::string > &aux)
std::vector< std::vector< size_t > > ired_
std::vector< std::string > aux_
std::vector< std::vector< size_t > > ored_
std::map< std::string, std::vector< size_t > > scheme_
int discrete_states_iter(void *instance) const
virtual void serialize_body(SerializingStream &s) const
virtual int get_aux(void *instance)=0
virtual int get_real(void *instance, const unsigned int *vr, size_t n_vr, double *values, size_t n_values) const =0
void get_adj(FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
void gather_fwd(FmuMemory *m) const
std::vector< double > nominal_out_
void request(FmuMemory *m, size_t ind) const
void gather_io(FmuMemory *m) const
int eval_fd(FmuMemory *m, bool independent_seeds) const
std::vector< std::string > vn_in_
std::vector< size_t > oind_
virtual void load_functions()=0
~FmuInternal() override
Destructor.
virtual int update_discrete_states(void *instance, EventMemory *eventmem) const =0
static FmuInternal * deserialize(DeserializingStream &s)
void set_fwd(FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
virtual void serialize_type(SerializingStream &s) const
void request_adj(FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
std::vector< unsigned int > vr_in_
virtual void * instantiate() const =0
virtual int exit_initialization_mode(void *instance) const =0
virtual int get_adjoint_derivative(void *instance, const unsigned int *vr_out, size_t n_out, const unsigned int *vr_in, size_t n_in, const double *seed, size_t n_seed, double *sensitivity, size_t n_sensitivity) const
virtual int set_values(void *instance) const =0
std::vector< double > min_out_
bool can_be_instantiated_only_once_per_process_
int eval_ad(FmuMemory *m) const
std::vector< double > nominal_in_
std::vector< double > max_out_
size_t index_out(const std::string &n) const
std::string resource_loc_
std::vector< double > min_in_
static std::string dll_suffix()
void set_adj(FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
std::vector< double > value_in_
void get(FmuMemory *m, size_t id, double *value) const
virtual int set_real(void *instance, const unsigned int *vr, size_t n_vr, const double *values, size_t n_values) const =0
casadi_int number_of_event_indicators_
std::vector< double > all_nominal_out(size_t i) const
Retreive nominal values.
int eval_fwd(FmuMemory *m, bool independent_seeds) const
virtual void init(const DaeBuilderInternal *dae)
size_t n_out() const
Get the number of scheme outputs.
void get_fwd(FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
void gather_adj(FmuMemory *m) const
int init_mem(FmuMemory *m) const
Initalize memory block.
virtual int enter_continuous_time_mode(void *instance) const =0
size_t index_in(const std::string &n) const
void request_fwd(FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
virtual int enter_initialization_mode(void *instance) const =0
Sparsity hess_sparsity(const std::vector< size_t > &r, const std::vector< size_t > &c) const
std::vector< size_t > oind_map_
Sparsity jac_sparsity(const std::vector< size_t > &osub, const std::vector< size_t > &isub) const
std::vector< std::string > scheme_in_
std::string instance_name_
bool provides_directional_derivatives_
virtual std::string system_infix() const =0
int eval_adj(FmuMemory *m) const
int eval(FmuMemory *m) const
std::vector< size_t > iind_map_
void set(FmuMemory *m, size_t ind, const double *value) const
void get_fwd(FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
const std::vector< size_t > & ored(size_t ind) const
static Fmu deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
size_t index_out(const std::string &n) const
int eval_adj(FmuMemory *m) const
Fmu()
Default constructor.
double nominal_out(size_t ind) const
void get_stats(FmuMemory *m, Dict *stats, const std::vector< std::string > &name_in, const InputStruct *in) const
Get stats.
Sparsity hess_sparsity(const std::vector< size_t > &r, const std::vector< size_t > &c) const
bool can_be_instantiated_only_once_per_process() const
Does the FMU declare restrictions on instantiation?
std::vector< double > all_nominal_out(size_t ind) const
bool provides_adjoint_derivatives() const
Does the FMU provide support for adjoint directional derivatives.
Sparsity jac_sparsity(const std::vector< size_t > &osub, const std::vector< size_t > &isub) const
int eval_fwd(FmuMemory *m, bool independent_seeds) const
double nominal_in(size_t ind) const
size_t index_in(const std::string &n) const
void get_adj(FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
double max_in(size_t ind) const
const std::string & name() const
Name of the instance.
void set_fwd(FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
static Fmu create(FmuInternal *node)
Create from node.
size_t n_out() const
Get the number of scheme outputs.
const std::string & instance_name() const
Name of the FMU.
std::vector< double > all_nominal_in(size_t ind) const
double min_in(size_t ind) const
FmuInternal * get() const
FmuInternal * operator->()
void set_adj(FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
int init_mem(FmuMemory *m) const
Initalize memory block.
bool provides_directional_derivatives() const
Does the FMU provide support for forward directional derivatives.
int eval(FmuMemory *m) const
const std::vector< size_t > & ired(size_t ind) const
void request_adj(FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
size_t n_in() const
Get the number of scheme inputs.
void free_instance(void *instance) const
void request(FmuMemory *m, size_t ind) const
void request_fwd(FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
std::string desc_in(FmuMemory *m, size_t id, bool more=true) const
void serialize(SerializingStream &s) const
Serialize an object.
SharedObjectInternal * get() const
Get a const pointer to the node.
bool is_null() const
Is a null pointer?
void own(SharedObjectInternal *node)
SharedObjectInternal * operator->() const
Access a member function or object.
const std::string & path() const
Get path for a consumer.
Helper class for Serialization.
void version(const std::string &name, int v)
void pack(const Sparsity &e)
Serializes an object to the output stream.
virtual std::string class_name() const =0
Readable name of the internal class.
Sparsity sub(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, std::vector< casadi_int > &mapping, bool ind1=false) const
Get a submatrix.
const double eps
Machine epsilon.
casadi_int n_fd_points(FdMode v)
Length of FD stencil, including unperturbed input.
casadi_int fd_offset(FdMode v)
Offset for FD stencil, i.e. index of unperturbed input.
double sign(double x)
Sign function, note that sign(nan) == nan.
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
std::string str(const T &v)
String representation, any type.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
std::string to_string(TypeFmi2 v)
const double nan
Not a number.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.
CASADI_EXPORT void finite_diff(FdMode v, const T1 **yk, T1 *J, T1 h, casadi_int n_y, T1 smoothing)
Calculate FD estimate.
bool discrete_states_need_update
bool terminate_simulation
bool next_event_time_defined
bool nominals_of_continuous_states_changed
bool values_of_continuous_states_changed
std::vector< double > d_in_
std::vector< size_t > id_in_
std::vector< double > obuf_
std::vector< double > isens_
std::vector< bool > in_bounds_
std::vector< double > osens_
std::vector< size_t > wrt_
std::vector< double > d_out_
std::vector< unsigned int > vr_in_
std::vector< double > v_out_
std::vector< bool > flip_
std::vector< double > v_pert_
std::vector< size_t > id_out_
std::vector< double > fd_out_
std::vector< bool > omarked_
std::vector< double > v_in_
std::vector< double > ibuf_
std::vector< bool > imarked_
std::vector< unsigned int > vr_out_
Holds expressions and meta-data corresponding to a physical quantity evolving in time.
std::string name
Name of the variable.
unsigned int value_reference