Salome HOME
improve error message.
[tools/medcoupling.git] / src / MEDLoader / MEDFileMeshLL.cxx
index 79ea1141a59ee6dcff2c41fcd3086f77aca057fb..39c409025837cd97ad314850edcf0ff7f8ccc967 100644 (file)
@@ -535,13 +535,25 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *m
     {
       for(int i=0;i<sz;i++)
         fams[i]=v[i]->getFam();
-      _fam=DataArrayInt::Aggregate(fams);
+      if(sz!=1)
+        _fam=DataArrayInt::Aggregate(fams);
+      else
+        {
+          fams[0]->incrRef();
+          _fam=const_cast<DataArrayInt *>(fams[0]);
+        }
     }
   if(l2.isNumDefinedOnLev(id))
     {
       for(int i=0;i<sz;i++)
         nums[i]=v[i]->getNum();
-      _num=DataArrayInt::Aggregate(nums);
+      if(sz!=1)
+        _num=DataArrayInt::Aggregate(nums);
+      else
+        {
+          nums[0]->incrRef();
+          _num=const_cast<DataArrayInt *>(nums[0]);
+        }
       computeRevNum();
     }
   if(l2.isNamesDefinedOnLev(id))
@@ -552,6 +564,13 @@ MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *m
     }
 }
 
+MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m):_m(this)
+{
+  std::vector< const MEDCoupling1GTUMesh * > v(1);
+  v[0]=m;
+  assignParts(v);
+}
+
 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
 {
   assignMesh(m,true);
@@ -691,8 +710,24 @@ void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
       m->incrRef();
       _m_by_types.assignUMesh(m);
     }
+  assignCommonPart();
+}
+
+void MEDFileUMeshSplitL1::forceComputationOfParts() const
+{
+  _m_by_types.forceComputationOfPartsFromUMesh();
+}
+
+void MEDFileUMeshSplitL1::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
+{
+  _m_by_types.assignParts(mParts);
+  assignCommonPart();
+}
+
+void MEDFileUMeshSplitL1::assignCommonPart()
+{
   _fam=DataArrayInt::New();
-  _fam->alloc(m->getNumberOfCells(),1);
+  _fam->alloc(_m_by_types.getSize(),1);
   _fam->fillWithValue(0);
 }
 
@@ -747,6 +782,11 @@ DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int
   return da.retn();
 }
 
+std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshSplitL1::getGeoTypes() const
+{
+  return _m_by_types.getGeoTypes();
+}
+
 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
 {
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp;
@@ -757,6 +797,26 @@ MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
   return tmp.retn();
 }
 
+DataArrayInt *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
+{
+  const DataArrayInt *fam(_fam);
+  if(!fam)
+    return 0;
+  int start(0),stop(0);
+  _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
+  return fam->selectByTupleId2(start,stop,1);
+}
+
+DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
+{
+  const DataArrayInt *num(_num);
+  if(!num)
+    return 0;
+  int start(0),stop(0);
+  _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
+  return num->selectByTupleId2(start,stop,1);
+}
+
 DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
 {
   if((DataArrayInt *)_fam)
@@ -991,6 +1051,20 @@ MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
   return _m;
 }
 
+std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::getGeoTypes() const
+{
+  if(_mp_time>=_m_time)
+    {
+      std::size_t sz(_m_parts.size());
+      std::vector<INTERP_KERNEL::NormalizedCellType> ret(sz);
+      for(std::size_t i=0;i<sz;i++)
+        ret[i]=_m_parts[i]->getCellModelEnum();
+      return ret;
+    }
+  else
+    return _m->getAllGeoTypesSorted();
+}
+
 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getPartsWithoutComputation() const
 {
   if(_mp_time<_m_time)
@@ -1026,6 +1100,27 @@ MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::getPartWithoutComputation(INT
   throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
 }
 
+void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const
+{
+  start=0; stop=0;
+  std::vector<MEDCoupling1GTUMesh *> v(getPartsWithoutComputation());
+  std::size_t sz(v.size());
+  for(std::size_t i=0;i<sz;i++)
+    {
+      if(v[i])
+        {
+          if(v[i]->getCellModelEnum()==gt)
+            {
+              stop=start+v[i]->getNumberOfCells();
+              return;
+            }
+          else
+            start+=v[i]->getNumberOfCells();
+        }
+    }
+  throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !");
+}
+
 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
 {
   const MEDCouplingUMesh *m(_m);