Skip to content

Commit

Permalink
Simplify state saving in slave_simulator
Browse files Browse the repository at this point in the history
By simply not allowing state saving when modifiers are active (which is
sketchy anyway), the implementation becomes much simpler.
  • Loading branch information
kyllingstad committed Jun 27, 2024
1 parent 7d363f4 commit b1bb170
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 97 deletions.
4 changes: 0 additions & 4 deletions include/cosim/algorithm/simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ class simulator : public manipulable
* `state_index`. The index is only valid for this particular simulator.
*
* The function may be called at any point after `setup()` has been called.
*
* \pre `this->model_description().can_save_state`
*/
virtual state_index save_state() = 0;

Expand All @@ -157,8 +155,6 @@ class simulator : public manipulable
* This function does the same as `save_state()`, except that it
* overwrites a state which has previously been stored by that function.
* The old index thereafter refers to the newly-saved state.
*
* \pre `this->model_description().can_save_state`
*/
virtual void save_state(state_index stateIndex) = 0;

Expand Down
3 changes: 0 additions & 3 deletions include/cosim/model_description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,6 @@ struct model_description

/// Variable descriptions.
std::vector<variable_description> variables;

/// Whether saving of state is supported.
bool can_save_state = false;
};

/// Getter for returning a variable description.
Expand Down
8 changes: 4 additions & 4 deletions src/cosim/fmi/v1/fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,31 +553,31 @@ slave::state_index slave_instance::save_state()
{
throw error(
make_error_code(errc::unsupported_feature),
"Getting and setting state not supported");
"Getting and setting state not supported in FMI 1.0");
}


void slave_instance::save_state(state_index)
{
throw error(
make_error_code(errc::unsupported_feature),
"Getting and setting state not supported");
"Getting and setting state not supported in FMI 1.0");
}


void slave_instance::restore_state(state_index)
{
throw error(
make_error_code(errc::unsupported_feature),
"Getting and setting state not supported");
"Getting and setting state not supported in FMI 1.0");
}


void slave_instance::release_state(state_index)
{
throw error(
make_error_code(errc::unsupported_feature),
"Getting and setting state not supported");
"Getting and setting state not supported in FMI 1.0");
}


Expand Down
7 changes: 5 additions & 2 deletions src/cosim/fmi/v2/fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ fmu::fmu(
<< vd.name << " will be ignored";
}
}
modelDescription_.can_save_state =
fmi2_import_get_capability(handle_, fmi2_cs_canGetAndSetFMUstate) != 0;
}


Expand Down Expand Up @@ -634,6 +632,11 @@ fmi2_import_t* slave_instance::fmilib_handle() const

void slave_instance::copy_current_state(saved_state& state)
{
if (!fmi2_import_get_capability(handle_, fmi2_cs_canGetAndSetFMUstate)) {
throw error(
make_error_code(errc::unsupported_feature),
instanceName_ + ": FMU does not support state saving");
}
const auto status = fmi2_import_get_fmu_state(handle_, &state.fmuState);
if (status != fmi2_status_ok && status != fmi2_status_warning) {
throw error(
Expand Down
Loading

0 comments on commit b1bb170

Please sign in to comment.