Back to index

salome-med  6.5.0
MEDCalculatorDBSliceField.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 "MEDCalculatorDBSliceField.hxx"
00021 #include "MEDCalculatorDBRangeSelection.hxx"
00022 
00023 #include "MEDLoader.hxx"
00024 
00025 #include "MEDCouplingFieldDouble.hxx"
00026 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
00027 
00028 using namespace ParaMEDMEM;
00029 
00030 MEDCalculatorDBSliceField::MEDCalculatorDBSliceField(int iter, int order):_iteration(iter),_order(order),_field(0),_work(0)
00031 {
00032 }
00033 
00034 MEDCalculatorDBSliceField::MEDCalculatorDBSliceField(MEDCouplingFieldDouble *f):_field(f),_work(0)
00035 {
00036 }
00037 
00038 void MEDCalculatorDBSliceField::setField(MEDCouplingFieldDouble *f) const
00039 {
00040   if(_field!=f)
00041     {
00042       if(_field)
00043         _field->decrRef();
00044       _field=f;
00045     }
00046 }
00047 
00048 void MEDCalculatorDBSliceField::setName(const char *name)
00049 {
00050   _field->setName(name);
00051 }
00052 
00053 void MEDCalculatorDBSliceField::setDescription(const char *descr)
00054 {
00055   _field->setDescription(descr);
00056 }
00057 
00058 void MEDCalculatorDBSliceField::write(const char *fName, const std::string& n, const std::string& d) const throw(INTERP_KERNEL::Exception)
00059 {
00060   std::string kn=_field->getName();
00061   std::string kd=_field->getDescription();
00062   MEDCouplingFieldDouble *myF=const_cast<MEDCouplingFieldDouble *>(_field);
00063   myF->setName(n.c_str());
00064   myF->setDescription(d.c_str());
00065   MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fName,_field);
00066   myF->setName(kn.c_str());
00067   myF->setDescription(kd.c_str());
00068 }
00069 
00070 const MEDCouplingMesh *MEDCalculatorDBSliceField::getMesh(TypeOfField type, const std::string& fname, const std::string& mname, const std::string& fieldName) const
00071 {
00072   MEDCouplingFieldDouble *f=getField(type,fname,mname,fieldName);
00073   return f->getMesh();
00074 }
00075 
00076 MEDCalculatorDBSliceField::~MEDCalculatorDBSliceField()
00077 {
00078   if(_field)
00079     _field->decrRef();
00080   if(_work)
00081     _work->decrRef();
00082 }
00083 
00084 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::getField(TypeOfField type, const std::string& fname, const std::string& mname, const std::string& fieldName) const
00085 {
00086   if(!_field)
00087     _field=MEDLoader::ReadField(type,fname.c_str(),mname.c_str(),0,fieldName.c_str(),_iteration,_order);
00088   return _field;
00089 }
00090 
00094 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::getFieldWithoutQuestion(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const
00095 {
00096   std::vector<int> tIds=thisC.getIds(sizeCThis);
00097   return _field->keepSelectedComponents(tIds);
00098 }
00099 
00100 MEDCouplingFieldDouble *MEDCalculatorDBSliceField::buildCstFromThis(double val, int nbOfComp, const MEDCouplingFieldDouble *f) const
00101 {
00102   MEDCouplingFieldDouble *ret=MEDCouplingFieldDouble::New(f->getTypeOfField(),ONE_TIME);
00103   ret->setMesh(f->getMesh());
00104   ret->applyFunc(nbOfComp,val);
00105   ret->copyTinyAttrFrom(f);
00106   return ret;
00107 }
00108 
00109 void MEDCalculatorDBSliceField::assign(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
00110                                     int sizeCOther, const MEDCalculatorDBRangeSelection& otherC)
00111 {
00112   std::vector<int> tIds=thisC.getIds(sizeCThis);
00113   std::vector<int> oIds=otherC.getIds(sizeCOther);
00114   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=other->_field->keepSelectedComponents(oIds);
00115   _field->setSelectedComponents(f1,tIds);
00116 }
00117 
00118 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::add(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
00119                                                     int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
00120                                                     int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
00121 {
00122   if(cc!=0 || nc!=0)
00123     throw INTERP_KERNEL::Exception("Slice::add : not implemented yet node/cell permutation !");
00124   std::vector<int> tIds=thisC.getIds(sizeCThis);
00125   std::vector<int> oIds=otherC.getIds(sizeCOther);
00126   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00127   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
00128   f2->setMesh(f1->getMesh());
00129   MEDCouplingFieldDouble *f3=(*f1)+(*f2);
00130   return new MEDCalculatorDBSliceField(f3);
00131 }
00132 
00133 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::substract(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
00134                                                           int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
00135                                                           int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
00136 {
00137   if(cc!=0 || nc!=0)
00138     throw INTERP_KERNEL::Exception("Slice::substract : not implemented yet node/cell permutation !");
00139   std::vector<int> tIds=thisC.getIds(sizeCThis);
00140   std::vector<int> oIds=otherC.getIds(sizeCOther);
00141   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00142   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
00143   f2->setMesh(f1->getMesh());
00144   MEDCouplingFieldDouble *f3=(*f1)-(*f2);
00145   return new MEDCalculatorDBSliceField(f3);
00146 }
00147 
00148 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::multiply(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
00149                                                          int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
00150                                                          int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
00151 {
00152   if(cc!=0 || nc!=0)
00153     throw INTERP_KERNEL::Exception("Slice::multiply : not implemented yet node/cell permutation !");
00154   std::vector<int> tIds=thisC.getIds(sizeCThis);
00155   std::vector<int> oIds=otherC.getIds(sizeCOther);
00156   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00157   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
00158   f2->setMesh(f1->getMesh());
00159   MEDCouplingFieldDouble *f3=(*f1)*(*f2);
00160   return new MEDCalculatorDBSliceField(f3);
00161 }
00162 
00163 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::divide(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
00164                                                        int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
00165                                                        int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
00166 {
00167   if(cc!=0 || nc!=0)
00168     throw INTERP_KERNEL::Exception("Slice::divide : not implemented yet node/cell permutation !");
00169   std::vector<int> tIds=thisC.getIds(sizeCThis);
00170   std::vector<int> oIds=otherC.getIds(sizeCOther);
00171   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00172   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
00173   f2->setMesh(f1->getMesh());
00174   MEDCouplingFieldDouble *f3=(*f1)/(*f2);
00175   return new MEDCalculatorDBSliceField(f3);
00176 }
00177 
00178 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::dot(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
00179                                                     int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
00180 {
00181   std::vector<int> tIds=thisC.getIds(sizeCThis);
00182   std::vector<int> oIds=otherC.getIds(sizeCOther);
00183   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00184   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
00185   f2->setMesh(f1->getMesh());
00186   MEDCouplingFieldDouble *f3=f1->dot(*f2);
00187   return new MEDCalculatorDBSliceField(f3);
00188 }
00189 
00190 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::crossProduct(const MEDCalculatorDBSliceField* other, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
00191                                                              int sizeCOther, const MEDCalculatorDBRangeSelection& otherC) const
00192 {
00193   std::vector<int> tIds=thisC.getIds(sizeCThis);
00194   std::vector<int> oIds=otherC.getIds(sizeCOther);
00195   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00196   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
00197   f2->setMesh(f1->getMesh());
00198   MEDCouplingFieldDouble *f3=f1->crossProduct(*f2);
00199   return new MEDCalculatorDBSliceField(f3);
00200 }
00201 
00202 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::doublyContractedProduct(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
00203 {
00204   std::vector<int> tIds=thisC.getIds(sizeCThis);
00205   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00206   MEDCouplingFieldDouble *f2=f1->doublyContractedProduct();
00207   return new MEDCalculatorDBSliceField(f2);
00208 }
00209 
00210 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::determinant(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
00211 {
00212   std::vector<int> tIds=thisC.getIds(sizeCThis);
00213   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00214   MEDCouplingFieldDouble *f2=f1->determinant();
00215   return new MEDCalculatorDBSliceField(f2);
00216 }
00217 
00218 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::eigenValues(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
00219 {
00220   std::vector<int> tIds=thisC.getIds(sizeCThis);
00221   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00222   MEDCouplingFieldDouble *f2=f1->eigenValues();
00223   return new MEDCalculatorDBSliceField(f2);
00224 }
00225 
00226 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::eigenVectors(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
00227 {
00228   std::vector<int> tIds=thisC.getIds(sizeCThis);
00229   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00230   MEDCouplingFieldDouble *f2=f1->eigenVectors();
00231   return new MEDCalculatorDBSliceField(f2);
00232 }
00233 
00234 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::inverse(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
00235 {
00236   std::vector<int> tIds=thisC.getIds(sizeCThis);
00237   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00238   MEDCouplingFieldDouble *f2=f1->inverse();
00239   return new MEDCalculatorDBSliceField(f2);
00240 }
00241 
00242 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::trace(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
00243 {
00244   std::vector<int> tIds=thisC.getIds(sizeCThis);
00245   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00246   MEDCouplingFieldDouble *f2=f1->trace();
00247   return new MEDCalculatorDBSliceField(f2);
00248 }
00249 
00250 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::deviator(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
00251 {
00252   std::vector<int> tIds=thisC.getIds(sizeCThis);
00253   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00254   MEDCouplingFieldDouble *f2=f1->deviator();
00255   return new MEDCalculatorDBSliceField(f2);
00256 }
00257 
00258 MEDCalculatorDBSliceField *MEDCalculatorDBSliceField::magnitude(int sizeCThis, const MEDCalculatorDBRangeSelection& thisC) const throw(INTERP_KERNEL::Exception)
00259 {
00260   std::vector<int> tIds=thisC.getIds(sizeCThis);
00261   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00262   MEDCouplingFieldDouble *f2=f1->magnitude();
00263   return new MEDCalculatorDBSliceField(f2);
00264 }
00265 
00266 void MEDCalculatorDBSliceField::applyFunc(const char *func, int sizeCThis, const MEDCalculatorDBRangeSelection& thisC)
00267 {
00268   std::vector<int> tIds=thisC.getIds(sizeCThis);
00269   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00270   f1->applyFunc(func);
00271   _field->setSelectedComponents(f1,tIds);
00272 }
00273 
00274 bool MEDCalculatorDBSliceField::isEqual(const MEDCalculatorDBSliceField* other, const DataArrayInt *cc, const DataArrayInt *nc,
00275                                      int sizeCThis, const MEDCalculatorDBRangeSelection& thisC,
00276                                      int sizeCOther, const MEDCalculatorDBRangeSelection& otherC, double prec) const
00277 {
00278   if(cc!=0 || nc!=0)
00279     throw INTERP_KERNEL::Exception("Slice::isEqual : not implemented yet node/cell permutation !");
00280   std::vector<int> tIds=thisC.getIds(sizeCThis);
00281   std::vector<int> oIds=otherC.getIds(sizeCOther);
00282   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f1=_field->keepSelectedComponents(tIds);
00283   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2=other->_field->keepSelectedComponents(oIds);
00284   f2->setMesh(f1->getMesh());
00285   return f1->isEqualWithoutConsideringStr(f2,0,prec);
00286 }