IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
LagrangeSpace.h
1// Class LagrangeSpace
2// This is the LagrangeSpace class. It is a class representing a Lagrange space
3// for finite element methods on a structured grid.
4
5#ifndef IPPL_LAGRANGESPACE_H
6#define IPPL_LAGRANGESPACE_H
7
8#include <cmath>
9
10#include "FEM/FEMQuadratureData.h"
11#include "FEM/FiniteElementSpace.h"
12
13constexpr unsigned getLagrangeNumElementDOFs(unsigned Dim, unsigned Order) {
14 // needs to be constexpr pow function to work at compile time. Kokkos::pow doesn't work.
15 return static_cast<unsigned>(power(static_cast<int>(Order + 1), static_cast<int>(Dim)));
16}
17
18namespace ippl {
19
31 template <typename T, unsigned Dim, unsigned Order, typename ElementType,
32 typename QuadratureType, typename FieldLHS, typename FieldRHS>
33 // requires IsQuadrature<QuadratureType>
35 : public FiniteElementSpace<T, Dim, getLagrangeNumElementDOFs(Dim, Order), ElementType,
36 QuadratureType, FieldLHS, FieldRHS> {
37 public:
38 // The number of degrees of freedom per element
39 static constexpr unsigned numElementDOFs = getLagrangeNumElementDOFs(Dim, Order);
40
41 // The dimension of the mesh
42 static constexpr unsigned dim = FiniteElementSpace<T, Dim, numElementDOFs, ElementType,
43 QuadratureType, FieldLHS, FieldRHS>::dim;
44
45 // The order of the Lagrange space
46 static constexpr unsigned order = Order;
47
48 // The number of mesh vertices per element
49 static constexpr unsigned numElementVertices =
50 FiniteElementSpace<T, Dim, numElementDOFs, ElementType, QuadratureType, FieldLHS,
51 FieldRHS>::numElementVertices;
52
53 // A vector with the position of the element in the mesh in each dimension
54 typedef typename FiniteElementSpace<T, Dim, numElementDOFs, ElementType, QuadratureType,
55 FieldLHS, FieldRHS>::indices_t indices_t;
56
57 // A point in the global coordinate system
58 typedef typename FiniteElementSpace<T, Dim, numElementDOFs, ElementType, QuadratureType,
59 FieldLHS, FieldRHS>::point_t point_t;
60
61 typedef typename FiniteElementSpace<T, Dim, numElementDOFs, ElementType, QuadratureType,
62 FieldLHS, FieldRHS>::vertex_points_t vertex_points_t;
63
64 // Field layout type for domain decomposition info
66
67 // View types
68 typedef typename detail::ViewType<T, Dim>::view_type ViewType;
70 AtomicViewType;
71
73 // Constructors ///////////////////////////////////////////////////////
75
84 LagrangeSpace(UniformCartesian<T, Dim>& mesh, ElementType& ref_element,
85 const QuadratureType& quadrature, Layout_t& layout);
86
96 LagrangeSpace(UniformCartesian<T, Dim>& mesh, ElementType& ref_element,
97 const QuadratureType& quadrature);
98
105 void initialize(UniformCartesian<T, Dim>& mesh, Layout_t& layout);
106
108
113
115
120 void updateLayout(Layout_t& layout);
121
124
130 KOKKOS_FUNCTION size_t numGlobalDOFs() const override;
131
141 KOKKOS_FUNCTION size_t getLocalDOFIndex(const size_t& elementIndex,
142 const size_t& globalDOFIndex) const override;
143
152 KOKKOS_FUNCTION size_t getGlobalDOFIndex(const size_t& elementIndex,
153 const size_t& localDOFIndex) const override;
154
162 KOKKOS_FUNCTION Vector<size_t, numElementDOFs> getLocalDOFIndices() const override;
163
172 const size_t& element_index) const override;
173
177
187 KOKKOS_FUNCTION T evaluateRefElementShapeFunction(const size_t& localDOF,
188 const point_t& localPoint) const;
189
201 const size_t& localDOF, const point_t& localPoint) const;
202
206
207 KOKKOS_FUNCTION point_t
209 return this->ref_element_m.getInverseTransposeTransformationJacobian(pt);
210 }
211
215
224 template <typename F>
225 FieldLHS evaluateAx(FieldLHS& field, F& evalFunction);
226
227 template <typename F>
228 FieldLHS evaluateAx_lower(FieldLHS& field, F& evalFunction);
229
230 template <typename F>
231 FieldLHS evaluateAx_upper(FieldLHS& field, F& evalFunction);
232
233 template <typename F>
234 FieldLHS evaluateAx_upperlower(FieldLHS& field, F& evalFunction);
235
236 template <typename F>
237 FieldLHS evaluateAx_inversediag(FieldLHS& field, F& evalFunction);
238
239 template <typename F>
240 FieldLHS evaluateAx_diag(FieldLHS& field, F& evalFunction);
241
252 template <typename F>
253 FieldLHS evaluateAx_lift(FieldLHS& field, F& evalFunction);
254
260 void evaluateLoadVector(FieldRHS& field) const;
261 void evaluateLumpedMass(FieldRHS& field) const;
262
266
275 template <typename F>
276 T computeErrorL2(const FieldLHS& u_h, const F& u_sol) const;
277
285 T computeAvg(const FieldLHS& u_h) const;
286
291 // members we need to copy for the following functions:
292 // works since numElementDOFs in LagrangeSpace is static constexpr
293 static constexpr unsigned numElementDOFs = LagrangeSpace::numElementDOFs;
295 ElementType ref_element_m;
296
297 // these are the functions needed for interpolation to the space
298 KOKKOS_FUNCTION indices_t getMeshVertexNDIndex(const size_t& vertex_index) const;
299
300 KOKKOS_FUNCTION size_t getLocalDOFIndex(const indices_t& elementNDIndex,
301 const size_t& globalDOFIndex) const;
302 KOKKOS_FUNCTION Vector<size_t, numElementDOFs> getGlobalDOFIndices(
303 const indices_t& elementNDIndex) const;
304
305 KOKKOS_FUNCTION T evaluateRefElementShapeFunction(const size_t& localDOF,
306 const point_t& localPoint) const;
307 KOKKOS_FUNCTION point_t evaluateRefElementShapeFunctionGradient(
308 const size_t& localDOF, const point_t& localPoint) const;
309 };
310
312
313 private:
322 KOKKOS_FUNCTION bool isDOFOnBoundary(const indices_t& ndindex) const {
323 for (size_t d = 0; d < Dim; ++d) {
324 if (ndindex[d] <= 0 || ndindex[d] >= this->nr_m[d] - 1) {
325 return true;
326 }
327 }
328 return false;
329 }
330
335 Kokkos::View<size_t*> elementIndices;
336
337 // One time allocated field of type FieldLHS to store results
338 FieldLHS resultField;
339 };
340
341} // namespace ippl
342
343#include "FEM/LagrangeSpace.hpp"
344
345#endif
Definition FieldLayout.h:166
The FiniteElementSpace class handles the mesh index mapping to vertices and elements and is the base ...
Definition FiniteElementSpace.h:41
A class representing a Lagrange space for finite element methods on a structured, rectilinear grid.
Definition LagrangeSpace.h:36
void initializeElementIndices(Layout_t &layout)
Initialize a Kokkos view containing the element indices. This distributes the elements among MPI rank...
Definition LagrangeSpace.hpp:58
T computeAvg(const FieldLHS &u_h) const
Given a field, compute the average.
Definition LagrangeSpace.hpp:1609
void initialize(UniformCartesian< T, Dim > &mesh, Layout_t &layout)
Initialize a LagrangeSpace object created with the default constructor.
Definition LagrangeSpace.hpp:41
KOKKOS_FUNCTION size_t numGlobalDOFs() const override
Degree of Freedom operations //////////////////////////////////////.
Definition LagrangeSpace.hpp:132
KOKKOS_FUNCTION Vector< size_t, numElementDOFs > getGlobalDOFIndices(const size_t &element_index) const override
Get the global DOF indices (vector of global DOF indices) of an element.
Definition LagrangeSpace.hpp:200
void evaluateLoadVector(FieldRHS &field) const
Assemble the load vector b of the system Ax = b.
Definition LagrangeSpace.hpp:1330
DeviceStruct getDeviceMirror() const
Device struct definitions /////////////////////////////////////////.
Definition LagrangeSpace.hpp:1697
KOKKOS_FUNCTION size_t getLocalDOFIndex(const size_t &elementIndex, const size_t &globalDOFIndex) const override
Get the elements local DOF from the element index and global DOF index.
Definition LagrangeSpace.hpp:145
FieldLHS evaluateAx(FieldLHS &field, F &evalFunction)
Assembly operations ///////////////////////////////////////////////.
Definition LagrangeSpace.hpp:372
KOKKOS_FUNCTION T evaluateRefElementShapeFunction(const size_t &localDOF, const point_t &localPoint) const
Basis functions and gradients /////////////////////////////////////.
Definition LagrangeSpace.hpp:279
KOKKOS_FUNCTION Vector< size_t, numElementDOFs > getLocalDOFIndices() const override
Get the local DOF indices (vector of local DOF indices) They are independent of the specific element ...
Definition LagrangeSpace.hpp:185
KOKKOS_FUNCTION point_t getInverseTransposeTransformationJacobian(vertex_points_t pt) const
Functions to access element info from outside /////////////////////.
Definition LagrangeSpace.h:208
T computeErrorL2(const FieldLHS &u_h, const F &u_sol) const
Error norm computations ///////////////////////////////////////////.
Definition LagrangeSpace.hpp:1525
KOKKOS_FUNCTION point_t evaluateRefElementShapeFunctionGradient(const size_t &localDOF, const point_t &localPoint) const
Evaluate the gradient of the shape function of a local degree of freedom at a given point in the refe...
Definition LagrangeSpace.hpp:314
FieldLHS evaluateAx_lift(FieldLHS &field, F &evalFunction)
Assemble the left stiffness matrix A of the system but only for the boundary values,...
Definition LagrangeSpace.hpp:1212
void evaluateLumpedMass(FieldRHS &field) const
Functions for error computations, etc. ////////////////////////////.
Definition LagrangeSpace.hpp:1452
KOKKOS_FUNCTION size_t getGlobalDOFIndex(const size_t &elementIndex, const size_t &localDOFIndex) const override
Get the global DOF index from the element index and local DOF.
Definition LagrangeSpace.hpp:173
void updateLayout(Layout_t &layout)
Function to update the element partition and the layout of fields in the LagrangeSpace if the layout ...
Definition LagrangeSpace.hpp:118
Definition UniformCartesian.h:14
Definition Archive.h:20
Device struct for copies //////////////////////////////////////////.
Definition LagrangeSpace.h:290
Definition ViewTypes.h:44