Back to index

salome-med  6.5.0
InterpolationOptionsTest.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "InterpolationOptionsTest.hxx"
00021 #include "MEDNormalizedUnstructuredMesh.txx"
00022 #include "Interpolation2D.txx"
00023 #include "TestInterpKernelUtils.hxx"
00024 #include <iostream>
00025 #include <vector>
00026 
00027 namespace INTERP_TEST
00028 {
00029   void InterpolationOptionsTest::setUp()
00030   {
00031   }
00032 
00033 
00034   void InterpolationOptionsTest::tearDown()
00035   {
00036   }
00037 
00046   void InterpolationOptionsTest::test_InterpolationOptions() 
00047   {
00048     string sourcename=INTERP_TEST::getResourceFile("square1.med");
00049     MEDMEM::MESH *source_mesh=new MEDMEM::MESH(MED_DRIVER,sourcename,"Mesh_2");
00050 
00051     string targetname=INTERP_TEST::getResourceFile("square2.med");
00052     MEDMEM::MESH *target_mesh=new MEDMEM::MESH(MED_DRIVER,targetname,"Mesh_3");
00053 
00054     const MEDMEM::SUPPORT *source_support=source_mesh->getSupportOnAll(MED_EN::MED_CELL);
00055     MEDMEM::FIELD<double> *source_field=new FIELD<double>(source_support,1);
00056     double* value=const_cast<double*>(source_field->getValue());
00057     for (int i=0; i<source_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); i++)
00058       value[i]=1.0;
00059     const MEDMEM::SUPPORT *target_support=target_mesh->getSupportOnAll(MED_EN::MED_CELL);
00060     MEDMEM::FIELD<double> *target_field=new FIELD<double>(target_support,1);
00061     double* targetvalue=const_cast<double*>(target_field->getValue());
00062     for (int i=0; i<target_support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); i++)
00063       targetvalue[i]=0.0;
00064     // Ok at this point we have our mesh in MED-Memory format.
00065     // Go to wrap med_source_mesh and med_target_mesh.
00066     MEDNormalizedUnstructuredMesh<2,2> wrap_source_mesh(source_mesh);
00067     MEDNormalizedUnstructuredMesh<2,2> wrap_target_mesh(target_mesh);
00068     // Go for interpolation...
00069     INTERP_KERNEL::Interpolation2D myInterpolator;
00070     //optionnal call to parametrize your interpolation. First precision, tracelevel, intersector wanted.
00071     myInterpolator.setPrecision(1e-7);
00072     myInterpolator.setPrintLevel(1);
00073     source_mesh->removeReference();
00074     source_field->removeReference();
00075     target_field->removeReference();
00076     target_mesh->removeReference();
00077   }
00078 }