1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 File MEDMEM_Family.cxx
27 #include "MEDMEM_Mesh.hxx"
28 #include "MEDMEM_Family.hxx"
31 using namespace MEDMEM;
32 using namespace MED_EN;
35 Those defines are from the med File V2.1 and for this class they are fixed.
38 #define MED_TAILLE_DESC 200
39 #define MED_TAILLE_LNOM 80
41 FAMILY::FAMILY():_identifier(0), _numberOfAttribute(0), _numberOfGroup(0)
43 MESSAGE_MED("FAMILY::FAMILY()");
46 FAMILY::FAMILY(MESH* Mesh, int Identifier, string Name, int NumberOfAttribute,
47 int *AttributeIdentifier, int *AttributeValue, string AttributeDescription,
48 int NumberOfGroup, string GroupName,
49 int * MEDArrayNodeFamily,
50 int ** MEDArrayCellFamily,
51 int ** MEDArrayFaceFamily,
52 int ** MEDArrayEdgeFamily
53 ): SUPPORT(Mesh,Name),
54 _identifier(Identifier),
55 _numberOfAttribute(NumberOfAttribute),
56 _numberOfGroup(NumberOfGroup)
58 MESSAGE_MED("FAMILY(int Identifier, string Name, int NumberOfAttribute,int *AttributeIdentifier,int *AttributeValue,string AttributeDescription,int NumberOfGroup,string GroupName, int ** Number) : "<<Identifier);
60 _isOnAllElts = false ;
61 SCRUTE_MED(_numberOfAttribute);
62 if (_numberOfAttribute > 0)
64 _attributeIdentifier.set(_numberOfAttribute,AttributeIdentifier);
65 _attributeValue.set(_numberOfAttribute,AttributeValue);
67 //_attributeDescription.set(_numberOfAttribute);
68 _attributeDescription.resize(_numberOfAttribute);
69 for (int i=0;i<NumberOfAttribute;i++) {
70 _attributeDescription[i].assign(AttributeDescription,i*MED_TAILLE_DESC,MED_TAILLE_DESC);
71 _attributeDescription[i].erase(strlen(_attributeDescription[i].c_str()));
72 //SCRUTE_MED(_attributeDescription[i]);
77 _attributeIdentifier.set(_numberOfAttribute);
78 _attributeValue.set(_numberOfAttribute);
79 //_attributeDescription.set(_numberOfAttribute);
80 _attributeDescription.resize(_numberOfAttribute);
83 //_groupName.set(_numberOfGroup);
84 _groupName.resize(_numberOfGroup);
85 for (int i=0;i<NumberOfGroup;i++) {
86 _groupName[i].assign(GroupName,i*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
87 _groupName[i].erase(strlen(_groupName[i].c_str()));
88 //SCRUTE_MED(_groupName[i]);
91 // well, we must set SUPPORT attribut
92 _description = "FAMILY" ;
93 // on which geometric type :
97 // ************************ NODES RELATED PART *************************************************
98 // Scan every node family number <NodeFamilyNumber[i]> in order to create
99 // the list <tmp_NodesList> of node numbers <i+1> belonging to the family <_identifier>
100 int NumberOfNodes = _mesh->getNumberOfNodes();
101 int NumberOfNodesInFamily = 0 ;
102 //int * NodeFamilyNumber = _mesh->getMEDArrayNodeFamily() ; // EF : TEMPORAIRE !!
103 int * tmp_NodesList = new int[NumberOfNodes] ; // Un peu brutal...., oui mais ce n'est qu'un tableau de travail !
104 for (int i=0; i<NumberOfNodes; i++)
105 if ( _identifier == MEDArrayNodeFamily[i] ) {
106 tmp_NodesList[NumberOfNodesInFamily]=i+1 ;
107 NumberOfNodesInFamily++;
110 SCRUTE_MED(NumberOfNodesInFamily);
112 // If we found nodes set the family attributes adequatly
113 if (NumberOfNodesInFamily>0) {
118 // _numberOfGeometricType = 1 ;
119 // _geometricType = new medGeometryElement[1] ;
120 // _geometricType[0]=MED_NONE ;
122 // family on all NODE
123 if (NumberOfNodesInFamily==NumberOfNodes) {
124 _isOnAllElts = true ;
127 _numberOfGeometricType = 1 ;
129 _geometricType.set(1) ;
131 _geometricType[0]=MED_NONE ;
132 _isOnAllElts= false ;
134 _numberOfElements.set(1) ;
136 _numberOfElements[0]=NumberOfNodesInFamily ;
137 _totalNumberOfElements=NumberOfNodesInFamily;
139 // _number=new MEDSKYLINEARRAY(1,NumberOfNodesInFamily) ;
140 // int * NumberIndex = _number->getIndex();
141 // int * NumberValue = _number->getValue();
142 int * NumberIndex = new int[2];
143 int * NumberValue = new int[NumberOfNodesInFamily];
145 NumberIndex[0]=1; //set the MEDSKYLINEARRAY Index table
146 NumberIndex[1]=1+NumberOfNodesInFamily; //set the MEDSKYLINEARRAY Index table
147 for(int i=0; i<NumberOfNodesInFamily; i++) // OH LA LA...
148 NumberValue[i]=tmp_NodesList[i] ; // RESIZE de tmp_NodesList serait plus efficace !!!!!!!!
149 // PG : pas de problème, si ca marche. Il faudra déplacer le delete !
150 if(_number!=NULL) delete _number ;
151 _number=new MEDSKYLINEARRAY(1,NumberOfNodesInFamily,NumberIndex,NumberValue) ;
152 delete[] NumberIndex ;
153 delete[] NumberValue ;
156 delete[] tmp_NodesList ;
160 // ************************ CELLS RELATED PART *************************************************
161 // If we previously found nodes in our family don't scan the CELLS because a
162 // family contains different geometic types of only one entity type.
163 // ?? Scan every cell family number <NodeFamilyNumber[i]> in order to create
164 // ?? the list <tmp_NodesList> of node numbers <i+1> belonging to the family <_identifier>
166 Find = build(MED_CELL,MEDArrayCellFamily) ;
170 if ((_mesh->existConnectivityWithPoly(MED_NODAL,MED_FACE)) |
171 (_mesh->existConnectivityWithPoly(MED_DESCENDING,MED_FACE))) {
172 Find = build(MED_FACE,MEDArrayFaceFamily) ;
178 if ((_mesh->existConnectivity(MED_NODAL,MED_EDGE))|(_mesh->existConnectivity(MED_DESCENDING,MED_EDGE))) {
179 Find = build(MED_EDGE,MEDArrayEdgeFamily) ;
184 // if not find : no entity in familly !!!
186 _numberOfGeometricType = 0 ;
187 _isOnAllElts = false ;
188 MESSAGE_MED ("FAMILY() : No entity found !") ;
191 MESSAGE_MED("Well now ??? :::");
193 MESSAGE_MED("Name : "<< getName());
194 MESSAGE_MED("Description : "<< getDescription());
195 MESSAGE_MED("Mesh name : " << getMesh()->getName());
196 MESSAGE_MED("Entity : "<< getEntity());
197 MESSAGE_MED("Entity list :");
198 if (!(isOnAllElements())) {
199 MESSAGE_MED("NumberOfTypes : "<<getNumberOfTypes());
200 for (int j=0;j<getNumberOfTypes();j++) {
201 MESSAGE_MED(" * Type "<<getTypes()[j]<<" : there is(are) "<<
202 getNumberOfElements(getTypes()[j])<<" element(s) : ");
203 SCRUTE_MED(getNumber(getTypes()[j]));
204 // for (int k=0; k<numberOfElements;k++)
205 // MESSAGE_MED("________________ " << number[k]);
210 MESSAGE_MED("Is on all entities !");
216 FAMILY::FAMILY(const FAMILY & m):SUPPORT(m)
218 MESSAGE_MED("FAMILY::FAMILY(FAMILY & m)");
219 _identifier = m._identifier;
220 _numberOfAttribute = m._numberOfAttribute;
222 if (_numberOfAttribute) {
223 _attributeIdentifier.set(_numberOfAttribute,m._attributeIdentifier);
224 _attributeValue.set(_numberOfAttribute,m._attributeValue);
227 //_attributeDescription.set(_numberOfAttribute);
228 _attributeDescription.resize(_numberOfAttribute);
229 for (int i=0;i<m._numberOfAttribute;i++)
230 _attributeDescription[i] = m._attributeDescription[i];
232 _numberOfGroup = m._numberOfGroup;
234 //_groupName.set(_numberOfGroup) ;
235 _groupName.resize(_numberOfGroup) ;
236 for (int i=0;i<m._numberOfGroup;i++)
237 _groupName[i]=m._groupName[i];
240 FAMILY::FAMILY(const SUPPORT & s):SUPPORT(s)
242 MESSAGE_MED("FAMILY::FAMILY(const SUPPORT & s)");
245 _numberOfAttribute = 0;
252 MESSAGE_MED("~FAMILY()");
255 FAMILY & FAMILY::operator=(const FAMILY &fam)
257 MESSAGE_MED("FAMILY::operator=");
258 if ( this == &fam ) return *this;
260 //Etant donné que l'opérateur d'affectation de la classe SUPPORT effectuait
261 //une recopie profonde j'ai mis en cohérence l'opérateur d'affectation
262 // de la classe FAMILY
263 SUPPORT::operator=(fam);
266 _identifier = fam._identifier;
267 _numberOfAttribute = fam._numberOfAttribute;
268 _attributeIdentifier.set(_numberOfAttribute, fam._attributeIdentifier) ;
269 _attributeValue.set(_numberOfAttribute, fam._attributeValue) ;
270 //_attributeDescription.set(_numberOfAttribute, fam._attributeDescription) ;
271 _attributeDescription.clear();
272 _attributeDescription = fam._attributeDescription;
273 _numberOfGroup = fam._numberOfGroup;
274 //_groupName.set(_numberOfGroup, fam._groupName) ;
276 _groupName = fam._groupName;
280 ostream & MEDMEM::operator<<(ostream &os, FAMILY &myFamily)
282 // how do cast without duplicate ?
283 os << (SUPPORT) myFamily;
285 os << " - Identifier : "<<myFamily.getIdentifier()<<endl;
286 int numberofattributes = myFamily.getNumberOfAttributes();
287 os << " - Attributes ("<<numberofattributes<<") :"<<endl;
288 for (int j=1;j<numberofattributes+1;j++)
289 os << " * "<<myFamily.getAttributeIdentifier(j)<<" : "<<myFamily.getAttributeValue(j)<<", "<<myFamily.getAttributeDescription(j).c_str()<<endl;
290 int numberofgroups = myFamily.getNumberOfGroups();
291 os << " - Groups ("<<numberofgroups<<") :"<<endl;
292 for (int j=1;j<numberofgroups+1;j++)
293 os << " * "<<myFamily.getGroupName(j).c_str()<<endl ;
298 ostream & MEDMEM::operator<<(ostream &os, const FAMILY &myFamily)
300 // how do cast without duplicate ?
301 os << (SUPPORT) myFamily;
303 os << " - Identifier : "<<myFamily.getIdentifier()<<endl;
304 int numberofattributes = myFamily.getNumberOfAttributes();
305 os << " - Attributes ("<<numberofattributes<<") :"<<endl;
306 for (int j=1;j<numberofattributes+1;j++)
307 os << " * "<<myFamily.getAttributeIdentifier(j)<<" : "<<myFamily.getAttributeValue(j)<<", "<<myFamily.getAttributeDescription(j).c_str()<<endl;
308 int numberofgroups = myFamily.getNumberOfGroups();
309 os << " - Groups ("<<numberofgroups<<") :"<<endl;
310 for (int j=1;j<numberofgroups+1;j++)
311 os << " * "<<myFamily.getGroupName(j).c_str()<<endl ;
316 bool FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)
318 MESSAGE_MED("FAMILY::build(medEntityMesh Entity,int **FamilyNumber /* from MED file */)");
320 // Get types information from <_mesh>
321 int numberOfTypes = _mesh->getNumberOfTypesWithPoly(Entity) ;
322 medGeometryElement * types = _mesh->getTypesWithPoly(Entity) ;
324 int * numberOfElementsInFamily = new int[numberOfTypes] ;
325 int numberOfElementTypesInFamily = 0 ;
327 medGeometryElement * tmp_Types = new medGeometryElement[numberOfTypes];
328 int ** tmp_ElementsLists = new int*[numberOfTypes] ;
329 // int * GeometricTypeNumber = new int[numberOfTypes] ;
330 const int * GlobalNumberingIndex = _mesh->getGlobalNumberingIndex(Entity);
333 SCRUTE_MED(numberOfTypes);
335 // we search for all elements in this family
336 for (int TypeNumber=0; TypeNumber < numberOfTypes; TypeNumber++) {
338 int NumberOfElements = _mesh->getNumberOfElementsWithPoly(Entity,types[TypeNumber]) ;
339 int NumberOfElementsInThisFamily = 0 ;
340 int * ElementsOfThisFamilyNumber = FamilyNumber[TypeNumber];
341 int * tmp_ElementsList = new int[NumberOfElements];
343 for (int i=0; i<NumberOfElements; i++)
345 // SCRUTE_MED(ElementsOfThisFamilyNumber[i]);
346 if (_identifier == ElementsOfThisFamilyNumber[i]) {
347 tmp_ElementsList[NumberOfElementsInThisFamily]=i+GlobalNumberingIndex[TypeNumber] ;
348 NumberOfElementsInThisFamily++;
352 if (NumberOfElementsInThisFamily>0) {// we have found some elements
353 numberOfElementsInFamily[numberOfElementTypesInFamily]=NumberOfElementsInThisFamily;
355 //int * ElementsList = tmp_ElementsList.resize(NumberOfElementsInThisFamily);
356 int * ElementsList = new int[NumberOfElementsInThisFamily] ;
357 memcpy(ElementsList,tmp_ElementsList,sizeof(int)*NumberOfElementsInThisFamily); // RESIZE de tmp_NodesList serait plus efficace !!!!!!!!
359 tmp_ElementsLists[numberOfElementTypesInFamily]=ElementsList ;
360 tmp_Types[numberOfElementTypesInFamily]=types[TypeNumber];
361 // GeometricTypeNumber[numberOfElementTypesInFamily]=TypeNumber+1;
362 numberOfElementTypesInFamily++;
363 // delete [] ElementsList;
365 delete[] tmp_ElementsList;
368 // we define all attribut in SUPPORT :
369 if (numberOfElementTypesInFamily>0) { // we have found elements
372 _numberOfGeometricType = numberOfElementTypesInFamily ;
373 _geometricType.set(numberOfElementTypesInFamily) ;
375 _isOnAllElts = false ;
377 _numberOfElements.set(numberOfElementTypesInFamily) ;
378 _totalNumberOfElements=0;
380 //_numberOfGaussPoint = new int[numberOfElementTypesInFamily] ;
382 //int * numberIndex = new int[numberOfElementTypesInFamily+1];
384 for (int i=0; i<numberOfElementTypesInFamily; i++) {
385 _geometricType[i]=tmp_Types[i] ;
386 //numberIndex[i+1]=numberIndex[i]+numberOfElementsInFamily[i];
387 _numberOfElements[i]=numberOfElementsInFamily[i]; // plutot un resize !!
388 _totalNumberOfElements+=_numberOfElements[i];
389 //_numberOfGaussPoint[i]=1;
391 // delete[] numberOfElementsInFamily;
392 // delete[] tmp_Types;
393 // delete[] GeometricTypeNumber;
395 // family on all ELEMENT ?
396 if (_totalNumberOfElements ==
397 _mesh->getNumberOfElementsWithPoly(Entity,MED_ALL_ELEMENTS)/* && Entity==MED_EN::MED_CELL*/) {
398 _isOnAllElts = true ;
399 // all others attributs are rights !
400 for (int i=0; i<_numberOfGeometricType; i++)
401 delete[] tmp_ElementsLists[i];
403 int *NumberValue = new int[_totalNumberOfElements];
404 int *NumberIndex = new int[_numberOfGeometricType+1];
406 for (int i=0; i<_numberOfGeometricType; i++) {
407 NumberIndex[i+1]=NumberIndex[i]+_numberOfElements[i];
408 for (int j=NumberIndex[i]; j<NumberIndex[i+1]; j++)
409 NumberValue[j-1]=tmp_ElementsLists[i][j-NumberIndex[i]];
410 delete[] tmp_ElementsLists[i];
412 if(_number!=NULL) delete _number ;
413 _number = new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,NumberIndex,NumberValue);
414 delete[] NumberIndex ;
415 delete[] NumberValue ;
420 delete[] numberOfElementsInFamily;
422 delete[] tmp_ElementsLists;