12 #include "MEDMEM_DriversDef.hxx"
13 #include "MEDMEM_Field.hxx"
14 #include "MEDMEM_Mesh.hxx"
16 #include "MEDMEM_Support.hxx"
17 #include "MEDMEM_Family.hxx"
18 #include "MEDMEM_Group.hxx"
19 #include "MEDMEM_Coordinate.hxx"
20 #include "MEDMEM_Connectivity.hxx"
21 #include "MEDMEM_CellModel.hxx"
23 #include "MEDMEM_DriverFactory.hxx"
26 using namespace MEDMEM;
27 using namespace MED_EN;
29 //#include "MEDMEM_Grid.hxx" this inclision should have never be here !!!
31 //update Families with content list
32 //int family_count(int family_number, int count, int * entities_number, int * entities_list) ;
34 // ------- Drivers Management Part
36 /*! Add a %MESH driver of type %driverTypes (MED_DRIVER, ....) associated with file fileName. The meshname used in the file
37 is driverName. addDriver returns an integer handler. */
38 int MESH::addDriver(driverTypes driverType,
39 const string & fileName/*="Default File Name.med"*/,const string & driverName/*="Default Mesh Name"*/) {
41 const char * LOC = "MESH::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\",const string & driverName=\"Default Mesh Name\") : ";
49 driver = DRIVERFACTORY::buildDriverForMesh(driverType,fileName,this,driverName) ;
51 _drivers.push_back(driver);
53 int current = _drivers.size()-1;
55 _drivers[current]->setMeshName(driverName);
62 /*! Add an existing MESH driver. */
63 int MESH::addDriver(GENDRIVER & driver) {
64 const char * LOC = "MESH::addDriver(GENDRIVER &) : ";
67 // A faire : Vérifier que le driver est de type MESH.
68 GENDRIVER * newDriver = driver.copy() ;
70 _drivers.push_back(newDriver);
71 return _drivers.size()-1;
76 /*! Remove an existing MESH driver. */
77 void MESH::rmDriver (int index/*=0*/) {
78 const char * LOC = "MESH::rmDriver (int index=0): ";
81 if ( _drivers[index] ) {
82 //_drivers.erase(&_drivers[index]);
87 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
88 << "The index given is invalid, index must be between 0 and |"
97 // ------ End of Drivers Management Part
102 const char * LOC = "MESH::init(): ";
106 _name = "NOT DEFINED"; // A POSITIONNER EN FCT DES IOS ?
108 _coordinate = (COORDINATE *) NULL;
109 _connectivity = (CONNECTIVITY *) NULL;
111 _spaceDimension = MED_INVALID; // 0 ?!?
112 _meshDimension = MED_INVALID;
113 _numberOfNodes = MED_INVALID;
117 _arePresentOptionnalNodesNumbers = 0;
122 /*! Create an empty MESH. */
123 MESH::MESH():_coordinate(NULL),_connectivity(NULL), _isAGrid(false) {
130 _isAGrid = m._isAGrid;
132 if (m._coordinate != NULL)
133 _coordinate = new COORDINATE(* m._coordinate);
135 _coordinate = (COORDINATE *) NULL;
137 if (m._connectivity != NULL)
138 _connectivity = new CONNECTIVITY(* m._connectivity);
140 _connectivity = (CONNECTIVITY *) NULL;
142 _spaceDimension = m._spaceDimension;
143 _meshDimension = m._meshDimension;
144 _numberOfNodes = m._numberOfNodes;
146 _familyNode = m._familyNode;
147 for (int i=0; i<m._familyNode.size(); i++)
149 _familyNode[i] = new FAMILY(* m._familyNode[i]);
150 _familyNode[i]->setMesh(this);
153 _familyCell = m._familyCell;
154 for (int i=0; i<m._familyCell.size(); i++)
156 _familyCell[i] = new FAMILY(* m._familyCell[i]);
157 _familyCell[i]->setMesh(this);
160 _familyFace = m._familyFace;
161 for (int i=0; i<m._familyFace.size(); i++)
163 _familyFace[i] = new FAMILY(* m._familyFace[i]);
164 _familyFace[i]->setMesh(this);
167 _familyEdge = m._familyEdge;
168 for (int i=0; i<m._familyEdge.size(); i++)
170 _familyEdge[i] = new FAMILY(* m._familyEdge[i]);
171 _familyEdge[i]->setMesh(this);
174 _groupNode = m._groupNode;
175 for (int i=0; i<m._groupNode.size(); i++)
177 _groupNode[i] = new GROUP(* m._groupNode[i]);
178 _groupNode[i]->setMesh(this);
181 _groupCell = m._groupCell;
182 for (int i=0; i<m._groupCell.size(); i++)
184 _groupCell[i] = new GROUP(* m._groupCell[i]);
185 _groupCell[i]->setMesh(this);
188 _groupFace = m._groupFace;
189 for (int i=0; i<m._groupFace.size(); i++)
191 _groupFace[i] = new GROUP(* m._groupFace[i]);
192 _groupFace[i]->setMesh(this);
195 _groupEdge = m._groupEdge;
196 for (int i=0; i<m._groupEdge.size(); i++)
198 _groupEdge[i] = new GROUP(* m._groupEdge[i]);
199 _groupEdge[i]->setMesh(this);
202 //_drivers = m._drivers; //Recopie des drivers?
207 MESSAGE("MESH::~MESH() : Destroying the Mesh");
208 if (_coordinate != ((COORDINATE *) NULL)) delete _coordinate ;
209 if (_connectivity != ((CONNECTIVITY *) NULL)) delete _connectivity ;
211 size = _familyNode.size() ;
212 for (int i=0;i<size;i++)
213 delete _familyNode[i] ;
214 size = _familyCell.size() ;
215 for (int i=0;i<size;i++)
216 delete _familyCell[i] ;
217 size = _familyFace.size() ;
218 for (int i=0;i<size;i++)
219 delete _familyFace[i] ;
220 size = _familyEdge.size() ;
221 for (int i=0;i<size;i++)
222 delete _familyEdge[i] ;
223 size = _groupNode.size() ;
224 for (int i=0;i<size;i++)
225 delete _groupNode[i] ;
226 size = _groupCell.size() ;
227 for (int i=0;i<size;i++)
228 delete _groupCell[i] ;
229 size = _groupFace.size() ;
230 for (int i=0;i<size;i++)
231 delete _groupFace[i] ;
232 size = _groupEdge.size() ;
233 for (int i=0;i<size;i++)
234 delete _groupEdge[i] ;
236 MESSAGE("In this object MESH there is(are) " << _drivers.size() << " driver(s)");
238 for (unsigned int index=0; index < _drivers.size(); index++ )
240 SCRUTE(_drivers[index]);
241 if ( _drivers[index] != NULL) delete _drivers[index];
246 MESH & MESH::operator=(const MESH &m)
248 const char * LOC = "MESH & MESH::operator=(const MESH &m) : ";
251 MESSAGE(LOC <<"Not yet implemented, operating on the object " << m);
254 // ATTENTION CET OPERATEUR DE RECOPIE EST DANGEREUX POUR LES
255 // POINTEURS : ex : nodal_connectivity ???? EXPRES ????
256 // _drivers = m._drivers;
258 // space_dimension=m.space_dimension;
259 // mesh_dimension=m.mesh_dimension;
261 // nodes_count=m.nodes_count;
262 // coordinates=m.coordinates;
263 // coordinates_name=m.coordinates_name ;
264 // coordinates_unit=m.coordinates_unit ;
265 // nodes_numbers=m.nodes_numbers ;
267 // cells_types_count=m.cells_types_count;
268 // cells_type=m.cells_type;
269 // cells_count=m.cells_count;
270 // nodal_connectivity=m.nodal_connectivity;
272 // nodes_families_count=m.nodes_families_count;
273 // nodes_Families=m.nodes_Families;
275 // cells_families_count=m.cells_families_count;
276 // cells_Families=m.cells_Families;
278 // maximum_cell_number_by_node = m.maximum_cell_number_by_node;
279 // if (maximum_cell_number_by_node > 0)
281 // reverse_nodal_connectivity = m.reverse_nodal_connectivity;
282 // reverse_nodal_connectivity_index = m.reverse_nodal_connectivity_index ;
289 /*! Create a %MESH object using a %MESH driver of type %driverTypes (MED_DRIVER, ....) associated with file fileName.
290 The meshname driverName must already exists in the file.*/
291 MESH::MESH(driverTypes driverType, const string & fileName/*=""*/, const string & driverName/*=""*/) throw (MEDEXCEPTION)
293 const char * LOC ="MESH::MESH(driverTypes driverType, const string & fileName="", const string & driverName="") : ";
299 GENDRIVER *myDriver=DRIVERFACTORY::buildDriverForMesh(driverType,fileName,this,driverName);
300 current = addDriver(*myDriver);
302 _drivers[current]->open();
303 _drivers[current]->read();
304 _drivers[current]->close();
307 // ((GRID *) this)->fillMeshAfterRead();
313 // Node MESH::Donne_Barycentre(const Maille &m) const
315 // Node N=node[m[0]];
316 // for (int i=1;i<m.donne_nbr_sommets();i++) N=N+node[m[i]];
317 // N=N*(1.0/m.donne_nbr_sommets());
321 ostream & MEDMEM::operator<<(ostream &os, const MESH &myMesh)
323 int spacedimension = myMesh.getSpaceDimension();
324 int meshdimension = myMesh.getMeshDimension();
325 int numberofnodes = myMesh.getNumberOfNodes();
327 os << "Space Dimension : " << spacedimension << endl << endl;
329 os << "Mesh Dimension : " << meshdimension << endl << endl;
331 const double * coordinates = myMesh.getCoordinates(MED_FULL_INTERLACE);
332 os << "SHOW NODES COORDINATES : " << endl;
334 os << "Name :" << endl;
335 const string * coordinatesnames = myMesh.getCoordinatesNames();
336 for(int i=0; i<spacedimension ; i++)
338 os << " - " << coordinatesnames[i] << endl;
340 os << "Unit :" << endl;
341 const string * coordinatesunits = myMesh.getCoordinatesUnits();
342 for(int i=0; i<spacedimension ; i++)
344 os << " - " << coordinatesunits[i] << endl;
346 for(int i=0; i<numberofnodes ; i++)
348 os << "Nodes " << i+1 << " : ";
349 for (int j=0; j<spacedimension ; j++)
350 os << coordinates[i*spacedimension+j] << " ";
354 os << endl << "SHOW CONNECTIVITY :" << endl;
355 os << *myMesh._connectivity << endl;
357 medEntityMesh entity;
358 os << endl << "SHOW FAMILIES :" << endl << endl;
359 for (int k=1; k<=4; k++)
361 if (k==1) entity = MED_NODE;
362 if (k==2) entity = MED_CELL;
363 if (k==3) entity = MED_FACE;
364 if (k==4) entity = MED_EDGE;
365 int numberoffamilies = myMesh.getNumberOfFamilies(entity);
366 os << "NumberOfFamilies on "<< entNames[entity] <<" : "<<numberoffamilies<<endl;
367 using namespace MED_EN;
368 for (int i=1; i<numberoffamilies+1;i++)
370 os << * myMesh.getFamily(entity,i) << endl;
374 os << endl << "SHOW GROUPS :" << endl << endl;
375 for (int k=1; k<=4; k++)
377 if (k==1) entity = MED_NODE;
378 if (k==2) entity = MED_CELL;
379 if (k==3) entity = MED_FACE;
380 if (k==4) entity = MED_EDGE;
381 int numberofgroups = myMesh.getNumberOfGroups(entity);
382 os << "NumberOfGroups on "<< entNames[entity] <<" : "<<numberofgroups<<endl;
383 using namespace MED_EN;
384 for (int i=1; i<numberofgroups+1;i++)
386 os << * myMesh.getGroup(entity,i) << endl;
394 Get global number of element which have same connectivity than connectivity argument.
396 It do not take care of connectivity order (3,4,7,10 is same as 7,3,10,4).
398 Return -1 if not found.
400 int MESH::getElementNumber(medConnectivity ConnectivityType, medEntityMesh Entity, medGeometryElement Type, int * connectivity) const
402 const char* LOC="MESH::getElementNumber " ;
405 int numberOfValue ; // size of connectivity array
406 CELLMODEL myType(Type) ;
407 if (ConnectivityType==MED_DESCENDING)
408 numberOfValue = myType.getNumberOfConstituents(1) ; // faces (3D) or edges (2D)
410 numberOfValue = myType.getNumberOfNodes() ; // nodes
412 const int * myReverseConnectivityValue = getReverseConnectivity(ConnectivityType,Entity) ;
413 const int * myReverseConnectivityIndex = getReverseConnectivityIndex(ConnectivityType,Entity) ;
415 // First node or face/edge
416 int indexBegin = myReverseConnectivityIndex[connectivity[0]-1] ;
417 int indexEnd = myReverseConnectivityIndex[connectivity[0]] ;
419 // list to put cells numbers
420 list<int> cellsList ;
421 list<int>::iterator itList ;
422 for (int i=indexBegin; i<indexEnd; i++)
423 cellsList.push_back(myReverseConnectivityValue[i-1]) ;
425 // Foreach node or face/edge in cell, we search cells which are in common.
426 // At the end, we must have only one !
428 for (int i=1; i<numberOfValue; i++) {
429 int connectivity_i = connectivity[i] ;
430 for (itList=cellsList.begin();itList!=cellsList.end();itList++) {
432 for (int j=myReverseConnectivityIndex[connectivity_i-1]; j<myReverseConnectivityIndex[connectivity_i]; j++) {
433 if ((*itList)==myReverseConnectivityValue[j-1]) {
439 itList=cellsList.erase(itList);
440 itList--; // well : rigth if itList = cellsList.begin() ??
445 if (cellsList.size()>1) // we have more than one cell
446 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Found more than one element !")) ;
448 if (cellsList.size()==0)
453 return cellsList.front() ;
458 Return a support which reference all elements on the boundary of mesh.
460 For instance, we could get only face in 3D and edge in 2D.
462 SUPPORT * MESH::getBoundaryElements(medEntityMesh Entity)
465 const char * LOC = "MESH::getBoundaryElements : " ;
468 // actually we could only get face (in 3D) and edge (in 2D)
469 if (_spaceDimension == 3)
470 if (Entity != MED_FACE)
471 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 3D mesh for entity "<<Entity<<" !"));
472 if (_spaceDimension == 2)
473 if (Entity != MED_EDGE)
474 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined in 2D mesh for entity "<<Entity<<" !"));
477 SUPPORT * mySupport = new SUPPORT(this,"Boundary",Entity);
478 //mySupport.setDescription("boundary of type ...");
479 mySupport->setAll(false);
482 const int * myConnectivityValue = getReverseConnectivity(MED_DESCENDING) ;
483 const int * myConnectivityIndex = getReverseConnectivityIndex(MED_DESCENDING) ;
484 int numberOf = getNumberOfElements(Entity,MED_ALL_ELEMENTS) ;
485 list<int> myElementsList ;
487 for (int i=0 ; i<numberOf; i++)
488 if (myConnectivityValue[myConnectivityIndex[i]] == 0) {
489 myElementsList.push_back(i+1) ;
492 // Well, we must know how many geometric type we have found
493 int * myListArray = new int[size] ;
495 list<int>::iterator myElementsListIt ;
496 for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
497 myListArray[id]=(*myElementsListIt) ;
501 int numberOfGeometricType ;
502 medGeometryElement* geometricType ;
503 int * numberOfGaussPoint ;
504 int * geometricTypeNumber ;
505 int * numberOfElements ;
506 //MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY() ;
507 int * mySkyLineArrayIndex ;
509 int numberOfType = getNumberOfTypes(Entity) ;
510 if (numberOfType == 1) { // wonderfull : it's easy !
511 numberOfGeometricType = 1 ;
512 geometricType = new medGeometryElement[1] ;
513 const medGeometryElement * allType = getTypes(Entity);
514 geometricType[0] = allType[0] ;
515 numberOfGaussPoint = new int[1] ;
516 numberOfGaussPoint[0] = 1 ;
517 geometricTypeNumber = new int[1] ; // not use, but initialized to nothing
518 geometricTypeNumber[0] = 0 ;
519 numberOfElements = new int[1] ;
520 numberOfElements[0] = size ;
521 mySkyLineArrayIndex = new int[2] ;
522 mySkyLineArrayIndex[0]=1 ;
523 mySkyLineArrayIndex[1]=1+size ;
526 map<medGeometryElement,int> theType ;
527 for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
528 medGeometryElement myType = getElementType(Entity,*myElementsListIt) ;
529 if (theType.find(myType) != theType.end() )
534 numberOfGeometricType = theType.size() ;
535 geometricType = new medGeometryElement[numberOfGeometricType] ;
536 //const medGeometryElement * allType = getTypes(Entity); !! UNUSZED VARIABLE !!
537 numberOfGaussPoint = new int[numberOfGeometricType] ;
538 geometricTypeNumber = new int[numberOfGeometricType] ; // not use, but initialized to nothing
539 numberOfElements = new int[numberOfGeometricType] ;
540 mySkyLineArrayIndex = new int[numberOfGeometricType+1] ;
542 mySkyLineArrayIndex[0]=1 ;
543 map<medGeometryElement,int>::iterator theTypeIt ;
544 for (theTypeIt=theType.begin();theTypeIt!=theType.end();theTypeIt++) {
545 geometricType[index] = (*theTypeIt).first ;
546 numberOfGaussPoint[index] = 1 ;
547 geometricTypeNumber[index] = 0 ;
548 numberOfElements[index] = (*theTypeIt).second ;
549 mySkyLineArrayIndex[index+1]=mySkyLineArrayIndex[index]+numberOfElements[index] ;
553 //mySkyLineArray->setMEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray) ;
554 MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray) ;
556 mySupport->setNumberOfGeometricType(numberOfGeometricType) ;
557 mySupport->setGeometricType(geometricType) ;
558 mySupport->setNumberOfGaussPoint(numberOfGaussPoint) ;
559 mySupport->setNumberOfElements(numberOfElements) ;
560 mySupport->setTotalNumberOfElements(size) ;
561 // mySupport->setGeometricTypeNumber(geometricTypeNumber) ;
562 mySupport->setNumber(mySkyLineArray) ;
564 delete[] numberOfElements;
565 delete[] geometricTypeNumber;
566 delete[] numberOfGaussPoint;
567 delete[] geometricType;
568 delete[] mySkyLineArrayIndex;
569 delete[] myListArray;
570 // delete mySkyLineArray;
576 FIELD<double>* MESH::getVolume(const SUPPORT * Support) const throw (MEDEXCEPTION)
578 const char * LOC = "MESH::getVolume(SUPPORT*) : ";
581 // Support must be on 3D elements
583 // Make sure that the MESH class is the same as the MESH class attribut
584 // in the class Support
585 MESH* myMesh = Support->getMesh();
587 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"no compatibility between *this and SUPPORT::_mesh !"));
589 int dim_space = getSpaceDimension();
590 medEntityMesh support_entity = Support->getEntity();
591 bool onAll = Support->isOnAllElements();
593 int nb_type, length_values;
594 const medGeometryElement* types;
596 // !!!! WARNING : use of nodal global numbering in the mesh !!!!
597 const int* global_connectivity;
601 // nb_type = myMesh->getNumberOfTypes(support_entity);
602 // length_values = getNumberOfElements(support_entity,MED_ALL_ELEMENTS);
603 // types = getTypes(support_entity);
607 nb_type = Support->getNumberOfTypes();
608 length_values = Support->getNumberOfElements(MED_ALL_ELEMENTS);
609 types = Support->getTypes();
613 FIELD<double>* Volume = new FIELD<double>(Support,1);
614 // double *volume = new double [length_values];
615 Volume->setName("VOLUME");
616 Volume->setDescription("cells volume");
617 Volume->setComponentName(1,"volume");
618 Volume->setComponentDescription(1,"desc-comp");
620 /* string MEDComponentUnit(MED_TAILLE_PNOM,' ');*/
622 string MEDComponentUnit = myMesh->getCoordinatesUnits()[0]+"*"+myMesh->getCoordinatesUnits()[1]+"*"+myMesh->getCoordinatesUnits()[2];
624 Volume->setMEDComponentUnit(1,MEDComponentUnit);
626 Volume->setValueType(MED_REEL64);
628 Volume->setIterationNumber(0);
629 Volume->setOrderNumber(0);
630 Volume->setTime(0.0);
632 //const double *volume = Volume->getValue(MED_FULL_INTERLACE);
633 MEDARRAY<double> *volume = Volume->getvalue();
636 const double * coord = getCoordinates(MED_FULL_INTERLACE);
638 for (int i=0;i<nb_type;i++)
640 medGeometryElement type = types[i] ;
645 nb_entity_type = getNumberOfElements(support_entity,type);
646 global_connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,type);
650 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support must be on all"));
652 nb_entity_type = Support->getNumberOfElements(type);
654 const int * supp_number = Support->getNumber(type);
655 const int * connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,MED_ALL_ELEMENTS);
656 const int * connectivityIndex = getConnectivityIndex(MED_NODAL,support_entity);
657 int * global_connectivity_tmp = new int[(type%100)*nb_entity_type];
659 for (int k_type = 0; k_type<nb_entity_type; k_type++) {
660 for (int j_ent = 0; j_ent<(type%100); j_ent++) {
661 global_connectivity_tmp[k_type*(type%100)+j_ent] = connectivity[connectivityIndex[supp_number[k_type]-1]+j_ent-1];
664 global_connectivity = global_connectivity_tmp ;
669 case MED_TETRA4 : case MED_TETRA10 :
671 for (int tetra=0;tetra<nb_entity_type;tetra++)
673 int tetra_index = (type%100)*tetra;
675 int N1 = global_connectivity[tetra_index]-1;
676 int N2 = global_connectivity[tetra_index+1]-1;
677 int N3 = global_connectivity[tetra_index+2]-1;
678 int N4 = global_connectivity[tetra_index+3]-1;
680 double x1 = coord[dim_space*N1];
681 double x2 = coord[dim_space*N2];
682 double x3 = coord[dim_space*N3];
683 double x4 = coord[dim_space*N4];
685 double y1 = coord[dim_space*N1+1];
686 double y2 = coord[dim_space*N2+1];
687 double y3 = coord[dim_space*N3+1];
688 double y4 = coord[dim_space*N4+1];
690 double z1 = coord[dim_space*N1+2];
691 double z2 = coord[dim_space*N2+2];
692 double z3 = coord[dim_space*N3+2];
693 double z4 = coord[dim_space*N4+2];
695 xvolume = ((x3-x1)*((y2-y1)*(z4-z1) - (z2-z1)*(y4-y1)) -
696 (x2-x1)*((y3-y1)*(z4-z1) - (z3-z1)*(y4-y1)) +
697 (x4-x1)*((y3-y1)*(z2-z1) - (z3-z1)*(y2-y1)))/6.0;
699 //volume[index] = xvolume ;
700 volume->setIJ(index,1,xvolume) ;
705 case MED_PYRA5 : case MED_PYRA13 :
707 for (int pyra=0;pyra<nb_entity_type;pyra++)
709 int pyra_index = (type%100)*pyra;
711 int N1 = global_connectivity[pyra_index]-1;
712 int N2 = global_connectivity[pyra_index+1]-1;
713 int N3 = global_connectivity[pyra_index+2]-1;
714 int N4 = global_connectivity[pyra_index+3]-1;
715 int N5 = global_connectivity[pyra_index+4]-1;
717 double x1 = coord[dim_space*N1];
718 double x2 = coord[dim_space*N2];
719 double x3 = coord[dim_space*N3];
720 double x4 = coord[dim_space*N4];
721 double x5 = coord[dim_space*N5];
723 double y1 = coord[dim_space*N1+1];
724 double y2 = coord[dim_space*N2+1];
725 double y3 = coord[dim_space*N3+1];
726 double y4 = coord[dim_space*N4+1];
727 double y5 = coord[dim_space*N5+1];
729 double z1 = coord[dim_space*N1+2];
730 double z2 = coord[dim_space*N2+2];
731 double z3 = coord[dim_space*N3+2];
732 double z4 = coord[dim_space*N4+2];
733 double z5 = coord[dim_space*N5+2];
735 xvolume = (((x3-x1)*((y2-y1)*(z5-z1) - (z2-z1)*(y5-y1)) -
736 (x2-x1)*((y3-y1)*(z5-z1) - (z3-z1)*(y5-y1)) +
737 (x5-x1)*((y3-y1)*(z2-z1) - (z3-z1)*(y2-y1))) +
738 ((x4-x1)*((y3-y1)*(z5-z1) - (z3-z1)*(y5-y1)) -
739 (x3-x1)*((y4-y1)*(z5-z1) - (z4-z1)*(y5-y1)) +
740 (x5-x1)*((y4-y1)*(z3-z1) - (z4-z1)*(y3-y1)))
743 //volume[index] = xvolume ;
744 volume->setIJ(index,1,xvolume) ;
749 case MED_PENTA6 : case MED_PENTA15 :
751 for (int penta=0;penta<nb_entity_type;penta++)
753 int penta_index = (type%100)*penta;
755 int N1 = global_connectivity[penta_index]-1;
756 int N2 = global_connectivity[penta_index+1]-1;
757 int N3 = global_connectivity[penta_index+2]-1;
758 int N4 = global_connectivity[penta_index+3]-1;
759 int N5 = global_connectivity[penta_index+4]-1;
760 int N6 = global_connectivity[penta_index+5]-1;
762 double x1 = coord[dim_space*N1];
763 double x2 = coord[dim_space*N2];
764 double x3 = coord[dim_space*N3];
765 double x4 = coord[dim_space*N4];
766 double x5 = coord[dim_space*N5];
767 double x6 = coord[dim_space*N6];
769 double y1 = coord[dim_space*N1+1];
770 double y2 = coord[dim_space*N2+1];
771 double y3 = coord[dim_space*N3+1];
772 double y4 = coord[dim_space*N4+1];
773 double y5 = coord[dim_space*N5+1];
774 double y6 = coord[dim_space*N6+1];
776 double z1 = coord[dim_space*N1+2];
777 double z2 = coord[dim_space*N2+2];
778 double z3 = coord[dim_space*N3+2];
779 double z4 = coord[dim_space*N4+2];
780 double z5 = coord[dim_space*N5+2];
781 double z6 = coord[dim_space*N6+2];
783 double a1 = (x2-x3)/2.0, a2 = (y2-y3)/2.0, a3 = (z2-z3)/2.0;
784 double b1 = (x5-x6)/2.0, b2 = (y5-y6)/2.0, b3 = (z5-z6)/2.0;
785 double c1 = (x4-x1)/2.0, c2 = (y4-y1)/2.0, c3 = (z4-z1)/2.0;
786 double d1 = (x5-x2)/2.0, d2 = (y5-y2)/2.0, d3 = (z5-z2)/2.0;
787 double e1 = (x6-x3)/2.0, e2 = (y6-y3)/2.0, e3 = (z6-z3)/2.0;
788 double f1 = (x1-x3)/2.0, f2 = (y1-y3)/2.0, f3 = (z1-z3)/2.0;
789 double h1 = (x4-x6)/2.0, h2 = (y4-y6)/2.0, h3 = (z4-z6)/2.0;
791 double A = a1*c2*f3 - a1*c3*f2 - a2*c1*f3 + a2*c3*f1 +
793 double B = b1*c2*h3 - b1*c3*h2 - b2*c1*h3 + b2*c3*h1 +
795 double C = (a1*c2*h3 + b1*c2*f3) - (a1*c3*h2 + b1*c3*f2) -
796 (a2*c1*h3 + b2*c1*f3) + (a2*c3*h1 + b2*c3*f1) +
797 (a3*c1*h2 + b3*c1*f2) - (a3*c2*h1 + b3*c2*f1);
798 double D = a1*d2*f3 - a1*d3*f2 - a2*d1*f3 + a2*d3*f1 +
800 double E = b1*d2*h3 - b1*d3*h2 - b2*d1*h3 + b2*d3*h1 +
802 double F = (a1*d2*h3 + b1*d2*f3) - (a1*d3*h2 + b1*d3*f2) -
803 (a2*d1*h3 + b2*d1*f3) + (a2*d3*h1 + b2*d3*f1) +
804 (a3*d1*h2 + b3*d1*f2) - (a3*d2*h1 + b3*d2*f1);
805 double G = a1*e2*f3 - a1*e3*f2 - a2*e1*f3 + a2*e3*f1 +
807 double H = b1*e2*h3 - b1*e3*h2 - b2*e1*h3 + b2*e3*h1 +
809 double P = (a1*e2*h3 + b1*e2*f3) - (a1*e3*h2 + b1*e3*f2) -
810 (a2*e1*h3 + b2*e1*f3) + (a2*e3*h1 + b2*e3*f1) +
811 (a3*e1*h2 + b3*e1*f2) - (a3*e2*h1 + b3*e2*f1);
813 xvolume = -2.0*(2.0*(A + B + D + E + G + H) + C + F + P)/9.0;
815 //volume[index] = xvolume ;
816 volume->setIJ(index,1,xvolume) ;
821 case MED_HEXA8 : case MED_HEXA20 :
823 for (int hexa=0;hexa<nb_entity_type;hexa++)
825 int hexa_index = (type%100)*hexa;
827 int N1 = global_connectivity[hexa_index]-1;
828 int N2 = global_connectivity[hexa_index+1]-1;
829 int N3 = global_connectivity[hexa_index+2]-1;
830 int N4 = global_connectivity[hexa_index+3]-1;
831 int N5 = global_connectivity[hexa_index+4]-1;
832 int N6 = global_connectivity[hexa_index+5]-1;
833 int N7 = global_connectivity[hexa_index+6]-1;
834 int N8 = global_connectivity[hexa_index+7]-1;
836 double x1 = coord[dim_space*N1];
837 double x2 = coord[dim_space*N2];
838 double x3 = coord[dim_space*N3];
839 double x4 = coord[dim_space*N4];
840 double x5 = coord[dim_space*N5];
841 double x6 = coord[dim_space*N6];
842 double x7 = coord[dim_space*N7];
843 double x8 = coord[dim_space*N8];
845 double y1 = coord[dim_space*N1+1];
846 double y2 = coord[dim_space*N2+1];
847 double y3 = coord[dim_space*N3+1];
848 double y4 = coord[dim_space*N4+1];
849 double y5 = coord[dim_space*N5+1];
850 double y6 = coord[dim_space*N6+1];
851 double y7 = coord[dim_space*N7+1];
852 double y8 = coord[dim_space*N8+1];
854 double z1 = coord[dim_space*N1+2];
855 double z2 = coord[dim_space*N2+2];
856 double z3 = coord[dim_space*N3+2];
857 double z4 = coord[dim_space*N4+2];
858 double z5 = coord[dim_space*N5+2];
859 double z6 = coord[dim_space*N6+2];
860 double z7 = coord[dim_space*N7+2];
861 double z8 = coord[dim_space*N8+2];
863 double a1 = (x3-x4)/8.0, a2 = (y3-y4)/8.0, a3 = (z3-z4)/8.0;
864 double b1 = (x2-x1)/8.0, b2 = (y2-y1)/8.0, b3 = (z2-z1)/8.0;
865 double c1 = (x7-x8)/8.0, c2 = (y7-y8)/8.0, c3 = (z7-z8)/8.0;
866 double d1 = (x6-x5)/8.0, d2 = (y6-y5)/8.0, d3 = (z6-z5)/8.0;
867 double e1 = (x3-x2)/8.0, e2 = (y3-y2)/8.0, e3 = (z3-z2)/8.0;
868 double f1 = (x4-x1)/8.0, f2 = (y4-y1)/8.0, f3 = (z4-z1)/8.0;
869 double h1 = (x7-x6)/8.0, h2 = (y7-y6)/8.0, h3 = (z7-z6)/8.0;
870 double p1 = (x8-x5)/8.0, p2 = (y8-y5)/8.0, p3 = (z8-z5)/8.0;
871 double q1 = (x3-x7)/8.0, q2 = (y3-y7)/8.0, q3 = (z3-z7)/8.0;
872 double r1 = (x4-x8)/8.0, r2 = (y4-y8)/8.0, r3 = (z4-z8)/8.0;
873 double s1 = (x2-x6)/8.0, s2 = (y2-y6)/8.0, s3 = (z2-z6)/8.0;
874 double t1 = (x1-x5)/8.0, t2 = (y1-y5)/8.0, t3 = (z1-z5)/8.0;
876 double A = a1*e2*q3 - a1*e3*q2 - a2*e1*q3 + a2*e3*q1 +
878 double B = c1*h2*q3 - c1*h3*q2 - c2*h1*q3 + c2*h3*q1 +
880 double C = (a1*h2 + c1*e2)*q3 - (a1*h3 + c1*e3)*q2 -
881 (a2*h1 + c2*e1)*q3 + (a2*h3 + c2*e3)*q1 +
882 (a3*h1 + c3*e1)*q2 - (a3*h2 + c3*e2)*q1;
883 double D = b1*e2*s3 - b1*e3*s2 - b2*e1*s3 + b2*e3*s1 +
885 double E = d1*h2*s3 - d1*h3*s2 - d2*h1*s3 + d2*h3*s1 +
887 double F = (b1*h2 + d1*e2)*s3 - (b1*h3 + d1*e3)*s2 -
888 (b2*h1 + d2*e1)*s3 + (b2*h3 + d2*e3)*s1 +
889 (b3*h1 + d3*e1)*s2 - (b3*h2 + d3*e2)*s1;
890 double G = (a1*e2*s3 + b1*e2*q3) - (a1*e3*s2 + b1*e3*q2) -
891 (a2*e1*s3 + b2*e1*q3) + (a2*e3*s1 + b2*e3*q1) +
892 (a3*e1*s2 + b3*e1*q2) - (a3*e2*s1 + b3*e2*q1);
893 double H = (c1*h2*s3 + d1*h2*q3) - (c1*h3*s2 + d1*h3*q2) -
894 (c2*h1*s3 + d2*h1*q3) + (c2*h3*s1 + d2*h3*q1) +
895 (c3*h1*s2 + d3*h1*q2) - (c3*h2*s1 + d3*h2*q1);
896 double I = ((a1*h2 + c1*e2)*s3 + (b1*h2 + d1*e2)*q3) -
897 ((a1*h3 + c1*e3)*s2 + (b1*h3 + d1*e3)*q2) -
898 ((a2*h1 + c2*e1)*s3 + (b2*h1 + d2*e1)*q3) +
899 ((a2*h3 + c2*e3)*s1 + (b2*h3 + d2*e3)*q1) +
900 ((a3*h1 + c3*e1)*s2 + (b3*h1 + d3*e1)*q2) -
901 ((a3*h2 + c3*e2)*s1 + (b3*h2 + d3*e2)*q1);
902 double J = a1*f2*r3 - a1*f3*r2 - a2*f1*r3 + a2*f3*r1 +
904 double K = c1*p2*r3 - c1*p3*r2 - c2*p1*r3 + c2*p3*r1 +
906 double L = (a1*p2 + c1*f2)*r3 - (a1*p3 + c1*f3)*r2 -
907 (a2*p1 + c2*f1)*r3 + (a2*p3 + c2*f3)*r1 +
908 (a3*p1 + c3*f1)*r2 - (a3*p2 + c3*f2)*r1;
909 double M = b1*f2*t3 - b1*f3*t2 - b2*f1*t3 + b2*f3*t1 +
911 double N = d1*p2*t3 - d1*p3*t2 - d2*p1*t3 + d2*p3*t1 +
913 double O = (b1*p2 + d1*f2)*t3 - (b1*p3 + d1*f3)*t2 -
914 (b2*p1 + d2*f1)*t3 + (b2*p3 + d2*f3)*t1 +
915 (b3*p1 + d3*f1)*t2 - (b3*p2 + d3*f2)*t1;
916 double P = (a1*f2*t3 + b1*f2*r3) - (a1*f3*t2 + b1*f3*r2) -
917 (a2*f1*t3 + b2*f1*r3) + (a2*f3*t1 + b2*f3*r1) +
918 (a3*f1*t2 + b3*f1*r2) - (a3*f2*t1 + b3*f2*r1);
919 double Q = (c1*p2*t3 + d1*p2*r3) - (c1*p3*t2 + d1*p3*r2) -
920 (c2*p1*t3 + d2*p1*r3) + (c2*p3*t1 + d2*p3*r1) +
921 (c3*p1*t2 + d3*p1*r2) - (c3*p2*t1 + d3*p2*r1);
922 double R = ((a1*p2 + c1*f2)*t3 + (b1*p2 + d1*f2)*r3) -
923 ((a1*p3 + c1*f3)*t2 + (b1*p3 + d1*f3)*r2) -
924 ((a2*p1 + c2*f1)*t3 + (b2*p1 + d2*f1)*r3) +
925 ((a2*p3 + c2*f3)*t1 + (b2*p3 + d2*f3)*r1) +
926 ((a3*p1 + c3*f1)*t2 + (b3*p1 + d3*f1)*r2) -
927 ((a3*p2 + c3*f2)*t1 + (b3*p2 + d3*f2)*r1);
928 double S = (a1*e2*r3 + a1*f2*q3) - (a1*e3*r2 + a1*f3*q2) -
929 (a2*e1*r3 + a2*f1*q3) + (a2*e3*r1 + a2*f3*q1) +
930 (a3*e1*r2 + a3*f1*q2) - (a3*e2*r1 + a3*f2*q1);
931 double T = (c1*h2*r3 + c1*p2*q3) - (c1*h3*r2 + c1*p3*q2) -
932 (c2*h1*r3 + c2*p1*q3) + (c2*h3*r1 + c2*p3*q1) +
933 (c3*h1*r2 + c3*p1*q2) - (c3*h2*r1 + c3*p2*q1);
934 double U = ((a1*h2 + c1*e2)*r3 + (a1*p2 + c1*f2)*q3) -
935 ((a1*h3 + c1*e3)*r2 + (a1*p3 + c1*f3)*q2) -
936 ((a2*h1 + c2*e1)*r3 + (a2*p1 + c2*f1)*q3) +
937 ((a2*h3 + c2*e3)*r1 + (a2*p3 + c2*f3)*q1) +
938 ((a3*h1 + c3*e1)*r2 + (a3*p1 + c3*f1)*q2) -
939 ((a3*h2 + c3*e2)*r1 + (a3*p2 + c3*f2)*q1);
940 double V = (b1*e2*t3 + b1*f2*s3) - (b1*e3*t2 + b1*f3*s2) -
941 (b2*e1*t3 + b2*f1*s3) + (b2*e3*t1 + b2*f3*s1) +
942 (b3*e1*t2 + b3*f1*s2) - (b3*e2*t1 + b3*f2*s1);
943 double W = (d1*h2*t3 + d1*p2*s3) - (d1*h3*t2 + d1*p3*s2) -
944 (d2*h1*t3 + d2*p1*s3) + (d2*h3*t1 + d2*p3*s1) +
945 (d3*h1*t2 + d3*p1*s2) - (d3*h2*t1 + d3*p2*s1);
946 double X = ((b1*h2 + d1*e2)*t3 + (b1*p2 + d1*f2)*s3) -
947 ((b1*h3 + d1*e3)*t2 + (b1*p3 + d1*f3)*s2) -
948 ((b2*h1 + d2*e1)*t3 + (b2*p1 + d2*f1)*s3) +
949 ((b2*h3 + d2*e3)*t1 + (b2*p3 + d2*f3)*s1) +
950 ((b3*h1 + d3*e1)*t2 + (b3*p1 + d3*f1)*s2) -
951 ((b3*h2 + d3*e2)*t1 + (b3*p2 + d3*f2)*s1);
952 double Y = (a1*e2*t3 + a1*f2*s3 + b1*e2*r3 + b1*f2*q3) -
953 (a1*e3*t2 + a1*f3*s2 + b1*e3*r2 + b1*f3*q2) -
954 (a2*e1*t3 + a2*f1*s3 + b2*e1*r3 + b2*f1*q3) +
955 (a2*e3*t1 + a2*f3*s1 + b2*e3*r1 + b2*f3*q1) +
956 (a3*e1*t2 + a3*f1*s2 + b3*e1*r2 + b3*f1*q2) -
957 (a3*e2*t1 + a3*f2*s1 + b3*e2*r1 + b3*f2*q1);
958 double Z = (c1*h2*t3 + c1*p2*s3 + d1*h2*r3 + d1*p2*q3) -
959 (c1*h3*t2 + c1*p3*s2 + d1*h3*r2 + d1*p3*q2) -
960 (c2*h1*t3 + c2*p1*s3 + d2*h1*r3 + d2*p1*q3) +
961 (c2*h3*t1 + c2*p3*s1 + d2*h3*r1 + d2*p3*q1) +
962 (c3*h1*t2 + c3*p1*s2 + d3*h1*r2 + d3*p1*q2) -
963 (c3*h2*t1 + c3*p2*s1 + d3*h2*r1 + d3*p2*q1);
964 double AA = ((a1*h2 + c1*e2)*t3 + (a1*p2 + c1*f2)*s3 +
965 (b1*h2 + d1*e2)*r3 + (b1*p2 + d1*f2)*q3) -
966 ((a1*h3 + c1*e3)*t2 + (a1*p3 + c1*f3)*s2 +
967 (b1*h3 + d1*e3)*r2 + (b1*p3 + d1*f3)*q2) -
968 ((a2*h1 + c2*e1)*t3 + (a2*p1 + c2*f1)*s3 +
969 (b2*h1 + d2*e1)*r3 + (b2*p1 + d2*f1)*q3) +
970 ((a2*h3 + c2*e3)*t1 + (a2*p3 + c2*f3)*s1 +
971 (b2*h3 + d2*e3)*r1 + (b2*p3 + d2*f3)*q1) +
972 ((a3*h1 + c3*e1)*t2 + (a3*p1 + c3*f1)*s2 +
973 (b3*h1 + d3*e1)*r2 + (b3*p1 + d3*f1)*q2) -
974 ((a3*h2 + c3*e2)*t1 + (a3*p2 + c3*f2)*s1 +
975 (b3*h2 + d3*e2)*r1 + (b3*p2 + d3*f2)*q1);
977 xvolume = 64.0*(8.0*(A + B + D + E + J + K + M + N) +
978 4.0*(C + F + G + H + L + O + P + Q + S + T +
979 V + W) + 2.0*(I + R + U + X + Y + Z) +
982 //volume[index] = xvolume ;
983 volume->setIJ(index,1,xvolume) ;
989 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get Volumes on it !"));
993 if (!onAll) delete [] global_connectivity ;
999 FIELD<double>* MESH::getArea(const SUPPORT * Support) const throw (MEDEXCEPTION)
1001 const char * LOC = "MESH::getArea(SUPPORT*) : ";
1004 // Support must be on 2D elements
1006 // Make sure that the MESH class is the same as the MESH class attribut
1007 // in the class Support
1008 MESH* myMesh = Support->getMesh();
1010 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"no compatibility between *this and SUPPORT::_mesh !"));
1012 int dim_space = getSpaceDimension();
1013 medEntityMesh support_entity = Support->getEntity();
1014 bool onAll = Support->isOnAllElements();
1016 int nb_type, length_values;
1017 const medGeometryElement* types;
1019 // !!!! WARNING : use of nodal global numbering in the mesh !!!!
1020 const int* global_connectivity;
1024 // nb_type = myMesh->getNumberOfTypes(support_entity);
1025 // length_values = getNumberOfElements(support_entity,MED_ALL_ELEMENTS);
1026 // types = getTypes(support_entity);
1030 nb_type = Support->getNumberOfTypes();
1031 length_values = Support->getNumberOfElements(MED_ALL_ELEMENTS);
1032 types = Support->getTypes();
1036 FIELD<double>* Area;
1038 Area = new FIELD<double>(Support,1);
1039 Area->setName("AREA");
1040 Area->setDescription("cells or faces area");
1042 Area->setComponentName(1,"area");
1043 Area->setComponentDescription(1,"desc-comp");
1045 /* string MEDComponentUnit = myMesh->getCoordinatesUnits()[0]+"*"+myMesh->getCoordinatesUnits()[1];*/
1047 string MEDComponentUnit="trucmuch";
1049 Area->setMEDComponentUnit(1,MEDComponentUnit);
1051 Area->setValueType(MED_REEL64);
1053 Area->setIterationNumber(0);
1054 Area->setOrderNumber(0);
1057 double *area = new double[length_values];
1058 //double *area = Area->getValue(MED_FULL_INTERLACE);
1060 const double * coord = getCoordinates(MED_FULL_INTERLACE);
1063 for (int i=0;i<nb_type;i++)
1065 medGeometryElement type = types[i] ;
1070 nb_entity_type = getNumberOfElements(support_entity,type);
1071 global_connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,type);
1075 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support must be on all !"));
1077 nb_entity_type = Support->getNumberOfElements(type);
1079 const int * supp_number = Support->getNumber(type);
1080 const int * connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,MED_ALL_ELEMENTS);
1081 const int * connectivityIndex = getConnectivityIndex(MED_NODAL,support_entity);
1082 int * global_connectivity_tmp = new int[(type%100)*nb_entity_type];
1084 for (int k_type = 0; k_type<nb_entity_type; k_type++) {
1085 for (int j_ent = 0; j_ent<(type%100); j_ent++) {
1086 global_connectivity_tmp[k_type*(type%100)+j_ent] = connectivity[connectivityIndex[supp_number[k_type]-1]+j_ent-1];
1090 global_connectivity = global_connectivity_tmp ;
1096 case MED_TRIA3 : case MED_TRIA6 :
1098 for (int tria=0;tria<nb_entity_type;tria++)
1100 int tria_index = (type%100)*tria;
1102 int N1 = global_connectivity[tria_index]-1;
1103 int N2 = global_connectivity[tria_index+1]-1;
1104 int N3 = global_connectivity[tria_index+2]-1;
1106 double x1 = coord[dim_space*N1];
1107 double x2 = coord[dim_space*N2];
1108 double x3 = coord[dim_space*N3];
1110 double y1 = coord[dim_space*N1+1];
1111 double y2 = coord[dim_space*N2+1];
1112 double y3 = coord[dim_space*N3+1];
1116 xarea = - ((x2-x1)*(y3-y1) - (x3-x1)*(y2-y1))/2.0;
1120 double z1 = coord[dim_space*N1+2];
1121 double z2 = coord[dim_space*N2+2];
1122 double z3 = coord[dim_space*N3+2];
1124 xarea = sqrt(((y2-y1)*(z3-z1) - (y3-y1)*(z2-z1))*
1125 ((y2-y1)*(z3-z1) - (y3-y1)*(z2-z1)) +
1126 ((x3-x1)*(z2-z1) - (x2-x1)*(z3-z1))*
1127 ((x3-x1)*(z2-z1) - (x2-x1)*(z3-z1)) +
1128 ((x2-x1)*(y3-y1) - (x3-x1)*(y2-y1))*
1129 ((x2-x1)*(y3-y1) - (x3-x1)*(y2-y1)))/2.0;
1132 area[index] = xarea ;
1137 case MED_QUAD4 : case MED_QUAD8 :
1139 for (int quad=0;quad<nb_entity_type;quad++)
1141 int quad_index = (type%100)*quad;
1143 int N1 = global_connectivity[quad_index]-1;
1144 int N2 = global_connectivity[quad_index+1]-1;
1145 int N3 = global_connectivity[quad_index+2]-1;
1146 int N4 = global_connectivity[quad_index+3]-1;
1148 double x1 = coord[dim_space*N1];
1149 double x2 = coord[dim_space*N2];
1150 double x3 = coord[dim_space*N3];
1151 double x4 = coord[dim_space*N4];
1153 double y1 = coord[dim_space*N1+1];
1154 double y2 = coord[dim_space*N2+1];
1155 double y3 = coord[dim_space*N3+1];
1156 double y4 = coord[dim_space*N4+1];
1160 double a1 = (x2-x1)/4.0, a2 = (y2-y1)/4.0;
1161 double b1 = (x3-x4)/4.0, b2 = (y3-y4)/4.0;
1162 double c1 = (x3-x2)/4.0, c2 = (y3-y2)/4.0;
1163 double d1 = (x4-x1)/4.0, d2 = (y4-y1)/4.0;
1165 xarea = - 4.0*(b1*c2 - c1*b2 + a1*c2 - c1*a2 + b1*d2 -
1166 d1*b2 + a1*d2 - d1*a2);
1170 double z1 = coord[dim_space*N1+2];
1171 double z2 = coord[dim_space*N2+2];
1172 double z3 = coord[dim_space*N3+2];
1173 double z4 = coord[dim_space*N4+2];
1175 xarea = (sqrt(((y2-y1)*(z4-z1) - (y4-y1)*(z2-z1))*
1176 ((y2-y1)*(z4-z1) - (y4-y1)*(z2-z1)) +
1177 ((x4-x1)*(z2-z1) - (x2-x1)*(z4-z1))*
1178 ((x4-x1)*(z2-z1) - (x2-x1)*(z4-z1)) +
1179 ((x2-x1)*(y4-y1) - (x4-x1)*(y2-y1))*
1180 ((x2-x1)*(y4-y1) - (x4-x1)*(y2-y1))) +
1181 sqrt(((y4-y3)*(z2-z3) - (y2-y3)*(z4-z3))*
1182 ((y4-y3)*(z2-z3) - (y2-y3)*(z4-z3)) +
1183 ((x2-x3)*(z4-z3) - (x4-x3)*(z2-z3))*
1184 ((x2-x3)*(z4-z3) - (x4-x3)*(z2-z3)) +
1185 ((x4-x3)*(y2-y3) - (x2-x3)*(y4-y3))*
1186 ((x4-x3)*(y2-y3) - (x2-x3)*(y4-y3))))/2.0;
1189 area[index] = xarea ;
1195 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get Areas on it !"));
1199 if (!onAll) delete [] global_connectivity ;
1202 Area->setValue(MED_FULL_INTERLACE,area);
1207 FIELD<double>* MESH::getLength(const SUPPORT * Support) const throw (MEDEXCEPTION)
1209 const char * LOC = "MESH::getLength(SUPPORT*) : ";
1212 // Support must be on 1D elements
1214 // Make sure that the MESH class is the same as the MESH class attribut
1215 // in the class Support
1216 MESH* myMesh = Support->getMesh();
1218 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"no compatibility between *this and SUPPORT::_mesh !"));
1220 int dim_space = getSpaceDimension();
1221 medEntityMesh support_entity = Support->getEntity();
1222 bool onAll = Support->isOnAllElements();
1224 int nb_type, length_values;
1225 const medGeometryElement* types;
1227 // !!!! WARNING : use of nodal global numbering in the mesh !!!!
1228 const int* global_connectivity;
1232 // nb_type = myMesh->getNumberOfTypes(support_entity);
1233 // length_values = getNumberOfElements(support_entity,MED_ALL_ELEMENTS);
1234 // types = getTypes(support_entity);
1238 nb_type = Support->getNumberOfTypes();
1239 length_values = Support->getNumberOfElements(MED_ALL_ELEMENTS);
1240 types = Support->getTypes();
1244 FIELD<double>* Length;
1246 Length = new FIELD<double>(Support,1);
1247 // double *length = new double [length_values];
1248 Length->setValueType(MED_REEL64);
1250 //const double *length = Length->getValue(MED_FULL_INTERLACE);
1251 MEDARRAY<double> * length = Length->getvalue();
1253 const double * coord = getCoordinates(MED_FULL_INTERLACE);
1256 for (int i=0;i<nb_type;i++)
1258 medGeometryElement type = types[i] ;
1263 nb_entity_type = getNumberOfElements(support_entity,type);
1264 global_connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,type);
1268 //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support must be on all !"));
1270 nb_entity_type = Support->getNumberOfElements(type);
1272 const int * supp_number = Support->getNumber(type);
1273 const int * connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,MED_ALL_ELEMENTS);
1274 const int * connectivityIndex = getConnectivityIndex(MED_NODAL,support_entity);
1275 int* global_connectivity_tmp = new int[(type%100)*nb_entity_type];
1277 for (int k_type = 0; k_type<nb_entity_type; k_type++) {
1278 for (int j_ent = 0; j_ent<(type%100); j_ent++) {
1279 global_connectivity_tmp[k_type*(type%100)+j_ent] = connectivity[connectivityIndex[supp_number[k_type]-1]+j_ent-1];
1282 global_connectivity = global_connectivity_tmp ;
1287 case MED_SEG2 : case MED_SEG3 :
1289 for (int edge=0;edge<nb_entity_type;edge++)
1291 int edge_index = (type%100)*edge;
1293 int N1 = global_connectivity[edge_index]-1;
1294 int N2 = global_connectivity[edge_index+1]-1;
1296 double x1 = coord[dim_space*N1];
1297 double x2 = coord[dim_space*N2];
1299 double y1 = coord[dim_space*N1+1];
1300 double y2 = coord[dim_space*N2+1];
1302 double z1, z2 ; z1 = 0.0 ; z2 = 0.0 ; if (dim_space==3) {
1303 z1 = coord[dim_space*N1+2]; z2 = coord[dim_space*N2+2];}
1305 xlength = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) +
1306 (z1 - z2)*(z1 - z2));
1308 length->setIJ(index,1,xlength) ;
1314 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get Lengths on it !"));
1318 if (!onAll) delete [] global_connectivity ;
1324 FIELD<double>* MESH::getNormal(const SUPPORT * Support) const throw (MEDEXCEPTION)
1326 const char * LOC = "MESH::getNormal(SUPPORT*) : ";
1329 // Support must be on 2D or 1D elements
1331 // Make sure that the MESH class is the same as the MESH class attribut
1332 // in the class Support
1333 MESH* myMesh = Support->getMesh();
1335 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"no compatibility between *this and SUPPORT::_mesh : pointeur problem !"));
1337 int dim_space = getSpaceDimension();
1338 medEntityMesh support_entity = Support->getEntity();
1339 bool onAll = Support->isOnAllElements();
1341 int nb_type, length_values;
1342 const medGeometryElement* types;
1344 // !!!! WARNING : use of nodal global numbering in the mesh !!!!
1345 const int* global_connectivity;
1349 // nb_type = myMesh->getNumberOfTypes(support_entity);
1350 // length_values = getNumberOfElements(support_entity,MED_ALL_ELEMENTS);
1351 // types = getTypes(support_entity);
1355 nb_type = Support->getNumberOfTypes();
1356 length_values = Support->getNumberOfElements(MED_ALL_ELEMENTS);
1357 types = Support->getTypes();
1362 FIELD<double>* Normal = new FIELD<double>(Support,dim_space);
1363 Normal->setName("NORMAL");
1364 Normal->setDescription("cells or faces normal");
1365 for (int k=1;k<=dim_space;k++) {
1366 Normal->setComponentName(k,"normal");
1367 Normal->setComponentDescription(k,"desc-comp");
1368 Normal->setMEDComponentUnit(k,"unit");
1371 Normal->setValueType(MED_REEL64);
1373 Normal->setIterationNumber(MED_NOPDT);
1374 Normal->setOrderNumber(MED_NONOR);
1375 Normal->setTime(0.0);
1377 double * normal = new double [dim_space*length_values];
1378 //double *normal = Normal->getValue(MED_FULL_INTERLACE);
1380 const double * coord = getCoordinates(MED_FULL_INTERLACE);
1383 for (int i=0;i<nb_type;i++)
1385 medGeometryElement type = types[i] ;
1387 // Make sure we trying to get Normals on
1388 // TRIA3 or TRIA6 or QUAD4 QUAD8 (2D) cells on a 3D mesh
1389 // or on SEG2 or SEG3 (1D) cells on a 2D mesh
1391 if ( (((type==MED_TRIA3) || (type==MED_TRIA6) ||
1392 (type==MED_QUAD4) || (type==MED_QUAD8)) &&
1393 (dim_space != 3)) || (((type==MED_SEG2) || (type==MED_SEG3)) &&
1395 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"no compatibility between *this and SUPPORT::_mesh : dimension problem !"));
1397 double xnormal1, xnormal2, xnormal3 ;
1401 nb_entity_type = getNumberOfElements(support_entity,type);
1402 global_connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,type);
1406 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support must be on all for instance !"));
1407 nb_entity_type = Support->getNumberOfElements(type);
1409 const int * supp_number = Support->getNumber(type);
1410 const int * connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,MED_ALL_ELEMENTS);
1411 const int * connectivityIndex = getConnectivityIndex(MED_NODAL,support_entity);
1412 int * global_connectivity_tmp = new int[(type%100)*nb_entity_type];
1414 for (int k_type = 0; k_type<nb_entity_type; k_type++) {
1415 for (int j_ent = 0; j_ent<(type%100); j_ent++) {
1416 global_connectivity_tmp[k_type*(type%100)+j_ent] = connectivity[connectivityIndex[supp_number[k_type]-1]+j_ent-1];
1420 global_connectivity = global_connectivity_tmp ;
1426 case MED_TRIA3 : case MED_TRIA6 :
1428 for (int tria=0;tria<nb_entity_type;tria++)
1430 int tria_index = (type%100)*tria;
1432 int N1 = global_connectivity[tria_index]-1;
1433 int N2 = global_connectivity[tria_index+1]-1;
1434 int N3 = global_connectivity[tria_index+2]-1;
1436 //double xarea; !! UNUSED VARIABLE !!
1437 double x1 = coord[dim_space*N1];
1438 double x2 = coord[dim_space*N2];
1439 double x3 = coord[dim_space*N3];
1441 double y1 = coord[dim_space*N1+1];
1442 double y2 = coord[dim_space*N2+1];
1443 double y3 = coord[dim_space*N3+1];
1445 double z1 = coord[dim_space*N1+2];
1446 double z2 = coord[dim_space*N2+2];
1447 double z3 = coord[dim_space*N3+2];
1449 xnormal1 = ((y2-y1)*(z3-z1) - (y3-y1)*(z2-z1))/2.0;
1450 xnormal2 = ((x3-x1)*(z2-z1) - (x2-x1)*(z3-z1))/2.0;
1451 xnormal3 = ((x2-x1)*(y3-y1) - (x3-x1)*(y2-y1))/2.0;
1453 normal[3*index] = xnormal1 ;
1454 normal[3*index+1] = xnormal2 ;
1455 normal[3*index+2] = xnormal3 ;
1461 case MED_QUAD4 : case MED_QUAD8 :
1463 for (int quad=0;quad<nb_entity_type;quad++)
1465 int quad_index = (type%100)*quad;
1467 int N1 = global_connectivity[quad_index]-1;
1468 int N2 = global_connectivity[quad_index+1]-1;
1469 int N3 = global_connectivity[quad_index+2]-1;
1470 int N4 = global_connectivity[quad_index+3]-1;
1473 double x1 = coord[dim_space*N1];
1474 double x2 = coord[dim_space*N2];
1475 double x3 = coord[dim_space*N3];
1476 double x4 = coord[dim_space*N4];
1478 double y1 = coord[dim_space*N1+1];
1479 double y2 = coord[dim_space*N2+1];
1480 double y3 = coord[dim_space*N3+1];
1481 double y4 = coord[dim_space*N4+1];
1483 double z1 = coord[dim_space*N1+2];
1484 double z2 = coord[dim_space*N2+2];
1485 double z3 = coord[dim_space*N3+2];
1486 double z4 = coord[dim_space*N4+2];
1488 xnormal1 = (y2-y1)*(z4-z1) - (y4-y1)*(z2-z1);
1489 xnormal2 = (x4-x1)*(z2-z1) - (x2-x1)*(z4-z1);
1490 xnormal3 = (x2-x1)*(y4-y1) - (x4-x1)*(y2-y1);
1491 xarea = sqrt(xnormal1*xnormal1 + xnormal2*xnormal2 +
1494 xnormal1 = xnormal1/xarea;
1495 xnormal2 = xnormal2/xarea;
1496 xnormal3 = xnormal3/xarea;
1498 xarea = (sqrt(((y2-y1)*(z4-z1) - (y4-y1)*(z2-z1))*
1499 ((y2-y1)*(z4-z1) - (y4-y1)*(z2-z1)) +
1500 ((x4-x1)*(z2-z1) - (x2-x1)*(z4-z1))*
1501 ((x4-x1)*(z2-z1) - (x2-x1)*(z4-z1)) +
1502 ((x2-x1)*(y4-y1) - (x4-x1)*(y2-y1))*
1503 ((x2-x1)*(y4-y1) - (x4-x1)*(y2-y1))) +
1504 sqrt(((y4-y3)*(z2-z3) - (y2-y3)*(z4-z3))*
1505 ((y4-y3)*(z2-z3) - (y2-y3)*(z4-z3)) +
1506 ((x2-x3)*(z4-z3) - (x4-x3)*(z2-z3))*
1507 ((x2-x3)*(z4-z3) - (x4-x3)*(z2-z3)) +
1508 ((x4-x3)*(y2-y3) - (x2-x3)*(y4-y3))*
1509 ((x4-x3)*(y2-y3) - (x2-x3)*(y4-y3))))/2.0;
1511 // sqrt(((y3-y2)*(z4-z3) - (y4-y3)*(z3-z2))*
1512 // ((y3-y2)*(z4-z3) - (y4-y3)*(z3-z2)) +
1513 // ((x4-x3)*(z2-z2) - (x3-x2)*(z4-z3))*
1514 // ((x4-x3)*(z4-z2) - (x3-x2)*(z4-z3)) +
1515 // ((x3-x2)*(y4-y3) - (x4-x3)*(y3-y2))*
1516 // ((x3-x2)*(y4-y3) - (x4-x3)*(y3-y2))))/2.0;
1518 xnormal1 = xnormal1*xarea;
1519 xnormal2 = xnormal2*xarea;
1520 xnormal3 = xnormal3*xarea;
1522 normal[3*index] = xnormal1 ;
1523 normal[3*index+1] = xnormal2 ;
1524 normal[3*index+2] = xnormal3 ;
1530 case MED_SEG2 : case MED_SEG3 :
1532 for (int edge=0;edge<nb_entity_type;edge++)
1534 int edge_index = (type%100)*edge;
1536 int N1 = global_connectivity[edge_index]-1;
1537 int N2 = global_connectivity[edge_index+1]-1;
1539 double x1 = coord[dim_space*N1];
1540 double x2 = coord[dim_space*N2];
1542 double y1 = coord[dim_space*N1+1];
1543 double y2 = coord[dim_space*N2+1];
1545 xnormal1 = -(y2-y1);
1548 normal[2*index] = xnormal1 ;
1549 normal[2*index+1] = xnormal2 ;
1556 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get Normals on it !"));
1560 if (!onAll) delete [] global_connectivity ;
1563 Normal->setValue(MED_FULL_INTERLACE,normal);
1571 FIELD<double>* MESH::getBarycenter(const SUPPORT * Support) const throw (MEDEXCEPTION)
1573 const char * LOC = "MESH::getBarycenter(SUPPORT*) : ";
1576 // Make sure that the MESH class is the same as the MESH class attribut
1577 // in the class Support
1578 MESH* myMesh = Support->getMesh();
1580 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"no compatibility between *this and SUPPORT::_mesh !"));
1582 int dim_space = getSpaceDimension();
1583 medEntityMesh support_entity = Support->getEntity();
1584 bool onAll = Support->isOnAllElements();
1586 int nb_type, length_values;
1587 const medGeometryElement* types;
1589 // !!!! WARNING : use of nodal global numbering in the mesh !!!!
1590 const int* global_connectivity;
1594 // nb_type = myMesh->getNumberOfTypes(support_entity);
1595 // length_values = getNumberOfElements(support_entity,MED_ALL_ELEMENTS);
1596 // types = getTypes(support_entity);
1600 nb_type = Support->getNumberOfTypes();
1601 length_values = Support->getNumberOfElements(MED_ALL_ELEMENTS);
1602 types = Support->getTypes();
1606 FIELD<double>* Barycenter;
1608 Barycenter = new FIELD<double>(Support,dim_space);
1609 Barycenter->setName("BARYCENTER");
1610 Barycenter->setDescription("cells or faces barycenter");
1612 for (int k=0;k<dim_space;k++) {
1614 Barycenter->setComponentName(kp1,myMesh->getCoordinatesNames()[k]);
1615 Barycenter->setComponentDescription(kp1,"desc-comp");
1616 Barycenter->setMEDComponentUnit(kp1,myMesh->getCoordinatesUnits()[k]);
1619 Barycenter->setValueType(MED_REEL64);
1621 Barycenter->setIterationNumber(0);
1622 Barycenter->setOrderNumber(0);
1623 Barycenter->setTime(0.0);
1625 double *barycenter = new double [dim_space*length_values];
1626 // double *barycenter = Barycenter->getValue(MED_FULL_INTERLACE);
1628 const double * coord = getCoordinates(MED_FULL_INTERLACE);
1631 for (int i=0;i<nb_type;i++)
1633 medGeometryElement type = types[i] ;
1634 double xbarycenter1, xbarycenter2, xbarycenter3;
1638 nb_entity_type = getNumberOfElements(support_entity,type);
1639 global_connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,type);
1643 // throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support must be on all !"));
1644 nb_entity_type = Support->getNumberOfElements(type);
1646 const int * supp_number = Support->getNumber(type);
1647 const int * connectivity = getConnectivity(MED_FULL_INTERLACE,MED_NODAL,support_entity,MED_ALL_ELEMENTS);
1648 const int * connectivityIndex = getConnectivityIndex(MED_NODAL,support_entity);
1649 int * global_connectivity_tmp = new int[(type%100)*nb_entity_type];
1651 for (int k_type = 0; k_type<nb_entity_type; k_type++) {
1652 for (int j_ent = 0; j_ent<(type%100); j_ent++) {
1653 global_connectivity_tmp[k_type*(type%100)+j_ent] = connectivity[connectivityIndex[supp_number[k_type]-1]+j_ent-1];
1656 global_connectivity = global_connectivity_tmp;
1661 case MED_TETRA4 : case MED_TETRA10 :
1663 for (int tetra =0;tetra<nb_entity_type;tetra++)
1665 int tetra_index = (type%100)*tetra;
1667 int N1 = global_connectivity[tetra_index]-1;
1668 int N2 = global_connectivity[tetra_index+1]-1;
1669 int N3 = global_connectivity[tetra_index+2]-1;
1670 int N4 = global_connectivity[tetra_index+3]-1;
1672 double x1 = coord[dim_space*N1];
1673 double x2 = coord[dim_space*N2];
1674 double x3 = coord[dim_space*N3];
1675 double x4 = coord[dim_space*N4];
1677 double y1 = coord[dim_space*N1+1];
1678 double y2 = coord[dim_space*N2+1];
1679 double y3 = coord[dim_space*N3+1];
1680 double y4 = coord[dim_space*N4+1];
1682 double z1 = coord[dim_space*N1+2];
1683 double z2 = coord[dim_space*N2+2];
1684 double z3 = coord[dim_space*N3+2];
1685 double z4 = coord[dim_space*N4+2];
1687 xbarycenter1 = (x1 + x2 + x3 + x4)/4.0;
1688 xbarycenter2 = (y1 + y2 + y3 + y4)/4.0;
1689 xbarycenter3 = (z1 + z2 + z3 + z4)/4.0;
1690 barycenter[3*index] = xbarycenter1 ;
1691 barycenter[3*index+1] = xbarycenter2 ;
1692 barycenter[3*index+2] = xbarycenter3 ;
1697 case MED_PYRA5 : case MED_PYRA13 :
1699 for (int pyra=0;pyra<nb_entity_type;pyra++)
1701 int pyra_index = (type%100)*pyra;
1703 int N1 = global_connectivity[pyra_index]-1;
1704 int N2 = global_connectivity[pyra_index+1]-1;
1705 int N3 = global_connectivity[pyra_index+2]-1;
1706 int N4 = global_connectivity[pyra_index+3]-1;
1707 int N5 = global_connectivity[pyra_index+4]-1;
1709 double x1 = coord[dim_space*N1];
1710 double x2 = coord[dim_space*N2];
1711 double x3 = coord[dim_space*N3];
1712 double x4 = coord[dim_space*N4];
1713 double x5 = coord[dim_space*N5];
1715 double y1 = coord[dim_space*N1+1];
1716 double y2 = coord[dim_space*N2+1];
1717 double y3 = coord[dim_space*N3+1];
1718 double y4 = coord[dim_space*N4+1];
1719 double y5 = coord[dim_space*N5+1];
1721 double z1 = coord[dim_space*N1+2];
1722 double z2 = coord[dim_space*N2+2];
1723 double z3 = coord[dim_space*N3+2];
1724 double z4 = coord[dim_space*N4+2];
1725 double z5 = coord[dim_space*N5+2];
1727 xbarycenter1 = (x1 + x2 + x3 + x4 + x5)/5.0;
1728 xbarycenter2 = (y1 + y2 + y3 + y4 + y5)/5.0;
1729 xbarycenter3 = (z1 + z2 + z3 + z4 + z5)/5.0;
1730 barycenter[3*index] = xbarycenter1 ;
1731 barycenter[3*index+1] = xbarycenter2 ;
1732 barycenter[3*index+2] = xbarycenter3 ;
1737 case MED_PENTA6 : case MED_PENTA15 :
1739 for (int penta=0;penta<nb_entity_type;penta++)
1741 int penta_index = (type%100)*penta;
1743 int N1 = global_connectivity[penta_index]-1;
1744 int N2 = global_connectivity[penta_index+1]-1;
1745 int N3 = global_connectivity[penta_index+2]-1;
1746 int N4 = global_connectivity[penta_index+3]-1;
1747 int N5 = global_connectivity[penta_index+4]-1;
1748 int N6 = global_connectivity[penta_index+5]-1;
1750 double x1 = coord[dim_space*N1];
1751 double x2 = coord[dim_space*N2];
1752 double x3 = coord[dim_space*N3];
1753 double x4 = coord[dim_space*N4];
1754 double x5 = coord[dim_space*N5];
1755 double x6 = coord[dim_space*N6];
1757 double y1 = coord[dim_space*N1+1];
1758 double y2 = coord[dim_space*N2+1];
1759 double y3 = coord[dim_space*N3+1];
1760 double y4 = coord[dim_space*N4+1];
1761 double y5 = coord[dim_space*N5+1];
1762 double y6 = coord[dim_space*N6+1];
1764 double z1 = coord[dim_space*N1+2];
1765 double z2 = coord[dim_space*N2+2];
1766 double z3 = coord[dim_space*N3+2];
1767 double z4 = coord[dim_space*N4+2];
1768 double z5 = coord[dim_space*N5+2];
1769 double z6 = coord[dim_space*N6+2];
1771 xbarycenter1 = (x1 + x2 + x3 + x4 + x5 + x6)/6.0;
1772 xbarycenter2 = (y1 + y2 + y3 + y4 + y5 + y6)/6.0;
1773 xbarycenter3 = (z1 + z2 + z3 + z4 + z5 + z6)/6.0;
1774 barycenter[3*index] = xbarycenter1 ;
1775 barycenter[3*index+1] = xbarycenter2 ;
1776 barycenter[3*index+2] = xbarycenter3 ;
1781 case MED_HEXA8 : case MED_HEXA20 :
1783 for (int hexa=0;hexa<nb_entity_type;hexa++)
1785 int hexa_index = (type%100)*hexa;
1787 int N1 = global_connectivity[hexa_index]-1;
1788 int N2 = global_connectivity[hexa_index+1]-1;
1789 int N3 = global_connectivity[hexa_index+2]-1;
1790 int N4 = global_connectivity[hexa_index+3]-1;
1791 int N5 = global_connectivity[hexa_index+4]-1;
1792 int N6 = global_connectivity[hexa_index+5]-1;
1793 int N7 = global_connectivity[hexa_index+6]-1;
1794 int N8 = global_connectivity[hexa_index+7]-1;
1796 double x1 = coord[dim_space*N1];
1797 double x2 = coord[dim_space*N2];
1798 double x3 = coord[dim_space*N3];
1799 double x4 = coord[dim_space*N4];
1800 double x5 = coord[dim_space*N5];
1801 double x6 = coord[dim_space*N6];
1802 double x7 = coord[dim_space*N7];
1803 double x8 = coord[dim_space*N8];
1805 double y1 = coord[dim_space*N1+1];
1806 double y2 = coord[dim_space*N2+1];
1807 double y3 = coord[dim_space*N3+1];
1808 double y4 = coord[dim_space*N4+1];
1809 double y5 = coord[dim_space*N5+1];
1810 double y6 = coord[dim_space*N6+1];
1811 double y7 = coord[dim_space*N7+1];
1812 double y8 = coord[dim_space*N8+1];
1814 double z1 = coord[dim_space*N1+2];
1815 double z2 = coord[dim_space*N2+2];
1816 double z3 = coord[dim_space*N3+2];
1817 double z4 = coord[dim_space*N4+2];
1818 double z5 = coord[dim_space*N5+2];
1819 double z6 = coord[dim_space*N6+2];
1820 double z7 = coord[dim_space*N7+2];
1821 double z8 = coord[dim_space*N8+2];
1823 xbarycenter1 = (x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8)/8.0;
1824 xbarycenter2 = (y1 + y2 + y3 + y4 + y5 + y6 + y7 + y8)/8.0;
1825 xbarycenter3 = (z1 + z2 + z3 + z4 + z5 + z6 + z7 + z8)/8.0;
1827 barycenter[3*index] = xbarycenter1 ;
1828 barycenter[3*index+1] = xbarycenter2 ;
1829 barycenter[3*index+2] = xbarycenter3 ;
1835 case MED_TRIA3 : case MED_TRIA6 :
1837 for (int tria=0;tria<nb_entity_type;tria++)
1839 int tria_index = (type%100)*tria;
1841 int N1 = global_connectivity[tria_index]-1;
1842 int N2 = global_connectivity[tria_index+1]-1;
1843 int N3 = global_connectivity[tria_index+2]-1;
1845 double x1 = coord[dim_space*N1];
1846 double x2 = coord[dim_space*N2];
1847 double x3 = coord[dim_space*N3];
1849 double y1 = coord[dim_space*N1+1];
1850 double y2 = coord[dim_space*N2+1];
1851 double y3 = coord[dim_space*N3+1];
1853 xbarycenter1 = (x1 + x2 + x3)/3.0;
1854 xbarycenter2 = (y1 + y2 + y3)/3.0;
1858 barycenter[2*index] = xbarycenter1 ;
1859 barycenter[2*index+1] = xbarycenter2 ;
1864 coord[dim_space*N1+2];
1866 coord[dim_space*N2+2];
1868 coord[dim_space*N3+2];
1870 xbarycenter3 = (z1 + z2 + z3)/3.0;
1872 barycenter[3*index] = xbarycenter1 ;
1873 barycenter[3*index+1] = xbarycenter2 ;
1874 barycenter[3*index+2] = xbarycenter3 ;
1881 case MED_QUAD4 : case MED_QUAD8 :
1883 for (int quad=0;quad<nb_entity_type;quad++)
1885 int quad_index = (type%100)*quad;
1887 int N1 = global_connectivity[quad_index]-1;
1888 int N2 = global_connectivity[quad_index+1]-1;
1889 int N3 = global_connectivity[quad_index+2]-1;
1890 int N4 = global_connectivity[quad_index+3]-1;
1892 double x1 = coord[dim_space*N1];
1893 double x2 = coord[dim_space*N2];
1894 double x3 = coord[dim_space*N3];
1895 double x4 = coord[dim_space*N4];
1897 double y1 = coord[dim_space*N1+1];
1898 double y2 = coord[dim_space*N2+1];
1899 double y3 = coord[dim_space*N3+1];
1900 double y4 = coord[dim_space*N4+1];
1902 xbarycenter1 = (x1 + x2 + x3 + x4)/4.0;
1903 xbarycenter2 = (y1 + y2 + y3 + y4)/4.0;
1907 barycenter[2*index] = xbarycenter1 ;
1908 barycenter[2*index+1] = xbarycenter2 ;
1912 double z1 = coord[dim_space*N1+2];
1913 double z2 = coord[dim_space*N2+2];
1914 double z3 = coord[dim_space*N3+2];
1915 double z4 = coord[dim_space*N4+2];
1917 xbarycenter3 = (z1 + z2 + z3 + z4)/4.0;
1919 barycenter[3*index] = xbarycenter1 ;
1920 barycenter[3*index+1] = xbarycenter2 ;
1921 barycenter[3*index+2] = xbarycenter3 ;
1927 case MED_SEG2 : case MED_SEG3 :
1929 for (int edge=0;edge<nb_entity_type;edge++)
1931 int edge_index = (type%100)*edge;
1933 int N1 = global_connectivity[edge_index]-1;
1934 int N2 = global_connectivity[edge_index+1]-1;
1936 double x1 = coord[dim_space*N1];
1937 double x2 = coord[dim_space*N2];
1939 double y1 = coord[dim_space*N1+1];
1940 double y2 = coord[dim_space*N2+1];
1942 xbarycenter1 = (x1 + x2)/2.0;
1943 xbarycenter2 = (y1 + y2)/2.0;
1947 barycenter[2*index] = xbarycenter1 ;
1948 barycenter[2*index+1] = xbarycenter2 ;
1952 double z1 = coord[dim_space*N1+2];
1953 double z2 = coord[dim_space*N2+2];
1955 xbarycenter3 = (z1 + z2)/2.0;
1957 barycenter[3*index] = xbarycenter1 ;
1958 barycenter[3*index+1] = xbarycenter2 ;
1959 barycenter[3*index+2] = xbarycenter3 ;
1966 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Support to get a barycenter on it (in fact unknown type) !"));
1970 if (!onAll) delete [] global_connectivity ;
1973 Barycenter->setValue(MED_FULL_INTERLACE,barycenter);
1975 delete[] barycenter ;
1982 //=======================================================================
1983 //function : checkGridFillCoords
1984 //purpose : if this->_isAGrid, assure that _coordinate is filled
1985 //=======================================================================
1987 // inline void MESH::checkGridFillCoords() const
1990 // ((GRID *) this)->fillCoordinates();
1993 //=======================================================================
1994 //function : checkGridFillConnectivity
1995 //purpose : if this->_isAGrid, assure that _connectivity is filled
1996 //=======================================================================
1998 // inline void MESH::checkGridFillConnectivity() const
2001 // ((GRID *) this)->fillConnectivity();
2004 bool MESH::isEmpty() const
2006 bool notempty = _name != "NOT DEFINED" || _coordinate != NULL || _connectivity != NULL ||
2007 _spaceDimension !=MED_INVALID || _meshDimension !=MED_INVALID ||
2008 _numberOfNodes !=MED_INVALID || _groupNode.size() != 0 ||
2009 _familyNode.size() != 0 || _groupCell.size() != 0 ||
2010 _familyCell.size() != 0 || _groupFace.size() != 0 ||
2011 _familyFace.size() != 0 || _groupEdge.size() != 0 ||
2012 _familyEdge.size() != 0 || _isAGrid != 0 ;
2016 void MESH::read(int index)
2018 const char * LOC = "MESH::read(int index=0) : ";
2021 if (_drivers[index]) {
2022 _drivers[index]->open();
2023 _drivers[index]->read();
2024 _drivers[index]->close();
2027 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
2028 << "The index given is invalid, index must be between 0 and |"
2033 // ((GRID *) this)->fillMeshAfterRead();
2037 //=======================================================================
2038 //function : getSkin
2040 //=======================================================================
2042 SUPPORT * MESH::getSkin(const SUPPORT * Support3D) throw (MEDEXCEPTION)
2044 const char * LOC = "MESH::getSkin : " ;
2047 if (this != Support3D->getMesh())
2048 throw MEDEXCEPTION(STRING(LOC) << "no compatibility between *this and SUPPORT::_mesh !");
2049 if (_meshDimension != 3 || Support3D->getEntity() != MED_CELL)
2050 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Defined on 3D cells only"));
2052 // well, all rigth !
2053 SUPPORT * mySupport = new SUPPORT(this,"Skin",MED_FACE);
2054 mySupport->setAll(false);
2056 list<int> myElementsList ;
2059 calculateConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, MED_CELL);
2060 if (Support3D->isOnAllElements())
2062 int * myConnectivityValue = const_cast <int*> (getReverseConnectivity(MED_DESCENDING)) ;
2063 int nbFaces = getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS);
2064 for (i=0, j=1 ; j<=nbFaces; ++j, i += 2)
2066 int cellNb1 = myConnectivityValue [i];
2067 int cellNb2 = myConnectivityValue [i+1];
2068 //MESSAGE( " FACE # " << j << " -- Cells: " << cellNb1 << ", " << cellNb2 );
2069 if ((cellNb1 == 0 || cellNb2 == 0) && (cellNb1 + cellNb2 > 0))
2071 myElementsList.push_back( j ) ;
2078 map<int,int> FaceNbEncounterNb;
2080 int * myConnectivityValue = const_cast <int *>
2081 (getConnectivity(MED_FULL_INTERLACE, MED_DESCENDING,
2082 MED_CELL, MED_ALL_ELEMENTS));
2083 int * myConnectivityIndex = const_cast <int *> (getConnectivityIndex(MED_DESCENDING, MED_CELL));
2084 int * myCellNbs = const_cast <int *> (Support3D->getnumber()->getValue());
2085 int nbCells = Support3D->getnumber()->getLength();
2086 for (i=0; i<nbCells; ++i)
2088 int cellNb = myCellNbs [ i ];
2089 int faceFirst = myConnectivityIndex[ cellNb-1 ];
2090 int faceLast = myConnectivityIndex[ cellNb ];
2091 for (j = faceFirst; j < faceLast; ++j)
2093 int faceNb = abs( myConnectivityValue [ j-1 ] );
2094 //MESSAGE( "Cell # " << i << " -- Face: " << faceNb);
2095 if (FaceNbEncounterNb.find( faceNb ) == FaceNbEncounterNb.end())
2096 FaceNbEncounterNb[ faceNb ] = 1;
2098 FaceNbEncounterNb[ faceNb ] ++;
2101 map<int,int>::iterator FaceNbEncounterNbItr;
2102 for (FaceNbEncounterNbItr = FaceNbEncounterNb.begin();
2103 FaceNbEncounterNbItr != FaceNbEncounterNb.end();
2104 FaceNbEncounterNbItr ++)
2105 if ((*FaceNbEncounterNbItr).second == 1)
2107 myElementsList.push_back( (*FaceNbEncounterNbItr).first) ;
2111 // Well, we must know how many geometric type we have found
2112 int * myListArray = new int[size] ;
2114 list<int>::iterator myElementsListIt ;
2115 for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
2116 myListArray[id]=(*myElementsListIt) ;
2120 int numberOfGeometricType ;
2121 medGeometryElement* geometricType ;
2122 int * numberOfGaussPoint ;
2123 int * geometricTypeNumber ;
2124 int * numberOfEntities ;
2125 // MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY() ;
2126 int * mySkyLineArrayIndex ;
2128 int numberOfType = getNumberOfTypes(MED_FACE) ;
2129 if (numberOfType == 1) { // wonderfull : it's easy !
2130 numberOfGeometricType = 1 ;
2131 geometricType = new medGeometryElement[1] ;
2132 const medGeometryElement * allType = getTypes(MED_FACE);
2133 geometricType[0] = allType[0] ;
2134 numberOfGaussPoint = new int[1] ;
2135 numberOfGaussPoint[0] = 1 ;
2136 geometricTypeNumber = new int[1] ; // not use, but initialized to nothing
2137 geometricTypeNumber[0] = 0 ;
2138 numberOfEntities = new int[1] ;
2139 numberOfEntities[0] = size ;
2140 mySkyLineArrayIndex = new int[2] ;
2141 mySkyLineArrayIndex[0]=1 ;
2142 mySkyLineArrayIndex[1]=1+size ;
2145 map<medGeometryElement,int> theType ;
2146 for (myElementsListIt=myElementsList.begin();myElementsListIt!=myElementsList.end();myElementsListIt++) {
2147 medGeometryElement myType = getElementType(MED_FACE,*myElementsListIt) ;
2148 if (theType.find(myType) != theType.end() )
2149 theType[myType]+=1 ;
2153 numberOfGeometricType = theType.size() ;
2154 geometricType = new medGeometryElement[numberOfGeometricType] ;
2155 //const medGeometryElement * allType = getTypes(MED_FACE); !! UNUSED VARIABLE !!
2156 numberOfGaussPoint = new int[numberOfGeometricType] ;
2157 geometricTypeNumber = new int[numberOfGeometricType] ; // not use, but initialized to nothing
2158 numberOfEntities = new int[numberOfGeometricType] ;
2159 mySkyLineArrayIndex = new int[numberOfGeometricType+1] ;
2161 mySkyLineArrayIndex[0]=1 ;
2162 map<medGeometryElement,int>::iterator theTypeIt ;
2163 for (theTypeIt=theType.begin();theTypeIt!=theType.end();theTypeIt++) {
2164 geometricType[index] = (*theTypeIt).first ;
2165 numberOfGaussPoint[index] = 1 ;
2166 geometricTypeNumber[index] = 0 ;
2167 numberOfEntities[index] = (*theTypeIt).second ;
2168 mySkyLineArrayIndex[index+1]=mySkyLineArrayIndex[index]+numberOfEntities[index] ;
2172 // mySkyLineArray->setMEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray) ;
2173 MEDSKYLINEARRAY * mySkyLineArray = new MEDSKYLINEARRAY(numberOfGeometricType,size,mySkyLineArrayIndex,myListArray) ;
2175 mySupport->setNumberOfGeometricType(numberOfGeometricType) ;
2176 mySupport->setGeometricType(geometricType) ;
2177 mySupport->setNumberOfGaussPoint(numberOfGaussPoint) ;
2178 // mySupport->setGeometricTypeNumber(geometricTypeNumber) ;
2179 mySupport->setNumberOfElements(numberOfEntities) ;
2180 mySupport->setTotalNumberOfElements(size) ;
2181 mySupport->setNumber(mySkyLineArray) ;
2183 delete[] numberOfEntities;
2184 delete[] geometricTypeNumber;
2185 delete[] numberOfGaussPoint;
2186 delete[] geometricType;
2187 delete[] mySkyLineArrayIndex;
2188 delete[] myListArray;
2189 // delete mySkyLineArray;
2197 return a SUPPORT pointer on the union of all SUPPORTs in Supports.
2198 You should delete this pointer after use to avoid memory leaks.
2200 SUPPORT * MESH::mergeSupports(const vector<SUPPORT *> Supports) const throw (MEDEXCEPTION)
2202 const char * LOC = "MESH:::mergeSupports(const vector<SUPPORT *> ) : " ;
2205 SUPPORT * returnedSupport;
2206 string returnedSupportName;
2207 string returnedSupportDescription;
2208 char * returnedSupportNameChar;
2209 char * returnedSupportDescriptionChar;
2210 int size = Supports.size();
2214 MESSAGE(LOC <<" there is only one SUPPORT in the argument list, the method return a copy of this object !");
2215 SUPPORT * obj = const_cast <SUPPORT *> (Supports[0]);
2217 returnedSupport = new SUPPORT(*obj);
2219 int lenName = strlen((Supports[0]->getName()).c_str()) + 8 + 1;
2220 int lenDescription = strlen((Supports[0]->getDescription()).c_str()) + 8 + 1;
2222 returnedSupportNameChar = new char[lenName];
2223 returnedSupportDescriptionChar = new char[lenDescription];
2225 returnedSupportNameChar = strcpy(returnedSupportNameChar,"Copy of ");
2226 returnedSupportNameChar = strcat(returnedSupportNameChar,(Supports[0]->getName()).c_str());
2227 returnedSupportDescriptionChar = strcpy(returnedSupportDescriptionChar,"Copy of ");
2228 returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar,
2229 (Supports[0]->getDescription()).c_str());
2231 returnedSupportName = string(returnedSupportNameChar);
2232 returnedSupportDescription = string(returnedSupportDescriptionChar);
2234 returnedSupport->setName(returnedSupportName);
2235 returnedSupport->setDescription(returnedSupportDescription);
2237 delete [] returnedSupportNameChar;
2238 delete [] returnedSupportDescriptionChar;
2242 SUPPORT * obj = const_cast <SUPPORT *> (Supports[0]);
2243 returnedSupport = new SUPPORT(*obj);
2245 int lenName = strlen((Supports[0]->getName()).c_str()) + 9 + 1;
2246 int lenDescription = strlen((Supports[0]->getDescription()).c_str()) + 9 + 1;
2248 for(int i = 1;i<size;i++)
2250 obj = const_cast <SUPPORT *> (Supports[i]);
2251 returnedSupport->blending(obj);
2255 lenName = lenName + 5 + strlen((Supports[i]->getName()).c_str());
2256 lenDescription = lenDescription + 5 +
2257 strlen((Supports[i]->getDescription()).c_str());
2261 lenName = lenName + 2 + strlen((Supports[i]->getName()).c_str());
2262 lenDescription = lenDescription + 2 +
2263 strlen((Supports[i]->getDescription()).c_str());
2267 returnedSupportNameChar = new char[lenName];
2268 returnedSupportDescriptionChar = new char[lenDescription];
2270 returnedSupportNameChar = strcpy(returnedSupportNameChar,"Merge of ");
2271 returnedSupportDescriptionChar = strcpy(returnedSupportDescriptionChar,"Merge of ");
2273 returnedSupportNameChar = strcat(returnedSupportNameChar,(Supports[0]->getName()).c_str());
2274 returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar,
2275 (Supports[0]->getDescription()).c_str());
2277 for(int i = 1;i<size;i++)
2281 returnedSupportNameChar = strcat(returnedSupportNameChar," and ");
2282 returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar," and ");
2284 returnedSupportNameChar = strcat(returnedSupportNameChar,
2285 (Supports[i]->getName()).c_str());
2286 returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar,
2287 (Supports[i]->getDescription()).c_str());
2291 returnedSupportNameChar = strcat(returnedSupportNameChar,", ");
2292 returnedSupportNameChar = strcat(returnedSupportNameChar,
2293 (Supports[i]->getName()).c_str());
2295 returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar,", ");
2296 returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar,
2297 (Supports[i]->getDescription()).c_str());
2301 returnedSupportName = string(returnedSupportNameChar);
2302 returnedSupport->setName(returnedSupportName);
2304 returnedSupportDescription = string(returnedSupportDescriptionChar);
2305 returnedSupport->setDescription(returnedSupportDescription);
2307 delete [] returnedSupportNameChar;
2308 delete [] returnedSupportDescriptionChar;
2312 return returnedSupport;
2316 return a SUPPORT pointer on the intersection of all SUPPORTs in Supports.
2317 The (SUPPORT *) NULL pointer is returned if the intersection is empty.
2318 You should delete this pointer after use to avois memory leaks.
2320 SUPPORT * MESH::intersectSupports(const vector<SUPPORT *> Supports) const throw (MEDEXCEPTION)
2322 const char * LOC = "MESH:::intersectSupports(const vector<SUPPORT *> ) : " ;
2325 SUPPORT * returnedSupport;
2326 string returnedSupportName;
2327 string returnedSupportDescription;
2328 char * returnedSupportNameChar;
2329 char * returnedSupportDescriptionChar;
2330 int size = Supports.size();
2334 MESSAGE(LOC <<" there is only one SUPPORT in the argument list, the method return a copy of this object !");
2335 SUPPORT * obj = const_cast <SUPPORT *> (Supports[0]);
2337 returnedSupport = new SUPPORT(*obj);
2339 int lenName = strlen((Supports[0]->getName()).c_str()) + 8 + 1;
2340 int lenDescription = strlen((Supports[0]->getDescription()).c_str()) + 8 + 1;
2342 returnedSupportNameChar = new char[lenName];
2343 returnedSupportDescriptionChar = new char[lenDescription];
2345 returnedSupportNameChar = strcpy(returnedSupportNameChar,"Copy of ");
2346 returnedSupportNameChar = strcat(returnedSupportNameChar,(Supports[0]->getName()).c_str());
2347 returnedSupportDescriptionChar = strcpy(returnedSupportDescriptionChar,"Copy of ");
2348 returnedSupportDescriptionChar = strcat(returnedSupportDescriptionChar,
2349 (Supports[0]->getDescription()).c_str());
2351 returnedSupportName = string(returnedSupportNameChar);
2352 returnedSupportDescription = string(returnedSupportDescriptionChar);
2354 returnedSupport->setName(returnedSupportName);
2355 returnedSupport->setDescription(returnedSupportDescription);
2357 delete [] returnedSupportNameChar;
2358 delete [] returnedSupportDescriptionChar;
2362 SUPPORT * obj = const_cast <SUPPORT *> (Supports[0]);
2363 returnedSupport = new SUPPORT(*obj);
2365 int lenName = strlen((Supports[0]->getName()).c_str()) + 16 + 1;
2366 int lenDescription = strlen((Supports[0]->getDescription()).c_str()) + 16 + 1;
2368 for(int i = 1;i<size;i++)
2370 obj = const_cast <SUPPORT *> (Supports[i]);
2371 returnedSupport->intersecting(obj);
2375 lenName = lenName + 5 + strlen((Supports[i]->getName()).c_str());
2376 lenDescription = lenDescription + 5 +
2377 strlen((Supports[i]->getDescription()).c_str());
2381 lenName = lenName + 2 + strlen((Supports[i]->getName()).c_str());
2382 lenDescription = lenDescription + 2 +
2383 strlen((Supports[i]->getDescription()).c_str());
2387 if(returnedSupport != (SUPPORT *) NULL)
2389 returnedSupportNameChar = new char[lenName];
2390 returnedSupportDescriptionChar = new char[lenDescription];
2392 returnedSupportNameChar = strcpy(returnedSupportNameChar,
2393 "Intersection of ");
2394 returnedSupportDescriptionChar =
2395 strcpy(returnedSupportDescriptionChar,"Intersection of ");
2397 returnedSupportNameChar = strcat(returnedSupportNameChar,
2398 (Supports[0]->getName()).c_str());
2399 returnedSupportDescriptionChar =
2400 strcat(returnedSupportDescriptionChar,
2401 (Supports[0]->getDescription()).c_str());
2403 for(int i = 1;i<size;i++)
2407 returnedSupportNameChar = strcat(returnedSupportNameChar,
2409 returnedSupportDescriptionChar =
2410 strcat(returnedSupportDescriptionChar," and ");
2412 returnedSupportNameChar =
2413 strcat(returnedSupportNameChar,
2414 (Supports[i]->getName()).c_str());
2415 returnedSupportDescriptionChar =
2416 strcat(returnedSupportDescriptionChar,
2417 (Supports[i]->getDescription()).c_str());
2421 returnedSupportNameChar = strcat(returnedSupportNameChar,
2423 returnedSupportNameChar =
2424 strcat(returnedSupportNameChar,
2425 (Supports[i]->getName()).c_str());
2427 returnedSupportDescriptionChar =
2428 strcat(returnedSupportDescriptionChar,", ");
2429 returnedSupportDescriptionChar =
2430 strcat(returnedSupportDescriptionChar,
2431 (Supports[i]->getDescription()).c_str());
2435 returnedSupportName = string(returnedSupportNameChar);
2436 returnedSupport->setName(returnedSupportName);
2438 returnedSupportDescription = string(returnedSupportDescriptionChar);
2439 returnedSupport->setDescription(returnedSupportDescription);
2441 delete [] returnedSupportNameChar;
2442 delete [] returnedSupportDescriptionChar;
2447 return returnedSupport;
2451 // internal helper type
2455 std::vector<int> groups;
2456 MED_EN::medGeometryElement geometricType;
2459 // Create families from groups
2460 void MESH::createFamilies()
2462 int nbFam=0; // count the families we create, used as identifier ???????????
2464 int idFamNode = 0; // identifier for node families
2465 int idFamElement = 0; // identifier for cell, face or edge families
2467 // Main loop on mesh's entities
2468 for (medEntityMesh entity=MED_CELL; entity!=MED_ALL_ENTITIES; ++entity)
2470 int numberofgroups = getNumberOfGroups(entity);
2472 continue; // no groups for this entity
2474 vector< vector<FAMILY*> > whichFamilyInGroup(numberofgroups); // this container is used to update groups at the end
2476 // make myFamilies points to the member corresponding to entity
2477 vector<FAMILY*>* myFamilies;
2481 myFamilies = & _familyCell;
2484 myFamilies = & _familyFace;
2487 myFamilies = & _familyEdge;
2490 myFamilies = & _familyNode;
2494 vector<GROUP*> myGroups=getGroups(entity); // get a copy of the groups ptr for the entity
2495 // get a copy of the (old) family ptrs before clearing
2496 vector<FAMILY*> myOldFamilies=getFamilies(entity);
2497 myFamilies->clear();
2500 // 1 - Create a vector containing for each cell (of the entity) an information structure
2501 // giving geometric type and the groups it belong to
2503 med_int numberOfTypes=getNumberOfTypes(entity);
2504 const int * index=getGlobalNumberingIndex(entity);
2505 const medGeometryElement* geometricTypes=_connectivity->getGeometricTypes(entity); // pb avec entity=MED_NODE???
2506 med_int numberOfCells=index[numberOfTypes]-1; // total number of cells for that entity
2507 SCRUTE(numberOfTypes);
2508 SCRUTE(numberOfCells);
2509 vector< _cell > tab_cell(numberOfCells);
2510 for(med_int t=0; t!=numberOfTypes; ++t)
2511 for(int n=index[t]-1; n!=index[t+1]-1; ++n)
2512 tab_cell[n].geometricType=geometricTypes[t];
2515 // 2 - Scan cells in groups and update in tab_cell the container of groups a cell belong to
2517 for (unsigned g=0; g!=myGroups.size(); ++g)
2519 // scan cells that belongs to the group
2520 const int* groupCells=myGroups[g]->getnumber()->getValue();
2521 int nbCells=myGroups[g]->getnumber()->getLength();
2522 for(int c=0; c!=nbCells; ++c)
2523 tab_cell[groupCells[c]-1].groups.push_back(g);
2527 // 3 - Scan the cells vector, genarate family name, and create a map associating the family names
2528 // whith the vector of contained cells
2530 map< string,vector<int> > tab_families;
2531 map< string,vector<int> >::iterator fam;
2532 for(int n=0; n!=numberOfCells; ++n)
2534 ostringstream key; // to generate the name of the family
2536 if(tab_cell[n].groups.empty()) // this cell don't belong to any group
2537 key << "_NONE" << entity;
2539 for(vector<int>::const_iterator it=tab_cell[n].groups.begin(); it!=tab_cell[n].groups.end(); ++it)
2541 string groupName=myGroups[*it]->getName();
2542 if(groupName.empty())
2545 key << "_" << groupName;
2548 tab_families[key.str()].push_back(n+1); // fill the vector of contained cells associated whith the family
2549 /* fam = tab_families.find(key.str());
2550 if( fam != tab_families.end())
2551 fam->second.push_back(n+1); // +1 : convention Fortran de MED
2554 vector<int> newfamily;
2555 newfamily.push_back(n+1); // +1 : convention Fortran de MED
2556 tab_families.insert(make_pair(key.str(),newfamily));
2561 // 4 - Scan the family map, create MED Families, check if it already exist.
2563 for( fam=tab_families.begin(); fam!=tab_families.end(); ++fam)
2565 vector<medGeometryElement> tab_types_geometriques;
2566 medGeometryElement geometrictype=MED_NONE;
2567 vector<int> tab_index_types_geometriques;
2568 vector<int> tab_nombres_elements;
2570 // scan family cells and fill the tab that are needed by the create a MED FAMILY
2571 for( int i=0; i!=fam->second.size(); ++i)
2573 int ncell=fam->second[i]-1;
2574 if(tab_cell[ncell].geometricType != geometrictype)
2576 // new geometric type -> we store it and complete index tabs
2577 if(!tab_index_types_geometriques.empty())
2578 tab_nombres_elements.push_back(i+1-tab_index_types_geometriques.back());
2579 tab_types_geometriques.push_back( (geometrictype=tab_cell[ncell].geometricType));
2580 tab_index_types_geometriques.push_back(i+1);
2583 // store and complete index tabs for the last geometric type
2584 tab_nombres_elements.push_back(fam->second.size()+1-tab_index_types_geometriques.back());
2585 tab_index_types_geometriques.push_back(fam->second.size()+1);
2587 // create a empty MED FAMILY and fill it with the tabs we constructed
2588 FAMILY* newFam = new FAMILY();
2589 newFam->setTotalNumberOfElements(fam->second.size());
2590 newFam->setName(fam->first);
2591 newFam->setMesh(this);
2592 newFam->setNumberOfGeometricType(tab_types_geometriques.size());
2593 newFam->setGeometricType(&tab_types_geometriques[0]); // we know the tab is not empy
2594 newFam->setNumberOfElements(&tab_nombres_elements[0]);
2595 newFam->setNumber(&tab_index_types_geometriques[0],&fam->second[0]);
2596 newFam->setEntity(entity);
2597 newFam->setAll(false);
2609 idFam = -idFamElement;
2613 idFam = -idFamElement;
2617 idFam = -idFamElement;
2621 newFam->setIdentifier(idFam);
2623 // Update links between families and groups
2625 int ncell1=fam->second[0]-1; // number of first cell in family
2626 int numberOfGroups=tab_cell[ncell1].groups.size(); // number of groups in the family
2629 newFam->setNumberOfGroups(numberOfGroups);
2630 string * groupNames=new string[numberOfGroups];
2632 // iterate on the groups the family belongs to
2633 vector<int>::const_iterator it=tab_cell[ncell1].groups.begin();
2634 for(int ng=0 ; it!=tab_cell[ncell1].groups.end(); ++it, ++ng)
2636 whichFamilyInGroup[*it].push_back(newFam);
2637 groupNames[ng]=myGroups[*it]->getName();
2639 newFam->setGroupsNames(groupNames);
2642 int sizeOfFamVect = myFamilies->size();
2644 MESSAGE(" MESH::createFamilies() entity " << entity << " size " << sizeOfFamVect);
2646 myFamilies->push_back(newFam);
2649 // delete old families
2650 for (int i=0;i<myOldFamilies.size();i++)
2651 delete myOldFamilies[i] ;
2653 // update references in groups
2654 for (int i=0;i<myGroups.size();i++)
2656 myGroups[i]->setNumberOfFamilies(whichFamilyInGroup[i].size());
2657 myGroups[i]->setFamilies(whichFamilyInGroup[i]);
2660 // re-scan the cells vector, and fill the family vector with cells.
2661 // creation of support, check if it already exist.