Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / INTERP_KERNELTest / PointLocatorTest.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "PointLocatorTest.hxx"
21 #include "PointLocator.hxx"
22 #include "MEDMeshMaker.hxx"
23 #include "MEDMEM_Mesh.hxx"
24
25 #include <iostream>
26 #include <list>
27
28 namespace INTERP_TEST
29 {
30
31
32   void PointLocatorTest::setUp() 
33   {
34   }
35
36  
37   void PointLocatorTest::tearDown() 
38   {
39   }
40
41   /**
42    * Test that creates a tree in 2D and check that 
43    * the results are correct in three
44    * cases :
45    * a non matching search
46    * a standard case
47    * a bbox overlapping the bboxes of the tree
48    */
49   void PointLocatorTest::test_PointLocator() {
50     MEDMEM::MESH* mesh2D= MEDMeshMaker(2,2,MED_EN::MED_QUAD4);
51     MEDMEM::PointLocator pl(*mesh2D) ;
52     double x[2]={0.0,0.0};
53     std::list<int> elems = pl.locate(x);
54     CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
55     CPPUNIT_ASSERT_EQUAL(1,(int)(*(elems.begin())));
56     elems.clear();
57     
58     double x2[2]={0.25,0.25};
59     elems = pl.locate(x2);
60     CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
61     CPPUNIT_ASSERT_EQUAL(1,(int)(*(elems.begin())));
62     elems.clear();
63     
64     double x3[2]={0.5,0.5};
65     elems = pl.locate(x3);
66     CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
67     elems.clear();
68
69     double x4[2]={-1.0,0.0};
70     elems = pl.locate(x4);
71     CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
72     elems.clear();
73     delete mesh2D;
74
75     MEDMEM::MESH* mesh3D= MEDMeshMaker(3,2,MED_EN::MED_HEXA8);
76     MEDMEM::PointLocator pl3(*mesh3D);
77     double xx[3]={0.0,0.0,0.0};
78     elems = pl3.locate(xx);
79     CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
80     CPPUNIT_ASSERT_EQUAL(1,(int)*(elems.begin()));
81     elems.clear();
82     
83     double xx2[3]={0.25,0.25,0.25};
84     elems = pl3.locate(xx2);
85     CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
86     CPPUNIT_ASSERT_EQUAL(1,(int)*(elems.begin()));
87     elems.clear();
88
89     double xx3[3]={0.5,0.5,0.5};
90     elems = pl3.locate(xx3);
91     CPPUNIT_ASSERT_EQUAL(8,(int)elems.size());
92     elems.clear();
93     
94     double xx4[3]={-1.0,0.0,0.0};
95     elems = pl3.locate(xx4);
96     CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
97     elems.clear();
98     delete mesh3D;
99
100   }
101
102   /**
103    * Test that the results are correct in three
104    * cases :
105    * a non matching search
106    * a standard case
107    * a bbox overlapping the bboxes of the tree
108    */
109   void PointLocatorTest::test_PointLocatorInSimplex()
110   {
111     MEDMEM::MESH* mesh2D= MEDMeshMaker(2,2,MED_EN::MED_QUAD4);
112     // mesh is a quadrangle (0.0-1.0 x 0.0-1.0 )
113     // 3 -- 6 -- 9
114     // |    |    |
115     // 2 -- 5 -- 8
116     // |    |    |
117     // 1 -- 4 -- 7
118     MEDMEM::PointLocatorInSimplex pl(*mesh2D) ;
119     std::list<int> elems;
120     std::list<int>::iterator elem;
121     {
122       double x[2]={0.0,0.25};
123       elems = pl.locate(x);
124       elem = elems.begin();
125       CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
126       CPPUNIT_ASSERT_EQUAL(1,*elem++);
127       CPPUNIT_ASSERT_EQUAL(2,*elem++);
128       CPPUNIT_ASSERT_EQUAL(5,*elem++);
129     }
130     {
131       double x[2]={0.25,0.0};
132       elems = pl.locate(x);
133       elem = elems.begin();
134       CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
135       CPPUNIT_ASSERT_EQUAL(1,*elem++);
136       CPPUNIT_ASSERT_EQUAL(2,*elem++);
137       CPPUNIT_ASSERT_EQUAL(4,*elem++);
138     }
139     {
140       double x[2]={0.25,1.0};
141       elems = pl.locate(x);
142       elem = elems.begin();
143       CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
144       CPPUNIT_ASSERT_EQUAL(2,*elem++);
145       CPPUNIT_ASSERT_EQUAL(3,*elem++);
146       CPPUNIT_ASSERT_EQUAL(6,*elem++);
147     }
148     {
149       double x[2]={0.4,0.75};
150       elems = pl.locate(x);
151       elem = elems.begin();
152       CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
153       CPPUNIT_ASSERT_EQUAL(3,*elem++);
154       CPPUNIT_ASSERT_EQUAL(6,*elem++);
155       CPPUNIT_ASSERT_EQUAL(5,*elem++);
156     }
157     {
158       double x[2]={-1.0,0.0};
159       elems = pl.locate(x);
160       CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
161       delete mesh2D;
162     }
163     MEDMEM::MESH* mesh3D= MEDMeshMaker(3,2,MED_EN::MED_HEXA8);
164     // ^Z
165     // |
166     // 3 -- 6 -- 9
167     // |    |    |
168     // 2 -- 5 -- 8     12 --15 --18
169     // |    |    |     |    |    | 
170     // 1 -- 4 -- 7->Y  11 --14 --17    21 --24 --27
171     //  \              |    |    |     |    |    | 
172     //   \ X           10 --13 --16    20 --23 --26
173     //    v                            |    |    | 
174     //                                 19 --22 --25
175     
176     MEDMEM::PointLocatorInSimplex pl3(*mesh3D);
177     {
178       double x[3]={0.0,0.0,0.0};
179       elems = pl3.locate(x);
180       elem = elems.begin();
181       CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
182       CPPUNIT_ASSERT_EQUAL(1,*elem++);
183       CPPUNIT_ASSERT_EQUAL(10,*elem++);
184       CPPUNIT_ASSERT_EQUAL(13,*elem++);
185       CPPUNIT_ASSERT_EQUAL(2,*elem++);
186     }
187     {
188       double x[3]={0.0,0.4,0.3};
189       elems = pl3.locate(x);
190       elem = elems.begin();
191       CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
192       CPPUNIT_ASSERT_EQUAL(1,*elem++);
193       CPPUNIT_ASSERT_EQUAL(10,*elem++);
194       CPPUNIT_ASSERT_EQUAL(4,*elem++);
195       CPPUNIT_ASSERT_EQUAL(5,*elem++);
196     }
197     {
198       double x[3]={0.5,0.5,0.5};
199       elems = pl3.locate(x);
200       elem = elems.begin();
201       CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
202       CPPUNIT_ASSERT_EQUAL(1,*elem++);
203       CPPUNIT_ASSERT_EQUAL(10,*elem++);
204       CPPUNIT_ASSERT_EQUAL(13,*elem++);
205       CPPUNIT_ASSERT_EQUAL(14,*elem++);
206     }
207     {
208       double x[3]={-1.0,0.0,0.0};
209       elems = pl3.locate(x);
210       CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
211     }
212     delete mesh3D;
213   }
214
215 }