1 // ORIG-DATE: Dec 2007 2 // -*- Mode : c++ -*- 3 // 4 // SUMMARY : Model mesh 2d 5 // USAGE : LGPL 6 // ORG : LJLL Universite Pierre et Marie Curi, Paris, FRANCE 7 // AUTHOR : Frederic Hecht 8 // E-MAIL : frederic.hecht@ann.jussieu.fr 9 // 10 11 /* 12 13 This file is part of Freefem++ 14 15 Freefem++ is free software; you can redistribute it and/or modify 16 it under the terms of the GNU Lesser General Public License as published by 17 the Free Software Foundation; either version 2.1 of the License, or 18 (at your option) any later version. 19 20 Freefem++ is distributed in the hope that it will be useful, 21 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 GNU Lesser General Public License for more details. 24 25 You should have received a copy of the GNU Lesser General Public License 26 along with Freefem++; if not, write to the Free Software 27 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 29 Thank to the ARN () FF2A3 grant 30 ref:ANR-07-CIS7-002-01 31 */ 32 33 #ifndef MESH2DN_HPP_ 34 #define MESH2DN_HPP_ 35 36 namespace Fem2D { 37 #include "R2.hpp" 38 } 39 40 #include "GenericMesh.hpp" 41 #include <cstdio> 42 #include <cstdlib> 43 using namespace std; 44 45 namespace Fem2D { 46 47 48 49 typedef GenericVertex<R2> Vertex2; 50 51 struct DataTriangle2 { 52 static const int NbOfVertices =3; 53 static const int NbOfFaces =1; 54 static const int NbOfEdges =3; 55 static const int NT =0; 56 static const int NbOfAdjElem =NbOfVertices; 57 static const int NbOfVertexOnHyperFace =NbOfVertices-1; 58 typedef Vertex2 V; 59 typedef V::Rd Rd ; mesureFem2D::DataTriangle260 static R mesure( V * pv[NbOfVertices]) { 61 return det(*pv[0],*pv[1],*pv[2])*0.5; 62 } 63 typedef R2 RdHat; 64 typedef R1 RdHatBord; PBordFem2D::DataTriangle265 static RdHat PBord(const int * nvb,const RdHatBord & P) { return RdHat::KHat[nvb[0]]*(1-P.x)+R2::KHat[nvb[1]]*(P.x) ;} 66 67 // static const int (* const nvface)[3];// = nvfaceTria ; 68 //static const int (* const nvedge)[2];// = nvedgeTrai; 69 70 }; 71 72 73 struct DataSeg2 { 74 static const int NbOfVertices =2; 75 static const int NbOfEdges =1; 76 static const int NbOfFaces =0; 77 static const int NT =0; 78 static const int NbOfAdjElem =NbOfVertices; 79 static const int NbOfVertexOnHyperFace =NbOfVertices-1; 80 typedef Vertex2 V; 81 typedef V::Rd Rd; mesureFem2D::DataSeg282 static R mesure( V * pv[NbOfVertices]) { 83 return R2(*pv[0],*pv[1]).norme(); 84 } 85 typedef R1 RdHat; 86 typedef R0 RdHatBord; PBordFem2D::DataSeg287 static RdHat PBord(const int * nvb,const RdHatBord &P) { return RdHat(*nvb) ;} 88 89 //static const int (* const nvface)[3];// = nvfaceSeg ; 90 //static const int (* const nvedge)[2];// = nvedgeSeg; 91 92 }; 93 94 95 96 class Triangle2: public GenericElement<DataTriangle2> 97 { 98 public: Triangle2()99 Triangle2() {}; // constructor empty for array 100 101 H(int i) const102 R2 H(int i) const { ASSERTION(i>=0 && i <3); 103 R2 E=Edge(i);return E.perp()/(2.*this->mesure());} // heigth 104 Gradlambda(R2 * GradL) const105 void Gradlambda(R2 * GradL) const 106 { 107 GradL[1]= H(1); 108 GradL[2]= H(2); 109 GradL[0]=-GradL[1]-GradL[2]; 110 } 111 112 113 114 }; 115 116 class BoundaryEdge2: public GenericElement<DataSeg2> 117 { 118 public: BoundaryEdge2()119 BoundaryEdge2() {}; // constructor empty for array 120 121 122 }; 123 124 template<typename Mesh> void GSave2(FILE * ff,const Mesh & Th) ; 125 126 class Mesh2 : public GenericMesh<Triangle2,BoundaryEdge2,Vertex2> 127 { 128 public: 129 Mesh2(const char *); // 130 Mesh2(int nnv, int nnt, int nnbe, Vertex2 *vv, Triangle2 *tt, BoundaryEdge2 *bb); 131 const Element * Find( R2 P, R2 & Phat,bool & outside,const Element * tstart) const; 132 int Save(const string & filename); 133 //int Popen(const FILE *namestream); 134 Mesh2(FILE *f); GSave(FILE * f) const135 void GSave(FILE * f) const { return GSave2<Mesh2>(f,*this);} 136 void GRead(FILE * f); 137 138 private: 139 int load(const string & filename); 140 Mesh2(const Mesh2 &); // pas de construction par copie 141 void operator=(const Mesh2 &);// pas affectation par copy 142 }; 143 144 } 145 146 #endif 147 148