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
Line.h
Go to the documentation of this file.
1
11#ifndef PBAT_FEM_LINE_H
12#define PBAT_FEM_LINE_H
13
14#include "pbat/Aliases.h"
16#include "QuadratureRules.h"
17
18#include <array>
19
20namespace pbat {
21namespace fem {
22
23namespace detail {
24
25template <int Order>
26struct Line;
27
28} // namespace detail
29
37template <int Order>
38using Line = typename detail::Line<Order>;
39
40namespace detail {
41
42template <>
43struct Line<1>
44{
45 using AffineBaseType = Line<1>;
46
47 static int constexpr kOrder = 1;
48 static int constexpr kDims = 1;
49 static int constexpr kNodes = 2;
50 static std::array<int, kNodes * kDims> constexpr Coordinates =
51 {0,1};
52 static std::array<int, AffineBaseType::kNodes> constexpr Vertices = {0,1};
53 static bool constexpr bHasConstantJacobian = true;
54
55 template <int PolynomialOrder, common::CFloatingPoint TScalar = Scalar>
57
58 template <class TDerived, class TScalar = typename TDerived::Scalar>
59 [[maybe_unused]] static Eigen::Vector<TScalar, kNodes> N([[maybe_unused]] Eigen::DenseBase<TDerived> const& X_)
60 {
61#include "pbat/warning/Push.h"
62#include "pbat/warning/SignConversion.h"
63 using namespace pbat::math;
64 Eigen::Vector<TScalar, kNodes> Nm;
65 auto const X = X_.reshaped();
66 Nm[0] = 1 - X[0];
67 Nm[1] = X[0];
68 return Nm;
69#include "pbat/warning/Pop.h"
70 }
71
72 template <class TDerived, class TScalar = typename TDerived::Scalar>
73 [[maybe_unused]] static Eigen::Matrix<TScalar, kNodes, kDims> GradN([[maybe_unused]] Eigen::DenseBase<TDerived> const& X_)
74 {
75#include "pbat/warning/Push.h"
76#include "pbat/warning/SignConversion.h"
77 Eigen::Matrix<TScalar, kNodes, kDims> GNm;
78 TScalar* GNp = GNm.data();
79 [[maybe_unused]] auto const X = X_.reshaped();
80 GNp[0] = -1;
81 GNp[1] = 1;
82 return GNm;
83#include "pbat/warning/Pop.h"
84 }
85};
86
87template <>
88struct Line<2>
89{
90 using AffineBaseType = Line<1>;
91
92 static int constexpr kOrder = 2;
93 static int constexpr kDims = 1;
94 static int constexpr kNodes = 3;
95 static std::array<int, kNodes * kDims> constexpr Coordinates =
96 {0,1,2};
97 static std::array<int, AffineBaseType::kNodes> constexpr Vertices = {0,2};
98 static bool constexpr bHasConstantJacobian = false;
99
100 template <int PolynomialOrder, common::CFloatingPoint TScalar = Scalar>
102
103 template <class TDerived, class TScalar = typename TDerived::Scalar>
104 [[maybe_unused]] static Eigen::Vector<TScalar, kNodes> N([[maybe_unused]] Eigen::DenseBase<TDerived> const& X_)
105 {
106#include "pbat/warning/Push.h"
107#include "pbat/warning/SignConversion.h"
108 using namespace pbat::math;
109 Eigen::Vector<TScalar, kNodes> Nm;
110 auto const X = X_.reshaped();
111 auto const a0 = X[0] - 1;
112 auto const a1 = 2*X[0] - 1;
113 Nm[0] = a0*a1;
114 Nm[1] = -4*a0*X[0];
115 Nm[2] = a1*X[0];
116 return Nm;
117#include "pbat/warning/Pop.h"
118 }
119
120 template <class TDerived, class TScalar = typename TDerived::Scalar>
121 [[maybe_unused]] static Eigen::Matrix<TScalar, kNodes, kDims> GradN([[maybe_unused]] Eigen::DenseBase<TDerived> const& X_)
122 {
123#include "pbat/warning/Push.h"
124#include "pbat/warning/SignConversion.h"
125 Eigen::Matrix<TScalar, kNodes, kDims> GNm;
126 TScalar* GNp = GNm.data();
127 [[maybe_unused]] auto const X = X_.reshaped();
128 auto const a0 = 4*X[0];
129 GNp[0] = a0 - 3;
130 GNp[1] = 4 - 8*X[0];
131 GNp[2] = a0 - 1;
132 return GNm;
133#include "pbat/warning/Pop.h"
134 }
135};
136
137template <>
138struct Line<3>
139{
140 using AffineBaseType = Line<1>;
141
142 static int constexpr kOrder = 3;
143 static int constexpr kDims = 1;
144 static int constexpr kNodes = 4;
145 static std::array<int, kNodes * kDims> constexpr Coordinates =
146 {0,1,2,3};
147 static std::array<int, AffineBaseType::kNodes> constexpr Vertices = {0,3};
148 static bool constexpr bHasConstantJacobian = false;
149
150 template <int PolynomialOrder, common::CFloatingPoint TScalar = Scalar>
152
153 template <class TDerived, class TScalar = typename TDerived::Scalar>
154 [[maybe_unused]] static Eigen::Vector<TScalar, kNodes> N([[maybe_unused]] Eigen::DenseBase<TDerived> const& X_)
155 {
156#include "pbat/warning/Push.h"
157#include "pbat/warning/SignConversion.h"
158 using namespace pbat::math;
159 Eigen::Vector<TScalar, kNodes> Nm;
160 auto const X = X_.reshaped();
161 auto const a0 = X[0] - 1;
162 auto const a1 = 3*X[0];
163 auto const a2 = a1 - 2;
164 auto const a3 = a0*a2;
165 auto const a4 = a1 - 1;
166 auto const a5 = (1.0/2.0)*a4;
167 auto const a6 = (9.0/2.0)*X[0];
168 Nm[0] = -a3*a5;
169 Nm[1] = a3*a6;
170 Nm[2] = -a0*a4*a6;
171 Nm[3] = a2*a5*X[0];
172 return Nm;
173#include "pbat/warning/Pop.h"
174 }
175
176 template <class TDerived, class TScalar = typename TDerived::Scalar>
177 [[maybe_unused]] static Eigen::Matrix<TScalar, kNodes, kDims> GradN([[maybe_unused]] Eigen::DenseBase<TDerived> const& X_)
178 {
179#include "pbat/warning/Push.h"
180#include "pbat/warning/SignConversion.h"
181 Eigen::Matrix<TScalar, kNodes, kDims> GNm;
182 TScalar* GNp = GNm.data();
183 [[maybe_unused]] auto const X = X_.reshaped();
184 auto const a0 = X[0] - 1;
185 auto const a1 = (3.0/2.0)*X[0];
186 auto const a2 = a1 - 1.0/2.0;
187 auto const a3 = -a2;
188 auto const a4 = 3*X[0] - 2;
189 auto const a5 = (27.0/2.0)*X[0];
190 auto const a6 = a5 - 27.0/2.0;
191 auto const a7 = (9.0/2.0)*X[0];
192 auto const a8 = 9.0/2.0 - a5;
193 GNp[0] = 3*a0*a3 + a3*a4 + a4*(3.0/2.0 - a1);
194 GNp[1] = a4*(a7 - 9.0/2.0) + a6*X[0] + (a5 - 9)*X[0];
195 GNp[2] = a0*a8 - a6*X[0] + a8*X[0];
196 GNp[3] = a2*a4 + (a7 - 3)*X[0] + (a7 - 3.0/2.0)*X[0];
197 return GNm;
198#include "pbat/warning/Pop.h"
199 }
200};
201
202} // namespace detail
203} // namespace fem
204} // namespace pbat
205
206#endif // PBAT_FEM_LINE_H
Concepts for common types.
Finite Element Method (FEM)
Definition Concepts.h:19
typename detail::Line< Order > Line
Line finite element.
Definition Line.h:38
Math related functionality.
Definition Concepts.h:19
typename detail::GaussLegendreQuadrature< Dims, Order, TScalar > GaussLegendreQuadrature
Shifted Gauss-Legendre quadrature scheme over the unit box in dimensions .
Definition GaussQuadrature.h:66
The main namespace of the library.
Definition Aliases.h:15