List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
casadi::Fmu2 Class Reference

Interface to a binary FMU, adhering to FMI version 2.0. More...

#include <fmu2.hpp>

Detailed Description

Author
Joel Andersson
Date
2023

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

Definition at line 42 of file fmu2.hpp.

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

Classes

struct  Value
 

Public Types

using weak_ref_type = WeakRefInternal
 

Public Member Functions

 Fmu2 (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)
 
 ~Fmu2 () override
 Destructor. More...
 
std::string class_name () const override
 Get type name. More...
 
void init (const DaeBuilderInternal *dae) override
 
int init_mem (FmuMemory *m) const override
 Initalize memory block. More...
 
FmuMemoryalloc_mem (const FmuFunction &f) const override
 Create memory block. More...
 
void free_mem (void *mem) const override
 Free memory block. More...
 
void finalize () override
 
void load_functions () override
 
std::string system_infix () const override
 
void * instantiate () const override
 
void free_instance (void *instance) const override
 
int reset (void *instance)
 
int enter_initialization_mode (void *instance) const override
 
int exit_initialization_mode (void *instance) const override
 
int enter_continuous_time_mode (void *instance) const override
 
int update_discrete_states (void *instance, EventMemory *eventmem) const override
 
int get_derivatives (void *instance, double *derivatives, size_t nx) const override
 
int set_real (void *instance, const unsigned int *vr, size_t n_vr, const double *values, size_t n_values) const override
 
int get_real (void *instance, const unsigned int *vr, size_t n_vr, double *values, size_t n_values) const override
 
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 override
 
int set_values (void *instance) const override
 
int get_aux (void *instance) override
 
int get_aux_impl (void *instance, Value &aux_value) const
 
void get_stats (FmuMemory *m, Dict *stats, const std::vector< std::string > &name_in, const InputStruct *in) const override
 Get stats. More...
 
void serialize_body (SerializingStream &s) const override
 
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
 
void disp (std::ostream &stream, bool more) const override
 Print. More...
 
size_t n_in () const
 Get the number of scheme inputs. More...
 
size_t n_out () const
 Get the number of scheme outputs. More...
 
size_t index_in (const std::string &n) const
 
size_t index_out (const std::string &n) const
 
Sparsity jac_sparsity (const std::vector< size_t > &osub, const std::vector< size_t > &isub) const
 
Sparsity hess_sparsity (const std::vector< size_t > &r, const std::vector< size_t > &c) const
 
std::string desc_in (FmuMemory *m, size_t id, bool more=true) const
 
template<typename T >
T * load_function (const std::string &symname)
 
int discrete_states_iter (void *instance) const
 
void set (FmuMemory *m, size_t ind, const double *value) const
 
void request (FmuMemory *m, size_t ind) const
 
int eval (FmuMemory *m) const
 
void get (FmuMemory *m, size_t id, double *value) const
 
void set_fwd (FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
 
void set_fwd (FmuMemory *m, size_t ind, const double *v) const
 
void request_fwd (FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
 
void request_fwd (FmuMemory *m, casadi_int ind) const
 
int eval_fwd (FmuMemory *m, bool independent_seeds) const
 
int eval_ad (FmuMemory *m) const
 
int eval_fd (FmuMemory *m, bool independent_seeds) const
 
void get_fwd (FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
 
void get_fwd (FmuMemory *m, size_t ind, double *v) const
 
void set_adj (FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
 
void set_adj (FmuMemory *m, size_t ind, const double *v) const
 
void request_adj (FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
 
void request_adj (FmuMemory *m, casadi_int ind) const
 
int eval_adj (FmuMemory *m) const
 
void get_adj (FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
 
void get_adj (FmuMemory *m, size_t ind, double *v) const
 
void gather_fwd (FmuMemory *m) const
 
void gather_adj (FmuMemory *m) const
 
void gather_io (FmuMemory *m) const
 
void serialize (SerializingStream &s) const
 
virtual void serialize_type (SerializingStream &s) const
 
casadi_int getCount () const
 Get the reference count. More...
 
std::string debug_repr (const SharedObjectInternal *) const
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 
std::vector< double > all_nominal_in (size_t i) const
 Retreive nominal values. More...
 
std::vector< double > all_nominal_out (size_t i) const
 Retreive nominal values. More...
 

Static Public Member Functions

static void logger (fmi2ComponentEnvironment componentEnvironment, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message,...)
 
static Fmu2deserialize (DeserializingStream &s)
 
static std::string dll_suffix ()
 

Public Attributes

std::vector< fmi2ValueReference > vr_real_
 
std::vector< fmi2ValueReference > vr_integer_
 
std::vector< fmi2ValueReference > vr_boolean_
 
std::vector< fmi2ValueReference > vr_string_
 
std::vector< fmi2Real > init_real_
 
std::vector< fmi2Integer > init_integer_
 
std::vector< fmi2Boolean > init_boolean_
 
std::vector< std::string > init_string_
 
std::vector< std::string > vn_aux_real_
 
std::vector< std::string > vn_aux_integer_
 
std::vector< std::string > vn_aux_boolean_
 
std::vector< std::string > vn_aux_string_
 
std::vector< fmi2ValueReference > vr_aux_real_
 
std::vector< fmi2ValueReference > vr_aux_integer_
 
std::vector< fmi2ValueReference > vr_aux_boolean_
 
std::vector< fmi2ValueReference > vr_aux_string_
 
fmi2InstantiateTYPE * instantiate_
 
fmi2FreeInstanceTYPE * free_instance_
 
fmi2ResetTYPE * reset_
 
fmi2SetupExperimentTYPE * setup_experiment_
 
fmi2EnterInitializationModeTYPE * enter_initialization_mode_
 
fmi2ExitInitializationModeTYPE * exit_initialization_mode_
 
fmi2EnterContinuousTimeModeTYPE * enter_continuous_time_mode_
 
fmi2GetDerivativesTYPE * get_derivatives_
 
fmi2SetTimeTYPE * set_time_
 
fmi2GetRealTYPE * get_real_
 
fmi2SetRealTYPE * set_real_
 
fmi2GetBooleanTYPE * get_boolean_
 
fmi2SetBooleanTYPE * set_boolean_
 
fmi2GetIntegerTYPE * get_integer_
 
fmi2SetIntegerTYPE * set_integer_
 
fmi2GetStringTYPE * get_string_
 
fmi2SetStringTYPE * set_string_
 
fmi2GetDirectionalDerivativeTYPE * get_directional_derivative_
 
fmi2NewDiscreteStatesTYPE * new_discrete_states_
 
fmi2CallbackFunctions functions_
 
Value aux_value_
 

Protected Member Functions

 Fmu2 (DeserializingStream &s)
 
void initSingleton ()
 
void destroySingleton ()
 
shared_from_this ()
 Get a shared object from the current internal object. More...
 
const B shared_from_this () const
 Get a shared object from the current internal object. More...
 

Protected Attributes

Resource resource_
 
std::string name_
 Instance name. More...
 
std::vector< std::string > scheme_in_
 
std::vector< std::string > scheme_out_
 
std::map< std::string, std::vector< size_t > > scheme_
 
std::vector< std::string > aux_
 
std::string resource_loc_
 
double fmutol_
 
std::string instance_name_
 
std::string instantiation_token_
 
bool logging_on_
 
casadi_int number_of_event_indicators_
 
bool provides_directional_derivatives_
 
bool provides_adjoint_derivatives_
 
bool can_be_instantiated_only_once_per_process_
 
Importer li_
 DLL. More...
 
std::vector< size_t > iind_
 
std::vector< size_t > iind_map_
 
std::vector< size_t > oind_
 
std::vector< size_t > oind_map_
 
bool has_independent_
 
std::vector< double > nominal_in_
 
std::vector< double > nominal_out_
 
std::vector< double > min_in_
 
std::vector< double > min_out_
 
std::vector< double > max_in_
 
std::vector< double > max_out_
 
std::vector< std::string > vn_in_
 
std::vector< std::string > vn_out_
 
std::vector< unsigned int > vr_in_
 
std::vector< unsigned int > vr_out_
 
std::vector< double > value_in_
 
std::vector< std::vector< size_t > > ired_
 
std::vector< std::vector< size_t > > ored_
 
Sparsity jac_sp_
 
Sparsity hess_sp_
 
bool warning_fired_discrete_states_need_update_
 
bool warning_fired_terminate_simulation_
 
bool warning_fired_nominals_of_continuous_states_changed_
 
bool warning_fired_values_of_continuous_states_changed_
 
bool warning_fired_next_event_time_defined_
 
size_t nx_
 
bool do_evaluation_dance_
 

Member Typedef Documentation

◆ weak_ref_type

Definition at line 152 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ Fmu2() [1/2]

casadi::Fmu2::Fmu2 ( 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 
)

Definition at line 517 of file fmu2.cpp.

522  : FmuInternal(name, scheme_in, scheme_out, scheme, aux) {
523  instantiate_ = 0;
524  free_instance_ = 0;
525  reset_ = 0;
526  setup_experiment_ = 0;
530  set_time_ = 0;
531  set_real_ = 0;
532  set_boolean_ = 0;
533  get_real_ = 0;
536 }
fmi2ExitInitializationModeTYPE * exit_initialization_mode_
Definition: fmu2.hpp:100
fmi2SetupExperimentTYPE * setup_experiment_
Definition: fmu2.hpp:98
fmi2EnterInitializationModeTYPE * enter_initialization_mode_
Definition: fmu2.hpp:99
fmi2InstantiateTYPE * instantiate_
Definition: fmu2.hpp:95
fmi2SetTimeTYPE * set_time_
Definition: fmu2.hpp:103
fmi2ResetTYPE * reset_
Definition: fmu2.hpp:97
fmi2SetBooleanTYPE * set_boolean_
Definition: fmu2.hpp:107
fmi2SetRealTYPE * set_real_
Definition: fmu2.hpp:105
fmi2GetDirectionalDerivativeTYPE * get_directional_derivative_
Definition: fmu2.hpp:112
fmi2FreeInstanceTYPE * free_instance_
Definition: fmu2.hpp:96
fmi2EnterContinuousTimeModeTYPE * enter_continuous_time_mode_
Definition: fmu2.hpp:101
fmi2NewDiscreteStatesTYPE * new_discrete_states_
Definition: fmu2.hpp:113
fmi2GetRealTYPE * get_real_
Definition: fmu2.hpp:104
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)
Definition: fmu.cpp:440

References enter_continuous_time_mode_, enter_initialization_mode_, exit_initialization_mode_, free_instance_, get_directional_derivative_, get_real_, instantiate_, new_discrete_states_, reset_, set_boolean_, set_real_, set_time_, and setup_experiment_.

Referenced by deserialize().

◆ ~Fmu2()

casadi::Fmu2::~Fmu2 ( )
override

Definition at line 58 of file fmu2.cpp.

58  {
59 }

◆ Fmu2() [2/2]

casadi::Fmu2::Fmu2 ( DeserializingStream s)
explicitprotected

Definition at line 544 of file fmu2.cpp.

544  : FmuInternal(s) {
545  instantiate_ = 0;
546  free_instance_ = 0;
547  reset_ = 0;
548  setup_experiment_ = 0;
552  set_real_ = 0;
553  set_boolean_ = 0;
554  get_real_ = 0;
557 
558  s.version("Fmu2", 2);
559  s.unpack("Fmu2::vr_real", vr_real_);
560  s.unpack("Fmu2::vr_integer", vr_integer_);
561  s.unpack("Fmu2::vr_boolean", vr_boolean_);
562  s.unpack("Fmu2::vr_string", vr_string_);
563  s.unpack("Fmu2::init_real", init_real_);
564  s.unpack("Fmu2::init_integer", init_integer_);
565  s.unpack("Fmu2::init_boolean", init_boolean_);
566  s.unpack("Fmu2::init_string", init_string_);
567 
568  s.unpack("Fmu2::vn_aux_real", vn_aux_real_);
569  s.unpack("Fmu2::vn_aux_integer", vn_aux_integer_);
570  s.unpack("Fmu2::vn_aux_boolean", vn_aux_boolean_);
571  s.unpack("Fmu2::vn_aux_string", vn_aux_string_);
572  s.unpack("Fmu2::vr_aux_real", vr_aux_real_);
573  s.unpack("Fmu2::vr_aux_integer", vr_aux_integer_);
574  s.unpack("Fmu2::vr_aux_boolean", vr_aux_boolean_);
575  s.unpack("Fmu2::vr_aux_string", vr_aux_string_);
576 }
std::vector< fmi2ValueReference > vr_string_
Definition: fmu2.hpp:82
std::vector< fmi2Real > init_real_
Definition: fmu2.hpp:83
std::vector< fmi2ValueReference > vr_boolean_
Definition: fmu2.hpp:82
std::vector< fmi2Boolean > init_boolean_
Definition: fmu2.hpp:85
std::vector< std::string > vn_aux_integer_
Definition: fmu2.hpp:89
std::vector< std::string > vn_aux_string_
Definition: fmu2.hpp:89
std::vector< fmi2Integer > init_integer_
Definition: fmu2.hpp:84
std::vector< std::string > vn_aux_real_
Definition: fmu2.hpp:89
std::vector< fmi2ValueReference > vr_integer_
Definition: fmu2.hpp:82
std::vector< std::string > vn_aux_boolean_
Definition: fmu2.hpp:89
std::vector< fmi2ValueReference > vr_aux_string_
Definition: fmu2.hpp:90
std::vector< fmi2ValueReference > vr_aux_integer_
Definition: fmu2.hpp:90
std::vector< fmi2ValueReference > vr_real_
Definition: fmu2.hpp:82
std::vector< fmi2ValueReference > vr_aux_real_
Definition: fmu2.hpp:90
std::vector< std::string > init_string_
Definition: fmu2.hpp:86
std::vector< fmi2ValueReference > vr_aux_boolean_
Definition: fmu2.hpp:90

References enter_continuous_time_mode_, enter_initialization_mode_, exit_initialization_mode_, free_instance_, get_directional_derivative_, get_real_, init_boolean_, init_integer_, init_real_, init_string_, instantiate_, new_discrete_states_, reset_, set_boolean_, set_real_, setup_experiment_, casadi::DeserializingStream::unpack(), casadi::DeserializingStream::version(), vn_aux_boolean_, vn_aux_integer_, vn_aux_real_, vn_aux_string_, vr_aux_boolean_, vr_aux_integer_, vr_aux_real_, vr_aux_string_, vr_boolean_, vr_integer_, vr_real_, and vr_string_.

Member Function Documentation

◆ all_nominal_in()

std::vector< double > casadi::FmuInternal::all_nominal_in ( size_t  i) const
inherited

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

Definition at line 687 of file fmu.cpp.

687  {
688  auto&& ind = ired_.at(i);
689  std::vector<double> n;
690  n.reserve(ind.size());
691  for (size_t k : ind) n.push_back(nominal_in_.at(k));
692  return n;
693 }
std::vector< std::vector< size_t > > ired_
Definition: fmu_impl.hpp:340
std::vector< double > nominal_in_
Definition: fmu_impl.hpp:330

References casadi::FmuInternal::ired_, and casadi::FmuInternal::nominal_in_.

◆ all_nominal_out()

std::vector< double > casadi::FmuInternal::all_nominal_out ( size_t  i) const
inherited

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

Definition at line 695 of file fmu.cpp.

695  {
696  auto&& ind = ored_.at(i);
697  std::vector<double> n;
698  n.reserve(ind.size());
699  for (size_t k : ind) n.push_back(nominal_out_.at(k));
700  return n;
701 }
std::vector< std::vector< size_t > > ored_
Definition: fmu_impl.hpp:340
std::vector< double > nominal_out_
Definition: fmu_impl.hpp:330

References casadi::FmuInternal::nominal_out_, and casadi::FmuInternal::ored_.

◆ alloc_mem()

FmuMemory * casadi::Fmu2::alloc_mem ( const FmuFunction f) const
overridevirtual

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

Implements casadi::FmuInternal.

Definition at line 50 of file fmu2.cpp.

50  {
51  return new Fmu2Memory(f);
52 }

◆ class_name()

std::string casadi::Fmu2::class_name ( ) const
inlineoverridevirtual

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

Implements casadi::SharedObjectInternal.

Definition at line 55 of file fmu2.hpp.

55 { return "Fmu2";}

◆ debug_repr()

std::string casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::debug_repr ( const Internal *  i) const
inherited

Definition at line 62 of file generic_shared_internal.hpp.

162  {
163  // Note: i != this because of something something multiple inheritance
164  return str( (casadi_int)(i)) + "/" + static_cast<const Internal*>(this)->class_name();
165  }
std::string str(const T &v)
String representation, any type.

◆ desc_in()

std::string casadi::FmuInternal::desc_in ( FmuMemory m,
size_t  id,
bool  more = true 
) const
inherited

Definition at line 716 of file fmu.cpp.

716  {
717  // Create description
718  if (more) {
719  // Detailed description
720  std::stringstream ss;
721  ss << vn_in_[id] << " = " << m->ibuf_[id] << " (nominal " << nominal_in_[id]
722  << ", min " << min_in_[id] << ", max " << max_in_[id] << ")";
723  return ss.str();
724  } else {
725  return vn_in_[id];
726  }
727 }
std::vector< double > max_in_
Definition: fmu_impl.hpp:332
std::vector< std::string > vn_in_
Definition: fmu_impl.hpp:333
std::vector< double > min_in_
Definition: fmu_impl.hpp:331

References casadi::FmuMemory::ibuf_, casadi::FmuInternal::max_in_, casadi::FmuInternal::min_in_, casadi::FmuInternal::nominal_in_, and casadi::FmuInternal::vn_in_.

Referenced by casadi::FmuInternal::eval_fd().

◆ deserialize()

Fmu2 * casadi::Fmu2::deserialize ( DeserializingStream s)
static

Definition at line 538 of file fmu2.cpp.

538  {
539  Fmu2* ret = new Fmu2(s);
540  ret->finalize();
541  return ret;
542 }
Fmu2(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)
Definition: fmu2.cpp:517

References finalize(), and Fmu2().

Referenced by casadi::FmuInternal::deserialize().

◆ destroySingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::destroySingleton ( )
inlineprotectedinherited

Called in the destructor of singletons

Definition at line 77 of file generic_shared_internal.hpp.

77  {
78  static_cast<Internal*>(this)->count--;
79  }

◆ discrete_states_iter()

int casadi::FmuInternal::discrete_states_iter ( void *  instance) const
inherited

Definition at line 1098 of file fmu.cpp.

1098  {
1099  // Helper function: update_discrete_states
1100  EventMemory eventmem;
1101  const size_t max_update_iter = 10;
1102  for (size_t update_iter = 0; update_iter < max_update_iter; ++update_iter) {
1103  if (update_discrete_states(instance, &eventmem)) {
1104  casadi_warning("update_discrete_states");
1105  return 1;
1106  }
1107  // Not implemented
1108  if (eventmem.discrete_states_need_update) {
1111  casadi_warning("Discrete state update not implemented");
1112  }
1113  }
1114  if (eventmem.terminate_simulation) {
1117  casadi_warning("Terminate simulation not implemented");
1118  }
1119  }
1120  if (eventmem.nominals_of_continuous_states_changed) {
1123  casadi_warning("Nominals of continuous states not implemented");
1124  }
1125  }
1126  if (eventmem.values_of_continuous_states_changed) {
1129  casadi_warning("Values of continuous states not implemented");
1130  }
1131  }
1132  if (eventmem.next_event_time_defined) {
1135  casadi_warning("Next event time not implemented");
1136  }
1137  }
1138  // Successful return
1139  if (!eventmem.discrete_states_need_update) {
1140  return 0;
1141  }
1142  }
1143  // Too many iterations
1144  casadi_warning("Discrete state update failed");
1145  return 1;
1146 }
bool warning_fired_values_of_continuous_states_changed_
Definition: fmu_impl.hpp:348
bool warning_fired_next_event_time_defined_
Definition: fmu_impl.hpp:349
bool warning_fired_nominals_of_continuous_states_changed_
Definition: fmu_impl.hpp:347
bool warning_fired_terminate_simulation_
Definition: fmu_impl.hpp:346
bool warning_fired_discrete_states_need_update_
Definition: fmu_impl.hpp:345
virtual int update_discrete_states(void *instance, EventMemory *eventmem) const =0

