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