]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Meshing.cxx
Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/med.git] / src / MEDMEM / MEDMEM_Meshing.cxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : MEDMEM_Meshing.cxx
8 //  Module : MED
9
10 using namespace std;
11 /*
12   File MEDMEM_Meshing.cxx
13   $Header$
14 */
15
16 #include <string>
17
18 #include "utilities.h"
19 #include "MEDMEM_STRING.hxx"
20 #include "MEDMEM_Exception.hxx"
21 #include "MEDMEM_define.hxx"
22
23 #include "MEDMEM_Meshing.hxx"
24 #include "MEDMEM_Group.hxx"
25
26 /*! Create an empty MESH. */
27 MESHING::MESHING(): MESH()
28 {
29   MESSAGE("MESHING::MESHING()");
30   SCRUTE(_coordinate);
31   SCRUTE(_connectivity);
32 }
33
34 MESHING::~MESHING()
35 {
36   MESSAGE("Deletinh MESHING !!");
37 }
38
39 /*! Set the dimension of the space */
40 void MESHING::setSpaceDimension(const int SpaceDimension)
41 {
42   _spaceDimension = SpaceDimension ;
43 }
44
45 /* Set the dimension of the MESHING */
46 // void MESHING::setMeshDimension(const int MeshDimension)
47 // {
48 //    _meshDimension = MeshDimension ;
49 // }
50
51 /*! Set the number of nodes used in the MESH */
52 void MESHING::setNumberOfNodes(const int NumberOfNodes)
53 {
54   _numberOfNodes = NumberOfNodes ;
55 }
56
57 /*! 
58   Set the whole coordinates array in a given system and interlacing mode.
59   The system coordinates are :
60     - "CARTESIAN"
61     - "CYLINDRICAL"
62     - "SPHERICAL"
63   The interlacing mode are :
64     - MED_NO_INTERLACE   :  X1 X2 Y1 Y2 Z1 Z2
65     - MED_FULL_INTERLACE :  X1 Y1 Z1 X2 Y2 Z2
66 */
67 void MESHING::setCoordinates(const int SpaceDimension,
68                              const int NumberOfNodes,
69                              const double * Coordinates,
70                              const string System,
71                              const medModeSwitch Mode)
72 {
73   setSpaceDimension(SpaceDimension);
74   setNumberOfNodes(NumberOfNodes);
75
76   SCRUTE(_coordinate);
77   SCRUTE(_connectivity);
78   //if (NULL != _coordinate) delete _coordinate;
79
80   _coordinate = new COORDINATE(SpaceDimension,
81                                NumberOfNodes,
82                                Mode);
83   _coordinate->setCoordinates(Mode,Coordinates);
84   _coordinate->setCoordinatesSystem(System);
85 }
86
87 /*! Set the system in which coordinates are given (CARTESIAN,CYLINDRICAL,SPHERICAL) __??MED_CART??__. */
88 void MESHING::setCoordinatesSystem(const string System)
89   throw (MEDEXCEPTION)
90 {
91   if (NULL == _coordinate)
92     throw MEDEXCEPTION(LOCALIZED("MESHING::setCoordinatesSystem : no coordinates defined"));
93   _coordinate->setCoordinatesSystem(System);
94 }
95
96 /*! Set the coordinate names array ("x       ","y       ","z       ")
97   of size n*MED_TAILLE_PNOM
98 */
99 void MESHING::setCoordinatesNames(const string * name)
100 {
101 //    int SpaceDimension = getSpaceDimension() ;
102 //    _coordinate->setCoordinatesNames(SpaceDimension,name);
103   _coordinate->setCoordinatesNames(name);
104 }
105
106 /*!
107   Set the (i+1)^th component of coordinate names array
108   ("x       ","y       ","z       ") of size n*MED_TAILLE_PNOM
109 */
110 void MESHING::setCoordinateName(const string name, const int i)
111 {
112   _coordinate->setCoordinateName(name,i);
113 }
114
115 /*! Set the coordinate unit names array ("cm       ","cm       ","cm       ")
116   of size n*MED_TAILLE_PNOM
117 */
118 void MESHING::setCoordinatesUnits(const string * units)
119 {
120 //    int SpaceDimension = getSpaceDimension() ;
121 //    _coordinate->setCoordinatesUnits(SpaceDimension,units);
122   _coordinate->setCoordinatesUnits(units);
123 }
124
125 /*!
126   Set the (i+1)^th component of the coordinate unit names array
127   ("cm       ","cm       ","cm       ") of size n*MED_TAILLE_PNOM
128 */
129 void MESHING::setCoordinateUnit(const string unit, const int i)
130 {
131   _coordinate->setCoordinateUnit(unit,i);
132 }
133
134 /*!
135   Create a new connectivity object with the given number of type and
136   entity. If a connectivity already exist, delete it !
137
138   For exemple setNumberOfTypes(3,MED_CELL) create a connectivity with 3 
139   medGeometryElement in MESH for MED_CELL entity (like MED_TETRA4, 
140   MED_PYRA5 and MED_HEXA6 for example).
141
142   Return an exception if could not create the connectivity (as if we set 
143   MED_FACE connectivity before MED_CELL).
144 */
145 void MESHING::setNumberOfTypes(const int NumberOfTypes,
146                                const medEntityMesh Entity) 
147   throw (MEDEXCEPTION)
148 {
149   const char * LOC = "MESHING::setNumberOfTypes( medEntityMesh ) : ";
150
151   // No defined for MED_NODE !
152   if (Entity == MED_NODE)
153     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not required with MED_NODE !"));
154
155   if (MED_CELL == Entity) {
156     SCRUTE(_connectivity);
157 //     if (_connectivity != (CONNECTIVITY *) NULL)
158 //       delete _connectivity ;
159     _connectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
160
161   } else {
162
163     if (_connectivity == NULL) // we must have defined MED_CELL connectivity
164       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_CELL defined !"));
165
166     if (MED_FACE == Entity)
167       if (3 != getSpaceDimension())
168         throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE could be defined in non 3D space !"));
169     
170     if (MED_EDGE == Entity)
171       if (3 == getSpaceDimension()) {
172         if (!_connectivity->existConnectivity(MED_NODAL,MED_FACE))
173           throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE defined !"));
174       } else {
175         if (2 != getSpaceDimension())
176           throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Could not set connectivity on MED_EDGE !"));
177       }
178     // all rigth, we could create connectivity !
179     CONNECTIVITY * myConnectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
180     _connectivity->setConstituent(myConnectivity);
181   }
182 }
183
184 /*!
185   Set the list of geometric types used by a given entity.
186   medEntityMesh entity could be : MED_CELL, MED_FACE, MED_EDGE
187
188   REM : Don't use MED_NODE and MED_ALL_ENTITIES
189
190   If entity is not defined, throw an exception.
191 */
192 void MESHING::setTypes(const medGeometryElement * Types,
193                        const medEntityMesh entity)
194   throw (MEDEXCEPTION)
195 {
196   if (entity == MED_NODE)
197     throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : Not defined with MED_NODE entity !"));
198
199   if (_connectivity == NULL)
200     throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : No connectivity defined !"));
201
202   _connectivity->setGeometricTypes(Types,entity) ;
203 }
204
205 /*!
206   Set the number of elements for each geometric type of given entity.
207
208   Example : setNumberOfElements({12,23},MED_FACE)
209   if we have two type of face (MED_TRIA3 and MED_QUAD4), 
210   we set 12 triangles and 23 quadrangles.
211 */
212 void MESHING::setNumberOfElements(const int * NumberOfElements,
213                                   medEntityMesh Entity)
214   throw (MEDEXCEPTION)
215 {
216   const char * LOC = "MESHING::setNumberOfElements(const int *, medEntityMesh) : " ;
217
218   if (Entity==MED_NODE)
219     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
220
221   if (_connectivity == (CONNECTIVITY*)NULL)
222     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
223
224   int NumberOfTypes = getNumberOfTypes(Entity) ;
225   int * Count = new int[NumberOfTypes+1] ;
226   Count[0]=1 ;
227   for (int i=0; i<NumberOfTypes; i++)
228     Count[i+1]=Count[i]+NumberOfElements[i] ;
229   _connectivity->setCount(Count,Entity) ;
230   delete[] Count ;
231 }
232
233 /*!
234   Set the nodal connectivity for one geometric type of the given entity.
235
236   Example : setConnectivity({1,2,3,1,4,2},MED_FACE,MED_TRIA3)
237   Define 2 triangles face defined with nodes 1,2,3 and 1,4,2.
238 */
239 void MESHING::setConnectivity(const int * Connectivity,
240                               const medEntityMesh Entity,
241                               const medGeometryElement Type)
242   throw (MEDEXCEPTION)
243 {
244   const char * LOC = "MESHING::setConnectivity : " ;
245
246   if (Entity==MED_NODE)
247     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
248
249   if (_connectivity == (CONNECTIVITY*)NULL)
250     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
251
252   _connectivity->setNodal(Connectivity,Entity,Type) ;
253 }
254
255 /*!
256   NOT YET IMPLEMENTED !! WARNING
257 */
258 void MESHING::setConnectivities (const int * ConnectivityIndex,
259                                  const int * ConnectivityValue,
260                                  const medConnectivity ConnectivityType,
261                                  const medEntityMesh Entity)
262   throw (MEDEXCEPTION)
263 {
264   const char * LOC = "MESHING::setConnectivities : " ;
265
266   throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not Yet Implemented :: Warning !"));
267 }
268
269 /*!
270 */
271
272 // void MESHING::setGroup(const string name,
273 //                     const string description,
274 //                     const int NumberOfElements,
275 //                     const int * ElementsNumbers,
276 //                     const medEntityMesh Entity)
277 // {
278 //   GROUP * myGroup = new GROUP() ;
279 //   myGroup->setMesh(*this) ;
280 //   myGroup->setName(name) ;
281 //   myGroup->setDescription(description) ;
282 //   myGroup->setEntity(Entity) ;
283 //   // medEntityMesh and medGeometryElement ???
284 //   myGroup->setNumberOfGeometricType(NumberOfType) ;
285 //   myGroup->setGeometricType(Type) ;
286 //   myGroup->setNumberOfGaussPoint(NumberOfGaussPoint) ;
287 //   myGroup->setNumberOfElements(NumberOfElements) ;
288 //   myGroup->setNumber(Number) ;
289 // }
290
291 void MESHING::addGroup(const GROUP & Group)
292   throw (MEDEXCEPTION)
293 {
294   const char * LOC = "MESHING::addGroup : " ;
295
296   GROUP * myGroup = new GROUP(Group) ;
297   switch(Group.getEntity()){
298   case MED_CELL : {
299     _groupCell.push_back(myGroup);
300     _numberOfCellsGroups++;
301     break;
302   }
303   case MED_FACE : {
304      _groupFace.push_back(myGroup);
305     _numberOfFacesGroups++;
306     break;
307   }
308   case MED_EDGE : {
309      _groupEdge.push_back(myGroup);
310     _numberOfEdgesGroups++;
311     break;
312   }
313   case MED_NODE : {
314      _groupNode.push_back(myGroup);
315     _numberOfNodesGroups++;
316     break;
317   }
318   default :
319     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Entity !"));
320   }
321 }