1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 File MEDMEM_Meshing.cxx
27 #include "MEDMEM_Utilities.hxx"
28 #include "MEDMEM_STRING.hxx"
29 #include "MEDMEM_Exception.hxx"
30 #include "MEDMEM_define.hxx"
32 #include "MEDMEM_Meshing.hxx"
33 #include "MEDMEM_Group.hxx"
36 using namespace MEDMEM;
37 using namespace MED_EN;
39 /*! Create an empty MESH. */
40 MESHING::MESHING(): MESH()
42 MESSAGE("MESHING::MESHING()");
44 SCRUTE(_connectivity);
49 MESSAGE("Deletinh MESHING !!");
52 /*! Set the dimension of the space */
53 void MESHING::setSpaceDimension(const int SpaceDimension)
55 _spaceDimension = SpaceDimension ;
58 /*! Set the dimension of the MESHING */
59 void MESHING::setMeshDimension(const int MeshDimension)
61 _meshDimension = MeshDimension ;
62 _connectivity->setEntityDimension(MeshDimension);
65 /*! Set the number of nodes used in the MESH */
66 void MESHING::setNumberOfNodes(const int NumberOfNodes)
68 _numberOfNodes = NumberOfNodes ;
72 Set the whole coordinates array in a given system and interlacing mode.
73 The system coordinates are :
77 The interlacing mode are :
78 - MED_NO_INTERLACE : X1 X2 Y1 Y2 Z1 Z2
79 - MED_FULL_INTERLACE : X1 Y1 Z1 X2 Y2 Z2
81 void MESHING::setCoordinates(const int SpaceDimension,
82 const int NumberOfNodes,
83 const double * Coordinates,
85 const medModeSwitch Mode)
87 setSpaceDimension(SpaceDimension);
88 setNumberOfNodes(NumberOfNodes);
91 SCRUTE(_connectivity);
92 //if (NULL != _coordinate) delete _coordinate;
94 _coordinate = new COORDINATE(SpaceDimension,
97 _coordinate->setCoordinates(Mode,Coordinates);
98 _coordinate->setCoordinatesSystem(System);
101 /*! Set the system in which coordinates are given (CARTESIAN,CYLINDRICAL,SPHERICAL) __??MED_CART??__. */
102 void MESHING::setCoordinatesSystem(const string System)
105 if (NULL == _coordinate)
106 throw MEDEXCEPTION(LOCALIZED("MESHING::setCoordinatesSystem : no coordinates defined"));
107 _coordinate->setCoordinatesSystem(System);
110 /*! Set the coordinate names array ("x ","y ","z ")
111 of size n*MED_TAILLE_PNOM
113 void MESHING::setCoordinatesNames(const string * name)
115 // int SpaceDimension = getSpaceDimension() ;
116 // _coordinate->setCoordinatesNames(SpaceDimension,name);
117 _coordinate->setCoordinatesNames(name);
121 Set the (i+1)^th component of coordinate names array
122 ("x ","y ","z ") of size n*MED_TAILLE_PNOM
124 void MESHING::setCoordinateName(const string name, const int i)
126 _coordinate->setCoordinateName(name,i);
129 /*! Set the coordinate unit names array ("cm ","cm ","cm ")
130 of size n*MED_TAILLE_PNOM
132 void MESHING::setCoordinatesUnits(const string * units)
134 // int SpaceDimension = getSpaceDimension() ;
135 // _coordinate->setCoordinatesUnits(SpaceDimension,units);
136 _coordinate->setCoordinatesUnits(units);
140 Set the (i+1)^th component of the coordinate unit names array
141 ("cm ","cm ","cm ") of size n*MED_TAILLE_PNOM
143 void MESHING::setCoordinateUnit(const string unit, const int i)
145 _coordinate->setCoordinateUnit(unit,i);
149 Create a new connectivity object with the given number of type and
150 entity. If a connectivity already exist, delete it !
152 For exemple setNumberOfTypes(3,MED_CELL) create a connectivity with 3
153 medGeometryElement in MESH for MED_CELL entity (like MED_TETRA4,
154 MED_PYRA5 and MED_HEXA6 for example).
156 Return an exception if could not create the connectivity (as if we set
157 MED_FACE connectivity before MED_CELL).
159 void MESHING::setNumberOfTypes(const int NumberOfTypes,
160 const medEntityMesh Entity)
163 const char * LOC = "MESHING::setNumberOfTypes( medEntityMesh ) : ";
165 // No defined for MED_NODE !
166 if (Entity == MED_NODE)
167 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not required with MED_NODE !"));
169 if (MED_CELL == Entity) {
170 SCRUTE(_connectivity);
171 // if (_connectivity != (CONNECTIVITY *) NULL)
172 // delete _connectivity ;
173 _connectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
177 if (_connectivity == NULL) // we must have defined MED_CELL connectivity
178 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_CELL defined !"));
180 if (MED_FACE == Entity)
181 if (3 != getSpaceDimension())
182 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE could be defined in non 3D space !"));
184 if (MED_EDGE == Entity)
185 if (3 == getSpaceDimension()) {
186 if (!_connectivity->existConnectivity(MED_NODAL,MED_FACE))
187 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE defined !"));
189 if (2 != getSpaceDimension())
190 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Could not set connectivity on MED_EDGE !"));
192 // all rigth, we could create connectivity !
193 CONNECTIVITY * myConnectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
194 myConnectivity->setEntityDimension(_connectivity->getEntityDimension()-1);
195 _connectivity->setConstituent(myConnectivity);
200 Set the list of geometric types used by a given entity.
201 medEntityMesh entity could be : MED_CELL, MED_FACE, MED_EDGE
203 REM : Don't use MED_NODE and MED_ALL_ENTITIES
205 If entity is not defined, throw an exception.
207 void MESHING::setTypes(const medGeometryElement * Types,
208 const medEntityMesh entity)
211 if (entity == MED_NODE)
212 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : Not defined with MED_NODE entity !"));
214 if (_connectivity == NULL)
215 throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : No connectivity defined !"));
217 _connectivity->setGeometricTypes(Types,entity) ;
221 Set the number of elements for each geometric type of given entity.
223 Example : setNumberOfElements({12,23},MED_FACE)
224 if we have two type of face (MED_TRIA3 and MED_QUAD4),
225 we set 12 triangles and 23 quadrangles.
227 void MESHING::setNumberOfElements(const int * NumberOfElements,
228 const medEntityMesh Entity)
231 const char * LOC = "MESHING::setNumberOfElements(const int *, medEntityMesh) : " ;
233 if (Entity==MED_NODE)
234 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
236 if (_connectivity == (CONNECTIVITY*)NULL)
237 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
239 int NumberOfTypes = getNumberOfTypes(Entity) ;
240 int * Count = new int[NumberOfTypes+1] ;
242 for (int i=0; i<NumberOfTypes; i++)
243 Count[i+1]=Count[i]+NumberOfElements[i] ;
244 _connectivity->setCount(Count,Entity) ;
249 Set the nodal connectivity for one geometric type of the given entity.
251 Example : setConnectivity({1,2,3,1,4,2},MED_FACE,MED_TRIA3)
252 Define 2 triangles face defined with nodes 1,2,3 and 1,4,2.
254 void MESHING::setConnectivity(const int * Connectivity,
255 const medEntityMesh Entity,
256 const medGeometryElement Type)
259 const char * LOC = "MESHING::setConnectivity : " ;
261 if (Entity==MED_NODE)
262 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
264 if (_connectivity == (CONNECTIVITY*)NULL)
265 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
267 _connectivity->setNodal(Connectivity,Entity,Type) ;
270 void MESHING::setPolygonsConnectivity (const int * ConnectivityIndex,
271 const int * ConnectivityValue,
273 const MED_EN::medEntityMesh Entity)
276 if (_connectivity == (CONNECTIVITY*)NULL)
277 throw MEDEXCEPTION("No connectivity defined !");
279 _connectivity->setPolygonsConnectivity(MED_NODAL, Entity, ConnectivityValue, ConnectivityIndex,ConnectivityIndex[nbOfPolygons]-1,nbOfPolygons) ;
282 void MESHING::setPolyhedraConnectivity (const int * PolyhedronIndex,
283 const int * FacesIndex,
286 const MED_EN::medEntityMesh Entity)
289 if (_connectivity == (CONNECTIVITY*)NULL)
290 throw MEDEXCEPTION("No connectivity defined !");
291 if(_connectivity->getPolyTypeRelativeTo()==MED_EN::MED_POLYHEDRA)
293 int nbOfFacesOfAllPolyhedra=PolyhedronIndex[nbOfPolyhedra]-1;
294 _connectivity->setPolyhedronConnectivity(MED_NODAL, Nodes, PolyhedronIndex, FacesIndex[nbOfFacesOfAllPolyhedra]-1 , nbOfPolyhedra, FacesIndex, nbOfFacesOfAllPolyhedra) ;
297 throw MEDEXCEPTION("Invalid connectivity for polyhedra !!!");
301 NOT YET IMPLEMENTED !! WARNING
303 void MESHING::setConnectivities (const int * ConnectivityIndex,
304 const int * ConnectivityValue,
305 const medConnectivity ConnectivityType,
306 const medEntityMesh Entity)
309 const char * LOC = "MESHING::setConnectivities : " ;
311 SCRUTE(ConnectivityType);
312 SCRUTE(ConnectivityValue);
313 SCRUTE(ConnectivityIndex);
315 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not Yet Implemented :: Warning !"));
321 // void MESHING::setGroup(const string name,
322 // const string description,
323 // const int NumberOfElements,
324 // const int * ElementsNumbers,
325 // const medEntityMesh Entity)
327 // GROUP * myGroup = new GROUP() ;
328 // myGroup->setMesh(*this) ;
329 // myGroup->setName(name) ;
330 // myGroup->setDescription(description) ;
331 // myGroup->setEntity(Entity) ;
332 // // medEntityMesh and medGeometryElement ???
333 // myGroup->setNumberOfGeometricType(NumberOfType) ;
334 // myGroup->setGeometricType(Type) ;
335 // myGroup->setNumberOfGaussPoint(NumberOfGaussPoint) ;
336 // myGroup->setNumberOfElements(NumberOfElements) ;
337 // myGroup->setNumber(Number) ;
340 void MESHING::addGroup(const GROUP & Group)
343 const char * LOC = "MESHING::addGroup : " ;
345 GROUP * myGroup = new GROUP(Group) ;
346 switch(Group.getEntity()){
348 _groupCell.push_back(myGroup);
352 _groupFace.push_back(myGroup);
356 _groupEdge.push_back(myGroup);
360 _groupNode.push_back(myGroup);
364 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Entity !"));