Set FMU simulation parameters

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

First, retrieve the path to the FMU deviation.fmu. Recall the deviation model is static, i.e. its output does not evolve over time.

import otfmi.example.utility
import openturns as ot

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

The FMU simulation final time is the only simulation-related parameter that can be passed to FMUPointToFieldFunction. This parameter is useless if the FMU is really time-independent (like this example); yet it can be come in use if the FMU requires time to converge.

function = otfmi.FMUPointToFieldFunction(
    path_fmu, inputs_fmu=["E", "I"], outputs_fmu=["y"], final_time=50.0
)

inputPoint = ot.Point([2e9, 7e7])
outputPoint = function(inputPoint)
print(outputPoint[-1])
[1.11607e-06]

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

midlevel_function = otfmi.OpenTURNSFMUPointToFieldFunction(
    path_fmu, inputs_fmu=["E", "I"], outputs_fmu=["y"]
)

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

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

pyfmi_model = midlevel_function.base.get_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_module_name', '_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_unpacked_fmu_path', '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 ~otfmi.FMUPointToFieldFunction and ~otfmi.OpenTURNSFMUPointToFieldFunction are designed to highlight the most useful PyFMI’s methods and simplify their use!

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