v0.15.0
Loading...
Searching...
No Matches
LobattoPolynomial.cpp
Go to the documentation of this file.
1/** \file LobattoPolynomial.cpp
2 * \brief implementation of multi-grid solver for p- adaptivity
3 */
4
5
6
7namespace MoFEM {
8
10LobattoPolynomialCtx::query_interface(boost::typeindex::type_index type_index,
11 UnknownInterface **iface) const {
12 *iface = const_cast<LobattoPolynomialCtx *>(this);
13 return 0;
14}
15
17LobattoPolynomial::query_interface(boost::typeindex::type_index type_index,
18 UnknownInterface **iface) const {
19 *iface = const_cast<LobattoPolynomial *>(this);
20 return 0;
21}
22
25 boost::shared_ptr<BaseFunctionCtx> ctx_ptr) {
26
28 auto ctx = ctx_ptr->getInterface<LobattoPolynomialCtx>();
29 // Polynomial order start from 2nd order
30 ctx->baseFunPtr->resize(pts.size2(), ctx->P + 1, false);
31 ctx->baseDiffFunPtr->resize(pts.size2(), ctx->dIm * (ctx->P + 1), false);
32 double *l = NULL;
33 double *diff_l = NULL;
34 for (unsigned int gg = 0; gg < pts.size2(); gg++) {
35 if (ctx->baseFunPtr)
36 l = &((*ctx->baseFunPtr)(gg, 0));
37 if (ctx->baseDiffFunPtr)
38 diff_l = &((*ctx->baseDiffFunPtr)(gg, 0));
39 ierr = (ctx->basePolynomialsType0)(ctx->P, pts(0, gg), ctx->diffS, l,
40 diff_l, ctx->dIm);
42 }
44}
45
47 boost::typeindex::type_index type_index, UnknownInterface **iface) const {
48 *iface = const_cast<KernelLobattoPolynomialCtx *>(this);
49 return 0;
50}
51
53 boost::typeindex::type_index type_index, UnknownInterface **iface) const {
54 *iface = const_cast<KernelLobattoPolynomial *>(this);
55 return 0;
56}
57
60 boost::shared_ptr<BaseFunctionCtx> ctx_ptr) {
61
63 auto ctx = ctx_ptr->getInterface<KernelLobattoPolynomialCtx>();
64 ctx->baseFunPtr->resize(pts.size2(), ctx->P + 1, false);
65 ctx->baseDiffFunPtr->resize(pts.size2(), ctx->dIm * (ctx->P + 1), false);
66 double *l = NULL;
67 double *diff_l = NULL;
68 for (unsigned int gg = 0; gg < pts.size2(); gg++) {
69 if (ctx->baseFunPtr)
70 l = &((*ctx->baseFunPtr)(gg, 0));
71 if (ctx->baseDiffFunPtr)
72 diff_l = &((*ctx->baseDiffFunPtr)(gg, 0));
73 ierr = (ctx->basePolynomialsType0)(ctx->P, pts(0, gg), ctx->diffS, l,
74 diff_l, ctx->dIm);
76 }
78}
79
80PetscErrorCode Lobatto_polynomials(int p, double s, double *diff_s, double *L,
81 double *diffL, const int dim) {
82
84#ifndef NDEBUG
85 if (dim < 1)
86 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
87 if (dim > 3)
88 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
89 if (p < 2)
90 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 2");
91#endif // NDEBUG
92 double l[p + 1];
93 ierr = Legendre_polynomials(p, s, NULL, l, NULL, 1);
94 CHKERRQ(ierr);
95
96 L[0] = 1;
97 if (diffL != NULL) {
98 for (int d = 0; d != dim; ++d) {
99 diffL[d * (p + 1) + 0] = 0;
100 }
101 }
102 L[1] = s;
103 if (diffL != NULL) {
104#ifndef NDEBUG
105 if (diff_s == NULL) {
106 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "diff_s == NULL");
107 }
108#endif // NDEBUG
109 for (int d = 0; d != dim; ++d) {
110 diffL[d * (p + 1) + 1] = diff_s[d];
111 }
112 }
113
114 // Integrated Legendre
115 for (int k = 2; k <= p; k++) {
116 const double factor = 2 * (2 * k - 1);
117 L[k] = 1.0 / factor * (l[k] - l[k - 2]);
118 }
119
120 if (diffL != NULL) {
121 for (int k = 2; k <= p; k++) {
122 double a = l[k - 1] / 2.;
123 for (int d = 0; d != dim; ++d) {
124 diffL[d * (p + 1) + k] = a * diff_s[d];
125 }
126 }
127 }
129}
130
131} // namespace MoFEM
constexpr double a
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode Lobatto_polynomials(int p, double s, double *diff_s, double *L, double *diffL, const int dim)
Calculate Lobatto basis functions .
PetscErrorCode Legendre_polynomials(int p, double s, double *diff_s, double *L, double *diffL, int dim)
Calculate Legendre approximation basis.
FTensor::Index< 'l', 3 > l
FTensor::Index< 'k', 3 > k
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
Context class for Kernel Lobatto basis function arguments.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Class for calculating Kernel Lobatto basis functions.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
MoFEMErrorCode getValue(MatrixDouble &pts, boost::shared_ptr< BaseFunctionCtx > ctx_ptr)
Evaluate Kernel Lobatto basis functions at given points.
boost::shared_ptr< MatrixDouble > baseFunPtr
Pointer to base function matrix.
Context class for Lobatto basis function arguments.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Class for calculating Lobatto basis functions.
MoFEMErrorCode getValue(MatrixDouble &pts, boost::shared_ptr< BaseFunctionCtx > ctx_ptr)
Evaluate Lobatto basis functions at given points.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
base class for all interface classes
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.