1 // Copyright (C) 2007-2015 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 (CEA/DEN)
21 #include "MEDFileData.hxx"
23 using namespace ParaMEDMEM;
25 MEDFileData *MEDFileData::New(const std::string& fileName)
27 return new MEDFileData(fileName);
30 MEDFileData *MEDFileData::New()
32 return new MEDFileData;
35 MEDFileData *MEDFileData::deepCpy() const
37 MEDCouplingAutoRefCountObjectPtr<MEDFileFields> fields;
38 if((const MEDFileFields *)_fields)
39 fields=_fields->deepCpy();
40 MEDCouplingAutoRefCountObjectPtr<MEDFileMeshes> meshes;
41 if((const MEDFileMeshes *)_meshes)
42 meshes=_meshes->deepCpy();
43 MEDCouplingAutoRefCountObjectPtr<MEDFileParameters> params;
44 if((const MEDFileParameters *)_params)
45 params=_params->deepCpy();
46 MEDCouplingAutoRefCountObjectPtr<MEDFileJoints> joints;
47 MEDCouplingAutoRefCountObjectPtr<MEDFileData> ret=MEDFileData::New();
48 ret->_fields=fields; ret->_meshes=meshes; ret->_params=params;
52 std::size_t MEDFileData::getHeapMemorySizeWithoutChildren() const
57 std::vector<const BigMemoryObject *> MEDFileData::getDirectChildrenWithNull() const
59 std::vector<const BigMemoryObject *> ret;
60 ret.push_back((const MEDFileFields *)_fields);
61 ret.push_back((const MEDFileMeshes *)_meshes);
62 ret.push_back((const MEDFileParameters *)_params);
67 /** Return a borrowed reference (caller is not responsible for object destruction) */
68 MEDFileFields *MEDFileData::getFields() const
70 return const_cast<MEDFileFields *>(static_cast<const MEDFileFields *>(_fields));
73 /** Return a borrowed reference (caller is not responsible for object destruction) */
74 MEDFileMeshes *MEDFileData::getMeshes() const
76 return const_cast<MEDFileMeshes *>(static_cast<const MEDFileMeshes *>(_meshes));
79 /** Return a borrowed reference (caller is not responsible for object destruction) */
80 MEDFileParameters *MEDFileData::getParams() const
82 return const_cast<MEDFileParameters *>(static_cast<const MEDFileParameters *>(_params));
85 void MEDFileData::setFields(MEDFileFields *fields)
92 void MEDFileData::setMeshes(MEDFileMeshes *meshes)
99 void MEDFileData::setParams(MEDFileParameters *params)
106 int MEDFileData::getNumberOfFields() const
108 const MEDFileFields *f=_fields;
110 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfFields : no fields set !");
111 return f->getNumberOfFields();
114 int MEDFileData::getNumberOfMeshes() const
116 const MEDFileMeshes *m=_meshes;
118 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfMeshes : no meshes set !");
119 return m->getNumberOfMeshes();
122 int MEDFileData::getNumberOfParams() const
124 const MEDFileParameters *p=_params;
126 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfParams : no params set !");
127 return p->getNumberOfParams();
130 std::string MEDFileData::simpleRepr() const
132 std::ostringstream oss;
133 oss << "(***************)\n(* MEDFileData *)\n(***************)\n\nFields part :\n*************\n\n";
134 const MEDFileFields *tmp=_fields;
137 tmp->simpleRepr(0,oss);
141 oss << "No fields set !!!\n\n";
142 oss << "Meshes part :\n*************\n\n";
143 const MEDFileMeshes *tmp2=_meshes;
146 tmp2->simpleReprWithoutHeader(oss);
149 oss << "No meshes set !!!\n\n";
150 oss << "Params part :\n*************\n\n";
151 const MEDFileParameters *tmp3=_params;
154 tmp3->simpleReprWithoutHeader(oss);
157 oss << "No params set !!!\n";
161 bool MEDFileData::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
164 MEDFileFields *fields=_fields;
166 ret=fields->changeMeshNames(modifTab) || ret;
167 MEDFileMeshes *meshes=_meshes;
169 ret=meshes->changeNames(modifTab) || ret;
173 bool MEDFileData::changeMeshName(const std::string& oldMeshName, const std::string& newMeshName)
175 std::string oldName(oldMeshName);
176 std::vector< std::pair<std::string,std::string> > v(1);
177 v[0].first=oldName; v[0].second=newMeshName;
178 return changeMeshNames(v);
182 * This method performs unpolyzation in meshes in \a this and if it leads to a modification to one or more than one meshes in \a this
183 * the fields are automatically renumbered (for those impacted, that is to say here fields on cells and fields on gauss points on impacted fields)
185 * \return If true is returned it means that some meshes in \a this has been modified and eventually fields have been renumbered.
186 * \n If false \a this remains unchanged.
188 bool MEDFileData::unPolyzeMeshes()
190 MEDFileMeshes *ms=_meshes;
193 std::vector< MEDFileMesh * > meshesImpacted;
194 std::vector< DataArrayInt * > renumParamsOfMeshImpacted;//same size as meshesImpacted
195 std::vector< std::vector<int> > oldCodeOfMeshImpacted,newCodeOfMeshImpacted;//same size as meshesImpacted
196 std::vector<MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > memSaverIfThrow;//same size as meshesImpacted
197 for(int i=0;i<ms->getNumberOfMeshes();i++)
199 MEDFileMesh *m=ms->getMeshAtPos(i);
202 std::vector<int> oldCode,newCode;
203 DataArrayInt *o2nRenumCell=0;
204 bool modif=m->unPolyze(oldCode,newCode,o2nRenumCell);
207 renumParamsOfMeshImpacted.push_back(o2nRenumCell); memSaverIfThrow.push_back(o2nRenumCell);
208 oldCodeOfMeshImpacted.push_back(oldCode);
209 newCodeOfMeshImpacted.push_back(newCode);
210 meshesImpacted.push_back(m);
213 if(!meshesImpacted.empty())
215 MEDFileFields *fs=_fields;
217 for(std::size_t i=0;i<meshesImpacted.size();i++)
218 fs->renumberEntitiesLyingOnMesh(meshesImpacted[i]->getName(),oldCodeOfMeshImpacted[i],newCodeOfMeshImpacted[i],renumParamsOfMeshImpacted[i]);
220 return !meshesImpacted.empty();
223 MEDFileData::MEDFileData()
227 MEDFileData::MEDFileData(const std::string& fileName)
230 _fields=MEDFileFields::New(fileName);
231 _meshes=MEDFileMeshes::New(fileName);
232 _params=MEDFileParameters::New(fileName);
234 catch(INTERP_KERNEL::Exception& e)
239 void MEDFileData::write(const std::string& fileName, int mode) const
241 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
242 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
243 const MEDFileMeshes *ms=_meshes;
246 const MEDFileFields *fs=_fields;
249 const MEDFileParameters *ps=_params;