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