1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : MEDMEM_GMesh.hxx
23 // Created : Fri Jul 23 10:17:08 2010
24 // Author : Edward AGAPOV (eap)
27 #ifndef __MEDMEM_GMesh_HXX__
28 #define __MEDMEM_GMesh_HXX__
31 #include "MEDMEM_define.hxx"
32 #include "MEDMEM_Exception.hxx"
33 #include "MEDMEM_RCBase.hxx"
34 #include "MEDMEM_GenDriver.hxx"
35 #include "MEDMEM_FieldForward.hxx"
36 #include "MEDMEM_Support.hxx"
48 MEDMEM_EXPORT std::ostream & operator<<(std::ostream &os, const GMESH &me);
51 * \brief Base class of structured and unstructured meshes
53 class MEDMEM_EXPORT GMESH: public RCBASE
58 std::string _description;
61 std::vector<FAMILY*> _familyNode;
62 std::vector<FAMILY*> _familyCell;
63 std::vector<FAMILY*> _familyFace;
64 std::vector<FAMILY*> _familyEdge;
66 std::vector<GROUP*> _groupNode;
67 std::vector<GROUP*> _groupCell;
68 std::vector<GROUP*> _groupFace;
69 std::vector<GROUP*> _groupEdge;
71 std::vector<GENDRIVER *> _drivers; // Storage of the drivers currently in use
73 std::map<MED_EN::medEntityMesh,SUPPORT*> _entitySupport;
75 virtual bool isEmpty() const = 0;
77 // Add your personnal driver line (step 2)
78 friend class MED_MESH_RDONLY_DRIVER;
79 friend class MED_MESH_WRONLY_DRIVER;
81 friend class GIBI_MESH_RDONLY_DRIVER;
82 friend class GIBI_MESH_WRONLY_DRIVER;
83 friend class GIBI_MESH_RDWR_DRIVER;
85 friend class PORFLOW_MESH_RDONLY_DRIVER;
86 friend class PORFLOW_MESH_WRONLY_DRIVER;
87 friend class PORFLOW_MESH_RDWR_DRIVER;
89 friend class VTK_MESH_DRIVER;
91 friend class ENSIGHT_MESH_RDONLY_DRIVER;
100 GMESH & operator=(const GMESH &m);
101 virtual bool operator==(const GMESH& other) const;
102 virtual bool deepCompare(const GMESH& other) const = 0;
104 friend std::ostream & operator<<(std::ostream &os, const GMESH &me);
105 virtual void printMySelf(std::ostream &os) const = 0;
107 int addDriver(driverTypes driverType,
108 const std::string & fileName ="Default File Name.med",
109 const std::string & driverName="Default Mesh Name",
110 MED_EN::med_mode_acces access=MED_EN::RDWR);
111 int addDriver(GENDRIVER & driver);
112 void rmDriver(int index=0);
114 virtual void read(int index=0);
115 virtual void read(const GENDRIVER & genDriver);
116 virtual void read(driverTypes driverType,
117 const std::string& filename,
118 const std::string& meshname);
120 virtual void write(int index=0) const ;
121 virtual void write(const GENDRIVER & genDriver,
122 MED_EN::med_mode_acces medMode=MED_EN::WRONLY) const;
123 virtual void write(driverTypes driverType,
124 const std::string& filename,
125 const std::string& meshname="",
126 MED_EN::med_mode_acces medMode=MED_EN::WRONLY) const;
128 void setName(std::string name);
129 std::string getName() const;
131 void setDescription(std::string description);
132 std::string getDescription() const;
134 int getSpaceDimension() const;
135 virtual int getMeshDimension() const = 0;
137 virtual bool getIsAGrid() const = 0;
139 virtual std::string getCoordinatesSystem() const = 0;
140 virtual const std::string * getCoordinatesNames() const = 0;
141 virtual const std::string * getCoordinatesUnits() const = 0;
143 virtual int getNumberOfNodes() const = 0;
144 virtual int getNumberOfTypes(MED_EN::medEntityMesh Entity) const = 0;
145 virtual int getNumberOfElements(MED_EN::medEntityMesh Entity,
146 MED_EN::medGeometryElement Type) const = 0;
147 virtual const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const = 0;
148 virtual MED_EN::medGeometryElement getElementType(MED_EN::medEntityMesh Entity,
149 int Number) const = 0;
152 virtual int getNumberOfFamilies(MED_EN::medEntityMesh Entity) const;
153 virtual const std::vector<FAMILY*> getFamilies(MED_EN::medEntityMesh Entity) const;
154 virtual const FAMILY* getFamily(MED_EN::medEntityMesh Entity,int i) const;
156 virtual int getNumberOfGroups(MED_EN::medEntityMesh Entity) const;
157 virtual const std::vector<GROUP*> getGroups(MED_EN::medEntityMesh Entity) const;
158 virtual const GROUP* getGroup(MED_EN::medEntityMesh Entity,int i) const;
159 virtual const GROUP* getGroup(const std::string& name) const throw (MEDEXCEPTION);
162 * \brief Return unstructured mesh. Call removeReference() after having finished using it!!!
164 virtual const MESH * convertInMESH() const = 0;
167 virtual SUPPORT * getBoundaryElements(MED_EN::medEntityMesh Entity) const
168 throw (MEDEXCEPTION) = 0;
169 virtual SUPPORT * getSkin(const SUPPORT * Support3D)
170 throw (MEDEXCEPTION) = 0;
172 virtual const SUPPORT * getSupportOnAll(MED_EN::medEntityMesh Entity) const
173 throw (MEDEXCEPTION);
175 static SUPPORT * mergeSupports(const std::vector<SUPPORT *> Supports)
176 throw (MEDEXCEPTION) ;
177 static SUPPORT * intersectSupports(const std::vector<SUPPORT *> Supports)
178 throw (MEDEXCEPTION) ;
180 virtual SUPPORT *buildSupportOnNodeFromElementList(const std::list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION) = 0;
181 virtual void fillSupportOnNodeFromElementList(const std::list<int>& listOfElt, SUPPORT *supportToFill) const throw (MEDEXCEPTION) = 0;
182 virtual SUPPORT *buildSupportOnElementsFromElementList(const std::list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION);
185 virtual FIELD<double>* getVolume (const SUPPORT * Support, bool isAbs = true) const
186 throw (MEDEXCEPTION) = 0;
187 // Support must be on 3D elements
188 virtual FIELD<double>* getArea (const SUPPORT * Support) const
189 throw (MEDEXCEPTION) = 0;
190 // Support must be on 2D elements
191 virtual FIELD<double>* getLength (const SUPPORT * Support) const
192 throw (MEDEXCEPTION) = 0;
193 // Support must be on 1D elements
194 virtual FIELD<double>* getNormal (const SUPPORT * Support) const
195 throw (MEDEXCEPTION) = 0;
196 // Support must be on 2D elements
197 virtual FIELD<double>* getBarycenter (const SUPPORT * Support) const
198 throw (MEDEXCEPTION) = 0;
200 virtual vector< vector<double> > getBoundingBox() const = 0;
202 template<class T> static FIELD<T>* mergeFields(const std::vector< FIELD<T> * > & others,
203 bool meshCompare=false);
205 void createFamilies();
209 // ================================================================================================
210 //Create a new FIELD that should be deallocated based on a SUPPORT that should be deallocated too.
211 // ================================================================================================
213 FIELD<T> * GMESH::mergeFields(const std::vector< FIELD<T> * > & others, bool meshCompare)
215 const char * LOC = "MESH::mergeFields(const vector< FIELD<T>* >& others,bool meshCompare): ";
220 std::vector<SUPPORT *> sup;
221 typename std::vector< FIELD<T, FullInterlace>* >::const_iterator iter;
222 iter = others.begin();
223 MED_EN::med_type_champ valueType = (*iter)->getValueType();
224 for(iter=others.begin();iter!=others.end();iter++)
226 MED_EN::med_type_champ valueTypeIter = (*iter)->getValueType();
227 if (valueTypeIter != valueType)
228 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Fields vector have not the same value type"));
230 sup.push_back((SUPPORT *)(*iter)->getSupport());
233 SUPPORT *retSup=mergeSupports(sup);
234 int retNumberOfComponents=(*iter)->getNumberOfComponents();
235 FIELD<T, FullInterlace> *ret=new FIELD<T, FullInterlace>(retSup, retNumberOfComponents);
236 T* valuesToSet=(T*)ret->getValue();
237 int nbOfEltsRetSup=retSup->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS);
238 T* tempValues=new T[retNumberOfComponents];
239 if(retSup->isOnAllElements())
241 for(i=0;i<nbOfEltsRetSup;i++)
244 for(iter=others.begin();iter!=others.end() && !found;iter++)
246 found=(*iter)->getValueOnElement(i+1,tempValues);
248 for(j=0;j<retNumberOfComponents;j++)
249 valuesToSet[i*retNumberOfComponents+j]=tempValues[j];
255 const int *eltsRetSup=retSup->getNumber(MED_EN::MED_ALL_ELEMENTS);
256 for(i=0;i<nbOfEltsRetSup;i++)
259 for(iter=others.begin();iter!=others.end() && !found;iter++)
261 found=(*iter)->getValueOnElement(eltsRetSup[i],tempValues);
263 for(j=0;j<retNumberOfComponents;j++)
264 valuesToSet[i*retNumberOfComponents+j]=tempValues[j];
267 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Merging error due to an error in merging support"));
271 retSup->removeReference();
272 delete [] tempValues;