gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
helmholtzTerm.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef HELMHOLTZ_TERM_H
7 #define HELMHOLTZ_TERM_H
8 
9 #include <assert.h>
10 #include "femTerm.h"
11 #include "simpleFunction.h"
12 #include "GmshGlobal.h"
13 #include "GModel.h"
14 #include "SElement.h"
15 #include "fullMatrix.h"
16 #include "Numeric.h"
17 
18 // \nabla \cdot k \nabla U - a U
19 template <class scalar> class helmholtzTerm : public femTerm<scalar> {
20 protected:
22  const int _iFieldR;
23  int _iFieldC;
24 
25 public:
26  helmholtzTerm(GModel *gm, int iFieldR, int iFieldC, simpleFunction<scalar> *k,
28  : femTerm<scalar>(gm), _k(k), _a(a), _iFieldR(iFieldR), _iFieldC(iFieldC)
29  {
30  }
31  // one dof per vertex (nodal fem)
32  virtual int sizeOfR(SElement *se) const
33  {
34  return se->getMeshElement()->getNumShapeFunctions();
35  }
36  virtual int sizeOfC(SElement *se) const
37  {
38  return se->getMeshElement()->getNumShapeFunctions();
39  }
40  Dof getLocalDofR(SElement *se, int iRow) const
41  {
42  return Dof(se->getMeshElement()->getShapeFunctionNode(iRow)->getNum(),
44  }
45  Dof getLocalDofC(SElement *se, int iRow) const
46  {
47  return Dof(se->getMeshElement()->getShapeFunctionNode(iRow)->getNum(),
49  }
50  virtual void elementMatrix(SElement *se, fullMatrix<scalar> &m) const
51  {
52  MElement *e = se->getMeshElement();
53  if(_k) _k->setElement(e);
54  if(_a) _a->setElement(e);
55  // compute integration rule
56  // const int integrationOrder = (_a) ? 2 * e->getPolynomialOrder() :
57  // 2 * (e->getPolynomialOrder() - 1);
58  const int integrationOrder = 2 * e->getPolynomialOrder() + 1;
59 
60  int npts;
61  IntPt *GP;
62  e->getIntegrationPoints(integrationOrder, &npts, &GP);
63  // get the number of nodes
64  const int nbSF = e->getNumShapeFunctions();
65  // assume a maximum of 100 nodes
66  assert(nbSF < 100);
67  double jac[3][3];
68  double invjac[3][3];
69  double Grads[100][3], grads[100][3];
70  double sf[100];
71  // set the local matrix to 0
72  m.setAll(0.);
73  // loop over integration points
74  for(int i = 0; i < npts; i++) {
75  // compute stuff at this point
76  const double u = GP[i].pt[0];
77  const double v = GP[i].pt[1];
78  const double w = GP[i].pt[2];
79  const double weightDetJ = GP[i].weight * e->getJacobian(u, v, w, jac);
80  SPoint3 p;
81  e->pnt(u, v, w, p);
82  const scalar K = _k ? (*_k)(p.x(), p.y(), p.z()) : 0.0;
83  const scalar A = _a ? (*_a)(p.x(), p.y(), p.z()) : 0.0;
84  inv3x3(jac, invjac);
85  e->getGradShapeFunctions(u, v, w, grads);
86  if(_a) e->getShapeFunctions(u, v, w, sf);
87  for(int j = 0; j < nbSF; j++) {
88  Grads[j][0] = invjac[0][0] * grads[j][0] + invjac[0][1] * grads[j][1] +
89  invjac[0][2] * grads[j][2];
90  Grads[j][1] = invjac[1][0] * grads[j][0] + invjac[1][1] * grads[j][1] +
91  invjac[1][2] * grads[j][2];
92  Grads[j][2] = invjac[2][0] * grads[j][0] + invjac[2][1] * grads[j][1] +
93  invjac[2][2] * grads[j][2];
94  if(!_a) sf[j] = 0;
95  }
96  for(int j = 0; j < nbSF; j++) {
97  for(int k = 0; k <= j; k++) {
98  m(j, k) +=
99  (K * (Grads[j][0] * Grads[k][0] + Grads[j][1] * Grads[k][1] +
100  Grads[j][2] * Grads[k][2]) +
101  A * sf[j] * sf[k]) *
102  weightDetJ;
103  }
104  }
105  }
106  for(int j = 0; j < nbSF; j++)
107  for(int k = 0; k < j; k++) m(k, j) = m(j, k);
108  }
109 };
110 
111 #endif
inv3x3
double inv3x3(double mat[3][3], double inv[3][3])
Definition: Numeric.cpp:232
helmholtzTerm::getLocalDofR
Dof getLocalDofR(SElement *se, int iRow) const
Definition: helmholtzTerm.h:40
helmholtzTerm::_a
const simpleFunction< scalar > * _a
Definition: helmholtzTerm.h:21
helmholtzTerm::_iFieldR
const int _iFieldR
Definition: helmholtzTerm.h:22
MElement::getIntegrationPoints
virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts)
Definition: MElement.h:436
fullMatrix::setAll
void setAll(const scalar &m)
Definition: fullMatrix.h:422
SPoint3
Definition: SPoint3.h:14
MVertex::getNum
std::size_t getNum() const
Definition: MVertex.h:86
helmholtzTerm::_k
const simpleFunction< scalar > * _k
Definition: helmholtzTerm.h:21
MElement::getShapeFunctionNode
virtual const MVertex * getShapeFunctionNode(int i) const
Definition: MElement.h:392
helmholtzTerm::getLocalDofC
Dof getLocalDofC(SElement *se, int iRow) const
Definition: helmholtzTerm.h:45
IntPt::pt
double pt[3]
Definition: GaussIntegration.h:13
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
fullMatrix
Definition: MElement.h:27
IntPt::weight
double weight
Definition: GaussIntegration.h:14
simpleFunction
Definition: GModel.h:30
Dof
Definition: dofManager.h:19
helmholtzTerm::sizeOfR
virtual int sizeOfR(SElement *se) const
Definition: helmholtzTerm.h:32
Dof::createTypeWithTwoInts
static int createTypeWithTwoInts(int i1, int i2)
Definition: dofManager.h:28
SElement.h
Numeric.h
GModel
Definition: GModel.h:44
MElement::getNumShapeFunctions
virtual std::size_t getNumShapeFunctions() const
Definition: MElement.h:387
helmholtzTerm
Definition: helmholtzTerm.h:19
SElement
Definition: SElement.h:18
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
MElement
Definition: MElement.h:30
GmshGlobal.h
SElement::getMeshElement
MElement * getMeshElement() const
Definition: SElement.h:35
MElement::pnt
virtual void pnt(double u, double v, double w, SPoint3 &p) const
Definition: MElement.cpp:1072
helmholtzTerm::helmholtzTerm
helmholtzTerm(GModel *gm, int iFieldR, int iFieldC, simpleFunction< scalar > *k, simpleFunction< scalar > *a)
Definition: helmholtzTerm.h:26
IntPt
Definition: GaussIntegration.h:12
simpleFunction.h
helmholtzTerm::sizeOfC
virtual int sizeOfC(SElement *se) const
Definition: helmholtzTerm.h:36
helmholtzTerm::_iFieldC
int _iFieldC
Definition: helmholtzTerm.h:23
MElement::getShapeFunctions
virtual void getShapeFunctions(double u, double v, double w, double s[], int order=-1) const
Definition: MElement.cpp:458
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
MElement::getJacobian
virtual double getJacobian(const fullMatrix< double > &gsf, double jac[3][3]) const
Definition: MElement.cpp:868
GModel.h
femTerm
Definition: femTerm.h:21
MElement::getPolynomialOrder
virtual int getPolynomialOrder() const
Definition: MElement.h:78
femTerm.h
helmholtzTerm::elementMatrix
virtual void elementMatrix(SElement *se, fullMatrix< scalar > &m) const
Definition: helmholtzTerm.h:50
fullMatrix.h
MElement::getGradShapeFunctions
virtual void getGradShapeFunctions(double u, double v, double w, double s[][3], int order=-1) const
Definition: MElement.cpp:468