7 #include "serac/numerics/functional/geometric_factors.hpp"
26 template <
int Q, mfem::Geometry::Type geom,
typename function_space>
28 const std::vector<int>& elements)
32 constexpr
int spatial_dim = function_space::components;
40 auto X_q =
reinterpret_cast<position_type*
>(positions_q.ReadWrite());
41 auto J_q =
reinterpret_cast<jacobian_type*
>(jacobians_q.ReadWrite());
42 auto X =
reinterpret_cast<const typename element_type::dof_type*
>(positions_e.Read());
44 std::size_t num_elements = elements.size();
47 for (uint32_t e = 0; e < num_elements; e++) {
52 auto quadrature_values = element_type::interpolate(X_e, rule);
55 for (
int q = 0; q < qpts_per_elem; q++) {
56 auto [value, gradient] = quadrature_values[q];
57 for (
int i = 0; i < spatial_dim; i++) {
58 X_q[e](i, q) = value[i];
59 if constexpr (std::is_same_v<decltype(value), decltype(gradient)>) {
60 J_q[e](0, i, q) = gradient[i];
62 if constexpr (!std::is_same_v<decltype(value), decltype(gradient)>) {
63 for (
int j = 0; j < geometry_dim; j++) {
64 J_q[e](j, i, q) = gradient(i, j);
74 const mfem::ParGridFunction* nodes =
static_cast<const mfem::ParGridFunction*
>(domain.
mesh_.GetNodes());
75 mfem::ParFiniteElementSpace* fes = nodes->ParFESpace();
79 const std::vector<int>& element_ids = domain.
get_mfem_ids(geom);
82 mfem::Vector X_e(
int(restriction.ESize()));
83 restriction.Gather(*nodes, X_e);
86 int p = fes->GetElementOrder(0);
88 int spatial_dim = domain.
mesh_.SpaceDimension();
94 X = mfem::Vector(
int(
num_elements) * qpts_per_elem * spatial_dim);
95 J = mfem::Vector(
int(
num_elements) * qpts_per_elem * spatial_dim * geometry_dim);
97 #define DISPATCH_KERNEL(GEOM, P, Q, BDR) \
98 if (geom == mfem::Geometry::GEOM && p == P && q == Q && (spatial_dim - geometry_dim) == BDR) { \
99 compute_geometric_factors<Q, mfem::Geometry::GEOM, H1<P, dimension_of(mfem::Geometry::GEOM) + BDR> >(X, J, X_e, \
104 DISPATCH_KERNEL(SEGMENT, 1, 1, 1);
105 DISPATCH_KERNEL(SEGMENT, 1, 2, 1);
106 DISPATCH_KERNEL(SEGMENT, 1, 3, 1);
107 DISPATCH_KERNEL(SEGMENT, 1, 4, 1);
109 DISPATCH_KERNEL(SEGMENT, 2, 1, 1);
110 DISPATCH_KERNEL(SEGMENT, 2, 2, 1);
111 DISPATCH_KERNEL(SEGMENT, 2, 3, 1);
112 DISPATCH_KERNEL(SEGMENT, 2, 4, 1);
114 DISPATCH_KERNEL(SEGMENT, 3, 1, 1);
115 DISPATCH_KERNEL(SEGMENT, 3, 2, 1);
116 DISPATCH_KERNEL(SEGMENT, 3, 3, 1);
117 DISPATCH_KERNEL(SEGMENT, 3, 4, 1);
121 DISPATCH_KERNEL(TRIANGLE, 1, 1, 0);
122 DISPATCH_KERNEL(TRIANGLE, 1, 2, 0);
123 DISPATCH_KERNEL(TRIANGLE, 1, 3, 0);
124 DISPATCH_KERNEL(TRIANGLE, 1, 4, 0);
126 DISPATCH_KERNEL(TRIANGLE, 2, 1, 0);
127 DISPATCH_KERNEL(TRIANGLE, 2, 2, 0);
128 DISPATCH_KERNEL(TRIANGLE, 2, 3, 0);
129 DISPATCH_KERNEL(TRIANGLE, 2, 4, 0);
131 DISPATCH_KERNEL(TRIANGLE, 3, 1, 0);
132 DISPATCH_KERNEL(TRIANGLE, 3, 2, 0);
133 DISPATCH_KERNEL(TRIANGLE, 3, 3, 0);
134 DISPATCH_KERNEL(TRIANGLE, 3, 4, 0);
136 DISPATCH_KERNEL(TRIANGLE, 1, 1, 1);
137 DISPATCH_KERNEL(TRIANGLE, 1, 2, 1);
138 DISPATCH_KERNEL(TRIANGLE, 1, 3, 1);
139 DISPATCH_KERNEL(TRIANGLE, 1, 4, 1);
141 DISPATCH_KERNEL(TRIANGLE, 2, 1, 1);
142 DISPATCH_KERNEL(TRIANGLE, 2, 2, 1);
143 DISPATCH_KERNEL(TRIANGLE, 2, 3, 1);
144 DISPATCH_KERNEL(TRIANGLE, 2, 4, 1);
146 DISPATCH_KERNEL(TRIANGLE, 3, 1, 1);
147 DISPATCH_KERNEL(TRIANGLE, 3, 2, 1);
148 DISPATCH_KERNEL(TRIANGLE, 3, 3, 1);
149 DISPATCH_KERNEL(TRIANGLE, 3, 4, 1);
153 DISPATCH_KERNEL(SQUARE, 1, 1, 0);
154 DISPATCH_KERNEL(SQUARE, 1, 2, 0);
155 DISPATCH_KERNEL(SQUARE, 1, 3, 0);
156 DISPATCH_KERNEL(SQUARE, 1, 4, 0);
158 DISPATCH_KERNEL(SQUARE, 2, 1, 0);
159 DISPATCH_KERNEL(SQUARE, 2, 2, 0);
160 DISPATCH_KERNEL(SQUARE, 2, 3, 0);
161 DISPATCH_KERNEL(SQUARE, 2, 4, 0);
163 DISPATCH_KERNEL(SQUARE, 3, 1, 0);
164 DISPATCH_KERNEL(SQUARE, 3, 2, 0);
165 DISPATCH_KERNEL(SQUARE, 3, 3, 0);
166 DISPATCH_KERNEL(SQUARE, 3, 4, 0);
168 DISPATCH_KERNEL(SQUARE, 1, 1, 1);
169 DISPATCH_KERNEL(SQUARE, 1, 2, 1);
170 DISPATCH_KERNEL(SQUARE, 1, 3, 1);
171 DISPATCH_KERNEL(SQUARE, 1, 4, 1);
173 DISPATCH_KERNEL(SQUARE, 2, 1, 1);
174 DISPATCH_KERNEL(SQUARE, 2, 2, 1);
175 DISPATCH_KERNEL(SQUARE, 2, 3, 1);
176 DISPATCH_KERNEL(SQUARE, 2, 4, 1);
178 DISPATCH_KERNEL(SQUARE, 3, 1, 1);
179 DISPATCH_KERNEL(SQUARE, 3, 2, 1);
180 DISPATCH_KERNEL(SQUARE, 3, 3, 1);
181 DISPATCH_KERNEL(SQUARE, 3, 4, 1);
185 DISPATCH_KERNEL(TETRAHEDRON, 1, 1, 0);
186 DISPATCH_KERNEL(TETRAHEDRON, 1, 2, 0);
187 DISPATCH_KERNEL(TETRAHEDRON, 1, 3, 0);
188 DISPATCH_KERNEL(TETRAHEDRON, 1, 4, 0);
190 DISPATCH_KERNEL(TETRAHEDRON, 2, 1, 0);
191 DISPATCH_KERNEL(TETRAHEDRON, 2, 2, 0);
192 DISPATCH_KERNEL(TETRAHEDRON, 2, 3, 0);
193 DISPATCH_KERNEL(TETRAHEDRON, 2, 4, 0);
195 DISPATCH_KERNEL(TETRAHEDRON, 3, 1, 0);
196 DISPATCH_KERNEL(TETRAHEDRON, 3, 2, 0);
197 DISPATCH_KERNEL(TETRAHEDRON, 3, 3, 0);
198 DISPATCH_KERNEL(TETRAHEDRON, 3, 4, 0);
202 DISPATCH_KERNEL(CUBE, 1, 1, 0);
203 DISPATCH_KERNEL(CUBE, 1, 2, 0);
204 DISPATCH_KERNEL(CUBE, 1, 3, 0);
205 DISPATCH_KERNEL(CUBE, 1, 4, 0);
207 DISPATCH_KERNEL(CUBE, 2, 1, 0);
208 DISPATCH_KERNEL(CUBE, 2, 2, 0);
209 DISPATCH_KERNEL(CUBE, 2, 3, 0);
210 DISPATCH_KERNEL(CUBE, 2, 4, 0);
212 DISPATCH_KERNEL(CUBE, 3, 1, 0);
213 DISPATCH_KERNEL(CUBE, 3, 2, 0);
214 DISPATCH_KERNEL(CUBE, 3, 3, 0);
215 DISPATCH_KERNEL(CUBE, 3, 4, 0);
217 #undef DISPATCH_KERNEL
219 std::cout <<
"should never be reached " << std::endl;
This file contains helper traits and enumerations for classifying finite elements.
Accelerator functionality.
constexpr int num_quadrature_points(mfem::Geometry::Type g, int Q)
return the number of quadrature points in a Gauss-Legendre rule with parameter "Q"
void compute_geometric_factors(mfem::Vector &positions_q, mfem::Vector &jacobians_q, const mfem::Vector &positions_e, const std::vector< int > &elements)
a kernel to compute the positions and jacobians at each quadrature point (mfem calls this "geometric ...
constexpr int dimension_of(mfem::Geometry::Type g)
Returns the dimension of an element geometry.
a class for representing a geometric region that can be used for integration
const mesh_t & mesh_
the underyling mesh for this domain
const std::vector< int > & get_mfem_ids(mfem::Geometry::Type geom) const
get elements by geometry type
std::size_t num_elements
the number of elements in the domain
mfem::Vector J
Jacobians of the element transformations at all quadrature points.
mfem::Vector X
Mapped (physical) coordinates of all quadrature points.
GeometricFactors()
default ctor, leaving this object uninitialized
a convenience class for generating information about tensor product integration rules from the underl...
Template prototype for finite element implementations.
Arbitrary-rank tensor class.