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 //=======================================================================
42 //purpose : copying constructor
43 //=======================================================================
45 GRID::GRID(const GRID& otherGrid) {
49 //=======================================================================
51 //purpose : destructor
52 //=======================================================================
55 MESSAGE("GRID::~GRID() : Destroying the Grid");
56 if ( _iArray != (double* ) NULL) delete [] _iArray;
57 if ( _jArray != (double* ) NULL) delete [] _jArray;
58 if ( _kArray != (double* ) NULL) delete [] _kArray;
61 //=======================================================================
64 //=======================================================================
68 _gridType = MED_CARTESIAN;
70 _iArray = _jArray = _kArray = (double* ) NULL;
71 _iArrayLength = _jArrayLength = _kArrayLength = 0;
73 _is_coordinates_filled = false;
74 _is_connectivity_filled = false;
81 //=======================================================================
84 //=======================================================================
86 GRID & GRID::operator=(const GRID & otherGrid)
90 MESH::operator=(otherGrid);
94 //=======================================================================
96 //purpose : Create a GRID object using a MESH driver of type
97 // (MED_DRIVER, ....) associated with file <fileName>.
98 //=======================================================================
100 GRID::GRID(driverTypes driverType, const string & fileName,
101 const string & driverName) : MESH(driverType, fileName, driverName)
103 const char * LOC ="GRID::GRID(driverTypes , const string & , const string &) : ";
110 // MESH(driverType,fileName,driverName);
112 // current = addDriver(driverType,fileName,driverName);
114 // switch(_drivers[current]->getAccessMode() ) {
116 // MESSAGE(LOC << "driverType must have a MED_RDWR accessMode");
117 // rmDriver(current);
121 // _drivers[current]->open();
122 // _drivers[current]->read();
123 // _drivers[current]->close();
125 // // fill some fields of MESH
126 // fillMeshAfterRead();
133 //=======================================================================
134 //function : fillMeshAfterRead
136 //=======================================================================
138 void GRID::fillMeshAfterRead()
140 // fill not only MESH (:-)
141 _is_coordinates_filled = false;
142 _is_connectivity_filled = false;
144 if (_gridType == MED_BODY_FITTED)
146 _is_coordinates_filled = true;
148 // nb of nodes in each direction is not known, set anything
149 // in order to be able to work anyhow
150 // INFOS("GRID::fillMeshAfterRead(): This stub must be removed");
151 // switch (_spaceDimension) {
153 // _iArrayLength = _numberOfNodes;
154 // _jArrayLength = 0;
155 // _kArrayLength = 0;
158 // _iArrayLength = 2;
159 // _jArrayLength = _numberOfNodes / _iArrayLength;
160 // _kArrayLength = 0;
163 // _iArrayLength = 2;
164 // _jArrayLength = _numberOfNodes / _iArrayLength / 2;
165 // _kArrayLength = _numberOfNodes / _iArrayLength / _jArrayLength;
167 //cout << "ARRAY LENGTHS: " << _iArrayLength << " " << _jArrayLength
168 // << " " << _kArrayLength << endl;
171 // int NbNodes = _iArrayLength;
172 // if (_jArrayLength)
173 // NbNodes *= _jArrayLength;
174 // if (_kArrayLength)
175 // NbNodes *= _kArrayLength;
176 // MESH::_numberOfNodes = NbNodes;
179 MESH::_meshDimension = MESH::_spaceDimension;
182 //=======================================================================
183 //function : fillCoordinates
185 //=======================================================================
187 void GRID::fillCoordinates() const
189 if (_is_coordinates_filled)
191 MESSAGE("GRID::fillCoordinates(): Already filled");
195 const char * LOC ="GRID::fillCoordinates()";
199 const_cast <double *> ( _coordinate->getCoordinates(MED_FULL_INTERLACE) );
201 bool hasJ = _jArrayLength, hasK = _kArrayLength;
202 int J = hasJ ? _jArrayLength : 1;
203 int K = hasK ? _kArrayLength : 1;
204 //int nb, !! UNUSED VARIABLE !!
206 for (k=0; k < K; ++k) {
207 for (j=0; j < J; ++j) {
208 for (i=0; i < _iArrayLength; ++i) {
210 * myCoord = _iArray[ i ];
215 * myCoord = _jArray[ j ];
220 * myCoord = _jArray[ k ];
228 (const_cast <GRID *> (this))->_is_coordinates_filled = true;
232 //=======================================================================
233 //function : makeConnectivity
235 //=======================================================================
237 CONNECTIVITY * GRID::makeConnectivity (const medEntityMesh Entity,
238 const medGeometryElement Geometry,
239 const int NbEntities,
244 CONNECTIVITY * Connectivity = new CONNECTIVITY(Entity) ;
245 Connectivity->_numberOfNodes = NbNodes ;
246 Connectivity->_entityDimension = Geometry/100 ;
248 int numberOfGeometricType = 1;
249 Connectivity->_numberOfTypes = numberOfGeometricType;
251 Connectivity->_count = new int [numberOfGeometricType + 1] ;
252 Connectivity->_count[0] = 1;
253 Connectivity->_count[1] = 1 + NbEntities;
255 Connectivity->_type = new CELLMODEL [numberOfGeometricType];
256 Connectivity->_type[0] = CELLMODEL( Geometry ) ;
258 Connectivity->_geometricTypes = new medGeometryElement [ numberOfGeometricType ];
259 Connectivity->_geometricTypes[0] = Geometry;
261 // Connectivity->_nodal = new MEDSKYLINEARRAY() ;
262 int * skyLineArrayIndex = new int [NbEntities + 1];
263 int i, j, nbEntityNodes = Connectivity->_type[0].getNumberOfNodes();
264 for (i=0, j=1; i <= NbEntities; ++i, j += nbEntityNodes)
265 skyLineArrayIndex [ i ] = j;
267 // Connectivity->_nodal->setMEDSKYLINEARRAY (NbEntities, NbNodes,
268 //skyLineArrayIndex, NodeNumbers);
270 Connectivity->_nodal = new MEDSKYLINEARRAY (NbEntities, NbNodes,
271 skyLineArrayIndex, NodeNumbers);
273 delete [] skyLineArrayIndex;
275 // test connectivity right away
276 // for (med_int j = 0; j < numberOfGeometricType; j++)
278 // int node_number = Connectivity->_type[j].getNumberOfNodes();
279 // for (med_int k = Connectivity->_count[j]; k < Connectivity->_count[j+1]; k++)
280 // for (med_int local_node_number = 1 ; local_node_number < node_number+1; local_node_number++)
282 // cout << "MEDSKYLINEARRAY::getIJ(" << k << ", " << local_node_number << endl;
283 // med_int global_node = Connectivity->_nodal->getIJ(k,local_node_number) ;
284 // cout << "...= " << global_node << endl;
291 //=======================================================================
292 //function : fillConnectivity
293 //purpose : fill _coordinates and _connectivity of MESH if not yet done
294 //=======================================================================
296 void GRID::fillConnectivity() const
298 if (_is_connectivity_filled)
300 MESSAGE("GRID::fillConnectivity(): Already filled");
304 const char * LOC = "GRID::fillConnectivity() ";
307 int nbCells, nbFaces, nbEdges;
308 int nbCNodes, nbFNodes, nbENodes;
309 int indexC, indexF, indexE;
310 int * nodeCNumbers, * nodeFNumbers, * nodeENumbers;
311 // about descending connectivity
312 int nbSub, nbRevSub, indexSub, indexRevSub, * subNumbers, * subRevNumbers;
314 bool hasFaces = _kArrayLength, hasEdges = _jArrayLength;
316 int iLenMin1 = _iArrayLength-1, jLenMin1 = _jArrayLength-1;
317 int kLenMin1 = _kArrayLength-1, ijLenMin1 = iLenMin1 * jLenMin1;
318 if (!hasEdges) jLenMin1 = 1;
319 if (!hasFaces) kLenMin1 = 1;
321 // nb of cells and of their connectivity nodes
323 nbCells = iLenMin1 * jLenMin1 * kLenMin1;
324 nbCNodes = nbCells * 2 * (hasEdges ? 2 : 1) * (hasFaces ? 2 : 1);
325 nodeCNumbers = new int [ nbCNodes ];
327 // nb of faces and of their connectivity nodes
330 nbFaces = _iArrayLength * jLenMin1 * kLenMin1;
331 nbFaces += _jArrayLength * kLenMin1 * iLenMin1;
332 nbFaces += _kArrayLength * iLenMin1 * jLenMin1;
333 nbFNodes = nbFaces * 4;
334 nodeFNumbers = new int [ nbFNodes ];
336 nbFaces = nbFNodes = 0;
338 // nb of edges and of their connectivity nodes
341 if (_kArrayLength) { // 3d grid
342 nbEdges = iLenMin1 * _jArrayLength * _kArrayLength;
343 nbEdges += jLenMin1 * _kArrayLength * _iArrayLength;
344 nbEdges += kLenMin1 * _iArrayLength * _jArrayLength;
346 else if (_jArrayLength) { // 2d
347 nbEdges = iLenMin1 * _jArrayLength;
348 nbEdges += jLenMin1 * _iArrayLength;
350 nbENodes = nbEdges * 2;
351 nodeENumbers = new int [ nbENodes ];
353 nbEdges = nbENodes = 0;
355 // nb of descending connectivity Elements
360 nbRevSub = nbFaces * 2;
365 nbRevSub = nbEdges * 2;
367 subNumbers = new int [ nbSub ];
368 subRevNumbers = new int [ nbRevSub ];
369 for (int r=0; r<nbRevSub; ++r)
370 subRevNumbers[ r ] = 0;
372 int nSubI = 1, nSubJ, nSubK; // subelement numbers
375 nSubJ = getFaceNumber(2, 0, 0, 0);
376 nSubK = getFaceNumber(3, 0, 0, 0);
379 nSubJ = getEdgeNumber(2, 0, 0, 0);
382 // fill cell node numbers and descending element numbers
385 indexC = indexF = indexE = indexSub = indexRevSub = -1;
386 int iNode = 0, iCell = 0;
387 int ijLen = _iArrayLength * _jArrayLength;
388 int i, j, k, n1, n2, n3 ,n4;
390 int I = _iArrayLength;
391 int J = _jArrayLength ? _jArrayLength : 2; // pass at least once
392 int K = _kArrayLength ? _kArrayLength : 2;
393 // pass by all but last nodes in all directions
394 for (k = 1; k < K; ++k ) {
395 for (j = 1; j < J; ++j ) {
396 for (i = 1; i < I; ++i ) {
400 n1 = ++iNode; // iNode
402 nodeCNumbers [ ++indexC ] = n1;
403 nodeCNumbers [ ++indexC ] = n2;
405 if (hasEdges) { // at least 2d
408 nodeCNumbers [ ++indexC ] = n3;
409 nodeCNumbers [ ++indexC ] = n4;
411 if (hasFaces) { // 3d
412 nodeCNumbers [ ++indexC ] = n1 + ijLen;
413 nodeCNumbers [ ++indexC ] = n2 + ijLen;
414 nodeCNumbers [ ++indexC ] = n3 + ijLen;
415 nodeCNumbers [ ++indexC ] = n4 + ijLen;
422 subNumbers [ ++indexSub ] = n1;
423 subRevNumbers[ n3 ] = iCell;
424 subNumbers [ ++indexSub ] = n2;
425 subRevNumbers[ n4 ] = -iCell;
430 subNumbers [ ++indexSub ] = n1;
431 subRevNumbers[ n3 ] = iCell;
432 subNumbers [ ++indexSub ] = n2;
433 subRevNumbers[ n4 ] = -iCell;
438 subNumbers [ ++indexSub ] = n1;
439 subRevNumbers[ n3 ] = iCell;
440 subNumbers [ ++indexSub ] = n2;
441 subRevNumbers[ n4 ] = -iCell;
450 subNumbers [ ++indexSub ] = n1;
451 subRevNumbers[ n3 ] = iCell;
452 subNumbers [ ++indexSub ] = n2;
453 subRevNumbers[ n4 ] = -iCell;
458 subNumbers [ ++indexSub ] = n1;
459 subRevNumbers[ n3 ] = iCell;
460 subNumbers [ ++indexSub ] = n2;
461 subRevNumbers[ n4 ] = -iCell;
463 ++nSubI; ++nSubJ; ++nSubK;
465 ++iNode; // skip the last node in a row
471 iNode += I; // skip the whole last row
474 // fill face node numbers
476 int ax, AX = hasFaces ? 3 : 0;
477 for (ax = 1; ax <= AX; ++ax) {
485 case 1: --J; --K; break;
486 case 2: --K; --I; break;
489 for (k = 1; k <= K; ++k ) {
490 for (j = 1; j <= J; ++j ) {
491 for (i = 1; i <= I; ++i ) {
496 case 1: // nodes for faces normal to i direction
501 case 2: // nodes for faces normal to j direction
506 default: // nodes for faces normal to k direction
511 nodeFNumbers [ ++indexF ] = n1;
512 nodeFNumbers [ ++indexF ] = n2;
513 nodeFNumbers [ ++indexF ] = n3;
514 nodeFNumbers [ ++indexF ] = n4;
516 if (ax != 1) ++iNode;
518 if (ax != 2) iNode += _iArrayLength;
521 if (nbFNodes != indexF+1) {
522 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Wrong nbFNodes : " \
523 << nbFNodes << " indexF : " << indexF ));
526 // fill edge node numbers
528 AX = hasEdges ? _spaceDimension : 0;
529 for (ax = 1; ax <= AX; ++ax) {
543 for (k = 1; k <= K; ++k ) {
544 for (j = 1; j <= J; ++j ) {
545 for (i = 1; i <= I; ++i ) {
550 case 1: // nodes for edges going along i direction
553 case 2: // nodes for edges going along j direction
554 n2 = n1 + _iArrayLength;
556 default: // nodes for edges going along k direction
559 nodeENumbers [ ++indexE ] = n1;
560 nodeENumbers [ ++indexE ] = n2;
562 if (ax == 1) ++iNode;
564 if (ax == 2) iNode += _iArrayLength;
567 if (nbENodes != indexE+1) {
568 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Wrong nbFNodes : " \
569 << nbENodes << " indexE : " << indexE ));
573 CONNECTIVITY * CellCNCT, * FaceCNCT, * EdgeCNCT;
575 // make connectivity for CELL
577 medGeometryElement aCellGeometry;
578 if (_kArrayLength) aCellGeometry = MED_HEXA8;
579 else if (_jArrayLength) aCellGeometry = MED_QUAD4;
580 else aCellGeometry = MED_SEG2;
583 CellCNCT = makeConnectivity (MED_CELL, aCellGeometry, nbCells, nbCNodes, nodeCNumbers);
585 delete [] nodeCNumbers;
589 // CellCNCT->_descending = new MEDSKYLINEARRAY() ;
590 int * skyLineArrayIndex = new int [nbCells + 1];
591 int nbEntitySub = CellCNCT->_type[0].getNumberOfConstituents(1);
592 for (i=0, j=1; i <= nbCells; ++i, j += nbEntitySub)
593 skyLineArrayIndex [ i ] = j;
594 // CellCNCT->_descending->setMEDSKYLINEARRAY (nbCells, nbSub,
595 // skyLineArrayIndex, subNumbers);
596 CellCNCT->_descending = new MEDSKYLINEARRAY (nbCells, nbSub,
599 delete [] skyLineArrayIndex;
601 delete [] subNumbers;
603 // reverse descending
605 // CellCNCT->_reverseDescendingConnectivity = new MEDSKYLINEARRAY() ;
607 int * skyLineArrayIndex = new int [nbSub + 1];
608 for (i=0, j=1; i <= nbSub; ++i, j += 2)
609 skyLineArrayIndex [ i ] = j;
610 // CellCNCT->_reverseDescendingConnectivity->setMEDSKYLINEARRAY
611 // (nbSub, nbRevSub, skyLineArrayIndex, subRevNumbers);
613 CellCNCT->_reverseDescendingConnectivity =
614 new MEDSKYLINEARRAY(nbSub, nbRevSub, skyLineArrayIndex, subRevNumbers);
616 delete [] skyLineArrayIndex;
618 delete [] subRevNumbers;
620 // make connectivity for FACE and/or EDGE
623 FaceCNCT = makeConnectivity (MED_FACE, MED_QUAD4, nbFaces, nbFNodes, nodeFNumbers);
625 delete [] nodeFNumbers;
627 CellCNCT->_constituent = FaceCNCT;
630 EdgeCNCT = makeConnectivity (MED_EDGE, MED_SEG2, nbEdges, nbENodes, nodeENumbers);
632 delete [] nodeENumbers;
635 FaceCNCT->_constituent = EdgeCNCT;
637 CellCNCT->_constituent = EdgeCNCT;
640 MESH::_connectivity = CellCNCT;
642 (const_cast <GRID *> (this))->_is_connectivity_filled = true;
647 //=======================================================================
648 //function : getArrayLength
649 //purpose : return array length. Axis = [1,2,3] meaning [i,j,k],
650 //=======================================================================
652 int GRID::getArrayLength( const int Axis ) const throw (MEDEXCEPTION)
655 case 1: return _iArrayLength;
656 case 2: return _jArrayLength;
657 case 3: return _kArrayLength;
659 throw MED_EXCEPTION ( LOCALIZED( STRING("GRID::getArrayLength ( ") << Axis << ")"));
664 //=======================================================================
665 //function : getArrayValue
666 //purpose : return i-th array component. Axis = [1,2,3] meaning [i,j,k],
667 // exception if Axis out of [1-3] range
668 // exception if i is out of range 0 <= i < getArrayLength(Axis);
669 //=======================================================================
671 const double GRID::getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION)
673 if (i < 0 || i >= getArrayLength(Axis))
675 ( LOCALIZED(STRING("GRID::getArrayValue ( ") << Axis << ", " << i << ")"));
678 case 1: return _iArray[ i ];
679 case 2: return _jArray[ i ];
680 default: return _kArray[ i ];
685 //=======================================================================
686 //function : getEdgeNumber
688 //=======================================================================
690 int GRID::getEdgeNumber(const int Axis, const int i, const int j, const int k)
691 const throw (MEDEXCEPTION)
693 const char * LOC = "GRID::getEdgeNumber(Axis, i,j,k) :";
697 int Len[4] = {0,_iArrayLength, _jArrayLength, _kArrayLength }, I=1, J=2, K=3;
698 int maxAxis = Len[ K ] ? 3 : 2;
700 if (Axis <= 0 || Axis > maxAxis)
701 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Axis out of range: " << Axis));
704 int Nb = 1 + i + j*Len[ I ] + k*Len[ J ]*Len[ K ];
710 if (Axis > 1) { // add all edges in i direction
712 Nb += Len[ I ]*Len[ J ]*Len[ K ];
715 if (Axis > 2) { // add all edges in j direction
717 Nb += Len[ I ]*Len[ J ]*Len[ K ];
725 //=======================================================================
726 //function : getFaceNumber
727 //purpose : return a NODE, EDGE, FACE, CELL number by its position in the grid.
728 // Axis [1,2,3] means one of directions: along i, j or k
729 // For Cell contituents (FACE or EDGE), Axis selects one of those having same (i,j,k):
730 // * a FACE which is normal to direction along given Axis;
731 // * an EDGE going along given Axis.
732 // Exception for Axis out of range
733 //=======================================================================
735 int GRID::getFaceNumber(const int Axis, const int i, const int j, const int k)
736 const throw (MEDEXCEPTION)
738 const char * LOC = "GRID::getFaceNumber(Axis, i,j,k) :";
742 // if (Axis <= 0 || Axis > 3)
743 if (Axis < 0 || Axis > 3)
744 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Axis = " << Axis));
746 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2, K=3;
749 int Nb = 1 + i + j*Len[ I ] + k*Len[ J ]*Len[ K ];
752 if (Axis > 1) { // add all faces in i direction
754 Nb += Len[ I ]*Len[ J ]*Len[ K ];
757 if (Axis > 2) { // add all faces in j direction
759 Nb += Len[ I ]*Len[ J ]*Len[ K ];
767 //=======================================================================
768 //function : getNodePosition
770 //=======================================================================
772 void GRID::getNodePosition(const int Number, int& i, int& j, int& k) const
775 const char * LOC = "GRID::getNodePosition(Number, i,j,k) :";
779 if (Number <= 0 || Number > _numberOfNodes)
780 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
782 int Len[] = {_iArrayLength, _jArrayLength, _kArrayLength }, I=0, J=1;
783 // , K=2; !! UNUSED VARIABLE !!
785 int ijLen = Len[I] * Len[J]; // nb in a full k layer
786 int kLen = (Number - 1) % ijLen; // nb in the non full k layer
790 k = (Number - 1) / ijLen;
792 ////cout <<" NODE POS: " << Number << " - " << i << ", " << j << ", " << k << endl;
798 //=======================================================================
799 //function : getCellPosition
801 //=======================================================================
803 void GRID::getCellPosition(const int Number, int& i, int& j, int& k) const
806 const char * LOC = "GRID::getCellPosition(Number, i,j,k) :";
810 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2;
811 // , K=3; !! UNUSED VARIABLE !!
813 // if (Number <= 0 || Number > getCellNumber(Len[I]-1, Len[J]-1, Len[K]-1))
814 // throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
816 int ijLen = Len[I] * Len[J]; // nb in a full k layer
817 int kLen = (Number - 1) % ijLen; // nb in the non full k layer
821 k = (Number - 1) / ijLen;
826 //=======================================================================
827 //function : getEdgePosition
829 //=======================================================================
831 void GRID::getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k)
832 const throw (MEDEXCEPTION)
834 const char * LOC = "GRID::getEdgePosition(Number, i,j,k) :";
839 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no edges in the grid: "));
842 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
844 int Len[4] = {0,_iArrayLength, _jArrayLength, _kArrayLength }, I=1, J=2, K=3;
847 int maxAxis = _kArrayLength ? 3 : 2;
849 for (Axis = 1; Axis <= maxAxis; ++Axis)
851 Len[Axis]--; // one less edge in Axis direction
853 // max edge number in Axis direction
854 int maxNb = getEdgeNumber (Axis, Len[I]-1, Len[J]-1, Len[K]-1);
871 int ijLen = Len[I] * Len[J]; // nb in a full k layer
872 int kLen = (theNb - 1) % ijLen; // nb in the non full k layer
875 k = (theNb - 1) / ijLen;
883 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
886 //=======================================================================
887 //function : getFacePosition
888 //purpose : return position (i,j,k) of an entity #Number
889 // Axis [1,2,3] means one of directions: along i, j or k
890 // For Cell contituents (FACE or EDGE), Axis selects one of those having same (i,j,k):
891 // * a FACE which is normal to direction along given Axis;
892 // * an EDGE going along given Axis.
893 // Exception for Number out of range
894 //=======================================================================
896 void GRID::getFacePosition(const int Number, int& Axis, int& i, int& j, int& k)
897 const throw (MEDEXCEPTION)
899 const char * LOC = "GRID::getFacePosition(Number, i,j,k) :";
903 if (_kArrayLength == 0) {
904 getCellPosition(Number, i, j, k);
910 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no faces in the grid: "));
913 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
915 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2, K=3;
918 for (Axis = 1; Axis <= 3; ++Axis)
922 // max face number in Axis direction
923 int maxNb = getFaceNumber (Axis, Len[I]-1, Len[J]-1, Len[K]-1);
940 int ijLen = Len[I] * Len[J]; // nb in a full k layer
941 int kLen = (theNb - 1) % ijLen; // nb in the non full k layer
944 k = (theNb - 1) / ijLen;
952 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
955 //=======================================================================
956 //function : writeUnstructured
957 //purpose : write a Grid as an Unstructured mesh
958 //=======================================================================
960 void GRID::writeUnstructured(int index, const string & driverName)
962 const char * LOC = "GRID::writeUnstructured(int index=0, const string & driverName) : ";
965 if ( _drivers[index] ) {
970 _drivers[index]->open();
971 if (driverName != "") _drivers[index]->setMeshName(driverName);
972 _drivers[index]->write();
973 _drivers[index]->close();
978 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
979 << "The index given is invalid, index must be between 0 and |"
986 void GRID::read(int index)
988 const char * LOC = "GRID::read(int index=0) : ";
991 if (_drivers[index]) {
992 _drivers[index]->open();
993 _drivers[index]->read();
994 _drivers[index]->close();
997 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
998 << "The index given is invalid, index must be between 0 and |"
1003 fillMeshAfterRead();