References casadi::EventMemory::discrete_states_need_update, casadi::EventMemory::next_event_time_defined, casadi::EventMemory::nominals_of_continuous_states_changed, casadi::EventMemory::terminate_simulation, casadi::FmuInternal::update_discrete_states(), casadi::EventMemory::values_of_continuous_states_changed, casadi::FmuInternal::warning_fired_discrete_states_need_update_, casadi::FmuInternal::warning_fired_next_event_time_defined_, casadi::FmuInternal::warning_fired_nominals_of_continuous_states_changed_, casadi::FmuInternal::warning_fired_terminate_simulation_, and casadi::FmuInternal::warning_fired_values_of_continuous_states_changed_.

Referenced by casadi::FmuInternal::init_mem().

◆ disp()

void casadi::FmuInternal::disp ( std::ostream &  stream,
bool  more 
) const
overridevirtualinherited

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

Implements casadi::SharedObjectInternal.

Definition at line 631 of file fmu.cpp.

631  {
632  (void)more; // unused
633  stream << name_ << " " << class_name();
634 }
std::string name_
Instance name.
Definition: fmu_impl.hpp:287
virtual std::string class_name() const =0
Readable name of the internal class.

References casadi::SharedObjectInternal::class_name(), and casadi::FmuInternal::name_.

◆ dll_suffix()

std::string casadi::FmuInternal::dll_suffix ( )
staticinherited

Definition at line 703 of file fmu.cpp.

703  {
704 #if defined(_WIN32)
705  // Windows system
706  return ".dll";
707 #elif defined(__APPLE__)
708  // OSX
709  return ".dylib";
710 #else
711  // Linux
712  return ".so";
713 #endif
714 }

Referenced by casadi::FmuInternal::finalize().

◆ enter_continuous_time_mode()

int casadi::Fmu2::enter_continuous_time_mode ( void *  instance) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 301 of file fmu2.cpp.

301  {
302  auto c = static_cast<fmi2Component>(instance);
303  fmi2Status status = enter_continuous_time_mode_(c);
304  if (status != fmi2OK) {
305  casadi_warning("fmi2EnterContinuousTimeMode failed");
306  return 1;
307  }
308  return 0;
309 }

References enter_continuous_time_mode_.

◆ enter_initialization_mode()

int casadi::Fmu2::enter_initialization_mode ( void *  instance) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 281 of file fmu2.cpp.

281  {
282  auto c = static_cast<fmi2Component>(instance);
283  fmi2Status status = enter_initialization_mode_(c);
284  if (status != fmi2OK) {
285  casadi_warning("fmi2EnterInitializationMode failed: " + str(status));
286  return 1;
287  }
288  return 0;
289 }

References enter_initialization_mode_, and casadi::str().

◆ eval()

int casadi::FmuInternal::eval ( FmuMemory m) const
inherited

Definition at line 1222 of file fmu.cpp.

1222  {
1223  // Gather inputs and outputs
1224  gather_io(m);
1225  // Number of inputs and outputs
1226  size_t n_set = m->id_in_.size();
1227  size_t n_out = m->id_out_.size();
1228  // Set all variables
1229  if (set_real(m->instance, get_ptr(m->vr_in_), n_set, get_ptr(m->v_in_), n_set)) {
1230  casadi_warning("Setting FMU variables failed");
1231  return 1;
1232  }
1233  // Quick return if nothing requested
1234  if (n_out == 0) return 0;
1235  // Calculate all variables
1236  m->v_out_.resize(n_out);
1237  if (get_real(m->instance, get_ptr(m->vr_out_), n_out, get_ptr(m->v_out_), n_out)) {
1238  casadi_warning("Evaluation failed");
1239  return 1;
1240  }
1241  // Collect requested variables
1242  auto it = m->v_out_.begin();
1243  for (size_t id : m->id_out_) {
1244  m->obuf_[id] = *it++;
1245  }
1246  // Successful return
1247  return 0;
1248 }
virtual int get_real(void *instance, const unsigned int *vr, size_t n_vr, double *values, size_t n_values) const =0
void gather_io(FmuMemory *m) const
Definition: fmu.cpp:1294
virtual int set_real(void *instance, const unsigned int *vr, size_t n_vr, const double *values, size_t n_values) const =0
size_t n_out() const
Get the number of scheme outputs.
Definition: fmu_impl.hpp:132
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.

References casadi::FmuInternal::gather_io(), casadi::get_ptr(), casadi::FmuInternal::get_real(), casadi::FmuMemory::id_in_, casadi::FmuMemory::id_out_, casadi::FmuMemory::instance, casadi::FmuInternal::n_out(), casadi::FmuMemory::obuf_, casadi::FmuInternal::set_real(), casadi::FmuMemory::v_in_, casadi::FmuMemory::v_out_, casadi::FmuMemory::vr_in_, and casadi::FmuMemory::vr_out_.

◆ eval_ad()

int casadi::FmuInternal::eval_ad ( FmuMemory m) const
inherited

Definition at line 768 of file fmu.cpp.

768  {
769  // Number of inputs and outputs
770  size_t n_known = m->id_in_.size();
771  size_t n_unknown = m->id_out_.size();
772  // Quick return if nothing to be calculated
773  if (n_unknown == 0) return 0;
774  // Evalute (should not be necessary)
775  if (get_real(m->instance, get_ptr(m->vr_out_), n_unknown, get_ptr(m->v_out_), n_unknown)) {
776  casadi_warning("FMU evaluation failed");
777  return 1;
778  }
779  // Evaluate directional derivatives
780  if (get_directional_derivative(m->instance,
781  get_ptr(m->vr_out_), n_unknown,
782  get_ptr(m->vr_in_), n_known,
783  get_ptr(m->d_in_), n_known,
784  get_ptr(m->d_out_), n_unknown)) {
785  casadi_warning("FMU directional derivative failed");
786  return 1;
787  }
788  // Collect requested variables
789  auto it = m->d_out_.begin();
790  for (size_t id : m->id_out_) {
791  m->osens_[id] = *it++;
792  }
793  // Successful return
794  return 0;
795 }
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

