Salome HOME
Adding support for int64 field in basic api
[tools/medcoupling.git] / src / MEDLoader / MEDFileMesh.cxx
index f3d05fa5e02d073d938f7c4044c88e2dd1cfda67..9ca7784721530ddd24eb82f27bfdf51e4963a183 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2020  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
@@ -35,6 +35,7 @@
 #include <limits>
 #include <cmath>
 
+// From MEDLOader.cxx TU
 extern med_geometry_type                 typmai[MED_N_CELL_FIXED_GEO];
 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
 extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
@@ -695,10 +696,10 @@ void MEDFileMesh::removeGroupAtLevel(int meshDimRelToMaxExt, const std::string&
   if(idsToKill->empty())
     return ;
   std::vector<std::string> newFamsOnGrp;
-  for(std::vector<std::string>::const_iterator it=famsOnGrp.begin();it!=famsOnGrp.end();it++)
+  for(std::vector<std::string>::const_iterator itt=famsOnGrp.begin();itt!=famsOnGrp.end();itt++)
     {
-      if(!idsToKill->presenceOfValue(getFamilyId(*it)))
-         newFamsOnGrp.push_back(*it);
+      if(!idsToKill->presenceOfValue(getFamilyId(*itt)))
+         newFamsOnGrp.push_back(*itt);
     }
   (*it).second=newFamsOnGrp;
 }
@@ -859,7 +860,7 @@ void MEDFileMesh::rearrangeFamilies()
       {
           fams=getFamilyFieldAtLevel(*it);
       }
-      catch(INTERP_KERNEL::Exception& e) { }
+      catch(INTERP_KERNEL::Exception& ) { }
       if(!fams)
         continue;
       std::vector<bool> v(fams->getNumberOfTuples(),false);
@@ -942,7 +943,7 @@ void MEDFileMesh::zipFamilies()
             {
               fams=getFamilyFieldAtLevel(*it);
             }
-          catch(INTERP_KERNEL::Exception& e) { }
+          catch(INTERP_KERNEL::Exception& ) { }
           if(!fams)
             continue;
           MCAuto<DataArrayIdType> idsToModif(fams->findIdsEqualList(famIdsSubstSession.second.data(),famIdsSubstSession.second.data()+famIdsSubstSession.second.size()));
@@ -2091,14 +2092,14 @@ DataArrayIdType *MEDFileMesh::getNodeGroupsArr(const std::vector<std::string>& g
 }
 
 /*!
- * Returns ids of nodes contained in a given group.
- *  \param [in] grp - the name of the group of interest.
+ * Returns ids of nodes contained in a given family.
+ *  \param [in] fam - the name of the family of interest.
  *  \param [in] renum - if \c true, the optional numbers of nodes, if available, are
  *          returned instead of ids. 
  *  \return DataArrayIdType * - a new instance of DataArrayIdType holding either ids or
- *          numbers, if available and required, of nodes of the group. The caller
+ *          numbers, if available and required, of nodes of the family. The caller
  *          is to delete this array using decrRef() as it is no more needed. 
- *  \throw If the name of a nonexistent group is specified.
+ *  \throw If the name of a nonexistent family is specified.
  *  \throw If the family field is missing for nodes.
  */
 DataArrayIdType *MEDFileMesh::getNodeFamilyArr(const std::string& fam, bool renum) const
@@ -2241,7 +2242,7 @@ void MEDFileMesh::TranslateFamilyIds(mcIdType offset, DataArrayIdType *famArr, s
     {
       if(offset<0)
         std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::negate<mcIdType>());
-      std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus<mcIdType>(),offset));
+      std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind(std::plus<mcIdType>(),std::placeholders::_1,offset));
     }
 }
 
@@ -2454,7 +2455,7 @@ MEDFileUMesh *MEDFileUMesh::New()
  * \param [in] fileName - the name of the file.
  * \param [in] mName - the name of the mesh to be read.
  * \param [in] types - the list of the geo types of which some part will be taken. A geometric type in \a types must appear only once at most.
