1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "MEDMEM_Exception.hxx"
24 #include "MEDMEM_Mesh.hxx"
25 #include "MEDMEM_Family.hxx"
26 #include "MEDMEM_Group.hxx"
28 #include "MEDMEM_Support.hxx"
29 #include "MEDMEM_Field.hxx"
30 #include "MEDMEM_MedMeshDriver.hxx"
31 #include "MEDMEM_MedFieldDriver.hxx"
32 #include "MEDMEM_define.hxx"
40 using namespace MEDMEM;
41 using namespace MED_EN;
43 static double dmax(double x, double y) { return (x>y)?x:y;}
45 static double dmin(double x, double y) { return (x>y)?y:x;}
47 static double infty = 1.e20;
49 static void affiche_support(const SUPPORT * mySupport)
51 cout << " - Name : "<<mySupport->getName().c_str()<<endl ;
52 cout << " - Description : "<<mySupport->getDescription().c_str()<<endl ;
53 cout << " - Entity : "<<mySupport->getEntity()<<endl ;
54 cout << " - Entities list : "<<endl ;
55 if (!(mySupport->isOnAllElements())) {
56 int NumberOfTypes = mySupport->getNumberOfTypes() ;
57 cout<<" - NumberOfTypes : "<<NumberOfTypes<<endl;
58 const medGeometryElement * Types = mySupport->getTypes() ;
59 for (int j=0;j<NumberOfTypes;j++) {
60 cout << " * Type "<<Types[j]<<" : " ;
61 int NumberOfElements = mySupport->getNumberOfElements(Types[j]) ;
62 const int * Number = mySupport->getNumber(Types[j]) ;
63 for (int k=0; k<NumberOfElements;k++)
64 cout << Number[k] << " ";
68 cout << " Is on all entities !"<< endl;
72 static void affiche_famille(MESH *myMesh,medEntityMesh Entity)
74 int NumberOfFamilies = myMesh->getNumberOfFamilies(Entity) ;
75 cout << "NumberOfFamilies : "<<NumberOfFamilies<<endl;
76 for (int i=1; i<NumberOfFamilies+1;i++) {
77 const FAMILY* myFamily = myMesh->getFamily(Entity,i);
78 affiche_support(myFamily);
79 cout << " - Identifier : "<<myFamily->getIdentifier()<<endl ;
80 int NumberOfAttributes = myFamily->getNumberOfAttributes() ;
81 cout << " - Attributes ("<<NumberOfAttributes<<") :"<<endl;
82 for (int j=1;j<NumberOfAttributes+1;j++)
83 cout << " * "<<myFamily->getAttributeIdentifier(j)<<" : "<<myFamily->getAttributeValue(j)<<", "<<myFamily->getAttributeDescription(j).c_str()<<endl ;
84 int NumberOfGroups = myFamily->getNumberOfGroups() ;
85 cout << " - Groups ("<<NumberOfGroups<<") :"<<endl;
86 for (int j=1;j<NumberOfGroups+1;j++)
87 cout << " * "<<myFamily->getGroupName(j).c_str()<<endl ;
91 static void affiche_groupe(MESH *myMesh,medEntityMesh Entity)
93 int NumberOfGroups = myMesh->getNumberOfGroups(Entity) ;
94 cout << "NumberOfGroups : "<<NumberOfGroups<<endl;
95 for (int i=1; i<NumberOfGroups+1;i++) {
96 const GROUP* myGroup = myMesh->getGroup(Entity,i);
97 affiche_support(myGroup);
98 int NumberOfFamillies = myGroup->getNumberOfFamilies() ;
99 cout << " - Families ("<<NumberOfFamillies<<") :"<<endl;
100 for (int j=1;j<NumberOfFamillies+1;j++)
101 cout << " * "<<myGroup->getFamily(j)->getName().c_str()<<endl ;
105 int main (int argc, char ** argv) {
107 if ((argc !=3) && (argc != 4)) {
108 cerr << "Usage : " << argv[0]
109 << " filename meshname [fieldname]" << endl << endl;
113 string filename = argv[1] ;
114 string meshname = argv[2] ;
116 MESH * myMesh= new MESH(MED_DRIVER,filename,meshname) ;
118 int SpaceDimension = myMesh->getSpaceDimension() ;
119 int MeshDimension = myMesh->getMeshDimension() ;
120 int NumberOfNodes = myMesh->getNumberOfNodes() ;
122 cout << "Space Dimension : " << SpaceDimension << endl << endl ;
124 cout << "Mesh Dimension : " << MeshDimension << endl << endl ;
126 const double * Coordinates = myMesh->getCoordinates(MED_FULL_INTERLACE) ;
128 cout << "Show Nodes Coordinates : " << endl ;
130 cout << "Name :" << endl ;
131 const string * CoordinatesNames = myMesh->getCoordinatesNames() ;
132 for(int i=0; i<SpaceDimension ; i++) {
133 cout << " - " << CoordinatesNames[i] << endl ;
135 cout << "Unit :" << endl ;
136 const string * CoordinatesUnits = myMesh->getCoordinatesUnits() ;
137 for(int i=0; i<SpaceDimension ; i++) {
138 cout << " - " << CoordinatesUnits[i] << endl ;
140 for(int i=0; i<NumberOfNodes ; i++) {
141 cout << "Nodes " << i+1 << " : " ;
142 for (int j=0; j<SpaceDimension ; j++)
143 cout << Coordinates[i*SpaceDimension+j] << " " ;
147 int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ;
148 const medGeometryElement * Types = myMesh->getTypes(MED_CELL) ;
150 cout << "Show Connectivity (Nodal) :" << endl ;
151 for (int i=0; i<NumberOfTypes; i++) {
152 cout << "For type " << Types[i] << " : " << endl ;
153 int NumberOfElements = myMesh->getNumberOfElements(MED_CELL,Types[i]);
154 const int * connectivity = myMesh->getConnectivity(MED_NODAL,MED_CELL,Types[i]);
155 int NomberOfNodesPerCell = Types[i]%100 ;
156 for (int j=0;j<NumberOfElements;j++){
157 cout << "Element "<< j+1 <<" : " ;
158 for (int k=0;k<NomberOfNodesPerCell;k++)
159 cout << connectivity[j*NomberOfNodesPerCell+k]<<" ";
164 cout << "Show Family :"<<endl ;
165 affiche_famille(myMesh,MED_NODE);
166 affiche_famille(myMesh,MED_CELL);
167 affiche_famille(myMesh,MED_FACE);
168 affiche_famille(myMesh,MED_EDGE);
170 cout << "Show Group :"<<endl ;
171 affiche_groupe(myMesh,MED_NODE);
172 affiche_groupe(myMesh,MED_CELL);
173 affiche_groupe(myMesh,MED_FACE);
174 affiche_groupe(myMesh,MED_EDGE);
176 cout << "Show Reverse Nodal Connectivity :" << endl ;
177 const int * ReverseNodalConnectivity = myMesh->getReverseConnectivity(MED_NODAL) ;
178 const int * ReverseNodalConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_NODAL) ;
179 for (int i=0; i<NumberOfNodes; i++) {
180 cout << "Node "<<i+1<<" : " ;
181 for (int j=ReverseNodalConnectivityIndex[i];j<ReverseNodalConnectivityIndex[i+1];j++)
182 cout << ReverseNodalConnectivity[j-1] << " " ;
186 cout << "Show Connectivity (Descending) :" << endl ;
187 int NumberOfElements ;
188 const int * connectivity ;
189 const int * connectivity_index ;
190 myMesh->calculateConnectivity(MED_DESCENDING,MED_CELL);
192 NumberOfElements = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
193 connectivity = myMesh->getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
194 connectivity_index = myMesh->getConnectivityIndex(MED_DESCENDING,MED_CELL);
196 catch (MEDEXCEPTION& m) {
197 cout << m.what() << endl ;
200 for (int j=0;j<NumberOfElements;j++) {
201 cout << "Element "<<j+1<<" : " ;
202 for (int k=connectivity_index[j];k<connectivity_index[j+1];k++)
203 cout << connectivity[k-1]<<" ";
207 cout << "Show Reverse Descending Connectivity :" << endl ;
208 const int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
209 const int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
211 int NumberOfConstituents = 0;
213 medEntityMesh constituentEntity ;
215 if (MeshDimension==3) {
216 constituent = "Face" ;
217 constituentEntity = MED_FACE ;
220 if (MeshDimension==2) {
221 constituent = "Edge" ;
222 constituentEntity = MED_EDGE ;
225 if (MeshDimension==1) {
226 INFOS_MED("ERROR : MeshDimension = 1 !");
227 INFOS_MED("We could not see Reverse Descending Connectivity.") ;
229 NumberOfConstituents = myMesh->getNumberOfElements (constituentEntity,MED_ALL_ELEMENTS);
230 for (int i=0; i<NumberOfConstituents; i++) {
231 cout << constituent <<i+1<<" : " ;
232 for (int j=ReverseDescendingConnectivityIndex[i];j<ReverseDescendingConnectivityIndex[i+1];j++)
233 cout << ReverseDescendingConnectivity[j-1] << " " ;
237 cout << "Show "<<constituent<<" Connectivity (Nodal) :" << endl ;
238 const int * face_connectivity = myMesh->getConnectivity(MED_NODAL,constituentEntity,MED_ALL_ELEMENTS);
239 const int * face_connectivity_index = myMesh->getConnectivityIndex(MED_NODAL,constituentEntity);
240 for (int i=0; i<NumberOfConstituents; i++) {
241 cout << constituent <<i+1<<" : " ;
242 for (int j=face_connectivity_index[i];j<face_connectivity_index[i+1];j++)
243 cout << face_connectivity[j-1]<<" ";
247 /* test of normal, area, volume, barycenter */
249 const SUPPORT* support1 = myMesh->getSupportOnAll(constituentEntity);
250 cout << "Building of the Support on all cells dimensionned (Meshdim-1) of the mesh :"<< endl ;
251 cout << "Face in 3D or Edge in 2D" << endl;
253 cout << "Getting the normal of each face of this support !" << endl ;
255 FIELD<double>* normal = myMesh->getNormal(support1);
257 double normal_square, norm ;
258 double maxnorm=-infty;
259 double minnorm=infty;
261 for (int i = 1; i<=NumberOfConstituents;i++)
264 cout << "Normal " << i << " " ;
265 for (int j=1; j<=SpaceDimension; j++)
267 tmp_value = normal->getValueIJ(i,j) ;
268 normal_square += tmp_value*tmp_value ;
269 cout << tmp_value << " " ;
271 norm = sqrt(normal_square);
272 maxnorm = dmax(maxnorm,norm);
273 minnorm = dmin(minnorm,norm);
274 cout << ", Norm = " << norm << endl;
276 cout << "Max Norm " << maxnorm << " Min Norm " << minnorm << endl;
279 normal->removeReference() ;
281 if (SpaceDimension == 2)
283 cout << "Getting the length of each edge !" << endl ;
285 FIELD<double>* length = myMesh->getLength(support1);
287 double length_value,maxlength,minlength;
290 for (int i = 1; i<=NumberOfConstituents;i++)
292 length_value = length->getValueIJ(i,1) ;
293 cout << "Length " << i << " " << length_value << endl;
294 maxlength = dmax(maxlength,length_value);
295 minlength = dmin(minlength,length_value);
297 cout << "Max Length " << maxlength << " Min Length " << minlength << endl;
299 length->removeReference();
302 cout << "Building of the Support on all space-dimensionned cells of the mesh :"<< endl ;
303 const SUPPORT * support = myMesh->getSupportOnAll( MED_CELL );
305 cout << "Getting the barycenter of each element of this support !" << endl ;
307 FIELD<double>* barycenter = myMesh->getBarycenter(support);
308 NumberOfElements = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
310 for (int i = 1; i<=NumberOfElements;i++)
312 if (SpaceDimension == 3)
313 cout << "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) << " " << barycenter->getValueIJ(i,3) << endl;
315 if (SpaceDimension == 2)
316 cout << "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) << endl;
319 barycenter->removeReference();
321 if (SpaceDimension == 3)
323 cout << "Getting the Volume of each element of this support which is a 3D one !" << endl;
325 FIELD<double>* volume = myMesh->getVolume(support);
327 double maxvol,minvol,voltot;
331 for (int i = 1; i<=NumberOfElements;i++)
333 cout << "Volume " << i << " " << volume->getValueIJ(i,1) << endl;
334 maxvol = dmax(maxvol,volume->getValueIJ(i,1));
335 minvol = dmin(minvol,volume->getValueIJ(i,1));
336 voltot = voltot + volume->getValueIJ(i,1);
339 cout << "Max Volume " << maxvol << " Min Volume " << minvol << endl;
340 cout << "Support Volume " << voltot << endl;
342 volume->removeReference() ;
344 else if (SpaceDimension == 2)
346 cout << "Getting the Area of each element of this support which is a 2D one !" << endl;
348 FIELD<double>* area = myMesh->getArea(support);
350 double maxarea,minarea,areatot;
354 for (int i = 1; i<=NumberOfElements;i++)
356 cout << "Area " << i << " " << area->getValueIJ(i,1) << endl;
357 maxarea = dmax(maxarea,area->getValueIJ(i,1));
358 minarea = dmin(minarea,area->getValueIJ(i,1));
359 areatot = areatot + area->getValueIJ(i,1);
362 cout << "Max Area " << maxarea << " Min Area " << minarea << endl;
363 cout << "Support Area " << areatot << endl;
365 area->removeReference();
368 if (argc < 4) return 0;
372 if (argc != 4) exit(0) ;
373 // else we have a field !
375 string fieldname = argv[3];
377 const SUPPORT * mySupport = myMesh->getSupportOnAll(MED_CELL);
378 FIELD<double> * myField= new FIELD<double>() ;
380 myField->setName(fieldname);
381 myField->setSupport(mySupport);
382 MED_FIELD_RDONLY_DRIVER<double> myFieldDriver(filename,myField) ;
383 myFieldDriver.setFieldName(fieldname);
384 myFieldDriver.open() ;
388 myFieldDriver.read() ;
392 mySupport = myMesh->getSupportOnAll(MED_NODE);
393 myField->setSupport(mySupport);
396 myFieldDriver.read() ;
400 cout << "Field " << fieldname << " not found !!!" << endl ;
405 myFieldDriver.close() ;
407 cout << "Field "<< myField->getName() << " : " <<myField->getDescription() << endl ;
408 int NumberOfComponents = myField->getNumberOfComponents() ;
409 cout << "- Nombre de composantes : "<< NumberOfComponents << endl ;
410 for (int i=1; i<NumberOfComponents+1; i++)
412 cout << " - composante "<<i<<" :"<<endl ;
413 cout << " - nom : "<<myField->getComponentName(i)<< endl;
414 cout << " - description : "<<myField->getComponentDescription(i) << endl;
415 cout << " - units : "<<myField->getMEDComponentUnit(i) << endl;
417 cout << "- iteration :" << endl ;
418 cout << " - numero : " << myField->getIterationNumber()<< endl ;
419 cout << " - ordre : " << myField->getOrderNumber()<< endl ;
420 cout << " - temps : " << myField->getTime()<< endl ;
422 cout << "- Valeurs :"<<endl;
423 int NumberOf = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
424 MEDMEM_Array<double> * myvalue = myField->getArrayNoGauss();
425 const double * value ;
426 for (int i=1; i<NumberOf+1; i++)
428 value = myvalue->getRow(i) ;
429 for (int j=0; j<NumberOfComponents; j++)
430 cout << value[j]<< " ";
435 myField->removeReference();
436 myMesh->removeReference();