Skip to main content

ModelExchange

Trait ModelExchange 

Source
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> { ... }
}
Available on crate feature fmi3 only.
Expand description

Interface for Model Exchange instances

Required Methods§

Source

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

Source

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: if set_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().

Source

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:

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.

See: https://fmi-standard.org/docs/3.0.1/#fmi3SetTime

Source

fn set_continuous_states( &mut self, states: &[f64], ) -> Result<Fmi3Res, Fmi3Error>

Set new continuous state values.

Arguments:

Source

fn get_continuous_states( &mut self, continuous_states: &mut [f64], ) -> Result<Fmi3Res, Fmi3Error>

Return the current continuous state vector.

Arguments:

See: https://fmi-standard.org/docs/3.0.1/#fmi3GetContinuousStates

Source

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.

Source

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 for ModelExchange::set_continuous_states(). If the FMU does not have information about the nominal value of a continuous state i, a nominal value nominals[i] = 1.0 should be returned. It is required that nominals[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

Source

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

Source

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§

Source

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 computed
  • Ok(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 returning fmi3Discard)
  • Err(Fmi3Error) for other error conditions

See: https://fmi-standard.org/docs/3.0.1/#fmi3GetEventIndicators

Implementors§