6 #include "MEDMEM_Exception.hxx"
7 #include "MEDMEM_Mesh.hxx"
8 #include "MEDMEM_Family.hxx"
9 #include "MEDMEM_Group.hxx"
11 #include "MEDMEM_MedMeshDriver.hxx"
12 #include "MEDMEM_MedFieldDriver.hxx"
13 #include "MEDMEM_Support.hxx"
14 #include "MEDMEM_Field.hxx"
15 #include "MEDMEM_define.hxx"
18 double dmax(double x, double y) { return (x>y)?x:y;}
20 double dmin(double x, double y) { return (x>y)?y:x;}
24 void affiche_support(SUPPORT * mySupport)
26 MESSAGE( " - Name : "<<mySupport->getName().c_str());
27 MESSAGE( " - Description : "<<mySupport->getDescription().c_str());
28 MESSAGE( " - Entity : "<<mySupport->getEntity());
29 MESSAGE( " - Entities list : ");
30 if (!(mySupport->isOnAllElements())) {
31 int NumberOfTypes = mySupport->getNumberOfTypes() ;
32 MESSAGE(" - NumberOfTypes : "<<NumberOfTypes);
33 medGeometryElement * Types = mySupport->getTypes() ;
34 for (int j=0;j<NumberOfTypes;j++) {
35 MESSAGE( " * Type "<<Types[j]<<" : " );
36 int NumberOfElements = mySupport->getNumberOfElements(Types[j]) ;
37 int * Number = mySupport->getNumber(Types[j]) ;
38 for (int k=0; k<NumberOfElements;k++)
39 MESSAGE( Number[k] << " ");
43 MESSAGE( " Is on all entities !");
47 void affiche_famille(MESH *myMesh,medEntityMesh Entity)
49 int NumberOfFamilies = myMesh->getNumberOfFamilies(Entity) ;
50 MESSAGE( "NumberOfFamilies : "<<NumberOfFamilies);
51 for (int i=1; i<NumberOfFamilies+1;i++) {
52 FAMILY* myFamily = myMesh->getFamily(Entity,i);
53 affiche_support(myFamily);
54 MESSAGE( " - Identifier : "<<myFamily->getIdentifier());
55 int NumberOfAttributes = myFamily->getNumberOfAttributes() ;
56 MESSAGE( " - Attributes ("<<NumberOfAttributes<<") :");
57 for (int j=1;j<NumberOfAttributes+1;j++)
58 MESSAGE( " * "<<myFamily->getAttributeIdentifier(j)<<" : "<<myFamily->getAttributeValue(j)<<", "<<myFamily->getAttributeDescription(j).c_str());
59 int NumberOfGroups = myFamily->getNumberOfGroups() ;
60 MESSAGE( " - Groups ("<<NumberOfGroups<<") :");
61 for (int j=1;j<NumberOfGroups+1;j++)
62 MESSAGE( " * "<<myFamily->getGroupName(j).c_str());
66 void affiche_groupe(MESH *myMesh,medEntityMesh Entity)
68 int NumberOfGroups = myMesh->getNumberOfGroups(Entity) ;
69 MESSAGE( "NumberOfGroups : "<<NumberOfGroups);
70 for (int i=1; i<NumberOfGroups+1;i++) {
71 GROUP* myGroup = myMesh->getGroup(Entity,i);
72 affiche_support(myGroup);
73 int NumberOfFamillies = myGroup->getNumberOfFamilies() ;
74 MESSAGE( " - Families ("<<NumberOfFamillies<<") :");
75 for (int j=1;j<NumberOfFamillies+1;j++)
76 MESSAGE( " * "<<myGroup->getFamily(j)->getName().c_str());
80 int main (int argc, char ** argv) {
84 if ((argc !=3) && (argc != 4)) {
85 cerr << "Usage : " << argv[0]
86 << " filename meshname [fieldname]" << endl << endl;
90 string filename = argv[1] ;
91 string meshname = argv[2] ;
93 // MESH * myMesh= new MESH(MED_DRIVER,filename,meshname) ;
94 MESH * myMesh= new MESH() ;
95 myMesh->setName(meshname);
96 MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
97 myMeshDriver.setMeshName(meshname);
100 myMeshDriver.close() ;
102 // int drv = myMesh->addDriver(MED_DRIVER,"sortie.med",meshname);
103 // myMesh->write(drv);
106 int SpaceDimension = myMesh->getSpaceDimension() ;
107 int MeshDimension = myMesh->getMeshDimension() ;
108 int NumberOfNodes = myMesh->getNumberOfNodes() ;
110 MESSAGE( "Space Dimension : " << SpaceDimension << endl );
112 MESSAGE( "Mesh Dimension : " << MeshDimension << endl );
114 const double * Coordinates = myMesh->getCoordinates(MED_FULL_INTERLACE) ;
116 MESSAGE( "Show Nodes Coordinates : " );
119 string * CoordinatesNames = myMesh->getCoordinatesNames() ;
120 for(int i=0; i<SpaceDimension ; i++) {
121 MESSAGE( " - " << CoordinatesNames[i] );
124 string * CoordinatesUnits = myMesh->getCoordinatesUnits() ;
125 for(int i=0; i<SpaceDimension ; i++) {
126 MESSAGE( " - " << CoordinatesUnits[i] );
128 for(int i=0; i<NumberOfNodes ; i++) {
129 MESSAGE( "Nodes " << i+1 << " : " );
130 for (int j=0; j<SpaceDimension ; j++)
131 MESSAGE( Coordinates[i*SpaceDimension+j] << " " );
135 int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ;
136 medGeometryElement * Types = myMesh->getTypes(MED_CELL) ;
138 MESSAGE( "Show Connectivity (Nodal) :" );
139 for (int i=0; i<NumberOfTypes; i++) {
140 MESSAGE( "For type " << Types[i] << " : " );
141 int NumberOfElements = myMesh->getNumberOfElements(MED_CELL,Types[i]);
142 int * connectivity = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,Types[i]);
143 int NomberOfNodesPerCell = Types[i]%100 ;
144 for (int j=0;j<NumberOfElements;j++){
145 MESSAGE( "Element "<< j+1 <<" : " );
146 for (int k=0;k<NomberOfNodesPerCell;k++)
147 MESSAGE( connectivity[j*NomberOfNodesPerCell+k]<<" ");
152 MESSAGE( "Show Family :");
153 affiche_famille(myMesh,MED_NODE);
154 affiche_famille(myMesh,MED_CELL);
155 affiche_famille(myMesh,MED_FACE);
156 affiche_famille(myMesh,MED_EDGE);
158 MESSAGE( "Show Group :");
159 affiche_groupe(myMesh,MED_NODE);
160 affiche_groupe(myMesh,MED_CELL);
161 affiche_groupe(myMesh,MED_FACE);
162 affiche_groupe(myMesh,MED_EDGE);
164 MESSAGE( "Show Reverse Nodal Connectivity :" );
165 int * ReverseNodalConnectivity = myMesh->getReverseConnectivity(MED_NODAL) ;
166 int * ReverseNodalConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_NODAL) ;
167 for (int i=0; i<NumberOfNodes; i++) {
168 MESSAGE( "Node "<<i+1<<" : " );
169 for (int j=ReverseNodalConnectivityIndex[i];j<ReverseNodalConnectivityIndex[i+1];j++)
170 MESSAGE( ReverseNodalConnectivity[j-1] << " " );
174 MESSAGE( "Show Connectivity (Descending) :" );
175 int NumberOfElements ;
177 int * connectivity_index ;
178 myMesh->calculateConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL);
180 NumberOfElements = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
181 connectivity = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
182 connectivity_index = myMesh->getConnectivityIndex(MED_DESCENDING,MED_CELL);
184 catch (MEDEXCEPTION m) {
188 for (int j=0;j<NumberOfElements;j++) {
189 MESSAGE( "Element "<<j+1<<" : " );
190 for (int k=connectivity_index[j];k<connectivity_index[j+1];k++)
191 MESSAGE( connectivity[k-1]<<" ");
195 MESSAGE( "Show Reverse Descending Connectivity :" );
196 int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
197 int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
199 int NumberOfConstituents = 0;
201 medEntityMesh constituentEntity ;
203 if (MeshDimension==3) {
204 constituent = "Face" ;
205 constituentEntity = MED_FACE ;
208 if (MeshDimension==2) {
209 constituent = "Edge" ;
210 constituentEntity = MED_EDGE ;
213 if (MeshDimension==1) {
214 MESSAGE("ERROR : MeshDimension = 1 !");
215 MESSAGE("We could not see Reverse Descending Connectivity.") ;
217 NumberOfConstituents = myMesh->getNumberOfElements (constituentEntity,MED_ALL_ELEMENTS);
218 for (int i=0; i<NumberOfConstituents; i++) {
219 MESSAGE( constituent <<i+1<<" : " );
220 for (int j=ReverseDescendingConnectivityIndex[i];j<ReverseDescendingConnectivityIndex[i+1];j++)
221 MESSAGE( ReverseDescendingConnectivity[j-1] << " " );
225 MESSAGE( "Show "<<constituent<<" Connectivity (Nodal) :" );
226 int * face_connectivity = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,constituentEntity,MED_ALL_ELEMENTS);
227 int * face_connectivity_index = myMesh->getConnectivityIndex(MED_NODAL,constituentEntity);
228 for (int i=0; i<NumberOfConstituents; i++) {
229 MESSAGE( constituent <<i+1<<" : " );
230 for (int j=face_connectivity_index[i];j<face_connectivity_index[i+1];j++)
231 MESSAGE( face_connectivity[j-1]<<" ");
235 /* test of normal, area, volume, barycenter */
237 SUPPORT * support1 = (SUPPORT*) NULL;
239 FIELD<double>* normal = new FIELD<double>::FIELD();
240 FIELD<double>* length = new FIELD<double>::FIELD();
243 string support_name = "Support on all " ;
244 support_name+=constituent;
245 support1 = new SUPPORT(myMesh,support_name,constituentEntity);
246 MESSAGE( "Building of the Support on all cells dimensionned (Meshdim-1) of the mesh :");
247 MESSAGE( "Face in 3D or Edge in 2D" );
249 MESSAGE( "Getting the normal of each face of this support !" );
251 normal = myMesh->getNormal(support1);
253 double normal_square, norm ;
254 double maxnorm=-infty;
255 double minnorm=infty;
257 for (int i = 1; i<=NumberOfConstituents;i++) {
259 MESSAGE( "Normal " << i << " " );
260 for (int j=1; j<=SpaceDimension; j++) {
261 tmp_value = normal->getValueIJ(i,j) ;
262 normal_square += tmp_value*tmp_value ;
263 MESSAGE( tmp_value << " " );
265 norm = sqrt(normal_square);
266 maxnorm = dmax(maxnorm,norm);
267 minnorm = dmin(minnorm,norm);
268 MESSAGE( ", Norm = " << norm );
270 MESSAGE( "Max Norm " << maxnorm << " Min Norm " << minnorm );
273 if (SpaceDimension == 2)
275 MESSAGE( "Getting the length of each edge !" );
277 length = myMesh->getLength(support1);
279 double length_value,maxlength,minlength;
282 for (int i = 1; i<=NumberOfConstituents;i++)
284 length_value = length->getValueIJ(i,1) ;
285 MESSAGE( "Length " << i << " " << length_value );
286 maxlength = dmax(maxlength,length_value);
287 minlength = dmin(minlength,length_value);
289 MESSAGE( "Max Length " << maxlength << " Min Length " << minlength );
292 MESSAGE( "Building of the Support on all space-dimensionned cells of the mesh :");
293 SUPPORT * support = new SUPPORT(myMesh);
295 MESSAGE( "Getting the barycenter of each element of this support !" );
297 FIELD<double>* barycenter = new FIELD<double>::FIELD();
299 barycenter = myMesh->getBarycenter(support);
300 NumberOfElements = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
302 for (int i = 1; i<=NumberOfElements;i++)
304 if (SpaceDimension == 3)
305 MESSAGE( "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) << " " << barycenter->getValueIJ(i,3) );
307 if (SpaceDimension == 2)
308 MESSAGE( "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) );
311 FIELD<double>* volume = new FIELD<double>::FIELD();
312 FIELD<double>* area = new FIELD<double>::FIELD();
316 if (SpaceDimension == 3)
318 MESSAGE( "Getting the Volume of each element of this support which is a 3D one !" );
320 volume = myMesh->getVolume(support);
322 double maxvol,minvol,voltot;
326 for (int i = 1; i<=NumberOfElements;i++)
328 MESSAGE( "Volume " << i << " " << volume->getValueIJ(i,1) );
329 maxvol = dmax(maxvol,volume->getValueIJ(i,1));
330 minvol = dmin(minvol,volume->getValueIJ(i,1));
331 voltot = voltot + volume->getValueIJ(i,1);
334 MESSAGE( "Max Volume " << maxvol << " Min Volume " << minvol );
335 MESSAGE( "Support Volume " << voltot );
337 else if (SpaceDimension == 2)
339 MESSAGE( "Getting the Area of each element of this support which is a 2D one !" );
341 area = myMesh->getArea(support);
343 // MESSAGE( "nb of comp "<< area->getNumberOfComponents() << " length " << area->getSupport()->getNumberOfElements(MED_ALL_ELEMENTS) );
345 double maxarea,minarea,areatot;
349 for (int i = 1; i<=NumberOfElements;i++)
351 MESSAGE( "Area " << i << " " << area->getValueIJ(i,1) );
352 maxarea = dmax(maxarea,area->getValueIJ(i,1));
353 minarea = dmin(minarea,area->getValueIJ(i,1));
354 areatot = areatot + area->getValueIJ(i,1);
357 MESSAGE( "Max Area " << maxarea << " Min Area " << minarea );
358 MESSAGE( "Support Area " << areatot );
361 if (barycenter != NULL) delete barycenter;
362 if (volume != NULL ) delete volume;
363 if (area != NULL ) delete area;
366 if (argc < 4) return 0;
370 if (argc != 4) exit(0) ;
371 // else we have a field !
373 string fieldname = argv[3];
375 // SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE);
376 SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_cell",MED_CELL);
377 FIELD<double> * myField= new FIELD<double>() ;
379 myField->setName(fieldname);
380 myField->setSupport(mySupport);
381 MED_FIELD_RDONLY_DRIVER<double> myFieldDriver(filename,myField) ;
382 myFieldDriver.setFieldName(fieldname);
383 myFieldDriver.open() ;
386 myFieldDriver.read() ;
389 mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE);
390 myField->setSupport(mySupport);
392 myFieldDriver.read() ;
394 cout << "Field " << fieldname << " not found !!!" << endl ;
399 myFieldDriver.close() ;
401 MESSAGE( "Field "<< myField->getName() << " : " <<myField->getDescription() );
402 int NumberOfComponents = myField->getNumberOfComponents() ;
403 MESSAGE( "- Nombre de composantes : "<< NumberOfComponents );
404 for (int i=1; i<NumberOfComponents+1; i++) {
405 MESSAGE( " - composante "<<i<<" :");
406 MESSAGE( " - nom : "<<myField->getComponentName(i));
407 MESSAGE( " - description : "<<myField->getComponentDescription(i) );
408 MESSAGE( " - units : "<<myField->getMEDComponentUnit(i) );
410 MESSAGE( "- iteration :" );
411 MESSAGE( " - numero : " << myField->getIterationNumber());
412 MESSAGE( " - ordre : " << myField->getOrderNumber());
413 MESSAGE( " - temps : " << myField->getTime());
415 MESSAGE( "- Valeurs :");
416 int NumberOf = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
417 // for (int i=1; i<NumberOfComponents+1; i++) {
418 // double * value = myField->getValueI(MED_NO_INTERLACE,i) ;
419 // for (int j=0; j<NumberOf; j++)
420 // MESSAGE( value[j]<< " ");
423 for (int i=1; i<NumberOf+1; i++) {
424 double * value = myField->getValueI(MED_FULL_INTERLACE,i) ;
425 for (int j=0; j<NumberOfComponents; j++)
426 MESSAGE( value[j]<< " ");