3 File MEDMEM_Meshing.cxx
10 #include "MEDMEM_STRING.hxx"
11 #include "MEDMEM_Exception.hxx"
12 #include "MEDMEM_define.hxx"
14 #include "MEDMEM_Meshing.hxx"
15 #include "MEDMEM_Group.hxx"
16 using namespace MEDMEM;
18 /*! Create an empty %MESH. */
19 MESHING::MESHING(): MESH()
21 MESSAGE("MESHING::MESHING()");
23 SCRUTE(_connectivity);
28 MESSAGE("Deletinh MESHING !!");
31 /*! Set the dimension of the space */
32 void MESHING::setSpaceDimension(const int SpaceDimension)
34 _spaceDimension = SpaceDimension ;
37 /* Set the dimension of the MESHING */
38 // void MESHING::setMeshDimension(const int MeshDimension)
40 // _meshDimension = MeshDimension ;
43 /*! Set the number of nodes used in the %MESH */
44 void MESHING::setNumberOfNodes(const int NumberOfNodes)
46 _numberOfNodes = NumberOfNodes ;
50 Set the whole coordinates array in a given system and interlacing mode.
51 The system coordinates are :
55 The interlacing mode are :
56 - %MED_NO_INTERLACE : X1 X2 Y1 Y2 Z1 Z2
57 - %MED_FULL_INTERLACE : X1 Y1 Z1 X2 Y2 Z2
59 void MESHING::setCoordinates(const int SpaceDimension,
60 const int NumberOfNodes,
61 const double * Coordinates,
63 const medModeSwitch Mode)
65 setSpaceDimension(SpaceDimension);
66 setNumberOfNodes(NumberOfNodes);
69 SCRUTE(_connectivity);
70 //if (NULL != _coordinate) delete _coordinate;
72 _coordinate = new COORDINATE(SpaceDimension,
75 _coordinate->setCoordinates(Mode,Coordinates);
76 _coordinate->setCoordinatesSystem(System);
79 /*! Set the system in which coordinates are given
83 void MESHING::setCoordinatesSystem(const string System)
86 if (NULL == _coordinate)
87 throw MEDEXCEPTION(LOCALIZED("MESHING::setCoordinatesSystem : no coordinates defined"));
88 _coordinate->setCoordinatesSystem(System);
91 /*! Set the coordinate names array ("x ","y ","z ")
92 of size n*%MED_TAILLE_PNOM
94 void MESHING::setCoordinatesNames(const string * name)
96 // int SpaceDimension = getSpaceDimension() ;
97 // _coordinate->setCoordinatesNames(SpaceDimension,name);
98 _coordinate->setCoordinatesNames(name);
102 Set the (i+1)^th component of coordinate names array
103 ("x ","y ","z ") of size n*%MED_TAILLE_PNOM
105 void MESHING::setCoordinateName(const string name, const int i)
107 _coordinate->setCoordinateName(name,i);
110 /*! Set the coordinate unit names array ("cm ","cm ","cm ")
111 of size n*%MED_TAILLE_PNOM
113 void MESHING::setCoordinatesUnits(const string * units)
115 // int SpaceDimension = getSpaceDimension() ;
116 // _coordinate->setCoordinatesUnits(SpaceDimension,units);
117 _coordinate->setCoordinatesUnits(units);
121 Set the (i+1)^th component of the coordinate unit names array
122 ("cm ","cm ","cm ") of size n*%MED_TAILLE_PNOM
124 void MESHING::setCoordinateUnit(const string unit, const int i)
126 _coordinate->setCoordinateUnit(unit,i);
130 Create a new connectivity object with the given number of type and
131 entity. If a connectivity already exist, delete it !
133 For exemple setNumberOfTypes(3,MED_CELL) create a connectivity with 3
134 medGeometryElement in MESH for MED_CELL entity (like MED_TETRA4,
135 MED_PYRA5 and MED_HEXA6 for example).
137 Return an exception if could not create the connectivity (as if we set
138 MED_FACE connectivity before MED_CELL).
140 void MESHING::setNumberOfTypes(const int NumberOfTypes,
141 const medEntityMesh Entity)
144 const char * LOC = "MESHING::setNumberOfTypes( medEntityMesh ) : ";
146 // No defined for MED_NODE !
147 if (Entity == MED_NODE)
148 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not required with MED_NODE !"));
150 if (MED_CELL == Entity) {
151 SCRUTE(_connectivity);
152 // if (_connectivity != (CONNECTIVITY *) NULL)
153 // delete _connectivity ;
154 _connectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
158 if (_connectivity == NULL) // we must have defined MED_CELL connectivity
159 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_CELL defined !"));
161 if (MED_FACE == Entity)
162 if (3 != getSpaceDimension())
163 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE could be defined in non 3D space !"));
165 if (MED_EDGE == Entity)
166 if (3 == getSpaceDimension()) {
167 if (!_connectivity->existConnectivity(MED_NODAL,MED_FACE))
168 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE defined !"));
170 if (2 != getSpaceDimension())
171 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Could not set connectivity on MED_EDGE !"));
173 // all rigth, we could create connectivity !
174 CONNECTIVITY * myConnectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
175 _connectivity->setConstituent(myConnectivity);
180 Set the list of geometric types used by a given entity.
181 medEntityMesh entity could be : MED_CELL, MED_FACE, MED_EDGE
183 REM : Don't use MED_NODE and MED_ALL_ENTITIES
185 If entity is not defined, throws an exception.
187 void MESHING::setTypes(const medGeometryElement * Types,
188 const medEntityMesh entity)
191 if (entity == MED_NODE)
192 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : Not defined with MED_NODE entity !"));
194 if (_connectivity == NULL)
195 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : No connectivity defined !"));
197 _connectivity->setGeometricTypes(Types,entity) ;
201 Set the number of elements for each geometric type of given entity.
203 Example : setNumberOfElements({12,23},MED_FACE)
204 if we have two type of face (MED_TRIA3 and MED_QUAD4),
205 we set 12 triangles and 23 quadrangles.
207 void MESHING::setNumberOfElements(const int * NumberOfElements,
208 medEntityMesh Entity)
211 const char * LOC = "MESHING::setNumberOfElements(const int *, medEntityMesh) : " ;
213 if (Entity==MED_NODE)
214 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
216 if (_connectivity == (CONNECTIVITY*)NULL)
217 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
219 int NumberOfTypes = getNumberOfTypes(Entity) ;
220 int * Count = new int[NumberOfTypes+1] ;
222 for (int i=0; i<NumberOfTypes; i++)
223 Count[i+1]=Count[i]+NumberOfElements[i] ;
224 _connectivity->setCount(Count,Entity) ;
229 Set the nodal connectivity for one geometric type of the given entity.
231 Example : setConnectivity({1,2,3,1,4,2},MED_FACE,MED_TRIA3)
232 Define 2 triangles face defined with nodes 1,2,3 and 1,4,2.
234 void MESHING::setConnectivity(const int * Connectivity,
235 const medEntityMesh Entity,
236 const medGeometryElement Type)
239 const char * LOC = "MESHING::setConnectivity : " ;
241 if (Entity==MED_NODE)
242 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
244 if (_connectivity == (CONNECTIVITY*)NULL)
245 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
247 _connectivity->setNodal(Connectivity,Entity,Type) ;
251 NOT YET IMPLEMENTED !! WARNING
253 void MESHING::setConnectivities (const int * ConnectivityIndex,
254 const int * ConnectivityValue,
255 const medConnectivity ConnectivityType,
256 const medEntityMesh Entity)
259 const char * LOC = "MESHING::setConnectivities : " ;
261 SCRUTE(ConnectivityType);
262 SCRUTE(ConnectivityValue);
263 SCRUTE(ConnectivityIndex);
265 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not Yet Implemented :: Warning !"));
271 // void MESHING::setGroup(const string name,
272 // const string description,
273 // const int NumberOfElements,
274 // const int * ElementsNumbers,
275 // const medEntityMesh Entity)
277 // GROUP * myGroup = new GROUP() ;
278 // myGroup->setMesh(*this) ;
279 // myGroup->setName(name) ;
280 // myGroup->setDescription(description) ;
281 // myGroup->setEntity(Entity) ;
282 // // medEntityMesh and medGeometryElement ???
283 // myGroup->setNumberOfGeometricType(NumberOfType) ;
284 // myGroup->setGeometricType(Type) ;
285 // myGroup->setNumberOfGaussPoint(NumberOfGaussPoint) ;
286 // myGroup->setNumberOfElements(NumberOfElements) ;
287 // myGroup->setNumber(Number) ;
290 void MESHING::addGroup(const GROUP & Group)
293 const char * LOC = "MESHING::addGroup : " ;
295 GROUP * myGroup = new GROUP(Group) ;
296 switch(Group.getEntity()){
298 _groupCell.push_back(myGroup);
302 _groupFace.push_back(myGroup);
306 _groupEdge.push_back(myGroup);
310 _groupNode.push_back(myGroup);
314 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Entity !"));