1 // Copyright (C) 2007-2014 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<MEDFileData> ret=MEDFileData::New();
47 ret->_fields=fields; ret->_meshes=meshes; ret->_params=params;
51 std::size_t MEDFileData::getHeapMemorySizeWithoutChildren() const
56 std::vector<const BigMemoryObject *> MEDFileData::getDirectChildren() const
58 std::vector<const BigMemoryObject *> ret;
59 if((const MEDFileFields *)_fields)
60 ret.push_back((const MEDFileFields *)_fields);
61 if((const MEDFileMeshes *)_meshes)
62 ret.push_back((const MEDFileMeshes *)_meshes);
63 if((const MEDFileParameters *)_params)
64 ret.push_back((const MEDFileParameters *)_params);
69 /** Return a borrowed reference (caller is not responsible for object destruction) */
70 MEDFileFields *MEDFileData::getFields() const
72 return const_cast<MEDFileFields *>(static_cast<const MEDFileFields *>(_fields));
75 /** Return a borrowed reference (caller is not responsible for object destruction) */
76 MEDFileMeshes *MEDFileData::getMeshes() const
78 return const_cast<MEDFileMeshes *>(static_cast<const MEDFileMeshes *>(_meshes));
81 /** Return a borrowed reference (caller is not responsible for object destruction) */
82 MEDFileParameters *MEDFileData::getParams() const
84 return const_cast<MEDFileParameters *>(static_cast<const MEDFileParameters *>(_params));
87 void MEDFileData::setFields(MEDFileFields *fields)
94 void MEDFileData::setMeshes(MEDFileMeshes *meshes)
101 void MEDFileData::setParams(MEDFileParameters *params)
108 int MEDFileData::getNumberOfFields() const
110 const MEDFileFields *f=_fields;
112 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfFields : no fields set !");
113 return f->getNumberOfFields();
116 int MEDFileData::getNumberOfMeshes() const
118 const MEDFileMeshes *m=_meshes;
120 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfMeshes : no meshes set !");
121 return m->getNumberOfMeshes();
124 int MEDFileData::getNumberOfParams() const
126 const MEDFileParameters *p=_params;
128 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfParams : no params set !");
129 return p->getNumberOfParams();
132 std::string MEDFileData::simpleRepr() const
134 std::ostringstream oss;
135 oss << "(***************)\n(* MEDFileData *)\n(***************)\n\nFields part :\n*************\n\n";
136 const MEDFileFields *tmp=_fields;
139 tmp->simpleRepr(0,oss);
143 oss << "No fields set !!!\n\n";
144 oss << "Meshes part :\n*************\n\n";
145 const MEDFileMeshes *tmp2=_meshes;
148 tmp2->simpleReprWithoutHeader(oss);
151 oss << "No meshes set !!!\n\n";
152 oss << "Params part :\n*************\n\n";
153 const MEDFileParameters *tmp3=_params;
156 tmp3->simpleReprWithoutHeader(oss);
159 oss << "No params set !!!\n";
163 bool MEDFileData::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
166 MEDFileFields *fields=_fields;
168 ret=fields->changeMeshNames(modifTab) || ret;
169 MEDFileMeshes *meshes=_meshes;
171 ret=meshes->changeNames(modifTab) || ret;
175 bool MEDFileData::changeMeshName(const std::string& oldMeshName, const std::string& newMeshName)
177 std::string oldName(oldMeshName);
178 std::vector< std::pair<std::string,std::string> > v(1);
179 v[0].first=oldName; v[0].second=newMeshName;
180 return changeMeshNames(v);
184 * 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
185 * the fields are automatically renumbered (for those impacted, that is to say here fields on cells and fields on gauss points on impacted fields)
187 * \return If true is returned it means that some meshes in \a this has been modified and eventually fields have been renumbered.
188 * \n If false \a this remains unchanged.
190 bool MEDFileData::unPolyzeMeshes()
192 MEDFileMeshes *ms=_meshes;
195 std::vector< MEDFileMesh * > meshesImpacted;
196 std::vector< DataArrayInt * > renumParamsOfMeshImpacted;//same size as meshesImpacted
197 std::vector< std::vector<int> > oldCodeOfMeshImpacted,newCodeOfMeshImpacted;//same size as meshesImpacted
198 std::vector<MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > memSaverIfThrow;//same size as meshesImpacted
199 for(int i=0;i<ms->getNumberOfMeshes();i++)
201 MEDFileMesh *m=ms->getMeshAtPos(i);
204 std::vector<int> oldCode,newCode;
205 DataArrayInt *o2nRenumCell=0;
206 bool modif=m->unPolyze(oldCode,newCode,o2nRenumCell);
209 renumParamsOfMeshImpacted.push_back(o2nRenumCell); memSaverIfThrow.push_back(o2nRenumCell);
210 oldCodeOfMeshImpacted.push_back(oldCode);
211 newCodeOfMeshImpacted.push_back(newCode);
212 meshesImpacted.push_back(m);
215 if(!meshesImpacted.empty())
217 MEDFileFields *fs=_fields;
219 for(std::size_t i=0;i<meshesImpacted.size();i++)
220 fs->renumberEntitiesLyingOnMesh(meshesImpacted[i]->getName(),oldCodeOfMeshImpacted[i],newCodeOfMeshImpacted[i],renumParamsOfMeshImpacted[i]);
222 return !meshesImpacted.empty();
225 MEDFileData::MEDFileData()
229 MEDFileData::MEDFileData(const std::string& fileName)
232 _fields=MEDFileFields::New(fileName);
233 _meshes=MEDFileMeshes::New(fileName);
234 _params=MEDFileParameters::New(fileName);
236 catch(INTERP_KERNEL::Exception& e)
241 void MEDFileData::write(const std::string& fileName, int mode) const
243 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
244 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
245 const MEDFileMeshes *ms=_meshes;
248 const MEDFileFields *fs=_fields;
251 const MEDFileParameters *ps=_params;