MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mbdynFMI.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/modules/module-FMU/mbdynFMI.cc,v 1.3 2017/01/12 15:20:16 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 /*
33  AUTHOR: Devyesh Tandon <devyeshtandon+mbdyn@gmail.com>
34  Copyright (C) 2016-2017 all rights reserved.
35  The copyright of this patch is transferred
36  to Pierangelo Masarati and Paolo Mantegazza
37  for use in the software MBDyn as described
38  in the GNU Public License version 2.1
39 
40 */
41 #include "mbconfig.h"
42 #include "mbdynFMI.h"
43 #include "stepsol.h"
44 
45 #include <sstream>
46 #include <iostream>
47 
48 #include <fmilib.h>
49 
50 #include <FMI2/fmi2_import.h>
51 //#include <FMI2/fmi2_xml_model_description.h>
52 
53 #include <FMI/fmi_version.h>
54 #include <FMI2/fmi2_types.h>
55 #include <FMI2/fmi2_functions.h>
56 #include <FMI2/fmi2_enums.h>
57 //#include <FMI2/fmi2_capi.h>
58 #include <FMI/fmi_util.h>
59 #include "fmi2_import_impl.h"
60 
61 //#include <FMI2/fmi2_capi_impl.h>
62 //#include <FMI2/fmi2_capi.h>
63 
64 #include <FMI1/fmi1_import.h>
65 //#include <FMI1/fmi1_xml_model_description.h>
66 
67 //#include "../FMI/fmi_import_context_impl.h"
68 //#include <FMI1/fmi1_capi_impl.h>
69 
70 #include <FMI/fmi_version.h>
71 #include <FMI1/fmi1_types.h>
72 #include <FMI1/fmi1_functions.h>
73 #include <FMI1/fmi1_enums.h>
74 //#include <FMI1/fmi1_capi.h>
75 #include <FMI/fmi_util.h>
76 #include "fmi1_import_impl.h"
77 
78 #define STATUSCHECK(a)\
79  if (a!=0) {\
80  printf("Error in %s, %d\n", __func__, __LINE__); \
81  throw ErrGeneric(MBDYN_EXCEPT_ARGS); \
82  }
83 
84 void do_event_iteration(fmi2_import_t *fmu, fmi2_event_info_t *eventInfo)
85 {
86  eventInfo->newDiscreteStatesNeeded = fmi2_true;
87  eventInfo->terminateSimulation = fmi2_false;
88  while (eventInfo->newDiscreteStatesNeeded && !eventInfo->terminateSimulation) {
89  fmi2_import_new_discrete_states(fmu, eventInfo);
90  }
91 }
92 
93 static void stepFinished(fmi2_component_environment_t env, fmi2_status_t status) {
94  silent_cout("stepFinished is called with fmiStatus = "<< fmi2_status_to_string(status)<<std::endl);
95 }
96 
97 
98 int annotation_start_handle(void *context, const char *parentName, void *parent, const char *elm, const char **attr) {
99  int i = 0;
100  printf("Annotation element %s start (tool: %s, parent:%s)\n", elm, parentName,
101  parent?fmi2_import_get_variable_name((fmi2_import_variable_t*)parent):"model");
102  while(attr[i]) {
103  printf("Attribute %s = %s\n", attr[i], attr[i+1]);
104  i+=2;
105  }
106  printf("Annotation data:\n");
107  return 0;
108 }
109 
110 int annotation_data_handle(void* context, const char *s, int len) {
111  int i;
112  for(i = 0; i < len; i++){
113  printf("%c", s[i]);
114  }
115  return 0;
116 }
117 
118 int annotation_end_handle(void *context, const char *elm) {
119  printf("\nAnnotation element %s end\n", elm);
120  return 0;
121 }
122 
123 
124 fmi2_xml_callbacks_t annotation_callbacks = {
127  annotation_end_handle, NULL};
128 
129 
130 
131 void fmu2::parseXML(fmi_import_context_t* context, const char* dirPath){
132 
133  fmu = fmi2_import_parse_xml(context, dirPath, &annotation_callbacks);
134  if (!fmu){
135  silent_cout("Error parsing XML 2.0\n");
137  } else {
138  silent_cout("XML Parsed successfully\n");
139  }
140 }
141 
143  callBackFunctions.logger = fmi2_log_forwarding;
144  callBackFunctions.allocateMemory = calloc;
145  callBackFunctions.freeMemory = free;
146  callBackFunctions.stepFinished = stepFinished;
147  callBackFunctions.componentEnvironment = 0;
148 }
149 
151 
152  if(simType != fmi2_import_get_fmu_kind(fmu)-1){
153  silent_cout("This FMU does not support the specified simulation type");
155  }
156 
157 
158  if(simType == IMPORT){
159  jmstatus = fmi2_import_create_dllfmu(fmu, fmi2_fmu_kind_me, &callBackFunctions);
160  }
161  else if (simType == COSIM){
162  jmstatus = fmi2_import_create_dllfmu(fmu, fmi2_fmu_kind_cs, &callBackFunctions);
163  }
164  else{
165  std::cout<<"Unknown Type";
166  }
167 
169 }
170 
172  numOfContStates = fmi2_import_get_number_of_continuous_states(fmu);
173 
174  return numOfContStates;
175 }
176 
178  return fmi2_import_get_number_of_event_indicators(fmu);
179 }
180 
182  fmi2_import_variable_list_t* vl;
183  vl = fmi2_import_get_variable_list(fmu, 0);
184  return fmi2_import_get_variable_list_size(vl);
185 }
186 
187 void fmu2::Initialize(double dTol, double time, double rTol){
188  jmstatus = fmi2_import_instantiate(fmu, "Test ME model instance",fmi2_model_exchange,0,0);
190 
191  if (rTol ==0){
192  rTol = 0.001;
193  }
194 
195  fmistatus = fmi2_import_setup_experiment(fmu, dTol, rTol, time, fmi2_false, 0.0);
197  fmistatus = fmi2_import_enter_initialization_mode(fmu);
199  fmistatus = fmi2_import_exit_initialization_mode(fmu);
201 
203  fmi2_import_enter_continuous_time_mode(fmu);
204  fmistatus = fmi2_import_set_time(fmu, time);
206 
207  eventInfo.newDiscreteStatesNeeded = fmi2_false;
208  eventInfo.terminateSimulation = fmi2_false;
209  eventInfo.nominalsOfContinuousStatesChanged = fmi2_false;
210  eventInfo.valuesOfContinuousStatesChanged = fmi2_true;
211  eventInfo.nextEventTimeDefined = fmi2_false;
212  eventInfo.nextEventTime = -0.0;
213 
214 }
215 
217  unsigned int capability = 0;
218 
219  if(simType == COSIM){
220  fmi2_capabilities_enu_t id = fmi2_cs_providesDirectionalDerivatives;
221  capability = fmi2_xml_get_capability(fmu->md, id);
222  } else if (simType == IMPORT){
223  fmi2_capabilities_enu_t id = fmi2_me_providesDirectionalDerivatives;
224  capability = fmi2_xml_get_capability(fmu->md, id);
225  }
226 
227  if (!capability){
228  silent_cout("This FMU does not support Directional Derivatives\n");
229  return false;
230  }
231 
232  silent_cout("This FMU supports Directional Derivatives\n");
233  return true;
234 
235 
236 }
237 
238 void fmu2::GetDirectionalDerivatives(FullMatrixHandler* jacobian, int* inputStatesVRef, int inputLength, double* seedVector){
239 //Seed Vector (the state value)
240 
241  fmi2_import_variable_list_t* derivativeList = fmi2_import_get_derivatives_list(fmu);
242  size_t derivativeListSize = fmi2_import_get_variable_list_size(derivativeList);
243 
244  fmi2_import_variable_t *var;
245  fmi2_import_real_variable_t *varCont;
246  fmi2_value_reference_t* derList = new fmi2_value_reference_t[derivativeListSize];
247  fmi2_value_reference_t* stateList = new fmi2_value_reference_t[derivativeListSize + inputLength];
248 
249  for (unsigned int i=0; i<derivativeListSize; i++){
250  var = fmi2_import_get_variable(derivativeList, i);
251  derList[i] = fmi2_import_get_variable_vr(var);
252  varCont = fmi2_import_get_real_variable_derivative_of((fmi2_import_real_variable_t*)var);
253  stateList[i] = fmi2_import_get_variable_vr((fmi2_import_variable_t*)varCont);
254  }
255 
256  for (int i=numOfContStates; i<inputLength+numOfContStates; i++){
257  stateList[i] = inputStatesVRef[i-numOfContStates];
258  }
259 
260  fmi2_real_t output[numOfContStates + inputLength];
261 
262  for (int i=0; i<numOfContStates; i++){
263  fmistatus = fmi2_import_get_directional_derivative(fmu, stateList, numOfContStates + inputLength, &derList[i], 1, output , seedVector);
265 
266  for (int j=0; j<numOfContStates + inputLength; j++){
267  jacobian->PutCoef(i+1, j+1, output[j]);
268  }
269  }
270  delete[] derList;
271  delete[] stateList;
272 }
273 
274 
275 
277  nEventIndicators = fmi2_import_get_number_of_event_indicators(fmu);
278 
279  eventIndicators = new fmi2_real_t [nEventIndicators];
280  eventIndicatorsPrev = new fmi2_real_t [nEventIndicators];
281 
282  fmistatus = fmi2_import_get_event_indicators(fmu, eventIndicatorsPrev, nEventIndicators);
283 
284  if(fmistatus){
285  silent_cout("This FMU does triggers events. Warning: Event triggers not supported by MBDyn\n");
286  }
287 }
288 
289 void fmu2::SetRelativeTol(double dTol){
290  relativeTolerance = (fmi1_real_t)dTol;
291 }
292 
293 void fmu2::SetTime(double time){
294  currTime = time;
295  fmistatus = fmi2_import_set_time(fmu, currTime);
297 }
298 
299 void fmu2::SetStates(double* states){
300  callEventUpdate = fmi2_false;
301  terminateSimulation = fmi2_false;
302  fmistatus = fmi2_import_set_continuous_states(fmu, states, numOfContStates);
304 
305  fmistatus = fmi2_import_completed_integrator_step(fmu, fmi2_true, &callEventUpdate, &terminateSimulation);
307 
308 }
309 
310 bool fmu2::CheckInput(const std::string s){
311  v = fmi2_import_get_variable_by_name(fmu, s.c_str());
312  if(v==NULL){
313  silent_cout(s.c_str()<<" is not defined in XML, hence ");
314  return false;
315  }
316  return ((fmi2_import_get_causality(v))==2);
317 }
318 
319 int fmu2::GetRefValueFromString(const char* s){
320  v = fmi2_import_get_variable_by_name(fmu, s);
321  return static_cast<int>(fmi2_import_get_variable_vr(v));
322 
323 }
324 
325 double fmu2::GetStateFromRefValue(unsigned int i){
326  double realValue[1];
327  fmi1_value_reference_t valueReference = {i};
328  fmistatus = fmi2_import_get_real(fmu, &valueReference, 1, realValue);
330 
331  return realValue[0];
332 
333 }
334 
336 
337  fmi_import_free_context(context);
338 
339  if (simType == IMPORT ){
340  delete[] eventIndicators;
341  delete[] eventIndicatorsPrev;
342 
343  fmi2_import_free_instance(fmu);
344  fmi2_import_destroy_dllfmu(fmu);
345  fmi2_import_free(fmu);
346 
347  } else {
348 
349  fmistatus = fmi2_import_terminate(fmu);
351  fmi2_import_free_instance(fmu);
352  fmi2_import_destroy_dllfmu(fmu);
353  fmi2_import_free(fmu);
354 
355  }
356 
357 }
358 
359 
360 void fmu2::GetStateDerivatives(double* derivatives){
361 
362  fmistatus = fmi2_import_get_derivatives(fmu, derivatives, numOfContStates);
363 
365 
366 }
367 
368 void fmu2::GetStates(double* states){
369  fmistatus = fmi2_import_get_continuous_states(fmu, states, numOfContStates);
371 }
372 
373 bool fmu2::CheckInterrupts(double currTime, double* states){
374  int zeroCrossningEvent = 0;
375 
376  fmistatus = fmi2_import_get_event_indicators(fmu, eventIndicators, nEventIndicators);
378  for (unsigned int k = 0; k < nEventIndicators; k++) {
379  if (eventIndicators[k]*eventIndicatorsPrev[k] < 0) {
380  zeroCrossningEvent = 1;
381  break;
382  }
383  }
384 
385  if ( zeroCrossningEvent || (eventInfo.nextEventTimeDefined && currTime == eventInfo.nextEventTime)) {
386  fmistatus = fmi2_import_enter_event_mode(fmu);
388  fmistatus = fmi2_import_enter_continuous_time_mode(fmu);
389  fmistatus = fmi2_import_get_continuous_states(fmu, states, numOfContStates);
390  fmistatus = fmi2_import_get_event_indicators(fmu, eventIndicatorsPrev, nEventIndicators);
391 
392 
393  return true;
394  } else {
395  return false;
396  }
397 }
398 
399 void fmu2::SetValuesByVariable(const std::string s, double value){
400  fmi2_value_reference_t ref;
401  fmi2_variable_alias_kind_enu_t aliasKind;
402  fmi2_base_type_enu_t baseType;
403 
404  fmi2_import_variable_t* v = fmi2_import_get_variable_by_name(fmu, s.c_str());
405 
406  ref = fmi2_import_get_variable_vr(v);
407  aliasKind = fmi2_import_get_variable_alias_kind(v);
408  baseType = fmi2_import_get_variable_base_type(v);
409 
410  if (aliasKind == fmi2_variable_is_not_alias){
411  if(baseType != fmi2_base_type_bool){
412  value = -value;
413  }
414  else{
415  value = (bool)!value;
416  }
417  }
418 
419  if (baseType == fmi2_base_type_real){
420  fmistatus = fmi2_import_set_real(fmu, &ref, 1, &value);
421  }
422  else if (baseType == fmi2_base_type_int){
423  fmistatus = fmi2_import_set_integer(fmu, &ref, 1, (const int*)&value);
424  }
425  else if (baseType == fmi2_base_type_bool){
426  fmistatus = fmi2_import_set_boolean(fmu, &ref, 1, (const fmi2_boolean_t*)&value);
427  }
428  else{
429  silent_cerr("Input type not Supported");
431  }
433 }
434 
435 
436 void fmu2::InitializeAsSlave(const char* location, double tstart, double tend){
437 
438  std::stringstream resourceLocation;
439  std::string strLocation = location;
440 
441  resourceLocation << "file://" << strLocation;
442  fmi2_boolean_t visible = fmi2_false;
443  jmstatus = fmi2_import_instantiate(fmu, "Model for CS", fmi2_cosimulation, resourceLocation.str().c_str(), visible);
445 
446  if (tend == std::numeric_limits<double>::max()){
447  fmistatus = fmi2_import_setup_experiment(fmu, fmi2_true, relativeTolerance, tstart, fmi2_false, 0);
448  } else {
449  fmistatus = fmi2_import_setup_experiment(fmu, fmi2_true, relativeTolerance, tstart, fmi2_true, tend);
450  }
451 
453 
454  fmistatus = fmi2_import_enter_initialization_mode(fmu);
456 
457  fmistatus = fmi2_import_exit_initialization_mode(fmu);
459 
460 }
461 
462 void fmu2::CSPropogate(double tcur, double dt){
463  fmistatus = fmi2_import_do_step(fmu, tcur, dt, fmi2_true);
465 }
466 
467 
468 fmu::~fmu(void){
469  NO_OP;
470 }
471 
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 }
498 
499 
500 void fmu1::parseXML(fmi_import_context_t* context, const char* dirPath){
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 }
509 
511  callBackFunctions.logger = fmi1_log_forwarding;
512  callBackFunctions.allocateMemory = calloc;
513  callBackFunctions.freeMemory = free;
514  silent_cout("Callback Functions Set.\n");
515 }
516 
518  jmstatus = fmi1_import_create_dllfmu(fmu, callBackFunctions, 1);
520 
521  silent_cout("Successfully created the DLL loading mechanism.\n");
522 }
523 
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 }
532 
533 void fmu1::Initialize(double dTol, double time, double rTol){
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 }
571 
573  return fmi1_import_get_number_of_event_indicators(fmu);
574 }
575 
576 bool fmu1::CheckInterrupts(double currTime, double* states){
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 }
597 
598 bool fmu1::CheckInput(const std::string s){
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 }
607 
608 
609 
610 void fmu1::SetValuesByVariable(const std::string s, double value){
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 }
645 
646 int fmu1::GetRefValueFromString(const char* s){
647  v = fmi1_import_get_variable_by_name(fmu, s);
648  return static_cast<int>(fmi1_import_get_variable_vr(v));
649 }
650 
651 void fmu1::GetStateDerivatives(double* derivatives){
652 
653  fmistatus = fmi1_import_get_derivatives(fmu, derivatives, numOfContStates);
655 }
656 
657 void fmu1::SetTime(double time){
658  currTime = time;
659  fmistatus = fmi1_import_set_time(fmu, currTime);
661 }
662 
663 void fmu1::SetStates(double* states){
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 }
671 
672 double fmu1::GetStateFromRefValue(unsigned int i){
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 }
680 
682  return false;
683 }
684 
685 void fmu1::GetDirectionalDerivatives(FullMatrixHandler* jacobian, int* vector, int vectorLength, double* seedVector){
686  NO_OP;
687 }
688 
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 }
694 
695 void fmu1::SetRelativeTol(double dTol){
696  relativeTolerance = (fmi1_real_t)dTol;
697 }
698 
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 }
710 
711 void fmu1::CSPropogate(double tcur, double dt){
712  fmistatus = fmi1_import_do_step(fmu, tcur, dt, fmi1_true);
714 }
715 
716 
717 void fmu1::GetStates(double* states){
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 }
732 
733 void fmu1::InitializeAsSlave(const char* location, double tstart, double tend){
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 }
fmi1_import_variable_t * v
Definition: mbdynFMI.h:130
void EventIndicatorInit(void)
Definition: mbdynFMI.cc:699
#define STATUSCHECK(a)
Definition: mbdynFMI.cc:78
Definition: mbdynFMI.h:65
Definition: matrix.h:68
size_t nEventIndicators
Definition: mbdynFMI.h:191
void GetStateDerivatives(double *)
Definition: mbdynFMI.cc:360
fmi2_real_t currTime
Definition: mbdynFMI.h:187
double GetStateFromRefValue(unsigned int i)
Definition: mbdynFMI.cc:325
static void stepFinished(fmi2_component_environment_t env, fmi2_status_t status)
Definition: mbdynFMI.cc:93
static void output(const LoadableElem *pEl, OutputHandler &OH)
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
int GetNumOfContinousStates(void)
Definition: mbdynFMI.cc:524
void SetStates(double *states)
Definition: mbdynFMI.cc:663
int GetRefValueFromString(const char *s)
Definition: mbdynFMI.cc:646
fmi2_xml_callbacks_t annotation_callbacks
Definition: mbdynFMI.cc:124
int bool
Definition: mbdyn.h:74
fmi1_real_t * eventIndicators
Definition: mbdynFMI.h:128
void GetStates(double *)
Definition: mbdynFMI.cc:368
void GetStateDerivatives(double *)
Definition: mbdynFMI.cc:651
void GetStates(double *)
Definition: mbdynFMI.cc:717
int GetNumOfEventIndicators(void)
Definition: mbdynFMI.cc:572
void CSPropogate(double tcur, double dt)
Definition: mbdynFMI.cc:462
void SetStates(double *states)
Definition: mbdynFMI.cc:299
bool SupportsDirectionalDerivatives()
Definition: mbdynFMI.cc:216
void SetRelativeTol(double dTol)
Definition: mbdynFMI.cc:289
#define NO_OP
Definition: myassert.h:74
void GetDirectionalDerivatives(FullMatrixHandler *, int *, int, double *)
Definition: mbdynFMI.cc:238
fmi1_event_info_t eventInfo
Definition: mbdynFMI.h:125
void Initialize(double dTol, double time, double rTol)
Definition: mbdynFMI.cc:533
void SetTime(double time)
Definition: mbdynFMI.cc:657
void parseXML(fmi_import_context_t *context, const char *dirPath)
Definition: mbdynFMI.cc:500
void CSPropogate(double tcur, double dt)
Definition: mbdynFMI.cc:711
fmi1_real_t * eventIndicatorsPrev
Definition: mbdynFMI.h:129
fmi1_real_t currTime
Definition: mbdynFMI.h:123
virtual ~fmu2(void)
Definition: mbdynFMI.cc:335
void InitializeAsSlave(const char *location, double tstart, double tend)
Definition: mbdynFMI.cc:733
virtual ~fmu(void)
Definition: mbdynFMI.cc:468
fmi2_event_info_t eventInfo
Definition: mbdynFMI.h:189
fmi1_boolean_t intermediateResults
Definition: mbdynFMI.h:136
fmi1_status_t fmistatus
Definition: mbdynFMI.h:120
void ImportCreateDLL(void)
Definition: mbdynFMI.cc:517
virtual void PutCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: fullmh.h:178
void SetValuesByVariable(const std::string, double)
Definition: mbdynFMI.cc:610
bool CheckInput(const std::string)
Definition: mbdynFMI.cc:598
fmi2_status_t fmistatus
Definition: mbdynFMI.h:184
void SetValuesByVariable(const std::string, double)
Definition: mbdynFMI.cc:399
int annotation_end_handle(void *context, const char *elm)
Definition: mbdynFMI.cc:118
fmi2_real_t * eventIndicators
Definition: mbdynFMI.h:192
void parseXML(fmi_import_context_t *context, const char *dirPath)
Definition: mbdynFMI.cc:131
fmi_import_context_t * context
Definition: mbdynFMI.h:73
int simType
Definition: mbdynFMI.h:72
fmi2_boolean_t callEventUpdate
Definition: mbdynFMI.h:195
void SetRelativeTol(double dTol)
Definition: mbdynFMI.cc:695
double GetStateFromRefValue(unsigned int i)
Definition: mbdynFMI.cc:672
virtual ~fmu1(void)
Definition: mbdynFMI.cc:472
size_t nEventIndicators
Definition: mbdynFMI.h:127
bool CheckInterrupts(double, double *)
Definition: mbdynFMI.cc:373
fmi2_real_t relativeTolerance
Definition: mbdynFMI.h:188
void EventIndicatorInit(void)
Definition: mbdynFMI.cc:276
bool SupportsDirectionalDerivatives()
Definition: mbdynFMI.cc:681
void setCallBackFunction()
Definition: mbdynFMI.cc:510
void ImportCreateDLL(void)
Definition: mbdynFMI.cc:150
fmi2_callback_functions_t callBackFunctions
Definition: mbdynFMI.h:181
fmi2_boolean_t terminateSimulation
Definition: mbdynFMI.h:196
fmi1_callback_functions_t callBackFunctions
Definition: mbdynFMI.h:117
void SetTime(double time)
Definition: mbdynFMI.cc:293
void setCallBackFunction()
Definition: mbdynFMI.cc:142
int GetNumOfEventIndicators(void)
Definition: mbdynFMI.cc:177
fmi2_real_t * eventIndicatorsPrev
Definition: mbdynFMI.h:193
int GetNumOfContinousStates(void)
Definition: mbdynFMI.cc:171
int annotation_start_handle(void *context, const char *parentName, void *parent, const char *elm, const char **attr)
Definition: mbdynFMI.cc:98
bool CheckInput(const std::string)
Definition: mbdynFMI.cc:310
bool CheckInterrupts(double, double *)
Definition: mbdynFMI.cc:576
int GetNumOfVar(void)
Definition: mbdynFMI.cc:689
int GetNumOfVar(void)
Definition: mbdynFMI.cc:181
int GetRefValueFromString(const char *s)
Definition: mbdynFMI.cc:319
fmi1_real_t * deriv
Definition: mbdynFMI.h:133
jm_status_enu_t jmstatus
Definition: mbdynFMI.h:121
fmi1_value_reference_t * vrs
Definition: mbdynFMI.h:134
void GetDirectionalDerivatives(FullMatrixHandler *, int *, int, double *)
Definition: mbdynFMI.cc:685
fmi1_real_t relativeTolerance
Definition: mbdynFMI.h:124
void InitializeAsSlave(const char *, double, double)
Definition: mbdynFMI.cc:436
void do_event_iteration(fmi2_import_t *fmu, fmi2_event_info_t *eventInfo)
Definition: mbdynFMI.cc:84
int annotation_data_handle(void *context, const char *s, int len)
Definition: mbdynFMI.cc:110
void Initialize(double dTol, double time, double rTol)
Definition: mbdynFMI.cc:187
fmi2_import_variable_t * v
Definition: mbdynFMI.h:194
int numOfContStates
Definition: mbdynFMI.h:132
int numOfContStates
Definition: mbdynFMI.h:198
jm_status_enu_t jmstatus
Definition: mbdynFMI.h:185