1 // MED MEDMEM : MED files in memory
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MEDMEM_Family.cxx
29 File MEDMEM_Family.cxx
33 #include "MEDMEM_Mesh.hxx"
34 #include "MEDMEM_Family.hxx"
36 FAMILY::FAMILY():_identifier(0), _numberOfAttribute(0),
37 _attributeIdentifier((int*)NULL),_attributeValue((int*)NULL), _attributeDescription((string*)NULL),
38 _numberOfGroup(0), _groupName((string*)NULL)
40 MESSAGE("FAMILY::FAMILY()");
43 FAMILY::FAMILY(MESH* Mesh, int Identifier, string Name, int NumberOfAttribute,
44 int *AttributeIdentifier, int *AttributeValue, string AttributeDescription,
45 int NumberOfGroup, string GroupName,
46 int * MEDArrayNodeFamily,
47 int ** MEDArrayCellFamily,
48 int ** MEDArrayFaceFamily,
49 int ** MEDArrayEdgeFamily
50 ): SUPPORT(Mesh,Name),
51 _identifier(Identifier),
52 _numberOfAttribute(NumberOfAttribute),
53 _numberOfGroup(NumberOfGroup)
55 MESSAGE("FAMILY(int Identifier, string Name, int NumberOfAttribute,int *AttributeIdentifier,int *AttributeValue,string AttributeDescription,int NumberOfGroup,string GroupName, int ** Number) : "<<Identifier);
57 _isOnAllElts = false ;
58 // replace them by pointerOf ?
59 _attributeIdentifier = new int[_numberOfAttribute] ;
60 memcpy(_attributeIdentifier,AttributeIdentifier,_numberOfAttribute*sizeof(int));
61 _attributeValue = new int[_numberOfAttribute] ;
62 memcpy(_attributeValue,AttributeValue,_numberOfAttribute*sizeof(int));
64 _attributeDescription=new string[_numberOfAttribute];
65 for (int i=0;i<NumberOfAttribute;i++) {
66 _attributeDescription[i].assign(AttributeDescription,i*MED_TAILLE_DESC,MED_TAILLE_DESC);
67 _attributeDescription[i].erase(strlen(_attributeDescription[i].c_str()));
68 //SCRUTE(_attributeDescription[i]);
71 _groupName=new string[_numberOfGroup];
72 for (int i=0;i<NumberOfGroup;i++) {
73 _groupName[i].assign(GroupName,i*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
74 _groupName[i].erase(strlen(_groupName[i].c_str()));
75 //SCRUTE(_groupName[i]);
78 // well, we must set SUPPORT attribut
79 _description = "FAMILY" ;
80 // on which geometric type :
84 // ************************ NODES RELATED PART *************************************************
85 // Scan every node family number <NodeFamilyNumber[i]> in order to create
86 // the list <tmp_NodesList> of node numbers <i+1> belonging to the family <_identifier>
87 int NumberOfNodes = _mesh->getNumberOfNodes();
88 int NumberOfNodesInFamily = 0 ;
89 //int * NodeFamilyNumber = _mesh->getMEDArrayNodeFamily() ; // EF : TEMPORAIRE !!
90 int * tmp_NodesList = new int[NumberOfNodes] ; // Un peu brutal...., oui mais ce n'est qu'un tableau de travail !
91 for (int i=0; i<NumberOfNodes; i++)
92 if ( _identifier == MEDArrayNodeFamily[i] ) {
93 tmp_NodesList[NumberOfNodesInFamily]=i+1 ;
94 NumberOfNodesInFamily++;
96 //SCRUTE(NumberOfNodesInFamily);
98 // If we found nodes set the family attributes adequatly
99 if (NumberOfNodesInFamily>0) {
104 // _numberOfGeometricType = 1 ;
105 // _geometricType = new medGeometryElement[1] ;
106 // _geometricType[0]=MED_NONE ;
108 // family on all NODE
109 if (NumberOfNodesInFamily==NumberOfNodes) {
110 _isOnAllElts = true ;
113 _numberOfGeometricType = 1 ;
114 if (_geometricType!=NULL) delete[] _geometricType ;
115 _geometricType = new medGeometryElement[1] ;
116 _geometricType[0]=MED_NONE ;
117 _isOnAllElts= false ;
118 if (_numberOfElements!=NULL) delete[] _numberOfElements ;
119 _numberOfElements = new int[1] ;
120 _numberOfElements[0]=NumberOfNodesInFamily ;
121 _totalNumberOfElements=NumberOfNodesInFamily;
123 // _number=new MEDSKYLINEARRAY(1,NumberOfNodesInFamily) ;
124 // int * NumberIndex = _number->getIndex();
125 // int * NumberValue = _number->getValue();
126 int * NumberIndex = new int[2];
127 int * NumberValue = new int[NumberOfNodesInFamily];
129 NumberIndex[0]=1; //set the MEDSKYLINEARRAY Index table
130 NumberIndex[1]=1+NumberOfNodesInFamily; //set the MEDSKYLINEARRAY Index table
131 for(int i=0; i<NumberOfNodesInFamily; i++) // OH LA LA...
132 NumberValue[i]=tmp_NodesList[i] ; // RESIZE de tmp_NodesList serait plus efficace !!!!!!!!
133 // PG : pas de problème, si ca marche. Il faudra déplacer le delete !
134 if(_number!=NULL) delete _number ;
135 _number=new MEDSKYLINEARRAY(1,NumberOfNodesInFamily,NumberIndex,NumberValue) ;
136 delete[] NumberIndex ;
137 delete[] NumberValue ;
140 delete[] tmp_NodesList ;
144 // ************************ CELLS RELATED PART *************************************************
145 // If we previously found nodes in our family don't scan the CELLS because a
146 // family contains different geometic types of only one entity type.
147 // ?? Scan every cell family number <NodeFamilyNumber[i]> in order to create
148 // ?? the list <tmp_NodesList> of node numbers <i+1> belonging to the family <_identifier>
150 Find = build(MED_CELL,MEDArrayCellFamily) ;
154 if ((_mesh->existConnectivity(MED_NODAL,MED_FACE))|(_mesh->existConnectivity(MED_DESCENDING,MED_FACE))) {
155 Find = build(MED_FACE,MEDArrayFaceFamily) ;
161 if ((_mesh->existConnectivity(MED_NODAL,MED_EDGE))|(_mesh->existConnectivity(MED_DESCENDING,MED_EDGE))) {
162 Find = build(MED_EDGE,MEDArrayEdgeFamily) ;
167 // if not find : no entity in familly !!!
169 _numberOfGeometricType = 0 ;
170 _isOnAllElts = false ;
171 MESSAGE ("FAMILY() : No entity found !") ;
173 // already done by support !!!!
174 // else { // set gauss point number to be equal one !
175 // _numberOfGaussPoint = new int[_numberOfGeometricType] ;
176 // for (int i=0; i<_numberOfGeometricType; i++)
177 // _numberOfGaussPoint[i]=1 ;
181 FAMILY::FAMILY(const FAMILY & m):SUPPORT(m)
183 MESSAGE("FAMILY::FAMILY(FAMILY & m)");
184 _identifier = m._identifier;
185 _numberOfAttribute = m._numberOfAttribute;
186 if (m._attributeIdentifier != NULL)
188 _attributeIdentifier = new int[m._numberOfAttribute];
189 memcpy(_attributeIdentifier,m._attributeIdentifier,m._numberOfAttribute*sizeof(int));
192 _attributeIdentifier = (int *) NULL;
193 if (m._attributeValue != NULL)
195 _attributeValue = new int[m._numberOfAttribute];
196 memcpy(_attributeValue,m._attributeValue,m._numberOfAttribute*sizeof(int));
199 _attributeValue = (int *) NULL;
200 if (m._attributeDescription != NULL)
202 _attributeDescription = new string[m._numberOfAttribute];
203 for (int i=0;i<m._numberOfAttribute;i++)
204 _attributeDescription[i] = m._attributeDescription[i];
207 _attributeDescription = (string *) NULL;
208 _numberOfGroup = m._numberOfGroup;
209 if (m._groupName != NULL)
211 _groupName = new string[m._numberOfGroup];
212 for (int i=0;i<m._numberOfGroup;i++)
213 _groupName[i]=m._groupName[i];
216 _groupName = (string *) NULL;
219 FAMILY::FAMILY(const SUPPORT & s):SUPPORT(s)
221 MESSAGE("FAMILY::FAMILY(const SUPPORT & s)");
224 _numberOfAttribute = 0;
225 _attributeIdentifier = (int*) NULL;
226 _attributeValue = (int*) NULL;
227 _attributeDescription = (string*) NULL;
229 _groupName= (string*) NULL;
232 FAMILY::FAMILY(FAMILY & m):SUPPORT(m)
234 _identifier = m._identifier;
235 _numberOfAttribute = m._numberOfAttribute;
236 if (m._attributeIdentifier != NULL)
238 _attributeIdentifier = new int[m._numberOfAttribute];
239 memcpy(_attributeIdentifier,m._attributeIdentifier,m._numberOfAttribute*sizeof(int));
242 _attributeIdentifier = (int *) NULL;
243 if (m._attributeValue != NULL)
245 _attributeValue = new int[m._numberOfAttribute];
246 memcpy(_attributeValue,m._attributeValue,m._numberOfAttribute*sizeof(int));
249 _attributeValue = (int *) NULL;
250 if (m._attributeDescription != NULL)
252 _attributeDescription = new string[m._numberOfAttribute];
253 for (int i=0;i<m._numberOfAttribute;i++)
254 _attributeDescription[i] = m._attributeDescription[i];
257 _attributeDescription = (string *) NULL;
258 _numberOfGroup = m._numberOfGroup;
259 if (m._groupName != NULL)
261 _groupName = new string[m._numberOfGroup];
262 for (int i=0;i<m._numberOfGroup;i++)
263 _groupName[i]=m._groupName[i];
266 _groupName = (string *) NULL;
271 MESSAGE("~FAMILY()");
272 if(_attributeIdentifier!=NULL)
273 delete[] _attributeIdentifier;
274 if(_attributeValue!=NULL)
275 delete[] _attributeValue;
276 if(_attributeDescription!=NULL)
277 delete[] _attributeDescription;
282 FAMILY & FAMILY::operator=(const FAMILY &fam)
284 MESSAGE("FAMILY::operator=");
285 _identifier = fam._identifier;
286 _numberOfAttribute = fam._numberOfAttribute;
287 _attributeIdentifier = fam._attributeIdentifier;
288 _attributeValue = fam._attributeValue;
289 _attributeDescription = fam._attributeDescription;
290 _numberOfGroup = fam._numberOfGroup;
291 _groupName = fam._groupName;
295 ostream & operator<<(ostream &os, FAMILY &myFamily)
297 // how do cast without duplicate ?
298 os << (SUPPORT) myFamily;
300 os << " - Identifier : "<<myFamily.getIdentifier()<<endl;
301 int numberofattributes = myFamily.getNumberOfAttributes();
302 os << " - Attributes ("<<numberofattributes<<") :"<<endl;
303 for (int j=1;j<numberofattributes+1;j++)
304 os << " * "<<myFamily.getAttributeIdentifier(j)<<" : "<<myFamily.getAttributeValue(j)<<", "<<myFamily.getAttributeDescription(j).c_str()<<endl;
305 int numberofgroups = myFamily.getNumberOfGroups();
306 os << " - Groups ("<<numberofgroups<<") :"<<endl;
307 for (int j=1;j<numberofgroups+1;j++)
308 os << " * "<<myFamily.getGroupName(j).c_str()<<endl ;
313 bool FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)
315 MESSAGE("FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)");
317 // Get types information from <_mesh>
318 int numberOfTypes = _mesh->getNumberOfTypes(Entity) ;
319 const medGeometryElement * types = _mesh->getTypes(Entity) ;
321 int * numberOfElementsInFamily = new int[numberOfTypes] ;
322 int numberOfElementTypesInFamily = 0 ;
324 medGeometryElement * tmp_Types = new medGeometryElement[numberOfTypes];
325 int ** tmp_ElementsLists = new int*[numberOfTypes] ;
326 // int * GeometricTypeNumber = new int[numberOfTypes] ;
327 const int * GlobalNumberingIndex = _mesh->getGlobalNumberingIndex(Entity);
329 // we search for all elements in this family
330 for (int TypeNumber=0; TypeNumber < numberOfTypes; TypeNumber++) {
332 int NumberOfElements = _mesh->getNumberOfElements(Entity,types[TypeNumber]) ;
333 int NumberOfElementsInThisFamily = 0 ;
334 int * ElementsOfThisFamilyNumber = FamilyNumber[TypeNumber];
335 int * tmp_ElementsList = new int[NumberOfElements];
337 for (int i=0; i<NumberOfElements; i++)
338 if (_identifier == ElementsOfThisFamilyNumber[i]) {
339 tmp_ElementsList[NumberOfElementsInThisFamily]=i+GlobalNumberingIndex[TypeNumber] ;
340 NumberOfElementsInThisFamily++;
343 if (NumberOfElementsInThisFamily>0) {// we have found some elements
344 numberOfElementsInFamily[numberOfElementTypesInFamily]=NumberOfElementsInThisFamily;
346 //int * ElementsList = tmp_ElementsList.resize(NumberOfElementsInThisFamily);
347 int * ElementsList = new int[NumberOfElementsInThisFamily] ;
348 memcpy(ElementsList,tmp_ElementsList,sizeof(int)*NumberOfElementsInThisFamily); // RESIZE de tmp_NodesList serait plus efficace !!!!!!!!
350 tmp_ElementsLists[numberOfElementTypesInFamily]=ElementsList ;
351 tmp_Types[numberOfElementTypesInFamily]=types[TypeNumber];
352 // GeometricTypeNumber[numberOfElementTypesInFamily]=TypeNumber+1;
353 numberOfElementTypesInFamily++;
354 // delete [] ElementsList;
356 delete[] tmp_ElementsList;
359 // we define all attribut in SUPPORT :
360 if (numberOfElementTypesInFamily>0) { // we have found elements
363 _numberOfGeometricType = numberOfElementTypesInFamily ;
364 if (_geometricType!=NULL) delete[] _geometricType ;
365 _geometricType = new medGeometryElement[numberOfElementTypesInFamily] ;
366 _isOnAllElts = false ;
367 if (_numberOfElements!=NULL) delete[] _numberOfElements ;
368 _numberOfElements = new int[numberOfElementTypesInFamily] ;
369 _totalNumberOfElements=0;
371 //_numberOfGaussPoint = new int[numberOfElementTypesInFamily] ;
373 //int * numberIndex = new int[numberOfElementTypesInFamily+1];
375 for (int i=0; i<numberOfElementTypesInFamily; i++) {
376 _geometricType[i]=tmp_Types[i] ;
377 //numberIndex[i+1]=numberIndex[i]+numberOfElementsInFamily[i];
378 _numberOfElements[i]=numberOfElementsInFamily[i]; // plutot un resize !!
379 _totalNumberOfElements+=_numberOfElements[i];
380 //_numberOfGaussPoint[i]=1;
382 // delete[] numberOfElementsInFamily;
383 // delete[] tmp_Types;
384 // delete[] GeometricTypeNumber;
386 // family on all ELEMENT ?
387 if (_totalNumberOfElements == _mesh->getNumberOfElements(Entity,MED_ALL_ELEMENTS)) {
388 _isOnAllElts = true ;
389 // all others attributs are rights !
390 for (int i=0; i<_numberOfGeometricType; i++)
391 delete[] tmp_ElementsLists[i];
393 int *NumberValue = new int[_totalNumberOfElements];
394 int *NumberIndex = new int[_numberOfGeometricType+1];
396 for (int i=0; i<_numberOfGeometricType; i++) {
397 NumberIndex[i+1]=NumberIndex[i]+_numberOfElements[i];
398 for (int j=NumberIndex[i]; j<NumberIndex[i+1]; j++)
399 NumberValue[j-1]=tmp_ElementsLists[i][j-NumberIndex[i]];
400 delete[] tmp_ElementsLists[i];
402 if(_number!=NULL) delete _number ;
403 _number = new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,NumberIndex,NumberValue);
404 delete[] NumberIndex ;
405 delete[] NumberValue ;
409 delete[] numberOfElementsInFamily;
411 delete[] tmp_ElementsLists;