File: terms.cpp

package info (click to toggle)
gmsh 4.7.1%2Bds1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 95,484 kB
  • sloc: cpp: 566,747; ansic: 150,384; yacc: 7,198; python: 6,130; java: 3,486; lisp: 622; lex: 621; makefile: 613; perl: 571; sh: 439; xml: 415; javascript: 113; pascal: 35; modula3: 32
file content (185 lines) | stat: -rw-r--r-- 6,696 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Gmsh - Copyright (C) 1997-2020 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.
//
// Contributor(s):
//   Eric Bechet
//

#include "terms.h"

void BilinearTermToScalarTerm::get(MElement *ele, int npts, IntPt *GP,
                                   double &val) const
{
  fullMatrix<double> localMatrix;
  bilterm.get(ele, npts, GP, localMatrix);
  val = localMatrix(0, 0);
}

void BilinearTermBase::get(MElement *ele, int npts, IntPt *GP,
                           fullMatrix<double> &m) const
{
  std::vector<fullMatrix<double> > mv(npts);
  get(ele, npts, GP, mv);
  m.resize(mv[0].size1(), mv[0].size2());
  m.setAll(0.);
  double jac[3][3];
  for(int k = 0; k < npts; k++) {
    const double u = GP[k].pt[0];
    const double v = GP[k].pt[1];
    const double w = GP[k].pt[2];
    const double weight = GP[k].weight;
    const double detJ = ele->getJacobian(u, v, w, jac);
    const double coeff = weight * detJ;
    for(int i = 0; i < mv[k].size1(); ++i)
      for(int j = 0; j < mv[k].size2(); ++j) m(i, j) += mv[k](i, j) * coeff;
  }
}

IsotropicElasticTerm::IsotropicElasticTerm(FunctionSpace<SVector3> &space1_,
                                           FunctionSpace<SVector3> &space2_,
                                           double E_, double nu_)
  : BilinearTerm<SVector3, SVector3>(space1_, space2_), E(E_), nu(nu_), H(6, 6)
{
  double FACT = E / (1 + nu);
  double C11 = FACT * (1 - nu) / (1 - 2 * nu);
  double C12 = FACT * nu / (1 - 2 * nu);
  double C44 = (C11 - C12) / 2;
  H.scale(0.);
  for(int i = 0; i < 3; ++i) {
    H(i, i) = C11;
    H(i + 3, i + 3) = C44;
  }
  H(1, 0) = H(0, 1) = H(2, 0) = H(0, 2) = H(1, 2) = H(2, 1) = C12;
  sym = (&space1_ == &space2_);
}
IsotropicElasticTerm::IsotropicElasticTerm(FunctionSpace<SVector3> &space1_,
                                           double E_, double nu_)
  : BilinearTerm<SVector3, SVector3>(space1_, space1_), E(E_), nu(nu_), H(6, 6)
{
  double FACT = E / (1 + nu);
  double C11 = FACT * (1 - nu) / (1 - 2 * nu);
  double C12 = FACT * nu / (1 - 2 * nu);
  double C44 = (C11 - C12) / 2;
  /*  FACT = E / (1 - nu * nu); // plane stress (plates)
    C11  = FACT;
    C12  = nu * FACT;
    C44 = (1. - nu) * .5 * FACT;*/
  H.scale(0.);
  for(int i = 0; i < 3; ++i) {
    H(i, i) = C11;
    H(i + 3, i + 3) = C44;
  }
  H(1, 0) = H(0, 1) = H(2, 0) = H(0, 2) = H(1, 2) = H(2, 1) = C12;
  sym = true;
}

