]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/test_copie_support.cxx
Salome HOME
update after merging trhe branches CEA_V3_0_x, OCC_V3_1_0_a1_x, and the main
[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 using namespace std;
18 using namespace MEDMEM;
19 using namespace MED_EN;
20
21 void affiche_support(const SUPPORT * mySupport) 
22 {
23   cout << "  - Name : "<<mySupport->getName().c_str()<<endl ;
24   cout << "  - Description : "<<mySupport->getDescription().c_str()<<endl ;
25   cout << "  - Entity : "<<mySupport->getEntity()<<endl ;
26   cout << "  - Entities list : "<<endl ;
27   if (!(mySupport->isOnAllElements())) {
28     int NumberOfTypes = mySupport->getNumberOfTypes() ;
29     cout<<"  - NumberOfTypes : "<<NumberOfTypes<<endl;
30     const medGeometryElement * Types = mySupport->getTypes() ;
31     for (int j=0;j<NumberOfTypes;j++) {
32       cout<<"    * Type "<<Types[j]<<" : ";
33       int NumberOfElements = mySupport->getNumberOfElements(Types[j]) ;
34       const int * Number = mySupport->getNumber(Types[j]) ;
35       for (int k=0; k<NumberOfElements;k++)
36         cout << Number[k] << " ";
37       cout << endl ;
38     }
39   } else
40     cout << "    Is on all entities !"<< endl;
41 }
42
43
44 void affiche_famille(MESH *myMesh,medEntityMesh Entity) 
45 {
46   int NumberOfFamilies = myMesh->getNumberOfFamilies(Entity) ;
47   cout << "NumberOfFamilies : "<<NumberOfFamilies<<endl;
48   for (int i=1; i<NumberOfFamilies+1;i++) {
49     const FAMILY* myFamily = myMesh->getFamily(Entity,i);
50     affiche_support(myFamily);
51     cout << "  - Identifier : "<<myFamily->getIdentifier()<<endl ;
52     int NumberOfAttributes = myFamily->getNumberOfAttributes() ;
53     cout << "  - Attributes ("<<NumberOfAttributes<<") :"<<endl;
54     for (int j=1;j<NumberOfAttributes+1;j++)
55       cout << "    * "<<myFamily->getAttributeIdentifier(j)<<" : "<<myFamily->getAttributeValue(j)<<", "<<myFamily->getAttributeDescription(j).c_str()<<endl ;
56     int NumberOfGroups = myFamily->getNumberOfGroups() ;
57     cout << "  - Groups ("<<NumberOfGroups<<") :"<<endl;
58     for (int j=1;j<NumberOfGroups+1;j++)
59       cout << "    * "<<myFamily->getGroupName(j).c_str()<<endl ;
60   }
61 }
62
63 void affiche_groupe(MESH *myMesh,medEntityMesh Entity) 
64 {
65   int NumberOfGroups = myMesh->getNumberOfGroups(Entity) ;
66   cout << "NumberOfGroups : "<<NumberOfGroups<<endl;
67   for (int i=1; i<NumberOfGroups+1;i++) {
68     const GROUP* myGroup = myMesh->getGroup(Entity,i);
69     affiche_support(myGroup);
70     int NumberOfFamillies = myGroup->getNumberOfFamilies() ;
71     cout << "  - Families ("<<NumberOfFamillies<<") :"<<endl;
72     for (int j=1;j<NumberOfFamillies+1;j++)
73       cout << "    * "<<myGroup->getFamily(j)->getName().c_str()<<endl ;
74   }
75 }
76
77 int main (int argc, char ** argv) {
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 }