1 // ORIG-DATE:     Dec 2007
2 // -*- Mode : c++ -*-
3 //
4 // SUMMARY  :  Model  mesh surface 3d
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 
34 #ifndef MESHSN_HPP_
35 #define MESHSN_HPP_
36 
37 
38 #include <cstdio>
39 #include "RNM.hpp"
40 // definition R
41 #include <cstdlib>
42 namespace Fem2D {
43 
44 #include "R3.hpp"
45 // #include "R2.hpp"
46 
47 }
48 
49 using namespace ::std;
50 #include "GenericMesh.hpp"
51 #include "MeshLn.hpp"
52 
53 namespace Fem2D {
54 
55 typedef GenericVertex<R3> Vertex3;
56 
57 
58     struct DataTriangle3  {
59         static const int NbOfVertices =3;
60         static const int NbOfEdges =3;
61         static const int NbOfFaces =1;
62         static const int NT =0;
63         static const int NbOfAdjElem =NbOfVertices;
64         static const int NbOfVertexOnHyperFace =NbOfVertices-1;
65         typedef Vertex3 V;
66         typedef  V::Rd Rd ;
67         typedef R2 RdHat;
68         typedef R1 RdHatBord;
PBordFem2D::DataTriangle369         static RdHat PBord(const int * nvb,const RdHatBord &P)  {
70             return RdHat::KHat[nvb[0]]*(1-P.x)+R2::KHat[nvb[1]]*(P.x) ;}
71 
mesureFem2D::DataTriangle372         static R mesure(  V *  pv[NbOfVertices]) {
73             return (R3(*pv[0],*pv[1])^R3(*pv[0],*pv[2])).norme()*0.5;
74         }
75     };
76 
77 
78     class BoundaryEdgeS: public GenericElement<DataSeg3>
79   {
80   public:
BoundaryEdgeS()81       BoundaryEdgeS() {}; // constructor empty for array
82 
83 
84   };
85 
86 
87 
88     class TriangleS: public GenericElement<DataTriangle3> { //public Triangle3  {
89     public:
TriangleS()90         TriangleS() {}; // constructor empty for array
91 
Gradlambda(Rd * GradL) const92         void Gradlambda(Rd * GradL) const
93         {
94             R3 Normal = Edge(2)^Edge(1);
95             R N = Normal.norme2();
96             for(int i=0 ; i<3 ; i++)
97                 GradL[i]= (Edge(i)^Normal) / N;
98         }
99 
NFrenet() const100         R3 NFrenet() const {
101             ASSERTION(i>=0 && i <3);
102             return R3( Edge(2)^Edge(1) );
103         }
NFrenetUnitaire() const104         R3 NFrenetUnitaire() const {// Add FH. Dec. 2019
105             R3 N(Edge(2)^Edge(1) );
106             return N/N.norme();
107         }
108     };
109 
110 
111 
112     template<typename Mesh> void GSave2(FILE * ff,const Mesh & Th) ;
113 
114     class MeshS : public GenericMesh<TriangleS,BoundaryEdgeS,Vertex3> {
115     public:
116          // mapping for volume/surface vertices
117         int *mapSurf2Vol;
118         int *mapVol2Surf;
119         MeshL *meshL;
120         int nPoints;
MeshS()121         MeshS():mapSurf2Vol(0),mapVol2Surf(0),meshL(0) {};
122         MeshS(const string, double ridgeangledetection=8.*atan(1.)/9.);
123         //MeshS(const string, const long);
124         MeshS(const string filename, bool cleanmesh, bool removeduplicate=false, bool rebuildboundary=false, int orientation=1, double precis_mesh=1e-7, double ridgeangledetection=8.*atan(1.)/9.);
125         void read(istream &f);
126         void readmsh(ifstream & f,int offset);
127         MeshS(FILE *f,int offset=0);
128         //MeshS(const string);
129         MeshS(int nnv, int nnt, int nnbe, Vertex3 *vv, TriangleS *tt, BoundaryEdgeS *bb, bool cleanmesh=false, bool removeduplicate=false, bool rebuildboundary=false, int orientation=1, double precis_mesh=1e-6);
130         MeshS(const Serialize&);
131         MeshS(const Serialize &serialized, int withSurface);
132         int load(const string & filename);
133         const Element * Find( Rd P, R2 & Phat,bool & outside,const Element * tstart=0) const;
134         int Save(const string & filename);
135         void flipSurfaceMeshS(int surface_orientation);
136         void GSave(FILE * f,int offset=0) const ;
137         void GRead(FILE * f,int offset);
138         double hmin() const;
139         int Save(const string & filename) const;
140         void BuildBdElem(double angle=8.*atan(1.)/9.);  // default angle = 40 deg);
141         Serialize serialize_withBorderMesh() const;
142         void BuildMeshL(double angle=8.*atan(1.)/9.);  // default angle = 40 deg);
143         KNM<R3> BuildCurvBasis();
~MeshS()144         ~MeshS() {
145             if (verbosity>4) cout << "destroy meshS" << this << " " << this->mapSurf2Vol << " " << this->mapVol2Surf << " destroy meshL " << this->meshL << endl;
146             delete [] mapSurf2Vol ;
147             delete [] mapVol2Surf ;
148             if (meshL)
149                 meshL->destroy();//  Add clean mesh if necessary ...FH and AF. april 2019
150 
151 
152             SHOWVERB(cout << " %%%% delete MeshS"<< this << endl) ; }
153     private:
154         MeshS(const MeshS &); // pas de construction par copie
155         void operator=(const MeshS &);// pas affectation par copy
156     };
157 
158 }
159 
160 #endif
161 
162