Skip to content

liblaf.apple.warp.energies.elastic ¤

Modules:

Classes:

Arap ¤

Bases: Hyperelastic


              flowchart TD
              liblaf.apple.warp.energies.elastic.Arap[Arap]
              liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic[Hyperelastic]
              liblaf.apple.warp.model._energy.WarpEnergy[WarpEnergy]
              liblaf.apple.utils._id_mixin.IdMixin[IdMixin]

                              liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic --> liblaf.apple.warp.energies.elastic.Arap
                                liblaf.apple.warp.model._energy.WarpEnergy --> liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic
                                liblaf.apple.utils._id_mixin.IdMixin --> liblaf.apple.warp.model._energy.WarpEnergy
                




              click liblaf.apple.warp.energies.elastic.Arap href "" "liblaf.apple.warp.energies.elastic.Arap"
              click liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic href "" "liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic"
              click liblaf.apple.warp.model._energy.WarpEnergy href "" "liblaf.apple.warp.model._energy.WarpEnergy"
              click liblaf.apple.utils._id_mixin.IdMixin href "" "liblaf.apple.utils._id_mixin.IdMixin"
            

Parameters:

  • id ¤

    (str, default: <dynamic> ) –
  • requires_grad ¤

    (Sequence[str], default: () ) –
  • cells ¤

    (Integer[array, 'c a']) –
  • dhdX ¤

    (Integer[array, 'c q a J']) –
  • dV ¤

    (Integer[array, 'c q']) –
  • params ¤

    (Struct) –
  • clamp_hess_diag ¤

    (bool, default: True ) –
  • clamp_hess_quad ¤

    (bool, default: True ) –
  • clamp_lambda ¤

    (bool, default: True ) –

Classes:

Methods:

Attributes:

cells instance-attribute ¤

cells: Integer[array, 'c a']

clamp_hess_diag class-attribute instance-attribute ¤

clamp_hess_diag: bool = True

clamp_hess_quad class-attribute instance-attribute ¤

clamp_hess_quad: bool = True

clamp_lambda class-attribute instance-attribute ¤

clamp_lambda: bool = True

dV instance-attribute ¤

dV: Integer[array, 'c q']

dhdX instance-attribute ¤

dhdX: Integer[array, 'c q a J']

fun_kernel cached property ¤

fun_kernel: Kernel

grad_and_hess_diag_kernel cached property ¤

grad_and_hess_diag_kernel: Kernel

grad_kernel cached property ¤

grad_kernel: Kernel

hess_diag_kernel cached property ¤

hess_diag_kernel: Kernel

hess_prod_kernel cached property ¤

hess_prod_kernel: Kernel

hess_quad_kernel cached property ¤

hess_quad_kernel: Kernel

id class-attribute instance-attribute ¤

id: str = field(
    default=Factory(_default_id, takes_self=True),
    kw_only=True,
)

n_cells property ¤

n_cells: int

n_quadrature_points property ¤

n_quadrature_points: int

params instance-attribute ¤

params: Params

requires_grad class-attribute instance-attribute ¤

requires_grad: Sequence[str] = field(
    default=(), kw_only=True
)

value_and_grad_kernel cached property ¤

value_and_grad_kernel: Kernel

Params ¤

Attributes:

mu instance-attribute ¤

mu: array(dtype=float_)

energy_density_func staticmethod ¤

