1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "RemapperTest.hxx"
20 #include "Remapper.hxx"
29 void RemapperTest::setUp()
34 void RemapperTest::tearDown()
39 * Test that creates a tree in 2D and check that
40 * the results are correct in three
42 * a non matching search
44 * a bbox overlapping the bboxes of the tree
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");
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");
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++)
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++)
68 INTERP_KERNEL::Remapper remapper;
69 remapper.prepare(source_mesh,target_mesh,"P0P0");
70 remapper.transfer(source_field,target_field);
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
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);
81 CPPUNIT_ASSERT_DOUBLES_EQUAL(source_integral,target_integral,1e-10);
87 void RemapperTest::absField(MEDMEM::FIELD<double>& field)
89 double* areas=const_cast<double*>(field.getValue());
90 for (int i=0; i< field.getNumberOfValues();i++)
92 areas[i]=fabs(areas[i]);