Salome HOME
LOT7: fix compilation at med_int==int64
[modules/med.git] / src / MEDCalculator / MEDCalculatorDBField.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "MEDCalculatorDBField.hxx"
22 #include "MEDCalculatorBrowserField.hxx"
23
24 #include "MEDLoaderBase.hxx"
25 #include "MEDLoader.hxx"
26
27 #include "MEDCouplingUMesh.hxx"
28 #include "MEDCouplingMemArray.hxx"
29 #include "MEDCouplingFieldDouble.hxx"
30 #include "MEDCouplingFieldOverTime.hxx"
31
32 #include "MEDCouplingFieldOverTimeServant.hxx"
33 #include "SALOME_NamingService.hxx"
34
35 #include <cmath>
36
37 using namespace MEDCoupling;
38
39 MEDCalculatorDBFieldReal *MEDCalculatorDBField::New(const MEDCalculatorBrowserField& ls)
40 {
41   return new MEDCalculatorDBFieldReal(ls);
42 }
43
44 MEDCalculatorDBFieldCst *MEDCalculatorDBField::New(double val)
45 {
46   return new MEDCalculatorDBFieldCst(val);
47 }
48
49 std::size_t MEDCalculatorDBField::getHeapMemorySizeWithoutChildren() const
50 {
51   return 0;
52 }
53
54 std::vector<const BigMemoryObject *> MEDCalculatorDBField::getDirectChildrenWithNull() const
55 {
56   return std::vector<const BigMemoryObject *>();
57 }
58
59 MEDCalculatorDBField *MEDCalculatorDBField::operator+(double val) const throw(INTERP_KERNEL::Exception)
60 {
61   MCAuto<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
62   return (*this)+(*par2);
63 }
64
65 MEDCalculatorDBField *MEDCalculatorDBField::operator-(double val) const throw(INTERP_KERNEL::Exception)
66 {
67   MCAuto<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
68   return (*this)-(*par2);
69 }
70
71 MEDCalculatorDBField *MEDCalculatorDBField::operator*(double val) const throw(INTERP_KERNEL::Exception)
72 {
73   MCAuto<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
74   return (*this)*(*par2);
75 }
76
77 MEDCalculatorDBField *MEDCalculatorDBField::operator/(double val) const throw(INTERP_KERNEL::Exception)
78 {
79   MCAuto<MEDCalculatorDBFieldCst> par2=new MEDCalculatorDBFieldCst(val);
80   return (*this)/(*par2);
81 }
82
83 MEDCalculatorDBFieldReal *MEDCalculatorDBFieldReal::operator()(const MEDCalculatorDBRangeSelection& t, const MEDCalculatorDBRangeSelection& p, const MEDCalculatorDBRangeSelection& c) throw(INTERP_KERNEL::Exception)
84 {
85   MEDCalculatorDBFieldReal *ret=new MEDCalculatorDBFieldReal(*this);
86   ret->_t=t;
87   ret->_p=p;
88   ret->_c=c;
89   return ret;
90 }
91
92 MEDCalculatorDBFieldReal::~MEDCalculatorDBFieldReal()
93 {
94 }
95
96 MEDCalculatorDBFieldReal::MEDCalculatorDBFieldReal(TypeOfField type):_type(type)
97 {
98 }
99
100 void MEDCalculatorDBFieldReal::setName(const char *name)
101 {
102   _name=name;
103   /*fetchData();
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);*/
107 }
108
109 void MEDCalculatorDBFieldReal::setDescription(const char *descr)
110 {
111   _description=descr;
112   /*fetchData();
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);*/
116 }
117
118 void MEDCalculatorDBFieldReal::write(const char *fName, bool writeFromScratch) const throw(INTERP_KERNEL::Exception)
119 {
120   fetchData();
121   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
122   int step=ids[0];
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)
127     {
128       std::vector<std::string> ms=GetMeshNames(fName);
129       if(std::find(ms.begin(),ms.end(),mesh->getName())!=ms.end())
130         {
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());
133         }
134       std::vector<std::string> fs=GetAllFieldNames(fName);
135       if(std::find(fs.begin(),fs.end(),field->getName())!=fs.end())
136         {
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());
139         }
140     }
141   WriteUMesh(fName,mesh,writeFromScratch);
142   for(std::vector<std::size_t>::const_iterator iter=ids.begin();iter!=ids.end();iter++)
143     _time_steps[*iter]->write(fName,_name,_description);
144 }
145
146 void MEDCalculatorDBFieldReal::display() const throw(INTERP_KERNEL::Exception)
147 {
148   fetchData();
149   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
150   std::vector< MCAuto<MEDCouplingFieldDouble> > fs2(ids.size());
151   int ii=0;
152   for(std::vector<std::size_t>::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   MCAuto<MEDCouplingFieldOverTime> fot=MEDCouplingFieldOverTime::New(fs);
157   //
158   int argc=0;
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();
163   mgr->activate();
164   MEDCouplingFieldOverTimeServant *fots=new MEDCouplingFieldOverTimeServant(fot);
165   SALOME_MED::MEDCouplingFieldOverTimeCorbaInterface_var fotPtr=fots->_this();
166   //
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";
172   //
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();
176   CORBA::Any ob;
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);
184   req->invoke();
185   // clean-up
186 }
187
188 std::string MEDCalculatorDBFieldReal::simpleRepr() const
189 {
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<std::size_t> ids=_c.getIds(_c_labels.size());
197   for(std::vector<std::size_t>::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";
200   return oss.str();
201 }
202
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())
205 {
206   const std::vector<MEDCalculatorBrowserStep>& steps=ls.getSteps();
207   int sz=steps.size();
208   for(int i=0;i<sz;i++)
209     {
210       MCAuto<MEDCalculatorDBSliceField> elt(new MEDCalculatorDBSliceField(steps[i].getTimeStep(),steps[i].getOrder()));
211       _time_steps.push_back(elt);
212     }
213 }
214
215 const MEDCalculatorDBFieldReal& MEDCalculatorDBFieldReal::operator=(const MEDCalculatorDBFieldReal& other) throw(INTERP_KERNEL::Exception)
216 {
217   checkConsistencyLight(other);
218   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
219   std::vector<std::size_t> ids2=other._t.getIds(other._time_steps.size());
220   unsigned int sz=ids.size();
221   if(sz!=ids2.size())
222     throw INTERP_KERNEL::Exception("FieldReal::operator= : Timesteps lengths mismatch !");
223   fetchData();
224   other.fetchData();
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);
227   return *this;
228 }
229
230 const MEDCalculatorDBFieldReal& MEDCalculatorDBFieldReal::operator=(double val) throw(INTERP_KERNEL::Exception)
231 {
232   MCAuto<MEDCalculatorDBFieldReal> other=buildCstFieldFromThis(val);
233   return (*this)=*other;
234 }
235
236 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator+(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
237 {
238   const MEDCalculatorDBField *other2=&other;
239   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
240   if(otherr)
241     return add(*otherr);
242   else
243     {
244       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
245       if(otherc)
246         {
247           MCAuto<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
248           MEDCalculatorDBField *ret=add(*othercr);
249           return ret;
250         }
251       else
252         throw INTERP_KERNEL::Exception("FieldReal::operator+ : unrecognized type of parameter received !");
253     }
254 }
255
256 MEDCalculatorDBField *MEDCalculatorDBFieldReal::add(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
257 {
258   checkConsistencyLight(other);
259   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
260   fetchData();
261   other.fetchData();
262   DataArrayIdType *cellCor,*nodeCor;
263   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
264   std::vector<std::size_t> ids2=other._t.getIds(other._time_steps.size());
265   if(ids.size()!=ids2.size())
266     throw INTERP_KERNEL::Exception("FieldReal::add : Timesteps lengths mismatch !");
267   int step=ids[0];
268   int step2=ids2[0];
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
272   int sz=ids.size();
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);
278   if(cellCor)
279     cellCor->decrRef();
280   if(nodeCor)
281     nodeCor->decrRef();
282   ret->incrRef();
283   return ret;
284 }
285
286 bool MEDCalculatorDBFieldReal::isEqual(const MEDCalculatorDBField& other, double precM, double precF) const
287 {
288   const MEDCalculatorDBField *other2=&other;
289   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
290   if(otherr)
291     return isEqualSameType(*otherr,precM,precF);
292   else
293     {
294       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
295       if(otherc)
296         {
297           MCAuto<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
298           bool ret=isEqualSameType(*othercr,precM,precF);
299           return ret;
300         }
301       else
302         throw INTERP_KERNEL::Exception("FieldReal::isEqual : unrecognized type of parameter received !");
303     }
304 }
305
306 bool MEDCalculatorDBFieldReal::isEqualSameType(const MEDCalculatorDBFieldReal& other, double precM, double precF) const
307 {
308   if(_description!=other._description)
309     return false;
310   fetchData();
311   other.fetchData();
312   DataArrayIdType *cellCor,*nodeCor;
313   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
314   std::vector<std::size_t> ids2=other._t.getIds(other._time_steps.size());
315   if(ids.size()!=ids2.size())
316     return false;
317   int step=ids[0];
318   int step2=ids2[0];
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);
322   int sz=ids.size();
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))
325       return false;
326   if(cellCor)
327     cellCor->decrRef();
328   if(nodeCor)
329     nodeCor->decrRef();
330   return true;
331 }
332
333 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator-(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
334 {
335   const MEDCalculatorDBField *other2=&other;
336   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
337   if(otherr)
338     return substract(*otherr);
339   else
340     {
341       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
342       if(otherc)
343         {
344           MCAuto<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
345           MEDCalculatorDBField *ret=substract(*othercr);
346           return ret;
347         }
348       else
349         throw INTERP_KERNEL::Exception("FieldReal::operator- : unrecognized type of parameter received !");
350     }
351 }
352
353 MEDCalculatorDBField *MEDCalculatorDBFieldReal::substract(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
354 {
355   checkConsistencyLight(other);
356   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
357   fetchData();
358   other.fetchData();
359   DataArrayIdType *cellCor,*nodeCor;
360   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
361   std::vector<std::size_t> ids2=other._t.getIds(other._time_steps.size());
362   if(ids.size()!=ids2.size())
363     throw INTERP_KERNEL::Exception("FieldReal::substract : Timesteps lengths mismatch !");
364   int step=ids[0];
365   int step2=ids2[0];
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
369   int sz=ids.size();
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);
375   if(cellCor)
376     cellCor->decrRef();
377   if(nodeCor)
378     nodeCor->decrRef();
379   ret->incrRef();
380   return ret;
381 }
382
383 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator*(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
384 {
385   const MEDCalculatorDBField *other2=&other;
386   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
387   if(otherr)
388     return multiply(*otherr);
389   else
390     {
391       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
392       if(otherc)
393         {
394           MCAuto<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
395           MEDCalculatorDBField *ret=multiply(*othercr);
396           return ret;
397         }
398       else
399         throw INTERP_KERNEL::Exception("FieldReal::operator* : unrecognized type of parameter received !");
400     }
401 }
402
403 MEDCalculatorDBField *MEDCalculatorDBFieldReal::multiply(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
404 {
405   checkConsistencyLight(other);
406   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
407   fetchData();
408   other.fetchData();
409   DataArrayIdType *cellCor,*nodeCor;
410   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
411   std::vector<std::size_t> ids2=other._t.getIds(other._time_steps.size());
412   if(ids.size()!=ids2.size())
413     throw INTERP_KERNEL::Exception("FieldReal::multiply : Timesteps lengths mismatch !");
414   int step=ids[0];
415   int step2=ids2[0];
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
419   int sz=ids.size();
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);
425   if(cellCor)
426     cellCor->decrRef();
427   if(nodeCor)
428     nodeCor->decrRef();
429   ret->incrRef();
430   return ret;
431 }
432
433 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator/(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
434 {
435   const MEDCalculatorDBField *other2=&other;
436   const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
437   if(otherr)
438     return divide(*otherr);
439   else
440     {
441       const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
442       if(otherc)
443         {
444           MCAuto<MEDCalculatorDBFieldReal> othercr=buildCstFieldFromThis(otherc->getValue());
445           MEDCalculatorDBField *ret=divide(*othercr);
446           return ret;
447         }
448       else
449         throw INTERP_KERNEL::Exception("FieldReal::operator/ : unrecognized type of parameter received !");
450     }
451 }
452
453 MEDCalculatorDBField *MEDCalculatorDBFieldReal::divide(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
454 {
455   checkConsistencyLight(other);
456   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
457   fetchData();
458   other.fetchData();
459   DataArrayIdType *cellCor,*nodeCor;
460   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
461   std::vector<std::size_t> ids2=other._t.getIds(other._time_steps.size());
462   if(ids.size()!=ids2.size())
463     throw INTERP_KERNEL::Exception("FieldReal::divide : Timesteps lengths mismatch !");
464   int step=ids[0];
465   int step2=ids2[0];
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
469   int sz=ids.size();
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);
475   if(cellCor)
476     cellCor->decrRef();
477   if(nodeCor)
478     nodeCor->decrRef();
479   ret->incrRef();
480   return ret;
481 }
482
483 MEDCalculatorDBField *MEDCalculatorDBFieldReal::operator^(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
484 {
485   return crossProduct(other);
486 }
487
488 MEDCalculatorDBField *MEDCalculatorDBFieldReal::dot(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
489 {
490   checkConsistencyLight(other);
491   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
492   fetchData();
493   other.fetchData();
494   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
495   std::vector<std::size_t> ids2=other._t.getIds(other._time_steps.size());
496   unsigned int sz=ids.size();
497   if(sz!=ids2.size())
498     throw INTERP_KERNEL::Exception("FieldReal::dot : Timesteps lengths 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);
504   ret->incrRef();
505   return ret;
506 }
507
508 MEDCalculatorDBField *MEDCalculatorDBFieldReal::crossProduct(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
509 {
510   checkConsistencyLight(other);
511   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
512   fetchData();
513   other.fetchData();
514   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
515   std::vector<std::size_t> ids2=other._t.getIds(other._time_steps.size());
516   unsigned int sz=ids.size();
517   if(sz!=ids2.size())
518     throw INTERP_KERNEL::Exception("FieldReal::crossProduct : Timesteps lengths 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);
524   ret->incrRef();
525   return ret;
526 }
527
528 MEDCalculatorDBField *MEDCalculatorDBFieldReal::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
529 {
530   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
531   fetchData();
532   std::vector<std::size_t> 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);
539   ret->incrRef();
540   return ret;
541 }
542
543 MEDCalculatorDBField *MEDCalculatorDBFieldReal::determinant() const throw(INTERP_KERNEL::Exception)
544 {
545   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
546   fetchData();
547   std::vector<std::size_t> 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);
554   ret->incrRef();
555   return ret;
556 }
557
558 MEDCalculatorDBField *MEDCalculatorDBFieldReal::eigenValues() const throw(INTERP_KERNEL::Exception)
559 {
560   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
561   fetchData();
562   std::vector<std::size_t> 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);
568   if(sz!=0)
569     {
570       int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
571       ret->_c_labels.resize(ncomp);
572     }
573   else
574     ret->_c_labels.resize(0);
575   ret->incrRef();
576   return ret;
577 }
578
579 MEDCalculatorDBField *MEDCalculatorDBFieldReal::eigenVectors() const throw(INTERP_KERNEL::Exception)
580 {
581   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
582   fetchData();
583   std::vector<std::size_t> 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);
589   if(sz!=0)
590     {
591       int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
592       ret->_c_labels.resize(ncomp);
593     }
594   else
595     ret->_c_labels.resize(0);
596   ret->incrRef();
597   return ret;
598 }
599
600 MEDCalculatorDBField *MEDCalculatorDBFieldReal::inverse() const throw(INTERP_KERNEL::Exception)
601 {
602   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
603   fetchData();
604   std::vector<std::size_t> 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);
610   if(sz!=0)
611     {
612       int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
613       ret->_c_labels.resize(ncomp);
614     }
615   else
616     ret->_c_labels.resize(0);
617   ret->incrRef();
618   return ret;
619 }
620
621 MEDCalculatorDBField *MEDCalculatorDBFieldReal::trace() const throw(INTERP_KERNEL::Exception)
622 {
623   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
624   fetchData();
625   std::vector<std::size_t> 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);
632   ret->incrRef();
633   return ret;
634 }
635
636 MEDCalculatorDBField *MEDCalculatorDBFieldReal::deviator() const throw(INTERP_KERNEL::Exception)
637 {
638   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
639   fetchData();
640   std::vector<std::size_t> 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);
646   if(sz!=0)
647     {
648       int ncomp=ret->_time_steps[0]->getFieldAttribute()->getNumberOfComponents();
649       ret->_c_labels.resize(ncomp);
650     }
651   else
652     ret->_c_labels.resize(0);
653   ret->incrRef();
654   return ret;
655 }
656
657 MEDCalculatorDBField *MEDCalculatorDBFieldReal::magnitude() const throw(INTERP_KERNEL::Exception)
658 {
659   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
660   fetchData();
661   std::vector<std::size_t> 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);
668   ret->incrRef();
669   return ret;
670 }
671
672 void MEDCalculatorDBFieldReal::applyFunc(const char *func) throw(INTERP_KERNEL::Exception)
673 {
674   fetchData();
675   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
676   for(std::vector<std::size_t>::const_iterator it=ids.begin();it!=ids.end();it++)
677     _time_steps[*it]->applyFunc(func,_c_labels.size(),_c);
678 }
679
680 MEDCalculatorDBFieldReal *MEDCalculatorDBFieldReal::buildCstFieldFromThis(double val) const
681 {
682   MCAuto<MEDCalculatorDBFieldReal> ret=new MEDCalculatorDBFieldReal(_type);
683   ret->_p=_p;
684   ret->_c_labels.resize(_c.getSize(_c_labels.size()));
685   std::vector<std::size_t> stps=_t.getIds(_time_steps.size());
686   int stepSize=stps.size();
687   ret->_time_steps.resize(stepSize);
688   if(stepSize==0)
689     throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::buildCstFieldFromThis : no time steps defined !");
690   for(int i=0;i<stepSize;i++)
691     {
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));
694     }
695   ret->incrRef();
696   return ret;
697 }
698
699 void MEDCalculatorDBFieldReal::checkConsistencyLight(const MEDCalculatorDBFieldReal& other) const throw(INTERP_KERNEL::Exception)
700 {
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 !");
707 }
708
709 void MEDCalculatorDBFieldReal::fetchData() const throw(INTERP_KERNEL::Exception)
710 {
711   std::vector<std::pair<int,int> > idstoFetch;
712   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
713   int sz=ids.size();
714   std::vector<std::size_t> idsInGlobalToFetch;
715   for(int i=0;i<sz;i++)
716     {
717       MCAuto<MEDCalculatorDBSliceField> elt=_time_steps[ids[i]];
718       if(!elt->isFetched())
719         {
720           int dt,it;
721           elt->getDtIt(dt,it);
722           std::pair<int,int> p(dt,it);
723           idstoFetch.push_back(p);
724           idsInGlobalToFetch.push_back(ids[i]);
725         }
726     }
727   std::vector<MEDCouplingFieldDouble *> fs=ReadFieldsOnSameMesh(_type,_file_name.c_str(),_mesh_name.c_str(),0,_field_name.c_str(),idstoFetch);
728   sz=fs.size();
729   for(int i=0;i<sz;i++)
730     {
731       MCAuto<MEDCalculatorDBSliceField> elt=_time_steps[idsInGlobalToFetch[i]];
732       elt->setField(fs[i]);
733     }
734 }
735
736 int MEDCalculatorDBFieldReal::getNumberOfSteps() const
737 {
738   return _t.getSize(_time_steps.size());
739 }
740
741 int MEDCalculatorDBFieldReal::getNumberOfFetchedSteps() const
742 {
743   int ret=0;
744   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
745   for(std::vector<std::size_t>::const_iterator it=ids.begin();it!=ids.end();it++)
746     if(_time_steps[*it]->isFetched())
747       ret++;
748   return ret;
749 }
750
751 int MEDCalculatorDBFieldReal::getNumberOfComponents() const
752 {
753   return _c.getSize(_c_labels.size());
754 }
755
756 /*!
757  * WARNING the caller has the ownership of all of instances in returned vector.
758  */
759 std::vector<MEDCouplingFieldDouble *> MEDCalculatorDBFieldReal::getFields() const throw(INTERP_KERNEL::Exception)
760 {
761   fetchData();
762   std::vector<std::size_t> ids=_t.getIds(_time_steps.size());
763   std::vector<MEDCouplingFieldDouble *> ret(ids.size());
764   int i=0;
765   for(std::vector<std::size_t>::const_iterator it=ids.begin();it!=ids.end();it++,i++)
766     ret[i]=_time_steps[*it]->getFieldWithoutQuestion(_c_labels.size(),_c);
767   return ret;
768 }
769
770 std::string MEDCalculatorDBFieldReal::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
771 {
772   if(i>=(int)_c_labels.size())
773     throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::getInfoOnComponent : specified id >= number of component !");
774   return _c_labels[i];
775 }
776
777 void MEDCalculatorDBFieldReal::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
778 {
779   if(i>=(int)_c_labels.size())
780     throw INTERP_KERNEL::Exception("MEDCalculatorDBFieldReal::setInfoOnComponent : specified id >= number of component !");
781   _c_labels[i]=info;
782 }
783
784 MEDCalculatorDBFieldCst::MEDCalculatorDBFieldCst(double val):_val(val)
785 {
786 }
787
788 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator+(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
789 {
790   const MEDCalculatorDBField *other2=&other;
791   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
792   if(otherc)
793     {
794       MCAuto<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
795       ret->_val=_val+otherc->_val;
796       ret->incrRef();
797       return ret;
798     }
799   else
800     {
801       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
802       if(otherr)
803         {
804           MCAuto<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
805           MEDCalculatorDBField *ret=(*thisr)+other;
806           return ret;
807         }
808       else
809         throw INTERP_KERNEL::Exception("FieldCst::operator+ : unrecognized type of parameter received !");
810     }
811 }
812
813 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator-(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
814 {
815   const MEDCalculatorDBField *other2=&other;
816   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
817   if(otherc)
818     {
819       MCAuto<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
820       ret->_val=_val-otherc->_val;
821       ret->incrRef();
822       return ret;
823     }
824   else
825     {
826       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
827       if(otherr)
828         {
829           MCAuto<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
830           MEDCalculatorDBField *ret=(*thisr)-other;
831           return ret;
832         }
833       else
834         throw INTERP_KERNEL::Exception("FieldCst::operator- : unrecognized type of parameter received !");
835     }
836 }
837
838 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator*(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
839 {
840   const MEDCalculatorDBField *other2=&other;
841   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
842   if(otherc)
843     {
844       MCAuto<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
845       ret->_val=_val*otherc->_val;
846       ret->incrRef();
847       return ret;
848     }
849   else
850     {
851       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
852       if(otherr)
853         {
854           MCAuto<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
855           MEDCalculatorDBField *ret=(*thisr)*other;
856           return ret;
857         }
858       else
859         throw INTERP_KERNEL::Exception("FieldCst::operator* : unrecognized type of parameter received !");
860     }
861 }
862
863 MEDCalculatorDBField *MEDCalculatorDBFieldCst::operator/(const MEDCalculatorDBField& other) const throw(INTERP_KERNEL::Exception)
864 {
865   const MEDCalculatorDBField *other2=&other;
866   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
867   if(otherc)
868     {
869       MCAuto<MEDCalculatorDBFieldCst> ret=new MEDCalculatorDBFieldCst(*this);
870       ret->_val=_val/otherc->_val;
871       ret->incrRef();
872       return ret;
873     }
874   else
875     {
876       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
877       if(otherr)
878         {
879           MCAuto<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
880           MEDCalculatorDBField *ret=(*thisr)/other;
881           return ret;
882         }
883       else
884         throw INTERP_KERNEL::Exception("FieldCst::operator/ : unrecognized type of parameter received !");
885     }
886 }
887
888 bool MEDCalculatorDBFieldCst::isEqual(const MEDCalculatorDBField& other, double precM, double precF) const
889 {
890   const MEDCalculatorDBField *other2=&other;
891   const MEDCalculatorDBFieldCst *otherc=dynamic_cast<const MEDCalculatorDBFieldCst *>(other2);
892   if(otherc)
893     return fabs(otherc->_val-_val)<precF;
894   else
895     {
896       const MEDCalculatorDBFieldReal *otherr=dynamic_cast<const MEDCalculatorDBFieldReal *>(other2);
897       if(otherr)
898         {
899           MCAuto<MEDCalculatorDBFieldReal> thisr=otherr->buildCstFieldFromThis(_val);
900           bool ret=thisr->isEqual(other,precM,precF);
901           return ret;
902         }
903       else
904         throw INTERP_KERNEL::Exception("FieldCst::isEqual : unrecognized type of parameter received !");
905     }
906 }