energy_density_func(
    F: mat33, params: ParamsElem
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap.py
39
40
41
42
43
44
45
46
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_func(F: mat33, params: ParamsElem) -> scalar:
    R, _ = math.polar_rv(F)
    Psi = F.dtype(0.5) * params.mu * math.fro_norm_square(F - R)
    return Psi

energy_density_hess_diag_func staticmethod ¤

energy_density_hess_diag_func(
    F: mat33,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap.py
61
62
63
64
65
66
67
68
69
70
71
72
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_diag_func(
    F: mat33, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    U, s, V = math.svd_rv(F)  # mat33, vec3, mat33
    h4_diag = func.h4_diag(dhdX, U, s, V, clamp=clamp)  # mat43
    h5_diag = func.h5_diag(dhdX)  # mat43
    h_diag = -F.dtype(2.0) * h4_diag + h5_diag  # mat43
    return F.dtype(0.5) * params.mu * h_diag  # mat43

energy_density_hess_prod_func staticmethod ¤

energy_density_hess_prod_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap.py
74
75
76
77
78
79
80
81
82
83
84
85
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_prod_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    U, s, V = math.svd_rv(F)  # mat33, vec3, mat33
    h4_prod = func.h4_prod(p, dhdX, U, s, V, clamp=clamp)  # mat43
    h5_prod = func.h5_prod(p, dhdX)  # mat43
    h_prod = -F.dtype(2.0) * h4_prod + h5_prod  # mat43
    return F.dtype(0.5) * params.mu * h_prod  # mat43

energy_density_hess_quad_func staticmethod ¤

energy_density_hess_quad_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap.py
87
88
89
90
91
92
93
94
95
96
97
98
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_quad_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> scalar:
    U, s, V = math.svd_rv(F)  # mat33, vec3, mat33
    h4_quad = func.h4_quad(p, dhdX, U, s, V, clamp=clamp)  # float
    h5_quad = func.h5_quad(p, dhdX)  # float
    h_quad = -F.dtype(2.0) * h4_quad + h5_quad
    return F.dtype(0.5) * params.mu * h_quad

first_piola_kirchhoff_stress_func staticmethod ¤

first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap.py
48
49
50
51
52
53
54
55
56
57
58
59
@override
@staticmethod
@no_type_check
@wp.func
def first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33:
    R, _ = math.polar_rv(F)
    g1 = func.g1(R)  # mat33
    g2 = func.g2(F)  # mat33
    PK1 = F.dtype(0.5) * params.mu * (g2 - F.dtype(2.0) * g1)  # mat33
    return PK1

from_pyvista classmethod ¤

from_pyvista(
    obj: DataObject,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
59
60
61
62
@classmethod
def from_pyvista(cls, obj: pv.DataObject, **kwargs) -> Self:
    region = Region.from_pyvista(obj, grad=True)
    return cls.from_region(region, **kwargs)

from_region classmethod ¤

from_region(
    region: Region,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
76
77
78
79
80
81
82
83
84
85
86
87
88
@classmethod
def from_region(
    cls, region: Region, *, requires_grad: Sequence[str] = (), **kwargs
) -> Self:
    self: Self = cls(
        cells=wpu.to_warp(region.cells, wpt.vec4i),
        dhdX=wpu.to_warp(region.dhdX, wpt.mat43),
        dV=wpu.to_warp(region.dV, wpt.float_),
        params=cls.make_params(region, requires_grad),
        requires_grad=requires_grad,
        **kwargs,
    )
    return self

fun ¤

fun(u: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
110
111
112
113
114
115
116
117
@override
def fun(self, u: Vector, output: Scalar) -> None:
    wp.launch(
        self.fun_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

get_cell_params staticmethod ¤

get_cell_params(params: Params, cid: int) -> ParamsElem
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap.py
32
33
34
35
36
37
@override
@staticmethod
@no_type_check
@wp.func
def get_cell_params(params: Params, cid: int) -> ParamsElem:
    return Arap.ParamsElem(mu=params.mu[cid])

grad ¤

grad(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
119
120
121
122
123
124
125
126
@override
def grad(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

grad_and_hess_diag ¤

grad_and_hess_diag(
    u: Vector, grad: Vector, hess_diag: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
179
180
181
182
183
184
185
186
@override
def grad_and_hess_diag(self, u: Vector, grad: Vector, hess_diag: Vector) -> None:
    wp.launch(
        self.grad_and_hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[grad, hess_diag],
    )

hess_diag ¤

hess_diag(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
128
129
130
131
132
133
134
135
@override
def hess_diag(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_prod ¤

hess_prod(u: Vector, p: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
137
138
139
140
141
142
143
144
@override
def hess_prod(self, u: Vector, p: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_prod_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_quad ¤

hess_quad(u: Vector, p: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
146
147
148
149
150
151
152
153
@override
def hess_quad(self, u: Vector, p: Vector, output: Scalar) -> None:
    wp.launch(
        self.hess_quad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

make_params classmethod ¤

make_params(
    region: Region, requires_grad: Sequence[str] = ()
) -> Params
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
90
91
92
93
94
@classmethod
@no_type_check
def make_params(cls, region: Region, requires_grad: Sequence[str] = ()) -> Params:
    fields: Mapping[str, wp.array] = cls._params_fields_from_region(region)
    return cls._params_from_fields(fields, requires_grad)

mixed_derivative_prod ¤

mixed_derivative_prod(
    u: array, p: array
) -> dict[str, array]
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
@override
def mixed_derivative_prod(self, u: wp.array, p: wp.array) -> dict[str, wp.array]:
    if not self.requires_grad:
        return {}
    for name in self.requires_grad:
        getattr(self.params, name).grad.zero_()
    output: wp.array = wp.zeros_like(u)
    with wp.Tape() as tape:
        self.grad(u, output)
    tape.backward(grads={output: p})
    outputs: dict[str, wp.array] = {
        name: getattr(self.params, name).grad for name in self.requires_grad
    }
    return outputs

update ¤

update(u: Vector) -> None
Source code in src/liblaf/apple/warp/model/_energy.py
19
20
def update(self, u: Vector) -> None:
    pass

update_params ¤

update_params(params: EnergyParams) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
104
105
106
107
108
@override
def update_params(self, params: EnergyParams) -> None:
    for name, value in params.items():
        param: wp.array = getattr(self.params, name)
        wp.copy(param, wpu.to_warp(value, param.dtype))

value_and_grad ¤

value_and_grad(
    u: Vector, value: Scalar, grad: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
170
171
172
173
174
175
176
177
@override
def value_and_grad(self, u: Vector, value: Scalar, grad: Vector) -> None:
    wp.launch(
        self.value_and_grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[value, grad],
    )

ArapActive ¤

Bases: Hyperelastic


              flowchart TD
              liblaf.apple.warp.energies.elastic.ArapActive[ArapActive]
              liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic[Hyperelastic]
              liblaf.apple.warp.model._energy.WarpEnergy[WarpEnergy]
              liblaf.apple.utils._id_mixin.IdMixin[IdMixin]

                              liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic --> liblaf.apple.warp.energies.elastic.ArapActive
                                liblaf.apple.warp.model._energy.WarpEnergy --> liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic
                                liblaf.apple.utils._id_mixin.IdMixin --> liblaf.apple.warp.model._energy.WarpEnergy
                




              click liblaf.apple.warp.energies.elastic.ArapActive href "" "liblaf.apple.warp.energies.elastic.ArapActive"
              click liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic href "" "liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic"
              click liblaf.apple.warp.model._energy.WarpEnergy href "" "liblaf.apple.warp.model._energy.WarpEnergy"
              click liblaf.apple.utils._id_mixin.IdMixin href "" "liblaf.apple.utils._id_mixin.IdMixin"
            

Parameters:

  • id ¤

    (str, default: <dynamic> ) –
  • requires_grad ¤

    (Sequence[str], default: () ) –
  • cells ¤

    (Integer[array, 'c a']) –
  • dhdX ¤

    (Integer[array, 'c q a J']) –
  • dV ¤

    (Integer[array, 'c q']) –
  • params ¤

    (Struct) –
  • clamp_hess_diag ¤

    (bool, default: True ) –
  • clamp_hess_quad ¤

    (bool, default: True ) –
  • clamp_lambda ¤

    (bool, default: True ) –

Classes:

Methods:

Attributes:

cells instance-attribute ¤

cells: Integer[array, 'c a']

clamp_hess_diag class-attribute instance-attribute ¤

clamp_hess_diag: bool = True

clamp_hess_quad class-attribute instance-attribute ¤

clamp_hess_quad: bool = True

clamp_lambda class-attribute instance-attribute ¤

clamp_lambda: bool = True

dV instance-attribute ¤

dV: Integer[array, 'c q']

dhdX instance-attribute ¤

dhdX: Integer[array, 'c q a J']

fun_kernel cached property ¤

fun_kernel: Kernel

grad_and_hess_diag_kernel cached property ¤

grad_and_hess_diag_kernel: Kernel

grad_kernel cached property ¤

grad_kernel: Kernel

hess_diag_kernel cached property ¤

hess_diag_kernel: Kernel

hess_prod_kernel cached property ¤

hess_prod_kernel: Kernel

hess_quad_kernel cached property ¤

hess_quad_kernel: Kernel

id class-attribute instance-attribute ¤

id: str = field(
    default=Factory(_default_id, takes_self=True),
    kw_only=True,
)

n_cells property ¤

n_cells: int

n_quadrature_points property ¤

n_quadrature_points: int

params instance-attribute ¤

params: Params

requires_grad class-attribute instance-attribute ¤

requires_grad: Sequence[str] = field(
    default=(), kw_only=True
)

value_and_grad_kernel cached property ¤

value_and_grad_kernel: Kernel

Params ¤

Attributes:

activation instance-attribute ¤

activation: array(dtype=vec6)

mu instance-attribute ¤

mu: array(dtype=float_)

muscle_fraction instance-attribute ¤

muscle_fraction: array(dtype=float_)

energy_density_func staticmethod ¤

energy_density_func(
    F: mat33, params: ParamsElem
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_active.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_func(F: mat33, params: ParamsElem) -> scalar:
    Psi_active = ArapMuscle.energy_density_func(
        F, ArapActive._arap_active_params(params)
    )  # float
    Psi_passive = Arap.energy_density_func(
        F, ArapActive._arap_params(params)
    )  # float
    Psi = (
        params.muscle_fraction * Psi_active
        + (F.dtype(1.0) - params.muscle_fraction) * Psi_passive
    )  # float
    return Psi

energy_density_hess_diag_func staticmethod ¤

energy_density_hess_diag_func(
    F: mat33,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_active.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_diag_func(
    F: mat33, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    diag_active = ArapMuscle.energy_density_hess_diag_func(
        F, dhdX, ArapActive._arap_active_params(params), clamp=clamp
    )  # mat43
    diag_passive = Arap.energy_density_hess_diag_func(
        F, dhdX, ArapActive._arap_params(params), clamp=clamp
    )  # mat43
    diag = (
        params.muscle_fraction * diag_active
        + (F.dtype(1.0) - params.muscle_fraction) * diag_passive
    )  # mat43
    return diag

energy_density_hess_prod_func staticmethod ¤

energy_density_hess_prod_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_active.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_prod_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    prod_active = ArapMuscle.energy_density_hess_prod_func(
        F, p, dhdX, ArapActive._arap_active_params(params), clamp=clamp
    )  # mat43
    prod_passive = Arap.energy_density_hess_prod_func(
        F, p, dhdX, ArapActive._arap_params(params), clamp=clamp
    )  # mat43
    prod = (
        params.muscle_fraction * prod_active
        + (F.dtype(1.0) - params.muscle_fraction) * prod_passive
    )  # mat43
    return prod

energy_density_hess_quad_func staticmethod ¤

energy_density_hess_quad_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_active.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_quad_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> scalar:
    quad_active = ArapMuscle.energy_density_hess_quad_func(
        F, p, dhdX, ArapActive._arap_active_params(params), clamp=clamp
    )
    quad_passive = Arap.energy_density_hess_quad_func(
        F, p, dhdX, ArapActive._arap_params(params), clamp=clamp
    )
    quad = (
        params.muscle_fraction * quad_active
        + (F.dtype(1.0) - params.muscle_fraction) * quad_passive
    )
    return quad

first_piola_kirchhoff_stress_func staticmethod ¤

first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_active.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@override
@staticmethod
@no_type_check
@wp.func
def first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33:
    PK1_active = ArapMuscle.first_piola_kirchhoff_stress_func(
        F, ArapActive._arap_active_params(params), clamp=clamp
    )  # mat33
    PK1_passive = Arap.first_piola_kirchhoff_stress_func(
        F, ArapActive._arap_params(params), clamp=clamp
    )  # mat33
    PK1 = (
        params.muscle_fraction * PK1_active
        + (F.dtype(1.0) - params.muscle_fraction) * PK1_passive
    )  # mat33
    return PK1

from_pyvista classmethod ¤

from_pyvista(
    obj: DataObject,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
59
60
61
62
@classmethod
def from_pyvista(cls, obj: pv.DataObject, **kwargs) -> Self:
    region = Region.from_pyvista(obj, grad=True)
    return cls.from_region(region, **kwargs)

from_region classmethod ¤

from_region(
    region: Region,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
76
77
78
79
80
81
82
83
84
85
86
87
88
@classmethod
def from_region(
    cls, region: Region, *, requires_grad: Sequence[str] = (), **kwargs
) -> Self:
    self: Self = cls(
        cells=wpu.to_warp(region.cells, wpt.vec4i),
        dhdX=wpu.to_warp(region.dhdX, wpt.mat43),
        dV=wpu.to_warp(region.dV, wpt.float_),
        params=cls.make_params(region, requires_grad),
        requires_grad=requires_grad,
        **kwargs,
    )
    return self

fun ¤

fun(u: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
110
111
112
113
114
115
116
117
@override
def fun(self, u: Vector, output: Scalar) -> None:
    wp.launch(
        self.fun_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

get_cell_params staticmethod ¤

get_cell_params(params: Params, cid: int) -> ParamsElem
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_active.py
37
38
39
40
41
42
43
44
45
46
@override
@staticmethod
@no_type_check
@wp.func
def get_cell_params(params: Params, cid: int) -> ParamsElem:
    return ArapActive.ParamsElem(
        activation=params.activation[cid],
        mu=params.mu[cid],
        muscle_fraction=params.muscle_fraction[cid],
    )

grad ¤

grad(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
119
120
121
122
123
124
125
126
@override
def grad(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

grad_and_hess_diag ¤

grad_and_hess_diag(
    u: Vector, grad: Vector, hess_diag: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
179
180
181
182
183
184
185
186
@override
def grad_and_hess_diag(self, u: Vector, grad: Vector, hess_diag: Vector) -> None:
    wp.launch(
        self.grad_and_hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[grad, hess_diag],
    )

hess_diag ¤

hess_diag(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
128
129
130
131
132
133
134
135
@override
def hess_diag(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_prod ¤

hess_prod(u: Vector, p: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
137
138
139
140
141
142
143
144
@override
def hess_prod(self, u: Vector, p: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_prod_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_quad ¤

hess_quad(u: Vector, p: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
146
147
148
149
150
151
152
153
@override
def hess_quad(self, u: Vector, p: Vector, output: Scalar) -> None:
    wp.launch(
        self.hess_quad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

make_params classmethod ¤

make_params(
    region: Region, requires_grad: Sequence[str] = ()
) -> Params
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
90
91
92
93
94
@classmethod
@no_type_check
def make_params(cls, region: Region, requires_grad: Sequence[str] = ()) -> Params:
    fields: Mapping[str, wp.array] = cls._params_fields_from_region(region)
    return cls._params_from_fields(fields, requires_grad)

mixed_derivative_prod ¤

mixed_derivative_prod(
    u: array, p: array
) -> dict[str, array]
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
@override
def mixed_derivative_prod(self, u: wp.array, p: wp.array) -> dict[str, wp.array]:
    if not self.requires_grad:
        return {}
    for name in self.requires_grad:
        getattr(self.params, name).grad.zero_()
    output: wp.array = wp.zeros_like(u)
    with wp.Tape() as tape:
        self.grad(u, output)
    tape.backward(grads={output: p})
    outputs: dict[str, wp.array] = {
        name: getattr(self.params, name).grad for name in self.requires_grad
    }
    return outputs

update ¤

update(u: Vector) -> None
Source code in src/liblaf/apple/warp/model/_energy.py
19
20
def update(self, u: Vector) -> None:
    pass

update_params ¤

update_params(params: EnergyParams) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
104
105
106
107
108
@override
def update_params(self, params: EnergyParams) -> None:
    for name, value in params.items():
        param: wp.array = getattr(self.params, name)
        wp.copy(param, wpu.to_warp(value, param.dtype))

value_and_grad ¤

value_and_grad(
    u: Vector, value: Scalar, grad: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
170
171
172
173
174
175
176
177
@override
def value_and_grad(self, u: Vector, value: Scalar, grad: Vector) -> None:
    wp.launch(
        self.value_and_grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[value, grad],
    )

ArapMuscle ¤

Bases: Arap


              flowchart TD
              liblaf.apple.warp.energies.elastic.ArapMuscle[ArapMuscle]
              liblaf.apple.warp.energies.elastic.hyperelastic._arap.Arap[Arap]
              liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic[Hyperelastic]
              liblaf.apple.warp.model._energy.WarpEnergy[WarpEnergy]
              liblaf.apple.utils._id_mixin.IdMixin[IdMixin]

                              liblaf.apple.warp.energies.elastic.hyperelastic._arap.Arap --> liblaf.apple.warp.energies.elastic.ArapMuscle
                                liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic --> liblaf.apple.warp.energies.elastic.hyperelastic._arap.Arap
                                liblaf.apple.warp.model._energy.WarpEnergy --> liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic
                                liblaf.apple.utils._id_mixin.IdMixin --> liblaf.apple.warp.model._energy.WarpEnergy
                





              click liblaf.apple.warp.energies.elastic.ArapMuscle href "" "liblaf.apple.warp.energies.elastic.ArapMuscle"
              click liblaf.apple.warp.energies.elastic.hyperelastic._arap.Arap href "" "liblaf.apple.warp.energies.elastic.hyperelastic._arap.Arap"
              click liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic href "" "liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic"
              click liblaf.apple.warp.model._energy.WarpEnergy href "" "liblaf.apple.warp.model._energy.WarpEnergy"
              click liblaf.apple.utils._id_mixin.IdMixin href "" "liblaf.apple.utils._id_mixin.IdMixin"
            

Parameters:

  • id ¤

    (str, default: <dynamic> ) –
  • requires_grad ¤

    (Sequence[str], default: () ) –
  • cells ¤

    (Integer[array, 'c a']) –
  • dhdX ¤

    (Integer[array, 'c q a J']) –
  • dV ¤

    (Integer[array, 'c q']) –
  • params ¤

    (Struct) –
  • clamp_hess_diag ¤

    (bool, default: True ) –
  • clamp_hess_quad ¤

    (bool, default: True ) –
  • clamp_lambda ¤

    (bool, default: True ) –

Classes:

Methods:

Attributes:

cells instance-attribute ¤

cells: Integer[array, 'c a']

clamp_hess_diag class-attribute instance-attribute ¤

clamp_hess_diag: bool = True

clamp_hess_quad class-attribute instance-attribute ¤

clamp_hess_quad: bool = True

clamp_lambda class-attribute instance-attribute ¤

clamp_lambda: bool = True

dV instance-attribute ¤

dV: Integer[array, 'c q']

dhdX instance-attribute ¤

dhdX: Integer[array, 'c q a J']

fun_kernel cached property ¤

fun_kernel: Kernel

grad_and_hess_diag_kernel cached property ¤

grad_and_hess_diag_kernel: Kernel

grad_kernel cached property ¤

grad_kernel: Kernel

hess_diag_kernel cached property ¤

hess_diag_kernel: Kernel

hess_prod_kernel cached property ¤

hess_prod_kernel: Kernel

hess_quad_kernel cached property ¤

hess_quad_kernel: Kernel

id class-attribute instance-attribute ¤

id: str = field(
    default=Factory(_default_id, takes_self=True),
    kw_only=True,
)

n_cells property ¤

n_cells: int

n_quadrature_points property ¤

n_quadrature_points: int

params instance-attribute ¤

params: Params

requires_grad class-attribute instance-attribute ¤

requires_grad: Sequence[str] = field(
    default=(), kw_only=True
)

value_and_grad_kernel cached property ¤

value_and_grad_kernel: Kernel

Params ¤

Attributes:

activation instance-attribute ¤

activation: array(dtype=vec6)

mu instance-attribute ¤

mu: array(dtype=float_)

energy_density_func staticmethod ¤

energy_density_func(
    F: mat33, params: ParamsElem
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_muscle.py
43
44
45
46
47
48
49
50
51
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_func(F: mat33, params: ParamsElem) -> scalar:
    A = func.make_activation_mat33(params.activation)  # mat33
    R, _ = math.polar_rv(F)
    Psi = F.dtype(0.5) * params.mu * math.fro_norm_square(F - R @ A)
    return Psi

energy_density_hess_diag_func staticmethod ¤

energy_density_hess_diag_func(
    F: mat33,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_muscle.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_diag_func(
    F: mat33, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    A = func.make_activation_mat33(params.activation)  # mat33
    U, s, V = math.svd_rv(F)  # mat33, vec3, mat33
    lambdas = func.lambdas(s, clamp=clamp)  # vec3
    Q0, Q1, Q2 = func.Qs(U, V)  # mat33, mat33, mat33
    h4_diag = (
        lambdas[0]
        * wp.cw_mul(
            func.deformation_gradient_vjp(dhdX, Q0 @ A),
            func.deformation_gradient_vjp(dhdX, Q0),
        )
        + lambdas[1]
        * wp.cw_mul(
            func.deformation_gradient_vjp(dhdX, Q1 @ A),
            func.deformation_gradient_vjp(dhdX, Q1),
        )
        + lambdas[2]
        * wp.cw_mul(
            func.deformation_gradient_vjp(dhdX, Q2 @ A),
            func.deformation_gradient_vjp(dhdX, Q2),
        )
    )  # mat43
    h5_diag = func.h5_diag(dhdX)  # mat43
    h_diag = -F.dtype(2.0) * h4_diag + h5_diag  # mat43
    return F.dtype(0.5) * params.mu * h_diag  # mat43

energy_density_hess_prod_func staticmethod ¤

energy_density_hess_prod_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_muscle.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_prod_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    A = func.make_activation_mat33(params.activation)  # mat33
    U, s, V = math.svd_rv(F)  # mat33, vec3, mat33
    lambdas = func.lambdas(s, clamp=clamp)  # vec3
    Q0, Q1, Q2 = func.Qs(U, V)  # mat33, mat33, mat33
    dFdx_p = func.deformation_gradient_jvp(dhdX, p)  # mat33
    h4_prod = (
        lambdas[0]
        * func.deformation_gradient_vjp(dhdX, Q0 @ A)
        * wp.ddot(Q0, dFdx_p)
        + lambdas[1]
        * func.deformation_gradient_vjp(dhdX, Q1 @ A)
        * wp.ddot(Q1, dFdx_p)
        + lambdas[2]
        * func.deformation_gradient_vjp(dhdX, Q2 @ A)
        * wp.ddot(Q2, dFdx_p)
    )  # mat43
    # h4_prod = func.h4_prod(p, dhdX, U, s, V, clamp=clamp)  # mat43
    h5_prod = func.h5_prod(p, dhdX)  # mat43
    h_prod = -F.dtype(2.0) * h4_prod + h5_prod  # mat43
    return F.dtype(0.5) * params.mu * h_prod  # mat43

energy_density_hess_quad_func staticmethod ¤

energy_density_hess_quad_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_muscle.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_quad_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> scalar:
    A = func.make_activation_mat33(params.activation)  # mat33
    U, s, V = math.svd_rv(F)  # mat33, vec3, mat33
    lambdas = func.lambdas(s, clamp=clamp)  # vec3
    Q0, Q1, Q2 = func.Qs(U, V)  # mat33, mat33, mat33
    h4_quad = (
        lambdas[0]
        * wp.ddot(func.deformation_gradient_vjp(dhdX, Q0 @ A), p)
        * wp.ddot(func.deformation_gradient_vjp(dhdX, Q0), p)
        + lambdas[1]
        * wp.ddot(func.deformation_gradient_vjp(dhdX, Q1 @ A), p)
        * wp.ddot(func.deformation_gradient_vjp(dhdX, Q1), p)
        + lambdas[2]
        * wp.ddot(func.deformation_gradient_vjp(dhdX, Q2 @ A), p)
        * wp.ddot(func.deformation_gradient_vjp(dhdX, Q2), p)
    )  # float
    h5_quad = func.h5_quad(p, dhdX)  # float
    h_quad = -F.dtype(2.0) * h4_quad + h5_quad
    return F.dtype(0.5) * params.mu * h_quad

first_piola_kirchhoff_stress_func staticmethod ¤

first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_muscle.py
53
54
55
56
57
58
59
60
61
62
63
@override
@staticmethod
@no_type_check
@wp.func
def first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33:
    A = func.make_activation_mat33(params.activation)  # mat33
    R, _ = math.polar_rv(F)  # mat33
    PK1 = params.mu * (F - R @ A)
    return PK1

from_pyvista classmethod ¤

from_pyvista(
    obj: DataObject,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
59
60
61
62
@classmethod
def from_pyvista(cls, obj: pv.DataObject, **kwargs) -> Self:
    region = Region.from_pyvista(obj, grad=True)
    return cls.from_region(region, **kwargs)

from_region classmethod ¤

from_region(
    region: Region,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
76
77
78
79
80
81
82
83
84
85
86
87
88
@classmethod
def from_region(
    cls, region: Region, *, requires_grad: Sequence[str] = (), **kwargs
) -> Self:
    self: Self = cls(
        cells=wpu.to_warp(region.cells, wpt.vec4i),
        dhdX=wpu.to_warp(region.dhdX, wpt.mat43),
        dV=wpu.to_warp(region.dV, wpt.float_),
        params=cls.make_params(region, requires_grad),
        requires_grad=requires_grad,
        **kwargs,
    )
    return self

fun ¤

fun(u: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
110
111
112
113
114
115
116
117
@override
def fun(self, u: Vector, output: Scalar) -> None:
    wp.launch(
        self.fun_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

get_cell_params staticmethod ¤

get_cell_params(params: Params, cid: int) -> ParamsElem
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_arap_muscle.py
34
35
36
37
38
39
40
41
@override
@staticmethod
@no_type_check
@wp.func
def get_cell_params(params: Params, cid: int) -> ParamsElem:
    return ArapMuscle.ParamsElem(
        activation=params.activation[cid], mu=params.mu[cid]
    )

grad ¤

grad(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
119
120
121
122
123
124
125
126
@override
def grad(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

grad_and_hess_diag ¤

grad_and_hess_diag(
    u: Vector, grad: Vector, hess_diag: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
179
180
181
182
183
184
185
186
@override
def grad_and_hess_diag(self, u: Vector, grad: Vector, hess_diag: Vector) -> None:
    wp.launch(
        self.grad_and_hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[grad, hess_diag],
    )

hess_diag ¤

hess_diag(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
128
129
130
131
132
133
134
135
@override
def hess_diag(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_prod ¤

hess_prod(u: Vector, p: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
137
138
139
140
141
142
143
144
@override
def hess_prod(self, u: Vector, p: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_prod_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_quad ¤

hess_quad(u: Vector, p: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
146
147
148
149
150
151
152
153
@override
def hess_quad(self, u: Vector, p: Vector, output: Scalar) -> None:
    wp.launch(
        self.hess_quad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

make_params classmethod ¤

make_params(
    region: Region, requires_grad: Sequence[str] = ()
) -> Params
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
90
91
92
93
94
@classmethod
@no_type_check
def make_params(cls, region: Region, requires_grad: Sequence[str] = ()) -> Params:
    fields: Mapping[str, wp.array] = cls._params_fields_from_region(region)
    return cls._params_from_fields(fields, requires_grad)

mixed_derivative_prod ¤

mixed_derivative_prod(
    u: array, p: array
) -> dict[str, array]
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
@override
def mixed_derivative_prod(self, u: wp.array, p: wp.array) -> dict[str, wp.array]:
    if not self.requires_grad:
        return {}
    for name in self.requires_grad:
        getattr(self.params, name).grad.zero_()
    output: wp.array = wp.zeros_like(u)
    with wp.Tape() as tape:
        self.grad(u, output)
    tape.backward(grads={output: p})
    outputs: dict[str, wp.array] = {
        name: getattr(self.params, name).grad for name in self.requires_grad
    }
    return outputs

update ¤

update(u: Vector) -> None
Source code in src/liblaf/apple/warp/model/_energy.py
19
20
def update(self, u: Vector) -> None:
    pass

update_params ¤

update_params(params: EnergyParams) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
104
105
106
107
108
@override
def update_params(self, params: EnergyParams) -> None:
    for name, value in params.items():
        param: wp.array = getattr(self.params, name)
        wp.copy(param, wpu.to_warp(value, param.dtype))

value_and_grad ¤

value_and_grad(
    u: Vector, value: Scalar, grad: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
170
171
172
173
174
175
176
177
@override
def value_and_grad(self, u: Vector, value: Scalar, grad: Vector) -> None:
    wp.launch(
        self.value_and_grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[value, grad],
    )

Hyperelastic ¤

Bases: WarpEnergy


              flowchart TD
              liblaf.apple.warp.energies.elastic.Hyperelastic[Hyperelastic]
              liblaf.apple.warp.model._energy.WarpEnergy[WarpEnergy]
              liblaf.apple.utils._id_mixin.IdMixin[IdMixin]

                              liblaf.apple.warp.model._energy.WarpEnergy --> liblaf.apple.warp.energies.elastic.Hyperelastic
                                liblaf.apple.utils._id_mixin.IdMixin --> liblaf.apple.warp.model._energy.WarpEnergy
                



              click liblaf.apple.warp.energies.elastic.Hyperelastic href "" "liblaf.apple.warp.energies.elastic.Hyperelastic"
              click liblaf.apple.warp.model._energy.WarpEnergy href "" "liblaf.apple.warp.model._energy.WarpEnergy"
              click liblaf.apple.utils._id_mixin.IdMixin href "" "liblaf.apple.utils._id_mixin.IdMixin"
            

Parameters:

  • id ¤

    (str, default: <dynamic> ) –
  • requires_grad ¤

    (Sequence[str], default: () ) –
  • cells ¤

    (Integer[array, 'c a']) –
  • dhdX ¤

    (Integer[array, 'c q a J']) –
  • dV ¤

    (Integer[array, 'c q']) –
  • params ¤

    (Struct) –
  • clamp_hess_diag ¤

    (bool, default: True ) –
  • clamp_hess_quad ¤

    (bool, default: True ) –
  • clamp_lambda ¤

    (bool, default: True ) –

Classes:

Methods:

Attributes:

cells instance-attribute ¤

cells: Integer[array, 'c a']

clamp_hess_diag class-attribute instance-attribute ¤

clamp_hess_diag: bool = True

clamp_hess_quad class-attribute instance-attribute ¤

clamp_hess_quad: bool = True

clamp_lambda class-attribute instance-attribute ¤

clamp_lambda: bool = True

dV instance-attribute ¤

dV: Integer[array, 'c q']

dhdX instance-attribute ¤

dhdX: Integer[array, 'c q a J']

fun_kernel cached property ¤

fun_kernel: Kernel

grad_and_hess_diag_kernel cached property ¤

grad_and_hess_diag_kernel: Kernel

grad_kernel cached property ¤

grad_kernel: Kernel

hess_diag_kernel cached property ¤

hess_diag_kernel: Kernel

hess_prod_kernel cached property ¤

hess_prod_kernel: Kernel

hess_quad_kernel cached property ¤

hess_quad_kernel: Kernel

id class-attribute instance-attribute ¤

id: str = field(
    default=Factory(_default_id, takes_self=True),
    kw_only=True,
)

n_cells property ¤

n_cells: int

n_quadrature_points property ¤

n_quadrature_points: int

params instance-attribute ¤

params: Params

requires_grad class-attribute instance-attribute ¤

requires_grad: Sequence[str] = field(
    default=(), kw_only=True
)

value_and_grad_kernel cached property ¤

value_and_grad_kernel: Kernel

Params ¤

ParamsElem ¤

energy_density_func staticmethod ¤

energy_density_func(
    F: mat33, params: ParamsElem
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
450
451
452
453
454
@staticmethod
@no_type_check
@wp.func
def energy_density_func(F: mat33, params: ParamsElem) -> scalar:
    raise NotImplementedError

energy_density_hess_diag_func staticmethod ¤

energy_density_hess_diag_func(
    F: mat33,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
464
465
466
467
468
469
470
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_diag_func(
    F: mat33, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    raise NotImplementedError

energy_density_hess_prod_func staticmethod ¤

energy_density_hess_prod_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
472
473
474
475
476
477
478
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_prod_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    raise NotImplementedError

energy_density_hess_quad_func staticmethod ¤

energy_density_hess_quad_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
480
481
482
483
484
485
486
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_quad_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> scalar:
    raise NotImplementedError

first_piola_kirchhoff_stress_func staticmethod ¤

first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
456
457
458
459
460
461
462
@staticmethod
@no_type_check
@wp.func
def first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33:
    raise NotImplementedError

from_pyvista classmethod ¤

from_pyvista(
    obj: DataObject,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
59
60
61
62
@classmethod
def from_pyvista(cls, obj: pv.DataObject, **kwargs) -> Self:
    region = Region.from_pyvista(obj, grad=True)
    return cls.from_region(region, **kwargs)

from_region classmethod ¤

from_region(
    region: Region,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
76
77
78
79
80
81
82
83
84
85
86
87
88
@classmethod
def from_region(
    cls, region: Region, *, requires_grad: Sequence[str] = (), **kwargs
) -> Self:
    self: Self = cls(
        cells=wpu.to_warp(region.cells, wpt.vec4i),
        dhdX=wpu.to_warp(region.dhdX, wpt.mat43),
        dV=wpu.to_warp(region.dV, wpt.float_),
        params=cls.make_params(region, requires_grad),
        requires_grad=requires_grad,
        **kwargs,
    )
    return self

fun ¤

fun(u: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
110
111
112
113
114
115
116
117
@override
def fun(self, u: Vector, output: Scalar) -> None:
    wp.launch(
        self.fun_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

get_cell_params staticmethod ¤

get_cell_params(params: Params, cid: int) -> ParamsElem
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
444
445
446
447
448
@staticmethod
@no_type_check
@wp.func
def get_cell_params(params: Params, cid: int) -> ParamsElem:
    raise NotImplementedError

grad ¤

grad(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
119
120
121
122
123
124
125
126
@override
def grad(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

grad_and_hess_diag ¤

grad_and_hess_diag(
    u: Vector, grad: Vector, hess_diag: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
179
180
181
182
183
184
185
186
@override
def grad_and_hess_diag(self, u: Vector, grad: Vector, hess_diag: Vector) -> None:
    wp.launch(
        self.grad_and_hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[grad, hess_diag],
    )

hess_diag ¤

hess_diag(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
128
129
130
131
132
133
134
135
@override
def hess_diag(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_prod ¤

hess_prod(u: Vector, p: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
137
138
139
140
141
142
143
144
@override
def hess_prod(self, u: Vector, p: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_prod_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_quad ¤

hess_quad(u: Vector, p: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
146
147
148
149
150
151
152
153
@override
def hess_quad(self, u: Vector, p: Vector, output: Scalar) -> None:
    wp.launch(
        self.hess_quad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

make_params classmethod ¤

make_params(
    region: Region, requires_grad: Sequence[str] = ()
) -> Params
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
90
91
92
93
94
@classmethod
@no_type_check
def make_params(cls, region: Region, requires_grad: Sequence[str] = ()) -> Params:
    fields: Mapping[str, wp.array] = cls._params_fields_from_region(region)
    return cls._params_from_fields(fields, requires_grad)

mixed_derivative_prod ¤

mixed_derivative_prod(
    u: array, p: array
) -> dict[str, array]
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
@override
def mixed_derivative_prod(self, u: wp.array, p: wp.array) -> dict[str, wp.array]:
    if not self.requires_grad:
        return {}
    for name in self.requires_grad:
        getattr(self.params, name).grad.zero_()
    output: wp.array = wp.zeros_like(u)
    with wp.Tape() as tape:
        self.grad(u, output)
    tape.backward(grads={output: p})
    outputs: dict[str, wp.array] = {
        name: getattr(self.params, name).grad for name in self.requires_grad
    }
    return outputs

update ¤

update(u: Vector) -> None
Source code in src/liblaf/apple/warp/model/_energy.py
19
20
def update(self, u: Vector) -> None:
    pass

update_params ¤

update_params(params: EnergyParams) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
104
105
106
107
108
@override
def update_params(self, params: EnergyParams) -> None:
    for name, value in params.items():
        param: wp.array = getattr(self.params, name)
        wp.copy(param, wpu.to_warp(value, param.dtype))

value_and_grad ¤

value_and_grad(
    u: Vector, value: Scalar, grad: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
170
171
172
173
174
175
176
177
@override
def value_and_grad(self, u: Vector, value: Scalar, grad: Vector) -> None:
    wp.launch(
        self.value_and_grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[value, grad],
    )

Phace ¤

Bases: Hyperelastic


              flowchart TD
              liblaf.apple.warp.energies.elastic.Phace[Phace]
              liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic[Hyperelastic]
              liblaf.apple.warp.model._energy.WarpEnergy[WarpEnergy]
              liblaf.apple.utils._id_mixin.IdMixin[IdMixin]

                              liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic --> liblaf.apple.warp.energies.elastic.Phace
                                liblaf.apple.warp.model._energy.WarpEnergy --> liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic
                                liblaf.apple.utils._id_mixin.IdMixin --> liblaf.apple.warp.model._energy.WarpEnergy
                




              click liblaf.apple.warp.energies.elastic.Phace href "" "liblaf.apple.warp.energies.elastic.Phace"
              click liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic href "" "liblaf.apple.warp.energies.elastic.hyperelastic._base.Hyperelastic"
              click liblaf.apple.warp.model._energy.WarpEnergy href "" "liblaf.apple.warp.model._energy.WarpEnergy"
              click liblaf.apple.utils._id_mixin.IdMixin href "" "liblaf.apple.utils._id_mixin.IdMixin"
            

Parameters:

  • id ¤

    (str, default: <dynamic> ) –
  • requires_grad ¤

    (Sequence[str], default: () ) –
  • cells ¤

    (Integer[array, 'c a']) –
  • dhdX ¤

    (Integer[array, 'c q a J']) –
  • dV ¤

    (Integer[array, 'c q']) –
  • params ¤

    (Struct) –
  • clamp_hess_diag ¤

    (bool, default: True ) –
  • clamp_hess_quad ¤

    (bool, default: True ) –
  • clamp_lambda ¤

    (bool, default: True ) –

Classes:

Methods:

Attributes:

cells instance-attribute ¤

cells: Integer[array, 'c a']

clamp_hess_diag class-attribute instance-attribute ¤

clamp_hess_diag: bool = True

clamp_hess_quad class-attribute instance-attribute ¤

clamp_hess_quad: bool = True

clamp_lambda class-attribute instance-attribute ¤

clamp_lambda: bool = True

dV instance-attribute ¤

dV: Integer[array, 'c q']

dhdX instance-attribute ¤

dhdX: Integer[array, 'c q a J']

fun_kernel cached property ¤

fun_kernel: Kernel

grad_and_hess_diag_kernel cached property ¤

grad_and_hess_diag_kernel: Kernel

grad_kernel cached property ¤

grad_kernel: Kernel

hess_diag_kernel cached property ¤

hess_diag_kernel: Kernel

hess_prod_kernel cached property ¤

hess_prod_kernel: Kernel

hess_quad_kernel cached property ¤

hess_quad_kernel: Kernel

id class-attribute instance-attribute ¤

id: str = field(
    default=Factory(_default_id, takes_self=True),
    kw_only=True,
)

n_cells property ¤

n_cells: int

n_quadrature_points property ¤

n_quadrature_points: int

params instance-attribute ¤

params: Params

requires_grad class-attribute instance-attribute ¤

requires_grad: Sequence[str] = field(
    default=(), kw_only=True
)

value_and_grad_kernel cached property ¤

value_and_grad_kernel: Kernel

Params ¤

Attributes:

activation instance-attribute ¤

activation: array(dtype=vec6)

lambda_ instance-attribute ¤

lambda_: array(dtype=float_)

mu instance-attribute ¤

mu: array(dtype=float_)

muscle_fraction instance-attribute ¤

muscle_fraction: array(dtype=float_)

energy_density_func staticmethod ¤

energy_density_func(
    F: mat33, params: ParamsElem
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_phace.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_func(F: mat33, params: ParamsElem) -> scalar:
    _1 = F.dtype(1.0)
    _2 = F.dtype(2.0)
    J = func.I3(F)  # float
    Psi_ARAP_active = ArapMuscle.energy_density_func(
        F, Phace._arap_active_params(params)
    )  # float
    Psi_ARAP_passive = Arap.energy_density_func(
        F, Phace._arap_params(params)
    )  # float
    Psi_ARAP = (
        params.muscle_fraction * Psi_ARAP_active
        + (_1 - params.muscle_fraction) * Psi_ARAP_passive
    )  # float
    Psi_VP = params.lambda_ * math.square(J - _1)  # float
    Psi = _2 * Psi_ARAP + Psi_VP  # float
    return Psi

energy_density_hess_diag_func staticmethod ¤

energy_density_hess_diag_func(
    F: mat33,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_phace.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_diag_func(
    F: mat33, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    _1 = F.dtype(1.0)
    _2 = F.dtype(2.0)
    J = func.I3(F)  # float
    g3 = func.g3(F)  # mat33
    diag_arap_active = ArapMuscle.energy_density_hess_diag_func(
        F, dhdX, Phace._arap_active_params(params), clamp=clamp
    )  # mat43
    diag_arap_passive = Arap.energy_density_hess_diag_func(
        F, dhdX, Phace._arap_params(params), clamp=clamp
    )  # mat43
    diag_arap = (
        params.muscle_fraction * diag_arap_active
        + (_1 - params.muscle_fraction) * diag_arap_passive
    )  # mat43
    d2Psi_dI32 = _2 * params.lambda_  # float
    dPsi_dI3 = _2 * params.lambda_ * (J - _1)  # float
    h3_diag = func.h3_diag(dhdX, g3)  # mat43
    h6_diag = func.h6_diag(dhdX, F)  # mat43
    diag_vp = d2Psi_dI32 * h3_diag + dPsi_dI3 * h6_diag  # mat43
    diag = _2 * diag_arap + diag_vp  # mat43
    return diag

energy_density_hess_prod_func staticmethod ¤

energy_density_hess_prod_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_phace.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_prod_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> mat33:
    _1 = F.dtype(1.0)
    _2 = F.dtype(2.0)
    J = func.I3(F)  # float
    g3 = func.g3(F)  # mat33
    prod_arap_active = ArapMuscle.energy_density_hess_prod_func(
        F, p, dhdX, Phace._arap_active_params(params), clamp=clamp
    )  # mat43
    prod_arap_passive = Arap.energy_density_hess_prod_func(
        F, p, dhdX, Phace._arap_params(params), clamp=clamp
    )  # mat43
    prod_arap = (
        params.muscle_fraction * prod_arap_active
        + (_1 - params.muscle_fraction) * prod_arap_passive
    )  # mat43
    d2Psi_dI32 = _2 * params.lambda_  # float
    dPsi_dI3 = _2 * params.lambda_ * (J - _1)  # float
    h3_prod = func.h3_prod(p, dhdX, g3)  # mat43
    h6_prod = func.h6_prod(p, dhdX, F)  # mat43
    prod_vp = d2Psi_dI32 * h3_prod + dPsi_dI3 * h6_prod  # mat43
    prod = _2 * prod_arap + prod_vp  # mat43
    return prod

energy_density_hess_quad_func staticmethod ¤

energy_density_hess_quad_func(
    F: mat33,
    p: mat43,
    dhdX: mat43,
    params: ParamsElem,
    *,
    clamp: bool = True,
) -> scalar
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_phace.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
@override
@staticmethod
@no_type_check
@wp.func
def energy_density_hess_quad_func(
    F: mat33, p: mat43, dhdX: mat43, params: ParamsElem, *, clamp: bool = True
) -> scalar:
    _1 = F.dtype(1.0)
    _2 = F.dtype(2.0)
    J = func.I3(F)  # float
    g3 = func.g3(F)  # mat33
    quad_arap_active = ArapMuscle.energy_density_hess_quad_func(
        F, p, dhdX, Phace._arap_active_params(params), clamp=clamp
    )
    quad_arap_passive = Arap.energy_density_hess_quad_func(
        F, p, dhdX, Phace._arap_params(params), clamp=clamp
    )
    quad_arap = (
        params.muscle_fraction * quad_arap_active
        + (_1 - params.muscle_fraction) * quad_arap_passive
    )
    d2Psi_dI32 = _2 * params.lambda_  # float
    dPsi_dI3 = _2 * params.lambda_ * (J - _1)  # float
    h3_quad = func.h3_quad(p, dhdX, g3)  # float
    h6_quad = func.h6_quad(p, dhdX, F)  # float
    quad_vp = d2Psi_dI32 * h3_quad + dPsi_dI3 * h6_quad  # float
    quad = _2 * quad_arap + quad_vp  # float
    return quad

first_piola_kirchhoff_stress_func staticmethod ¤

first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_phace.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@override
@staticmethod
@no_type_check
@wp.func
def first_piola_kirchhoff_stress_func(
    F: mat33, params: ParamsElem, *, clamp: bool = False
) -> mat33:
    _1 = F.dtype(1.0)
    _2 = F.dtype(2.0)
    J = func.I3(F)  # float
    g3 = func.g3(F)  # mat33
    PK1_ARAP_active = ArapMuscle.first_piola_kirchhoff_stress_func(
        F, Phace._arap_active_params(params), clamp=clamp
    )  # mat33
    PK1_ARAP_passive = Arap.first_piola_kirchhoff_stress_func(
        F, Phace._arap_params(params), clamp=clamp
    )  # mat33
    PK1_ARAP = (
        params.muscle_fraction * PK1_ARAP_active
        + (_1 - params.muscle_fraction) * PK1_ARAP_passive
    )  # mat33
    PK1_VP = _2 * params.lambda_ * (J - _1) * g3  # mat33
    PK1 = _2 * PK1_ARAP + PK1_VP  # mat33
    return PK1

from_pyvista classmethod ¤

from_pyvista(
    obj: DataObject,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
59
60
61
62
@classmethod
def from_pyvista(cls, obj: pv.DataObject, **kwargs) -> Self:
    region = Region.from_pyvista(obj, grad=True)
    return cls.from_region(region, **kwargs)

from_region classmethod ¤

from_region(
    region: Region,
    *,
    clamp_hess_diag: bool = True,
    clamp_hess_quad: bool = True,
    clamp_lambda: bool = True,
    requires_grad: Sequence[str] = (),
    **kwargs,
) -> Self
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
76
77
78
79
80
81
82
83
84
85
86
87
88
@classmethod
def from_region(
    cls, region: Region, *, requires_grad: Sequence[str] = (), **kwargs
) -> Self:
    self: Self = cls(
        cells=wpu.to_warp(region.cells, wpt.vec4i),
        dhdX=wpu.to_warp(region.dhdX, wpt.mat43),
        dV=wpu.to_warp(region.dV, wpt.float_),
        params=cls.make_params(region, requires_grad),
        requires_grad=requires_grad,
        **kwargs,
    )
    return self

fun ¤

fun(u: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
110
111
112
113
114
115
116
117
@override
def fun(self, u: Vector, output: Scalar) -> None:
    wp.launch(
        self.fun_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

get_cell_params staticmethod ¤

get_cell_params(params: Params, cid: int) -> ParamsElem
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_phace.py
40
41
42
43
44
45
46
47
48
49
50
@override
@staticmethod
@no_type_check
@wp.func
def get_cell_params(params: Params, cid: int) -> ParamsElem:
    return Phace.ParamsElem(
        activation=params.activation[cid],
        lambda_=params.lambda_[cid],
        mu=params.mu[cid],
        muscle_fraction=params.muscle_fraction[cid],
    )

grad ¤

grad(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
119
120
121
122
123
124
125
126
@override
def grad(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

grad_and_hess_diag ¤

grad_and_hess_diag(
    u: Vector, grad: Vector, hess_diag: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
179
180
181
182
183
184
185
186
@override
def grad_and_hess_diag(self, u: Vector, grad: Vector, hess_diag: Vector) -> None:
    wp.launch(
        self.grad_and_hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[grad, hess_diag],
    )

hess_diag ¤

hess_diag(u: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
128
129
130
131
132
133
134
135
@override
def hess_diag(self, u: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_diag_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_prod ¤

hess_prod(u: Vector, p: Vector, output: Vector) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
137
138
139
140
141
142
143
144
@override
def hess_prod(self, u: Vector, p: Vector, output: Vector) -> None:
    wp.launch(
        self.hess_prod_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

hess_quad ¤

hess_quad(u: Vector, p: Vector, output: Scalar) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
146
147
148
149
150
151
152
153
@override
def hess_quad(self, u: Vector, p: Vector, output: Scalar) -> None:
    wp.launch(
        self.hess_quad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, p, self.cells, self.dhdX, self.dV, self.params],
        outputs=[output],
    )

make_params classmethod ¤

make_params(
    region: Region, requires_grad: Sequence[str] = ()
) -> Params
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
90
91
92
93
94
@classmethod
@no_type_check
def make_params(cls, region: Region, requires_grad: Sequence[str] = ()) -> Params:
    fields: Mapping[str, wp.array] = cls._params_fields_from_region(region)
    return cls._params_from_fields(fields, requires_grad)

mixed_derivative_prod ¤

mixed_derivative_prod(
    u: array, p: array
) -> dict[str, array]
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
@override
def mixed_derivative_prod(self, u: wp.array, p: wp.array) -> dict[str, wp.array]:
    if not self.requires_grad:
        return {}
    for name in self.requires_grad:
        getattr(self.params, name).grad.zero_()
    output: wp.array = wp.zeros_like(u)
    with wp.Tape() as tape:
        self.grad(u, output)
    tape.backward(grads={output: p})
    outputs: dict[str, wp.array] = {
        name: getattr(self.params, name).grad for name in self.requires_grad
    }
    return outputs

update ¤

update(u: Vector) -> None
Source code in src/liblaf/apple/warp/model/_energy.py
19
20
def update(self, u: Vector) -> None:
    pass

update_params ¤

update_params(params: EnergyParams) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
104
105
106
107
108
@override
def update_params(self, params: EnergyParams) -> None:
    for name, value in params.items():
        param: wp.array = getattr(self.params, name)
        wp.copy(param, wpu.to_warp(value, param.dtype))

value_and_grad ¤

value_and_grad(
    u: Vector, value: Scalar, grad: Vector
) -> None
Source code in src/liblaf/apple/warp/energies/elastic/hyperelastic/_base.py
170
171
172
173
174
175
176
177
@override
def value_and_grad(self, u: Vector, value: Scalar, grad: Vector) -> None:
    wp.launch(
        self.value_and_grad_kernel,
        dim=(self.n_cells, self.n_quadrature_points),
        inputs=[u, self.cells, self.dhdX, self.dV, self.params],
        outputs=[value, grad],
    )