Salome HOME
9bc5c74062cb12ee48364617b93c14bfe1f011b8
[modules/med.git] / src / INTERP_KERNELTest / InterpolationOptionsTest.cxx
1 // Copyright (C) 2007-2015  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 "MEDFileMesh.hxx"
21 #include "MEDCouplingFieldDouble.hxx"
22
23 #include "InterpolationOptionsTest.hxx"
24 #include "MEDCouplingNormalizedUnstructuredMesh.txx"
25 #include "Interpolation2D.txx"
26 #include "TestInterpKernelUtils.hxx"
27
28 #include <iostream>
29 #include <vector>
30
31 using namespace ParaMEDMEM;
32
33 namespace INTERP_TEST
34 {
35   void InterpolationOptionsTest::setUp()
36   {
37   }
38
39
40   void InterpolationOptionsTest::tearDown()
41   {
42   }
43
44   /**
45    * Test that creates a tree in 2D and check that 
46    * the results are correct in three
47    * cases :
48    * a non matching search
49    * a standard case
50    * a bbox overlapping the bboxes of the tree
51    */
52   void InterpolationOptionsTest::test_InterpolationOptions() 
53   {
54     std::string sourcename=INTERP_TEST::getResourceFile("square1.med");
55     MEDFileUMesh *source_mesh=MEDFileUMesh::New(sourcename.c_str(),"Mesh_2");
56
57     std::string targetname=INTERP_TEST::getResourceFile("square2.med");
58     MEDFileUMesh *target_mesh=MEDFileUMesh::New(targetname.c_str(),"Mesh_3");
59
60     MEDCouplingUMesh *source_mesh_mc=source_mesh->getMeshAtLevel(0);
61     MEDCouplingFieldDouble *source_field=MEDCouplingFieldDouble::New(ON_CELLS);
62     source_field->setMesh(source_mesh_mc); source_mesh_mc->decrRef();
63     DataArrayDouble *arr=DataArrayDouble::New(); arr->alloc(source_mesh_mc->getNumberOfCells(),1);
64     source_field->setArray(arr); arr->decrRef();
65     double *value=arr->getPointer();
66     for(int i=0; i<source_mesh_mc->getNumberOfCells(); i++)
67       value[i]=1.0;
68     MEDCouplingUMesh *target_mesh_mc=target_mesh->getMeshAtLevel(0);
69     MEDCouplingFieldDouble *target_field=MEDCouplingFieldDouble::New(ON_CELLS);
70     target_field->setMesh(target_mesh_mc); target_mesh_mc->decrRef();
71     arr=DataArrayDouble::New(); arr->alloc(target_mesh_mc->getNumberOfCells(),1);
72     target_field->setArray(arr); arr->decrRef();
73     double* targetvalue=arr->getPointer();
74     for(int i=0; i<target_mesh_mc->getNumberOfCells(); i++)
75       targetvalue[i]=0.0;
76     // Ok at this point we have our mesh in MED-Memory format.
77     // Go to wrap med_source_mesh and med_target_mesh.
78     MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_source_mesh(source_mesh_mc);
79     MEDCouplingNormalizedUnstructuredMesh<2,2> wrap_target_mesh(target_mesh_mc);
80     // Go for interpolation...
81     INTERP_KERNEL::Interpolation2D myInterpolator;
82     //optionnal call to parametrize your interpolation. First precision, tracelevel, intersector wanted.
83     myInterpolator.setPrecision(1e-7);
84     myInterpolator.setPrintLevel(1);
85     source_mesh->decrRef();
86     source_field->decrRef();
87     target_field->decrRef();
88     target_mesh->decrRef();
89   }
90 }