void IsotropicElasticTerm::get(MElement *ele, int npts, IntPt *GP,
                               fullMatrix<double> &m) const
{
  if(ele->getParent()) ele = ele->getParent();
  if(sym) {
    int nbFF = BilinearTerm<SVector3, SVector3>::space1.getNumKeys(ele);
    double jac[3][3];
    fullMatrix<double> B(6, nbFF);
    fullMatrix<double> BTH(nbFF, 6);
    fullMatrix<double> BT(nbFF, 6);
    m.resize(nbFF, nbFF);
    m.setAll(0.);
    // std::cout << m.size1() << "  " << m.size2() << std::endl;
    for(int i = 0; i < npts; i++) {
      const double u = GP[i].pt[0];
      const double v = GP[i].pt[1];
      const double w = GP[i].pt[2];
      const double weight = GP[i].weight;
      const double detJ = ele->getJacobian(u, v, w, jac);
      std::vector<TensorialTraits<SVector3>::GradType> Grads;
      BilinearTerm<SVector3, SVector3>::space1.gradf(ele, u, v, w,
                                                     Grads); // a optimiser ??
      for(int j = 0; j < nbFF; j++) {
        BT(j, 0) = B(0, j) = Grads[j](0, 0);
        BT(j, 1) = B(1, j) = Grads[j](1, 1);
        BT(j, 2) = B(2, j) = Grads[j](2, 2);
        BT(j, 3) = B(3, j) = Grads[j](0, 1) + Grads[j](1, 0);
        BT(j, 4) = B(4, j) = Grads[j](1, 2) + Grads[j](2, 1);
        BT(j, 5) = B(5, j) = Grads[j](0, 2) + Grads[j](2, 0);
      }
      BTH.setAll(0.);
      BTH.gemm(BT, H);
      m.gemm(BTH, B, weight * detJ, 1.); // m = m + w*detJ*BT*H*B
    }
  }
  else {
    int nbFF1 = BilinearTerm<SVector3, SVector3>::space1.getNumKeys(ele);
    int nbFF2 = BilinearTerm<SVector3, SVector3>::space2.getNumKeys(ele);
    double jac[3][3];
    fullMatrix<double> B(6, nbFF2);
    fullMatrix<double> BTH(nbFF2, 6);
    fullMatrix<double> BT(nbFF1, 6);
    m.resize(nbFF1, nbFF2);
    m.setAll(0.);
    // Sum on Gauss Points i
    for(int i = 0; i < npts; i++) {
      const double u = GP[i].pt[0];
      const double v = GP[i].pt[1];
      const double w = GP[i].pt[2];
      const double weight = GP[i].weight;
      const double detJ = ele->getJacobian(u, v, w, jac);
      std::vector<TensorialTraits<SVector3>::GradType>
        Grads; // tableau de matrices...
      std::vector<TensorialTraits<SVector3>::GradType>
        GradsT; // tableau de matrices...
      BilinearTerm<SVector3, SVector3>::space1.gradf(ele, u, v, w, Grads);
      BilinearTerm<SVector3, SVector3>::space2.gradf(ele, u, v, w, GradsT);
      for(int j = 0; j < nbFF1; j++) {
        BT(j, 0) = Grads[j](0, 0);
        BT(j, 1) = Grads[j](1, 1);
        BT(j, 2) = Grads[j](2, 2);
        BT(j, 3) = Grads[j](0, 1) + Grads[j](1, 0);
        BT(j, 4) = Grads[j](1, 2) + Grads[j](2, 1);
        BT(j, 5) = Grads[j](0, 2) + Grads[j](2, 0);
      }
      for(int j = 0; j < nbFF2; j++) {
        B(0, j) = GradsT[j](0, 0);
        B(1, j) = GradsT[j](1, 1);
        B(2, j) = GradsT[j](2, 2);
        B(3, j) = GradsT[j](0, 1) + GradsT[j](1, 0);
        B(4, j) = GradsT[j](1, 2) + GradsT[j](2, 1);
        B(5, j) = GradsT[j](0, 2) + GradsT[j](2, 0);
      }
      BTH.setAll(0.);
      BTH.gemm(BT, H);
      // gemm add the product to m so there is a sum on gauss' points here
      m.gemm(BTH, B, weight * detJ, 1.);
    }
  }
}

void LagMultTerm::get(MElement *ele, int npts, IntPt *GP,
                      fullMatrix<double> &m) const
{
  int nbFF1 = BilinearTerm<SVector3, SVector3>::space1.getNumKeys(
    ele); // nbVertices*nbcomp of parent
  int nbFF2 = BilinearTerm<SVector3, SVector3>::space2.getNumKeys(
    ele); // nbVertices of boundary
  double jac[3][3];
  m.resize(nbFF1, nbFF2);
  m.setAll(0.);
  for(int i = 0; i < npts; i++) {
    double u = GP[i].pt[0];
    double v = GP[i].pt[1];
    double w = GP[i].pt[2];
    const double weight = GP[i].weight;
    const double detJ = ele->getJacobian(u, v, w, jac);
    std::vector<TensorialTraits<SVector3>::ValType> Vals;
    std::vector<TensorialTraits<SVector3>::ValType> ValsT;
    BilinearTerm<SVector3, SVector3>::space1.f(ele, u, v, w, Vals);
    BilinearTerm<SVector3, SVector3>::space2.f(ele, u, v, w, ValsT);
    for(int j = 0; j < nbFF1; j++) {
      for(int k = 0; k < nbFF2; k++) {
        m(j, k) += _eqfac * dot(Vals[j], ValsT[k]) * weight * detJ;
      }
    }
  }
}