X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FINTERP_KERNELTest%2FMeshTestToolkit.txx;h=ae583ffb3ab3bd6c37d695899257aaf29c7916d6;hb=c4551c56aa89896595842e5b41b048044681b4e8;hp=6121329e7f65b04f7caf63917a4bcd047f8e05f0;hpb=f1a947b32a36d8dc8e3079b25305bb50e8cb59a0;p=tools%2Fmedcoupling.git diff --git a/src/INTERP_KERNELTest/MeshTestToolkit.txx b/src/INTERP_KERNELTest/MeshTestToolkit.txx index 6121329e7..ae583ffb3 100644 --- a/src/INTERP_KERNELTest/MeshTestToolkit.txx +++ b/src/INTERP_KERNELTest/MeshTestToolkit.txx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 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,26 +18,27 @@ // #include "TestInterpKernelUtils.hxx" -#include "MEDNormalizedUnstructuredMesh.hxx" -#include "MEDNormalizedUnstructuredMesh.txx" - #include "MeshTestToolkit.hxx" -#include "MEDMEM_Mesh.hxx" -#include "MEDMEM_Field.hxx" -#include "MEDMEM_Support.hxx" + +#include "MEDFileMesh.hxx" + +#include "MEDCouplingNormalizedUnstructuredMesh.hxx" +#include "MEDCouplingNormalizedUnstructuredMesh.txx" +#include "MEDCouplingFieldDouble.hxx" #include "Interpolation3DSurf.hxx" #include "Interpolation2D.txx" #include "Interpolation3D.txx" -#include #include -#include #include +#include +#include +#include #include -// levels : +// levels : // 1 - titles and volume results // 2 - symmetry / diagonal results and intersection matrix output // 3 - empty @@ -48,9 +49,7 @@ #include //#define VOL_PREC 1.0e-6 - -using namespace MEDMEM; -using namespace MED_EN; +using namespace MEDCoupling; using namespace INTERP_KERNEL; namespace INTERP_TEST @@ -105,22 +104,10 @@ namespace INTERP_TEST * @param tab pointer to double[no. elements of mesh] array in which to store the volumes */ template - void MeshTestToolkit::getVolumes(MEDMEM::MESH& mesh, double* tab) const + void MeshTestToolkit::getVolumes(MEDCoupling::MEDCouplingUMesh& mesh, double *tab) const { - const SUPPORT *sup=mesh.getSupportOnAll( MED_CELL ); - FIELD* f; - switch (MESHDIM) - { - case 2: - f=mesh.getArea(sup); - break; - case 3: - f=mesh.getVolume(sup); - break; - } - const double *tabS = f->getValue(); - std::copy(tabS,tabS+mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS),tab); - f->removeReference(); + MCAuto vol=mesh.getMeasureField(true); + std::copy(vol->getArray()->begin(),vol->getArray()->end(),tab); } /** @@ -151,7 +138,7 @@ namespace INTERP_TEST } /** - * Verifies if for a given intersection matrix the sum of each row is equal to the volumes + * Verifies if for a given intersection matrix the sum of each row is equal to the volumes * of the corresponding source elements and the sum of each column is equal to the volumes * of the corresponding target elements. This will be true as long as the meshes correspond * to the same geometry. The equalities are in the "epsilon-sense", making sure the relative @@ -163,17 +150,17 @@ namespace INTERP_TEST * @return true if the condition is verified, false if not. */ template - bool MeshTestToolkit::testVolumes(const IntersectionMatrix& m, MEDMEM::MESH& sMesh, MEDMEM::MESH& tMesh) const + bool MeshTestToolkit::testVolumes(const IntersectionMatrix& m, MEDCoupling::MEDCouplingUMesh& sMesh, MEDCoupling::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); + const double sum_row = sumRow(m, i); if(!epsilonEqualRelative(sum_row, fabs(sVol[i]), _precision)) { LOG(1, "Source volume inconsistent : vol of cell " << i << " = " << sVol[i] << " but the row sum is " << sum_row ); @@ -183,9 +170,9 @@ namespace INTERP_TEST } // 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,fabs(tVol[i]), _precision)) @@ -219,11 +206,11 @@ namespace INTERP_TEST for(std::map::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2) { int j = iter2->first; - if(m2.at(j-1).count(i+1) == 0) + if(m2.at(j).count(i) == 0) { if(!epsilonEqual(iter2->second, 0.0, _precision)) { - LOG(2, "V1( " << i << ", " << j << ") exists, but V2( " << j - 1 << ", " << i + 1 << ") " << " does not " ); + LOG(2, "V1( " << i << ", " << j << ") exists, but V2( " << j << ", " << i << ") " << " does not " ); LOG(2, "(" << i << ", " << j << ") fails"); compatitable = false; } @@ -264,11 +251,11 @@ namespace INTERP_TEST const double v1 = fabs(iter2->second); //if(m2[j - 1].count(i+1) > 0) // { - std::map theMap = m2.at(j-1); - const double v2 = fabs(theMap[i + 1]); + std::map theMap = m2.at(j); + const double v2 = fabs(theMap[i]); if(v1 != v2) { - LOG(2, "V1( " << i << ", " << j << ") = " << v1 << " which is different from V2( " << j - 1 << ", " << i + 1 << ") = " << v2 << " | diff = " << v1 - v2 ); + LOG(2, "V1( " << i << ", " << j << ") = " << v1 << " which is different from V2( " << j << ", " << i << ") = " << v2 << " | diff = " << v1 - v2 ); if(!epsilonEqualRelative(v1, v2, _precision)) { LOG(2, "(" << i << ", " << j << ") fails"); @@ -280,7 +267,7 @@ namespace INTERP_TEST } if(!isSymmetric) { - LOG(1, "*** matrices are not symmetric"); + LOG(1, "*** matrices are not symmetric"); } return isSymmetric; } @@ -296,17 +283,17 @@ namespace INTERP_TEST bool MeshTestToolkit::testDiagonal(const IntersectionMatrix& m) const { LOG(1, "Checking if matrix is diagonal" ); - int i = 1; + int i = 0; bool isDiagonal = true; for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter) { - for(map::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2) + for(std::map::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2) { int j = iter2->first; const double vol = iter2->second; if(vol != 0.0 && (i != j)) { - LOG(2, "V( " << i - 1 << ", " << j << ") = " << vol << " which is not zero" ); + LOG(2, "V( " << i << ", " << j << ") = " << vol << " which is not zero" ); if(!epsilonEqual(vol, 0.0, _precision)) { LOG(2, "(" << i << ", " << j << ") fails"); @@ -332,12 +319,12 @@ namespace INTERP_TEST void MeshTestToolkit::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::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2) + for(std::map::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; } @@ -348,9 +335,9 @@ namespace INTERP_TEST * Calculates the intersection matrix for two meshes. * If the source and target meshes are the same, a CppUnit assertion raised if testVolumes() returns false. * - * @param mesh1path the path to the file containing the source mesh, relative to {$MED_ROOT_DIR}/share/salome/resources/med/ + * @param mesh1path the path to the file containing the source mesh, relative to {$MEDCOUPLING_ROOT_DIR}/share/resources/med/ * @param mesh1 the name of the source mesh - * @param mesh2path the path to the file containing the target mesh, relative to {$MED_ROOT_DIR}/share/salome/resources/med/ + * @param mesh2path the path to the file containing the target mesh, relative to {$MEDCOUPLING_ROOT_DIR}/share/resources/med/ * @param mesh2 the name of the target mesh * @param m intersection matrix in which to store the result of the intersection */ @@ -360,13 +347,15 @@ namespace INTERP_TEST LOG(1, std::endl << "=== -> intersecting src = " << mesh1path << ", target = " << mesh2path ); LOG(5, "Loading " << mesh1 << " from " << mesh1path); - MESH sMesh(MED_DRIVER, INTERP_TEST::getResourceFile(mesh1path), mesh1); + MCAuto sMeshML=MEDFileUMesh::New(INTERP_TEST::getResourceFile(mesh1path).c_str(),mesh1); + MCAuto sMesh=sMeshML->getMeshAtLevel(0); LOG(5, "Loading " << mesh2 << " from " << mesh2path); - MESH tMesh(MED_DRIVER, INTERP_TEST::getResourceFile(mesh2path), mesh2); + MCAuto tMeshML=MEDFileUMesh::New(INTERP_TEST::getResourceFile(mesh2path).c_str(),mesh2); + MCAuto tMesh=tMeshML->getMeshAtLevel(0); - MEDNormalizedUnstructuredMesh sMesh_wrapper(&sMesh); - MEDNormalizedUnstructuredMesh tMesh_wrapper(&tMesh); + MEDCouplingNormalizedUnstructuredMesh sMesh_wrapper(sMesh); + MEDCouplingNormalizedUnstructuredMesh tMesh_wrapper(tMesh); if (SPACEDIM==2 && MESHDIM==2) { @@ -387,12 +376,12 @@ namespace INTERP_TEST } else { - throw MEDEXCEPTION("Wrong dimensions"); + throw INTERP_KERNEL::Exception("Wrong dimensions"); } // if reflexive, check volumes if(strcmp(mesh1path,mesh2path) == 0) { - const bool row_and_col_sums_ok = testVolumes(m, sMesh, tMesh); + const bool row_and_col_sums_ok = testVolumes(m, *sMesh, *tMesh); CPPUNIT_ASSERT_EQUAL_MESSAGE("Row or column sums incorrect", true, row_and_col_sums_ok); const bool is_diagonal =testDiagonal(m); CPPUNIT_ASSERT_EQUAL_MESSAGE("Self intersection matrix is not diagonal", true, is_diagonal); @@ -408,12 +397,12 @@ namespace INTERP_TEST * it will be confirmed that the intersection matrix is diagonal, otherwise the intersection matrices will be * calculated once which each mesh as source mesh, and it will be verified that the they are each others' transpose. * - * @param mesh1path the path to the file containing the source mesh, relative to {$MED_ROOT_DIR}/share/salome/resources/med/ + * @param mesh1path the path to the file containing the source mesh, relative to {$MEDCOUPLING_ROOT_DIR}/share/resources/med/ * @param mesh1 the name of the source mesh - * @param mesh2path the path to the file containing the target mesh, relative to {$MED_ROOT_DIR}/share/salome/resources/med/ + * @param mesh2path the path to the file containing the target mesh, relative to {$MEDCOUPLING_ROOT_DIR}/share/resources/med/ * @param mesh2 the name of the target mesh * @param correctVol the total volume of the intersection of the two meshes - * @param prec maximum relative error to be tolerated in volume comparisions + * @param prec maximum relative error to be tolerated in volume comparisons * @param doubleTest if false, only the test with mesh 1 as the source mesh and mesh 2 as the target mesh will be performed * */ @@ -431,7 +420,7 @@ namespace INTERP_TEST IntersectionMatrix matrix1; calcIntersectionMatrix(mesh1path, mesh1, mesh2path, mesh2, matrix1); -#if LOG_LEVEL >= 2 +#if LOG_LEVEL >= 2 dumpIntersectionMatrix(matrix1); #endif @@ -452,7 +441,7 @@ namespace INTERP_TEST else { IntersectionMatrix matrix2; - calcIntersectionMatrix(mesh2path, mesh2, mesh1path, mesh1, matrix2); + calcIntersectionMatrix(mesh2path, mesh2, mesh1path, mesh1, matrix2); #if LOG_LEVEL >= 2 dumpIntersectionMatrix(matrix2); @@ -471,23 +460,23 @@ namespace INTERP_TEST /** * Utility method used to facilitate the call to intersect meshes. - * It calls intersectMeshes, using "mesh1.med" as file name for the mesh with name "mesh1" and + * It calls intersectMeshes, using "mesh1.med" as file name for the mesh with name "mesh1" and * "mesh2.med" as file name for the mesh with name "mesh2". The rest of the arguments are passed * along as they are. * * @param mesh1 the name of the source mesh * @param mesh2 the name of the target mesh * @param correctVol the total volume of the intersection of the two meshes - * @param prec maximum relative error to be tolerated in volume comparisions + * @param prec maximum relative error to be tolerated in volume comparisons * @param doubleTest if false, only the test with mesh 1 as the source mesh and mesh 2 as the target mesh will be performed * */ template void MeshTestToolkit::intersectMeshes(const char* mesh1, const char* mesh2, const double correctVol, const double prec, bool doubleTest) const { - const string path1 = string(mesh1) + string(".med"); + const std::string path1 = std::string(mesh1) + std::string(".med"); std::cout << "here :" << path1 << std::endl; - const string path2 = string(mesh2) + string(".med"); + const std::string path2 = std::string(mesh2) + std::string(".med"); intersectMeshes(path1.c_str(), mesh1, path2.c_str(), mesh2, correctVol, prec, doubleTest); }