File: BergotBasis.cpp

package info (click to toggle)
gmsh 4.8.4%2Bds2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 87,812 kB
  • sloc: cpp: 378,014; ansic: 99,669; yacc: 7,216; python: 6,680; java: 3,486; lisp: 659; lex: 621; perl: 571; makefile: 470; sh: 440; xml: 415; javascript: 113; pascal: 35; modula3: 32
file content (159 lines) | stat: -rw-r--r-- 5,863 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Gmsh - Copyright (C) 1997-2021 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/gmsh/gmsh/issues.

#include <cmath>
#include "BergotBasis.h"
#include "MElement.h"
#include "orthogonalBasis.h"

BergotBasis::BergotBasis(int p, bool incpl) : order(p), incomplete(incpl)
{
  if(incomplete && order > 2) {
    Msg::Error("Incomplete pyramids of order %i not yet implemented", order);
  }
}

BergotBasis::~BergotBasis() {}

bool BergotBasis::validIJ(int i, int j) const
{
  if(!incomplete) return (i <= order) && (j <= order);
  if(i + j <= order) return true;
  if(i + j == order + 1) return i == 1 || j == 1;
  return false;
}

// Values of Bergot basis functions for coordinates (u,v,w) in the unit pyramid:
// f = L_i(uhat)*L_j(vhat)*(1-w)^max(i,j)*P_k^{2*max(i,j)+2,0}(what)
// with i,j = 0...order and k = 0...order-max(i,j)
// and (uhat,vhat,what) = (u/(1-w),v/(1-w),2*w-1) reduced coordinates in the
// unit cube [-1,1]^3
void BergotBasis::f(double u, double v, double w, double *val) const
{
  // Compute Legendre polynomials at uhat
  double uhat = (w == 1.) ? 0. : u / (1. - w);
  std::vector<double> uFcts(order + 1);
  LegendrePolynomials::f(order, uhat, &(uFcts[0]));

  // Compute Legendre polynomials at vhat
  double vhat = (w == 1.) ? 0. : v / (1. - w);
  std::vector<double> vFcts(order + 1);
  LegendrePolynomials::f(order, vhat, &(vFcts[0]));

  // Compute Jacobi polynomials at what
  double what = 2. * w - 1.;
  std::vector<std::vector<double> > wFcts(order + 1), wGrads(order + 1);
  for(int mIJ = 0; mIJ <= order; mIJ++) {
    int kMax = order - mIJ;
    std::vector<double> &wf = wFcts[mIJ];
    wf.resize(kMax + 1);
    JacobiPolynomials::f(kMax, 2. * mIJ + 2., 0., what, &(wf[0]));
  }

  // Recombine to find shape function values
  int index = 0;
  for(int i = 0; i <= order; i++) {
    for(int j = 0; j <= order; j++) {
      if(validIJ(i, j)) {
        int mIJ = std::max(i, j);
        double fact = pow(1. - w, mIJ);
        std::vector<double> &wf = wFcts[mIJ];
        for(int k = 0; k <= order - mIJ; k++, index++)
          val[index] = uFcts[i] * vFcts[j] * wf[k] * fact;
      }
    }
  }
}

