1 // Copyright (C) 2007-2008 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 // Partitioning/decimation module for the SALOME v3.2 platform
22 * \file MULTIPR_Profil.cxx
24 * \brief see MULTIPR_Profil.hxx
26 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
31 //*****************************************************************************
33 //*****************************************************************************
35 #include "MULTIPR_Profil.hxx"
36 #include "MULTIPR_Exceptions.hxx"
37 #include "MULTIPR_Mesh.hxx"
48 //*****************************************************************************
49 // Class Profil implementation
50 //*****************************************************************************
57 Profil::Profil(const Profil& pProfil)
59 strcpy(mName, pProfil.mName);
60 mTable = pProfil.mTable;
61 mBinding = pProfil.mBinding;
62 mGeomIdx = pProfil.mGeomIdx;
80 void Profil::create(const char* pName)
82 if (pName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
90 const char* Profil::getName() const
95 void Profil::add(med_int pElt)
100 bool Profil::find(med_int pElt)
102 if (mTable.find(pElt) != mTable.end())
112 void Profil::filterSetOfElement(std::set<med_int>& pIn, std::set<med_int>& pOut)
114 if (&pOut == &pIn) throw IllegalStateException("pIn and pOut must be different !", __FILE__, __LINE__);
117 for (std::set< med_int>::iterator it = mTable.begin(); it != mTable.end(); ++it)
119 if (pIn.find(*it) != pIn.end())
127 void Profil::extractSetOfElement(const std::set<med_int>& pIn, std::set<med_int>& pOut)
129 if (&pOut == &pIn) throw IllegalStateException("pIn and pOut must be different !", __FILE__, __LINE__);
132 for (std::set< med_int>::iterator it = pIn.begin(); it != pIn.end(); ++it)
134 if (mTable.find(*it) != mTable.end())
142 void Profil::readMED(med_idt pMEDfile, med_int pIndexProfil)
144 if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__);
145 if (pIndexProfil < 1) throw IllegalArgumentException("", __FILE__, __LINE__);
149 // Get the profil info.
151 med_err ret = MEDprofilInfo(
156 if (ret != 0) throw IOException("", __FILE__, __LINE__);
158 // Read the data of the profil.
159 med_int* dataTmp = new med_int[numData];
164 if (ret != 0) throw IOException("", __FILE__, __LINE__);
165 for (int itData = 0 ; itData < numData ; itData++)
167 mTable.insert(dataTmp[itData]);
173 void Profil::readProfilBinding(med_idt pMEDfile, char* pMeshName)
175 if (strlen(mName) == 0) throw IllegalStateException("The name of the Profil is empty", __FILE__, __LINE__);
179 char cha[MED_TAILLE_NOM + 1];
183 med_int numComponents;
184 char gaussLocName[MED_TAILLE_NOM + 1];
185 char profilName[MED_TAILLE_NOM + 1];
188 unsigned char* fieldData;
189 bool fieldOnNodes = false;
190 med_entite_maillage entity;
191 med_geometrie_element geom;
195 char dtunit[MED_TAILLE_PNOM + 1];
197 char maa[MED_TAILLE_NOM + 1];
202 // Get the number of field in this file.
203 nbField = MEDnChamp(pMEDfile, 0);
204 if (nbField < 0) throw IOException("Can't read number of fields.", __FILE__, __LINE__);
206 for (int i = 1; i <= nbField; ++i)
208 // Get the number of component.
209 numComponents = MEDnChamp(pMEDfile, i);
210 comp = new char[numComponents * MED_TAILLE_PNOM + 1];
211 unit = new char[numComponents * MED_TAILLE_PNOM + 1];
212 // Get some information about the field.
213 ret = MEDchampInfo(pMEDfile, i, cha, &type, comp, unit, numComponents);
214 if (nbField < 0) throw IOException("Can't read fields info.", __FILE__, __LINE__);
215 // Get the size of one component.
218 case MED_FLOAT64: sizeOfType = 8; break;
219 case MED_INT64: sizeOfType = 8; break;
220 case MED_INT32: sizeOfType = 4; break;
221 case MED_INT: sizeOfType = 4; break;
222 default: throw IllegalStateException("Unknown field data type", __FILE__, __LINE__);
225 // Try to figure out if the field is on nodes or on elements.
226 med_int numTimeStepNodes = MEDnPasdetemps(
230 (med_geometrie_element) 0);
232 if (numTimeStepNodes < 0) throw IOException("Can't read fields number of time steps.", __FILE__, __LINE__);
233 if (numTimeStepNodes > 0)
238 geom = (med_geometrie_element) 0;
243 fieldOnNodes = false;
246 for (int i = 0; i < eMaxMedMesh; ++i)
248 if (MEDnPasdetemps(pMEDfile, cha, entity, CELL_TYPES[i]) > 0)
250 geom = CELL_TYPES[i];
257 // Get some information about the first time step.
258 ret = MEDpasdetempsInfo(
272 if (ret < 0) throw IOException("Can't read fields time steps info.", __FILE__, __LINE__);
273 // Get the number of values for the first time step.
274 med_int nval = MEDnVal(
283 if (nval < 0) throw IOException("Can't read fields number values.", __FILE__, __LINE__);
284 // Read the one time step of the field.
285 sizeOfData = sizeOfType * numComponents * nval * 10;
286 unsigned char* fieldData = new unsigned char[sizeOfData];
287 gaussLocName[0] = '\0';
303 if (ret < 0) throw IOException("Can't read field.", __FILE__, __LINE__);
304 // Does this field use our profile ?
305 if (strncmp(profilName, mName, MED_TAILLE_NOM) == 0)
315 mBinding = OnElements;
323 void Profil::writeMED(med_idt pMEDfile)
325 if (pMEDfile == 0) throw IOException("pMEDfile is 0", __FILE__, __LINE__);
326 if (strlen(mName) > MED_TAILLE_NOM) throw IllegalStateException("Empty name", __FILE__, __LINE__);
327 if (mTable.size() == 0) throw IllegalStateException("Empty table", __FILE__, __LINE__);
329 std::set<med_int>::iterator it;
330 med_int* dataTmp = new med_int[mTable.size()];
331 for (it = mTable.begin(), itData = 0; it != mTable.end(); ++it, ++itData)
333 dataTmp[itData] = *it;
335 med_err ret = MEDprofilEcr(
341 if (ret != 0) throw IOException("Can't write profil", __FILE__, __LINE__);
347 ostream& operator<<(ostream& pOs, Profil& pP)
349 pOs << "Profil:" << endl;
350 pOs << " Name=|" << pP.mName << "|" << endl;
351 pOs << " Size=" << pP.mTable.size() << endl;
353 pOs << " Entities=[";
354 for (std::set<med_int>::iterator it = pP.mTable.begin();
355 it != pP.mTable.end(); ++it)
365 } // namespace multipr