- * \param [in] slicPerType - an array of size 3 times larger than \a types that specifies for each type in \a types (in the same order) resp the start, the stop and the step.
+ * \param [in] slicPerTyp - an array of size 3 times larger than \a types that specifies for each type in \a types (in the same order) resp the start, the stop and the step.
  * \param [in] dt - the iteration, that is to say the first element of the pair that locates the asked time step.
  * \param [in] it - the order, that is to say the second element of the pair that locates the asked time step.
  * \param [in] mrs - the request for what to be loaded.
@@ -2478,6 +2479,33 @@ MEDFileUMesh *MEDFileUMesh::LoadPartOf(med_idt fid, const std::string& mName, co
   return ret.retn();
 }
 
+/*!
+ * This method is an helper to load only consecutive nodes chunk of data of MED file pointed by \a fileName.
+ * Consecutive chunk is specified classicaly by start (included) stop (excluded) format with \a startNodeId and \a stopNodeId respectively.
+ * This method returns 5 elements.
+ * 
+ * \param [in] fileName - Name of file nodes to be read of.
+ * \param [in] mName - Name of the mesh inside file pointed be \a fileName nodes to be read of.
+ * \param [in] dt - Time iteration inside file pointed be \a fileName nodes to be read of.
+ * \param [in] it - Time order inside file pointed be \a fileName nodes to be read of.
+ * \param [in] infosOnComp - Components info of nodes to be read of. The size of string vector should be equal to space dimension of mesh to be read.
+ * \param [in] startNodeId - Start Node Id (included) of chunk of data to be read
+ * \param [in] stopNodeId - Start Node Id (included) of chunk of data to be read
+ * \param [out] coords - output coordinates of requested chunk (DataArrayDouble)
+ * \param [out] partCoords - output PartDefinition object of chunk
+ * \param [out] famCoords - output family id field of requested chunk (DataArrayIdType)
+ * \param [out] numCoords - output num id field of requested chunk (DataArrayIdType)
+ * \param [out] nameCoords - output names on nodes of requested chunk (DataArrayAsciiChar)
+ * 
+ * \sa MEDLoaderUMesh::LoadPartOf
+ */
+void MEDFileUMesh::LoadPartCoords(const std::string& fileName, const std::string& mName, int dt, int it, const std::vector<std::string>& infosOnComp, mcIdType startNodeId, mcIdType stopNodeId,
+MCAuto<DataArrayDouble>& coords, MCAuto<PartDefinition>& partCoords, MCAuto<DataArrayIdType>& famCoords, MCAuto<DataArrayIdType>& numCoords, MCAuto<DataArrayAsciiChar>& nameCoords)
+{
+  MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
+  MEDFileUMeshL2::LoadPartCoords(fid,infosOnComp,mName,dt,it,startNodeId,stopNodeId,coords,partCoords,famCoords,numCoords,nameCoords);
+}
+
 std::size_t MEDFileUMesh::getHeapMemorySizeWithoutChildren() const
 {
   std::size_t ret(MEDFileMesh::getHeapMemorySizeWithoutChildren());
@@ -3007,7 +3035,6 @@ void MEDFileUMesh::dispatchLoadedPart(med_idt fid, const MEDFileUMeshL2& loaderl
   if(!mrs || mrs->isGlobalNodeNumFieldReading())
     _global_num_coords=loaderl2.getCoordsGlobalNum();
   _part_coords=loaderl2.getPartDefOfCoo();
-  computeRevNum();
 }
 
 MEDFileUMesh::~MEDFileUMesh()
@@ -3681,7 +3708,7 @@ DataArrayIdType *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std:
  * valid**. This is a feature, because MEDLoader does not create cells that do not exist! 
  * To build a valid MEDCouplingUMesh from the returned one in this case,
  * call MEDCouplingUMesh::Build0DMeshFromCoords().
- *  \param [in] meshDimRelToMax - the relative dimension of interest.
+ *  \param [in] meshDimRelToMaxExt - the relative dimension of interest.
  *  \param [in] renum - if \c true, the returned mesh is permuted according to the
  *          optional numbers of mesh entities.
  *  \return MEDCouplingUMesh * - a pointer to MEDCouplingUMesh that the caller is to
@@ -5458,7 +5485,6 @@ void MEDFileUMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayIdType *ren
         throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumFieldArr : the coordinates have not been set !");
       renumArr->checkNbOfTuplesAndComp(_coords->getNumberOfTuples(),1,"MEDFileUMesh::setRenumArr : Problem in size of node numbering arr ! ");
       _num_coords.takeRef(renumArr);
-      computeRevNum();
       return ;
     }
   if(meshDimRelToMaxExt>1)
