Salome HOME
1437358606259cbadba864a02f1a3dba80e70477
[tools/medcoupling.git] / src / INTERP_KERNELTest / UnitTetra3D2DIntersectionTest.cxx
1 // Copyright (C) 2007-2020  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, or (at your option) any later version.
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 "UnitTetra3D2DIntersectionTest.hxx"
21
22 #include "TetraAffineTransform.hxx"
23 #include "InterpolationUtils.hxx"
24 #include "SplitterTetra.txx"
25 #include "MCIdType.hxx"
26
27 #include <iostream>
28
29 using namespace INTERP_KERNEL;
30
31 namespace INTERP_TEST
32 {
33   struct __MESH_DUMMY
34   {
35     typedef mcIdType MyConnType;
36     static const int MY_SPACEDIM=3;
37   };
38
39   static SplitterTetra<__MESH_DUMMY>* buildSplitterTetra()
40   {
41     const mcIdType conn[4] = { 0,1,2,3 };
42
43     const double targetCoords[] = { -20., 0.,10.,
44                                     -20.,10.,10.,
45                                     -12., 0.,10.,
46                                     -20., 0.,18. };
47
48     const double* tetraCoords[]={ targetCoords, targetCoords+3, targetCoords+6, targetCoords+9 };
49
50     __MESH_DUMMY dummyMesh;
51     SplitterTetra<__MESH_DUMMY>* targetTetra = new SplitterTetra<__MESH_DUMMY>( dummyMesh, tetraCoords, conn );
52     return targetTetra;
53   }
54
55   void UnitTetra3D2DIntersectionTest::test_UnitTetra3D2DIntersection_1()
56   {
57     const mcIdType conn[4] = { 0,1,2 };
58
59     const double sourceCoords[] = { -20., 0., 10.,
60                                     -12., 0., 10.,
61                                     -20.,10., 10. };
62
63     SplitterTetra<__MESH_DUMMY>* targetTetra = buildSplitterTetra();
64     const double dimCaracteristic = 1.;
65     const double precision = 1.e-12;
66     std::multiset<TriangleFaceKey> listOfTetraFacesTreated;
67     std::set<TriangleFaceKey> listOfTetraFacesColinear;
68
69     const double* sourceTriCoords[] = { sourceCoords, sourceCoords+3, sourceCoords+6 };
70     double surface = targetTetra->intersectSourceFace(NORM_TRI3,
71                                                       3,
72                                                       conn,
73                                                       sourceTriCoords,
74                                                       dimCaracteristic,
75                                                       precision,
76                                                       listOfTetraFacesTreated,
77                                                       listOfTetraFacesColinear);
78     delete targetTetra;
79     CPPUNIT_ASSERT_DOUBLES_EQUAL(40.,surface,precision);
80
81     CPPUNIT_ASSERT_EQUAL(4,(int)listOfTetraFacesTreated.size());
82     std::multiset<TriangleFaceKey> correctListOfTetraFacesTreated;
83     TriangleFaceKey key1 = TriangleFaceKey(0, 1, 2);
84     correctListOfTetraFacesTreated.insert(key1);
85     TriangleFaceKey key2 = TriangleFaceKey(0, 1, 3);
86     correctListOfTetraFacesTreated.insert(key2);
87     TriangleFaceKey key3 = TriangleFaceKey(0, 2, 3);
88     correctListOfTetraFacesTreated.insert(key3);
89     TriangleFaceKey key4 = TriangleFaceKey(1, 2, 3);
90     correctListOfTetraFacesTreated.insert(key4);
91     CPPUNIT_ASSERT(correctListOfTetraFacesTreated == listOfTetraFacesTreated);
92
93     CPPUNIT_ASSERT_EQUAL(1,(int)listOfTetraFacesColinear.size());
94     std::set<TriangleFaceKey> correctListOfTetraFacesColinear;
95     correctListOfTetraFacesColinear.insert(key1);
96     CPPUNIT_ASSERT(correctListOfTetraFacesColinear == listOfTetraFacesColinear);
97
98   }
99
100   void UnitTetra3D2DIntersectionTest::test_UnitTetra3D2DIntersection_2()
101   {
102     const mcIdType conn[4] = { 0,1,2,3 };
103
104     const double sourceCoords[] = { -20., 0., 10.,
105                                     -12., 0., 10.,
106                                     -12.,10., 10.,
107                                     -20.,10., 10. };
108
109     SplitterTetra<__MESH_DUMMY>* targetTetra = buildSplitterTetra();
110     const double dimCaracteristic = 1.;
111     const double precision = 1.e-12;
112     std::multiset<TriangleFaceKey> listOfTetraFacesTreated;
113     std::set<TriangleFaceKey> listOfTetraFacesColinear;
114
115     const double* sourceQuadCoords[] = { sourceCoords, sourceCoords+3, sourceCoords+6, sourceCoords+9 };
116     double surface = targetTetra->intersectSourceFace(NORM_QUAD4,
117                                                       4,
118                                                       conn,
119                                                       sourceQuadCoords,
120                                                       dimCaracteristic,
121                                                       precision,
122                                                       listOfTetraFacesTreated,
123                                                       listOfTetraFacesColinear);
124     delete targetTetra;
125     CPPUNIT_ASSERT_DOUBLES_EQUAL(40.,surface,precision);
126
127     CPPUNIT_ASSERT_EQUAL(4,(int)listOfTetraFacesTreated.size());
128     std::multiset<TriangleFaceKey> correctListOfTetraFacesTreated;
129     TriangleFaceKey key1 = TriangleFaceKey(0, 1, 2);
130     correctListOfTetraFacesTreated.insert(key1);
131     TriangleFaceKey key2 = TriangleFaceKey(0, 1, 3);
132     correctListOfTetraFacesTreated.insert(key2);
133     TriangleFaceKey key3 = TriangleFaceKey(0, 2, 3);
134     correctListOfTetraFacesTreated.insert(key3);
135     TriangleFaceKey key4 = TriangleFaceKey(1, 2, 3);
136     correctListOfTetraFacesTreated.insert(key4);
137     CPPUNIT_ASSERT(correctListOfTetraFacesTreated == listOfTetraFacesTreated);
138
139     CPPUNIT_ASSERT_EQUAL(1,(int)listOfTetraFacesColinear.size());
140     std::set<TriangleFaceKey> correctListOfTetraFacesColinear;
141     correctListOfTetraFacesColinear.insert(key1);
142     CPPUNIT_ASSERT(correctListOfTetraFacesColinear == listOfTetraFacesColinear);
143
144  }
145
146   void UnitTetra3D2DIntersectionTest::test_UnitTetra3D2DIntersection_3()
147   {
148     const mcIdType conn[4] = { 0,1,2 };
149
150     const double sourceCoords[] = { -20., 0., 16.,
151                                     -18., 0., 16.,
152                                     -20.,2.5, 16. };
153
154     SplitterTetra<__MESH_DUMMY>* targetTetra = buildSplitterTetra();
155     const double dimCaracteristic = 1.;
156     const double precision = 1.e-12;
157     std::multiset<TriangleFaceKey> listOfTetraFacesTreated;
158     std::set<TriangleFaceKey> listOfTetraFacesColinear;
159
160     const double* sourceTri2Coords[] = { sourceCoords, sourceCoords+3, sourceCoords+6 };
161     double surface = targetTetra->intersectSourceFace(NORM_TRI3,
162                                                       3,
163                                                       conn,
164                                                       sourceTri2Coords,
165                                                       dimCaracteristic,
166                                                       precision,
167                                                       listOfTetraFacesTreated,
168                                                       listOfTetraFacesColinear);
169     delete targetTetra;
170     CPPUNIT_ASSERT_DOUBLES_EQUAL(2.5,surface,precision);
171
172     CPPUNIT_ASSERT_EQUAL(0,(int)listOfTetraFacesTreated.size());
173
174     CPPUNIT_ASSERT_EQUAL(0,(int)listOfTetraFacesColinear.size());
175  }
176
177 }