Back to index

salome-med  6.5.0
MEDMEM_Meshing.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 /*
00024   File MEDMEM_Meshing.cxx
00025 */
00026 
00027 #include <string>
00028 
00029 #include "MEDMEM_Utilities.hxx"
00030 #include "MEDMEM_STRING.hxx"
00031 #include "MEDMEM_Exception.hxx"
00032 #include "MEDMEM_define.hxx"
00033 
00034 #include "MEDMEM_Meshing.hxx"
00035 #include "MEDMEM_Group.hxx"
00036 
00037 using namespace std;
00038 using namespace MEDMEM;
00039 using namespace MED_EN;
00040 
00041 namespace MEDMEM {
00076 MESHING::MESHING(): MESH()
00077 {
00078   MESSAGE_MED("MESHING::MESHING()");
00079   SCRUTE_MED(_coordinate);
00080   SCRUTE_MED(_connectivity);
00081 }
00084 MESHING::~MESHING()
00085 {
00086   MESSAGE_MED("Deleting MESHING !!");
00087 }
00088 
00115 void MESHING::setCoordinates(const int SpaceDimension,
00116                              const int NumberOfNodes,
00117                              const double * Coordinates,
00118                              const string System,
00119                              const MED_EN::medModeSwitch Mode)
00120 {
00121   _spaceDimension = SpaceDimension;
00122   _numberOfNodes  = NumberOfNodes;
00123   if (_connectivity)
00124     _connectivity->setNumberOfNodes(NumberOfNodes);
00125 
00126   if ( !NumberOfNodes && !Coordinates )
00127     return; // enable using this method for setting SpaceDimension only
00128 
00129   SCRUTE_MED(_coordinate);
00130   SCRUTE_MED(_connectivity);
00131 
00132   if ( _coordinate )
00133     delete _coordinate, _coordinate = 0;
00134   _coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,Mode);
00135   _coordinate->setCoordinates(Mode,Coordinates);
00136   _coordinate->setCoordinatesSystem(System);
00137 }
00153 void MESHING::setCoordinatesNames(const string * name)
00154 {
00155 //    int SpaceDimension = getSpaceDimension() ;
00156 //    _coordinate->setCoordinatesNames(SpaceDimension,name);
00157   _coordinate->setCoordinatesNames(name);
00158 }
00159 
00160 
00161 
00169 void MESHING::setCoordinateName(const string name, const int i)
00170 {
00171   _coordinate->setCoordinateName(name,i);
00172 }
00173 
00184 void MESHING::setCoordinatesUnits(const string * units)
00185 {
00186 //    int SpaceDimension = getSpaceDimension() ;
00187 //    _coordinate->setCoordinatesUnits(SpaceDimension,units);
00188   _coordinate->setCoordinatesUnits(units);
00189 }
00190 
00196 void MESHING::setCoordinateUnit(const string unit, const int i)
00197 {
00198   _coordinate->setCoordinateUnit(unit,i);
00199 }
00218 void MESHING::setNumberOfTypes(const int NumberOfTypes,
00219                                const MED_EN::medEntityMesh Entity) 
00220   throw (MEDEXCEPTION)
00221 {
00222   const char * LOC = "MESHING::setNumberOfTypes( medEntityMesh ) : ";
00223 
00224   // No defined for MED_NODE !
00225   if (Entity == MED_NODE)
00226     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not required with MED_NODE !"));
00227 
00228   if (MED_CELL == Entity) {
00229     SCRUTE_MED(_connectivity);
00230     if (_connectivity )
00231       delete _connectivity ;
00232     _connectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
00233     _connectivity->setNumberOfNodes( _numberOfNodes );
00234 
00235   } else {
00236 
00237     if (_connectivity == NULL) // we must have defined MED_CELL connectivity
00238       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_CELL defined !"));
00239 
00240     if (MED_FACE == Entity)
00241       if (3 != getSpaceDimension())
00242         throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE could be defined in non 3D space !"));
00243 
00244     if (MED_EDGE == Entity)
00245       {
00246         if (3 == getSpaceDimension()) {
00247           if (3 == getMeshDimension() && !_connectivity->existConnectivity(MED_NODAL,MED_FACE))
00248             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity on MED_FACE defined !"));
00249           if (2 > getMeshDimension())
00250             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Could not set connectivity on MED_EDGE !"));
00251         } else {
00252           if (2 != getSpaceDimension())
00253             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Could not set connectivity on MED_EDGE !"));
00254         }
00255       }
00256     // all right, we could create connectivity !
00257     CONNECTIVITY * myConnectivity = new CONNECTIVITY(NumberOfTypes,Entity) ;
00258     myConnectivity->setNumberOfNodes(_connectivity->getNumberOfNodes());
00259     _connectivity->setConstituent(myConnectivity);
00260   }
00261 }
00262 
00275 void MESHING::setTypes(const MED_EN::medGeometryElement * Types,
00276                        const MED_EN::medEntityMesh        entity)
00277   throw (MEDEXCEPTION)
00278 {
00279   if (entity == MED_NODE)
00280     throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : Not defined with MED_NODE entity !"));
00281 
00282   if (_connectivity == NULL)
00283     throw MEDEXCEPTION(LOCALIZED("MESHING::setTypes : No connectivity defined !"));
00284 
00285   _connectivity->setGeometricTypes(Types,entity);
00286 }
00287 
00295 void MESHING::setNumberOfElements(const int * NumberOfElements,
00296                                   const MED_EN::medEntityMesh Entity)
00297   throw (MEDEXCEPTION)
00298 {
00299   const char * LOC = "MESHING::setNumberOfElements(const int *, medEntityMesh) : " ;
00300 
00301   if (Entity==MED_NODE)
00302     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
00303 
00304   if (_connectivity == (CONNECTIVITY*)NULL)
00305     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
00306 
00307   int NumberOfTypes = getNumberOfTypes(Entity) ;
00308   int * Count = new int[NumberOfTypes+1] ;
00309   Count[0]=1 ;
00310   for (int i=0; i<NumberOfTypes; i++)
00311     Count[i+1]=Count[i]+NumberOfElements[i] ;
00312   _connectivity->setCount(Count,Entity) ;
00313   delete[] Count ;
00314 }
00315 
00342 void MESHING::setConnectivity(const MED_EN::medEntityMesh Entity,
00343                               const MED_EN::medGeometryElement Type,
00344                               const int * Connectivity,
00345                               const int * PolyConnectivityIndex)
00346   throw (MEDEXCEPTION)
00347 {
00348   const char * LOC = "MESHING::setConnectivity : " ;
00349 
00350   if (Entity==MED_NODE)
00351     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined with MED_NODE entity !"));
00352 
00353   if (_connectivity == (CONNECTIVITY*)NULL)
00354     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"No connectivity defined !"));
00355 
00356   _connectivity->setNumberOfNodes(_numberOfNodes);
00357   _connectivity->setNodal(Connectivity,Entity,Type,PolyConnectivityIndex) ;
00358 }
00359 
00373 void MESHING::addGroup(const GROUP & Group)
00374   throw (MEDEXCEPTION)
00375 {
00376   const char * LOC = "MESHING::addGroup : " ;
00377 
00378   GROUP * myGroup = new GROUP(Group) ;
00379   if(myGroup->getMesh()==this)
00380     {
00381       removeReference();
00382     }
00383   switch(Group.getEntity()){
00384   case MED_CELL : {
00385     _groupCell.push_back(myGroup);
00386     break;
00387   }
00388   case MED_FACE : {
00389      _groupFace.push_back(myGroup);
00390     break;
00391   }
00392   case MED_EDGE : {
00393      _groupEdge.push_back(myGroup);
00394     break;
00395   }
00396   case MED_NODE : {
00397      _groupNode.push_back(myGroup);
00398     break;
00399   }
00400   default :
00401     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Bad Entity !"));
00402   }
00403 }
00404 
00405 }