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