References casadi::FmuMemory::d_in_, casadi::FmuMemory::d_out_, casadi::FmuInternal::get_directional_derivative(), casadi::get_ptr(), casadi::FmuInternal::get_real(), casadi::FmuMemory::id_in_, casadi::FmuMemory::id_out_, casadi::FmuMemory::instance, casadi::FmuMemory::osens_, casadi::FmuMemory::v_out_, casadi::FmuMemory::vr_in_, and casadi::FmuMemory::vr_out_.

Referenced by casadi::FmuInternal::eval_fwd().

◆ eval_adj()

int casadi::FmuInternal::eval_adj ( FmuMemory m) const
inherited

Definition at line 745 of file fmu.cpp.

745  {
746  // Gather input and output indices
747  gather_adj(m);
748  // Quick return if nothing to be calculated
749  if (m->id_in_.size() == 0) return 0;
750  // Evaluate adjoint derivatives
751  if (get_adjoint_derivative(m->instance,
752  get_ptr(m->vr_out_), m->id_out_.size(),
753  get_ptr(m->vr_in_), m->id_in_.size(),
754  get_ptr(m->d_out_), m->id_out_.size(),
755  get_ptr(m->d_in_), m->id_in_.size())) {
756  casadi_warning("FMU adjoint derivative failed");
757  return 1;
758  }
759  // Collect requested variables
760  auto it = m->d_in_.begin();
761  for (size_t id : m->id_in_) {
762  m->isens_[id] = *it++;
763  }
764  // Successful return
765  return 0;
766 }
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
Definition: fmu.cpp:572
void gather_adj(FmuMemory *m) const
Definition: fmu.cpp:1338

References casadi::FmuMemory::d_in_, casadi::FmuMemory::d_out_, casadi::FmuInternal::gather_adj(), casadi::FmuInternal::get_adjoint_derivative(), casadi::get_ptr(), casadi::FmuMemory::id_in_, casadi::FmuMemory::id_out_, casadi::FmuMemory::instance, casadi::FmuMemory::isens_, casadi::FmuMemory::vr_in_, and casadi::FmuMemory::vr_out_.

◆ eval_fd()

int casadi::FmuInternal::eval_fd ( FmuMemory m,
bool  independent_seeds 
) const
inherited

Definition at line 797 of file fmu.cpp.

797  {
798  // Number of inputs and outputs
799  size_t n_known = m->id_in_.size();
800  size_t n_unknown = m->id_out_.size();
801  // Quick return if nothing to be calculated
802  if (n_unknown == 0) return 0;
803  // Evalute (should not be necessary)
804  if (get_real(m->instance, get_ptr(m->vr_out_), n_unknown, get_ptr(m->v_out_), n_unknown)) {
805  casadi_warning("Evaluating FMU failed");
806  return 1;
807  }
808  // Make outputs dimensionless
809  for (size_t k = 0; k < n_unknown; ++k) m->v_out_[k] /= nominal_out_[m->id_out_[k]];
810  // Number of points in FD stencil
811  casadi_int n_points = n_fd_points(m->self.fd_);
812  // Offset for points
813  casadi_int offset = fd_offset(m->self.fd_);
814  // Memory for perturbed outputs
815  m->fd_out_.resize(n_points * n_unknown);
816  // Which inputs are in bounds
817  m->in_bounds_.resize(n_known);
818  // Memory for perturbed inputs
819  m->v_pert_.resize(n_known);
820  // Do any any inputs need flipping?
821  m->flip_.resize(n_known);
822  size_t first_flip = -1;
823  for (size_t i = 0; i < n_known; ++i) {
824  // Try to take step
825  double test = m->v_in_[i] + m->self.step_ * m->d_in_[i];
826  // Check if in bounds
827  size_t id = m->id_in_[i];
828  if (test >= min_in_[id] && test <= max_in_[id]) {
829  // Positive perturbation is fine
830  m->flip_[i] = false;
831  } else {
832  // Try negative direction instead
833  test = m->v_in_[i] - m->self.step_ * m->d_in_[i];
834  casadi_assert(test >= min_in_[id] && test <= max_in_[id],
835  "Cannot perturb " + vn_in_[id] + " at " + str(m->v_in_[i]) + ", min " + str(min_in_[id])
836  + ", max " + str(max_in_[id]) + ", nominal " + str(nominal_in_[id]));
837  m->flip_[i] = true;
838  if (first_flip == size_t(-1)) first_flip = i;
839  }
840  }
841  // If seeds are not independent, we have to flip the sign for all of the seeds or none
842  if (first_flip != size_t(-1) && !independent_seeds) {
843  // Flip the rest of the seeds
844  for (size_t i = 0; i < n_known; ++i) {
845  if (!m->flip_[i]) {
846  // Test negative direction
847  double test = m->v_in_[i] - m->self.step_ * m->d_in_[i];
848  size_t id = m->id_in_[i];
849  casadi_assert(test >= min_in_[id] && test <= max_in_[id],
850  "Cannot perturb both " + vn_in_[id] + " and " + vn_in_[first_flip]);
851  // Flip it too
852  m->flip_[i] = true;
853  }
854  }
855  }
856  // All perturbed outputs
857  const double* yk_all[5] = {0};
858 
859  // Calculate all perturbed outputs
860  for (casadi_int k = 0; k < n_points; ++k) {
861  // Where to save the perturbed outputs
862  double* yk = &m->fd_out_[n_unknown * k];
863  casadi_assert_dev(k < 5);
864  yk_all[k] = yk;
865  // If unperturbed output, quick return
866  if (k == offset) {
867  casadi_copy(get_ptr(m->v_out_), n_unknown, yk);
868  continue;
869  }
870  // Perturbation size
871  double pert = (k - offset) * m->self.step_;
872  // Perturb inputs, if allowed
873  for (size_t i = 0; i < n_known; ++i) {
874  // Try to take step
875  double sign = m->flip_[i] ? -1 : 1;
876  double test = m->v_in_[i] + pert * sign * m->d_in_[i];
877  // Check if in bounds
878  size_t id = m->id_in_[i];
879  m->in_bounds_[i] = test >= min_in_[id] && test <= max_in_[id];
880  // Take step, if allowed
881  m->v_pert_[i] = m->in_bounds_[i] ? test : m->v_in_[i];
882  }
883  // Pass perturbed inputs to FMU
884  if (set_real(m->instance, get_ptr(m->vr_in_), n_known, get_ptr(m->v_pert_), n_known)) {
885  casadi_warning("Setting FMU variables failed");
886  return 1;
887  }
888  // Evaluate perturbed FMU
889  if (get_real(m->instance, get_ptr(m->vr_out_), n_unknown, yk, n_unknown)) {
890  casadi_warning("Evaluation failed");
891  return 1;
892  }
893  // Post-process yk if there was any scaling
894  if (independent_seeds) {
895  for (size_t i = 0; i < n_unknown; ++i) {
896  // Variable id
897  size_t id = m->id_out_[i];
898  // Differentiation with respect to what variable
899  size_t wrt_id = m->wrt_.at(id);
900  // Find the corresponding input variable
901  size_t wrt_i;
902  for (wrt_i = 0; wrt_i < n_known; ++wrt_i) {
903  if (m->id_in_[wrt_i] == wrt_id) break;
904  }
905  // Check if in bounds
906  if (m->in_bounds_.at(wrt_i)) {
907  // Input was in bounds: Keep output, make dimensionless
908  yk[i] /= nominal_out_[m->id_out_[i]];
909  } else {
910  // Input was out of bounds: Discard output
911  yk[i] = nan;
912  }
913  }
914  }
915  }
916  // Restore FMU inputs
917  if (set_real(m->instance, get_ptr(m->vr_in_), n_known, get_ptr(m->v_in_), n_known)) {
918  casadi_warning("Setting FMU variables failed");
919  return 1;
920  }
921  // Step size
922  double h = m->self.step_;
923 
924  // Calculate FD approximation
925  finite_diff(m->self.fd_, yk_all, get_ptr(m->d_out_), h, n_unknown, eps);
926 
927  // If seeds are dependent, quick return
928  if (!independent_seeds) {
929  // Simpy copy the results to output (no validation)
930  for (size_t ind = 0; ind < m->id_out_.size(); ++ind) {
931  m->osens_[m->id_out_[ind]] = m->d_out_[ind];
932  }
933  return 0;
934  }
935 
936  // Collect requested variables
937  for (size_t ind = 0; ind < m->id_out_.size(); ++ind) {
938  // Variable id
939  size_t id = m->id_out_[ind];
940  // With respect to what variable
941  size_t wrt = m->wrt_[id];
942  // Find the corresponding input variable
943  size_t wrt_i;
944  for (wrt_i = 0; wrt_i < n_known; ++wrt_i) {
945  if (m->id_in_[wrt_i] == wrt) break;
946  }
947  // Nominal value
948  double n = nominal_out_[id];
949  // Get the value
950  double d_fd = m->d_out_[ind] * n;
951  // Correct sign, if necessary
952  if (m->flip_[wrt_i]) d_fd = -d_fd;
953  // Use FD instead of AD or to compare with AD
954  if (m->self.validate_forward_) {
955  // Value to compare with
956  double d_ad = m->osens_[id];
957  // Nominal value used as seed
958  d_ad /= nominal_in_[wrt];
959  d_fd /= nominal_in_[wrt];
960  // Is it a not a number?
961  bool d_is_nan = d_ad != d_ad;
962  // Magnitude of derivatives
963  double d_max = std::fmax(std::fabs(d_fd), std::fabs(d_ad));
964  // Check if NaN or error exceeds thresholds
965  if (d_is_nan || (d_max > n * m->self.abstol_
966  && std::fabs(d_ad - d_fd) > d_max * m->self.reltol_)) {
967  // Offset for printing the stencil
968  double off = m->fd_out_.at(ind + offset * n_unknown);
969  // Warning or add to file
970  std::stringstream ss;
971  if (m->self.validate_ad_file_.empty()) {
972  // Issue warning
973  ss << (d_is_nan ? "NaN" : "Inconsistent") << " derivatives of " << vn_out_[id]
974  << " w.r.t. " << desc_in(m, wrt) << ", got " << d_ad
975  << " for AD vs. " << d_fd << " for FD[" << to_string(m->self.fd_) << "].";
976  // Print the stencil:
977  ss << "\nValues for step size " << h << ": " << (n * off) << " + [";
978  for (casadi_int k = 0; k < n_points; ++k) {
979  if (k > 0) ss << ", ";
980  ss << (n * (m->fd_out_.at(ind + k * n_unknown) - off));
981  }
982  ss << "]";
983  // Issue warning
984  casadi_warning(ss.str());
985  } else {
986  // Output
987  ss << vn_out_[id] << " ";
988  // Input
989  ss << vn_in_[wrt] << " ";
990  // Value
991  ss << m->ibuf_[wrt] << " ";
992  // Noninal
993  ss << nominal_in_[wrt] << " ";
994  // Min
995  ss << min_in_[wrt] << " ";
996  // Max
997  ss << max_in_[wrt] << " ";
998  // AD
999  ss << d_ad << " ";
1000  // FD
1001  ss << d_fd << " ";
1002  // Step
1003  ss << h << " ";
1004  // Offset
1005  ss << off << " ";
1006  // Stencil
1007  ss << "[";
1008  for (casadi_int k = 0; k < n_points; ++k) {
1009  if (k > 0) ss << ",";
1010  ss << (n * (m->fd_out_.at(ind + k * n_unknown) - off));
1011  }
1012  ss << "]" << std::endl;
1013  // Append to file
1014  auto valfile_ptr = Filesystem::ofstream_ptr(m->self.validate_ad_file_,
1015  std::ios_base::app);
1016  std::ostream& valfile = *valfile_ptr;
1017  valfile << ss.str();
1018  }
1019  }
1020  } else {
1021  // Use instead of AD
1022  m->osens_[id] = d_fd;
1023  }
1024  }
1025  // Successful return
1026  return 0;
1027 }
static std::unique_ptr< std::ostream > ofstream_ptr(const std::string &path, std::ios_base::openmode mode=std::ios_base::out)
Definition: filesystem.cpp:115
std::string desc_in(FmuMemory *m, size_t id, bool more=true) const
Definition: fmu.cpp:716
std::vector< std::string > vn_out_
Definition: fmu_impl.hpp:333
const double eps
Machine epsilon.
Definition: calculus.hpp:56
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.
Definition: calculus.hpp:264
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
std::string to_string(TypeFmi2 v)
const double nan
Not a number.
Definition: calculus.hpp:53
CASADI_EXPORT void finite_diff(FdMode v, const T1 **yk, T1 *J, T1 h, casadi_int n_y, T1 smoothing)
Calculate FD estimate.

