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>
17 //=======================================================================
19 //purpose : empty constructor
20 //=======================================================================
24 MESSAGE("A GRID CREATED");
27 //=======================================================================
29 //purpose : empty constructor
30 //=======================================================================
32 GRID::GRID(const med_grid_type type)
36 MESSAGE("A TYPED GRID CREATED");
39 //=======================================================================
41 //purpose : copying constructor
42 //=======================================================================
44 GRID::GRID(const GRID& otherGrid) {
48 //=======================================================================
50 //purpose : destructor
51 //=======================================================================
54 MESSAGE("GRID::~GRID() : Destroying the Grid");
55 if ( _iArray != (double* ) NULL) delete [] _iArray;
56 if ( _jArray != (double* ) NULL) delete [] _jArray;
57 if ( _kArray != (double* ) NULL) delete [] _kArray;
60 //=======================================================================
63 //=======================================================================
67 _gridType = MED_CARTESIAN;
69 _iArray = _jArray = _kArray = (double* ) NULL;
70 _iArrayLength = _jArrayLength = _kArrayLength = 0;
72 _is_coordinates_filled = false;
73 _is_connectivity_filled = false;
80 //=======================================================================
83 //=======================================================================
85 GRID & GRID::operator=(const GRID & otherGrid)
89 MESH::operator=(otherGrid);
93 //=======================================================================
95 //purpose : Create a GRID object using a MESH driver of type
96 // (MED_DRIVER, ....) associated with file <fileName>.
97 //=======================================================================
99 GRID::GRID(driverTypes driverType, const string & fileName,
100 const string & driverName) : MESH(driverType, fileName, driverName)
102 const char * LOC ="GRID::GRID(driverTypes , const string & , const string &) : ";
109 // MESH(driverType,fileName,driverName);
111 // current = addDriver(driverType,fileName,driverName);
113 // switch(_drivers[current]->getAccessMode() ) {
115 // MESSAGE(LOC << "driverType must have a MED_RDWR accessMode");
116 // rmDriver(current);
120 // _drivers[current]->open();
121 // _drivers[current]->read();
122 // _drivers[current]->close();
124 // // fill some fields of MESH
125 // fillMeshAfterRead();
132 //=======================================================================
133 //function : fillMeshAfterRead
135 //=======================================================================
137 void GRID::fillMeshAfterRead()
139 // fill not only MESH (:-)
140 _is_coordinates_filled = false;
141 _is_connectivity_filled = false;
143 if (_gridType == MED_BODY_FITTED)
145 _is_coordinates_filled = true;
147 // nb of nodes in each direction is not known, set anything
148 // in order to be able to work anyhow
149 // INFOS("GRID::fillMeshAfterRead(): This stub must be removed");
150 // switch (_spaceDimension) {
152 // _iArrayLength = _numberOfNodes;
153 // _jArrayLength = 0;
154 // _kArrayLength = 0;
157 // _iArrayLength = 2;
158 // _jArrayLength = _numberOfNodes / _iArrayLength;
159 // _kArrayLength = 0;
162 // _iArrayLength = 2;
163 // _jArrayLength = _numberOfNodes / _iArrayLength / 2;
164 // _kArrayLength = _numberOfNodes / _iArrayLength / _jArrayLength;
166 //cout << "ARRAY LENGTHS: " << _iArrayLength << " " << _jArrayLength
167 // << " " << _kArrayLength << endl;
170 // int NbNodes = _iArrayLength;
171 // if (_jArrayLength)
172 // NbNodes *= _jArrayLength;
173 // if (_kArrayLength)
174 // NbNodes *= _kArrayLength;
175 // MESH::_numberOfNodes = NbNodes;
178 MESH::_meshDimension = MESH::_spaceDimension;
181 //=======================================================================
182 //function : fillCoordinates
184 //=======================================================================
186 void GRID::fillCoordinates() const
188 if (_is_coordinates_filled)
190 MESSAGE("GRID::fillCoordinates(): Already filled");
194 const char * LOC ="GRID::fillCoordinates()";
198 const_cast <double *> ( _coordinate->getCoordinates(MED_FULL_INTERLACE) );
200 bool hasJ = _jArrayLength, hasK = _kArrayLength;
201 int J = hasJ ? _jArrayLength : 1;
202 int K = hasK ? _kArrayLength : 1;
203 //int nb, !! UNUSED VARIABLE !!
205 for (k=0; k < K; ++k) {
206 for (j=0; j < J; ++j) {
207 for (i=0; i < _iArrayLength; ++i) {
209 * myCoord = _iArray[ i ];
214 * myCoord = _jArray[ j ];
219 * myCoord = _jArray[ k ];
227 (const_cast <GRID *> (this))->_is_coordinates_filled = true;
231 //=======================================================================
232 //function : makeConnectivity
234 //=======================================================================
236 CONNECTIVITY * GRID::makeConnectivity (const medEntityMesh Entity,
237 const medGeometryElement Geometry,
238 const int NbEntities,
243 CONNECTIVITY * Connectivity = new CONNECTIVITY(Entity) ;
244 Connectivity->_numberOfNodes = NbNodes ;
245 Connectivity->_entityDimension = Geometry/100 ;
247 int numberOfGeometricType = 1;
248 Connectivity->_numberOfTypes = numberOfGeometricType;
250 Connectivity->_count = new int [numberOfGeometricType + 1] ;
251 Connectivity->_count[0] = 1;
252 Connectivity->_count[1] = 1 + NbEntities;
254 Connectivity->_type = new CELLMODEL [numberOfGeometricType];
255 Connectivity->_type[0] = CELLMODEL( Geometry ) ;
257 Connectivity->_geometricTypes = new medGeometryElement [ numberOfGeometricType ];
258 Connectivity->_geometricTypes[0] = Geometry;
260 // Connectivity->_nodal = new MEDSKYLINEARRAY() ;
261 int * skyLineArrayIndex = new int [NbEntities + 1];
262 int i, j, nbEntityNodes = Connectivity->_type[0].getNumberOfNodes();
263 for (i=0, j=1; i <= NbEntities; ++i, j += nbEntityNodes)
264 skyLineArrayIndex [ i ] = j;
266 // Connectivity->_nodal->setMEDSKYLINEARRAY (NbEntities, NbNodes,
267 //skyLineArrayIndex, NodeNumbers);
269 Connectivity->_nodal = new MEDSKYLINEARRAY (NbEntities, NbNodes,
270 skyLineArrayIndex, NodeNumbers);
272 delete [] skyLineArrayIndex;
274 // test connectivity right away
275 // for (med_int j = 0; j < numberOfGeometricType; j++)
277 // int node_number = Connectivity->_type[j].getNumberOfNodes();
278 // for (med_int k = Connectivity->_count[j]; k < Connectivity->_count[j+1]; k++)
279 // for (med_int local_node_number = 1 ; local_node_number < node_number+1; local_node_number++)
281 // cout << "MEDSKYLINEARRAY::getIJ(" << k << ", " << local_node_number << endl;
282 // med_int global_node = Connectivity->_nodal->getIJ(k,local_node_number) ;
283 // cout << "...= " << global_node << endl;
290 //=======================================================================
291 //function : fillConnectivity
292 //purpose : fill _coordinates and _connectivity of MESH if not yet done
293 //=======================================================================
295 void GRID::fillConnectivity() const
297 if (_is_connectivity_filled)
299 MESSAGE("GRID::fillConnectivity(): Already filled");
303 const char * LOC = "GRID::fillConnectivity() ";
306 int nbCells, nbFaces, nbEdges;
307 int nbCNodes, nbFNodes, nbENodes;
308 int indexC, indexF, indexE;
309 int * nodeCNumbers, * nodeFNumbers, * nodeENumbers;
310 // about descending connectivity
311 int nbSub, nbRevSub, indexSub, indexRevSub, * subNumbers, * subRevNumbers;
313 bool hasFaces = _kArrayLength, hasEdges = _jArrayLength;
315 int iLenMin1 = _iArrayLength-1, jLenMin1 = _jArrayLength-1;
316 int kLenMin1 = _kArrayLength-1, ijLenMin1 = iLenMin1 * jLenMin1;
317 if (!hasEdges) jLenMin1 = 1;
318 if (!hasFaces) kLenMin1 = 1;
320 // nb of cells and of their connectivity nodes
322 nbCells = iLenMin1 * jLenMin1 * kLenMin1;
323 nbCNodes = nbCells * 2 * (hasEdges ? 2 : 1) * (hasFaces ? 2 : 1);
324 nodeCNumbers = new int [ nbCNodes ];
326 // nb of faces and of their connectivity nodes
329 nbFaces = _iArrayLength * jLenMin1 * kLenMin1;
330 nbFaces += _jArrayLength * kLenMin1 * iLenMin1;
331 nbFaces += _kArrayLength * iLenMin1 * jLenMin1;
332 nbFNodes = nbFaces * 4;
333 nodeFNumbers = new int [ nbFNodes ];
335 nbFaces = nbFNodes = 0;
337 // nb of edges and of their connectivity nodes
340 if (_kArrayLength) { // 3d grid
341 nbEdges = iLenMin1 * _jArrayLength * _kArrayLength;
342 nbEdges += jLenMin1 * _kArrayLength * _iArrayLength;
343 nbEdges += kLenMin1 * _iArrayLength * _jArrayLength;
345 else if (_jArrayLength) { // 2d
346 nbEdges = iLenMin1 * _jArrayLength;
347 nbEdges += jLenMin1 * _iArrayLength;
349 nbENodes = nbEdges * 2;
350 nodeENumbers = new int [ nbENodes ];
352 nbEdges = nbENodes = 0;
354 // nb of descending connectivity Elements
359 nbRevSub = nbFaces * 2;
364 nbRevSub = nbEdges * 2;
366 subNumbers = new int [ nbSub ];
367 subRevNumbers = new int [ nbRevSub ];
368 for (int r=0; r<nbRevSub; ++r)
369 subRevNumbers[ r ] = 0;
371 int nSubI = 1, nSubJ, nSubK; // subelement numbers
374 nSubJ = getFaceNumber(2, 0, 0, 0);
375 nSubK = getFaceNumber(3, 0, 0, 0);
378 nSubJ = getEdgeNumber(2, 0, 0, 0);
381 // fill cell node numbers and descending element numbers
384 indexC = indexF = indexE = indexSub = indexRevSub = -1;
385 int iNode = 0, iCell = 0;
386 int ijLen = _iArrayLength * _jArrayLength;
387 int i, j, k, n1, n2, n3 ,n4;
389 int I = _iArrayLength;
390 int J = _jArrayLength ? _jArrayLength : 2; // pass at least once
391 int K = _kArrayLength ? _kArrayLength : 2;
392 // pass by all but last nodes in all directions
393 for (k = 1; k < K; ++k ) {
394 for (j = 1; j < J; ++j ) {
395 for (i = 1; i < I; ++i ) {
399 n1 = ++iNode; // iNode
401 nodeCNumbers [ ++indexC ] = n1;
402 nodeCNumbers [ ++indexC ] = n2;
404 if (hasEdges) { // at least 2d
407 nodeCNumbers [ ++indexC ] = n3;
408 nodeCNumbers [ ++indexC ] = n4;
410 if (hasFaces) { // 3d
411 nodeCNumbers [ ++indexC ] = n1 + ijLen;
412 nodeCNumbers [ ++indexC ] = n2 + ijLen;
413 nodeCNumbers [ ++indexC ] = n3 + ijLen;
414 nodeCNumbers [ ++indexC ] = n4 + ijLen;
421 subNumbers [ ++indexSub ] = n1;
422 subRevNumbers[ n3 ] = iCell;
423 subNumbers [ ++indexSub ] = n2;
424 subRevNumbers[ n4 ] = -iCell;
429 subNumbers [ ++indexSub ] = n1;
430 subRevNumbers[ n3 ] = iCell;
431 subNumbers [ ++indexSub ] = n2;
432 subRevNumbers[ n4 ] = -iCell;
437 subNumbers [ ++indexSub ] = n1;
438 subRevNumbers[ n3 ] = iCell;
439 subNumbers [ ++indexSub ] = n2;
440 subRevNumbers[ n4 ] = -iCell;
449 subNumbers [ ++indexSub ] = n1;
450 subRevNumbers[ n3 ] = iCell;
451 subNumbers [ ++indexSub ] = n2;
452 subRevNumbers[ n4 ] = -iCell;
457 subNumbers [ ++indexSub ] = n1;
458 subRevNumbers[ n3 ] = iCell;
459 subNumbers [ ++indexSub ] = n2;
460 subRevNumbers[ n4 ] = -iCell;
462 ++nSubI; ++nSubJ; ++nSubK;
464 ++iNode; // skip the last node in a row
470 iNode += I; // skip the whole last row
473 // fill face node numbers
475 int ax, AX = hasFaces ? 3 : 0;
476 for (ax = 1; ax <= AX; ++ax) {
484 case 1: --J; --K; break;
485 case 2: --K; --I; break;
488 for (k = 1; k <= K; ++k ) {
489 for (j = 1; j <= J; ++j ) {
490 for (i = 1; i <= I; ++i ) {
495 case 1: // nodes for faces normal to i direction
500 case 2: // nodes for faces normal to j direction
505 default: // nodes for faces normal to k direction
510 nodeFNumbers [ ++indexF ] = n1;
511 nodeFNumbers [ ++indexF ] = n2;
512 nodeFNumbers [ ++indexF ] = n3;
513 nodeFNumbers [ ++indexF ] = n4;
515 if (ax != 1) ++iNode;
517 if (ax != 2) iNode += _iArrayLength;
520 if (nbFNodes != indexF+1) {
521 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Wrong nbFNodes : " \
522 << nbFNodes << " indexF : " << indexF ));
525 // fill edge node numbers
527 AX = hasEdges ? _spaceDimension : 0;
528 for (ax = 1; ax <= AX; ++ax) {
542 for (k = 1; k <= K; ++k ) {
543 for (j = 1; j <= J; ++j ) {
544 for (i = 1; i <= I; ++i ) {
549 case 1: // nodes for edges going along i direction
552 case 2: // nodes for edges going along j direction
553 n2 = n1 + _iArrayLength;
555 default: // nodes for edges going along k direction
558 nodeENumbers [ ++indexE ] = n1;
559 nodeENumbers [ ++indexE ] = n2;
561 if (ax == 1) ++iNode;
563 if (ax == 2) iNode += _iArrayLength;
566 if (nbENodes != indexE+1) {
567 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Wrong nbFNodes : " \
568 << nbENodes << " indexE : " << indexE ));
572 CONNECTIVITY * CellCNCT, * FaceCNCT, * EdgeCNCT;
574 // make connectivity for CELL
576 medGeometryElement aCellGeometry;
577 if (_kArrayLength) aCellGeometry = MED_HEXA8;
578 else if (_jArrayLength) aCellGeometry = MED_QUAD4;
579 else aCellGeometry = MED_SEG2;
582 CellCNCT = makeConnectivity (MED_CELL, aCellGeometry, nbCells, nbCNodes, nodeCNumbers);
584 delete [] nodeCNumbers;
588 // CellCNCT->_descending = new MEDSKYLINEARRAY() ;
589 int * skyLineArrayIndex = new int [nbCells + 1];
590 int nbEntitySub = CellCNCT->_type[0].getNumberOfConstituents(1);
591 for (i=0, j=1; i <= nbCells; ++i, j += nbEntitySub)
592 skyLineArrayIndex [ i ] = j;
593 // CellCNCT->_descending->setMEDSKYLINEARRAY (nbCells, nbSub,
594 // skyLineArrayIndex, subNumbers);
595 CellCNCT->_descending = new MEDSKYLINEARRAY (nbCells, nbSub,
598 delete [] skyLineArrayIndex;
600 delete [] subNumbers;
602 // reverse descending
604 // CellCNCT->_reverseDescendingConnectivity = new MEDSKYLINEARRAY() ;
606 int * skyLineArrayIndex = new int [nbSub + 1];
607 for (i=0, j=1; i <= nbSub; ++i, j += 2)
608 skyLineArrayIndex [ i ] = j;
609 // CellCNCT->_reverseDescendingConnectivity->setMEDSKYLINEARRAY
610 // (nbSub, nbRevSub, skyLineArrayIndex, subRevNumbers);
612 CellCNCT->_reverseDescendingConnectivity =
613 new MEDSKYLINEARRAY(nbSub, nbRevSub, skyLineArrayIndex, subRevNumbers);
615 delete [] skyLineArrayIndex;
617 delete [] subRevNumbers;
619 // make connectivity for FACE and/or EDGE
622 FaceCNCT = makeConnectivity (MED_FACE, MED_QUAD4, nbFaces, nbFNodes, nodeFNumbers);
624 delete [] nodeFNumbers;
626 CellCNCT->_constituent = FaceCNCT;
629 EdgeCNCT = makeConnectivity (MED_EDGE, MED_SEG2, nbEdges, nbENodes, nodeENumbers);
631 delete [] nodeENumbers;
634 FaceCNCT->_constituent = EdgeCNCT;
636 CellCNCT->_constituent = EdgeCNCT;
639 MESH::_connectivity = CellCNCT;
641 (const_cast <GRID *> (this))->_is_connectivity_filled = true;
646 //=======================================================================
647 //function : getArrayLength
648 //purpose : return array length. Axis = [1,2,3] meaning [i,j,k],
649 //=======================================================================
651 int GRID::getArrayLength( const int Axis ) const throw (MEDEXCEPTION)
654 case 1: return _iArrayLength;
655 case 2: return _jArrayLength;
656 case 3: return _kArrayLength;
658 throw MED_EXCEPTION ( LOCALIZED( STRING("GRID::getArrayLength ( ") << Axis << ")"));
663 //=======================================================================
664 //function : getArrayValue
665 //purpose : return i-th array component. Axis = [1,2,3] meaning [i,j,k],
666 // exception if Axis out of [1-3] range
667 // exception if i is out of range 0 <= i < getArrayLength(Axis);
668 //=======================================================================
670 const double GRID::getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION)
672 if (i < 0 || i >= getArrayLength(Axis))
674 ( LOCALIZED(STRING("GRID::getArrayValue ( ") << Axis << ", " << i << ")"));
677 case 1: return _iArray[ i ];
678 case 2: return _jArray[ i ];
679 default: return _kArray[ i ];
684 //=======================================================================
685 //function : getEdgeNumber
687 //=======================================================================
689 int GRID::getEdgeNumber(const int Axis, const int i, const int j, const int k)
690 const throw (MEDEXCEPTION)
692 const char * LOC = "GRID::getEdgeNumber(Axis, i,j,k) :";
696 int Len[4] = {0,_iArrayLength, _jArrayLength, _kArrayLength }, I=1, J=2, K=3;
697 int maxAxis = Len[ K ] ? 3 : 2;
699 if (Axis <= 0 || Axis > maxAxis)
700 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Axis out of range: " << Axis));
703 int Nb = 1 + i + j*Len[ I ] + k*Len[ J ]*Len[ K ];
709 if (Axis > 1) { // add all edges in i direction
711 Nb += Len[ I ]*Len[ J ]*Len[ K ];
714 if (Axis > 2) { // add all edges in j direction
716 Nb += Len[ I ]*Len[ J ]*Len[ K ];
724 //=======================================================================
725 //function : getFaceNumber
726 //purpose : return a NODE, EDGE, FACE, CELL number by its position in the grid.
727 // Axis [1,2,3] means one of directions: along i, j or k
728 // For Cell contituents (FACE or EDGE), Axis selects one of those having same (i,j,k):
729 // * a FACE which is normal to direction along given Axis;
730 // * an EDGE going along given Axis.
731 // Exception for Axis out of range
732 //=======================================================================
734 int GRID::getFaceNumber(const int Axis, const int i, const int j, const int k)
735 const throw (MEDEXCEPTION)
737 const char * LOC = "GRID::getFaceNumber(Axis, i,j,k) :";
741 // if (Axis <= 0 || Axis > 3)
742 if (Axis < 0 || Axis > 3)
743 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Axis = " << Axis));
745 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2, K=3;
748 int Nb = 1 + i + j*Len[ I ] + k*Len[ J ]*Len[ K ];
751 if (Axis > 1) { // add all faces in i direction
753 Nb += Len[ I ]*Len[ J ]*Len[ K ];
756 if (Axis > 2) { // add all faces in j direction
758 Nb += Len[ I ]*Len[ J ]*Len[ K ];
766 //=======================================================================
767 //function : getNodePosition
769 //=======================================================================
771 void GRID::getNodePosition(const int Number, int& i, int& j, int& k) const
774 const char * LOC = "GRID::getNodePosition(Number, i,j,k) :";
778 if (Number <= 0 || Number > _numberOfNodes)
779 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
781 int Len[] = {_iArrayLength, _jArrayLength, _kArrayLength }, I=0, J=1;
782 // , K=2; !! UNUSED VARIABLE !!
784 int ijLen = Len[I] * Len[J]; // nb in a full k layer
785 int kLen = (Number - 1) % ijLen; // nb in the non full k layer
789 k = (Number - 1) / ijLen;
791 ////cout <<" NODE POS: " << Number << " - " << i << ", " << j << ", " << k << endl;
797 //=======================================================================
798 //function : getCellPosition
800 //=======================================================================
802 void GRID::getCellPosition(const int Number, int& i, int& j, int& k) const
805 const char * LOC = "GRID::getCellPosition(Number, i,j,k) :";
809 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2;
810 // , K=3; !! UNUSED VARIABLE !!
812 // if (Number <= 0 || Number > getCellNumber(Len[I]-1, Len[J]-1, Len[K]-1))
813 // throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
815 int ijLen = Len[I] * Len[J]; // nb in a full k layer
816 int kLen = (Number - 1) % ijLen; // nb in the non full k layer
820 k = (Number - 1) / ijLen;
825 //=======================================================================
826 //function : getEdgePosition
828 //=======================================================================
830 void GRID::getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k)
831 const throw (MEDEXCEPTION)
833 const char * LOC = "GRID::getEdgePosition(Number, i,j,k) :";
838 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no edges in the grid: "));
841 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
843 int Len[4] = {0,_iArrayLength, _jArrayLength, _kArrayLength }, I=1, J=2, K=3;
846 int maxAxis = _kArrayLength ? 3 : 2;
848 for (Axis = 1; Axis <= maxAxis; ++Axis)
850 Len[Axis]--; // one less edge in Axis direction
852 // max edge number in Axis direction
853 int maxNb = getEdgeNumber (Axis, Len[I]-1, Len[J]-1, Len[K]-1);
870 int ijLen = Len[I] * Len[J]; // nb in a full k layer
871 int kLen = (theNb - 1) % ijLen; // nb in the non full k layer
874 k = (theNb - 1) / ijLen;
882 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
885 //=======================================================================
886 //function : getFacePosition
887 //purpose : return position (i,j,k) of an entity #Number
888 // Axis [1,2,3] means one of directions: along i, j or k
889 // For Cell contituents (FACE or EDGE), Axis selects one of those having same (i,j,k):
890 // * a FACE which is normal to direction along given Axis;
891 // * an EDGE going along given Axis.
892 // Exception for Number out of range
893 //=======================================================================
895 void GRID::getFacePosition(const int Number, int& Axis, int& i, int& j, int& k)
896 const throw (MEDEXCEPTION)
898 const char * LOC = "GRID::getFacePosition(Number, i,j,k) :";
902 if (_kArrayLength == 0) {
903 getCellPosition(Number, i, j, k);
909 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no faces in the grid: "));
912 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
914 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2, K=3;
917 for (Axis = 1; Axis <= 3; ++Axis)
921 // max face number in Axis direction
922 int maxNb = getFaceNumber (Axis, Len[I]-1, Len[J]-1, Len[K]-1);
939 int ijLen = Len[I] * Len[J]; // nb in a full k layer
940 int kLen = (theNb - 1) % ijLen; // nb in the non full k layer
943 k = (theNb - 1) / ijLen;
951 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
954 //=======================================================================
955 //function : writeUnstructured
956 //purpose : write a Grid as an Unstructured mesh
957 //=======================================================================
959 void GRID::writeUnstructured(int index, const string & driverName)
961 const char * LOC = "GRID::writeUnstructured(int index=0, const string & driverName) : ";
964 if ( _drivers[index] ) {
969 _drivers[index]->open();
970 if (driverName != "") _drivers[index]->setMeshName(driverName);
971 _drivers[index]->write();
972 _drivers[index]->close();
977 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
978 << "The index given is invalid, index must be between 0 and |"
985 void GRID::read(int index)
987 const char * LOC = "GRID::read(int index=0) : ";
990 if (_drivers[index]) {
991 _drivers[index]->open();
992 _drivers[index]->read();
993 _drivers[index]->close();
996 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
997 << "The index given is invalid, index must be between 0 and |"
1002 fillMeshAfterRead();