Salome HOME
Copyright update 2021
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingGaussLocalization.cxx
index e5a5a413c001768ce071bbc6d8253b671f8561c1..5075612a1f08448778d619643f3e2f4dc91e4e92 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2021  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
@@ -34,29 +34,18 @@ using namespace MEDCoupling;
 
 MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
                                                            const std::vector<double>& gsCoo, const std::vector<double>& w)
-try:_type(type),_ref_coord(refCoo),_gauss_coord(gsCoo),_weight(w)
+:_type(type),_ref_coord(refCoo),_gauss_coord(gsCoo),_weight(w)
 {
+  // Will potentially throw (and then release memory for above objects _ref_coord etc ...)
   checkConsistencyLight();
 }
-catch(INTERP_KERNEL::Exception& e)
-{
-    _type=INTERP_KERNEL::NORM_ERROR;
-    _ref_coord.clear();
-    _gauss_coord.clear();
-    _weight.clear();
-    throw e;
-}
 
 MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType typ)
-try:_type(typ)
+:_type(typ)
 {
+  // Will potentially throw
   INTERP_KERNEL::CellModel::GetCellModel(_type);
 }
-catch(INTERP_KERNEL::Exception& e)
-{
-    _type=INTERP_KERNEL::NORM_ERROR;
-    throw e;
-}
 
 void MEDCouplingGaussLocalization::setType(INTERP_KERNEL::NormalizedCellType typ)
 {
@@ -71,7 +60,7 @@ void MEDCouplingGaussLocalization::checkConsistencyLight() const
   int dim=cm.getDimension();
   if(!cm.isDynamic())
     {
-      if((int)_ref_coord.size()!=nbNodes*dim)
+      if(ToIdType(_ref_coord.size())!=nbNodes*dim)
         {
           std::ostringstream oss; oss << "Invalid size of refCoo : expecting to be : " << nbNodes << " (nbNodePerCell) * " << dim << " (dim) !";
           throw INTERP_KERNEL::Exception(oss.str().c_str());
@@ -160,9 +149,9 @@ double MEDCouplingGaussLocalization::getWeight(int gaussPtIdInCell, double newVa
  * push at the end of tinyInfo its basic serialization info. The size of pushed data is always the same.
  * @param tinyInfo inout parameter.
  */
-void MEDCouplingGaussLocalization::pushTinySerializationIntInfo(std::vector<int>& tinyInfo) const
+void MEDCouplingGaussLocalization::pushTinySerializationIntInfo(std::vector<mcIdType>& tinyInfo) const
 {
-  tinyInfo.push_back((int)_type);
+  tinyInfo.push_back(ToIdType(_type));
   tinyInfo.push_back(getNumberOfPtsInRefCell());
   tinyInfo.push_back(getNumberOfGaussPt());
 }
@@ -212,23 +201,22 @@ MCAuto<DataArrayDouble> MEDCouplingGaussLocalization::localizePtsInRefCooForEach
   ptsInRefCoo->checkAllocated();
   mesh->checkConsistencyLight();
   //
-  int nbCells(mesh->getNumberOfCells());
+  mcIdType nbCells=mesh->getNumberOfCells();
   const double *coords(mesh->getCoords()->begin());
-  const int *connI(mesh->getNodalConnectivityIndex()->begin()),*conn(mesh->getNodalConnectivity()->begin());
+  const mcIdType *connI(mesh->getNodalConnectivityIndex()->begin()),*conn(mesh->getNodalConnectivity()->begin());
   //
-  int nbPts(ptsInRefCoo->getNumberOfTuples());
+  mcIdType nbPts(ptsInRefCoo->getNumberOfTuples());
   INTERP_KERNEL::NormalizedCellType typ(getType());
   int dim(INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension()),outDim(mesh->getSpaceDimension());
   MCAuto<DataArrayDouble> ret(DataArrayDouble::New());
   ret->alloc(nbPts*nbCells,outDim);
   double *retPtr(ret->getPointer());
-  if(dim!=(int)ptsInRefCoo->getNumberOfComponents())
+  if(dim!=ToIdType(ptsInRefCoo->getNumberOfComponents()))
     throw INTERP_KERNEL::Exception("MEDCouplingGaussLocalization::localizePtsInRefCooForEachCell : number of components of input coo is not equal to dim of element !");
-  const std::vector<double>& wg(getWeights());
   INTERP_KERNEL::GaussCoords calculator;
   calculator.addGaussInfo(typ,dim, ptsInRefCoo->begin(),nbPts,&_ref_coord[0],getNumberOfPtsInRefCell());
   //
-  for(int i=0;i<nbCells;i++,retPtr+=nbPts*outDim)
+  for(mcIdType i=0;i<nbCells;i++,retPtr+=nbPts*outDim)
     calculator.calculateCoords(getType(),coords,outDim,conn+connI[i]+1,retPtr);
   return ret;
 }
@@ -240,13 +228,13 @@ MCAuto<MEDCouplingUMesh> MEDCouplingGaussLocalization::buildRefCell() const
 {
   MCAuto<DataArrayDouble> coo(DataArrayDouble::New());
   const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(getType()));
-  if(getDimension()!=(int)cm.getDimension())
+  if(getDimension()!=ToIdType(cm.getDimension()))
     throw INTERP_KERNEL::Exception("BuildRefCell : dimension mistmatch !");
   coo->alloc(cm.getNumberOfNodes(),getDimension());
   std::copy(_ref_coord.begin(),_ref_coord.end(),coo->getPointer());
   MCAuto<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New("",getType()));
   ret->setCoords(coo);
-  MCAuto<DataArrayInt> conn(DataArrayInt::New());
+  MCAuto<DataArrayIdType> conn(DataArrayIdType::New());
   conn->alloc(cm.getNumberOfNodes(),1);
   conn->iota();
   ret->setNodalConnectivity(conn);
@@ -299,17 +287,17 @@ void MEDCouplingGaussLocalization::setWeights(const std::vector<double>& w)
 /*!
  * The format of 'tinyData' parameter is the same than pushed in method MEDCouplingGaussLocalization::pushTinySerializationIntInfo.
  */
-MEDCouplingGaussLocalization MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(int dim, const std::vector<int>& tinyData)
+MEDCouplingGaussLocalization MEDCouplingGaussLocalization::BuildNewInstanceFromTinyInfo(mcIdType dim, const std::vector<mcIdType>& tinyData)
 {
   std::vector<double> v1(dim*tinyData[1]),v2(dim*tinyData[2]),v3(tinyData[2]);
   return MEDCouplingGaussLocalization((INTERP_KERNEL::NormalizedCellType)tinyData[0],v1,v2,v3);
 }
 
-int MEDCouplingGaussLocalization::checkCoherencyOfRequest(int gaussPtIdInCell, int comp) const
+int MEDCouplingGaussLocalization::checkCoherencyOfRequest(mcIdType gaussPtIdInCell, int comp) const
 {
   const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_type);
   int dim=cm.getDimension();
-  int nbGsPts=getNumberOfGaussPt();
+  mcIdType nbGsPts=getNumberOfGaussPt();
   if(gaussPtIdInCell<0 || gaussPtIdInCell>=nbGsPts)
     throw INTERP_KERNEL::Exception("gaussPtIdInCell specified is invalid : must be in [0:nbGsPts) !");
   if(comp<0 || comp>=dim)
@@ -324,6 +312,6 @@ bool MEDCouplingGaussLocalization::AreAlmostEqual(const std::vector<double>& v1,
     return false;
   std::vector<double> tmp(sz);
   std::transform(v1.begin(),v1.end(),v2.begin(),tmp.begin(),std::minus<double>());
-  std::transform(tmp.begin(),tmp.end(),tmp.begin(),std::ptr_fun<double,double>(fabs));
+  std::transform(tmp.begin(),tmp.end(),tmp.begin(),[](double c){return fabs(c);});
   return *std::max_element(tmp.begin(),tmp.end())<eps;
 }