@@ -6033,6 +6059,7 @@ void MEDFileStructuredMesh::setNameFieldAtLevel(int meshDimRelToMaxExt, DataArra
         mcIdType nbCells=mesh->getNumberOfCellsOfSubLevelMesh();
         nameArr->checkNbOfTuplesAndComp(nbCells,MED_SNAME_SIZE,"MEDFileStructuredMesh::setNameFieldAtLevel : Problem in size of names arr ! Mismatch with number of faces of mesh !");
         _names_faces=nameArr;
+        break;
       }
     default:
       throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setNameFieldAtLevel : Only available for levels 0 or 1 or -1 !");
@@ -6387,24 +6414,37 @@ MEDCouplingMesh *MEDFileStructuredMesh::getMeshAtLevel(int meshDimRelToMax, bool
   }
 }
 
+/*!
+ * Returns all relative mesh levels (**excluding nodes**) where given families are defined.
+ * To include nodes, call getFamsNonEmptyLevelsExt() method.
+ *  \param [in] fams - the name of the family of interest.
+ *  \return std::vector<int> - a sequence of the relative dimensions.
+ */
 std::vector<mcIdType> MEDFileStructuredMesh::getFamsNonEmptyLevels(const std::vector<std::string>& fams) const
 {
-  std::vector<mcIdType> ret;
+  std::vector<mcIdType> lvls;
+  std::vector<mcIdType> famIds(getFamiliesIds(fams));
   const DataArrayIdType *famCells(_fam_cells),*famFaces(_fam_faces);
-  if(famCells && famCells->presenceOfValue(ret))
-    ret.push_back(0);
-  if(famFaces && famFaces->presenceOfValue(ret))
-    ret.push_back(-1);
-  return ret;  
+  if(famCells && famCells->presenceOfValue(famIds))
+    lvls.push_back(0);
+  if(famFaces && famFaces->presenceOfValue(famIds))
+    lvls.push_back(-1);
+  return lvls;
 }
 
+/*!
+ * Returns all relative mesh levels (including nodes) where given families are defined.
+ *  \param [in] fams - the names of the families of interest.
+ *  \return std::vector<int> - a sequence of the relative dimensions.
+ */
 std::vector<mcIdType> MEDFileStructuredMesh::getFamsNonEmptyLevelsExt(const std::vector<std::string>& fams) const
 {
-  std::vector<mcIdType> ret(getFamsNonEmptyLevels(fams));
+  std::vector<mcIdType> lvls(getFamsNonEmptyLevels(fams));
+  std::vector<mcIdType> famIds(getFamiliesIds(fams));
   const DataArrayIdType *famNodes(_fam_nodes);
-  if(famNodes && famNodes->presenceOfValue(ret))
-    ret.push_back(1);
-  return ret;  
+  if(famNodes && famNodes->presenceOfValue(famIds))
+    lvls.push_back(1);
+  return lvls;
 }
 
 /*!
@@ -7102,10 +7142,17 @@ MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::deepCopy() const
 int MEDFileCurveLinearMesh::getMeshDimension() const
 {
   if(!((const MEDCouplingCurveLinearMesh*)_clmesh))
-    throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::getMeshDimension : unable to get meshdimension because no mesh set !");
+    throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::getMeshDimension : unable to get mesh dimension because no mesh set !");
   return _clmesh->getMeshDimension();
 }
 
+int MEDFileCurveLinearMesh::getSpaceDimension() const
+{
+  if(!((const MEDCouplingCurveLinearMesh*)_clmesh))
+    throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::getMeshDimension : unable to get space dimension because no mesh set !");
+  return _clmesh->getSpaceDimension();
+}
+
 std::string MEDFileCurveLinearMesh::simpleRepr() const
 {
   return MEDFileStructuredMesh::simpleRepr();