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"
17 /*! Create an empty MESH. */
18 MESHING::MESHING(): MESH()
20 MESSAGE("MESHING::MESHING()");
22 SCRUTE(_connectivity);
27 MESSAGE("Deletinh MESHING !!");
30 /*! Set the dimension of the space */
31 void MESHING::setSpaceDimension(const int SpaceDimension)
33 _spaceDimension = SpaceDimension ;
36 /* Set the dimension of the MESHING */
37 // void MESHING::setMeshDimension(const int MeshDimension)
39 // _meshDimension = MeshDimension ;
42 /*! Set the number of nodes used in the MESH */
43 void MESHING::setNumberOfNodes(const int NumberOfNodes)
45 _numberOfNodes = NumberOfNodes ;
49 Set the whole coordinates array in a given system and interlacing mode.
50 The system coordinates are :
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
58 void MESHING::setCoordinates(const int SpaceDimension,
59 const int NumberOfNodes,
60 const double * Coordinates,
62 const medModeSwitch Mode)
64 setSpaceDimension(SpaceDimension);
65 setNumberOfNodes(NumberOfNodes);
68 SCRUTE(_connectivity);
69 //if (NULL != _coordinate) delete _coordinate;
71 _coordinate = new COORDINATE(SpaceDimension,
74 _coordinate->setCoordinates(Mode,Coordinates);
75 _coordinate->setCoordinatesSystem(System);
78 /*! Set the system in which coordinates are given (CARTESIAN,CYLINDRICAL,SPHERICAL) __??MED_CART??__. */
79 void MESHING::setCoordinatesSystem(const string System)
82 if (NULL == _coordinate)
83 throw MEDEXCEPTION(LOCALIZED("MESHING::setCoordinatesSystem : no coordinates defined"));
84 _coordinate->setCoordinatesSystem(System);
87 /*! Set the coordinate names array ("x ","y ","z ")
88 of size n*MED_TAILLE_PNOM
90 void MESHING::setCoordinatesNames(const string * name)
92 // int SpaceDimension = getSpaceDimension() ;
93 // _coordinate->setCoordinatesNames(SpaceDimension,name);
94 _coordinate->setCoordinatesNames(name);
98 Set the (i+1)^th component of coordinate names array
99 ("x ","y ","z ") of size n*MED_TAILLE_PNOM
101 void MESHING::setCoordinateName(const string name, const int i)
103 _coordinate->setCoordinateName(name,i);
106 /*! Set the coordinate unit names array ("cm ","cm ","cm ")
107 of size n*MED_TAILLE_PNOM
109 void MESHING::setCoordinatesUnits(const string * units)
111 // int SpaceDimension = getSpaceDimension() ;
112 // _coordinate->setCoordinatesUnits(SpaceDimension,units);
113 _coordinate->setCoordinatesUnits(units);
117 Set the (i+1)^th component of the coordinate unit names array
118 ("cm ","cm ","cm ") of size n*MED_TAILLE_PNOM
120 void MESHING::setCoordinateUnit(const string unit, const int i)
122 _coordinate->setCoordinateUnit(unit,i);
126 Create a new connectivity object with the given number of type and
127 entity. If a connectivity already exist, delete it !
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).
133 Return an exception if could not create the connectivity (as if we set
134 MED_FACE connectivity before MED_CELL).
136 void MESHING::setNumberOfTypes(const int NumberOfTypes,
137 const medEntityMesh Entity)
140 const char * LOC = "MESHING::setNumberOfTypes( medEntityMesh ) : ";
142 // No defined for MED_NODE !
143 if (Entity == MED_NODE)
144 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not required with MED_NODE !"));
146 if (MED_CELL == Entity) {
147 SCRUTE(_connectivity);
148 // if (_connectivity != (CONNECTIVITY *) NULL)
149 // delete _connectivity ;
150 _connectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
154 if (_connectivity == NULL) // we must have defined MED_CELL connectivity
155 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_CELL defined !"));
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 !"));
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 !"));
166 if (2 != getSpaceDimension())
167 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Could not set connectivity on MED_EDGE !"));
169 // all rigth, we could create connectivity !
170 CONNECTIVITY * myConnectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
171 _connectivity->setConstituent(myConnectivity);
176 Set the list of geometric types used by a given entity.
177 medEntityMesh entity could be : MED_CELL, MED_FACE, MED_EDGE
179 REM : Don't use MED_NODE and MED_ALL_ENTITIES
181 If entity is not defined, throw an exception.
183 void MESHING::setTypes(const medGeometryElement * Types,
184 const medEntityMesh entity)
187 if (entity == MED_NODE)
188 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : Not defined with MED_NODE entity !"));
190 if (_connectivity == NULL)
191 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : No connectivity defined !"));
193 _connectivity->setGeometricTypes(Types,entity) ;
197 Set the number of elements for each geometric type of given entity.
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.
203 void MESHING::setNumberOfElements(const int * NumberOfElements,
204 medEntityMesh Entity)
207 const char * LOC = "MESHING::setNumberOfElements(const int *, medEntityMesh) : " ;
209 if (Entity==MED_NODE)
210 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
212 if (_connectivity == (CONNECTIVITY*)NULL)
213 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
215 int NumberOfTypes = getNumberOfTypes(Entity) ;
216 int * Count = new int[NumberOfTypes+1] ;
218 for (int i=0; i<NumberOfTypes; i++)
219 Count[i+1]=Count[i]+NumberOfElements[i] ;
220 _connectivity->setCount(Count,Entity) ;
225 Set the nodal connectivity for one geometric type of the given entity.
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.
230 void MESHING::setConnectivity(const int * Connectivity,
231 const medEntityMesh Entity,
232 const medGeometryElement Type)
235 const char * LOC = "MESHING::setConnectivity : " ;
237 if (Entity==MED_NODE)
238 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
240 if (_connectivity == (CONNECTIVITY*)NULL)
241 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
243 _connectivity->setNodal(Connectivity,Entity,Type) ;
247 NOT YET IMPLEMENTED !! WARNING
249 void MESHING::setConnectivities (const int * ConnectivityIndex,
250 const int * ConnectivityValue,
251 const medConnectivity ConnectivityType,
252 const medEntityMesh Entity)
255 const char * LOC = "MESHING::setConnectivities : " ;
257 SCRUTE(ConnectivityType);
258 SCRUTE(ConnectivityValue);
259 SCRUTE(ConnectivityIndex);
261 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not Yet Implemented :: Warning !"));
267 // void MESHING::setGroup(const string name,
268 // const string description,
269 // const int NumberOfElements,
270 // const int * ElementsNumbers,
271 // const medEntityMesh Entity)
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) ;
286 void MESHING::addGroup(const GROUP & Group)
289 const char * LOC = "MESHING::addGroup : " ;
291 GROUP * myGroup = new GROUP(Group) ;
292 switch(Group.getEntity()){
294 _groupCell.push_back(myGroup);
295 _numberOfCellsGroups++;
299 _groupFace.push_back(myGroup);
300 _numberOfFacesGroups++;
304 _groupEdge.push_back(myGroup);
305 _numberOfEdgesGroups++;
309 _groupNode.push_back(myGroup);
310 _numberOfNodesGroups++;
314 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Entity !"));