1 // Copyright (C) 2007-2017 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,&pflSz));
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,nbCompo);
75 if(pflSz==0 && getProfile().empty())
81 std::vector<INTERP_KERNEL::NormalizedCellType> gt(mesh->getAllGeoTypes());
83 throw INTERP_KERNEL::Exception("MEDFileSEConstAtt constr : only one cell type expected !");
84 pflSz=mesh->getNumberOfCellsWithType(gt[0]);
89 pflSz=mesh->getNumberOfNodes();
93 throw INTERP_KERNEL::Exception("MEDFileSEConstAtt cstr : not recognized entity type !");
96 if(constatttype==MED_ATT_NAME)
98 _val->alloc(pflSz,nbCompo);
99 MEDFILESAFECALLERRD0(MEDstructElementConstAttRd,(fid,modelName.c_str(),name.c_str(),_val->getVoidStarPointer()));
100 if(constatttype==MED_ATT_NAME)
101 { pflSz--; _val->reAlloc(pflSz); }
104 std::vector<const BigMemoryObject *> MEDFileSEConstAtt::getDirectChildrenWithNull() const
106 std::vector<const BigMemoryObject *> ret;
111 std::size_t MEDFileSEConstAtt::getHeapMemorySizeWithoutChildren() const
113 return getHeapMemorySizeLoc()+_pfl.capacity();
116 void MEDFileSEConstAtt::writeLL(med_idt fid) const
120 void MEDFileSEConstAtt::setProfile(const std::string& name)
125 std::string MEDFileSEConstAtt::getProfile() const
132 MEDFileSEVarAtt *MEDFileSEVarAtt::New(med_idt fid, MEDFileStructureElement *father, int idVarAtt)
134 return new MEDFileSEVarAtt(fid,father,idVarAtt);
137 MEDFileSEVarAtt::MEDFileSEVarAtt(med_idt fid, MEDFileStructureElement *father, int idVarAtt):MEDFileSEHolder(father)
139 std::string modelName(getModelName());
140 INTERP_KERNEL::AutoPtr<char> varattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
141 med_attribute_type varatttype;
144 MEDFILESAFECALLERRD0(MEDstructElementVarAttInfo,(fid,modelName.c_str(),idVarAtt+1,varattname,&varatttype,&_nb_compo));
146 setName(MEDLoaderBase::buildStringFromFortran(varattname,MED_NAME_SIZE));
147 _gen=MEDFileStructureElement::BuildFrom(varatttype);
151 std::vector<const BigMemoryObject *> MEDFileSEVarAtt::getDirectChildrenWithNull() const
153 return std::vector<const BigMemoryObject *>();
156 std::size_t MEDFileSEVarAtt::getHeapMemorySizeWithoutChildren() const
158 return getHeapMemorySizeLoc();
161 void MEDFileSEVarAtt::writeLL(med_idt fid) const
167 MEDFileStructureElement *MEDFileStructureElement::New(med_idt fid, int idSE, const MEDFileMeshSupports *ms)
169 return new MEDFileStructureElement(fid,idSE,ms);
172 MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE, const MEDFileMeshSupports *ms)
174 INTERP_KERNEL::AutoPtr<char> modelName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),supportMeshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
175 med_geometry_type sgeoType;
176 med_entity_type entiyType;
177 int nConsAttr(0),nVarAttr(0);
180 int nnode(0),ncell(0);
181 MEDFILESAFECALLERRD0(MEDstructElementInfo,(fid,idSE+1,modelName,&_id_type,&_dim,supportMeshName,&entiyType,&nnode,&ncell,&sgeoType,&nConsAttr,&anyPfl,&nVarAttr));
183 _name=MEDLoaderBase::buildStringFromFortran(modelName,MED_NAME_SIZE);
184 _sup_mesh_name=MEDLoaderBase::buildStringFromFortran(supportMeshName,MED_NAME_SIZE);
185 _geo_type=MEDFileMesh::ConvertFromMEDFileGeoType(sgeoType);
186 _tof=MEDFileMesh::ConvertFromMEDFileEntity(entiyType);
187 _cst_att.resize(nConsAttr);
188 for(int i=0;i<nConsAttr;i++)
189 _cst_att[i]=MEDFileSEConstAtt::New(fid,this,i,ms->getSupMeshWithName(_sup_mesh_name));
190 _var_att.resize(nVarAttr);
191 for(int i=0;i<nVarAttr;i++)
192 _var_att[i]=MEDFileSEVarAtt::New(fid,this,i);
195 std::vector<const BigMemoryObject *> MEDFileStructureElement::getDirectChildrenWithNull() const
197 std::vector<const BigMemoryObject *> ret;
198 for(std::vector< MCAuto<MEDFileSEConstAtt> >::const_iterator it=_cst_att.begin();it!=_cst_att.end();it++)
200 for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
205 std::size_t MEDFileStructureElement::getHeapMemorySizeWithoutChildren() const
207 return _name.capacity()+_cst_att.capacity()*sizeof(MCAuto<MEDFileSEConstAtt>)+_var_att.capacity()*sizeof(MCAuto<MEDFileSEVarAtt>);
210 void MEDFileStructureElement::writeLL(med_idt fid) const
214 std::string MEDFileStructureElement::getName() const
219 MCAuto<DataArray> MEDFileStructureElement::BuildFrom(med_attribute_type mat)
221 MCAuto<DataArray> ret;
226 ret=DataArrayInt::New();
229 case MED_ATT_FLOAT64:
231 ret=DataArrayDouble::New();
236 ret=DataArrayAsciiChar::New();
240 throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !");
245 int MEDFileStructureElement::EffectiveNbCompo(med_attribute_type mat, int nbCompo)
250 case MED_ATT_FLOAT64:
253 return nbCompo*MED_NAME_SIZE;
255 throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !");
259 int MEDFileStructureElement::getDynGT() const
264 TypeOfField MEDFileStructureElement::getEntity() const
269 std::string MEDFileStructureElement::getMeshName() const
271 return _sup_mesh_name;
274 std::vector<std::string> MEDFileStructureElement::getVarAtts() const
276 std::vector<std::string> ret;
277 for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
278 if((*it).isNotNull())
279 ret.push_back((*it)->getName());
283 const MEDFileSEVarAtt *MEDFileStructureElement::getVarAtt(const std::string& varName) const
285 for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
286 if((*it).isNotNull())
287 if((*it)->getName()==varName)
289 std::ostringstream oss; oss << "MEDFileStructureElement::getVarAtt : no var att with name \"" << varName << "\" !";
290 throw INTERP_KERNEL::Exception(oss.str());
295 MEDFileStructureElements *MEDFileStructureElements::New(const std::string& fileName, const MEDFileMeshSupports *ms)
297 MEDFileUtilities::AutoFid fid(OpenMEDFileForRead(fileName));
301 MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid, const MEDFileMeshSupports *ms)
303 return new MEDFileStructureElements(fid,ms);
306 MEDFileStructureElements *MEDFileStructureElements::New()
308 return new MEDFileStructureElements;
311 std::vector<const BigMemoryObject *> MEDFileStructureElements::getDirectChildrenWithNull() const
313 std::vector<const BigMemoryObject *> ret;
314 for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
319 std::size_t MEDFileStructureElements::getHeapMemorySizeWithoutChildren() const
321 return _elems.capacity()*sizeof(MEDFileStructureElement);
324 void MEDFileStructureElements::writeLL(med_idt fid) const
328 MEDFileStructureElements::MEDFileStructureElements(med_idt fid, const MEDFileMeshSupports *ms)
330 int nbSE(MEDnStructElement(fid));
332 for(int i=0;i<nbSE;i++)
333 _elems[i]=MEDFileStructureElement::New(fid,i,ms);
337 MEDFileStructureElements::MEDFileStructureElements()
341 MEDFileStructureElements::~MEDFileStructureElements()
345 int MEDFileStructureElements::getNumberOf() const
347 return _elems.size();
350 std::vector<int> MEDFileStructureElements::getDynGTAvail() const
352 std::vector<int> ret;
353 for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
355 const MEDFileStructureElement *elt(*it);
357 ret.push_back(elt->getDynGT());
362 const MEDFileStructureElement *MEDFileStructureElements::getWithGT(int idGT) const
364 for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
365 if((*it).isNotNull())
367 if((*it)->getDynGT()==idGT)
370 std::ostringstream oss; oss << "MEDFileStructureElements::getWithGT : no such geo type " << idGT << " !";
371 throw INTERP_KERNEL::Exception(oss.str());
374 int MEDFileStructureElements::getNumberOfNodesPerSE(const std::string& seName) const
376 if(seName=="MED_PARTICLE")
378 const MEDFileStructureElement *se(getSEWithName(seName));
379 std::string meshName(se->getMeshName());
380 return _sup->getNumberOfNodesInConnOf(se->getEntity(),meshName);
383 const MEDFileStructureElement *MEDFileStructureElements::getSEWithName(const std::string& seName) const
385 for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
387 if((*it).isNotNull())
388 if((*it)->getName()==seName)
391 std::ostringstream oss; oss << "MEDFileStructureElements::getSEWithName : no such structure element with name " << seName << " !";
392 throw INTERP_KERNEL::Exception(oss.str());
395 std::vector<std::string> MEDFileStructureElements::getVarAttsOf(const std::string& seName) const
397 const MEDFileStructureElement *se(getSEWithName(seName));
398 return se->getVarAtts();
401 const MEDFileSEVarAtt *MEDFileStructureElements::getVarAttOf(const std::string &seName, const std::string& varName) const
403 const MEDFileStructureElement *se(getSEWithName(seName));
404 return se->getVarAtt(varName);
407 const MEDFileUMesh *MEDFileStructureElements::getSupMeshWithName(const std::string& name) const
409 return _sup->getSupMeshWithName(name);