v0.15.0
Loading...
Searching...
No Matches
CGGTonsorialBubbleBase.cpp
Go to the documentation of this file.
1/** \file CGGTonsorialBubbleBase.hpp
2
3 \brief Implementation of tonsorial bubble base div(v) = 0.
4
5 Implementation is based and motiveted by \cite cockburn2010new. This base
6 is used to approximate stresses using Hdiv base with weakly enforced
7 symmetry.
8
9*/
10
11#include <MoFEM.hpp>
12#include <h1_hdiv_hcurl_l2.h>
13using namespace MoFEM;
15
16using namespace FTensor;
17
18namespace EshelbianPlasticity {
19
20template <typename T>
22 const T *diffN,
23 Tensor2<PackPtr<T *, 9>, 3, 3> &t_phi,
24 const int gdim) {
26
27 // FIXME: In this implementation symmetry of mix derivatives is not exploited
28
29 if (p < 1)
31
32 Index<'i', 3> i;
33 Index<'j', 3> j;
34 Index<'k', 3> k;
35 Index<'m', 3> m;
36 Index<'f', 3> f;
37
38 Tensor1<T, 3> t_diff_n[4];
39 {
40 Tensor1<PackPtr<const T *, 3>, 3> t_diff_n_tmp(&diffN[0], &diffN[1],
41 &diffN[2]);
42 for (int ii = 0; ii != 4; ++ii) {
43 t_diff_n[ii](i) = t_diff_n_tmp(i);
44 ++t_diff_n_tmp;
45 }
46 }
47
48 Tensor1<T, 3> t_diff_ksi[3];
49 for (int ii = 0; ii != 3; ++ii)
50 t_diff_ksi[ii](i) = t_diff_n[ii + 1](i) - t_diff_n[0](i);
51
52 int lp = p >= 2 ? p - 2 + 1 : 0;
53 UBlasVector<T> l[3] = {VectorDouble(lp + 1), VectorDouble(lp + 1),
54 VectorDouble(lp + 1)};
55 UBlasMatrix<T> diff_l[3] = {MatrixDouble(3, lp + 1), MatrixDouble(3, lp + 1),
56 MatrixDouble(3, lp + 1)};
57 UBlasMatrix<T> diff2_l[3] = {MatrixDouble(9, lp + 1), MatrixDouble(9, lp + 1),
58 MatrixDouble(9, lp + 1)};
59
60 for (int ii = 0; ii != 3; ++ii)
61 diff2_l[ii].clear();
62
63 for (int gg = 0; gg != gdim; ++gg) {
64
65 const int node_shift = gg * 4;
66
67 for (int ii = 0; ii != 3; ++ii) {
68
69 auto &t_diff_ksi_ii = t_diff_ksi[ii];
70 auto &l_ii = l[ii];
71 auto &diff_l_ii = diff_l[ii];
72 auto &diff2_l_ii = diff2_l[ii];
73
74 T ksi_ii = N[node_shift + ii + 1] - N[node_shift + 0];
75
76 CHKERR Legendre_polynomials(lp, ksi_ii, &t_diff_ksi_ii(0),
77 &*l_ii.data().begin(),
78 &*diff_l_ii.data().begin(), 3);
79
80 for (int l = 1; l < lp; ++l) {
81 const T a = ((2 * (T)l + 1) / ((T)l + 1));
82 const T b = ((T)l / ((T)l + 1));
83 for (int d0 = 0; d0 != 3; ++d0)
84 for (int d1 = 0; d1 != 3; ++d1) {
85 const int r = 3 * d0 + d1;
86 diff2_l_ii(r, l + 1) = a * (t_diff_ksi_ii(d0) * diff_l_ii(d1, l) +
87 t_diff_ksi_ii(d1) * diff_l_ii(d0, l) +
88 ksi_ii * diff2_l_ii(r, l)) -
89 b * diff2_l_ii(r, l - 1);
90 }
91 }
92 }
93
94 const T n[] = {N[node_shift + 0], N[node_shift + 1], N[node_shift + 2],
95 N[node_shift + 3]};
96
98 Tensor3<T, 3, 3, 3> t_bk_diff;
99 const int tab[4][4] = {
100 {1, 2, 3, 0}, {2, 3, 0, 1}, {3, 0, 1, 2}, {0, 1, 2, 3}};
101 t_bk(i, j) = 0;
102 t_bk_diff(i, j, k) = 0;
103 for (int ii = 0; ii != 3; ++ii) {
104 const int i0 = tab[ii][0];
105 const int i1 = tab[ii][1];
106 const int i2 = tab[ii][2];
107 const int i3 = tab[ii][3];
108 auto &t_diff_n_i0 = t_diff_n[i0];
109 auto &t_diff_n_i1 = t_diff_n[i1];
110 auto &t_diff_n_i2 = t_diff_n[i2];
111 auto &t_diff_n_i3 = t_diff_n[i3];
113 t_k(i, j) = t_diff_n_i3(i) * t_diff_n_i3(j);
114 const T b = n[i0] * n[i1] * n[i2];
115 t_bk(i, j) += b * t_k(i, j);
116 Tensor1<T, 3> t_diff_b;
117 t_diff_b(i) = t_diff_n_i0(i) * n[i1] * n[i2] +
118 t_diff_n_i1(i) * n[i0] * n[i2] +
119 t_diff_n_i2(i) * n[i0] * n[i1];
120 t_bk_diff(i, j, k) += t_k(i, j) * t_diff_b(k);
121 }
122
123 int zz = 0;
124 for (int o = p - 2 + 1; o <= p - 2 + 1; ++o) {
125
126 for (int ii = 0; ii <= o; ++ii)
127 for (int jj = 0; (ii + jj) <= o; ++jj) {
128
129 const int kk = o - ii - jj;
130
131 auto get_diff_l = [&](const int y, const int i) {
132 return Tensor1<T, 3>(diff_l[y](0, i), diff_l[y](1, i),
133 diff_l[y](2, i));
134 };
135 auto get_diff2_l = [&](const int y, const int i) {
136 return Tensor2<T, 3, 3>(
137 diff2_l[y](0, i), diff2_l[y](1, i), diff2_l[y](2, i),
138 diff2_l[y](3, i), diff2_l[y](4, i), diff2_l[y](5, i),
139 diff2_l[y](6, i), diff2_l[y](7, i), diff2_l[y](8, i));
140 };
141
142 auto l_i = l[0][ii];
143 auto t_diff_i = get_diff_l(0, ii);
144 auto t_diff2_i = get_diff2_l(0, ii);
145 auto l_j = l[1][jj];
146 auto t_diff_j = get_diff_l(1, jj);
147 auto t_diff2_j = get_diff2_l(1, jj);
148 auto l_k = l[2][kk];
149 auto t_diff_k = get_diff_l(2, kk);
150 auto t_diff2_k = get_diff2_l(2, kk);
151
152 Tensor1<T, 3> t_diff_l2;
153 t_diff_l2(i) = t_diff_i(i) * l_j * l_k + t_diff_j(i) * l_i * l_k +
154 t_diff_k(i) * l_i * l_j;
155 Tensor2<T, 3, 3> t_diff2_l2;
156 t_diff2_l2(i, j) =
157 t_diff2_i(i, j) * l_j * l_k + t_diff_i(i) * t_diff_j(j) * l_k +
158 t_diff_i(i) * l_j * t_diff_k(j) +
159
160 t_diff2_j(i, j) * l_i * l_k + t_diff_j(i) * t_diff_i(j) * l_k +
161 t_diff_j(i) * l_i * t_diff_k(j) +
162
163 t_diff2_k(i, j) * l_i * l_j + t_diff_k(i) * t_diff_i(j) * l_j +
164 t_diff_k(i) * l_i * t_diff_j(j);
165
166 for (int dd = 0; dd != 3; ++dd) {
167
168 Tensor2<T, 3, 3> t_axial_diff;
169 t_axial_diff(i, j) = 0;
170 for (int mm = 0; mm != 3; ++mm)
171 t_axial_diff(dd, mm) = t_diff_l2(mm);
172
173 FTensor::Tensor3<T, 3, 3, 3> t_levi_civita;
174 t_levi_civita(i, j, k) = FTensor::levi_civita(i, j, k);
175
176 Tensor3<T, 3, 3, 3> t_A_diff;
177 t_A_diff(i, j, k) =
178 levi_civita<double>(i, j, m) * t_axial_diff(m, k);
179 Tensor2<T, 3, 3> t_curl_A;
180 t_curl_A(i, j) = levi_civita<double>(j, m, f) * t_A_diff(i, f, m);
181 Tensor3<T, 3, 3, 3> t_curl_A_bK_diff;
182 t_curl_A_bK_diff(i, j, k) = t_curl_A(i, m) * t_bk_diff(m, j, k);
183
184 Tensor3<T, 3, 3, 3> t_axial_diff2;
185 t_axial_diff2(i, j, k) = 0;
186 for (int mm = 0; mm != 3; ++mm)
187 for (int nn = 0; nn != 3; ++nn)
188 t_axial_diff2(dd, mm, nn) = t_diff2_l2(mm, nn);
189 Tensor4<T, 3, 3, 3, 3> t_A_diff2;
190 t_A_diff2(i, j, k, f) =
191 levi_civita<double>(i, j, m) * t_axial_diff2(m, k, f);
192 Tensor3<T, 3, 3, 3> t_curl_A_diff2;
193 t_curl_A_diff2(i, j, k) =
194 levi_civita<double>(j, m, f) * t_A_diff2(i, f, m, k);
195 Tensor3<T, 3, 3, 3> t_curl_A_diff2_bK;
196 t_curl_A_diff2_bK(i, j, k) = t_curl_A_diff2(i, m, k) * t_bk(m, j);
197
198 t_phi(i, j) =
199 levi_civita<double>(j, m, f) *
200 (t_curl_A_bK_diff(i, f, m) + t_curl_A_diff2_bK(i, f, m));
201
202 ++t_phi;
203 ++zz;
204 }
205 }
206 }
207 if (zz != NBVOLUMETET_CCG_BUBBLE(p))
208 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
209 "Wrong number of base functions %d != %d", zz,
211 }
212
214}
215
216MoFEMErrorCode CGG_BubbleBase_MBTET(const int p, const double *N,
217 const double *diffN,
218 Tensor2<PackPtr<double *, 9>, 3, 3> &t_phi,
219 const int gdim) {
220 return CGG_BubbleBase_MBTET_Impl<double>(p, N, diffN, t_phi, gdim);
221}
222
224 const int p, const std::complex<double> *N,
225 const std::complex<double> *diffN,
226 FTensor::Tensor2<FTensor::PackPtr<std::complex<double> *, 9>, 3, 3> &t_phi,
227 const int gdim) {
228 return CGG_BubbleBase_MBTET_Impl<std::complex<double>>(p, N, diffN, t_phi,
229 gdim);
230}
231
232} // namespace EshelbianPlasticity
Implementation of tonsorial bubble base div(v) = 0.
#define NBVOLUMETET_CCG_BUBBLE(P)
Bubble function for CGG H div space.
constexpr double a
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode Legendre_polynomials(int p, double s, double *diff_s, double *L, double *diffL, int dim)
Calculate Legendre approximation basis.
Functions to approximate hierarchical spaces.
FTensor::Index< 'i', SPACE_DIM > i
const double n
refractive index of diffusive medium
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
MoFEMErrorCode CGG_BubbleBase_MBTET(const int p, const double *N, const double *diffN, FTensor::Tensor2< FTensor::PackPtr< double *, 9 >, 3, 3 > &phi, const int gdim)
Calculate CGGT tonsorial bubble base.
MoFEMErrorCode CGG_BubbleBase_MBTET_Impl(const int p, const T *N, const T *diffN, Tensor2< PackPtr< T *, 9 >, 3, 3 > &t_phi, const int gdim)
Tensors class implemented by Walter Landry.
Definition FTensor.hpp:51
constexpr std::enable_if<(Dim0<=2 &&Dim1<=2), Tensor2_Expr< Levi_Civita< T >, T, Dim0, Dim1, i, j > >::type levi_civita(const Index< i, Dim0 > &, const Index< j, Dim1 > &)
levi_civita functions to make for easy adhoc use
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition ddTensor0.hpp:33
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
ublas::vector< T, VecAllocator< T > > UBlasVector
Definition Types.hpp:66
UBlasMatrix< double > MatrixDouble
Definition Types.hpp:77
UBlasVector< double > VectorDouble
Definition Types.hpp:68
ublas::matrix< T, ublas::row_major, VecAllocator< T > > UBlasMatrix
Definition Types.hpp:75
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
FTensor::Index< 'm', 3 > m
const int N
Definition speed_test.cpp:3