PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
Kernels.h
1#ifndef PBAT_SIM_VBD_MULTIGRID_KERNELS_H
2#define PBAT_SIM_VBD_MULTIGRID_KERNELS_H
3
4#include "pbat/Aliases.h"
5#include "pbat/HostDevice.h"
9#include "pbat/sim/vbd/Mesh.h"
10
11namespace pbat {
12namespace sim {
13namespace vbd {
14namespace multigrid {
15namespace kernels {
16
17namespace mini = math::linalg::mini;
18
19template <
20 physics::CHyperElasticEnergy TPsi,
21 mini::CMatrix TMatrixIL,
22 mini::CMatrix TMatrixX,
23 mini::CMatrix TMatrixGN,
24 mini::CMatrix TMatrixN,
25 mini::CMatrix TMatrixGU,
26 mini::CMatrix TMatrixHU,
27 class ScalarType = typename TMatrixX::ScalarType>
28PBAT_HOST_DEVICE void AccumulateElasticEnergy(
29 TPsi const& Psi,
30 TMatrixIL const& ilocal,
31 ScalarType wg,
32 ScalarType mug,
33 ScalarType lambdag,
34 TMatrixX const& xe,
35 TMatrixGN const& GNe,
36 TMatrixN const& N,
37 TMatrixGU& gu,
38 TMatrixHU& Hu)
39{
40 using namespace mini;
41 SMatrix<ScalarType, 3, 3> F = xe * GNe;
42 SVector<Scalar, 9> gF = Zeros<Scalar, 9>();
43 SMatrix<Scalar, 9, 9> HF = Zeros<Scalar, 9, 9>();
44 Psi.gradAndHessian(F, mug, lambdag, gF, HF);
45 using Element = typename VolumeMesh::ElementType;
46 SMatrix<Scalar, 3, 3> dHu = Zeros<Scalar, 3, 3>();
47 SVector<Scalar, 3> dgu = Zeros<Scalar, 3>();
48 for (auto i = 0; i < 4; ++i)
49 {
50 for (auto j = 0; j < 4; ++j)
51 {
52 if (ilocal(i) >= 0 and ilocal(j) >= 0)
53 {
54 auto Hij = fem::HessianBlockWrtDofs<Element, 3>(HF, GNe, i, j);
55 dHu += N(ilocal(i), i) * N(ilocal(j), j) * Hij;
56 }
57 }
58 }
59 for (auto i = 0; i < 4; ++i)
60 {
61 if (ilocal(i) >= 0)
62 {
63 auto gi = fem::GradientSegmentWrtDofs<Element, 3>(gF, GNe, i);
64 dgu += N(ilocal(i), i) * gi;
65 }
66 }
67 Hu += wg * dHu;
68 gu += wg * dgu;
69}
70
71} // namespace kernels
72} // namespace multigrid
73} // namespace vbd
74} // namespace sim
75} // namespace pbat
76
77#endif // PBAT_SIM_VBD_MULTIGRID_KERNELS_H
Functions to compute deformation gradient and its derivatives.
This file includes all the mini linear algebra headers.
auto GradientSegmentWrtDofs(TMatrixGF const &GF, TMatrixGP const &GP, auto i) -> math::linalg::mini::SVector< ScalarType, Dims >
Computes , i.e. the gradient of a scalar function w.r.t. the node's degrees of freedom.
Definition DeformationGradient.h:68
auto HessianBlockWrtDofs(TMatrixHF const &HF, TMatrixGP const &GP, auto i, auto j) -> math::linalg::mini::SMatrix< ScalarType, Dims, Dims >
Computes , i.e. the hessian of a scalar function w.r.t. the and node's degrees of freedom.
Definition DeformationGradient.h:169
Mini linear algebra related functionality.
Definition Assign.h:12
PBAT's Vertex Block Descent (VBD) anka2024vbd API.
Definition AndersonIntegrator.cpp:10
PBAT simulation algorithms.
The main namespace of the library.
Definition Aliases.h:15
TElement ElementType
Definition Mesh.h:46