Skip to content

liblaf.apple.sim.actor ¤

Modules:

Classes:

Actor ¤

Bases: PyTreeNode

Parameters:

  • id (str, default: <dynamic> ) –
  • collision_mesh (Mesh, default: None ) –
  • components (list[ComponentProtocol], default: <dynamic> ) –

    Built-in mutable sequence.

    If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

  • dirichlet (Dirichlet, default: <dynamic> ) –
  • dofs (DOFs, default: <dynamic> ) –
  • region (Region, default: None ) –

Methods:

Attributes:

cell_data property ¤

cell_data: GeometryAttributes

collision_mesh class-attribute instance-attribute ¤

collision_mesh: Mesh = static(default=None)

components class-attribute instance-attribute ¤

components: list[ComponentProtocol] = data(factory=list)

dim property ¤

dim: int

dirichlet class-attribute instance-attribute ¤

dirichlet: Dirichlet = data(factory=Dirichlet)

displacement property ¤

displacement: Float[Array, 'points dim']

dofs class-attribute instance-attribute ¤

dofs: DOFs = data(factory=DOFsArray)

element property ¤

element: Element

field_data property ¤

field_data: GeometryAttributes

force property ¤

force: Float[Array, 'points dim']

geometry property ¤

geometry: Geometry

id class-attribute instance-attribute ¤

id: str = static(
    default=Factory(uniq_id, takes_self=True), kw_only=True
)

mass property ¤

mass: Float[Array, points]

n_dirichlet property ¤

n_dirichlet: int

n_dofs property ¤

n_dofs: int

n_points property ¤

n_points: int

point_data property ¤

point_data: GeometryAttributes

points property ¤

points: Float[Array, 'points dim']

positions property ¤

positions: Float[Array, 'points dim']

region class-attribute instance-attribute ¤

region: Region = data(default=None)

velocity property ¤

velocity: Float[Array, 'points dim']

__pdoc__ ¤

__pdoc__(**kwargs) -> AbstractDoc

...

References
  1. wadler_lindig._definitions._pformat_dataclass()
Source code in src/liblaf/apple/sim/actor/actor.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from .protocol import ComponentProtocol


@struct.pytree
class Actor(struct.PyTreeNode):
    collision_mesh: wp.Mesh = struct.static(default=None)
    components: list[ComponentProtocol] = struct.data(factory=list)
    dirichlet: Dirichlet = struct.data(factory=Dirichlet)
    dofs: DOFs = struct.data(factory=DOFsArray)
    region: Region = struct.data(default=None)

    @classmethod
    def from_pyvista(
        cls, mesh: pv.DataSet, *, collision: bool = False, grad: bool = False
    ) -> Self:
        geometry: Geometry = Geometry.from_pyvista(mesh)
        return cls.from_geometry(geometry, collision=collision, grad=grad)

    @classmethod
    def from_geometry(
        cls, geometry: Geometry, *, collision: bool = False, grad: bool = False
    ) -> Self:
        region: Region = Region.from_geometry(geometry, grad=grad)
        return cls.from_region(region, collision=collision)

__repr__ ¤

__repr__() -> str
Source code in src/liblaf/apple/sim/actor/actor.py
43
44
@classmethod
def from_region(cls, region: Region, *, collision: bool = False) -> Self:

boundary ¤

boundary() -> Actor
Source code in src/liblaf/apple/sim/actor/actor.py
167
168
def boundary(self) -> "Actor":
    raise NotImplementedError

evolve ¤

