Back to index

salome-med  6.5.0
PerfTest.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 "Interpolation3D.hxx"
00021 #include "Interpolation3D.txx"
00022 #include "MeshTestToolkit.txx"
00023 #include "Log.hxx"
00024 #include "VectorUtils.hxx"
00025 #include "TestInterpKernelUtils.hxx"
00026 
00027 #include "MEDMEM_Mesh.hxx"
00028 #include "MEDNormalizedUnstructuredMesh.hxx"
00029 
00030 #include <cassert>
00031 #include <string>
00032 
00033 using namespace MEDMEM;
00034 using namespace MED_EN;
00035 
00046 namespace INTERP_TEST
00047 {
00052   class PerfTestToolkit : public MeshTestToolkit<3,3>
00053   {
00054     
00055   public:
00056 
00069     void calcIntersectionMatrix(const char* mesh1path, const char* mesh1, const char* mesh2path, const char* mesh2, IntersectionMatrix& m) 
00070     {
00071       LOG(1, std::endl << "=== -> intersecting src = " << mesh1 << ", target = " << mesh2 );
00072       
00073       LOG(5, "Loading " << mesh1 << " from " << mesh1path);
00074       const MESH sMesh(MED_DRIVER, INTERP_TEST::getResourceFile(mesh1path), mesh1);
00075     
00076     
00077       LOG(5, "Loading " << mesh2 << " from " << mesh2path);
00078       const MESH tMesh(MED_DRIVER, INTERP_TEST::getResourceFile(mesh2path), mesh2);
00079       
00080       MEDNormalizedUnstructuredMesh<3,3> sMesh_wrapper(&sMesh);
00081       MEDNormalizedUnstructuredMesh<3,3> tMesh_wrapper(&tMesh);
00082       
00083       Interpolation3D interpolator;
00084       interpolator.interpolateMeshes(sMesh_wrapper, tMesh_wrapper,m,"P0P0");
00085     
00086       std::pair<int, int> eff = countNumberOfMatrixEntries(m);
00087       LOG(1, eff.first << " of " << numTargetElems * numSrcElems << " intersections calculated : ratio = " 
00088           << double(eff.first) / double(numTargetElems * numSrcElems));
00089       LOG(1, eff.second << " non-zero elements of " << eff.first << " total : filter efficiency = " 
00090           << double(eff.second) / double(eff.first));
00091     
00092       LOG(1, "Intersection calculation done. " << std::endl );
00093     
00094     }
00095 
00103     std::pair<int,int> countNumberOfMatrixEntries(const IntersectionMatrix& m)
00104     {
00105       
00106       int numElems = 0;
00107       int numNonZero = 0;
00108       for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter)
00109         {
00110           numElems += iter->size();
00111           for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
00112             {
00113               if(!INTERP_KERNEL::epsilonEqual(iter2->second, 0.0, VOL_PREC))
00114                 {
00115                   ++numNonZero;
00116                 }
00117             }
00118         }
00119       return std::make_pair(numElems, numNonZero);
00120     }
00121     
00122   };
00123 }
00124 
00133 int main(int argc, char** argv)
00134 {
00135   using INTERP_TEST::PerfTestToolkit;
00136 
00137   assert(argc == 3);
00138   
00139   // load meshes
00140   const string mesh1 = argv[1];
00141   const string mesh2 = argv[2];
00142 
00143   const string mesh1path = mesh1 + ".med";
00144   const string mesh2path = mesh2 + ".med";
00145 
00146   IntersectionMatrix m;
00147 
00148   PerfTestToolkit testTools;
00149 
00150   testTools.calcIntersectionMatrix(mesh1path.c_str(), mesh1.c_str(), mesh2path.c_str(), mesh2.c_str(), m);
00151 
00152   testTools.dumpIntersectionMatrix(m);
00153     
00154   return 0;
00155 
00156 }
00157