return ret;
}
-std::vector<const BigMemoryObject *> MEDFileMesh::getDirectChildren() const
+std::vector<const BigMemoryObject *> MEDFileMesh::getDirectChildrenWithNull() const
{
return std::vector<const BigMemoryObject *>();
}
return new MEDFileUMesh;
}
+/*!
+ * This method loads from file with name \a fileName the mesh called \a mName as New does. The difference is that
+ * here only a part of cells contained in the file will be loaded. The selection of cell is specified using the two consecutive parameters
+ * \a types and \a slicPerTyp. This method allows to load from a mesh (typically huge) in a MED file a part of cells of that mesh.
+ * The part of cells is specified using triplet (start,stop,step) for each geometric type. Only nodes lying on selected cells will be loaded to reduce
+ * at most the memory consumtion.
+ *
+ * \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] 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.
+ * \return MEDFileUMesh * - a new instance of MEDFileUMesh. The caller is to delete this mesh using decrRef() as it is no more needed.
+ */
+MEDFileUMesh *MEDFileUMesh::LoadPartOf(const std::string& fileName, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
+ MEDFileUtilities::CheckFileForRead(fileName);
+ MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
+ return MEDFileUMesh::LoadPartOf(fid,mName,types,slicPerTyp,dt,it,mrs);
+}
+
+/*!
+ * Please refer to the other MEDFileUMesh::LoadPartOf method that has the same semantic and the same parameter (excepted the first).
+ * This method is \b NOT wrapped into python.
+ */
+MEDFileUMesh *MEDFileUMesh::LoadPartOf(med_idt fid, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(MEDFileUMesh::New());
+ ret->loadPartUMeshFromFile(fid,mName,types,slicPerTyp,dt,it,mrs);
+ return ret.retn();
+}
+
std::size_t MEDFileUMesh::getHeapMemorySizeWithoutChildren() const
{
std::size_t ret(MEDFileMesh::getHeapMemorySizeWithoutChildren());
return ret;
}
-std::vector<const BigMemoryObject *> MEDFileUMesh::getDirectChildren() const
+std::vector<const BigMemoryObject *> MEDFileUMesh::getDirectChildrenWithNull() const
{
- std::vector<const BigMemoryObject *> ret(MEDFileMesh::getDirectChildren());
- if((const DataArrayDouble*)_coords)
- ret.push_back((const DataArrayDouble*)_coords);
- if((const DataArrayInt *)_fam_coords)
- ret.push_back((const DataArrayInt *)_fam_coords);
- if((const DataArrayInt *)_num_coords)
- ret.push_back((const DataArrayInt *)_num_coords);
- if((const DataArrayInt *)_rev_num_coords)
- ret.push_back((const DataArrayInt *)_rev_num_coords);
- if((const DataArrayAsciiChar *)_name_coords)
- ret.push_back((const DataArrayAsciiChar *)_name_coords);
+ std::vector<const BigMemoryObject *> ret(MEDFileMesh::getDirectChildrenWithNull());
+ ret.push_back((const DataArrayDouble*)_coords);
+ ret.push_back((const DataArrayInt *)_fam_coords);
+ ret.push_back((const DataArrayInt *)_num_coords);
+ ret.push_back((const DataArrayInt *)_rev_num_coords);
+ ret.push_back((const DataArrayAsciiChar *)_name_coords);
+ ret.push_back((const PartDefinition *)_part_coords);
for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
- if((const MEDFileUMeshSplitL1*) *it)
- ret.push_back((const MEDFileUMeshSplitL1*) *it);
+ ret.push_back((const MEDFileUMeshSplitL1*) *it);
return ret;
}
throw e;
}
+/*!
+ * This method loads only a part of specified cells (given by range of cell ID per geometric type)
+ * See MEDFileUMesh::LoadPartOf for detailed description.
+ *
+ * \sa loadUMeshFromFile
+ */
+void MEDFileUMesh::loadPartUMeshFromFile(med_idt fid, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
+ MEDFileUMeshL2 loaderl2;
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ int dummy0,dummy1;
+ std::string dummy2;
+ int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2));
+ if(meshType!=UNSTRUCTURED)
+ {
+ std::ostringstream oss; oss << "loadPartUMeshFromFile : Trying to load as unstructured an existing mesh with name '" << mName << "' !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ loaderl2.loadPart(fid,mid,mName,types,slicPerTyp,dt,it,mrs);
+ dispatchLoadedPart(fid,loaderl2,mName,mrs);
+}
+
+/*!
+ * This method loads \b all \b the \b mesh \a mName in the file with \a fid descriptor.
+ *
+ * \sa loadPartUMeshFromFile
+ */
void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
{
MEDFileUMeshL2 loaderl2;
ParaMEDMEM::MEDCouplingMeshType meshType;
int dummy0,dummy1;
std::string dummy2;
- int mid=MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
+ int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2));
if(meshType!=UNSTRUCTURED)
{
std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
loaderl2.loadAll(fid,mid,mName,dt,it,mrs);
+ dispatchLoadedPart(fid,loaderl2,mName,mrs);
+
+}
+
+void MEDFileUMesh::dispatchLoadedPart(med_idt fid, const MEDFileUMeshL2& loaderl2, const std::string& mName, MEDFileMeshReadSelector *mrs)
+{
int lev=loaderl2.getNumberOfLevels();
_ms.resize(lev);
for(int i=0;i<lev;i++)
_num_coords=loaderl2.getCoordsNum();
if(!mrs || mrs->isNodeNameFieldReading())
_name_coords=loaderl2.getCoordsName();
+ _part_coords=loaderl2.getPartDefOfCoo();
computeRevNum();
}
return l1->getNameField();
}
+/*!
+ * This method returns for a specified relative level \a meshDimRelToMaxExt the part effectively read (if the instance is the result of the read of a file).
+ *
+ * \param [in] meshDimRelToMaxExt - the extended relative level for which the part definition is requested.
+ * \param [in] gt - The input geometric type for which the part definition is requested.
+ * \return the part definition owned by \a this. So no need to deallocate the returned instance.
+ */
+const PartDefinition *MEDFileUMesh::getPartDefAtLevel(int meshDimRelToMaxExt, INTERP_KERNEL::NormalizedCellType gt) const
+{
+ if(meshDimRelToMaxExt==1)
+ return _part_coords;
+ const MEDFileUMeshSplitL1 *l1(getMeshAtLevSafe(meshDimRelToMaxExt));
+ return l1->getPartDef(gt);
+}
+
int MEDFileUMesh::getNumberOfNodes() const
{
const DataArrayDouble *coo=_coords;
return sp->extractNumberFieldOnGeoType(gt);
}
+/*!
+ * This method returns for specified geometric type \a gt the relative level to \a this.
+ * If the relative level is empty an exception will be thrown.
+ */
+int MEDFileUMesh::getRelativeLevOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
+{
+ const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(gt);
+ int ret((int)cm.getDimension()-getMeshDimension());
+ getMeshAtLevSafe(ret);//To test that returned value corresponds to a valid level.
+ return ret;
+}
+
const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const
{
if(meshDimRelToMaxExt==1)
return MEDFileMesh::getHeapMemorySizeWithoutChildren();
}
-std::vector<const BigMemoryObject *> MEDFileStructuredMesh::getDirectChildren() const
-{
- std::vector<const BigMemoryObject *> ret(MEDFileMesh::getDirectChildren());
- if((const DataArrayInt *)_fam_nodes)
- ret.push_back((const DataArrayInt *)_fam_nodes);
- if((const DataArrayInt *)_num_nodes)
- ret.push_back((const DataArrayInt *)_num_nodes);
- if((const DataArrayAsciiChar *)_names_nodes)
- ret.push_back((const DataArrayAsciiChar *)_names_nodes);
- if((const DataArrayInt *)_fam_cells)
- ret.push_back((const DataArrayInt *)_fam_cells);
- if((const DataArrayInt *)_num_cells)
- ret.push_back((const DataArrayInt *)_num_cells);
- if((const DataArrayAsciiChar *)_names_cells)
- ret.push_back((const DataArrayAsciiChar *)_names_cells);
- if((const DataArrayInt *)_fam_faces)
- ret.push_back((const DataArrayInt *)_fam_faces);
- if((const DataArrayInt *)_num_faces)
- ret.push_back((const DataArrayInt *)_num_faces);
- if((const DataArrayInt *)_rev_num_nodes)
- ret.push_back((const DataArrayInt *)_rev_num_nodes);
- if((const DataArrayAsciiChar *)_names_faces)
- ret.push_back((const DataArrayAsciiChar *)_names_faces);
- if((const DataArrayInt *)_rev_num_cells)
- ret.push_back((const DataArrayInt *)_rev_num_cells);
+std::vector<const BigMemoryObject *> MEDFileStructuredMesh::getDirectChildrenWithNull() const
+{
+ std::vector<const BigMemoryObject *> ret(MEDFileMesh::getDirectChildrenWithNull());
+ ret.push_back((const DataArrayInt *)_fam_nodes);
+ ret.push_back((const DataArrayInt *)_num_nodes);
+ ret.push_back((const DataArrayAsciiChar *)_names_nodes);
+ ret.push_back((const DataArrayInt *)_fam_cells);
+ ret.push_back((const DataArrayInt *)_num_cells);
+ ret.push_back((const DataArrayAsciiChar *)_names_cells);
+ ret.push_back((const DataArrayInt *)_fam_faces);
+ ret.push_back((const DataArrayInt *)_num_faces);
+ ret.push_back((const DataArrayInt *)_rev_num_nodes);
+ ret.push_back((const DataArrayAsciiChar *)_names_faces);
+ ret.push_back((const DataArrayInt *)_rev_num_cells);
+ ret.push_back((const MEDCoupling1SGTUMesh*)_faces_if_necessary);
return ret;
}
{
if(!m)
throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGenMeshAtLevel : level -1 requested must be non empty to be able to compute unstructured sub mesh !");
- return _faces_if_necessary;
+ buildMinusOneImplicitPartIfNeeded();
+ MEDCouplingMesh *ret(_faces_if_necessary);
+ if(ret)
+ ret->incrRef();
+ return ret;
}
default:
throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support multi level for mesh 0 expected as input !");
const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(getMeshDimension())));
if(cm.getReverseExtrudedType()!=gt)
throw INTERP_KERNEL::Exception(MSG);
- const MEDCouplingStructuredMesh *mcmesh(getStructuredMesh());
- _faces_if_necessary=mcmesh->build1SGTSubLevelMesh();
- return mcmesh->getNumberOfCellsOfSubLevelMesh();
+ buildImplicitPart();
+ return getStructuredMesh()->getNumberOfCellsOfSubLevelMesh();
}
else
{
}
}
+void MEDFileStructuredMesh::buildMinusOneImplicitPartIfNeeded() const
+{
+ const MEDCoupling1SGTUMesh *zeFaceMesh(_faces_if_necessary);
+ if(!zeFaceMesh)
+ buildImplicitPart();
+}
+
+void MEDFileStructuredMesh::buildImplicitPart() const
+{
+ const MEDCouplingStructuredMesh *mcmesh(getStructuredMesh());
+ if(!mcmesh)
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::buildImplicitPart : Unable to build the implicit part of structured mesh because no structured mesh at level 0 defined !");
+ _faces_if_necessary=mcmesh->build1SGTSubLevelMesh();
+}
+
void MEDFileStructuredMesh::releaseImplicitPartIfAny() const
{
_faces_if_necessary=0;
return MEDFileStructuredMesh::getHeapMemorySizeWithoutChildren();
}
-std::vector<const BigMemoryObject *> MEDFileCMesh::getDirectChildren() const
+std::vector<const BigMemoryObject *> MEDFileCMesh::getDirectChildrenWithNull() const
{
- std::vector<const BigMemoryObject *> ret(MEDFileStructuredMesh::getDirectChildren());
- if((const MEDCouplingCMesh *)_cmesh)
- ret.push_back((const MEDCouplingCMesh *)_cmesh);
+ std::vector<const BigMemoryObject *> ret(MEDFileStructuredMesh::getDirectChildrenWithNull());
+ ret.push_back((const MEDCouplingCMesh *)_cmesh);
return ret;
}
return MEDFileStructuredMesh::getHeapMemorySizeWithoutChildren();
}
-std::vector<const BigMemoryObject *> MEDFileCurveLinearMesh::getDirectChildren() const
+std::vector<const BigMemoryObject *> MEDFileCurveLinearMesh::getDirectChildrenWithNull() const
{
- std::vector<const BigMemoryObject *> ret(MEDFileStructuredMesh::getDirectChildren());
- if((const MEDCouplingCurveLinearMesh *)_clmesh)
- ret.push_back((const MEDCouplingCurveLinearMesh *)_clmesh);
+ std::vector<const BigMemoryObject *> ret(MEDFileStructuredMesh::getDirectChildrenWithNull());
+ ret.push_back((const MEDCouplingCurveLinearMesh *)_clmesh);
return ret;
}
return _mesh_one_ts.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileMesh>);
}
-std::vector<const BigMemoryObject *> MEDFileMeshMultiTS::getDirectChildren() const
+std::vector<const BigMemoryObject *> MEDFileMeshMultiTS::getDirectChildrenWithNull() const
{
std::vector<const BigMemoryObject *> ret;
for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
- {
- const MEDFileMesh *cur(*it);
- if(cur)
- ret.push_back(cur);
- }
+ ret.push_back((const MEDFileMesh *)*it);
return ret;
}
return new MEDFileMeshesIterator(this);
}
+/** Return a borrowed reference (caller is not responsible) */
MEDFileMesh *MEDFileMeshes::getMeshAtPos(int i) const
{
if(i<0 || i>=(int)_meshes.size())
return _meshes[i]->getOneTimeStep();
}
+/** Return a borrowed reference (caller is not responsible) */
MEDFileMesh *MEDFileMeshes::getMeshWithName(const std::string& mname) const
{
std::vector<std::string> ms=getMeshesNames();
return _meshes.capacity()*(sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS>));
}
-std::vector<const BigMemoryObject *> MEDFileMeshes::getDirectChildren() const
+std::vector<const BigMemoryObject *> MEDFileMeshes::getDirectChildrenWithNull() const
{
std::vector<const BigMemoryObject *> ret;
for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
- {
- const MEDFileMeshMultiTS *cur(*it);
- if(cur)
- ret.push_back(cur);
- }
+ ret.push_back((const MEDFileMeshMultiTS *)*it);
return ret;
}