Source code for loads.component_acceleration.api.component_acceleration_api

import typing
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.component_acceleration import ComponentAcceleration
from more import log

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

def _component_acceleration_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='Component acceleration')


[docs] @register_api_implementation(core_class=ComponentAcceleration) class ComponentAccelerationSetup(LoadSetup, TranslationSettableMixin, RotationSettableMixin): """ The API handler for component accelerations The following example shows how to create a component acceleration 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') >>> component_acceleration_setup = lc_setup.create_load_setup(load_type='Component acceleration') .. >>> isinstance(component_acceleration_setup, ComponentAccelerationSetup) True >>> isinstance(component_acceleration_setup._load, ComponentAcceleration) 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') .. >>> component_acceleration_setup = lc_setup.create_load_setup(load_type='Component acceleration') >>> component_acceleration_setup = lc_setup.get_load_setup(index=0) # The load under this index must already exist .. >>> isinstance(component_acceleration_setup, ComponentAccelerationSetup) True >>> isinstance(component_acceleration_setup._load, ComponentAcceleration) True """
[docs] def set_u(self, value: float) -> 'ComponentAccelerationSetup': """ Sets the 'u' value of the load vector See example at the top for how to create a component acceleration setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> component_acceleration_setup = _component_acceleration_api_setup(api) >>> component_acceleration_setup = component_acceleration_setup.set_u(value=10) .. >>> component_acceleration_setup._load.generalized_force_vector.u == 10 True >>> component_acceleration_setup.set_u(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: ComponentAccelerationSetup Raises ------ TypeError Raised if the supplied value is not a floating point number """ self.set_dof_dict(dof_values_dict={'u': value}) return self
[docs] def set_v(self, value: float) -> 'ComponentAccelerationSetup': """ Sets the 'v' value of the load vector See example at the top for how to create a component acceleration setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> component_acceleration_setup = _component_acceleration_api_setup(api) >>> component_acceleration_setup = component_acceleration_setup.set_v(value=10) .. >>> component_acceleration_setup._load.generalized_force_vector.v == 10 True >>> component_acceleration_setup.set_v(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: ComponentAccelerationSetup Raises ------ TypeError Raised if the supplied value is not a floating point number """ self.set_dof_dict(dof_values_dict={'v': value}) return self
[docs] def set_w(self, value: float) -> 'ComponentAccelerationSetup': """ Sets the 'w' value of the load vector See example at the top for how to create a component acceleration setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> component_acceleration_setup = _component_acceleration_api_setup(api) >>> component_acceleration_setup = component_acceleration_setup.set_w(value=10) .. >>> component_acceleration_setup._load.generalized_force_vector.w == 10 True >>> component_acceleration_setup.set_w(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: ComponentAccelerationSetup Raises ------ TypeError Raised if the supplied value is not a floating point number """ self.set_dof_dict(dof_values_dict={'w': value}) return self
[docs] def set_ru(self, value: float) -> 'ComponentAccelerationSetup': """ Sets the 'ru' value of the load vector See example at the top for how to create a component acceleration setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> component_acceleration_setup = _component_acceleration_api_setup(api) >>> component_acceleration_setup = component_acceleration_setup.set_ru(value=10) .. >>> component_acceleration_setup._load.generalized_force_vector.ru == 10 True >>> component_acceleration_setup.set_ru(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: ComponentAccelerationSetup Raises ------ TypeError Raised if the supplied value is not a floating point number """ self.set_dof_dict(dof_values_dict={'ru': value}) return self
[docs] def set_rv(self, value: float) -> 'ComponentAccelerationSetup': """ Sets the 'rv' value of the load vector See example at the top for how to create a component acceleration setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> component_acceleration_setup = _component_acceleration_api_setup(api) >>> component_acceleration_setup = component_acceleration_setup.set_rv(value=10) .. >>> component_acceleration_setup._load.generalized_force_vector.rv == 10 True >>> component_acceleration_setup.set_rv(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: ComponentAccelerationSetup Raises ------ TypeError Raised if the supplied value is not a floating point number """ self.set_dof_dict(dof_values_dict={'rv': value}) return self
[docs] def set_rw(self, value: float) -> 'ComponentAccelerationSetup': """ Sets the 'rw' value of the load vector See example at the top for how to create a component acceleration setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> component_acceleration_setup = _component_acceleration_api_setup(api) >>> component_acceleration_setup = component_acceleration_setup.set_rw(value=10) .. >>> component_acceleration_setup._load.generalized_force_vector.rw == 10 True >>> component_acceleration_setup.set_rw(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: ComponentAccelerationSetup Raises ------ TypeError Raised if the supplied value is not a floating point number """ self.set_dof_dict(dof_values_dict={'rw': value}) return self
[docs] def set_dof_dict(self, dof_values_dict: typing.Dict[str, float]) -> 'ComponentAccelerationSetup': """ Sets the values of the load vector to those given in the dictionary See example at the top for how to create a component acceleration setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> component_acceleration_setup = _component_acceleration_api_setup(api) >>> component_acceleration_setup = component_acceleration_setup.set_dof_dict(dof_values_dict={'u': 5, 'ru': 10, 'v': 2.0}) .. >>> component_acceleration_setup._load.generalized_force_vector.u == 5 True >>> component_acceleration_setup._load.generalized_force_vector.ru == 10 True >>> component_acceleration_setup._load.generalized_force_vector.v == 2.0 True >>> component_acceleration_setup.set_dof_dict(dof_values_dict={'u': 'wrong value'}) Traceback (most recent call last): ... TypeError: ... >>> component_acceleration_setup.set_dof_dict(dof_values_dict={'wrong dof': 10}) Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: ComponentAccelerationSetup 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) -> 'ComponentAccelerationSetup': """ 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) >>> component_acceleration_setup = _component_acceleration_api_setup(api) >>> component_acceleration_setup = component_acceleration_setup.set_dof(dof_name='v', value=10) .. >>> component_acceleration_setup._load.generalized_force_vector.v == 10 True >>> component_acceleration_setup.set_dof(dof_name='v', value='wrong value') Traceback (most recent call last): ... TypeError: ... >>> component_acceleration_setup.set_dof(dof_name='wrong dof', value=10) Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: ComponentAccelerationSetup Raises ------ TypeError Raised if the supplied value is not a floating point number NameNotFoundError Raised if the given name is not a recognized DOF """ return self.set_dof_dict(dof_values_dict={dof_name: value})
[docs] def set_component_by_name(self, component_name: str) -> 'ComponentAccelerationSetup': """ Sets the component for the associated component acceleration See example at the top for how to create a component acceleration setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> component_acceleration_setup = _component_acceleration_api_setup(api) >>> component = proj.comp.add_component() >>> component.name = 'example component' >>> component_acceleration_setup = component_acceleration_setup.set_component_by_name(component_name='example component') # The component with this name must already exist .. >>> component_acceleration_setup._load.component_selector.selected_entity == component True >>> component_acceleration_setup = component_acceleration_setup.set_component_by_name(component_name='nonexistent name') Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: ComponentAccelerationSetup Raises ------ NameNotFoundError Raised if there is no component with the supplied name """ self._load.component_selector.select_entity_by_name(name=component_name) return self
[docs] def set_component(self, component) -> 'ComponentAccelerationSetup': """ Deprecated method .. admonition:: Deprecated :class: warning `set_component` will be removed in a future MORe release, it is replaced by :meth:`~.set_component_by_name` """ logger.warning( 'Deprecation: \"set_component\" will be removed in a future MORe release, it is replaced by \"set_component_by_name\"') return self.set_component_by_name(component_name=component.name)