/usr/include/gmsh/femTerm.h is in libgmsh-dev 3.0.6+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | // Gmsh - Copyright (C) 1997-2017 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@onelab.info>.
#ifndef _FEM_TERM_H_
#define _FEM_TERM_H_
#include <math.h>
#include <map>
#include <vector>
#include "fullMatrix.h"
#include "simpleFunction.h"
#include "dofManager.h"
#include "GModel.h"
#include "SElement.h"
#include "groupOfElements.h"
// a nodal finite element term : variables are always defined at nodes
// of the mesh
template<class T>
class femTerm {
private:
typedef typename dofTraits<T>::VecType dataVec;
typedef typename dofTraits<T>::MatType dataMat;
protected:
GModel *_gm;
public:
femTerm(GModel *gm) : _gm(gm) {}
virtual ~femTerm() {}
// return the number of columns of the element matrix
virtual int sizeOfC(SElement *se) const = 0;
// return the number of rows of the element matrix
virtual int sizeOfR(SElement *se) const = 0;
// in a given element, return the dof associated to a given row (column)
// of the local element matrix
virtual Dof getLocalDofR(SElement *se, int iRow) const = 0;
// default behavior: symmetric
virtual Dof getLocalDofC(SElement *se, int iCol) const
{
return getLocalDofR(se, iCol);
}
// compute the elementary matrix
virtual void elementMatrix(SElement *se, fullMatrix<dataMat> &m) const = 0;
virtual void elementVector(SElement *se, fullVector<dataVec> &m) const
{
m.scale(0.0);
}
// add the contribution from all the elements in the intersection
// of two element groups L and C
void addToMatrix(dofManager<dataVec> &dm,
groupOfElements &L,
groupOfElements &C) const
{
groupOfElements::elementContainer::const_iterator it = L.begin();
for ( ; it != L.end(); ++it){
MElement *eL = *it;
if (&C == &L || C.find(eL)){
SElement se(eL);
addToMatrix(dm, &se);
}
}
}
// add the contribution from a single element to the dof manager
void addToMatrix(dofManager<dataVec> &dm, SElement *se) const
{
const int nbR = sizeOfR(se);
const int nbC = sizeOfC(se);
fullMatrix<dataMat> localMatrix(nbR, nbC);
elementMatrix(se, localMatrix);
addToMatrix(dm, localMatrix, se);
}
void addToMatrix(dofManager<dataVec> &dm,
fullMatrix<dataMat> &localMatrix,
SElement *se) const
{
const int nbR = localMatrix.size1();
const int nbC = localMatrix.size2();
std::vector<Dof> R, C; // better use default consdtructors and reserve the right amount of space to avoid reallocation
R.reserve(nbR);
C.reserve(nbC);
bool sym=true;
if (nbR == nbC)
{
for (int j = 0; j < nbR; j++)
{
Dof r(getLocalDofR(se, j));
Dof c(getLocalDofC(se, j));
R.push_back(r);
C.push_back(c);
if (!(r == c)) sym = false;
}
}
else
{
sym = false;
for (int j = 0; j < nbR; j++)
R.push_back(getLocalDofR(se, j));
for (int k = 0; k < nbC; k++)
C.push_back(getLocalDofC(se, k));
}
if (!sym)
dm.assemble(R, C, localMatrix);
else
dm.assemble(R, localMatrix);
}
void dirichletNodalBC(int physical, int dim, int comp, int field,
const simpleFunction<dataVec> &e,
dofManager<dataVec> &dm)
{
std::vector<MVertex *> v;
GModel *m = _gm;
m->getMeshVerticesForPhysicalGroup(dim, physical, v);
for (unsigned int i = 0; i < v.size(); i++)
dm.fixVertex(v[i], comp, field, e(v[i]->x(), v[i]->y(), v[i]->z()));
}
void neumannNodalBC(MElement *e, int comp, int field,
const simpleFunction<dataVec> &fct,
dofManager<dataVec> &dm)
{
double jac[3][3];
double sf[256];
int integrationOrder = 2 * e->getPolynomialOrder();
int npts;
IntPt *GP;
e->getIntegrationPoints(integrationOrder, &npts, &GP);
for (int ip = 0; ip < npts; ip++){
const double u = GP[ip].pt[0];
const double v = GP[ip].pt[1];
const double w = GP[ip].pt[2];
const double weight = GP[ip].weight;
const double detJ = e->getJacobian(u, v, w, jac);
SPoint3 p; e->pnt(u, v, w, p);
e->getShapeFunctions(u, v, w, sf);
const dataVec FCT = fct(p.x(), p.y(), p.z());
for (int k = 0; k < e->getNumShapeFunctions(); k++){
dm.assemble(e->getShapeFunctionNode(k), comp, field, detJ * weight * sf[k] * FCT);
}
}
}
void neumannNodalBC(int physical, int dim, int comp, int field,
const simpleFunction<dataVec> &fct,
dofManager<dataVec> &dm)
{
std::map<int, std::vector<GEntity*> > groups[4];
GModel *m = _gm;
m->getPhysicalGroups(groups);
std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].find(physical);
if (it == groups[dim].end()) return;
for (unsigned int i = 0; i < it->second.size(); ++i){
GEntity *ge = it->second[i];
for (unsigned int j = 0; j < ge->getNumMeshElements(); j++){
MElement *e = ge->getMeshElement(j);
neumannNodalBC(e, comp, field, fct, dm);
}
}
}
void neumannNormalNodalBC(int physical, int dim, int field,
const simpleFunction<dataVec> &fct,
dofManager<dataVec> &dm)
{
std::map<int, std::vector<GEntity*> > groups[4];
GModel *m = _gm;
m->getPhysicalGroups(groups);
std::map<int, std::vector<GEntity*> >::iterator it = groups[dim].find(physical);
if (it == groups[dim].end()) return;
for (unsigned int i = 0; i < it->second.size(); ++i){
GEntity *ge = it->second[i];
for (unsigned int j = 0; j < ge->getNumMeshElements(); j++){
MElement *e = ge->getMeshElement(j);
neumannNodalBC(e, 0, field, fct, dm);
neumannNodalBC(e, 1, field, fct, dm);
neumannNodalBC(e, 2, field, fct, dm);
}
}
}
void addToRightHandSide(dofManager<dataVec> &dm, groupOfElements &C) const
{
groupOfElements::elementContainer::const_iterator it = C.begin();
for ( ; it != C.end(); ++it){
MElement *eL = *it;
SElement se(eL);
int nbR = sizeOfR(&se);
fullVector<dataVec> V(nbR);
elementVector(&se, V);
// assembly
for (int j = 0; j < nbR; j++) dm.assemble(getLocalDofR(&se, j), V(j));
}
}
};
class DummyfemTerm : public femTerm<double>
{
public:
typedef dofTraits<double>::VecType dataVec;
typedef dofTraits<double>::MatType dataMat;
DummyfemTerm(GModel *gm) : femTerm<double>(gm) {}
virtual ~DummyfemTerm() {}
private : // i dont want to mess with this anymore
virtual int sizeOfC(SElement *se) const {return 0;}
virtual int sizeOfR(SElement *se) const {return 0;}
virtual Dof getLocalDofR(SElement *se, int iRow) const {return Dof(0, 0);}
virtual Dof getLocalDofC(SElement *se, int iCol) const {return Dof(0, 0);}
virtual void elementMatrix(SElement *se, fullMatrix<dataMat> &m) const {m.scale(0.);}
virtual void elementVector(SElement *se, fullVector<dataVec> &m) const {m.scale(0.);}
};
#endif
|