1 // Copyright (C) 2007-2012 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.
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 char *fileName) throw(INTERP_KERNEL::Exception)
27 return new MEDFileData(fileName);
30 MEDFileData *MEDFileData::New()
32 return new MEDFileData;
35 MEDFileFields *MEDFileData::getFields() const
37 return const_cast<MEDFileFields *>(static_cast<const MEDFileFields *>(_fields));
40 MEDFileMeshes *MEDFileData::getMeshes() const
42 return const_cast<MEDFileMeshes *>(static_cast<const MEDFileMeshes *>(_meshes));
45 void MEDFileData::setFields(MEDFileFields *fields) throw(INTERP_KERNEL::Exception)
48 throw INTERP_KERNEL::Exception("MEDFileData::setFields : input pointer is null !");
53 void MEDFileData::setMeshes(MEDFileMeshes *meshes) throw(INTERP_KERNEL::Exception)
56 throw INTERP_KERNEL::Exception("MEDFileData::setMeshes : input pointer is null !");
61 int MEDFileData::getNumberOfFields() const throw(INTERP_KERNEL::Exception)
63 const MEDFileFields *f=_fields;
65 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfFields : no fields set !");
66 return f->getNumberOfFields();
69 int MEDFileData::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception)
71 const MEDFileMeshes *m=_meshes;
73 throw INTERP_KERNEL::Exception("MEDFileData::getNumberOfMeshes : no meshes set !");
74 return m->getNumberOfMeshes();
77 std::string MEDFileData::simpleRepr() const
79 std::ostringstream oss;
80 oss << "(***************)\n(* MEDFileData *)\n(***************)\n\nFields part :\n*************\n\n";
81 const MEDFileFields *tmp=_fields;
84 tmp->simpleRepr(0,oss);
88 oss << "No fields set !!!\n\n";
89 oss << "Meshes part :\n*************\n\n";
90 const MEDFileMeshes *tmp2=_meshes;
93 tmp2->simpleReprWithoutHeader(oss);
96 oss << "No meshes set !!!\n";
100 bool MEDFileData::changeMeshNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
103 MEDFileFields *fields=_fields;
105 ret=fields->changeMeshNames(modifTab) || ret;
106 MEDFileMeshes *meshes=_meshes;
108 ret=meshes->changeNames(modifTab) || ret;
112 bool MEDFileData::changeMeshName(const char *oldMeshName, const char *newMeshName) throw(INTERP_KERNEL::Exception)
114 std::string oldName(oldMeshName);
115 std::vector< std::pair<std::string,std::string> > v(1);
116 v[0].first=oldName; v[0].second=newMeshName;
117 return changeMeshNames(v);
121 * 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
122 * the fields are automatically renumbered (for those impacted, that is to say here fields on cells and fields on gauss points on impacted fields)
124 * \return If true is returned it means that some meshes in \a this has been modified and eventually fields have been renumbered.
125 * \n If false \a this remains unchanged.
127 bool MEDFileData::unPolyzeMeshes() throw(INTERP_KERNEL::Exception)
129 MEDFileMeshes *ms=_meshes;
132 std::vector< MEDFileMesh * > meshesImpacted;
133 std::vector< DataArrayInt * > renumParamsOfMeshImpacted;//same size as meshesImpacted
134 std::vector< std::vector<int> > oldCodeOfMeshImpacted,newCodeOfMeshImpacted;//same size as meshesImpacted
135 std::vector<MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > memSaverIfThrow;//same size as meshesImpacted
136 for(int i=0;i<ms->getNumberOfMeshes();i++)
138 MEDFileMesh *m=ms->getMeshAtPos(i);
141 std::vector<int> oldCode,newCode;
142 DataArrayInt *o2nRenumCell=0;
143 bool modif=m->unPolyze(oldCode,newCode,o2nRenumCell);
146 renumParamsOfMeshImpacted.push_back(o2nRenumCell); memSaverIfThrow.push_back(o2nRenumCell);
147 oldCodeOfMeshImpacted.push_back(oldCode);
148 newCodeOfMeshImpacted.push_back(newCode);
149 meshesImpacted.push_back(m);
152 if(!meshesImpacted.empty())
154 MEDFileFields *fs=_fields;
156 for(std::size_t i=0;i<meshesImpacted.size();i++)
157 fs->renumberEntitiesLyingOnMesh(meshesImpacted[i]->getName(),oldCodeOfMeshImpacted[i],newCodeOfMeshImpacted[i],renumParamsOfMeshImpacted[i]);
159 return !meshesImpacted.empty();
162 MEDFileData::MEDFileData()
166 MEDFileData::MEDFileData(const char *fileName) throw(INTERP_KERNEL::Exception)
169 _fields=MEDFileFields::New(fileName);
170 _meshes=MEDFileMeshes::New(fileName);
172 catch(INTERP_KERNEL::Exception& e)
177 void MEDFileData::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
179 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
180 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
181 const MEDFileMeshes *ms=_meshes;
184 const MEDFileFields *fs=_fields;