2 // File : MEDMEM_Grid.hxx
3 // Created : Wed Dec 18 08:35:26 2002
4 // Descr : class containing structured mesh data
6 // Author : Edward AGAPOV (eap)
7 // Project : SALOME Pro
9 // Copyright : Open CASCADE
13 #include "MEDMEM_Grid.hxx"
14 #include "MEDMEM_CellModel.hxx"
15 #include "MEDMEM_SkyLineArray.hxx"
16 using namespace MEDMEM;
18 //=======================================================================
20 //purpose : empty constructor
21 //=======================================================================
25 MESSAGE("A GRID CREATED");
28 //=======================================================================
30 //purpose : empty constructor
31 //=======================================================================
33 // GRID::GRID(const med_grid_type type)
37 // MESSAGE("A TYPED GRID CREATED");
40 GRID::GRID(const med_type_grille type)
44 MESSAGE("A TYPED GRID CREATED");
47 //=======================================================================
49 //purpose : copying constructor
50 //=======================================================================
52 GRID::GRID(const GRID& otherGrid) {
56 //=======================================================================
58 //purpose : destructor
59 //=======================================================================
62 MESSAGE("GRID::~GRID() : Destroying the Grid");
63 if ( _iArray != (double* ) NULL) delete [] _iArray;
64 if ( _jArray != (double* ) NULL) delete [] _jArray;
65 if ( _kArray != (double* ) NULL) delete [] _kArray;
68 //=======================================================================
71 //=======================================================================
75 // _gridType = MED_CARTESIAN;
76 _gridType = MED_GRILLE_CARTESIENNE;
78 _iArray = _jArray = _kArray = (double* ) NULL;
79 _iArrayLength = _jArrayLength = _kArrayLength = 0;
81 _is_coordinates_filled = false;
82 _is_connectivity_filled = false;
89 //=======================================================================
92 //=======================================================================
94 GRID & GRID::operator=(const GRID & otherGrid)
98 MESH::operator=(otherGrid);
102 //=======================================================================
104 //purpose : Create a GRID object using a MESH driver of type
105 // (MED_DRIVER, ....) associated with file <fileName>.
106 //=======================================================================
108 GRID::GRID(driverTypes driverType, const string & fileName,
109 const string & driverName) : MESH(driverType, fileName, driverName)
111 const char * LOC ="GRID::GRID(driverTypes , const string & , const string &) : ";
118 // MESH(driverType,fileName,driverName);
120 // current = addDriver(driverType,fileName,driverName);
122 // switch(_drivers[current]->getAccessMode() ) {
124 // MESSAGE(LOC << "driverType must have a MED_RDWR accessMode");
125 // rmDriver(current);
129 // _drivers[current]->open();
130 // _drivers[current]->read();
131 // _drivers[current]->close();
133 // // fill some fields of MESH
134 // fillMeshAfterRead();
141 //=======================================================================
142 //function : fillMeshAfterRead
144 //=======================================================================
146 void GRID::fillMeshAfterRead()
148 // fill not only MESH (:-)
149 _is_coordinates_filled = false;
150 _is_connectivity_filled = false;
152 // if (_gridType == MED_BODY_FITTED)
153 if (_gridType == MED_GRILLE_STANDARD)
155 _is_coordinates_filled = true;
157 // nb of nodes in each direction is not known, set anything
158 // in order to be able to work anyhow
159 // INFOS("GRID::fillMeshAfterRead(): This stub must be removed");
160 // switch (_spaceDimension) {
162 // _iArrayLength = _numberOfNodes;
163 // _jArrayLength = 0;
164 // _kArrayLength = 0;
167 // _iArrayLength = 2;
168 // _jArrayLength = _numberOfNodes / _iArrayLength;
169 // _kArrayLength = 0;
172 // _iArrayLength = 2;
173 // _jArrayLength = _numberOfNodes / _iArrayLength / 2;
174 // _kArrayLength = _numberOfNodes / _iArrayLength / _jArrayLength;
176 //cout << "ARRAY LENGTHS: " << _iArrayLength << " " << _jArrayLength
177 // << " " << _kArrayLength << endl;
180 // int NbNodes = _iArrayLength;
181 // if (_jArrayLength)
182 // NbNodes *= _jArrayLength;
183 // if (_kArrayLength)
184 // NbNodes *= _kArrayLength;
185 // MESH::_numberOfNodes = NbNodes;
188 MESH::_meshDimension = MESH::_spaceDimension;
191 //=======================================================================
192 //function : fillCoordinates
194 //=======================================================================
196 void GRID::fillCoordinates() const
198 if (_is_coordinates_filled)
200 MESSAGE("GRID::fillCoordinates(): Already filled");
204 const char * LOC ="GRID::fillCoordinates()";
208 const_cast <double *> ( _coordinate->getCoordinates(MED_FULL_INTERLACE) );
210 bool hasJ = _jArrayLength, hasK = _kArrayLength;
211 int J = hasJ ? _jArrayLength : 1;
212 int K = hasK ? _kArrayLength : 1;
213 //int nb, !! UNUSED VARIABLE !!
215 for (k=0; k < K; ++k) {
216 for (j=0; j < J; ++j) {
217 for (i=0; i < _iArrayLength; ++i) {
219 * myCoord = _iArray[ i ];
224 * myCoord = _jArray[ j ];
229 * myCoord = _jArray[ k ];
237 (const_cast <GRID *> (this))->_is_coordinates_filled = true;
241 //=======================================================================
242 //function : makeConnectivity
244 //=======================================================================
246 CONNECTIVITY * GRID::makeConnectivity (const medEntityMesh Entity,
247 const medGeometryElement Geometry,
248 const int NbEntities,
253 CONNECTIVITY * Connectivity = new CONNECTIVITY(Entity) ;
254 Connectivity->_numberOfNodes = NbNodes ;
255 Connectivity->_entityDimension = Geometry/100 ;
257 int numberOfGeometricType = 1;
258 Connectivity->_numberOfTypes = numberOfGeometricType;
260 Connectivity->_count = new int [numberOfGeometricType + 1] ;
261 Connectivity->_count[0] = 1;
262 Connectivity->_count[1] = 1 + NbEntities;
264 Connectivity->_type = new CELLMODEL [numberOfGeometricType];
265 Connectivity->_type[0] = CELLMODEL( Geometry ) ;
267 Connectivity->_geometricTypes = new medGeometryElement [ numberOfGeometricType ];
268 Connectivity->_geometricTypes[0] = Geometry;
270 // Connectivity->_nodal = new MEDSKYLINEARRAY() ;
271 int * skyLineArrayIndex = new int [NbEntities + 1];
272 int i, j, nbEntityNodes = Connectivity->_type[0].getNumberOfNodes();
273 for (i=0, j=1; i <= NbEntities; ++i, j += nbEntityNodes)
274 skyLineArrayIndex [ i ] = j;
276 // Connectivity->_nodal->setMEDSKYLINEARRAY (NbEntities, NbNodes,
277 //skyLineArrayIndex, NodeNumbers);
279 Connectivity->_nodal = new MEDSKYLINEARRAY (NbEntities, NbNodes,
280 skyLineArrayIndex, NodeNumbers);
282 delete [] skyLineArrayIndex;
284 // test connectivity right away
285 // for (med_int j = 0; j < numberOfGeometricType; j++)
287 // int node_number = Connectivity->_type[j].getNumberOfNodes();
288 // for (med_int k = Connectivity->_count[j]; k < Connectivity->_count[j+1]; k++)
289 // for (med_int local_node_number = 1 ; local_node_number < node_number+1; local_node_number++)
291 // cout << "MEDSKYLINEARRAY::getIJ(" << k << ", " << local_node_number << endl;
292 // med_int global_node = Connectivity->_nodal->getIJ(k,local_node_number) ;
293 // cout << "...= " << global_node << endl;
300 //=======================================================================
301 //function : fillConnectivity
302 //purpose : fill _coordinates and _connectivity of MESH if not yet done
303 //=======================================================================
305 void GRID::fillConnectivity() const
307 if (_is_connectivity_filled)
309 MESSAGE("GRID::fillConnectivity(): Already filled");
313 const char * LOC = "GRID::fillConnectivity() ";
316 int nbCells, nbFaces, nbEdges;
317 int nbCNodes, nbFNodes, nbENodes;
318 int indexC, indexF, indexE;
319 int * nodeCNumbers, * nodeFNumbers, * nodeENumbers;
320 // about descending connectivity
321 int nbSub, nbRevSub, indexSub, indexRevSub, * subNumbers, * subRevNumbers;
323 bool hasFaces = _kArrayLength, hasEdges = _jArrayLength;
325 int iLenMin1 = _iArrayLength-1, jLenMin1 = _jArrayLength-1;
326 int kLenMin1 = _kArrayLength-1, ijLenMin1 = iLenMin1 * jLenMin1;
327 if (!hasEdges) jLenMin1 = 1;
328 if (!hasFaces) kLenMin1 = 1;
330 // nb of cells and of their connectivity nodes
332 nbCells = iLenMin1 * jLenMin1 * kLenMin1;
333 nbCNodes = nbCells * 2 * (hasEdges ? 2 : 1) * (hasFaces ? 2 : 1);
334 nodeCNumbers = new int [ nbCNodes ];
336 // nb of faces and of their connectivity nodes
339 nbFaces = _iArrayLength * jLenMin1 * kLenMin1;
340 nbFaces += _jArrayLength * kLenMin1 * iLenMin1;
341 nbFaces += _kArrayLength * iLenMin1 * jLenMin1;
342 nbFNodes = nbFaces * 4;
343 nodeFNumbers = new int [ nbFNodes ];
345 nbFaces = nbFNodes = 0;
347 // nb of edges and of their connectivity nodes
350 if (_kArrayLength) { // 3d grid
351 nbEdges = iLenMin1 * _jArrayLength * _kArrayLength;
352 nbEdges += jLenMin1 * _kArrayLength * _iArrayLength;
353 nbEdges += kLenMin1 * _iArrayLength * _jArrayLength;
355 else if (_jArrayLength) { // 2d
356 nbEdges = iLenMin1 * _jArrayLength;
357 nbEdges += jLenMin1 * _iArrayLength;
359 nbENodes = nbEdges * 2;
360 nodeENumbers = new int [ nbENodes ];
362 nbEdges = nbENodes = 0;
364 // nb of descending connectivity Elements
369 nbRevSub = nbFaces * 2;
374 nbRevSub = nbEdges * 2;
376 subNumbers = new int [ nbSub ];
377 subRevNumbers = new int [ nbRevSub ];
378 for (int r=0; r<nbRevSub; ++r)
379 subRevNumbers[ r ] = 0;
381 int nSubI = 1, nSubJ, nSubK; // subelement numbers
384 nSubJ = getFaceNumber(2, 0, 0, 0);
385 nSubK = getFaceNumber(3, 0, 0, 0);
388 nSubJ = getEdgeNumber(2, 0, 0, 0);
391 // fill cell node numbers and descending element numbers
394 indexC = indexF = indexE = indexSub = indexRevSub = -1;
395 int iNode = 0, iCell = 0;
396 int ijLen = _iArrayLength * _jArrayLength;
397 int i, j, k, n1, n2, n3 ,n4;
399 int I = _iArrayLength;
400 int J = _jArrayLength ? _jArrayLength : 2; // pass at least once
401 int K = _kArrayLength ? _kArrayLength : 2;
402 // pass by all but last nodes in all directions
403 for (k = 1; k < K; ++k ) {
404 for (j = 1; j < J; ++j ) {
405 for (i = 1; i < I; ++i ) {
409 n1 = ++iNode; // iNode
411 nodeCNumbers [ ++indexC ] = n1;
412 nodeCNumbers [ ++indexC ] = n2;
414 if (hasEdges) { // at least 2d
417 nodeCNumbers [ ++indexC ] = n3;
418 nodeCNumbers [ ++indexC ] = n4;
420 if (hasFaces) { // 3d
421 nodeCNumbers [ ++indexC ] = n1 + ijLen;
422 nodeCNumbers [ ++indexC ] = n2 + ijLen;
423 nodeCNumbers [ ++indexC ] = n3 + ijLen;
424 nodeCNumbers [ ++indexC ] = n4 + ijLen;
431 subNumbers [ ++indexSub ] = n1;
432 subRevNumbers[ n3 ] = iCell;
433 subNumbers [ ++indexSub ] = n2;
434 subRevNumbers[ n4 ] = -iCell;
439 subNumbers [ ++indexSub ] = n1;
440 subRevNumbers[ n3 ] = iCell;
441 subNumbers [ ++indexSub ] = n2;
442 subRevNumbers[ n4 ] = -iCell;
447 subNumbers [ ++indexSub ] = n1;
448 subRevNumbers[ n3 ] = iCell;
449 subNumbers [ ++indexSub ] = n2;
450 subRevNumbers[ n4 ] = -iCell;
459 subNumbers [ ++indexSub ] = n1;
460 subRevNumbers[ n3 ] = iCell;
461 subNumbers [ ++indexSub ] = n2;
462 subRevNumbers[ n4 ] = -iCell;
467 subNumbers [ ++indexSub ] = n1;
468 subRevNumbers[ n3 ] = iCell;
469 subNumbers [ ++indexSub ] = n2;
470 subRevNumbers[ n4 ] = -iCell;
472 ++nSubI; ++nSubJ; ++nSubK;
474 ++iNode; // skip the last node in a row
480 iNode += I; // skip the whole last row
483 // fill face node numbers
485 int ax, AX = hasFaces ? 3 : 0;
486 for (ax = 1; ax <= AX; ++ax) {
494 case 1: --J; --K; break;
495 case 2: --K; --I; break;
498 for (k = 1; k <= K; ++k ) {
499 for (j = 1; j <= J; ++j ) {
500 for (i = 1; i <= I; ++i ) {
505 case 1: // nodes for faces normal to i direction
510 case 2: // nodes for faces normal to j direction
515 default: // nodes for faces normal to k direction
520 nodeFNumbers [ ++indexF ] = n1;
521 nodeFNumbers [ ++indexF ] = n2;
522 nodeFNumbers [ ++indexF ] = n3;
523 nodeFNumbers [ ++indexF ] = n4;
525 if (ax != 1) ++iNode;
527 if (ax != 2) iNode += _iArrayLength;
530 if (nbFNodes != indexF+1) {
531 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Wrong nbFNodes : " \
532 << nbFNodes << " indexF : " << indexF ));
535 // fill edge node numbers
537 AX = hasEdges ? _spaceDimension : 0;
538 for (ax = 1; ax <= AX; ++ax) {
552 for (k = 1; k <= K; ++k ) {
553 for (j = 1; j <= J; ++j ) {
554 for (i = 1; i <= I; ++i ) {
559 case 1: // nodes for edges going along i direction
562 case 2: // nodes for edges going along j direction
563 n2 = n1 + _iArrayLength;
565 default: // nodes for edges going along k direction
568 nodeENumbers [ ++indexE ] = n1;
569 nodeENumbers [ ++indexE ] = n2;
571 if (ax == 1) ++iNode;
573 if (ax == 2) iNode += _iArrayLength;
576 if (nbENodes != indexE+1) {
577 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Wrong nbFNodes : " \
578 << nbENodes << " indexE : " << indexE ));
582 CONNECTIVITY * CellCNCT, * FaceCNCT, * EdgeCNCT;
584 // make connectivity for CELL
586 medGeometryElement aCellGeometry;
587 if (_kArrayLength) aCellGeometry = MED_HEXA8;
588 else if (_jArrayLength) aCellGeometry = MED_QUAD4;
589 else aCellGeometry = MED_SEG2;
592 CellCNCT = makeConnectivity (MED_CELL, aCellGeometry, nbCells, nbCNodes, nodeCNumbers);
594 delete [] nodeCNumbers;
598 // CellCNCT->_descending = new MEDSKYLINEARRAY() ;
599 int * skyLineArrayIndex = new int [nbCells + 1];
600 int nbEntitySub = CellCNCT->_type[0].getNumberOfConstituents(1);
601 for (i=0, j=1; i <= nbCells; ++i, j += nbEntitySub)
602 skyLineArrayIndex [ i ] = j;
603 // CellCNCT->_descending->setMEDSKYLINEARRAY (nbCells, nbSub,
604 // skyLineArrayIndex, subNumbers);
605 CellCNCT->_descending = new MEDSKYLINEARRAY (nbCells, nbSub,
608 delete [] skyLineArrayIndex;
610 delete [] subNumbers;
612 // reverse descending
614 // CellCNCT->_reverseDescendingConnectivity = new MEDSKYLINEARRAY() ;
616 int * skyLineArrayIndex = new int [nbSub + 1];
617 for (i=0, j=1; i <= nbSub; ++i, j += 2)
618 skyLineArrayIndex [ i ] = j;
619 // CellCNCT->_reverseDescendingConnectivity->setMEDSKYLINEARRAY
620 // (nbSub, nbRevSub, skyLineArrayIndex, subRevNumbers);
622 CellCNCT->_reverseDescendingConnectivity =
623 new MEDSKYLINEARRAY(nbSub, nbRevSub, skyLineArrayIndex, subRevNumbers);
625 delete [] skyLineArrayIndex;
627 delete [] subRevNumbers;
629 // make connectivity for FACE and/or EDGE
632 FaceCNCT = makeConnectivity (MED_FACE, MED_QUAD4, nbFaces, nbFNodes, nodeFNumbers);
634 delete [] nodeFNumbers;
636 CellCNCT->_constituent = FaceCNCT;
639 EdgeCNCT = makeConnectivity (MED_EDGE, MED_SEG2, nbEdges, nbENodes, nodeENumbers);
641 delete [] nodeENumbers;
644 FaceCNCT->_constituent = EdgeCNCT;
646 CellCNCT->_constituent = EdgeCNCT;
649 MESH::_connectivity = CellCNCT;
651 (const_cast <GRID *> (this))->_is_connectivity_filled = true;
656 //=======================================================================
657 //function : getArrayLength
658 //purpose : return array length. Axis = [1,2,3] meaning [i,j,k],
659 //=======================================================================
661 int GRID::getArrayLength( const int Axis ) const throw (MEDEXCEPTION)
664 case 1: return _iArrayLength;
665 case 2: return _jArrayLength;
666 case 3: return _kArrayLength;
668 throw MED_EXCEPTION ( LOCALIZED( STRING("GRID::getArrayLength ( ") << Axis << ")"));
673 //=======================================================================
674 //function : getArrayValue
675 //purpose : return i-th array component. Axis = [1,2,3] meaning [i,j,k],
676 // exception if Axis out of [1-3] range
677 // exception if i is out of range 0 <= i < getArrayLength(Axis);
678 //=======================================================================
680 const double GRID::getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION)
682 if (i < 0 || i >= getArrayLength(Axis))
684 ( LOCALIZED(STRING("GRID::getArrayValue ( ") << Axis << ", " << i << ")"));
687 case 1: return _iArray[ i ];
688 case 2: return _jArray[ i ];
689 default: return _kArray[ i ];
694 //=======================================================================
695 //function : getEdgeNumber
697 //=======================================================================
699 int GRID::getEdgeNumber(const int Axis, const int i, const int j, const int k)
700 const throw (MEDEXCEPTION)
702 const char * LOC = "GRID::getEdgeNumber(Axis, i,j,k) :";
706 int Len[4] = {0,_iArrayLength, _jArrayLength, _kArrayLength }, I=1, J=2, K=3;
707 int maxAxis = Len[ K ] ? 3 : 2;
709 if (Axis <= 0 || Axis > maxAxis)
710 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Axis out of range: " << Axis));
713 int Nb = 1 + i + j*Len[ I ] + k*Len[ J ]*Len[ K ];
719 if (Axis > 1) { // add all edges in i direction
721 Nb += Len[ I ]*Len[ J ]*Len[ K ];
724 if (Axis > 2) { // add all edges in j direction
726 Nb += Len[ I ]*Len[ J ]*Len[ K ];
734 //=======================================================================
735 //function : getFaceNumber
736 //purpose : return a NODE, EDGE, FACE, CELL number by its position in the grid.
737 // Axis [1,2,3] means one of directions: along i, j or k
738 // For Cell contituents (FACE or EDGE), Axis selects one of those having same (i,j,k):
739 // * a FACE which is normal to direction along given Axis;
740 // * an EDGE going along given Axis.
741 // Exception for Axis out of range
742 //=======================================================================
744 int GRID::getFaceNumber(const int Axis, const int i, const int j, const int k)
745 const throw (MEDEXCEPTION)
747 const char * LOC = "GRID::getFaceNumber(Axis, i,j,k) :";
751 // if (Axis <= 0 || Axis > 3)
752 if (Axis < 0 || Axis > 3)
753 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Axis = " << Axis));
755 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2, K=3;
758 int Nb = 1 + i + j*Len[ I ] + k*Len[ J ]*Len[ K ];
761 if (Axis > 1) { // add all faces in i direction
763 Nb += Len[ I ]*Len[ J ]*Len[ K ];
766 if (Axis > 2) { // add all faces in j direction
768 Nb += Len[ I ]*Len[ J ]*Len[ K ];
776 //=======================================================================
777 //function : getNodePosition
779 //=======================================================================
781 void GRID::getNodePosition(const int Number, int& i, int& j, int& k) const
784 const char * LOC = "GRID::getNodePosition(Number, i,j,k) :";
788 if (Number <= 0 || Number > _numberOfNodes)
789 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
791 int Len[] = {_iArrayLength, _jArrayLength, _kArrayLength }, I=0, J=1;
792 // , K=2; !! UNUSED VARIABLE !!
794 int ijLen = Len[I] * Len[J]; // nb in a full k layer
795 int kLen = (Number - 1) % ijLen; // nb in the non full k layer
799 k = (Number - 1) / ijLen;
801 ////cout <<" NODE POS: " << Number << " - " << i << ", " << j << ", " << k << endl;
807 //=======================================================================
808 //function : getCellPosition
810 //=======================================================================
812 void GRID::getCellPosition(const int Number, int& i, int& j, int& k) const
815 const char * LOC = "GRID::getCellPosition(Number, i,j,k) :";
819 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2;
820 // , K=3; !! UNUSED VARIABLE !!
822 // if (Number <= 0 || Number > getCellNumber(Len[I]-1, Len[J]-1, Len[K]-1))
823 // throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
825 int ijLen = Len[I] * Len[J]; // nb in a full k layer
826 int kLen = (Number - 1) % ijLen; // nb in the non full k layer
830 k = (Number - 1) / ijLen;
835 //=======================================================================
836 //function : getEdgePosition
838 //=======================================================================
840 void GRID::getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k)
841 const throw (MEDEXCEPTION)
843 const char * LOC = "GRID::getEdgePosition(Number, i,j,k) :";
848 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no edges in the grid: "));
851 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
853 int Len[4] = {0,_iArrayLength, _jArrayLength, _kArrayLength }, I=1, J=2, K=3;
856 int maxAxis = _kArrayLength ? 3 : 2;
858 for (Axis = 1; Axis <= maxAxis; ++Axis)
860 Len[Axis]--; // one less edge in Axis direction
862 // max edge number in Axis direction
863 int maxNb = getEdgeNumber (Axis, Len[I]-1, Len[J]-1, Len[K]-1);
880 int ijLen = Len[I] * Len[J]; // nb in a full k layer
881 int kLen = (theNb - 1) % ijLen; // nb in the non full k layer
884 k = (theNb - 1) / ijLen;
892 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
895 //=======================================================================
896 //function : getFacePosition
897 //purpose : return position (i,j,k) of an entity #Number
898 // Axis [1,2,3] means one of directions: along i, j or k
899 // For Cell contituents (FACE or EDGE), Axis selects one of those having same (i,j,k):
900 // * a FACE which is normal to direction along given Axis;
901 // * an EDGE going along given Axis.
902 // Exception for Number out of range
903 //=======================================================================
905 void GRID::getFacePosition(const int Number, int& Axis, int& i, int& j, int& k)
906 const throw (MEDEXCEPTION)
908 const char * LOC = "GRID::getFacePosition(Number, i,j,k) :";
912 if (_kArrayLength == 0) {
913 getCellPosition(Number, i, j, k);
919 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no faces in the grid: "));
922 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
924 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2, K=3;
927 for (Axis = 1; Axis <= 3; ++Axis)
931 // max face number in Axis direction
932 int maxNb = getFaceNumber (Axis, Len[I]-1, Len[J]-1, Len[K]-1);
949 int ijLen = Len[I] * Len[J]; // nb in a full k layer
950 int kLen = (theNb - 1) % ijLen; // nb in the non full k layer
953 k = (theNb - 1) / ijLen;
961 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
964 //=======================================================================
965 //function : writeUnstructured
966 //purpose : write a Grid as an Unstructured mesh
967 //=======================================================================
969 void GRID::writeUnstructured(int index, const string & driverName)
971 const char * LOC = "GRID::writeUnstructured(int index=0, const string & driverName) : ";
974 if ( _drivers[index] ) {
979 _drivers[index]->open();
980 if (driverName != "") _drivers[index]->setMeshName(driverName);
981 _drivers[index]->write();
982 _drivers[index]->close();
987 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
988 << "The index given is invalid, index must be between 0 and |"
995 void GRID::read(int index)
997 const char * LOC = "GRID::read(int index=0) : ";
1000 if (_drivers[index]) {
1001 _drivers[index]->open();
1002 _drivers[index]->read();
1003 _drivers[index]->close();
1006 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
1007 << "The index given is invalid, index must be between 0 and |"
1012 fillMeshAfterRead();