]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Family.cxx
Salome HOME
remove a reference to the $MED_ROOT_DIR in the Makefile.in wich is useless
[modules/med.git] / src / MEDMEM / MEDMEM_Family.cxx
1 /*
2  File MEDMEM_Family.cxx
3  $Header$
4 */
5
6 #include "MEDMEM_Mesh.hxx"
7 #include "MEDMEM_Family.hxx"
8
9 using namespace std;
10 using namespace MEDMEM;
11 using namespace MED_EN;
12
13 /*
14   Those defines are from the med File V2.1 and for this class they are fixed.
15 */
16
17 #define MED_TAILLE_DESC 200
18 #define MED_TAILLE_LNOM  80
19
20 FAMILY::FAMILY():_identifier(0), _numberOfAttribute(0), 
21                  _attributeIdentifier((int*)NULL),_attributeValue((int*)NULL), _attributeDescription((string*)NULL),
22                  _numberOfGroup(0), _groupName((string*)NULL) 
23 {
24     MESSAGE("FAMILY::FAMILY()");
25 };
26
27 FAMILY::FAMILY(MESH* Mesh, int Identifier, string Name, int NumberOfAttribute,
28                int *AttributeIdentifier, int *AttributeValue, string AttributeDescription,
29                int NumberOfGroup, string GroupName,
30                int * MEDArrayNodeFamily,
31                int ** MEDArrayCellFamily,
32                int ** MEDArrayFaceFamily,
33                int ** MEDArrayEdgeFamily
34                ): SUPPORT(Mesh,Name),
35                   _identifier(Identifier), 
36                   _numberOfAttribute(NumberOfAttribute), 
37                   _numberOfGroup(NumberOfGroup)
38 {
39   MESSAGE("FAMILY(int Identifier, string Name, int NumberOfAttribute,int *AttributeIdentifier,int *AttributeValue,string AttributeDescription,int NumberOfGroup,string GroupName, int ** Number) : "<<Identifier);
40
41   _isOnAllElts = false ;
42   // replace them by pointerOf ?
43   _attributeIdentifier = new int[_numberOfAttribute] ;
44   memcpy(_attributeIdentifier,AttributeIdentifier,_numberOfAttribute*sizeof(int));
45   _attributeValue = new int[_numberOfAttribute] ;
46   memcpy(_attributeValue,AttributeValue,_numberOfAttribute*sizeof(int));
47
48   _attributeDescription=new string[_numberOfAttribute];
49   for (int i=0;i<NumberOfAttribute;i++) {
50     _attributeDescription[i].assign(AttributeDescription,i*MED_TAILLE_DESC,MED_TAILLE_DESC);
51     _attributeDescription[i].erase(strlen(_attributeDescription[i].c_str()));
52     //SCRUTE(_attributeDescription[i]);
53   }
54  
55   _groupName=new string[_numberOfGroup];
56   for (int i=0;i<NumberOfGroup;i++) {
57     _groupName[i].assign(GroupName,i*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
58     _groupName[i].erase(strlen(_groupName[i].c_str()));
59     //SCRUTE(_groupName[i]);
60   }
61
62   // well, we must set SUPPORT attribut
63   _description = "FAMILY" ;
64   // on which geometric type :
65   bool Find = false ;
66   
67
68   // ************************ NODES RELATED PART *************************************************
69   // Scan every node family number <NodeFamilyNumber[i]> in order to create 
70   // the list <tmp_NodesList> of node numbers <i+1> belonging to the family <_identifier>
71   int NumberOfNodes         = _mesh->getNumberOfNodes();
72   int NumberOfNodesInFamily = 0 ;
73   //int * NodeFamilyNumber    = _mesh->getMEDArrayNodeFamily() ;   // EF : TEMPORAIRE !!
74   int * tmp_NodesList       = new int[NumberOfNodes] ;           // Un peu brutal...., oui mais ce n'est qu'un tableau de travail !
75   for (int i=0; i<NumberOfNodes; i++)
76     if ( _identifier == MEDArrayNodeFamily[i] ) {
77       tmp_NodesList[NumberOfNodesInFamily]=i+1 ;
78       NumberOfNodesInFamily++;
79     }
80
81   SCRUTE(NumberOfNodesInFamily);
82
83   // If we found nodes set the family attributes adequatly
84   if (NumberOfNodesInFamily>0) {
85     
86     Find = true ;
87     
88     _entity = MED_NODE ;
89 //      _numberOfGeometricType = 1 ;
90 //      _geometricType = new medGeometryElement[1] ;
91 //      _geometricType[0]=MED_NONE ;
92     
93     // family on all NODE
94     if (NumberOfNodesInFamily==NumberOfNodes) {
95       _isOnAllElts = true ;
96       update();
97     } else {
98       _numberOfGeometricType = 1 ;
99       if (_geometricType!=NULL) delete[] _geometricType ;
100       _geometricType = new medGeometryElement[1] ;
101       _geometricType[0]=MED_NONE ;
102       _isOnAllElts= false ;
103       if (_numberOfElements!=NULL) delete[] _numberOfElements ;
104       _numberOfElements = new int[1] ;
105       _numberOfElements[0]=NumberOfNodesInFamily ;
106       _totalNumberOfElements=NumberOfNodesInFamily;
107       
108 //        _number=new MEDSKYLINEARRAY(1,NumberOfNodesInFamily) ;
109 //        int * NumberIndex = _number->getIndex();
110 //        int * NumberValue = _number->getValue();
111       int * NumberIndex = new int[2];
112       int * NumberValue = new int[NumberOfNodesInFamily];
113
114       NumberIndex[0]=1;                          //set the MEDSKYLINEARRAY Index table
115       NumberIndex[1]=1+NumberOfNodesInFamily;    //set the MEDSKYLINEARRAY Index table
116       for(int i=0; i<NumberOfNodesInFamily; i++) // OH LA LA... 
117         NumberValue[i]=tmp_NodesList[i] ;        // RESIZE de tmp_NodesList serait plus efficace !!!!!!!!
118       // PG : pas de problème, si ca marche. Il faudra déplacer le delete !
119       if(_number!=NULL) delete _number ;
120       _number=new MEDSKYLINEARRAY(1,NumberOfNodesInFamily,NumberIndex,NumberValue) ;
121       delete[] NumberIndex ;
122       delete[] NumberValue ;
123     }
124   }
125   delete[] tmp_NodesList ;
126   
127
128
129   // ************************ CELLS RELATED PART *************************************************
130   // If we previously found nodes in our family don't scan the CELLS because a
131   // family contains different geometic types of only one entity type.
132   // ?? Scan every cell family number <NodeFamilyNumber[i]> in order to create 
133   // ?? the list <tmp_NodesList> of node numbers <i+1> belonging to the family <_identifier>
134   if (!Find) {
135     Find = build(MED_CELL,MEDArrayCellFamily) ;
136   }
137   // on face ?
138   if (!Find) {
139     if ((_mesh->existConnectivity(MED_NODAL,MED_FACE))|(_mesh->existConnectivity(MED_DESCENDING,MED_FACE))) {
140       Find = build(MED_FACE,MEDArrayFaceFamily) ;
141     }
142   }
143   
144   // on edge ?
145   if (!Find) {
146     if ((_mesh->existConnectivity(MED_NODAL,MED_EDGE))|(_mesh->existConnectivity(MED_DESCENDING,MED_EDGE))) {
147       Find = build(MED_EDGE,MEDArrayEdgeFamily) ;
148     }
149   }
150   // That's all !
151
152   // if not find : no entity in familly !!!
153   if (!Find) {
154     _numberOfGeometricType = 0 ;
155     _isOnAllElts = false ;
156     MESSAGE ("FAMILY() : No entity found !") ;
157   } 
158   // already done by support !!!!
159 //    else { // set gauss point number to be equal one !
160 //      _numberOfGaussPoint = new int[_numberOfGeometricType] ;
161 //      for (int i=0; i<_numberOfGeometricType; i++)
162 //        _numberOfGaussPoint[i]=1 ;
163 //    }
164
165
166   MESSAGE("Well now ??? :::");
167
168   MESSAGE("Name : "<< getName());
169   MESSAGE("Description : "<< getDescription());
170   MESSAGE("Mesh name : " << getMesh()->getName());
171   MESSAGE("Entity : "<< getEntity());
172   MESSAGE("Entity list :");
173   if (!(isOnAllElements())) {
174     int numberoftypes = getNumberOfTypes() ;
175     MESSAGE("NumberOfTypes : "<<numberoftypes);
176     const medGeometryElement * types = getTypes();
177     for (int j=0;j<numberoftypes;j++) {
178       int numberOfElements = getNumberOfElements(types[j]);
179       MESSAGE("    * Type "<<types[j]<<" : there is(are) "<<numberOfElements<<" element(s) : ");
180       const int * number = getNumber(types[j]);
181       SCRUTE(number);
182       for (int k=0; k<numberOfElements;k++)
183         MESSAGE("________________ " << number[k]);
184     }
185   } else
186     MESSAGE("Is on all entities !");
187   
188
189
190 };
191
192 FAMILY::FAMILY(const FAMILY & m):SUPPORT(m)
193 {
194   MESSAGE("FAMILY::FAMILY(FAMILY & m)");
195   _identifier = m._identifier;
196   _numberOfAttribute = m._numberOfAttribute;
197   if (m._attributeIdentifier != NULL)
198     {
199       _attributeIdentifier = new int[m._numberOfAttribute];
200       memcpy(_attributeIdentifier,m._attributeIdentifier,m._numberOfAttribute*sizeof(int));
201     }
202   else
203     _attributeIdentifier = (int *) NULL;
204   if (m._attributeValue != NULL)
205     {
206       _attributeValue = new int[m._numberOfAttribute];
207       memcpy(_attributeValue,m._attributeValue,m._numberOfAttribute*sizeof(int));
208     }
209   else
210     _attributeValue = (int *) NULL;
211   if (m._attributeDescription != NULL)
212     {
213       _attributeDescription = new string[m._numberOfAttribute];
214       for (int i=0;i<m._numberOfAttribute;i++)
215         _attributeDescription[i] = m._attributeDescription[i];
216     }
217   else
218     _attributeDescription = (string *) NULL;
219   _numberOfGroup = m._numberOfGroup;
220   if (m._groupName != NULL)
221     {
222       _groupName = new string[m._numberOfGroup];
223       for (int i=0;i<m._numberOfGroup;i++)
224         _groupName[i]=m._groupName[i];
225     }
226   else
227     _groupName = (string *) NULL;
228 };
229
230 FAMILY::FAMILY(const SUPPORT & s):SUPPORT(s)
231 {
232   MESSAGE("FAMILY::FAMILY(const SUPPORT & s)");
233
234   _identifier = 0;
235   _numberOfAttribute = 0;
236   _attributeIdentifier = (int*) NULL;
237   _attributeValue = (int*) NULL;
238   _attributeDescription = (string*) NULL;
239   _numberOfGroup = 0;
240   _groupName= (string*) NULL;
241 };
242
243 FAMILY::~FAMILY() 
244 {
245     MESSAGE("~FAMILY()");
246     if(_attributeIdentifier!=NULL)
247        delete[] _attributeIdentifier;
248     if(_attributeValue!=NULL)
249        delete[] _attributeValue;
250     if(_attributeDescription!=NULL)
251        delete[] _attributeDescription;
252     if(_groupName!=NULL)
253        delete[] _groupName;
254 };
255   
256 FAMILY & FAMILY::operator=(const FAMILY &fam) 
257 {
258     MESSAGE("FAMILY::operator=");
259     _identifier = fam._identifier;
260     _numberOfAttribute = fam._numberOfAttribute; 
261     _attributeIdentifier = fam._attributeIdentifier;
262     _attributeValue = fam._attributeValue;
263     _attributeDescription = fam._attributeDescription;
264     _numberOfGroup = fam._numberOfGroup;
265     _groupName = fam._groupName;
266     return *this;
267 };
268
269 ostream & MEDMEM::operator<<(ostream &os, FAMILY &myFamily)
270 {
271   // how do cast without duplicate ?
272   os << (SUPPORT) myFamily;
273
274   os << "  - Identifier : "<<myFamily.getIdentifier()<<endl;
275   int numberofattributes = myFamily.getNumberOfAttributes();
276   os << "  - Attributes ("<<numberofattributes<<") :"<<endl;
277   for (int j=1;j<numberofattributes+1;j++)
278     os << "    * "<<myFamily.getAttributeIdentifier(j)<<" : "<<myFamily.getAttributeValue(j)<<", "<<myFamily.getAttributeDescription(j).c_str()<<endl;
279   int numberofgroups = myFamily.getNumberOfGroups();
280   os << "  - Groups ("<<numberofgroups<<") :"<<endl;
281   for (int j=1;j<numberofgroups+1;j++)
282     os << "    * "<<myFamily.getGroupName(j).c_str()<<endl ;
283
284   return os;
285 };
286
287 ostream & MEDMEM::operator<<(ostream &os, const FAMILY &myFamily)
288 {
289   // how do cast without duplicate ?
290   os << (SUPPORT) myFamily;
291
292   os << "  - Identifier : "<<myFamily.getIdentifier()<<endl;
293   int numberofattributes = myFamily.getNumberOfAttributes();
294   os << "  - Attributes ("<<numberofattributes<<") :"<<endl;
295   for (int j=1;j<numberofattributes+1;j++)
296     os << "    * "<<myFamily.getAttributeIdentifier(j)<<" : "<<myFamily.getAttributeValue(j)<<", "<<myFamily.getAttributeDescription(j).c_str()<<endl;
297   int numberofgroups = myFamily.getNumberOfGroups();
298   os << "  - Groups ("<<numberofgroups<<") :"<<endl;
299   for (int j=1;j<numberofgroups+1;j++)
300     os << "    * "<<myFamily.getGroupName(j).c_str()<<endl ;
301
302   return os;
303 };
304
305 bool FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)
306 {
307   MESSAGE("FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)");
308   bool Find = false ;
309   // Get types information from <_mesh>
310   int    numberOfTypes             = _mesh->getNumberOfTypesWithPoly(Entity) ;
311   medGeometryElement * types       = _mesh->getTypesWithPoly(Entity) ;
312   
313   int *  numberOfElementsInFamily         = new int[numberOfTypes] ;
314   int    numberOfElementTypesInFamily     = 0 ;
315   
316   medGeometryElement * tmp_Types  = new medGeometryElement[numberOfTypes];
317   int ** tmp_ElementsLists                = new int*[numberOfTypes] ;
318   //  int *  GeometricTypeNumber           = new int[numberOfTypes] ;
319   const int *  GlobalNumberingIndex          = _mesh->getGlobalNumberingIndex(Entity);
320   
321
322   SCRUTE(numberOfTypes);
323
324   // we search for all elements in this family
325   for (int TypeNumber=0; TypeNumber < numberOfTypes; TypeNumber++) {
326     
327     int NumberOfElements             = _mesh->getNumberOfElementsWithPoly(Entity,types[TypeNumber]) ;
328     int NumberOfElementsInThisFamily = 0 ;
329     int * ElementsOfThisFamilyNumber = FamilyNumber[TypeNumber];
330     int * tmp_ElementsList           = new int[NumberOfElements];
331       
332     for (int i=0; i<NumberOfElements; i++)
333       {
334         SCRUTE(ElementsOfThisFamilyNumber[i]);
335         if (_identifier == ElementsOfThisFamilyNumber[i]) {
336           tmp_ElementsList[NumberOfElementsInThisFamily]=i+GlobalNumberingIndex[TypeNumber] ;
337           NumberOfElementsInThisFamily++;
338         }
339       }
340     
341     if (NumberOfElementsInThisFamily>0) {// we have found some elements
342       numberOfElementsInFamily[numberOfElementTypesInFamily]=NumberOfElementsInThisFamily;
343
344       //int * ElementsList = tmp_ElementsList.resize(NumberOfElementsInThisFamily);
345       int * ElementsList = new int[NumberOfElementsInThisFamily] ;
346       memcpy(ElementsList,tmp_ElementsList,sizeof(int)*NumberOfElementsInThisFamily); // RESIZE de tmp_NodesList serait plus efficace !!!!!!!!
347         
348       tmp_ElementsLists[numberOfElementTypesInFamily]=ElementsList ;
349       tmp_Types[numberOfElementTypesInFamily]=types[TypeNumber];
350       //      GeometricTypeNumber[numberOfElementTypesInFamily]=TypeNumber+1;
351       numberOfElementTypesInFamily++;
352       //      delete [] ElementsList;
353     }
354     delete[] tmp_ElementsList;
355   }
356   
357   // we define all attribut in SUPPORT :
358   if (numberOfElementTypesInFamily>0) { // we have found elements
359     Find = true ;
360     _entity = Entity ;
361     _numberOfGeometricType = numberOfElementTypesInFamily ;
362     if (_geometricType!=NULL) delete[] _geometricType ;
363     _geometricType = new medGeometryElement[numberOfElementTypesInFamily] ;
364     _isOnAllElts = false ;
365     if (_numberOfElements!=NULL) delete[] _numberOfElements ;
366     _numberOfElements = new int[numberOfElementTypesInFamily] ;
367     _totalNumberOfElements=0;
368
369     //_numberOfGaussPoint = new int[numberOfElementTypesInFamily] ;
370
371     //int * numberIndex = new int[numberOfElementTypesInFamily+1];
372     //numberIndex[0]=1;
373     for (int i=0; i<numberOfElementTypesInFamily; i++) {
374       _geometricType[i]=tmp_Types[i] ;
375       //numberIndex[i+1]=numberIndex[i]+numberOfElementsInFamily[i];
376       _numberOfElements[i]=numberOfElementsInFamily[i]; // plutot un resize !!
377       _totalNumberOfElements+=_numberOfElements[i];
378       //_numberOfGaussPoint[i]=1;
379     }
380     //    delete[] numberOfElementsInFamily;
381     //    delete[] tmp_Types;
382     //    delete[] GeometricTypeNumber;
383       
384     // family on all ELEMENT ?
385     if (_totalNumberOfElements == _mesh->getNumberOfElementsWithPoly(Entity,MED_ALL_ELEMENTS) && Entity==MED_EN::MED_CELL) {
386       _isOnAllElts = true ;
387       // all others attributs are rights !
388       for (int i=0; i<_numberOfGeometricType; i++)
389         delete[] tmp_ElementsLists[i];
390     } else {
391       int *NumberValue = new int[_totalNumberOfElements];
392       int *NumberIndex = new int[_numberOfGeometricType+1];
393       NumberIndex[0]=1;
394       for (int i=0; i<_numberOfGeometricType; i++) {
395         NumberIndex[i+1]=NumberIndex[i]+_numberOfElements[i];
396         for (int j=NumberIndex[i]; j<NumberIndex[i+1]; j++)
397           NumberValue[j-1]=tmp_ElementsLists[i][j-NumberIndex[i]];
398         delete[] tmp_ElementsLists[i];
399       }
400       if(_number!=NULL) delete _number ;
401       _number = new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,NumberIndex,NumberValue);
402       delete[] NumberIndex ;
403       delete[] NumberValue ;
404     }
405   }
406   delete[] tmp_Types;
407   delete[] types;
408   delete[] numberOfElementsInFamily;
409
410   delete[] tmp_ElementsLists;
411
412   return Find ;
413 }
414