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
DeformationGradient.h
Go to the documentation of this file.
1
10
11#ifndef PBAT_FEM_DEFORMATIONGRADIENT_H
12#define PBAT_FEM_DEFORMATIONGRADIENT_H
13
14#include "Concepts.h"
15#include "pbat/Aliases.h"
16#include "pbat/math/linalg/mini/BinaryOperations.h"
17#include "pbat/math/linalg/mini/Concepts.h"
18#include "pbat/math/linalg/mini/Matrix.h"
19
20namespace pbat::fem {
21
37template <CElement TElement, class TDerivedx, class TDerivedX>
39 Eigen::MatrixBase<TDerivedx> const& x,
40 Eigen::MatrixBase<TDerivedX> const& GP) -> Matrix<TDerivedx::RowsAtCompileTime, TElement::kDims>
41{
42 return x * GP;
43}
44
62template <
63 CElement TElement,
64 int Dims,
67 class ScalarType = typename TMatrixGF::ScalarType>
68auto GradientSegmentWrtDofs(TMatrixGF const& GF, TMatrixGP const& GP, auto i)
69 -> math::linalg::mini::SVector<ScalarType, Dims>
70{
71 using namespace math::linalg::mini;
72 SVector<ScalarType, Dims> dPsidx = Zeros<ScalarType, Dims, 1>{};
73 for (auto k = 0; k < Dims; ++k)
74 {
75 dPsidx += GP(i, k) * GF.template Slice<Dims, 1>(k * Dims, 0);
76 }
77 return dPsidx;
78}
79
120template <
121 CElement TElement,
122 int Dims,
125 class ScalarType = typename TMatrixGF::ScalarType>
126auto GradientWrtDofs(TMatrixGF const& GF, TMatrixGP const& GP)
127 -> math::linalg::mini::SVector<ScalarType, TElement::kNodes * Dims>
128{
129 auto constexpr kRows = TElement::kNodes * Dims;
130 using namespace math::linalg::mini;
131 SVector<ScalarType, kRows> dPsidx = Zeros<ScalarType, kRows, 1>{};
132 for (auto k = 0; k < Dims; ++k)
133 {
134 for (auto i = 0; i < TElement::kNodes; ++i)
135 {
136 dPsidx.template Slice<Dims, 1>(i * Dims, 0) +=
137 GP(i, k) * GF.template Slice<Dims, 1>(k * Dims, 0);
138 }
139 }
140 return dPsidx;
141}
142
163template <
164 CElement TElement,
165 int Dims,
168 class ScalarType = typename TMatrixHF::ScalarType>
169auto HessianBlockWrtDofs(TMatrixHF const& HF, TMatrixGP const& GP, auto i, auto j)
171{
172 using namespace math::linalg::mini;
173 SMatrix<ScalarType, Dims, Dims> d2Psidx2 = Zeros<ScalarType, Dims, Dims>{};
174 for (auto kj = 0; kj < Dims; ++kj)
175 {
176 for (auto ki = 0; ki < Dims; ++ki)
177 {
178 d2Psidx2 += GP(i, ki) * GP(j, kj) * HF.template Slice<Dims, Dims>(ki * Dims, kj * Dims);
179 }
180 }
181 return d2Psidx2;
182}
183
225template <
226 CElement TElement,
227 int Dims,
230 class ScalarType = typename TMatrixHF::ScalarType>
231auto HessianWrtDofs(TMatrixHF const& HF, TMatrixGP const& GP)
233{
234 auto constexpr kRows = TElement::kNodes * Dims;
235 auto constexpr kCols = TElement::kNodes * Dims;
236 using namespace math::linalg::mini;
237 SMatrix<ScalarType, kRows, kCols> d2Psidx2 = Zeros<ScalarType, kRows, kCols>{};
238 for (auto kj = 0; kj < Dims; ++kj)
239 {
240 for (auto ki = 0; ki < Dims; ++ki)
241 {
242 for (auto j = 0; j < TElement::kNodes; ++j)
243 {
244 for (auto i = 0; i < TElement::kNodes; ++i)
245 {
246 d2Psidx2.template Slice<Dims, Dims>(i * Dims, j * Dims) +=
247 GP(i, ki) * GP(j, kj) * HF.template Slice<Dims, Dims>(ki * Dims, kj * Dims);
248 }
249 }
250 }
251 }
252 return d2Psidx2;
253}
254
255} // namespace pbat::fem
256
257#endif // PBAT_FEM_DEFORMATIONGRADIENT_H
Definition Matrix.h:121
Definition Concepts.h:14
Finite Element Method (FEM)
Definition Concepts.h:19
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 HessianWrtDofs(TMatrixHF const &HF, TMatrixGP const &GP) -> math::linalg::mini::SMatrix< ScalarType, TElement::kNodes *Dims, TElement::kNodes *Dims >
Computes hessian w.r.t. FEM degrees of freedom of scalar function , where is the jacobian of ,...
Definition DeformationGradient.h:231
auto DeformationGradient(Eigen::MatrixBase< TDerivedx > const &x, Eigen::MatrixBase< TDerivedX > const &GP) -> Matrix< TDerivedx::RowsAtCompileTime, TElement::kDims >
Computes the deformation gradient of the deformation map .
Definition DeformationGradient.h:38
auto GradientWrtDofs(TMatrixGF const &GF, TMatrixGP const &GP) -> math::linalg::mini::SVector< ScalarType, TElement::kNodes *Dims >
Computes gradient w.r.t. FEM degrees of freedom of scalar function , where is the jacobian of ,...
Definition DeformationGradient.h:126
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
Eigen::Matrix< Scalar, Rows, Cols > Matrix
Fixed-size matrix type.
Definition Aliases.h:31