6 #include "MEDMEM_Mesh.hxx"
7 #include "MEDMEM_Family.hxx"
10 using namespace MEDMEM;
11 using namespace MED_EN;
14 Those defines are from the med File V2.1 and for this class they are fixed.
17 #define MED_TAILLE_DESC 200
18 #define MED_TAILLE_LNOM 80
20 FAMILY::FAMILY():_identifier(0), _numberOfAttribute(0),
21 _attributeIdentifier((int*)NULL),_attributeValue((int*)NULL), _attributeDescription((string*)NULL),
22 _numberOfGroup(0), _groupName((string*)NULL)
24 MESSAGE("FAMILY::FAMILY()");
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)
39 MESSAGE("FAMILY(int Identifier, string Name, int NumberOfAttribute,int *AttributeIdentifier,int *AttributeValue,string AttributeDescription,int NumberOfGroup,string GroupName, int ** Number) : "<<Identifier);
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));
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]);
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]);
62 // well, we must set SUPPORT attribut
63 _description = "FAMILY" ;
64 // on which geometric type :
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++;
81 SCRUTE(NumberOfNodesInFamily);
83 // If we found nodes set the family attributes adequatly
84 if (NumberOfNodesInFamily>0) {
89 // _numberOfGeometricType = 1 ;
90 // _geometricType = new medGeometryElement[1] ;
91 // _geometricType[0]=MED_NONE ;
94 if (NumberOfNodesInFamily==NumberOfNodes) {
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;
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];
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 ;
125 delete[] tmp_NodesList ;
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>
135 Find = build(MED_CELL,MEDArrayCellFamily) ;
139 if ((_mesh->existConnectivity(MED_NODAL,MED_FACE))|(_mesh->existConnectivity(MED_DESCENDING,MED_FACE))) {
140 Find = build(MED_FACE,MEDArrayFaceFamily) ;
146 if ((_mesh->existConnectivity(MED_NODAL,MED_EDGE))|(_mesh->existConnectivity(MED_DESCENDING,MED_EDGE))) {
147 Find = build(MED_EDGE,MEDArrayEdgeFamily) ;
152 // if not find : no entity in familly !!!
154 _numberOfGeometricType = 0 ;
155 _isOnAllElts = false ;
156 MESSAGE ("FAMILY() : No entity found !") ;
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 ;
166 MESSAGE("Well now ??? :::");
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]);
182 for (int k=0; k<numberOfElements;k++)
183 MESSAGE("________________ " << number[k]);
186 MESSAGE("Is on all entities !");
192 FAMILY::FAMILY(const FAMILY & m):SUPPORT(m)
194 MESSAGE("FAMILY::FAMILY(FAMILY & m)");
195 _identifier = m._identifier;
196 _numberOfAttribute = m._numberOfAttribute;
197 if (m._attributeIdentifier != NULL)
199 _attributeIdentifier = new int[m._numberOfAttribute];
200 memcpy(_attributeIdentifier,m._attributeIdentifier,m._numberOfAttribute*sizeof(int));
203 _attributeIdentifier = (int *) NULL;
204 if (m._attributeValue != NULL)
206 _attributeValue = new int[m._numberOfAttribute];
207 memcpy(_attributeValue,m._attributeValue,m._numberOfAttribute*sizeof(int));
210 _attributeValue = (int *) NULL;
211 if (m._attributeDescription != NULL)
213 _attributeDescription = new string[m._numberOfAttribute];
214 for (int i=0;i<m._numberOfAttribute;i++)
215 _attributeDescription[i] = m._attributeDescription[i];
218 _attributeDescription = (string *) NULL;
219 _numberOfGroup = m._numberOfGroup;
220 if (m._groupName != NULL)
222 _groupName = new string[m._numberOfGroup];
223 for (int i=0;i<m._numberOfGroup;i++)
224 _groupName[i]=m._groupName[i];
227 _groupName = (string *) NULL;
230 FAMILY::FAMILY(const SUPPORT & s):SUPPORT(s)
232 MESSAGE("FAMILY::FAMILY(const SUPPORT & s)");
235 _numberOfAttribute = 0;
236 _attributeIdentifier = (int*) NULL;
237 _attributeValue = (int*) NULL;
238 _attributeDescription = (string*) NULL;
240 _groupName= (string*) NULL;
245 MESSAGE("~FAMILY()");
246 if(_attributeIdentifier!=NULL)
247 delete[] _attributeIdentifier;
248 if(_attributeValue!=NULL)
249 delete[] _attributeValue;
250 if(_attributeDescription!=NULL)
251 delete[] _attributeDescription;
256 FAMILY & FAMILY::operator=(const FAMILY &fam)
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;
269 ostream & MEDMEM::operator<<(ostream &os, FAMILY &myFamily)
271 // how do cast without duplicate ?
272 os << (SUPPORT) myFamily;
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 ;
287 ostream & MEDMEM::operator<<(ostream &os, const FAMILY &myFamily)
289 // how do cast without duplicate ?
290 os << (SUPPORT) myFamily;
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 ;
305 bool FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)
307 MESSAGE("FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)");
309 // Get types information from <_mesh>
310 int numberOfTypes = _mesh->getNumberOfTypesWithPoly(Entity) ;
311 medGeometryElement * types = _mesh->getTypesWithPoly(Entity) ;
313 int * numberOfElementsInFamily = new int[numberOfTypes] ;
314 int numberOfElementTypesInFamily = 0 ;
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);
322 SCRUTE(numberOfTypes);
324 // we search for all elements in this family
325 for (int TypeNumber=0; TypeNumber < numberOfTypes; TypeNumber++) {
327 int NumberOfElements = _mesh->getNumberOfElementsWithPoly(Entity,types[TypeNumber]) ;
328 int NumberOfElementsInThisFamily = 0 ;
329 int * ElementsOfThisFamilyNumber = FamilyNumber[TypeNumber];
330 int * tmp_ElementsList = new int[NumberOfElements];
332 for (int i=0; i<NumberOfElements; i++)
334 SCRUTE(ElementsOfThisFamilyNumber[i]);
335 if (_identifier == ElementsOfThisFamilyNumber[i]) {
336 tmp_ElementsList[NumberOfElementsInThisFamily]=i+GlobalNumberingIndex[TypeNumber] ;
337 NumberOfElementsInThisFamily++;
341 if (NumberOfElementsInThisFamily>0) {// we have found some elements
342 numberOfElementsInFamily[numberOfElementTypesInFamily]=NumberOfElementsInThisFamily;
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 !!!!!!!!
348 tmp_ElementsLists[numberOfElementTypesInFamily]=ElementsList ;
349 tmp_Types[numberOfElementTypesInFamily]=types[TypeNumber];
350 // GeometricTypeNumber[numberOfElementTypesInFamily]=TypeNumber+1;
351 numberOfElementTypesInFamily++;
352 // delete [] ElementsList;
354 delete[] tmp_ElementsList;
357 // we define all attribut in SUPPORT :
358 if (numberOfElementTypesInFamily>0) { // we have found elements
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;
369 //_numberOfGaussPoint = new int[numberOfElementTypesInFamily] ;
371 //int * numberIndex = new int[numberOfElementTypesInFamily+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;
380 // delete[] numberOfElementsInFamily;
381 // delete[] tmp_Types;
382 // delete[] GeometricTypeNumber;
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];
391 int *NumberValue = new int[_totalNumberOfElements];
392 int *NumberIndex = new int[_numberOfGeometricType+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];
400 if(_number!=NULL) delete _number ;
401 _number = new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,NumberIndex,NumberValue);
402 delete[] NumberIndex ;
403 delete[] NumberValue ;
408 delete[] numberOfElementsInFamily;
410 delete[] tmp_ElementsLists;