References casadi::FmuFunction::abstol_, casadi::casadi_copy(), casadi::FmuMemory::d_in_, casadi::FmuMemory::d_out_, casadi::FmuInternal::desc_in(), casadi::eps, casadi::FmuFunction::fd_, casadi::fd_offset(), casadi::FmuMemory::fd_out_, casadi::finite_diff(), casadi::FmuMemory::flip_, casadi::get_ptr(), casadi::FmuInternal::get_real(), casadi::FmuMemory::ibuf_, casadi::FmuMemory::id_in_, casadi::FmuMemory::id_out_, casadi::FmuMemory::in_bounds_, casadi::FmuMemory::instance, casadi::FmuInternal::max_in_, casadi::FmuInternal::min_in_, casadi::n_fd_points(), casadi::nan, casadi::FmuInternal::nominal_in_, casadi::FmuInternal::nominal_out_, casadi::Filesystem::ofstream_ptr(), casadi::FmuMemory::osens_, casadi::FmuFunction::reltol_, casadi::FmuMemory::self, casadi::FmuInternal::set_real(), casadi::sign(), casadi::FmuFunction::step_, casadi::str(), casadi::to_string(), casadi::FmuMemory::v_in_, casadi::FmuMemory::v_out_, casadi::FmuMemory::v_pert_, casadi::FmuFunction::validate_ad_file_, casadi::FmuFunction::validate_forward_, casadi::FmuInternal::vn_in_, casadi::FmuInternal::vn_out_, casadi::FmuMemory::vr_in_, casadi::FmuMemory::vr_out_, and casadi::FmuMemory::wrt_.

Referenced by casadi::FmuInternal::eval_fwd().

◆ eval_fwd()

int casadi::FmuInternal::eval_fwd ( FmuMemory m,
bool  independent_seeds 
) const
inherited

Definition at line 729 of file fmu.cpp.

729  {
730  // Gather input and output indices
731  gather_fwd(m);
732  // Calculate derivatives using FMU directional derivative support
733  if (m->self.uses_directional_derivatives_) {
734  // Evaluate using AD
735  if (eval_ad(m)) return 1;
736  }
737  // Calculate derivatives using finite differences
738  if (!m->self.uses_directional_derivatives_ || m->self.validate_forward_) {
739  // Evaluate using FD
740  if (eval_fd(m, independent_seeds)) return 1;
741  }
742  return 0;
743 }
void gather_fwd(FmuMemory *m) const
Definition: fmu.cpp:1319
int eval_fd(FmuMemory *m, bool independent_seeds) const
Definition: fmu.cpp:797
int eval_ad(FmuMemory *m) const
Definition: fmu.cpp:768

References casadi::FmuInternal::eval_ad(), casadi::FmuInternal::eval_fd(), casadi::FmuInternal::gather_fwd(), casadi::FmuMemory::self, casadi::FmuFunction::uses_directional_derivatives_, and casadi::FmuFunction::validate_forward_.

◆ exit_initialization_mode()

int casadi::Fmu2::exit_initialization_mode ( void *  instance) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 291 of file fmu2.cpp.

291  {
292  auto c = static_cast<fmi2Component>(instance);
293  fmi2Status status = exit_initialization_mode_(c);
294  if (status != fmi2OK) {
295  casadi_warning("fmi2ExitInitializationMode failed");
296  return 1;
297  }
298  return 0;
299 }

References exit_initialization_mode_.

◆ finalize()

void casadi::Fmu2::finalize ( )
overridevirtual

Allocate numerical values for initial auxilliary variables

Reimplemented from casadi::FmuInternal.

Definition at line 166 of file fmu2.cpp.

166  {
168  aux_value_.v_real.resize(vn_aux_real_.size());
169  aux_value_.v_integer.resize(vn_aux_integer_.size());
170  aux_value_.v_boolean.resize(vn_aux_boolean_.size());
171  aux_value_.v_string.resize(vn_aux_string_.size());
172 
173  // Recursive call
175 }
Value aux_value_
Definition: fmu2.hpp:126
virtual void finalize()
Definition: fmu.cpp:579
std::vector< fmi2Boolean > v_boolean
Definition: fmu2.hpp:122
std::vector< fmi2Real > v_real
Definition: fmu2.hpp:120
std::vector< std::string > v_string
Definition: fmu2.hpp:123
std::vector< fmi2Integer > v_integer
Definition: fmu2.hpp:121

References aux_value_, casadi::FmuInternal::finalize(), casadi::Fmu2::Value::v_boolean, casadi::Fmu2::Value::v_integer, casadi::Fmu2::Value::v_real, casadi::Fmu2::Value::v_string, vn_aux_boolean_, vn_aux_integer_, vn_aux_real_, and vn_aux_string_.

Referenced by deserialize().

◆ free_instance()

void casadi::Fmu2::free_instance ( void *  instance) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 262 of file fmu2.cpp.

262  {
263  if (free_instance_) {
264  auto c = static_cast<fmi2Component>(instance);
265  free_instance_(c);
266  } else {
267  casadi_warning("No free_instance function pointer available");
268  }
269 }

References free_instance_.

◆ free_mem()

void casadi::Fmu2::free_mem ( void *  mem) const
overridevirtual

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

Implements casadi::FmuInternal.

Definition at line 54 of file fmu2.cpp.

54  {
55  delete static_cast<Fmu2Memory*>(mem);
56 }

◆ gather_adj()

void casadi::FmuInternal::gather_adj ( FmuMemory m) const
inherited

Definition at line 1338 of file fmu.cpp.

1338  {
1339  // Gather input and output indices
1340  gather_io(m);
1341  // Number of inputs and outputs
1342  size_t n_known = m->id_in_.size();
1343  size_t n_unknown = m->id_out_.size();
1344  // Get/clear seeds
1345  m->d_out_.clear();
1346  for (size_t id : m->id_out_) {
1347  m->d_out_.push_back(m->osens_[id]);
1348  m->osens_[id] = 0;
1349  }
1350  // Ensure at least one seed
1351  casadi_assert(n_unknown != 0, "No seeds");
1352  // Allocate result vectors
1353  m->v_in_.resize(n_known);
1354  m->d_in_.resize(n_known);
1355 }

References casadi::FmuMemory::d_in_, casadi::FmuMemory::d_out_, casadi::FmuInternal::gather_io(), casadi::FmuMemory::id_in_, casadi::FmuMemory::id_out_, casadi::FmuMemory::osens_, and casadi::FmuMemory::v_in_.

Referenced by casadi::FmuInternal::eval_adj().

◆ gather_fwd()

void casadi::FmuInternal::gather_fwd ( FmuMemory m) const
inherited

Definition at line 1319 of file fmu.cpp.

1319  {
1320  // Gather input and output indices
1321  gather_io(m);
1322  // Number of inputs and outputs
1323  size_t n_known = m->id_in_.size();
1324  size_t n_unknown = m->id_out_.size();
1325  // Get/clear seeds
1326  m->d_in_.clear();
1327  for (size_t id : m->id_in_) {
1328  m->d_in_.push_back(m->isens_[id]);
1329  m->isens_[id] = 0;
1330  }
1331  // Ensure at least one seed
1332  casadi_assert(n_known != 0, "No seeds");
1333  // Allocate result vectors
1334  m->v_out_.resize(n_unknown);
1335  m->d_out_.resize(n_unknown);
1336 }

References casadi::FmuMemory::d_in_, casadi::FmuMemory::d_out_, casadi::FmuInternal::gather_io(), casadi::FmuMemory::id_in_, casadi::FmuMemory::id_out_, casadi::FmuMemory::isens_, and casadi::FmuMemory::v_out_.

Referenced by casadi::FmuInternal::eval_fwd().

◆ gather_io()

void casadi::FmuInternal::gather_io ( FmuMemory m) const
inherited

Definition at line 1294 of file fmu.cpp.

1294  {
1295  // Collect input indices and corresponding value references and values
1296  m->id_in_.clear();
1297  m->vr_in_.clear();
1298  m->v_in_.clear();
1299  for (size_t id = 0; id < m->imarked_.size(); ++id) {
1300  if (m->imarked_[id]) {
1301  m->id_in_.push_back(id);
1302  m->vr_in_.push_back(vr_in_[id]);
1303  m->v_in_.push_back(m->ibuf_[id]);
1304  m->imarked_[id] = false;
1305  }
1306  }
1307  // Collect output indices, corresponding value references
1308  m->id_out_.clear();
1309  m->vr_out_.clear();
1310  for (size_t id = 0; id < m->omarked_.size(); ++id) {
1311  if (m->omarked_[id]) {
1312  m->id_out_.push_back(id);
1313  m->vr_out_.push_back(vr_out_[id]);
1314  m->omarked_[id] = false;
1315  }
1316  }
1317 }
std::vector< unsigned int > vr_out_
Definition: fmu_impl.hpp:334
std::vector< unsigned int > vr_in_
Definition: fmu_impl.hpp:334

References casadi::FmuMemory::ibuf_, casadi::FmuMemory::id_in_, casadi::FmuMemory::id_out_, casadi::FmuMemory::imarked_, casadi::FmuMemory::omarked_, casadi::FmuMemory::v_in_, casadi::FmuMemory::vr_in_, casadi::FmuInternal::vr_in_, casadi::FmuMemory::vr_out_, and casadi::FmuInternal::vr_out_.

Referenced by casadi::FmuInternal::eval(), casadi::FmuInternal::gather_adj(), and casadi::FmuInternal::gather_fwd().

◆ get()

void casadi::FmuInternal::get ( FmuMemory m,
size_t  id,
double *  value 
) const
inherited

Definition at line 1250 of file fmu.cpp.

1250  {
1251  // Save to return
1252  for (size_t id : ored_[ind]) {
1253  *value++ = m->obuf_.at(id);
1254  }
1255 }

References casadi::FmuMemory::obuf_, and casadi::FmuInternal::ored_.

Referenced by casadi::Fmu::get().

◆ get_adj() [1/2]

void casadi::FmuInternal::get_adj ( FmuMemory m,
casadi_int  nsens,
const casadi_int *  id,
double *  v 
) const
inherited

Definition at line 1082 of file fmu.cpp.

1082  {
1083  for (casadi_int i = 0; i < nsens; ++i) {
1084  *v++ = m->isens_.at(*id++);
1085  }
1086 }

References casadi::FmuMemory::isens_.

Referenced by casadi::FmuInternal::get_adj().

◆ get_adj() [2/2]

void casadi::FmuInternal::get_adj ( FmuMemory m,
size_t  ind,
double *  v 
) const
inherited

Definition at line 1088 of file fmu.cpp.

