pub trait ModelExchange: Common {
// Required methods
fn enter_continuous_time_mode(&mut self) -> Result<Fmi3Res, Fmi3Error>;
fn completed_integrator_step(
&mut self,
no_set_fmu_state_prior: bool,
enter_event_mode: &mut bool,
terminate_simulation: &mut bool,
) -> Result<Fmi3Res, Fmi3Error>;
fn set_time(&mut self, time: f64) -> Result<Fmi3Res, Fmi3Error>;
fn set_continuous_states(
&mut self,
states: &[f64],
) -> Result<Fmi3Res, Fmi3Error>;
fn get_continuous_states(
&mut self,
continuous_states: &mut [f64],
) -> Result<Fmi3Res, Fmi3Error>;
fn get_continuous_state_derivatives(
&mut self,
states: &mut [f64],
) -> Result<Fmi3Res, Fmi3Error>;
fn get_nominals_of_continuous_states(
&mut self,
nominals: &mut [f64],
) -> Result<Fmi3Res, Fmi3Error>;
fn get_number_of_event_indicators(&mut self) -> Result<usize, Fmi3Error>;
fn get_number_of_continuous_states(&mut self) -> Result<usize, Fmi3Error>;
// Provided method
fn get_event_indicators(
&mut self,
_event_indicators: &mut [f64],
) -> Result<bool, Fmi3Error> { ... }
}fmi3 only.Expand description
Interface for Model Exchange instances
Required Methods§
Sourcefn enter_continuous_time_mode(&mut self) -> Result<Fmi3Res, Fmi3Error>
fn enter_continuous_time_mode(&mut self) -> Result<Fmi3Res, Fmi3Error>
This function must be called to change from Event Mode into Continuous-Time Mode in Model Exchange.
See https://fmi-standard.org/docs/3.0.1/#fmi3EnterContinuousTimeMode
Sourcefn completed_integrator_step(
&mut self,
no_set_fmu_state_prior: bool,
enter_event_mode: &mut bool,
terminate_simulation: &mut bool,
) -> Result<Fmi3Res, Fmi3Error>
fn completed_integrator_step( &mut self, no_set_fmu_state_prior: bool, enter_event_mode: &mut bool, terminate_simulation: &mut bool, ) -> Result<Fmi3Res, Fmi3Error>
This function is called after every completed step of the integrator provided the capability
flag crate::fmi3::schema::Fmi3ModelExchange::needs_completed_integrator_step =
true.
The importer must have set valid values for time, continuous inputs and continuous states prior to calling this function to evaluate 𝐟comp with valid right-hand side data.
Arguments:
no_set_fmu_state_prior: ifset_fmu_state()will no longer be called for time instants prior to current time in this simulation run.
enter_event_mode signals that the importer must call Common::enter_event_mode() to handle a step event.
When terminate_simulation = true, the FMU requests to stop the simulation and the
importer must call Common::terminate().
Sourcefn set_time(&mut self, time: f64) -> Result<Fmi3Res, Fmi3Error>
fn set_time(&mut self, time: f64) -> Result<Fmi3Res, Fmi3Error>
Set a new value for the independent variable (typically a time instant).
Argument time is the new value for the real part 𝑡𝑅 of 𝑡:=(𝑡𝑅,0). It refers to the unit of
the independent variable. time must be larger or equal to:
start_time,- the time at the second last call to
ModelExchange::completed_integrator_step, - the time at the last call to
Common::enter_event_mode.
This allows limited simulation backward in time. As soon as an event occurs
(Common::enter_event_mode was called), going back in time is impossible, because
Common::enter_event_mode / Common::update_discrete_states can only compute the next
discrete state, not the previous one.
Sourcefn set_continuous_states(
&mut self,
states: &[f64],
) -> Result<Fmi3Res, Fmi3Error>
fn set_continuous_states( &mut self, states: &[f64], ) -> Result<Fmi3Res, Fmi3Error>
Set new continuous state values.
Arguments:
states: the new values for each continuous state. The order of the continuousStates vector must be the same as the ordered list of elements incrate::fmi3::schema::ModelStructure::continuous_state_derivatives.
Sourcefn get_continuous_states(
&mut self,
continuous_states: &mut [f64],
) -> Result<Fmi3Res, Fmi3Error>
fn get_continuous_states( &mut self, continuous_states: &mut [f64], ) -> Result<Fmi3Res, Fmi3Error>
Return the current continuous state vector.
Arguments:
continuous_states: returns the values for each continuous state with the same convention for the order as defined forModelExchange::set_continuous_states().
See: https://fmi-standard.org/docs/3.0.1/#fmi3GetContinuousStates
Sourcefn get_continuous_state_derivatives(
&mut self,
states: &mut [f64],
) -> Result<Fmi3Res, Fmi3Error>
fn get_continuous_state_derivatives( &mut self, states: &mut [f64], ) -> Result<Fmi3Res, Fmi3Error>
Fetch the first-order derivatives with respect to the independent variable (usually time) of the continuous states.
Returns:
crate::fmi3::Fmi3Error::Discard if the FMU was not able to compute the derivatives
according to 𝐟cont because, for example, a numerical issue, such as division by zero,
occurred.
Sourcefn get_nominals_of_continuous_states(
&mut self,
nominals: &mut [f64],
) -> Result<Fmi3Res, Fmi3Error>
fn get_nominals_of_continuous_states( &mut self, nominals: &mut [f64], ) -> Result<Fmi3Res, Fmi3Error>
Return the nominal values of the continuous states.
Returns:
nominals: returns the nominal values for each continuous state with the same convention for the order as defined forModelExchange::set_continuous_states(). If the FMU does not have information about the nominal value of a continuous state i, a nominal valuenominals[i] = 1.0should be returned. It is required thatnominals[i] > 0.0.
This function should always be called after calling function
Common::update_discrete_states(), if nominals_of_continuous_states_changed = true, since then the nominal values of the continuous states have changed (for example,
because the mapping of the continuous states to variables has changed because of internal
dynamic state selection).
See: https://fmi-standard.org/docs/3.0.1/#fmi3GetNominalsOfContinuousStates
Sourcefn get_number_of_event_indicators(&mut self) -> Result<usize, Fmi3Error>
fn get_number_of_event_indicators(&mut self) -> Result<usize, Fmi3Error>
This function returns the number of event indicators.
See: https://fmi-standard.org/docs/3.0/#fmi3GetNumberOfEventIndicators
Sourcefn get_number_of_continuous_states(&mut self) -> Result<usize, Fmi3Error>
fn get_number_of_continuous_states(&mut self) -> Result<usize, Fmi3Error>
This function returns the number of continuous states.
See: https://fmi-standard.org/docs/3.0/#fmi3GetNumberOfContinuousStates
Provided Methods§
Sourcefn get_event_indicators(
&mut self,
_event_indicators: &mut [f64],
) -> Result<bool, Fmi3Error>
fn get_event_indicators( &mut self, _event_indicators: &mut [f64], ) -> Result<bool, Fmi3Error>
Returns the event indicators signaling state events by their sign changes.
Arguments:
event_indicators: returns the values for the event indicators in the order defined by the ordered list of XML elements<EventIndicator>.
Returns:
Ok(true)if the event indicators were successfully computedOk(false)if the FMU was not able to compute the event indicators according to 𝐟cont because, for example, a numerical issue such as division by zero occurred (corresponding to the C API returningfmi3Discard)Err(Fmi3Error)for other error conditions
See: https://fmi-standard.org/docs/3.0.1/#fmi3GetEventIndicators