X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileStructureElement.cxx;h=b53ff049a64655dd7087ad90b1e90d605a38dd28;hb=88916ccf9c681624b682d10a62c1ee376324c946;hp=417d9d7f0df491c98f7b34f5b25d99ae38bc045f;hpb=4074002279f1ca79b31bcd1465f19a19a98f73ac;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileStructureElement.cxx b/src/MEDLoader/MEDFileStructureElement.cxx index 417d9d7f0..b53ff049a 100644 --- a/src/MEDLoader/MEDFileStructureElement.cxx +++ b/src/MEDLoader/MEDFileStructureElement.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2017 CEA/DEN, EDF R&D +// Copyright (C) 2007-2019 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,6 +19,7 @@ // Author : Anthony Geay (EDF R&D) #include "MEDFileStructureElement.hxx" +#include "MEDFileMeshSupport.hxx" #include "MEDLoaderBase.hxx" #include "MEDFileMeshLL.hxx" #include "MEDFileSafeCaller.txx" @@ -33,6 +34,11 @@ std::string MEDFileSEHolder::getModelName() const return _father->getName(); } +std::string MEDFileSEHolder::getName() const +{ + return _name; +} + void MEDFileSEHolder::setName(const std::string& name) { _name=name; @@ -45,12 +51,12 @@ std::size_t MEDFileSEHolder::getHeapMemorySizeLoc() const //////////////////// -MEDFileSEConstAtt *MEDFileSEConstAtt::New(med_idt fid, MEDFileStructureElement *father, int idCstAtt) +MEDFileSEConstAtt *MEDFileSEConstAtt::New(med_idt fid, MEDFileStructureElement *father, int idCstAtt, const MEDFileUMesh *mesh) { - return new MEDFileSEConstAtt(fid,father,idCstAtt); + return new MEDFileSEConstAtt(fid,father,idCstAtt,mesh); } -MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt):MEDFileSEHolder(father) +MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt, const MEDFileUMesh *mesh):MEDFileSEHolder(father) { std::string modelName(getModelName()); INTERP_KERNEL::AutoPtr constattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); @@ -67,10 +73,28 @@ MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *fathe _val=MEDFileStructureElement::BuildFrom(constatttype); nbCompo=MEDFileStructureElement::EffectiveNbCompo(constatttype,nbCompo); if(pflSz==0 && getProfile().empty()) - pflSz=1; + { + switch(met) + { + case MED_CELL: + { + std::vector gt(mesh->getAllGeoTypes()); + if(gt.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileSEConstAtt constr : only one cell type expected !"); + pflSz=mesh->getNumberOfCellsWithType(gt[0]); + break; + } + case MED_NODE: + { + pflSz=mesh->getNumberOfNodes(); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDFileSEConstAtt cstr : not recognized entity type !"); + } + } if(constatttype==MED_ATT_NAME) pflSz++; - std::cerr << "******* " << pflSz << std::endl; _val->alloc(pflSz,nbCompo); MEDFILESAFECALLERRD0(MEDstructElementConstAttRd,(fid,modelName.c_str(),name.c_str(),_val->getVoidStarPointer())); if(constatttype==MED_ATT_NAME) @@ -140,12 +164,12 @@ void MEDFileSEVarAtt::writeLL(med_idt fid) const //////////////////// -MEDFileStructureElement *MEDFileStructureElement::New(med_idt fid, int idSE) +MEDFileStructureElement *MEDFileStructureElement::New(med_idt fid, int idSE, const MEDFileMeshSupports *ms) { - return new MEDFileStructureElement(fid,idSE); + return new MEDFileStructureElement(fid,idSE,ms); } -MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE) +MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE, const MEDFileMeshSupports *ms) { INTERP_KERNEL::AutoPtr modelName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),supportMeshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)); med_geometry_type sgeoType; @@ -157,10 +181,12 @@ MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE) MEDFILESAFECALLERRD0(MEDstructElementInfo,(fid,idSE+1,modelName,&_id_type,&_dim,supportMeshName,&entiyType,&nnode,&ncell,&sgeoType,&nConsAttr,&anyPfl,&nVarAttr)); } _name=MEDLoaderBase::buildStringFromFortran(modelName,MED_NAME_SIZE); + _sup_mesh_name=MEDLoaderBase::buildStringFromFortran(supportMeshName,MED_NAME_SIZE); _geo_type=MEDFileMesh::ConvertFromMEDFileGeoType(sgeoType); + _tof=MEDFileMesh::ConvertFromMEDFileEntity(entiyType); _cst_att.resize(nConsAttr); for(int i=0;igetSupMeshWithName(_sup_mesh_name)); _var_att.resize(nVarAttr); for(int i=0;i MEDFileStructureElement::getVarAtts() const +{ + std::vector ret; + for(std::vector< MCAuto >::const_iterator it=_var_att.begin();it!=_var_att.end();it++) + if((*it).isNotNull()) + ret.push_back((*it)->getName()); + return ret; +} + +const MEDFileSEVarAtt *MEDFileStructureElement::getVarAtt(const std::string& varName) const +{ + for(std::vector< MCAuto >::const_iterator it=_var_att.begin();it!=_var_att.end();it++) + if((*it).isNotNull()) + if((*it)->getName()==varName) + return *it; + std::ostringstream oss; oss << "MEDFileStructureElement::getVarAtt : no var att with name \"" << varName << "\" !"; + throw INTERP_KERNEL::Exception(oss.str()); +} + //////////////////// -MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid) +MEDFileStructureElements *MEDFileStructureElements::New(const std::string& fileName, const MEDFileMeshSupports *ms) +{ + MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName)); + return New(fid,ms); +} + +MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid, const MEDFileMeshSupports *ms) { - return new MEDFileStructureElements(fid); + return new MEDFileStructureElements(fid,ms); } MEDFileStructureElements *MEDFileStructureElements::New() @@ -259,12 +325,13 @@ void MEDFileStructureElements::writeLL(med_idt fid) const { } -MEDFileStructureElements::MEDFileStructureElements(med_idt fid) +MEDFileStructureElements::MEDFileStructureElements(med_idt fid, const MEDFileMeshSupports *ms) { int nbSE(MEDnStructElement(fid)); _elems.resize(nbSE); for(int i=0;i MEDFileStructureElements::getDynGTAvail() const +{ + std::vector ret; + for(std::vector< MCAuto >::const_iterator it=_elems.begin();it!=_elems.end();it++) + { + const MEDFileStructureElement *elt(*it); + if(elt) + ret.push_back(elt->getDynGT()); + } + return ret; +} + +const MEDFileStructureElement *MEDFileStructureElements::getWithGT(int idGT) const +{ + for(std::vector< MCAuto >::const_iterator it=_elems.begin();it!=_elems.end();it++) + if((*it).isNotNull()) + { + if((*it)->getDynGT()==idGT) + return *it; + } + std::ostringstream oss; oss << "MEDFileStructureElements::getWithGT : no such geo type " << idGT << " !"; + throw INTERP_KERNEL::Exception(oss.str()); +} + +int MEDFileStructureElements::getNumberOfNodesPerSE(const std::string& seName) const +{ + if(seName=="MED_PARTICLE") + return 1; + const MEDFileStructureElement *se(getSEWithName(seName)); + std::string meshName(se->getMeshName()); + return _sup->getNumberOfNodesInConnOf(se->getEntity(),meshName); +} + +const MEDFileStructureElement *MEDFileStructureElements::getSEWithName(const std::string& seName) const +{ + for(std::vector< MCAuto >::const_iterator it=_elems.begin();it!=_elems.end();it++) + { + if((*it).isNotNull()) + if((*it)->getName()==seName) + return *it; + } + std::ostringstream oss; oss << "MEDFileStructureElements::getSEWithName : no such structure element with name " << seName << " !"; + throw INTERP_KERNEL::Exception(oss.str()); +} + +std::vector MEDFileStructureElements::getVarAttsOf(const std::string& seName) const +{ + const MEDFileStructureElement *se(getSEWithName(seName)); + return se->getVarAtts(); +} + +const MEDFileSEVarAtt *MEDFileStructureElements::getVarAttOf(const std::string &seName, const std::string& varName) const +{ + const MEDFileStructureElement *se(getSEWithName(seName)); + return se->getVarAtt(varName); +} + +const MEDFileUMesh *MEDFileStructureElements::getSupMeshWithName(const std::string& name) const +{ + return _sup->getSupMeshWithName(name); +}