1088  {
1089  // Quick return if not needed
1090  if (!v) return;
1091  // Retrieve all sensitivities FIXME(@jaeandersson): should use compatible types
1092  for (size_t id : ired_[ind]) {
1093  casadi_int id2 = id;
1094  get_adj(m, 1, &id2, v++);
1095  }
1096 }
void get_adj(FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
Definition: fmu.cpp:1082

References casadi::FmuInternal::get_adj(), and casadi::FmuInternal::ired_.

◆ get_adjoint_derivative()

int casadi::FmuInternal::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
virtualinherited

Reimplemented in casadi::Fmu3.

Definition at line 572 of file fmu.cpp.

574  {
575  casadi_error("Adjoint derivatives not supported for " + class_name());
576  return 1;
577 }

References casadi::SharedObjectInternal::class_name().

Referenced by casadi::FmuInternal::eval_adj().

◆ get_aux()

int casadi::Fmu2::get_aux ( void *  instance)
overridevirtual

Implements casadi::FmuInternal.

Definition at line 474 of file fmu2.cpp.

474  {
475  return get_aux_impl(instance, aux_value_);
476 }
int get_aux_impl(void *instance, Value &aux_value) const
Definition: fmu2.cpp:432

References aux_value_, and get_aux_impl().

◆ get_aux_impl()

int casadi::Fmu2::get_aux_impl ( void *  instance,
Value aux_value 
) const

Definition at line 432 of file fmu2.cpp.

432  {
433  auto c = static_cast<fmi2Component>(instance);
434  // Get real auxilliary variables
435  if (!vr_aux_real_.empty()) {
436  fmi2Status status = get_real_(c, get_ptr(vr_aux_real_), vr_aux_real_.size(),
437  get_ptr(aux_value.v_real));
438  if (status != fmi2OK) {
439  casadi_warning("fmi2GetReal failed");
440  return 1;
441  }
442  }
443  // Get integer/enum auxilliary variables
444  if (!vr_aux_integer_.empty()) {
445  fmi2Status status = get_integer_(c, get_ptr(vr_aux_integer_), vr_aux_integer_.size(),
446  get_ptr(aux_value.v_integer));
447  if (status != fmi2OK) {
448  casadi_warning("fmi2GetInteger failed");
449  return 1;
450  }
451  }
452  // Get boolean auxilliary variables
453  if (!vr_aux_boolean_.empty()) {
454  fmi2Status status = get_boolean_(c, get_ptr(vr_aux_boolean_), vr_aux_boolean_.size(),
455  get_ptr(aux_value.v_boolean));
456  if (status != fmi2OK) {
457  casadi_warning("fmi2GetBoolean failed");
458  return 1;
459  }
460  }
461  // Get string auxilliary variables
462  for (size_t k = 0; k < vr_aux_string_.size(); ++k) {
463  fmi2ValueReference vr = vr_aux_string_[k];
464  fmi2String value = aux_value.v_string.at(k).c_str();
465  fmi2Status status = set_string_(c, &vr, 1, &value);
466  if (status != fmi2OK) {
467  casadi_error("fmi2GetString failed for value reference " + str(vr));
468  }
469  }
470  // Successful return
471  return 0;
472 }
fmi2GetIntegerTYPE * get_integer_
Definition: fmu2.hpp:108
fmi2GetBooleanTYPE * get_boolean_
Definition: fmu2.hpp:106
fmi2SetStringTYPE * set_string_
Definition: fmu2.hpp:111

References get_boolean_, get_integer_, casadi::get_ptr(), get_real_, set_string_, casadi::str(), casadi::Fmu2::Value::v_boolean, casadi::Fmu2::Value::v_integer, casadi::Fmu2::Value::v_real, casadi::Fmu2::Value::v_string, vr_aux_boolean_, vr_aux_integer_, vr_aux_real_, and vr_aux_string_.

Referenced by get_aux(), and get_stats().

◆ get_derivatives()

int casadi::Fmu2::get_derivatives ( void *  instance,
double *  derivatives,
size_t  nx 
) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 311 of file fmu2.cpp.

311  {
312  auto c = static_cast<fmi2Component>(instance);
313  fmi2Status status = get_derivatives_(c, derivatives, nx);
314  if (status != fmi2OK) {
315  casadi_warning("fmi2GetDerivatives failed");
316  return 1;
317  }
318  return 0;
319 }
fmi2GetDerivativesTYPE * get_derivatives_
Definition: fmu2.hpp:102

References get_derivatives_.

◆ get_directional_derivative()

int casadi::Fmu2::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
overridevirtual

Implements casadi::FmuInternal.

Definition at line 381 of file fmu2.cpp.

383  {
384  casadi_assert(n_in == n_seed, "Vector-valued variables not supported in FMI 2");
385  casadi_assert(n_out == n_sensitivity, "Vector-valued variables not supported in FMI 2");
386  fmi2Status status = get_directional_derivative_(instance, vr_out, n_out, vr_in, n_in,
387  seed, sensitivity);
388  return status != fmi2OK;
389 }
size_t n_in() const
Get the number of scheme inputs.
Definition: fmu_impl.hpp:127

References get_directional_derivative_, casadi::FmuInternal::n_in(), and casadi::FmuInternal::n_out().

◆ get_fwd() [1/2]

void casadi::FmuInternal::get_fwd ( FmuMemory m,
casadi_int  nsens,
const casadi_int *  id,
double *  v 
) const
inherited

Definition at line 1029 of file fmu.cpp.

1029  {
1030  for (casadi_int i = 0; i < nsens; ++i) {
1031  *v++ = m->osens_.at(*id++);
1032  }
1033 }

References casadi::FmuMemory::osens_.

Referenced by casadi::FmuInternal::get_fwd().

◆ get_fwd() [2/2]

void casadi::FmuInternal::get_fwd ( FmuMemory m,
size_t  ind,
double *  v 
) const
inherited

Definition at line 1035 of file fmu.cpp.

1035  {
1036  // Quick return if not needed
1037  if (!v) return;
1038  // Retrieve all sensitivities FIXME(@jaeandersson): should use compatible types
1039  for (size_t id : ored_[ind]) {
1040  casadi_int id2 = id;
1041  get_fwd(m, 1, &id2, v++);
1042  }
1043 }
void get_fwd(FmuMemory *m, casadi_int nsens, const casadi_int *id, double *v) const
Definition: fmu.cpp:1029

References casadi::FmuInternal::get_fwd(), and casadi::FmuInternal::ored_.

◆ get_real()

int casadi::Fmu2::get_real ( void *  instance,
const unsigned int *  vr,
size_t  n_vr,
double *  values,
size_t  n_values 
) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 363 of file fmu2.cpp.

364  {
365  casadi_assert(n_vr == n_values, "Vector-valued variables not supported in FMI 2");
366  if (do_evaluation_dance_) {
367  // Dummy call to trigger rtOneStep
368  fmi2Status status = get_real_(instance, nullptr, 0, nullptr);
369  if (status != fmi2OK) return 1;
370  // Scratch space to write derivative to (not used)
371  static thread_local std::vector<double> derivate_dump;
372  if (derivate_dump.size() < nx_) derivate_dump.resize(nx_);
373  // Dummy call to trigger computation of derivatives, possibly read later via get_real
374  status = get_derivatives_(instance, get_ptr(derivate_dump), nx_);
375  if (status != fmi2OK) return 1;
376  }
377  fmi2Status status = get_real_(instance, vr, n_vr, values);
378  return status != fmi2OK;
379 }

References casadi::FmuInternal::do_evaluation_dance_, get_derivatives_, casadi::get_ptr(), get_real_, and casadi::FmuInternal::nx_.

◆ get_stats()

void casadi::Fmu2::get_stats ( FmuMemory m,
Dict stats,
const std::vector< std::string > &  name_in,
const InputStruct in 
) const
overridevirtual

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

Implements casadi::FmuInternal.

Definition at line 478 of file fmu2.cpp.

479  {
480  Value& v = static_cast<Fmu2Memory*>(m)->aux_value;
481  get_aux_impl(m->instance, v);
482  // Collect auxilliary variables
483  Dict aux;
484  // Real
485  for (size_t k = 0; k < vn_aux_real_.size(); ++k) {
486  aux[vn_aux_real_[k]] = static_cast<double>(v.v_real[k]);
487  }
488  // Integer
489  for (size_t k = 0; k < vn_aux_integer_.size(); ++k) {
490  aux[vn_aux_integer_[k]] = static_cast<casadi_int>(v.v_integer[k]);
491  }
492  // Boolean
493  for (size_t k = 0; k < vn_aux_boolean_.size(); ++k) {
494  aux[vn_aux_boolean_[k]] = static_cast<bool>(v.v_boolean[k]);
495  }
496  // String
497  for (size_t k = 0; k < vn_aux_string_.size(); ++k) {
498  aux[vn_aux_string_[k]] = v.v_string[k];
499  }
500  // Copy to stats
501  (*stats)["aux"] = aux;
502  // Loop over input variables
503  for (size_t k = 0; k < name_in.size(); ++k) {
504  // Only consider regular inputs
505  if (in[k].type == InputType::REG) {
506  // Get the indices
507  const std::vector<size_t>& iind = ired_.at(in[k].ind);
508  // Collect values
509  std::vector<double> v(iind.size());
510  for (size_t i = 0; i < v.size(); ++i) v[i] = value_in_.at(iind[i]);
511  // Save to stats
512  (*stats)[name_in[k]] = v;
513  }
514  }
515 }
std::vector< double > value_in_
Definition: fmu_impl.hpp:337
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.

References get_aux_impl(), casadi::FmuMemory::instance, casadi::FmuInternal::ired_, casadi::REG, casadi::Fmu2::Value::v_boolean, casadi::Fmu2::Value::v_integer, casadi::Fmu2::Value::v_real, casadi::Fmu2::Value::v_string, casadi::FmuInternal::value_in_, vn_aux_boolean_, vn_aux_integer_, vn_aux_real_, and vn_aux_string_.

◆ getCount()

Definition at line 60 of file generic_shared_internal.hpp.

186  {
187  return static_cast<const Internal*>(this)->count;
188  }

◆ hess_sparsity()

Sparsity casadi::FmuInternal::hess_sparsity ( const std::vector< size_t > &  r,
const std::vector< size_t > &  c 
) const
inherited

Definition at line 676 of file fmu.cpp.

677  {
678  // Convert to casadi_int type
679  std::vector<casadi_int> r1(r.begin(), r.end());
680  std::vector<casadi_int> c1(c.begin(), c.end());
681  // Index mapping (not used)
682  std::vector<casadi_int> mapping;
683  // Get selection
684  return hess_sp_.sub(r1, c1, mapping);
685 }
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.
Definition: sparsity.cpp:334

References casadi::FmuInternal::hess_sp_, and casadi::Sparsity::sub().

◆ index_in()

size_t casadi::FmuInternal::index_in ( const std::string &  n) const
inherited

Definition at line 645 of file fmu.cpp.

645  {
646  // Linear search for the input
647  for (size_t i = 0; i < scheme_in_.size(); ++i) {
648  if (scheme_in_[i] == n) return i;
649  }
650  // Not found
651  casadi_error("No such input: " + n);
652  return -1;
653 }
std::vector< std::string > scheme_in_
Definition: fmu_impl.hpp:290

References casadi::FmuInternal::scheme_in_.

Referenced by casadi::InputStruct::parse(), and casadi::OutputStruct::parse().

◆ index_out()

size_t casadi::FmuInternal::index_out ( const std::string &  n) const
inherited

Definition at line 655 of file fmu.cpp.

655  {
656  // Linear search for the input
657  for (size_t i = 0; i < scheme_out_.size(); ++i) {
658  if (scheme_out_[i] == n) return i;
659  }
660  // Not found
661  casadi_error("No such output: " + n);
662  return -1;
663 }
std::vector< std::string > scheme_out_
Definition: fmu_impl.hpp:290

References casadi::FmuInternal::scheme_out_.

Referenced by casadi::InputStruct::parse(), and casadi::OutputStruct::parse().

◆ init()

void casadi::Fmu2::init ( const DaeBuilderInternal dae)
overridevirtual

Reimplemented from casadi::FmuInternal.

Definition at line 78 of file fmu2.cpp.

78  {
79  // Initialize base classes
80  FmuInternal::init(dae);
81 
82  // Collect input and parameter values
83  vr_real_.clear();
84  vr_integer_.clear();
85  vr_boolean_.clear();
86  vr_string_.clear();
87  init_real_.clear();
88  init_integer_.clear();
89  init_boolean_.clear();
90  init_string_.clear();
91  for (size_t i = 0; i < dae->n_variables(); ++i) {
92  const Variable& v = dae->variable(i);
93  casadi_assert(v.numel == 1, "Vector variable support not implemented");
94  // Skip if the wrong type
95  if (v.causality != Causality::PARAMETER && v.causality != Causality::INPUT) continue;
96  // Variable has not been set - keep default value
97  if (!v.is_set()) continue;
98  // Value reference
99  fmi2ValueReference vr = v.value_reference;
100  // Get value
101  switch (to_fmi2(v.type)) {
102  case TypeFmi2::REAL:
103  init_real_.push_back(static_cast<fmi2Real>(v.value.front()));
104  vr_real_.push_back(vr);
105  break;
106  case TypeFmi2::INTEGER:
107  case TypeFmi2::ENUM:
108  init_integer_.push_back(static_cast<fmi2Integer>(v.value.front()));
109  vr_integer_.push_back(vr);
110  break;
111  case TypeFmi2::BOOLEAN:
112  init_boolean_.push_back(static_cast<fmi2Boolean>(v.value.front()));
113  vr_boolean_.push_back(vr);
114  break;
115  case TypeFmi2::STRING:
116  init_string_.push_back(v.stringvalue);
117  vr_string_.push_back(vr);
118  break;
119  default:
120  casadi_warning("Ignoring " + v.name + ", type: " + to_string(v.type));
121  }
122  }
123 
124  // Collect auxilliary variables
125  vn_aux_real_.clear();
126  vn_aux_integer_.clear();
127  vn_aux_boolean_.clear();
128  vn_aux_string_.clear();
129  vr_aux_real_.clear();
130  vr_aux_integer_.clear();
131  vr_aux_boolean_.clear();
132  vr_aux_string_.clear();
133  for (auto&& s : aux_) {
134  const Variable& v = dae->variable(s);
135  // Convert to expected type
136  fmi2ValueReference vr = v.value_reference;
137  // Sort by type
138  switch (to_fmi2(v.type)) {
139  case TypeFmi2::REAL:
140  // Real
141  vn_aux_real_.push_back(v.name);
142  vr_aux_real_.push_back(vr);
143  break;
144  case TypeFmi2::INTEGER:
145  case TypeFmi2::ENUM:
146  // Integer or enum
147  vn_aux_integer_.push_back(v.name);
148  vr_aux_integer_.push_back(vr);
149  break;
150  case TypeFmi2::BOOLEAN:
151  // Boolean
152  vn_aux_boolean_.push_back(v.name);
153  vr_aux_boolean_.push_back(vr);
154  break;
155  case TypeFmi2::STRING:
156  // String
157  vn_aux_string_.push_back(v.name);
158  vr_aux_string_.push_back(vr);
159  break;
160  default:
161  casadi_warning("Ignoring " + v.name + ", type: " + to_string(v.type));
162  }
163  }
164 }
std::vector< std::string > aux_
Definition: fmu_impl.hpp:294
virtual void init(const DaeBuilderInternal *dae)
Definition: fmu.cpp:451
struct VariableStruct Variable
TypeFmi2 to_fmi2(Type v)

References casadi::FmuInternal::aux_, casadi::BOOLEAN, casadi::Variable::causality, casadi::ENUM, casadi::FmuInternal::init(), init_boolean_, init_integer_, init_real_, init_string_, casadi::INPUT, casadi::INTEGER, casadi::Variable::is_set(), casadi::DaeBuilderInternal::n_variables(), casadi::Variable::name, casadi::Variable::numel, casadi::PARAMETER, casadi::REAL, casadi::STRING, casadi::Variable::stringvalue, casadi::to_fmi2(), casadi::to_string(), casadi::Variable::type, casadi::Variable::value, casadi::Variable::value_reference, casadi::DaeBuilderInternal::variable(), vn_aux_boolean_, vn_aux_integer_, vn_aux_real_, vn_aux_string_, vr_aux_boolean_, vr_aux_integer_, vr_aux_real_, vr_aux_string_, vr_boolean_, vr_integer_, vr_real_, and vr_string_.

◆ init_mem()

int casadi::Fmu2::init_mem ( FmuMemory m) const
overridevirtual

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

Allocate numerical values for initial auxilliary variables

Reimplemented from casadi::FmuInternal.

Definition at line 39 of file fmu2.cpp.

39  {
40  if (FmuInternal::init_mem(mem)) return 1;
41  auto m = static_cast<Fmu2Memory*>(mem);
43  m->aux_value.v_real.resize(vn_aux_real_.size());
44  m->aux_value.v_integer.resize(vn_aux_integer_.size());
45  m->aux_value.v_boolean.resize(vn_aux_boolean_.size());
46  m->aux_value.v_string.resize(vn_aux_string_.size());
47  return 0;
48 }
virtual int init_mem(FmuMemory *m) const
Initalize memory block.
Definition: fmu.cpp:1148

References casadi::FmuInternal::init_mem(), vn_aux_boolean_, vn_aux_integer_, vn_aux_real_, and vn_aux_string_.

◆ initSingleton()

void casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::initSingleton ( )
inlineprotectedinherited

Called in the constructor of singletons to avoid that the counter reaches zero

Definition at line 71 of file generic_shared_internal.hpp.

71  {
72  casadi_assert_dev(static_cast<Internal*>(this)->count==0);
73  static_cast<Internal*>(this)->count++;
74  }

◆ instantiate()

void * casadi::Fmu2::instantiate ( ) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 244 of file fmu2.cpp.

244  {
245  // Instantiate FMU
246  fmi2String instanceName = instance_name_.c_str();
247  fmi2Type fmuType = fmi2ModelExchange;
248  fmi2String fmuGUID = instantiation_token_.c_str();
249  fmi2String fmuResourceLocation = resource_loc_.c_str();
250  fmi2Boolean visible = fmi2False;
251  fmi2Component c = instantiate_(instanceName, fmuType, fmuGUID, fmuResourceLocation,
252  &functions_, visible, logging_on_);
253  if (c == 0) casadi_error("fmi2Instantiate failed");
254 
255  // Call fmi2SetupExperiment
256  fmi2Status status = setup_experiment_(c, fmutol_ > 0, fmutol_, 0., fmi2True, 1.);
257  casadi_assert(status == fmi2OK, "fmi2SetupExperiment failed");
258 
259  return c;
260 }
fmi2CallbackFunctions functions_
Definition: fmu2.hpp:116
std::string instantiation_token_
Definition: fmu_impl.hpp:306
std::string resource_loc_
Definition: fmu_impl.hpp:297
std::string instance_name_
Definition: fmu_impl.hpp:303

References casadi::FmuInternal::fmutol_, functions_, casadi::FmuInternal::instance_name_, instantiate_, casadi::FmuInternal::instantiation_token_, casadi::FmuInternal::logging_on_, casadi::FmuInternal::resource_loc_, and setup_experiment_.

◆ jac_sparsity()

Sparsity casadi::FmuInternal::jac_sparsity ( const std::vector< size_t > &  osub,
const std::vector< size_t > &  isub 
) const
inherited

Definition at line 665 of file fmu.cpp.

666  {
667  // Convert to casadi_int type
668  std::vector<casadi_int> osub1(osub.begin(), osub.end());
669  std::vector<casadi_int> isub1(isub.begin(), isub.end());
670  // Index mapping (not used)
671  std::vector<casadi_int> mapping;
672  // Get selection
673  return jac_sp_.sub(osub1, isub1, mapping);
674 }

References casadi::FmuInternal::jac_sp_, and casadi::Sparsity::sub().

◆ load_function()

template<typename T >
T * casadi::FmuInternal::load_function ( const std::string &  symname)
inherited

Definition at line 357 of file fmu_impl.hpp.

357  {
358  // Load the function
359  signal_t f = li_.get_function(symname);
360  // Ensure that it was found
361  casadi_assert(f != 0, "Cannot retrieve '" + symname + "'");
362  // Return function with the right type
363  return reinterpret_cast<T*>(f);
364 }
Importer li_
DLL.
Definition: fmu_impl.hpp:321
signal_t get_function(const std::string &symname)
Get a function pointer for numerical evaluation.
Definition: importer.cpp:79
void(* signal_t)(void)
Function pointer types for the C API.

References casadi::Importer::get_function(), casadi::FmuInternal::li_, and casadi::T.

◆ load_functions()

void casadi::Fmu2::load_functions ( )
overridevirtual

Implements casadi::FmuInternal.

Definition at line 177 of file fmu2.cpp.

177  {
178  instantiate_ = load_function<fmi2InstantiateTYPE>("fmi2Instantiate");
179  free_instance_ = load_function<fmi2FreeInstanceTYPE>("fmi2FreeInstance");
180  reset_ = load_function<fmi2ResetTYPE>("fmi2Reset");
181  setup_experiment_ = load_function<fmi2SetupExperimentTYPE>("fmi2SetupExperiment");
182  enter_initialization_mode_ = load_function<fmi2EnterInitializationModeTYPE>(
183  "fmi2EnterInitializationMode");
184  exit_initialization_mode_ = load_function<fmi2ExitInitializationModeTYPE>(
185  "fmi2ExitInitializationMode");
186  enter_continuous_time_mode_ = load_function<fmi2EnterContinuousTimeModeTYPE>(
187  "fmi2EnterContinuousTimeMode");
188  get_derivatives_ = load_function<fmi2GetDerivativesTYPE>("fmi2GetDerivatives");
189  set_time_ = load_function<fmi2SetTimeTYPE>("fmi2SetTime");
190  get_real_ = load_function<fmi2GetRealTYPE>("fmi2GetReal");
191  set_real_ = load_function<fmi2SetRealTYPE>("fmi2SetReal");
192  get_integer_ = load_function<fmi2GetIntegerTYPE>("fmi2GetInteger");
193  set_integer_ = load_function<fmi2SetIntegerTYPE>("fmi2SetInteger");
194  get_boolean_ = load_function<fmi2GetBooleanTYPE>("fmi2GetBoolean");
195  set_boolean_ = load_function<fmi2SetBooleanTYPE>("fmi2SetBoolean");
196  get_string_ = load_function<fmi2GetStringTYPE>("fmi2GetString");
197  set_string_ = load_function<fmi2SetStringTYPE>("fmi2SetString");
200  load_function<fmi2GetDirectionalDerivativeTYPE>("fmi2GetDirectionalDerivative");
201  }
202  new_discrete_states_ = load_function<fmi2NewDiscreteStatesTYPE>("fmi2NewDiscreteStates");
203 
204  // Callback functions
205  functions_.logger = logger;
206  functions_.allocateMemory = calloc;
207  functions_.freeMemory = free;
208  functions_.stepFinished = 0;
209  functions_.componentEnvironment = 0;
210 }
fmi2SetIntegerTYPE * set_integer_
Definition: fmu2.hpp:109
static void logger(fmi2ComponentEnvironment componentEnvironment, fmi2String instanceName, fmi2Status status, fmi2String category, fmi2String message,...)
Definition: fmu2.cpp:212
fmi2GetStringTYPE * get_string_
Definition: fmu2.hpp:110
bool provides_directional_derivatives_
Definition: fmu_impl.hpp:315

