Back to index

salome-med  6.5.0
PointLocatorTest.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "PointLocatorTest.hxx"
00021 #include "PointLocator.hxx"
00022 #include "MEDMeshMaker.hxx"
00023 #include "MEDMEM_Mesh.hxx"
00024 
00025 #include <iostream>
00026 #include <list>
00027 
00028 namespace INTERP_TEST
00029 {
00030 
00031 
00032   void PointLocatorTest::setUp() 
00033   {
00034   }
00035 
00036  
00037   void PointLocatorTest::tearDown() 
00038   {
00039   }
00040 
00049   void PointLocatorTest::test_PointLocator() {
00050     MEDMEM::MESH* mesh2D= MEDMeshMaker(2,2,MED_EN::MED_QUAD4);
00051     MEDMEM::PointLocator pl(*mesh2D) ;
00052     double x[2]={0.0,0.0};
00053     std::list<int> elems = pl.locate(x);
00054     CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
00055     CPPUNIT_ASSERT_EQUAL(1,(int)(*(elems.begin())));
00056     elems.clear();
00057     
00058     double x2[2]={0.25,0.25};
00059     elems = pl.locate(x2);
00060     CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
00061     CPPUNIT_ASSERT_EQUAL(1,(int)(*(elems.begin())));
00062     elems.clear();
00063     
00064     double x3[2]={0.5,0.5};
00065     elems = pl.locate(x3);
00066     CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
00067     elems.clear();
00068 
00069     double x4[2]={-1.0,0.0};
00070     elems = pl.locate(x4);
00071     CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
00072     elems.clear();
00073     delete mesh2D;
00074 
00075     MEDMEM::MESH* mesh3D= MEDMeshMaker(3,2,MED_EN::MED_HEXA8);
00076     MEDMEM::PointLocator pl3(*mesh3D);
00077     double xx[3]={0.0,0.0,0.0};
00078     elems = pl3.locate(xx);
00079     CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
00080     CPPUNIT_ASSERT_EQUAL(1,(int)*(elems.begin()));
00081     elems.clear();
00082     
00083     double xx2[3]={0.25,0.25,0.25};
00084     elems = pl3.locate(xx2);
00085     CPPUNIT_ASSERT_EQUAL(1,(int)elems.size());
00086     CPPUNIT_ASSERT_EQUAL(1,(int)*(elems.begin()));
00087     elems.clear();
00088 
00089     double xx3[3]={0.5,0.5,0.5};
00090     elems = pl3.locate(xx3);
00091     CPPUNIT_ASSERT_EQUAL(8,(int)elems.size());
00092     elems.clear();
00093     
00094     double xx4[3]={-1.0,0.0,0.0};
00095     elems = pl3.locate(xx4);
00096     CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
00097     elems.clear();
00098     delete mesh3D;
00099 
00100   }
00101 
00109   void PointLocatorTest::test_PointLocatorInSimplex()
00110   {
00111     MEDMEM::MESH* mesh2D= MEDMeshMaker(2,2,MED_EN::MED_QUAD4);
00112     // mesh is a quadrangle (0.0-1.0 x 0.0-1.0 )
00113     // 3 -- 6 -- 9
00114     // |    |    |
00115     // 2 -- 5 -- 8
00116     // |    |    |
00117     // 1 -- 4 -- 7
00118     MEDMEM::PointLocatorInSimplex pl(*mesh2D) ;
00119     std::list<int> elems;
00120     std::list<int>::iterator elem;
00121     {
00122       double x[2]={0.0,0.25};
00123       elems = pl.locate(x);
00124       elem = elems.begin();
00125       CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
00126       CPPUNIT_ASSERT_EQUAL(1,*elem++);
00127       CPPUNIT_ASSERT_EQUAL(2,*elem++);
00128       CPPUNIT_ASSERT_EQUAL(5,*elem++);
00129     }
00130     {
00131       double x[2]={0.25,0.0};
00132       elems = pl.locate(x);
00133       elem = elems.begin();
00134       CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
00135       CPPUNIT_ASSERT_EQUAL(1,*elem++);
00136       CPPUNIT_ASSERT_EQUAL(2,*elem++);
00137       CPPUNIT_ASSERT_EQUAL(4,*elem++);
00138     }
00139     {
00140       double x[2]={0.25,1.0};
00141       elems = pl.locate(x);
00142       elem = elems.begin();
00143       CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
00144       CPPUNIT_ASSERT_EQUAL(2,*elem++);
00145       CPPUNIT_ASSERT_EQUAL(3,*elem++);
00146       CPPUNIT_ASSERT_EQUAL(6,*elem++);
00147     }
00148     {
00149       double x[2]={0.4,0.75};
00150       elems = pl.locate(x);
00151       elem = elems.begin();
00152       CPPUNIT_ASSERT_EQUAL(3,(int)elems.size());
00153       CPPUNIT_ASSERT_EQUAL(3,*elem++);
00154       CPPUNIT_ASSERT_EQUAL(6,*elem++);
00155       CPPUNIT_ASSERT_EQUAL(5,*elem++);
00156     }
00157     {
00158       double x[2]={-1.0,0.0};
00159       elems = pl.locate(x);
00160       CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
00161       delete mesh2D;
00162     }
00163     MEDMEM::MESH* mesh3D= MEDMeshMaker(3,2,MED_EN::MED_HEXA8);
00164     // ^Z
00165     // |
00166     // 3 -- 6 -- 9
00167     // |    |    |
00168     // 2 -- 5 -- 8     12 --15 --18
00169     // |    |    |     |    |    | 
00170     // 1 -- 4 -- 7->Y  11 --14 --17    21 --24 --27
00171     //  \              |    |    |     |    |    | 
00172     //   \ X           10 --13 --16    20 --23 --26
00173     //    v                            |    |    | 
00174     //                                 19 --22 --25
00175     
00176     MEDMEM::PointLocatorInSimplex pl3(*mesh3D);
00177     {
00178       double x[3]={0.0,0.0,0.0};
00179       elems = pl3.locate(x);
00180       elem = elems.begin();
00181       CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
00182       CPPUNIT_ASSERT_EQUAL(1,*elem++);
00183       CPPUNIT_ASSERT_EQUAL(10,*elem++);
00184       CPPUNIT_ASSERT_EQUAL(13,*elem++);
00185       CPPUNIT_ASSERT_EQUAL(2,*elem++);
00186     }
00187     {
00188       double x[3]={0.0,0.4,0.3};
00189       elems = pl3.locate(x);
00190       elem = elems.begin();
00191       CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
00192       CPPUNIT_ASSERT_EQUAL(1,*elem++);
00193       CPPUNIT_ASSERT_EQUAL(10,*elem++);
00194       CPPUNIT_ASSERT_EQUAL(4,*elem++);
00195       CPPUNIT_ASSERT_EQUAL(5,*elem++);
00196     }
00197     {
00198       double x[3]={0.5,0.5,0.5};
00199       elems = pl3.locate(x);
00200       elem = elems.begin();
00201       CPPUNIT_ASSERT_EQUAL(4,(int)elems.size());
00202       CPPUNIT_ASSERT_EQUAL(1,*elem++);
00203       CPPUNIT_ASSERT_EQUAL(10,*elem++);
00204       CPPUNIT_ASSERT_EQUAL(13,*elem++);
00205       CPPUNIT_ASSERT_EQUAL(14,*elem++);
00206     }
00207     {
00208       double x[3]={-1.0,0.0,0.0};
00209       elems = pl3.locate(x);
00210       CPPUNIT_ASSERT_EQUAL(0,(int)elems.size());
00211     }
00212     delete mesh3D;
00213   }
00214 
00215 }