MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
fmu1 Class Reference

#include <mbdynFMI.h>

Inheritance diagram for fmu1:
Collaboration diagram for fmu1:

Public Member Functions

void parseXML (fmi_import_context_t *context, const char *dirPath)
 
void setCallBackFunction ()
 
 fmu1 (fmi_import_context_t *text, int type)
 
void ImportCreateDLL (void)
 
bool CheckInput (const std::string)
 
int GetNumOfContinousStates (void)
 
int GetNumOfEventIndicators (void)
 
int GetNumOfVar (void)
 
void Initialize (double dTol, double time, double rTol)
 
void EventIndicatorInit (void)
 
void SetRelativeTol (double dTol)
 
void SetTime (double time)
 
void SetStates (double *states)
 
void SetValuesByVariable (const std::string, double)
 
int GetRefValueFromString (const char *s)
 
double GetStateFromRefValue (unsigned int i)
 
void GetStateDerivatives (double *)
 
void GetStates (double *)
 
void GetDirectionalDerivatives (FullMatrixHandler *, int *, int, double *)
 
bool SupportsDirectionalDerivatives ()
 
bool CheckInterrupts (double, double *)
 
void InitializeAsSlave (const char *location, double tstart, double tend)
 
void CSPropogate (double tcur, double dt)
 
virtual ~fmu1 (void)
 
- Public Member Functions inherited from fmu
 fmu (fmi_import_context_t *text, int type)
 
virtual ~fmu (void)
 

Private Attributes

fmi1_callback_functions_t callBackFunctions
 
fmi1_import_t * fmu
 
fmi1_status_t fmistatus
 
jm_status_enu_t jmstatus
 
fmi1_real_t currTime
 
fmi1_real_t relativeTolerance
 
fmi1_event_info_t eventInfo
 
size_t nEventIndicators
 
fmi1_real_t * eventIndicators
 
fmi1_real_t * eventIndicatorsPrev
 
fmi1_import_variable_t * v
 
int numOfContStates
 
fmi1_real_t * deriv
 
fmi1_value_reference_t * vrs
 
fmi1_boolean_t intermediateResults
 

Additional Inherited Members

- Public Types inherited from fmu
enum  SimulationTypes { IMPORT, COSIM }
 
- Public Attributes inherited from fmu
int simType
 
fmi_import_context_t * context
 

Detailed Description

Definition at line 115 of file mbdynFMI.h.

Constructor & Destructor Documentation

fmu1::fmu1 ( fmi_import_context_t *  text,
int  type 
)
inline

Definition at line 143 of file mbdynFMI.h.

References NO_OP.

143  :fmu::fmu(text, type){
144  NO_OP;
145  }
fmu(fmi_import_context_t *text, int type)
Definition: mbdynFMI.h:75
#define NO_OP
Definition: myassert.h:74
fmu1::~fmu1 ( void  )
virtual

Definition at line 472 of file mbdynFMI.cc.

References fmu::context, deriv, eventIndicators, eventIndicatorsPrev, fmistatus, fmu::IMPORT, fmu::simType, STATUSCHECK, and vrs.

