Back to index

salome-med  6.5.0
Functions
TestingUtils.hxx File Reference
#include "Interpolation3D.hxx"
#include "MEDMEM_Mesh.hxx"
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#include "VectorUtils.hxx"
#include "Log.hxx"

Go to the source code of this file.

Functions

double sumVolume (const IntersectionMatrix &m)
void dumpIntersectionMatrix (const IntersectionMatrix &m)
std::pair< int, int > countNumberOfMatrixEntries (const IntersectionMatrix &m)
void calcIntersectionMatrix (const char *mesh1path, const char *mesh1, const char *mesh2path, const char *mesh2, IntersectionMatrix &m)

Function Documentation

void calcIntersectionMatrix ( const char *  mesh1path,
const char *  mesh1,
const char *  mesh2path,
const char *  mesh2,
IntersectionMatrix m 
)

Definition at line 207 of file TestingUtils.hxx.

{
  const std::string dataBaseDir = getenv("MED_ROOT_DIR");
  const std::string dataDir = dataBaseDir + "/share/salome/resources/med/";

  LOG(1, std::endl << "=== -> intersecting src = " << mesh1 << ", target = " << mesh2 );

  LOG(5, "Loading " << mesh1 << " from " << mesh1path);
  const MESH sMesh(MED_DRIVER, dataDir+mesh1path, mesh1);
  const int numSrcElems = sMesh.getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS);
  LOG(1, "Source mesh has " << numSrcElems << " elements");


  LOG(5, "Loading " << mesh2 << " from " << mesh2path);
  const MESH tMesh(MED_DRIVER, dataDir+mesh2path, mesh2);
  const int numTargetElems = tMesh.getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS);

  LOG(1, "Target mesh has " << numTargetElems << " elements");

  Interpolation3D* interpolator = new Interpolation3D();

  m = interpolator->interpolateMeshes(sMesh, tMesh);

  std::pair<int, int> eff = countNumberOfMatrixEntries(m);
  LOG(1, eff.first << " of " << numTargetElems * numSrcElems << " intersections calculated : ratio = " 
      << double(eff.first) / double(numTargetElems * numSrcElems));
  LOG(1, eff.second << " non-zero elements of " << eff.first << " total : filter efficiency = " 
      << double(eff.second) / double(eff.first));

  delete interpolator;

  LOG(1, "Intersection calculation done. " << std::endl );
  
}

Here is the call graph for this function:

std::pair<int,int> countNumberOfMatrixEntries ( const IntersectionMatrix m)

Definition at line 187 of file TestingUtils.hxx.

{
  
  int numElems = 0;
  int numNonZero = 0;
  for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter)
    {
      numElems += iter->size();
      for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
        {
          if(!epsilonEqual(iter2->second, 0.0, VOL_PREC))
            {
              ++numNonZero;
            }
        }
    }
  return std::make_pair(numElems, numNonZero);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 170 of file TestingUtils.hxx.

{
  int i = 0;
  std::cout << "Intersection matrix is " << std::endl;
  for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter)
    {
      for(std::map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
        {
    
          std::cout << "V(" << i << ", " << iter2->first << ") = " << iter2->second << std::endl;
    
        }
      ++i;
    }
  std::cout << "Sum of volumes = " << sumVolume(m) << std::endl;
}

Here is the call graph for this function:

double sumVolume ( const IntersectionMatrix m)

Definition at line 47 of file TestingUtils.hxx.

{
  
  vector<double> volumes;
  for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter)
    {
      for(std::map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
        {
          volumes.push_back(iter2->second);
          //    vol += std::fabs(iter2->second);
        }
    }
  
  // sum in ascending order to avoid rounding errors

  sort(volumes.begin(), volumes.end());
  const double vol = accumulate(volumes.begin(), volumes.end(), 0.0);

  return vol;
}

Here is the caller graph for this function: