gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
femTerm.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 FEM_TERM_H
7 #define FEM_TERM_H
8 
9 #include <math.h>
10 #include <map>
11 #include <vector>
12 #include "fullMatrix.h"
13 #include "simpleFunction.h"
14 #include "dofManager.h"
15 #include "GModel.h"
16 #include "SElement.h"
17 #include "groupOfElements.h"
18 
19 // a nodal finite element term : variables are always defined at nodes
20 // of the mesh
21 template <class T> class femTerm {
22 private:
23  typedef typename dofTraits<T>::VecType dataVec;
24  typedef typename dofTraits<T>::MatType dataMat;
25 
26 protected:
28 
29 public:
30  femTerm(GModel *gm) : _gm(gm) {}
31  virtual ~femTerm() {}
32  // return the number of columns of the element matrix
33  virtual int sizeOfC(SElement *se) const = 0;
34  // return the number of rows of the element matrix
35  virtual int sizeOfR(SElement *se) const = 0;
36  // in a given element, return the dof associated to a given row (column)
37  // of the local element matrix
38  virtual Dof getLocalDofR(SElement *se, int iRow) const = 0;
39  // default behavior: symmetric
40  virtual Dof getLocalDofC(SElement *se, int iCol) const
41  {
42  return getLocalDofR(se, iCol);
43  }
44  // compute the elementary matrix
45  virtual void elementMatrix(SElement *se, fullMatrix<dataMat> &m) const = 0;
46  virtual void elementVector(SElement *se, fullVector<dataVec> &m) const
47  {
48  m.scale(0.0);
49  }
50 
51  // add the contribution from all the elements in the intersection
52  // of two element groups L and C
54  groupOfElements &C) const
55  {
56  auto it = L.begin();
57  for(; it != L.end(); ++it) {
58  MElement *eL = *it;
59  if(&C == &L || C.find(eL)) {
60  SElement se(eL);
61  addToMatrix(dm, &se);
62  }
63  }
64  }
65 
66  // add the contribution from a single element to the dof manager
68  {
69  const int nbR = sizeOfR(se);
70  const int nbC = sizeOfC(se);
71  fullMatrix<dataMat> localMatrix(nbR, nbC);
72  elementMatrix(se, localMatrix);
73  addToMatrix(dm, localMatrix, se);
74  }
76  SElement *se) const
77  {
78  const int nbR = localMatrix.size1();
79  const int nbC = localMatrix.size2();
80  std::vector<Dof> R, C; // better use default consdtructors and reserve the
81  // right amount of space to avoid reallocation
82  R.reserve(nbR);
83  C.reserve(nbC);
84  bool sym = true;
85  if(nbR == nbC) {
86  for(int j = 0; j < nbR; j++) {
87  Dof r(getLocalDofR(se, j));
88  Dof c(getLocalDofC(se, j));
89  R.push_back(r);
90  C.push_back(c);
91  if(!(r == c)) sym = false;
92  }
93  }
94  else {
95  sym = false;
96  for(int j = 0; j < nbR; j++) R.push_back(getLocalDofR(se, j));
97  for(int k = 0; k < nbC; k++) C.push_back(getLocalDofC(se, k));
98  }
99  if(!sym)
100  dm.assemble(R, C, localMatrix);
101  else
102  dm.assemble(R, localMatrix);
103  }
104 
105  void dirichletNodalBC(int physical, int dim, int comp, int field,
106  const simpleFunction<dataVec> &e,
108  {
109  std::vector<MVertex *> v;
110  GModel *m = _gm;
111  m->getMeshVerticesForPhysicalGroup(dim, physical, v);
112  for(std::size_t i = 0; i < v.size(); i++)
113  dm.fixVertex(v[i], comp, field, e(v[i]->x(), v[i]->y(), v[i]->z()));
114  }
115 
116  void neumannNodalBC(MElement *e, int comp, int field,
117  const simpleFunction<dataVec> &fct,
119  {
120  double jac[3][3];
121  double sf[256];
122  int integrationOrder = 2 * e->getPolynomialOrder();
123  int npts;
124  IntPt *GP;
125  e->getIntegrationPoints(integrationOrder, &npts, &GP);
126  for(int ip = 0; ip < npts; ip++) {
127  const double u = GP[ip].pt[0];
128  const double v = GP[ip].pt[1];
129  const double w = GP[ip].pt[2];
130  const double weight = GP[ip].weight;
131  const double detJ = e->getJacobian(u, v, w, jac);
132  SPoint3 p;
133  e->pnt(u, v, w, p);
134  e->getShapeFunctions(u, v, w, sf);
135  const dataVec FCT = fct(p.x(), p.y(), p.z());
136  for(int k = 0; k < e->getNumShapeFunctions(); k++) {
137  dm.assemble(e->getShapeFunctionNode(k), comp, field,
138  detJ * weight * sf[k] * FCT);
139  }
140  }
141  }
142 
143  void neumannNodalBC(int physical, int dim, int comp, int field,
144  const simpleFunction<dataVec> &fct,
146  {
147  std::map<int, std::vector<GEntity *> > groups[4];
148  GModel *m = _gm;
149  m->getPhysicalGroups(groups);
150  auto it =
151  groups[dim].find(physical);
152  if(it == groups[dim].end()) return;
153  for(std::size_t i = 0; i < it->second.size(); ++i) {
154  GEntity *ge = it->second[i];
155  for(std::size_t j = 0; j < ge->getNumMeshElements(); j++) {
156  MElement *e = ge->getMeshElement(j);
157  neumannNodalBC(e, comp, field, fct, dm);
158  }
159  }
160  }
161  void neumannNormalNodalBC(int physical, int dim, int field,
162  const simpleFunction<dataVec> &fct,
164  {
165  std::map<int, std::vector<GEntity *> > groups[4];
166  GModel *m = _gm;
167  m->getPhysicalGroups(groups);
168  auto it =
169  groups[dim].find(physical);
170  if(it == groups[dim].end()) return;
171  for(std::size_t i = 0; i < it->second.size(); ++i) {
172  GEntity *ge = it->second[i];
173  for(std::size_t j = 0; j < ge->getNumMeshElements(); j++) {
174  MElement *e = ge->getMeshElement(j);
175 
176  neumannNodalBC(e, 0, field, fct, dm);
177  neumannNodalBC(e, 1, field, fct, dm);
178  neumannNodalBC(e, 2, field, fct, dm);
179  }
180  }
181  }
182 
184  {
185  auto it = C.begin();
186  for(; it != C.end(); ++it) {
187  MElement *eL = *it;
188  SElement se(eL);
189  int nbR = sizeOfR(&se);
190  fullVector<dataVec> V(nbR);
191  elementVector(&se, V);
192  // assembly
193  for(int j = 0; j < nbR; j++) dm.assemble(getLocalDofR(&se, j), V(j));
194  }
195  }
196 };
197 
198 class DummyfemTerm : public femTerm<double> {
199 public:
202  DummyfemTerm(GModel *gm) : femTerm<double>(gm) {}
203  virtual ~DummyfemTerm() {}
204 
205 private: // i dont want to mess with this anymore
206  virtual int sizeOfC(SElement *se) const { return 0; }
207  virtual int sizeOfR(SElement *se) const { return 0; }
208  virtual Dof getLocalDofR(SElement *se, int iRow) const { return Dof(0, 0); }
209  virtual Dof getLocalDofC(SElement *se, int iCol) const { return Dof(0, 0); }
210  virtual void elementMatrix(SElement *se, fullMatrix<dataMat> &m) const
211  {
212  m.scale(0.);
213  }
214  virtual void elementVector(SElement *se, fullVector<dataVec> &m) const
215  {
216  m.scale(0.);
217  }
218 };
219 
220 #endif
femTerm::getLocalDofC
virtual Dof getLocalDofC(SElement *se, int iCol) const
Definition: femTerm.h:40
groupOfElements::end
elementContainer::const_iterator end() const
Definition: groupOfElements.h:56
femTerm::sizeOfR
virtual int sizeOfR(SElement *se) const =0
DummyfemTerm::sizeOfC
virtual int sizeOfC(SElement *se) const
Definition: femTerm.h:206
femTerm::neumannNodalBC
void neumannNodalBC(MElement *e, int comp, int field, const simpleFunction< dataVec > &fct, dofManager< dataVec > &dm)
Definition: femTerm.h:116
fullVector
Definition: MElement.h:26
MElement::getIntegrationPoints
virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts)
Definition: MElement.h:436
femTerm::addToRightHandSide
void addToRightHandSide(dofManager< dataVec > &dm, groupOfElements &C) const
Definition: femTerm.h:183
c
static double c(int i, int j, fullMatrix< double > &CA, const std::vector< SPoint3 > &P, const std::vector< SPoint3 > &Q)
Definition: discreteFrechetDistance.cpp:15
dofTraits::MatType
T MatType
Definition: dofManager.h:52
femTerm::femTerm
femTerm(GModel *gm)
Definition: femTerm.h:30
SPoint3
Definition: SPoint3.h:14
femTerm::elementVector
virtual void elementVector(SElement *se, fullVector< dataVec > &m) const
Definition: femTerm.h:46
fullMatrix::scale
void scale(const scalar s)
Definition: fullMatrix.h:447
MElement::getShapeFunctionNode
virtual const MVertex * getShapeFunctionNode(int i) const
Definition: MElement.h:392
DummyfemTerm::~DummyfemTerm
virtual ~DummyfemTerm()
Definition: femTerm.h:203
fullVector::scale
void scale(const scalar s)
Definition: fullMatrix.h:144
DummyfemTerm::dataVec
dofTraits< double >::VecType dataVec
Definition: femTerm.h:200
groupOfElements
Definition: groupOfElements.h:24
GEntity
Definition: GEntity.h:31
IntPt::pt
double pt[3]
Definition: GaussIntegration.h:13
femTerm::addToMatrix
void addToMatrix(dofManager< dataVec > &dm, groupOfElements &L, groupOfElements &C) const
Definition: femTerm.h:53
DummyfemTerm::elementMatrix
virtual void elementMatrix(SElement *se, fullMatrix< dataMat > &m) const
Definition: femTerm.h:210
DummyfemTerm::getLocalDofR
virtual Dof getLocalDofR(SElement *se, int iRow) const
Definition: femTerm.h:208
femTerm::addToMatrix
void addToMatrix(dofManager< dataVec > &dm, SElement *se) const
Definition: femTerm.h:67
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
fullMatrix
Definition: MElement.h:27
GModel::getPhysicalGroups
void getPhysicalGroups(std::map< int, std::vector< GEntity * > > groups[4]) const
Definition: GModel.cpp:837
IntPt::weight
double weight
Definition: GaussIntegration.h:14
simpleFunction
Definition: GModel.h:30
Dof
Definition: dofManager.h:19
GEntity::getNumMeshElements
virtual std::size_t getNumMeshElements() const
Definition: GEntity.h:348
SElement.h
GModel
Definition: GModel.h:44
MElement::getNumShapeFunctions
virtual std::size_t getNumShapeFunctions() const
Definition: MElement.h:387
GModel::getMeshVerticesForPhysicalGroup
void getMeshVerticesForPhysicalGroup(int dim, int num, std::vector< MVertex * > &)
Definition: GModel.cpp:1987
DummyfemTerm::DummyfemTerm
DummyfemTerm(GModel *gm)
Definition: femTerm.h:202
SElement
Definition: SElement.h:18
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
dofManager
Definition: dofManager.h:113
DummyfemTerm::dataMat
dofTraits< double >::MatType dataMat
Definition: femTerm.h:201
femTerm::getLocalDofR
virtual Dof getLocalDofR(SElement *se, int iRow) const =0
femTerm::addToMatrix
void addToMatrix(dofManager< dataVec > &dm, fullMatrix< dataMat > &localMatrix, SElement *se) const
Definition: femTerm.h:75
MElement
Definition: MElement.h:30
femTerm::~femTerm
virtual ~femTerm()
Definition: femTerm.h:31
dofManager.h
femTerm::dataMat
dofTraits< T >::MatType dataMat
Definition: femTerm.h:24
dofManager::assemble
virtual void assemble(const Dof &R, const Dof &C, const dataMat &value)
Definition: dofManager.h:393
fullMatrix::size2
int size2() const
Definition: fullMatrix.h:275
DummyfemTerm::sizeOfR
virtual int sizeOfR(SElement *se) const
Definition: femTerm.h:207
groupOfElements::begin
elementContainer::const_iterator begin() const
Definition: groupOfElements.h:55
MElement::pnt
virtual void pnt(double u, double v, double w, SPoint3 &p) const
Definition: MElement.cpp:1072
femTerm::neumannNodalBC
void neumannNodalBC(int physical, int dim, int comp, int field, const simpleFunction< dataVec > &fct, dofManager< dataVec > &dm)
Definition: femTerm.h:143
femTerm::dirichletNodalBC
void dirichletNodalBC(int physical, int dim, int comp, int field, const simpleFunction< dataVec > &e, dofManager< dataVec > &dm)
Definition: femTerm.h:105
DummyfemTerm
Definition: femTerm.h:198
IntPt
Definition: GaussIntegration.h:12
GEntity::getMeshElement
virtual MElement * getMeshElement(std::size_t index) const
Definition: GEntity.h:363
simpleFunction.h
fullMatrix::size1
int size1() const
Definition: fullMatrix.h:274
femTerm::_gm
GModel * _gm
Definition: femTerm.h:27
z
const double z
Definition: GaussQuadratureQuad.cpp:56
dofTraits::VecType
T VecType
Definition: dofManager.h:51
MElement::getShapeFunctions
virtual void getShapeFunctions(double u, double v, double w, double s[], int order=-1) const
Definition: MElement.cpp:458
DummyfemTerm::elementVector
virtual void elementVector(SElement *se, fullVector< dataVec > &m) const
Definition: femTerm.h:214
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::dataVec
dofTraits< T >::VecType dataVec
Definition: femTerm.h:23
groupOfElements.h
dofManager::fixVertex
void fixVertex(MVertex const *v, int iComp, int iField, const dataVec &value)
Definition: dofManager.h:170
DummyfemTerm::getLocalDofC
virtual Dof getLocalDofC(SElement *se, int iCol) const
Definition: femTerm.h:209
femTerm::sizeOfC
virtual int sizeOfC(SElement *se) const =0
fullMatrix.h
femTerm::neumannNormalNodalBC
void neumannNormalNodalBC(int physical, int dim, int field, const simpleFunction< dataVec > &fct, dofManager< dataVec > &dm)
Definition: femTerm.h:161
groupOfElements::find
bool find(MElement *e) const
Definition: groupOfElements.h:62
femTerm::elementMatrix
virtual void elementMatrix(SElement *se, fullMatrix< dataMat > &m) const =0