Set FMU simulation parameters

FMUPointToFieldFunction is an OpenTURNS-friendly overlay of the class ÒpenTURNSFMUPointToFieldFunction, closer to the underlying PyFMI implementation. Some FMU simulation parameters can be given to FMUPointToFieldFunction, yet most of them can only be passed to an OpenTURNSFMUPointToFieldFunction.


First, retrieve the path to epid.fmu. Recall the deviation model is dynamic, i.e. its output evolves over time.

import otfmi.example.utility
import openturns as ot

path_fmu = otfmi.example.utility.get_path_fmu("epid")

The FMU simulation start and final times are the only simulation-related parameter that can be passed to FMUPointToFieldFunction.

mesh = ot.RegularGrid(0.0, 0.1, 20)

function = otfmi.FMUPointToFieldFunction(
    mesh,
    path_fmu,
    inputs_fmu=["infection_rate", "healing_rate"],
    outputs_fmu=["infected"],
    start_time=0.0,
    final_time=2.0,
)

inputPoint = ot.Point([0.007, 0.02])
outputSample = function(inputPoint)
print(outputSample)
     [ infected  ]
 0 : [   1       ]
 1 : [   1.62    ]
 2 : [   2.62296 ]
 3 : [   4.24314 ]
 4 : [   6.85437 ]
 5 : [  11.0473  ]
 6 : [  17.7402  ]
 7 : [  28.3228  ]
 8 : [  44.8078  ]
 9 : [  69.8978  ]
10 : [ 106.764   ]
11 : [ 158.219   ]
12 : [ 225.087   ]
13 : [ 304.319   ]
14 : [ 388.471   ]
15 : [ 467.984   ]
16 : [ 535.124   ]
17 : [ 586.539   ]
18 : [ 622.934   ]
19 : [ 647.176   ]

To set more parameters for the FMU simulation, OpenTURNSFMUPointToFieldFunction can be employed. Below, we set the PyFMI algorithm running the simulation, and require simulation silent mode.

midlevel_function = otfmi.OpenTURNSFMUPointToFieldFunction(
    mesh,
    path_fmu,
    inputs_fmu=["infection_rate", "healing_rate"],
    outputs_fmu=["infected"],
    start_time=0.0,
    final_time=2.0,
)

outputPoint = midlevel_function.simulate(
    inputPoint, algorithm="FMICSAlg", options={"silent_mode": True}
)

For advanced users, the middle-level class OpenTURNSFMUFunction also gives access to the PyFMI model. We can hence access all PyFMI’s object methods:

pyfmi_model = midlevel_function.model
print(dir(pyfmi_model))
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__pyx_vtable__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '_additional_logger', '_close_log_file', '_convert_filter', '_current_log_size', '_default_options', '_enable_logging', '_exec_algorithm', '_exec_estimate_algorithm', '_exec_simulate_algorithm', '_get', '_get_A', '_get_B', '_get_C', '_get_D', '_get_directional_proxy', '_get_time', '_group_A', '_group_B', '_group_C', '_group_D', '_has_entered_init_mode', '_invoked_dealloc', '_last_accepted_time', '_log_handler', '_log_is_stream', '_log_open', '_log_stream', '_log_stream_is_open', '_max_log_size', '_max_log_size_msg_sent', '_open_log_file', '_provides_directional_derivatives', '_pyEventInfo', '_relative_tolerance', '_result_file', '_save_bool_variables_val', '_save_int_variables_val', '_save_real_variables_val', '_set', '_set_log_stream', '_set_time', '_supports_get_set_FMU_state', 'append_log_message', 'cache', 'cancel_step', 'deserialize_fmu_state', 'do_step', 'enter_initialization_mode', 'estimate', 'estimate_options', 'exit_initialization_mode', 'extract_xml_log', 'file_object', 'free_fmu_state', 'free_instance', 'get', 'get_author', 'get_boolean', 'get_boolean_status', 'get_capability_flags', 'get_categories', 'get_copyright', 'get_default_experiment_start_time', 'get_default_experiment_step', 'get_default_experiment_stop_time', 'get_default_experiment_tolerance', 'get_derivatives_dependencies', 'get_derivatives_dependencies_kind', 'get_derivatives_list', 'get_description', 'get_directional_derivative', 'get_fmil_log_level', 'get_fmu_state', 'get_generation_date_and_time', 'get_generation_tool', 'get_guid', 'get_identifier', 'get_input_list', 'get_integer', 'get_integer_status', 'get_last_result_file', 'get_license', 'get_log', 'get_log_filename', 'get_log_level', 'get_max_log_size', 'get_model_time_varying_value_references', 'get_model_types_platform', 'get_model_variables', 'get_model_version', 'get_name', 'get_number_of_lines_log', 'get_ode_sizes', 'get_output_dependencies', 'get_output_dependencies_kind', 'get_output_derivatives', 'get_output_list', 'get_real', 'get_real_status', 'get_scalar_variable', 'get_state_space_representation', 'get_states_list', 'get_status', 'get_string', 'get_string_status', 'get_variable_alias', 'get_variable_alias_base', 'get_variable_by_valueref', 'get_variable_causality', 'get_variable_data_type', 'get_variable_declared_type', 'get_variable_description', 'get_variable_display_unit', 'get_variable_display_value', 'get_variable_initial', 'get_variable_max', 'get_variable_min', 'get_variable_naming_convention', 'get_variable_nominal', 'get_variable_references', 'get_variable_relative_quantity', 'get_variable_start', 'get_variable_unbounded', 'get_variable_unit', 'get_variable_valueref', 'get_variable_variability', 'get_version', 'has_reached_max_log_size', 'initialize', 'instantiate', 'print_log', 'reset', 'serialize_fmu_state', 'serialized_fmu_state_size', 'set', 'set_additional_logger', 'set_boolean', 'set_debug_logging', 'set_fmu_state', 'set_input_derivatives', 'set_integer', 'set_log_level', 'set_max_log_size', 'set_real', 'set_string', 'setup_experiment', 'simulate', 'simulate_options', 'terminate', 'time']

Note

Otfmi’ classes FMUPointToFieldFunction and OpenTURNSFMUPointToFieldFunction are designed to highlight the most useful PyFMI’s methods and simplify their use!

Total running time of the script: (0 minutes 0.063 seconds)