5#ifndef IPPL_FEMPOISSONSOLVER_H
6#define IPPL_FEMPOISSONSOLVER_H
8#include "EvalFunctor.h"
9#include "LinearSolvers/PCG.h"
21 template <
typename FieldLHS,
typename FieldRHS = FieldLHS,
unsigned Order = 1,
22 unsigned QuadNumNodes = 5>
24 constexpr static unsigned Dim = FieldLHS::dim;
25 using Tlhs =
typename FieldLHS::value_type;
29 using typename Base::lhs_type,
typename Base::rhs_type;
30 using MeshType =
typename FieldRHS::Mesh_t;
38 std::conditional_t<Dim == 1, ippl::EdgeElement<Tlhs>,
39 std::conditional_t<Dim == 2, ippl::QuadrilateralElement<Tlhs>,
51 , quadrature_m(refElement_m, 0.0, 0.0)
54 refElement_m, quadrature_m) {
61 , quadrature_m(refElement_m, 0.0, 0.0)
62 , lagrangeSpace_m(rhs.get_mesh(), refElement_m, quadrature_m, rhs.getLayout()) {
63 static_assert(std::is_floating_point<Tlhs>::value,
"Not a floating point type");
65 pcg_algo_m.initializeFields(rhs.get_mesh(), rhs.getLayout());
68 void setRhs(rhs_type& rhs)
override {
71 lagrangeSpace_m.
initialize(rhs.get_mesh(), rhs.getLayout());
72 pcg_algo_m.initializeFields(rhs.get_mesh(), rhs.getLayout());
86 this->rhs_mp->fillHalo();
93 const auto firstElementVertexPoints =
98 refElement_m.getInverseTransposeTransformationJacobian(firstElementVertexPoints);
102 const Tlhs absDetDPhi = Kokkos::abs(
103 refElement_m.getDeterminantOfTransformationJacobian(firstElementVertexPoints));
110 FieldBC bcType = bcField[0]->getBCType();
112 const auto algoOperator = [poissonEquationEval, &bcField,
113 this](rhs_type field) -> lhs_type {
115 field.setFieldBC(bcField);
119 auto return_field = lagrangeSpace_m.
evaluateAx(field, poissonEquationEval);
127 if (bcType == CONSTANT_FACE) {
130 bcField.apply(*(this->rhs_mp));
131 bcField.assignGhostToPhysical(*(this->rhs_mp));
132 this->rhs_mp->fillHalo();
135 - lagrangeSpace_m.
evaluateAx_lift(*(this->rhs_mp), poissonEquationEval);
139 static IpplTimings::TimerRef pcgTimer = IpplTimings::getTimer(
"pcg");
140 IpplTimings::startTimer(pcgTimer);
142 pcg_algo_m(*(this->lhs_mp), *(this->rhs_mp), this->params_m);
144 (this->lhs_mp)->fillHalo();
146 IpplTimings::stopTimer(pcgTimer);
168 template <
typename F>
170 Tlhs error_norm = this->lagrangeSpace_m.
computeErrorL2(*(this->lhs_mp), analytic);
180 Tlhs avg = this->lagrangeSpace_m.
computeAvg(*(this->lhs_mp));
182 lhs_type unit((this->lhs_mp)->get_mesh(), (this->lhs_mp)->getLayout());
184 Tlhs vol = this->lagrangeSpace_m.
computeAvg(unit);
192 PCGSolverAlgorithm_t pcg_algo_m;
195 this->params_m.
add(
"max_iterations", 1000);
196 this->params_m.
add(
"tolerance", (Tlhs)1e-13);
199 ElementType refElement_m;
200 QuadratureType quadrature_m;
201 LagrangeType lagrangeSpace_m;
virtual int getIterationCount()
Definition PCG.h:106
virtual void setOperator(OperatorF op)
Definition PCG.h:70
A solver for the poisson equation using finite element methods and Conjugate Gradient (CG)
Definition FEMPoissonSolver.h:23
void setRhs(rhs_type &rhs) override
Definition FEMPoissonSolver.h:68
virtual void setDefaultParameters() override
Definition FEMPoissonSolver.h:194
Tlhs getResidue() const
Definition FEMPoissonSolver.h:160
int getIterationCount()
Definition FEMPoissonSolver.h:154
LagrangeType & getSpace()
Return the LagrangeSpace object.
Definition FEMPoissonSolver.h:78
Tlhs getL2Error(const F &analytic)
Definition FEMPoissonSolver.h:169
Tlhs getAvg(bool Vol=false)
Definition FEMPoissonSolver.h:179
void solve() override
Solve the poisson equation using finite element methods. The problem is described by -laplace(lhs) = ...
Definition FEMPoissonSolver.h:84
KOKKOS_FUNCTION vertex_points_t getElementMeshVertexPoints(const indices_t &elementNDIndex) const
Get all the global vertex points of an element (given by its NDIndex).
Definition FiniteElementSpace.hpp:271
This is class represents the Gauss-Jacobi quadrature rule on a reference element.
Definition GaussJacobiQuadrature.h:27
Definition HexahedralElement.h:14
A class representing a Lagrange space for finite element methods on a structured, rectilinear grid.
Definition LagrangeSpace.h:36
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
void evaluateLoadVector(FieldRHS &field) const
Assemble the load vector b of the system Ax = b.
Definition LagrangeSpace.hpp:1330
FieldLHS evaluateAx(FieldLHS &field, F &evalFunction)
Assembly operations ///////////////////////////////////////////////.
Definition LagrangeSpace.hpp:372
T computeErrorL2(const FieldLHS &u_h, const F &u_sol) const
Error norm computations ///////////////////////////////////////////.
Definition LagrangeSpace.hpp:1525
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 add(const std::string &key, const T &value)
Definition ParameterList.h:44
virtual void setRhs(rhs_type &rhs)
Definition Poisson.h:96
Representation of the lhs of the problem we are trying to solve.
Definition FEMMaxwellDiffusionSolver.h:29