2 File MEDMEM_Meshing.cxx
9 #include "MEDMEM_STRING.hxx"
10 #include "MEDMEM_Exception.hxx"
11 #include "MEDMEM_define.hxx"
13 #include "MEDMEM_Meshing.hxx"
14 #include "MEDMEM_Group.hxx"
17 using namespace MEDMEM;
18 using namespace MED_EN;
20 /*! Create an empty MESH. */
21 MESHING::MESHING(): MESH()
23 MESSAGE("MESHING::MESHING()");
25 SCRUTE(_connectivity);
30 MESSAGE("Deletinh MESHING !!");
33 /*! Set the dimension of the space */
34 void MESHING::setSpaceDimension(const int SpaceDimension)
36 _spaceDimension = SpaceDimension ;
39 /* Set the dimension of the MESHING */
40 // void MESHING::setMeshDimension(const int MeshDimension)
42 // _meshDimension = MeshDimension ;
45 /*! Set the number of nodes used in the MESH */
46 void MESHING::setNumberOfNodes(const int NumberOfNodes)
48 _numberOfNodes = NumberOfNodes ;
52 Set the whole coordinates array in a given system and interlacing mode.
53 The system coordinates are :
57 The interlacing mode are :
58 - MED_NO_INTERLACE : X1 X2 Y1 Y2 Z1 Z2
59 - MED_FULL_INTERLACE : X1 Y1 Z1 X2 Y2 Z2
61 void MESHING::setCoordinates(const int SpaceDimension,
62 const int NumberOfNodes,
63 const double * Coordinates,
65 const medModeSwitch Mode)
67 setSpaceDimension(SpaceDimension);
68 setNumberOfNodes(NumberOfNodes);
71 SCRUTE(_connectivity);
72 //if (NULL != _coordinate) delete _coordinate;
74 _coordinate = new COORDINATE(SpaceDimension,
77 _coordinate->setCoordinates(Mode,Coordinates);
78 _coordinate->setCoordinatesSystem(System);
81 /*! Set the system in which coordinates are given (CARTESIAN,CYLINDRICAL,SPHERICAL) __??MED_CART??__. */
82 void MESHING::setCoordinatesSystem(const string System)
85 if (NULL == _coordinate)
86 throw MEDEXCEPTION(LOCALIZED("MESHING::setCoordinatesSystem : no coordinates defined"));
87 _coordinate->setCoordinatesSystem(System);
90 /*! Set the coordinate names array ("x ","y ","z ")
91 of size n*MED_TAILLE_PNOM
93 void MESHING::setCoordinatesNames(const string * name)
95 // int SpaceDimension = getSpaceDimension() ;
96 // _coordinate->setCoordinatesNames(SpaceDimension,name);
97 _coordinate->setCoordinatesNames(name);
101 Set the (i+1)^th component of coordinate names array
102 ("x ","y ","z ") of size n*MED_TAILLE_PNOM
104 void MESHING::setCoordinateName(const string name, const int i)
106 _coordinate->setCoordinateName(name,i);
109 /*! Set the coordinate unit names array ("cm ","cm ","cm ")
110 of size n*MED_TAILLE_PNOM
112 void MESHING::setCoordinatesUnits(const string * units)
114 // int SpaceDimension = getSpaceDimension() ;
115 // _coordinate->setCoordinatesUnits(SpaceDimension,units);
116 _coordinate->setCoordinatesUnits(units);
120 Set the (i+1)^th component of the coordinate unit names array
121 ("cm ","cm ","cm ") of size n*MED_TAILLE_PNOM
123 void MESHING::setCoordinateUnit(const string unit, const int i)
125 _coordinate->setCoordinateUnit(unit,i);
129 Create a new connectivity object with the given number of type and
130 entity. If a connectivity already exist, delete it !
132 For exemple setNumberOfTypes(3,MED_CELL) create a connectivity with 3
133 medGeometryElement in MESH for MED_CELL entity (like MED_TETRA4,
134 MED_PYRA5 and MED_HEXA6 for example).
136 Return an exception if could not create the connectivity (as if we set
137 MED_FACE connectivity before MED_CELL).
139 void MESHING::setNumberOfTypes(const int NumberOfTypes,
140 const medEntityMesh Entity)
143 const char * LOC = "MESHING::setNumberOfTypes( medEntityMesh ) : ";
145 // No defined for MED_NODE !
146 if (Entity == MED_NODE)
147 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not required with MED_NODE !"));
149 if (MED_CELL == Entity) {
150 SCRUTE(_connectivity);
151 // if (_connectivity != (CONNECTIVITY *) NULL)
152 // delete _connectivity ;
153 _connectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
157 if (_connectivity == NULL) // we must have defined MED_CELL connectivity
158 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_CELL defined !"));
160 if (MED_FACE == Entity)
161 if (3 != getSpaceDimension())
162 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE could be defined in non 3D space !"));
164 if (MED_EDGE == Entity)
165 if (3 == getSpaceDimension()) {
166 if (!_connectivity->existConnectivity(MED_NODAL,MED_FACE))
167 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE defined !"));
169 if (2 != getSpaceDimension())
170 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Could not set connectivity on MED_EDGE !"));
172 // all rigth, we could create connectivity !
173 CONNECTIVITY * myConnectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
174 _connectivity->setConstituent(myConnectivity);
179 Set the list of geometric types used by a given entity.
180 medEntityMesh entity could be : MED_CELL, MED_FACE, MED_EDGE
182 REM : Don't use MED_NODE and MED_ALL_ENTITIES
184 If entity is not defined, throw an exception.
186 void MESHING::setTypes(const medGeometryElement * Types,
187 const medEntityMesh entity)
190 if (entity == MED_NODE)
191 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : Not defined with MED_NODE entity !"));
193 if (_connectivity == NULL)
194 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : No connectivity defined !"));
196 _connectivity->setGeometricTypes(Types,entity) ;
200 Set the number of elements for each geometric type of given entity.
202 Example : setNumberOfElements({12,23},MED_FACE)
203 if we have two type of face (MED_TRIA3 and MED_QUAD4),
204 we set 12 triangles and 23 quadrangles.
206 void MESHING::setNumberOfElements(const int * NumberOfElements,
207 const medEntityMesh Entity)
210 const char * LOC = "MESHING::setNumberOfElements(const int *, medEntityMesh) : " ;
212 if (Entity==MED_NODE)
213 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
215 if (_connectivity == (CONNECTIVITY*)NULL)
216 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
218 int NumberOfTypes = getNumberOfTypes(Entity) ;
219 int * Count = new int[NumberOfTypes+1] ;
221 for (int i=0; i<NumberOfTypes; i++)
222 Count[i+1]=Count[i]+NumberOfElements[i] ;
223 _connectivity->setCount(Count,Entity) ;
228 Set the nodal connectivity for one geometric type of the given entity.
230 Example : setConnectivity({1,2,3,1,4,2},MED_FACE,MED_TRIA3)
231 Define 2 triangles face defined with nodes 1,2,3 and 1,4,2.
233 void MESHING::setConnectivity(const int * Connectivity,
234 const medEntityMesh Entity,
235 const medGeometryElement Type)
238 const char * LOC = "MESHING::setConnectivity : " ;
240 if (Entity==MED_NODE)
241 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
243 if (_connectivity == (CONNECTIVITY*)NULL)
244 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
246 _connectivity->setNodal(Connectivity,Entity,Type) ;
250 NOT YET IMPLEMENTED !! WARNING
252 void MESHING::setConnectivities (const int * ConnectivityIndex,
253 const int * ConnectivityValue,
254 const medConnectivity ConnectivityType,
255 const medEntityMesh Entity)
258 const char * LOC = "MESHING::setConnectivities : " ;
260 SCRUTE(ConnectivityType);
261 SCRUTE(ConnectivityValue);
262 SCRUTE(ConnectivityIndex);
264 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not Yet Implemented :: Warning !"));
270 // void MESHING::setGroup(const string name,
271 // const string description,
272 // const int NumberOfElements,
273 // const int * ElementsNumbers,
274 // const medEntityMesh Entity)
276 // GROUP * myGroup = new GROUP() ;
277 // myGroup->setMesh(*this) ;
278 // myGroup->setName(name) ;
279 // myGroup->setDescription(description) ;
280 // myGroup->setEntity(Entity) ;
281 // // medEntityMesh and medGeometryElement ???
282 // myGroup->setNumberOfGeometricType(NumberOfType) ;
283 // myGroup->setGeometricType(Type) ;
284 // myGroup->setNumberOfGaussPoint(NumberOfGaussPoint) ;
285 // myGroup->setNumberOfElements(NumberOfElements) ;
286 // myGroup->setNumber(Number) ;
289 void MESHING::addGroup(const GROUP & Group)
292 const char * LOC = "MESHING::addGroup : " ;
294 GROUP * myGroup = new GROUP(Group) ;
295 switch(Group.getEntity()){
297 _groupCell.push_back(myGroup);
301 _groupFace.push_back(myGroup);
305 _groupEdge.push_back(myGroup);
309 _groupNode.push_back(myGroup);
313 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Entity !"));