@@ -54,32 +54,36 @@ namespace {
5454 class fmi2Logger : public fmu4cpp ::logger {
5555
5656 public:
57- explicit fmi2Logger (const std::string &instanceName, const fmi2CallbackFunctions* f)
57+ explicit fmi2Logger (const std::string &instanceName, const fmi2CallbackFunctions * f)
5858 : logger(instanceName), f_(f) {}
5959
6060 protected:
6161 void debugLog (fmiStatus s, const std::string &message) override {
6262 f_->logger (f_->componentEnvironment , instanceName_.c_str (),
63- toFmi2StatusFromCommon (s), nullptr , message.c_str ());
63+ toFmi2StatusFromCommon (s), nullptr , message.c_str ());
6464 }
6565
6666 private:
67- const fmi2CallbackFunctions* f_;
67+ const fmi2CallbackFunctions * f_;
6868 };
6969
7070 // A struct that holds all the data for one model instance.
71- struct Component {
71+ struct Fmi2Component {
7272
73- Component (std::unique_ptr<fmu4cpp::fmu_base> slave, const fmi2CallbackFunctions* callbackFunctions)
73+ Fmi2Component (std::unique_ptr<fmu4cpp::fmu_base> slave, const fmi2CallbackFunctions * callbackFunctions)
7474 : lastSuccessfulTime{std::numeric_limits<double >::quiet_NaN ()},
7575 slave (std::move(slave)),
7676 logger (std::make_unique<fmi2Logger>(this ->slave->instanceName (), callbackFunctions)) {
7777 this ->slave ->__set_logger (logger.get ());
7878 }
7979
80- double lastSuccessfulTime;
80+ double lastSuccessfulTime{ 0 } ;
8181 std::unique_ptr<fmu4cpp::fmu_base> slave;
8282 std::unique_ptr<fmu4cpp::logger> logger;
83+
84+ double start{0 };
85+ std::optional<double > stop;
86+ std::optional<double > tolerance;
8387 };
8488
8589}// namespace
@@ -141,7 +145,7 @@ fmi2Component fmi2Instantiate(fmi2String instanceName,
141145 return nullptr ;
142146 }
143147
144- auto c = std::make_unique<Component >(std::move (slave), functions);
148+ auto c = std::make_unique<Fmi2Component >(std::move (slave), functions);
145149 c->logger ->setDebugLogging (loggingOn);
146150 return c.release ();
147151}
@@ -158,24 +162,20 @@ fmi2Status fmi2SetupExperiment(fmi2Component c,
158162 if (stopTimeDefined) stop = stopTime;
159163 if (toleranceDefined) tol = tolerance;
160164
161- const auto component = static_cast <Component *>(c);
162- try {
163- component->slave ->setup_experiment (startTime, stop, tol);
164- return fmi2OK;
165- } catch (const fmu4cpp::fatal_error &ex) {
166- component->logger ->log (toCommonStatusFromFmi2 (fmi2Fatal), ex.what ());
167- return fmi2Fatal;
168- } catch (const std::exception &ex) {
169- component->logger ->log (toCommonStatusFromFmi2 (fmi2Error), ex.what ());
170- return fmi2Error;
171- }
165+ const auto component = static_cast <Fmi2Component *>(c);
166+
167+ component->start = startTime;
168+ component->stop = stop;
169+ component->tolerance = tol;
170+
171+ return fmi2OK;
172172}
173173
174174fmi2Status fmi2EnterInitializationMode (fmi2Component c) {
175- const auto component = static_cast <Component *>(c);
175+ const auto component = static_cast <Fmi2Component *>(c);
176176
177177 try {
178- component->slave ->enter_initialisation_mode ();
178+ component->slave ->enter_initialisation_mode (component-> start , component-> stop , component-> tolerance );
179179 return fmi2OK;
180180 } catch (const fmu4cpp::fatal_error &ex) {
181181 component->logger ->log (toCommonStatusFromFmi2 (fmi2Fatal), ex.what ());
@@ -187,7 +187,7 @@ fmi2Status fmi2EnterInitializationMode(fmi2Component c) {
187187}
188188
189189fmi2Status fmi2ExitInitializationMode (fmi2Component c) {
190- const auto component = static_cast <Component *>(c);
190+ const auto component = static_cast <Fmi2Component *>(c);
191191 try {
192192 component->slave ->exit_initialisation_mode ();
193193 return fmi2OK;
@@ -201,7 +201,7 @@ fmi2Status fmi2ExitInitializationMode(fmi2Component c) {
201201}
202202
203203fmi2Status fmi2Terminate (fmi2Component c) {
204- const auto component = static_cast <Component *>(c);
204+ const auto component = static_cast <Fmi2Component *>(c);
205205 try {
206206 component->slave ->terminate ();
207207 return fmi2OK;
@@ -220,9 +220,9 @@ fmi2Status fmi2DoStep(
220220 fmi2Real communicationStepSize,
221221 fmi2Boolean /* noSetFMUStatePriorToCurrentPoint*/ ) {
222222
223- const auto component = static_cast <Component *>(c);
223+ const auto component = static_cast <Fmi2Component *>(c);
224224 try {
225- if (component->slave ->do_step (currentCommunicationPoint, communicationStepSize)) {
225+ if (component->slave ->step (currentCommunicationPoint, communicationStepSize)) {
226226 component->lastSuccessfulTime = currentCommunicationPoint + communicationStepSize;
227227 return fmi2OK;
228228 }
@@ -242,7 +242,7 @@ fmi2Status fmi2CancelStep(fmi2Component) {
242242}
243243
244244fmi2Status fmi2Reset (fmi2Component c) {
245- const auto component = static_cast <Component *>(c);
245+ const auto component = static_cast <Fmi2Component *>(c);
246246 component->slave ->reset ();
247247 return fmi2OK;
248248}
@@ -253,7 +253,7 @@ fmi2Status fmi2GetInteger(
253253 size_t nvr,
254254 fmi2Integer value[]) {
255255
256- const auto component = static_cast <Component *>(c);
256+ const auto component = static_cast <Fmi2Component *>(c);
257257 try {
258258 component->slave ->get_integer (vr, nvr, value);
259259 return fmi2OK;
@@ -272,7 +272,7 @@ fmi2Status fmi2GetReal(
272272 size_t nvr,
273273 fmi2Real value[]) {
274274
275- const auto component = static_cast <Component *>(c);
275+ const auto component = static_cast <Fmi2Component *>(c);
276276 try {
277277 component->slave ->get_real (vr, nvr, value);
278278 return fmi2OK;
@@ -291,7 +291,7 @@ fmi2Status fmi2GetBoolean(
291291 size_t nvr,
292292 fmi2Boolean value[]) {
293293
294- const auto component = static_cast <Component *>(c);
294+ const auto component = static_cast <Fmi2Component *>(c);
295295 try {
296296 component->slave ->get_boolean (vr, nvr, value);
297297 return fmi2OK;
@@ -310,7 +310,7 @@ fmi2Status fmi2GetString(
310310 size_t nvr,
311311 fmi2String value[]) {
312312
313- const auto component = static_cast <Component *>(c);
313+ const auto component = static_cast <Fmi2Component *>(c);
314314 try {
315315 component->slave ->get_string (vr, nvr, value);
316316 return fmi2OK;
@@ -329,7 +329,7 @@ fmi2Status fmi2SetInteger(
329329 size_t nvr,
330330 const fmi2Integer value[]) {
331331
332- const auto component = static_cast <Component *>(c);
332+ const auto component = static_cast <Fmi2Component *>(c);
333333 try {
334334 component->slave ->set_integer (vr, nvr, value);
335335 return fmi2OK;
@@ -348,7 +348,7 @@ fmi2Status fmi2SetReal(
348348 size_t nvr,
349349 const fmi2Real value[]) {
350350
351- const auto component = static_cast <Component *>(c);
351+ const auto component = static_cast <Fmi2Component *>(c);
352352 try {
353353 component->slave ->set_real (vr, nvr, value);
354354 return fmi2OK;
@@ -367,7 +367,7 @@ fmi2Status fmi2SetBoolean(
367367 size_t nvr,
368368 const fmi2Boolean value[]) {
369369
370- const auto component = static_cast <Component *>(c);
370+ const auto component = static_cast <Fmi2Component *>(c);
371371 try {
372372 component->slave ->set_boolean (vr, nvr, value);
373373 return fmi2OK;
@@ -386,7 +386,7 @@ fmi2Status fmi2SetString(
386386 size_t nvr,
387387 const fmi2String value[]) {
388388
389- const auto component = static_cast <Component *>(c);
389+ const auto component = static_cast <Fmi2Component *>(c);
390390 try {
391391 component->slave ->set_string (vr, nvr, value);
392392 return fmi2OK;
@@ -412,7 +412,7 @@ fmi2Status fmi2GetRealStatus(
412412 const fmi2StatusKind s,
413413 fmi2Real *value) {
414414
415- const auto component = static_cast <Component *>(c);
415+ const auto component = static_cast <Fmi2Component *>(c);
416416 if (s == fmi2LastSuccessfulTime) {
417417 *value = component->lastSuccessfulTime ;
418418 return fmi2OK;
@@ -449,7 +449,7 @@ fmi2Status fmi2SetDebugLogging(fmi2Component c,
449449 size_t /* nCategories*/ ,
450450 const fmi2String /* categories*/ []) {
451451
452- const auto component = static_cast <Component *>(c);
452+ const auto component = static_cast <Fmi2Component *>(c);
453453 component->logger ->setDebugLogging (loggingOn);
454454 return fmi2OK;
455455}
@@ -480,7 +480,7 @@ fmi2Status fmi2GetDirectionalDerivative(fmi2Component,
480480
481481
482482fmi2Status fmi2GetFMUstate (fmi2Component c, fmi2FMUstate *state) {
483- const auto component = static_cast <Component *>(c);
483+ const auto component = static_cast <Fmi2Component *>(c);
484484
485485 if (auto s = component->slave ->getFMUState ()) {
486486 state = &s;
@@ -491,7 +491,7 @@ fmi2Status fmi2GetFMUstate(fmi2Component c, fmi2FMUstate *state) {
491491}
492492
493493fmi2Status fmi2SetFMUstate (fmi2Component c, fmi2FMUstate state) {
494- const auto component = static_cast <Component *>(c);
494+ const auto component = static_cast <Fmi2Component *>(c);
495495
496496 if (component->slave ->setFmuState (state)) {
497497 return fmi2OK;
@@ -502,7 +502,7 @@ fmi2Status fmi2SetFMUstate(fmi2Component c, fmi2FMUstate state) {
502502
503503
504504fmi2Status fmi2FreeFMUstate (fmi2Component c, fmi2FMUstate *state) {
505- const auto component = static_cast <Component *>(c);
505+ const auto component = static_cast <Fmi2Component *>(c);
506506
507507 if (component->slave ->freeFmuState (state)) {
508508 return fmi2OK;
@@ -527,7 +527,7 @@ fmi2Status fmi2DeSerializeFMUstate(fmi2Component, const fmi2Byte[], size_t, fmi2
527527}
528528
529529void fmi2FreeInstance (fmi2Component c) {
530- const auto component = static_cast <Component *>(c);
530+ const auto component = static_cast <Fmi2Component *>(c);
531531 delete component;
532532}
533533}
0 commit comments