1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #include "MEDFileStructureElement.hxx"
22 #include "MEDFileMeshSupport.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileMeshLL.hxx"
25 #include "MEDFileSafeCaller.txx"
27 #include "InterpKernelAutoPtr.hxx"
29 using namespace MEDCoupling;
32 std::string MEDFileSEHolder::getModelName() const
34 return _father->getName();
37 std::string MEDFileSEHolder::getName() const
42 void MEDFileSEHolder::setName(const std::string& name)
47 std::size_t MEDFileSEHolder::getHeapMemorySizeLoc() const
49 return _name.capacity();
54 MEDFileSEConstAtt *MEDFileSEConstAtt::New(med_idt fid, MEDFileStructureElement *father, int idCstAtt, const MEDFileUMesh *mesh)
56 return new MEDFileSEConstAtt(fid,father,idCstAtt,mesh);
59 MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt, const MEDFileUMesh *mesh):MEDFileSEHolder(father)
61 std::string modelName(getModelName());
62 INTERP_KERNEL::AutoPtr<char> constattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
63 med_attribute_type constatttype;
67 MEDFILESAFECALLERRD0(MEDstructElementConstAttInfo,(fid,modelName.c_str(),idCstAtt+1,constattname,&constatttype,&nbCompo,&met,profilename,&miPflSz));
68 std::string name(MEDLoaderBase::buildStringFromFortran(constattname,MED_NAME_SIZE));
70 setProfile(MEDLoaderBase::buildStringFromFortran(profilename,MED_NAME_SIZE));
71 _tof=MEDFileMesh::ConvertFromMEDFileEntity(met);
73 _val=MEDFileStructureElement::BuildFrom(constatttype);
74 nbCompo=MEDFileStructureElement::EffectiveNbCompo(constatttype,FromMedInt<int>(nbCompo));
75 mcIdType pflSz = miPflSz;
76 if(pflSz==0 && getProfile().empty())
82 std::vector<INTERP_KERNEL::NormalizedCellType> gt(mesh->getAllGeoTypes());
84 throw INTERP_KERNEL::Exception("MEDFileSEConstAtt constr : only one cell type expected !");
85 pflSz=mesh->getNumberOfCellsWithType(gt[0]);
90 pflSz=mesh->getNumberOfNodes();
94 throw INTERP_KERNEL::Exception("MEDFileSEConstAtt cstr : not recognized entity type !");
97 if(constatttype==MED_ATT_NAME)
99 _val->alloc(pflSz,nbCompo);
100 MEDFILESAFECALLERRD0(MEDstructElementConstAttRd,(fid,modelName.c_str(),name.c_str(),_val->getVoidStarPointer()));
101 if(constatttype==MED_ATT_NAME)
102 { pflSz--; _val->reAlloc(pflSz); }
105 std::vector<const BigMemoryObject *> MEDFileSEConstAtt::getDirectChildrenWithNull() const
107 std::vector<const BigMemoryObject *> ret;
112 std::size_t MEDFileSEConstAtt::getHeapMemorySizeWithoutChildren() const
114 return getHeapMemorySizeLoc()+_pfl.capacity();
117 void MEDFileSEConstAtt::writeLL(med_idt fid) const
121 void MEDFileSEConstAtt::setProfile(const std::string& name)
126 std::string MEDFileSEConstAtt::getProfile() const
133 MEDFileSEVarAtt *MEDFileSEVarAtt::New(med_idt fid, MEDFileStructureElement *father, int idVarAtt)
135 return new MEDFileSEVarAtt(fid,father,idVarAtt);
138 MEDFileSEVarAtt::MEDFileSEVarAtt(med_idt fid, MEDFileStructureElement *father, int idVarAtt):MEDFileSEHolder(father)
140 std::string modelName(getModelName());
141 INTERP_KERNEL::AutoPtr<char> varattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
142 med_attribute_type varatttype;
146 MEDFILESAFECALLERRD0(MEDstructElementVarAttInfo,(fid,modelName.c_str(),idVarAtt+1,varattname,&varatttype,&nbComp));
147 _nb_compo=FromMedInt<int>(nbComp);
149 setName(MEDLoaderBase::buildStringFromFortran(varattname,MED_NAME_SIZE));
150 _gen=MEDFileStructureElement::BuildFrom(varatttype);
154 std::vector<const BigMemoryObject *> MEDFileSEVarAtt::getDirectChildrenWithNull() const
156 return std::vector<const BigMemoryObject *>();
159 std::size_t MEDFileSEVarAtt::getHeapMemorySizeWithoutChildren() const
161 return getHeapMemorySizeLoc();
164 void MEDFileSEVarAtt::writeLL(med_idt fid) const
170 MEDFileStructureElement *MEDFileStructureElement::New(med_idt fid, int idSE, const MEDFileMeshSupports *ms)
172 return new MEDFileStructureElement(fid,idSE,ms);
175 MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE, const MEDFileMeshSupports *ms)
177 INTERP_KERNEL::AutoPtr<char> modelName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),supportMeshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
178 med_geometry_type sgeoType;
179 med_entity_type entiyType;
180 med_int nConsAttr(0),nVarAttr(0);
183 med_int nnode(0),ncell(0),dim(0);
184 med_geometry_type idType;
185 MEDFILESAFECALLERRD0(MEDstructElementInfo,(fid,idSE+1,modelName,&idType,&dim,supportMeshName,&entiyType,&nnode,&ncell,&sgeoType,&nConsAttr,&anyPfl,&nVarAttr));
186 _id_type=(int)idType;
187 _dim=FromMedInt<int>(dim);
189 _name=MEDLoaderBase::buildStringFromFortran(modelName,MED_NAME_SIZE);
190 _sup_mesh_name=MEDLoaderBase::buildStringFromFortran(supportMeshName,MED_NAME_SIZE);
191 _geo_type=MEDFileMesh::ConvertFromMEDFileGeoType(sgeoType);
192 _tof=MEDFileMesh::ConvertFromMEDFileEntity(entiyType);
193 _cst_att.resize(nConsAttr);
194 for(int i=0;i<nConsAttr;i++)
195 _cst_att[i]=MEDFileSEConstAtt::New(fid,this,i,ms->getSupMeshWithName(_sup_mesh_name));
196 _var_att.resize(nVarAttr);
197 for(int i=0;i<nVarAttr;i++)
198 _var_att[i]=MEDFileSEVarAtt::New(fid,this,i);
201 std::vector<const BigMemoryObject *> MEDFileStructureElement::getDirectChildrenWithNull() const
203 std::vector<const BigMemoryObject *> ret;
204 for(std::vector< MCAuto<MEDFileSEConstAtt> >::const_iterator it=_cst_att.begin();it!=_cst_att.end();it++)
206 for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
211 std::size_t MEDFileStructureElement::getHeapMemorySizeWithoutChildren() const
213 return _name.capacity()+_cst_att.capacity()*sizeof(MCAuto<MEDFileSEConstAtt>)+_var_att.capacity()*sizeof(MCAuto<MEDFileSEVarAtt>);
216 void MEDFileStructureElement::writeLL(med_idt fid) const
220 std::string MEDFileStructureElement::getName() const
225 MCAuto<DataArray> MEDFileStructureElement::BuildFrom(med_attribute_type mat)
227 MCAuto<DataArray> ret;
232 ret=DataArrayInt::New();
235 case MED_ATT_FLOAT64:
237 ret=DataArrayDouble::New();
242 ret=DataArrayAsciiChar::New();
246 throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !");
251 int MEDFileStructureElement::EffectiveNbCompo(med_attribute_type mat, int nbCompo)
256 case MED_ATT_FLOAT64:
259 return nbCompo*MED_NAME_SIZE;
261 throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !");
265 int MEDFileStructureElement::getDynGT() const
270 TypeOfField MEDFileStructureElement::getEntity() const
275 std::string MEDFileStructureElement::getMeshName() const
277 return _sup_mesh_name;
280 std::vector<std::string> MEDFileStructureElement::getVarAtts() const
282 std::vector<std::string> ret;
283 for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
284 if((*it).isNotNull())
285 ret.push_back((*it)->getName());
289 const MEDFileSEVarAtt *MEDFileStructureElement::getVarAtt(const std::string& varName) const
291 for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
292 if((*it).isNotNull())
293 if((*it)->getName()==varName)
295 std::ostringstream oss; oss << "MEDFileStructureElement::getVarAtt : no var att with name \"" << varName << "\" !";
296 throw INTERP_KERNEL::Exception(oss.str());
301 MEDFileStructureElements *MEDFileStructureElements::New(const std::string& fileName, const MEDFileMeshSupports *ms)
303 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
307 MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid, const MEDFileMeshSupports *ms)
309 return new MEDFileStructureElements(fid,ms);
312 MEDFileStructureElements *MEDFileStructureElements::New()
314 return new MEDFileStructureElements;
317 std::vector<const BigMemoryObject *> MEDFileStructureElements::getDirectChildrenWithNull() const
319 std::vector<const BigMemoryObject *> ret;
320 for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
325 std::size_t MEDFileStructureElements::getHeapMemorySizeWithoutChildren() const
327 return _elems.capacity()*sizeof(MEDFileStructureElement);
330 void MEDFileStructureElements::writeLL(med_idt fid) const
334 MEDFileStructureElements::MEDFileStructureElements(med_idt fid, const MEDFileMeshSupports *ms)
336 med_int nbSE(MEDnStructElement(fid));
338 for(int i=0;i<nbSE;i++)
339 _elems[i]=MEDFileStructureElement::New(fid,i,ms);
343 MEDFileStructureElements::MEDFileStructureElements()
347 MEDFileStructureElements::~MEDFileStructureElements()
351 int MEDFileStructureElements::getNumberOf() const
353 return (int)_elems.size();
356 std::vector<int> MEDFileStructureElements::getDynGTAvail() const
358 std::vector<int> ret;
359 for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
361 const MEDFileStructureElement *elt(*it);
363 ret.push_back(elt->getDynGT());
368 const MEDFileStructureElement *MEDFileStructureElements::getWithGT(int idGT) const
370 for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
371 if((*it).isNotNull())
373 if((*it)->getDynGT()==idGT)
376 std::ostringstream oss; oss << "MEDFileStructureElements::getWithGT : no such geo type " << idGT << " !";
377 throw INTERP_KERNEL::Exception(oss.str());
380 mcIdType MEDFileStructureElements::getNumberOfNodesPerSE(const std::string& seName) const
382 if(seName=="MED_PARTICLE")
384 const MEDFileStructureElement *se(getSEWithName(seName));
385 std::string meshName(se->getMeshName());
386 return _sup->getNumberOfNodesInConnOf(se->getEntity(),meshName);
389 const MEDFileStructureElement *MEDFileStructureElements::getSEWithName(const std::string& seName) const
391 for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
393 if((*it).isNotNull())
394 if((*it)->getName()==seName)
397 std::ostringstream oss; oss << "MEDFileStructureElements::getSEWithName : no such structure element with name " << seName << " !";
398 throw INTERP_KERNEL::Exception(oss.str());
401 std::vector<std::string> MEDFileStructureElements::getVarAttsOf(const std::string& seName) const
403 const MEDFileStructureElement *se(getSEWithName(seName));
404 return se->getVarAtts();
407 const MEDFileSEVarAtt *MEDFileStructureElements::getVarAttOf(const std::string &seName, const std::string& varName) const
409 const MEDFileStructureElement *se(getSEWithName(seName));
410 return se->getVarAtt(varName);
413 const MEDFileUMesh *MEDFileStructureElements::getSupMeshWithName(const std::string& name) const
415 return _sup->getSupMeshWithName(name);