Source code for outputs.interface_temperature.api.interface_temperature_api

import typing

from more.api.exceptions.api_exception import NameNotFoundError, MOReAPIError
from more.api.simulation.output_cases.output_setup import OutputSetup
from more.api.utils.interface_registries import register_api_implementation
from more.outputs.interface_temperature import InterfaceTemperature
from more.log import get_logger
logger = get_logger(__name__)




def _interface_temperature_api_setup(api):
    simulation_setup = api.create_simulation_setup()
    occ_setup = simulation_setup.create_output_case_container_setup().set_name(name='Example OCC')
    oc_setup = occ_setup.create_output_case_setup(oc_type='Thermal output case').set_name(name='Example OC')
    return oc_setup.create_output_setup(output_type='Interface temperature')


[docs] @register_api_implementation(core_class=InterfaceTemperature) class InterfaceTemperatureSetup(OutputSetup): """ The API handler for Interface temperature outputs The following example shows how to create a Interface temperature Output 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') >>> oc_setup = occ_setup.create_output_case_setup(oc_type='Thermal output case').set_name(name='Example OC') >>> output_setup = oc_setup.create_output_setup(output_type='Interface temperature') .. >>> isinstance(output_setup, InterfaceTemperatureSetup) True >>> isinstance(output_setup._output, InterfaceTemperature) True The next example shows how to get an API object for an already existing output. .. 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') >>> oc_setup = occ_setup.create_output_case_setup(oc_type='Thermal output case').set_name(name='Example OC') .. >>> output_setup = oc_setup.create_output_setup(output_type='Interface temperature') >>> output_setup = oc_setup.get_output_setup(index=0) # The output under this index must already exist .. >>> isinstance(output_setup, InterfaceTemperatureSetup) True >>> isinstance(output_setup._output, InterfaceTemperature) True """
[docs] def set_value(self, value) -> 'InterfaceTemperatureSetup': """ Sets the value of the DOF vector See example at the top for how to create a Interface temperature setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_setup = _interface_temperature_api_setup(api) >>> output_setup = output_setup.set_value(value=100) .. >>> output_setup._output.generalized_dof_vector.value == 100 True >>> output_setup.set_value(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: InterfaceTemperatureSetup Raises ------ TypeError Raised if the supplied value is not a floating point number """ self.set_dof_dict(dof_values_dict={'value': value}) return self
[docs] def set_dof_dict(self, dof_values_dict: typing.Dict[str, float]) -> 'InterfaceTemperatureSetup': """ Sets the values of the DOF vector to those given in the dictionary See example at the top for how to create a Interface temperature setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_setup = _interface_temperature_api_setup(api) >>> output_setup = output_setup.set_dof_dict(dof_values_dict={'value': 100}) .. >>> output_setup._output.generalized_dof_vector.value == 100 True >>> output_setup.set_dof_dict(dof_values_dict={'value': 'wrong value'}) Traceback (most recent call last): ... TypeError: ... >>> output_setup.set_dof_dict(dof_values_dict={'wrong dof': 10}) Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: InterfaceTemperatureSetup Raises ------ TypeError Raised if the supplied value is not a floating point number NameNotFoundError Raised if a key in the supplied dictionary is not a recognized dof """ self._output.generalized_dof_vector.set_dof_dict(dof_values_dict=dof_values_dict) return self
[docs] def set_component_by_name(self, component_name: str) -> 'InterfaceTemperatureSetup': """ Sets the component for the associated Interface temperature See example at the top for how to create a Interface temperature setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_setup = _interface_temperature_api_setup(api) >>> component = proj.comp.add_component() >>> component.name = 'example component' >>> output_setup = output_setup.set_component_by_name(component_name='example component') .. >>> output_setup._output.component_selector.selected_entity == component True >>> output_setup = output_setup.set_component_by_name(component_name='nonexistent name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: InterfaceTemperatureSetup Raises ------ NameNotFoundError Raised if the supplied name is not a recognized component """ self._output.component_selector.select_entity_by_name(name=component_name) return self
@property def _available_interfaces_dict(self) -> typing.Dict[str, typing.Any]: return {cv.name: cv for cv in self._output.available_interfaces}
[docs] def set_interface_by_name(self, interface_name) -> 'InterfaceTemperatureSetup': """ Sets the interface for the associated Interface temperature Returns ------- self: InterfaceTemperatureSetup Raises ------ NameNotFoundError Raised if the supplied name is not recognized """ try: self._output.selected_interface = self._available_interfaces_dict[interface_name] except KeyError: raise NameNotFoundError( 'Interface with name: {} not found, available names are: {}'.format(interface_name, self._available_interfaces_dict.keys())) return self
[docs] def set_dof(self, dof_name, value) -> 'InterfaceTemperatureSetup': """ Sets the value of an element of the DOF vector See example at the top for how to create the setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> output_setup = _interface_temperature_api_setup(api) >>> output_setup = output_setup.set_dof(dof_name='value', value=10) .. >>> output_setup._output.generalized_dof_vector.value == 10 True >>> output_setup.set_dof(dof_name='value', value='wrong value') Traceback (most recent call last): ... TypeError: ... >>> output_setup.set_dof(dof_name='wrong dof', value=10) Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: InterfaceTemperatureSetup Raises ------ TypeError Raised if the supplied value is not a floating point number NameNotFoundError Raised if there is no DOF with the given name """ return self.set_dof_dict(dof_values_dict={dof_name: value})