Back to index

salome-med  6.5.0
MEDMEM_Grid.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File      : MEDMEM_Grid.hxx
00024 // Created   : Wed Dec 18 08:35:26 2002
00025 // Descr     : class containing structured mesh data
00026 // Author    : Edward AGAPOV (eap)
00027 // Project   : SALOME Pro
00028 // Module    : MED 
00029 //
00030 #ifndef MEDMEM_Grid_HeaderFile
00031 #define MEDMEM_Grid_HeaderFile
00032 
00033 #include <MEDMEM.hxx>
00034 
00035 #include "MEDMEM_Mesh.hxx"
00036 
00037 // class containing structured mesh data
00038 
00039 namespace MEDMEM {
00040 class MEDMEM_EXPORT GRID: public GMESH
00041 {
00042  protected:
00043   //-----------------------//
00044   //   Fields
00045   //-----------------------//
00046   
00047   // 1. grid type: MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED
00048   MED_EN::med_grid_type     _gridType;
00049   
00050   // 2. node coordinates for MED_BODY_FITTED and coordinate names, units etc.
00051   COORDINATE*       _coordinate;
00052 
00053   // 2.1. i component array: X for MED_CARTESIAN, R for MED_POLAR
00054   int               _iArrayLength;
00055   double*           _iArray;
00056   // 2.2. j component array: Y for MED_CARTESIAN, Theta for MED_POLAR
00057   int               _jArrayLength;
00058   double*           _jArray;
00059   // 2.3. k component array: Z for both MED_CARTESIAN and MED_POLAR
00060   int               _kArrayLength;
00061   double*           _kArray;
00062 
00063   // 3. is _gridType a true value or just a default one
00064   bool              _is_default_gridType;
00065 
00066   // Suppose a READ Driver to do the following except filling _[ijk]Array's
00067   // 1) fill GMESH fields:
00068   //    * _name
00069   //    * _spaceDimension
00070   //    * _numberOfNodesFamilies, _numberOfCellsFamilies, ect
00071   //    * _familyNode, _familyCell, etc
00072   //    * _numberOfNodesGroups, _numberOfCellsGroups, etc
00073   //    * _groupNode, _groupCell, etc
00074   //    * _
00075   // 2) create _coordinate without setting _coordinate->_coordinate and set: 
00076   //    * _coordinate->_coordinateSystem
00077   //    * _coordinate->_coordinateName
00078   //    * _coordinate->_coordinateUnit
00079  protected:
00080   virtual bool isEmpty() const;
00081 
00082 
00083  public:
00084   //-----------------------//
00085   //   Public Methods
00086   //-----------------------//
00087 
00088   GRID();
00089   GRID(const MED_EN::med_grid_type type);
00090   GRID(const GRID &m);
00091   GRID( driverTypes driverType, const string & fileName,const string & meshName);
00092   GRID(const std::vector<std::vector<double> >& xyz_array,
00093        const std::vector<std::string>&          coord_name,
00094        const std::vector<std::string>&          coord_unit,
00095        const MED_EN::med_grid_type              type=MED_EN::MED_CARTESIAN);
00096   GRID & operator=(const GRID &m);
00097   virtual ~GRID();
00098   virtual void init();
00099   virtual bool deepCompare(const GMESH& other) const;
00100   virtual void printMySelf(std::ostream &os) const;
00101 
00102   virtual const MESH *        convertInMESH() const;
00103 
00104   virtual int                 getMeshDimension() const;
00105   virtual bool                getIsAGrid() const;
00106   virtual int                 getNumberOfNodes() const;
00107 
00108   virtual std::string         getCoordinatesSystem() const;
00109   virtual const std::string * getCoordinatesNames() const;
00110   virtual const std::string * getCoordinatesUnits() const;
00111 
00112   virtual int                 getNumberOfTypes(MED_EN::medEntityMesh Entity) const;
00113   virtual int                 getNumberOfElements(MED_EN::medEntityMesh      Entity,
00114                                                   MED_EN::medGeometryElement Type) const;
00115   virtual const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const;
00116   virtual MED_EN::medGeometryElement getElementType(MED_EN::medEntityMesh Entity,
00117                                                     int                   Number) const;
00118 
00119   virtual SUPPORT *                  getBoundaryElements(MED_EN::medEntityMesh Entity) const
00120                                                 throw (MEDEXCEPTION);
00121   virtual SUPPORT *                  getSkin(const SUPPORT * Support3D)
00122                                                 throw (MEDEXCEPTION);
00123   virtual SUPPORT *buildSupportOnNodeFromElementList(const std::list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION);
00124   virtual void     fillSupportOnNodeFromElementList(const std::list<int>& listOfElt, SUPPORT *supportToFill) const throw (MEDEXCEPTION);
00125 
00126   virtual FIELD<double>* getVolume (const SUPPORT * Support, bool isAbs = true) const
00127                                 throw (MEDEXCEPTION);
00128                                 // Support must be on 3D elements
00129   virtual FIELD<double>* getArea (const SUPPORT * Support) const
00130                                 throw (MEDEXCEPTION);
00131                                 // Support must be on 2D elements
00132   virtual FIELD<double>* getLength (const SUPPORT * Support) const
00133                                 throw (MEDEXCEPTION);
00134                                 // Support must be on 1D elements
00135   virtual FIELD<double>* getNormal (const SUPPORT * Support) const
00136                                 throw (MEDEXCEPTION);
00137                                 // Support must be on 2D elements
00138   virtual FIELD<double>* getBarycenter (const SUPPORT * Support) const
00139                                 throw (MEDEXCEPTION);
00140   
00141   virtual vector< vector<double> >   getBoundingBox() const;
00142 
00143 
00144   // Specific GRID methods
00145   //-----------------------//
00146 
00147   inline int getNodeNumber(const int i, const int j=0, const int k=0) const;
00148   // return a NODE number by its position in the grid.
00149   // WARNING: be carefull, there is no check that i,j,k are within a good range
00150   // A good range is: 0 <= X < getArrayLength( X_Axis )
00151 
00152   inline int getCellNumber(const int i, const int j=0, const int k=0) const ;
00153   // return a CELL number by its position in the grid.
00154   // WARNING: be carefull, there is no check that i,j,k are within a good range
00155   // A good range is: 0 <= X < (getArrayLength( X_Axis )-1)
00156 
00157   int getEdgeNumber(const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION) ;
00158   // return an EDGE number by its position in the grid.
00159   // Axis [1,2,3] means one of directions: along i, j or k.
00160   // It selects an edge of ones having same (i,j,k):
00161   //  * an EDGE going along given Axis.
00162   // Exception for Axis out of range or when there is no edges in the grid (1D)
00163   // WARNING: be carefull, there is no check that i,j,k are within a good range
00164   // A good range is:
00165   // 0 <= X < (getArrayLength( X_Axis )-1)
00166   // 0 <= X < getArrayLength( NOT_X_Axis )
00167 
00168   int getFaceNumber(const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION) ;
00169   // return a FACE number by its position in the grid.
00170   // Axis [1,2,3] means one of directions: along i, j or k.
00171   // It selects a face of ones having same (i,j,k):
00172   //  * a FACE which is normal to given Axis
00173   // Exception for Axis out of range or when there is no faces in the grid (1,2D)
00174   // WARNING: be carefull, there is no check that i,j,k are within a good range
00175   // A good range is:
00176   // 0 <= X < (getArrayLength( NOT_X_Axis )-1)
00177   // 0 <= X < getArrayLength( X_Axis )
00178   
00179 
00180   void getNodePosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
00181   void getCellPosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
00182   void getEdgePosition(const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
00183   void getFacePosition(const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION) ;
00184   // return position (i,j,k) of an entity #Number
00185   // Axis: [1,2,3], see get*Number for details
00186   // Exception for Number out of range
00187 
00188 
00189   //  Access to fields
00190   //-----------------------//
00191 
00192   inline MED_EN::med_grid_type getGridType() const;
00193   // return MED_CARTESIAN, MED_POLAR or MED_BODY_FITTED
00194 
00195   int getArrayLength( const int Axis ) const throw (MEDEXCEPTION);
00196   // return array length. Axis = [1,2,3] meaning [i,j,k],
00197   // exception if Axis out of [1-3] range
00198 
00199   const double getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION) ;
00200   // return i-th array component. Axis = [1,2,3] meaning [i,j,k],
00201   // exception if Axis out of [1 - 3] range
00202   // exception if i is out of range [0 - (getArrayLength(Axis)-1)];
00203 
00204   inline void setGridType(MED_EN::med_grid_type gridType);
00205 
00206 
00207   friend class MED_MESH_RDONLY_DRIVER;
00208   friend class MED_MESH_WRONLY_DRIVER;
00209   friend class ENSIGHT_MESH_RDONLY_DRIVER;
00210 };
00211 
00212 
00213   //----------------------------------//
00214   //   Inline Methods Implementation
00215   //----------------------------------//
00216 
00217 inline MED_EN::med_grid_type GRID::getGridType() const
00218 {
00219   return _gridType;
00220 }
00221 //=======================================================================
00222 //function : getNodeNumber
00223 //purpose  : 
00224 //=======================================================================
00225 
00226 inline int GRID::getNodeNumber(const int i, const int j, const int k) const
00227 {
00228   return 1 + i + _iArrayLength * j + _iArrayLength * _jArrayLength * k;
00229 }
00230 
00231 //=======================================================================
00232 //function : getCellNumber
00233 //purpose  : 
00234 //=======================================================================
00235 
00236 inline int GRID::getCellNumber(const int i, const int j, const int k) const
00237 {
00238   return 1 + i + (_iArrayLength-1) * j + (_iArrayLength-1) * (_jArrayLength-1) * k;
00239 }
00240 
00241 //=======================================================================
00242 //function : setGridType
00243 //purpose : set the _gridType field od the class GRID
00244 //=======================================================================
00245 
00246 inline void GRID::setGridType(MED_EN::med_grid_type gridType)
00247 {
00248   _gridType = gridType;
00249 }
00250 
00251 }
00252 
00253 #endif