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_path
str
File path to the TWIN file for the twin model.
- log_path
str
(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_path
str
(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_level
LogLevel
(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.
- model_path
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.
Returns the appropriate error message depending on prop_status when executing the function method_name with the variable var.
Returns the current status message associated to the TWIN if its status is TWIN_STATUS_WARNING.
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.
Set the default simulation settings (end time, step size, tolerance) stored within the model.
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.
Closes the TWIN model.
Disables the generation of 3D data (mode coefficients and optionally snapshots files) for the given model name in the next time steps.
Disables the ROM image generation for the given model name and views in the next time steps.
Enables the generation of 3D data (mode coefficients and optionally snapshots files) for the given model name in the next time steps.
Enables the ROM image generation for the given model name and views in the next time steps (until disabled).
Returns the version of the Twin Runtime SDK being used.
Retrieves the default directory in the local filesystem where ROM images will be saved for the TBROM model name.
Retrieves the default simulation settings (end time, step size and tolerance) associated with the TWIN.
Retrieves the names of inputs of the TWIN model.
Returns the list of associated dependencies to the TWIN model and the corresponding binaries found on the current environment where the TWIN is loaded.
Retrieves the name of the TWIN model.
Retrieves the number of inputs of the TWIN model.
Retrieves the number of outputs of the TWIN model.
Retrieves the number of parameters of the TWIN model.
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.
Retrieves the names of outputs of the TWIN model.
Retrieves the current value of all the TWIN outputs.
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.
Retrieves the model mode coefficients files from 'time_from' up to 'time_to' for the given TBROM model name.
Retrieves the absolute path of the resource directory for the given TBROM model name.
Retrieves the model snapshots files from 'time_from' up to 'time_to' for the given TBROM model name.
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.
Retrieves a JSON-like data structure in string format with the information about model visualization resources available in the TWIN model.
Initializes the TWIN model.
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.
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.
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.
Set the current value of a single TWIN parameter specified by name.
Set the directory in the local filesystem where ROM images will be saved for the TBROM model 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.
Simulates the TWIN model in batch mode using given input CSV file and write the results in the output CSV file.