472  {
473  fmi_xml_free_context(context);
474 
475  if(simType == IMPORT){
476 
477  fmi1_capi_free_dll(fmu->capi);
478 
479  delete[] eventIndicators;
480  delete[] eventIndicatorsPrev;
481  // delete[] currStates;
482 
483  delete[] deriv;
484  delete[] vrs;
485 
486  fmi1_import_free_model_instance(fmu);
487  fmi1_import_destroy_dllfmu(fmu);
488  fmi1_import_free(fmu);
489 
490  } else {
491 
492  fmistatus = fmi1_import_terminate_slave(fmu);
494  fmi1_import_free_slave_instance(fmu);
495 
496  }
497 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_real_t * eventIndicators
Definition: mbdynFMI.h:128
fmi1_real_t * eventIndicatorsPrev
Definition: mbdynFMI.h:129
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
fmi_import_context_t * context
Definition: mbdynFMI.h:73
int simType
Definition: mbdynFMI.h:72
fmi1_real_t * deriv
Definition: mbdynFMI.h:133
fmi1_value_reference_t * vrs
Definition: mbdynFMI.h:134

Member Function Documentation

bool fmu1::CheckInput ( const std::string  s)
virtual

Implements fmu.

Definition at line 598 of file mbdynFMI.cc.

References v.

598  {
599  v = fmi1_import_get_variable_by_name(fmu, s.c_str());
600  if(v==NULL){
601  silent_cout(s.c_str()<<" is not defined in XML, hence ");
602  return false;
603  }
604 
605  return ((fmi1_import_get_causality(v))==0);
606 }
fmi1_import_variable_t * v
Definition: mbdynFMI.h:130
Definition: mbdynFMI.h:65
bool fmu1::CheckInterrupts ( double  currTime,
double *  states 
)
virtual

Implements fmu.

Definition at line 576 of file mbdynFMI.cc.

References eventIndicators, eventIndicatorsPrev, eventInfo, fmistatus, intermediateResults, nEventIndicators, numOfContStates, and STATUSCHECK.

576  {
577  int zeroCrossningEvent = 0;
578 
579  fmistatus = fmi1_import_get_event_indicators(fmu, eventIndicators, nEventIndicators);
581  for (unsigned int k = 0; k < nEventIndicators; k++) {
582  if (eventIndicators[k]*eventIndicatorsPrev[k] < 0) {
583  zeroCrossningEvent = 1;
584  break;
585  }
586  }
587 
588  if ( zeroCrossningEvent || (eventInfo.upcomingTimeEvent && currTime == eventInfo.nextEventTime)) {
589  fmistatus = fmi1_import_eventUpdate(fmu, intermediateResults, &eventInfo);
590  fmistatus = fmi1_import_get_continuous_states(fmu, states, numOfContStates);
591  fmistatus = fmi1_import_get_event_indicators(fmu, eventIndicatorsPrev, nEventIndicators);
592  return true;
593  } else {
594  return false;
595  }
596 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_real_t * eventIndicators
Definition: mbdynFMI.h:128
fmi1_event_info_t eventInfo
Definition: mbdynFMI.h:125
fmi1_real_t * eventIndicatorsPrev
Definition: mbdynFMI.h:129
fmi1_real_t currTime
Definition: mbdynFMI.h:123
fmi1_boolean_t intermediateResults
Definition: mbdynFMI.h:136
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
size_t nEventIndicators
Definition: mbdynFMI.h:127
int numOfContStates
Definition: mbdynFMI.h:132
void fmu1::CSPropogate ( double  tcur,
double  dt 
)
virtual

Implements fmu.

Definition at line 711 of file mbdynFMI.cc.

References fmistatus, and STATUSCHECK.

711  {
712  fmistatus = fmi1_import_do_step(fmu, tcur, dt, fmi1_true);
714 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
void fmu1::EventIndicatorInit ( void  )
virtual

Implements fmu.

Definition at line 699 of file mbdynFMI.cc.

References eventIndicators, eventIndicatorsPrev, fmistatus, and nEventIndicators.

699  {
700  nEventIndicators = fmi1_import_get_number_of_event_indicators(fmu);
701 
702  eventIndicators = new fmi1_real_t [nEventIndicators];
703  eventIndicatorsPrev = new fmi1_real_t [nEventIndicators];
704 
705  fmistatus = fmi1_import_get_event_indicators(fmu, eventIndicatorsPrev, nEventIndicators);
706  if(fmistatus){
707  silent_cout("This FMU does triggers events. Warning: Event triggers not supported by MBDyn\n");
708  }
709 }
Definition: mbdynFMI.h:65
fmi1_real_t * eventIndicators
Definition: mbdynFMI.h:128
fmi1_real_t * eventIndicatorsPrev
Definition: mbdynFMI.h:129
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
size_t nEventIndicators
Definition: mbdynFMI.h:127
void fmu1::GetDirectionalDerivatives ( FullMatrixHandler jacobian,
int vector,
int  vectorLength,
double *  seedVector 
)
virtual

Implements fmu.

Definition at line 685 of file mbdynFMI.cc.

References NO_OP.

685  {
686  NO_OP;
687 }
#define NO_OP
Definition: myassert.h:74
int fmu1::GetNumOfContinousStates ( void  )
virtual

Implements fmu.

Definition at line 524 of file mbdynFMI.cc.

References deriv, numOfContStates, and vrs.

524  {
525  numOfContStates = fmi1_import_get_number_of_continuous_states(fmu);
526 // currStates = new double [numOfContStates];
527 // currStatesDer = new double [numOfContStates];
528  vrs = new fmi1_value_reference_t [numOfContStates];
529  deriv = new fmi1_real_t [numOfContStates];
530  return numOfContStates;
531 }
Definition: mbdynFMI.h:65
fmi1_real_t * deriv
Definition: mbdynFMI.h:133
fmi1_value_reference_t * vrs
Definition: mbdynFMI.h:134
int numOfContStates
Definition: mbdynFMI.h:132
int fmu1::GetNumOfEventIndicators ( void  )
virtual

Implements fmu.

Definition at line 572 of file mbdynFMI.cc.

572  {
573  return fmi1_import_get_number_of_event_indicators(fmu);
574 }
Definition: mbdynFMI.h:65
int fmu1::GetNumOfVar ( void  )
virtual

Implements fmu.

Definition at line 689 of file mbdynFMI.cc.

689  {
690  fmi1_import_variable_list_t* vl;
691  vl = fmi1_import_get_variable_list(fmu);
692  return fmi1_import_get_variable_list_size(vl);
693 }
Definition: mbdynFMI.h:65
int fmu1::GetRefValueFromString ( const char *  s)
virtual

Implements fmu.

Definition at line 646 of file mbdynFMI.cc.

References v.

646  {
647  v = fmi1_import_get_variable_by_name(fmu, s);
648  return static_cast<int>(fmi1_import_get_variable_vr(v));
649 }
fmi1_import_variable_t * v
Definition: mbdynFMI.h:130
Definition: mbdynFMI.h:65
void fmu1::GetStateDerivatives ( double *  derivatives)
virtual

Implements fmu.

Definition at line 651 of file mbdynFMI.cc.

References fmistatus, numOfContStates, and STATUSCHECK.

651  {
652 
653  fmistatus = fmi1_import_get_derivatives(fmu, derivatives, numOfContStates);
655 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
int numOfContStates
Definition: mbdynFMI.h:132
double fmu1::GetStateFromRefValue ( unsigned int  i)
virtual

Implements fmu.

Definition at line 672 of file mbdynFMI.cc.

References fmistatus, and STATUSCHECK.

672  {
673  double realValue[1];
674  fmi1_value_reference_t valueReference = {i};
675  fmistatus = fmi1_import_get_real(fmu, &valueReference, 1, realValue);
677 
678  return realValue[0];
679 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
void fmu1::GetStates ( double *  states)
virtual

Implements fmu.

Definition at line 717 of file mbdynFMI.cc.

References fmistatus, and numOfContStates.

717  {
718 
719  fmistatus = fmi1_import_get_continuous_states(fmu, states, numOfContStates);
720  if(!fmistatus){
721  fmistatus = fmi1_import_get_nominal_continuous_states(fmu, states, numOfContStates);
722  }
723  if(!fmistatus){
724  for(int i=0; i<numOfContStates; i++){
725  states[i] = 0;
726  }
727  }
728 
729 // STATUSCHECK(fmistatus);
730 
731 }
Definition: mbdynFMI.h:65
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
int numOfContStates
Definition: mbdynFMI.h:132
void fmu1::ImportCreateDLL ( void  )
virtual

Implements fmu.

Definition at line 517 of file mbdynFMI.cc.

References callBackFunctions, jmstatus, and STATUSCHECK.

517  {
518  jmstatus = fmi1_import_create_dllfmu(fmu, callBackFunctions, 1);
520 
521  silent_cout("Successfully created the DLL loading mechanism.\n");
522 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_callback_functions_t callBackFunctions
Definition: mbdynFMI.h:117
jm_status_enu_t jmstatus
Definition: mbdynFMI.h:121
void fmu1::Initialize ( double  dTol,
double  time,
double  rTol 
)
virtual

Implements fmu.

Definition at line 533 of file mbdynFMI.cc.

References currTime, eventInfo, fmistatus, intermediateResults, jmstatus, and STATUSCHECK.

533  {
534 
535  fmi1_boolean_t tolControlled = fmi1_true;
536 
537  if (dTol ==0 ){
538  dTol = fmi1_import_get_default_experiment_tolerance(fmu);
539  tolControlled = fmi1_false;
540  }
541  currTime = time;
542 
543  STATUSCHECK(fmi1_status_ok);
544 
545  jmstatus = fmi1_import_instantiate_model(fmu, "Test ME model instance");
547 
548  fmistatus = fmi1_import_initialize(fmu, tolControlled, dTol, &eventInfo);
550 
551  fmistatus = fmi1_import_set_time(fmu, currTime);
553 
554 // Necessary to initialize model as capi
555  fmi1_capi_load_dll(fmu->capi);
556 
557  jmstatus = fmi1_capi_load_fcn(fmu->capi);
559 
560 #ifdef DEBUG
561  fmi1_boolean_t loggingOn = fmi1_true;
562 #else
563  fmi1_boolean_t loggingOn = fmi1_false;
564 #endif
565 
566  fmi1_capi_instantiate_model(fmu->capi, "noName", fmi1_import_get_GUID(fmu), loggingOn);
567 
568  intermediateResults = fmi1_false;
569  silent_cout("FMU Initialized\n");
570 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_event_info_t eventInfo
Definition: mbdynFMI.h:125
fmi1_real_t currTime
Definition: mbdynFMI.h:123
fmi1_boolean_t intermediateResults
Definition: mbdynFMI.h:136
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
jm_status_enu_t jmstatus
Definition: mbdynFMI.h:121
void fmu1::InitializeAsSlave ( const char *  location,
double  tstart,
double  tend 
)
virtual

Implements fmu.

Definition at line 733 of file mbdynFMI.cc.

References fmistatus, jmstatus, and STATUSCHECK.

733  {
734  std::stringstream resourceLocation;
735  std::string strLocation = location;
736 
737  resourceLocation << "file://" << strLocation;
738  jmstatus = fmi1_import_instantiate_slave(fmu, "Test CS model instance", resourceLocation.str().c_str(), "", 0.0, fmi1_false, fmi1_false);
740 // INITIALIZE PRINTS SOME WARNINGS.
741  fmistatus = fmi1_import_initialize_slave(fmu, 1.0, fmi1_false, 10.0);
743 
744 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
jm_status_enu_t jmstatus
Definition: mbdynFMI.h:121
void fmu1::parseXML ( fmi_import_context_t *  context,
const char *  dirPath 
)
virtual

Implements fmu.

Definition at line 500 of file mbdynFMI.cc.

References MBDYN_EXCEPT_ARGS.

500  {
501  fmu = fmi1_import_parse_xml(context, dirPath);
502  if (!fmu){
503  silent_cout("Error parsing XML\n");
505  } else {
506  silent_cout("XML Parsed successfully\n");
507  }
508 }
Definition: mbdynFMI.h:65
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
fmi_import_context_t * context
Definition: mbdynFMI.h:73
void fmu1::setCallBackFunction ( )
virtual

Implements fmu.

Definition at line 510 of file mbdynFMI.cc.

References callBackFunctions.

510  {
511  callBackFunctions.logger = fmi1_log_forwarding;
512  callBackFunctions.allocateMemory = calloc;
513  callBackFunctions.freeMemory = free;
514  silent_cout("Callback Functions Set.\n");
515 }
fmi1_callback_functions_t callBackFunctions
Definition: mbdynFMI.h:117
void fmu1::SetRelativeTol ( double  dTol)
virtual

Implements fmu.

Definition at line 695 of file mbdynFMI.cc.

References relativeTolerance.

695  {
696  relativeTolerance = (fmi1_real_t)dTol;
697 }
fmi1_real_t relativeTolerance
Definition: mbdynFMI.h:124
void fmu1::SetStates ( double *  states)
virtual

Implements fmu.

Definition at line 663 of file mbdynFMI.cc.

References fmistatus, numOfContStates, STATUSCHECK, and vrs.

663  {
664 
665  fmistatus = fmi1_capi_get_state_value_references(fmu->capi, vrs, numOfContStates);
667  fmistatus = fmi1_import_set_real(fmu, vrs, numOfContStates, states);
669 
670 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
fmi1_value_reference_t * vrs
Definition: mbdynFMI.h:134
int numOfContStates
Definition: mbdynFMI.h:132
void fmu1::SetTime ( double  time)
virtual

Implements fmu.

Definition at line 657 of file mbdynFMI.cc.

References currTime, fmistatus, and STATUSCHECK.

657  {
658  currTime = time;
659  fmistatus = fmi1_import_set_time(fmu, currTime);
661 }
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
fmi1_real_t currTime
Definition: mbdynFMI.h:123
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
void fmu1::SetValuesByVariable ( const std::string  s,
double  value 
)
virtual

Implements fmu.

Definition at line 610 of file mbdynFMI.cc.

References fmistatus, MBDYN_EXCEPT_ARGS, STATUSCHECK, and v.

610  {
611  fmi1_value_reference_t ref;
612  fmi1_variable_alias_kind_enu_t aliasKind;
613  fmi1_base_type_enu_t baseType;
614 
615  fmi1_import_variable_t* v = fmi1_import_get_variable_by_name(fmu, s.c_str());
616 
617  ref = fmi1_import_get_variable_vr(v);
618  aliasKind = fmi1_import_get_variable_alias_kind(v);
619  baseType = fmi1_import_get_variable_base_type(v);
620 
621  if (aliasKind == fmi1_variable_is_negated_alias){
622  if(baseType != fmi1_base_type_bool){
623  value = -value;
624  }
625  else {
626  value = (bool)!value;
627  }
628  }
629 
630  if (baseType == fmi1_base_type_real){
631  fmistatus = fmi1_import_set_real(fmu, &ref, 1, &value);
632  }
633  else if (baseType == fmi1_base_type_int){
634  fmistatus = fmi1_import_set_integer(fmu, &ref, 1, (const int*)&value);
635  }
636  else if (baseType == fmi1_base_type_bool){
637  fmistatus = fmi1_import_set_boolean(fmu, &ref, 1, (const fmi1_boolean_t*)&value);
638  }
639  else{
640  silent_cerr("Input type not Supported");
642  }
644 }
fmi1_import_variable_t * v
Definition: mbdynFMI.h:130
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
int bool
Definition: mbdyn.h:74
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
bool fmu1::SupportsDirectionalDerivatives ( )
virtual

Implements fmu.

Definition at line 681 of file mbdynFMI.cc.

681  {
682  return false;
683 }

Member Data Documentation

fmi1_callback_functions_t fmu1::callBackFunctions
private

Definition at line 117 of file mbdynFMI.h.

Referenced by ImportCreateDLL(), and setCallBackFunction().

fmi1_real_t fmu1::currTime
private

Definition at line 123 of file mbdynFMI.h.

Referenced by Initialize(), and SetTime().

fmi1_real_t* fmu1::deriv
private

Definition at line 133 of file mbdynFMI.h.

Referenced by GetNumOfContinousStates(), and ~fmu1().

fmi1_real_t* fmu1::eventIndicators
private

Definition at line 128 of file mbdynFMI.h.

Referenced by CheckInterrupts(), EventIndicatorInit(), and ~fmu1().

fmi1_real_t* fmu1::eventIndicatorsPrev
private

Definition at line 129 of file mbdynFMI.h.

Referenced by CheckInterrupts(), EventIndicatorInit(), and ~fmu1().

fmi1_event_info_t fmu1::eventInfo
private

Definition at line 125 of file mbdynFMI.h.

Referenced by CheckInterrupts(), and Initialize().

fmi1_import_t* fmu1::fmu
private

Definition at line 118 of file mbdynFMI.h.

fmi1_boolean_t fmu1::intermediateResults
private

Definition at line 136 of file mbdynFMI.h.

Referenced by CheckInterrupts(), and Initialize().

jm_status_enu_t fmu1::jmstatus
private

Definition at line 121 of file mbdynFMI.h.

Referenced by ImportCreateDLL(), Initialize(), and InitializeAsSlave().

size_t fmu1::nEventIndicators
private

Definition at line 127 of file mbdynFMI.h.

Referenced by CheckInterrupts(), and EventIndicatorInit().

int fmu1::numOfContStates
private
fmi1_real_t fmu1::relativeTolerance
private

Definition at line 124 of file mbdynFMI.h.

Referenced by SetRelativeTol().

fmi1_import_variable_t* fmu1::v
private

Definition at line 130 of file mbdynFMI.h.

Referenced by CheckInput(), GetRefValueFromString(), and SetValuesByVariable().

fmi1_value_reference_t* fmu1::vrs
private

Definition at line 134 of file mbdynFMI.h.

Referenced by GetNumOfContinousStates(), SetStates(), and ~fmu1().


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