// Derivatives of Bergot basis functions for coordinates (u,v,w) in the unit
// pyramid: dfdu =
// L'_i(uhat)*L_j(vhat)*(1-w)^(max(i,j)-1)*P_k^{2*max(i,j)+2,0}(what) dfdv =
// L_i(uhat)*L'_j(vhat)*(1-w)^(max(i,j)-1)*P_k^{2*max(i,j)+2,0}(what) dfdw =
// (1-w)^(max(i,j)-2)*P_k^{2*max(i,j)+2,0}(what)*(u*L'_i(uhat)*L_j(vhat)+v*L_i(uhat)*L'_j(vhat))
//        +
//        u*v*(1-w)^(max(i,j)-1)*(2*(1-w)*P'_k^{2*max(i,j)+2,0}(what)-max(i,j)*P_k^{2*max(i,j)+2,0}(what))
// with i,j = 0...order and k = 0...order-max(i,j)
// and (uhat,vhat,what) = (u/(1-w),v/(1-w),2*w-1) reduced coordinates in the
// unit cube [-1,1]^3
void BergotBasis::df(double u, double v, double w, double grads[][3]) const
{
  // Compute Legendre polynomials and derivatives at uhat
  double uhat = (w == 1.) ? 0. : u / (1. - w);
  std::vector<double> uFcts(order + 1), uGrads(order + 1);
  LegendrePolynomials::f(order, uhat, &(uFcts[0]));
  LegendrePolynomials::df(order, uhat, &(uGrads[0]));

  // Compute Legendre polynomials and derivatives at vhat
  double vhat = (w == 1.) ? 0. : v / (1. - w);
  std::vector<double> vFcts(order + 1), vGrads(order + 1);
  LegendrePolynomials::f(order, vhat, &(vFcts[0]));
  LegendrePolynomials::df(order, vhat, &(vGrads[0]));

  // Compute Jacobi polynomials and derivatives at what
  double what = 2. * w - 1.;
  std::vector<std::vector<double> > wFcts(order + 1), wGrads(order + 1);
  for(int mIJ = 0; mIJ <= order; mIJ++) {
    int kMax = order - mIJ;
    std::vector<double> &wf = wFcts[mIJ], &wg = wGrads[mIJ];
    wf.resize(kMax + 1);
    wg.resize(kMax + 1);
    JacobiPolynomials::f(kMax, 2. * mIJ + 2., 0., what, &(wf[0]));
    JacobiPolynomials::df(kMax, 2. * mIJ + 2., 0., what, &(wg[0]));
  }

  // Recombine to find the shape function gradients
  int index = 0;
  for(int i = 0; i <= order; i++) {
    for(int j = 0; j <= order; j++) {
      if(validIJ(i, j)) {
        int mIJ = std::max(i, j);
        std::vector<double> &wf = wFcts[mIJ], &wg = wGrads[mIJ];
        if(mIJ == 0) { // Indeterminate form for mIJ = 0
          for(int k = 0; k <= order - mIJ; k++, index++) {
            grads[index][0] = 0.;
            grads[index][1] = 0.;
            grads[index][2] = 2. * wg[k];
          }
        }
        else if(mIJ == 1) { // Indeterminate form for mIJ = 1
          if(i == 0) {
            for(int k = 0; k <= order - mIJ; k++, index++) {
              grads[index][0] = 0.;
              grads[index][1] = wf[k];
              grads[index][2] = 2. * v * wg[k];
            }
          }
          else if(j == 0) {
            for(int k = 0; k <= order - mIJ; k++, index++) {
              grads[index][0] = wf[k];
              grads[index][1] = 0.;
              grads[index][2] = 2. * u * wg[k];
            }
          }
          else {
            for(int k = 0; k <= order - mIJ; k++, index++) {
              grads[index][0] = vhat * wf[k];
              grads[index][1] = uhat * wf[k];
              grads[index][2] = uhat * vhat * wf[k] + 2. * uhat * v * wg[k];
            }
          }
        }
        else { // General formula
          double oMW = 1. - w;
          double powM2 = pow(oMW, mIJ - 2);
          double powM1 = powM2 * oMW;
          for(int k = 0; k <= order - mIJ; k++, index++) {
            grads[index][0] = uGrads[i] * vFcts[j] * wf[k] * powM1;
            grads[index][1] = uFcts[i] * vGrads[j] * wf[k] * powM1;
            grads[index][2] =
              wf[k] * powM2 *
                (u * uGrads[i] * vFcts[j] + v * uFcts[i] * vGrads[j]) +
              uFcts[i] * vFcts[j] * powM1 * (2. * oMW * wg[k] - mIJ * wf[k]);
          }
        }
      }
    }
  }
}