Salome HOME
Update copyrights 2014.
[tools/medcoupling.git] / src / INTERP_KERNELTest / Interpolation3DTest.cxx
index a538c6fdbbe0ee89c89fc969a944f586844e89a2..c5e46448e493f55395bb8cde8852d863c6a099fe 100644 (file)
@@ -1,35 +1,36 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "Interpolation3DTest.hxx"
-#include "MEDMEM_Mesh.hxx"
 
-#include <iostream>
+#include "MEDFileMesh.hxx"
+#include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+
 #include <map>
-#include <vector>
 #include <cmath>
+#include <vector>
+#include <iostream>
 #include <algorithm>
 
 #include "VectorUtils.hxx"
 
-#include "MEDMEM_Field.hxx"
-#include "MEDMEM_Support.hxx"
-
 // levels : 
 // 1 - titles and volume results
 // 2 - symmetry / diagonal results and intersection matrix output
 
 //#define VOL_PREC 1.0e-6
 
-using namespace MEDMEM;
-using namespace std;
+using namespace ParaMEDMEM;
 using namespace INTERP_KERNEL;
-using namespace MED_EN;
 
 double Interpolation3DTest::sumRow(const IntersectionMatrix& m, int i) const
 {
@@ -53,7 +52,7 @@ double Interpolation3DTest::sumRow(const IntersectionMatrix& m, int i) const
     {
       if(iter->count(i) != 0.0)
         {
-          map<int, double>::const_iterator iter2 = iter->find(i);
+          std::map<int, double>::const_iterator iter2 = iter->find(i);
           vol += iter2->second;
         }
     }
@@ -64,7 +63,7 @@ double Interpolation3DTest::sumCol(const IntersectionMatrix& m, int i) const
 {
   double vol = 0.0;
   const std::map<int, double>& col = m[i];
-  for(map<int, double>::const_iterator iter = col.begin() ; iter != col.end() ; ++iter)
+  for(std::map<int, double>::const_iterator iter = col.begin() ; iter != col.end() ; ++iter)
     {
       vol += std::fabs(iter->second);
     }
@@ -72,22 +71,19 @@ double Interpolation3DTest::sumCol(const IntersectionMatrix& m, int i) const
 }
 
 
-void Interpolation3DTest::getVolumes(MESH& mesh, double* tab) const
+void Interpolation3DTest::getVolumes(ParaMEDMEM::MEDCouplingUMesh& mesh, double *tab) const
 {
-  SUPPORT *sup=new SUPPORT(&mesh,"dummy",MED_CELL);
-  FIELD<double>* f=mesh.getVolume(sup);
-  const double *tabS=f->getValue();
-  std::copy(tabS,tabS+mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS),tab)
-    delete sup;
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> vol=mesh->getMeasureField(true);
+  std::copy(vol->getArray()->begin(),vol->getArray()->end(),tab);
 }
 
 double Interpolation3DTest::sumVolume(const IntersectionMatrix& m) const
 {
   
-  vector<double> volumes;
+  std::vector<double> volumes;
   for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter)
     {
-      for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
+      for(std::map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
         {
           volumes.push_back(iter2->second);
           //    vol += std::abs(iter2->second);
@@ -102,15 +98,15 @@ double Interpolation3DTest::sumVolume(const IntersectionMatrix& m) const
   return vol;
 }
 
-bool Interpolation3DTest::testVolumes(const IntersectionMatrix& m,  MESH& sMesh,  MESH& tMesh) const
+bool Interpolation3DTest::testVolumes(const IntersectionMatrix& m,  MEDCouplingUMesh& sMesh,  MEDCouplingUMesh& tMesh) const
 {
   bool ok = true;
 
   // source elements
-  double* sVol = new double[sMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)];
+  double* sVol = new double[sMesh.getNumberOfCells()];
   getVolumes(sMesh, sVol);
 
-  for(int i = 0; i < sMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS); ++i)
+  for(int i = 0; i < sMesh.getNumberOfCells(); ++i)
     {
       const double sum_row = sumRow(m, i+1);
       if(!epsilonEqualRelative(sum_row, sVol[i], VOL_PREC))
@@ -122,9 +118,9 @@ bool Interpolation3DTest::testVolumes(const IntersectionMatrix& m,  MESH& sMesh,
     }
 
   // target elements
-  double* tVol = new double[tMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)];
+  double* tVol = new double[tMesh.getNumberOfCells()];
   getVolumes(tMesh, tVol);
-  for(int i = 0; i < tMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS); ++i)
+  for(int i = 0; i < tMesh.getNumberOfCells(); ++i)
     {
       const double sum_col = sumCol(m, i);
       if(!epsilonEqualRelative(sum_col, tVol[i], VOL_PREC))
@@ -146,7 +142,7 @@ bool Interpolation3DTest::areCompatitable(const IntersectionMatrix& m1, const In
   int i = 0;
   for(IntersectionMatrix::const_iterator iter = m1.begin() ; iter != m1.end() ; ++iter)
     {
-      for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
+      for(std::map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
         {
           int j = iter2->first;
           if(m2.at(j-1).count(i+1) == 0)
@@ -181,13 +177,13 @@ bool Interpolation3DTest::testSymmetric(const IntersectionMatrix& m1, const Inte
 
   for(IntersectionMatrix::const_iterator iter = m1.begin() ; iter != m1.end() ; ++iter)
     {
-      for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
+      for(std::map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
         {
           int j = iter2->first;
           const double v1 = iter2->second;
           //if(m2[j - 1].count(i+1) > 0)
           //  {
-          map<int, double> theMap =  m2.at(j-1);
+          std::map<int, double> theMap =  m2.at(j-1);
           const double v2 = theMap[i + 1];
           if(v1 != v2)
             {
@@ -215,7 +211,7 @@ bool Interpolation3DTest::testDiagonal(const IntersectionMatrix& m) const
   bool isDiagonal = true;
   for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter)
     {
-      for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
+      for(std::map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
         {
           int j = iter2->first;
           const double vol = iter2->second;
@@ -241,13 +237,13 @@ bool Interpolation3DTest::testDiagonal(const IntersectionMatrix& m) const
 void Interpolation3DTest::dumpIntersectionMatrix(const IntersectionMatrix& m) const
 {
   int i = 0;
-  std::cout << "Intersection matrix is " << endl;
+  std::cout << "Intersection matrix is " << std::endl;
   for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter)
     {
-      for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
+      for(std::map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
         {
     
-          std::cout << "V(" << i << ", " << iter2->first << ") = " << iter2->second << endl;
+          std::cout << "V(" << i << ", " << iter2->first << ") = " << iter2->second << std::endl;
     
         }
       ++i;