Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / INTERP_KERNELTest / RemapperTest.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 "RemapperTest.hxx"
21 #include "Remapper.hxx"
22 #include "TestInterpKernelUtils.hxx"
23
24 #include <iostream>
25 #include <vector>
26
27 namespace INTERP_TEST
28 {
29
30
31   void RemapperTest::setUp() 
32   {
33   }
34
35  
36   void RemapperTest::tearDown() 
37   {
38   }
39
40   /**
41    * Test that creates a tree in 2D and check that 
42    * the results are correct in three
43    * cases :
44    * a non matching search
45    * a standard case
46    * a bbox overlapping the bboxes of the tree
47    */
48   void RemapperTest::test_Remapper() {
49     string sourcename=INTERP_TEST::getResourceFile("square1.med");
50     MEDMEM::MESH source_mesh (MED_DRIVER,sourcename,"Mesh_2");
51
52     string targetname=INTERP_TEST::getResourceFile("square2.med");
53     MEDMEM::MESH target_mesh (MED_DRIVER,targetname,"Mesh_3");
54
55     MEDMEM::SUPPORT source_support(&source_mesh,"on All support");
56     MEDMEM::FIELD<double> source_field(&source_support,1);
57     double* value=const_cast<double*>(source_field.getValue());
58     for (int i=0; i<source_support.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); i++)
59       value[i]=1.0;
60     
61     MEDMEM::SUPPORT target_support(&target_mesh,"on All support");
62     MEDMEM::FIELD<double> target_field(&target_support,1);
63     double* targetvalue=const_cast<double*>(target_field.getValue());
64     for (int i=0; i<target_support.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); i++)
65       targetvalue[i]=0.0;
66
67
68     INTERP_KERNEL::Remapper remapper;
69     remapper.prepare(source_mesh,target_mesh,"P0P0");
70     remapper.transfer(source_field,target_field);
71
72     MEDMEM::FIELD<double> *source_areas=source_mesh.getArea(&source_support);
73     MEDMEM::FIELD<double> *target_areas=target_mesh.getArea(&target_support);
74     absField(*source_areas); //absolute value
75     absField(*target_areas); //absolute value
76
77     //target square is in reverse order as compared to initial square
78     double source_integral=source_field.normL2(1,source_areas);
79     double target_integral=target_field.normL2(1,target_areas);
80     
81     CPPUNIT_ASSERT_DOUBLES_EQUAL(source_integral,target_integral,1e-10);
82     delete source_areas;
83     delete target_areas;
84     
85   }
86
87   void RemapperTest::absField(MEDMEM::FIELD<double>& field)
88   {
89     double* areas=const_cast<double*>(field.getValue());
90     for (int i=0; i< field.getNumberOfValues();i++)
91       {
92         areas[i]=fabs(areas[i]);
93       }
94   }
95
96 }