Back to index

salome-med  6.5.0
MEDMEM_GMesh.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 // File      : MEDMEM_GMesh.hxx
00023 // Created   : Fri Jul 23 10:17:08 2010
00024 // Author    : Edward AGAPOV (eap)
00025 //
00026 
00027 #ifndef __MEDMEM_GMesh_HXX__
00028 #define __MEDMEM_GMesh_HXX__
00029 
00030 #include "MEDMEM.hxx"
00031 #include "MEDMEM_define.hxx"
00032 #include "MEDMEM_Exception.hxx"
00033 #include "MEDMEM_RCBase.hxx"
00034 #include "MEDMEM_GenDriver.hxx"
00035 #include "MEDMEM_FieldForward.hxx"
00036 #include "MEDMEM_Support.hxx"
00037 
00038 #include <map>
00039 
00040 namespace MEDMEM {
00041 
00042 class FAMILY;
00043 class GROUP;
00044 class SUPPORT;
00045 class GMESH;
00046 class MESH;
00047 
00048 MEDMEM_EXPORT std::ostream & operator<<(std::ostream &os, const GMESH &me);
00049 
00053 class MEDMEM_EXPORT GMESH: public RCBASE
00054 {
00055  protected:
00056 
00057   std::string          _name;
00058   std::string          _description;
00059   int                  _spaceDimension;
00060 
00061   std::vector<FAMILY*> _familyNode;
00062   std::vector<FAMILY*> _familyCell;
00063   std::vector<FAMILY*> _familyFace;
00064   std::vector<FAMILY*> _familyEdge;
00065 
00066   std::vector<GROUP*>  _groupNode;
00067   std::vector<GROUP*>  _groupCell;
00068   std::vector<GROUP*>  _groupFace;
00069   std::vector<GROUP*>  _groupEdge;
00070 
00071   std::vector<GENDRIVER *> _drivers; // Storage of the drivers currently in use
00072 
00073   std::map<MED_EN::medEntityMesh,SUPPORT*> _entitySupport;
00074 
00075   virtual bool isEmpty() const = 0;
00076 
00077   // Add your personnal driver line (step 2)
00078   friend class MED_MESH_RDONLY_DRIVER;
00079   friend class MED_MESH_WRONLY_DRIVER;
00080 
00081   friend class GIBI_MESH_RDONLY_DRIVER;
00082   friend class GIBI_MESH_WRONLY_DRIVER;
00083   friend class GIBI_MESH_RDWR_DRIVER;
00084 
00085   friend class PORFLOW_MESH_RDONLY_DRIVER;
00086   friend class PORFLOW_MESH_WRONLY_DRIVER;
00087   friend class PORFLOW_MESH_RDWR_DRIVER;
00088 
00089   friend class VTK_MESH_DRIVER;
00090 
00091   friend class ENSIGHT_MESH_RDONLY_DRIVER;
00092 
00093  public:
00094 
00095   GMESH();
00096   GMESH(GMESH &m);
00097   virtual ~GMESH();
00098 
00099   virtual void init();
00100   GMESH & operator=(const GMESH &m);
00101   virtual bool operator==(const GMESH& other) const;
00102   virtual bool deepCompare(const GMESH& other) const = 0;
00103 
00104   friend std::ostream & operator<<(std::ostream &os, const GMESH &me);
00105   virtual void printMySelf(std::ostream &os) const = 0;
00106 
00107   int  addDriver(driverTypes            driverType,
00108                  const std::string &    fileName  ="Default File Name.med",
00109                  const std::string &    driverName="Default Mesh Name",
00110                  MED_EN::med_mode_acces access=MED_EN::RDWR);
00111   int  addDriver(GENDRIVER & driver);
00112   void rmDriver(int index=0);
00113 
00114   virtual void read(int index=0);
00115   virtual void read(const GENDRIVER & genDriver);
00116   virtual void read(driverTypes        driverType,
00117                     const std::string& filename,
00118                     const std::string& meshname);
00119 
00120   virtual void write(int index=0) const ;
00121   virtual void write(const GENDRIVER & genDriver,
00122                      MED_EN::med_mode_acces medMode=MED_EN::WRONLY) const;
00123   virtual void write(driverTypes        driverType,
00124                      const std::string& filename,
00125                      const std::string& meshname="",
00126                      MED_EN::med_mode_acces medMode=MED_EN::WRONLY) const;
00127 
00128   void                               setName(std::string name);
00129   std::string                        getName() const;
00130 
00131   void                               setDescription(std::string description);
00132   std::string                        getDescription() const;
00133 
00134   int                                getSpaceDimension() const;
00135   virtual int                        getMeshDimension() const = 0;
00136 
00137   virtual bool                       getIsAGrid() const = 0;
00138 
00139   virtual std::string                getCoordinatesSystem() const = 0;
00140   virtual const std::string *        getCoordinatesNames() const = 0;
00141   virtual const std::string *        getCoordinatesUnits() const = 0;
00142 
00143   virtual int                        getNumberOfNodes() const = 0;
00144   virtual int                        getNumberOfTypes(MED_EN::medEntityMesh Entity) const = 0;
00145   virtual int                        getNumberOfElements(MED_EN::medEntityMesh      Entity,
00146                                                          MED_EN::medGeometryElement Type) const = 0;
00147   virtual const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const = 0;
00148   virtual MED_EN::medGeometryElement getElementType(MED_EN::medEntityMesh Entity,
00149                                                     int                   Number) const = 0;
00150 
00151 
00152   virtual int                        getNumberOfFamilies(MED_EN::medEntityMesh Entity) const;
00153   virtual const std::vector<FAMILY*> getFamilies(MED_EN::medEntityMesh Entity) const;
00154   virtual const FAMILY*              getFamily(MED_EN::medEntityMesh Entity,int i) const;
00155 
00156   virtual int                        getNumberOfGroups(MED_EN::medEntityMesh Entity) const;
00157   virtual const std::vector<GROUP*>  getGroups(MED_EN::medEntityMesh Entity) const;
00158   virtual const GROUP*               getGroup(MED_EN::medEntityMesh Entity,int i) const;
00159   virtual const GROUP*               getGroup(const std::string& name) const throw (MEDEXCEPTION);
00160 
00164   virtual const MESH *               convertInMESH() const = 0;
00165 
00166 
00167   virtual SUPPORT *                  getBoundaryElements(MED_EN::medEntityMesh Entity) const
00168                                                 throw (MEDEXCEPTION) = 0;
00169   virtual SUPPORT *                  getSkin(const SUPPORT * Support3D)
00170                                                 throw (MEDEXCEPTION) = 0;
00171 
00172   virtual const SUPPORT *            getSupportOnAll(MED_EN::medEntityMesh Entity) const
00173                                                 throw (MEDEXCEPTION);
00174 
00175   static SUPPORT *                   mergeSupports(const std::vector<SUPPORT *> Supports)
00176                                                 throw (MEDEXCEPTION) ;
00177   static SUPPORT *                   intersectSupports(const std::vector<SUPPORT *> Supports)
00178                                                 throw (MEDEXCEPTION) ;
00179 
00180   virtual SUPPORT *buildSupportOnNodeFromElementList(const std::list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION) = 0;
00181   virtual void     fillSupportOnNodeFromElementList(const std::list<int>& listOfElt, SUPPORT *supportToFill) const throw (MEDEXCEPTION) = 0;
00182   virtual SUPPORT *buildSupportOnElementsFromElementList(const std::list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION);
00183 
00184 
00185   virtual FIELD<double>* getVolume (const SUPPORT * Support, bool isAbs = true) const
00186                                 throw (MEDEXCEPTION) = 0;
00187                                 // Support must be on 3D elements
00188   virtual FIELD<double>* getArea (const SUPPORT * Support) const
00189                                 throw (MEDEXCEPTION) = 0;
00190                                 // Support must be on 2D elements
00191   virtual FIELD<double>* getLength (const SUPPORT * Support) const
00192                                 throw (MEDEXCEPTION) = 0;
00193                                 // Support must be on 1D elements
00194   virtual FIELD<double>* getNormal (const SUPPORT * Support) const
00195                                 throw (MEDEXCEPTION) = 0;
00196                                 // Support must be on 2D elements
00197   virtual FIELD<double>* getBarycenter (const SUPPORT * Support) const
00198                                 throw (MEDEXCEPTION) = 0;
00199   
00200   virtual vector< vector<double> >   getBoundingBox() const = 0;
00201 
00202   template<class T> static FIELD<T>* mergeFields(const std::vector< FIELD<T> * > & others,
00203                                                  bool meshCompare=false);
00204 
00205   void                               createFamilies();
00206   void                               createGroups();
00207 };
00208 
00209 // ================================================================================================
00210 //Create a new FIELD that should be deallocated based on a SUPPORT that should be deallocated too.
00211 // ================================================================================================
00212 template<class T>
00213 FIELD<T> * GMESH::mergeFields(const std::vector< FIELD<T> * > & others, bool meshCompare)
00214 {
00215   const char * LOC = "MESH::mergeFields(const vector< FIELD<T>* >& others,bool meshCompare): ";
00216   BEGIN_OF_MED(LOC);
00217   int i,j;
00218   if(others.size()==0)
00219     return 0;
00220   std::vector<SUPPORT *> sup;
00221   typename std::vector< FIELD<T, FullInterlace>* >::const_iterator iter;
00222   iter = others.begin();
00223   MED_EN::med_type_champ valueType = (*iter)->getValueType();
00224   for(iter=others.begin();iter!=others.end();iter++)
00225     {
00226       MED_EN::med_type_champ valueTypeIter = (*iter)->getValueType();
00227       if (valueTypeIter != valueType)
00228         throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Fields vector have not the same value type"));
00229 
00230       sup.push_back((SUPPORT *)(*iter)->getSupport());
00231     }
00232   iter=others.begin();
00233   SUPPORT *retSup=mergeSupports(sup);
00234   int retNumberOfComponents=(*iter)->getNumberOfComponents();
00235   FIELD<T, FullInterlace> *ret=new FIELD<T, FullInterlace>(retSup, retNumberOfComponents);
00236   T* valuesToSet=(T*)ret->getValue();
00237   int nbOfEltsRetSup=retSup->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS);
00238   T* tempValues=new T[retNumberOfComponents];
00239   if(retSup->isOnAllElements())
00240     {
00241       for(i=0;i<nbOfEltsRetSup;i++)
00242         {
00243           bool found=false;
00244           for(iter=others.begin();iter!=others.end() && !found;iter++)
00245             {
00246               found=(*iter)->getValueOnElement(i+1,tempValues);
00247               if(found)
00248                 for(j=0;j<retNumberOfComponents;j++)
00249                   valuesToSet[i*retNumberOfComponents+j]=tempValues[j];
00250             }
00251         }
00252     }
00253   else
00254     {
00255       const int *eltsRetSup=retSup->getNumber(MED_EN::MED_ALL_ELEMENTS);
00256       for(i=0;i<nbOfEltsRetSup;i++)
00257         {
00258           bool found=false;
00259           for(iter=others.begin();iter!=others.end() && !found;iter++)
00260             {
00261               found=(*iter)->getValueOnElement(eltsRetSup[i],tempValues);
00262               if(found)
00263                 for(j=0;j<retNumberOfComponents;j++)
00264                   valuesToSet[i*retNumberOfComponents+j]=tempValues[j];
00265             }
00266           if(!found)
00267             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Merging error due to an error in merging support"));
00268         }
00269     }
00270   if(retSup)
00271     retSup->removeReference();
00272   delete [] tempValues;
00273   END_OF_MED(LOC);
00274   return ret;
00275 }
00276 }
00277 #endif