Source code for loads.link_spacer.api.link_spacer_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.link_spacer import LinkSpacer
from more import log

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

def _link_spacer_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='Link spacer')


[docs] @register_api_implementation(core_class=LinkSpacer) class LinkSpacerSetup(LoadSetup, TranslationSettableMixin, RotationSettableMixin): """ The API handler for link spacers The following example shows how to create a link spacer 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') >>> link_spacer_setup = lc_setup.create_load_setup(load_type='Link spacer') .. >>> isinstance(link_spacer_setup, LinkSpacerSetup) True >>> isinstance(link_spacer_setup._load, LinkSpacer) 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') .. >>> link_spacer_setup = lc_setup.create_load_setup(load_type='Link spacer') >>> link_spacer_setup = lc_setup.get_load_setup(index=0) # The load under this index must already exist .. >>> isinstance(link_spacer_setup, LinkSpacerSetup) True >>> isinstance(link_spacer_setup._load, LinkSpacer) True """
[docs] def set_u(self, value: float) -> 'LinkSpacerSetup': """ Sets the 'u' value of the load vector See example at the top for how to create a link spacer setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> link_spacer_setup = _link_spacer_api_setup(api) >>> link_spacer_setup = link_spacer_setup.set_u(value=10) .. >>> link_spacer_setup._load.generalized_force_vector.u == 10 True >>> link_spacer_setup.set_u(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: LinkSpacerSetup 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) -> 'LinkSpacerSetup': """ Sets the 'v' value of the load vector See example at the top for how to create a link spacer setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> link_spacer_setup = _link_spacer_api_setup(api) >>> link_spacer_setup = link_spacer_setup.set_v(value=10) .. >>> link_spacer_setup._load.generalized_force_vector.v == 10 True >>> link_spacer_setup.set_v(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: LinkSpacerSetup 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) -> 'LinkSpacerSetup': """ Sets the 'w' value of the load vector See example at the top for how to create a link spacer setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> link_spacer_setup = _link_spacer_api_setup(api) >>> link_spacer_setup = link_spacer_setup.set_w(value=10) .. >>> link_spacer_setup._load.generalized_force_vector.w == 10 True >>> link_spacer_setup.set_w(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: LinkSpacerSetup 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) -> 'LinkSpacerSetup': """ Sets the 'ru' value of the load vector See example at the top for how to create a link spacer setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> link_spacer_setup = _link_spacer_api_setup(api) >>> link_spacer_setup = link_spacer_setup.set_ru(value=10) .. >>> link_spacer_setup._load.generalized_force_vector.ru == 10 True >>> link_spacer_setup.set_ru(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: LinkSpacerSetup 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) -> 'LinkSpacerSetup': """ Sets the 'rv' value of the load vector See example at the top for how to create a link spacer setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> link_spacer_setup = _link_spacer_api_setup(api) >>> link_spacer_setup = link_spacer_setup.set_rv(value=10) .. >>> link_spacer_setup._load.generalized_force_vector.rv == 10 True >>> link_spacer_setup.set_rv(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: LinkSpacerSetup 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) -> 'LinkSpacerSetup': """ Sets the 'rw' value of the load vector See example at the top for how to create a link spacer setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> link_spacer_setup = _link_spacer_api_setup(api) >>> link_spacer_setup = link_spacer_setup.set_rw(value=10) .. >>> link_spacer_setup._load.generalized_force_vector.rw == 10 True >>> link_spacer_setup.set_rw(value='wrong value') Traceback (most recent call last): ... TypeError: ... Returns ------- self: LinkSpacerSetup 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]) -> 'LinkSpacerSetup': """ Sets the values of the load vector to those given in the dictionary See example at the top for how to create a link spacer setup object .. admonition:: Example :class: note .. >>> import more.project >>> proj = more.project.Project() >>> from more.api import ApiGateway >>> api = ApiGateway(proj=proj) >>> link_spacer_setup = _link_spacer_api_setup(api) >>> link_spacer_setup = link_spacer_setup.set_dof_dict(dof_values_dict={'u': 5, 'ru': 10, 'v': 2.0}) .. >>> link_spacer_setup._load.generalized_force_vector.u == 5 True >>> link_spacer_setup._load.generalized_force_vector.ru == 10 True >>> link_spacer_setup._load.generalized_force_vector.v == 2.0 True >>> link_spacer_setup.set_dof_dict(dof_values_dict={'u': 'wrong value'}) Traceback (most recent call last): ... TypeError: ... >>> link_spacer_setup.set_dof_dict(dof_values_dict={'wrong dof': 10}) Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: LinkSpacerSetup 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) -> 'LinkSpacerSetup': """ 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) >>> link_spacer_setup = _link_spacer_api_setup(api) >>> link_spacer_setup = link_spacer_setup.set_dof(dof_name='v', value=10) .. >>> link_spacer_setup._load.generalized_force_vector.v == 10 True >>> link_spacer_setup.set_dof(dof_name='v', value='wrong value') Traceback (most recent call last): ... TypeError: ... >>> link_spacer_setup.set_dof(dof_name='wrong dof', value=10) Traceback (most recent call last): ... more.api.exceptions.api_exception.NameNotFoundError: ... Returns ------- self: LinkSpacerSetup Raises ------ TypeError Raised if the supplied value is not a floating point number NameNotFoundError Raised if the given dof name is not supported """ return self.set_dof_dict(dof_values_dict={dof_name: value})