+ switch(meshDimRelToMaxExt)
+ {
+ case 0:
+ return _num_cells;
+ case 1:
+ return _num_nodes;
+ case -1:
+ return _num_faces;
+ default:
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberFieldAtLevel : Only available for levels 0 or 1 or -1 !");
+ }
+}
+
+/*!
+ * Returns the optional numbers of mesh entities of a given dimension transformed using
+ * DataArrayInt::invertArrayN2O2O2N().
+ * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
+ * \return const DataArrayInt * - the array of the entity numbers transformed using
+ * DataArrayInt::invertArrayN2O2O2N().
+ * \throw If \a meshDimRelToMaxExt != 0 and \a meshDimRelToMaxExt != 1.
+ * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
+ */
+const DataArrayInt *MEDFileStructuredMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const
+{
+ if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getRevNumberFieldAtLevel : Only available for levels 0 or 1 !");
+ if(meshDimRelToMaxExt==0)
+ {
+ if((const DataArrayInt *)_num_cells)
+ {
+ int pos;
+ int maxValue=_num_cells->getMaxValue(pos);
+ _rev_num_cells=_num_cells->invertArrayN2O2O2N(maxValue+1);
+ return _rev_num_cells;
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no cell renumbering for a request on reverse numbering !");
+ }
+ else
+ {
+ if((const DataArrayInt *)_num_nodes)
+ {
+ int pos;
+ int maxValue=_num_nodes->getMaxValue(pos);
+ _rev_num_nodes=_num_nodes->invertArrayN2O2O2N(maxValue+1);
+ return _rev_num_nodes;
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no node renumbering for a request on reverse numbering !");
+ }
+}
+
+const DataArrayAsciiChar *MEDFileStructuredMesh::getNameFieldAtLevel(int meshDimRelToMaxExt) const
+{
+ switch(meshDimRelToMaxExt)
+ {
+ case 0:
+ return _names_cells;
+ case 1:
+ return _names_nodes;
+ case -1:
+ return _names_faces;
+ default:
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNameFieldAtLevel : Only available for levels 0 or 1 or -1 !");
+ }
+}
+
+/*!
+ * Returns relative dimensions of mesh entities (excluding nodes) present in \a this mesh.
+ * \return std::vector<int> - a sequence of the relative dimensions: [0].
+ */
+std::vector<int> MEDFileStructuredMesh::getNonEmptyLevels() const
+{
+ std::vector<int> ret(1);
+ return ret;
+}
+
+/*!
+ * Returns relative dimensions of mesh entities (including nodes) present in \a this mesh.
+ * \return std::vector<int> - a sequence of the relative dimensions: [1,0].
+ */
+std::vector<int> MEDFileStructuredMesh::getNonEmptyLevelsExt() const
+{
+ std::vector<int> ret(2);
+ ret[0]=1;
+ return ret;
+}
+
+/*!
+ * Returns the set of extensive levels (nodes included) where not NULL family arr are defined.
+ */
+std::vector<int> MEDFileStructuredMesh::getFamArrNonEmptyLevelsExt() const
+{
+ std::vector<int> ret;
+ const DataArrayInt *famNodes(_fam_nodes),*famCells(_fam_cells),*famFaces(_fam_faces);
+ if(famNodes)
+ ret.push_back(1);
+ if(famCells)
+ ret.push_back(0);
+ if(famFaces)
+ ret.push_back(-1);
+ return ret;
+}
+
+/*!
+ * Returns the set of extensive levels (nodes included) where not NULL numbering arr are defined.
+ */
+std::vector<int> MEDFileStructuredMesh::getNumArrNonEmptyLevelsExt() const
+{
+ std::vector<int> ret;
+ const DataArrayInt *numNodes(_num_nodes),*numCells(_num_cells),*numFaces(_num_faces);
+ if(numNodes)
+ ret.push_back(1);
+ if(numCells)
+ ret.push_back(0);
+ if(numFaces)
+ ret.push_back(-1);
+ return ret;
+}
+
+/*!
+ * Returns the set of extensive levels (nodes included) where not NULL naming arr are defined.
+ */
+std::vector<int> MEDFileStructuredMesh::getNameArrNonEmptyLevelsExt() const
+{
+ std::vector<int> ret;
+ const DataArrayAsciiChar *namesNodes(_names_nodes),*namesCells(_names_cells),*namesFaces(_names_faces);
+ if(namesNodes)
+ ret.push_back(1);
+ if(namesCells)
+ ret.push_back(0);
+ if(namesFaces)
+ ret.push_back(-1);
+ return ret;
+}
+
+/*!
+ * no implementation here, it is not a bug, but intresically no polyhedra in \a this.
+ */
+bool MEDFileStructuredMesh::unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell)
+{
+ oldCode.clear(); newCode.clear(); o2nRenumCell=0;
+ return false;
+}
+
+void MEDFileStructuredMesh::changeFamilyIdArr(int oldId, int newId)
+{
+ DataArrayInt *arr=_fam_nodes;
+ if(arr)
+ arr->changeValue(oldId,newId);
+ arr=_fam_cells;
+ if(arr)
+ arr->changeValue(oldId,newId);
+ arr=_fam_faces;
+ if(arr)
+ arr->changeValue(oldId,newId);
+}
+
+void MEDFileStructuredMesh::deepCpyAttributes()
+{
+ if((const DataArrayInt*)_fam_nodes)
+ _fam_nodes=_fam_nodes->deepCpy();
+ if((const DataArrayInt*)_num_nodes)
+ _num_nodes=_num_nodes->deepCpy();
+ if((const DataArrayAsciiChar*)_names_nodes)
+ _names_nodes=_names_nodes->deepCpy();
+ if((const DataArrayInt*)_fam_cells)
+ _fam_cells=_fam_cells->deepCpy();
+ if((const DataArrayInt*)_num_cells)
+ _num_cells=_num_cells->deepCpy();
+ if((const DataArrayAsciiChar*)_names_cells)
+ _names_cells=_names_cells->deepCpy();
+ if((const DataArrayInt*)_fam_faces)
+ _fam_faces=_fam_faces->deepCpy();
+ if((const DataArrayInt*)_num_faces)
+ _num_faces=_num_faces->deepCpy();
+ if((const DataArrayAsciiChar*)_names_faces)
+ _names_faces=_names_faces->deepCpy();
+ if((const DataArrayInt*)_rev_num_nodes)
+ _rev_num_nodes=_rev_num_nodes->deepCpy();
+ if((const DataArrayInt*)_rev_num_cells)
+ _rev_num_cells=_rev_num_cells->deepCpy();
+}
+
+/*!
+ * Returns a pointer to mesh at the specified level (here 0 is compulsary for cartesian mesh).
+ *
+ * \return a pointer to cartesian mesh that need to be managed by the caller.
+ * \warning the returned pointer has to be managed by the caller.
+ */
+
+/*!
+ * Returns a pointer to MEDCouplingStructuredMesh held by \a this.
+ * \param [in] meshDimRelToMax - it must be \c 0 or \c -1.
+ * \param [in] renum - it must be \c false.
+ * \return MEDCouplingMesh * - a pointer to MEDCouplingMesh that the caller is to
+ * delete using decrRef() as it is no more needed.
+ */
+MEDCouplingMesh *MEDFileStructuredMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const
+{
+ if(renum)
+ throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support renumbering ! To do it perform request of renum array directly !");
+ const MEDCouplingStructuredMesh *m(getStructuredMesh());
+ switch(meshDimRelToMax)
+ {
+ case 0:
+ {
+ if(m)
+ m->incrRef();
+ return const_cast<MEDCouplingStructuredMesh *>(m);
+ }
+ case -1:
+ {
+ if(!m)
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGenMeshAtLevel : level -1 requested must be non empty to be able to compute unstructured sub mesh !");
+ 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 !");
+ }
+}
+
+/*!
+ * Returns number of mesh entities of a given relative dimension in \a this mesh.
+ * \param [in] meshDimRelToMaxExt - the relative dimension of interest.
+ * \return int - the number of entities.
+ * \throw If no mesh entities of dimension \a meshDimRelToMaxExt are available in \a this mesh.
+ */
+int MEDFileStructuredMesh::getSizeAtLevel(int meshDimRelToMaxExt) const
+{
+ const MEDCouplingStructuredMesh *cmesh(getStructuredMesh());
+ if(!cmesh)
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getSizeAtLevel : No structured mesh set !");
+ switch(meshDimRelToMaxExt)
+ {
+ case 0:
+ return cmesh->getNumberOfCells();
+ case 1:
+ return cmesh->getNumberOfNodes();
+ case -1:
+ return cmesh->getNumberOfCellsOfSubLevelMesh();
+ default:
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getSizeAtLevel : Only available for levels 0 or 1 or -1 !");
+ }
+}
+
+int MEDFileStructuredMesh::getNumberOfNodes() const
+{
+ const MEDCouplingStructuredMesh *cmesh(getStructuredMesh());
+ if(!cmesh)
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberOfNodes : no cartesian mesh set !");
+ return cmesh->getNumberOfNodes();
+}
+
+bool MEDFileStructuredMesh::hasImplicitPart() const
+{
+ return true;
+}
+
+/*!
+ * \sa MEDFileStructuredMesh::getImplicitFaceMesh
+ */
+int MEDFileStructuredMesh::buildImplicitPartIfAny(INTERP_KERNEL::NormalizedCellType gt) const
+{
+ static const char MSG[]="MEDFileStructuredMesh::buildImplicitPartIfAny : the given geo type is not manageable by a structured mesh !";
+ const MEDCoupling1SGTUMesh *zeFaceMesh(_faces_if_necessary);
+ if(!zeFaceMesh)
+ {
+ const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(getMeshDimension())));
+ if(cm.getReverseExtrudedType()!=gt)
+ throw INTERP_KERNEL::Exception(MSG);
+ buildImplicitPart();
+ return getStructuredMesh()->getNumberOfCellsOfSubLevelMesh();
+ }
+ else
+ {
+ if(gt!=zeFaceMesh->getCellModelEnum())
+ throw INTERP_KERNEL::Exception(MSG);
+ return zeFaceMesh->getNumberOfCells();
+ }
+}
+
+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;
+}
+
+/*!
+ * Retrieves the internal pointer (no decrRef requested) of the implicit face mesh if any.
+ * To force to build it you can invoke MEDFileStructuredMesh::buildImplicitPartIfAny method.
+ *
+ * \sa MEDFileStructuredMesh::buildImplicitPartIfAny
+ */
+MEDCoupling1SGTUMesh *MEDFileStructuredMesh::getImplicitFaceMesh() const
+{
+ return _faces_if_necessary;
+}
+
+std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileStructuredMesh::getGeoTypesAtLevel(int meshDimRelToMax) const
+{
+ const MEDCouplingStructuredMesh *cmesh(getStructuredMesh());
+ if(!cmesh)
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGeoTypesAtLevel : No structured mesh set !");
+ switch(meshDimRelToMax)
+ {
+ case 0:
+ {
+ std::vector<INTERP_KERNEL::NormalizedCellType> ret(1,cmesh->getTypeOfCell(0));
+ return ret;
+ }
+ case -1:
+ {
+ int mdim(cmesh->getMeshDimension());
+ if(mdim<1)
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGeoTypesAtLevel : only one level available for structured meshes ! Input 0 is mandatory or 0D mesh !");
+ std::vector<INTERP_KERNEL::NormalizedCellType> ret(1,MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim-1));
+ return ret;
+ }
+ default:
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGeoTypesAtLevel : only 2 levels available at most : 0 and -1 !");
+ }
+}
+
+void MEDFileStructuredMesh::whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector<bool>& nodesFetched) const
+{
+ if(st.getNumberOfItems()!=1)
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::whichAreNodesFetched : The sturture of field is not lying on single geo type ! it is not managed yet for structured mesh !");
+ if(st[0].getGeo()!=MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(getMeshDimension()))
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::whichAreNodesFetched : The sturture of field is not lying on expected geo type !");
+ if(getNumberOfNodes()!=(int)nodesFetched.size())
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::whichAreNodesFetched : invalid size of array !");
+ if(st[0].getPflName().empty())
+ {
+ std::fill(nodesFetched.begin(),nodesFetched.end(),true);
+ return ;
+ }
+ const DataArrayInt *arr(globs->getProfile(st[0].getPflName()));
+ const MEDCouplingStructuredMesh *cmesh=getStructuredMesh();//cmesh not null because getNumberOfNodes called before
+ int sz(nodesFetched.size());
+ for(const int *work=arr->begin();work!=arr->end();work++)
+ {
+ std::vector<int> conn;
+ cmesh->getNodeIdsOfCell(*work,conn);
+ for(std::vector<int>::const_iterator it=conn.begin();it!=conn.end();it++)
+ if(*it>=0 && *it<sz)
+ nodesFetched[*it]=true;
+ else
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::whichAreNodesFetched : internal error !");
+ }
+}
+
+med_geometry_type MEDFileStructuredMesh::GetGeoTypeFromMeshDim(int meshDim)
+{
+ INTERP_KERNEL::NormalizedCellType ct(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(meshDim));
+ return typmai3[ct];
+}
+
+void MEDFileStructuredMesh::LoadStrMeshDAFromFile(med_idt fid, int meshDim, int dt, int it, const std::string& mName, MEDFileMeshReadSelector *mrs,
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& famCells, MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& numCells, MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar>& namesCells)
+{
+ med_bool chgt=MED_FALSE,trsf=MED_FALSE;
+ med_geometry_type geoTypeReq=MEDFileStructuredMesh::GetGeoTypeFromMeshDim(meshDim);
+ int nbOfElt(0);
+ nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ if(!mrs || mrs->isCellFamilyFieldReading())
+ {
+ famCells=DataArrayInt::New();
+ famCells->alloc(nbOfElt,1);
+ MEDmeshEntityFamilyNumberRd(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,famCells->getPointer());
+ }
+ }
+ nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ if(!mrs || mrs->isCellNumFieldReading())
+ {
+ numCells=DataArrayInt::New();
+ numCells->alloc(nbOfElt,1);
+ MEDmeshEntityNumberRd(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,numCells->getPointer());
+ }
+ }
+ nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,MED_NAME,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ if(!mrs || mrs->isCellNameFieldReading())
+ {
+ namesCells=DataArrayAsciiChar::New();
+ namesCells->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
+ MEDmeshEntityNameRd(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,namesCells->getPointer());
+ namesCells->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end
+ }
+ }
+}
+
+void MEDFileStructuredMesh::loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
+ setName(strm->getName());
+ setDescription(strm->getDescription());
+ setUnivName(strm->getUnivName());
+ setIteration(strm->getIteration());
+ setOrder(strm->getOrder());
+ setTimeValue(strm->getTime());
+ setTimeUnit(strm->getTimeUnit());
+ MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups,mrs);
+ med_bool chgt=MED_FALSE,trsf=MED_FALSE;
+ int nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ if(!mrs || mrs->isNodeFamilyFieldReading())
+ {
+ int nbNodes(getNumberOfNodes());
+ if(nbOfElt>nbNodes)
+ throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::loadStrMeshFromFile : invalid size of family node array regarding number of nodes in this ! File seems to be corrupted !");
+ _fam_nodes=DataArrayInt::New();
+ _fam_nodes->alloc(nbNodes,1);//yes nbNodes and not nbOfElt see next line.
+ if(nbNodes>nbOfElt)//yes it appends some times... It explains surely the mdump implementation. Bug revealed by PARAVIS EDF #2475 on structured.med file where only 12 first nodes are !=0 so nbOfElt=12 and nbOfNodes=378...
+ _fam_nodes->fillWithZero();
+ MEDmeshEntityFamilyNumberRd(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer());
+ }
+ }
+ nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ if(!mrs || mrs->isNodeNumFieldReading())
+ {
+ _num_nodes=DataArrayInt::New();
+ _num_nodes->alloc(nbOfElt,1);
+ MEDmeshEntityNumberRd(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer());
+ }
+ }
+ nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_NAME,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ if(!mrs || mrs->isNodeNameFieldReading())
+ {
+ _names_nodes=DataArrayAsciiChar::New();
+ _names_nodes->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
+ MEDmeshEntityNameRd(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,_names_nodes->getPointer());
+ _names_nodes->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end
+ }
+ }
+ int meshDim(getStructuredMesh()->getMeshDimension());
+ LoadStrMeshDAFromFile(fid,meshDim,dt,it,mName,mrs,_fam_cells,_num_cells,_names_cells);
+ if(meshDim>=1)
+ LoadStrMeshDAFromFile(fid,meshDim-1,dt,it,mName,mrs,_fam_faces,_num_faces,_names_faces);
+}
+
+void MEDFileStructuredMesh::writeStructuredLL(med_idt fid, const std::string& maa) const
+{
+ int meshDim(getStructuredMesh()->getMeshDimension());
+ med_geometry_type geoTypeReq(GetGeoTypeFromMeshDim(meshDim)),geoTypeReq2(GetGeoTypeFromMeshDim(meshDim-1));
+ //
+ if((const DataArrayInt *)_fam_cells)
+ MEDmeshEntityFamilyNumberWr(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq,_fam_cells->getNumberOfTuples(),_fam_cells->getConstPointer());
+ if((const DataArrayInt *)_fam_faces)
+ MEDmeshEntityFamilyNumberWr(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq2,_fam_faces->getNumberOfTuples(),_fam_faces->getConstPointer());
+ if((const DataArrayInt *)_fam_nodes)
+ MEDmeshEntityFamilyNumberWr(fid,maa.c_str(),_iteration,_order,MED_NODE,MED_NONE,_fam_nodes->getNumberOfTuples(),_fam_nodes->getConstPointer());
+ if((const DataArrayInt *)_num_cells)
+ MEDmeshEntityNumberWr(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq,_num_cells->getNumberOfTuples(),_num_cells->getConstPointer());
+ if((const DataArrayInt *)_num_faces)
+ MEDmeshEntityNumberWr(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq2,_num_faces->getNumberOfTuples(),_num_faces->getConstPointer());
+ if((const DataArrayInt *)_num_nodes)
+ MEDmeshEntityNumberWr(fid,maa.c_str(),_iteration,_order,MED_NODE,MED_NONE,_num_nodes->getNumberOfTuples(),_num_nodes->getConstPointer());
+ if((const DataArrayAsciiChar *)_names_cells)
+ {
+ if(_names_cells->getNumberOfComponents()!=MED_SNAME_SIZE)
+ {
+ std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on cells with number of components set to " << MED_SNAME_SIZE;
+ oss << " ! The array has " << _names_cells->getNumberOfComponents() << " components !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ MEDmeshEntityNameWr(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq,_names_cells->getNumberOfTuples(),_names_cells->getConstPointer());
+ }
+ if((const DataArrayAsciiChar *)_names_faces)
+ {
+ if(_names_faces->getNumberOfComponents()!=MED_SNAME_SIZE)
+ {
+ std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on faces with number of components set to " << MED_SNAME_SIZE;
+ oss << " ! The array has " << _names_faces->getNumberOfComponents() << " components !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ MEDmeshEntityNameWr(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq2,_names_faces->getNumberOfTuples(),_names_faces->getConstPointer());
+ }
+ if((const DataArrayAsciiChar *)_names_nodes)
+ {
+ if(_names_nodes->getNumberOfComponents()!=MED_SNAME_SIZE)
+ {
+ std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
+ oss << " ! The array has " << _names_cells->getNumberOfComponents() << " components !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ MEDmeshEntityNameWr(fid,maa.c_str(),_iteration,_order,MED_NODE,MED_NONE,_names_nodes->getNumberOfTuples(),_names_nodes->getConstPointer());
+ }
+ //
+ MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa.c_str(),_families,_groups,_too_long_str);
+}
+
+/*!
+ * Returns an empty instance of MEDFileCMesh.
+ * \return MEDFileCMesh * - a new instance of MEDFileCMesh. The caller is to delete this
+ * mesh using decrRef() as it is no more needed.
+ */
+MEDFileCMesh *MEDFileCMesh::New()
+{
+ return new MEDFileCMesh;
+}
+
+/*!
+ * Returns a new MEDFileCMesh holding the mesh data that has been read from a given MED
+ * file. The first mesh in the file is loaded.
+ * \param [in] fileName - the name of MED file to read.
+ * \return MEDFileCMesh * - a new instance of MEDFileCMesh. The caller is to delete this
+ * mesh using decrRef() as it is no more needed.
+ * \throw If the file is not readable.
+ * \throw If there is no meshes in the file.
+ * \throw If the mesh in the file is not a Cartesian one.
+ */
+MEDFileCMesh *MEDFileCMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs)
+{
+ std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
+ if(ms.empty())
+ {
+ std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ MEDFileUtilities::CheckFileForRead(fileName);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ int dt,it;
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ std::string dummy2;
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
+ return new MEDFileCMesh(fid,ms.front(),dt,it,mrs);
+}
+
+/*!
+ * Returns a new MEDFileCMesh holding the mesh data that has been read from a given MED
+ * file. The mesh to load is specified by its name and numbers of a time step and an
+ * iteration.
+ * \param [in] fileName - the name of MED file to read.
+ * \param [in] mName - the name of the mesh to read.
+ * \param [in] dt - the number of a time step.
+ * \param [in] it - the number of an iteration.
+ * \return MEDFileCMesh * - a new instance of MEDFileCMesh. The caller is to delete this
+ * mesh using decrRef() as it is no more needed.
+ * \throw If the file is not readable.
+ * \throw If there is no mesh with given attributes in the file.
+ * \throw If the mesh in the file is not a Cartesian one.
+ */
+MEDFileCMesh *MEDFileCMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
+ MEDFileUtilities::CheckFileForRead(fileName);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
+ return new MEDFileCMesh(fid,mName,dt,it,mrs);
+}
+
+std::size_t MEDFileCMesh::getHeapMemorySizeWithoutChildren() const
+{
+ return MEDFileStructuredMesh::getHeapMemorySizeWithoutChildren();
+}
+
+std::vector<const BigMemoryObject *> MEDFileCMesh::getDirectChildrenWithNull() const
+{
+ std::vector<const BigMemoryObject *> ret(MEDFileStructuredMesh::getDirectChildrenWithNull());
+ ret.push_back((const MEDCouplingCMesh *)_cmesh);
+ return ret;
+}
+
+/*!
+ * Returns the dimension on cells in \a this mesh.
+ * \return int - the mesh dimension.
+ * \throw If there are no cells in this mesh.
+ */
+int MEDFileCMesh::getMeshDimension() const
+{
+ if(!((const MEDCouplingCMesh*)_cmesh))
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getMeshDimension : unable to get meshdimension because no mesh set !");
+ return _cmesh->getMeshDimension();
+}
+
+/*!
+ * Returns the dimension on nodes in \a this mesh.
+ * \return int - the space dimension.
+ * \throw If there are no cells in this mesh.
+ */
+int MEDFileCMesh::getSpaceDimension() const
+{
+ if(!((const MEDCouplingCMesh*)_cmesh))
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getSpaceDimension : unable to get spacedimension because no mesh set !");
+ return _cmesh->getSpaceDimension();
+}
+
+/*!
+ * Returns a string describing \a this mesh.
+ * \return std::string - the mesh information string.
+ */
+std::string MEDFileCMesh::simpleRepr() const
+{
+ return MEDFileStructuredMesh::simpleRepr();
+}
+
+/*!
+ * Returns a full textual description of \a this mesh.
+ * \return std::string - the string holding the mesh description.
+ */
+std::string MEDFileCMesh::advancedRepr() const
+{
+ return simpleRepr();
+}
+
+MEDFileMesh *MEDFileCMesh::shallowCpy() const
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=new MEDFileCMesh(*this);
+ return ret.retn();
+}
+
+MEDFileMesh *MEDFileCMesh::createNewEmpty() const
+{
+ return new MEDFileCMesh;
+}
+
+MEDFileMesh *MEDFileCMesh::deepCpy() const
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=new MEDFileCMesh(*this);
+ if((const MEDCouplingCMesh*)_cmesh)
+ ret->_cmesh=static_cast<MEDCouplingCMesh*>(_cmesh->deepCpy());
+ ret->deepCpyAttributes();
+ return ret.retn();
+}
+
+/*!
+ * Checks if \a this and another mesh are equal.
+ * \param [in] other - the mesh to compare with.
+ * \param [in] eps - a precision used to compare real values.
+ * \param [in,out] what - the string returning description of unequal data.
+ * \return bool - \c true if the meshes are equal, \c false, else.
+ */
+bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
+{
+ if(!MEDFileStructuredMesh::isEqual(other,eps,what))
+ return false;
+ const MEDFileCMesh *otherC=dynamic_cast<const MEDFileCMesh *>(other);
+ if(!otherC)
+ {
+ what="Mesh types differ ! This is cartesian and other is NOT !";
+ return false;
+ }
+ clearNonDiscrAttributes();
+ otherC->clearNonDiscrAttributes();
+ const MEDCouplingCMesh *coo1=_cmesh;
+ const MEDCouplingCMesh *coo2=otherC->_cmesh;
+ if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
+ {
+ what="Mismatch of cartesian meshes ! One is defined and not other !";
+ return false;
+ }
+ if(coo1)
+ {
+ bool ret=coo1->isEqual(coo2,eps);
+ if(!ret)
+ {
+ what="cartesian meshes differ !";
+ return false;
+ }
+ }
+ return true;
+}
+
+/*!
+ * Clears redundant attributes of incorporated data arrays.
+ */
+void MEDFileCMesh::clearNonDiscrAttributes() const
+{
+ MEDFileStructuredMesh::clearNonDiscrAttributes();
+ MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_cmesh);//to it is not a bug umeshsplit have already the method implemented
+}
+
+MEDFileCMesh::MEDFileCMesh()
+{
+}
+
+MEDFileCMesh::MEDFileCMesh(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+try
+{
+ loadCMeshFromFile(fid,mName,dt,it,mrs);
+}
+catch(INTERP_KERNEL::Exception& e)
+{
+ throw e;
+}
+
+void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
+{
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ int dummy0,dummy1;
+ std::string dtunit;
+ int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
+ if(meshType!=CARTESIAN)
+ {
+ std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ MEDFileCMeshL2 loaderl2;
+ loaderl2.loadAll(fid,mid,mName,dt,it);
+ MEDCouplingCMesh *mesh=loaderl2.getMesh();
+ mesh->incrRef();
+ _cmesh=mesh;
+ loadStrMeshFromFile(&loaderl2,fid,mName,dt,it,mrs);