TwinRuntime#

class pytwin.TwinRuntime(model_path, log_path=None, twin_runtime_library_path=None, log_level=LogLevel.TWIN_LOG_WARNING, load_model=True)#

Instantiate a TwinRuntime wrapper object based on a TWIN file created by Ansys Twin Builder.

After a TwinRuntime object is instantiated, it can be used to call different APIs to manipulate and process the TWIN Runtime execution (e.g. initialization, setting up inputs, evaluating a time step, getting the outputs,…).

Parameters:
model_pathstr

File path to the TWIN file for the twin model.

log_pathstr (optional)

File path to the log file associated to the TwinRuntime. By default, the log is written at the same location as the TWIN file.

twin_runtime_library_pathstr (optional)

File path to the TWIN Runtime library. By default, it is located in a subfolder of the current working directory based on the OS (TwinRuntimeSDK.dll or libTwinRuntimeSDK.so).

log_levelLogLevel (optional)

Level option associated to the TWIN Runtime logging. By default, it is set to LogLevel.TWIN_LOG_WARNING.

load_modelbool (optinal)

Whether the TWIN model is loaded (True) or not (False) during the TwinRuntime object instantiation. Default value is True.

Examples

Create the TwinRuntime given the file path to the TWIN file. Print the general information related to the TWIN model, then instantiate the model, initialize it, evaluate for a step and close the TwinRuntime.

>>> from twin_runtime.twin_runtime_core import TwinRuntime
>>> twin_file = "model.twin"
>>> twin_runtime = TwinRuntime(twin_file)
>>> twin_runtime.twin_instantiate()
>>> twin_runtime.twin_initialize()
>>> twin_runtime.twin_simulate(0.001)
>>> twin_runtime.twin_close()

Methods

TwinRuntime.build_prop_info_df(var_names)

Evaluate the properties (name, unit, quantity type, start value, minimum value, maximum values, description) of the given variables.

TwinRuntime.evaluate_twin_prop_status(...)

Returns the appropriate error message depending on prop_status when executing the function method_name with the variable var.

TwinRuntime.evaluate_twin_status(...)

Returns the current status message associated to the TWIN if its status is TWIN_STATUS_WARNING.

TwinRuntime.full_model_properties_info_df()

Evaluate the properties (name, unit, quantity type, start value, minimum value, maximum values, description) of all the model's variables (inputs, outputs, parameters).

TwinRuntime.get_model_fmi_type(file_path)

Searches the description file of the source model to discover if it is a Model Exchange or Co Simulation type of model.

TwinRuntime.get_twin_version(file_path)

Returns whether the loaded TWIN model is a valid model or not, as well as the Twin Builder version used to compile it.

TwinRuntime.load_dll([twin_runtime_library_path])

Load the TwinRuntime library.

TwinRuntime.load_twin_default_sim_settings()

Set the default simulation settings (end time, step size, tolerance) stored within the model.

TwinRuntime.model_properties_info_df(...)

Evaluate the properties (name, unit, quantity type, start value, minimum value, maximum values, description) of the given variables, with a maximum number of variables to consider.

TwinRuntime.print_model_info([max_var_to_print])

Print all the model information including Twin Runtime version, model name, number of outputs, inputs, parameters, default simulation settings, output names, input names and parameter names.

TwinRuntime.print_var_info(var_names, ...)

Print all the properties (name, unit, quantity type, start value, minimum value, maximum values, description) of the given variables, with a maximum number of variables to consider.

TwinRuntime.twin_close()

Closes the TWIN model.

TwinRuntime.twin_disable_3d_rom_model_data(...)

Disables the generation of 3D data (mode coefficients and optionally snapshots files) for the given model name in the next time steps.

TwinRuntime.twin_disable_rom_model_images(...)

Disables the ROM image generation for the given model name and views in the next time steps.

TwinRuntime.twin_enable_3d_rom_model_data(...)

Enables the generation of 3D data (mode coefficients and optionally snapshots files) for the given model name in the next time steps.

TwinRuntime.twin_enable_rom_model_images(...)

Enables the ROM image generation for the given model name and views in the next time steps (until disabled).

TwinRuntime.twin_get_api_version()

Returns the version of the Twin Runtime SDK being used.

TwinRuntime.twin_get_default_rom_image_directory(...)

Retrieves the default directory in the local filesystem where ROM images will be saved for the TBROM model name.

TwinRuntime.twin_get_default_simulation_settings()

Retrieves the default simulation settings (end time, step size and tolerance) associated with the TWIN.

TwinRuntime.twin_get_input_names()

Retrieves the names of inputs of the TWIN model.

TwinRuntime.twin_get_model_dependencies(...)

Returns the list of associated dependencies to the TWIN model and the corresponding binaries found on the current environment where the TWIN is loaded.

TwinRuntime.twin_get_model_name()

Retrieves the name of the TWIN model.

TwinRuntime.twin_get_number_inputs()

