Back to index

salome-med  6.5.0
MEDMEM_Mesh.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 #ifndef MESH_HXX
00024 #define MESH_HXX
00025 
00026 #include <MEDMEM.hxx>
00027 
00028 #include <string>
00029 #include <vector>
00030 #include <list>
00031 #include <map>
00032 
00033 #include "MEDMEM_GMesh.hxx"
00034 #include "MEDMEM_Utilities.hxx"
00035 #include "MEDMEM_STRING.hxx"
00036 #include "MEDMEM_Exception.hxx"
00037 #include "MEDMEM_define.hxx"
00038 #include "MEDMEM_Coordinate.hxx"
00039 #include "MEDMEM_Connectivity.hxx"
00040 #include "MEDMEM_GenDriver.hxx"
00041 #include "MEDMEM_RCBase.hxx"
00042 #include "MEDMEM_FieldForward.hxx"
00043 
00044 namespace MEDMEM {
00045 
00046 class CELLMODEL;
00047 class FAMILY;
00048 class GROUP;
00049 class SUPPORT;
00050 class MESH;
00051 
00052 MEDMEM_EXPORT ostream & operator<<(ostream &os, const MESH &my);
00053 
00059 class MEDMEM_EXPORT MESH : public GMESH
00060 {
00061   //-----------------------//
00062   //   Attributes
00063   //-----------------------//
00064 
00065 protected :
00066 
00067   int   _numberOfNodes;
00068   mutable COORDINATE *   _coordinate;
00069   mutable CONNECTIVITY * _connectivity;
00070 
00081 
00082   int _arePresentOptionnalNodesNumbers;
00083   map<int,int> _optionnalToCanonicNodesNumbers;
00084 
00085   //-----------------------//
00086   //   Methods
00087   //-----------------------//
00088 
00089  public :
00090 
00091   // Add your personnal driver line (step 2)
00092   friend class MED_MESH_RDONLY_DRIVER;
00093   friend class MED_MESH_WRONLY_DRIVER;
00094 
00095   friend class MED_MED_RDONLY_DRIVER21;
00096   friend class MED_MED_WRONLY_DRIVER21;
00097   friend class MED_MED_RDWR_DRIVER21;
00098   friend class MED_MED_RDONLY_DRIVER22;
00099   friend class MED_MED_WRONLY_DRIVER22;
00100   friend class MED_MED_RDWR_DRIVER22;
00101 
00102   friend class GIBI_MESH_RDONLY_DRIVER;
00103   friend class GIBI_MESH_WRONLY_DRIVER;
00104   friend class GIBI_MESH_RDWR_DRIVER;
00105 
00106   friend class PORFLOW_MESH_RDONLY_DRIVER;
00107   friend class PORFLOW_MESH_WRONLY_DRIVER;
00108   friend class PORFLOW_MESH_RDWR_DRIVER;
00109 
00110   friend class VTK_MESH_DRIVER;
00111 
00112   friend class ENSIGHT_MESH_RDONLY_DRIVER;
00113 
00114  public:
00115   MESH();
00116   MESH(MESH &m);
00117   virtual ~MESH();
00118   MESH( driverTypes driverType, const string & fileName="",
00119         const string & meshName="") throw (MEDEXCEPTION);
00120  public:
00121   void init();
00122   MESH & operator=(const MESH &m);
00123   virtual bool operator==(const MESH& other) const;
00124   virtual bool deepCompare(const GMESH& other) const;
00125   virtual bool isEmpty() const;
00126 
00127   friend ostream & operator<<(ostream &os, const MESH &my);
00128   virtual void printMySelf(ostream &os) const;
00129 
00130   virtual int         getMeshDimension() const;
00131   virtual bool        getIsAGrid() const;
00132   virtual const MESH* convertInMESH() const;
00133 
00134   inline int                        getNumberOfNodes() const;
00135   virtual inline const COORDINATE * getCoordinateptr() const;
00136   inline string                     getCoordinatesSystem() const;
00137   virtual inline const double *     getCoordinates(MED_EN::medModeSwitch Mode) const;
00138   virtual inline const double       getCoordinate(int Number,int Axis) const;
00139   inline const string *             getCoordinatesNames() const;
00140   inline const string *             getCoordinatesUnits() const;
00141 
00142   virtual inline int getNumberOfTypes(MED_EN::medEntityMesh Entity) const;
00143   virtual inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const;
00144   virtual inline const CELLMODEL * getCellsTypes(MED_EN::medEntityMesh Entity) const;
00145   virtual inline string * getCellTypeNames(MED_EN::medEntityMesh Entity) const;
00146   virtual inline const int * getGlobalNumberingIndex(MED_EN::medEntityMesh Entity) const;
00147   virtual inline int getNumberOfElements(MED_EN::medEntityMesh Entity,
00148                                          MED_EN::medGeometryElement Type) const;
00149   virtual inline bool existConnectivity(MED_EN::medConnectivity ConnectivityType,
00150                                         MED_EN::medEntityMesh Entity) const;
00151 
00152   virtual inline MED_EN::medGeometryElement getElementType(MED_EN::medEntityMesh Entity,
00153                                                            int Number) const;
00154   virtual inline void calculateConnectivity(MED_EN::medConnectivity ConnectivityType,
00155                                             MED_EN::medEntityMesh Entity) const ;
00156   virtual inline int getConnectivityLength(MED_EN::medConnectivity ConnectivityType,
00157                                            MED_EN::medEntityMesh Entity,
00158                                            MED_EN::medGeometryElement Type) const;
00159   virtual inline const int * getConnectivity(MED_EN::medConnectivity ConnectivityType,
00160                                              MED_EN::medEntityMesh Entity,
00161                                              MED_EN::medGeometryElement Type) const;
00162   virtual inline const int * getConnectivityIndex(MED_EN::medConnectivity ConnectivityType,
00163                                                   MED_EN::medEntityMesh Entity) const;
00164 
00165   virtual int                 getElementNumber(MED_EN::medConnectivity ConnectivityType,
00166                                                MED_EN::medEntityMesh Entity,
00167                                                MED_EN::medGeometryElement Type,
00168                                                int * connectivity) const;
00169   virtual inline int getReverseConnectivityLength(MED_EN::medConnectivity ConnectivityType,
00170                                                   MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const;
00171   virtual inline const int * getReverseConnectivity(MED_EN::medConnectivity ConnectivityType,
00172                                                     MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const;
00173   virtual inline int getReverseConnectivityIndexLength(MED_EN::medConnectivity ConnectivityType,
00174                                                          MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const;
00175   virtual inline const int * getReverseConnectivityIndex(MED_EN::medConnectivity ConnectivityType,
00176                                                          MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const;
00177 
00178   virtual inline const CONNECTIVITY*   getConnectivityptr() const;
00179   inline void setConnectivityptr(CONNECTIVITY*);
00180   virtual SUPPORT *                    getBoundaryElements(MED_EN::medEntityMesh Entity) const
00181                                                 throw (MEDEXCEPTION);
00182   virtual SUPPORT *                    getSkin(const SUPPORT * Support3D)
00183                                                 throw (MEDEXCEPTION);
00184 
00185   //  Node DonneBarycentre(const Cell &m) const;
00186   virtual FIELD<double>* getVolume (const SUPPORT * Support, bool isAbs = true) const
00187                                 throw (MEDEXCEPTION);
00188                                 // Support must be on 3D elements
00189   virtual FIELD<double>* getArea (const SUPPORT * Support) const
00190                                 throw (MEDEXCEPTION);
00191                                 // Support must be on 2D elements
00192   virtual FIELD<double>* getLength (const SUPPORT * Support) const
00193                                 throw (MEDEXCEPTION);
00194                                 // Support must be on 1D elements
00195   virtual FIELD<double>* getNormal (const SUPPORT * Support) const
00196                                 throw (MEDEXCEPTION);
00197                                 // Support must be on 2D elements
00198   virtual FIELD<double>* getBarycenter (const SUPPORT * Support) const
00199                                 throw (MEDEXCEPTION);
00200   //  FIELD<int>* getNeighbourhood(SUPPORT * Support) const
00201   //                            throw (MEDEXCEPTION); // Il faut preciser !
00202 
00203   SUPPORT *buildSupportOnNodeFromElementList(const list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION);
00204   void fillSupportOnNodeFromElementList(const list<int>& listOfElt, SUPPORT *supportToFill) const throw (MEDEXCEPTION);
00205   int getElementContainingPoint(const double *coord);
00206   vector< vector<double> > getBoundingBox() const;
00207   void convertToPoly();
00208 };
00209 
00210 // ---------------------------------------
00211 //              Methodes Inline
00212 // ---------------------------------------
00213 
00214 inline const CONNECTIVITY* MESH::getConnectivityptr() const
00215 {
00216 //   checkGridFillConnectivity();
00217   return _connectivity;
00218 }
00219 
00220 inline void MESH::setConnectivityptr(CONNECTIVITY* conn)
00221 {
00222   if(_connectivity)
00223     delete _connectivity;
00224   _connectivity=conn;
00225 }
00226 
00233 inline int MESH::getNumberOfNodes() const
00234 {
00235   return _numberOfNodes;
00236 }
00237 
00242 inline const COORDINATE * MESH::getCoordinateptr() const
00243 {
00244 //   checkGridFillCoords();
00245   return _coordinate;
00246 }
00247 
00249 inline string MESH::getCoordinatesSystem() const
00250 {
00251   return _coordinate->getCoordinatesSystem();
00252 }
00253 
00258 inline const double * MESH::getCoordinates(MED_EN::medModeSwitch Mode) const
00259 {
00260 //   checkGridFillCoords();
00261   return _coordinate->getCoordinates(Mode);
00262 }
00263 
00265 inline const double MESH::getCoordinate(int number, int axis) const
00266 {
00267 //   checkGridFillCoords();
00268   return _coordinate->getCoordinate(number,axis);
00269 }
00270 
00273 inline const string * MESH::getCoordinatesNames() const
00274 {
00275   return _coordinate->getCoordinatesNames();
00276 }
00277 
00280 inline const string * MESH::getCoordinatesUnits() const
00281 {
00282   return _coordinate->getCoordinatesUnits();
00283 }
00296 //  int * MESH::getNodesNumbers() const
00297 //  {
00298 //    return nodesNumbers;
00299 //  }
00300 
00316 inline int MESH::getNumberOfTypes(MED_EN::medEntityMesh entity) const
00317 {
00318   MESSAGE_MED("MESH::getNumberOfTypes(medEntityMesh entity) : "<<entity);
00319   if (entity == MED_EN::MED_NODE)
00320     return 1;
00321 //   checkGridFillConnectivity();
00322   if (_connectivity != NULL)
00323     return _connectivity->getNumberOfTypes(entity);
00324   throw MEDEXCEPTION(LOCALIZED("MESH::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !"));
00325 }
00326 
00333 inline const MED_EN::medGeometryElement * MESH::getTypes(MED_EN::medEntityMesh entity) const
00334 {
00335   if (entity == MED_EN::MED_NODE)
00336     throw MEDEXCEPTION(LOCALIZED("MESH::getTypes( medEntityMesh ) : No medGeometryElement with MED_NODE entity !"));
00337   // return un tableau de taille 1 contenant MED_NONE, comme les supports pour etre coherent avec getNumberOfTypes ???? PG
00338 
00339 //   checkGridFillConnectivity();
00340   if (_connectivity != NULL)
00341     return _connectivity->getGeometricTypes(entity);
00342   throw MEDEXCEPTION(LOCALIZED("MESH::getTypes( medEntityMesh ) : Connectivity not defined !"));
00343 }
00350 inline const CELLMODEL * MESH::getCellsTypes(MED_EN::medEntityMesh Entity) const
00351 {
00352   //  checkGridFillConnectivity();
00353   if (_connectivity != NULL)
00354     return _connectivity->getCellsTypes(Entity);
00355   throw MEDEXCEPTION(LOCALIZED("MESH::getCellsTypes( medEntityMesh ) : Connectivity not defined !"));
00356 }
00357 
00364 inline string * MESH::getCellTypeNames(MED_EN::medEntityMesh Entity) const
00365 {
00366   //  checkGridFillConnectivity();
00367   if (_connectivity != NULL)
00368     return _connectivity->getCellTypeNames(Entity);
00369   throw MEDEXCEPTION(LOCALIZED("MESH::getCellTypesName( medEntityMesh ) : Connectivity not defined !"));
00370 }
00387 inline const int * MESH::getGlobalNumberingIndex(MED_EN::medEntityMesh entity) const
00388 {
00389   //  checkGridFillConnectivity();
00390   if (_connectivity != NULL)
00391     return _connectivity->getGlobalNumberingIndex(entity);
00392   throw MEDEXCEPTION(LOCALIZED("MESH::getNumberOfTypes( medEntityMesh ) : Connectivity not defined !"));
00393 }
00405 inline int MESH::getNumberOfElements(MED_EN::medEntityMesh entity, MED_EN::medGeometryElement Type) const
00406 {
00407   if (entity==MED_EN::MED_NODE)
00408     if ((Type==MED_EN::MED_NONE)|(Type==MED_EN::MED_ALL_ELEMENTS))
00409       return _numberOfNodes;
00410     else
00411       return 0;
00412   //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"wrong medGeometryElement with MED_NODE"));
00413   else
00414     {
00415 //       checkGridFillConnectivity();
00416       if (_connectivity != (CONNECTIVITY*)NULL)
00417         return _connectivity->getNumberOf(entity,Type);
00418       else
00419         return 0;
00420       //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"connectivity not defined !"));
00421     }
00422 }
00454 inline bool MESH::existConnectivity(MED_EN::medConnectivity connectivityType, MED_EN::medEntityMesh entity) const
00455 {
00456 //   checkGridFillConnectivity();
00457   if (_connectivity==(CONNECTIVITY*)NULL)
00458     throw MEDEXCEPTION("MESH::existConnectivity(medConnectivity,medEntityMesh) : no connectivity defined !");
00459   return _connectivity->existConnectivity(connectivityType,entity);
00460 }
00472 inline MED_EN::medGeometryElement MESH::getElementType(MED_EN::medEntityMesh Entity,int Number) const
00473 {
00474   //  checkGridFillConnectivity();
00475   if (_connectivity==(CONNECTIVITY*)NULL)
00476     throw MEDEXCEPTION("MESH::getElementType(medEntityMesh,int) : no connectivity defined !");
00477   return _connectivity->getElementType(Entity,Number);
00478 }
00490 inline void MESH::calculateConnectivity(MED_EN::medConnectivity ConnectivityType,MED_EN::medEntityMesh entity) const
00491 {
00492   _connectivity->calculateConnectivity(ConnectivityType,entity);
00493 }
00498 inline int MESH::getConnectivityLength(MED_EN::medConnectivity ConnectivityType,MED_EN::medEntityMesh entity, MED_EN::medGeometryElement Type) const
00499 {
00500   int nbOfElm = getNumberOfElements(entity,Type);
00501   int size;
00502 
00503   if (Type == MED_EN::MED_ALL_ELEMENTS)
00504     {
00505       size = getConnectivityIndex(ConnectivityType,entity)[nbOfElm]-1;
00506     }
00507   else
00508     {
00509       size = _connectivity->getConnectivityLength(ConnectivityType,entity,Type); // issue 19983
00510     }
00511   return size;
00512 }
00513 
00529 inline const int * MESH::getConnectivity(MED_EN::medConnectivity ConnectivityType,MED_EN::medEntityMesh entity, MED_EN::medGeometryElement Type) const
00530 {
00531   return _connectivity->getConnectivity(ConnectivityType,entity,Type);
00532 }
00544 inline const int * MESH::getConnectivityIndex(MED_EN::medConnectivity    ConnectivityType,
00545                                               MED_EN::medEntityMesh      entity) const
00546 {
00547   return _connectivity->getConnectivityIndex(ConnectivityType, entity);
00548 }
00549 
00561 inline int MESH::getReverseConnectivityLength(MED_EN::medConnectivity ConnectivityType,
00562                                               MED_EN::medEntityMesh   Entity) const
00563 {
00564   int spaceDim = getSpaceDimension();
00565   int nb;
00566 
00567   if (ConnectivityType == MED_EN::MED_NODAL)
00568     {
00569       nb = getNumberOfNodes();
00570     }
00571   else
00572     {
00573       if (spaceDim == 2)
00574         nb = getNumberOfElements(MED_EN::MED_EDGE,
00575                                         MED_EN::MED_ALL_ELEMENTS);
00576       else if (spaceDim == 3)
00577         nb = getNumberOfElements(MED_EN::MED_FACE,
00578                                         MED_EN::MED_ALL_ELEMENTS);
00579     }
00580   return getReverseConnectivityIndex(ConnectivityType,Entity)[nb]-1;
00581 }
00590 inline const int * MESH::getReverseConnectivity(MED_EN::medConnectivity ConnectivityType,MED_EN::medEntityMesh Entity/*=MED_CELL*/) const
00591 {
00592   //  checkGridFillConnectivity();
00593   if (NULL==_connectivity)
00594     throw MEDEXCEPTION("MESH::getReverseConnectivity : no connectivity defined in MESH !");
00595 
00596   return _connectivity->getReverseConnectivity(ConnectivityType,Entity);
00597 }
00602 inline int MESH::getReverseConnectivityIndexLength(MED_EN::medConnectivity ConnectivityType,
00603                                                          MED_EN::medEntityMesh Entity) const
00604 {
00605   int spaceDim = getSpaceDimension();
00606 
00607   if (ConnectivityType == MED_EN::MED_NODAL)
00608     {
00609       return getNumberOfNodes()+1;
00610     }
00611   else
00612     {
00613       if (spaceDim == 2)
00614         return getNumberOfElements(MED_EN::MED_EDGE,MED_EN::MED_ALL_ELEMENTS)+1;
00615       else if (spaceDim == 3)
00616         return getNumberOfElements(MED_EN::MED_FACE,MED_EN::MED_ALL_ELEMENTS)+1;
00617       else
00618         throw MEDEXCEPTION("Invalid dimension");
00619     }
00620 }
00633 inline const int * MESH::getReverseConnectivityIndex(MED_EN::medConnectivity ConnectivityType,MED_EN::medEntityMesh Entity/*=MED_CELL*/) const
00634 {
00635   //  checkGridFillConnectivity();
00636   if (NULL==_connectivity)
00637     throw MEDEXCEPTION("MESH::getReverseConnectivityIndex : no connectivity defined in MESH !");
00638 
00639   return _connectivity->getReverseConnectivityIndex(ConnectivityType,Entity);
00640 }
00641 
00642 }
00643 
00644 #endif /* MESH_HXX */