1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDCalculatorDBField.hxx"
21 #include "MEDCalculatorBrowserField.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDLoader.hxx"
26 #include "MEDCouplingUMesh.hxx"
27 #include "MEDCouplingMemArray.hxx"
28 #include "MEDCouplingFieldDouble.hxx"
29 #include "MEDCouplingFieldOverTime.hxx"
31 #include "MEDCouplingFieldOverTimeServant.hxx"
32 #include "SALOME_NamingService.hxx"
36 using namespace ParaMEDMEM;
38 MEDCalculatorDBFieldReal *MEDCalculatorDBField::New(const MEDCalculatorBrowserField& ls)
40 return new MEDCalculatorDBFieldReal(ls);
43 MEDCalculatorDBFieldCst *MEDCalculatorDBField::New(double val)
45 return new MEDCalculatorDBFieldCst(val);
48 MEDCalculatorDBField *MEDCalculatorDBField::operator+(double val) const throw(INTERP_KERNEL::Exception)
50 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
51 return (*this)+(*par2);
54 MEDCalculatorDBField *MEDCalculatorDBField::operator-(double val) const throw(INTERP_KERNEL::Exception)
56 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
57 return (*this)-(*par2);
60 MEDCalculatorDBField *MEDCalculatorDBField::operator*(double val) const throw(INTERP_KERNEL::Exception)
62 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
63 return (*this)*(*par2);
66 MEDCalculatorDBField *MEDCalculatorDBField::operator/(double val) const throw(INTERP_KERNEL::Exception)
68 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
69 return (*this)/(*par2);
72 MEDCalculatorDBFieldReal *MEDCalculatorDBFieldReal::operator()(const MEDCalculatorDBRangeSelection& t, const MEDCalculatorDBRangeSelection& p, const MEDCalculatorDBRangeSelection& c) throw(INTERP_KERNEL::Exception)
74 MEDCalculatorDBFieldReal *ret=new MEDCalculatorDBFieldReal(*this);
81 MEDCalculatorDBFieldReal::~MEDCalculatorDBFieldReal()
85 MEDCalculatorDBFieldReal::MEDCalculatorDBFieldReal(TypeOfField type):_type(type)
89 void MEDCalculatorDBFieldReal::setName(const char *name)
93 std::vector<int> ids=_t.getIds(_time_steps.size());
94 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
95 _time_steps[*iter]->setName(name);*/
98 void MEDCalculatorDBFieldReal::setDescription(const char *descr)
102 std::vector<int> ids=_t.getIds(_time_steps.size());
103 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
104 _time_steps[*iter]->setDescription(descr);*/
107 void MEDCalculatorDBFieldReal::write(const char *fName, bool writeFromScratch) const throw(INTERP_KERNEL::Exception)
110 std::vector<int> ids=_t.getIds(_time_steps.size());
112 const MEDCouplingFieldDouble *field=_time_steps[step]->getField(_type,_file_name,_mesh_name,_field_name);
113 const MEDCouplingUMesh *mesh=static_cast<const MEDCouplingUMesh *>(field->getMesh());
114 int status=MEDLoaderBase::getStatusOfFile(fName);
115 if(!writeFromScratch && status==MEDLoaderBase::EXIST_RW)
117 std::vector<std::string> ms=MEDLoader::GetMeshNames(fName);
118 if(std::find(ms.begin(),ms.end(),mesh->getName())!=ms.end())
120 std::ostringstream oss; oss << "In file \"" << fName << "\" the mesh with name \"" << mesh->getName() << "\" already exists !";
121 throw INTERP_KERNEL::Exception(oss.str().c_str());
123 std::vector<std::string> fs=MEDLoader::GetAllFieldNames(fName);
124 if(std::find(fs.begin(),fs.end(),field->getName())!=fs.end())
126 std::ostringstream oss; oss << "In file \"" << fName << "\" the field with name \"" << field->getName() << "\" already exists !";
127 throw INTERP_KERNEL::Exception(oss.str().c_str());
130 MEDLoader::WriteUMesh(fName,mesh,writeFromScratch);
131 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
132 _time_steps[*iter]->write(fName,_name,_description);
135 void MEDCalculatorDBFieldReal::display() const throw(INTERP_KERNEL::Exception)
138 std::vector<int> ids=_t.getIds(_time_steps.size());
139 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > fs2(ids.size());
141 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
142 fs2[ii++]=_time_steps[*iter]->getFieldWithoutQuestion(_c_labels.size(),_c);
143 std::vector<MEDCouplingFieldDouble *> fs(fs2.size());
144 std::copy(fs2.begin(),fs2.end(),fs.begin());
145 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldOverTime> fot=MEDCouplingFieldOverTime::New(fs);
148 CORBA::ORB_var orb=CORBA::ORB_init(argc,0);
149 CORBA::Object_var obj=orb->resolve_initial_references("RootPOA");
150 PortableServer::POA_var poa=PortableServer::POA::_narrow(obj);
151 PortableServer::POAManager_var mgr=poa->the_POAManager();
153 MEDCouplingFieldOverTimeServant *fots=new MEDCouplingFieldOverTimeServant(fot);
154 SALOME_MED::MEDCouplingFieldOverTimeCorbaInterface_var fotPtr=fots->_this();
156 SALOME_NamingService ns(orb);
157 ns.Change_Directory("/Containers");
158 std::vector<std::string> subdirs=ns.list_subdirs();
159 std::ostringstream path;
160 path << "/Containers/" << subdirs[0] << "/FactoryServer/PARAVIS_inst_1";
162 CORBA::Object_var paravis=ns.Resolve(path.str().c_str());
163 CORBA::Request_var req=paravis->_request("ExecuteScript");
164 CORBA::NVList_ptr args=req->arguments();
166 std::ostringstream script;
167 char *ior=orb->object_to_string(fotPtr);
168 script << "src1 = ParaMEDCorbaPluginSource()\nsrc1.IORCorba = '" << ior << "'\nasc=GetAnimationScene()\nrw=GetRenderView()\ndr=Show()\ndr.Visibility = 1\n";
169 CORBA::string_free(ior);
170 ob <<= script.str().c_str();
171 args->add_value("script",ob,CORBA::ARG_IN);
172 req->set_return_type(CORBA::_tc_void);
177 std::string MEDCalculatorDBFieldReal::simpleRepr() const
179 std::ostringstream oss;
180 oss << "Multitime field with name : \""<< _name << "\".\n";
181 oss << "Description of the field is : \"" << _description << "\".\n";
182 oss << "Number of time steps of multitime field : " << getNumberOfSteps() << ".\n";
183 oss << "Number of components of multitime field : " << getNumberOfComponents() << ".\n";
184 oss << "Components names attached are : ";
185 std::vector<int> ids=_c.getIds(_c_labels.size());
186 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
187 oss << "\"" << _c_labels[*iter] << "\" ";
188 oss << ".\nNumber of fetched field in multime field : " << getNumberOfFetchedSteps() << "/" << getNumberOfSteps() << ".\n";
192 MEDCalculatorDBFieldReal::MEDCalculatorDBFieldReal(const MEDCalculatorBrowserField& ls):_file_name(ls.getFileName()),_mesh_name(ls.getCorrespondingMeshesFromField().front()),_field_name(ls.getName()),_type(ls.getType()),
193 _c_labels(ls.getComponents())
195 const std::vector<MEDCalculatorBrowserStep>& steps=ls.getSteps();
197 for(int i=0;i<sz;i++)
199 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBSliceField> elt(new MEDCalculatorDBSliceField(steps[i].getTimeStep(),steps[i].getOrder()));
200 _time_steps.push_back(elt);
204 const MEDCalculatorDBFieldReal& MEDCalculatorDBFieldReal::operator=(const MEDCalculatorDBFieldReal& other) throw(INTERP_KERNEL::Exception)
206 checkCoherency(other);
207 std::vector<int> ids=_t.getIds(_time_steps.size());
208 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
209 unsigned int sz=ids.size();
211 throw INTERP_KERNEL::Exception("FieldReal::operator= : Timesteps lengthes mismatch !");
214 for(unsigned int i=0;i<sz;i++)
215 _time_steps[ids[i]]->assign(other._time_steps[ids2[i]],_c_labels.size(),_c,other._c_labels.size(),other._c);
219 const MEDCalculatorDBFieldReal& MEDCalculatorDBFieldReal::operator=(double val) throw(INTERP_KERNEL::Exception)
221 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> other=buildCstFieldFromThis(val);
222 return (*this)=*other;
225 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator+(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
227 const MEDCalculatorDBField *other2=&other;
228 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
233 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
236 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
237 MEDCalculatorDBField *ret=add(*othercr);
241 throw INTERP_KERNEL::Exception("FieldReal::operator+ : unrecognized type of parameter recieved !");
245 MEDCalculatorDBField *MEDCalculatorDBFieldReal::add(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
247 checkCoherency(other);
248 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
251 DataArrayInt *cellCor,*nodeCor;
252 std::vector<int> ids=_t.getIds(_time_steps.size());
253 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
254 if(ids.size()!=ids2.size())
255 throw INTERP_KERNEL::Exception("FieldReal::add : Timesteps lengthes mismatch !");
258 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
259 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
260 mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
262 ret->_time_steps.resize(sz);
263 for(int i=0;i<sz;i++)
264 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);
265 int newNbOfCompo=_c.getSize(_c_labels.size());
266 ret->_c_labels.resize(newNbOfCompo);
275 bool MEDCalculatorDBFieldReal::isEqual(const MEDCalculatorDBField& other, double precM, double precF) const
277 const MEDCalculatorDBField *other2=&other;
278 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
280 return isEqualSameType(*otherr,precM,precF);
283 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
286 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
287 bool ret=isEqualSameType(*othercr,precM,precF);
291 throw INTERP_KERNEL::Exception("FieldReal::isEqual : unrecognized type of parameter recieved !");
295 bool MEDCalculatorDBFieldReal::isEqualSameType(const MEDCalculatorDBFieldReal& other, double precM, double precF) const
297 if(_description!=other._description)
301 DataArrayInt *cellCor,*nodeCor;
302 std::vector<int> ids=_t.getIds(_time_steps.size());
303 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
304 if(ids.size()!=ids2.size())
308 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
309 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
310 mesh->checkGeoEquivalWith(otherm,0,precM,cellCor,nodeCor);
312 for(int i=0;i<sz;i++)
313 if(!_time_steps[ids[i]]->isEqual(other._time_steps[ids2[i]],cellCor,nodeCor,_c_labels.size(),_c,other._c_labels.size(),other._c,precF))
322 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator-(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
324 const MEDCalculatorDBField *other2=&other;
325 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
327 return substract(*otherr);
330 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
333 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
334 MEDCalculatorDBField *ret=substract(*othercr);
338 throw INTERP_KERNEL::Exception("FieldReal::operator- : unrecognized type of parameter recieved !");
342 MEDCalculatorDBField *MEDCalculatorDBFieldReal::substract(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
344 checkCoherency(other);
345 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
348 DataArrayInt *cellCor,*nodeCor;
349 std::vector<int> ids=_t.getIds(_time_steps.size());
350 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
351 if(ids.size()!=ids2.size())
352 throw INTERP_KERNEL::Exception("FieldReal::substract : Timesteps lengthes mismatch !");
355 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
356 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
357 mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
359 ret->_time_steps.resize(sz);
360 for(int i=0;i<sz;i++)
361 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);
362 int newNbOfCompo=_c.getSize(_c_labels.size());
363 ret->_c_labels.resize(newNbOfCompo);
372 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator*(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
374 const MEDCalculatorDBField *other2=&other;
375 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
377 return multiply(*otherr);
380 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
383 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
384 MEDCalculatorDBField *ret=multiply(*othercr);
388 throw INTERP_KERNEL::Exception("FieldReal::operator* : unrecognized type of parameter recieved !");
392 MEDCalculatorDBField *MEDCalculatorDBFieldReal::multiply(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
394 checkCoherency(other);
395 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
398 DataArrayInt *cellCor,*nodeCor;
399 std::vector<int> ids=_t.getIds(_time_steps.size());
400 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
401 if(ids.size()!=ids2.size())
402 throw INTERP_KERNEL::Exception("FieldReal::multiply : Timesteps lengthes mismatch !");
405 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
406 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
407 mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
409 ret->_time_steps.resize(sz);
410 for(int i=0;i<sz;i++)
411 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);
412 int newNbOfCompo=_c.getSize(_c_labels.size());
413 ret->_c_labels.resize(newNbOfCompo);
422 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator/(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
424 const MEDCalculatorDBField *other2=&other;
425 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
427 return divide(*otherr);
430 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
433 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
434 MEDCalculatorDBField *ret=divide(*othercr);
438 throw INTERP_KERNEL::Exception("FieldReal::operator/ : unrecognized type of parameter recieved !");
442 MEDCalculatorDBField *MEDCalculatorDBFieldReal::divide(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
444 checkCoherency(other);
445 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
448 DataArrayInt *cellCor,*nodeCor;
449 std::vector<int> ids=_t.getIds(_time_steps.size());
450 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
451 if(ids.size()!=ids2.size())
452 throw INTERP_KERNEL::Exception("FieldReal::divide : Timesteps lengthes mismatch !");
455 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
456 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
457 mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
459 ret->_time_steps.resize(sz);
460 for(int i=0;i<sz;i++)
461 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);
462 int newNbOfCompo=_c.getSize(_c_labels.size());
463 ret->_c_labels.resize(newNbOfCompo);
472 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator^(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
474 return crossProduct(other);
477 MEDCalculatorDBField *MEDCalculatorDBFieldReal::dot(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
479 checkCoherency(other);
480 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
483 std::vector<int> ids=_t.getIds(_time_steps.size());
484 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
485 unsigned int sz=ids.size();
487 throw INTERP_KERNEL::Exception("FieldReal::dot : Timesteps lengthes mismatch !");
488 ret->_time_steps.resize(sz);
489 for(unsigned int i=0;i<sz;i++)
490 ret->_time_steps[i]=_time_steps[ids[i]]->dot(other._time_steps[ids2[i]],_c_labels.size(),_c,other._c_labels.size(),other._c);
491 ret->_time_steps.resize(sz);
492 ret->_c_labels.resize(1);
497 MEDCalculatorDBField *MEDCalculatorDBFieldReal::crossProduct(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
499 checkCoherency(other);
500 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
503 std::vector<int> ids=_t.getIds(_time_steps.size());
504 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
505 unsigned int sz=ids.size();
507 throw INTERP_KERNEL::Exception("FieldReal::crossProduct : Timesteps lengthes mismatch !");
508 ret->_time_steps.resize(sz);
509 for(unsigned int i=0;i<sz;i++)
510 ret->_time_steps[i]=_time_steps[ids[i]]->crossProduct(other._time_steps[ids2[i]],_c_labels.size(),_c,other._c_labels.size(),other._c);
511 ret->_time_steps.resize(sz);
512 ret->_c_labels.resize(3);
517 MEDCalculatorDBField *MEDCalculatorDBFieldReal::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
519 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
521 std::vector<int> ids=_t.getIds(_time_steps.size());
522 unsigned int sz=ids.size();
523 ret->_time_steps.resize(sz);
524 for(unsigned int i=0;i<sz;i++)
525 ret->_time_steps[i]=_time_steps[ids[i]]->doublyContractedProduct(_c_labels.size(),_c);
526 ret->_time_steps.resize(sz);
527 ret->_c_labels.resize(1);
532 MEDCalculatorDBField *MEDCalculatorDBFieldReal::determinant() const throw(INTERP_KERNEL::Exception)
534 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
536 std::vector<int> ids=_t.getIds(_time_steps.size());
537 unsigned int sz=ids.size();
538 ret->_time_steps.resize(sz);
539 for(unsigned int i=0;i<sz;i++)
540 ret->_time_steps[i]=_time_steps[ids[i]]->determinant(_c_labels.size(),_c);
541 ret->_time_steps.resize(sz);
542 ret->_c_labels.resize(1);
547 MEDCalculatorDBField *MEDCalculatorDBFieldReal::eigenValues() const throw(INTERP_KERNEL::Exception)
549 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
551 std::vector<int> ids=_t.getIds(_time_steps.size());
552 unsigned int sz=ids.size();
553 ret->_time_steps.resize(sz);
554 for(unsigned int i=0;i<sz;i++)
555 ret->_time_steps[i]=_time_steps[ids[i]]->eigenValues(_c_labels.size(),_c);
556 ret->_time_steps.resize(sz);
559 int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
560 ret->_c_labels.resize(ncomp);
563 ret->_c_labels.resize(0);
568 MEDCalculatorDBField *MEDCalculatorDBFieldReal::eigenVectors() const throw(INTERP_KERNEL::Exception)
570 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
572 std::vector<int> ids=_t.getIds(_time_steps.size());
573 unsigned int sz=ids.size();
574 ret->_time_steps.resize(sz);
575 for(unsigned int i=0;i<sz;i++)
576 ret->_time_steps[i]=_time_steps[ids[i]]->eigenVectors(_c_labels.size(),_c);
577 ret->_time_steps.resize(sz);
580 int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
581 ret->_c_labels.resize(ncomp);
584 ret->_c_labels.resize(0);
589 MEDCalculatorDBField *MEDCalculatorDBFieldReal::inverse() const throw(INTERP_KERNEL::Exception)
591 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
593 std::vector<int> ids=_t.getIds(_time_steps.size());
594 unsigned int sz=ids.size();
595 ret->_time_steps.resize(sz);
596 for(unsigned int i=0;i<sz;i++)
597 ret->_time_steps[i]=_time_steps[ids[i]]->inverse(_c_labels.size(),_c);
598 ret->_time_steps.resize(sz);
601 int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
602 ret->_c_labels.resize(ncomp);
605 ret->_c_labels.resize(0);
610 MEDCalculatorDBField *MEDCalculatorDBFieldReal::trace() const throw(INTERP_KERNEL::Exception)
612 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
614 std::vector<int> ids=_t.getIds(_time_steps.size());
615 unsigned int sz=ids.size();
616 ret->_time_steps.resize(sz);
617 for(unsigned int i=0;i<sz;i++)
618 ret->_time_steps[i]=_time_steps[ids[i]]->trace(_c_labels.size(),_c);
619 ret->_time_steps.resize(sz);
620 ret->_c_labels.resize(1);
625 MEDCalculatorDBField *MEDCalculatorDBFieldReal::deviator() const throw(INTERP_KERNEL::Exception)
627 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
629 std::vector<int> ids=_t.getIds(_time_steps.size());
630 unsigned int sz=ids.size();
631 ret->_time_steps.resize(sz);
632 for(unsigned int i=0;i<sz;i++)
633 ret->_time_steps[i]=_time_steps[ids[i]]->deviator(_c_labels.size(),_c);
634 ret->_time_steps.resize(sz);
637 int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
638 ret->_c_labels.resize(ncomp);
641 ret->_c_labels.resize(0);
646 MEDCalculatorDBField *MEDCalculatorDBFieldReal::magnitude() const throw(INTERP_KERNEL::Exception)
648 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
650 std::vector<int> ids=_t.getIds(_time_steps.size());
651 unsigned int sz=ids.size();
652 ret->_time_steps.resize(sz);
653 for(unsigned int i=0;i<sz;i++)
654 ret->_time_steps[i]=_time_steps[ids[i]]->magnitude(_c_labels.size(),_c);
655 ret->_time_steps.resize(sz);
656 ret->_c_labels.resize(1);
661 void MEDCalculatorDBFieldReal::applyFunc(const char *func) throw(INTERP_KERNEL::Exception)
664 std::vector<int> ids=_t.getIds(_time_steps.size());
665 for(std::vector<int>::const_iterator it=ids.begin();it!=ids.end();it++)
666 _time_steps[*it]->applyFunc(func,_c_labels.size(),_c);
669 MEDCalculatorDBFieldReal *MEDCalculatorDBFieldReal::buildCstFieldFromThis(double val) const
671 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
673 ret->_c_labels.resize(_c.getSize(_c_labels.size()));
674 std::vector<int> stps=_t.getIds(_time_steps.size());
675 int stepSize=stps.size();
676 ret->_time_steps.resize(stepSize);
678 throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::buildCstFieldFromThis : no time steps defined !");
679 for(int i=0;i<stepSize;i++)
681 const MEDCouplingFieldDouble *f=_time_steps[stps[i]]->getField(_type,_file_name,_mesh_name,_field_name);
682 ret->_time_steps[i]=new MEDCalculatorDBSliceField(_time_steps[stps[i]]->buildCstFromThis(val,ret->_c_labels.size(),f));
688 void MEDCalculatorDBFieldReal::checkCoherency(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
690 if(_type!=other._type)
691 throw INTERP_KERNEL::Exception("Types of field mismatch !");
692 if(getNumberOfSteps()!=other.getNumberOfSteps())
693 throw INTERP_KERNEL::Exception("Time steps mismatch !");
694 if(getNumberOfComponents()!=other.getNumberOfComponents())
695 throw INTERP_KERNEL::Exception("Components mismatch !");
698 void MEDCalculatorDBFieldReal::fetchData() const throw(INTERP_KERNEL::Exception)
700 std::vector<std::pair<int,int> > idstoFetch;
701 std::vector<int> ids=_t.getIds(_time_steps.size());
703 std::vector<int> idsInGlobalToFetch;
704 for(int i=0;i<sz;i++)
706 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBSliceField> elt=_time_steps[ids[i]];
707 if(!elt->isFetched())
711 std::pair<int,int> p(dt,it);
712 idstoFetch.push_back(p);
713 idsInGlobalToFetch.push_back(ids[i]);
716 std::vector<MEDCouplingFieldDouble *> fs=MEDLoader::ReadFieldsOnSameMesh(_type,_file_name.c_str(),_mesh_name.c_str(),0,_field_name.c_str(),idstoFetch);
718 for(int i=0;i<sz;i++)
720 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBSliceField> elt=_time_steps[idsInGlobalToFetch[i]];
721 elt->setField(fs[i]);
725 int MEDCalculatorDBFieldReal::getNumberOfSteps() const
727 return _t.getSize(_time_steps.size());
730 int MEDCalculatorDBFieldReal::getNumberOfFetchedSteps() const
733 std::vector<int> ids=_t.getIds(_time_steps.size());
734 for(std::vector<int>::const_iterator it=ids.begin();it!=ids.end();it++)
735 if(_time_steps[*it]->isFetched())
740 int MEDCalculatorDBFieldReal::getNumberOfComponents() const
742 return _c.getSize(_c_labels.size());
746 * WARNING the caller has the ownership of all of instances in returned vector.
748 std::vector<MEDCouplingFieldDouble *> MEDCalculatorDBFieldReal::getFields() const throw(INTERP_KERNEL::Exception)
751 std::vector<int> ids=_t.getIds(_time_steps.size());
752 std::vector<MEDCouplingFieldDouble *> ret(ids.size());
754 for(std::vector<int>::const_iterator it=ids.begin();it!=ids.end();it++,i++)
755 ret[i]=_time_steps[*it]->getFieldWithoutQuestion(_c_labels.size(),_c);
759 std::string MEDCalculatorDBFieldReal::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
761 if(i>=(int)_c_labels.size())
762 throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::getInfoOnComponent : sepcified id >= number of component !");
766 void MEDCalculatorDBFieldReal::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
768 if(i>=(int)_c_labels.size())
769 throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::setInfoOnComponent : sepcified id >= number of component !");
773 MEDCalculatorDBFieldCst::MEDCalculatorDBFieldCst(double val):_val(val)
777 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator+(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
779 const MEDCalculatorDBField *other2=&other;
780 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
783 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
784 ret->_val=_val+otherc->_val;
790 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
793 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
794 MEDCalculatorDBField *ret=(*thisr)+other;
798 throw INTERP_KERNEL::Exception("FieldCst::operator+ : unrecognized type of parameter recieved !");
802 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator-(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
804 const MEDCalculatorDBField *other2=&other;
805 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
808 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
809 ret->_val=_val-otherc->_val;
815 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
818 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
819 MEDCalculatorDBField *ret=(*thisr)-other;
823 throw INTERP_KERNEL::Exception("FieldCst::operator- : unrecognized type of parameter recieved !");
827 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator*(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
829 const MEDCalculatorDBField *other2=&other;
830 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
833 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
834 ret->_val=_val*otherc->_val;
840 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
843 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
844 MEDCalculatorDBField *ret=(*thisr)*other;
848 throw INTERP_KERNEL::Exception("FieldCst::operator* : unrecognized type of parameter recieved !");
852 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator/(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
854 const MEDCalculatorDBField *other2=&other;
855 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
858 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
859 ret->_val=_val/otherc->_val;
865 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
868 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
869 MEDCalculatorDBField *ret=(*thisr)/other;
873 throw INTERP_KERNEL::Exception("FieldCst::operator/ : unrecognized type of parameter recieved !");
877 bool MEDCalculatorDBFieldCst::isEqual(const MEDCalculatorDBField& other, double precM, double precF) const
879 const MEDCalculatorDBField *other2=&other;
880 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
882 return fabs(otherc->_val-_val)<precF;
885 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
888 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
889 bool ret=thisr->isEqual(other,precM,precF);
893 throw INTERP_KERNEL::Exception("FieldCst::isEqual : unrecognized type of parameter recieved !");