evolve(**changes) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
46
47
self = self.update(
    displacement=jnp.zeros((region.n_points, region.dim)),

from_geometry classmethod ¤

from_geometry(
    geometry: Geometry,
    *,
    collision: bool = False,
    grad: bool = False,
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
36
37
38
39
40
41
@classmethod
def from_geometry(
    cls, geometry: Geometry, *, collision: bool = False, grad: bool = False
) -> Self:
    region: Region = Region.from_geometry(geometry, grad=grad)
    return cls.from_region(region, collision=collision)

from_pyvista classmethod ¤

from_pyvista(
    mesh: DataSet,
    *,
    collision: bool = False,
    grad: bool = False,
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
29
30
31
32
33
34
@classmethod
def from_pyvista(
    cls, mesh: pv.DataSet, *, collision: bool = False, grad: bool = False
) -> Self:
    geometry: Geometry = Geometry.from_pyvista(mesh)
    return cls.from_geometry(geometry, collision=collision, grad=grad)

from_region classmethod ¤

from_region(
    region: Region, *, collision: bool = False
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
43
44
45
46
47
48
49
50
51
52
53
@classmethod
def from_region(cls, region: Region, *, collision: bool = False) -> Self:
    self: Self = cls(region=region)
    self = self.update(
        displacement=jnp.zeros((region.n_points, region.dim)),
        velocity=jnp.zeros((region.n_points, region.dim)),
        force=jnp.zeros((region.n_points, region.dim)),
    )
    if collision:
        self = self.with_collision_mesh()
    return self

make_field ¤

make_field(x: Float[ArrayLike, 'points dim']) -> Field
Source code in src/liblaf/apple/sim/actor/actor.py
160
161
def make_field(self, x: Float[ArrayLike, "points dim"]) -> Field:
    return Field.from_region(self.region, x)

pre_optim_iter ¤

pre_optim_iter(
    displacement: Float[ArrayLike, "points dim"]
    | None = None,
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
132
133
134
135
136
137
138
139
def pre_optim_iter(
    self, displacement: Float[ArrayLike, "points dim"] | None = None
) -> Self:
    actor: Self = self.update(displacement)
    if actor.collision_mesh is not None:
        actor.collision_mesh.points = wp.from_jax(actor.positions, dtype=wp.vec3)
        actor.collision_mesh.refit()
    return actor

pre_time_step ¤

pre_time_step() -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
129
130
def pre_time_step(self) -> Self:
    return self

set_dirichlet ¤

set_dirichlet(dirichlet: Dirichlet) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
174
175
176
177
178
def set_dirichlet(self, dirichlet: Dirichlet) -> Self:
    actor: Self = self
    actor = actor.evolve(dirichlet=dirichlet)
    actor = actor.update(displacement=dirichlet.apply(actor.displacement))
    return actor

set_field_data ¤

set_field_data(
    name: str, value: Shaped[ArrayLike, ...]
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
184
185
186
def set_field_data(self, name: str, value: Shaped[ArrayLike, "..."]) -> Self:
    field_data: GeometryAttributes = self.field_data.set(name, value)
    return self.tree_at(lambda self: self.field_data, field_data)

set_point_data ¤

set_point_data(
    name: str, value: Shaped[ArrayLike, "points dim"]
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
180
181
182
def set_point_data(self, name: str, value: Shaped[ArrayLike, "points dim"]) -> Self:
    point_data: GeometryAttributes = self.point_data.set(name, value)
    return self.tree_at(lambda self: self.point_data, point_data)

to_pyvista ¤

to_pyvista(*, attributes: bool = True) -> DataSet
Source code in src/liblaf/apple/sim/actor/actor.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
def to_pyvista(self, *, attributes: bool = True) -> pv.DataSet:
    mesh: pv.DataSet = self.geometry.to_pyvista(attributes=attributes)
    if attributes:
        dirichlet_values: Float[np.ndarray, "points dim"] = np.zeros(
            (mesh.n_points, self.dim)
        )
        dirichlet_values = np.asarray(self.dirichlet.apply(dirichlet_values))
        dirichlet_mask: Bool[np.ndarray, "points dim"] = np.zeros(
            (mesh.n_points, self.dim), dtype=bool
        )
        dirichlet_mask = np.asarray(self.dirichlet.mask(dirichlet_mask), dtype=bool)
        mesh.point_data["dirichlet-values"] = dirichlet_values
        mesh.point_data["dirichlet-mask"] = dirichlet_mask
    return mesh

to_warp ¤

to_warp(**kwargs) -> Mesh
Source code in src/liblaf/apple/sim/actor/actor.py
234
235
236
237
238
239
240
def to_warp(self, **kwargs) -> wp.Mesh:
    mesh: wp.Mesh = wp.Mesh(
        wp.from_jax(self.positions, dtype=wp.vec3),
        wp.from_jax(self.geometry.cells.ravel(), dtype=wp.int32),
        **kwargs,
    )
    return mesh

tree_at ¤

tree_at(
    where: Callable[[Self], Node | Sequence[Node]],
    replace: Any | Sequence[Any] = ...,
    replace_fn: Callable[[Node], Any] = ...,
    is_leaf: Callable[[Any], bool] | None = None,
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
        force=jnp.zeros((region.n_points, region.dim)),
    )
    if collision:
        self = self.with_collision_mesh()
    return self

# region Structure

@property
def element(self) -> Element:
    return self.region.element

@property
def geometry(self) -> Geometry:
    return self.region.geometry

update ¤

update(
    displacement: Float[ArrayLike, "points dim"]
    | None = None,
    velocity: Float[ArrayLike, "points dim"] | None = None,
    force: Float[ArrayLike, "points dim"] | None = None,
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
def update(
    self,
    displacement: Float[ArrayLike, "points dim"] | None = None,
    velocity: Float[ArrayLike, "points dim"] | None = None,
    force: Float[ArrayLike, "points dim"] | None = None,
) -> Self:
    actor: Self = self
    if displacement is not None:
        actor = actor.set_point_data("displacement", displacement)
    if velocity is not None:
        actor = actor.set_point_data("velocity", velocity)
    if force is not None:
        actor = actor.set_point_data("force", force)
    return actor

update_field_data ¤

update_field_data(
    updates: Mapping[str, Shaped[ArrayLike, ...]],
    /,
    **kwargs: Shaped[ArrayLike, ...],
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
197
198
199
200
201
202
203
204
def update_field_data(
    self,
    updates: Mapping[str, Shaped[ArrayLike, "..."]],
    /,
    **kwargs: Shaped[ArrayLike, "..."],
) -> Self:
    field_data: GeometryAttributes = self.field_data.update(updates, **kwargs)
    return self.tree_at(lambda self: self.field_data, replace=field_data)

update_point_data ¤

update_point_data(
    updates: Mapping[str, Shaped[ArrayLike, "points ..."]],
    /,
    **kwargs: Shaped[ArrayLike, "points ..."],
) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
188
189
190
191
192
193
194
195
def update_point_data(
    self,
    updates: Mapping[str, Shaped[ArrayLike, "points ..."]],
    /,
    **kwargs: Shaped[ArrayLike, "points ..."],
) -> Self:
    point_data: GeometryAttributes = self.point_data.update(updates, **kwargs)
    return self.tree_at(lambda self: self.point_data, replace=point_data)

with_collision_mesh ¤

with_collision_mesh() -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
206
207
208
209
210
def with_collision_mesh(self) -> Self:
    if self.collision_mesh is not None:
        return self
    mesh: wp.Mesh = self.to_warp()
    return self.evolve(collision_mesh=mesh)

with_dofs ¤

with_dofs(dofs: DOFs) -> Self
Source code in src/liblaf/apple/sim/actor/actor.py
212
213
def with_dofs(self, dofs: DOFs) -> Self:
    return self.evolve(dofs=dofs)