X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileMeshSupport.cxx;h=5e1697ab9cf50c055d6e57144c0492eb5441da52;hb=662a2a2393a25baef77e42f74204b11b70a9646c;hp=b7ff2ab561524754a565cfc3959aac5c16e88a92;hpb=4aed19cb3f96f7072311a8006f6a5b3ae9312bc0;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileMeshSupport.cxx b/src/MEDLoader/MEDFileMeshSupport.cxx index b7ff2ab56..5e1697ab9 100644 --- a/src/MEDLoader/MEDFileMeshSupport.cxx +++ b/src/MEDLoader/MEDFileMeshSupport.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2017 CEA/DEN, EDF R&D +// Copyright (C) 2007-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -19,74 +19,123 @@ // Author : Anthony Geay (EDF R&D) #include "MEDFileMeshSupport.hxx" - #include "MEDLoaderBase.hxx" +#include "MEDFileMeshLL.hxx" #include "MEDFileSafeCaller.txx" #include "InterpKernelAutoPtr.hxx" using namespace MEDCoupling; -MEDFileMeshSupport *MEDFileMeshSupport::New() +MEDFileMeshSupports *MEDFileMeshSupports::New(const std::string& fileName) { - return new MEDFileMeshSupport; + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid); } -MEDFileMeshSupport *MEDFileMeshSupport::New(const std::string& fileName, int smid) +MEDFileMeshSupports *MEDFileMeshSupports::New(med_idt fid) { - MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); - return New(fid,smid); + return new MEDFileMeshSupports(fid); } -MEDFileMeshSupport *MEDFileMeshSupport::New(med_idt fid, int smid) +MEDFileMeshSupports *MEDFileMeshSupports::New() { - return new MEDFileMeshSupport(fid,smid); + return new MEDFileMeshSupports; } -std::vector MEDFileMeshSupport::getDirectChildrenWithNull() const +MEDFileMeshSupports::MEDFileMeshSupports(med_idt fid) { - return std::vector(); + med_int nbSM(MEDnSupportMesh(fid)); + _supports.resize(nbSM); + for(int i=0;i msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); + INTERP_KERNEL::AutoPtr description(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE)); + med_axis_type axType; + med_int nAxis(MEDsupportMeshnAxis(fid,i+1)); + INTERP_KERNEL::AutoPtr axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]); + med_int spaceDim(0),meshDim(0); + MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,i+1,msn,&spaceDim,&meshDim,description,&axType,axisName,axisUnit)); + std::string name(MEDLoaderBase::buildStringFromFortran(msn,MED_NAME_SIZE)); + _supports[i]=MEDFileUMesh::New(fid,name); + } } -std::size_t MEDFileMeshSupport::getHeapMemorySizeWithoutChildren() const +MEDFileMeshSupports::MEDFileMeshSupports() { - return 0; } -int MEDFileMeshSupport::getSpaceDim() const +MEDFileMeshSupports::~MEDFileMeshSupports() { - return _space_dim; } -void MEDFileMeshSupport::setSpaceDim(int dim) +std::vector MEDFileMeshSupports::getDirectChildrenWithNull() const { - _space_dim=dim; + std::size_t sz(_supports.size()); + std::vector ret(sz); + for(std::size_t i=0;i); } -void MEDFileMeshSupport::setMeshDim(int dim) +void MEDFileMeshSupports::writeLL(med_idt fid) const { - _mesh_dim=dim; + for(std::vector< MCAuto >::const_iterator it=_supports.begin();it!=_supports.end();it++) + if((*it).isNotNull()) + (*it)->writeLL(fid); } -void MEDFileMeshSupport::writeLL(med_idt fid) const +std::vector MEDFileMeshSupports::getSupMeshNames() const { + std::vector ret; + for(std::vector< MCAuto >::const_iterator it=_supports.begin();it!=_supports.end();it++) + if((*it).isNotNull()) + ret.push_back((*it)->getName()); + return ret; } -MEDFileMeshSupport::MEDFileMeshSupport(med_idt fid, int smid) +const MEDFileUMesh *MEDFileMeshSupports::getSupMeshWithName(const std::string& name) const { - INTERP_KERNEL::AutoPtr msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); - INTERP_KERNEL::AutoPtr description(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); - med_axis_type axType; - int nAxis(MEDsupportMeshnAxis(fid,smid)); - INTERP_KERNEL::AutoPtr axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]); - MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,smid,msn,&_space_dim,&_mesh_dim,description,&axType,axisName,axisUnit)); + std::vector mns; + for(std::vector< MCAuto >::const_iterator it=_supports.begin();it!=_supports.end();it++) + { + if((*it).isNotNull()) + { + std::string na((*it)->getName()); + if(na==name) + return *it; + else + mns.push_back(na); + } + } + std::ostringstream oss; + oss << "MEDFileMeshSupports::getSupMeshWithName : no such name \"" << name << "\". Possibilities are :"; + std::copy(mns.begin(),mns.end(),std::ostream_iterator(oss,",")); + oss << " !"; + throw INTERP_KERNEL::Exception(oss.str()); } -MEDFileMeshSupport::MEDFileMeshSupport():_space_dim(-1),_mesh_dim(-1) +mcIdType MEDFileMeshSupports::getNumberOfNodesInConnOf(TypeOfField entity, INTERP_KERNEL::NormalizedCellType gt, const std::string& name) const { + const MEDFileUMesh *sup(getSupMeshWithName(name)); + switch(entity) + { + case ON_NODES: + return sup->getNumberOfNodes(); + case ON_CELLS: + { + std::vector gts(sup->getAllGeoTypes()); + if(std::find(gts.begin(),gts.end(),gt) == gts.end()) + throw INTERP_KERNEL::Exception("MEDFileMeshSupports::getNumberOfNodesInConnOf : specified geometric type not found !"); + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(gt)); + return sup->getNumberOfCellsWithType(gt)*cm.getNumberOfNodes(); + } + default: + throw INTERP_KERNEL::Exception("MEDFileMeshSupports::getNumberOfNodesInConnOf : not recognized entity type !"); + } }