1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCalculatorDBField.hxx"
22 #include "MEDCalculatorBrowserField.hxx"
24 #include "MEDLoaderBase.hxx"
25 #include "MEDLoader.hxx"
27 #include "MEDCouplingUMesh.hxx"
28 #include "MEDCouplingMemArray.hxx"
29 #include "MEDCouplingFieldDouble.hxx"
30 #include "MEDCouplingFieldOverTime.hxx"
32 #include "MEDCouplingFieldOverTimeServant.hxx"
33 #include "SALOME_NamingService.hxx"
37 using namespace ParaMEDMEM;
39 MEDCalculatorDBFieldReal *MEDCalculatorDBField::New(const MEDCalculatorBrowserField& ls)
41 return new MEDCalculatorDBFieldReal(ls);
44 MEDCalculatorDBFieldCst *MEDCalculatorDBField::New(double val)
46 return new MEDCalculatorDBFieldCst(val);
49 std::size_t MEDCalculatorDBField::getHeapMemorySizeWithoutChildren() const
54 std::vector<const BigMemoryObject *> MEDCalculatorDBField::getDirectChildrenWithNull() const
56 return std::vector<const BigMemoryObject *>();
59 MEDCalculatorDBField *MEDCalculatorDBField::operator+(double val) const throw(INTERP_KERNEL::Exception)
61 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
62 return (*this)+(*par2);
65 MEDCalculatorDBField *MEDCalculatorDBField::operator-(double val) const throw(INTERP_KERNEL::Exception)
67 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
68 return (*this)-(*par2);
71 MEDCalculatorDBField *MEDCalculatorDBField::operator*(double val) const throw(INTERP_KERNEL::Exception)
73 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
74 return (*this)*(*par2);
77 MEDCalculatorDBField *MEDCalculatorDBField::operator/(double val) const throw(INTERP_KERNEL::Exception)
79 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
80 return (*this)/(*par2);
83 MEDCalculatorDBFieldReal *MEDCalculatorDBFieldReal::operator()(const MEDCalculatorDBRangeSelection& t, const MEDCalculatorDBRangeSelection& p, const MEDCalculatorDBRangeSelection& c) throw(INTERP_KERNEL::Exception)
85 MEDCalculatorDBFieldReal *ret=new MEDCalculatorDBFieldReal(*this);
92 MEDCalculatorDBFieldReal::~MEDCalculatorDBFieldReal()
96 MEDCalculatorDBFieldReal::MEDCalculatorDBFieldReal(TypeOfField type):_type(type)
100 void MEDCalculatorDBFieldReal::setName(const char *name)
104 std::vector<int> ids=_t.getIds(_time_steps.size());
105 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
106 _time_steps[*iter]->setName(name);*/
109 void MEDCalculatorDBFieldReal::setDescription(const char *descr)
113 std::vector<int> ids=_t.getIds(_time_steps.size());
114 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
115 _time_steps[*iter]->setDescription(descr);*/
118 void MEDCalculatorDBFieldReal::write(const char *fName, bool writeFromScratch) const throw(INTERP_KERNEL::Exception)
121 std::vector<int> ids=_t.getIds(_time_steps.size());
123 const MEDCouplingFieldDouble *field=_time_steps[step]->getField(_type,_file_name,_mesh_name,_field_name);
124 const MEDCouplingUMesh *mesh=static_cast<const MEDCouplingUMesh *>(field->getMesh());
125 int status=MEDLoaderBase::getStatusOfFile(fName);
126 if(!writeFromScratch && status==MEDLoaderBase::EXIST_RW)
128 std::vector<std::string> ms=MEDLoader::GetMeshNames(fName);
129 if(std::find(ms.begin(),ms.end(),mesh->getName())!=ms.end())
131 std::ostringstream oss; oss << "In file \"" << fName << "\" the mesh with name \"" << mesh->getName() << "\" already exists !";
132 throw INTERP_KERNEL::Exception(oss.str().c_str());
134 std::vector<std::string> fs=MEDLoader::GetAllFieldNames(fName);
135 if(std::find(fs.begin(),fs.end(),field->getName())!=fs.end())
137 std::ostringstream oss; oss << "In file \"" << fName << "\" the field with name \"" << field->getName() << "\" already exists !";
138 throw INTERP_KERNEL::Exception(oss.str().c_str());
141 MEDLoader::WriteUMesh(fName,mesh,writeFromScratch);
142 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
143 _time_steps[*iter]->write(fName,_name,_description);
146 void MEDCalculatorDBFieldReal::display() const throw(INTERP_KERNEL::Exception)
149 std::vector<int> ids=_t.getIds(_time_steps.size());
150 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > fs2(ids.size());
152 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
153 fs2[ii++]=_time_steps[*iter]->getFieldWithoutQuestion(_c_labels.size(),_c);
154 std::vector<MEDCouplingFieldDouble *> fs(fs2.size());
155 std::copy(fs2.begin(),fs2.end(),fs.begin());
156 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldOverTime> fot=MEDCouplingFieldOverTime::New(fs);
159 CORBA::ORB_var orb=CORBA::ORB_init(argc,0);
160 CORBA::Object_var obj=orb->resolve_initial_references("RootPOA");
161 PortableServer::POA_var poa=PortableServer::POA::_narrow(obj);
162 PortableServer::POAManager_var mgr=poa->the_POAManager();
164 MEDCouplingFieldOverTimeServant *fots=new MEDCouplingFieldOverTimeServant(fot);
165 SALOME_MED::MEDCouplingFieldOverTimeCorbaInterface_var fotPtr=fots->_this();
167 SALOME_NamingService ns(orb);
168 ns.Change_Directory("/Containers");
169 std::vector<std::string> subdirs=ns.list_subdirs();
170 std::ostringstream path;
171 path << "/Containers/" << subdirs[0] << "/FactoryServer/PARAVIS_inst_1";
173 CORBA::Object_var paravis=ns.Resolve(path.str().c_str());
174 CORBA::Request_var req=paravis->_request("ExecuteScript");
175 CORBA::NVList_ptr args=req->arguments();
177 std::ostringstream script;
178 char *ior=orb->object_to_string(fotPtr);
179 script << "src1 = ParaMEDCorbaPluginSource()\nsrc1.IORCorba = '" << ior << "'\nasc=GetAnimationScene()\nrw=GetRenderView()\ndr=Show()\ndr.Visibility = 1\n";
180 CORBA::string_free(ior);
181 ob <<= script.str().c_str();
182 args->add_value("script",ob,CORBA::ARG_IN);
183 req->set_return_type(CORBA::_tc_void);
188 std::string MEDCalculatorDBFieldReal::simpleRepr() const
190 std::ostringstream oss;
191 oss << "Multitime field with name : \""<< _name << "\".\n";
192 oss << "Description of the field is : \"" << _description << "\".\n";
193 oss << "Number of time steps of multitime field : " << getNumberOfSteps() << ".\n";
194 oss << "Number of components of multitime field : " << getNumberOfComponents() << ".\n";
195 oss << "Components names attached are : ";
196 std::vector<int> ids=_c.getIds(_c_labels.size());
197 for(std::vector<int>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
198 oss << "\"" << _c_labels[*iter] << "\" ";
199 oss << ".\nNumber of fetched field in multime field : " << getNumberOfFetchedSteps() << "/" << getNumberOfSteps() << ".\n";
203 MEDCalculatorDBFieldReal::MEDCalculatorDBFieldReal(const MEDCalculatorBrowserField& ls):_file_name(ls.getFileName()),_mesh_name(ls.getCorrespondingMeshesFromField().front()),_field_name(ls.getName()),_type(ls.getType()),
204 _c_labels(ls.getComponents())
206 const std::vector<MEDCalculatorBrowserStep>& steps=ls.getSteps();
208 for(int i=0;i<sz;i++)
210 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBSliceField> elt(new MEDCalculatorDBSliceField(steps[i].getTimeStep(),steps[i].getOrder()));
211 _time_steps.push_back(elt);
215 const MEDCalculatorDBFieldReal& MEDCalculatorDBFieldReal::operator=(const MEDCalculatorDBFieldReal& other) throw(INTERP_KERNEL::Exception)
217 checkCoherency(other);
218 std::vector<int> ids=_t.getIds(_time_steps.size());
219 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
220 unsigned int sz=ids.size();
222 throw INTERP_KERNEL::Exception("FieldReal::operator= : Timesteps lengthes mismatch !");
225 for(unsigned int i=0;i<sz;i++)
226 _time_steps[ids[i]]->assign(other._time_steps[ids2[i]],_c_labels.size(),_c,other._c_labels.size(),other._c);
230 const MEDCalculatorDBFieldReal& MEDCalculatorDBFieldReal::operator=(double val) throw(INTERP_KERNEL::Exception)
232 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> other=buildCstFieldFromThis(val);
233 return (*this)=*other;
236 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator+(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
238 const MEDCalculatorDBField *other2=&other;
239 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
244 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
247 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
248 MEDCalculatorDBField *ret=add(*othercr);
252 throw INTERP_KERNEL::Exception("FieldReal::operator+ : unrecognized type of parameter recieved !");
256 MEDCalculatorDBField *MEDCalculatorDBFieldReal::add(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
258 checkCoherency(other);
259 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
262 DataArrayInt *cellCor,*nodeCor;
263 std::vector<int> ids=_t.getIds(_time_steps.size());
264 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
265 if(ids.size()!=ids2.size())
266 throw INTERP_KERNEL::Exception("FieldReal::add : Timesteps lengthes mismatch !");
269 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
270 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
271 mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
273 ret->_time_steps.resize(sz);
274 for(int i=0;i<sz;i++)
275 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);
276 int newNbOfCompo=_c.getSize(_c_labels.size());
277 ret->_c_labels.resize(newNbOfCompo);
286 bool MEDCalculatorDBFieldReal::isEqual(const MEDCalculatorDBField& other, double precM, double precF) const
288 const MEDCalculatorDBField *other2=&other;
289 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
291 return isEqualSameType(*otherr,precM,precF);
294 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
297 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
298 bool ret=isEqualSameType(*othercr,precM,precF);
302 throw INTERP_KERNEL::Exception("FieldReal::isEqual : unrecognized type of parameter recieved !");
306 bool MEDCalculatorDBFieldReal::isEqualSameType(const MEDCalculatorDBFieldReal& other, double precM, double precF) const
308 if(_description!=other._description)
312 DataArrayInt *cellCor,*nodeCor;
313 std::vector<int> ids=_t.getIds(_time_steps.size());
314 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
315 if(ids.size()!=ids2.size())
319 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
320 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
321 mesh->checkGeoEquivalWith(otherm,0,precM,cellCor,nodeCor);
323 for(int i=0;i<sz;i++)
324 if(!_time_steps[ids[i]]->isEqual(other._time_steps[ids2[i]],cellCor,nodeCor,_c_labels.size(),_c,other._c_labels.size(),other._c,precF))
333 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator-(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
335 const MEDCalculatorDBField *other2=&other;
336 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
338 return substract(*otherr);
341 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
344 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
345 MEDCalculatorDBField *ret=substract(*othercr);
349 throw INTERP_KERNEL::Exception("FieldReal::operator- : unrecognized type of parameter recieved !");
353 MEDCalculatorDBField *MEDCalculatorDBFieldReal::substract(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
355 checkCoherency(other);
356 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
359 DataArrayInt *cellCor,*nodeCor;
360 std::vector<int> ids=_t.getIds(_time_steps.size());
361 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
362 if(ids.size()!=ids2.size())
363 throw INTERP_KERNEL::Exception("FieldReal::substract : Timesteps lengthes mismatch !");
366 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
367 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
368 mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
370 ret->_time_steps.resize(sz);
371 for(int i=0;i<sz;i++)
372 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);
373 int newNbOfCompo=_c.getSize(_c_labels.size());
374 ret->_c_labels.resize(newNbOfCompo);
383 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator*(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
385 const MEDCalculatorDBField *other2=&other;
386 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
388 return multiply(*otherr);
391 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
394 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
395 MEDCalculatorDBField *ret=multiply(*othercr);
399 throw INTERP_KERNEL::Exception("FieldReal::operator* : unrecognized type of parameter recieved !");
403 MEDCalculatorDBField *MEDCalculatorDBFieldReal::multiply(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
405 checkCoherency(other);
406 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
409 DataArrayInt *cellCor,*nodeCor;
410 std::vector<int> ids=_t.getIds(_time_steps.size());
411 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
412 if(ids.size()!=ids2.size())
413 throw INTERP_KERNEL::Exception("FieldReal::multiply : Timesteps lengthes mismatch !");
416 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
417 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
418 mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
420 ret->_time_steps.resize(sz);
421 for(int i=0;i<sz;i++)
422 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);
423 int newNbOfCompo=_c.getSize(_c_labels.size());
424 ret->_c_labels.resize(newNbOfCompo);
433 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator/(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
435 const MEDCalculatorDBField *other2=&other;
436 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
438 return divide(*otherr);
441 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
444 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
445 MEDCalculatorDBField *ret=divide(*othercr);
449 throw INTERP_KERNEL::Exception("FieldReal::operator/ : unrecognized type of parameter recieved !");
453 MEDCalculatorDBField *MEDCalculatorDBFieldReal::divide(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
455 checkCoherency(other);
456 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
459 DataArrayInt *cellCor,*nodeCor;
460 std::vector<int> ids=_t.getIds(_time_steps.size());
461 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
462 if(ids.size()!=ids2.size())
463 throw INTERP_KERNEL::Exception("FieldReal::divide : Timesteps lengthes mismatch !");
466 const MEDCouplingMesh *mesh=_time_steps[step]->getMesh(_type,_file_name,_mesh_name,_field_name);
467 const MEDCouplingMesh *otherm=other._time_steps[step2]->getMesh(_type,other._file_name,other._mesh_name,other._field_name);
468 mesh->checkGeoEquivalWith(otherm,1,1e-12,cellCor,nodeCor);//1 for fast check
470 ret->_time_steps.resize(sz);
471 for(int i=0;i<sz;i++)
472 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);
473 int newNbOfCompo=_c.getSize(_c_labels.size());
474 ret->_c_labels.resize(newNbOfCompo);
483 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator^(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
485 return crossProduct(other);
488 MEDCalculatorDBField *MEDCalculatorDBFieldReal::dot(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
490 checkCoherency(other);
491 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
494 std::vector<int> ids=_t.getIds(_time_steps.size());
495 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
496 unsigned int sz=ids.size();
498 throw INTERP_KERNEL::Exception("FieldReal::dot : Timesteps lengthes mismatch !");
499 ret->_time_steps.resize(sz);
500 for(unsigned int i=0;i<sz;i++)
501 ret->_time_steps[i]=_time_steps[ids[i]]->dot(other._time_steps[ids2[i]],_c_labels.size(),_c,other._c_labels.size(),other._c);
502 ret->_time_steps.resize(sz);
503 ret->_c_labels.resize(1);
508 MEDCalculatorDBField *MEDCalculatorDBFieldReal::crossProduct(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
510 checkCoherency(other);
511 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
514 std::vector<int> ids=_t.getIds(_time_steps.size());
515 std::vector<int> ids2=other._t.getIds(other._time_steps.size());
516 unsigned int sz=ids.size();
518 throw INTERP_KERNEL::Exception("FieldReal::crossProduct : Timesteps lengthes mismatch !");
519 ret->_time_steps.resize(sz);
520 for(unsigned int i=0;i<sz;i++)
521 ret->_time_steps[i]=_time_steps[ids[i]]->crossProduct(other._time_steps[ids2[i]],_c_labels.size(),_c,other._c_labels.size(),other._c);
522 ret->_time_steps.resize(sz);
523 ret->_c_labels.resize(3);
528 MEDCalculatorDBField *MEDCalculatorDBFieldReal::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
530 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
532 std::vector<int> ids=_t.getIds(_time_steps.size());
533 unsigned int sz=ids.size();
534 ret->_time_steps.resize(sz);
535 for(unsigned int i=0;i<sz;i++)
536 ret->_time_steps[i]=_time_steps[ids[i]]->doublyContractedProduct(_c_labels.size(),_c);
537 ret->_time_steps.resize(sz);
538 ret->_c_labels.resize(1);
543 MEDCalculatorDBField *MEDCalculatorDBFieldReal::determinant() const throw(INTERP_KERNEL::Exception)
545 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
547 std::vector<int> ids=_t.getIds(_time_steps.size());
548 unsigned int sz=ids.size();
549 ret->_time_steps.resize(sz);
550 for(unsigned int i=0;i<sz;i++)
551 ret->_time_steps[i]=_time_steps[ids[i]]->determinant(_c_labels.size(),_c);
552 ret->_time_steps.resize(sz);
553 ret->_c_labels.resize(1);
558 MEDCalculatorDBField *MEDCalculatorDBFieldReal::eigenValues() const throw(INTERP_KERNEL::Exception)
560 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
562 std::vector<int> ids=_t.getIds(_time_steps.size());
563 unsigned int sz=ids.size();
564 ret->_time_steps.resize(sz);
565 for(unsigned int i=0;i<sz;i++)
566 ret->_time_steps[i]=_time_steps[ids[i]]->eigenValues(_c_labels.size(),_c);
567 ret->_time_steps.resize(sz);
570 int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
571 ret->_c_labels.resize(ncomp);
574 ret->_c_labels.resize(0);
579 MEDCalculatorDBField *MEDCalculatorDBFieldReal::eigenVectors() const throw(INTERP_KERNEL::Exception)
581 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
583 std::vector<int> ids=_t.getIds(_time_steps.size());
584 unsigned int sz=ids.size();
585 ret->_time_steps.resize(sz);
586 for(unsigned int i=0;i<sz;i++)
587 ret->_time_steps[i]=_time_steps[ids[i]]->eigenVectors(_c_labels.size(),_c);
588 ret->_time_steps.resize(sz);
591 int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
592 ret->_c_labels.resize(ncomp);
595 ret->_c_labels.resize(0);
600 MEDCalculatorDBField *MEDCalculatorDBFieldReal::inverse() const throw(INTERP_KERNEL::Exception)
602 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
604 std::vector<int> ids=_t.getIds(_time_steps.size());
605 unsigned int sz=ids.size();
606 ret->_time_steps.resize(sz);
607 for(unsigned int i=0;i<sz;i++)
608 ret->_time_steps[i]=_time_steps[ids[i]]->inverse(_c_labels.size(),_c);
609 ret->_time_steps.resize(sz);
612 int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
613 ret->_c_labels.resize(ncomp);
616 ret->_c_labels.resize(0);
621 MEDCalculatorDBField *MEDCalculatorDBFieldReal::trace() const throw(INTERP_KERNEL::Exception)
623 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
625 std::vector<int> ids=_t.getIds(_time_steps.size());
626 unsigned int sz=ids.size();
627 ret->_time_steps.resize(sz);
628 for(unsigned int i=0;i<sz;i++)
629 ret->_time_steps[i]=_time_steps[ids[i]]->trace(_c_labels.size(),_c);
630 ret->_time_steps.resize(sz);
631 ret->_c_labels.resize(1);
636 MEDCalculatorDBField *MEDCalculatorDBFieldReal::deviator() const throw(INTERP_KERNEL::Exception)
638 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
640 std::vector<int> ids=_t.getIds(_time_steps.size());
641 unsigned int sz=ids.size();
642 ret->_time_steps.resize(sz);
643 for(unsigned int i=0;i<sz;i++)
644 ret->_time_steps[i]=_time_steps[ids[i]]->deviator(_c_labels.size(),_c);
645 ret->_time_steps.resize(sz);
648 int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
649 ret->_c_labels.resize(ncomp);
652 ret->_c_labels.resize(0);
657 MEDCalculatorDBField *MEDCalculatorDBFieldReal::magnitude() const throw(INTERP_KERNEL::Exception)
659 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
661 std::vector<int> ids=_t.getIds(_time_steps.size());
662 unsigned int sz=ids.size();
663 ret->_time_steps.resize(sz);
664 for(unsigned int i=0;i<sz;i++)
665 ret->_time_steps[i]=_time_steps[ids[i]]->magnitude(_c_labels.size(),_c);
666 ret->_time_steps.resize(sz);
667 ret->_c_labels.resize(1);
672 void MEDCalculatorDBFieldReal::applyFunc(const char *func) throw(INTERP_KERNEL::Exception)
675 std::vector<int> ids=_t.getIds(_time_steps.size());
676 for(std::vector<int>::const_iterator it=ids.begin();it!=ids.end();it++)
677 _time_steps[*it]->applyFunc(func,_c_labels.size(),_c);
680 MEDCalculatorDBFieldReal *MEDCalculatorDBFieldReal::buildCstFieldFromThis(double val) const
682 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
684 ret->_c_labels.resize(_c.getSize(_c_labels.size()));
685 std::vector<int> stps=_t.getIds(_time_steps.size());
686 int stepSize=stps.size();
687 ret->_time_steps.resize(stepSize);
689 throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::buildCstFieldFromThis : no time steps defined !");
690 for(int i=0;i<stepSize;i++)
692 const MEDCouplingFieldDouble *f=_time_steps[stps[i]]->getField(_type,_file_name,_mesh_name,_field_name);
693 ret->_time_steps[i]=new MEDCalculatorDBSliceField(_time_steps[stps[i]]->buildCstFromThis(val,ret->_c_labels.size(),f));
699 void MEDCalculatorDBFieldReal::checkCoherency(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
701 if(_type!=other._type)
702 throw INTERP_KERNEL::Exception("Types of field mismatch !");
703 if(getNumberOfSteps()!=other.getNumberOfSteps())
704 throw INTERP_KERNEL::Exception("Time steps mismatch !");
705 if(getNumberOfComponents()!=other.getNumberOfComponents())
706 throw INTERP_KERNEL::Exception("Components mismatch !");
709 void MEDCalculatorDBFieldReal::fetchData() const throw(INTERP_KERNEL::Exception)
711 std::vector<std::pair<int,int> > idstoFetch;
712 std::vector<int> ids=_t.getIds(_time_steps.size());
714 std::vector<int> idsInGlobalToFetch;
715 for(int i=0;i<sz;i++)
717 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBSliceField> elt=_time_steps[ids[i]];
718 if(!elt->isFetched())
722 std::pair<int,int> p(dt,it);
723 idstoFetch.push_back(p);
724 idsInGlobalToFetch.push_back(ids[i]);
727 std::vector<MEDCouplingFieldDouble *> fs=MEDLoader::ReadFieldsOnSameMesh(_type,_file_name.c_str(),_mesh_name.c_str(),0,_field_name.c_str(),idstoFetch);
729 for(int i=0;i<sz;i++)
731 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBSliceField> elt=_time_steps[idsInGlobalToFetch[i]];
732 elt->setField(fs[i]);
736 int MEDCalculatorDBFieldReal::getNumberOfSteps() const
738 return _t.getSize(_time_steps.size());
741 int MEDCalculatorDBFieldReal::getNumberOfFetchedSteps() const
744 std::vector<int> ids=_t.getIds(_time_steps.size());
745 for(std::vector<int>::const_iterator it=ids.begin();it!=ids.end();it++)
746 if(_time_steps[*it]->isFetched())
751 int MEDCalculatorDBFieldReal::getNumberOfComponents() const
753 return _c.getSize(_c_labels.size());
757 * WARNING the caller has the ownership of all of instances in returned vector.
759 std::vector<MEDCouplingFieldDouble *> MEDCalculatorDBFieldReal::getFields() const throw(INTERP_KERNEL::Exception)
762 std::vector<int> ids=_t.getIds(_time_steps.size());
763 std::vector<MEDCouplingFieldDouble *> ret(ids.size());
765 for(std::vector<int>::const_iterator it=ids.begin();it!=ids.end();it++,i++)
766 ret[i]=_time_steps[*it]->getFieldWithoutQuestion(_c_labels.size(),_c);
770 std::string MEDCalculatorDBFieldReal::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
772 if(i>=(int)_c_labels.size())
773 throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::getInfoOnComponent : sepcified id >= number of component !");
777 void MEDCalculatorDBFieldReal::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
779 if(i>=(int)_c_labels.size())
780 throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::setInfoOnComponent : sepcified id >= number of component !");
784 MEDCalculatorDBFieldCst::MEDCalculatorDBFieldCst(double val):_val(val)
788 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator+(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
790 const MEDCalculatorDBField *other2=&other;
791 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
794 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
795 ret->_val=_val+otherc->_val;
801 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
804 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
805 MEDCalculatorDBField *ret=(*thisr)+other;
809 throw INTERP_KERNEL::Exception("FieldCst::operator+ : unrecognized type of parameter recieved !");
813 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator-(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
815 const MEDCalculatorDBField *other2=&other;
816 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
819 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
820 ret->_val=_val-otherc->_val;
826 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
829 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
830 MEDCalculatorDBField *ret=(*thisr)-other;
834 throw INTERP_KERNEL::Exception("FieldCst::operator- : unrecognized type of parameter recieved !");
838 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator*(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
840 const MEDCalculatorDBField *other2=&other;
841 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
844 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
845 ret->_val=_val*otherc->_val;
851 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
854 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
855 MEDCalculatorDBField *ret=(*thisr)*other;
859 throw INTERP_KERNEL::Exception("FieldCst::operator* : unrecognized type of parameter recieved !");
863 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator/(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
865 const MEDCalculatorDBField *other2=&other;
866 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
869 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
870 ret->_val=_val/otherc->_val;
876 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
879 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
880 MEDCalculatorDBField *ret=(*thisr)/other;
884 throw INTERP_KERNEL::Exception("FieldCst::operator/ : unrecognized type of parameter recieved !");
888 bool MEDCalculatorDBFieldCst::isEqual(const MEDCalculatorDBField& other, double precM, double precF) const
890 const MEDCalculatorDBField *other2=&other;
891 const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
893 return fabs(otherc->_val-_val)<precF;
896 const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
899 MEDCouplingAutoRefCountObjectPtr<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
900 bool ret=thisr->isEqual(other,precM,precF);
904 throw INTERP_KERNEL::Exception("FieldCst::isEqual : unrecognized type of parameter recieved !");