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<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::getDirectChildrenWithNull() const
58 std::vector<const BigMemoryObject *> ret;
59 ret.push_back((const MEDFileFields *)_fields);
60 ret.push_back((const MEDFileMeshes *)_meshes);
61 ret.push_back((const MEDFileParameters *)_params);
66 /** Return a borrowed reference (caller is not responsible for object destruction) */
67 MEDFileFields *MEDFileData::getFields() const
69 return const_cast<MEDFileFields *>(static_cast<const MEDFileFields *>(_fields));
72 /** Return a borrowed reference (caller is not responsible for object destruction) */
73 MEDFileMeshes *MEDFileData::getMeshes() const
75 return const_cast<MEDFileMeshes *>(static_cast<const MEDFileMeshes *>(_meshes));
78 /** Return a borrowed reference (caller is not responsible for object destruction) */
79 MEDFileParameters *MEDFileData::getParams() const
81 return const_cast<MEDFileParameters *>(static_cast<const MEDFileParameters *>(_params));
84 void MEDFileData::setFields(MEDFileFields *fields)
91 void MEDFileData::setMeshes(MEDFileMeshes *meshes)
98 void MEDFileData::setParams(MEDFileParameters *params)
105 int MEDFileData::getNumberOfFields() const
107 const MEDFileFields *f=_fields;
109 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfFields : no fields set !");
110 return f->getNumberOfFields();
113 int MEDFileData::getNumberOfMeshes() const
115 const MEDFileMeshes *m=_meshes;
117 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfMeshes : no meshes set !");
118 return m->getNumberOfMeshes();
121 int MEDFileData::getNumberOfParams() const
123 const MEDFileParameters *p=_params;
125 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfParams : no params set !");
126 return p->getNumberOfParams();
129 std::string MEDFileData::simpleRepr() const
131 std::ostringstream oss;
132 oss << "(***************)\n(* MEDFileData *)\n(***************)\n\nFields part :\n*************\n\n";
133 const MEDFileFields *tmp=_fields;
136 tmp->simpleRepr(0,oss);
140 oss << "No fields set !!!\n\n";
141 oss << "Meshes part :\n*************\n\n";
142 const MEDFileMeshes *tmp2=_meshes;
145 tmp2->simpleReprWithoutHeader(oss);
148 oss << "No meshes set !!!\n\n";
149 oss << "Params part :\n*************\n\n";
150 const MEDFileParameters *tmp3=_params;
153 tmp3->simpleReprWithoutHeader(oss);
156 oss << "No params set !!!\n";
160 bool MEDFileData::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
163 MEDFileFields *fields=_fields;
165 ret=fields->changeMeshNames(modifTab) || ret;
166 MEDFileMeshes *meshes=_meshes;
168 ret=meshes->changeNames(modifTab) || ret;
172 bool MEDFileData::changeMeshName(const std::string& oldMeshName, const std::string& newMeshName)
174 std::string oldName(oldMeshName);
175 std::vector< std::pair<std::string,std::string> > v(1);
176 v[0].first=oldName; v[0].second=newMeshName;
177 return changeMeshNames(v);
181 * 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
182 * the fields are automatically renumbered (for those impacted, that is to say here fields on cells and fields on gauss points on impacted fields)
184 * \return If true is returned it means that some meshes in \a this has been modified and eventually fields have been renumbered.
185 * \n If false \a this remains unchanged.
187 bool MEDFileData::unPolyzeMeshes()
189 MEDFileMeshes *ms=_meshes;
192 std::vector< MEDFileMesh * > meshesImpacted;
193 std::vector< DataArrayInt * > renumParamsOfMeshImpacted;//same size as meshesImpacted
194 std::vector< std::vector<int> > oldCodeOfMeshImpacted,newCodeOfMeshImpacted;//same size as meshesImpacted
195 std::vector<MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > memSaverIfThrow;//same size as meshesImpacted
196 for(int i=0;i<ms->getNumberOfMeshes();i++)
198 MEDFileMesh *m=ms->getMeshAtPos(i);
201 std::vector<int> oldCode,newCode;
202 DataArrayInt *o2nRenumCell=0;
203 bool modif=m->unPolyze(oldCode,newCode,o2nRenumCell);
206 renumParamsOfMeshImpacted.push_back(o2nRenumCell); memSaverIfThrow.push_back(o2nRenumCell);
207 oldCodeOfMeshImpacted.push_back(oldCode);
208 newCodeOfMeshImpacted.push_back(newCode);
209 meshesImpacted.push_back(m);
212 if(!meshesImpacted.empty())
214 MEDFileFields *fs=_fields;
216 for(std::size_t i=0;i<meshesImpacted.size();i++)
217 fs->renumberEntitiesLyingOnMesh(meshesImpacted[i]->getName(),oldCodeOfMeshImpacted[i],newCodeOfMeshImpacted[i],renumParamsOfMeshImpacted[i]);
219 return !meshesImpacted.empty();
222 MEDFileData::MEDFileData()
226 MEDFileData::MEDFileData(const std::string& fileName)
229 _fields=MEDFileFields::New(fileName);
230 _meshes=MEDFileMeshes::New(fileName);
231 _params=MEDFileParameters::New(fileName);
233 catch(INTERP_KERNEL::Exception& e)
238 void MEDFileData::write(const std::string& fileName, int mode) const
240 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
241 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
242 const MEDFileMeshes *ms=_meshes;
245 const MEDFileFields *fs=_fields;
248 const MEDFileParameters *ps=_params;