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 void MEDFileSEHolder::setName(const std::string& name)
42 std::size_t MEDFileSEHolder::getHeapMemorySizeLoc() const
44 return _name.capacity();
49 MEDFileSEConstAtt *MEDFileSEConstAtt::New(med_idt fid, MEDFileStructureElement *father, int idCstAtt, const MEDFileUMesh *mesh)
51 return new MEDFileSEConstAtt(fid,father,idCstAtt,mesh);
54 MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt, const MEDFileUMesh *mesh):MEDFileSEHolder(father)
56 std::string modelName(getModelName());
57 INTERP_KERNEL::AutoPtr<char> constattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
58 med_attribute_type constatttype;
62 MEDFILESAFECALLERRD0(MEDstructElementConstAttInfo,(fid,modelName.c_str(),idCstAtt+1,constattname,&constatttype,&nbCompo,&met,profilename,&pflSz));
63 std::string name(MEDLoaderBase::buildStringFromFortran(constattname,MED_NAME_SIZE));
65 setProfile(MEDLoaderBase::buildStringFromFortran(profilename,MED_NAME_SIZE));
66 _tof=MEDFileMesh::ConvertFromMEDFileEntity(met);
68 _val=MEDFileStructureElement::BuildFrom(constatttype);
69 nbCompo=MEDFileStructureElement::EffectiveNbCompo(constatttype,nbCompo);
70 if(pflSz==0 && getProfile().empty())
76 std::vector<INTERP_KERNEL::NormalizedCellType> gt(mesh->getAllGeoTypes());
78 throw INTERP_KERNEL::Exception("MEDFileSEConstAtt constr : only one cell type expected !");
79 pflSz=mesh->getNumberOfCellsWithType(gt[0]);
84 pflSz=mesh->getNumberOfNodes();
88 throw INTERP_KERNEL::Exception("MEDFileSEConstAtt cstr : not recognized entity type !");
91 if(constatttype==MED_ATT_NAME)
93 std::cerr << "******* " << pflSz << std::endl;
94 _val->alloc(pflSz,nbCompo);
95 MEDFILESAFECALLERRD0(MEDstructElementConstAttRd,(fid,modelName.c_str(),name.c_str(),_val->getVoidStarPointer()));
96 if(constatttype==MED_ATT_NAME)
97 { pflSz--; _val->reAlloc(pflSz); }
100 std::vector<const BigMemoryObject *> MEDFileSEConstAtt::getDirectChildrenWithNull() const
102 std::vector<const BigMemoryObject *> ret;
107 std::size_t MEDFileSEConstAtt::getHeapMemorySizeWithoutChildren() const
109 return getHeapMemorySizeLoc()+_pfl.capacity();
112 void MEDFileSEConstAtt::writeLL(med_idt fid) const
116 void MEDFileSEConstAtt::setProfile(const std::string& name)
121 std::string MEDFileSEConstAtt::getProfile() const
128 MEDFileSEVarAtt *MEDFileSEVarAtt::New(med_idt fid, MEDFileStructureElement *father, int idVarAtt)
130 return new MEDFileSEVarAtt(fid,father,idVarAtt);
133 MEDFileSEVarAtt::MEDFileSEVarAtt(med_idt fid, MEDFileStructureElement *father, int idVarAtt):MEDFileSEHolder(father)
135 std::string modelName(getModelName());
136 INTERP_KERNEL::AutoPtr<char> varattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
137 med_attribute_type varatttype;
140 MEDFILESAFECALLERRD0(MEDstructElementVarAttInfo,(fid,modelName.c_str(),idVarAtt+1,varattname,&varatttype,&_nb_compo));
142 setName(MEDLoaderBase::buildStringFromFortran(varattname,MED_NAME_SIZE));
143 _gen=MEDFileStructureElement::BuildFrom(varatttype);
147 std::vector<const BigMemoryObject *> MEDFileSEVarAtt::getDirectChildrenWithNull() const
149 return std::vector<const BigMemoryObject *>();
152 std::size_t MEDFileSEVarAtt::getHeapMemorySizeWithoutChildren() const
154 return getHeapMemorySizeLoc();
157 void MEDFileSEVarAtt::writeLL(med_idt fid) const
163 MEDFileStructureElement *MEDFileStructureElement::New(med_idt fid, int idSE, const MEDFileMeshSupports *ms)
165 return new MEDFileStructureElement(fid,idSE,ms);
168 MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE, const MEDFileMeshSupports *ms)
170 INTERP_KERNEL::AutoPtr<char> modelName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),supportMeshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
171 med_geometry_type sgeoType;
172 med_entity_type entiyType;
173 int nConsAttr(0),nVarAttr(0);
176 int nnode(0),ncell(0);
177 MEDFILESAFECALLERRD0(MEDstructElementInfo,(fid,idSE+1,modelName,&_id_type,&_dim,supportMeshName,&entiyType,&nnode,&ncell,&sgeoType,&nConsAttr,&anyPfl,&nVarAttr));
179 _name=MEDLoaderBase::buildStringFromFortran(modelName,MED_NAME_SIZE);
180 _sup_mesh_name=MEDLoaderBase::buildStringFromFortran(supportMeshName,MED_NAME_SIZE);
181 _geo_type=MEDFileMesh::ConvertFromMEDFileGeoType(sgeoType);
182 _cst_att.resize(nConsAttr);
183 for(int i=0;i<nConsAttr;i++)
184 _cst_att[i]=MEDFileSEConstAtt::New(fid,this,i,ms->getSupMeshWithName(_sup_mesh_name));
185 _var_att.resize(nVarAttr);
186 for(int i=0;i<nVarAttr;i++)
187 _var_att[i]=MEDFileSEVarAtt::New(fid,this,i);
190 std::vector<const BigMemoryObject *> MEDFileStructureElement::getDirectChildrenWithNull() const
192 std::vector<const BigMemoryObject *> ret;
193 for(std::vector< MCAuto<MEDFileSEConstAtt> >::const_iterator it=_cst_att.begin();it!=_cst_att.end();it++)
195 for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
200 std::size_t MEDFileStructureElement::getHeapMemorySizeWithoutChildren() const
202 return _name.capacity()+_cst_att.capacity()*sizeof(MCAuto<MEDFileSEConstAtt>)+_var_att.capacity()*sizeof(MCAuto<MEDFileSEVarAtt>);
205 void MEDFileStructureElement::writeLL(med_idt fid) const
209 std::string MEDFileStructureElement::getName() const
214 MCAuto<DataArray> MEDFileStructureElement::BuildFrom(med_attribute_type mat)
216 MCAuto<DataArray> ret;
221 ret=DataArrayInt::New();
224 case MED_ATT_FLOAT64:
226 ret=DataArrayDouble::New();
231 ret=DataArrayAsciiChar::New();
235 throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !");
240 int MEDFileStructureElement::EffectiveNbCompo(med_attribute_type mat, int nbCompo)
245 case MED_ATT_FLOAT64:
248 return nbCompo*MED_NAME_SIZE;
250 throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !");
256 MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid, const MEDFileMeshSupports *ms)
258 return new MEDFileStructureElements(fid,ms);
261 MEDFileStructureElements *MEDFileStructureElements::New()
263 return new MEDFileStructureElements;
266 std::vector<const BigMemoryObject *> MEDFileStructureElements::getDirectChildrenWithNull() const
268 std::vector<const BigMemoryObject *> ret;
269 for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
274 std::size_t MEDFileStructureElements::getHeapMemorySizeWithoutChildren() const
276 return _elems.capacity()*sizeof(MEDFileStructureElement);
279 void MEDFileStructureElements::writeLL(med_idt fid) const
283 MEDFileStructureElements::MEDFileStructureElements(med_idt fid, const MEDFileMeshSupports *ms)
285 int nbSE(MEDnStructElement(fid));
287 for(int i=0;i<nbSE;i++)
288 _elems[i]=MEDFileStructureElement::New(fid,i,ms);
291 MEDFileStructureElements::MEDFileStructureElements()
295 MEDFileStructureElements::~MEDFileStructureElements()