]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDFileStructureElement.cxx
Salome HOME
417d9d7f0df491c98f7b34f5b25d99ae38bc045f
[tools/medcoupling.git] / src / MEDLoader / MEDFileStructureElement.cxx
1 // Copyright (C) 2007-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (EDF R&D)
20
21 #include "MEDFileStructureElement.hxx"
22 #include "MEDLoaderBase.hxx"
23 #include "MEDFileMeshLL.hxx"
24 #include "MEDFileSafeCaller.txx"
25
26 #include "InterpKernelAutoPtr.hxx"
27
28 using namespace MEDCoupling;
29
30
31 std::string MEDFileSEHolder::getModelName() const
32 {
33   return _father->getName();
34 }
35
36 void MEDFileSEHolder::setName(const std::string& name)
37 {
38   _name=name;
39 }
40
41 std::size_t MEDFileSEHolder::getHeapMemorySizeLoc() const
42 {
43   return _name.capacity();
44 }
45
46 ////////////////////
47
48 MEDFileSEConstAtt *MEDFileSEConstAtt::New(med_idt fid, MEDFileStructureElement *father, int idCstAtt)
49 {
50   return new MEDFileSEConstAtt(fid,father,idCstAtt);
51 }
52
53 MEDFileSEConstAtt::MEDFileSEConstAtt(med_idt fid, MEDFileStructureElement *father, int idCstAtt):MEDFileSEHolder(father)
54 {
55   std::string modelName(getModelName());
56   INTERP_KERNEL::AutoPtr<char> constattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
57   med_attribute_type constatttype;
58   int nbCompo;
59   med_entity_type met;
60   int pflSz;
61   MEDFILESAFECALLERRD0(MEDstructElementConstAttInfo,(fid,modelName.c_str(),idCstAtt+1,constattname,&constatttype,&nbCompo,&met,profilename,&pflSz));
62   std::string name(MEDLoaderBase::buildStringFromFortran(constattname,MED_NAME_SIZE));
63   setName(name);
64   setProfile(MEDLoaderBase::buildStringFromFortran(profilename,MED_NAME_SIZE));
65   _tof=MEDFileMesh::ConvertFromMEDFileEntity(met);
66   //
67   _val=MEDFileStructureElement::BuildFrom(constatttype);
68   nbCompo=MEDFileStructureElement::EffectiveNbCompo(constatttype,nbCompo);
69   if(pflSz==0 && getProfile().empty())
70     pflSz=1;
71   if(constatttype==MED_ATT_NAME)
72     pflSz++;
73   std::cerr << "******* " << pflSz << std::endl;
74   _val->alloc(pflSz,nbCompo);
75   MEDFILESAFECALLERRD0(MEDstructElementConstAttRd,(fid,modelName.c_str(),name.c_str(),_val->getVoidStarPointer()));
76   if(constatttype==MED_ATT_NAME)
77     { pflSz--; _val->reAlloc(pflSz); }
78 }
79
80 std::vector<const BigMemoryObject *> MEDFileSEConstAtt::getDirectChildrenWithNull() const
81 {
82   std::vector<const BigMemoryObject *> ret;
83   ret.push_back(_val);
84   return ret;
85 }
86
87 std::size_t MEDFileSEConstAtt::getHeapMemorySizeWithoutChildren() const
88 {
89   return getHeapMemorySizeLoc()+_pfl.capacity();
90 }
91
92 void MEDFileSEConstAtt::writeLL(med_idt fid) const
93 {
94 }
95
96 void MEDFileSEConstAtt::setProfile(const std::string& name)
97 {
98   _pfl=name;
99 }
100
101 std::string MEDFileSEConstAtt::getProfile() const
102 {
103   return _pfl;
104 }
105
106 ////////////////////
107
108 MEDFileSEVarAtt *MEDFileSEVarAtt::New(med_idt fid, MEDFileStructureElement *father, int idVarAtt)
109 {
110   return new MEDFileSEVarAtt(fid,father,idVarAtt);
111 }
112
113 MEDFileSEVarAtt::MEDFileSEVarAtt(med_idt fid, MEDFileStructureElement *father, int idVarAtt):MEDFileSEHolder(father)
114 {
115   std::string modelName(getModelName());
116   INTERP_KERNEL::AutoPtr<char> varattname(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),profilename(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
117   med_attribute_type varatttype;
118   {
119     int pflSz;
120     MEDFILESAFECALLERRD0(MEDstructElementVarAttInfo,(fid,modelName.c_str(),idVarAtt+1,varattname,&varatttype,&_nb_compo));
121   }
122   setName(MEDLoaderBase::buildStringFromFortran(varattname,MED_NAME_SIZE));
123   _gen=MEDFileStructureElement::BuildFrom(varatttype);
124   _gen->alloc(0,1);
125 }
126
127 std::vector<const BigMemoryObject *> MEDFileSEVarAtt::getDirectChildrenWithNull() const
128 {
129   return std::vector<const BigMemoryObject *>();
130 }
131
132 std::size_t MEDFileSEVarAtt::getHeapMemorySizeWithoutChildren() const
133 {
134   return getHeapMemorySizeLoc();
135 }
136
137 void MEDFileSEVarAtt::writeLL(med_idt fid) const
138 {
139 }
140
141 ////////////////////
142
143 MEDFileStructureElement *MEDFileStructureElement::New(med_idt fid, int idSE)
144 {
145   return new MEDFileStructureElement(fid,idSE);
146 }
147
148 MEDFileStructureElement::MEDFileStructureElement(med_idt fid, int idSE)
149 {
150   INTERP_KERNEL::AutoPtr<char> modelName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE)),supportMeshName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
151   med_geometry_type sgeoType;
152   med_entity_type entiyType;
153   int nConsAttr(0),nVarAttr(0);
154   {
155     med_bool anyPfl;
156     int nnode(0),ncell(0);
157     MEDFILESAFECALLERRD0(MEDstructElementInfo,(fid,idSE+1,modelName,&_id_type,&_dim,supportMeshName,&entiyType,&nnode,&ncell,&sgeoType,&nConsAttr,&anyPfl,&nVarAttr));
158   }
159   _name=MEDLoaderBase::buildStringFromFortran(modelName,MED_NAME_SIZE);
160   _geo_type=MEDFileMesh::ConvertFromMEDFileGeoType(sgeoType);
161   _cst_att.resize(nConsAttr);
162   for(int i=0;i<nConsAttr;i++)
163     _cst_att[i]=MEDFileSEConstAtt::New(fid,this,i);
164   _var_att.resize(nVarAttr);
165   for(int i=0;i<nVarAttr;i++)
166     _var_att[i]=MEDFileSEVarAtt::New(fid,this,i);
167 }
168
169 std::vector<const BigMemoryObject *> MEDFileStructureElement::getDirectChildrenWithNull() const
170 {
171   std::vector<const BigMemoryObject *> ret;
172   for(std::vector< MCAuto<MEDFileSEConstAtt> >::const_iterator it=_cst_att.begin();it!=_cst_att.end();it++)
173     ret.push_back(*it);
174   for(std::vector< MCAuto<MEDFileSEVarAtt> >::const_iterator it=_var_att.begin();it!=_var_att.end();it++)
175     ret.push_back(*it);
176   return ret;
177 }
178
179 std::size_t MEDFileStructureElement::getHeapMemorySizeWithoutChildren() const
180 {
181   return _name.capacity()+_cst_att.capacity()*sizeof(MCAuto<MEDFileSEConstAtt>)+_var_att.capacity()*sizeof(MCAuto<MEDFileSEVarAtt>);
182 }
183
184 void MEDFileStructureElement::writeLL(med_idt fid) const
185 {
186 }
187
188 std::string MEDFileStructureElement::getName() const
189 {
190   return _name;
191 }
192
193 MCAuto<DataArray> MEDFileStructureElement::BuildFrom(med_attribute_type mat)
194 {
195   MCAuto<DataArray> ret;
196   switch(mat)
197     {
198     case MED_ATT_INT:
199       {
200         ret=DataArrayInt::New();
201         break;
202       }
203     case MED_ATT_FLOAT64:
204       {
205         ret=DataArrayDouble::New();
206         break;
207       }
208     case MED_ATT_NAME:
209       {
210         ret=DataArrayAsciiChar::New();
211         break;
212       }
213     default:
214       throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !");
215     }
216   return ret;
217 }
218
219 int MEDFileStructureElement::EffectiveNbCompo(med_attribute_type mat, int nbCompo)
220 {
221   switch(mat)
222     {
223     case MED_ATT_INT:
224     case MED_ATT_FLOAT64:
225       return nbCompo;
226     case MED_ATT_NAME:
227       return nbCompo*MED_NAME_SIZE;
228     default:
229       throw INTERP_KERNEL::Exception("MEDFileStructureElement::BuildFrom : not recognized type ! Only INT and FLOAT64 !");
230     }
231 }
232
233 ////////////////////
234
235 MEDFileStructureElements *MEDFileStructureElements::New(med_idt fid)
236 {
237   return new MEDFileStructureElements(fid);
238 }
239
240 MEDFileStructureElements *MEDFileStructureElements::New()
241 {
242   return new MEDFileStructureElements;
243 }
244
245 std::vector<const BigMemoryObject *> MEDFileStructureElements::getDirectChildrenWithNull() const
246 {
247   std::vector<const BigMemoryObject *> ret;
248   for(std::vector< MCAuto<MEDFileStructureElement> >::const_iterator it=_elems.begin();it!=_elems.end();it++)
249     ret.push_back(*it);
250   return ret;
251 }
252
253 std::size_t MEDFileStructureElements::getHeapMemorySizeWithoutChildren() const
254 {
255   return _elems.capacity()*sizeof(MEDFileStructureElement);
256 }
257
258 void MEDFileStructureElements::writeLL(med_idt fid) const
259 {
260 }
261
262 MEDFileStructureElements::MEDFileStructureElements(med_idt fid)
263 {
264   int nbSE(MEDnStructElement(fid));
265   _elems.resize(nbSE);
266   for(int i=0;i<nbSE;i++)
267     _elems[i]=MEDFileStructureElement::New(fid,i);
268 }
269
270 MEDFileStructureElements::MEDFileStructureElements()
271 {
272 }
273
274 MEDFileStructureElements::~MEDFileStructureElements()
275 {
276 }
277