Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / INTERP_KERNELTest / RemapperTest.cxx
1 //  Copyright (C) 2007-2008  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 #include "RemapperTest.hxx"
20 #include "Remapper.hxx"
21
22 #include <iostream>
23 #include <vector>
24
25 namespace INTERP_TEST
26 {
27
28
29   void RemapperTest::setUp() 
30   {
31   }
32
33  
34   void RemapperTest::tearDown() 
35   {
36   }
37
38   /**
39    * Test that creates a tree in 2D and check that 
40    * the results are correct in three
41    * cases :
42    * a non matching search
43    * a standard case
44    * a bbox overlapping the bboxes of the tree
45    */
46   void RemapperTest::test_Remapper() {
47     string sourcename=getenv("MED_ROOT_DIR");
48     sourcename +="/share/salome/resources/med/square1.med";
49     MEDMEM::MESH source_mesh (MED_DRIVER,sourcename,"Mesh_2");
50
51     string targetname=getenv("MED_ROOT_DIR");
52     targetname +="/share/salome/resources/med/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 }