Karana.KUtils.BasicPrefab#
BasicPrefab and associated classes.
This Prefab is used to generically represent multibody objects and a list of KModels.
Attributes#
Classes#
Params for the BasicPrefab. |
|
Context for the BasicPrefab. |
|
BasicPrefab for holding multibody objects and KModels. |
Module Contents#
- Karana.KUtils.BasicPrefab.ExtraInfoType#
- class Karana.KUtils.BasicPrefab.BasicParams(/, **data: Any)#
Bases:
Karana.KUtils.Prefab.Params,Generic[ExtraInfoType]Params for the BasicPrefab.
- Parameters:
subtree (SubTreeDS[SubTreeDSType]) – The SubTree of bodies/nodes to add.
models (list[tuple[KModelDS[BaseKModelType], KModelStateDS[BaseKModelType] | None]] = []) – The list of models to add. Each value in the list is a KModelDS and optional state data for the associated KModel.
subtree_state_info (SubTreeStateDS | None = None) – State information for the SubTree.
extra_info (SerializeAsAny[ExtraInfoType] | None = None) – Any extra information to store. This information is primarily used for validation of the SubTree and/or models. It is Python Generic, and can set by the user.
- subtree: pydantic.SerializeAsAny[Karana.Dynamics.SOADyn_types.SubTreeDS[Karana.Dynamics.SOADyn_types.SubTreeDSType]]#
- models: list[tuple[pydantic.SerializeAsAny[Karana.Dynamics.SOADyn_types.KModelDS[Karana.Dynamics.SOADyn_types.BaseKModelType]], pydantic.SerializeAsAny[Karana.Dynamics.SOADyn_types.KModelStateDS[Karana.Dynamics.SOADyn_types.BaseKModelType]] | None]] = []#
- subtree_state_info: Karana.Dynamics.SOADyn_types.SubTreeStateDS | None = None#
- extra_info: pydantic.SerializeAsAny[ExtraInfoType] | None = None#
- class Karana.KUtils.BasicPrefab.BasicContext(/, **data: Any)#
Bases:
Karana.KUtils.Prefab.ContextContext for the BasicPrefab.
- parent_body#
The parent_body to attach bodies to from the subtree on params. If None, then a FrameContainer can be used if the subtree is a SubGraphDS. See frame_container above for details.
- Type:
PhysicalBody | None = None
- model_manager#
The model_manager to register models with. If None and allow_create_model_manager is True in BasicConfig, then the BasicPrefab will attempt to create one.
- Type:
ModelManager | None = None
- frame_colliders#
An optional list of FrameColliders. If provided, these will be used for any PenaltyContact models in-place of the FrameColliders that they have listed as part of their DataStruct.
- Type:
list[FrameCollider] = []
- subtree_modification_fn#
This function runs after creating the SubTree from the SubTreeDS on params.subtree. It is used to make any modifications to the SubTree desired by the user, e.g., converting an FA model to a TA model, adding constraint embedding, etc.
- parent_body_raw: Annotated[Karana.Dynamics.PhysicalBody | int | None, *SerializeAsId(allow_int=True, allow_None=True)] = None#
- model_manager_raw: Annotated[Karana.Dynamics.ModelManager | int | None, *SerializeAsId(allow_int=True, allow_None=True)] = None#
- frame_colliders_raw: list[Karana.Collision.FrameCollider | Karana.Collision.Collision_types.FrameColliderDS] = None#
- subtree_modification_fn: Callable[[Karana.Dynamics.SubTree], Karana.Dynamics.SubTree] = None#
- property frame_colliders: list[Karana.Collision.FrameCollider]#
Get the FrameColliders for the associated PenaltyContact model.
- Returns:
The FrameColliders for the associated PenaltyContact model.
- Return type:
list[FrameCollider]
- property model_manager: Karana.Dynamics.ModelManager | None#
Return the ModelManager.
- Returns:
The ModelManager if set. Otherwise, returns None.
- Return type:
ModelManager | None
- property parent_body: Karana.Dynamics.PhysicalBody | None#
Get the parent_body.
- Returns:
The parent_body if it is set. Otherwise, None is returned.
- Return type:
PhysicalBody | None
- class Karana.KUtils.BasicPrefab.BasicPrefab(name: str, config: ConfigType, context: ContextType, params: ParamsType, parent_prefab: Prefab[Any, Any, Any] | None = None)#
Bases:
Karana.KUtils.Prefab.Prefab[Karana.KUtils.Prefab.Config,BasicContext,BasicParams[ExtraInfoType]],Generic[ExtraInfoType]BasicPrefab for holding multibody objects and KModels.
This BasicPrefab contains contains a SubTreeDS and a list of KModelDSs in its BasicParams. These are used to create multibody objects and KModels. See the associated BasicConfig, BasicContext, and BasicParams for how these can be used.
- addMultibodyObjects()#
Add multibody objects from params.
This adds the multibody objects stored in params.subtree.
If the context.parent_body is None, then no multibody objects will be added and a warning will be triggered.
- addKModels()#
Add KModels from params.
This method attempts to create KModels. To do so requires a ModelManager. This can be provided via context.model_manager.
If this value is None and there are models, a warning will be triggered.
- getSubTree() Karana.Dynamics.SubTree#
Get the SubTree created by this BasicPrefab.
- Returns:
The SubTree created by this BasicPrefab.
- Return type:
- classmethod createDS(name: str, config: Karana.KUtils.Prefab.Config, context: BasicContext, params: BasicParams[ExtraInfoType]) Karana.KUtils.Prefab.PrefabDS[Karana.KUtils.Prefab.Config, BasicContext, BasicParams[ExtraInfoType]]#
Create a DataStruct representing a BasicPrefab.
This is a helper method to create the DataStruct version of Basic, without having to create an instance of Basic.
- Parameters:
name (str) – The name for the BasicPrefab.
config (Config) – The Config for the BasicPrefab.
context (BasicContext) – The BasicContext for the BasicPrefab.
params (BasicParams[ExtraInfoType]) – The BasicParams for the BasicPrefab.
- Returns:
The DataStruct representation of the BasicPrefab with the provided config, context, and params.
- Return type:
PrefabDS[BasicConfig, BasicContext, BasicParams[ExtraInfoType]]
- classmethod createStandalone(basic_prefab_ds: Karana.KUtils.Prefab.PrefabDS[Karana.KUtils.Prefab.Config, BasicContext, BasicParams[ExtraInfoType]], fc: Karana.Frame.FrameContainer) tuple[Self, Karana.Dynamics.StatePropagator]#
Create a simulation from a BasicPrefab DataStruct.
This creates an empty Multibody from the FrameContainer and an empty StatePropagator with the cvode integrator from the Multibody. Then, these are added to the BasicPrefab DataStruct’s context, and a BasicPrefab is created from it.
- Parameters:
basic_prefab_ds (PrefabDS[Config, BasicContext, BasicParams[ExtraInfoType]]) – The BasicPrefab DataStruct to use to construct the simulation.
fc (FrameContainer) – The FrameContainer used to create the Multibody.
- Returns:
An instance of the BasicPrefab and the StatePropagator created by this method.
- Return type:
tuple[Self, StatePropagator]