fmu_discipline module¶
A discipline wrapping a Functional Mockup Unit (FMU) model.
- class gemseo_fmu.disciplines.fmu_discipline.FMUDiscipline(fmu_file_path, input_names=(), output_names=(), initial_time=None, final_time=None, time_step=0.0, add_time_to_output_grammar=True, restart=True, do_step=False, name='', use_co_simulation=True, solver_name='CVode', fmu_instance_directory='', delete_fmu_instance_directory=True, **pre_instantiation_parameters)[source]
Bases:
MDODisciplineA discipline wrapping a Functional Mockup Unit (FMU) model.
This discipline relies on FMPy.
Notes
The time series are interpolated at the time steps resulting from the union of their respective time steps. Then, between two time steps, the time series for the variables of causality “input” are linearly interpolated at the integration time steps while for the variables of causality “parameter”, the time series are considered as constant.
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
fmu_file_path (str | Path) – The path to the FMU model file.
input_names (Iterable[str] | None) –
The names of the FMU model inputs; if empty, use all the inputs and parameters of the FMU model; if
None, do not use inputs.By default it is set to ().
output_names (Iterable[str]) –
The names of the FMU model outputs. if empty, use all the outputs of the FMU model.
By default it is set to ().
initial_time (float | None) – The initial time of the simulation; if
None, use the start time defined in the FMU model if any; otherwise use 0.final_time (float | None) – The final time of the simulation; if
None, use the stop time defined in the FMU model if any; otherwise use the initial time.time_step (float) –
The time step of the simulation. If
0., it is computed by the wrapped libraryfmpy.By default it is set to 0.0.
add_time_to_output_grammar (bool) –
Whether the time is added to the output grammar.
By default it is set to True.
restart (bool) –
Whether the model is restarted at
initial_timeafter execution.By default it is set to True.
do_step (bool) –
Whether the model is simulated over only one
time_stepwhen callingexecute(). Otherwise, simulate the model frominitial_timetofinal_time.By default it is set to False.
name (str) –
The name of the discipline. If
None, use the class name.By default it is set to “”.
use_co_simulation (bool) –
Whether the co-simulation FMI type is used. Otherwise, use model-exchange FMI type. When
do_stepisTrue, the co-simulation FMI type is required.By default it is set to True.
solver_name (str) –
The name of the solver to simulate a model-exchange model.
By default it is set to “CVode”.
fmu_instance_directory (str | Path) –
The directory of the FMU instance, containing the files extracted from the FMU model file; if empty, let
fmpycreate a temporary directory.By default it is set to “”.
delete_fmu_instance_directory (bool) –
Whether to delete the directory of the FMU instance when deleting the discipline.
By default it is set to True.
**pre_instantiation_parameters (Any) – The parameters to be passed to
_pre_instantiate().
- execute(input_data=mappingproxy({}))[source]
Execute the discipline.
This method executes the discipline:
Adds the default inputs to the
input_dataif some inputs are not defined in input_data but exist inMDODiscipline.default_inputs.Checks whether the last execution of the discipline was called with identical inputs, i.e. cached in
MDODiscipline.cache; if so, directly returnsself.cache.get_output_cache(inputs).Caches the inputs.
Checks the input data against
MDODiscipline.input_grammar.If
MDODiscipline.data_processoris not None, runs the preprocessor.Updates the status to
MDODiscipline.ExecutionStatus.RUNNING.Calls the
MDODiscipline._run()method, that shall be defined.If
MDODiscipline.data_processoris not None, runs the postprocessor.Checks the output data.
Caches the outputs.
Updates the status to
MDODiscipline.ExecutionStatus.DONEorMDODiscipline.ExecutionStatus.FAILED.Updates summed execution time.
- Parameters:
input_data (Mapping[str, ndarray | TimeSeries]) –
The input data needed to execute the discipline according to the discipline input grammar. If
None, use theMDODiscipline.default_inputs.By default it is set to {}.
- Returns:
The discipline local data after execution.
- Raises:
RuntimeError – When residual_variables are declared but self.run_solves_residuals is False. This is not supported yet.
- Return type:
- set_next_execution(restart=None, simulation_time=None, time_step=None)[source]
Change the simulation settings for the next call to
execute().- Parameters:
time_step (float | None) – The time step of the simulation; if
None, use the value passed at the instantiation.restart (bool | None) – Whether to restart the model at
initial_timebefore executing it; ifNone, use the value passed at the instantiation.simulation_time (float | None) – The duration of the simulation; if
None, execute until the final time.
- Return type:
None
- cache: AbstractCache | None
The cache containing one or several executions of the discipline according to the cache policy.
- property causalities_to_variable_names: dict[str, list[str]]
The names of the variables sorted by causality.
- data_processor: DataProcessor
A tool to pre- and post-process discipline data.
- exec_for_lin: bool
Whether the last execution was due to a linearization.
- property fmu_model: fmpy.fmi1.FMU1Model | fmpy.fmi2.FMU2Model | fmpy.fmi3.FMU3Model | fmpy.fmi1.FMU1Slave | fmpy.fmi2.FMU2Slave | fmpy.fmi3.FMU3Slave
The FMU model.
- property fmu_model_description: fmpy.model_description.ModelDescription
The description of the FMU model.
- property initial_values: dict[str, numpy.ndarray[Any, numpy.dtype[float]]]
The initial input, output and time values.
- input_grammar: BaseGrammar
The input grammar.
- jac: dict[str, dict[str, ndarray]]
The Jacobians of the outputs wrt inputs.
The structure is
{output: {input: matrix}}.
- name: str
The name of the discipline.
- output_grammar: BaseGrammar
The output grammar.
- re_exec_policy: ReExecutionPolicy
The policy to re-execute the same discipline.
- residual_variables: Mapping[str, str]
The output variables mapping to their inputs, to be considered as residuals; they shall be equal to zero.
- run_solves_residuals: bool
Whether the run method shall solve the residuals.