Back to index

salome-med  6.5.0
MEDCouplingFieldOverTime.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 "MEDCouplingFieldOverTime.hxx"
00021 #include "MEDCouplingMesh.hxx"
00022 
00023 #include <cmath>
00024 
00025 using namespace ParaMEDMEM;
00026 
00027 MEDCouplingFieldOverTime *MEDCouplingFieldOverTime::New(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception)
00028 {
00029   return new MEDCouplingFieldOverTime(fs);
00030 }
00031 
00032 double MEDCouplingFieldOverTime::getTimeTolerance() const throw(INTERP_KERNEL::Exception)
00033 {
00034   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
00035   if(_fs.empty())
00036     throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::getTimeTolerance : empty set !");
00037   for(;it!=_fs.end();it++)
00038     if((const MEDCouplingFieldDouble *)(*it)!=0)
00039       return (*it)->getTimeTolerance();
00040   throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::getTimeTolerance : only empty fields in this !");
00041 }
00042 
00043 void MEDCouplingFieldOverTime::checkCoherency() const throw(INTERP_KERNEL::Exception)
00044 {
00045   MEDCouplingMultiFields::checkCoherency();
00046   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> >::const_iterator it=_fs.begin();
00047   for(;it!=_fs.end();it++)
00048     if((*it)->getTimeDiscretization()==NO_TIME)
00049       {
00050         std::ostringstream oss; oss << "MEDCouplingFieldOverTime::checkCoherency : At rank #" << std::distance(_fs.begin(),it) << " the field has no time !";
00051         throw INTERP_KERNEL::Exception(oss.str().c_str());
00052       }
00053   if(_fs.empty())
00054     return ;
00055   it=_fs.begin();
00056   const MEDCouplingFieldDouble& ref=*(*(it++));
00057   int tt1,tt2;
00058   double reft=ref.getEndTime(tt1,tt2);
00059   double eps=getTimeTolerance();
00060   int id=1;
00061   for(;it!=_fs.end();it++,id++)
00062     {
00063       if(!ref.getMesh()->areCompatibleForMerge((*it)->getMesh()))
00064         {
00065           std::ostringstream oss; oss << "Field slice at rank #" << id << " is not compatible with the first !";
00066           throw INTERP_KERNEL::Exception(oss.str().c_str());
00067         }
00068       double curt=(*it)->getStartTime(tt1,tt2);
00069       if(curt<reft-eps)
00070         throw INTERP_KERNEL::Exception("MEDCouplingFieldOverTime::checkCoherency : fields are NOT sorted properly in ascending time !");
00071       reft=(*it)->getEndTime(tt1,tt2);
00072     }
00073 }
00074 
00075 std::string MEDCouplingFieldOverTime::simpleRepr() const
00076 {
00077   std::ostringstream ret;
00078   ret << "MEDCouplingFieldOverTime with name : \"" << getName() << "\"\n";
00079   ret << "Description of MEDCouplingFieldOverTime is : \"" << getDescription() << "\"\n";
00080   ret << "Number of discretization : " << _fs.size() << "\n";
00081   ret << "Number of different meshes : ";
00082   std::vector<MEDCouplingMesh *> ms;
00083   std::vector<int> refms;
00084   try
00085     {
00086       ms=getDifferentMeshes(refms);
00087       ret << ms.size() << "\n";
00088     }
00089   catch(INTERP_KERNEL::Exception& e)
00090     { ret << "Current instance is INVALID !\n"; }
00091   try
00092     {
00093       MEDCouplingDefinitionTime dt=getDefinitionTimeZone();
00094       dt.appendRepr(ret);
00095     }
00096   catch(INTERP_KERNEL::Exception& e)
00097     { ret << "Definition zone is INVALID !\n"; }
00098   return ret.str();
00099 }
00100 
00101 bool MEDCouplingFieldOverTime::isEqual(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
00102 {
00103   if(!MEDCouplingMultiFields::isEqual(other,meshPrec,valsPrec))
00104     return false;
00105   const MEDCouplingFieldOverTime *otherC=dynamic_cast<const MEDCouplingFieldOverTime *>(other);
00106   if(!otherC)
00107     return false;
00108   // to implement
00109   return true;
00110 }
00111 
00112 bool MEDCouplingFieldOverTime::isEqualWithoutConsideringStr(const MEDCouplingMultiFields *other, double meshPrec, double valsPrec) const
00113 {
00114   if(!MEDCouplingMultiFields::isEqualWithoutConsideringStr(other,meshPrec,valsPrec))
00115     return false;
00116   const MEDCouplingFieldOverTime *otherC=dynamic_cast<const MEDCouplingFieldOverTime *>(other);
00117   if(!otherC)
00118     return false;
00119   // to implement
00120   return true;
00121 }
00122 
00123 std::vector<MEDCouplingMesh *> MEDCouplingFieldOverTime::getMeshes() const throw(INTERP_KERNEL::Exception)
00124 {
00125   checkCoherency();
00126   return MEDCouplingMultiFields::getMeshes();
00127 }
00128 
00129 std::vector<MEDCouplingMesh *> MEDCouplingFieldOverTime::getDifferentMeshes(std::vector<int>& refs) const throw(INTERP_KERNEL::Exception)
00130 {
00131   checkCoherency();
00132   return MEDCouplingMultiFields::getDifferentMeshes(refs);
00133 }
00134 
00135 std::vector<DataArrayDouble *> MEDCouplingFieldOverTime::getArrays() const throw(INTERP_KERNEL::Exception)
00136 {
00137   checkCoherency();
00138   return MEDCouplingMultiFields::getArrays();
00139 }
00140 
00141 std::vector<DataArrayDouble *> MEDCouplingFieldOverTime::getDifferentArrays(std::vector< std::vector<int> >& refs) const throw(INTERP_KERNEL::Exception)
00142 {
00143   checkCoherency();
00144   return MEDCouplingMultiFields::getDifferentArrays(refs);
00145 }
00146 
00147 MEDCouplingDefinitionTime MEDCouplingFieldOverTime::getDefinitionTimeZone() const
00148 {
00149   std::vector< std::vector<int> > tmp;
00150   getDifferentArrays(tmp);
00151   std::vector<const MEDCouplingFieldDouble *> tmp2(_fs.begin(),_fs.end());
00152   std::vector<int> tmp3;
00153   getDifferentMeshes(tmp3);
00154   return MEDCouplingDefinitionTime(tmp2,tmp3,tmp);
00155 }
00156 
00157 MEDCouplingFieldOverTime::MEDCouplingFieldOverTime(const std::vector<MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception):MEDCouplingMultiFields(fs)
00158 {
00159   checkCoherency();
00160 }
00161 
00162 MEDCouplingFieldOverTime::MEDCouplingFieldOverTime()
00163 {
00164 }