References enter_continuous_time_mode_, enter_initialization_mode_, exit_initialization_mode_, free_instance_, functions_, get_boolean_, get_derivatives_, get_directional_derivative_, get_integer_, get_real_, get_string_, instantiate_, logger(), new_discrete_states_, casadi::FmuInternal::provides_directional_derivatives_, reset_, set_boolean_, set_integer_, set_real_, set_string_, set_time_, and setup_experiment_.

◆ logger()

void casadi::Fmu2::logger ( fmi2ComponentEnvironment  componentEnvironment,
fmi2String  instanceName,
fmi2Status  status,
fmi2String  category,
fmi2String  message,
  ... 
)
static

Definition at line 212 of file fmu2.cpp.

216  {
217  // Variable number of arguments
218  va_list args;
219  va_start(args, message);
220  // Static & dynamic buffers
221  char buf[256];
222  size_t buf_sz = sizeof(buf);
223  char* buf_dyn = nullptr;
224  // Try to print with a small buffer
225  int n = vsnprintf(buf, buf_sz, message, args);
226  // Need a larger buffer?
227  if (n > buf_sz) {
228  buf_sz = n + 1;
229  buf_dyn = new char[buf_sz];
230  n = vsnprintf(buf_dyn, buf_sz, message, args);
231  }
232  // Print buffer content
233  if (n >= 0) {
234  uout() << "[" << instanceName << ":" << category << "] "
235  << (buf_dyn ? buf_dyn : buf) << std::endl;
236  }
237  // Cleanup
238  delete[] buf_dyn;
239  va_end(args);
240  // Throw error if failure
241  casadi_assert(n>=0, "Print failure while processing '" + std::string(message) + "'");
242 }
std::ostream & uout()

References casadi::uout().

Referenced by load_functions().

◆ n_in()

size_t casadi::FmuInternal::n_in ( ) const
inlineinherited

◆ n_out()

size_t casadi::FmuInternal::n_out ( ) const
inlineinherited

◆ request()

void casadi::FmuInternal::request ( FmuMemory m,
size_t  ind 
) const
inherited

Definition at line 1213 of file fmu.cpp.

1213  {
1214  for (size_t id : ored_[ind]) {
1215  // Mark as requested
1216  m->omarked_.at(id) = true;
1217  // Also log corresponding input index
1218  m->wrt_.at(id) = -1;
1219  }
1220 }

References casadi::FmuMemory::omarked_, casadi::FmuInternal::ored_, and casadi::FmuMemory::wrt_.

◆ request_adj() [1/2]

void casadi::FmuInternal::request_adj ( FmuMemory m,
casadi_int  ind 
) const
inherited

Definition at line 1073 of file fmu.cpp.

