Skip to content
Snippets Groups Projects
Commit 66bc4bc0 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

templatize gmshTermOfFormulation

parent 587f74b5
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "MElement.h" #include "MElement.h"
#include "GmshMatrix.h" #include "GmshMatrix.h"
class gmshElasticityTerm : public gmshNodalFemTerm { class gmshElasticityTerm : public gmshNodalFemTerm<double> {
double _E,_nu; double _E,_nu;
int _iField; int _iField;
protected: protected:
...@@ -27,7 +27,7 @@ class gmshElasticityTerm : public gmshNodalFemTerm { ...@@ -27,7 +27,7 @@ class gmshElasticityTerm : public gmshNodalFemTerm {
} }
public: public:
gmshElasticityTerm(GModel *gm, double E, double nu, int iField = 1) : gmshElasticityTerm(GModel *gm, double E, double nu, int iField = 1) :
gmshNodalFemTerm(gm), _E(E), _nu(nu), _iField(iField){} gmshNodalFemTerm<double>(gm), _E(E), _nu(nu), _iField(iField){}
void elementMatrix(MElement *e, gmshMatrix<double> &m) const; void elementMatrix(MElement *e, gmshMatrix<double> &m) const;
}; };
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "MElement.h" #include "MElement.h"
#include "GmshMatrix.h" #include "GmshMatrix.h"
class gmshLaplaceTerm : public gmshNodalFemTerm { class gmshLaplaceTerm : public gmshNodalFemTerm<double> {
private: private:
const gmshFunction *_diffusivity; const gmshFunction *_diffusivity;
const int _iField ; const int _iField ;
...@@ -28,7 +28,7 @@ class gmshLaplaceTerm : public gmshNodalFemTerm { ...@@ -28,7 +28,7 @@ class gmshLaplaceTerm : public gmshNodalFemTerm {
} }
public: public:
gmshLaplaceTerm(GModel *gm, gmshFunction *diffusivity, int iField = 0) : gmshLaplaceTerm(GModel *gm, gmshFunction *diffusivity, int iField = 0) :
gmshNodalFemTerm(gm), _diffusivity(diffusivity), _iField(iField){} gmshNodalFemTerm<double>(gm), _diffusivity(diffusivity), _iField(iField){}
virtual void elementMatrix(MElement *e, gmshMatrix<double> &m) const; virtual void elementMatrix(MElement *e, gmshMatrix<double> &m) const;
}; };
......
...@@ -14,18 +14,20 @@ ...@@ -14,18 +14,20 @@
#include "GModel.h" #include "GModel.h"
#include "MElement.h" #include "MElement.h"
template<class scalar>
class gmshTermOfFormulation { class gmshTermOfFormulation {
protected: protected:
GModel *_gm; GModel *_gm;
public: public:
gmshTermOfFormulation(GModel *gm) : _gm(gm) {} gmshTermOfFormulation(GModel *gm) : _gm(gm) {}
virtual ~gmshTermOfFormulation(){} virtual ~gmshTermOfFormulation(){}
virtual void addToMatrix(gmshAssembler<double> &) const = 0; virtual void addToMatrix(gmshAssembler<scalar> &) const = 0;
}; };
// a nodal finite element term : variables are always defined at nodes // a nodal finite element term : variables are always defined at nodes
// of the mesh // of the mesh
class gmshNodalFemTerm : public gmshTermOfFormulation { template<class scalar>
class gmshNodalFemTerm : public gmshTermOfFormulation<scalar> {
protected: protected:
// return the number of columns of the element matrix // return the number of columns of the element matrix
virtual int sizeOfC(MElement*) const = 0; virtual int sizeOfC(MElement*) const = 0;
...@@ -41,43 +43,44 @@ class gmshNodalFemTerm : public gmshTermOfFormulation { ...@@ -41,43 +43,44 @@ class gmshNodalFemTerm : public gmshTermOfFormulation {
getLocalDofR(e, iCol, vC, iCompC, iFieldC); getLocalDofR(e, iCol, vC, iCompC, iFieldC);
} }
public: public:
gmshNodalFemTerm(GModel *gm) : gmshTermOfFormulation(gm) {} gmshNodalFemTerm(GModel *gm) : gmshTermOfFormulation<scalar>(gm) {}
virtual ~gmshNodalFemTerm (){} virtual ~gmshNodalFemTerm (){}
virtual void elementMatrix(MElement *e, gmshMatrix<double> &m) const = 0; virtual void elementMatrix(MElement *e, gmshMatrix<scalar> &m) const = 0;
void addToMatrix(gmshAssembler<double> &lsys) const void addToMatrix(gmshAssembler<scalar> &lsys) const
{ {
if (_gm->getNumRegions()){ GModel *m = gmshTermOfFormulation<scalar>::_gm;
for(GModel::riter it = _gm->firstRegion(); it != _gm->lastRegion(); ++it){ if (m->getNumRegions()){
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it){
addToMatrix(lsys, *it); addToMatrix(lsys, *it);
} }
} }
else if(_gm->getNumFaces()){ else if(m->getNumFaces()){
for(GModel::fiter it = _gm->firstFace(); it != _gm->lastFace(); ++it){ for(GModel::fiter it = m->firstFace(); it != m->lastFace(); ++it){
addToMatrix(lsys, *it); addToMatrix(lsys, *it);
} }
} }
} }
void addToMatrix(gmshAssembler<double> &lsys, GEntity *ge) const void addToMatrix(gmshAssembler<scalar> &lsys, GEntity *ge) const
{ {
for(unsigned int i = 0; i < ge->getNumMeshElements(); i++){ for(unsigned int i = 0; i < ge->getNumMeshElements(); i++){
MElement *e = ge->getMeshElement(i); MElement *e = ge->getMeshElement(i);
addToMatrix(lsys, e); addToMatrix(lsys, e);
} }
} }
void addToMatrix(gmshAssembler<double> &lsys, MElement *e) const void addToMatrix(gmshAssembler<scalar> &lsys, MElement *e) const
{ {
const int nbR = sizeOfR(e); const int nbR = sizeOfR(e);
const int nbC = sizeOfC(e); const int nbC = sizeOfC(e);
gmshMatrix<double> localMatrix (nbR, nbC); gmshMatrix<scalar> localMatrix(nbR, nbC);
elementMatrix(e, localMatrix); elementMatrix(e, localMatrix);
addToMatrix(lsys, localMatrix, e); addToMatrix(lsys, localMatrix, e);
} }
void addToMatrix(gmshAssembler<double> &lsys, const std::vector<MElement*> &v) const void addToMatrix(gmshAssembler<scalar> &lsys, const std::vector<MElement*> &v) const
{ {
for (unsigned int i = 0; i < v.size(); i++) for (unsigned int i = 0; i < v.size(); i++)
addToMatrix(lsys, v[i]); addToMatrix(lsys, v[i]);
} }
void addToMatrix(gmshAssembler<double> &lsys, gmshMatrix<double> &localMatrix, void addToMatrix(gmshAssembler<scalar> &lsys, gmshMatrix<scalar> &localMatrix,
MElement *e) const MElement *e) const
{ {
const int nbR = sizeOfR(e); const int nbR = sizeOfR(e);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment