1 // Copyright (C) 2011 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
20 #include "HomardMedCommun.h"
33 #include "utilities.h"
34 // =======================================================================
35 std::set<std::string> GetListeGroupesInMedFile(const char * aFile)
36 // =======================================================================
38 std::set<std::string> ListeGroupes;
39 med_idt medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
40 if ( medIdt < 0 ) { return ListeGroupes; };
42 char meshname[MED_NAME_SIZE+1];
43 med_int spacedim,meshdim;
44 med_mesh_type meshtype;
45 char descriptionription[MED_COMMENT_SIZE+1];
46 char dtunit[MED_SNAME_SIZE+1];
47 med_sorting_type sortingtype;
49 med_axis_type axistype;
50 int naxis = MEDmeshnAxis(medIdt,1);
51 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
52 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
53 med_err aRet = MEDmeshInfo(medIdt,
66 if ( aRet < 0 ) { return ListeGroupes; };
68 med_int nfam, ngro, natt;
69 if ((nfam = MEDnFamily(medIdt,meshname)) < 0) { return ListeGroupes; };
71 char familyname[MED_NAME_SIZE+1];
73 for (int i=0;i<nfam;i++)
75 if ((ngro = MEDnFamilyGroup(medIdt,meshname,i+1)) < 0)
77 // GERALD -- QMESSAGE BOX
78 std::cerr << " Error : Families are unreadable" << std::endl;
79 std::cerr << "Pb avec la famille : " << i+1 << std::endl;
82 if (ngro == 0) continue;
84 if ((natt = MEDnFamily23Attribute(medIdt,meshname,i+1)) < 0)
86 // GERALD -- QMESSAGE BOX
87 std::cerr << " Error : Families are unreadable" << std::endl;
88 std::cerr << "Pb avec la famille : " << i+1 << std::endl;
92 med_int* attide = (med_int*) malloc(sizeof(med_int)*natt);
93 med_int* attval = (med_int*) malloc(sizeof(med_int)*natt);
94 char* attdes = (char *) malloc(MED_COMMENT_SIZE*natt+1);
95 char* gro = (char*) malloc(MED_LNAME_SIZE*ngro+1);
97 med_err aRet = MEDfamily23Info(medIdt,
109 // GERALD -- QMESSAGE BOX
110 std::cerr << " Error : Families are unreadable" << std::endl;
111 std::cerr << "Pb avec la famille : " << i+1 << std::endl;
117 if ((numfam )> 0) { continue;} // On ne garde que les familles d elts
119 for (int j=0;j<ngro;j++)
121 char str2[MED_LNAME_SIZE+1];
122 strncpy(str2,gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
123 str2[MED_LNAME_SIZE] = '\0';
124 ListeGroupes.insert(std::string(str2));
128 MEDfileClose(medIdt);
132 // =======================================================================
133 std::vector<double> GetBoundingBoxInMedFile(const char * aFile)
134 // =======================================================================
136 // Le vecteur en retour contiendra les informations suivantes :
137 // en position 0 et 1 Xmin, Xmax et en position 2 Dx si < 0 2D
138 // en position 3 et 4 Ymin, Ymax et en position 5 Dy si < 0 2D
139 // en position 6 et 7 Zmin, Zmax et en position 8 Dz si < 0 2D
140 // 9 distance max dans le maillage
142 std::vector<double> LesExtremes;
144 // Ouverture du Fichier Med
145 med_idt medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
148 // GERALD -- QMESSAGE BOX
149 std::cerr << "Error : mesh is unreadable" << std::endl;
153 // Le fichier Med est lisible
154 // Boucle sur les noms de maillage
155 med_int numberOfMeshes = MEDnMesh(medIdt) ;
156 if (numberOfMeshes != 1 )
158 // GERALD -- QMESSAGE BOX
159 std::cerr << "Error : file contains more than one mesh" << std::endl;
163 char meshname[MED_NAME_SIZE+1];
164 med_int spacedim,meshdim;
165 med_mesh_type meshtype;
166 char descriptionription[MED_COMMENT_SIZE+1];
167 char dtunit[MED_SNAME_SIZE+1];
168 med_sorting_type sortingtype;
170 med_axis_type axistype;
171 int naxis = MEDmeshnAxis(medIdt,1);
172 char *axisname=new char[naxis*MED_SNAME_SIZE+1];
173 char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
174 med_err aRet = MEDmeshInfo(medIdt,
190 // GERALD -- QMESSAGE BOX
191 std::cerr << "Error : mesh is unreadable" << std::endl;
196 med_int nnoe = MEDmeshnEntity(medIdt,
208 // GERALD -- QMESSAGE BOX
209 std::cerr << "Error : mesh is unreadable" << std::endl;
213 med_float* coo = (med_float*) malloc(sizeof(med_float)*nnoe*spacedim);
215 aRet = MEDmeshNodeCoordinateRd(medIdt,
223 // GERALD -- QMESSAGE BOX
224 std::cerr << "Error : mesh coordinates are unreadable" << std::endl;
228 med_float xmin,xmax,ymin,ymax,zmin,zmax;
232 for (int i=1;i<nnoe;i++)
234 xmin = std::min(xmin,coo[i]);
235 xmax = std::max(xmax,coo[i]);
240 ymin=coo[nnoe]; ymax=coo[nnoe];
241 for (int i=nnoe+1;i<2*nnoe;i++)
243 ymin = std::min(ymin,coo[i]);
244 ymax = std::max(ymax,coo[i]);
257 zmin=coo[2*nnoe]; zmax=coo[2*nnoe];
258 for (int i=2*nnoe+1;i<3*nnoe;i++)
260 zmin = std::min(zmin,coo[i]);
261 zmax = std::max(zmax,coo[i]);
269 MEDfileClose(medIdt);
271 MESSAGE( "_______________________________________");
272 MESSAGE( "xmin : " << xmin << " xmax : " << xmax );
273 MESSAGE( "ymin : " << ymin << " ymax : " << ymax );
274 MESSAGE( "zmin : " << zmin << " zmax : " << zmax );
275 MESSAGE( "_______________________________________" );
276 double epsilon = 1.e-6 ;
277 LesExtremes.push_back(xmin);
278 LesExtremes.push_back(xmax);
279 LesExtremes.push_back(0);
280 LesExtremes.push_back(ymin);
281 LesExtremes.push_back(ymax);
282 LesExtremes.push_back(0);
283 LesExtremes.push_back(zmin);
284 LesExtremes.push_back(zmax);
285 LesExtremes.push_back(0);
288 double max1=std::max ( LesExtremes[1] - LesExtremes[0] , LesExtremes[4] - LesExtremes[3] ) ;
289 double max2=std::max ( max1 , LesExtremes[7] - LesExtremes[6] ) ;
290 LesExtremes.push_back(max2);
292 // LesExtremes[0] = Xmini du maillage
293 // LesExtremes[1] = Xmaxi du maillage
294 // LesExtremes[2] = increment de progression en X
295 // LesExtremes[3,4,5] : idem pour Y
296 // LesExtremes[6,7,8] : idem pour Z
297 // LesExtremes[9] = ecart maximal entre coordonnees
298 // On fait un traitement pour dans le cas d'une coordonnee constante
299 // inhiber ce cas en mettant un increment negatif
301 double diff = LesExtremes[1] - LesExtremes[0];
302 if (fabs(diff) > epsilon*max2)
304 LesExtremes[2] = diff/100.;
308 LesExtremes[2] = -1. ;
311 diff = LesExtremes[4] - LesExtremes[3];
312 if (fabs(diff) > epsilon*max2)
314 LesExtremes[5]=diff/100.;
318 LesExtremes[5] = -1. ;
321 diff = LesExtremes[7] - LesExtremes[6];
322 if (fabs(diff) > epsilon*max2)
324 LesExtremes[8]=diff/100.;
328 LesExtremes[8] = -1. ;
331 MESSAGE ( "_______________________________________" );
332 MESSAGE ( "xmin : " << LesExtremes[0] << " xmax : " << LesExtremes[1] << " xincr : " << LesExtremes[2] );
333 MESSAGE ( "ymin : " << LesExtremes[3] << " ymax : " << LesExtremes[4] << " yincr : " << LesExtremes[5] );
334 MESSAGE ( "zmin : " << LesExtremes[6] << " zmax : " << LesExtremes[7] << " zincr : " << LesExtremes[8] );
335 MESSAGE ( "dmax : " << LesExtremes[9] );
336 MESSAGE ( "_______________________________________" );