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_ClusterNode.cpp
19 \author E. Lunéville
20 \since 17 may 2016
21 \date 17 may 2016
22
23 Low level tests of ClusterNode class.
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 #include "xlife++-libs.h"
31 #include "hierarchicalMatrix.h"
32 #include "testUtils.hpp"
33
34 #include <iostream>
35 #include <fstream>
36 #include <vector>
37
38 using namespace xlifepp;
39
40 namespace unit_ClusterNode {
41
unit_ClusterNode(bool check)42 String unit_ClusterNode(bool check)
43 {
44 String rootname = "unit_ClusterNode";
45 trace_p->push(rootname);
46 std::stringstream out; // string stream receiving results
47 out.precision(testPrec);
48
49 number_t nbox=10;
50 //test on a disk
51 Mesh meshd(Disk(_center=Point(0.,0.),_radius=1.,_nnodes=32,_domain_name="Omega"),_triangle,1,_gmsh);
52
53 ClusterTree<Point> dn_regular(meshd.nodes,_regularBisection,nbox);
54 dn_regular.saveToFile("cluster_disk_regular.txt");
55 ClusterTree<Point> dn_bounding(meshd.nodes,_boundingBoxBisection,nbox);
56 dn_bounding.saveToFile("cluster_disk_bounding.txt");
57 ClusterTree<Point> dn_cardinal(meshd.nodes,_cardinalityBisection,nbox);
58 dn_cardinal.saveToFile("cluster_disk_cardinal.txt");
59 ClusterTree<Point> dn_kdtree(meshd.nodes,_uniformKdtree,10, 0, true, false,_fmmCloseNodeRule,0.01);
60 dn_kdtree.saveToFile("cluster_disk_kdtree.txt");
61 ClusterTree<Point> dn_nukdtree(meshd.nodes,_nonuniformKdtree,10, 0,true,false);
62 dn_nukdtree.saveToFile("cluster_disk_nukdtree.txt");
63
64 //test on a circle
65 Mesh meshc(Disk(_center=Point(0.,0.),_radius=1.,_nnodes=50),_segment,1,_gmsh);
66 nbox=10;
67 ClusterTree<Point> cn_regular(meshc.nodes,_regularBisection,nbox);
68 cn_regular.saveToFile("cluster_circle_regular.txt");
69 ClusterTree<Point> cn_bounding(meshc.nodes,_boundingBoxBisection,nbox);
70 cn_bounding.saveToFile("cluster_circle_bounding.txt");
71 ClusterTree<Point> cn_cardinal(meshc.nodes,_cardinalityBisection,nbox);
72 cn_cardinal.saveToFile("cluster_circle_cardinal.txt");
73 ClusterTree<Point> cn_kdtree(meshc.nodes,_uniformKdtree,5);
74 cn_kdtree.saveToFile("cluster_circle_kdtree.txt");
75 ClusterTree<Point> cn_nukdtree(meshc.nodes,_nonuniformKdtree,5);
76 cn_nukdtree.saveToFile("cluster_circle_nukdtree.txt");
77
78 //test on a half sphere
79 Mesh meshs(Sphere(_center=Point(0.,0.,0.),_radius=1.,_nnodes=16,_nboctants=4),_triangle,1,_subdiv);
80 nbox=3;
81 ClusterTree<Point> sn_regular(meshs.nodes,_regularBisection,nbox);
82 sn_regular.saveToFile("cluster_sphere_regular.txt");
83 ClusterTree<Point> sn_bounding(meshs.nodes,_boundingBoxBisection,nbox);
84 sn_bounding.saveToFile("cluster_sphere_bounding.txt");
85 ClusterTree<Point> sn_cardinal(meshs.nodes,_cardinalityBisection,nbox);
86 sn_cardinal.saveToFile("cluster_sphere_cardinal.txt");
87 ClusterTree<Point> sn_kdtree(meshs.nodes,_uniformKdtree,5);
88 sn_kdtree.saveToFile("cluster_sphere_kdtree.txt");
89 ClusterTree<Point> sn_nukdtree(meshs.nodes,_nonuniformKdtree,5);
90 sn_nukdtree.saveToFile("cluster_sphere_nukdtree.txt");
91
92 //test on a half ball
93 Mesh meshb(Ball(_center=Point(0.,0.,0.),_radius=1.,_nnodes=16, _nboctants=4),_tetrahedron,1,_subdiv);
94 ClusterTree<Point> bn_regular(meshb.nodes,_regularBisection,nbox);
95 bn_regular.saveToFile("cluster_ball_regular.txt");
96 ClusterTree<Point> bn_bounding(meshb.nodes,_boundingBoxBisection,nbox);
97 bn_bounding.saveToFile("cluster_ball_bounding.txt");
98 ClusterTree<Point> bn_cardinal(meshb.nodes,_cardinalityBisection,nbox);
99 bn_cardinal.saveToFile("cluster_ball_cardinal.txt");
100 ClusterTree<Point> bn_kdtree(meshb.nodes,_uniformKdtree,5);
101 bn_kdtree.saveToFile("cluster_ball_kdtree.txt");
102 ClusterTree<Point> bn_nukdtree(meshb.nodes,_nonuniformKdtree,5);
103 bn_nukdtree.saveToFile("cluster_ball_nukdtree.txt");
104
105 //test update of real bounding boxes
106 dn_regular.updateRealBoundingBoxes();
107 dn_regular.saveToFile("cluster_disk_regular_realbox.txt",true);
108
109 //test update of close nodes vectors
110 dn_kdtree.updateCloseNodes();
111 verboseLevel(10);
112 dn_kdtree.print(thePrintStream);
113
114 //test from FeDof vector
115 Domain omega = meshd.domain("Omega");
116 Space V(omega,P1,"V");
117 ClusterTree<FeDof> fn_regular(V.feSpace()->dofs,_regularBisection,nbox);
118 fn_regular.updateRealBoundingBoxes();
119 fn_regular.updateDofNumbers();
120 fn_regular.updateElements();
121 fn_regular.saveToFile("cluster_fedof_regular.txt");
122 verboseLevel(10);
123 fn_regular.print(thePrintStream);
124 //
125 // //test from Element vector
126 ClusterTree<Element> en_regular(V.feSpace()->elements,_regularBisection,nbox);
127 en_regular.saveToFile("cluster_element_regular.txt");
128 en_regular.updateRealBoundingBoxes();
129 en_regular.saveToFile("cluster_element_regular_realbox.txt",true);
130 en_regular.updateDofNumbers();
131 en_regular.updateElements();
132 verboseLevel(10);
133 en_regular.print(thePrintStream);
134
135 //performance test
136 // for(number_t p=101;p<=1001;p+=100)
137 // {
138 // Mesh mesh2d(Rectangle(_xmin=0.,_xmax=1.,_ymin=0.,_ymax=1.,_nnodes=Numbers(p,p),
139 // _domain_name="Omega",_side_names="Gamma"),_triangle,1,_structured);
140 // elapsedTime();
141 // ClusterTree cn(&meshd.nodes,_cardinalBisection, 20, true);
142 // elapsedTime("cardinal box cluster of 20 for a "+tostring(mesh2d.nbOfNodes())+" nodes mesh",thePrintStream);
143 // }
144
145
146 //------------------------------------------------------------------------------------
147 // save results in a file or compare results with some references value in a file
148 //------------------------------------------------------------------------------------
149 trace_p->pop();
150 if (check) { return diffResFile(out, rootname); }
151 else { return saveResToFile(out, rootname); }
152 }
153
154 }
155