1 /*
2 XLiFE++ is an extended library of finite elements written in C++
3     Copyright (C) 2014  Lunéville, Eric; Kielbasiewicz, Nicolas; Lafranche, Yvon; Nguyen, Manh-Ha; Chambeyron, Colin
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13     You should have received a copy of the GNU General Public License
14     along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 /*!
18 \file unit_Mesh.cpp
19 \authors E. Lunéville, Y. Lafranche
20 \since 10 may 2012
21 \date  23 oct 2012
22 
23 Low level tests of Mesh class and related classes.
24 Almost functionalities are checked.
25 This function may either creates a reference file storing the results (check=false)
26 or compares results to those stored in the reference file (check=true)
27 It returns reporting informations in a string
28 */
29 
30 //===============================================================================
31 //library dependences
32 #include "xlife++-libs.h"
33 #include "testUtils.hpp"
34 
35 //===============================================================================
36 //stl dependences
37 #include <iostream>
38 #include <fstream>
39 #include <vector>
40 
41 //===============================================================================
42 
43 using namespace xlifepp;
44 
45 namespace unit_Mesh {
46 
47 void test_SubdvMesh(std::stringstream& out);
48 void test_MeshFromFile(std::stringstream& out);
49 
unit_Mesh(bool check)50 String unit_Mesh(bool check)
51 {
52   String rootname = "unit_Mesh";
53   trace_p->push(rootname);
54   //crTeXFiles();
55   std::stringstream out;                  //string stream receiving results
56   out.precision(testPrec);
57   verboseLevel(5);
58 
59   std::vector<String> sidenames(2, "");
60   sidenames[0] = "Sigma_1";
61 
62   //test P1 2D mesh
63   Mesh mesh1dP1(Segment(_xmin=0, _xmax=1, _nnodes=11, _side_names=sidenames), 1, _structured, "P1 mesh of [0,1], step=0.01");
64   out << "------------------- P1 mesh of a segment -------------------------\n";
65   out << mesh1dP1 << std::endl;
66   mesh1dP1.saveToFile("mesh1dP1.vtk", _vtk, true);
67   out << "\n------------------ P1 mesh of a rectangle ------------------------\n";
68   sidenames.resize(4);
69   sidenames[0] = "Gamma_1";
70   sidenames[3] = "Gamma_2";
71   Mesh mesh2dP1(Rectangle(_xmin=0, _xmax=1, _ymin=1, _ymax=3, _nnodes=Numbers(3, 5), _side_names=sidenames), _triangle, 1, _structured, "P1 mesh of [0,1]x[1,3]");
72   out << mesh2dP1 << std::endl;
73   out << "\n------------ P1 mesh of a rectangle with sides----------------------\n";
74   mesh2dP1.buildSides();
75   mesh2dP1.buildVertexElements();
76   verboseLevel(9);
77   out << mesh2dP1 << std::endl;
78   mesh2dP1.saveToFile("mesh2dP1.vtk", _vtk, true);
79 
80   //test Q1 2D mesh
81   sidenames[0] = "Sigma_1";
82   sidenames[2] = "Sigma_2";
83   sidenames[1] = "";
84   Mesh mesh2dQ1(Rectangle(_xmin=1, _xmax=2, _ymin=1, _ymax=3, _nnodes=Numbers(3, 5), _side_names=sidenames), _quadrangle, 1, _structured, "Q1 mesh of [1,2]x[1,3]");
85   mesh2dQ1.domain("Omega").rename("OmegaQ");
86   out << mesh2dQ1 << std::endl;
87   out << "\n------------ Q1 mesh of a rectangle with sides----------------------\n";
88   mesh2dQ1.buildSides();
89   mesh2dQ1.buildVertexElements();
90   out << mesh2dQ1 << std::endl;
91   mesh2dQ1.saveToFile("mesh2dQ1.vtk", _vtk, true);
92 
93   //merging meshes P1/Q1
94   Mesh mesh2dP1Q1(mesh2dP1);
95   out << "\n-------------------------- copy of P1 mesh --------------------------\n";
96   out << mesh2dP1Q1 << std::endl;
97   mesh2dP1Q1.merge(mesh2dQ1);
98   verboseLevel(24);
99   out << "\n----------------------- merge P1 and Q1 mesh ------------------------\n";
100   out << mesh2dP1Q1 << std::endl;
101   mesh2dP1Q1.saveToFile("mesh2dP1Q1.vtk", _vtk, true);
102   verboseLevel(5);
103 
104   out << "\n------------------ Q1 mesh of a hexahedron ------------------------\n";
105   sidenames.clear(); sidenames.resize(6);
106   sidenames[0] = "z=1";
107   sidenames[1] = "z=5";
108   sidenames[2] = "y=1";
109   sidenames[3] = "y=3";
110   sidenames[4] = "x=0";
111   sidenames[5] = "x=1";
112   Mesh mesh3dQ1(Cuboid(_xmin=0, _xmax=1, _ymin=1, _ymax=3, _zmin=1, _zmax=5, _nnodes=Numbers(3, 5, 9), _side_names=sidenames), _hexahedron, 1, _structured, "Q1 mesh of [0,1]x[1,3]x[1,5]");
113   out << mesh3dQ1 << std::endl;
114   mesh3dQ1.saveToFile("mesh3dQ1.vtk", _vtk, true);
115 
116   out << "\n--------- convert hexahedron mesh to pyramid mesh -------------\n";
117   Mesh mesh3DPyramid(mesh3dQ1,_pyramid);
118   out << mesh3DPyramid << std::endl;
119   mesh3DPyramid.saveToFile("mesh3DPyramid.msh", _msh, false);
120 
121   out << "\n--------- mesh of cube using pyramids -------------\n";
122   Mesh mesh3DPyramid2(Parallelepiped(_v1=Point(0,1,1), _v2=Point(1,1,1), _v4=Point(0,3,1),_v5=Point(0,1,5), _nnodes=Numbers(3, 5, 9), _side_names=sidenames),
123                       _pyramid, 1, _structured, "Q1 mesh of [0,1]x[1,3]x[1,5]");
124   out << mesh3DPyramid2 << std::endl;
125   mesh3DPyramid2.saveToFile("mesh3DPyramid2.msh", _msh, false);
126 
127   out << "\n------------------ extrusion of 1D mesh ------------------------\n";
128   Mesh mesh1dExtrude(mesh1dP1,Point(0.,0.),Point(0.,1.),10,1,1,0);
129   out << mesh1dExtrude << std::endl;
130   mesh1dExtrude.saveToFile("mesh1dExtrude.vtk", _vtk, true);
131 
132   out << "\n------------------ extrusion of 2D mesh ------------------------\n";
133   Mesh mesh2dExtrudeP1(mesh2dP1,Point(0.,0.,0.),Point(0.,0.,1.),10,1,1,1);
134   out << mesh2dExtrudeP1 << std::endl;
135   mesh2dExtrudeP1.saveToFile("mesh2dExtrudeP1.vtk", _vtk, true);
136 
137   out << "\n------------------ extrusion of 2D mesh ------------------------\n";
138   Mesh mesh2dExtrudeP1b(mesh2dP1,Point(0.,0.,0.),Point(0.,0.,1.),10,2,2,2);
139   out << mesh2dExtrudeP1b << std::endl;
140   mesh2dExtrudeP1b.saveToFile("mesh2dExtrudeP1b.vtk", _vtk, true);
141 
142   out << "\n------------------ extrusion of 2D mesh ------------------------\n";
143   Mesh mesh2dExtrudeQ1(mesh2dQ1,Point(0.,0.,0.),Point(0.,0.,1.),10,1,1,1);
144   out << mesh2dExtrudeQ1 << std::endl;
145   mesh2dExtrudeQ1.saveToFile("mesh2dExtrudeQ1.vtk", _vtk, true);
146 
147   out << "\n-------------- parallelepiped mesh with prisms -------------------\n";
148   Mesh mesh3dPrism(Parallelepiped(_v1=Point(0.,0.,0.), _v2=Point(0.,0.,1.), _v4=Point(1.,0.,0.), _v5=Point(0.,1.,0.),
149                 _nnodes=10, _side_names="Gamma"), _prism, 1, _structured, "Prism mesh of cube");
150   out << mesh3dPrism << std::endl;
151   mesh3dPrism.saveToFile("mesh3dPrism.vtk", _vtk, false);
152 
153   //    out<<"\n------------ P1 mesh of a rectangle with sides----------------------\n";
154   //    mesh3dP1.buildSides();
155   //    mesh3dP1.buildVertexElements();
156   //    verboseLevel(9);
157   //    out<<mesh3dP1;
158 
159   out << "\n------------------ creation of underlying P1 mesh ------------------------\n";
160   //test creation of underlying P1 mesh
161   Mesh* mesh2dQ1_P1= mesh2dQ1.createFirstOrderMesh();
162   out << *mesh2dQ1_P1 << std::endl;
163 
164   //test creation of underlying first order mesh
165   Mesh& mesh2dQ1ToP1= *mesh2dQ1.createFirstOrderMesh();
166   out << mesh2dQ1ToP1 << std::endl;
167 
168   Mesh mesh1dFromBasic(Segment(_v1=Point(0.,0.,0.),_v2=Point(1.,2.,3.),_nnodes=12),1,_structured);
169   Mesh mesh2dP1FromBasic(Rectangle(_xmin=0,_xmax=2,_ymin=0,_ymax=4,_nnodes=12),_triangle,1,_structured);
170   Mesh mesh2dQ1FromBasic(Rectangle(_xmin=0.,_xmax=2.,_ymin=0.,_ymax=4.,_nnodes=12),_quadrangle,1,_structured);
171   Mesh mesh3dQ1FromBasic(Cuboid(_xmin=0.,_xmax=2.,_ymin=0.,_ymax=4.,_zmin=0.,_zmax=1.,_nnodes=12),_hexahedron,1,_structured);
172 
173   //test of meshes built using a subdivision algorithm
174   test_SubdvMesh(out);
175 
176   //test of meshes read from a file
177   test_MeshFromFile(out);
178 
179   //------------------------------------------------------------------------------------
180   //   save results in a file or compare results with some references value in a file
181   //------------------------------------------------------------------------------------
182   trace_p->pop();
183   if (check) { return diffResFile(out, rootname); }
184   else { return saveResToFile(out, rootname); }
185 }
186 
187 //===============================================================================
188 
189 /*!
190    Test functions for subdivision algorithm.
191 */
192 
193 //! Tests for the sphere
test_Subdv_Sph(std::stringstream & out,dimen_t nboctants=8)194 void test_Subdv_Sph(std::stringstream& out, dimen_t nboctants = 8) {
195   number_t order;
196   Ball sphu; // unit sphere by default
197 
198   order=1;
199   Mesh mesh3dP1S0VolSph(sphu, _tetrahedron, order, _subdiv, "mesh3dP1S0VolSph");
200   out << "\n---------------- Volume P1 mesh of the unit sphere (subdiv 0) -------------------\n";
201   out << mesh3dP1S0VolSph << std::endl;
202 
203   order=1;
204   sphu = Ball(_center=Point(0.,0.,0.),_radius=1,_nboctants=nboctants,_nnodes=3);
205   Mesh mesh3dP1S1VolSph(sphu, _tetrahedron, order, _subdiv, "mesh3dP1S1VolSph");
206   out << "\n---------------- Volume P1 mesh of the unit sphere (subdiv 1) -------------------\n";
207   out << mesh3dP1S1VolSph << std::endl;
208   //mesh3dP1S1VolSph.saveToFile("mesh3dP1S1VolSph.vtk", _vtk, true);
209 
210 
211   order=2;
212   Mesh mesh3dP2S1VolSph(sphu, _tetrahedron, order, _subdiv, "mesh3dP2S1VolSph");
213   out << "\n---------------- Volume P2 mesh of the unit sphere (subdiv 1) -------------------\n";
214   out << mesh3dP2S1VolSph << std::endl;
215 
216 
217   order=1;
218   sphu = Ball(_center=Point(0.,0.,0.),_radius=1.,_nboctants=nboctants,_nnodes=2);
219   Mesh mesh3dP1S0SurfSph(sphu, _triangle, order, _subdiv, "mesh3dP1S0SurfSph");
220   out << "\n---------------- Surface P1 mesh of the unit sphere (subdiv 0) -------------------\n";
221   out << mesh3dP1S0SurfSph << std::endl;
222 
223   order=1;
224   sphu = Ball(_center=Point(0.,0.,0.),_radius=1.,_nboctants=nboctants,_nnodes=3);
225   Mesh mesh3dP1S1SurfSph(sphu, _triangle, order, _subdiv, "mesh3dP1S1SurfSph");
226   out << "\n---------------- Surface P1 mesh of the unit sphere (subdiv 1) -------------------\n";
227   out << mesh3dP1S1SurfSph << std::endl;
228 
229   order=2;
230   Mesh mesh3dP2S1SurfSph(sphu, _triangle, order, _subdiv, "mesh3dP2S1SurfSph");
231   out << "\n---------------- Surface P2 mesh of the unit sphere (subdiv 1) -------------------\n";
232   out << mesh3dP2S1SurfSph << std::endl;
233 }
234 
235 //! Tests for the cone
test_Subdv_Cone(std::stringstream & out)236 void test_Subdv_Cone(std::stringstream& out) {
237   std::string fname;
238   number_t order=1;
239 
240   fname = "P1VolMeshTetCone";
241   number_t n=5;
242   Real radius=1.;
243   RevCone cone(_center=Point(0.,0.,2.), _radius=radius, _apex=Point(-1.,-1.,0.), _nnodes=n);
244   Mesh mesh3dP1S2VolConeT(cone, _tetrahedron, order, _subdiv, fname);
245   out << "\n---------------- Volume P1 mesh of the cone (subdiv 2) with tetrahedrons -------------------\n";
246   out << mesh3dP1S2VolConeT << std::endl;
247   fname = "P1VolMeshTetTrunk";
248   Real radius1=0.6, radius2=1.;
249   RevTrunk trunk1(_center1=Point(-1.,-1.,0.), _radius1=radius1, _center2=Point(0.,0.,2.), _radius2=radius2,
250                  _end1_shape=_gesCone, _end1_distance=1.5, _end2_shape=_gesEllipsoid, _end2_distance=0.7, _nnodes=n);
251   Mesh mesh3dP1S2VolTrunkTE(trunk1, _tetrahedron, order, _subdiv, fname);
252   out << "\n---------------- Volume P1 mesh of the trunk (subdiv 2) with tetrahedrons -------------------\n";
253   out << mesh3dP1S2VolTrunkTE << std::endl;
254 
255   fname = "P1VolMeshHexTrunk";
256   radius1=0.5;//radius1=1.e-15;
257   RevTrunk trunk2(_center1=Point(-1.,-1.,0.), _radius1=radius1, _center2=Point(0.,0.,2.), _radius2=radius2, _nnodes=n);
258   Mesh mesh3dP1S2VolTrunkH(trunk2, _hexahedron, order, _subdiv, fname);
259   out << "\n---------------- Volume P1 mesh of the trunk (subdiv 2) with hexahedrons -------------------\n";
260   out << mesh3dP1S2VolTrunkH << std::endl;
261 
262   fname = "P1SurfMeshQuaTrunk";
263   RevTrunk trunk3(_center1=Point(-1.,-1.,0.), _radius1=radius1, _center2=Point(0.,0.,2.), _radius2=radius2, _nnodes=n);
264   {std::stringstream ss; ss << fname << trunk3.nbSubdomains() << ".tex"; trunk3.teXFilename(ss.str());}
265   Mesh mesh3dP1S2SurfConeQ(trunk3, _quadrangle, order, _subdiv, fname);
266   out << "\n---------------- Surface P1 mesh of the cone (subdiv 2) with quadrangles -------------------\n";
267   out << mesh3dP1S2SurfConeQ << std::endl;
268 
269   fname = "P1SurfMeshTriTrunk";
270   {std::stringstream ss; ss << fname << trunk3.nbSubdomains() << ".tex"; trunk3.teXFilename(ss.str());}
271   Mesh mesh3dP1S2SurfConeT(trunk3, _triangle, order, _subdiv, fname);
272   out << "\n---------------- Surface P1 mesh of the cone (subdiv 2) with triangles -------------------\n";
273   out << mesh3dP1S2SurfConeT << std::endl;
274 }
275 
276 //! Tests for the cube
test_Subdv_Cub(std::stringstream & out,dimen_t nboctants=8)277 void test_Subdv_Cub(std::stringstream& out, dimen_t nboctants = 8) {
278   number_t order=1;
279   Cube cube(_center=Point(0.,0.,0.),_length=2.,_nboctants=nboctants, _nnodes=2); cube.rotate3d(Point(0.,0.,0.), 1.,0.,0., pi_);
280 
281   Mesh mesh3dP1S0VolCubT(cube, _tetrahedron,  order, _subdiv, "mesh3dP1S0VolCubT");
282   out << "\n---------------- Volume P1 mesh of the cube (subdiv 0) with tetrahedrons -------------------\n";
283   out << mesh3dP1S0VolCubT << std::endl;
284 
285   Cube cube2(_center=Point(0.,0.,0.),_length=1., _nboctants=2, _nnodes=2);
286   std::string fname("mesh3dP1S0VolCubH");
287   Mesh mesh3dP1S0VolCubH(cube2, _hexahedron,  3, _subdiv, fname);
288   out << "\n---------------- Volume P1 mesh of the cube (subdiv 0) with hexahedrons -------------------\n";
289   out << mesh3dP1S0VolCubH << std::endl;
290 
291   fname="mesh3dQ3S0SurfCubQ";
292   Mesh mesh3dQ3S0SurfCubQ(cube2, _quadrangle,  3, _subdiv, fname);
293   out << "\n---------------- Volume Q3 mesh of the cube (subdiv 0) with quadrangles -------------------\n";
294   out << mesh3dQ3S0SurfCubQ << std::endl;
295 }
296 
297 //! Tests for the cylinder
test_Subdv_Cyl(std::stringstream & out)298 void test_Subdv_Cyl(std::stringstream& out) {
299   number_t order=1;
300   string_t fname;
301   RevCylinder cyl;
302 
303   fname="mesh3dP1S0VolCylT";
304   Mesh mesh3dP1S0VolCylT(cyl, _tetrahedron, order, _subdiv, fname);
305   out << "\n---------------- Volume P1 mesh of the cylinder (subdiv 0) with tetrahedrons -------------------\n";
306   out << mesh3dP1S0VolCylT << std::endl;
307 
308   fname="mesh3dP1S0VolCylH";
309   Real radius=1.;
310   number_t n=3;
311   RevCylinder cyl2(_center1=Point(0.,0.,0.), _center2=Point(0.,0.,1.), _radius=radius, _nnodes=n);
312   Mesh mesh3dP1S0VolCylH(cyl2, _hexahedron, order, _subdiv, fname);
313   out << "\n---------------- Volume P1 mesh of the cylinder (subdiv 0) with hexahedrons -------------------\n";
314   out << mesh3dP1S0VolCylH << std::endl;
315 
316   fname="mesh3dP1S0SurfCylH";
317   Mesh mesh3dP1S0SurfCylH(cyl2, _quadrangle, order, _subdiv, fname);
318   out << "\n---------------- Volume P1 mesh of the cylinder (subdiv 0) with quadrangles -------------------\n";
319   out << mesh3dP1S0SurfCylH << std::endl;
320 
321   fname="mesh3dP1S0SurfCylT";
322   Mesh mesh3dP1S0SurfCylT(cyl2, _triangle, order, _subdiv, fname);
323   out << "\n---------------- Volume P1 mesh of the cylinder (subdiv 1) with triangles -------------------\n";
324   out << mesh3dP1S0SurfCylT << std::endl;
325 }
326 
327 //! Tests for the set of elements
test_Subdv_TrSet(std::stringstream & out)328 void test_Subdv_TrSet(std::stringstream& out) {
329   std::vector<Point> pts;
330   pts.push_back(Point(0.,0.,0.));
331   pts.push_back(Point(1.,0.,0.));
332   pts.push_back(Point(0.,1.,0.3));
333   pts.push_back(Point(0.,-1.,0.3));
334 
335   std::vector<std::vector<number_t> > elems;
336   { number_t T[]={1,2,3}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
337   { number_t T[]={1,4,2}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
338   std::vector<std::vector<number_t> > bounds;
339   std::vector<String> names;
340   { number_t L[]={1,4}; bounds.push_back(std::vector<number_t>(L,L+sizeof(L)/sizeof(number_t))); names.push_back("S1"); }
341   { number_t L[]={4,2}; bounds.push_back(std::vector<number_t>(L,L+sizeof(L)/sizeof(number_t))); names.push_back("S2"); }
342   { number_t L[]={2,3}; bounds.push_back(std::vector<number_t>(L,L+sizeof(L)/sizeof(number_t))); names.push_back("S3"); }
343   { number_t L[]={1,3}; bounds.push_back(std::vector<number_t>(L,L+sizeof(L)/sizeof(number_t))); names.push_back("S4"); }
344 
345   number_t nbsubdiv(1), order(3);
346 
347   SetOfElems sot(pts, elems, bounds, names, _triangle, nbsubdiv);
348   sot.teXFilename("P1SurfMeshTriSet.tex");
349   Mesh meshTriSet(sot, _triangle, order, _subdiv, "meshTriSet");
350   out << "\n---------------- Surface P3 mesh starting from an initial mesh of triangles (subdiv 1) -------------------\n";
351   out << meshTriSet << std::endl;
352 
353   pts.clear();
354   pts.push_back(Point(0.,0.));
355   pts.push_back(Point(0.,1.));
356   pts.push_back(Point(1.,0.));
357   pts.push_back(Point(1.,1.));
358   pts.push_back(Point(1.5,0.5));
359   pts.push_back(Point(1.5,1.5));
360   pts.push_back(Point(2.,0.));
361   pts.push_back(Point(2.,1.));
362   pts.push_back(Point(3.,0.));
363   pts.push_back(Point(3.,1.));
364   pts.push_back(Point(0.,-1.));
365   pts.push_back(Point(1.,-1.));
366   pts.push_back(Point(1.5,-0.5));
367   pts.push_back(Point(1.5,-1.5));
368   pts.push_back(Point(2.,-1.));
369   pts.push_back(Point(3.,-1.));
370 
371   elems.clear();
372   { number_t T[]={1,3,4,2}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
373   { number_t T[]={3,5,6,4}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
374   { number_t T[]={5,7,8,6}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
375   { number_t T[]={7,9,10,8}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
376   { number_t T[]={11,12,3,1}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
377   { number_t T[]={12,14,13,3}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
378   { number_t T[]={14,15,7,13}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
379   { number_t T[]={15,16,9,7}; elems.push_back(std::vector<number_t>(T,T+sizeof(T)/sizeof(number_t))); }
380   bounds.clear();
381   names.clear();
382   { number_t L[]={1,2,11}; bounds.push_back(std::vector<number_t>(L,L+sizeof(L)/sizeof(number_t))); }
383   { number_t L[]={11,12,14,15,16}; bounds.push_back(std::vector<number_t>(L,L+sizeof(L)/sizeof(number_t))); }
384   { number_t L[]={16,9,10}; bounds.push_back(std::vector<number_t>(L,L+sizeof(L)/sizeof(number_t))); }
385   { number_t L[]={2,4,6,8,10}; bounds.push_back(std::vector<number_t>(L,L+sizeof(L)/sizeof(number_t))); }
386   { number_t L[]={3,5,7,13}; bounds.push_back(std::vector<number_t>(L,L+sizeof(L)/sizeof(number_t))); }
387 
388   SetOfElems soq(pts, elems, bounds, names, _quadrangle, nbsubdiv);
389   soq.teXFilename("P1SurfMeshQuaSet.tex");
390   Mesh meshQuaSet(soq, _quadrangle, order, _subdiv, "meshQuaSet");
391   out << "\n---------------- Surface Q3 mesh starting from an initial mesh of quadrangles (subdiv 1) -------------------\n";
392   out << meshQuaSet << std::endl;
393 }
394 
395 //! Tests for the disk
test_Subdv_Disk_Sub(std::stringstream & out)396 void test_Subdv_Disk_Sub(std::stringstream& out) {
397   real_t radius=1.;
398   number_t order=1;
399   Disk pdisk(_center=Point(0.,1.), _radius=radius, _angle1=10., _angle2=300., _nnodes=5);
400   pdisk.teXFilename("P1SurfMeshTriDisk.tex");
401   Mesh meshTriDisk(pdisk, _triangle, order, _subdiv, "meshTriDisk");
402   out << "\n---------------- Surface mesh of a portion of disk (subdiv 1) -------------------\n";
403   out << meshTriDisk << std::endl;
404 
405   pdisk.teXFilename("P1SurfMeshQuaDisk.tex");
406   Mesh meshQuaDisk(pdisk, _quadrangle, order, _subdiv, "meshQuaDisk");
407   out << "\n---------------- Surface mesh of a portion of disk (subdiv 1) -------------------\n";
408   out << meshQuaDisk << std::endl;
409 
410   Mesh submeshQuaDisk(meshQuaDisk,1);
411   out << "\n---------------- Subdivision of the previous one -------------------\n";
412   out << submeshQuaDisk << std::endl;
413 }
414 
415 //! Global test function
test_SubdvMesh(std::stringstream & out)416 void test_SubdvMesh(std::stringstream& out) {
417   test_Subdv_Sph(out,8); // nboctants = 8;
418   test_Subdv_Cub(out,7); // nboctants = 7;
419   test_Subdv_Cyl(out);
420   test_Subdv_TrSet(out);
421   test_Subdv_Disk_Sub(out);
422   test_Subdv_Cone(out);
423 }
424 //===============================================================================
425 
426 /*!
427    Test functions for mesh read from a file.
428 */
test_MeshFromFile(std::stringstream & out)429 void test_MeshFromFile(std::stringstream& out) {
430   using std::vector;
431   // Mesh in Gmsh format
432   String fn("concentric_sphere.msh");
433   Mesh mesh3DGmsh=Mesh(inputsPathTo(fn),"mesh3DGmsh",msh);
434   out << "\n---------------- Read file in Gmsh format (file " << fn << ") -------------------\n";
435   out << mesh3DGmsh << std::endl;
436 
437   // Mesh in Melina format
438   vector<String> vfn;
439   vfn.push_back("tr4x4");
440   vfn.push_back("qu4x4");
441   for (vector<String>::const_iterator it_vfn=vfn.begin(); it_vfn < vfn.end(); it_vfn++) {
442     Mesh mesh2DMel=Mesh(inputsPathTo(*it_vfn),"mesh2DMel",mel);
443     out << "\n---------------- Read file in Melina format (file " << *it_vfn << ") -------------------\n";
444     out << mesh2DMel << std::endl;
445   }
446   fn="unitCube_1e3.ply";
447   out << "\n---------------- Read file in PLY format (file " << fn << ") -------------------\n";
448   Mesh mesh2DPly(inputsPathTo(fn), "mesh PLY",ply);
449   out << mesh2DPly << std::endl;
450   fn="square.vtk";
451   out << "\n---------------- Read file in VTK format (file " << fn << ") -------------------\n";
452   Mesh meshSquareVtk(inputsPathTo(fn), "mesh square VTK",vtk);
453   out << meshSquareVtk << std::endl;
454   fn="screen_4.msh";
455   out << "\n---------------- Read file in Msh format (file " << fn << ") -------------------\n";
456   Mesh mesh2DMsh(inputsPathTo(fn), "mesh Msh",msh);
457   out << mesh2DMsh << std::endl;
458   fn="screen_4.mesh";
459   out << "\n---------------- Read file in Medit format (file " << fn << ") -------------------\n";
460   Mesh mesh2DMedit(inputsPathTo(fn), "mesh Medit",medit);
461   out << mesh2DMedit << std::endl;
462 }
463 
464 }
465