ModelExchange

Trait ModelExchange 

Source
pub trait ModelExchange: Common {
    // Required methods
    fn enter_event_mode(&mut self) -> Result<Fmi2Res, Fmi2Error>;
    fn new_discrete_states(
        &mut self,
        discrete_states_need_update: &mut bool,
        terminate_simulation: &mut bool,
        nominals_of_continuous_states_changed: &mut bool,
        values_of_continuous_states_changed: &mut bool,
        next_event_time: &mut Option<f64>,
    ) -> Result<Fmi2Res, Fmi2Error>;
    fn enter_continuous_time_mode(&mut self) -> Result<Fmi2Res, Fmi2Error>;
    fn completed_integrator_step(
        &mut self,
        no_set_fmu_state_prior_to_current_point: bool,
        enter_event_mode: &mut bool,
        terminate_simulation: &mut bool,
    ) -> Result<Fmi2Res, Fmi2Error>;
    fn set_time(&mut self, time: f64) -> Result<Fmi2Res, Fmi2Error>;
    fn set_continuous_states(
        &mut self,
        states: &[f64],
    ) -> Result<Fmi2Res, Fmi2Error>;
    fn get_derivatives(&mut self, dx: &mut [f64]) -> Result<Fmi2Res, Fmi2Error>;
    fn get_event_indicators(
        &mut self,
        events: &mut [f64],
    ) -> Result<bool, Fmi2Error>;
    fn get_continuous_states(
        &mut self,
        x: &mut [f64],
    ) -> Result<Fmi2Res, Fmi2Error>;
    fn get_nominals_of_continuous_states(
        &mut self,
        nominals: &mut [f64],
    ) -> Result<Fmi2Res, Fmi2Error>;
}

Required Methods§

Source

fn enter_event_mode(&mut self) -> Result<Fmi2Res, Fmi2Error>

The model enters Event Mode from the Continuous-Time Mode and discrete-time equations may become active (and relations are not “frozen”).

Source

fn new_discrete_states( &mut self, discrete_states_need_update: &mut bool, terminate_simulation: &mut bool, nominals_of_continuous_states_changed: &mut bool, values_of_continuous_states_changed: &mut bool, next_event_time: &mut Option<f64>, ) -> Result<Fmi2Res, Fmi2Error>

The FMU is in Event Mode and the super dense time is incremented by this call. If the super dense time before a call to ModelExchange::new_discrete_states was (tR,tI) then the time instant after the call is (tR,tI + 1).

If returned new_discrete_states_needed = true, the FMU should stay in Event Mode and the FMU requires to set new inputs to the FMU (set_XXX on inputs), to compute and get the outputs (get_XXX on outputs) and to call new_discrete_states() again.

Depending on the connection with other FMUs, the environment shall

Source

fn enter_continuous_time_mode(&mut self) -> Result<Fmi2Res, Fmi2Error>

The model enters Continuous-Time Mode and all discrete-time equations become inactive and all relations are “frozen”.

This function has to be called when changing from Event Mode (after the global event iteration in Event Mode over all involved FMUs and other models has converged) into Continuous-Time Mode.

Source

fn completed_integrator_step( &mut self, no_set_fmu_state_prior_to_current_point: bool, enter_event_mode: &mut bool, terminate_simulation: &mut bool, ) -> Result<Fmi2Res, Fmi2Error>

Complete integrator step and return enterEventMode.

This function must be called by the environment after every completed step of the integrator provided the capability flag completedIntegratorStepNotNeeded = false. Argument no_set_fmu_state_prior_to_current_point is true if set_fmu_state will no longer be called for time instants prior to current time in this simulation run [the FMU can use this flag to flush a result buffer].

The returned tuple are the flags (enter_event_mode, terminate_simulation)

Source

fn set_time(&mut self, time: f64) -> Result<Fmi2Res, Fmi2Error>

Set a new time instant and re-initialize caching of variables that depend on time, provided the newly provided time value is different to the previously set time value (variables that depend solely on constants or parameters need not to be newly computed in the sequel, but the previously computed values can be reused).

Source

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

Set a new (continuous) state vector and re-initialize caching of variables that depend on the states. Argument nx is the length of vector x and is provided for checking purposes (variables that depend solely on constants, parameters, time, and inputs do not need to be newly computed in the sequel, but the previously computed values can be reused). Note, the continuous states might also be changed in Event Mode. Note: fmi2Status = fmi2Discard is possible.

Source

fn get_derivatives(&mut self, dx: &mut [f64]) -> Result<Fmi2Res, Fmi2Error>

Compute state derivatives and event indicators at the current time instant and for the current states. The derivatives are returned as a vector with “nx” elements.

Source

fn get_event_indicators( &mut self, events: &mut [f64], ) -> Result<bool, Fmi2Error>

A state event is triggered when the domain of an event indicator changes from zj > 0 to zj ≤ 0 or vice versa. The FMU must guarantee that at an event restart zj ≠ 0, for example by shifting zj with a small value. Furthermore, zj should be scaled in the FMU with its nominal value (so all elements of the returned vector “eventIndicators” should be in the order of “one”). The event indicators are returned as a vector with “ni” elements.

Source

fn get_continuous_states(&mut self, x: &mut [f64]) -> Result<Fmi2Res, Fmi2Error>

Return the new (continuous) state vector x. This function has to be called directly after calling function enter_continuous_time_mode if it returns with eventInfo->valuesOfContinuousStatesChanged = true (indicating that the (continuous-time) state vector has changed).

Source

fn get_nominals_of_continuous_states( &mut self, nominals: &mut [f64], ) -> Result<Fmi2Res, Fmi2Error>

Return the nominal values of the continuous states. This function should always be called after calling function new_discrete_states if it returns with eventInfo->nominals_of_continuous_states = true since then the nominal values of the continuous states have changed [e.g. because the association of the continuous states to variables has changed due to internal dynamic state selection].

If the FMU does not have information about the nominal value of a continuous state i, a nominal value x_nominal[i] = 1.0 should be returned.

Note, it is required that x_nominal[i] > 0.0 (Typically, the nominal values of the continuous states are used to compute the absolute tolerance required by the integrator. Example: absoluteTolerance[i] = 0.01*tolerance*x_nominal[i];)

Implementors§