Source code for loads.heat_flow.api.heat_flow_api

import typing

from more.api.simulation.load_cases.load_setup import LoadSetup, SourceTargetSettableMixin
from more.api.utils.interface_registries import register_api_implementation
from more.loads.heat_flow import HeatFlow
from more import log

log.init_logging()
logger = log.getLogger(__name__)

def _heat_flow_api_setup(api):
    simulation_setup = api.create_simulation_setup()
    lcc_setup = simulation_setup.create_load_case_container_setup().set_name(name='Example LCC')
    lc_setup = lcc_setup.create_load_case_setup(lc_type='Thermal load case').set_name(name='Example LC')
    return lc_setup.create_load_setup(load_type='Heat flow')


[docs] @register_api_implementation(core_class=HeatFlow) class HeatFlowSetup(LoadSetup, SourceTargetSettableMixin): """ The API handler for heat flow loads The following example shows how to create a heat flow 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() >>> lcc_setup = simulation_setup.create_load_case_container_setup().set_name(name='Example LCC') >>> lc_setup = lcc_setup.create_load_case_setup(lc_type='Thermal load case').set_name(name='Example LC') >>> load_setup = lc_setup.create_load_setup(load_type='Heat flow') .. >>> isinstance(load_setup, HeatFlowSetup) True >>> isinstance(load_setup._load, HeatFlow) True The next example shows how to get an API object for an already existing load. .. 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() >>> lcc_setup = simulation_setup.create_load_case_container_setup().set_name(name='Example LCC') >>> lc_setup = lcc_setup.create_load_case_setup(lc_type='Thermal load case').set_name(name='Example LC') .. >>> load_setup = lc_setup.create_load_setup(load_type='Heat flow') >>> load_setup = lc_setup.get_load_setup(index=0) # The load under this index must already exist .. >>> isinstance(load_setup, HeatFlowSetup) True >>> isinstance(load_setup._load, HeatFlow) True """
[docs] def set_target_value(self, value) -> 'HeatFlowSetup': """ Sets the 'target' value of the load vector See example at the top for how to create a heat flow setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> load_setup = _heat_flow_api_setup(api) >>> load_setup = load_setup.set_target_value(value=10) .. >>> load_setup._load.generalized_force_vector.target == 10 True >>> load_setup.set_target_value(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: HeatFlowSetup Raises ------ TypeError Raised if the supplied value is not a floating point number """ self.set_dof_dict(dof_values_dict={'target': value}) return self
[docs] def set_source_value(self, value) -> 'HeatFlowSetup': """ Sets the 'source' value of the load vector See example at the top for how to create a heat flow setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> load_setup = _heat_flow_api_setup(api) >>> load_setup = load_setup.set_source_value(value=10) .. >>> load_setup._load.generalized_force_vector.source == 10 True >>> load_setup.set_source_value(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: HeatFlowSetup Raises ------ TypeError Raised if the supplied value is not a floating point number """ self.set_dof_dict(dof_values_dict={'source': value}) return self
[docs] def set_dof_dict(self, dof_values_dict: typing.Dict[str, float]) -> 'HeatFlowSetup': """ Sets the values of the load vector to those given in the dictionary See example at the top for how to create a heat flow setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> load_setup = _heat_flow_api_setup(api) >>> load_setup = load_setup.set_dof_dict(dof_values_dict={'source': 5, 'target': 10}) .. >>> load_setup._load.generalized_force_vector.source == 5 True >>> load_setup._load.generalized_force_vector.target == 10 True >>> load_setup.set_dof_dict(dof_values_dict={'source': 'wrong value'}) Traceback (most recent call last): ... TypeError: ... >>> load_setup.set_dof_dict(dof_values_dict={'wrong dof': 10}) Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: HeatFlowSetup 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._load.generalized_force_vector.set_dof_dict(dof_values_dict=dof_values_dict) return self
[docs] def set_dof(self, dof_name, value) -> 'HeatFlowSetup': """ 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) >>> heat_flow_setup = _heat_flow_api_setup(api) >>> heat_flow_setup = heat_flow_setup.set_dof(dof_name='target', value=10) .. >>> heat_flow_setup._load.generalized_force_vector.target == 10 True >>> heat_flow_setup.set_dof(dof_name='v', value='wrong value') Traceback (most recent call last): ... TypeError: ... >>> heat_flow_setup.set_dof(dof_name='wrong dof', value=10) Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: HeatFlowSetup 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})
[docs] def set_heat_flow(self, value) -> 'HeatFlowSetup': """ Deprecated version of :meth:`~.set_general_job_settings_parameter` .. admonition:: Deprecated :class: warning `set_heat_flow` will be removed in a future MORe release, it is split into two methods :meth:`~.set_target_value` and :meth:`~.set_source_value`: """ logger.warning('Deprecation: \"set_heat_flow\" will be removed in a future MORe release, replace with \"set_target_value\" and \"set_source_value\"') self.set_target_value(value) return self.set_source_value(value)
[docs] def set_target_heat_flow(self, value) -> 'HeatFlowSetup': """ Deprecated version of :meth:`~.set_target_value` .. admonition:: Deprecated :class: warning `set_target_heat_flow` will be removed in a future MORe release, it is replaced by :meth:`~.set_target_value` """ logger.warning('Deprecation: \"set_target_heat_flow\" will be removed in a future MORe release, it is replaced by \"set_target_value\"') return self.set_target_value(value)
[docs] def set_source_heat_flow(self, value) -> 'HeatFlowSetup': """ Deprecated version of :meth:`~.set_source_value` .. admonition:: Deprecated :class: warning `set_source_heat_flow` will be removed in a future MORe release, it is replaced by :meth:`~.set_source_value` """ logger.warning('Deprecation: \"set_source_heat_flow\" will be removed in a future MORe release, it is replaced by \"set_source_value\"') return self.set_source_value(value)