1 #include "serac/numerics/functional/geometric_factors.hpp"
16 template <
int Q, mfem::Geometry::Type geom,
typename function_space>
18 const std::vector<int>& elements)
22 constexpr
int spatial_dim = function_space::components;
30 auto X_q =
reinterpret_cast<position_type*
>(positions_q.ReadWrite());
31 auto J_q =
reinterpret_cast<jacobian_type*
>(jacobians_q.ReadWrite());
32 auto X =
reinterpret_cast<const typename element_type::dof_type*
>(positions_e.Read());
34 std::size_t num_elements = elements.size();
37 for (uint32_t e = 0; e < num_elements; e++) {
39 auto X_e = X[elements[e]];
42 auto quadrature_values = element_type::interpolate(X_e, rule);
45 for (
int q = 0; q < qpts_per_elem; q++) {
46 auto [value, gradient] = quadrature_values[q];
47 for (
int i = 0; i < spatial_dim; i++) {
48 X_q[e](i, q) = value[i];
49 if constexpr (std::is_same_v<decltype(value), decltype(gradient)>) {
50 J_q[e](0, i, q) = gradient[i];
52 if constexpr (!std::is_same_v<decltype(value), decltype(gradient)>) {
53 for (
int j = 0; j < geometry_dim; j++) {
54 J_q[e](j, i, q) = gradient(i, j);
64 auto* nodes = d.
mesh_.GetNodes();
65 auto* fes = nodes->FESpace();
68 mfem::Vector X_e(
int(restriction.ESize()));
69 restriction.Gather(*nodes, X_e);
72 int p = fes->GetElementOrder(0);
74 int spatial_dim = d.
mesh_.SpaceDimension();
78 if (g == mfem::Geometry::TRIANGLE)
elements = d.tri_ids_;
79 if (g == mfem::Geometry::SQUARE)
elements = d.quad_ids_;
80 if (g == mfem::Geometry::TETRAHEDRON)
elements = d.tet_ids_;
81 if (g == mfem::Geometry::CUBE)
elements = d.hex_ids_;
85 X = mfem::Vector(
int(
num_elements) * qpts_per_elem * spatial_dim);
86 J = mfem::Vector(
int(
num_elements) * qpts_per_elem * spatial_dim * geometry_dim);
88 #define DISPATCH_KERNEL(GEOM, P, Q) \
89 if (g == mfem::Geometry::GEOM && p == P && q == Q) { \
90 compute_geometric_factors<Q, mfem::Geometry::GEOM, H1<P, dimension_of(mfem::Geometry::GEOM)> >(X, J, X_e, \
95 DISPATCH_KERNEL(TRIANGLE, 1, 1);
96 DISPATCH_KERNEL(TRIANGLE, 1, 2);
97 DISPATCH_KERNEL(TRIANGLE, 1, 3);
98 DISPATCH_KERNEL(TRIANGLE, 1, 4);
100 DISPATCH_KERNEL(SQUARE, 1, 1);
101 DISPATCH_KERNEL(SQUARE, 1, 2);
102 DISPATCH_KERNEL(SQUARE, 1, 3);
103 DISPATCH_KERNEL(SQUARE, 1, 4);
105 DISPATCH_KERNEL(SQUARE, 2, 1);
106 DISPATCH_KERNEL(SQUARE, 2, 2);
107 DISPATCH_KERNEL(SQUARE, 2, 3);
108 DISPATCH_KERNEL(SQUARE, 2, 4);
110 DISPATCH_KERNEL(SQUARE, 3, 1);
111 DISPATCH_KERNEL(SQUARE, 3, 2);
112 DISPATCH_KERNEL(SQUARE, 3, 3);
113 DISPATCH_KERNEL(SQUARE, 3, 4);
115 DISPATCH_KERNEL(TETRAHEDRON, 1, 1);
116 DISPATCH_KERNEL(TETRAHEDRON, 1, 2);
117 DISPATCH_KERNEL(TETRAHEDRON, 1, 3);
118 DISPATCH_KERNEL(TETRAHEDRON, 1, 4);
120 DISPATCH_KERNEL(CUBE, 1, 1);
121 DISPATCH_KERNEL(CUBE, 1, 2);
122 DISPATCH_KERNEL(CUBE, 1, 3);
123 DISPATCH_KERNEL(CUBE, 1, 4);
125 DISPATCH_KERNEL(CUBE, 2, 1);
126 DISPATCH_KERNEL(CUBE, 2, 2);
127 DISPATCH_KERNEL(CUBE, 2, 3);
128 DISPATCH_KERNEL(CUBE, 2, 4);
130 DISPATCH_KERNEL(CUBE, 3, 1);
131 DISPATCH_KERNEL(CUBE, 3, 2);
132 DISPATCH_KERNEL(CUBE, 3, 3);
133 DISPATCH_KERNEL(CUBE, 3, 4);
135 #undef DISPATCH_KERNEL
137 std::cout <<
"should never be reached " << std::endl;
142 auto* nodes = d.
mesh_.GetNodes();
143 auto* fes = nodes->FESpace();
146 mfem::Vector X_e(
int(restriction.ESize()));
147 restriction.Gather(*nodes, X_e);
150 int p = fes->GetElementOrder(0);
152 int spatial_dim = d.
mesh_.SpaceDimension();
162 X = mfem::Vector(
int(
num_elements) * qpts_per_elem * spatial_dim);
163 J = mfem::Vector(
int(
num_elements) * qpts_per_elem * spatial_dim * geometry_dim);
165 #define DISPATCH_KERNEL(GEOM, P, Q) \
166 if (g == mfem::Geometry::GEOM && p == P && q == Q) { \
167 compute_geometric_factors<Q, mfem::Geometry::GEOM, H1<P, dimension_of(mfem::Geometry::GEOM) + 1> >(X, J, X_e, \
172 DISPATCH_KERNEL(SEGMENT, 1, 1);
173 DISPATCH_KERNEL(SEGMENT, 1, 2);
174 DISPATCH_KERNEL(SEGMENT, 1, 3);
175 DISPATCH_KERNEL(SEGMENT, 1, 4);
177 DISPATCH_KERNEL(SEGMENT, 2, 1);
178 DISPATCH_KERNEL(SEGMENT, 2, 2);
179 DISPATCH_KERNEL(SEGMENT, 2, 3);
180 DISPATCH_KERNEL(SEGMENT, 2, 4);
182 DISPATCH_KERNEL(SEGMENT, 3, 1);
183 DISPATCH_KERNEL(SEGMENT, 3, 2);
184 DISPATCH_KERNEL(SEGMENT, 3, 3);
185 DISPATCH_KERNEL(SEGMENT, 3, 4);
187 DISPATCH_KERNEL(TRIANGLE, 1, 1);
188 DISPATCH_KERNEL(TRIANGLE, 1, 2);
189 DISPATCH_KERNEL(TRIANGLE, 1, 3);
190 DISPATCH_KERNEL(TRIANGLE, 1, 4);
192 DISPATCH_KERNEL(TRIANGLE, 2, 1);
193 DISPATCH_KERNEL(TRIANGLE, 2, 2);
194 DISPATCH_KERNEL(TRIANGLE, 2, 3);
195 DISPATCH_KERNEL(TRIANGLE, 2, 4);
197 DISPATCH_KERNEL(TRIANGLE, 3, 1);
198 DISPATCH_KERNEL(TRIANGLE, 3, 2);
199 DISPATCH_KERNEL(TRIANGLE, 3, 3);
200 DISPATCH_KERNEL(TRIANGLE, 3, 4);
202 DISPATCH_KERNEL(SQUARE, 1, 1);
203 DISPATCH_KERNEL(SQUARE, 1, 2);
204 DISPATCH_KERNEL(SQUARE, 1, 3);
205 DISPATCH_KERNEL(SQUARE, 1, 4);
207 DISPATCH_KERNEL(SQUARE, 2, 1);
208 DISPATCH_KERNEL(SQUARE, 2, 2);
209 DISPATCH_KERNEL(SQUARE, 2, 3);
210 DISPATCH_KERNEL(SQUARE, 2, 4);
212 DISPATCH_KERNEL(SQUARE, 3, 1);
213 DISPATCH_KERNEL(SQUARE, 3, 2);
214 DISPATCH_KERNEL(SQUARE, 3, 3);
215 DISPATCH_KERNEL(SQUARE, 3, 4);
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 SERAC_HOST_DEVICE auto type(const tuple< T... > &values)
a function intended to be used for extracting the ith type from a tuple.
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 mfem::Mesh & mesh_
the underyling mesh for this domain
const std::vector< int > & get(mfem::Geometry::Type geom) const
get elements by geometry type
std::size_t num_elements
the number of elements in the domain
std::vector< int > elements
list of element indices that are part of the associated 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.