X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileMesh.cxx;h=3d59c0b9544d51bdee37dc4971d4b9ba9c913750;hb=b7e277ad50223814bc479c5bd64cf12abe8fc959;hp=ce388ecac0790d91f1ec4931a32e4f61d82f4b2f;hpb=4e1030adc659b5b96dadf305ec544ffc9801076f;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index ce388ecac..3d59c0b95 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -19,26 +19,31 @@ // Author : Anthony Geay (CEA/DEN) #include "MEDFileMesh.hxx" -#include "MEDFileUtilities.hxx" #include "MEDFileFieldOverView.hxx" #include "MEDFileField.hxx" #include "MEDLoader.hxx" +#include "MEDLoaderNS.hxx" #include "MEDFileSafeCaller.txx" #include "MEDLoaderBase.hxx" #include "MEDCouplingUMesh.hxx" +#include "MEDCouplingMappedExtrudedMesh.hxx" #include "InterpKernelAutoPtr.hxx" #include #include +extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO]; +extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO]; extern med_geometry_type typmai3[34]; using namespace MEDCoupling; const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO"; +const char MEDFileUMesh::SPE_FAM_STR_EXTRUDED_MESH[]="HIDDEN_FAM_EXT_MESH@"; + MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.),_univ_wr_status(true),_axis_type(AX_CART) { } @@ -76,15 +81,19 @@ std::vector MEDFileMesh::getDirectChildrenWithNull() co */ MEDFileMesh *MEDFileMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs) { - std::vector ms=MEDCoupling::GetMeshNames(fileName); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,mrs); +} + +MEDFileMesh *MEDFileMesh::New(med_idt fid, MEDFileMeshReadSelector *mrs) +{ + std::vector ms(MEDLoaderNS::getMeshNamesFid(fid)); if(ms.empty()) { - std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << fileName << "\" !"; + std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << FileNameFromFID(fid) << "\" !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MEDFileUtilities::CheckFileForRead(fileName); MEDCoupling::MEDCouplingMeshType meshType; - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY); int dt,it; std::string dummy2; MEDCoupling::MEDCouplingAxisType dummy3; @@ -136,9 +145,13 @@ MEDFileMesh *MEDFileMesh::New(const std::string& fileName, MEDFileMeshReadSelect */ MEDFileMesh *MEDFileMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs, MEDFileJoints* joints) { - MEDFileUtilities::CheckFileForRead(fileName); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,mName,dt,it,mrs,joints); +} + +MEDFileMesh *MEDFileMesh::New(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs, MEDFileJoints* joints) +{ MEDCoupling::MEDCouplingMeshType meshType; - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY); int dummy0,dummy1; std::string dummy2; MEDCoupling::MEDCouplingAxisType dummy3; @@ -178,36 +191,17 @@ MEDFileMesh *MEDFileMesh::New(const std::string& fileName, const std::string& mN * \throw If the file is open for reading only. * \throw If the writing mode == 1 and the same data is present in an existing file. */ -void MEDFileMesh::write(med_idt fid) const +void MEDFileMesh::writeLL(med_idt fid) const { if(!existsFamily(0)) const_cast(this)->addFamily(DFT_FAM_NAME,0); if(_name.empty()) throw INTERP_KERNEL::Exception("MEDFileMesh : name is empty. MED file ask for a NON EMPTY name !"); - writeLL(fid); + writeMeshLL(fid); writeJoints(fid); const MEDFileEquivalences *eqs(_equiv); if(eqs) - eqs->write(fid); -} - -/*! - * Writes \a this mesh into a MED file specified by its name. - * \param [in] fileName - the MED file name. - * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics. - * - 2 - erase; an existing file is removed. - * - 1 - append; same data should not be present in an existing file. - * - 0 - overwrite; same data present in an existing file is overwritten. - * \throw If the mesh name is not set. - * \throw If \a mode == 1 and the same data is present in an existing file. - */ -void MEDFileMesh::write(const std::string& fileName, int mode) const -{ - med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod); - std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\""; - MEDFileUtilities::CheckMEDCode(fid,fid,oss.str()); - write(fid); + eqs->writeLL(fid); } /*! @@ -1432,11 +1426,10 @@ void MEDFileMesh::setGroupInfo(const std::map::const_iterator it=_families.find(oname); - std::vector fams=getFamiliesNames(); + std::map::const_iterator it=_families.find(name); if(it==_families.end()) { + std::vector fams(getFamiliesNames()); std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :"; std::copy(fams.begin(),fams.end(),std::ostream_iterator(oss," ")); throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -2091,6 +2084,9 @@ std::vector MEDFileMesh::getAllGeoTypes() con return ret; } +/*! + * \sa getAllDistributionOfTypes + */ std::vector MEDFileMesh::getDistributionOfTypes(int meshDimRelToMax) const { MCAuto mLev(getMeshAtLevel(meshDimRelToMax)); @@ -2238,8 +2234,12 @@ void MEDFileMesh::getFamilyRepr(std::ostream& oss) const */ MEDFileUMesh *MEDFileUMesh::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); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,mName,dt,it,mrs); +} + +MEDFileUMesh *MEDFileUMesh::New(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs) +{ return new MEDFileUMesh(fid,mName,dt,it,mrs); } @@ -2255,20 +2255,49 @@ MEDFileUMesh *MEDFileUMesh::New(const std::string& fileName, const std::string& */ MEDFileUMesh *MEDFileUMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs) { - std::vector ms(MEDCoupling::GetMeshNames(fileName)); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,mrs); +} + +template +T *NewForTheFirstMeshInFile(med_idt fid, MEDFileMeshReadSelector *mrs) +{ + std::vector ms(MEDLoaderNS::getMeshNamesFid(fid)); if(ms.empty()) { - std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !"; + std::ostringstream oss; oss << MLMeshTraits::ClassName << "::New : no meshes in file \"" << MEDFileWritable::FileNameFromFID(fid) << "\" !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MEDFileUtilities::CheckFileForRead(fileName); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY); int dt,it; MEDCoupling::MEDCouplingMeshType meshType; std::string dummy2; MEDCoupling::MEDCouplingAxisType dummy3; MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2); - return new MEDFileUMesh(fid,ms.front(),dt,it,mrs); + return T::New(fid,ms.front(),dt,it,mrs); +} + +MEDFileUMesh *MEDFileUMesh::New(med_idt fid, MEDFileMeshReadSelector *mrs) +{ + return NewForTheFirstMeshInFile(fid,mrs); +} + +/*! + * \b WARNING this implementation is dependant from MEDCouplingMappedExtrudedMesh::buildUnstructured ! + * \sa MEDCouplingMappedExtrudedMesh::buildUnstructured , MEDCouplingMappedExtrudedMesh::build3DUnstructuredMesh + */ +MEDFileUMesh *MEDFileUMesh::New(const MEDCouplingMappedExtrudedMesh *mem) +{ + if(!mem) + throw INTERP_KERNEL::Exception("MEDFileUMesh::New : null input vector !"); + MCAuto ret(MEDFileUMesh::New()); + MCAuto m3D(mem->buildUnstructured()); + MCAuto m2D(mem->getMesh2D()->deepCopy()); + m2D->zipCoords(); + m2D->setCoords(m3D->getCoords()); + ret->setMeshAtLevel(0,m3D); + ret->setMeshAtLevel(-1,m2D); + ret->setFamilyId(GetSpeStr4ExtMesh(),std::numeric_limits::max()-mem->get2DCellIdForExtrusion()); + return ret.retn(); } /*! @@ -2318,7 +2347,7 @@ MEDFileUMesh *MEDFileUMesh::LoadPartOf(med_idt fid, const std::string& mName, co std::size_t MEDFileUMesh::getHeapMemorySizeWithoutChildren() const { std::size_t ret(MEDFileMesh::getHeapMemorySizeWithoutChildren()); - ret+=_ms.capacity()*(sizeof(MCAuto)); + ret+=_ms.capacity()*(sizeof(MCAuto))+_elt_str.capacity()*sizeof(MCAuto); return ret; } @@ -2333,10 +2362,12 @@ std::vector MEDFileUMesh::getDirectChildrenWithNull() c ret.push_back((const PartDefinition *)_part_coords); for(std::vector< MCAuto >::const_iterator it=_ms.begin();it!=_ms.end();it++) ret.push_back((const MEDFileUMeshSplitL1*) *it); + for(std::vector< MCAuto >::const_iterator it=_elt_str.begin();it!=_elt_str.end();it++) + ret.push_back((const MEDFileEltStruct4Mesh *)*it); return ret; } -MEDFileMesh *MEDFileUMesh::shallowCpy() const +MEDFileUMesh *MEDFileUMesh::shallowCpy() const { MCAuto ret(new MEDFileUMesh(*this)); return ret.retn(); @@ -2347,7 +2378,7 @@ MEDFileMesh *MEDFileUMesh::createNewEmpty() const return new MEDFileUMesh; } -MEDFileMesh *MEDFileUMesh::deepCopy() const +MEDFileUMesh *MEDFileUMesh::deepCopy() const { MCAuto ret(new MEDFileUMesh(*this)); ret->deepCpyEquivalences(*this); @@ -2640,7 +2671,7 @@ void MEDFileUMesh::loadPartUMeshFromFile(med_idt fid, const std::string& mName, int dummy0,dummy1; std::string dummy2; MEDCoupling::MEDCouplingAxisType dummy3; - int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy3,dummy0,dummy1,dummy2)); + INTERP_KERNEL::AutoCppPtr mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy3,dummy0,dummy1,dummy2)); if(meshType!=UNSTRUCTURED) { std::ostringstream oss; oss << "loadPartUMeshFromFile : Trying to load as unstructured an existing mesh with name '" << mName << "' !"; @@ -2655,8 +2686,8 @@ void MEDFileUMesh::loadPartUMeshFromFile(med_idt fid, const std::string& mName, */ void MEDFileMesh::writeJoints(med_idt fid) const { - if ( (const MEDFileJoints*) _joints ) - _joints->write(fid); + if ( _joints.isNotNull() ) + _joints->writeLL(fid); } /*! @@ -2767,7 +2798,7 @@ void MEDFileUMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, int dummy0,dummy1; std::string dummy2; MEDCoupling::MEDCouplingAxisType axType; - int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dummy2)); + INTERP_KERNEL::AutoCppPtr mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dummy2)); setAxisType(axType); if(meshType!=UNSTRUCTURED) { @@ -2776,6 +2807,17 @@ void MEDFileUMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, } loaderl2.loadAll(fid,mid,mName,dt,it,mrs); dispatchLoadedPart(fid,loaderl2,mName,mrs); + // Structure element part... + int nModels(-1); + { + med_bool chgt=MED_FALSE,trsf=MED_FALSE; + nModels=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf); + } + if(nModels<=0) + return ; + _elt_str.resize(nModels); + for(int i=0;i maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); @@ -2831,8 +2873,8 @@ void MEDFileUMesh::writeLL(med_idt fid) const std::string info=coo->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 + MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE,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,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo } MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MEDFileMeshL2::TraduceAxisTypeRev(getAxisType()),comp,unit)); if(_univ_wr_status) @@ -3272,6 +3314,19 @@ MEDFileMesh *MEDFileUMesh::cartesianize() const } } +bool MEDFileUMesh::presenceOfStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_elt_str.begin();it!=_elt_str.end();it++) + if((*it).isNotNull()) + return true; + return false; +} + +void MEDFileUMesh::killStructureElements() +{ + _elt_str.clear(); +} + /*! * Returns the optional numbers of mesh entities of a given dimension transformed using * DataArrayInt::invertArrayN2O2O2N(). @@ -3589,6 +3644,30 @@ MEDCoupling1GTUMesh *MEDFileUMesh::getDirectUndergroundSingleGeoTypeMesh(INTERP_ return sp->getDirectUndergroundSingleGeoTypeMesh(gt); } +/*! + * This method returns for each geo types in \a this number of cells with this geo type. + * This method returns info as a vector of pair. The first element of pair is geo type and the second the number of cells associated. + * This method also returns the number of nodes of \a this (key associated is NORM_ERROR) + * + * \sa getDistributionOfTypes + */ +std::vector< std::pair > MEDFileUMesh::getAllDistributionOfTypes() const +{ + std::vector< std::pair > ret; + std::vector nel(getNonEmptyLevels()); + for(std::vector::reverse_iterator it=nel.rbegin();it!=nel.rend();it++) + { + std::vector gt(getGeoTypesAtLevel(*it)); + for(std::vector::const_iterator it1=gt.begin();it1!=gt.end();it1++) + { + int nbCells(getNumberOfCellsWithType(*it1)); + ret.push_back(std::pair(*it1,nbCells)); + } + } + ret.push_back(std::pair(INTERP_KERNEL::NORM_ERROR,getNumberOfNodes())); + return ret; +} + /*! * Given a relative level \a meshDimRelToMax it returns the sorted vector of geometric types present in \a this. * \throw if the reqsuested \a meshDimRelToMax does not exist. @@ -3704,12 +3783,42 @@ void MEDFileUMesh::setCoords(DataArrayDouble *coords) if(coords==(DataArrayDouble *)_coords) return ; coords->checkAllocated(); - int nbOfTuples=coords->getNumberOfTuples(); + int nbOfTuples(coords->getNumberOfTuples()); _coords=coords; coords->incrRef(); _fam_coords=DataArrayInt::New(); _fam_coords->alloc(nbOfTuples,1); _fam_coords->fillWithZero(); + _num_coords=0; _rev_num_coords=0; _name_coords=0; + for(std::vector< MCAuto >::iterator it=_ms.begin();it!=_ms.end();it++) + if((MEDFileUMeshSplitL1 *)(*it)) + (*it)->setCoords(coords); +} + +/*! + * Change coords without changing anything concerning families and numbering on nodes. + */ +void MEDFileUMesh::setCoordsForced(DataArrayDouble *coords) +{ + if(!coords) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setCoordsForced : null pointer in input !"); + if(coords==(DataArrayDouble *)_coords) + return ; + coords->checkAllocated(); + int nbOfTuples(coords->getNumberOfTuples()); + if(_coords.isNull()) + { + _coords=coords; + coords->incrRef(); + } + else + { + int oldNbTuples(_coords->getNumberOfTuples()); + if(oldNbTuples!=nbOfTuples) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setCoordsForced : number of tuples is not the same -> invoke setCoords instead !"); + _coords=coords; + coords->incrRef(); + } for(std::vector< MCAuto >::iterator it=_ms.begin();it!=_ms.end();it++) if((MEDFileUMeshSplitL1 *)(*it)) (*it)->setCoords(coords); @@ -3911,7 +4020,10 @@ void MEDFileUMesh::buildInnerBoundaryAlongM1Group(const std::string& grpNameM1, cellsNotModified=cellsToModifyConn1.retn(); } -/*! +/*! Similar to MEDCouplingUMesh::unPolyze(): converts all polygons (if \a this is a 2D mesh) or polyhedrons + * (if \a this is a 3D mesh) to cells of classical types. The cells remain correctly sorted by geometric type + * in this method. + * * \param [out] oldCode retrieves the distribution of types before the call if true is returned * \param [out] newCode etrieves the distribution of types after the call if true is returned * \param [out] o2nRenumCell tells for **all levels** the old 2 new renumbering of cells. @@ -4060,6 +4172,108 @@ DataArrayInt *MEDFileUMesh::zipCoords() return ret.retn(); } +/*! + * This method is a const method. It computes the minimal set of node ids covered by the cell extraction of \a this. + * The extraction of \a this is specified by the extractDef \a input map. + * This map tells for each level of cells, the cells kept in the extraction. + * + * \return - a new reference of DataArrayInt that represents sorted node ids, the extraction is lying on. + * \sa MEDFileField1TS::extractPart, MEDFileUMesh::extractPart + */ +DataArrayInt *MEDFileUMesh::deduceNodeSubPartFromCellSubPart(const std::map >& extractDef) const +{ + std::vector levs(getNonEmptyLevels()); + std::vector fetchedNodes(getNumberOfNodes(),false); + for(std::map >::const_iterator it=extractDef.begin();it!=extractDef.end();it++) + { + if((*it).first>1) + throw INTERP_KERNEL::Exception("MEDFileUMesh::deduceNodeSubPartFromCellSubPart : invalid key ! Must be <=1 !"); + if((*it).second.isNull()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::deduceNodeSubPartFromCellSubPart : presence of a value with null pointer !"); + if((*it).first==1) + continue; + if(std::find(levs.begin(),levs.end(),(*it).first)==levs.end()) + { + std::ostringstream oss; oss << "MEDFileUMesh::deduceNodeSubPartFromCellSubPart : invalid level " << (*it).first << " ! Not present in this !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + MCAuto m(getMeshAtLevel((*it).first)); + MCAuto mPart(m->buildPartOfMySelf((*it).second->begin(),(*it).second->end(),true)); + mPart->computeNodeIdsAlg(fetchedNodes); + } + return DataArrayInt::BuildListOfSwitchedOn(fetchedNodes); +} + +/*! + * This method returns a new MEDFileUMesh that is the result of the extraction of cells/nodes in \a this. + * + * \return - a new reference of MEDFileUMesh + * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart, MEDFileFields::extractPart + */ +MEDFileUMesh *MEDFileUMesh::extractPart(const std::map >& extractDef) const +{ + MCAuto ret(MEDFileUMesh::New()); ret->setName(getName()); ret->copyFamGrpMapsFrom(*this); + std::vector levs(getNonEmptyLevels()); + for(std::map >::const_iterator it=extractDef.begin();it!=extractDef.end();it++) + { + if((*it).first>1) + throw INTERP_KERNEL::Exception("MEDFileUMesh::extractPart : invalid key ! Must be <=1 !"); + if((*it).second.isNull()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::extractPart : presence of a value with null pointer !"); + if((*it).first==1) + continue; + if(std::find(levs.begin(),levs.end(),(*it).first)==levs.end()) + { + std::ostringstream oss; oss << "MEDFileUMesh::extractPart : invalid level " << (*it).first << " ! Not present in this !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + MCAuto m(getMeshAtLevel((*it).first)); + MCAuto mPart(m->buildPartOfMySelf((*it).second->begin(),(*it).second->end(),true)); + ret->setMeshAtLevel((*it).first,mPart); + const DataArrayInt *fam(getFamilyFieldAtLevel((*it).first)),*num(getNumberFieldAtLevel((*it).first)); + if(fam) + { + MCAuto famPart(fam->selectByTupleIdSafe((*it).second->begin(),(*it).second->end())); + ret->setFamilyFieldArr((*it).first,famPart); + } + if(num) + { + MCAuto numPart(num->selectByTupleIdSafe((*it).second->begin(),(*it).second->end())); + ret->setFamilyFieldArr((*it).first,numPart); + } + } + std::map >::const_iterator it2(extractDef.find(1)); + if(it2!=extractDef.end()) + { + const DataArrayDouble *coo(ret->getCoords()); + if(!coo) + throw INTERP_KERNEL::Exception("MEDFileUMesh::extractPart : trying to extract nodes whereas there is no nodes !"); + MCAuto o2nNodes(((*it2).second)->invertArrayN2O2O2N(coo->getNumberOfTuples())); + MCAuto cooPart(coo->selectByTupleIdSafe((*it2).second->begin(),(*it2).second->end())); + ret->setCoords(cooPart); + const DataArrayInt *fam(getFamilyFieldAtLevel(1)),*num(getNumberFieldAtLevel(1)); + if(fam) + { + MCAuto famPart(fam->selectByTupleIdSafe((*it2).second->begin(),(*it2).second->end())); + ret->setFamilyFieldArr(1,famPart); + } + if(num) + { + MCAuto numPart(num->selectByTupleIdSafe((*it2).second->begin(),(*it2).second->end())); + ret->setFamilyFieldArr(1,numPart); + } + for(std::map >::const_iterator it3=extractDef.begin();it3!=extractDef.end();it3++) + { + if((*it3).first==1) + continue; + MCAuto m(ret->getMeshAtLevel((*it3).first)); + m->renumberNodesInConn(o2nNodes->begin()); + ret->setMeshAtLevel((*it3).first,m); + } + } + return ret.retn(); +} + /*! * This method performs an extrusion along a path defined by \a m1D. * \a this is expected to be a mesh with max mesh dimension equal to 2. @@ -4349,6 +4563,132 @@ MEDFileUMesh *MEDFileUMesh::quadraticToLinear(double eps) const return ret.retn(); } +/*! + * Computes the symmetry of \a this. + * \return a new object. + */ +MCAuto MEDFileUMesh::symmetry3DPlane(const double point[3], const double normalVector[3]) const +{ + MCAuto ret(deepCopy()); + DataArrayDouble *myCoo(getCoords()); + if(myCoo) + { + MCAuto newCoo(myCoo->symmetry3DPlane(point,normalVector)); + ret->setCoordsForced(newCoo); + } + return ret; +} + +MCAuto MEDFileUMesh::Aggregate(const std::vector& meshes) +{ + if(meshes.empty()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::Aggregate : empty input vector !"); + std::size_t sz(meshes.size()),i(0); + std::vector coos(sz); + std::vector fam_coos(sz),num_coos(sz); + for(std::vector::const_iterator it=meshes.begin();it!=meshes.end();it++,i++) + { + if(!(*it)) + throw INTERP_KERNEL::Exception("MEDFileUMesh::Aggregate : presence of NULL pointer in input vector !"); + coos[i]=(*it)->getCoords(); + fam_coos[i]=(*it)->getFamilyFieldAtLevel(1); + num_coos[i]=(*it)->getNumberFieldAtLevel(1); + } + const MEDFileUMesh *ref(meshes[0]); + int spaceDim(ref->getSpaceDimension()),meshDim(ref->getMeshDimension()); + std::vector levs(ref->getNonEmptyLevels()); + std::map > m_fam,m_renum; + std::map > > m_mesh2; + std::map > m_mesh; + std::map map1; + std::map > map2; + for(std::vector::const_iterator it=meshes.begin();it!=meshes.end();it++,i++) + { + if((*it)->getSpaceDimension()!=spaceDim) + throw INTERP_KERNEL::Exception("MEDFileUMesh::Aggregate : space dimension must be homogeneous !"); + if((*it)->getMeshDimension()!=meshDim) + throw INTERP_KERNEL::Exception("MEDFileUMesh::Aggregate : mesh dimension must be homogeneous !"); + if((*it)->getNonEmptyLevels()!=levs) + throw INTERP_KERNEL::Exception("MEDFileUMesh::Aggregate : levels must be the same for elements in input vector !"); + for(std::vector::const_iterator it2=levs.begin();it2!=levs.end();it2++) + { + MCAuto locMesh((*it)->getMeshAtLevel(*it2)); + m_mesh[*it2].push_back(locMesh); m_mesh2[*it2].push_back(locMesh); + m_fam[*it2].push_back((*it)->getFamilyFieldAtLevel(*it2)); + m_renum[*it2].push_back((*it)->getNumberFieldAtLevel(*it2)); + } + const std::map& locMap1((*it)->getFamilyInfo()); + for(std::map::const_iterator it3=locMap1.begin();it3!=locMap1.end();it3++) + map1[(*it3).first]=(*it3).second; + const std::map >& locMap2((*it)->getGroupInfo()); + for(std::map >::const_iterator it4=locMap2.begin();it4!=locMap2.end();it4++) + map2[(*it4).first]=(*it4).second; + } + // Easy part : nodes + MCAuto ret(MEDFileUMesh::New()); + MCAuto coo(DataArrayDouble::Aggregate(coos)); + ret->setCoords(coo); + if(std::find(fam_coos.begin(),fam_coos.end(),(const DataArrayInt *)0)==fam_coos.end()) + { + MCAuto fam_coo(DataArrayInt::Aggregate(fam_coos)); + ret->setFamilyFieldArr(1,fam_coo); + } + if(std::find(num_coos.begin(),num_coos.end(),(const DataArrayInt *)0)==num_coos.end()) + { + MCAuto num_coo(DataArrayInt::Aggregate(num_coos)); + ret->setRenumFieldArr(1,num_coo); + } + // cells + for(std::vector::const_iterator it=levs.begin();it!=levs.end();it++) + { + std::map >::const_iterator it2(m_mesh.find(*it)); + if(it2==m_mesh.end()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::Aggregate : internal error 1 !"); + MCAuto mesh(MEDCouplingUMesh::MergeUMeshes((*it2).second)); + mesh->setCoords(coo); mesh->setName(ref->getName()); + MCAuto renum(mesh->sortCellsInMEDFileFrmt()); + ret->setMeshAtLevel(*it,mesh); + std::map >::const_iterator it3(m_fam.find(*it)),it4(m_renum.find(*it)); + if(it3!=m_fam.end()) + { + const std::vector& fams((*it3).second); + if(std::find(fams.begin(),fams.end(),(const DataArrayInt *)0)==fams.end()) + { + MCAuto famm(DataArrayInt::Aggregate(fams)); + famm->renumberInPlace(renum->begin()); + ret->setFamilyFieldArr(*it,famm); + } + } + if(it4!=m_renum.end()) + { + const std::vector& renums((*it4).second); + if(std::find(renums.begin(),renums.end(),(const DataArrayInt *)0)==renums.end()) + { + MCAuto renumm(DataArrayInt::Aggregate(renums)); + renumm->renumberInPlace(renum->begin()); + ret->setRenumFieldArr(*it,renumm); + } + } + } + // + ret->setFamilyInfo(map1); + ret->setGroupInfo(map2); + ret->setName(ref->getName()); + return ret; +} + +MEDCouplingMappedExtrudedMesh *MEDFileUMesh::convertToExtrudedMesh() const +{ + if(getMeshDimension()!=3) + throw INTERP_KERNEL::Exception("MEDFileUMesh::convertToExtrudedMesh : works only for 3D mesh !"); + MCAuto m3D(getMeshAtLevel(0)),m2D(getMeshAtLevel(-1)); + if(m3D.isNull() || m2D.isNull()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::convertToExtrudedMesh : this must be defined both at level 0 and level -1 !"); + int zeId(std::numeric_limits::max()-getFamilyId(GetSpeStr4ExtMesh())); + MCAuto ret(MEDCouplingMappedExtrudedMesh::New(m3D,m2D,zeId)); + return ret.retn(); +} + void MEDFileUMesh::serialize(std::vector& tinyDouble, std::vector& tinyInt, std::vector& tinyStr, std::vector< MCAuto >& bigArraysI, MCAuto& bigArrayD) { clearNonDiscrAttributes(); @@ -5301,22 +5641,25 @@ void MEDFileStructuredMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayI { case 0: { - int nbCells=mesh->getNumberOfCells(); - famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of cells of mesh !"); + int nbCells(mesh->getNumberOfCells()); + if(famArr) + famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of cells of mesh !"); _fam_cells=famArr; break; } case 1: { - int nbNodes=mesh->getNumberOfNodes(); - famArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); + int nbNodes(mesh->getNumberOfNodes()); + if(famArr) + famArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); _fam_nodes=famArr; break; } case -1: { - int nbCells=mesh->getNumberOfCellsOfSubLevelMesh(); - famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of faces of mesh !"); + int nbCells(mesh->getNumberOfCellsOfSubLevelMesh()); + if(famArr) + famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of faces of mesh !"); _fam_faces=famArr; break; } @@ -6107,20 +6450,13 @@ MEDFileCMesh *MEDFileCMesh::New() */ MEDFileCMesh *MEDFileCMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs) { - std::vector ms(MEDCoupling::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; - MEDCoupling::MEDCouplingMeshType meshType; - std::string dummy2; - MEDCoupling::MEDCouplingAxisType dummy3; - MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2); - return new MEDFileCMesh(fid,ms.front(),dt,it,mrs); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,mrs); +} + +MEDFileCMesh *MEDFileCMesh::New(med_idt fid, MEDFileMeshReadSelector *mrs) +{ + return NewForTheFirstMeshInFile(fid,mrs); } /*! @@ -6139,8 +6475,12 @@ MEDFileCMesh *MEDFileCMesh::New(const std::string& fileName, MEDFileMeshReadSele */ 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); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,mName,dt,it,mrs); +} + +MEDFileCMesh *MEDFileCMesh::New(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs) +{ return new MEDFileCMesh(fid,mName,dt,it,mrs); } @@ -6198,7 +6538,7 @@ std::string MEDFileCMesh::advancedRepr() const return simpleRepr(); } -MEDFileMesh *MEDFileCMesh::shallowCpy() const +MEDFileCMesh *MEDFileCMesh::shallowCpy() const { MCAuto ret(new MEDFileCMesh(*this)); return ret.retn(); @@ -6209,7 +6549,7 @@ MEDFileMesh *MEDFileCMesh::createNewEmpty() const return new MEDFileCMesh; } -MEDFileMesh *MEDFileCMesh::deepCopy() const +MEDFileCMesh *MEDFileCMesh::deepCopy() const { MCAuto ret(new MEDFileCMesh(*this)); ret->deepCpyEquivalences(*this); @@ -6286,7 +6626,7 @@ void MEDFileCMesh::loadLL(med_idt fid, const std::string& mName, int dt, int it, int dummy0,dummy1; std::string dtunit; MEDCoupling::MEDCouplingAxisType axType; - int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit); + INTERP_KERNEL::AutoCppPtr mid(MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,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 !"; @@ -6354,7 +6694,7 @@ MEDFileMesh *MEDFileCMesh::cartesianize() const } } -void MEDFileCMesh::writeLL(med_idt fid) const +void MEDFileCMesh::writeMeshLL(med_idt fid) const { INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); @@ -6403,28 +6743,25 @@ MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New() return new MEDFileCurveLinearMesh; } +MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(med_idt fid, MEDFileMeshReadSelector *mrs) +{ + return NewForTheFirstMeshInFile(fid,mrs); +} + MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs) { - std::vector ms(MEDCoupling::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; - MEDCoupling::MEDCouplingMeshType meshType; - MEDCoupling::MEDCouplingAxisType dummy3; - std::string dummy2; - MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2); - return new MEDFileCurveLinearMesh(fid,ms.front(),dt,it,mrs); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,mrs); } MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::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); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,mName,dt,it,mrs); +} + +MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs) +{ return new MEDFileCurveLinearMesh(fid,mName,dt,it,mrs); } @@ -6440,7 +6777,7 @@ std::vector MEDFileCurveLinearMesh::getDirectChildrenWi return ret; } -MEDFileMesh *MEDFileCurveLinearMesh::shallowCpy() const +MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::shallowCpy() const { MCAuto ret(new MEDFileCurveLinearMesh(*this)); return ret.retn(); @@ -6451,7 +6788,7 @@ MEDFileMesh *MEDFileCurveLinearMesh::createNewEmpty() const return new MEDFileCurveLinearMesh; } -MEDFileMesh *MEDFileCurveLinearMesh::deepCopy() const +MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::deepCopy() const { MCAuto ret(new MEDFileCurveLinearMesh(*this)); ret->deepCpyEquivalences(*this); @@ -6585,7 +6922,7 @@ catch(INTERP_KERNEL::Exception& e) throw e; } -void MEDFileCurveLinearMesh::writeLL(med_idt fid) const +void MEDFileCurveLinearMesh::writeMeshLL(med_idt fid) const { INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); @@ -6599,7 +6936,7 @@ void MEDFileCurveLinearMesh::writeLL(med_idt fid) const 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 !"); + throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::writeMeshLL : no coordinates set !"); for(int i=0;igetCoords()->getInfoOnComponent(i)); @@ -6627,7 +6964,7 @@ void MEDFileCurveLinearMesh::loadLL(med_idt fid, const std::string& mName, int d int dummy0,dummy1; std::string dtunit; MEDCoupling::MEDCouplingAxisType axType; - int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit); + INTERP_KERNEL::AutoCppPtr mid(MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,axType,dummy0,dummy1,dtunit)); setAxisType(axType); if(meshType!=CURVE_LINEAR) { @@ -6647,21 +6984,33 @@ MEDFileMeshMultiTS *MEDFileMeshMultiTS::New() return new MEDFileMeshMultiTS; } +MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(med_idt fid) +{ + return new MEDFileMeshMultiTS(fid); +} + MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const std::string& fileName) { - return new MEDFileMeshMultiTS(fileName); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid); +} + +MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(med_idt fid, const std::string& mName) +{ + return new MEDFileMeshMultiTS(fid,mName); } MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const std::string& fileName, const std::string& mName) { - return new MEDFileMeshMultiTS(fileName,mName); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,mName); } MEDFileMeshMultiTS *MEDFileMeshMultiTS::deepCopy() const { - MCAuto ret=MEDFileMeshMultiTS::New(); + MCAuto ret(MEDFileMeshMultiTS::New()); std::vector< MCAuto > meshOneTs(_mesh_one_ts.size()); - std::size_t i=0; + std::size_t i(0); for(std::vector< MCAuto >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++,i++) if((const MEDFileMesh *)*it) meshOneTs[i]=(*it)->deepCopy(); @@ -6757,7 +7106,23 @@ void MEDFileMeshMultiTS::setJoints( MEDFileJoints* joints ) } } -void MEDFileMeshMultiTS::write(med_idt fid) const +bool MEDFileMeshMultiTS::presenceOfStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +void MEDFileMeshMultiTS::killStructureElements() +{ + for(std::vector< MCAuto >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) + if((*it).isNotNull()) + (*it)->killStructureElements(); +} + +void MEDFileMeshMultiTS::writeLL(med_idt fid) const { MEDFileJoints *joints(getJoints()); bool jointsWritten(false); @@ -6770,65 +7135,53 @@ void MEDFileMeshMultiTS::write(med_idt fid) const jointsWritten = true; (*it)->copyOptionsFrom(*this); - (*it)->write(fid); + (*it)->writeLL(fid); } (const_cast(this))->setJoints( joints ); // restore joints } -void MEDFileMeshMultiTS::write(const std::string& fileName, int mode) const +void MEDFileMeshMultiTS::loadFromFile(med_idt fid, const std::string& mName) { - med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod); - std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\""; - MEDFileUtilities::CheckMEDCode(fid,fid,oss.str()); - write(fid); -} - -void MEDFileMeshMultiTS::loadFromFile(const std::string& fileName, const std::string& mName) -{ - MEDFileJoints* joints = 0; + MEDFileJoints *joints(0); if ( !_mesh_one_ts.empty() && getOneTimeStep() ) { // joints of mName already read, pass them to MEDFileMesh::New() to prevent repeated reading joints = getOneTimeStep()->getJoints(); } - _mesh_one_ts.clear(); //for the moment to be improved - _mesh_one_ts.push_back( MEDFileMesh::New(fileName,mName,-1,-1,0, joints )); + _mesh_one_ts.push_back( MEDFileMesh::New(fid,mName,-1,-1,0, joints )); } MEDFileMeshMultiTS::MEDFileMeshMultiTS() { } -MEDFileMeshMultiTS::MEDFileMeshMultiTS(const std::string& fileName) +MEDFileMeshMultiTS::MEDFileMeshMultiTS(med_idt fid) try { - std::vector ms(MEDCoupling::GetMeshNames(fileName)); + std::vector ms(MEDLoaderNS::getMeshNamesFid(fid)); if(ms.empty()) { - std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !"; + std::ostringstream oss; oss << "MEDFileMeshMultiTS : no meshes in file \"" << FileNameFromFID(fid) << "\" !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MEDFileUtilities::CheckFileForRead(fileName); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY); int dt,it; MEDCoupling::MEDCouplingMeshType meshType; std::string dummy2; MEDCoupling::MEDCouplingAxisType dummy3; MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dummy3,dt,it,dummy2); - loadFromFile(fileName,ms.front()); + loadFromFile(fid,ms.front()); } catch(INTERP_KERNEL::Exception& e) { throw e; } -MEDFileMeshMultiTS::MEDFileMeshMultiTS(const std::string& fileName, const std::string& mName) +MEDFileMeshMultiTS::MEDFileMeshMultiTS(med_idt fid, const std::string& mName) try { - loadFromFile(fileName,mName); + loadFromFile(fid,mName); } catch(INTERP_KERNEL::Exception& e) { @@ -6840,30 +7193,28 @@ MEDFileMeshes *MEDFileMeshes::New() return new MEDFileMeshes; } +MEDFileMeshes *MEDFileMeshes::New(med_idt fid) +{ + return new MEDFileMeshes(fid); +} + MEDFileMeshes *MEDFileMeshes::New(const std::string& fileName) { - return new MEDFileMeshes(fileName); + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid); } -void MEDFileMeshes::write(med_idt fid) const +void MEDFileMeshes::writeLL(med_idt fid) const { checkConsistencyLight(); for(std::vector< MCAuto >::const_iterator it=_meshes.begin();it!=_meshes.end();it++) { (*it)->copyOptionsFrom(*this); - (*it)->write(fid); + (*it)->writeLL(fid); } } -void MEDFileMeshes::write(const std::string& fileName, int mode) const -{ - med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod); - std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\""; - MEDFileUtilities::CheckMEDCode(fid,fid,oss.str()); - checkConsistencyLight(); - write(fid); -} +// MEDFileMeshes::writ checkConsistencyLight(); int MEDFileMeshes::getNumberOfMeshes() const { @@ -6977,23 +7328,23 @@ void MEDFileMeshes::destroyMeshAtPos(int i) _meshes.erase(_meshes.begin()+i); } -void MEDFileMeshes::loadFromFile(const std::string& fileName) +void MEDFileMeshes::loadFromFile(med_idt fid) { - std::vector ms(MEDCoupling::GetMeshNames(fileName)); + std::vector ms(MEDLoaderNS::getMeshNamesFid(fid)); int i=0; _meshes.resize(ms.size()); for(std::vector::const_iterator it=ms.begin();it!=ms.end();it++,i++) - _meshes[i]=MEDFileMeshMultiTS::New(fileName,(*it)); + _meshes[i]=MEDFileMeshMultiTS::New(fid,(*it)); } MEDFileMeshes::MEDFileMeshes() { } -MEDFileMeshes::MEDFileMeshes(const std::string& fileName) +MEDFileMeshes::MEDFileMeshes(med_idt fid) try { - loadFromFile(fileName); + loadFromFile(fid); } catch(INTERP_KERNEL::Exception& /*e*/) { @@ -7006,7 +7357,7 @@ MEDFileMeshes *MEDFileMeshes::deepCopy() const for(std::vector< MCAuto >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++) if((const MEDFileMeshMultiTS *)*it) meshes[i]=(*it)->deepCopy(); - MCAuto ret=MEDFileMeshes::New(); + MCAuto ret(MEDFileMeshes::New()); ret->_meshes=meshes; return ret.retn(); } @@ -7064,6 +7415,22 @@ void MEDFileMeshes::checkConsistencyLight() const } } +bool MEDFileMeshes::presenceOfStructureElements() const +{ + for(std::vector< MCAuto >::const_iterator it=_meshes.begin();it!=_meshes.end();it++) + if((*it).isNotNull()) + if((*it)->presenceOfStructureElements()) + return true; + return false; +} + +void MEDFileMeshes::killStructureElements() +{ + for(std::vector< MCAuto >::iterator it=_meshes.begin();it!=_meshes.end();it++) + if((*it).isNotNull()) + (*it)->killStructureElements(); +} + MEDFileMeshesIterator::MEDFileMeshesIterator(MEDFileMeshes *ms):_ms(ms),_iter_id(0),_nb_iter(0) { if(ms) @@ -7090,3 +7457,34 @@ MEDFileMesh *MEDFileMeshesIterator::nextt() else return 0; } + +INTERP_KERNEL::NormalizedCellType MEDFileMesh::ConvertFromMEDFileGeoType(med_geometry_type geoType) +{ + med_geometry_type *pos(std::find(typmai,typmai+MED_N_CELL_FIXED_GEO,geoType)); + if(pos==typmai+MED_N_CELL_FIXED_GEO) + { + if(geoType==MED_NO_GEOTYPE) + return INTERP_KERNEL::NORM_ERROR; + std::ostringstream oss; oss << "MEDFileMesh::ConvertFromMEDFileGeoType : no entry with " << geoType << " !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + return typmai2[std::distance(typmai,pos)]; +} + +TypeOfField MEDFileMesh::ConvertFromMEDFileEntity(med_entity_type etype) +{ + switch(etype) + { + case MED_NODE: + return ON_NODES; + case MED_CELL: + return ON_CELLS; + default: + { + std::ostringstream oss; oss << "EDFileMesh::ConvertFromMEDFileEntity : not recognized entity " << etype << " !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + } +} + +