From: ageay Date: Thu, 7 Feb 2013 11:57:52 +0000 (+0000) Subject: CurveLinearMesh 2 X-Git-Tag: V6_main_FINAL~381 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b1e6866126bcfb1eff1d4ef8c8f44dab2dd579bc;p=tools%2Fmedcoupling.git CurveLinearMesh 2 --- diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 518b525ca..63f31a5d1 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2019,6 +2019,13 @@ DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::ve return l1->getFamilyPartArr(0,0,renum); } +/*! + * Returns a pointer to mesh at the specified level. + * + * \return a pointer to unstructured mesh that need to be managed by the caller. + * \warning the returned pointer has to be managed by the caller. + * \sa MEDFileUMesh::getGenMeshAtLevel + */ MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception) { synchronizeTinyInfoOnLeaves(); @@ -2038,6 +2045,13 @@ MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renu return l1->getWholeMesh(renum); } +/*! + * Returns a pointer to mesh at the specified level. + * + * \return a pointer to unstructured mesh that need to be managed by the caller. + * \warning the returned pointer has to be managed by the caller. + * \sa MEDFileUMesh::getMeshAtLevel + */ MEDCouplingMesh *MEDFileUMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception) { return getMeshAtLevel(meshDimRelToMax,renum); @@ -2727,40 +2741,9 @@ void MEDFileUMesh::computeRevNum() const } } -MEDFileCMesh *MEDFileCMesh::New() -{ - return new MEDFileCMesh; -} - -MEDFileCMesh *MEDFileCMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception) -{ - std::vector 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,MED_ACC_RDONLY); - int dt,it; - ParaMEDMEM::MEDCouplingMeshType meshType; - std::string dummy2; - MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2); - return new MEDFileCMesh(fid,ms.front().c_str(),dt,it); -} - -MEDFileCMesh *MEDFileCMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) -{ - MEDFileUtilities::CheckFileForRead(fileName); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); - return new MEDFileCMesh(fid,mName,dt,it); -} - -std::size_t MEDFileCMesh::getHeapMemorySize() const +std::size_t MEDFileStructuredMesh::getHeapMemorySize() const { std::size_t ret=MEDFileMesh::getHeapMemorySize(); - if((const MEDCouplingCMesh *)_cmesh) - ret+=_cmesh->getHeapMemorySize(); if((const DataArrayInt*)_fam_nodes) ret+=_fam_nodes->getHeapMemorySize(); if((const DataArrayInt*)_num_nodes) @@ -2776,7 +2759,7 @@ std::size_t MEDFileCMesh::getHeapMemorySize() const return ret; } -int MEDFileCMesh::getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) +int MEDFileStructuredMesh::getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) { int ret=-std::numeric_limits::max(),tmp=-1; if((const DataArrayInt *)_fam_nodes) @@ -2792,7 +2775,7 @@ int MEDFileCMesh::getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) return ret; } -int MEDFileCMesh::getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) +int MEDFileStructuredMesh::getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) { int ret=std::numeric_limits::max(),tmp=-1; if((const DataArrayInt *)_fam_nodes) @@ -2808,77 +2791,16 @@ int MEDFileCMesh::getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception) return ret; } -int MEDFileCMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception) -{ - if(!((const MEDCouplingCMesh*)_cmesh)) - throw INTERP_KERNEL::Exception("MEDFileCMesh::getMeshDimension : unable to get meshdimension because no mesh set !"); - return _cmesh->getMeshDimension(); -} - -std::string MEDFileCMesh::simpleRepr() const -{ - return MEDFileMesh::simpleRepr(); -} - -std::string MEDFileCMesh::advancedRepr() const -{ - return simpleRepr(); -} - -MEDFileMesh *MEDFileCMesh::shallowCpy() const throw(INTERP_KERNEL::Exception) -{ - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCMesh(*this); - return ret.retn(); -} - -MEDFileMesh *MEDFileCMesh::deepCpy() const throw(INTERP_KERNEL::Exception) -{ - MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCMesh(*this); - if((const MEDCouplingCMesh*)_cmesh) - ret->_cmesh=static_cast(_cmesh->deepCpy()); - if((const DataArrayInt*)_fam_nodes) - ret->_fam_nodes=_fam_nodes->deepCpy(); - if((const DataArrayInt*)_num_nodes) - ret->_num_nodes=_num_nodes->deepCpy(); - if((const DataArrayInt*)_fam_cells) - ret->_fam_cells=_fam_cells->deepCpy(); - if((const DataArrayInt*)_num_cells) - ret->_num_cells=_num_cells->deepCpy(); - if((const DataArrayInt*)_rev_num_nodes) - ret->_rev_num_nodes=_rev_num_nodes->deepCpy(); - if((const DataArrayInt*)_rev_num_cells) - ret->_rev_num_cells=_rev_num_cells->deepCpy(); - return ret.retn(); -} - -bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const +bool MEDFileStructuredMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const { if(!MEDFileMesh::isEqual(other,eps,what)) return false; - const MEDFileCMesh *otherC=dynamic_cast(other); + const MEDFileStructuredMesh *otherC=dynamic_cast(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 !"; + what="Mesh types differ ! This is structured and other is NOT !"; return false; } - if(coo1) - { - bool ret=coo1->isEqual(coo2,eps); - if(!ret) - { - what="cartesian meshes differ !"; - return false; - } - } const DataArrayInt *famc1=_fam_nodes; const DataArrayInt *famc2=otherC->_fam_nodes; if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0)) @@ -2946,10 +2868,9 @@ bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& wh return true; } -void MEDFileCMesh::clearNonDiscrAttributes() const +void MEDFileStructuredMesh::clearNonDiscrAttributes() const { MEDFileMesh::clearNonDiscrAttributes(); - MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_cmesh); const DataArrayInt *tmp=_fam_nodes; if(tmp) (const_cast(tmp))->setName(""); @@ -2964,158 +2885,212 @@ void MEDFileCMesh::clearNonDiscrAttributes() const (const_cast(tmp))->setName(""); } -MEDFileCMesh::MEDFileCMesh() -{ -} - -MEDFileCMesh::MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) -try - { - loadCMeshFromFile(fid,mName,dt,it); - } -catch(INTERP_KERNEL::Exception& e) - { - throw e; - } - -void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDFileStructuredMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) { - MEDFileCMeshL2 loaderl2; - 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()); - } - loaderl2.loadAll(fid,mid,mName,dt,it); - MEDCouplingCMesh *mesh=loaderl2.getMesh(); - mesh->incrRef(); - _cmesh=mesh; - setName(loaderl2.getName()); - setDescription(loaderl2.getDescription()); - setIteration(loaderl2.getIteration()); - setOrder(loaderl2.getOrder()); - setTimeValue(loaderl2.getTime()); - setTimeUnit(loaderl2.getTimeUnit()); - MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups); - med_bool chgt=MED_FALSE,trsf=MED_FALSE; - int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf); - if(nbOfElt>0) - { - _fam_nodes=DataArrayInt::New(); - _fam_nodes->alloc(nbOfElt,1); - MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer()); - } - nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf); - if(nbOfElt>0) - { - _num_nodes=DataArrayInt::New(); - _num_nodes->alloc(nbOfElt,1); - MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer()); - } - int spaceDim=mesh->getSpaceDimension(); - med_geometry_type geoTypeReq=MED_NONE; - switch(spaceDim) - { - case 3: - geoTypeReq=MED_HEXA8; - break; - case 2: - geoTypeReq=MED_QUAD4; - break; - case 1: - geoTypeReq=MED_SEG2; - break; - case 0: - geoTypeReq=MED_POINT1; - break; - default: - throw INTERP_KERNEL::Exception("Invalid spacedim detected for cartesian mesh ! Must be in (1,2,3) !"); - } - nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf); - if(nbOfElt>0) + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : Only available for levels 0 or 1 !"); + std::vector famIds=getFamiliesIds(fams); + if(meshDimRelToMaxExt==1) { - _fam_cells=DataArrayInt::New(); - _fam_cells->alloc(nbOfElt,1); - MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_fam_cells->getPointer()); + if((const DataArrayInt *)_fam_nodes) + { + MEDCouplingAutoRefCountObjectPtr da; + if(!famIds.empty()) + da=_fam_nodes->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size()); + else + da=_fam_nodes->getIdsEqualList(0,0); + if(renum) + return MEDFileUMeshSplitL1::Renumber(_num_nodes,da); + else + return da.retn(); + } + else + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : no family array specified on nodes !"); } - nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf); - if(nbOfElt>0) + else { - _num_cells=DataArrayInt::New(); - _num_cells->alloc(nbOfElt,1); - MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer()); + if((const DataArrayInt *)_fam_cells) + { + MEDCouplingAutoRefCountObjectPtr da; + if(!famIds.empty()) + da=_fam_cells->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size()); + else + da=_fam_cells->getIdsEqualList(0,0); + if(renum) + return MEDFileUMeshSplitL1::Renumber(_num_cells,da); + else + return da.retn(); + } + else + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : no family array specified on cells !"); } } -void MEDFileCMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception) +void MEDFileStructuredMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception) { - DataArrayInt *arr=_fam_nodes; - if(arr) - arr->changeValue(oldId,newId); - arr=_fam_cells; - if(arr) - arr->changeValue(oldId,newId); + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : Only available for levels 0 or 1 !"); + if(famArr) + famArr->incrRef(); + if(meshDimRelToMaxExt==0) + _fam_cells=famArr; + else + _fam_nodes=famArr; } -const MEDCouplingCMesh *MEDFileCMesh::getMesh() const +void MEDFileStructuredMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) { - synchronizeTinyInfoOnLeaves(); - return _cmesh; + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : Only available for levels 0 or 1 !"); + if(renumArr) + renumArr->incrRef(); + if(meshDimRelToMaxExt==0) + _num_cells=renumArr; + else + _num_nodes=renumArr; } -MEDCouplingMesh *MEDFileCMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception) +const DataArrayInt *MEDFileStructuredMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { - if(renum) - throw INTERP_KERNEL::Exception("MEDFileCMesh does not support renumbering ! To do it perform request of renum array directly !"); - if(meshDimRelToMax!=0) - throw INTERP_KERNEL::Exception("MEDFileCMesh does not support multi level for mesh 0 expected as input !"); - const MEDCouplingCMesh *m=getMesh(); - if(m) - m->incrRef(); - return const_cast(m); + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamilyFieldAtLevel : Only available for levels 0 or 1 !"); + if(meshDimRelToMaxExt==0) + return _fam_cells; + else + return _fam_nodes; } -void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception) +const DataArrayInt *MEDFileStructuredMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { - dealWithTinyInfo(m); - if(m) - m->incrRef(); - _cmesh=m; + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberFieldAtLevel : Only available for levels 0 or 1 !"); + if(meshDimRelToMaxExt==0) + return _num_cells; + else + return _num_nodes; } -void MEDFileCMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) +const DataArrayInt *MEDFileStructuredMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { - INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); - INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); - INTERP_KERNEL::AutoPtr dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); - MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str); - MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str); - MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str); - int spaceDim=_cmesh->getSpaceDimension(); - INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); - INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); - for(int i=0;igetCoordsAt(i)->getInfoOnComponent(0)); - std::string c,u; - MEDLoaderBase::splitIntoNameAndUnit(info,c,u); - MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo - MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + 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 !"); } - MEDmeshCr(fid,maa,spaceDim,spaceDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit); - MEDmeshGridTypeWr(fid,maa,MED_CARTESIAN_GRID); - for(int i=0;igetCoordsAt(i); - MEDmeshGridIndexCoordinateWr(fid,maa,_iteration,_order,_time,i+1,da->getNumberOfTuples(),da->getConstPointer()); + 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 !"); } - // +} + +std::vector MEDFileStructuredMesh::getNonEmptyLevels() const +{ + std::vector ret(1); + return ret; +} + +std::vector MEDFileStructuredMesh::getNonEmptyLevelsExt() const +{ + std::vector ret(2); + ret[0]=1; + return ret; +} + +/*! + * no implementation here, it is not a bug, but intresically no polyhedra in \a this. + */ +bool MEDFileStructuredMesh::unPolyze(std::vector& oldCode, std::vector& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception) +{ + oldCode.clear(); newCode.clear(); o2nRenumCell=0; + return false; +} + +void MEDFileStructuredMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception) +{ + DataArrayInt *arr=_fam_nodes; + if(arr) + arr->changeValue(oldId,newId); + arr=_fam_cells; + if(arr) + arr->changeValue(oldId,newId); +} + +void MEDFileStructuredMesh::deepCpyAttributes() throw(INTERP_KERNEL::Exception) +{ + if((const DataArrayInt*)_fam_nodes) + _fam_nodes=_fam_nodes->deepCpy(); + if((const DataArrayInt*)_num_nodes) + _num_nodes=_num_nodes->deepCpy(); + if((const DataArrayInt*)_fam_cells) + _fam_cells=_fam_cells->deepCpy(); + if((const DataArrayInt*)_num_cells) + _num_cells=_num_cells->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. + */ +MEDCouplingMesh *MEDFileStructuredMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception) +{ + if(renum) + throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support renumbering ! To do it perform request of renum array directly !"); + if(meshDimRelToMax!=0) + throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support multi level for mesh 0 expected as input !"); + const MEDCouplingStructuredMesh *m=getStructuredMesh(); + if(m) + m->incrRef(); + return const_cast(m); +} + +int MEDFileStructuredMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +{ + if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getSizeAtLevel : Only available for levels 0 or 1 !"); + const MEDCouplingStructuredMesh *cmesh=getStructuredMesh(); + if(!cmesh) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getSizeAtLevel : No structured mesh set !"); + if(meshDimRelToMaxExt==0) + return cmesh->getNumberOfCells(); + else + return cmesh->getNumberOfNodes(); +} + +int MEDFileStructuredMesh::getNumberOfNodes() const throw(INTERP_KERNEL::Exception) +{ + const MEDCouplingStructuredMesh *cmesh=getStructuredMesh(); + if(!cmesh) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberOfNodes : no cartesian mesh set !"); + return cmesh->getNumberOfNodes(); +} + +med_geometry_type MEDFileStructuredMesh::GetGeoTypeFromMeshDim(int meshDim) throw(INTERP_KERNEL::Exception) +{ med_geometry_type geoTypeReq=MED_NONE; - switch(spaceDim) + switch(meshDim) { case 3: geoTypeReq=MED_HEXA8; @@ -3130,8 +3105,57 @@ void MEDFileCMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) geoTypeReq=MED_POINT1; break; default: - throw INTERP_KERNEL::Exception("Invalid spacedim detected for cartesian mesh ! Must be in (1,2,3) !"); + throw INTERP_KERNEL::Exception("Invalid meshdim detected for structured mesh ! Must be in (1,2,3) !"); + } + return geoTypeReq; +} + +void MEDFileStructuredMesh::loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + setName(strm->getName()); + setDescription(strm->getDescription()); + setIteration(strm->getIteration()); + setOrder(strm->getOrder()); + setTimeValue(strm->getTime()); + setTimeUnit(strm->getTimeUnit()); + MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups); + med_bool chgt=MED_FALSE,trsf=MED_FALSE; + int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _fam_nodes=DataArrayInt::New(); + _fam_nodes->alloc(nbOfElt,1); + MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer()); + } + nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _num_nodes=DataArrayInt::New(); + _num_nodes->alloc(nbOfElt,1); + MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer()); + } + int meshDim=getStructuredMesh()->getMeshDimension(); + med_geometry_type geoTypeReq=GetGeoTypeFromMeshDim(meshDim); + nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _fam_cells=DataArrayInt::New(); + _fam_cells->alloc(nbOfElt,1); + MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_fam_cells->getPointer()); + } + nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf); + if(nbOfElt>0) + { + _num_cells=DataArrayInt::New(); + _num_cells->alloc(nbOfElt,1); + MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer()); } +} + +void MEDFileStructuredMesh::writeStructuredLL(med_idt fid, const char *maa) const throw(INTERP_KERNEL::Exception) +{ + int meshDim=getStructuredMesh()->getMeshDimension(); + med_geometry_type geoTypeReq=GetGeoTypeFromMeshDim(meshDim); // if((const DataArrayInt *)_fam_cells) MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_fam_cells->getNumberOfTuples(),_fam_cells->getConstPointer()); @@ -3141,170 +3165,408 @@ void MEDFileCMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str); } -int MEDFileCMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +MEDFileCMesh *MEDFileCMesh::New() +{ + return new MEDFileCMesh; +} + +MEDFileCMesh *MEDFileCMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception) { - if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) - throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : Only available for levels 0 or 1 !"); - if(!((const MEDCouplingCMesh *)_cmesh)) - throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : No cartesian mesh set !"); - if(meshDimRelToMaxExt==0) - return _cmesh->getNumberOfCells(); - else - return _cmesh->getNumberOfNodes(); + std::vector 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,MED_ACC_RDONLY); + int dt,it; + ParaMEDMEM::MEDCouplingMeshType meshType; + std::string dummy2; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2); + return new MEDFileCMesh(fid,ms.front().c_str(),dt,it); +} + +MEDFileCMesh *MEDFileCMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + return new MEDFileCMesh(fid,mName,dt,it); +} + +std::size_t MEDFileCMesh::getHeapMemorySize() const +{ + std::size_t ret=MEDFileStructuredMesh::getHeapMemorySize(); + if((const MEDCouplingCMesh *)_cmesh) + ret+=_cmesh->getHeapMemorySize(); + return ret; +} + +int MEDFileCMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception) +{ + if(!((const MEDCouplingCMesh*)_cmesh)) + throw INTERP_KERNEL::Exception("MEDFileCMesh::getMeshDimension : unable to get meshdimension because no mesh set !"); + return _cmesh->getMeshDimension(); +} + +std::string MEDFileCMesh::simpleRepr() const +{ + return MEDFileStructuredMesh::simpleRepr(); +} + +std::string MEDFileCMesh::advancedRepr() const +{ + return simpleRepr(); +} + +MEDFileMesh *MEDFileCMesh::shallowCpy() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCMesh(*this); + return ret.retn(); +} + +MEDFileMesh *MEDFileCMesh::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCMesh(*this); + if((const MEDCouplingCMesh*)_cmesh) + ret->_cmesh=static_cast(_cmesh->deepCpy()); + ret->deepCpyAttributes(); + return ret.retn(); +} + +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(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; +} + +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 char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +try + { + loadCMeshFromFile(fid,mName,dt,it); + } +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +{ + 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); +} + +const MEDCouplingCMesh *MEDFileCMesh::getMesh() const +{ + synchronizeTinyInfoOnLeaves(); + return _cmesh; +} + +const MEDCouplingStructuredMesh *MEDFileCMesh::getStructuredMesh() const +{ + synchronizeTinyInfoOnLeaves(); + return _cmesh; +} + +void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception) +{ + dealWithTinyInfo(m); + if(m) + m->incrRef(); + _cmesh=m; +} + +void MEDFileCMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) +{ + INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str); + MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str); + MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str); + int spaceDim=_cmesh->getSpaceDimension(); + int meshDim=_cmesh->getMeshDimension(); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + for(int i=0;igetCoordsAt(i)->getInfoOnComponent(0)); + std::string c,u; + MEDLoaderBase::splitIntoNameAndUnit(info,c,u); + MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + } + MEDmeshCr(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit); + MEDmeshGridTypeWr(fid,maa,MED_CARTESIAN_GRID); + for(int i=0;igetCoordsAt(i); + MEDmeshGridIndexCoordinateWr(fid,maa,_iteration,_order,_time,i+1,da->getNumberOfTuples(),da->getConstPointer()); + } + // + MEDFileStructuredMesh::writeStructuredLL(fid,maa); } void MEDFileCMesh::synchronizeTinyInfoOnLeaves() const { const MEDCouplingCMesh *cmesh=_cmesh; + if(!cmesh) + return; (const_cast(cmesh))->setName(_name.c_str()); (const_cast(cmesh))->setDescription(_desc_name.c_str()); (const_cast(cmesh))->setTime(_time,_iteration,_order); (const_cast(cmesh))->setTimeUnit(_dt_unit.c_str()); } -int MEDFileCMesh::getNumberOfNodes() const throw(INTERP_KERNEL::Exception) +MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New() { - const MEDCouplingCMesh *cmesh(_cmesh); - if(!cmesh) - throw INTERP_KERNEL::Exception("MEDFileCMesh::getNumberOfNodes : no cartesian mesh set !"); - return cmesh->getNumberOfNodes(); + return new MEDFileCurveLinearMesh; } -std::vector MEDFileCMesh::getNonEmptyLevels() const +MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception) { - std::vector ret(1); - return ret; + std::vector 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,MED_ACC_RDONLY); + int dt,it; + ParaMEDMEM::MEDCouplingMeshType meshType; + std::string dummy2; + MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2); + return new MEDFileCurveLinearMesh(fid,ms.front().c_str(),dt,it); } -std::vector MEDFileCMesh::getNonEmptyLevelsExt() const +MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) { - std::vector ret(2); - ret[0]=1; + MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); + return new MEDFileCurveLinearMesh(fid,mName,dt,it); +} + +std::size_t MEDFileCurveLinearMesh::getHeapMemorySize() const +{ + std::size_t ret=MEDFileStructuredMesh::getHeapMemorySize(); + if((const MEDCouplingCurveLinearMesh *)_clmesh) + ret+=_clmesh->getHeapMemorySize(); return ret; } -DataArrayInt *MEDFileCMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) +MEDFileMesh *MEDFileCurveLinearMesh::shallowCpy() const throw(INTERP_KERNEL::Exception) { - if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) - throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : Only available for levels 0 or 1 !"); - std::vector famIds=getFamiliesIds(fams); - if(meshDimRelToMaxExt==1) + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCurveLinearMesh(*this); + return ret.retn(); +} + +MEDFileMesh *MEDFileCurveLinearMesh::deepCpy() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret=new MEDFileCurveLinearMesh(*this); + if((const MEDCouplingCurveLinearMesh*)_clmesh) + ret->_clmesh=static_cast(_clmesh->deepCpy()); + ret->deepCpyAttributes(); + return ret.retn(); +} + +int MEDFileCurveLinearMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception) +{ + if(!((const MEDCouplingCurveLinearMesh*)_clmesh)) + throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::getMeshDimension : unable to get meshdimension because no mesh set !"); + return _clmesh->getMeshDimension(); +} + +std::string MEDFileCurveLinearMesh::simpleRepr() const +{ + return MEDFileStructuredMesh::simpleRepr(); +} + +std::string MEDFileCurveLinearMesh::advancedRepr() const +{ + return simpleRepr(); +} + +bool MEDFileCurveLinearMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const +{ + if(!MEDFileStructuredMesh::isEqual(other,eps,what)) + return false; + const MEDFileCurveLinearMesh *otherC=dynamic_cast(other); + if(!otherC) { - if((const DataArrayInt *)_fam_nodes) - { - MEDCouplingAutoRefCountObjectPtr da; - if(!famIds.empty()) - da=_fam_nodes->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size()); - else - da=_fam_nodes->getIdsEqualList(0,0); - if(renum) - return MEDFileUMeshSplitL1::Renumber(_num_nodes,da); - else - return da.retn(); - } - else - throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on nodes !"); + what="Mesh types differ ! This is curve linear and other is NOT !"; + return false; } - else + clearNonDiscrAttributes(); + otherC->clearNonDiscrAttributes(); + const MEDCouplingCurveLinearMesh *coo1=_clmesh; + const MEDCouplingCurveLinearMesh *coo2=otherC->_clmesh; + if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0)) { - if((const DataArrayInt *)_fam_cells) + what="Mismatch of curve linear meshes ! One is defined and not other !"; + return false; + } + if(coo1) + { + bool ret=coo1->isEqual(coo2,eps); + if(!ret) { - MEDCouplingAutoRefCountObjectPtr da; - if(!famIds.empty()) - da=_fam_cells->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size()); - else - da=_fam_cells->getIdsEqualList(0,0); - if(renum) - return MEDFileUMeshSplitL1::Renumber(_num_cells,da); - else - return da.retn(); + what="curve linear meshes differ !"; + return false; } - else - throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on cells !"); } + return true; } -void MEDFileCMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception) +void MEDFileCurveLinearMesh::clearNonDiscrAttributes() const { - if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) - throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !"); - if(famArr) - famArr->incrRef(); - if(meshDimRelToMaxExt==0) - _fam_cells=famArr; - else - _fam_nodes=famArr; + MEDFileStructuredMesh::clearNonDiscrAttributes(); + MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_clmesh);//to it is not a bug umeshsplit have already the method implemented } -void MEDFileCMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) +void MEDFileCurveLinearMesh::synchronizeTinyInfoOnLeaves() const { - if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) - throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !"); - if(renumArr) - renumArr->incrRef(); - if(meshDimRelToMaxExt==0) - _num_cells=renumArr; - else - _num_nodes=renumArr; + const MEDCouplingCurveLinearMesh *clmesh=_clmesh; + if(!clmesh) + return; + (const_cast(clmesh))->setName(_name.c_str()); + (const_cast(clmesh))->setDescription(_desc_name.c_str()); + (const_cast(clmesh))->setTime(_time,_iteration,_order); + (const_cast(clmesh))->setTimeUnit(_dt_unit.c_str()); } -const DataArrayInt *MEDFileCMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +const MEDCouplingCurveLinearMesh *MEDFileCurveLinearMesh::getMesh() const { - if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) - throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamilyFieldAtLevel : Only available for levels 0 or 1 !"); - if(meshDimRelToMaxExt==0) - return _fam_cells; - else - return _fam_nodes; + synchronizeTinyInfoOnLeaves(); + return _clmesh; } -const DataArrayInt *MEDFileCMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +void MEDFileCurveLinearMesh::setMesh(MEDCouplingCurveLinearMesh *m) throw(INTERP_KERNEL::Exception) { - if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) - throw INTERP_KERNEL::Exception("MEDFileCMesh::getNumberFieldAtLevel : Only available for levels 0 or 1 !"); - if(meshDimRelToMaxExt==0) - return _num_cells; - else - return _num_nodes; + dealWithTinyInfo(m); + if(m) + m->incrRef(); + _clmesh=m; } -const DataArrayInt *MEDFileCMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) +const MEDCouplingStructuredMesh *MEDFileCurveLinearMesh::getStructuredMesh() const { - if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1) - throw INTERP_KERNEL::Exception("MEDFileCMesh::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 + synchronizeTinyInfoOnLeaves(); + return _clmesh; +} + +MEDFileCurveLinearMesh::MEDFileCurveLinearMesh() +{ +} + +MEDFileCurveLinearMesh::MEDFileCurveLinearMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) +try + { + loadCLMeshFromFile(fid,mName,dt,it); + } +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +void MEDFileCurveLinearMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) +{ + INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); + INTERP_KERNEL::AutoPtr dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); + MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str); + MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str); + MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str); + int spaceDim=_clmesh->getSpaceDimension(); + int meshDim=_clmesh->getMeshDimension(); + INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); + const DataArrayDouble *coords=_clmesh->getCoords(); + if(!coords) + throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::writeLL : no coordinates set !"); + for(int i=0;igetMaxValue(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 !"); + std::string info(_clmesh->getCoords()->getInfoOnComponent(i)); + std::string c,u; + MEDLoaderBase::splitIntoNameAndUnit(info,c,u); + MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo + MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo } + MEDmeshCr(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit); + MEDmeshGridTypeWr(fid,maa,MED_CURVILINEAR_GRID); + std::vector nodeGridSt=_clmesh->getNodeGridStructure(); + MEDmeshGridStructWr(fid,maa,_iteration,_order,_time,&nodeGridSt[0]); + + MEDmeshNodeCoordinateWr(fid,maa,_iteration,_order,_time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->begin()); + // + MEDFileStructuredMesh::writeStructuredLL(fid,maa); } -/*! - * no implementation here, it is not a bug, but intresically no polyhedra in \a this. - */ -bool MEDFileCMesh::unPolyze(std::vector& oldCode, std::vector& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception) +void MEDFileCurveLinearMesh::loadCLMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception) { - oldCode.clear(); newCode.clear(); o2nRenumCell=0; - return false; + ParaMEDMEM::MEDCouplingMeshType meshType; + int dummy0,dummy1; + std::string dtunit; + int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit); + if(meshType!=CURVE_LINEAR) + { + std::ostringstream oss; oss << "Trying to load as curve linear an existing mesh with name '" << mName << "' that is NOT curve linear !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDFileCLMeshL2 loaderl2; + loaderl2.loadAll(fid,mid,mName,dt,it); + MEDCouplingCurveLinearMesh *mesh=loaderl2.getMesh(); + mesh->incrRef(); + _clmesh=mesh; + loadStrMeshFromFile(&loaderl2,fid,mName,dt,it); } MEDFileMeshMultiTS *MEDFileMeshMultiTS::New() diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index ef5f8fc9e..eb1e5bb37 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -248,7 +248,45 @@ namespace ParaMEDMEM mutable MEDCouplingAutoRefCountObjectPtr _rev_num_coords; }; - class MEDLOADER_EXPORT MEDFileCMesh : public MEDFileMesh + class MEDLOADER_EXPORT MEDFileStructuredMesh : public MEDFileMesh + { + friend class MEDFileMesh; + public: + std::size_t getHeapMemorySize() const; + int getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception); + int getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception); + bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; + void clearNonDiscrAttributes() const; + DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); + const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception); + void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception); + const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + std::vector getNonEmptyLevels() const; + std::vector getNonEmptyLevelsExt() const; + MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception); + int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); + int getNumberOfNodes() const throw(INTERP_KERNEL::Exception); + // tools + bool unPolyze(std::vector& oldCode, std::vector& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception); + protected: + void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception); + void deepCpyAttributes() throw(INTERP_KERNEL::Exception); + void loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); + void writeStructuredLL(med_idt fid, const char *maa) const throw(INTERP_KERNEL::Exception); + virtual const MEDCouplingStructuredMesh *getStructuredMesh() const = 0; + static med_geometry_type GetGeoTypeFromMeshDim(int meshDim) throw(INTERP_KERNEL::Exception); + private: + MEDCouplingAutoRefCountObjectPtr _fam_nodes; + MEDCouplingAutoRefCountObjectPtr _num_nodes; + MEDCouplingAutoRefCountObjectPtr _fam_cells; + MEDCouplingAutoRefCountObjectPtr _num_cells; + mutable MEDCouplingAutoRefCountObjectPtr _rev_num_nodes; + mutable MEDCouplingAutoRefCountObjectPtr _rev_num_cells; + }; + + class MEDLOADER_EXPORT MEDFileCMesh : public MEDFileStructuredMesh { friend class MEDFileMesh; public: @@ -259,42 +297,49 @@ namespace ParaMEDMEM MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception); MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception); bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; - int getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception); - int getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception); int getMeshDimension() const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; std::string advancedRepr() const; void clearNonDiscrAttributes() const; const MEDCouplingCMesh *getMesh() const; - MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception); void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception); - int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); - DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); - void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception); - void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception); - int getNumberOfNodes() const throw(INTERP_KERNEL::Exception); - std::vector getNonEmptyLevels() const; - std::vector getNonEmptyLevelsExt() const; - const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); - const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); - const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); - // tools - bool unPolyze(std::vector& oldCode, std::vector& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception); private: + const MEDCouplingStructuredMesh *getStructuredMesh() const; void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); MEDFileCMesh(); void synchronizeTinyInfoOnLeaves() const; MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); void loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); - void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception); private: MEDCouplingAutoRefCountObjectPtr _cmesh; - MEDCouplingAutoRefCountObjectPtr _fam_nodes; - MEDCouplingAutoRefCountObjectPtr _num_nodes; - MEDCouplingAutoRefCountObjectPtr _fam_cells; - MEDCouplingAutoRefCountObjectPtr _num_cells; - mutable MEDCouplingAutoRefCountObjectPtr _rev_num_nodes; - mutable MEDCouplingAutoRefCountObjectPtr _rev_num_cells; + }; + + class MEDLOADER_EXPORT MEDFileCurveLinearMesh : public MEDFileStructuredMesh + { + friend class MEDFileMesh; + public: + static MEDFileCurveLinearMesh *New(); + static MEDFileCurveLinearMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileCurveLinearMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); + std::size_t getHeapMemorySize() const; + MEDFileMesh *deepCpy() const throw(INTERP_KERNEL::Exception); + MEDFileMesh *shallowCpy() const throw(INTERP_KERNEL::Exception); + bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; + int getMeshDimension() const throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + std::string advancedRepr() const; + void clearNonDiscrAttributes() const; + const MEDCouplingCurveLinearMesh *getMesh() const; + void setMesh(MEDCouplingCurveLinearMesh *m) throw(INTERP_KERNEL::Exception); + private: + MEDFileCurveLinearMesh(); + MEDFileCurveLinearMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); + const MEDCouplingStructuredMesh *getStructuredMesh() const; + void synchronizeTinyInfoOnLeaves() const; + void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); + void loadCLMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);//to imp + private: + MEDCouplingAutoRefCountObjectPtr _clmesh; }; class MEDLOADER_EXPORT MEDFileMeshMultiTS : public RefCountObject, public MEDFileWritable diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 09c249705..e6851db84 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -81,8 +81,22 @@ int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const char *mname, ParaMEDMEM: meshType=UNSTRUCTURED; break; case MED_STRUCTURED_MESH: - meshType=CARTESIAN; - break; + { + med_grid_type gt; + MEDmeshGridTypeRd(fid,mname,>); + switch(gt) + { + case MED_CARTESIAN_GRID: + meshType=CARTESIAN; + break; + case MED_CURVILINEAR_GRID: + meshType=CURVE_LINEAR; + break; + default: + throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); + } + break; + } default: throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !"); } @@ -135,8 +149,22 @@ std::vector MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, meshType=UNSTRUCTURED; break; case MED_STRUCTURED_MESH: - meshType=CARTESIAN; - break; + { + med_grid_type gt; + MEDmeshGridTypeRd(fid,mName,>); + switch(gt) + { + case MED_CARTESIAN_GRID: + meshType=CARTESIAN; + break; + case MED_CURVILINEAR_GRID: + meshType=CURVE_LINEAR; + break; + default: + throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n"); + } + break; + } default: throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !"); } @@ -334,7 +362,7 @@ void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, in med_grid_type gridtype; MEDmeshGridTypeRd(fid,mName,&gridtype); if(gridtype!=MED_CARTESIAN_GRID) - throw INTERP_KERNEL::Exception("Invalid cartesion mesh type ! Only Cartesian Grid supported ! Curvilinear grid will come soon !"); + throw INTERP_KERNEL::Exception("Invalid structured mesh ! Expected cartesian mesh type !"); _cmesh=MEDCouplingCMesh::New(); for(int i=0;i infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim); + if(meshType!=CURVE_LINEAR) + throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !"); + _time=CheckMeshTimeStep(fid,mName,nstep,dt,it); + _iteration=dt; + _order=it; + // + _clmesh=MEDCouplingCurveLinearMesh::New(); + INTERP_KERNEL::AutoPtr stGrid=new int[Mdim]; + MEDmeshGridStructRd(fid,mName,dt,it,stGrid); + _clmesh->setNodeGridStructure(stGrid,((int *)stGrid)+Mdim); + med_bool chgt=MED_FALSE,trsf=MED_FALSE; + int nbNodes=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf); + MEDCouplingAutoRefCountObjectPtr da=DataArrayDouble::New(); + da->alloc(nbNodes,infosOnComp.size()); + da->setInfoOnComponents(infosOnComp); + MEDmeshNodeCoordinateRd(fid,mName,dt,it,MED_FULL_INTERLACE,da->getPointer()); + _clmesh->setCoords(da); +} + MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0) { } diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 220d09cf7..07306af54 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -26,6 +26,7 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingCMesh.hxx" +#include "MEDCouplingCurveLinearMesh.hxx" #include "MEDCouplingAutoRefCountObjectPtr.hxx" #include "med.h" @@ -84,7 +85,11 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _num_coords; }; - class MEDFileCMeshL2 : public MEDFileMeshL2 + class MEDFileStrMeshL2 : public MEDFileMeshL2 + { + }; + + class MEDFileCMeshL2 : public MEDFileStrMeshL2 { public: MEDFileCMeshL2(); @@ -95,6 +100,16 @@ namespace ParaMEDMEM private: MEDCouplingAutoRefCountObjectPtr _cmesh; }; + + class MEDFileCLMeshL2 : public MEDFileStrMeshL2 + { + public: + MEDFileCLMeshL2(); + void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); + MEDCouplingCurveLinearMesh *getMesh() { return _clmesh; } + private: + MEDCouplingAutoRefCountObjectPtr _clmesh; + }; class MEDFileMesh; class MEDFileUMeshSplitL1; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 59a2a8508..84736406e 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -80,6 +80,7 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM3Mesh; %newobject ParaMEDMEM::MEDFileUMesh::zipCoords; %newobject ParaMEDMEM::MEDFileCMesh::New; +%newobject ParaMEDMEM::MEDFileCurveLinearMesh::New; %newobject ParaMEDMEM::MEDFileMeshMultiTS::New; %newobject ParaMEDMEM::MEDFileMeshMultiTS::deepCpy; %newobject ParaMEDMEM::MEDFileMeshMultiTS::getOneTimeStep; @@ -647,7 +648,11 @@ namespace ParaMEDMEM } }; - class MEDFileCMesh : public MEDFileMesh + class MEDFileStructuredMesh : public MEDFileMesh + { + }; + + class MEDFileCMesh : public MEDFileStructuredMesh { public: static MEDFileCMesh *New(); @@ -681,6 +686,40 @@ namespace ParaMEDMEM } }; + class MEDFileCurveLinearMesh : public MEDFileStructuredMesh + { + public: + static MEDFileCurveLinearMesh *New(); + static MEDFileCurveLinearMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception); + static MEDFileCurveLinearMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception); + void setMesh(MEDCouplingCurveLinearMesh *m) throw(INTERP_KERNEL::Exception); + %extend + { + MEDFileCurveLinearMesh() + { + return MEDFileCurveLinearMesh::New(); + } + + MEDFileCurveLinearMesh(const char *fileName) throw(INTERP_KERNEL::Exception) + { + return MEDFileCurveLinearMesh::New(fileName); + } + + MEDFileCurveLinearMesh(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception) + { + return MEDFileCurveLinearMesh::New(fileName,mName,dt,it); + } + + PyObject *getMesh() const throw(INTERP_KERNEL::Exception) + { + const MEDCouplingCurveLinearMesh *tmp=self->getMesh(); + if(tmp) + tmp->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh, SWIG_POINTER_OWN | 0 ); + } + } + }; + class MEDFileMeshMultiTS : public RefCountObject, public MEDFileWritable { public: diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index 111fd0e2b..cbab3a4d0 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -27,6 +27,8 @@ static PyObject* convertMEDFileMesh(ParaMEDMEM::MEDFileMesh* mesh, int owner) th ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileUMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDFileCurveLinearMesh,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of MEDFileMesh on downcast !"); return ret;