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