karniadakisOp.hh

Go to the documentation of this file.
1 
7 #ifndef karniadakisOp_hh
8 #define karniadakisOp_hh
9 
10 
11 #include "toolbox/array.hh"
12 
13 
14 namespace concepts {
15 
46  inline const concepts::Array<Real> computeKarniadakisValues(uint np, const Real* absc,
47  uint npx, uint type) {
48 
49  //at least first order functions
51 
52  //only value and derivative - evaluation implemented
53  if (type > 1)
54  throw conceptsException(concepts::MissingFeature("Only Karniadakis type evaluation not supported yet."));
55 
56  //values of derivative or values
57  concepts::Array<Real> val((np + 1) * npx);
58 
59 
60  //jacobi(alpha=1,beta=1) polynomials evaluations on [0,1] representations
61  concepts::Array<Real> jacobi;
62  if (np >= 2) {
63  jacobi = concepts::Array<Real>((np - 1) * npx);
64 
65  //values for recursion formula
66  Real an, bn, dn;
67 
68  for (uint i = 0; i < npx; ++i) {
69  Real x = absc[i];
70  // Q_0
71  jacobi[i] = 1.0;
72  if (np >= 3) {
73  //Q_1
74  jacobi[npx + i] = 4 * x - 2.0;
75  //recursive formula
76  //dn*Q_{n}(x) = (2an * x - an)Q_{n-1}(x) - bn * Q_{n-2}(x)
77  for (uint n = 2; n < np - 1; ++n) {
78  an = 2 * n * (2 * n + 1) * (2 * n + 2);
79  bn = 2 * n * n * (2 * n + 2);
80  dn = 2 * n * 2 * n * (n + 2);
81  jacobi[n * npx + i] = ((2 * an * x - an) * jacobi[(n - 1)
82  * npx + i] - bn * jacobi[(n - 2) * npx + i]) / dn;
83  }// for j
84  }// if np >= 3
85  }//for i
86  }// if np >= 2
87 
88 
89  switch (type) {
90  case (0): {
91 
92  //evaluate transformed karniadakis polynomials K_0 and K_1
93  for (uint i = 0; i < npx; ++i) {
94  val[i] = 1 - absc[i];
95  val[npx + i] = absc[i];
96  }
97  //build karniadakis K_m evaluations
98  //loop over jacobi polynomials
99  for (uint n = 0; n < np - 1; ++n) {
100  uint m = n + 2;
101  //loop over abscissa points
102  for (uint i = 0; i < npx; ++i) {
103  // K_m = (1-x)*x * Q_{m-2} = K_0*K_1 * Q_{m-2}, m = n + 2
104  val[m * npx + i] = (val[i] * val[npx + i])
105  * jacobi[n * npx + i];
106  }
107  }
108  break;
109  }//case normal values
110 
111  case (1): {
112  //derivative of the polynomial = JacobiPolynomial ( alpha = 2, beta = 2)
113  concepts::Array<Real> jacobiD;
114  if (np >= 3) {
115  jacobiD = concepts::Array<Real>((np - 2) * npx);
116  //values for recursion formula
117  Real an, bn, dn;
118  for (uint i = 0; i < npx; ++i) {
119  Real x = absc[i];
120  // Q_0
121  jacobiD[i] = 1.0;
122  if (np >= 4) {
123  //Q_1
124  jacobiD[npx + i] = 6.0 * x - 3.0;
125  //recursive formula
126  //dn*Q_{n}(x) = (2an * x - an)Q_{n-1}(x) - bn * Q_{n-2}(x)
127  for (uint n = 2; n < np - 2; ++n) {
128  an = (2 * n + 2) * (2 * n + 3) * (2 * n + 4);
129  bn = 2 * (n + 1) * (n + 1) * (2 * n + 4);
130  dn = 2 * n * (n + 4) * (2 * n + 2);
131  jacobiD[n * npx + i] = ((2 * an * x - an) * jacobiD[(n
132  - 1) * npx + i] - bn * jacobiD[(n - 2) * npx
133  + i]) / dn;
134  }// for j
135  }// if np >= 3
136  }//for i
137  }
138  //evaluate karniadakis polynomials K_0 and K_1
139  for (uint i = 0; i < npx; ++i) {
140  val[i] = -0.5;
141  val[npx + i] = 0.5;
142  }
143 
144  if (np >= 2) {
145  // (-0.25z^2+0.25)' -> -0.5z -> z = 2x-1 -> -x+0.5 (derivative of p=2 karniadakis)
146 
147  // loop over all fcts.
148  for (uint n = 0; n < np - 1; ++n) {
149  uint m = n + 2;
150  // loop over all points
151  for (uint i = 0; i < npx; ++i) {
152  Real x = absc[i];
153  // dx [ - 0.25z^2 +0.25 ] * dx/dz , z = 2x-1, as substituted multiplied with P_n^(1,1)(2x-1)
154  Real& v = val[m * npx + i] = (0.5 - x)
155  * jacobi[n * npx + i];
156 
157  if (n > 0)
158  // + (- 0.25z^2 +0.25) * d/dx P_n(1,1)(z) * dx/dz, z = 2x-1
159  // = (- x^2+x) * (n+3)/2*P_{n-1}^(2,2)(2x-1) * 1/2
160  v += (x - x * x) * (n + 3) / 2 * jacobiD[(n - 1) * npx
161  + i];
162  } //loop i
163  } //loop n
164  } //np>=2
165  break;
166  } //case == derivative
167 
168  default:
169  //already thrown above
170  throw conceptsException(concepts::MissingFeature("Karniadakis type evaluation not supported yet."));
171  break;
172  }
173 
174  return val;
175 }
176 
177 
178 
179 } // namespace concepts
180 
181 #endif // karniadakisOp_hh
#define conceptsException(exc)
Prepares an exception for throwing.
Definition: exceptions.hh:344
#define conceptsAssert(cond, exc)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:394
Exception class for assertions.
Definition: exceptions.hh:258
const concepts::Array< Real > computeKarniadakisValues(uint np, const Real *absc, uint npx, uint type)
Evaluate (transformed) Karniadakis Shapefunctions up to a order np on requested abcissa points in [0,...
Exception class to express a missing feature.
Definition: exceptions.hh:206
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich