Salome HOME
440d67a3c63139ba9c9e977b9446d409cbf62df1
[modules/med.git] / src / MEDMEM / MEDMEM_CellModel.hxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 /*
24  File MEDMEM_CellModel.hxx
25 */
26
27 #ifndef CELLMODEL_HXX
28 #define CELLMODEL_HXX
29
30 #include <MEDMEM.hxx>
31
32 #include <set>
33 #include <map>
34 #include <string>
35
36 #include "MEDMEM_Utilities.hxx"
37 #include "MEDMEM_define.hxx"
38
39 using namespace std ;
40
41 /*!
42   This class is an internal class and should not be used by the end-user.
43   This class describes all possible cell models and is used in order
44   to acces informations about geometric type of the cell : 
45   Each object (if instancied), contains generic informations about
46   the cell model it describes as cell dimensions, number of nodes...
47 */
48
49
50 namespace MEDMEM {
51   class CELLMODEL;
52   MEDMEM_EXPORT ostream & operator<<(ostream &os,const CELLMODEL &my);
53
54 class MEDMEM_EXPORT CELLMODEL 
55 {
56
57 private:
58                         /*! private method : \n
59                             used by constructor and operator= */
60   void init(const CELLMODEL &m);
61
62                         /*! private method : \n */
63   void clean();
64
65
66   //protected:
67                         /*! explicit name (as MED_POINT1)           */
68   string             _name;
69                         /*! type of cell (cf define.h)              */
70   MED_EN::medGeometryElement _type;
71                         /*! Cell dimension (not space dimension)    */
72   int                _dimension;
73                         /*! number of nodes forming this type of a cell    */
74   int                _numberOfNodes;
75                         /*! number of vertexes forming this type of a cell */
76   int                _numberOfVertexes;
77                         /*!  2 for a  3D Cell and 1 for a 2DCell */
78   int                _numberOfConstituentsDimension;
79                         /*! Array of size numberOfConstituentsDimension */
80   int*               _numberOfConstituents ;
81                         /*! Array of size _numberOfConstituentsDimension
82                             x_numberOfConstituents[i]               */
83   int**              _numberOfNodeOfEachConstituent ;
84                         /*! defines nodal local connectivity for each 
85                             constituents of each dimension: 
86                             should be seen as a vector<vector<vector>> \n
87                             - first vector : for each cell dimension 
88                               (first : dim-1, second if any : dim-2)\n
89                             - second vector : for each constituent of 
90                               this dimension\n
91                             - third vector : list of local nodes    */
92   int***                _constituents ;
93   MED_EN::medGeometryElement**  _constituentsType ;
94
95 public :
96
97                         /*! Constructor. */
98   inline CELLMODEL();
99                         /*! Constructor. */
100   CELLMODEL(MED_EN::medGeometryElement t);
101                         /*! Copy constructor. */
102   inline CELLMODEL(const CELLMODEL &m);
103                         /*! Destructor. */
104   inline ~CELLMODEL();
105
106                         /*! Operator = : duplicate CELLMODEL. */
107   inline CELLMODEL & operator=(const CELLMODEL &m);
108
109                         /*! Operator << : print CELLMODEL to the given stream. */
110   friend MEDMEM_EXPORT ostream & operator<<(ostream &os,const CELLMODEL &my);
111
112                         /*! returns _name attribute (ie: MED_PENTA15).\n
113                             see med.h (in med/include) */
114   inline string                 getName()             const;
115
116                         /*! returns number of vertexes forming this type of cell */
117   inline int                    getNumberOfVertexes() const;
118
119                         /*! returns number of nodes forming this type of cell    */
120   inline int                    getNumberOfNodes()    const;
121
122                         /*! returns the dimension of this type of cell.\n
123                             it can be different from mesh dimension              */
124   inline int                    getDimension()        const;
125
126                         /*! returns the geometric type of the cell. \n
127                             see med.h (in med/include) */
128   inline MED_EN::medGeometryElement     getType()             const;
129
130                         /*! returns all constituents which dimension is _dimension-dim.*/
131   int** getConstituents(int dim) const;
132
133                         /*! returns number of constituents which dimension is _dimension-dim.*/
134   int   getNumberOfConstituents(int dim) const;
135
136                         /*! returns local nodes numbers vector for num-th constituent 
137                             which dimension is _dimension-dim.*/
138   int* getNodesConstituent(int dim,int num) const;
139
140                         /*! returns local node number of nodes_index-th node for 
141                             num-th constituent which dimension is _dimension-dim.*/
142   int getNodeConstituent(int dim,int num,int nodes_index) const;
143
144                         /*! returns types of each constituents which dimension 
145                             is _dimension-dim.*/
146   MED_EN::medGeometryElement*  getConstituentsType(int dim) const;
147
148                         /*! returns type of num-th constituent which dimension 
149                             is _dimension-dim.*/
150   MED_EN::medGeometryElement getConstituentType(int dim,int num) const;
151
152                         /*! returns number of constituents type 
153                             (which dimension is _dimension-1).*/
154   int getNumberOfConstituentsType() const;
155
156                         /*! returns all types of constituents which dimension 
157                             is (_dimension-1).*/
158   set<MED_EN::medGeometryElement>  getAllConstituentsType() const;
159
160                         /*! returns number of constituents foreach type (which dimension 
161                             is _dimension-1).*/
162   map<MED_EN::medGeometryElement,int>  getNumberOfConstituentsForeachType() const;
163
164
165 };
166
167 // ------------------------------------------
168 //      Methodes Inline
169 // ------------------------------------------
170
171 inline CELLMODEL::CELLMODEL():
172     _type(MED_EN::MED_NONE),
173     _dimension(0),
174     _numberOfNodes(0),
175     _numberOfVertexes(0),
176     _numberOfConstituentsDimension(0),
177     _numberOfConstituents((int*)NULL),
178     _numberOfNodeOfEachConstituent((int**)NULL),
179     _constituents((int***)NULL),
180     _constituentsType((MED_EN::medGeometryElement**)NULL)
181 {
182 }
183 inline CELLMODEL::CELLMODEL(const CELLMODEL &m):
184     _type(MED_EN::MED_NONE),
185     _dimension(0),
186     _numberOfNodes(0),
187     _numberOfVertexes(0),
188     _numberOfConstituentsDimension(0),
189     _numberOfConstituents((int*)NULL),
190     _numberOfNodeOfEachConstituent((int**)NULL),
191     _constituents((int***)NULL),
192     _constituentsType((MED_EN::medGeometryElement**)NULL)
193 {
194     init(m) ;
195 }
196 inline CELLMODEL::~CELLMODEL() 
197 {
198   //  MESSAGE_MED("CELLMODEL::~CELLMODEL() destroying the cell");
199   clean() ;
200 }
201 inline CELLMODEL & CELLMODEL::operator=(const CELLMODEL &m) 
202 {
203     clean() ;
204     init(m) ;
205     return *this ;
206 }
207 inline string CELLMODEL::getName() const
208 {
209   return _name ;
210 }
211 inline int CELLMODEL::getNumberOfVertexes() const
212 {
213   return _numberOfVertexes;
214 }
215 inline int CELLMODEL::getNumberOfNodes() const
216 {
217   return _numberOfNodes;
218 }
219 inline int CELLMODEL::getDimension() const
220 {
221   return _dimension;
222 }
223 inline MED_EN::medGeometryElement CELLMODEL::getType() const
224 {
225   return _type;
226 }
227 inline int** CELLMODEL::getConstituents(int dim) const
228 {
229   return _constituents[dim-1] ;
230 }
231 inline int CELLMODEL::getNumberOfConstituents(int dim) const
232 {
233   return _numberOfConstituents[dim-1] ;
234 }
235 inline int* CELLMODEL::getNodesConstituent(int dim,int num) const
236 {
237   return _constituents[dim-1][num-1];
238 }
239 inline int CELLMODEL::getNodeConstituent(int dim,int num,int nodesNumber) const
240 {
241   return _constituents[dim-1][num-1][nodesNumber-1] ;
242 }
243 inline MED_EN::medGeometryElement* CELLMODEL::getConstituentsType(int dim) const
244 {
245   return _constituentsType[dim-1];
246 }
247 inline MED_EN::medGeometryElement CELLMODEL::getConstituentType(int dim,int num) const
248 {
249   return _constituentsType[dim-1][num-1];
250 }
251
252 /*!: Utility  class for storing cell models. Avoids calling the cellmodel constructor too
253 often.
254 */
255 class MEDMEM_EXPORT CELLMODEL_Map
256 {
257 public:
258   static const MEDMEM::CELLMODEL& retrieveCellModel(MED_EN::medGeometryElement type);
259 private:
260   static CELLMODEL_Map *getInstance();
261   static CELLMODEL_Map *_singleton;
262   std::map<MED_EN::medGeometryElement,MEDMEM::CELLMODEL> _cell_models;
263
264   CELLMODEL_Map() {}
265   ~CELLMODEL_Map(){ if(_singleton) delete _singleton;}
266
267   const MEDMEM::CELLMODEL& getCellModel(MED_EN::medGeometryElement type);
268
269 };
270
271 }//End of namespace MEDMEM
272
273 #endif /* CELLMODEL_HXX */