X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FINTERP_KERNELTest%2FUnitTetraIntersectionBaryTest.cxx;h=851685eaae4fc49f86dafa4fd1243aba79f952a6;hb=c4551c56aa89896595842e5b41b048044681b4e8;hp=c92b25e5e81616b0183fffced885360b0123c9e0;hpb=48782c06022ca2caa36f849cb5a29ea4fe2aaa83;p=tools%2Fmedcoupling.git diff --git a/src/INTERP_KERNELTest/UnitTetraIntersectionBaryTest.cxx b/src/INTERP_KERNELTest/UnitTetraIntersectionBaryTest.cxx index c92b25e5e..851685eaa 100644 --- a/src/INTERP_KERNELTest/UnitTetraIntersectionBaryTest.cxx +++ b/src/INTERP_KERNELTest/UnitTetraIntersectionBaryTest.cxx @@ -1,44 +1,50 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : UnitTetraIntersectionBaryTest.cxx // Created : Thu Dec 11 15:54:41 2008 // Author : Edward AGAPOV (eap) +// #include "UnitTetraIntersectionBaryTest.hxx" #include "UnitTetraIntersectionBary.hxx" #include "TetraAffineTransform.hxx" #include "InterpolationUtils.hxx" +#include "SplitterTetra.txx" #include using namespace INTERP_KERNEL; -using namespace std; namespace INTERP_TEST { void fill_UnitTetraIntersectionBary(UnitTetraIntersectionBary& bary, double nodes[][3]) { - int faceConn[4][3] = { { 0, 2, 1 }, - { 0, 1, 3 }, - { 1, 2, 3 }, - { 3, 2, 0 } }; - bary.init(); + int faceConn[4][3] = { { 0, 1, 2 },// inverse order + { 0, 3, 1 }, + { 1, 3, 2 }, + { 3, 0, 2 } }; +// int faceConn[4][3] = { { 0, 2, 1 }, +// { 0, 1, 3 }, +// { 1, 2, 3 }, +// { 3, 2, 0 } }; + bary.init(true); for ( int i = 0; i < 4; ++i ) { int* faceNodes = faceConn[ i ]; TransformedTriangle tri(nodes[faceNodes[0]], nodes[faceNodes[1]], nodes[faceNodes[2]]); @@ -244,18 +250,65 @@ namespace INTERP_TEST CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.230952, baryCenter[1], 1e-5); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.260714, baryCenter[2], 1e-5); } + void UnitTetraIntersectionBaryTest::test_UnitTetraIntersectionBary_12() + { + // cutting tetra has one corner inside the UT and one its side passes through an UT edge + double nodes[4][3] = { { 0.25, 0.25, 0.25 }, // 0 + { 1.75,-0.25,-0.25 }, // OX + { 0.5 , 0.25, 0.25 }, // OY + { 0.5 , 0 , 0.5 } };//OZ + UnitTetraIntersectionBary bary; + fill_UnitTetraIntersectionBary(bary,nodes); + double baryCenter[3]; + bool ok = bary.getBary( baryCenter ); + double vol = bary.getVolume(); + CPPUNIT_ASSERT( ok ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.005208 , vol, 1e-5); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.562500, baryCenter[0], 1e-5); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.125000, baryCenter[1], 1e-5); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.250000, baryCenter[2], 1e-5); + } + + struct __MESH_DUMMY + { + typedef int MyConnType; + }; + + void UnitTetraIntersectionBaryTest::test_UnitTetraIntersectionBary_13() + { + double T[] = { + 66.6666666666666714,133.333333333333343,66.6666666666666714, + 100,200,100, + 100,100,100, + 200,200,0 }; + + double S[] = { + 100,166.666666666666657,66.6666666666666714, + 100,150,50, + 75,150,75, + 100,100,100}; + + int conn[4] = { 0,1,2,3 }; + + const double* tnodes[4]={ T, T+3, T+6, T+9 }; + const double* snodes[4]={ S, S+3, S+6, S+9 }; + + __MESH_DUMMY dummyMesh; + SplitterTetra<__MESH_DUMMY> src( dummyMesh, snodes, conn ); + double volume = src.intersectTetra( tnodes ); + CPPUNIT_ASSERT_DOUBLES_EQUAL(6944.4444444444443,volume,1e-9); + } void UnitTetraIntersectionBaryTest::test_TetraAffineTransform_reverseApply() { - double nodes[4][3] = { {-4.0, 9.0, 3.0 }, - {11.0, 0.0, 2.0 }, - { 0.0, 0.0, 0.0 }, - { 2.0, 1.0,10.0 }}; + double nodes[12] = { -4.0, 9.0, 3.0, + 11.0, 0.0, 2.0, + 0.0, 0.0, 0.0, + 2.0, 1.0,10.0 }; // double pSrc[3] = { -4.0, 9.0, 3.0 }; double pSrc[3] = { 40., -20., 100. }; double pDest[] = {1,1,1}; - const double* n[4] = { &nodes[0][0], &nodes[1][0], &nodes[2][0], &nodes[3][0] }; - TetraAffineTransform a(&n[0]); + TetraAffineTransform a(nodes); a.apply( pDest, pSrc ); a.reverseApply( pDest, pDest ); CPPUNIT_ASSERT_DOUBLES_EQUAL( pSrc[0], pDest[0], 1e-12); @@ -270,7 +323,7 @@ namespace INTERP_TEST {-4.0, 9.0, 3.0 }, { 0.0, 0.0, 0.0 }, { 6.0, 1.0,10.0 }}; - vector n (4); + std::vector n (4); n[0] = &nodes[0][0]; n[1] = &nodes[1][0]; n[2] = &nodes[2][0]; @@ -289,5 +342,148 @@ namespace INTERP_TEST CPPUNIT_ASSERT_DOUBLES_EQUAL( p[0], p2[0], 1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL( p[1], p2[1], 1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL( p[2], p2[2], 1e-12); - } + } + + /* Conventions: + * - for HEXA8, point 5 is taken to be the origin (see med file ref connec): + * 0 ------ 3 + /| /| + / | / | + 1 ------ 2 | + | | | | + | | | | + | 4-----|- 7 + | / | / + 5 ------ 6 + */ + void UnitTetraIntersectionBaryTest::test_cuboid_mapped_coords_3D() + { + double nodes[8][3] = { { 0.0, 2.0, 4.0 }, //0 + { 0.0, 0.0, 4.0 }, + { 1.0, 0.0, 4.0 }, + { 1.0, 2.0, 4.0 }, + { 0.0, 2.0, 0.0 }, // 4 + { 0.0, 0.0, 0.0 }, + { 1.0, 0.0, 0.0 }, + { 1.0, 2.0, 0.0 } + }; + // Translate cube: + for (int i=0; i < 8; ++i) + for (int j=0; j < 3; ++j) + nodes[i][j] += 15.0; + + std::vector n (8); + for (int i=0; i<8; i++) + n[i] = &nodes[i][0]; + + { + // middle point + double p[3] = { 15.5, 16.0, 17.0 }, bc[3]; + cuboid_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[1], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[2], 1e-12); + } + { + // point 1 + double p[3] = { 15.0, 15.0, 19.0 }, bc[3]; + cuboid_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[1], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[2], 1e-12); + } + { + // point 7 + double p[3] = { 16.0, 17.0, 15.0 }, bc[3]; + cuboid_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[1], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[2], 1e-12); + } + { + // point 3 + double p[3] = { 16.0, 17.0, 19.0 }, bc[3]; + cuboid_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[1], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[2], 1e-12); + } + { + // point outside + double p[3] = { 2.0, 16.0, 18.0 }, bc[3]; + CPPUNIT_ASSERT_THROW(cuboid_mapped_coords(n, p, bc), INTERP_KERNEL::Exception); + } + + } + + /* Convention + - for QUAD4, point 0 is taken to be the origin (again see med file ref connec): + + 1------2 + | | + | | + 0------3 + */ + void UnitTetraIntersectionBaryTest::test_quad_mapped_coords_2D() + { + + double nodes[4][2] = { { 0.0, 0.0 }, + { 0.0, 1.0 }, + { 2.0, 3.0 }, + { 1.0, 0.0 } }; + + // Translate quad4: + for (int i=0; i < 4; ++i) + for (int j=0; j < 2; ++j) + nodes[i][j] += 15.0; + + std::vector n (4); + for (int i=0; i<4; i++) + n[i] = &nodes[i][0]; + + { + // middle point + double p[2] = { 15.75, 16.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[1], 1e-12); + } + + { + // middle point of seg + double p[2] = { 15.5, 15.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[1], 1e-12); + } + + { + // point 1 + double p[2] = { 15.0, 16.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[1], 1e-12); + } + { + // point 2 + double p[2] = { 17.0, 18.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[1], 1e-12); + } + { + // point 3 + double p[2] = { 16.0, 15.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[1], 1e-12); + } + { + // point outside + double p[2] = { 18.0, 18.0 }, bc[2]; + CPPUNIT_ASSERT_THROW(quad_mapped_coords(n, p, bc), INTERP_KERNEL::Exception); + } + } + + }