7 #include "MEDMEM_Mesh.hxx"
8 #include "MEDMEM_Family.hxx"
10 FAMILY::FAMILY():_identifier(0), _numberOfAttribute(0),
11 _attributeIdentifier((int*)NULL),_attributeValue((int*)NULL), _attributeDescription((string*)NULL),
12 _numberOfGroup(0), _groupName((string*)NULL)
14 MESSAGE("FAMILY::FAMILY()");
17 FAMILY::FAMILY(MESH* Mesh, int Identifier, string Name, int NumberOfAttribute,
18 int *AttributeIdentifier, int *AttributeValue, string AttributeDescription,
19 int NumberOfGroup, string GroupName,
20 int * MEDArrayNodeFamily,
21 int ** MEDArrayCellFamily,
22 int ** MEDArrayFaceFamily,
23 int ** MEDArrayEdgeFamily
24 ): SUPPORT(Mesh,Name),
25 _identifier(Identifier),
26 _numberOfAttribute(NumberOfAttribute),
27 _numberOfGroup(NumberOfGroup)
29 MESSAGE("FAMILY(int Identifier, string Name, int NumberOfAttribute,int *AttributeIdentifier,int *AttributeValue,string AttributeDescription,int NumberOfGroup,string GroupName, int ** Number) : "<<Identifier);
31 _isOnAllElts = false ;
32 // replace them by pointerOf ?
33 _attributeIdentifier = new int[_numberOfAttribute] ;
34 memcpy(_attributeIdentifier,AttributeIdentifier,_numberOfAttribute*sizeof(int));
35 _attributeValue = new int[_numberOfAttribute] ;
36 memcpy(_attributeValue,AttributeValue,_numberOfAttribute*sizeof(int));
38 _attributeDescription=new string[_numberOfAttribute];
39 for (int i=0;i<NumberOfAttribute;i++) {
40 _attributeDescription[i].assign(AttributeDescription,i*MED_TAILLE_DESC,MED_TAILLE_DESC);
41 _attributeDescription[i].erase(strlen(_attributeDescription[i].c_str()));
42 //SCRUTE(_attributeDescription[i]);
45 _groupName=new string[_numberOfGroup];
46 for (int i=0;i<NumberOfGroup;i++) {
47 _groupName[i].assign(GroupName,i*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
48 _groupName[i].erase(strlen(_groupName[i].c_str()));
49 //SCRUTE(_groupName[i]);
52 // well, we must set SUPPORT attribut
53 _description = "FAMILY" ;
54 // on which geometric type :
58 // ************************ NODES RELATED PART *************************************************
59 // Scan every node family number <NodeFamilyNumber[i]> in order to create
60 // the list <tmp_NodesList> of node numbers <i+1> belonging to the family <_identifier>
61 int NumberOfNodes = _mesh->getNumberOfNodes();
62 int NumberOfNodesInFamily = 0 ;
63 //int * NodeFamilyNumber = _mesh->getMEDArrayNodeFamily() ; // EF : TEMPORAIRE !!
64 int * tmp_NodesList = new int[NumberOfNodes] ; // Un peu brutal...., oui mais ce n'est qu'un tableau de travail !
65 for (int i=0; i<NumberOfNodes; i++)
66 if ( _identifier == MEDArrayNodeFamily[i] ) {
67 tmp_NodesList[NumberOfNodesInFamily]=i+1 ;
68 NumberOfNodesInFamily++;
70 //SCRUTE(NumberOfNodesInFamily);
72 // If we found nodes set the family attributes adequatly
73 if (NumberOfNodesInFamily>0) {
78 // _numberOfGeometricType = 1 ;
79 // _geometricType = new medGeometryElement[1] ;
80 // _geometricType[0]=MED_NONE ;
83 if (NumberOfNodesInFamily==NumberOfNodes) {
87 _numberOfGeometricType = 1 ;
88 if (_geometricType!=NULL) delete[] _geometricType ;
89 _geometricType = new medGeometryElement[1] ;
90 _geometricType[0]=MED_NONE ;
92 if (_numberOfElements!=NULL) delete[] _numberOfElements ;
93 _numberOfElements = new int[1] ;
94 _numberOfElements[0]=NumberOfNodesInFamily ;
95 _totalNumberOfElements=NumberOfNodesInFamily;
97 // _number=new MEDSKYLINEARRAY(1,NumberOfNodesInFamily) ;
98 // int * NumberIndex = _number->getIndex();
99 // int * NumberValue = _number->getValue();
100 int * NumberIndex = new int[2];
101 int * NumberValue = new int[NumberOfNodesInFamily];
103 NumberIndex[0]=1; //set the MEDSKYLINEARRAY Index table
104 NumberIndex[1]=1+NumberOfNodesInFamily; //set the MEDSKYLINEARRAY Index table
105 for(int i=0; i<NumberOfNodesInFamily; i++) // OH LA LA...
106 NumberValue[i]=tmp_NodesList[i] ; // RESIZE de tmp_NodesList serait plus efficace !!!!!!!!
107 // PG : pas de problème, si ca marche. Il faudra déplacer le delete !
108 if(_number!=NULL) delete _number ;
109 _number=new MEDSKYLINEARRAY(1,NumberOfNodesInFamily,NumberIndex,NumberValue) ;
110 delete[] NumberIndex ;
111 delete[] NumberValue ;
114 delete[] tmp_NodesList ;
118 // ************************ CELLS RELATED PART *************************************************
119 // If we previously found nodes in our family don't scan the CELLS because a
120 // family contains different geometic types of only one entity type.
121 // ?? Scan every cell family number <NodeFamilyNumber[i]> in order to create
122 // ?? the list <tmp_NodesList> of node numbers <i+1> belonging to the family <_identifier>
124 Find = build(MED_CELL,MEDArrayCellFamily) ;
128 if ((_mesh->existConnectivity(MED_NODAL,MED_FACE))|(_mesh->existConnectivity(MED_DESCENDING,MED_FACE))) {
129 Find = build(MED_FACE,MEDArrayFaceFamily) ;
135 if ((_mesh->existConnectivity(MED_NODAL,MED_EDGE))|(_mesh->existConnectivity(MED_DESCENDING,MED_EDGE))) {
136 Find = build(MED_EDGE,MEDArrayEdgeFamily) ;
141 // if not find : no entity in familly !!!
143 _numberOfGeometricType = 0 ;
144 _isOnAllElts = false ;
145 MESSAGE ("FAMILY() : No entity found !") ;
147 // already done by support !!!!
148 // else { // set gauss point number to be equal one !
149 // _numberOfGaussPoint = new int[_numberOfGeometricType] ;
150 // for (int i=0; i<_numberOfGeometricType; i++)
151 // _numberOfGaussPoint[i]=1 ;
155 FAMILY::FAMILY(const FAMILY & m):SUPPORT(m)
157 MESSAGE("FAMILY::FAMILY(FAMILY & m)");
158 _identifier = m._identifier;
159 _numberOfAttribute = m._numberOfAttribute;
160 if (m._attributeIdentifier != NULL)
162 _attributeIdentifier = new int[m._numberOfAttribute];
163 memcpy(_attributeIdentifier,m._attributeIdentifier,m._numberOfAttribute*sizeof(int));
166 _attributeIdentifier = (int *) NULL;
167 if (m._attributeValue != NULL)
169 _attributeValue = new int[m._numberOfAttribute];
170 memcpy(_attributeValue,m._attributeValue,m._numberOfAttribute*sizeof(int));
173 _attributeValue = (int *) NULL;
174 if (m._attributeDescription != NULL)
176 _attributeDescription = new string[m._numberOfAttribute];
177 for (int i=0;i<m._numberOfAttribute;i++)
178 _attributeDescription[i] = m._attributeDescription[i];
181 _attributeDescription = (string *) NULL;
182 _numberOfGroup = m._numberOfGroup;
183 if (m._groupName != NULL)
185 _groupName = new string[m._numberOfGroup];
186 for (int i=0;i<m._numberOfGroup;i++)
187 _groupName[i]=m._groupName[i];
190 _groupName = (string *) NULL;
193 FAMILY::FAMILY(const SUPPORT & s):SUPPORT(s)
195 MESSAGE("FAMILY::FAMILY(const SUPPORT & s)");
198 _numberOfAttribute = 0;
199 _attributeIdentifier = (int*) NULL;
200 _attributeValue = (int*) NULL;
201 _attributeDescription = (string*) NULL;
203 _groupName= (string*) NULL;
208 MESSAGE("~FAMILY()");
209 if(_attributeIdentifier!=NULL)
210 delete[] _attributeIdentifier;
211 if(_attributeValue!=NULL)
212 delete[] _attributeValue;
213 if(_attributeDescription!=NULL)
214 delete[] _attributeDescription;
219 FAMILY & FAMILY::operator=(const FAMILY &fam)
221 MESSAGE("FAMILY::operator=");
222 _identifier = fam._identifier;
223 _numberOfAttribute = fam._numberOfAttribute;
224 _attributeIdentifier = fam._attributeIdentifier;
225 _attributeValue = fam._attributeValue;
226 _attributeDescription = fam._attributeDescription;
227 _numberOfGroup = fam._numberOfGroup;
228 _groupName = fam._groupName;
232 ostream & operator<<(ostream &os, FAMILY &myFamily)
234 // how do cast without duplicate ?
235 os << (SUPPORT) myFamily;
237 os << " - Identifier : "<<myFamily.getIdentifier()<<endl;
238 int numberofattributes = myFamily.getNumberOfAttributes();
239 os << " - Attributes ("<<numberofattributes<<") :"<<endl;
240 for (int j=1;j<numberofattributes+1;j++)
241 os << " * "<<myFamily.getAttributeIdentifier(j)<<" : "<<myFamily.getAttributeValue(j)<<", "<<myFamily.getAttributeDescription(j).c_str()<<endl;
242 int numberofgroups = myFamily.getNumberOfGroups();
243 os << " - Groups ("<<numberofgroups<<") :"<<endl;
244 for (int j=1;j<numberofgroups+1;j++)
245 os << " * "<<myFamily.getGroupName(j).c_str()<<endl ;
250 bool FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)
252 MESSAGE("FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)");
254 // Get types information from <_mesh>
255 int numberOfTypes = _mesh->getNumberOfTypes(Entity) ;
256 const medGeometryElement * types = _mesh->getTypes(Entity) ;
258 int * numberOfElementsInFamily = new int[numberOfTypes] ;
259 int numberOfElementTypesInFamily = 0 ;
261 medGeometryElement * tmp_Types = new medGeometryElement[numberOfTypes];
262 int ** tmp_ElementsLists = new int*[numberOfTypes] ;
263 // int * GeometricTypeNumber = new int[numberOfTypes] ;
264 const int * GlobalNumberingIndex = _mesh->getGlobalNumberingIndex(Entity);
266 // we search for all elements in this family
267 for (int TypeNumber=0; TypeNumber < numberOfTypes; TypeNumber++) {
269 int NumberOfElements = _mesh->getNumberOfElements(Entity,types[TypeNumber]) ;
270 int NumberOfElementsInThisFamily = 0 ;
271 int * ElementsOfThisFamilyNumber = FamilyNumber[TypeNumber];
272 int * tmp_ElementsList = new int[NumberOfElements];
274 for (int i=0; i<NumberOfElements; i++)
275 if (_identifier == ElementsOfThisFamilyNumber[i]) {
276 tmp_ElementsList[NumberOfElementsInThisFamily]=i+GlobalNumberingIndex[TypeNumber] ;
277 NumberOfElementsInThisFamily++;
280 if (NumberOfElementsInThisFamily>0) {// we have found some elements
281 numberOfElementsInFamily[numberOfElementTypesInFamily]=NumberOfElementsInThisFamily;
283 //int * ElementsList = tmp_ElementsList.resize(NumberOfElementsInThisFamily);
284 int * ElementsList = new int[NumberOfElementsInThisFamily] ;
285 memcpy(ElementsList,tmp_ElementsList,sizeof(int)*NumberOfElementsInThisFamily); // RESIZE de tmp_NodesList serait plus efficace !!!!!!!!
287 tmp_ElementsLists[numberOfElementTypesInFamily]=ElementsList ;
288 tmp_Types[numberOfElementTypesInFamily]=types[TypeNumber];
289 // GeometricTypeNumber[numberOfElementTypesInFamily]=TypeNumber+1;
290 numberOfElementTypesInFamily++;
291 // delete [] ElementsList;
293 delete[] tmp_ElementsList;
296 // we define all attribut in SUPPORT :
297 if (numberOfElementTypesInFamily>0) { // we have found elements
300 _numberOfGeometricType = numberOfElementTypesInFamily ;
301 if (_geometricType!=NULL) delete[] _geometricType ;
302 _geometricType = new medGeometryElement[numberOfElementTypesInFamily] ;
303 _isOnAllElts = false ;
304 if (_numberOfElements!=NULL) delete[] _numberOfElements ;
305 _numberOfElements = new int[numberOfElementTypesInFamily] ;
306 _totalNumberOfElements=0;
308 //_numberOfGaussPoint = new int[numberOfElementTypesInFamily] ;
310 //int * numberIndex = new int[numberOfElementTypesInFamily+1];
312 for (int i=0; i<numberOfElementTypesInFamily; i++) {
313 _geometricType[i]=tmp_Types[i] ;
314 //numberIndex[i+1]=numberIndex[i]+numberOfElementsInFamily[i];
315 _numberOfElements[i]=numberOfElementsInFamily[i]; // plutot un resize !!
316 _totalNumberOfElements+=_numberOfElements[i];
317 //_numberOfGaussPoint[i]=1;
319 // delete[] numberOfElementsInFamily;
320 // delete[] tmp_Types;
321 // delete[] GeometricTypeNumber;
323 // family on all ELEMENT ?
324 if (_totalNumberOfElements == _mesh->getNumberOfElements(Entity,MED_ALL_ELEMENTS)) {
325 _isOnAllElts = true ;
326 // all others attributs are rights !
327 for (int i=0; i<_numberOfGeometricType; i++)
328 delete[] tmp_ElementsLists[i];
330 int *NumberValue = new int[_totalNumberOfElements];
331 int *NumberIndex = new int[_numberOfGeometricType+1];
333 for (int i=0; i<_numberOfGeometricType; i++) {
334 NumberIndex[i+1]=NumberIndex[i]+_numberOfElements[i];
335 for (int j=NumberIndex[i]; j<NumberIndex[i+1]; j++)
336 NumberValue[j-1]=tmp_ElementsLists[i][j-NumberIndex[i]];
337 delete[] tmp_ElementsLists[i];
339 if(_number!=NULL) delete _number ;
340 _number = new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,NumberIndex,NumberValue);
341 delete[] NumberIndex ;
342 delete[] NumberValue ;
346 delete[] numberOfElementsInFamily;
348 delete[] tmp_ElementsLists;