]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/test_copie_support.cxx
Salome HOME
remove a reference to the $MED_ROOT_DIR in the Makefile.in wich is useless
[modules/med.git] / src / MEDMEM / test_copie_support.cxx
1 #include<string>
2
3 #include <math.h>
4 #include <stdlib.h>
5
6 #include "MEDMEM_Exception.hxx"
7 #include "MEDMEM_Mesh.hxx"
8 #include "MEDMEM_Family.hxx"
9 #include "MEDMEM_Group.hxx"
10
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"
16
17 #ifdef _DEBUG_
18 #include "LocalTraceCollector.hxx"
19 #endif /* ifdef _DEBUG_*/
20
21 using namespace std;
22 using namespace MEDMEM;
23 using namespace MED_EN;
24
25 void affiche_support(const SUPPORT * mySupport) 
26 {
27   cout << "  - Name : "<<mySupport->getName().c_str()<<endl ;
28   cout << "  - Description : "<<mySupport->getDescription().c_str()<<endl ;
29   cout << "  - Entity : "<<mySupport->getEntity()<<endl ;
30   cout << "  - Entities list : "<<endl ;
31   if (!(mySupport->isOnAllElements())) {
32     int NumberOfTypes = mySupport->getNumberOfTypes() ;
33     cout<<"  - NumberOfTypes : "<<NumberOfTypes<<endl;
34     const medGeometryElement * Types = mySupport->getTypes() ;
35     for (int j=0;j<NumberOfTypes;j++) {
36       cout<<"    * Type "<<Types[j]<<" : ";
37       int NumberOfElements = mySupport->getNumberOfElements(Types[j]) ;
38       const int * Number = mySupport->getNumber(Types[j]) ;
39       for (int k=0; k<NumberOfElements;k++)
40         cout << Number[k] << " ";
41       cout << endl ;
42     }
43   } else
44     cout << "    Is on all entities !"<< endl;
45 }
46
47
48 void affiche_famille(MESH *myMesh,medEntityMesh Entity) 
49 {
50   int NumberOfFamilies = myMesh->getNumberOfFamilies(Entity) ;
51   cout << "NumberOfFamilies : "<<NumberOfFamilies<<endl;
52   for (int i=1; i<NumberOfFamilies+1;i++) {
53     const FAMILY* myFamily = myMesh->getFamily(Entity,i);
54     affiche_support(myFamily);
55     cout << "  - Identifier : "<<myFamily->getIdentifier()<<endl ;
56     int NumberOfAttributes = myFamily->getNumberOfAttributes() ;
57     cout << "  - Attributes ("<<NumberOfAttributes<<") :"<<endl;
58     for (int j=1;j<NumberOfAttributes+1;j++)
59       cout << "    * "<<myFamily->getAttributeIdentifier(j)<<" : "<<myFamily->getAttributeValue(j)<<", "<<myFamily->getAttributeDescription(j).c_str()<<endl ;
60     int NumberOfGroups = myFamily->getNumberOfGroups() ;
61     cout << "  - Groups ("<<NumberOfGroups<<") :"<<endl;
62     for (int j=1;j<NumberOfGroups+1;j++)
63       cout << "    * "<<myFamily->getGroupName(j).c_str()<<endl ;
64   }
65 }
66
67 void affiche_groupe(MESH *myMesh,medEntityMesh Entity) 
68 {
69   int NumberOfGroups = myMesh->getNumberOfGroups(Entity) ;
70   cout << "NumberOfGroups : "<<NumberOfGroups<<endl;
71   for (int i=1; i<NumberOfGroups+1;i++) {
72     const GROUP* myGroup = myMesh->getGroup(Entity,i);
73     affiche_support(myGroup);
74     int NumberOfFamillies = myGroup->getNumberOfFamilies() ;
75     cout << "  - Families ("<<NumberOfFamillies<<") :"<<endl;
76     for (int j=1;j<NumberOfFamillies+1;j++)
77       cout << "    * "<<myGroup->getFamily(j)->getName().c_str()<<endl ;
78   }
79 }
80
81 int main (int argc, char ** argv) {
82 #ifdef _DEBUG_
83   LocalTraceCollector::instance();
84 #endif /* ifdef _DEBUG_*/
85
86   int read;
87
88   if (argc <3) { // after 3, ignored !
89     cerr << "Usage : " << argv[0] 
90          << " filename meshname" << endl << endl;
91     exit(-1);
92   }
93
94   string filename = argv[1] ;
95   string meshname = argv[2] ;
96
97   MESH * myMesh= new MESH() ;
98   myMesh->setName(meshname);
99   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
100   myMeshDriver.setMeshName(meshname);
101   myMeshDriver.open() ;
102   myMeshDriver.read() ;
103   myMeshDriver.close() ;
104
105   //Construction d'un support total
106   SUPPORT * mySupport = new SUPPORT(myMesh,"Support on CELLs",MED_CELL);
107
108   cout << "Show Support on all :"<<endl ;
109   affiche_support(mySupport);
110   SUPPORT * mySupport2 = new SUPPORT(* mySupport);
111   delete mySupport;
112   affiche_support(mySupport2);
113   delete mySupport2;
114
115   //Construction d'un support partiel
116   mySupport = new SUPPORT(myMesh,"Support on CELLs",MED_CELL);
117   mySupport->setAll(false);
118
119   //  int NumberOfGeometricType = 1;
120   int NumberOfGeometricType = 0;
121   //  int TotalNumberOfEntity = 2;
122   //  medGeometryElement * GeometricTypePartial = new medGeometryElement[NumberOfGeometricType];
123   //  GeometricTypePartial[0] = MED_HEXA8;
124   int TotalNumberOfElements = 0;
125   int * NumberOfElements = new int[myMesh->getNumberOfTypes(MED_CELL)];
126   //  NumberOfEntity[0] = 2;
127   //  int * NumberValue = new int[TotalNumberOfEntity];
128   int * NumberValue = new int[myMesh->getGlobalNumberingIndex(MED_CELL)[myMesh->getNumberOfTypes(MED_CELL)]-1];
129   //  NumberValue[0] = 14;
130   //  NumberValue[1] = 15;
131   int cmp = 0;
132   medGeometryElement * GeometricTypePartial = new medGeometryElement[myMesh->getNumberOfTypes(MED_CELL)];
133   const medGeometryElement * GeometricType = myMesh->getTypes(MED_CELL);
134   for (int i=0;i<myMesh->getNumberOfTypes(MED_CELL);i=i+2)
135     { 
136       NumberOfGeometricType=NumberOfGeometricType+1;
137       TotalNumberOfElements=TotalNumberOfElements+myMesh->getNumberOfElements(MED_CELL,GeometricType[i]);
138       NumberOfElements[i/2]=myMesh->getNumberOfElements(MED_CELL,GeometricType[i]);
139       for (int j=0;j<myMesh->getNumberOfElements(MED_CELL,GeometricType[i]);j++)
140         {
141           NumberValue[cmp]=myMesh->getGlobalNumberingIndex(MED_CELL)[i]+j;
142           cmp=cmp+1;
143         }
144       GeometricTypePartial[i/2]=GeometricType[i];
145     }
146
147   mySupport->setpartial("Support partiel",NumberOfGeometricType,TotalNumberOfElements,GeometricTypePartial,NumberOfElements,NumberValue);
148
149   delete[] NumberOfElements ;
150   delete[] NumberValue ;
151   delete[] GeometricTypePartial ;
152
153   cout << "Show Partial Support :"<<endl ;
154   affiche_support(mySupport);
155   mySupport2 = new SUPPORT(* mySupport);
156   delete mySupport;
157   affiche_support(mySupport2);
158   delete mySupport2;
159
160   /*
161   cout << "Show Family :"<<endl ;
162   affiche_famille(myMesh,MED_NODE);
163   affiche_famille(myMesh,MED_CELL);
164   affiche_famille(myMesh,MED_FACE);
165   affiche_famille(myMesh,MED_EDGE);
166
167   cout << "Show Group :"<<endl ;
168   affiche_groupe(myMesh,MED_NODE);
169   affiche_groupe(myMesh,MED_CELL);
170   affiche_groupe(myMesh,MED_FACE);
171   affiche_groupe(myMesh,MED_EDGE);
172   */
173
174   delete myMesh ;
175
176   return 0;
177 }