1 // File : MEDMEM_Grid.hxx
2 // Created : Wed Dec 18 08:35:26 2002
3 // Descr : class containing structured mesh data
5 // Author : Edward AGAPOV (eap)
6 // Project : SALOME Pro
8 // Copyright : Open CASCADE
12 #include "MEDMEM_Grid.hxx"
13 #include "MEDMEM_CellModel.hxx"
14 #include "MEDMEM_SkyLineArray.hxx"
17 using namespace MEDMEM;
18 using namespace MED_EN;
20 //=======================================================================
22 //purpose : empty constructor
23 //=======================================================================
27 MESSAGE("A GRID CREATED");
30 //=======================================================================
32 ////purpose : array constructor
33 ////=======================================================================
34 GRID::GRID(const std::vector<std::vector<double> >& xyz_array,const std::vector<std::string>& coord_name,
35 const std::vector<std::string>& coord_unit, const med_grid_type type) : _gridType(type)
37 _spaceDimension = xyz_array.size();
39 // compute & set _numberOfNodes
41 for(int i=0;i!=xyz_array.size();++i)
42 NumberOfNodes*=xyz_array[i].size();
43 _numberOfNodes = NumberOfNodes ;
45 // create a non allocated COORDINATE
46 _coordinate = new COORDINATE(_spaceDimension, &coord_name[0], &coord_unit[0]);
47 string coordinateSystem = "UNDEFINED";
48 if( _gridType == MED_CARTESIAN)
49 coordinateSystem = "CARTESIAN";
50 else if ( _gridType == MED_POLAR)
51 coordinateSystem = "CYLINDRICAL";
52 _coordinate->setCoordinatesSystem(coordinateSystem);
55 if (_spaceDimension>=1)
57 _iArrayLength=xyz_array[0].size();
58 _iArray=new double[_iArrayLength];
59 std::copy(xyz_array[0].begin(),xyz_array[0].end(),_iArray);
61 if (_spaceDimension>=2)
63 _jArrayLength=xyz_array[1].size();
64 _jArray=new double[_jArrayLength];
65 std::copy(xyz_array[1].begin(),xyz_array[1].end(),_jArray);
67 if (_spaceDimension>=3)
69 _kArrayLength=xyz_array[2].size();
70 _kArray=new double[_kArrayLength];
71 std::copy(xyz_array[2].begin(),xyz_array[2].end(),_kArray);
74 _is_coordinates_filled = false;
75 _is_connectivity_filled = false;
79 //=======================================================================
81 //purpose : empty constructor
82 //=======================================================================
84 GRID::GRID(const med_grid_type type)
88 MESSAGE("A TYPED GRID CREATED");
91 //=======================================================================
93 //purpose : copying constructor
94 //=======================================================================
96 GRID::GRID(const GRID& otherGrid) {
100 //=======================================================================
102 //purpose : destructor
103 //=======================================================================
106 MESSAGE("GRID::~GRID() : Destroying the Grid");
107 if ( _iArray != (double* ) NULL) delete [] _iArray;
108 if ( _jArray != (double* ) NULL) delete [] _jArray;
109 if ( _kArray != (double* ) NULL) delete [] _kArray;
112 //=======================================================================
115 //=======================================================================
119 _gridType = MED_CARTESIAN;
121 _iArray = _jArray = _kArray = (double* ) NULL;
122 _iArrayLength = _jArrayLength = _kArrayLength = 0;
124 _is_coordinates_filled = false;
125 _is_connectivity_filled = false;
132 //=======================================================================
133 //function: operator=
134 //purpose : operator=
135 //=======================================================================
137 GRID & GRID::operator=(const GRID & otherGrid)
141 MESH::operator=(otherGrid);
145 //=======================================================================
147 //purpose : Create a GRID object using a MESH driver of type
148 // (MED_DRIVER, ....) associated with file <fileName>.
149 //=======================================================================
151 GRID::GRID(driverTypes driverType, const string & fileName,
152 const string & driverName) : MESH(driverType, fileName, driverName)
154 const char * LOC ="GRID::GRID(driverTypes , const string & , const string &) : ";
161 // MESH(driverType,fileName,driverName);
163 // current = addDriver(driverType,fileName,driverName);
165 // switch(_drivers[current]->getAccessMode() ) {
167 // MESSAGE(LOC << "driverType must have a MED_RDWR accessMode");
168 // rmDriver(current);
172 // _drivers[current]->open();
173 // _drivers[current]->read();
174 // _drivers[current]->close();
176 // // fill some fields of MESH
177 // fillMeshAfterRead();
185 return the GRID Geometric type, without computing all connectivity
187 const medGeometryElement * GRID::getTypes(medEntityMesh entity) const
189 static const medGeometryElement _gridGeometry[4]={MED_HEXA8,MED_QUAD4,MED_SEG2,MED_POINT1};
195 else if(entity==MED_FACE && _spaceDimension>2 )
197 else if(entity==MED_EDGE && _spaceDimension>1 )
199 else if(entity==MED_NODE && _spaceDimension>0)
202 throw MEDEXCEPTION(LOCALIZED("CONNECTIVITY::getGeometricTypes : Entity not defined !"));
203 return &_gridGeometry[i];
206 //=======================================================================
207 //function : fillMeshAfterRead
209 //=======================================================================
211 void GRID::fillMeshAfterRead()
213 // fill not only MESH (:-)
214 _is_coordinates_filled = false;
215 _is_connectivity_filled = false;
217 if (_gridType == MED_BODY_FITTED)
219 _is_coordinates_filled = true;
221 // nb of nodes in each direction is not known, set anything
222 // in order to be able to work anyhow
223 // INFOS("GRID::fillMeshAfterRead(): This stub must be removed");
224 // switch (_spaceDimension) {
226 // _iArrayLength = _numberOfNodes;
227 // _jArrayLength = 0;
228 // _kArrayLength = 0;
231 // _iArrayLength = 2;
232 // _jArrayLength = _numberOfNodes / _iArrayLength;
233 // _kArrayLength = 0;
236 // _iArrayLength = 2;
237 // _jArrayLength = _numberOfNodes / _iArrayLength / 2;
238 // _kArrayLength = _numberOfNodes / _iArrayLength / _jArrayLength;
240 //cout << "ARRAY LENGTHS: " << _iArrayLength << " " << _jArrayLength
241 // << " " << _kArrayLength << endl;
244 // int NbNodes = _iArrayLength;
245 // if (_jArrayLength)
246 // NbNodes *= _jArrayLength;
247 // if (_kArrayLength)
248 // NbNodes *= _kArrayLength;
249 // MESH::_numberOfNodes = NbNodes;
252 MESH::_meshDimension = MESH::_spaceDimension;
255 //=======================================================================
256 //function : fillCoordinates
258 //=======================================================================
260 void GRID::fillCoordinates() const
262 if (_is_coordinates_filled)
265 const char * LOC ="GRID::fillCoordinates()";
268 // if coordonate has not been allocated, perform shalow copy, transfer ownership of matrix
269 if(_coordinate->getSpaceDimension()*_coordinate->getNumberOfNodes() == 0)
270 _coordinate->setCoordinates(new MEDARRAY<double>(_spaceDimension,_numberOfNodes,MED_FULL_INTERLACE),true);
272 double* myCoord = const_cast <double *> ( _coordinate->getCoordinates(MED_FULL_INTERLACE) );
274 bool hasJ = _jArrayLength, hasK = _kArrayLength;
275 int J = hasJ ? _jArrayLength : 1;
276 int K = hasK ? _kArrayLength : 1;
277 //int nb, !! UNUSED VARIABLE !!
279 for (k=0; k < K; ++k) {
280 for (j=0; j < J; ++j) {
281 for (i=0; i < _iArrayLength; ++i) {
283 * myCoord = _iArray[ i ];
288 * myCoord = _jArray[ j ];
293 * myCoord = _kArray[ k ];
301 (const_cast <GRID *> (this))->_is_coordinates_filled = true;
305 //=======================================================================
306 //function : makeConnectivity
308 //=======================================================================
310 CONNECTIVITY * GRID::makeConnectivity (medEntityMesh Entity,
311 medGeometryElement Geometry,
315 const int * NodeNumbers)
318 CONNECTIVITY * Connectivity = new CONNECTIVITY(Entity) ;
319 Connectivity->_numberOfNodes = nbMeshNodes ;
320 Connectivity->_entityDimension = Geometry/100 ;
322 int numberOfGeometricType = 1;
323 Connectivity->_numberOfTypes = numberOfGeometricType;
325 Connectivity->_count = new int [numberOfGeometricType + 1] ;
326 Connectivity->_count[0] = 1;
327 Connectivity->_count[1] = 1 + NbEntities;
329 Connectivity->_type = new CELLMODEL [numberOfGeometricType];
330 Connectivity->_type[0] = CELLMODEL( Geometry ) ;
332 Connectivity->_geometricTypes = new medGeometryElement [ numberOfGeometricType ];
333 Connectivity->_geometricTypes[0] = Geometry;
335 // Connectivity->_nodal = new MEDSKYLINEARRAY() ;
336 int * skyLineArrayIndex = new int [NbEntities + 1];
337 int i, j, nbEntityNodes = Connectivity->_type[0].getNumberOfNodes();
338 for (i=0, j=1; i <= NbEntities; ++i, j += nbEntityNodes)
339 skyLineArrayIndex [ i ] = j;
341 // Connectivity->_nodal->setMEDSKYLINEARRAY (NbEntities, NbNodes,
342 //skyLineArrayIndex, NodeNumbers);
344 Connectivity->_nodal = new MEDSKYLINEARRAY (NbEntities, NbNodes,
345 skyLineArrayIndex, NodeNumbers);
347 delete [] skyLineArrayIndex;
349 // test connectivity right away
350 // for (med_int j = 0; j < numberOfGeometricType; j++)
352 // int node_number = Connectivity->_type[j].getNumberOfNodes();
353 // for (med_int k = Connectivity->_count[j]; k < Connectivity->_count[j+1]; k++)
354 // for (med_int local_node_number = 1 ; local_node_number < node_number+1; local_node_number++)
356 // cout << "MEDSKYLINEARRAY::getIJ(" << k << ", " << local_node_number << endl;
357 // med_int global_node = Connectivity->_nodal->getIJ(k,local_node_number) ;
358 // cout << "...= " << global_node << endl;
365 //=======================================================================
366 //function : fillConnectivity
367 //purpose : fill _coordinates and _connectivity of MESH if not yet done
368 //=======================================================================
370 void GRID::fillConnectivity() const
372 if (_is_connectivity_filled)
374 MESSAGE("GRID::fillConnectivity(): Already filled");
378 const char * LOC = "GRID::fillConnectivity() ";
381 int nbCells, nbFaces, nbEdges;
382 int nbCNodes, nbFNodes, nbENodes, nbMeshNodes;
383 int indexC, indexF, indexE;
384 int * nodeCNumbers, * nodeFNumbers, * nodeENumbers;
385 // about descending connectivity
386 int nbSub, nbRevSub, indexSub, indexRevSub, * subNumbers, * subRevNumbers;
388 bool hasFaces = _kArrayLength, hasEdges = _jArrayLength;
390 int iLenMin1 = _iArrayLength-1, jLenMin1 = _jArrayLength-1;
391 int kLenMin1 = _kArrayLength-1, ijLenMin1 = iLenMin1 * jLenMin1;
392 if (!hasEdges) jLenMin1 = 1;
393 if (!hasFaces) kLenMin1 = 1;
395 // nb of cells and of their connectivity nodes
397 nbCells = iLenMin1 * jLenMin1 * kLenMin1;
398 nbMeshNodes = _iArrayLength * (_jArrayLength ? _jArrayLength : 1) * (_kArrayLength ? _kArrayLength : 1);
399 nbCNodes = nbCells * 2 * (hasEdges ? 2 : 1) * (hasFaces ? 2 : 1);
400 nodeCNumbers = new int [ nbCNodes ];
402 // nb of faces and of their connectivity nodes
405 nbFaces = _iArrayLength * jLenMin1 * kLenMin1;
406 nbFaces += _jArrayLength * kLenMin1 * iLenMin1;
407 nbFaces += _kArrayLength * iLenMin1 * jLenMin1;
408 nbFNodes = nbFaces * 4;
409 nodeFNumbers = new int [ nbFNodes ];
411 nbFaces = nbFNodes = 0;
413 // nb of edges and of their connectivity nodes
416 if (_kArrayLength) { // 3d grid
417 nbEdges = iLenMin1 * _jArrayLength * _kArrayLength;
418 nbEdges += jLenMin1 * _kArrayLength * _iArrayLength;
419 nbEdges += kLenMin1 * _iArrayLength * _jArrayLength;
421 else if (_jArrayLength) { // 2d
422 nbEdges = iLenMin1 * _jArrayLength;
423 nbEdges += jLenMin1 * _iArrayLength;
425 nbENodes = nbEdges * 2;
426 nodeENumbers = new int [ nbENodes ];
428 nbEdges = nbENodes = 0;
430 // nb of descending connectivity Elements
435 nbRevSub = nbFaces * 2;
440 nbRevSub = nbEdges * 2;
442 subNumbers = new int [ nbSub ];
443 subRevNumbers = new int [ nbRevSub ];
444 for (int r=0; r<nbRevSub; ++r)
445 subRevNumbers[ r ] = 0;
447 int nSubI = 1, nSubJ, nSubK; // subelement numbers
450 nSubJ = getFaceNumber(2, 0, 0, 0);
451 nSubK = getFaceNumber(3, 0, 0, 0);
454 nSubJ = getEdgeNumber(2, 0, 0, 0);
457 // fill cell node numbers and descending element numbers
460 indexC = indexF = indexE = indexSub = indexRevSub = -1;
461 int iNode = 0, iCell = 0;
462 int ijLen = _iArrayLength * _jArrayLength;
463 int i, j, k, n1, n2, n3 ,n4;
465 int I = _iArrayLength;
466 int J = _jArrayLength ? _jArrayLength : 2; // pass at least once
467 int K = _kArrayLength ? _kArrayLength : 2;
468 // pass by all but last nodes in all directions
469 for (k = 1; k < K; ++k ) {
470 for (j = 1; j < J; ++j ) {
471 for (i = 1; i < I; ++i ) {
475 n1 = ++iNode; // iNode
477 nodeCNumbers [ ++indexC ] = n1;
478 nodeCNumbers [ ++indexC ] = n2;
480 if (hasEdges) { // at least 2d
483 nodeCNumbers [ ++indexC ] = n3;
484 nodeCNumbers [ ++indexC ] = n4;
486 if (hasFaces) { // 3d
487 nodeCNumbers [ ++indexC ] = n1 + ijLen;
488 nodeCNumbers [ ++indexC ] = n2 + ijLen;
489 nodeCNumbers [ ++indexC ] = n3 + ijLen;
490 nodeCNumbers [ ++indexC ] = n4 + ijLen;
497 subNumbers [ ++indexSub ] = n1;
498 subRevNumbers[ n3 ] = iCell;
499 subNumbers [ ++indexSub ] = n2;
500 subRevNumbers[ n4 ] = -iCell;
505 subNumbers [ ++indexSub ] = n1;
506 subRevNumbers[ n3 ] = iCell;
507 subNumbers [ ++indexSub ] = n2;
508 subRevNumbers[ n4 ] = -iCell;
513 subNumbers [ ++indexSub ] = n1;
514 subRevNumbers[ n3 ] = iCell;
515 subNumbers [ ++indexSub ] = n2;
516 subRevNumbers[ n4 ] = -iCell;
525 subNumbers [ ++indexSub ] = n1;
526 subRevNumbers[ n3 ] = iCell;
527 subNumbers [ ++indexSub ] = n2;
528 subRevNumbers[ n4 ] = -iCell;
533 subNumbers [ ++indexSub ] = n1;
534 subRevNumbers[ n3 ] = iCell;
535 subNumbers [ ++indexSub ] = n2;
536 subRevNumbers[ n4 ] = -iCell;
538 ++nSubI; ++nSubJ; ++nSubK;
540 ++iNode; // skip the last node in a row
546 iNode += I; // skip the whole last row
549 // fill face node numbers
551 int ax, AX = hasFaces ? 3 : 0;
552 for (ax = 1; ax <= AX; ++ax) {
560 case 1: --J; --K; break;
561 case 2: --K; --I; break;
564 for (k = 1; k <= K; ++k ) {
565 for (j = 1; j <= J; ++j ) {
566 for (i = 1; i <= I; ++i ) {
571 case 1: // nodes for faces normal to i direction
576 case 2: // nodes for faces normal to j direction
581 default: // nodes for faces normal to k direction
586 nodeFNumbers [ ++indexF ] = n1;
587 nodeFNumbers [ ++indexF ] = n2;
588 nodeFNumbers [ ++indexF ] = n3;
589 nodeFNumbers [ ++indexF ] = n4;
591 if (ax != 1) ++iNode;
593 if (ax != 2) iNode += _iArrayLength;
596 if (nbFNodes != indexF+1) {
597 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Wrong nbFNodes : " \
598 << nbFNodes << " indexF : " << indexF ));
601 // fill edge node numbers
603 AX = hasEdges ? _spaceDimension : 0;
604 for (ax = 1; ax <= AX; ++ax) {
618 for (k = 1; k <= K; ++k ) {
619 for (j = 1; j <= J; ++j ) {
620 for (i = 1; i <= I; ++i ) {
625 case 1: // nodes for edges going along i direction
628 case 2: // nodes for edges going along j direction
629 n2 = n1 + _iArrayLength;
631 default: // nodes for edges going along k direction
634 nodeENumbers [ ++indexE ] = n1;
635 nodeENumbers [ ++indexE ] = n2;
637 if (ax == 1) ++iNode;
639 if (ax == 2) iNode += _iArrayLength;
642 if (nbENodes != indexE+1) {
643 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Wrong nbFNodes : " \
644 << nbENodes << " indexE : " << indexE ));
648 CONNECTIVITY * CellCNCT, * FaceCNCT, * EdgeCNCT;
650 // make connectivity for CELL
652 medGeometryElement aCellGeometry;
653 if (_kArrayLength) aCellGeometry = MED_HEXA8;
654 else if (_jArrayLength) aCellGeometry = MED_QUAD4;
655 else aCellGeometry = MED_SEG2;
658 CellCNCT = makeConnectivity (MED_CELL, aCellGeometry, nbCells, nbCNodes, nbMeshNodes, nodeCNumbers);
660 delete [] nodeCNumbers;
664 // CellCNCT->_descending = new MEDSKYLINEARRAY() ;
665 int * skyLineArrayIndex = new int [nbCells + 1];
666 int nbEntitySub = CellCNCT->_type[0].getNumberOfConstituents(1);
667 for (i=0, j=1; i <= nbCells; ++i, j += nbEntitySub)
668 skyLineArrayIndex [ i ] = j;
669 // CellCNCT->_descending->setMEDSKYLINEARRAY (nbCells, nbSub,
670 // skyLineArrayIndex, subNumbers);
671 CellCNCT->_descending = new MEDSKYLINEARRAY (nbCells, nbSub,
674 delete [] skyLineArrayIndex;
676 delete [] subNumbers;
678 // reverse descending
680 // CellCNCT->_reverseDescendingConnectivity = new MEDSKYLINEARRAY() ;
682 int * skyLineArrayIndex = new int [nbSub + 1];
683 for (i=0, j=1; i <= nbSub; ++i, j += 2)
684 skyLineArrayIndex [ i ] = j;
685 // CellCNCT->_reverseDescendingConnectivity->setMEDSKYLINEARRAY
686 // (nbSub, nbRevSub, skyLineArrayIndex, subRevNumbers);
688 CellCNCT->_reverseDescendingConnectivity =
689 new MEDSKYLINEARRAY(nbSub, nbRevSub, skyLineArrayIndex, subRevNumbers);
691 delete [] skyLineArrayIndex;
693 delete [] subRevNumbers;
695 // make connectivity for FACE and/or EDGE
698 FaceCNCT = makeConnectivity (MED_FACE, MED_QUAD4, nbFaces, nbFNodes, nbMeshNodes, nodeFNumbers);
700 delete [] nodeFNumbers;
702 CellCNCT->_constituent = FaceCNCT;
705 EdgeCNCT = makeConnectivity (MED_EDGE, MED_SEG2, nbEdges, nbENodes, nbMeshNodes, nodeENumbers);
707 delete [] nodeENumbers;
710 FaceCNCT->_constituent = EdgeCNCT;
712 CellCNCT->_constituent = EdgeCNCT;
715 MESH::_connectivity = CellCNCT;
717 (const_cast <GRID *> (this))->_is_connectivity_filled = true;
722 //=======================================================================
723 //function : getArrayLength
724 //purpose : return array length. Axis = [1,2,3] meaning [i,j,k],
725 //=======================================================================
727 int GRID::getArrayLength( const int Axis ) const throw (MEDEXCEPTION)
730 case 1: return _iArrayLength;
731 case 2: return _jArrayLength;
732 case 3: return _kArrayLength;
734 throw MED_EXCEPTION ( LOCALIZED( STRING("GRID::getArrayLength ( ") << Axis << ")"));
739 //=======================================================================
740 //function : getArrayValue
741 //purpose : return i-th array component. Axis = [1,2,3] meaning [i,j,k],
742 // exception if Axis out of [1-3] range
743 // exception if i is out of range 0 <= i < getArrayLength(Axis);
744 //=======================================================================
746 const double GRID::getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION)
748 if (i < 0 || i >= getArrayLength(Axis))
750 ( LOCALIZED(STRING("GRID::getArrayValue ( ") << Axis << ", " << i << ")"));
753 case 1: return _iArray[ i ];
754 case 2: return _jArray[ i ];
755 default: return _kArray[ i ];
760 //=======================================================================
761 //function : getEdgeNumber
763 //=======================================================================
765 int GRID::getEdgeNumber(const int Axis, const int i, const int j, const int k)
766 const throw (MEDEXCEPTION)
768 const char * LOC = "GRID::getEdgeNumber(Axis, i,j,k) :";
772 int Len[4] = {0,_iArrayLength, _jArrayLength, _kArrayLength }, I=1, J=2, K=3;
773 int maxAxis = Len[ K ] ? 3 : 2;
775 if (Axis <= 0 || Axis > maxAxis)
776 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Axis out of range: " << Axis));
779 int Nb = 1 + i + j*Len[ I ] + k*Len[ J ]*Len[ K ];
785 if (Axis > 1) { // add all edges in i direction
787 Nb += Len[ I ]*Len[ J ]*Len[ K ];
790 if (Axis > 2) { // add all edges in j direction
792 Nb += Len[ I ]*Len[ J ]*Len[ K ];
800 //=======================================================================
801 //function : getFaceNumber
802 //purpose : return a NODE, EDGE, FACE, CELL number by its position in the grid.
803 // Axis [1,2,3] means one of directions: along i, j or k
804 // For Cell contituents (FACE or EDGE), Axis selects one of those having same (i,j,k):
805 // * a FACE which is normal to direction along given Axis;
806 // * an EDGE going along given Axis.
807 // Exception for Axis out of range
808 //=======================================================================
810 int GRID::getFaceNumber(const int Axis, const int i, const int j, const int k)
811 const throw (MEDEXCEPTION)
813 const char * LOC = "GRID::getFaceNumber(Axis, i,j,k) :";
817 // if (Axis <= 0 || Axis > 3)
818 if (Axis < 0 || Axis > 3)
819 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Axis = " << Axis));
821 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2, K=3;
824 int Nb = 1 + i + j*Len[ I ] + k*Len[ J ]*Len[ K ];
827 if (Axis > 1) { // add all faces in i direction
829 Nb += Len[ I ]*Len[ J ]*Len[ K ];
832 if (Axis > 2) { // add all faces in j direction
834 Nb += Len[ I ]*Len[ J ]*Len[ K ];
842 //=======================================================================
843 //function : getNodePosition
845 //=======================================================================
847 void GRID::getNodePosition(const int Number, int& i, int& j, int& k) const
850 const char * LOC = "GRID::getNodePosition(Number, i,j,k) :";
854 if (Number <= 0 || Number > _numberOfNodes)
855 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
857 int Len[] = {_iArrayLength, _jArrayLength, _kArrayLength }, I=0, J=1;
858 // , K=2; !! UNUSED VARIABLE !!
860 int ijLen = Len[I] * Len[J]; // nb in a full k layer
861 int kLen = (Number - 1) % ijLen; // nb in the non full k layer
865 k = (Number - 1) / ijLen;
867 ////cout <<" NODE POS: " << Number << " - " << i << ", " << j << ", " << k << endl;
873 //=======================================================================
874 //function : getCellPosition
876 //=======================================================================
878 void GRID::getCellPosition(const int Number, int& i, int& j, int& k) const
881 const char * LOC = "GRID::getCellPosition(Number, i,j,k) :";
885 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2;
886 // , K=3; !! UNUSED VARIABLE !!
888 // if (Number <= 0 || Number > getCellNumber(Len[I]-1, Len[J]-1, Len[K]-1))
889 // throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
891 int ijLen = Len[I] * Len[J]; // nb in a full k layer
892 int kLen = (Number - 1) % ijLen; // nb in the non full k layer
896 k = (Number - 1) / ijLen;
901 //=======================================================================
902 //function : getEdgePosition
904 //=======================================================================
906 void GRID::getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k)
907 const throw (MEDEXCEPTION)
909 const char * LOC = "GRID::getEdgePosition(Number, i,j,k) :";
914 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no edges in the grid: "));
917 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
919 int Len[4] = {0,_iArrayLength, _jArrayLength, _kArrayLength }, I=1, J=2, K=3;
922 int maxAxis = _kArrayLength ? 3 : 2;
924 for (Axis = 1; Axis <= maxAxis; ++Axis)
926 Len[Axis]--; // one less edge in Axis direction
928 // max edge number in Axis direction
929 int maxNb = getEdgeNumber (Axis, Len[I]-1, Len[J]-1, Len[K]-1);
946 int ijLen = Len[I] * Len[J]; // nb in a full k layer
947 int kLen = (theNb - 1) % ijLen; // nb in the non full k layer
950 k = (theNb - 1) / ijLen;
958 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
961 //=======================================================================
962 //function : getFacePosition
963 //purpose : return position (i,j,k) of an entity #Number
964 // Axis [1,2,3] means one of directions: along i, j or k
965 // For Cell contituents (FACE or EDGE), Axis selects one of those having same (i,j,k):
966 // * a FACE which is normal to direction along given Axis;
967 // * an EDGE going along given Axis.
968 // Exception for Number out of range
969 //=======================================================================
971 void GRID::getFacePosition(const int Number, int& Axis, int& i, int& j, int& k)
972 const throw (MEDEXCEPTION)
974 const char * LOC = "GRID::getFacePosition(Number, i,j,k) :";
978 if (_kArrayLength == 0) {
979 getCellPosition(Number, i, j, k);
985 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "no faces in the grid: "));
988 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
990 int Len[4] = {0,_iArrayLength-1, _jArrayLength-1, _kArrayLength-1 }, I=1, J=2, K=3;
993 for (Axis = 1; Axis <= 3; ++Axis)
997 // max face number in Axis direction
998 int maxNb = getFaceNumber (Axis, Len[I]-1, Len[J]-1, Len[K]-1);
1015 int ijLen = Len[I] * Len[J]; // nb in a full k layer
1016 int kLen = (theNb - 1) % ijLen; // nb in the non full k layer
1019 k = (theNb - 1) / ijLen;
1027 throw MED_EXCEPTION ( LOCALIZED(STRING(LOC) << "Number is out of range: " << Number));
1030 //=======================================================================
1031 //function : writeUnstructured
1032 //purpose : write a Grid as an Unstructured mesh
1033 //=======================================================================
1035 void GRID::writeUnstructured(int index, const string & driverName)
1037 const char * LOC = "GRID::writeUnstructured(int index=0, const string & driverName) : ";
1040 if ( _drivers[index] ) {
1045 _drivers[index]->open();
1046 if (driverName != "") _drivers[index]->setMeshName(driverName);
1047 _drivers[index]->write();
1048 _drivers[index]->close();
1053 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
1054 << "The index given is invalid, index must be between 0 and |"
1061 void GRID::read(int index)
1063 const char * LOC = "GRID::read(int index=0) : ";
1066 if (_drivers[index]) {
1067 _drivers[index]->open();
1068 _drivers[index]->read();
1069 _drivers[index]->close();
1072 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
1073 << "The index given is invalid, index must be between 0 and |"
1078 fillMeshAfterRead();