1 // MED MEDMEM : MED files in memory
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : MEDMEM_Meshing.cxx
12 File MEDMEM_Meshing.cxx
18 #include "utilities.h"
19 #include "MEDMEM_STRING.hxx"
20 #include "MEDMEM_Exception.hxx"
21 #include "MEDMEM_define.hxx"
23 #include "MEDMEM_Meshing.hxx"
24 #include "MEDMEM_Group.hxx"
26 /*! Create an empty MESH. */
27 MESHING::MESHING(): MESH()
29 MESSAGE("MESHING::MESHING()");
31 SCRUTE(_connectivity);
36 MESSAGE("Deletinh MESHING !!");
39 /*! Set the dimension of the space */
40 void MESHING::setSpaceDimension(const int SpaceDimension)
42 _spaceDimension = SpaceDimension ;
45 /* Set the dimension of the MESHING */
46 // void MESHING::setMeshDimension(const int MeshDimension)
48 // _meshDimension = MeshDimension ;
51 /*! Set the number of nodes used in the MESH */
52 void MESHING::setNumberOfNodes(const int NumberOfNodes)
54 _numberOfNodes = NumberOfNodes ;
58 Set the whole coordinates array in a given system and interlacing mode.
59 The system coordinates are :
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
67 void MESHING::setCoordinates(const int SpaceDimension,
68 const int NumberOfNodes,
69 const double * Coordinates,
71 const medModeSwitch Mode)
73 setSpaceDimension(SpaceDimension);
74 setNumberOfNodes(NumberOfNodes);
77 SCRUTE(_connectivity);
78 //if (NULL != _coordinate) delete _coordinate;
80 _coordinate = new COORDINATE(SpaceDimension,
83 _coordinate->setCoordinates(Mode,Coordinates);
84 _coordinate->setCoordinatesSystem(System);
87 /*! Set the system in which coordinates are given (CARTESIAN,CYLINDRICAL,SPHERICAL) __??MED_CART??__. */
88 void MESHING::setCoordinatesSystem(const string System)
91 if (NULL == _coordinate)
92 throw MEDEXCEPTION(LOCALIZED("MESHING::setCoordinatesSystem : no coordinates defined"));
93 _coordinate->setCoordinatesSystem(System);
96 /*! Set the coordinate names array ("x ","y ","z ")
97 of size n*MED_TAILLE_PNOM
99 void MESHING::setCoordinatesNames(const string * name)
101 // int SpaceDimension = getSpaceDimension() ;
102 // _coordinate->setCoordinatesNames(SpaceDimension,name);
103 _coordinate->setCoordinatesNames(name);
107 Set the (i+1)^th component of coordinate names array
108 ("x ","y ","z ") of size n*MED_TAILLE_PNOM
110 void MESHING::setCoordinateName(const string name, const int i)
112 _coordinate->setCoordinateName(name,i);
115 /*! Set the coordinate unit names array ("cm ","cm ","cm ")
116 of size n*MED_TAILLE_PNOM
118 void MESHING::setCoordinatesUnits(const string * units)
120 // int SpaceDimension = getSpaceDimension() ;
121 // _coordinate->setCoordinatesUnits(SpaceDimension,units);
122 _coordinate->setCoordinatesUnits(units);
126 Set the (i+1)^th component of the coordinate unit names array
127 ("cm ","cm ","cm ") of size n*MED_TAILLE_PNOM
129 void MESHING::setCoordinateUnit(const string unit, const int i)
131 _coordinate->setCoordinateUnit(unit,i);
135 Create a new connectivity object with the given number of type and
136 entity. If a connectivity already exist, delete it !
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).
142 Return an exception if could not create the connectivity (as if we set
143 MED_FACE connectivity before MED_CELL).
145 void MESHING::setNumberOfTypes(const int NumberOfTypes,
146 const medEntityMesh Entity)
149 const char * LOC = "MESHING::setNumberOfTypes( medEntityMesh ) : ";
151 // No defined for MED_NODE !
152 if (Entity == MED_NODE)
153 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not required with MED_NODE !"));
155 if (MED_CELL == Entity) {
156 SCRUTE(_connectivity);
157 // if (_connectivity != (CONNECTIVITY *) NULL)
158 // delete _connectivity ;
159 _connectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
163 if (_connectivity == NULL) // we must have defined MED_CELL connectivity
164 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_CELL defined !"));
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 !"));
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 !"));
175 if (2 != getSpaceDimension())
176 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Could not set connectivity on MED_EDGE !"));
178 // all rigth, we could create connectivity !
179 CONNECTIVITY * myConnectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
180 _connectivity->setConstituent(myConnectivity);
185 Set the list of geometric types used by a given entity.
186 medEntityMesh entity could be : MED_CELL, MED_FACE, MED_EDGE
188 REM : Don't use MED_NODE and MED_ALL_ENTITIES
190 If entity is not defined, throw an exception.
192 void MESHING::setTypes(const medGeometryElement * Types,
193 const medEntityMesh entity)
196 if (entity == MED_NODE)
197 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : Not defined with MED_NODE entity !"));
199 if (_connectivity == NULL)
200 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : No connectivity defined !"));
202 _connectivity->setGeometricTypes(Types,entity) ;
206 Set the number of elements for each geometric type of given entity.
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.
212 void MESHING::setNumberOfElements(const int * NumberOfElements,
213 medEntityMesh Entity)
216 const char * LOC = "MESHING::setNumberOfElements(const int *, medEntityMesh) : " ;
218 if (Entity==MED_NODE)
219 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
221 if (_connectivity == (CONNECTIVITY*)NULL)
222 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
224 int NumberOfTypes = getNumberOfTypes(Entity) ;
225 int * Count = new int[NumberOfTypes+1] ;
227 for (int i=0; i<NumberOfTypes; i++)
228 Count[i+1]=Count[i]+NumberOfElements[i] ;
229 _connectivity->setCount(Count,Entity) ;
234 Set the nodal connectivity for one geometric type of the given entity.
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.
239 void MESHING::setConnectivity(const int * Connectivity,
240 const medEntityMesh Entity,
241 const medGeometryElement Type)
244 const char * LOC = "MESHING::setConnectivity : " ;
246 if (Entity==MED_NODE)
247 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
249 if (_connectivity == (CONNECTIVITY*)NULL)
250 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
252 _connectivity->setNodal(Connectivity,Entity,Type) ;
256 NOT YET IMPLEMENTED !! WARNING
258 void MESHING::setConnectivities (const int * ConnectivityIndex,
259 const int * ConnectivityValue,
260 const medConnectivity ConnectivityType,
261 const medEntityMesh Entity)
264 const char * LOC = "MESHING::setConnectivities : " ;
266 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not Yet Implemented :: Warning !"));
272 // void MESHING::setGroup(const string name,
273 // const string description,
274 // const int NumberOfElements,
275 // const int * ElementsNumbers,
276 // const medEntityMesh Entity)
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) ;
291 void MESHING::addGroup(const GROUP & Group)
294 const char * LOC = "MESHING::addGroup : " ;
296 GROUP * myGroup = new GROUP(Group) ;
297 switch(Group.getEntity()){
299 _groupCell.push_back(myGroup);
300 _numberOfCellsGroups++;
304 _groupFace.push_back(myGroup);
305 _numberOfFacesGroups++;
309 _groupEdge.push_back(myGroup);
310 _numberOfEdgesGroups++;
314 _groupNode.push_back(myGroup);
315 _numberOfNodesGroups++;
319 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Entity !"));