Back to index

salome-med  6.5.0
MEDMEM_Mesh_i.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_Mesh_i.cxx
00025 // Project   : SALOME
00026 // Author    : EDF 
00027 //=============================================================================
00028 //
00029 #include "utilities.h"
00030 #include "Utils_CorbaException.hxx"
00031 #include "Utils_ORB_INIT.hxx"
00032 #include "Utils_SINGLETON.hxx"
00033 
00034 #include "MEDMEM_convert.hxx"
00035 #include "MEDMEM_Mesh_i.hxx"
00036 #include "MEDMEM_Support_i.hxx"
00037 #include "MEDMEM_Family_i.hxx"
00038 #include "MEDMEM_Group_i.hxx"
00039 #include "MEDMEM_FieldTemplate_i.hxx"
00040 
00041 #include "MEDMEM_Mesh.hxx"
00042 #include "MEDMEM_Family.hxx"
00043 #include "MEDMEM_Group.hxx"
00044 #include "MEDMEM_CellModel.hxx"
00045 
00046 #include "SenderFactory.hxx"
00047 #include "MultiCommException.hxx"
00048 
00049 #include <vector>
00050 
00051 using namespace MEDMEM;
00052 
00053 //=============================================================================
00057 //=============================================================================
00058 MESH_i::MESH_i():GMESH_i()
00059 {
00060 }
00061 //=============================================================================
00065 //=============================================================================
00066 MESH_i::~MESH_i()
00067 {
00068 }
00069 //=============================================================================
00073 //=============================================================================
00074 MESH_i::MESH_i(::MESH * const m ) :GMESH_i(m)
00075 {
00076 }
00077 //=============================================================================
00081 //=============================================================================
00082 MESH_i::MESH_i( MESH_i & m) :GMESH_i(m._mesh)
00083 {
00084 }
00085 //=============================================================================
00089 //=============================================================================
00090 CORBA::Boolean MESH_i::existConnectivity
00091 (SALOME_MED::medConnectivity connectivityType,
00092  SALOME_MED::medEntityMesh entity)
00093   throw (SALOME::SALOME_Exception)
00094 {
00095   if (_mesh==NULL)
00096     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00097   try
00098     {
00099       return ((::MESH*)_mesh)->existConnectivity(connectivityType,
00100                                                  convertIdlEntToMedEnt(entity));
00101     }
00102   catch (MEDEXCEPTION &ex)
00103     {
00104       MESSAGE("Unable to acces mesh flag existConnectivity");
00105       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00106     }
00107 }
00108 
00109 //=============================================================================
00113 //=============================================================================
00114 CORBA::Double MESH_i::getCoordinate(CORBA::Long Number, CORBA::Long Axis)
00115   throw (SALOME::SALOME_Exception)
00116 {
00117   if (_mesh==NULL)
00118     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00119   try
00120     {
00121       return ((::MESH*)_mesh)->getCoordinate(Number,Axis);
00122     }
00123   catch (MEDEXCEPTION &ex)
00124     {
00125       MESSAGE("Unable to acces this coordinate");
00126       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00127     }
00128 }
00129 //=============================================================================
00133 //=============================================================================
00134 SALOME_TYPES::ListOfDouble * MESH_i::getCoordinates(SALOME_MED::medModeSwitch typeSwitch)
00135   throw (SALOME::SALOME_Exception)
00136 {
00137   if (_mesh==NULL)
00138     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00139   SALOME_TYPES::ListOfDouble_var myseq = new SALOME_TYPES::ListOfDouble;
00140   try
00141     {
00142       int spaceDimension=((::MESH*)_mesh)->getSpaceDimension();
00143       int nbNodes=((::MESH*)_mesh)->getNumberOfNodes();
00144       const double * coordinates =((::MESH*)_mesh)->getCoordinates(
00145                                                                    convertIdlModeToMedMode(typeSwitch));
00146 
00147       myseq->length(nbNodes*spaceDimension);
00148       for (int i=0; i<nbNodes*spaceDimension; i++)
00149         {
00150           myseq[i]=coordinates[i];
00151         };
00152     }
00153   catch (MEDEXCEPTION &ex)
00154     {
00155       MESSAGE("Unable to acces the coordinates");
00156       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00157     }
00158   return myseq._retn();
00159 }
00160 //=============================================================================
00164 //=============================================================================
00165 SALOME::SenderDouble_ptr MESH_i::getSenderForCoordinates(SALOME_MED::medModeSwitch typeSwitch)
00166   throw (SALOME::SALOME_Exception)
00167 {
00168   if (_mesh==NULL)
00169     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",SALOME::INTERNAL_ERROR);
00170   SALOME::SenderDouble_ptr ret;
00171   try
00172     {
00173       int spaceDimension=((::MESH*)_mesh)->getSpaceDimension();
00174       int nbNodes=((::MESH*)_mesh)->getNumberOfNodes();
00175       const double * coordinates =((::MESH*)_mesh)->getCoordinates(convertIdlModeToMedMode(typeSwitch));
00176       ret=SenderFactory::buildSender(*this,coordinates,nbNodes*spaceDimension);
00177     }
00178   catch (MEDEXCEPTION &ex)
00179     {
00180       MESSAGE("Unable to acces the coordinates");
00181       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00182     }
00183   catch(MultiCommException &ex2)
00184     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
00185   return ret;
00186 }
00187 //=============================================================================
00191 //=============================================================================
00192 SALOME_TYPES::ListOfLong *  MESH_i::getConnectivity(SALOME_MED::medConnectivity mode, 
00193                                                     SALOME_MED::medEntityMesh entity, 
00194                                                     SALOME_MED::medGeometryElement geomElement)
00195   throw (SALOME::SALOME_Exception)
00196 {
00197   if (_mesh==NULL)
00198     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00199   if (verifieParam(entity,geomElement)==false)
00200     THROW_SALOME_CORBA_EXCEPTION("parameters don't match", SALOME::BAD_PARAM);
00201   SALOME_TYPES::ListOfLong_var myseq= new SALOME_TYPES::ListOfLong;
00202   try
00203     {
00204       int nbelements; 
00205       int elt1 = ((::MESH*)_mesh)->getNumberOfElements(
00206                                                        convertIdlEntToMedEnt(entity),
00207                                                        convertIdlEltToMedElt(geomElement));
00208       SCRUTE(elt1);
00209       if ( mode == SALOME_MED::MED_DESCENDING)
00210         {
00211           MESSAGE("MED_DESCENDING");
00212           int elt2 =(((::MESH*)_mesh)->getCellsTypes(MED_CELL))->getNumberOfConstituents(1);
00213           nbelements= elt2 * elt1;
00214           SCRUTE(elt2);
00215         }
00216       else
00217         {
00218           MESSAGE("MED_NODAL");
00219           nbelements = ((::MESH*)_mesh)->getConnectivityLength
00220             (convertIdlConnToMedConn(mode),
00221              convertIdlEntToMedEnt(entity),
00222              convertIdlEltToMedElt(geomElement));
00223         }
00224       SCRUTE(entity);
00225       SCRUTE(geomElement);
00226       SCRUTE(nbelements);
00227       myseq->length(nbelements);
00228       const int * numbers=((::MESH*)_mesh)->getConnectivity(convertIdlConnToMedConn(mode),
00229                                                             convertIdlEntToMedEnt(entity),
00230                                                             convertIdlEltToMedElt(geomElement));
00231       for (int i=0;i<nbelements;i++)
00232         {
00233           myseq[i]=numbers[i];
00234         }
00235     }
00236   catch (MEDEXCEPTION &ex)
00237     {
00238       MESSAGE("Unable to acces connectivities");
00239       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00240     }
00241   return myseq._retn();
00242 }
00243 //=============================================================================
00247 //=============================================================================
00248 SALOME::SenderInt_ptr MESH_i::getSenderForConnectivity(SALOME_MED::medConnectivity mode, 
00249                                                        SALOME_MED::medEntityMesh entity, 
00250                                                        SALOME_MED::medGeometryElement geomElement)
00251   throw (SALOME::SALOME_Exception)
00252 {
00253   if (_mesh==NULL)
00254     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00255   if (verifieParam(entity,geomElement)==false)
00256     THROW_SALOME_CORBA_EXCEPTION("parameters don't match", SALOME::BAD_PARAM);
00257   SALOME::SenderInt_ptr ret;
00258   try
00259     {
00260       int nbelements=((::MESH*)_mesh)->getConnectivityLength(convertIdlConnToMedConn(mode),
00261                                                              convertIdlEntToMedEnt(entity),
00262                                                              convertIdlEltToMedElt(geomElement));
00263       const int * numbers=((::MESH*)_mesh)->getConnectivity(convertIdlConnToMedConn(mode),
00264                                                             convertIdlEntToMedEnt(entity),
00265                                                             convertIdlEltToMedElt(geomElement));
00266       ret=SenderFactory::buildSender(*this,numbers,nbelements);
00267     }
00268   catch (MEDEXCEPTION &ex)
00269     {
00270       MESSAGE("Unable to acces connectivities");
00271       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00272     }
00273   catch(MultiCommException &ex2)
00274     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
00275   return ret;
00276 }
00277 
00278 //=============================================================================
00282 //=============================================================================
00283 SALOME_TYPES::ListOfLong* MESH_i::getConnectivityIndex(SALOME_MED::medConnectivity mode, 
00284                                                        SALOME_MED::medEntityMesh entity) 
00285   throw (SALOME::SALOME_Exception)
00286 {
00287   if (_mesh==NULL)
00288     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00289   SALOME_TYPES::ListOfLong_var myseq= new SALOME_TYPES::ListOfLong;
00290   try
00291     {
00292       int nbelements = ((::MESH*)_mesh)->getNumberOfElements(
00293                                                              convertIdlEntToMedEnt(entity),
00294                                                              MED_ALL_ELEMENTS) + 1;
00295       myseq->length(nbelements);
00296       const int * numbers=((::MESH*)_mesh)->getConnectivityIndex(convertIdlConnToMedConn(mode),
00297                                                                  convertIdlEntToMedEnt(entity));
00298       for (int i=0;i<nbelements;i++)
00299         {
00300           myseq[i]=numbers[i];
00301         }
00302     }
00303   catch (MEDEXCEPTION &ex)
00304     {
00305       MESSAGE("Unable to acces connectivities index");
00306       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00307     }
00308   return myseq._retn();
00309 }
00310 //=============================================================================
00314 //=============================================================================
00315 SALOME::SenderInt_ptr MESH_i::getSenderForConnectivityIndex(SALOME_MED::medConnectivity mode,
00316                                                             SALOME_MED::medEntityMesh entity,
00317                                                             SALOME_MED::medGeometryElement geomElement)
00318   throw (SALOME::SALOME_Exception)
00319 {
00320   if (_mesh==NULL)
00321     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00322   SALOME::SenderInt_ptr ret;
00323   try
00324     {
00325       int nbelements=((::MESH*)_mesh)->getNumberOfElements( convertIdlEntToMedEnt(entity),
00326                                                             convertIdlEltToMedElt(geomElement)) + 1;
00327       int iType = 0, nbTypes = ((::MESH*)_mesh)->getNumberOfTypes(convertIdlEntToMedEnt(entity));
00328       const MED_EN::medGeometryElement * types = ((::MESH*)_mesh)->getTypes(convertIdlEntToMedEnt(entity));
00329       while ( iType < nbTypes && types[iType] != convertIdlEltToMedElt(geomElement))
00330         ++iType;
00331       int prev_nbelements = ((::MESH*)_mesh)->getGlobalNumberingIndex( convertIdlEntToMedEnt(entity))[iType]-1;
00332 
00333       const int * numbers=((::MESH*)_mesh)->getConnectivityIndex(convertIdlConnToMedConn(mode),
00334                                                                  convertIdlEntToMedEnt(entity)) + prev_nbelements;
00335       ret=SenderFactory::buildSender(*this,numbers,nbelements);
00336     }
00337   catch (MEDEXCEPTION &ex)
00338     {
00339       MESSAGE("Unable to acces connectivities");
00340       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00341     }
00342   catch(MultiCommException &ex2)
00343     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
00344   return ret;
00345 }
00346 
00347 //=============================================================================
00351 //=============================================================================
00352 SALOME_TYPES::ListOfLong* MESH_i::getGlobalNumberingIndex( SALOME_MED::medEntityMesh entity)
00353   throw (SALOME::SALOME_Exception)
00354 {
00355   if (_mesh==NULL)
00356     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00357   SALOME_TYPES::ListOfLong_var myseq= new SALOME_TYPES::ListOfLong;
00358   try
00359     {
00360       int nbelements = ((::MESH*)_mesh)->getNumberOfTypes( convertIdlEntToMedEnt(entity)) + 1;
00361       myseq->length(nbelements);
00362       const int * numbers=((::MESH*)_mesh)->getGlobalNumberingIndex( convertIdlEntToMedEnt(entity));
00363       for (int i=0;i<nbelements;i++)
00364         {
00365           myseq[i]=numbers[i];
00366         }
00367     }
00368   catch (MEDEXCEPTION &ex)
00369     {
00370       MESSAGE("Unable to acces global index");
00371       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00372     }
00373   return myseq._retn();
00374 }
00375 
00376 //=============================================================================
00382 //=============================================================================
00383 CORBA::Long MESH_i::getElementNumber(SALOME_MED::medConnectivity mode,
00384                                      SALOME_MED::medEntityMesh entity,
00385                                      SALOME_MED::medGeometryElement type,
00386                                      const SALOME_TYPES::ListOfLong& connectivity)
00387   throw (SALOME::SALOME_Exception)
00388 {
00389   if (_mesh==NULL)
00390     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00391   int numberOfValue = connectivity.length() ;
00392   int * myConnectivity = new int[numberOfValue] ;
00393   for (int i=0; i<numberOfValue; i++)
00394     myConnectivity[i]=connectivity[i] ;
00395 
00396   int result ;
00397   try
00398     {
00399       result = ((::MESH*)_mesh)->getElementNumber(convertIdlConnToMedConn(mode),
00400                                                   convertIdlEntToMedEnt(entity),
00401                                                   convertIdlEltToMedElt(type),
00402                                                   myConnectivity) ;
00403     }
00404   catch (MEDEXCEPTION &ex) 
00405     {
00406       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00407     }
00408   return result ;
00409 }
00410 //=============================================================================
00415 //=============================================================================
00416 SALOME_TYPES::ListOfLong* MESH_i::getReverseConnectivity(SALOME_MED::medConnectivity mode)
00417   throw (SALOME::SALOME_Exception)
00418 {
00419   if (_mesh==NULL)
00420     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00421   SALOME_TYPES::ListOfLong_var myseq= new SALOME_TYPES::ListOfLong;
00422   try
00423     {
00424       int nbelements=((::MESH*)_mesh)->getReverseConnectivityLength(convertIdlConnToMedConn(mode));
00425       SCRUTE(nbelements);
00426       myseq->length(nbelements);
00427       const int * numbers=((::MESH*)_mesh)->getReverseConnectivity(convertIdlConnToMedConn(mode));
00428       for (int i=0;i<nbelements;i++)
00429         {
00430           myseq[i]=numbers[i];
00431         }
00432     }
00433   catch (MEDEXCEPTION &ex)
00434     {
00435       MESSAGE("Unable to acces reverse connectivities");
00436       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00437     }
00438   return myseq._retn();
00439 }
00440 //=============================================================================
00444 //=============================================================================
00445 SALOME_TYPES::ListOfLong* MESH_i::getReverseConnectivityIndex(SALOME_MED::medConnectivity mode)
00446   throw (SALOME::SALOME_Exception)
00447 {
00448   if (_mesh==NULL)
00449     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00450   SALOME_TYPES::ListOfLong_var myseq= new SALOME_TYPES::ListOfLong;
00451   try
00452     {
00453       int nbelements=((::MESH*)_mesh)->getReverseConnectivityIndexLength(convertIdlConnToMedConn(mode));
00454       myseq->length(nbelements);
00455       const int * numbers=((::MESH*)_mesh)->getReverseConnectivityIndex(convertIdlConnToMedConn(mode));
00456       for (int i=0;i<nbelements;i++)
00457         {
00458           myseq[i]=numbers[i];
00459         }
00460     }
00461   catch (MEDEXCEPTION &ex)
00462     {
00463       MESSAGE("Unable to acces reverse connectivities index");
00464       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00465     }
00466   return myseq._retn();
00467 }
00468 //=============================================================================
00472 //=============================================================================
00473 SALOME_MED::MESH::connectivityInfos * MESH_i::getConnectGlobal (SALOME_MED::medEntityMesh entity)
00474   throw (SALOME::SALOME_Exception)
00475 {
00476   if (_mesh==NULL)
00477     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
00478   SALOME_MED::MESH::connectivityInfos_var all=new SALOME_MED::MESH::connectivityInfos;
00479   try
00480     {
00481       MED_EN::medEntityMesh anEntity = convertIdlEntToMedEnt(entity);
00482       all->numberOfNodes  = ((::MESH*)_mesh)->getNumberOfNodes();
00483 
00484       int nbTypes=((::MESH*)_mesh)->getNumberOfTypes(anEntity);
00485       const medGeometryElement * types =((::MESH*)_mesh)->getTypes(anEntity);
00486       all->meshTypes.length(nbTypes);
00487       all->numberOfElements.length(nbTypes);
00488       all->nodalConnectivityLength.length(nbTypes);
00489       all->entityDimension=((::MESH*)_mesh)->getConnectivityptr()->getEntityDimension();
00490       for (int i=0; i<nbTypes; i++)
00491         {
00492           all->meshTypes[i]=convertMedEltToIdlElt(types[i]);
00493           all->numberOfElements[i]=((::MESH*)_mesh)->getNumberOfElements(anEntity,types[i]);
00494           all->nodalConnectivityLength[i]=
00495             ((::MESH*)_mesh)->getConnectivityLength(MED_EN::MED_NODAL,anEntity,types[i]);
00496         }
00497     }
00498   catch (MEDEXCEPTION &ex)
00499     {
00500       MESSAGE("Unable to acces connectivities informations");
00501       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
00502     }
00503   return all._retn();
00504 }