Back to index

salome-med  6.5.0
MEDCouplingField.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDCouplingField.hxx"
00021 #include "MEDCouplingMesh.hxx"
00022 #include "MEDCouplingFieldDiscretization.hxx"
00023 
00024 using namespace ParaMEDMEM;
00025 
00026 bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const
00027 {
00028   if(_name!=other->_name)
00029     return false;
00030   if(_desc!=other->_desc)
00031     return false;
00032   if(_nature!=other->_nature)
00033     return false;
00034   if(!_type->isEqual(other->_type,valsPrec))
00035     return false;
00036   if(_mesh==0 && other->_mesh==0)
00037     return true;
00038   if(_mesh==0 || other->_mesh==0)
00039     return false;
00040   if(_mesh==other->_mesh)
00041     return true;
00042   return _mesh->isEqual(other->_mesh,meshPrec);
00043 }
00044 
00045 bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
00046 {
00047   if(!_type->isEqualWithoutConsideringStr(other->_type,valsPrec))
00048     return false;
00049   if(_nature!=other->_nature)
00050     return false;
00051   if(_mesh==0 && other->_mesh==0)
00052     return true;
00053   if(_mesh==0 || other->_mesh==0)
00054     return false;
00055   if(_mesh==other->_mesh)
00056     return true;
00057   return _mesh->isEqualWithoutConsideringStr(other->_mesh,meshPrec);
00058 }
00059 
00065 bool MEDCouplingField::areCompatibleForMerge(const MEDCouplingField *other) const
00066 {
00067   if(!_type->isEqual(other->_type,1.))
00068     return false;
00069   if(_nature!=other->_nature)
00070     return false;
00071   if(_mesh==other->_mesh)
00072     return true;
00073   return _mesh->areCompatibleForMerge(other->_mesh);
00074 }
00075 
00080 bool MEDCouplingField::areStrictlyCompatible(const MEDCouplingField *other) const
00081 {
00082   if(!_type->isEqual(other->_type,1.e-12))
00083     return false;
00084   if(_nature!=other->_nature)
00085     return false;
00086   return _mesh==other->_mesh;
00087 }
00088 
00089 void MEDCouplingField::updateTime() const
00090 {
00091   if(_mesh)
00092     updateTimeWith(*_mesh);
00093   if(_type)
00094     updateTimeWith(*_type);
00095 }
00096 
00097 TypeOfField MEDCouplingField::getTypeOfField() const
00098 {
00099   return _type->getEnum();
00100 }
00101 
00107 NatureOfField MEDCouplingField::getNature() const
00108 {
00109   return _nature;
00110 }
00111 
00117 void MEDCouplingField::setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception)
00118 {
00119   _nature=nat;
00120 }
00121 
00128 DataArrayDouble *MEDCouplingField::getLocalizationOfDiscr() const throw(INTERP_KERNEL::Exception)
00129 {
00130   if(!_mesh)
00131     throw INTERP_KERNEL::Exception("MEDCouplingField::getLocalizationOfDiscr : No mesh set !");
00132   return _type->getLocalizationOfDiscValues(_mesh);
00133 }
00134 
00139 MEDCouplingFieldDouble *MEDCouplingField::buildMeasureField(bool isAbs) const throw(INTERP_KERNEL::Exception)
00140 {
00141   if(_mesh==0)
00142     throw INTERP_KERNEL::Exception("MEDCouplingField::getMeasureField : no mesh defined !!!");
00143   return _type->getMeasureField(_mesh,isAbs);
00144 }
00145 
00146 void MEDCouplingField::setMesh(const MEDCouplingMesh *mesh)
00147 {
00148   if(mesh!=_mesh)
00149     {
00150       if(_mesh)
00151         _mesh->decrRef();
00152       _mesh=mesh;
00153       if(_mesh)
00154         {
00155           _mesh->incrRef();
00156           updateTimeWith(*_mesh);
00157         }
00158     }
00159 }
00160 
00169 void MEDCouplingField::setGaussLocalizationOnType(INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
00170                                                   const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception)
00171 {
00172   if(!_mesh)
00173     throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnType method !");
00174   _type->setGaussLocalizationOnType(_mesh,type,refCoo,gsCoo,wg);
00175 }
00176 
00187 void MEDCouplingField::setGaussLocalizationOnCells(const int *begin, const int *end, const std::vector<double>& refCoo,
00188                                                    const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception)
00189 {
00190   if(!_mesh)
00191     throw INTERP_KERNEL::Exception("Mesh has to be set before calling setGaussLocalizationOnCells method !");
00192   _type->setGaussLocalizationOnCells(_mesh,begin,end,refCoo,gsCoo,wg);
00193 }
00194 
00198 void MEDCouplingField::clearGaussLocalizations()
00199 {
00200   if(!_mesh)
00201     throw INTERP_KERNEL::Exception("Mesh has to be set before calling clearGaussLocalizations method !");
00202   _type->clearGaussLocalizations();
00203 }
00204 
00211 MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception)
00212 {
00213   if(!_mesh)
00214     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !");
00215   return _type->getGaussLocalization(locId);
00216 }
00217 
00223 int MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
00224 {
00225   if(!_mesh)
00226     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneType method !");
00227   return _type->getGaussLocalizationIdOfOneType(type);
00228 }
00229 
00234 int MEDCouplingField::getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception)
00235 {
00236   if(!_mesh)
00237     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getNbOfGaussLocalization method !");
00238   return _type->getNbOfGaussLocalization();
00239 }
00240 
00246 int MEDCouplingField::getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception)
00247 {
00248   if(!_mesh)
00249     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !");
00250   return _type->getGaussLocalizationIdOfOneCell(cellId);
00251 }
00252 
00260 void MEDCouplingField::getCellIdsHavingGaussLocalization(int locId, std::vector<int>& cellIds) const throw(INTERP_KERNEL::Exception)
00261 {
00262   cellIds.clear();
00263   if(!_mesh)
00264     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdOfOneCell method !");
00265   _type->getCellIdsHavingGaussLocalization(locId,cellIds);
00266 }
00267 
00274 const MEDCouplingGaussLocalization& MEDCouplingField::getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception)
00275 {
00276   if(!_mesh)
00277     throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalization method !");
00278   return _type->getGaussLocalization(locId);
00279 }
00280 
00281 MEDCouplingField::~MEDCouplingField()
00282 {
00283   if(_mesh)
00284     _mesh->decrRef();
00285   delete _type;
00286 }
00287 
00288 MEDCouplingField::MEDCouplingField(MEDCouplingFieldDiscretization *type, NatureOfField nature):_nature(nature),_mesh(0),_type(type)
00289 {
00290 }
00291 
00292 MEDCouplingField::MEDCouplingField(TypeOfField type):_nature(NoNature),_mesh(0),_type(MEDCouplingFieldDiscretization::New(type))
00293 {
00294 }
00295 
00296 MEDCouplingField::MEDCouplingField(const MEDCouplingField& other):RefCountObject(other),_name(other._name),_desc(other._desc),_nature(other._nature),
00297                                                                   _mesh(0),_type(other._type->clone())
00298 {
00299   if(other._mesh)
00300     {
00301       _mesh=other._mesh;
00302       _mesh->incrRef();
00303     }
00304 }
00305 
00310 MEDCouplingMesh *MEDCouplingField::buildSubMeshData(const int *start, const int *end, DataArrayInt *&di) const
00311 {
00312   return _type->buildSubMeshData(_mesh,start,end,di);
00313 }
00314 
00319 int MEDCouplingField::getNumberOfTuplesExpected() const throw(INTERP_KERNEL::Exception)
00320 {
00321   if(_mesh)
00322     return _type->getNumberOfTuples(_mesh);
00323   else
00324     throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfTuplesExpected : Empty mesh !");
00325 }
00326 
00331 int MEDCouplingField::getNumberOfMeshPlacesExpected() const throw(INTERP_KERNEL::Exception)
00332 {
00333   if(_mesh)
00334     return _type->getNumberOfMeshPlaces(_mesh);
00335   else
00336     throw INTERP_KERNEL::Exception("MEDCouplingField::getNumberOfMeshPlacesExpected : Empty mesh !");
00337 }