v0.15.0
Loading...
Searching...
No Matches
base_functions.c
Go to the documentation of this file.
1/** \file base_functions.c
2
3*/
4
5#include <cblas.h>
6#include <petscsys.h>
7#include <phg-quadrule/quad.h>
8
9#include <definitions.h>
10
11#include <base_functions.h>
12
13static PetscErrorCode ierr;
14
15// Note: Implementation of Legendre_polynomials is moved to LegendrePolynomial.cpp
16
17PetscErrorCode Jacobi_polynomials(int p, double alpha, double x, double t,
18 double *diff_x, double *diff_t, double *L,
19 double *diffL, const int dim) {
21#ifndef NDEBUG
22 if (dim < 1)
23 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
24 if (dim > 3)
25 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
26 if (p < 0)
27 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 0");
28
29 if (diffL != NULL) {
30 if (diff_x == NULL) {
31 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "diff_s == NULL");
32 }
33 }
34
35#endif // NDEBUG
36 L[0] = 1;
37 if (diffL != NULL) {
38 diffL[0 * (p + 1) + 0] = 0;
39 if (dim >= 2) {
40 diffL[1 * (p + 1) + 0] = 0;
41 if (dim == 3) {
42 diffL[2 * (p + 1) + 0] = 0;
43 }
44 }
45 }
46 if (p == 0)
48 L[1] = 2 * x - t + alpha * x;
49 if (diffL != NULL) {
50 int d = 0;
51 for (; d < dim; ++d) {
52 double d_t = (diff_t) ? diff_t[d] : 0;
53 diffL[d * (p + 1) + 1] = (2 + alpha) * diff_x[d] - d_t;
54 }
55 }
56 if (p == 1)
58 int l = 1;
59 for (; l < p; l++) {
60 int lp1 = l + 1;
61 double a = 2 * lp1 * (lp1 + alpha) * (2 * lp1 + alpha - 2);
62 double b = 2 * lp1 + alpha - 1;
63 double c = (2 * lp1 + alpha) * (2 * lp1 + alpha - 2);
64 double d = 2 * (lp1 + alpha - 1) * (lp1 - 1) * (2 * lp1 + alpha);
65 double A = b * (c * (2 * x - t) + alpha * alpha * t) / a;
66 double B = d * t * t / a;
67 L[lp1] = A * L[l] - B * L[l - 1];
68 if (diffL != NULL) {
69 int z = 0;
70 for (; z < dim; ++z) {
71 double d_t = (diff_t) ? diff_t[z] : 0;
72 double diffA =
73 b * (c * (2 * diff_x[z] - d_t) + alpha * alpha * d_t) / a;
74 double diffB = d * 2 * t * d_t / a;
75 diffL[z * (p + 1) + lp1] = A * diffL[z * (p + 1) + l] -
76 B * diffL[z * (p + 1) + l - 1] +
77 diffA * L[l] - diffB * L[l - 1];
78 }
79 }
80 }
82}
83
84PetscErrorCode IntegratedJacobi_polynomials(int p, double alpha, double x,
85 double t, double *diff_x,
86 double *diff_t, double *L,
87 double *diffL, const int dim) {
89#ifndef NDEBUG
90 if (dim < 1)
91 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
92 if (dim > 3)
93 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
94 if (p < 1)
95 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 1");
96#endif // NDEBUG
97 L[0] = x;
98 if (diffL != NULL) {
99 int d = 0;
100 for (; d != dim; ++d) {
101 diffL[d * p + 0] = diff_x[d];
102 }
103 }
104 if (p == 0)
106 double jacobi[(p + 1)];
107 double diff_jacobi[(p + 1) * dim];
108 ierr = Jacobi_polynomials(p, alpha, x, t, diff_x, diff_t, jacobi, diff_jacobi,
109 dim);
110 CHKERRQ(ierr);
111 int l = 1;
112 for (; l < p; l++) {
113 int i = l + 1;
114 const double a = (i + alpha) / ((2 * i + alpha - 1) * (2 * i + alpha));
115 const double b = alpha / ((2 * i + alpha - 2) * (2 * i + alpha));
116 const double c = (i - 1) / ((2 * i + alpha - 2) * (2 * i + alpha - 1));
117 L[l] = a * jacobi[i] + b * t * jacobi[i - 1] - c * t * t * jacobi[i - 2];
118 if (diffL != NULL) {
119 int d = 0;
120 for (; d != dim; ++d) {
121 diffL[d * p + l] = a * diff_jacobi[d * (p + 1) + i] +
122 b * (t * diff_jacobi[d * (p + 1) + i - 1] +
123 diff_t[d] * jacobi[i - 1]) -
124 c * (t * t * diff_jacobi[d * (p + 1) + i - 2] +
125 2 * t * diff_t[d] * jacobi[i - 2]);
126 }
127 }
128 }
130}
131
132// Note: Implementation of Lobatto_polynomials is moved to LobattoPolynomial.cpp
133
134static double f_phi0(double x) { return LOBATTO_PHI0(x); }
135static double f_phi1(double x) { return LOBATTO_PHI1(x); }
136static double f_phi2(double x) { return LOBATTO_PHI2(x); }
137static double f_phi3(double x) { return LOBATTO_PHI3(x); }
138static double f_phi4(double x) { return LOBATTO_PHI4(x); }
139static double f_phi5(double x) { return LOBATTO_PHI5(x); }
140static double f_phi6(double x) { return LOBATTO_PHI6(x); }
141static double f_phi7(double x) { return LOBATTO_PHI7(x); }
142static double f_phi8(double x) { return LOBATTO_PHI8(x); }
143static double f_phi9(double x) { return LOBATTO_PHI9(x); }
144
145static double (*f_phi[])(double x) = {f_phi0, f_phi1, f_phi2, f_phi3, f_phi4,
147
148static double f_phi0x(double x) { return LOBATTO_PHI0X(x); }
149static double f_phi1x(double x) { return LOBATTO_PHI1X(x); }
150static double f_phi2x(double x) { return LOBATTO_PHI2X(x); }
151static double f_phi3x(double x) { return LOBATTO_PHI3X(x); }
152static double f_phi4x(double x) { return LOBATTO_PHI4X(x); }
153static double f_phi5x(double x) { return LOBATTO_PHI5X(x); }
154static double f_phi6x(double x) { return LOBATTO_PHI6X(x); }
155static double f_phi7x(double x) { return LOBATTO_PHI7X(x); }
156static double f_phi8x(double x) { return LOBATTO_PHI8X(x); }
157static double f_phi9x(double x) { return LOBATTO_PHI9X(x); }
158
162
163// /// Legendre polynomials
164// #define Legendre0(x) (1.0)
165// #define Legendre1(x) (x)
166// #define Legendre2(x) (1.0 / 2.0 * (3 * (x) * (x) - 1))
167// #define Legendre3(x) (1.0 / 2.0 * (5 * (x) * (x) - 3) * (x))
168// #define Legendre4(x) (1.0 / 8.0 * ((35 * (x) * (x) - 30) * (x) * (x) + 3))
169// #define Legendre5(x) (1.0 / 8.0 * ((63 * (x) * (x) - 70) * (x) * (x) + 15) *
170// (x)) #define Legendre6(x) (1.0 / 16.0 * (((231 * (x) * (x) - 315) * (x) * (x)
171// + 105) * (x) * (x) - 5)) #define Legendre7(x) (1.0 / 16.0 * (((429 * (x) *
172// (x) - 693) * (x) * (x) + 315) * (x) * (x) - 35) * (x)) #define Legendre8(x)
173// (1.0 / 128.0 * ((((6435 * (x) * (x) - 12012) * (x) * (x) + 6930) * (x) * (x)
174// - 1260) * (x) * (x) + 35)) #define Legendre9(x) (1.0 / 128.0 * ((((12155 *
175// (x) * (x) - 25740) * (x) * (x) + 18018) * (x) * (x) - 4620) * (x) * (x) +
176// 315) * (x)) #define Legendre10(x) (1.0 / 256.0 * (((((46189 * (x) * (x) -
177// 109395) * (x) * (x) + 90090) * (x) * (x) - 30030) * (x) * (x) + 3465) * (x) *
178// (x) - 63))
179//
180// /// derivatives of Legendre polynomials
181// #define Legendre0x(x) (0.0)
182// #define Legendre1x(x) (1.0)
183// #define Legendre2x(x) (3.0 * (x))
184// #define Legendre3x(x) (15.0 / 2.0 * (x) * (x) - 3.0 / 2.0)
185// #define Legendre4x(x) (5.0 / 2.0 * (x) * (7.0 * (x) * (x) - 3.0))
186// #define Legendre5x(x) ((315.0 / 8.0 * (x) * (x) - 105.0 / 4.0) * (x) * (x)
187// + 15.0 / 8.0) #define Legendre6x(x) (21.0 / 8.0 * (x) * ((33.0 * (x) * (x)
188// - 30.0) * (x) * (x) + 5.0)) #define Legendre7x(x) (((3003.0 / 16.0 * (x) *
189// (x) - 3465.0 / 16.0) * (x) * (x) + 945.0 / 16.0) * (x) * (x) - 35.0 / 16.0)
190// #define Legendre8x(x) (9.0 / 16.0 * (x) * (((715.0 * (x) * (x) - 1001.0) *
191// (x) * (x) + 385.0) * (x) * (x) - 35.0)) #define Legendre9x(x) ((((109395.0 /
192// 128.0 * (x) * (x) - 45045.0 / 32.0) * (x) * (x) + 45045.0 / 64.0) * (x) * (x)
193// - 3465.0 / 32.0) * (x) * (x) + 315.0 / 128.0) #define Legendre10x(x) (2.0 /
194// 256.0 * (x) * ((((230945.0 * (x) * (x) - 437580.0) * (x) * (x) + 270270.0) *
195// (x) * (x) - 60060.0) * (x) * (x) + 3465.0))
196//
197// /// first two Lobatto shape functions
198// #define l0(x) ((1.0 - (x)) * 0.5)
199// #define l1(x) ((1.0 + (x)) * 0.5)
200//
201// #define l0l1(x) ((1.0 - (x)*(x)) * 0.25)
202//
203// /// other Lobatto shape functions
204// #define l2(x) (phi0(x) * l0l1(x))
205// #define l3(x) (phi1(x) * l0l1(x))
206// #define l4(x) (phi2(x) * l0l1(x))
207// #define l5(x) (phi3(x) * l0l1(x))
208// #define l6(x) (phi4(x) * l0l1(x))
209// #define l7(x) (phi5(x) * l0l1(x))
210// #define l8(x) (phi6(x) * l0l1(x))
211// #define l9(x) (phi7(x) * l0l1(x))
212// #define l10(x) (phi8(x) * l0l1(x))
213// #define l11(x) (phi9(x) * l0l1(x))
214//
215// /// derivatives of Lobatto functions
216// #define dl0(x) (-0.5)
217// #define dl1(x) (0.5)
218// #define dl2(x) (sqrt(3.0/2.0) * Legendre1(x))
219// #define dl3(x) (sqrt(5.0/2.0) * Legendre2(x))
220// #define dl4(x) (sqrt(7.0/2.0) * Legendre3(x))
221// #define dl5(x) (sqrt(9.0/2.0) * Legendre4(x))
222// #define dl6(x) (sqrt(11.0/2.0) * Legendre5(x))
223// #define dl7(x) (sqrt(13.0/2.0) * Legendre6(x))
224// #define dl8(x) (sqrt(15.0/2.0) * Legendre7(x))
225// #define dl9(x) (sqrt(17.0/2.0) * Legendre8(x))
226// #define dl10(x) (sqrt(19.0/2.0) * Legendre9(x))
227// #define dl11(x) (sqrt(21.0/2.0) * Legendre10(x))
228
229PetscErrorCode LobattoKernel_polynomials(int p, double s, double *diff_s,
230 double *L, double *diffL,
231 const int dim) {
233#ifndef NDEBUG
234 if (dim < 1)
235 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim < 1");
236 if (dim > 3)
237 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "dim > 3");
238 if (p < 0)
239 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "p < 0");
240 if (p > 9)
241 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
242 "Polynomial beyond order 9 is not implemented");
243 if (diffL != NULL) {
244 if (diff_s == NULL) {
245 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA, "diff_s == NULL");
246 }
247 }
248
249#endif // NDEBUG
250 if (L) {
251 int l = 0;
252 for (; l != p + 1; l++) {
253 L[l] = f_phi[l](s);
254 }
255 }
256 if (diffL != NULL) {
257 int l = 0;
258 for (; l != p + 1; l++) {
259 double a = f_phix[l](s);
260 int d = 0;
261 for (; d < dim; ++d) {
262 diffL[d * (p + 1) + l] = diff_s[d] * a;
263 }
264 }
265 }
267}
constexpr double a
static double f_phi4(double x)
static double f_phi1(double x)
static double f_phi0(double x)
static double f_phi8x(double x)
PetscErrorCode IntegratedJacobi_polynomials(int p, double alpha, double x, double t, double *diff_x, double *diff_t, double *L, double *diffL, const int dim)
Calculate integrated Jacobi approximation basis.
static double(* f_phi[])(double x)
static double f_phi7(double x)
static double f_phi0x(double x)
static double f_phi4x(double x)
static PetscErrorCode ierr
static double f_phi8(double x)
static double(* f_phix[])(double x)
PetscErrorCode Jacobi_polynomials(int p, double alpha, double x, double t, double *diff_x, double *diff_t, double *L, double *diffL, const int dim)
Calculate Jacobi approximation basis.
static double f_phi2x(double x)
static double f_phi1x(double x)
static double f_phi9x(double x)
static double f_phi5(double x)
static double f_phi7x(double x)
static double f_phi3x(double x)
static double f_phi3(double x)
static double f_phi5x(double x)
static double f_phi6x(double x)
static double f_phi9(double x)
static double f_phi2(double x)
static double f_phi6(double x)
#define LOBATTO_PHI2(x)
#define LOBATTO_PHI5(x)
#define LOBATTO_PHI8(x)
#define LOBATTO_PHI3(x)
#define LOBATTO_PHI7X(x)
#define LOBATTO_PHI0X(x)
Derivatives of kernel functions for Lobbatto base.
#define LOBATTO_PHI2X(x)
#define LOBATTO_PHI5X(x)
#define LOBATTO_PHI0(x)
Definitions taken from Hermes2d code.
#define LOBATTO_PHI1(x)
#define LOBATTO_PHI9X(x)
#define LOBATTO_PHI4(x)
#define LOBATTO_PHI8X(x)
#define LOBATTO_PHI7(x)
#define LOBATTO_PHI6(x)
#define LOBATTO_PHI1X(x)
#define LOBATTO_PHI9(x)
#define LOBATTO_PHI4X(x)
#define LOBATTO_PHI6X(x)
#define LOBATTO_PHI3X(x)
useful compiler derivatives and definitions
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ MOFEM_INVALID_DATA
Definition definitions.h:36
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode LobattoKernel_polynomials(int p, double s, double *diff_s, double *L, double *diffL, const int dim)
Calculate Kernel Lobatto base functions.
FTensor::Index< 'i', SPACE_DIM > i
const double c
speed of light (cm/ns)
FTensor::Index< 'l', 3 > l
constexpr AssemblyType A
constexpr double t
plate stiffness
Definition plate.cpp:58