1073  {
1074  // Request all sensitivities FIXME(@jaeandersson): should use compatible types
1075  casadi_int wrt_id = -1;
1076  for (size_t id : ired_[ind]) {
1077  casadi_int id2 = id;
1078  request_adj(m, 1, &id2, &wrt_id);
1079  }
1080 }
void request_adj(FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
Definition: fmu.cpp:1064

References casadi::FmuInternal::ired_, and casadi::FmuInternal::request_adj().

◆ request_adj() [2/2]

void casadi::FmuInternal::request_adj ( FmuMemory m,
casadi_int  nsens,
const casadi_int *  id,
const casadi_int *  wrt_id 
) const
inherited

Definition at line 1064 of file fmu.cpp.

1065  {
1066  for (casadi_int i = 0; i < nsens; ++i) {
1067  m->imarked_.at(*id) = true;
1068  m->wrt_.at(*id) = *wrt_id++;
1069  id++;
1070  }
1071 }

References casadi::FmuMemory::imarked_, and casadi::FmuMemory::wrt_.

Referenced by casadi::FmuInternal::request_adj().

◆ request_fwd() [1/2]

void casadi::FmuInternal::request_fwd ( FmuMemory m,
casadi_int  ind 
) const
inherited

Definition at line 1285 of file fmu.cpp.

1285  {
1286  // Request all sensitivities FIXME(@jaeandersson): should use compatible types
1287  casadi_int wrt_id = -1;
1288  for (size_t id : ored_[ind]) {
1289  casadi_int id2 = id;
1290  request_fwd(m, 1, &id2, &wrt_id);
1291  }
1292 }
void request_fwd(FmuMemory *m, casadi_int nsens, const casadi_int *id, const casadi_int *wrt_id) const
Definition: fmu.cpp:1276

References casadi::FmuInternal::ored_, and casadi::FmuInternal::request_fwd().

◆ request_fwd() [2/2]

void casadi::FmuInternal::request_fwd ( FmuMemory m,
casadi_int  nsens,
const casadi_int *  id,
const casadi_int *  wrt_id 
) const
inherited

Definition at line 1276 of file fmu.cpp.

1277  {
1278  for (casadi_int i = 0; i < nsens; ++i) {
1279  m->omarked_.at(*id) = true;
1280  m->wrt_.at(*id) = *wrt_id++;
1281  id++;
1282  }
1283 }

References casadi::FmuMemory::omarked_, and casadi::FmuMemory::wrt_.

Referenced by casadi::FmuInternal::request_fwd().

◆ reset()

int casadi::Fmu2::reset ( void *  instance)

Definition at line 271 of file fmu2.cpp.

271  {
272  auto c = static_cast<fmi2Component>(instance);
273  fmi2Status status = reset_(c);
274  if (status != fmi2OK) {
275  casadi_warning("fmi2Reset failed");
276  return 1;
277  }
278  return 0;
279 }

References reset_.

◆ serialize()

void casadi::FmuInternal::serialize ( SerializingStream s) const
inherited

Definition at line 1371 of file fmu.cpp.

1371  {
1372  serialize_type(s);
1373  serialize_body(s);
1374 }
virtual void serialize_body(SerializingStream &s) const
Definition: fmu.cpp:1380
virtual void serialize_type(SerializingStream &s) const
Definition: fmu.cpp:1376

References casadi::FmuInternal::serialize_body(), and casadi::FmuInternal::serialize_type().

◆ serialize_body()

void casadi::Fmu2::serialize_body ( SerializingStream s) const
overridevirtual

Reimplemented from casadi::FmuInternal.

Definition at line 579 of file fmu2.cpp.

579  {
581 
582  s.version("Fmu2", 2);
583  s.pack("Fmu2::vr_real", vr_real_);
584  s.pack("Fmu2::vr_integer", vr_integer_);
585  s.pack("Fmu2::vr_boolean", vr_boolean_);
586  s.pack("Fmu2::vr_string", vr_string_);
587  s.pack("Fmu2::init_real", init_real_);
588  s.pack("Fmu2::init_integer", init_integer_);
589  s.pack("Fmu2::init_boolean", init_boolean_);
590  s.pack("Fmu2::init_string", init_string_);
591 
592  s.pack("Fmu2::vn_aux_real", vn_aux_real_);
593  s.pack("Fmu2::vn_aux_integer", vn_aux_integer_);
594  s.pack("Fmu2::vn_aux_boolean", vn_aux_boolean_);
595  s.pack("Fmu2::vn_aux_string", vn_aux_string_);
596  s.pack("Fmu2::vr_aux_real", vr_aux_real_);
597  s.pack("Fmu2::vr_aux_integer", vr_aux_integer_);
598  s.pack("Fmu2::vr_aux_boolean", vr_aux_boolean_);
599  s.pack("Fmu2::vr_aux_string", vr_aux_string_);
600 }

References init_boolean_, init_integer_, init_real_, init_string_, casadi::SerializingStream::pack(), casadi::FmuInternal::serialize_body(), casadi::SerializingStream::version(), vn_aux_boolean_, vn_aux_integer_, vn_aux_real_, vn_aux_string_, vr_aux_boolean_, vr_aux_integer_, vr_aux_real_, vr_aux_string_, vr_boolean_, vr_integer_, vr_real_, and vr_string_.

◆ serialize_type()

void casadi::FmuInternal::serialize_type ( SerializingStream s) const
virtualinherited

Definition at line 1376 of file fmu.cpp.

1376  {
1377  s.pack("FmuInternal::type", class_name());
1378 }

References casadi::SharedObjectInternal::class_name(), and casadi::SerializingStream::pack().

Referenced by casadi::FmuInternal::serialize().

◆ set()

void casadi::FmuInternal::set ( FmuMemory m,
size_t  ind,
const double *  value 
) const
inherited

Definition at line 1192 of file fmu.cpp.

1192  {
1193  if (value) {
1194  // Argument is given
1195  for (size_t id : ired_[ind]) {
1196  if (*value != m->ibuf_.at(id)) {
1197  m->ibuf_.at(id) = *value;
1198  m->imarked_.at(id) = true;
1199  }
1200  value++;
1201  }
1202  } else {
1203  // Argument is null - all zeros
1204  for (size_t id : ired_[ind]) {
1205  if (0 != m->ibuf_.at(id)) {
1206  m->ibuf_.at(id) = 0;
1207  m->imarked_.at(id) = true;
1208  }
1209  }
1210  }
1211 }

References casadi::FmuMemory::ibuf_, casadi::FmuMemory::imarked_, and casadi::FmuInternal::ired_.

◆ set_adj() [1/2]

void casadi::FmuInternal::set_adj ( FmuMemory m,
casadi_int  nseed,
const casadi_int *  id,
const double *  v 
) const
inherited

Definition at line 1045 of file fmu.cpp.

1046  {
1047  for (casadi_int i = 0; i < nseed; ++i) {
1048  m->osens_.at(*id) = *v++;
1049  m->omarked_.at(*id) = true;
1050  id++;
1051  }
1052 }

References casadi::FmuMemory::omarked_, and casadi::FmuMemory::osens_.

Referenced by casadi::FmuInternal::set_adj().

◆ set_adj() [2/2]

void casadi::FmuInternal::set_adj ( FmuMemory m,
size_t  ind,
const double *  v 
) const
inherited

Definition at line 1054 of file fmu.cpp.

1054  {
1055  // If seeds are zero, no need to add to seed buffers
1056  if (!v) return;
1057  // Pass all seeds FIXME(@jaeandersson): should use compatible types
1058  for (size_t id : ored_[ind]) {
1059  casadi_int id2 = id;
1060  set_adj(m, 1, &id2, v++);
1061  }
1062 }
void set_adj(FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
Definition: fmu.cpp:1045

References casadi::FmuInternal::ored_, and casadi::FmuInternal::set_adj().

◆ set_fwd() [1/2]

void casadi::FmuInternal::set_fwd ( FmuMemory m,
casadi_int  nseed,
const casadi_int *  id,
const double *  v 
) const
inherited

Definition at line 1257 of file fmu.cpp.

1258  {
1259  for (casadi_int i = 0; i < nseed; ++i) {
1260  m->isens_.at(*id) = *v++;
1261  m->imarked_.at(*id) = true;
1262  id++;
1263  }
1264 }

References casadi::FmuMemory::imarked_, and casadi::FmuMemory::isens_.

Referenced by casadi::FmuInternal::set_fwd().

◆ set_fwd() [2/2]

void casadi::FmuInternal::set_fwd ( FmuMemory m,
size_t  ind,
const double *  v 
) const
inherited

Definition at line 1266 of file fmu.cpp.

1266  {
1267  // If seeds are zero, no need to add to seed buffers
1268  if (!v) return;
1269  // Pass all seeds FIXME(@jaeandersson): should use compatible types
1270  for (size_t id : ired_[ind]) {
1271  casadi_int id2 = id;
1272  set_fwd(m, 1, &id2, v++);
1273  }
1274 }
void set_fwd(FmuMemory *m, casadi_int nseed, const casadi_int *id, const double *v) const
Definition: fmu.cpp:1257

References casadi::FmuInternal::ired_, and casadi::FmuInternal::set_fwd().

◆ set_real()

int casadi::Fmu2::set_real ( void *  instance,
const unsigned int *  vr,
size_t  n_vr,
const double *  values,
size_t  n_values 
) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 343 of file fmu2.cpp.

344  {
345  casadi_assert(n_vr == n_values, "Vector-valued variables not supported in FMI 2");
346 
347  // Set time variable, if any
348  if (has_independent_ && n_vr > 0 && *vr == vr_in_[0]) {
349  // Update FMU time
350  fmi2Status status = set_time_(instance, *values);
351  if (status != fmi2OK) return 1;
352  // Skip when setting remaining variables
353  vr++;
354  n_vr--;
355  values++;
356  n_values--;
357  }
358 
359  fmi2Status status = set_real_(instance, vr, n_vr, values);
360  return status != fmi2OK;
361 }

References casadi::FmuInternal::has_independent_, set_real_, set_time_, and casadi::FmuInternal::vr_in_.

◆ set_values()

int casadi::Fmu2::set_values ( void *  instance) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 391 of file fmu2.cpp.

391  {
392  auto c = static_cast<fmi2Component>(instance);
393  // Pass real values before initialization
394  if (!vr_real_.empty()) {
395  fmi2Status status = set_real_(c, get_ptr(vr_real_), vr_real_.size(), get_ptr(init_real_));
396  if (status != fmi2OK) {
397  casadi_warning("fmi2SetReal failed");
398  return 1;
399  }
400  }
401  // Pass integer values before initialization (also enums)
402  if (!vr_integer_.empty()) {
403  fmi2Status status = set_integer_(c, get_ptr(vr_integer_), vr_integer_.size(),
405  if (status != fmi2OK) {
406  casadi_warning("fmi2SetInteger failed");
407  return 1;
408  }
409  }
410  // Pass boolean values before initialization
411  if (!vr_boolean_.empty()) {
412  fmi2Status status = set_boolean_(c, get_ptr(vr_boolean_), vr_boolean_.size(),
414  if (status != fmi2OK) {
415  casadi_warning("fmi2SetBoolean failed");
416  return 1;
417  }
418  }
419  // Pass string values before initialization
420  for (size_t k = 0; k < vr_string_.size(); ++k) {
421  fmi2ValueReference vr = vr_string_[k];
422  fmi2String value = init_string_[k].c_str();
423  fmi2Status status = set_string_(c, &vr, 1, &value);
424  if (status != fmi2OK) {
425  casadi_error("fmi2SetString failed for value reference " + str(vr));
426  }
427  }
428  // Successful return
429  return 0;
430 }

References casadi::get_ptr(), init_boolean_, init_integer_, init_real_, init_string_, set_boolean_, set_integer_, set_real_, set_string_, casadi::str(), vr_boolean_, vr_integer_, vr_real_, and vr_string_.

◆ shared_from_this() [1/2]

B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( )
inlineprotectedinherited

Definition at line 83 of file generic_shared_internal.hpp.

83  {
84  casadi_assert_dev(B::test_cast(static_cast<Internal*>(this)));
85  B ret;
86  ret.own(static_cast<Internal*>(this));
87  return ret;
88  }

◆ shared_from_this() [2/2]

const B casadi::GenericSharedInternal< SharedObject , SharedObjectInternal >::shared_from_this ( ) const
inlineprotectedinherited

Definition at line 92 of file generic_shared_internal.hpp.

92  {
93  casadi_assert_dev(B::test_cast(static_cast<const Internal*>(this)));
94  B ret;
95  ret.own(const_cast<Internal*>(static_cast<const Internal*>(this)));
96  return ret;
97  }

◆ system_infix()

std::string casadi::Fmu2::system_infix ( ) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 61 of file fmu2.cpp.

61  {
62 #if defined(_WIN32)
63  // Windows system
64 #ifdef _WIN64
65  return "win64";
66 #else
67  return "win32";
68 #endif
69 #elif defined(__APPLE__)
70  // OSX
71  return sizeof(void*) == 4 ? "darwin32" : "darwin64";
72 #else
73  // Linux
74  return sizeof(void*) == 4 ? "linux32" : "linux64";
75 #endif
76 }

◆ update_discrete_states()

int casadi::Fmu2::update_discrete_states ( void *  instance,
EventMemory eventmem 
) const
overridevirtual

Implements casadi::FmuInternal.

Definition at line 321 of file fmu2.cpp.

321  {
322  auto c = static_cast<fmi2Component>(instance);
323  // Return arguments in FMI types
324  fmi2EventInfo eventInfo;
325  eventInfo.newDiscreteStatesNeeded = fmi2False;
326  eventInfo.terminateSimulation = fmi2False;
327  eventInfo.nominalsOfContinuousStatesChanged = fmi2False;
328  eventInfo.valuesOfContinuousStatesChanged = fmi2False;
329  eventInfo.nextEventTimeDefined = fmi2False;
330  eventInfo.nextEventTime = 0.0;
331  // Call FMU
332  fmi2Status status = new_discrete_states_(c, &eventInfo);
333  // Pass to event iteration memory
334  eventmem->discrete_states_need_update = eventInfo.newDiscreteStatesNeeded;
335  eventmem->terminate_simulation = eventInfo.terminateSimulation;
336  eventmem->nominals_of_continuous_states_changed = eventInfo.nominalsOfContinuousStatesChanged;
337  eventmem->values_of_continuous_states_changed = eventInfo.valuesOfContinuousStatesChanged;
338  eventmem->next_event_time_defined = eventInfo.nextEventTimeDefined;
339  eventmem->next_event_time = eventInfo.nextEventTime;
340  return status != fmi2OK;
341 }

References casadi::EventMemory::discrete_states_need_update, new_discrete_states_, casadi::EventMemory::next_event_time, casadi::EventMemory::next_event_time_defined, casadi::EventMemory::nominals_of_continuous_states_changed, casadi::EventMemory::terminate_simulation, and casadi::EventMemory::values_of_continuous_states_changed.

◆ weak()

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

Definition at line 67 of file generic_shared_internal.hpp.

191  {
192  if (weak_ref_==nullptr) {
193  weak_ref_ = new GenericWeakRef<Shared, Internal>(static_cast<Internal*>(this));
194  }
195  return weak_ref_;
196  }

Member Data Documentation

◆ aux_

std::vector<std::string> casadi::FmuInternal::aux_
protectedinherited

◆ aux_value_

Value casadi::Fmu2::aux_value_

Definition at line 126 of file fmu2.hpp.

Referenced by finalize(), and get_aux().

◆ can_be_instantiated_only_once_per_process_

bool casadi::FmuInternal::can_be_instantiated_only_once_per_process_
protectedinherited

◆ do_evaluation_dance_

bool casadi::FmuInternal::do_evaluation_dance_
protectedinherited

◆ enter_continuous_time_mode_

fmi2EnterContinuousTimeModeTYPE* casadi::Fmu2::enter_continuous_time_mode_

Definition at line 101 of file fmu2.hpp.

Referenced by enter_continuous_time_mode(), Fmu2(), and load_functions().

◆ enter_initialization_mode_

fmi2EnterInitializationModeTYPE* casadi::Fmu2::enter_initialization_mode_

Definition at line 99 of file fmu2.hpp.

Referenced by enter_initialization_mode(), Fmu2(), and load_functions().

◆ exit_initialization_mode_

fmi2ExitInitializationModeTYPE* casadi::Fmu2::exit_initialization_mode_

Definition at line 100 of file fmu2.hpp.

Referenced by exit_initialization_mode(), Fmu2(), and load_functions().

◆ fmutol_

double casadi::FmuInternal::fmutol_
protectedinherited

◆ free_instance_

fmi2FreeInstanceTYPE* casadi::Fmu2::free_instance_

Definition at line 96 of file fmu2.hpp.

Referenced by Fmu2(), free_instance(), and load_functions().

◆ functions_

fmi2CallbackFunctions casadi::Fmu2::functions_

Definition at line 116 of file fmu2.hpp.

Referenced by instantiate(), and load_functions().

◆ get_boolean_

fmi2GetBooleanTYPE* casadi::Fmu2::get_boolean_

Definition at line 106 of file fmu2.hpp.

Referenced by get_aux_impl(), and load_functions().

◆ get_derivatives_

fmi2GetDerivativesTYPE* casadi::Fmu2::get_derivatives_

Definition at line 102 of file fmu2.hpp.

Referenced by get_derivatives(), get_real(), and load_functions().

◆ get_directional_derivative_

fmi2GetDirectionalDerivativeTYPE* casadi::Fmu2::get_directional_derivative_

Definition at line 112 of file fmu2.hpp.

Referenced by Fmu2(), get_directional_derivative(), and load_functions().

◆ get_integer_

fmi2GetIntegerTYPE* casadi::Fmu2::get_integer_

Definition at line 108 of file fmu2.hpp.

Referenced by get_aux_impl(), and load_functions().

◆ get_real_

fmi2GetRealTYPE* casadi::Fmu2::get_real_

Definition at line 104 of file fmu2.hpp.

Referenced by Fmu2(), get_aux_impl(), get_real(), and load_functions().

◆ get_string_

fmi2GetStringTYPE* casadi::Fmu2::get_string_

Definition at line 110 of file fmu2.hpp.

Referenced by load_functions().

◆ has_independent_

bool casadi::FmuInternal::has_independent_
protectedinherited

◆ hess_sp_

Sparsity casadi::FmuInternal::hess_sp_
protectedinherited

◆ iind_

std::vector<size_t> casadi::FmuInternal::iind_
protectedinherited

◆ iind_map_

std::vector<size_t> casadi::FmuInternal::iind_map_
protectedinherited

◆ init_boolean_

std::vector<fmi2Boolean> casadi::Fmu2::init_boolean_

Definition at line 85 of file fmu2.hpp.

Referenced by Fmu2(), init(), serialize_body(), and set_values().

◆ init_integer_

std::vector<fmi2Integer> casadi::Fmu2::init_integer_

Definition at line 84 of file fmu2.hpp.

Referenced by Fmu2(), init(), serialize_body(), and set_values().

◆ init_real_

std::vector<fmi2Real> casadi::Fmu2::init_real_

Definition at line 83 of file fmu2.hpp.

Referenced by Fmu2(), init(), serialize_body(), and set_values().

◆ init_string_

std::vector<std::string> casadi::Fmu2::init_string_

Definition at line 86 of file fmu2.hpp.

Referenced by Fmu2(), init(), serialize_body(), and set_values().

◆ instance_name_

std::string casadi::FmuInternal::instance_name_
protectedinherited

◆ instantiate_

fmi2InstantiateTYPE* casadi::Fmu2::instantiate_

Definition at line 95 of file fmu2.hpp.

Referenced by Fmu2(), instantiate(), and load_functions().

◆ instantiation_token_

std::string casadi::FmuInternal::instantiation_token_
protectedinherited

◆ ired_

std::vector<std::vector<size_t> > casadi::FmuInternal::ired_
protectedinherited

◆ jac_sp_

Sparsity casadi::FmuInternal::jac_sp_
protectedinherited

◆ li_

Importer casadi::FmuInternal::li_
protectedinherited

◆ logging_on_

bool casadi::FmuInternal::logging_on_
protectedinherited

◆ max_in_

std::vector<double> casadi::FmuInternal::max_in_
protectedinherited

◆ max_out_

std::vector<double> casadi::FmuInternal::max_out_
protectedinherited

◆ min_in_

std::vector<double> casadi::FmuInternal::min_in_
protectedinherited

◆ min_out_

std::vector<double> casadi::FmuInternal::min_out_
protectedinherited

◆ name_

std::string casadi::FmuInternal::name_
protectedinherited

◆ new_discrete_states_

fmi2NewDiscreteStatesTYPE* casadi::Fmu2::new_discrete_states_

Definition at line 113 of file fmu2.hpp.

Referenced by Fmu2(), load_functions(), and update_discrete_states().

◆ nominal_in_

std::vector<double> casadi::FmuInternal::nominal_in_
protectedinherited

◆ nominal_out_

std::vector<double> casadi::FmuInternal::nominal_out_
protectedinherited

◆ number_of_event_indicators_

casadi_int casadi::FmuInternal::number_of_event_indicators_
protectedinherited

◆ nx_

size_t casadi::FmuInternal::nx_
protectedinherited

◆ oind_

std::vector<size_t> casadi::FmuInternal::oind_
protectedinherited

◆ oind_map_

std::vector<size_t> casadi::FmuInternal::oind_map_
protectedinherited

◆ ored_

std::vector<std::vector<size_t> > casadi::FmuInternal::ored_
protectedinherited

◆ provides_adjoint_derivatives_

bool casadi::FmuInternal::provides_adjoint_derivatives_
protectedinherited

◆ provides_directional_derivatives_

bool casadi::FmuInternal::provides_directional_derivatives_
protectedinherited

◆ reset_

fmi2ResetTYPE* casadi::Fmu2::reset_

Definition at line 97 of file fmu2.hpp.

Referenced by Fmu2(), load_functions(), and reset().

◆ resource_

Resource casadi::FmuInternal::resource_
protectedinherited

◆ resource_loc_

std::string casadi::FmuInternal::resource_loc_
protectedinherited

◆ scheme_

std::map<std::string, std::vector<size_t> > casadi::FmuInternal::scheme_
protectedinherited

◆ scheme_in_

std::vector<std::string> casadi::FmuInternal::scheme_in_
protectedinherited

◆ scheme_out_

std::vector<std::string> casadi::FmuInternal::scheme_out_
protectedinherited

◆ set_boolean_

fmi2SetBooleanTYPE* casadi::Fmu2::set_boolean_

Definition at line 107 of file fmu2.hpp.

Referenced by Fmu2(), load_functions(), and set_values().

◆ set_integer_

fmi2SetIntegerTYPE* casadi::Fmu2::set_integer_

Definition at line 109 of file fmu2.hpp.

Referenced by load_functions(), and set_values().

◆ set_real_

fmi2SetRealTYPE* casadi::Fmu2::set_real_

Definition at line 105 of file fmu2.hpp.

Referenced by Fmu2(), load_functions(), set_real(), and set_values().

◆ set_string_

fmi2SetStringTYPE* casadi::Fmu2::set_string_

Definition at line 111 of file fmu2.hpp.

Referenced by get_aux_impl(), load_functions(), and set_values().

◆ set_time_

fmi2SetTimeTYPE* casadi::Fmu2::set_time_

Definition at line 103 of file fmu2.hpp.

Referenced by Fmu2(), load_functions(), and set_real().

◆ setup_experiment_

fmi2SetupExperimentTYPE* casadi::Fmu2::setup_experiment_

Definition at line 98 of file fmu2.hpp.

Referenced by Fmu2(), instantiate(), and load_functions().

◆ value_in_

std::vector<double> casadi::FmuInternal::value_in_
protectedinherited

◆ vn_aux_boolean_

std::vector<std::string> casadi::Fmu2::vn_aux_boolean_

Definition at line 89 of file fmu2.hpp.

Referenced by finalize(), Fmu2(), get_stats(), init(), init_mem(), and serialize_body().

◆ vn_aux_integer_

std::vector<std::string> casadi::Fmu2::vn_aux_integer_

Definition at line 89 of file fmu2.hpp.

Referenced by finalize(), Fmu2(), get_stats(), init(), init_mem(), and serialize_body().

◆ vn_aux_real_

std::vector<std::string> casadi::Fmu2::vn_aux_real_

Definition at line 89 of file fmu2.hpp.

Referenced by finalize(), Fmu2(), get_stats(), init(), init_mem(), and serialize_body().

◆ vn_aux_string_

std::vector<std::string> casadi::Fmu2::vn_aux_string_

Definition at line 89 of file fmu2.hpp.

Referenced by finalize(), Fmu2(), get_stats(), init(), init_mem(), and serialize_body().

◆ vn_in_

std::vector<std::string> casadi::FmuInternal::vn_in_
protectedinherited

◆ vn_out_

std::vector<std::string> casadi::FmuInternal::vn_out_
protectedinherited

◆ vr_aux_boolean_

std::vector<fmi2ValueReference> casadi::Fmu2::vr_aux_boolean_

Definition at line 90 of file fmu2.hpp.

Referenced by Fmu2(), get_aux_impl(), init(), and serialize_body().

◆ vr_aux_integer_

std::vector<fmi2ValueReference> casadi::Fmu2::vr_aux_integer_

Definition at line 90 of file fmu2.hpp.

Referenced by Fmu2(), get_aux_impl(), init(), and serialize_body().

◆ vr_aux_real_

std::vector<fmi2ValueReference> casadi::Fmu2::vr_aux_real_

Definition at line 90 of file fmu2.hpp.

Referenced by Fmu2(), get_aux_impl(), init(), and serialize_body().

◆ vr_aux_string_

std::vector<fmi2ValueReference> casadi::Fmu2::vr_aux_string_

Definition at line 90 of file fmu2.hpp.

Referenced by Fmu2(), get_aux_impl(), init(), and serialize_body().

◆ vr_boolean_

std::vector<fmi2ValueReference> casadi::Fmu2::vr_boolean_

Definition at line 82 of file fmu2.hpp.

Referenced by Fmu2(), init(), serialize_body(), and set_values().

◆ vr_in_

std::vector<unsigned int> casadi::FmuInternal::vr_in_
protectedinherited

◆ vr_integer_

std::vector<fmi2ValueReference> casadi::Fmu2::vr_integer_

Definition at line 82 of file fmu2.hpp.

Referenced by Fmu2(), init(), serialize_body(), and set_values().

◆ vr_out_

std::vector<unsigned int> casadi::FmuInternal::vr_out_
protectedinherited

◆ vr_real_

std::vector<fmi2ValueReference> casadi::Fmu2::vr_real_

Definition at line 82 of file fmu2.hpp.

Referenced by Fmu2(), init(), serialize_body(), and set_values().

◆ vr_string_

std::vector<fmi2ValueReference> casadi::Fmu2::vr_string_

Definition at line 82 of file fmu2.hpp.

Referenced by Fmu2(), init(), serialize_body(), and set_values().

◆ warning_fired_discrete_states_need_update_

bool casadi::FmuInternal::warning_fired_discrete_states_need_update_
mutableprotectedinherited

◆ warning_fired_next_event_time_defined_

bool casadi::FmuInternal::warning_fired_next_event_time_defined_
mutableprotectedinherited

◆ warning_fired_nominals_of_continuous_states_changed_

bool casadi::FmuInternal::warning_fired_nominals_of_continuous_states_changed_
mutableprotectedinherited

◆ warning_fired_terminate_simulation_

bool casadi::FmuInternal::warning_fired_terminate_simulation_
mutableprotectedinherited

◆ warning_fired_values_of_continuous_states_changed_

bool casadi::FmuInternal::warning_fired_values_of_continuous_states_changed_
mutableprotectedinherited

The documentation for this class was generated from the following files: