7 #include "MEDMEM_Mesh.hxx"
8 #include "MEDMEM_Family.hxx"
9 using namespace MEDMEM;
11 FAMILY::FAMILY():_identifier(0), _numberOfAttribute(0),
12 _attributeIdentifier((int*)NULL),_attributeValue((int*)NULL), _attributeDescription((string*)NULL),
13 _numberOfGroup(0), _groupName((string*)NULL)
15 MESSAGE("FAMILY::FAMILY()");
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)
30 MESSAGE("FAMILY(int Identifier, string Name, int NumberOfAttribute,int *AttributeIdentifier,int *AttributeValue,string AttributeDescription,int NumberOfGroup,string GroupName, int ** Number) : "<<Identifier);
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));
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]);
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]);
53 // well, we must set SUPPORT attribut
54 _description = "FAMILY" ;
55 // on which geometric type :
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++;
72 SCRUTE(NumberOfNodesInFamily);
74 // If we found nodes set the family attributes adequatly
75 if (NumberOfNodesInFamily>0) {
80 // _numberOfGeometricType = 1 ;
81 // _geometricType = new medGeometryElement[1] ;
82 // _geometricType[0]=MED_NONE ;
85 if (NumberOfNodesInFamily==NumberOfNodes) {
89 _numberOfGeometricType = 1 ;
90 if (_geometricType!=NULL) delete[] _geometricType ;
91 _geometricType = new medGeometryElement[1] ;
92 _geometricType[0]=MED_NONE ;
94 if (_numberOfElements!=NULL) delete[] _numberOfElements ;
95 _numberOfElements = new int[1] ;
96 _numberOfElements[0]=NumberOfNodesInFamily ;
97 _totalNumberOfElements=NumberOfNodesInFamily;
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];
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 ;
116 delete[] tmp_NodesList ;
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>
126 Find = build(MED_CELL,MEDArrayCellFamily) ;
130 if ((_mesh->existConnectivity(MED_NODAL,MED_FACE))|(_mesh->existConnectivity(MED_DESCENDING,MED_FACE))) {
131 Find = build(MED_FACE,MEDArrayFaceFamily) ;
137 if ((_mesh->existConnectivity(MED_NODAL,MED_EDGE))|(_mesh->existConnectivity(MED_DESCENDING,MED_EDGE))) {
138 Find = build(MED_EDGE,MEDArrayEdgeFamily) ;
143 // if not find : no entity in familly !!!
145 _numberOfGeometricType = 0 ;
146 _isOnAllElts = false ;
147 MESSAGE ("FAMILY() : No entity found !") ;
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 ;
157 MESSAGE("Well now ??? :::");
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]);
173 for (int k=0; k<numberOfElements;k++)
174 MESSAGE("________________ " << number[k]);
177 MESSAGE("Is on all entities !");
183 FAMILY::FAMILY(const FAMILY & m):SUPPORT(m)
185 MESSAGE("FAMILY::FAMILY(FAMILY & m)");
186 _identifier = m._identifier;
187 _numberOfAttribute = m._numberOfAttribute;
188 if (m._attributeIdentifier != NULL)
190 _attributeIdentifier = new int[m._numberOfAttribute];
191 memcpy(_attributeIdentifier,m._attributeIdentifier,m._numberOfAttribute*sizeof(int));
194 _attributeIdentifier = (int *) NULL;
195 if (m._attributeValue != NULL)
197 _attributeValue = new int[m._numberOfAttribute];
198 memcpy(_attributeValue,m._attributeValue,m._numberOfAttribute*sizeof(int));
201 _attributeValue = (int *) NULL;
202 if (m._attributeDescription != NULL)
204 _attributeDescription = new string[m._numberOfAttribute];
205 for (int i=0;i<m._numberOfAttribute;i++)
206 _attributeDescription[i] = m._attributeDescription[i];
209 _attributeDescription = (string *) NULL;
210 _numberOfGroup = m._numberOfGroup;
211 if (m._groupName != NULL)
213 _groupName = new string[m._numberOfGroup];
214 for (int i=0;i<m._numberOfGroup;i++)
215 _groupName[i]=m._groupName[i];
218 _groupName = (string *) NULL;
221 FAMILY::FAMILY(const SUPPORT & s):SUPPORT(s)
223 MESSAGE("FAMILY::FAMILY(const SUPPORT & s)");
226 _numberOfAttribute = 0;
227 _attributeIdentifier = (int*) NULL;
228 _attributeValue = (int*) NULL;
229 _attributeDescription = (string*) NULL;
231 _groupName= (string*) NULL;
236 MESSAGE("~FAMILY()");
237 if(_attributeIdentifier!=NULL)
238 delete[] _attributeIdentifier;
239 if(_attributeValue!=NULL)
240 delete[] _attributeValue;
241 if(_attributeDescription!=NULL)
242 delete[] _attributeDescription;
247 FAMILY & FAMILY::operator=(const FAMILY &fam)
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;
260 ostream & MEDMEM::operator<<(ostream &os, FAMILY &myFamily)
262 // how do cast without duplicate ?
263 os << (SUPPORT) myFamily;
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 ;
278 ostream & MEDMEM::operator<<(ostream &os, const FAMILY &myFamily)
280 // how do cast without duplicate ?
281 os << (SUPPORT) myFamily;
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 ;
296 bool FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)
298 MESSAGE("FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)");
300 // Get types information from <_mesh>
301 int numberOfTypes = _mesh->getNumberOfTypes(Entity) ;
302 const medGeometryElement * types = _mesh->getTypes(Entity) ;
304 int * numberOfElementsInFamily = new int[numberOfTypes] ;
305 int numberOfElementTypesInFamily = 0 ;
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);
313 SCRUTE(numberOfTypes);
315 // we search for all elements in this family
316 for (int TypeNumber=0; TypeNumber < numberOfTypes; TypeNumber++) {
318 int NumberOfElements = _mesh->getNumberOfElements(Entity,types[TypeNumber]) ;
319 int NumberOfElementsInThisFamily = 0 ;
320 int * ElementsOfThisFamilyNumber = FamilyNumber[TypeNumber];
321 int * tmp_ElementsList = new int[NumberOfElements];
323 for (int i=0; i<NumberOfElements; i++)
325 SCRUTE(ElementsOfThisFamilyNumber[i]);
326 if (_identifier == ElementsOfThisFamilyNumber[i]) {
327 tmp_ElementsList[NumberOfElementsInThisFamily]=i+GlobalNumberingIndex[TypeNumber] ;
328 NumberOfElementsInThisFamily++;
332 if (NumberOfElementsInThisFamily>0) {// we have found some elements
333 numberOfElementsInFamily[numberOfElementTypesInFamily]=NumberOfElementsInThisFamily;
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 !!!!!!!!
339 tmp_ElementsLists[numberOfElementTypesInFamily]=ElementsList ;
340 tmp_Types[numberOfElementTypesInFamily]=types[TypeNumber];
341 // GeometricTypeNumber[numberOfElementTypesInFamily]=TypeNumber+1;
342 numberOfElementTypesInFamily++;
343 // delete [] ElementsList;
345 delete[] tmp_ElementsList;
348 // we define all attribut in SUPPORT :
349 if (numberOfElementTypesInFamily>0) { // we have found elements
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;
360 //_numberOfGaussPoint = new int[numberOfElementTypesInFamily] ;
362 //int * numberIndex = new int[numberOfElementTypesInFamily+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;
371 // delete[] numberOfElementsInFamily;
372 // delete[] tmp_Types;
373 // delete[] GeometricTypeNumber;
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];
382 int *NumberValue = new int[_totalNumberOfElements];
383 int *NumberIndex = new int[_numberOfGeometricType+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];
391 if(_number!=NULL) delete _number ;
392 _number = new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,NumberIndex,NumberValue);
393 delete[] NumberIndex ;
394 delete[] NumberValue ;
398 delete[] numberOfElementsInFamily;
400 delete[] tmp_ElementsLists;