Karana.Math.Ktyping
===================

.. py:module:: Karana.Math.Ktyping

.. autoapi-nested-parse::

   Module containing types used throughout kdFlex.



Submodules
----------

.. toctree::
   :maxdepth: 1

   /generated/python_api/Karana/Math/Ktyping/Math_types/index


Attributes
----------

.. autoapisummary::

   Karana.Math.Ktyping.mass
   Karana.Math.Ktyping.inertia
   Karana.Math.Ktyping.length
   Karana.Math.Ktyping.angle
   Karana.Math.Ktyping.velocity
   Karana.Math.Ktyping.acceleration
   Karana.Math.Ktyping.force
   Karana.Math.Ktyping.torque
   Karana.Math.Ktyping.angular_velocity
   Karana.Math.Ktyping.angular_acceleration
   Karana.Math.Ktyping.gravitational_parameter
   Karana.Math.Ktyping.linear_spring_constant
   Karana.Math.Ktyping.linear_damping_constant
   Karana.Math.Ktyping.rotational_spring_constant
   Karana.Math.Ktyping.rotational_damping_constant
   Karana.Math.Ktyping.momentum
   Karana.Math.Ktyping.angular_momentum
   Karana.Math.Ktyping.translational_nodal_matrix
   Karana.Math.Ktyping.rotational_nodal_matrix
   Karana.Math.Ktyping.modal_stiffness
   Karana.Math.Ktyping.modal_damping
   Karana.Math.Ktyping.MATH_EPSILON
   Karana.Math.Ktyping.NonNegativeInt
   Karana.Math.Ktyping.NonNegativeFloat
   Karana.Math.Ktyping.Vec
   Karana.Math.Ktyping.Mat
   Karana.Math.Ktyping.Vec3
   Karana.Math.Ktyping.Mat33
   Karana.Math.Ktyping.Mat66
   Karana.Math.Ktyping.Mat6n
   Karana.Math.Ktyping.Mat3n
   Karana.Math.Ktyping.Mass
   Karana.Math.Ktyping.Length
   Karana.Math.Ktyping.Angle
   Karana.Math.Ktyping.Velocity
   Karana.Math.Ktyping.AngularVelocity
   Karana.Math.Ktyping.Acceleration
   Karana.Math.Ktyping.AngularAcceleration
   Karana.Math.Ktyping.Momentum
   Karana.Math.Ktyping.AngularMomentum
   Karana.Math.Ktyping.Inertia
   Karana.Math.Ktyping.Force
   Karana.Math.Ktyping.Torque
   Karana.Math.Ktyping.GravitationalParameter
   Karana.Math.Ktyping.LinearSpringConstant
   Karana.Math.Ktyping.RotationalSpringConstant
   Karana.Math.Ktyping.LinearDampingConstant
   Karana.Math.Ktyping.RotationalDampingConstant
   Karana.Math.Ktyping.TranslationalNodalMatrix
   Karana.Math.Ktyping.RotationalNodalMatrix
   Karana.Math.Ktyping.ModalStiffness
   Karana.Math.Ktyping.ModalDamping


Classes
-------

.. autoapisummary::

   Karana.Math.Ktyping.OptionallyWithUnits


Functions
---------

.. autoapisummary::

   Karana.Math.Ktyping.getDefaultUnits
   Karana.Math.Ktyping.npSizeCheck
   Karana.Math.Ktyping.normCheck
   Karana.Math.Ktyping.beforeVal
   Karana.Math.Ktyping.ser
   Karana.Math.Ktyping.SerializeAsId


Package Contents
----------------

.. py:data:: mass

.. py:data:: inertia

.. py:data:: length

.. py:data:: angle

.. py:data:: velocity

.. py:data:: acceleration

.. py:data:: force

.. py:data:: torque

.. py:data:: angular_velocity

.. py:data:: angular_acceleration

.. py:data:: gravitational_parameter

.. py:data:: linear_spring_constant

.. py:data:: linear_damping_constant

.. py:data:: rotational_spring_constant

.. py:data:: rotational_damping_constant

.. py:function:: getDefaultUnits(quantity: pint.util.UnitsContainer) -> pint.facets.plain.objects.PlainUnit

   Get the default units for a quantity.

   :param quantity: The quantity to get default units for.
   :type quantity: UnitsContainer

   :returns: The default units for the provided quantity.
   :rtype: PlainUnit


.. py:data:: momentum

.. py:data:: angular_momentum

.. py:data:: translational_nodal_matrix

.. py:data:: rotational_nodal_matrix

.. py:data:: modal_stiffness

.. py:data:: modal_damping

.. py:data:: MATH_EPSILON
   :type:  float
   :value: 1e-12


.. py:data:: NonNegativeInt

.. py:data:: NonNegativeFloat

