X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FINTERP_KERNELTest%2FInterpolation3DTest.cxx;h=c0349a5ffc1d71ae67c440dc6d41b29543492341;hb=c4551c56aa89896595842e5b41b048044681b4e8;hp=5b6376e06ef6a5fe7bebac67fbbe0e52a52c484a;hpb=10f37bf6f33a762626d7f1093b2f5450c1688667;p=tools%2Fmedcoupling.git diff --git a/src/INTERP_KERNELTest/Interpolation3DTest.cxx b/src/INTERP_KERNELTest/Interpolation3DTest.cxx index 5b6376e06..c0349a5ff 100644 --- a/src/INTERP_KERNELTest/Interpolation3DTest.cxx +++ b/src/INTERP_KERNELTest/Interpolation3DTest.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2007-2016 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. +// 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 @@ -18,20 +18,20 @@ // #include "Interpolation3DTest.hxx" -#include "MEDMEM_Mesh.hxx" -#include +#include "MEDFileMesh.hxx" +#include "MEDCouplingUMesh.hxx" +#include "MEDCouplingFieldDouble.hxx" + #include -#include #include +#include +#include #include #include "VectorUtils.hxx" -#include "MEDMEM_Field.hxx" -#include "MEDMEM_Support.hxx" - -// levels : +// levels : // 1 - titles and volume results // 2 - symmetry / diagonal results and intersection matrix output // 3 - empty @@ -42,9 +42,8 @@ //#define VOL_PREC 1.0e-6 -using namespace MEDMEM; +using namespace MEDCoupling; using namespace INTERP_KERNEL; -using namespace MED_EN; double Interpolation3DTest::sumRow(const IntersectionMatrix& m, int i) const { @@ -72,18 +71,15 @@ double Interpolation3DTest::sumCol(const IntersectionMatrix& m, int i) const } -void Interpolation3DTest::getVolumes(MESH& mesh, double* tab) const +void Interpolation3DTest::getVolumes(MEDCoupling::MEDCouplingUMesh& mesh, double *tab) const { - SUPPORT *sup=new SUPPORT(&mesh,"dummy",MED_CELL); - FIELD* f=mesh.getVolume(sup); - const double *tabS=f->getValue(); - std::copy(tabS,tabS+mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS),tab) - delete sup; + MCAuto vol=mesh->getMeasureField(true); + std::copy(vol->getArray()->begin(),vol->getArray()->end(),tab); } double Interpolation3DTest::sumVolume(const IntersectionMatrix& m) const { - + std::vector volumes; for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter) { @@ -93,7 +89,7 @@ double Interpolation3DTest::sumVolume(const IntersectionMatrix& m) const // vol += std::abs(iter2->second); } } - + // sum in ascending order to avoid rounding errors sort(volumes.begin(), volumes.end()); @@ -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)) @@ -167,7 +163,7 @@ bool Interpolation3DTest::areCompatitable(const IntersectionMatrix& m1, const In } return compatitable; } - + bool Interpolation3DTest::testSymmetric(const IntersectionMatrix& m1, const IntersectionMatrix& m2) const { @@ -246,9 +242,9 @@ void Interpolation3DTest::dumpIntersectionMatrix(const IntersectionMatrix& m) co { for(std::map::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2) { - + std::cout << "V(" << i << ", " << iter2->first << ") = " << iter2->second << std::endl; - + } ++i; } @@ -263,18 +259,25 @@ void Interpolation3DTest::setUp() void Interpolation3DTest::tearDown() { delete interpolator; -} +} void Interpolation3DTest::calcIntersectionMatrix(const char* mesh1path, const char* mesh1, const char* mesh2path, const char* mesh2, IntersectionMatrix& m) const { - const string dataBaseDir = getenv("MED_ROOT_DIR"); - const string dataDir = dataBaseDir + "/share/salome/resources/med/"; + string dataDir = ""; + if ( getenv("MEDCOUPLING_ROOT_DIR") ) { + dataDir = getenv("MEDCOUPLING_ROOT_DIR"); + dataDir += "/share/resources/med/"; + } + else { + dataDir = get_current_dir_name(); + dataDir += "/../../resources/"; + } LOG(1, std::endl << "=== -> intersecting src = " << mesh1 << ", target = " << mesh2 ); LOG(5, "Loading " << mesh1 << " from " << mesh1path); MESH sMesh(MED_DRIVER, dataDir+mesh1path, mesh1); - + LOG(5, "Loading " << mesh2 << " from " << mesh2path); MESH tMesh(MED_DRIVER, dataDir+mesh2path, mesh2); @@ -288,7 +291,7 @@ void Interpolation3DTest::calcIntersectionMatrix(const char* mesh1path, const ch } LOG(1, "Intersection calculation done. " << std::endl ); - + } void Interpolation3DTest::intersectMeshes(const char* mesh1path, const char* mesh1, const char* mesh2path, const char* mesh2, const double correctVol, const double prec, bool doubleTest) const @@ -304,7 +307,7 @@ void Interpolation3DTest::intersectMeshes(const char* mesh1path, const char* mes IntersectionMatrix matrix1; calcIntersectionMatrix(mesh1path, mesh1, mesh2path, mesh2, matrix1); -#if LOG_LEVEL >= 2 +#if LOG_LEVEL >= 2 dumpIntersectionMatrix(matrix1); #endif @@ -324,14 +327,14 @@ void Interpolation3DTest::intersectMeshes(const char* mesh1path, const char* mes } else { - + IntersectionMatrix matrix2; - calcIntersectionMatrix(mesh2path, mesh2, mesh1path, mesh1, matrix2); + calcIntersectionMatrix(mesh2path, mesh2, mesh1path, mesh1, matrix2); #if LOG_LEVEL >= 2 dumpIntersectionMatrix(matrix2); #endif - + const double vol2 = sumVolume(matrix2); LOG(1, "vol1 = " << vol1 << ", vol2 = " << vol2 << ", correctVol = " << correctVol );