Back to index

salome-med  6.5.0
MEDCalculatorDBField.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 "MEDCalculatorDBField.hxx"
00021 #include "MEDCalculatorBrowserField.hxx"
00022 
00023 #include "MEDLoaderBase.hxx"
00024 #include "MEDLoader.hxx"
00025 
00026 #include "MEDCouplingUMesh.hxx"
00027 #include "MEDCouplingMemArray.hxx"
00028 #include "MEDCouplingFieldDouble.hxx"
00029 #include "MEDCouplingFieldOverTime.hxx"
00030 
00031 #include "MEDCouplingFieldOverTimeServant.hxx"
00032 #include "SALOME_NamingService.hxx"
00033 
00034 #include <cmath>
00035 
00036 using namespace ParaMEDMEM;
00037 
00038 MEDCalculatorDBFieldReal *MEDCalculatorDBField::New(const MEDCalculatorBrowserField& ls)
00039 {
00040   return new MEDCalculatorDBFieldReal(ls);
00041 }
00042 
00043 MEDCalculatorDBFieldCst *MEDCalculatorDBField::New(double val)
00044 {
00045   return new MEDCalculatorDBFieldCst(val);
00046 }
00047 
00048 MEDCalculatorDBField *MEDCalculatorDBField::operator+(double val) const throw(INTERP_KERNEL::Exception)
00049 {
00050   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
00051   return (*this)+(*par2);
00052 }
00053 
00054 MEDCalculatorDBField *MEDCalculatorDBField::operator-(double val) const throw(INTERP_KERNEL::Exception)
00055 {
00056   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
00057   return (*this)-(*par2);
00058 }
00059 
00060 MEDCalculatorDBField *MEDCalculatorDBField::operator*(double val) const throw(INTERP_KERNEL::Exception)
00061 {
00062   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
00063   return (*this)*(*par2);
00064 }
00065 
00066 MEDCalculatorDBField *MEDCalculatorDBField::operator/(double val) const throw(INTERP_KERNEL::Exception)
00067 {
00068   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
00069   return (*this)/(*par2);
00070 }
00071 
00072 MEDCalculatorDBFieldReal *MEDCalculatorDBFieldReal::operator()(const MEDCalculatorDBRangeSelection& t, const MEDCalculatorDBRangeSelection& p, const MEDCalculatorDBRangeSelection& c) throw(INTERP_KERNEL::Exception)
00073 {
00074   MEDCalculatorDBFieldReal *ret=new MEDCalculatorDBFieldReal(*this);
00075   ret->_t=t;
00076   ret->_p=p;
00077   ret->_c=c;
00078   return ret;
00079 }
00080 
00081 MEDCalculatorDBFieldReal::~MEDCalculatorDBFieldReal()
00082 {
00083 }
00084 
00085 MEDCalculatorDBFieldReal::MEDCalculatorDBFieldReal(TypeOfField type):_type(type)
00086 {
00087 }
00088 
00089 void MEDCalculatorDBFieldReal::setName(const char *name)
00090 {
00091   _name=name;
00092   /*fetchData();
00093   std::vector<int> ids=_t.getIds(_time_steps.size());
00094   for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
00095   _time_steps[*iter]->setName(name);*/
00096 }
00097 
00098 void MEDCalculatorDBFieldReal::setDescription(const char *descr)
00099 {
00100   _description=descr;
00101   /*fetchData();
00102   std::vector<int> ids=_t.getIds(_time_steps.size());
00103   for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
00104   _time_steps[*iter]->setDescription(descr);*/
00105 }
00106 
00107 void MEDCalculatorDBFieldReal::write(const char *fName, bool writeFromScratch) const throw(INTERP_KERNEL::Exception)
00108 {
00109   fetchData();
00110   std::vector<int> ids=_t.getIds(_time_steps.size());
00111   int step=ids[0];
00112   const MEDCouplingFieldDouble *field=_time_steps[step]->getField(_type,_file_name,_mesh_name,_field_name);
00113   const MEDCouplingUMesh *mesh=static_cast<const MEDCouplingUMesh *>(field->getMesh());
00114   int status=MEDLoaderBase::getStatusOfFile(fName);
00115   if(!writeFromScratch && status==MEDLoaderBase::EXIST_RW)
00116     {
00117       std::vector<std::string> ms=MEDLoader::GetMeshNames(fName);
00118       if(std::find(ms.begin(),ms.end(),mesh->getName())!=ms.end())
00119         {
00120           std::ostringstream oss; oss << "In file \"" << fName << "\" the mesh with name \"" << mesh->getName() << "\" already exists !"; 
00121           throw INTERP_KERNEL::Exception(oss.str().c_str());
00122         }
00123       std::vector<std::string> fs=MEDLoader::GetAllFieldNames(fName);
00124       if(std::find(fs.begin(),fs.end(),field->getName())!=fs.end())
00125         {
00126           std::ostringstream oss; oss << "In file \"" << fName << "\" the field with name \"" << field->getName() << "\" already exists !"; 
00127           throw INTERP_KERNEL::Exception(oss.str().c_str());
00128         }
00129     }
00130   MEDLoader::WriteUMesh(fName,mesh,writeFromScratch);
00131   for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
00132     _time_steps[*iter]->write(fName,_name,_description);
00133 }
00134 
00135 void MEDCalculatorDBFieldReal::display() const throw(INTERP_KERNEL::Exception)
00136 {
00137   fetchData();
00138   std::vector<int> ids=_t.getIds(_time_steps.size());
00139   std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > fs2(ids.size());
00140   int ii=0;
00141   for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
00142     fs2[ii++]=_time_steps[*iter]->getFieldWithoutQuestion(_c_labels.size(),_c);
00143   std::vector<MEDCouplingFieldDouble *> fs(fs2.size());
00144   std::copy(fs2.begin(),fs2.end(),fs.begin());
00145   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldOverTime> fot=MEDCouplingFieldOverTime::New(fs);
00146   //
00147   int argc=0;
00148   CORBA::ORB_var orb=CORBA::ORB_init(argc,0);
00149   CORBA::Object_var obj=orb->resolve_initial_references("RootPOA");
00150   PortableServer::POA_var poa=PortableServer::POA::_narrow(obj);
00151   PortableServer::POAManager_var mgr=poa->the_POAManager();
00152   mgr->activate();
00153   MEDCouplingFieldOverTimeServant *fots=new MEDCouplingFieldOverTimeServant(fot);
00154   SALOME_MED::MEDCouplingFieldOverTimeCorbaInterface_var fotPtr=fots->_this();
00155   //
00156   SALOME_NamingService ns(orb);
00157   ns.Change_Directory("/Containers");
00158   std::vector<std::string> subdirs=ns.list_subdirs();
00159   std::ostringstream path;
00160   path << "/Containers/" << subdirs[0] << "/FactoryServer/PARAVIS_inst_1";
00161   //
00162   CORBA::Object_var paravis=ns.Resolve(path.str().c_str());
00163   CORBA::Request_var req=paravis->_request("ExecuteScript");
00164   CORBA::NVList_ptr args=req->arguments();
00165   CORBA::Any ob;
00166   std::ostringstream script;
00167   char *ior=orb->object_to_string(fotPtr);
00168   script << "src1 = ParaMEDCorbaPluginSource()\nsrc1.IORCorba = '" << ior << "'\nasc=GetAnimationScene()\nrw=GetRenderView()\ndr=Show()\ndr.Visibility = 1\n";
00169   CORBA::string_free(ior);
00170   ob <<= script.str().c_str();
00171   args->add_value("script",ob,CORBA::ARG_IN);
00172   req->set_return_type(CORBA::_tc_void);
00173   req->invoke();
00174   // clean-up
00175 }
00176 
00177 std::string MEDCalculatorDBFieldReal::simpleRepr() const
00178 {
00179   std::ostringstream oss;
00180   oss << "Multitime field with name : \""<< _name << "\".\n";
00181   oss << "Description of the field is : \"" << _description << "\".\n";
00182   oss << "Number of time steps of multitime field : " << getNumberOfSteps() << ".\n";
00183   oss << "Number of components of multitime field : " << getNumberOfComponents() << ".\n";
00184   oss << "Components names attached are : ";
00185   std::vector<int> ids=_c.getIds(_c_labels.size());
00186   for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
00187     oss << "\"" << _c_labels[*iter] << "\" ";
00188   oss << ".\nNumber of fetched field in multime field : " << getNumberOfFetchedSteps() << "/" << getNumberOfSteps() << ".\n";
00189   return oss.str();
00190 }
00191 
00192 MEDCalculatorDBFieldReal::MEDCalculatorDBFieldReal(const MEDCalculatorBrowserField& ls):_file_name(ls.getFileName()),_mesh_name(ls.getCorrespondingMeshesFromField().front()),_field_name(ls.getName()),_type(ls.getType()),
00193                                                                      _c_labels(ls.getComponents())
00194 {
00195   const std::vector<MEDCalculatorBrowserStep>& steps=ls.getSteps();
00196   int sz=steps.size();
00197   for(int i=0;i<sz;i++)
00198     {
00199       MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBSliceField> elt(new MEDCalculatorDBSliceField(steps[i].getTimeStep(),steps[i].getOrder()));
00200       _time_steps.push_back(elt);
00201     }
00202 }
00203 
00204 const MEDCalculatorDBFieldReal& MEDCalculatorDBFieldReal::operator=(const MEDCalculatorDBFieldReal& other) throw(INTERP_KERNEL::Exception)
00205 {
00206   checkCoherency(other);
00207   std::vector<int> ids=_t.getIds(_time_steps.size());
00208   std::vector<int> ids2=other._t.getIds(other._time_steps.size());
00209   unsigned int sz=ids.size();
00210   if(sz!=ids2.size())
00211     throw INTERP_KERNEL::Exception("FieldReal::operator= : Timesteps lengthes mismatch !");
00212   fetchData();
00213   other.fetchData();
00214   for(unsigned int i=0;i<sz;i++)
00215     _time_steps[ids[i]]->assign(other._time_steps[ids2[i]],_c_labels.size(),_c,other._c_labels.size(),other._c);
00216   return *this;
00217 }
00218 
00219 const MEDCalculatorDBFieldReal& MEDCalculatorDBFieldReal::operator=(double val) throw(INTERP_KERNEL::Exception)
00220 {
00221   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> other=buildCstFieldFromThis(val);
00222   return (*this)=*other;
00223 }
00224 
00225 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator+(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
00226 {
00227   const MEDCalculatorDBField *other2=&other;
00228   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00229   if(otherr)
00230     return add(*otherr);
00231   else
00232     {
00233       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00234       if(otherc)
00235         {
00236           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
00237           MEDCalculatorDBField *ret=add(*othercr);
00238           return ret;
00239         }
00240       else
00241         throw INTERP_KERNEL::Exception("FieldReal::operator+ : unrecognized type of parameter recieved !");
00242     }
00243 }
00244 
00245 MEDCalculatorDBField *MEDCalculatorDBFieldReal::add(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
00246 {
00247   checkCoherency(other);
00248   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00249   fetchData();
00250   other.fetchData();
00251   DataArrayInt *cellCor,*nodeCor;
00252   std::vector<int> ids=_t.getIds(_time_steps.size());
00253   std::vector<int> ids2=other._t.getIds(other._time_steps.size());
00254   if(ids.size()!=ids2.size())
00255     throw INTERP_KERNEL::Exception("FieldReal::add : Timesteps lengthes mismatch !");
00256   int step=ids[0];
00257   int step2=ids2[0];
00258   const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
00259   const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
00260   mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
00261   int sz=ids.size();
00262   ret->_time_steps.resize(sz);
00263   for(int i=0;i<sz;i++)
00264     ret->_time_steps[i]=_time_steps[ids[i]]->add(other._time_steps[ids2[i]],cellCor,nodeCor,_c_labels.size(),_c,other._c_labels.size(),other._c);
00265   int newNbOfCompo=_c.getSize(_c_labels.size());
00266   ret->_c_labels.resize(newNbOfCompo);
00267   if(cellCor)
00268     cellCor->decrRef();
00269   if(nodeCor)
00270     nodeCor->decrRef();
00271   ret->incrRef();
00272   return ret;
00273 }
00274 
00275 bool MEDCalculatorDBFieldReal::isEqual(const MEDCalculatorDBField& other, double precM, double precF) const
00276 {
00277   const MEDCalculatorDBField *other2=&other;
00278   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00279   if(otherr)
00280     return isEqualSameType(*otherr,precM,precF);
00281   else
00282     {
00283       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00284       if(otherc)
00285         {
00286           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
00287           bool ret=isEqualSameType(*othercr,precM,precF);
00288           return ret;
00289         }
00290       else
00291         throw INTERP_KERNEL::Exception("FieldReal::isEqual : unrecognized type of parameter recieved !");
00292     }
00293 }
00294 
00295 bool MEDCalculatorDBFieldReal::isEqualSameType(const MEDCalculatorDBFieldReal& other, double precM, double precF) const
00296 {
00297   if(_description!=other._description)
00298     return false;
00299   fetchData();
00300   other.fetchData();
00301   DataArrayInt *cellCor,*nodeCor;
00302   std::vector<int> ids=_t.getIds(_time_steps.size());
00303   std::vector<int> ids2=other._t.getIds(other._time_steps.size());
00304   if(ids.size()!=ids2.size())
00305     return false;
00306   int step=ids[0];
00307   int step2=ids2[0];
00308   const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
00309   const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
00310   mesh->checkGeoEquivalWith(otherm,0,precM,cellCor,nodeCor);
00311   int sz=ids.size();
00312   for(int i=0;i<sz;i++)
00313     if(!_time_steps[ids[i]]->isEqual(other._time_steps[ids2[i]],cellCor,nodeCor,_c_labels.size(),_c,other._c_labels.size(),other._c,precF))
00314       return false;
00315   if(cellCor)
00316     cellCor->decrRef();
00317   if(nodeCor)
00318     nodeCor->decrRef();
00319   return true;
00320 }
00321 
00322 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator-(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
00323 {
00324   const MEDCalculatorDBField *other2=&other;
00325   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00326   if(otherr)
00327     return substract(*otherr);
00328   else
00329     {
00330       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00331       if(otherc)
00332         {
00333           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
00334           MEDCalculatorDBField *ret=substract(*othercr);
00335           return ret;
00336         }
00337       else
00338         throw INTERP_KERNEL::Exception("FieldReal::operator- : unrecognized type of parameter recieved !");
00339     }
00340 }
00341 
00342 MEDCalculatorDBField *MEDCalculatorDBFieldReal::substract(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
00343 {
00344   checkCoherency(other);
00345   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00346   fetchData();
00347   other.fetchData();
00348   DataArrayInt *cellCor,*nodeCor;
00349   std::vector<int> ids=_t.getIds(_time_steps.size());
00350   std::vector<int> ids2=other._t.getIds(other._time_steps.size());
00351   if(ids.size()!=ids2.size())
00352     throw INTERP_KERNEL::Exception("FieldReal::substract : Timesteps lengthes mismatch !");
00353   int step=ids[0];
00354   int step2=ids2[0];
00355   const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
00356   const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
00357   mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
00358   int sz=ids.size();
00359   ret->_time_steps.resize(sz);
00360   for(int i=0;i<sz;i++)
00361     ret->_time_steps[i]=_time_steps[ids[i]]->substract(other._time_steps[ids2[i]],cellCor,nodeCor,_c_labels.size(),_c,other._c_labels.size(),other._c);
00362   int newNbOfCompo=_c.getSize(_c_labels.size());
00363   ret->_c_labels.resize(newNbOfCompo);
00364   if(cellCor)
00365     cellCor->decrRef();
00366   if(nodeCor)
00367     nodeCor->decrRef();
00368   ret->incrRef();
00369   return ret;
00370 }
00371 
00372 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator*(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
00373 {
00374   const MEDCalculatorDBField *other2=&other;
00375   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00376   if(otherr)
00377     return multiply(*otherr);
00378   else
00379     {
00380       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00381       if(otherc)
00382         {
00383           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
00384           MEDCalculatorDBField *ret=multiply(*othercr);
00385           return ret;
00386         }
00387       else
00388         throw INTERP_KERNEL::Exception("FieldReal::operator* : unrecognized type of parameter recieved !");
00389     }
00390 }
00391 
00392 MEDCalculatorDBField *MEDCalculatorDBFieldReal::multiply(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
00393 {
00394   checkCoherency(other);
00395   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00396   fetchData();
00397   other.fetchData();
00398   DataArrayInt *cellCor,*nodeCor;
00399   std::vector<int> ids=_t.getIds(_time_steps.size());
00400   std::vector<int> ids2=other._t.getIds(other._time_steps.size());
00401   if(ids.size()!=ids2.size())
00402     throw INTERP_KERNEL::Exception("FieldReal::multiply : Timesteps lengthes mismatch !");
00403   int step=ids[0];
00404   int step2=ids2[0];
00405   const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
00406   const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
00407   mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
00408   int sz=ids.size();
00409   ret->_time_steps.resize(sz);
00410   for(int i=0;i<sz;i++)
00411     ret->_time_steps[i]=_time_steps[ids[i]]->multiply(other._time_steps[ids2[i]],cellCor,nodeCor,_c_labels.size(),_c,other._c_labels.size(),other._c);
00412   int newNbOfCompo=_c.getSize(_c_labels.size());
00413   ret->_c_labels.resize(newNbOfCompo);
00414   if(cellCor)
00415     cellCor->decrRef();
00416   if(nodeCor)
00417     nodeCor->decrRef();
00418   ret->incrRef();
00419   return ret;
00420 }
00421 
00422 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator/(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
00423 {
00424   const MEDCalculatorDBField *other2=&other;
00425   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00426   if(otherr)
00427     return divide(*otherr);
00428   else
00429     {
00430       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00431       if(otherc)
00432         {
00433           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
00434           MEDCalculatorDBField *ret=divide(*othercr);
00435           return ret;
00436         }
00437       else
00438         throw INTERP_KERNEL::Exception("FieldReal::operator/ : unrecognized type of parameter recieved !");
00439     }
00440 }
00441 
00442 MEDCalculatorDBField *MEDCalculatorDBFieldReal::divide(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
00443 {
00444   checkCoherency(other);
00445   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00446   fetchData();
00447   other.fetchData();
00448   DataArrayInt *cellCor,*nodeCor;
00449   std::vector<int> ids=_t.getIds(_time_steps.size());
00450   std::vector<int> ids2=other._t.getIds(other._time_steps.size());
00451   if(ids.size()!=ids2.size())
00452     throw INTERP_KERNEL::Exception("FieldReal::divide : Timesteps lengthes mismatch !");
00453   int step=ids[0];
00454   int step2=ids2[0];
00455   const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
00456   const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
00457   mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
00458   int sz=ids.size();
00459   ret->_time_steps.resize(sz);
00460   for(int i=0;i<sz;i++)
00461     ret->_time_steps[i]=_time_steps[ids[i]]->divide(other._time_steps[ids2[i]],cellCor,nodeCor,_c_labels.size(),_c,other._c_labels.size(),other._c);
00462   int newNbOfCompo=_c.getSize(_c_labels.size());
00463   ret->_c_labels.resize(newNbOfCompo);
00464   if(cellCor)
00465     cellCor->decrRef();
00466   if(nodeCor)
00467     nodeCor->decrRef();
00468   ret->incrRef();
00469   return ret;
00470 }
00471 
00472 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator^(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
00473 {
00474   return crossProduct(other);
00475 }
00476 
00477 MEDCalculatorDBField *MEDCalculatorDBFieldReal::dot(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
00478 {
00479   checkCoherency(other);
00480   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00481   fetchData();
00482   other.fetchData();
00483   std::vector<int> ids=_t.getIds(_time_steps.size());
00484   std::vector<int> ids2=other._t.getIds(other._time_steps.size());
00485   unsigned int sz=ids.size();
00486   if(sz!=ids2.size())
00487     throw INTERP_KERNEL::Exception("FieldReal::dot : Timesteps lengthes mismatch !");
00488   ret->_time_steps.resize(sz);
00489   for(unsigned int i=0;i<sz;i++)
00490     ret->_time_steps[i]=_time_steps[ids[i]]->dot(other._time_steps[ids2[i]],_c_labels.size(),_c,other._c_labels.size(),other._c);
00491   ret->_time_steps.resize(sz);
00492   ret->_c_labels.resize(1);
00493   ret->incrRef();
00494   return ret;
00495 }
00496 
00497 MEDCalculatorDBField *MEDCalculatorDBFieldReal::crossProduct(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
00498 {
00499   checkCoherency(other);
00500   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00501   fetchData();
00502   other.fetchData();
00503   std::vector<int> ids=_t.getIds(_time_steps.size());
00504   std::vector<int> ids2=other._t.getIds(other._time_steps.size());
00505   unsigned int sz=ids.size();
00506   if(sz!=ids2.size())
00507     throw INTERP_KERNEL::Exception("FieldReal::crossProduct : Timesteps lengthes mismatch !");
00508   ret->_time_steps.resize(sz);
00509   for(unsigned int i=0;i<sz;i++)
00510     ret->_time_steps[i]=_time_steps[ids[i]]->crossProduct(other._time_steps[ids2[i]],_c_labels.size(),_c,other._c_labels.size(),other._c);
00511   ret->_time_steps.resize(sz);
00512   ret->_c_labels.resize(3);
00513   ret->incrRef();
00514   return ret;
00515 }
00516 
00517 MEDCalculatorDBField *MEDCalculatorDBFieldReal::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
00518 {
00519   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00520   fetchData();
00521   std::vector<int> ids=_t.getIds(_time_steps.size());
00522   unsigned int sz=ids.size();
00523   ret->_time_steps.resize(sz);
00524   for(unsigned int i=0;i<sz;i++)
00525     ret->_time_steps[i]=_time_steps[ids[i]]->doublyContractedProduct(_c_labels.size(),_c);
00526   ret->_time_steps.resize(sz);
00527   ret->_c_labels.resize(1);
00528   ret->incrRef();
00529   return ret;
00530 }
00531 
00532 MEDCalculatorDBField *MEDCalculatorDBFieldReal::determinant() const throw(INTERP_KERNEL::Exception)
00533 {
00534   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00535   fetchData();
00536   std::vector<int> ids=_t.getIds(_time_steps.size());
00537   unsigned int sz=ids.size();
00538   ret->_time_steps.resize(sz);
00539   for(unsigned int i=0;i<sz;i++)
00540     ret->_time_steps[i]=_time_steps[ids[i]]->determinant(_c_labels.size(),_c);
00541   ret->_time_steps.resize(sz);
00542   ret->_c_labels.resize(1);
00543   ret->incrRef();
00544   return ret;
00545 }
00546 
00547 MEDCalculatorDBField *MEDCalculatorDBFieldReal::eigenValues() const throw(INTERP_KERNEL::Exception)
00548 {
00549   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00550   fetchData();
00551   std::vector<int> ids=_t.getIds(_time_steps.size());
00552   unsigned int sz=ids.size();
00553   ret->_time_steps.resize(sz);
00554   for(unsigned int i=0;i<sz;i++)
00555     ret->_time_steps[i]=_time_steps[ids[i]]->eigenValues(_c_labels.size(),_c);
00556   ret->_time_steps.resize(sz);
00557   if(sz!=0)
00558     {
00559       int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
00560       ret->_c_labels.resize(ncomp);
00561     }
00562   else
00563     ret->_c_labels.resize(0);
00564   ret->incrRef();
00565   return ret;
00566 }
00567 
00568 MEDCalculatorDBField *MEDCalculatorDBFieldReal::eigenVectors() const throw(INTERP_KERNEL::Exception)
00569 {
00570   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00571   fetchData();
00572   std::vector<int> ids=_t.getIds(_time_steps.size());
00573   unsigned int sz=ids.size();
00574   ret->_time_steps.resize(sz);
00575   for(unsigned int i=0;i<sz;i++)
00576     ret->_time_steps[i]=_time_steps[ids[i]]->eigenVectors(_c_labels.size(),_c);
00577   ret->_time_steps.resize(sz);
00578   if(sz!=0)
00579     {
00580       int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
00581       ret->_c_labels.resize(ncomp);
00582     }
00583   else
00584     ret->_c_labels.resize(0);
00585   ret->incrRef();
00586   return ret;
00587 }
00588 
00589 MEDCalculatorDBField *MEDCalculatorDBFieldReal::inverse() const throw(INTERP_KERNEL::Exception)
00590 {
00591   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00592   fetchData();
00593   std::vector<int> ids=_t.getIds(_time_steps.size());
00594   unsigned int sz=ids.size();
00595   ret->_time_steps.resize(sz);
00596   for(unsigned int i=0;i<sz;i++)
00597     ret->_time_steps[i]=_time_steps[ids[i]]->inverse(_c_labels.size(),_c);
00598   ret->_time_steps.resize(sz);
00599   if(sz!=0)
00600     {
00601       int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
00602       ret->_c_labels.resize(ncomp);
00603     }
00604   else
00605     ret->_c_labels.resize(0);
00606   ret->incrRef();
00607   return ret;
00608 }
00609 
00610 MEDCalculatorDBField *MEDCalculatorDBFieldReal::trace() const throw(INTERP_KERNEL::Exception)
00611 {
00612   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00613   fetchData();
00614   std::vector<int> ids=_t.getIds(_time_steps.size());
00615   unsigned int sz=ids.size();
00616   ret->_time_steps.resize(sz);
00617   for(unsigned int i=0;i<sz;i++)
00618     ret->_time_steps[i]=_time_steps[ids[i]]->trace(_c_labels.size(),_c);
00619   ret->_time_steps.resize(sz);
00620   ret->_c_labels.resize(1);
00621   ret->incrRef();
00622   return ret;
00623 }
00624 
00625 MEDCalculatorDBField *MEDCalculatorDBFieldReal::deviator() const throw(INTERP_KERNEL::Exception)
00626 {
00627   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00628   fetchData();
00629   std::vector<int> ids=_t.getIds(_time_steps.size());
00630   unsigned int sz=ids.size();
00631   ret->_time_steps.resize(sz);
00632   for(unsigned int i=0;i<sz;i++)
00633     ret->_time_steps[i]=_time_steps[ids[i]]->deviator(_c_labels.size(),_c);
00634   ret->_time_steps.resize(sz);
00635   if(sz!=0)
00636     {
00637       int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
00638       ret->_c_labels.resize(ncomp);
00639     }
00640   else
00641     ret->_c_labels.resize(0);
00642   ret->incrRef();
00643   return ret;
00644 }
00645 
00646 MEDCalculatorDBField *MEDCalculatorDBFieldReal::magnitude() const throw(INTERP_KERNEL::Exception)
00647 {
00648   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00649   fetchData();
00650   std::vector<int> ids=_t.getIds(_time_steps.size());
00651   unsigned int sz=ids.size();
00652   ret->_time_steps.resize(sz);
00653   for(unsigned int i=0;i<sz;i++)
00654     ret->_time_steps[i]=_time_steps[ids[i]]->magnitude(_c_labels.size(),_c);
00655   ret->_time_steps.resize(sz);
00656   ret->_c_labels.resize(1);
00657   ret->incrRef();
00658   return ret;
00659 }
00660 
00661 void MEDCalculatorDBFieldReal::applyFunc(const char *func) throw(INTERP_KERNEL::Exception)
00662 {
00663   fetchData();
00664   std::vector<int> ids=_t.getIds(_time_steps.size());
00665   for(std::vector<int>::const_iterator it=ids.begin();it!=ids.end();it++)
00666     _time_steps[*it]->applyFunc(func,_c_labels.size(),_c);
00667 }
00668 
00669 MEDCalculatorDBFieldReal *MEDCalculatorDBFieldReal::buildCstFieldFromThis(double val) const
00670 {
00671   MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
00672   ret->_p=_p;
00673   ret->_c_labels.resize(_c.getSize(_c_labels.size()));
00674   std::vector<int> stps=_t.getIds(_time_steps.size());
00675   int stepSize=stps.size();
00676   ret->_time_steps.resize(stepSize);
00677   if(stepSize==0)
00678     throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::buildCstFieldFromThis : no time steps defined !");
00679   for(int i=0;i<stepSize;i++)
00680     {
00681       const MEDCouplingFieldDouble *f=_time_steps[stps[i]]->getField(_type,_file_name,_mesh_name,_field_name);
00682       ret->_time_steps[i]=new MEDCalculatorDBSliceField(_time_steps[stps[i]]->buildCstFromThis(val,ret->_c_labels.size(),f));
00683     }
00684   ret->incrRef();
00685   return ret;
00686 }
00687 
00688 void MEDCalculatorDBFieldReal::checkCoherency(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
00689 {
00690   if(_type!=other._type)
00691     throw INTERP_KERNEL::Exception("Types of field mismatch !");
00692   if(getNumberOfSteps()!=other.getNumberOfSteps())
00693     throw INTERP_KERNEL::Exception("Time steps mismatch !");
00694   if(getNumberOfComponents()!=other.getNumberOfComponents())
00695     throw INTERP_KERNEL::Exception("Components mismatch !");
00696 }
00697 
00698 void MEDCalculatorDBFieldReal::fetchData() const throw(INTERP_KERNEL::Exception)
00699 {
00700   std::vector<std::pair<int,int> > idstoFetch;
00701   std::vector<int> ids=_t.getIds(_time_steps.size());
00702   int sz=ids.size();
00703   std::vector<int> idsInGlobalToFetch;
00704   for(int i=0;i<sz;i++)
00705     {
00706       MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBSliceField> elt=_time_steps[ids[i]];
00707       if(!elt->isFetched())
00708         {
00709           int dt,it;
00710           elt->getDtIt(dt,it);
00711           std::pair<int,int> p(dt,it);
00712           idstoFetch.push_back(p);
00713           idsInGlobalToFetch.push_back(ids[i]);
00714         }
00715     }
00716   std::vector<MEDCouplingFieldDouble *> fs=MEDLoader::ReadFieldsOnSameMesh(_type,_file_name.c_str(),_mesh_name.c_str(),0,_field_name.c_str(),idstoFetch);
00717   sz=fs.size();
00718   for(int i=0;i<sz;i++)
00719     {
00720       MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBSliceField> elt=_time_steps[idsInGlobalToFetch[i]];
00721       elt->setField(fs[i]);
00722     }
00723 }
00724 
00725 int MEDCalculatorDBFieldReal::getNumberOfSteps() const
00726 {
00727   return _t.getSize(_time_steps.size());
00728 }
00729 
00730 int MEDCalculatorDBFieldReal::getNumberOfFetchedSteps() const
00731 {
00732   int ret=0;
00733   std::vector<int> ids=_t.getIds(_time_steps.size());
00734   for(std::vector<int>::const_iterator it=ids.begin();it!=ids.end();it++)
00735     if(_time_steps[*it]->isFetched())
00736       ret++;
00737   return ret;
00738 }
00739 
00740 int MEDCalculatorDBFieldReal::getNumberOfComponents() const
00741 {
00742   return _c.getSize(_c_labels.size());
00743 }
00744 
00748 std::vector<MEDCouplingFieldDouble *> MEDCalculatorDBFieldReal::getFields() const throw(INTERP_KERNEL::Exception)
00749 {
00750   fetchData();
00751   std::vector<int> ids=_t.getIds(_time_steps.size());
00752   std::vector<MEDCouplingFieldDouble *> ret(ids.size());
00753   int i=0;
00754   for(std::vector<int>::const_iterator it=ids.begin();it!=ids.end();it++,i++)
00755     ret[i]=_time_steps[*it]->getFieldWithoutQuestion(_c_labels.size(),_c);
00756   return ret;
00757 }
00758 
00759 std::string MEDCalculatorDBFieldReal::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
00760 {
00761   if(i>=(int)_c_labels.size())
00762     throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::getInfoOnComponent : sepcified id >= number of component !");
00763   return _c_labels[i];
00764 }
00765 
00766 void MEDCalculatorDBFieldReal::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
00767 {
00768   if(i>=(int)_c_labels.size())
00769     throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::setInfoOnComponent : sepcified id >= number of component !");
00770   _c_labels[i]=info;
00771 }
00772 
00773 MEDCalculatorDBFieldCst::MEDCalculatorDBFieldCst(double val):_val(val)
00774 {
00775 }
00776 
00777 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator+(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
00778 {
00779   const MEDCalculatorDBField *other2=&other;
00780   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00781   if(otherc)
00782     {
00783       MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
00784       ret->_val=_val+otherc->_val;
00785       ret->incrRef();
00786       return ret;
00787     }
00788   else
00789     {
00790       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00791       if(otherr)
00792         {
00793           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
00794           MEDCalculatorDBField *ret=(*thisr)+other;
00795           return ret;
00796         }
00797       else
00798         throw INTERP_KERNEL::Exception("FieldCst::operator+ : unrecognized type of parameter recieved !");
00799     }
00800 }
00801 
00802 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator-(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
00803 {
00804   const MEDCalculatorDBField *other2=&other;
00805   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00806   if(otherc)
00807     {
00808       MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
00809       ret->_val=_val-otherc->_val;
00810       ret->incrRef();
00811       return ret;
00812     }
00813   else
00814     {
00815       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00816       if(otherr)
00817         {
00818           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
00819           MEDCalculatorDBField *ret=(*thisr)-other;
00820           return ret;
00821         }
00822       else
00823         throw INTERP_KERNEL::Exception("FieldCst::operator- : unrecognized type of parameter recieved !");
00824     }
00825 }
00826 
00827 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator*(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
00828 {
00829   const MEDCalculatorDBField *other2=&other;
00830   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00831   if(otherc)
00832     {
00833       MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
00834       ret->_val=_val*otherc->_val;
00835       ret->incrRef();
00836       return ret;
00837     }
00838   else
00839     {
00840       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00841       if(otherr)
00842         {
00843           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
00844           MEDCalculatorDBField *ret=(*thisr)*other;
00845           return ret;
00846         }
00847       else
00848         throw INTERP_KERNEL::Exception("FieldCst::operator* : unrecognized type of parameter recieved !");
00849     }
00850 }
00851 
00852 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator/(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
00853 {
00854   const MEDCalculatorDBField *other2=&other;
00855   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00856   if(otherc)
00857     {
00858       MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
00859       ret->_val=_val/otherc->_val;
00860       ret->incrRef();
00861       return ret;
00862     }
00863   else
00864     {
00865       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00866       if(otherr)
00867         {
00868           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
00869           MEDCalculatorDBField *ret=(*thisr)/other;
00870           return ret;
00871         }
00872       else
00873         throw INTERP_KERNEL::Exception("FieldCst::operator/ : unrecognized type of parameter recieved !");
00874     }
00875 }
00876 
00877 bool MEDCalculatorDBFieldCst::isEqual(const MEDCalculatorDBField& other, double precM, double precF) const
00878 {
00879   const MEDCalculatorDBField *other2=&other;
00880   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
00881   if(otherc)
00882     return fabs(otherc->_val-_val)<precF;
00883   else
00884     {
00885       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
00886       if(otherr)
00887         {
00888           MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
00889           bool ret=thisr->isEqual(other,precM,precF);
00890           return ret;
00891         }
00892       else
00893         throw INTERP_KERNEL::Exception("FieldCst::isEqual : unrecognized type of parameter recieved !");
00894     }
00895 }