Retrieves the number of inputs of the TWIN model.

TwinRuntime.twin_get_number_outputs()

Retrieves the number of outputs of the TWIN model.

TwinRuntime.twin_get_number_params()

Retrieves the number of parameters of the TWIN model.

TwinRuntime.twin_get_output_by_index(index)

Retrieves the current value of a single TWIN output specified by index.

TwinRuntime.twin_get_output_by_name(output_name)

Retrieves the current value of a single TWIN output specified by name.

TwinRuntime.twin_get_output_names()

Retrieves the names of outputs of the TWIN model.

TwinRuntime.twin_get_outputs()

Retrieves the current value of all the TWIN outputs.

TwinRuntime.twin_get_param_names()

Retrieves the names of parameters of the TWIN model.

TwinRuntime.twin_get_rom_images_files(...[, ...])

Retrieves the model images from 'time_from' up to 'time_to' for the given views from the given TBROM model name.

TwinRuntime.twin_get_rom_mode_coef_files(...)

Retrieves the model mode coefficients files from 'time_from' up to 'time_to' for the given TBROM model name.

TwinRuntime.twin_get_rom_resource_directory(...)

Retrieves the absolute path of the resource directory for the given TBROM model name.

TwinRuntime.twin_get_rom_snapshot_files(...)

Retrieves the model snapshots files from 'time_from' up to 'time_to' for the given TBROM model name.

TwinRuntime.twin_get_status_string()

Retrieves the status of the last operation if the result is not TWIN_STATUS_OK.

TwinRuntime.twin_get_str_var_start(var_name)

Retrieves the start value of a given variable by name.

TwinRuntime.twin_get_var_data_type(var_name)

Retrieves the data type of a given variable ("Real", "Integer", "Boolean", or "Enumeration") by name.

TwinRuntime.twin_get_var_description(var_name)

Retrieves the description string for a given variable by name.

TwinRuntime.twin_get_var_max(var_name)

Retrieves the maximum value of a given variable by name.

TwinRuntime.twin_get_var_min(var_name)

Retrieves the minimum value of a given variable by name.

TwinRuntime.twin_get_var_nominal(var_name)

Retrieves the nominal value of a given variable by name.

TwinRuntime.twin_get_var_quantity_type(var_name)

Retrieves the physical quantity type such as pressure, temperature, etc.

TwinRuntime.twin_get_var_start(var_name)

Retrieves the start value of a given variable by name.

TwinRuntime.twin_get_var_unit(var_name)

Retrieves the unit string of a given variable by name.

TwinRuntime.twin_get_visualization_resources()

Retrieves a JSON-like data structure in string format with the information about model visualization resources available in the TWIN model.

TwinRuntime.twin_initialize()

Initializes the TWIN model.

TwinRuntime.twin_instantiate()

Instantiates the TWIN model.

TwinRuntime.twin_is_cross_platform(file_path)

Returns whether the loaded TWIN model is cross-platform (Windows and Linux) compiled or not.

TwinRuntime.twin_load(log_level)

Opens and loads the TWIN model, with a given log level for the log file.

TwinRuntime.twin_load_state(load_from[, ...])

Load and set the TWIN states with the ones stored in the file 'load_from' (including model values used in the TWIN when saving the states).

TwinRuntime.twin_number_of_deployments(file_path)

Returns the expected number of deployments for the given TWIN model as defined at the export time.

TwinRuntime.twin_platform_support(file_path)

Determines whether the TWIN model has Windows and/or Linux binaries.

TwinRuntime.twin_reset()

Resets the state of the TWIN model back to the instantiated state.

TwinRuntime.twin_save_state(save_to)

Save the TWIN states (including model parameters) in the file 'save_to'.

TwinRuntime.twin_set_input_by_index(index, value)

Set the current value of a single TWIN input specified by index.

TwinRuntime.twin_set_input_by_name(...)

Set the current value of a single TWIN input specified by name.

TwinRuntime.twin_set_inputs(input_array)

Set the current value of all the TWIN inputs.

TwinRuntime.twin_set_param_by_index(index, value)

Set the current value of a single TWIN parameter specified by index.

TwinRuntime.twin_set_param_by_name(...)

Set the current value of a single TWIN parameter specified by name.

TwinRuntime.twin_set_rom_image_directory(...)

Set the directory in the local filesystem where ROM images will be saved for the TBROM model name.

TwinRuntime.twin_set_str_param_by_name(...)

Set the current value of a single TWIN string parameter specified by name.

TwinRuntime.twin_simulate(time_stop[, time_step])

Simulates the TWIN model from previous time point to the stop point given by time_stop.

TwinRuntime.twin_simulate_batch_mode(...[, ...])

Simulates the TWIN model in batch mode using given input dataframe and returns the results in an output dataframe using output column names.

TwinRuntime.twin_simulate_batch_mode_csv(...)

Simulates the TWIN model in batch mode using given input CSV file and write the results in the output CSV file.