Source code for output_cases.thermal_output_case.api.thermal_output_case_api

import typing

from more.api.exceptions.api_exception import NameNotUniqueError
from more.api.simulation.output_cases.output_case_setup import OutputCaseSetupPipeline
from more.api.simulation.output_cases.output_setup import OutputSetup
from more.api.utils.change_duplicate_name import change_duplicate_name

from more.api.utils.interface_registries import register_api_implementation
from more.output_cases.thermal_output_case import ThermalOutputCase
from more.output_cases.utils.data_table_dependent_outputs_handler.api.data_table_dependent_outputs_handler_api import DataTableDependentOutputsHandlerAPI
from more.output_cases.utils.data_table_dependent_outputs_handler.api.data_table_dependent_outputs_handler_api_mixin import \
    DataTableDependentOutputsHandlerApiMixin
from more.log import get_logger
logger = get_logger(__name__)




def _thermal_output_case_api_setup(api) -> 'ThermalOutputCaseSetup':
    simulation_setup = api.create_simulation_setup()
    output_case_container_setup = simulation_setup.create_output_case_container_setup()
    return output_case_container_setup.create_output_case_setup(oc_type='Thermal output case')


[docs] @register_api_implementation(core_class=ThermalOutputCase) class ThermalOutputCaseSetup(OutputCaseSetupPipeline, DataTableDependentOutputsHandlerApiMixin): """ The API handler for thermal output cases The following example shows how to create a thermal output case using the API, it is assumed that these steps were performed in each of the examples for other methods in this class. .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> occ_setup = simulation_setup.create_output_case_container_setup().set_name(name='Example OCC') >>> output_case_setup = occ_setup.create_output_case_setup(oc_type='Thermal output case').set_name(name='Example OC') .. >>> isinstance(output_case_setup, ThermalOutputCaseSetup) True >>> isinstance(output_case_setup._output_case, ThermalOutputCase) True The next example shows how to get an API object for an already existing output case. .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> simulation_setup = api.create_simulation_setup() >>> occ_setup = simulation_setup.create_output_case_container_setup().set_name(name='Example OCC') .. >>> _output_case_setup = occ_setup.create_output_case_setup(oc_type='Thermal output case').set_name(name='Example OC') >>> output_case_setup = occ_setup.get_output_case_setup(name='Example OC') # The output case must already exist .. >>> isinstance(output_case_setup, ThermalOutputCaseSetup) True >>> isinstance(output_case_setup._output_case, ThermalOutputCase) True """ def __init__(self, item: ThermalOutputCase): super().__init__(item) self._output_case = item # Backwards compatibility self.output_case = item self._data_table_dependent_outputs_handler_api = DataTableDependentOutputsHandlerAPI( data_table_dependent_outputs_handler=self._output_case.data_table_dependent_outputs_handler)
[docs] def get_name(self) -> str: """ Returns the name of the output case .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_case_setup = _thermal_output_case_api_setup(api=api) >>> output_case_setup.set_name(name='new_name') <more...> >>> output_case_setup.get_name() 'new_name' Returns ------- name: str The name of the output case """ return self._output_case.name
[docs] def set_name(self, name: str, resolve_duplicate_name: bool = False) -> 'ThermalOutputCaseSetup': """ Sets the name of the output case See example at the top to see how to create a ThermalOutputCaseSetup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> occ = api.create_simulation_setup().create_output_case_container_setup() >>> output_case_setup = occ.create_output_case_setup(oc_type='Thermal output case') >>> second_output_case_setup = occ.create_output_case_setup(oc_type='Thermal output case') >>> output_case_setup.set_name(name='new_name') <more...> >>> second_output_case_setup.set_name(name='new_name', resolve_duplicate_name=True).get_name() 'new_name 1' .. >>> output_case_setup._output_case.name 'new_name' Trying to set the name to a non-string value >>> output_case_setup.set_name(name=None) Traceback (most recent call last): ... TypeError: ... Setting a non-unique name >>> output_case_setup.set_name('new_name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotUniqueError: ... Parameters ---------- name : str The new name for the output case resolve_duplicate_name: bool Whether to automatically assign a new name when the chosen one is already taken Returns ------- self: ThermalOutputCaseSetup Raises ------ NameNotUniqueError Raised if the given name is not unique TypeError Raised if the given name is not a string """ if not isinstance(name, str): raise TypeError('The given name must be of type string, but a: \"{}\" was given'.format(type(name))) created_names = [oc.name for oc in self._output_case.parent.elements] if name in created_names: if not resolve_duplicate_name: raise NameNotUniqueError( f'The given name: \"{name}\" is already given in the list: \"{created_names}\"') else: name = change_duplicate_name(name=name, names_list=created_names) self._output_case.name = name return self
[docs] def get_output_setup(self, index: int) -> OutputSetup: """ Gets a output setup object for an existing output .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_case_setup = _thermal_output_case_api_setup(api=api) >>> _output_setup_1 = output_case_setup.create_output_setup(output_type='Interface temperature') >>> _output_setup_2 = output_case_setup.create_output_setup(output_type='Interface temperature') >>> output_setup = output_case_setup.get_output_setup(index=1) # Two outputs must already exist .. >>> _output_setup_2._output == output_setup._output True >>> len(output_case_setup._output_case.data_table_dependent_outputs_handler.outputs_container.elements) 2 >>> output_case_setup._output_case.data_table_dependent_outputs_handler.outputs_container.elements[1] == output_setup._output True >>> output_case_setup.get_output_setup(index=None) Traceback (most recent call last): ... TypeError: ... Parameters ---------- index : int The index of the output in the output table Returns ------- OutputSetup: OutputSetup Raises ------ TypeError Raised if the index is not an integer """ return self._data_table_dependent_outputs_handler_api.get_output_setup(index=index)
[docs] def create_output_setup(self, output_type: str) -> OutputSetup: """ Creates a output of a specified type .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_case_setup = _thermal_output_case_api_setup(api=api) >>> interface_output_setup = output_case_setup.create_output_setup(output_type='Interface temperature') >>> interface_output_setup2 = output_case_setup.create_output_setup(output_type='Interface temperature') .. >>> len(output_case_setup._output_case.data_table_dependent_outputs_handler.outputs_container.elements) 2 >>> output_case_setup._output_case.data_table_dependent_outputs_handler.outputs_container.elements[1] == interface_output_setup2._output True >>> output_case_setup._output_case.data_table_dependent_outputs_handler.outputs_container.elements[0] == interface_output_setup._output True >>> output_case_setup.create_output_setup(output_type='Non existent output type') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... >>> output_case_setup.create_output_setup(output_type='Link displacement') Traceback (most recent call last): ... more.api.exceptions.api_exception.NotCompatibleError: ... Parameters ---------- index : int The index of the output in the output table Returns ------- OutputSetup: OutputSetup Raises ------ NameNotFoundError Raised if not output with the specified type was found NotCompatibleError Raised if the specified output type exists, but is not compatible with this output case """ return self._data_table_dependent_outputs_handler_api.create_output_setup(output_type=output_type)
[docs] def remove_output_setup(self, index: int) -> 'ThermalOutputCaseSetup': """ Removes the output under the specified index .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_case_setup = _thermal_output_case_api_setup(api=api) >>> _output_setup_1 = output_case_setup.create_output_setup(output_type='Interface temperature') >>> _output_setup_2 = output_case_setup.create_output_setup(output_type='Interface temperature') >>> output_case_setup = output_case_setup.remove_output_setup(index=1) # Two outputs must already exist .. >>> len(output_case_setup._output_case.data_table_dependent_outputs_handler.outputs_container.elements) 1 >>> output_case_setup._output_case.data_table_dependent_outputs_handler.outputs_container.elements[0] == _output_setup_1._output True >>> output_case_setup.remove_output_setup(index=None) Traceback (most recent call last): ... TypeError: ... Parameters ---------- index : int The index of the output in the output table Returns ------- ThermalOutputCaseSetup: ThermalOutputCaseSetup Raises ------ TypeError Raised if the index is not an integer """ self._data_table_dependent_outputs_handler_api.remove_output_setup(index=index) return self
[docs] def set_time_dependent_data_bool(self, value: bool) -> 'ThermalOutputCaseSetup': """ Sets whether data table data should be used in the output case .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_case_setup = _thermal_output_case_api_setup(api=api) >>> output_case_setup = output_case_setup.set_time_dependent_data_bool(value=True) .. >>> output_case_setup._output_case.data_table_dependent_outputs_handler.table_dependent_data.time_dependent_data == True True >>> output_case_setup = output_case_setup.set_time_dependent_data_bool(value=False) >>> output_case_setup._output_case.data_table_dependent_outputs_handler.table_dependent_data.time_dependent_data == False True Parameters ---------- value : bool A boolean value specifying whether data table dependence should be used Returns ------- ThermalOutputCaseSetup: ThermalOutputCaseSetup """ self._data_table_dependent_outputs_handler_api.set_time_dependent_data_bool(value=value) return self
[docs] def set_data_table_by_name(self, data_table_name: str) -> 'ThermalOutputCaseSetup': """Sets the data table to be used in this output case .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_case_setup = _thermal_output_case_api_setup(api=api) >>> data_table_setup = api.create_simulation_setup() \\ ... .create_data_table_setup(data_table_type_name='Transient data table') \\ ... .set_name(name='data_table_name') >>> print("Available data tables: {}".format(output_case_setup.available_data_table_names)) # To check which data tables are available Available data tables: ... >>> output_case_setup = output_case_setup.set_data_table_by_name(data_table_name='data_table_name') .. >>> output_case_setup._output_case.data_table_dependent_outputs_handler.table_dependent_data.single_data_table_choice == data_table_setup._data_table True >>> output_case_setup.set_data_table_by_name(data_table_name='Non-existent data table') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Parameters ---------- data_table_name: str The name of the data table to set Returns ------- self: ThermalOutputCaseSetup Raises ------ NameNotFoundError Raised if the data table was not found """ self._data_table_dependent_outputs_handler_api.set_data_table_by_name(data_table_name=data_table_name) return self
[docs] def get_data_table_query_config(self): """ Returns the api object for setting up the data table query for this output case .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_case_setup = _thermal_output_case_api_setup(api=api) >>> data_table_setup = api.create_simulation_setup() \\ ... .create_data_table_setup(data_table_type_name='Transient data table') \\ ... .set_name(name='data_table_name') >>> print("Available data tables: {}".format(output_case_setup.available_data_table_names)) # To check which data tables are available Available data tables: ... >>> output_case_setup = output_case_setup \\ ... .set_data_table_by_name(data_table_name='data_table_name') \\ ... .set_time_dependent_data_bool(value=True) >>> query_config = output_case_setup.get_data_table_query_config() .. >>> query_config._initial_partial_find_creator.data_table == data_table_setup._data_table True >>> _ = output_case_setup.set_time_dependent_data_bool(value=False) >>> output_case_setup.get_data_table_query_config() Traceback (most recent call last): ... more.api.exceptions.api_exception.NotCompatibleError: The current load case setup is not compatible with a data table query config, most probably the time dependency was set to false Returns ------- Query config An object for configuring the data table querying in the output case Raises ------ NotCompatibleError Raised if the current output case configuration is not compatible with a query config object """ return self._data_table_dependent_outputs_handler_api.get_data_table_query_config()
[docs] def set_time_dependent_data_column_index(self, index: int) -> 'ThermalOutputCaseSetup': """ Deprecated method .. admonition:: Deprecated :class: warning `set_time_dependent_data_column_index` will be removed in a future MORe release, it is replaced by the more general :meth:`~.get_data_table_query_config` """ logger.warning( 'Deprecation: \"set_time_dependent_data_column_index\" will be removed in a future MORe release, it is replaced by \"get_data_table_query_config\"') self._data_table_dependent_outputs_handler_api.set_time_dependent_data_column_index(index=index) return self
[docs] def set_time_dependent_data_table_by_name(self, data_table_name: str) -> 'ThermalOutputCaseSetup': """ Deprecated method .. admonition:: Deprecated :class: warning `set_time_dependent_data_table_by_name` will be removed in a future MORe release, it is replaced by :meth:`~.set_data_table_by_name` """ logger.warning( 'Deprecation: \"set_time_dependent_data_table_by_name\" will be removed in a future MORe release, it is replaced by \"set_data_table_by_name\"') return self.set_data_table_by_name(data_table_name=data_table_name)
@property def available_data_table_names(self) -> typing.List[str]: """ Returns the names of compatible data tables .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_case_setup = _thermal_output_case_api_setup(api=api) >>> data_table_setup = api.create_simulation_setup() \\ ... .create_data_table_setup(data_table_type_name='Transient data table') \\ ... .set_name(name='data_table_name') >>> print("Available data tables: {}".format(output_case_setup.available_data_table_names)) # To check which data tables are available Available data tables: ... .. >>> len(output_case_setup.available_data_table_names) == 1 True Returns ------ available_data_tables: Dict(str, str) A list with the names of compatible data tables """ return self._data_table_dependent_outputs_handler_api.available_data_table_names @property def available_data_tables_dict(self) -> typing.Dict[str, str]: """ Deprecated method .. admonition:: Deprecated :class: warning `available_data_tables_dict` will be removed in a future MORe release, it is replaced by :meth:`~.available_data_table_names` """ logger.warning( 'Deprecation: \"available_data_tables_dict\" will be removed in a future MORe release, it is replaced by \"available_data_table_names\"') return self._data_table_dependent_outputs_handler_api.available_data_tables_dict