.. py:function:: npSizeCheck(shape: tuple[int, Ellipsis]) -> pydantic.AfterValidator

   Ensure that the numpy array is the given shape.

   :param shape: Desired shape of the array. A value of -1 indicates that, that particular axis can be any size.
                 For example, a shape of (3, -1, 2) indicates the first axis must be size 3, the second axis can be
                 any size, and the third axis must be size 2.
   :type shape: tuple[int, ...]


.. py:class:: OptionallyWithUnits

   Pydantic metadata validating quantity dimensions and magnitude.

   When Pydantic specializes `Angle[Vec3]`, `source_type` is
   `NumpyQuantity[Vec3]`.  This metadata extracts `Vec3` and builds a
   separate adapter for `quantity.m`.  Consequently the generic parameter
   supplies both the static type of `.m` and its runtime Pydantic
   validation.

   This validator will coerce types without units to have them. If no unit is
   supplied, then the default unit for that quantity will be added.


   .. py:attribute:: dimensionality
      :type:  pint.util.UnitsContainer


   .. py:method:: __get_pydantic_core_schema__(source_type: Any, handler: Any) -> pydantic_core.CoreSchema

      Get the validation Schema.

      :param source_type: The source type to validate.
      :type source_type: Any
      :param handler: The handler to run for normal validation.
      :type handler: Any

      :returns: The core schema to use for validation.
      :rtype: CoreSchema



.. py:function:: normCheck(norm: float, prec: float = MATH_EPSILON) -> pydantic.AfterValidator

   Ensure the given value is within prec of norm.

   :param norm: The value we want the norm to be.
   :type norm: float
   :param prec: The tolerance for the value to be within that norm.
   :type prec: float


.. py:data:: Vec

.. py:data:: Mat

.. py:data:: Vec3

.. py:data:: Mat33

.. py:data:: Mat66

.. py:data:: Mat6n

.. py:data:: Mat3n

.. py:type:: Mass
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(mass)]


.. py:type:: Length
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(length)]


.. py:type:: Angle
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(angle)]


.. py:type:: Velocity
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(velocity)]


.. py:type:: AngularVelocity
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(angular_velocity)]


.. py:type:: Acceleration
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(acceleration)]


.. py:type:: AngularAcceleration
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(angular_acceleration)]


.. py:type:: Momentum
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(momentum)]


.. py:type:: AngularMomentum
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(angular_momentum)]


.. py:type:: Inertia
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(inertia)]


.. py:type:: Force
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(force)]


.. py:type:: Torque
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(torque)]


.. py:type:: GravitationalParameter
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(gravitational_parameter)]


.. py:type:: LinearSpringConstant
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(linear_spring_constant)]


.. py:type:: RotationalSpringConstant
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(rotational_spring_constant)]


.. py:type:: LinearDampingConstant
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(linear_damping_constant)]


.. py:type:: RotationalDampingConstant
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(rotational_damping_constant)]


.. py:type:: TranslationalNodalMatrix
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(translational_nodal_matrix)]


.. py:type:: RotationalNodalMatrix
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(rotational_nodal_matrix)]


.. py:type:: ModalStiffness
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(modal_stiffness)]


.. py:type:: ModalDamping
   :canonical: Annotated[NumpyQuantity[Magnitude], OptionallyWithUnits(modal_damping)]


.. py:function:: beforeVal(val: int | Any, allow_int: bool = False, allow_None: bool = True) -> Any

   Validate an incoming object.

   If this is an integer, then us IdMixin to look up the
   object that corresponds to that integer.

   :param val: The value to validate.
   :type val: int | Any
   :param allow_int: If True, then if the val does not correspond to an object that has been
                     created, then return the integer. This overshadows allow_None if both
                     are set. If False, then try allow_None before.
   :type allow_int: bool
   :param allow_None: If True, then if the val does not correspond to an object that has been
                      created, then return None. If False, then throw an error val does not
                      correspond to an object that has been created.
   :type allow_None: bool

   :returns: The value.
   :rtype: Any


.. py:function:: ser(val: Any) -> int | None

   Serialize an object using its ID rather than the object itself.

   :param val: Use the id() method to get the value to serialize.
   :type val: Any

   :returns: This returns an integer if Value is none None, and None otherwise.
   :rtype: int | None


.. py:function:: SerializeAsId(allow_int: bool = False, allow_None: bool = True) -> tuple[pydantic.BeforeValidator, pydantic.PlainSerializer]

   Create pydantic functions to serialize object as ID.

   This is typically used like:

   class MyDataStruct(DataStruct):
       body: Annotated[PhysicalBody, *SerializeAsId()]

   :param allow_int: If True, then if the val does not correspond to an object that has been
                     created, then return the integer. This overshadows allow_None if both
                     are set. If False, then try allow_None before.
   :type allow_int: bool
   :param allow_None: This affects deserialization. If True, then if the ID does not correspond to
                      an object that has been created, then return None. If False, then throw an
                      error if val does not correspond to an object that has been created.
   :type allow_None: bool

   :returns: A validator function and serializer function for the pydantic field to serialize
             as an ID.
   :rtype: tuple[BeforeValidator, PlainSerializer]


