Source code for loads.auxiliary_system_input.api.auxiliary_system_input_api

import typing

from more.api.exceptions.api_exception import NameNotFoundError
from more.api.simulation.load_cases.load_setup import LoadSetup, TranslationSettableMixin, RotationSettableMixin
from more.api.utils.interface_registries import register_api_implementation
from more.loads.auxiliary_system_input import AuxiliarySystemInput
from more.log import get_logger
logger = get_logger(__name__)




def _auxiliary_system_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='Mechanical load case').set_name(name='Example LC')
    return lc_setup.create_load_setup(load_type='Control module input')


[docs] @register_api_implementation(core_class=AuxiliarySystemInput) class AuxiliarySystemInputSetup(LoadSetup): """ The API handler for auxiliary system inputs The following example shows how to create an auxiliary system input 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='Mechanical load case').set_name(name='Example LC') >>> auxiliary_system_input_setup = lc_setup.create_load_setup(load_type='Control module input') .. >>> isinstance(auxiliary_system_input_setup, AuxiliarySystemInputSetup) True >>> isinstance(auxiliary_system_input_setup._load, AuxiliarySystemInput) 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='Mechanical load case').set_name(name='Example LC') .. >>> auxiliary_system_input_setup = lc_setup.create_load_setup(load_type='Control module input') >>> auxiliary_system_input_setup = lc_setup.get_load_setup(index=0) # The load under this index must already exist .. >>> isinstance(auxiliary_system_input_setup, AuxiliarySystemInputSetup) True >>> isinstance(auxiliary_system_input_setup._load, AuxiliarySystemInput) True """
[docs] def set_auxiliary_system_by_name(self, auxiliary_system_name: str) -> 'AuxiliarySystemInputSetup': """ Sets the auxiliary system for the associated auxiliary system input See example at the top for how to create an auxiliary system input setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> auxiliary_system_input_setup = _auxiliary_system_api_setup(api) >>> proj.comp.add_controller() >>> auxiliary_system = proj.comp.auxiliary_systems[0] >>> auxiliary_system.name = 'example auxiliary_system' >>> auxiliary_system_input_setup = auxiliary_system_input_setup.set_auxiliary_system_by_name(auxiliary_system_name='example auxiliary_system') # The controller with this name must already exist .. >>> auxiliary_system_input_setup._load.auxiliary_system_selector.selected_entity == auxiliary_system True >>> auxiliary_system_input_setup = auxiliary_system_input_setup.set_auxiliary_system_by_name(auxiliary_system_name='nonexistent name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: AuxiliarySystemInputSetup Raises ------ NameNotFoundError Raised if a key in the name is not a viable controller """ self._load.auxiliary_system_selector.select_entity_by_name(name=auxiliary_system_name) return self
[docs] def set_auxiliary_system_input_by_name(self, input_name) -> 'AuxiliarySystemInputSetup': """ Sets the external input for the associated auxiliary system input See example at the top for how to create an auxiliary system input setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> auxiliary_system_input_setup = _auxiliary_system_api_setup(api) >>> proj.comp.add_controller() >>> auxiliary_system = proj.comp.auxiliary_systems[0] >>> auxiliary_system.name = 'example auxiliary_system' >>> auxiliary_system_input_setup = auxiliary_system_input_setup.set_auxiliary_system_by_name(auxiliary_system_name='example auxiliary_system') # The controller with this name must already exist >>> auxiliary_system_input_setup = auxiliary_system_input_setup.set_auxiliary_system_input_by_name(input_name='Position command value') .. >>> auxiliary_system_input_setup._load.external_input.name == 'Position command value' True >>> auxiliary_system_input_setup = auxiliary_system_input_setup.set_auxiliary_system_input_by_name(input_name='nonexistent name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: AuxiliarySystemInputSetup Raises ------ NameNotFoundError Raised if a key in there is no external input with the given name """ try: self._load.external_input = self._available_auxiliary_system_inputs_dict[input_name] except KeyError: raise NameNotFoundError('Command value with name: {} not found, available command values are: {}'.format(input_name, self._available_auxiliary_system_inputs_dict.keys())) return self
@property def available_auxiliary_system_input_names(self) -> typing.List[str]: """ Returns the list of available external input names See example at the top for how to create an auxiliary system input setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> auxiliary_system_input_setup = _auxiliary_system_api_setup(api) >>> proj.comp.add_controller() >>> auxiliary_system = proj.comp.auxiliary_systems[0] >>> auxiliary_system.name = 'example auxiliary_system' >>> auxiliary_system_input_setup.available_auxiliary_system_input_names ['Position command value', 'Velocity command value', 'Position command value with setpoint scaling'] Returns ------- list of strings The list of available command values """ return list(self._available_auxiliary_system_inputs_dict.keys()) @property def _available_auxiliary_system_inputs_dict(self): return {cv.name: cv for cv in self._load._available_external_inputs} @property def available_command_values_dict(self): """ Deprecated method .. admonition:: Deprecated :class: warning `available_command_values_dict` will be removed in a future MORe release, it is replaced by :meth:`~.available_command_value_names` """ logger.warning( 'Deprecation: \"available_command_values_dict\" will be removed in a future MORe release, it is replaced by \"available_command_value_names\"') return self._available_auxiliary_system_inputs_dict
[docs] def set_controller(self, controller): """ Deprecated method .. admonition:: Deprecated :class: warning `set_controller` will be removed in a future MORe release, it is replaced by :meth:`~.set_controller_by_name` """ logger.warning( 'Deprecation: \"set_controller\" will be removed in a future MORe release, it is replaced by \"set_controller_by_name\"') return self.set_controller_by_name(controller_name=controller.name)
[docs] def set_command_value(self, command_value): """ Deprecated method .. admonition:: Deprecated :class: warning `set_command_value` will be removed in a future MORe release, it is replaced by :meth:`~.set_command_value_by_name` """ logger.warning( 'Deprecation: \"set_command_value\" will be removed in a future MORe release, it is replaced by \"set_command_value_by_name\"') return self.set_command_value_by_name(command_value_name=command_value.name)
[docs] def set_command_value_by_name(self, command_value_name: str) -> 'AuxiliarySystemInputSetup': """ Deprecated method .. admonition:: Deprecated :class: warning `set_command_value_by_name` will be removed in a future MORe release, it is replaced by :meth:`~.set_auxiliary_system_input_by_name` """ logger.warning( 'Deprecation: \"set_command_value_by_name\" will be removed in a future MORe release, it is replaced by \"set_auxiliary_system_input_by_name\"') return self.set_auxiliary_system_input_by_name(input_name=command_value_name)
[docs] def set_controller_by_name(self, controller_name: str) -> 'AuxiliarySystemInputSetup': """ Deprecated method .. admonition:: Deprecated :class: warning `set_controller_by_name` will be removed in a future MORe release, it is replaced by :meth:`~.set_auxiliary_system_by_name` """ logger.warning( 'Deprecation: \"set_controller_by_name\" will be removed in a future MORe release, it is replaced by \"set_auxiliary_system_by_name\"') return self.set_auxiliary_system_by_name(auxiliary_system_name=controller_name)
@property def available_command_value_names(self) -> typing.List[str]: """ Deprecated method .. admonition:: Deprecated :class: warning `available_command_value_names` will be removed in a future MORe release, it is replaced by :meth:`~.available_auxiliary_system_input_names` """ logger.warning( 'Deprecation: \"available_command_value_names\" will be removed in a future MORe release, it is replaced by \"available_auxiliary_system_input_names\"') return list(self._available_auxiliary_system_inputs_dict.keys())