1 // Copyright (C) 2007-2016 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 "MEDCouplingFieldDouble.hxx"
22 #include "MEDCouplingFieldTemplate.hxx"
23 #include "MEDCouplingUMesh.hxx"
24 #include "MEDCouplingTimeDiscretization.hxx"
25 #include "MEDCouplingFieldDiscretization.hxx"
27 #include "MEDCouplingNatureOfField.hxx"
29 #include "InterpKernelAutoPtr.hxx"
36 using namespace MEDCoupling;
40 * Creates a new MEDCouplingFieldDouble, of given spatial type and time discretization.
41 * For more info, see \ref MEDCouplingFirstSteps3.
42 * \param [in] type - the type of spatial discretization of the created field, one of
43 * (\ref MEDCoupling::ON_CELLS "ON_CELLS",
44 * \ref MEDCoupling::ON_NODES "ON_NODES",
45 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
46 * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
47 * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
48 * \param [in] td - the type of time discretization of the created field, one of
49 * (\ref MEDCoupling::NO_TIME "NO_TIME",
50 * \ref MEDCoupling::ONE_TIME "ONE_TIME",
51 * \ref MEDCoupling::LINEAR_TIME "LINEAR_TIME",
52 * \ref MEDCoupling::CONST_ON_TIME_INTERVAL "CONST_ON_TIME_INTERVAL").
53 * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
54 * caller is to delete this field using decrRef() as it is no more needed.
56 MEDCouplingFieldDouble* MEDCouplingFieldDouble::New(TypeOfField type, TypeOfTimeDiscretization td)
58 return new MEDCouplingFieldDouble(type,td);
62 * Creates a new MEDCouplingFieldDouble, of a given time discretization and with a
63 * spatial type and supporting mesh copied from a given
64 * \ref MEDCouplingFieldTemplatesPage "field template".
65 * For more info, see \ref MEDCouplingFirstSteps3.
66 * \warning This method does not deeply copy neither the mesh nor the spatial
67 * discretization. Only a shallow copy (reference) is done for the mesh and the spatial
69 * \param [in] ft - the \ref MEDCouplingFieldTemplatesPage "field template" defining
70 * the spatial discretization and the supporting mesh.
71 * \param [in] td - the type of time discretization of the created field, one of
72 * (\ref MEDCoupling::NO_TIME "NO_TIME",
73 * \ref MEDCoupling::ONE_TIME "ONE_TIME",
74 * \ref MEDCoupling::LINEAR_TIME "LINEAR_TIME",
75 * \ref MEDCoupling::CONST_ON_TIME_INTERVAL "CONST_ON_TIME_INTERVAL").
76 * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
77 * caller is to delete this field using decrRef() as it is no more needed.
79 MEDCouplingFieldDouble *MEDCouplingFieldDouble::New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td)
81 return new MEDCouplingFieldDouble(ft,td);
85 * Sets a time \a unit of \a this field. For more info, see \ref MEDCouplingFirstSteps3.
86 * \param [in] unit \a unit (string) in which time is measured.
88 void MEDCouplingFieldDouble::setTimeUnit(const std::string& unit)
90 _time_discr->setTimeUnit(unit);
94 * Returns a time unit of \a this field.
95 * \return a string describing units in which time is measured.
97 std::string MEDCouplingFieldDouble::getTimeUnit() const
99 return _time_discr->getTimeUnit();
103 * This method if possible the time information (time unit, time iteration, time unit and time value) with its support
104 * that is to say its mesh.
106 * \throw If \c this->_mesh is null an exception will be thrown. An exception will also be throw if the spatial discretization is
109 void MEDCouplingFieldDouble::synchronizeTimeWithSupport()
111 _time_discr->synchronizeTimeWith(_mesh);
115 * Returns a new MEDCouplingFieldDouble which is a copy of \a this one. The data
116 * of \a this field is copied either deep or shallow depending on \a recDeepCpy
117 * parameter. But the underlying mesh is always shallow copied.
118 * Data that can be copied either deeply or shallow are:
119 * - \ref MEDCouplingTemporalDisc "temporal discretization" data that holds array(s)
121 * - \ref MEDCouplingSpatialDisc "a spatial discretization".
123 * \c clone(false) is rather dedicated for advanced users that want to limit the amount
124 * of memory. It allows the user to perform methods like operator+(), operator*()
125 * etc. with \a this and the returned field. If the user wants to duplicate deeply the
126 * underlying mesh he should call cloneWithMesh() method or deepCopy() instead.
127 * \warning The underlying \b mesh of the returned field is **always the same**
128 * (pointer) as \a this one **whatever the value** of \a recDeepCpy parameter.
129 * \param [in] recDeepCpy - if \c true, the copy of the underlying data arrays is
130 * deep, else all data arrays of \a this field are shared by the new field.
131 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
132 * caller is to delete this field using decrRef() as it is no more needed.
133 * \sa cloneWithMesh()
135 MEDCouplingFieldDouble *MEDCouplingFieldDouble::clone(bool recDeepCpy) const
137 return new MEDCouplingFieldDouble(*this,recDeepCpy);
141 * Returns a new MEDCouplingFieldDouble which is a copy of \a this one. The data
142 * of \a this field is copied either deep or shallow depending on \a recDeepCpy
143 * parameter. But the underlying mesh is always deep copied.
144 * Data that can be copied either deeply or shallow are:
145 * - \ref MEDCouplingTemporalDisc "temporal discretization" data that holds array(s)
147 * - \ref MEDCouplingSpatialDisc "a spatial discretization".
149 * This method behaves exactly like clone() except that here the underlying **mesh is
150 * always deeply duplicated**, whatever the value \a recDeepCpy parameter.
151 * The result of \c cloneWithMesh(true) is exactly the same as that of deepCopy().
152 * So the resulting field can not be used together with \a this one in the methods
153 * like operator+(), operator*() etc. To avoid deep copying the underlying mesh,
154 * the user can call clone().
155 * \param [in] recDeepCpy - if \c true, the copy of the underlying data arrays is
156 * deep, else all data arrays of \a this field are shared by the new field.
157 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
158 * caller is to delete this field using decrRef() as it is no more needed.
161 MEDCouplingFieldDouble *MEDCouplingFieldDouble::cloneWithMesh(bool recDeepCpy) const
163 MCAuto<MEDCouplingFieldDouble> ret=clone(recDeepCpy);
166 MCAuto<MEDCouplingMesh> mCpy=_mesh->deepCopy();
173 * Returns a new MEDCouplingFieldDouble which is a deep copy of \a this one **including
175 * The result of this method is exactly the same as that of \c cloneWithMesh(true).
176 * So the resulting field can not be used together with \a this one in the methods
177 * like operator+(), operator*() etc. To avoid deep copying the underlying mesh,
178 * the user can call clone().
179 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
180 * caller is to delete this field using decrRef() as it is no more needed.
181 * \sa cloneWithMesh()
183 MEDCouplingFieldDouble *MEDCouplingFieldDouble::deepCopy() const
185 return cloneWithMesh(true);
189 * Creates a new MEDCouplingFieldDouble of given
190 * \ref MEDCouplingTemporalDisc "temporal discretization". The result field either
191 * shares the data array(s) with \a this field, or holds a deep copy of it, depending on
192 * \a deepCopy parameter. But the underlying \b mesh is always **shallow copied**.
193 * \param [in] td - the type of time discretization of the created field, one of
194 * (\ref MEDCoupling::NO_TIME "NO_TIME",
195 * \ref MEDCoupling::ONE_TIME "ONE_TIME",
196 * \ref MEDCoupling::LINEAR_TIME "LINEAR_TIME",
197 * \ref MEDCoupling::CONST_ON_TIME_INTERVAL "CONST_ON_TIME_INTERVAL").
198 * \param [in] deepCopy - if \c true, the copy of the underlying data arrays is
199 * deep, else all data arrays of \a this field are shared by the new field.
200 * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
201 * caller is to delete this field using decrRef() as it is no more needed.
203 * \if ENABLE_EXAMPLES
204 * \ref cpp_mcfielddouble_buildNewTimeReprFromThis "Here is a C++ example."<br>
205 * \ref py_mcfielddouble_buildNewTimeReprFromThis "Here is a Python example."
209 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const
211 MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(td,deepCopy);
212 MCAuto<MEDCouplingFieldDiscretization> disc;
215 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),tdo,disc.retn());
216 ret->setMesh(getMesh());
217 ret->setName(getName());
218 ret->setDescription(getDescription());
223 * This method converts a field on nodes (\a this) to a cell field (returned field). The convertion is a \b non \b conservative remapping !
224 * This method is useful only for users that need a fast convertion from node to cell spatial discretization. The algorithm applied is simply to attach
225 * to each cell the average of values on nodes constituting this cell.
227 * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
228 * caller is to delete this field using decrRef() as it is no more needed. The returned field will share the same mesh object object than those in \a this.
229 * \throw If \a this spatial discretization is empty or not ON_NODES.
230 * \throw If \a this is not coherent (see MEDCouplingFieldDouble::checkConsistencyLight).
232 * \warning This method is a \b non \b conservative method of remapping from node spatial discretization to cell spatial discretization.
233 * If a conservative method of interpolation is required MEDCoupling::MEDCouplingRemapper class should be used instead with "P1P0" method.
235 MEDCouplingFieldDouble *MEDCouplingFieldDouble::nodeToCellDiscretization() const
237 checkConsistencyLight();
238 TypeOfField tf(getTypeOfField());
240 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::nodeToCellDiscretization : this field is expected to be on ON_NODES !");
241 MCAuto<MEDCouplingFieldDouble> ret(clone(false));
242 MCAuto<MEDCouplingFieldDiscretizationP0> nsp(new MEDCouplingFieldDiscretizationP0);
243 ret->setDiscretization(nsp);
244 const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkConsistencyLight call
245 int nbCells(m->getNumberOfCells());
246 std::vector<DataArrayDouble *> arrs(getArrays());
247 std::size_t sz(arrs.size());
248 std::vector< MCAuto<DataArrayDouble> > outArrsSafe(sz); std::vector<DataArrayDouble *> outArrs(sz);
249 for(std::size_t j=0;j<sz;j++)
251 int nbCompo(arrs[j]->getNumberOfComponents());
252 outArrsSafe[j]=DataArrayDouble::New(); outArrsSafe[j]->alloc(nbCells,nbCompo);
253 outArrsSafe[j]->copyStringInfoFrom(*arrs[j]);
254 outArrs[j]=outArrsSafe[j];
255 double *pt(outArrsSafe[j]->getPointer());
256 const double *srcPt(arrs[j]->begin());
257 for(int i=0;i<nbCells;i++,pt+=nbCompo)
259 std::vector<int> nodeIds;
260 m->getNodeIdsOfCell(i,nodeIds);
261 std::fill(pt,pt+nbCompo,0.);
262 std::size_t nbNodesInCell(nodeIds.size());
263 for(std::size_t k=0;k<nbNodesInCell;k++)
264 std::transform(srcPt+nodeIds[k]*nbCompo,srcPt+(nodeIds[k]+1)*nbCompo,pt,pt,std::plus<double>());
266 std::transform(pt,pt+nbCompo,pt,std::bind2nd(std::multiplies<double>(),1./((double)nbNodesInCell)));
269 std::ostringstream oss; oss << "MEDCouplingFieldDouble::nodeToCellDiscretization : Cell id #" << i << " has been detected to have no nodes !";
270 throw INTERP_KERNEL::Exception(oss.str().c_str());
274 ret->setArrays(outArrs);
279 * This method converts a field on cell (\a this) to a node field (returned field). The convertion is a \b non \b conservative remapping !
280 * This method is useful only for users that need a fast convertion from cell to node spatial discretization. The algorithm applied is simply to attach
281 * to each node the average of values on cell sharing this node. If \a this lies on a mesh having orphan nodes the values applied on them will be NaN (division by 0.).
283 * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
284 * caller is to delete this field using decrRef() as it is no more needed. The returned field will share the same mesh object object than those in \a this.
285 * \throw If \a this spatial discretization is empty or not ON_CELLS.
286 * \throw If \a this is not coherent (see MEDCouplingFieldDouble::checkConsistencyLight).
288 * \warning This method is a \b non \b conservative method of remapping from cell spatial discretization to node spatial discretization.
289 * If a conservative method of interpolation is required MEDCoupling::MEDCouplingRemapper class should be used instead with "P0P1" method.
291 MEDCouplingFieldDouble *MEDCouplingFieldDouble::cellToNodeDiscretization() const
293 checkConsistencyLight();
294 TypeOfField tf(getTypeOfField());
296 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::cellToNodeDiscretization : this field is expected to be on ON_CELLS !");
297 MCAuto<MEDCouplingFieldDouble> ret(clone(false));
298 MCAuto<MEDCouplingFieldDiscretizationP1> nsp(new MEDCouplingFieldDiscretizationP1);
299 ret->setDiscretization(nsp);
300 const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkConsistencyLight call
301 MCAuto<DataArrayInt> rn(DataArrayInt::New()),rni(DataArrayInt::New());
302 m->getReverseNodalConnectivity(rn,rni);
303 MCAuto<DataArrayInt> rni2(rni->deltaShiftIndex());
304 MCAuto<DataArrayDouble> rni3(rni2->convertToDblArr()); rni2=0;
305 std::vector<DataArrayDouble *> arrs(getArrays());
306 std::size_t sz(arrs.size());
307 std::vector< MCAuto<DataArrayDouble> > outArrsSafe(sz); std::vector<DataArrayDouble *> outArrs(sz);
308 for(std::size_t j=0;j<sz;j++)
310 MCAuto<DataArrayDouble> tmp(arrs[j]->selectByTupleIdSafe(rn->begin(),rn->end()));
311 outArrsSafe[j]=(tmp->accumulatePerChunck(rni->begin(),rni->end())); tmp=0;
312 outArrsSafe[j]->divideEqual(rni3);
313 outArrsSafe[j]->copyStringInfoFrom(*arrs[j]);
314 outArrs[j]=outArrsSafe[j];
316 ret->setArrays(outArrs);
321 * Copies tiny info (component names, name and description) from an \a other field to
323 * \warning The underlying mesh is not renamed (for safety reason).
324 * \param [in] other - the field to copy the tiny info from.
325 * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
327 void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingField *other)
329 MEDCouplingField::copyTinyStringsFrom(other);
330 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
333 _time_discr->copyTinyStringsFrom(*otherC->_time_discr);
338 * Copies only times, order and iteration from an \a other field to
339 * \a this one. The underlying mesh is not impacted by this method.
340 * Arrays are not impacted neither.
341 * \param [in] other - the field to tiny attributes from.
342 * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
344 void MEDCouplingFieldDouble::copyTinyAttrFrom(const MEDCouplingFieldDouble *other)
348 _time_discr->copyTinyAttrFrom(*other->_time_discr);
352 void MEDCouplingFieldDouble::copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other)
354 copyTinyStringsFrom(other);
355 copyTinyAttrFrom(other);
359 * Returns a string describing \a this field. This string is outputted by \c print
360 * Python command. The string includes info on
363 * - \ref MEDCouplingSpatialDisc "spatial discretization",
364 * - \ref MEDCouplingTemporalDisc "time discretization",
365 * - \ref NatureOfField,
369 * \return std::string - the string describing \a this field.
371 std::string MEDCouplingFieldDouble::simpleRepr() const
373 std::ostringstream ret;
374 ret << "FieldDouble with name : \"" << getName() << "\"\n";
375 ret << "Description of field is : \"" << getDescription() << "\"\n";
377 { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; }
379 { ret << "FieldDouble has no spatial discretization !\n"; }
381 { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; }
383 { ret << "FieldDouble has no time discretization !\n"; }
384 ret << "FieldDouble nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
387 if(getArray()->isAllocated())
389 int nbOfCompo=getArray()->getNumberOfComponents();
390 ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
391 ret << "FieldDouble default array has following info on components : ";
392 for(int i=0;i<nbOfCompo;i++)
393 ret << "\"" << getArray()->getInfoOnComponent(i) << "\" ";
398 ret << "Array set but not allocated !\n";
402 ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
404 ret << "Mesh support information : No mesh set !\n";
409 * Returns a string describing \a this field. The string includes info on
412 * - \ref MEDCouplingSpatialDisc "spatial discretization",
413 * - \ref MEDCouplingTemporalDisc "time discretization",
416 * - contents of data arrays.
418 * \return std::string - the string describing \a this field.
420 std::string MEDCouplingFieldDouble::advancedRepr() const
422 std::ostringstream ret;
423 ret << "FieldDouble with name : \"" << getName() << "\"\n";
424 ret << "Description of field is : \"" << getDescription() << "\"\n";
426 { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; }
428 { ret << "FieldDouble has no space discretization set !\n"; }
430 { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; }
432 { ret << "FieldDouble has no time discretization set !\n"; }
434 ret << "FieldDouble default array has " << getArray()->getNumberOfComponents() << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
436 ret << "Mesh support information :\n__________________________\n" << _mesh->advancedRepr();
438 ret << "Mesh support information : No mesh set !\n";
439 std::vector<DataArrayDouble *> arrays;
440 _time_discr->getArrays(arrays);
442 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,arrayId++)
444 ret << "Array #" << arrayId << " :\n__________\n";
446 (*iter)->reprWithoutNameStream(ret);
448 ret << "Array empty !";
454 std::string MEDCouplingFieldDouble::writeVTK(const std::string& fileName, bool isBinary) const
456 std::vector<const MEDCouplingFieldDouble *> fs(1,this);
457 return MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary);
460 bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const
463 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::isEqualIfNotWhy : other instance is NULL !");
464 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
467 reason="field given in input is not castable in MEDCouplingFieldDouble !";
470 if(!MEDCouplingField::isEqualIfNotWhy(other,meshPrec,valsPrec,reason))
472 if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,valsPrec,reason))
474 reason.insert(0,"In FieldDouble time discretizations differ :");
481 * Checks equality of \a this and \a other field. Only numeric data is considered,
482 * i.e. names, description etc are not compared.
483 * \param [in] other - the field to compare with.
484 * \param [in] meshPrec - a precision used to compare node coordinates of meshes.
485 * \param [in] valsPrec - a precision used to compare data arrays of the two fields.
486 * \return bool - \c true if the two fields are equal, \c false else.
487 * \throw If \a other == NULL.
488 * \throw If the spatial discretization of \a this field is NULL.
490 bool MEDCouplingFieldDouble::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
492 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
495 if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec))
497 if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,valsPrec))
503 * This method states if \a this and 'other' are compatibles each other before performing any treatment.
504 * This method is good for methods like : mergeFields.
505 * This method is not very demanding compared to areStrictlyCompatible that is better for operation on fields.
507 bool MEDCouplingFieldDouble::areCompatibleForMerge(const MEDCouplingField *other) const
509 if(!MEDCouplingField::areCompatibleForMerge(other))
511 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
514 if(!_time_discr->areCompatible(otherC->_time_discr))
520 * This method is more strict than MEDCouplingField::areCompatibleForMerge method.
521 * This method is used for operation on fields to operate a first check before attempting operation.
523 bool MEDCouplingFieldDouble::areStrictlyCompatible(const MEDCouplingField *other) const
526 if(!MEDCouplingField::areStrictlyCompatible(other))
528 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
531 if(!_time_discr->areStrictlyCompatible(otherC->_time_discr,tmp))
537 * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatibleForMulDiv method except that
538 * number of components between \a this and 'other' can be different here (for operator*).
540 bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other) const
542 if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other))
544 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
547 if(!_time_discr->areStrictlyCompatibleForMul(otherC->_time_discr))
553 * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatibleForMulDiv method except that
554 * number of components between \a this and 'other' can be different here (for operator/).
556 bool MEDCouplingFieldDouble::areCompatibleForDiv(const MEDCouplingField *other) const
558 if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other))
560 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
563 if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr))
569 * This method is invocated before any attempt of melding. This method is very close to areStrictlyCompatible,
570 * except that \a this and other can have different number of components.
572 bool MEDCouplingFieldDouble::areCompatibleForMeld(const MEDCouplingFieldDouble *other) const
574 if(!MEDCouplingField::areStrictlyCompatible(other))
576 if(!_time_discr->areCompatibleForMeld(other->_time_discr))
582 * Permutes values of \a this field according to a given permutation array for cells
583 * renumbering. The underlying mesh is deeply copied and its cells are also permuted.
584 * The number of cells remains the same; for that the permutation array \a old2NewBg
585 * should not contain equal ids.
586 * ** Warning, this method modifies the mesh aggreagated by \a this (by performing a deep copy ) **.
588 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
589 * to be equal to \a this->getMesh()->getNumberOfCells().
590 * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
591 * array, so that its maximal cell id to correspond to (be less than) the number
592 * of cells in mesh. This new array is then used for the renumbering. If \a
593 * check == \c false, \a old2NewBg is used as is, that is less secure as validity
594 * of ids in \a old2NewBg is not checked.
595 * \throw If the mesh is not set.
596 * \throw If the spatial discretization of \a this field is NULL.
597 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
598 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
600 * \if ENABLE_EXAMPLES
601 * \ref cpp_mcfielddouble_renumberCells "Here is a C++ example".<br>
602 * \ref py_mcfielddouble_renumberCells "Here is a Python example".
605 void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check)
607 renumberCellsWithoutMesh(old2NewBg,check);
608 MCAuto<MEDCouplingMesh> m=_mesh->deepCopy();
609 m->renumberCells(old2NewBg,check);
615 * Permutes values of \a this field according to a given permutation array for cells
616 * renumbering. The underlying mesh is \b not permuted.
617 * The number of cells remains the same; for that the permutation array \a old2NewBg
618 * should not contain equal ids.
619 * This method performs a part of job of renumberCells(). The reasonable use of this
620 * method is only for multi-field instances lying on the same mesh to avoid a
621 * systematic duplication and renumbering of _mesh attribute.
622 * \warning Use this method with a lot of care!
623 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
624 * to be equal to \a this->getMesh()->getNumberOfCells().
625 * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
626 * array, so that its maximal cell id to correspond to (be less than) the number
627 * of cells in mesh. This new array is then used for the renumbering. If \a
628 * check == \c false, \a old2NewBg is used as is, that is less secure as validity
629 * of ids in \a old2NewBg is not checked.
630 * \throw If the mesh is not set.
631 * \throw If the spatial discretization of \a this field is NULL.
632 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
633 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
635 void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool check)
638 throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !");
639 if(!((const MEDCouplingFieldDiscretization *)_type))
640 throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
642 _type->renumberCells(old2NewBg,check);
643 std::vector<DataArrayDouble *> arrays;
644 _time_discr->getArrays(arrays);
645 std::vector<DataArray *> arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin());
646 _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check);
652 * Permutes values of \a this field according to a given permutation array for node
653 * renumbering. The underlying mesh is deeply copied and its nodes are also permuted.
654 * The number of nodes can change, contrary to renumberCells().
655 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
656 * to be equal to \a this->getMesh()->getNumberOfNodes().
657 * \param [in] eps - a precision used to compare field values at merged nodes. If
658 * the values differ more than \a eps, an exception is thrown.
659 * \throw If the mesh is not set.
660 * \throw If the spatial discretization of \a this field is NULL.
661 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
662 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
663 * \throw If values at merged nodes deffer more than \a eps.
665 * \if ENABLE_EXAMPLES
666 * \ref cpp_mcfielddouble_renumberNodes "Here is a C++ example".<br>
667 * \ref py_mcfielddouble_renumberNodes "Here is a Python example".
670 void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg, double eps)
672 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
674 throw INTERP_KERNEL::Exception("Invalid mesh to apply renumberNodes on it !");
675 int nbOfNodes=meshC->getNumberOfNodes();
676 MCAuto<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCopy());
677 int newNbOfNodes=*std::max_element(old2NewBg,old2NewBg+nbOfNodes)+1;
678 renumberNodesWithoutMesh(old2NewBg,newNbOfNodes,eps);
679 meshC2->renumberNodes(old2NewBg,newNbOfNodes);
684 * Permutes values of \a this field according to a given permutation array for nodes
685 * renumbering. The underlying mesh is \b not permuted.
686 * The number of nodes can change, contrary to renumberCells().
687 * A given epsilon specifies a threshold of error in case of two nodes are merged but
688 * the difference of values on these nodes are higher than \a eps.
689 * This method performs a part of job of renumberNodes(), excluding node renumbering
690 * in mesh. The reasonable use of this
691 * method is only for multi-field instances lying on the same mesh to avoid a
692 * systematic duplication and renumbering of _mesh attribute.
693 * \warning Use this method with a lot of care!
694 * \warning In case of an exception thrown, the contents of the data array can be
695 * partially modified until the exception occurs.
696 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
697 * to be equal to \a this->getMesh()->getNumberOfNodes().
698 * \param [in] newNbOfNodes - a number of nodes in the mesh after renumbering.
699 * \param [in] eps - a precision used to compare field values at merged nodes. If
700 * the values differ more than \a eps, an exception is thrown.
701 * \throw If the mesh is not set.
702 * \throw If the spatial discretization of \a this field is NULL.
703 * \throw If values at merged nodes deffer more than \a eps.
705 void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps)
707 if(!((const MEDCouplingFieldDiscretization *)_type))
708 throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
709 std::vector<DataArrayDouble *> arrays;
710 _time_discr->getArrays(arrays);
711 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
713 _type->renumberValuesOnNodes(eps,old2NewBg,newNbOfNodes,*iter);
717 * Returns all tuple ids of \a this scalar field that fit the range [\a vmin,
718 * \a vmax]. This method calls DataArrayDouble::findIdsInRange().
719 * \param [in] vmin - a lower boundary of the range. Tuples with values less than \a
720 * vmin are not included in the result array.
721 * \param [in] vmax - an upper boundary of the range. Tuples with values more than \a
722 * vmax are not included in the result array.
723 * \return DataArrayInt * - a new instance of DataArrayInt holding ids of selected
724 * tuples. The caller is to delete this array using decrRef() as it is no
726 * \throw If the data array is not set.
727 * \throw If \a this->getNumberOfComponents() != 1.
729 DataArrayInt *MEDCouplingFieldDouble::findIdsInRange(double vmin, double vmax) const
732 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::findIdsInRange : no default array set !");
733 return getArray()->findIdsInRange(vmin,vmax);
737 * Builds a newly created field, that the caller will have the responsability to deal with (decrRef()).
738 * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done.
739 * This method returns a restriction of \a this so that only tuples with ids specified in \a part will be contained in the returned field.
740 * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (
741 * \ref MEDCoupling::ON_CELLS "ON_CELLS",
742 * \ref MEDCoupling::ON_NODES "ON_NODES",
743 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
744 * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
745 * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
747 * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a part contains following cell ids [3,7,6].
748 * Then the returned field will lie on mesh having 3 cells and the returned field will contain 3 tuples.<br>
749 * Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().<br>
750 * Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().<br>
751 * Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
753 * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a part contains following cellIds [3,7,6].
754 * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
755 * will contain 6 tuples and \a this field will lie on this restricted mesh.
757 * \param [in] part - an array of cell ids to include to the result field.
758 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The caller is to delete this field using decrRef() as it is no more needed.
760 * \if ENABLE_EXAMPLES
761 * \ref cpp_mcfielddouble_subpart1 "Here is a C++ example".<br>
762 * \ref py_mcfielddouble_subpart1 "Here is a Python example".
764 * \sa MEDCouplingFieldDouble::buildSubPartRange
767 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *part) const
770 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : not empty array must be passed to this method !");
771 return buildSubPart(part->begin(),part->end());
775 * Builds a newly created field, that the caller will have the responsability to deal with.
776 * \n This method makes the assumption that \a this field is correctly defined when this method is called (\a this->checkConsistencyLight() returns without any exception thrown), **no check of this will be done**.
777 * \n This method returns a restriction of \a this so that only tuple ids specified in [ \a partBg , \a partEnd ) will be contained in the returned field.
778 * \n Parameter [\a partBg, \a partEnd ) specifies **cell ids whatever the spatial discretization** of \a this (
779 * \ref MEDCoupling::ON_CELLS "ON_CELLS",
780 * \ref MEDCoupling::ON_NODES "ON_NODES",
781 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT",
782 * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE",
783 * \ref MEDCoupling::ON_NODES_KR "ON_NODES_KR").
785 * For example, \a this is a field on cells lying on a mesh that have 10 cells, \a partBg contains the following cell ids [3,7,6].
786 * Then the returned field will lie on mesh having 3 cells and will contain 3 tuples.
787 *- Tuple #0 of the result field will refer to the cell #0 of returned mesh. The cell #0 of returned mesh will be equal to the cell #3 of \a this->getMesh().
788 *- Tuple #1 of the result field will refer to the cell #1 of returned mesh. The cell #1 of returned mesh will be equal to the cell #7 of \a this->getMesh().
789 *- Tuple #2 of the result field will refer to the cell #2 of returned mesh. The cell #2 of returned mesh will be equal to the cell #6 of \a this->getMesh().
791 * Let, for example, \a this be a field on nodes lying on a mesh that have 10 cells and 11 nodes, and \a partBg contains following cellIds [3,7,6].
792 * Thus \a this currently contains 11 tuples. If the restriction of mesh to 3 cells leads to a mesh with 6 nodes, then the returned field
793 * will contain 6 tuples and \a this field will lie on this restricted mesh.
795 * \param [in] partBg - start (included) of input range of cell ids to select [ \a partBg, \a partEnd )
796 * \param [in] partEnd - end (not included) of input range of cell ids to select [ \a partBg, \a partEnd )
797 * \return a newly allocated field the caller should deal with.
799 * \throw if there is presence of an invalid cell id in [ \a partBg, \a partEnd ) regarding the number of cells of \a this->getMesh().
801 * \if ENABLE_EXAMPLES
802 * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."<br>
803 * \ref py_mcfielddouble_subpart1 "Here a Python example."
805 * \sa MEDCoupling::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
807 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const
809 if(!((const MEDCouplingFieldDiscretization *)_type))
810 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
811 DataArrayInt *arrSelect;
812 MCAuto<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
813 MCAuto<DataArrayInt> arrSelect2(arrSelect);
814 MCAuto<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
815 const MEDCouplingFieldDiscretization *disc=getDiscretization();
817 ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePart(partBg,partEnd)));
819 std::vector<DataArrayDouble *> arrays;
820 _time_discr->getArrays(arrays);
821 std::vector<DataArrayDouble *> arrs;
822 std::vector< MCAuto<DataArrayDouble> > arrsSafe;
823 const int *arrSelBg=arrSelect->begin();
824 const int *arrSelEnd=arrSelect->end();
825 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
827 DataArrayDouble *arr=0;
829 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
830 arrs.push_back(arr); arrsSafe.push_back(arr);
832 ret->_time_discr->setArrays(arrs,0);
837 * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is
838 * given using a range given \a begin, \a end and \a step to optimize the part computation.
840 * \sa MEDCouplingFieldDouble::buildSubPart
842 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int end, int step) const
844 if(!((const MEDCouplingFieldDiscretization *)_type))
845 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
846 DataArrayInt *arrSelect;
847 int beginOut,endOut,stepOut;
848 MCAuto<MEDCouplingMesh> m=_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect);
849 MCAuto<DataArrayInt> arrSelect2(arrSelect);
850 MCAuto<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
851 const MEDCouplingFieldDiscretization *disc=getDiscretization();
853 ret->setDiscretization(MCAuto<MEDCouplingFieldDiscretization>(disc->clonePartRange(begin,end,step)));
855 std::vector<DataArrayDouble *> arrays;
856 _time_discr->getArrays(arrays);
857 std::vector<DataArrayDouble *> arrs;
858 std::vector< MCAuto<DataArrayDouble> > arrsSafe;
859 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
861 DataArrayDouble *arr=0;
866 const int *arrSelBg=arrSelect->begin();
867 const int *arrSelEnd=arrSelect->end();
868 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
871 arr=(*iter)->selectByTupleIdSafeSlice(beginOut,endOut,stepOut);
873 arrs.push_back(arr); arrsSafe.push_back(arr);
875 ret->_time_discr->setArrays(arrs,0);
880 * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field.
881 * \return MEDCoupling::TypeOfTimeDiscretization - an enum item describing the time
882 * discretization type.
884 TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const
886 return _time_discr->getEnum();
889 MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),
890 _time_discr(MEDCouplingTimeDiscretization::New(td))
895 * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! **
897 MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false),
898 _time_discr(MEDCouplingTimeDiscretization::New(td))
902 MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingField(other,deepCopy),
903 _time_discr(other._time_discr->performCopyOrIncrRef(deepCopy))
907 MEDCouplingFieldDouble::MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td)
911 MEDCouplingFieldDouble::~MEDCouplingFieldDouble()
917 * Checks if \a this field is correctly defined, else an exception is thrown.
918 * \throw If the mesh is not set.
919 * \throw If the data array is not set.
920 * \throw If the spatial discretization of \a this field is NULL.
921 * \throw If \a this->getTimeTolerance() < 0.
922 * \throw If the temporal discretization data is incorrect.
923 * \throw If mesh data does not correspond to field data.
925 void MEDCouplingFieldDouble::checkConsistencyLight() const
928 throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !");
929 if(!((const MEDCouplingFieldDiscretization *)_type))
930 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::checkConsistencyLight : no spatial discretization !");
931 _time_discr->checkConsistencyLight();
932 _type->checkCoherencyBetween(_mesh,getArray());
936 * Accumulate values of a given component of \a this field.
937 * \param [in] compId - the index of the component of interest.
938 * \return double - a sum value of *compId*-th component.
939 * \throw If the data array is not set.
940 * \throw If \a the condition ( 0 <= \a compId < \a this->getNumberOfComponents() ) is
943 double MEDCouplingFieldDouble::accumulate(int compId) const
946 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
947 return getArray()->accumulate(compId);
951 * Accumulates values of each component of \a this array.
952 * \param [out] res - an array of length \a this->getNumberOfComponents(), allocated
953 * by the caller, that is filled by this method with sum value for each
955 * \throw If the data array is not set.
957 void MEDCouplingFieldDouble::accumulate(double *res) const
960 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
961 getArray()->accumulate(res);
965 * Returns the maximal value within \a this scalar field. Values of all arrays stored
966 * in \a this->_time_discr are checked.
967 * \return double - the maximal value among all values of \a this field.
968 * \throw If \a this->getNumberOfComponents() != 1
969 * \throw If the data array is not set.
970 * \throw If there is an empty data array in \a this field.
972 double MEDCouplingFieldDouble::getMaxValue() const
974 std::vector<DataArrayDouble *> arrays;
975 _time_discr->getArrays(arrays);
976 double ret=-std::numeric_limits<double>::max();
977 bool isExistingArr=false;
978 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
984 ret=std::max(ret,(*iter)->getMaxValue(loc));
988 throw INTERP_KERNEL::Exception("getMaxValue : No arrays defined !");
993 * Returns the maximal value and all its locations within \a this scalar field.
994 * Only the first of available data arrays is checked.
995 * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
996 * tuples holding the maximal value. The caller is to delete it using
997 * decrRef() as it is no more needed.
998 * \return double - the maximal value among all values of the first array of \a this filed.
999 * \throw If \a this->getNumberOfComponents() != 1.
1000 * \throw If there is an empty data array in \a this field.
1002 double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const
1004 std::vector<DataArrayDouble *> arrays;
1005 _time_discr->getArrays(arrays);
1006 double ret=-std::numeric_limits<double>::max();
1007 bool isExistingArr=false;
1009 MCAuto<DataArrayInt> ret1;
1010 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
1016 ret=std::max(ret,(*iter)->getMaxValue2(tmp));
1017 MCAuto<DataArrayInt> tmpSafe(tmp);
1018 if(!((const DataArrayInt *)ret1))
1023 throw INTERP_KERNEL::Exception("getMaxValue2 : No arrays defined !");
1024 tupleIds=ret1.retn();
1029 * Returns the minimal value within \a this scalar field. Values of all arrays stored
1030 * in \a this->_time_discr are checked.
1031 * \return double - the minimal value among all values of \a this field.
1032 * \throw If \a this->getNumberOfComponents() != 1
1033 * \throw If the data array is not set.
1034 * \throw If there is an empty data array in \a this field.
1036 double MEDCouplingFieldDouble::getMinValue() const
1038 std::vector<DataArrayDouble *> arrays;
1039 _time_discr->getArrays(arrays);
1040 double ret=std::numeric_limits<double>::max();
1041 bool isExistingArr=false;
1042 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
1048 ret=std::min(ret,(*iter)->getMinValue(loc));
1052 throw INTERP_KERNEL::Exception("getMinValue : No arrays defined !");
1057 * Returns the minimal value and all its locations within \a this scalar field.
1058 * Only the first of available data arrays is checked.
1059 * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
1060 * tuples holding the minimal value. The caller is to delete it using
1061 * decrRef() as it is no more needed.
1062 * \return double - the minimal value among all values of the first array of \a this filed.
1063 * \throw If \a this->getNumberOfComponents() != 1.
1064 * \throw If there is an empty data array in \a this field.
1066 double MEDCouplingFieldDouble::getMinValue2(DataArrayInt*& tupleIds) const
1068 std::vector<DataArrayDouble *> arrays;
1069 _time_discr->getArrays(arrays);
1070 double ret=-std::numeric_limits<double>::max();
1071 bool isExistingArr=false;
1073 MCAuto<DataArrayInt> ret1;
1074 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
1080 ret=std::max(ret,(*iter)->getMinValue2(tmp));
1081 MCAuto<DataArrayInt> tmpSafe(tmp);
1082 if(!((const DataArrayInt *)ret1))
1087 throw INTERP_KERNEL::Exception("getMinValue2 : No arrays defined !");
1088 tupleIds=ret1.retn();
1093 * Returns the average value of \a this scalar field.
1094 * \return double - the average value over all values of the data array.
1095 * \throw If \a this->getNumberOfComponents() != 1
1096 * \throw If the data array is not set or it is empty.
1098 double MEDCouplingFieldDouble::getAverageValue() const
1101 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getAverageValue : no default array defined !");
1102 return getArray()->getAverageValue();
1106 * This method returns the euclidean norm of \a this field.
1108 * \sqrt{\sum_{0 \leq i < nbOfEntity}val[i]*val[i]}
1110 * \throw If the data array is not set.
1112 double MEDCouplingFieldDouble::norm2() const
1115 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::norm2 : no default array defined !");
1116 return getArray()->norm2();
1120 * This method returns the max norm of \a this field.
1122 * \max_{0 \leq i < nbOfEntity}{abs(val[i])}
1124 * \throw If the data array is not set.
1126 double MEDCouplingFieldDouble::normMax() const
1129 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::normMax : no default array defined !");
1130 return getArray()->normMax();
1134 * Computes the weighted average of values of each component of \a this field, the weights being the
1135 * values returned by buildMeasureField().
1136 * \param [out] res - pointer to an array of result sum values, of size at least \a
1137 * this->getNumberOfComponents(), that is to be allocated by the caller.
1138 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weights computed by
1139 * buildMeasureField(). It makes this method slower. If you are sure that all
1140 * the cells of the underlying mesh have a correct orientation (no negative volume), you can put \a isWAbs ==
1141 * \c false to speed up the method.
1142 * \throw If the mesh is not set.
1143 * \throw If the data array is not set.
1145 void MEDCouplingFieldDouble::getWeightedAverageValue(double *res, bool isWAbs) const
1148 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getWeightedAverageValue : no default array defined !");
1149 MCAuto<MEDCouplingFieldDouble> w=buildMeasureField(isWAbs);
1150 double deno=w->getArray()->accumulate(0);
1151 MCAuto<DataArrayDouble> arr=getArray()->deepCopy();
1152 arr->multiplyEqual(w->getArray());
1153 arr->accumulate(res);
1154 int nCompo = getArray()->getNumberOfComponents();
1155 std::transform(res,res+nCompo,res,std::bind2nd(std::multiplies<double>(),1./deno));
1159 * Computes the weighted average of values of a given component of \a this field, the weights being the
1160 * values returned by buildMeasureField().
1161 * \param [in] compId - an index of the component of interest.
1162 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weights computed by
1163 * buildMeasureField(). It makes this method slower. If you are sure that all
1164 * the cells of the underlying mesh have a correct orientation (no negative volume), you can put \a isWAbs ==
1165 * \c false to speed up the method.
1166 * \throw If the mesh is not set.
1167 * \throw If the data array is not set.
1168 * \throw If \a compId is not valid.
1169 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1171 double MEDCouplingFieldDouble::getWeightedAverageValue(int compId, bool isWAbs) const
1173 int nbComps=getArray()->getNumberOfComponents();
1174 if(compId<0 || compId>=nbComps)
1176 std::ostringstream oss; oss << "MEDCouplingFieldDouble::getWeightedAverageValue : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1177 throw INTERP_KERNEL::Exception(oss.str().c_str());
1179 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1180 getWeightedAverageValue(res,isWAbs);
1185 * Returns the \c normL1 of values of a given component of \a this field:
1187 * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1189 * \param [in] compId - an index of the component of interest.
1190 * \throw If the mesh is not set.
1191 * \throw If the spatial discretization of \a this field is NULL.
1192 * \throw If \a compId is not valid.
1193 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1195 double MEDCouplingFieldDouble::normL1(int compId) const
1198 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1 !");
1199 if(!((const MEDCouplingFieldDiscretization *)_type))
1200 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1201 int nbComps=getArray()->getNumberOfComponents();
1202 if(compId<0 || compId>=nbComps)
1204 std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL1 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1205 throw INTERP_KERNEL::Exception(oss.str().c_str());
1207 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1208 _type->normL1(_mesh,getArray(),res);
1213 * Returns the \c normL1 of values of each component of \a this field:
1215 * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1217 * \param [out] res - pointer to an array of result values, of size at least \a
1218 * this->getNumberOfComponents(), that is to be allocated by the caller.
1219 * \throw If the mesh is not set.
1220 * \throw If the spatial discretization of \a this field is NULL.
1222 void MEDCouplingFieldDouble::normL1(double *res) const
1225 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1");
1226 if(!((const MEDCouplingFieldDiscretization *)_type))
1227 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1228 _type->normL1(_mesh,getArray(),res);
1232 * Returns the \c normL2 of values of a given component of \a this field:
1234 * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1236 * \param [in] compId - an index of the component of interest.
1237 * \throw If the mesh is not set.
1238 * \throw If the spatial discretization of \a this field is NULL.
1239 * \throw If \a compId is not valid.
1240 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1242 double MEDCouplingFieldDouble::normL2(int compId) const
1245 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1246 if(!((const MEDCouplingFieldDiscretization *)_type))
1247 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1248 int nbComps=getArray()->getNumberOfComponents();
1249 if(compId<0 || compId>=nbComps)
1251 std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL2 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1252 throw INTERP_KERNEL::Exception(oss.str().c_str());
1254 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1255 _type->normL2(_mesh,getArray(),res);
1260 * Returns the \c normL2 of values of each component of \a this field:
1262 * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1264 * \param [out] res - pointer to an array of result values, of size at least \a
1265 * this->getNumberOfComponents(), that is to be allocated by the caller.
1266 * \throw If the mesh is not set.
1267 * \throw If the spatial discretization of \a this field is NULL.
1269 void MEDCouplingFieldDouble::normL2(double *res) const
1272 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1273 if(!((const MEDCouplingFieldDiscretization *)_type))
1274 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1275 _type->normL2(_mesh,getArray(),res);
1279 * Computes a sum of values of a given component of \a this field multiplied by
1280 * values returned by buildMeasureField().
1281 * This method is useful to check the conservativity of interpolation method.
1282 * \param [in] compId - an index of the component of interest.
1283 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1284 * buildMeasureField() that makes this method slower. If a user is sure that all
1285 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1286 * \c false that speeds up this method.
1287 * \throw If the mesh is not set.
1288 * \throw If the data array is not set.
1289 * \throw If \a compId is not valid.
1290 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1292 double MEDCouplingFieldDouble::integral(int compId, bool isWAbs) const
1295 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral");
1296 if(!((const MEDCouplingFieldDiscretization *)_type))
1297 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral !");
1298 int nbComps=getArray()->getNumberOfComponents();
1299 if(compId<0 || compId>=nbComps)
1301 std::ostringstream oss; oss << "MEDCouplingFieldDouble::integral : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1302 throw INTERP_KERNEL::Exception(oss.str().c_str());
1304 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1305 _type->integral(_mesh,getArray(),isWAbs,res);
1310 * Computes a sum of values of each component of \a this field multiplied by
1311 * values returned by buildMeasureField().
1312 * This method is useful to check the conservativity of interpolation method.
1313 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1314 * buildMeasureField() that makes this method slower. If a user is sure that all
1315 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1316 * \c false that speeds up this method.
1317 * \param [out] res - pointer to an array of result sum values, of size at least \a
1318 * this->getNumberOfComponents(), that is to be allocated by the caller.
1319 * \throw If the mesh is not set.
1320 * \throw If the data array is not set.
1321 * \throw If the spatial discretization of \a this field is NULL.
1323 void MEDCouplingFieldDouble::integral(bool isWAbs, double *res) const
1326 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral2");
1327 if(!((const MEDCouplingFieldDiscretization *)_type))
1328 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral2 !");
1329 _type->integral(_mesh,getArray(),isWAbs,res);
1333 * Returns a value at a given cell of a structured mesh. The cell is specified by its
1335 * \param [in] i - a index of node coordinates array along X axis. The cell is
1336 * located between the i-th and ( i + 1 )-th nodes along X axis.
1337 * \param [in] j - a index of node coordinates array along Y axis. The cell is
1338 * located between the j-th and ( j + 1 )-th nodes along Y axis.
1339 * \param [in] k - a index of node coordinates array along Z axis. The cell is
1340 * located between the k-th and ( k + 1 )-th nodes along Z axis.
1341 * \param [out] res - pointer to an array returning a feild value, of size at least
1342 * \a this->getNumberOfComponents(), that is to be allocated by the caller.
1343 * \throw If the spatial discretization of \a this field is NULL.
1344 * \throw If the mesh is not set.
1345 * \throw If the mesh is not a structured one.
1347 * \if ENABLE_EXAMPLES
1348 * \ref cpp_mcfielddouble_getValueOnPos "Here is a C++ example".<br>
1349 * \ref py_mcfielddouble_getValueOnPos "Here is a Python example".
1352 void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) const
1354 const DataArrayDouble *arr=_time_discr->getArray();
1356 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnPos");
1357 if(!((const MEDCouplingFieldDiscretization *)_type))
1358 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1359 _type->getValueOnPos(arr,_mesh,i,j,k,res);
1363 * Returns a value of \a this at a given point using spatial discretization.
1364 * \param [in] spaceLoc - the point of interest.
1365 * \param [out] res - pointer to an array returning a feild value, of size at least
1366 * \a this->getNumberOfComponents(), that is to be allocated by the caller.
1367 * \throw If the spatial discretization of \a this field is NULL.
1368 * \throw If the mesh is not set.
1369 * \throw If \a spaceLoc is out of the spatial discretization.
1371 * \if ENABLE_EXAMPLES
1372 * \ref cpp_mcfielddouble_getValueOn "Here is a C++ example".<br>
1373 * \ref py_mcfielddouble_getValueOn "Here is a Python example".
1376 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) const
1378 const DataArrayDouble *arr=_time_discr->getArray();
1380 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1381 if(!((const MEDCouplingFieldDiscretization *)_type))
1382 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1383 _type->getValueOn(arr,_mesh,spaceLoc,res);
1387 * Returns values of \a this at given points using spatial discretization.
1388 * \param [in] spaceLoc - coordinates of points of interest in full-interlace
1389 * mode. This array is to be of size ( \a nbOfPoints * \a this->getNumberOfComponents() ).
1390 * \param [in] nbOfPoints - number of points of interest.
1391 * \return DataArrayDouble * - a new instance of DataArrayDouble holding field
1392 * values relating to the input points. This array is of size \a nbOfPoints
1393 * tuples per \a this->getNumberOfComponents() components. The caller is to
1394 * delete this array using decrRef() as it is no more needed.
1395 * \throw If the spatial discretization of \a this field is NULL.
1396 * \throw If the mesh is not set.
1397 * \throw If any point in \a spaceLoc is out of the spatial discretization.
1399 * \if ENABLE_EXAMPLES
1400 * \ref cpp_mcfielddouble_getValueOnMulti "Here is a C++ example".<br>
1401 * \ref py_mcfielddouble_getValueOnMulti "Here is a Python example".
1404 DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, int nbOfPoints) const
1406 const DataArrayDouble *arr=_time_discr->getArray();
1408 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnMulti");
1409 if(!((const MEDCouplingFieldDiscretization *)_type))
1410 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnMulti !");
1411 return _type->getValueOnMulti(arr,_mesh,spaceLoc,nbOfPoints);
1415 * Returns a value of \a this field at a given point at a given time using spatial discretization.
1416 * If the time is not covered by \a this->_time_discr, an exception is thrown.
1417 * \param [in] spaceLoc - the point of interest.
1418 * \param [in] time - the time of interest.
1419 * \param [out] res - pointer to an array returning a feild value, of size at least
1420 * \a this->getNumberOfComponents(), that is to be allocated by the caller.
1421 * \throw If the spatial discretization of \a this field is NULL.
1422 * \throw If the mesh is not set.
1423 * \throw If \a spaceLoc is out of the spatial discretization.
1424 * \throw If \a time is not covered by \a this->_time_discr.
1426 * \if ENABLE_EXAMPLES
1427 * \ref cpp_mcfielddouble_getValueOn_time "Here is a C++ example".<br>
1428 * \ref py_mcfielddouble_getValueOn_time "Here is a Python example".
1431 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, double *res) const
1433 std::vector< const DataArrayDouble *> arrs=_time_discr->getArraysForTime(time);
1435 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1436 if(!((const MEDCouplingFieldDiscretization *)_type))
1437 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOn !");
1438 std::vector<double> res2;
1439 for(std::vector< const DataArrayDouble *>::const_iterator iter=arrs.begin();iter!=arrs.end();iter++)
1441 int sz=(int)res2.size();
1442 res2.resize(sz+(*iter)->getNumberOfComponents());
1443 _type->getValueOn(*iter,_mesh,spaceLoc,&res2[sz]);
1445 _time_discr->getValueForTime(time,res2,res);
1449 * Apply a linear function to a given component of \a this field, so that
1450 * a component value <em>(x)</em> becomes \f$ a * x + b \f$.
1451 * \param [in] a - the first coefficient of the function.
1452 * \param [in] b - the second coefficient of the function.
1453 * \param [in] compoId - the index of component to modify.
1454 * \throw If the data array(s) is(are) not set.
1456 void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId)
1458 _time_discr->applyLin(a,b,compoId);
1462 * Apply a linear function to all components of \a this field, so that
1463 * values <em>(x)</em> becomes \f$ a * x + b \f$.
1464 * \param [in] a - the first coefficient of the function.
1465 * \param [in] b - the second coefficient of the function.
1466 * \throw If the data array(s) is(are) not set.
1468 void MEDCouplingFieldDouble::applyLin(double a, double b)
1470 _time_discr->applyLin(a,b);
1474 * This method sets \a this to a uniform scalar field with one component.
1475 * All tuples will have the same value 'value'.
1476 * An exception is thrown if no underlying mesh is defined.
1478 MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value)
1481 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !");
1482 if(!((const MEDCouplingFieldDiscretization *)_type))
1483 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform operator = !");
1484 int nbOfTuple=_type->getNumberOfTuples(_mesh);
1485 _time_discr->setOrCreateUniformValueOnAllComponents(nbOfTuple,value);
1490 * Creates data array(s) of \a this field by using a C function for value generation.
1491 * \param [in] nbOfComp - the number of components for \a this field to have.
1492 * \param [in] func - the function used to compute values of \a this field.
1493 * This function is to compute a field value basing on coordinates of value
1495 * \throw If the mesh is not set.
1496 * \throw If \a func returns \c false.
1497 * \throw If the spatial discretization of \a this field is NULL.
1499 * \if ENABLE_EXAMPLES
1500 * \ref cpp_mcfielddouble_fillFromAnalytic_c_func "Here is a C++ example".
1503 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate func)
1506 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1507 if(!((const MEDCouplingFieldDiscretization *)_type))
1508 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1509 MCAuto<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1510 _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1514 * Creates data array(s) of \a this field by using a function for value generation.<br>
1515 * The function is applied to coordinates of value location points. For example, if
1516 * \a this field is on cells, the function is applied to cell barycenters.
1517 * For more info on supported expressions that can be used in the function, see \ref
1518 * MEDCouplingArrayApplyFuncExpr. <br>
1519 * The function can include arbitrary named variables
1520 * (e.g. "x","y" or "va44") to refer to components of point coordinates. Names of
1521 * variables are sorted in \b alphabetical \b order to associate a variable name with a
1522 * component. For example, in the expression "2*x+z", "x" stands for the component #0
1523 * and "z" stands for the component #1 (\b not #2)!<br>
1524 * In a general case, a value resulting from the function evaluation is assigned to all
1525 * components of a field value. But there is a possibility to have its own expression for
1526 * each component within one function. For this purpose, there are predefined variable
1527 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1528 * the component #0 etc). A factor of such a variable is added to the
1529 * corresponding component only.<br>
1530 * For example, \a nbOfComp == 4, coordinates of a 3D point are (1.,3.,7.), then
1531 * - "2*x + z" produces (5.,5.,5.,5.)
1532 * - "2*x + 0*y + z" produces (9.,9.,9.,9.)
1533 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1534 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1536 * \param [in] nbOfComp - the number of components for \a this field to have.
1537 * \param [in] func - the function used to compute values of \a this field.
1538 * This function is used to compute a field value basing on coordinates of value
1539 * location point. For example, if \a this field is on cells, the function
1540 * is applied to cell barycenters.
1541 * \throw If the mesh is not set.
1542 * \throw If the spatial discretization of \a this field is NULL.
1543 * \throw If computing \a func fails.
1545 * \if ENABLE_EXAMPLES
1546 * \ref cpp_mcfielddouble_fillFromAnalytic "Here is a C++ example".<br>
1547 * \ref py_mcfielddouble_fillFromAnalytic "Here is a Python example".
1550 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func)
1553 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1554 if(!((const MEDCouplingFieldDiscretization *)_type))
1555 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1556 MCAuto<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1557 _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1561 * Creates data array(s) of \a this field by using a function for value generation.<br>
1562 * The function is applied to coordinates of value location points. For example, if
1563 * \a this field is on cells, the function is applied to cell barycenters.<br>
1564 * This method differs from
1565 * \ref MEDCoupling::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func) "fillFromAnalytic()"
1566 * by the way how variable
1567 * names, used in the function, are associated with components of coordinates of field
1568 * location points; here, a variable name corresponding to a component is retrieved from
1569 * a corresponding node coordinates array (where it is set via
1570 * DataArrayDouble::setInfoOnComponent()).<br>
1571 * For more info on supported expressions that can be used in the function, see \ref
1572 * MEDCouplingArrayApplyFuncExpr. <br>
1573 * In a general case, a value resulting from the function evaluation is assigned to all
1574 * components of a field value. But there is a possibility to have its own expression for
1575 * each component within one function. For this purpose, there are predefined variable
1576 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1577 * the component #0 etc). A factor of such a variable is added to the
1578 * corresponding component only.<br>
1579 * For example, \a nbOfComp == 4, names of spatial components are "x", "y" and "z",
1580 * coordinates of a 3D point are (1.,3.,7.), then
1581 * - "2*x + z" produces (9.,9.,9.,9.)
1582 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1583 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1585 * \param [in] nbOfComp - the number of components for \a this field to have.
1586 * \param [in] func - the function used to compute values of \a this field.
1587 * This function is used to compute a field value basing on coordinates of value
1588 * location point. For example, if \a this field is on cells, the function
1589 * is applied to cell barycenters.
1590 * \throw If the mesh is not set.
1591 * \throw If the spatial discretization of \a this field is NULL.
1592 * \throw If computing \a func fails.
1594 * \if ENABLE_EXAMPLES
1595 * \ref cpp_mcfielddouble_fillFromAnalytic2 "Here is a C++ example".<br>
1596 * \ref py_mcfielddouble_fillFromAnalytic2 "Here is a Python example".
1599 void MEDCouplingFieldDouble::fillFromAnalyticCompo(int nbOfComp, const std::string& func)
1602 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalyticCompo : no mesh defined !");
1603 if(!((const MEDCouplingFieldDiscretization *)_type))
1604 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalyticCompo !");
1605 MCAuto<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1606 _time_discr->fillFromAnalyticCompo(loc,nbOfComp,func);
1610 * Creates data array(s) of \a this field by using a function for value generation.<br>
1611 * The function is applied to coordinates of value location points. For example, if
1612 * \a this field is on cells, the function is applied to cell barycenters.<br>
1613 * This method differs from
1614 * \ref MEDCoupling::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func) "fillFromAnalytic()"
1615 * by the way how variable
1616 * names, used in the function, are associated with components of coordinates of field
1617 * location points; here, a component index of a variable is defined by a
1618 * rank of the variable within the input array \a varsOrder.<br>
1619 * For more info on supported expressions that can be used in the function, see \ref
1620 * MEDCouplingArrayApplyFuncExpr.
1621 * In a general case, a value resulting from the function evaluation is assigned to all
1622 * components of a field value. But there is a possibility to have its own expression for
1623 * each component within one function. For this purpose, there are predefined variable
1624 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1625 * the component #0 etc). A factor of such a variable is added to the
1626 * corresponding component only.<br>
1627 * For example, \a nbOfComp == 4, names of
1628 * spatial components are given in \a varsOrder: ["x", "y","z"], coordinates of a
1629 * 3D point are (1.,3.,7.), then
1630 * - "2*x + z" produces (9.,9.,9.,9.)
1631 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1632 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1634 * \param [in] nbOfComp - the number of components for \a this field to have.
1635 * \param [in] func - the function used to compute values of \a this field.
1636 * This function is used to compute a field value basing on coordinates of value
1637 * location point. For example, if \a this field is on cells, the function
1638 * is applied to cell barycenters.
1639 * \throw If the mesh is not set.
1640 * \throw If the spatial discretization of \a this field is NULL.
1641 * \throw If computing \a func fails.
1643 * \if ENABLE_EXAMPLES
1644 * \ref cpp_mcfielddouble_fillFromAnalytic3 "Here is a C++ example".<br>
1645 * \ref py_mcfielddouble_fillFromAnalytic3 "Here is a Python example".
1648 void MEDCouplingFieldDouble::fillFromAnalyticNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
1651 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalyticCompo : no mesh defined !");
1652 if(!((const MEDCouplingFieldDiscretization *)_type))
1653 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalyticNamedCompo !");
1654 MCAuto<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1655 _time_discr->fillFromAnalyticNamedCompo(loc,nbOfComp,varsOrder,func);
1659 * Modifies values of \a this field by applying a C function to each tuple of all
1661 * \param [in] nbOfComp - the number of components for \a this field to have.
1662 * \param [in] func - the function used to compute values of \a this field.
1663 * This function is to compute a field value basing on a current field value.
1664 * \throw If \a func returns \c false.
1666 * \if ENABLE_EXAMPLES
1667 * \ref cpp_mcfielddouble_applyFunc_c_func "Here is a C++ example".
1670 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, FunctionToEvaluate func)
1672 _time_discr->applyFunc(nbOfComp,func);
1676 * Fill \a this field with a given value.<br>
1677 * This method is a specialization of other overloaded methods. When \a nbOfComp == 1
1678 * this method is equivalent to MEDCoupling::MEDCouplingFieldDouble::operator=().
1679 * \param [in] nbOfComp - the number of components for \a this field to have.
1680 * \param [in] val - the value to assign to every atomic value of \a this field.
1681 * \throw If the spatial discretization of \a this field is NULL.
1682 * \throw If the mesh is not set.
1684 * \if ENABLE_EXAMPLES
1685 * \ref cpp_mcfielddouble_applyFunc_val "Here is a C++ example".<br>
1686 * \ref py_mcfielddouble_applyFunc_val "Here is a Python example".
1689 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val)
1692 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::applyFunc : no mesh defined !");
1693 if(!((const MEDCouplingFieldDiscretization *)_type))
1694 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform applyFunc !");
1695 int nbOfTuple=_type->getNumberOfTuples(_mesh);
1696 _time_discr->setUniformValue(nbOfTuple,nbOfComp,val);
1700 * Modifies values of \a this field by applying a function to each tuple of all
1702 * For more info on supported expressions that can be used in the function, see \ref
1703 * MEDCouplingArrayApplyFuncExpr. <br>
1704 * The function can include arbitrary named variables
1705 * (e.g. "x","y" or "va44") to refer to components of a field value. Names of
1706 * variables are sorted in \b alphabetical \b order to associate a variable name with a
1707 * component. For example, in the expression "2*x+z", "x" stands for the component #0
1708 * and "z" stands for the component #1 (\b not #2)!<br>
1709 * In a general case, a value resulting from the function evaluation is assigned to all
1710 * components of a field value. But there is a possibility to have its own expression for
1711 * each component within one function. For this purpose, there are predefined variable
1712 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1713 * the component #0 etc). A factor of such a variable is added to the
1714 * corresponding component only.<br>
1715 * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1716 * - "2*x + z" produces (5.,5.,5.,5.)
1717 * - "2*x + 0*y + z" produces (9.,9.,9.,9.)
1718 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1719 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1721 * \param [in] nbOfComp - the number of components for \a this field to have.
1722 * \param [in] func - the function used to compute values of \a this field.
1723 * This function is to compute a field value basing on a current field value.
1724 * \throw If computing \a func fails.
1726 * \if ENABLE_EXAMPLES
1727 * \ref cpp_mcfielddouble_applyFunc "Here is a C++ example".<br>
1728 * \ref py_mcfielddouble_applyFunc "Here is a Python example".
1731 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func)
1733 _time_discr->applyFunc(nbOfComp,func);
1738 * Modifies values of \a this field by applying a function to each tuple of all
1740 * For more info on supported expressions that can be used in the function, see \ref
1741 * MEDCouplingArrayApplyFuncExpr. <br>
1742 * This method differs from
1743 * \ref MEDCoupling::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) "applyFunc()"
1744 * by the way how variable
1745 * names, used in the function, are associated with components of field values;
1746 * here, a variable name corresponding to a component is retrieved from
1747 * component information of an array (where it is set via
1748 * DataArrayDouble::setInfoOnComponent()).<br>
1749 * In a general case, a value resulting from the function evaluation is assigned to all
1750 * components of a field value. But there is a possibility to have its own expression for
1751 * each component within one function. For this purpose, there are predefined variable
1752 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1753 * the component #0 etc). A factor of such a variable is added to the
1754 * corresponding component only.<br>
1755 * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1756 * - "2*x + z" produces (5.,5.,5.,5.)
1757 * - "2*x + 0*y + z" produces (9.,9.,9.,9.)
1758 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1759 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1761 * \param [in] nbOfComp - the number of components for \a this field to have.
1762 * \param [in] func - the function used to compute values of \a this field.
1763 * This function is to compute a new field value basing on a current field value.
1764 * \throw If computing \a func fails.
1766 * \if ENABLE_EXAMPLES
1767 * \ref cpp_mcfielddouble_applyFunc2 "Here is a C++ example".<br>
1768 * \ref py_mcfielddouble_applyFunc2 "Here is a Python example".
1771 void MEDCouplingFieldDouble::applyFuncCompo(int nbOfComp, const std::string& func)
1773 _time_discr->applyFuncCompo(nbOfComp,func);
1777 * Modifies values of \a this field by applying a function to each tuple of all
1779 * This method differs from
1780 * \ref MEDCoupling::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) "applyFunc()"
1781 * by the way how variable
1782 * names, used in the function, are associated with components of field values;
1783 * here, a component index of a variable is defined by a
1784 * rank of the variable within the input array \a varsOrder.<br>
1785 * For more info on supported expressions that can be used in the function, see \ref
1786 * MEDCouplingArrayApplyFuncExpr.
1787 * In a general case, a value resulting from the function evaluation is assigned to all
1788 * components of a field value. But there is a possibility to have its own expression for
1789 * each component within one function. For this purpose, there are predefined variable
1790 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1791 * the component #0 etc). A factor of such a variable is added to the
1792 * corresponding component only.<br>
1793 * For example, \a nbOfComp == 4, names of
1794 * components are given in \a varsOrder: ["x", "y","z"], components of a
1795 * 3D vector are (1.,3.,7.), then
1796 * - "2*x + z" produces (9.,9.,9.,9.)
1797 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1798 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1800 * \param [in] nbOfComp - the number of components for \a this field to have.
1801 * \param [in] func - the function used to compute values of \a this field.
1802 * This function is to compute a new field value basing on a current field value.
1803 * \throw If computing \a func fails.
1805 * \if ENABLE_EXAMPLES
1806 * \ref cpp_mcfielddouble_applyFunc3 "Here is a C++ example".<br>
1807 * \ref py_mcfielddouble_applyFunc3 "Here is a Python example".
1810 void MEDCouplingFieldDouble::applyFuncNamedCompo(int nbOfComp, const std::vector<std::string>& varsOrder, const std::string& func)
1812 _time_discr->applyFuncNamedCompo(nbOfComp,varsOrder,func);
1816 * Modifies values of \a this field by applying a function to each atomic value of all
1817 * data arrays. The function computes a new single value basing on an old single value.
1818 * For more info on supported expressions that can be used in the function, see \ref
1819 * MEDCouplingArrayApplyFuncExpr. <br>
1820 * The function can include **only one** arbitrary named variable
1821 * (e.g. "x","y" or "va44") to refer to a field atomic value. <br>
1822 * In a general case, a value resulting from the function evaluation is assigned to
1823 * a single field value. But there is a possibility to have its own expression for
1824 * each component within one function. For this purpose, there are predefined variable
1825 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1826 * the component #0 etc). A factor of such a variable is added to the
1827 * corresponding component only.<br>
1828 * For example, components of a field value are (1.,3.,7.), then
1829 * - "2*x - 1" produces (1.,5.,13.)
1830 * - "2*x*IVec + (x+3)*KVec" produces (2.,0.,10.)
1831 * - "2*x*IVec + (x+3)*KVec + 1" produces (3.,1.,11.)
1833 * \param [in] func - the function used to compute values of \a this field.
1834 * This function is to compute a field value basing on a current field value.
1835 * \throw If computing \a func fails.
1837 * \if ENABLE_EXAMPLES
1838 * \ref cpp_mcfielddouble_applyFunc_same_nb_comp "Here is a C++ example".<br>
1839 * \ref py_mcfielddouble_applyFunc_same_nb_comp "Here is a Python example".
1842 void MEDCouplingFieldDouble::applyFunc(const std::string& func)
1844 _time_discr->applyFunc(func);
1848 * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1849 * The field will contain exactly the same number of components after the call.
1850 * Use is not warranted for the moment !
1852 void MEDCouplingFieldDouble::applyFuncFast32(const std::string& func)
1854 _time_discr->applyFuncFast32(func);
1858 * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1859 * The field will contain exactly the same number of components after the call.
1860 * Use is not warranted for the moment !
1862 void MEDCouplingFieldDouble::applyFuncFast64(const std::string& func)
1864 _time_discr->applyFuncFast64(func);
1868 * Returns number of components in the data array. For more info on the data arrays,
1870 * \return int - the number of components in the data array.
1871 * \throw If the data array is not set.
1873 int MEDCouplingFieldDouble::getNumberOfComponents() const
1876 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfComponents : No array specified !");
1877 return getArray()->getNumberOfComponents();
1881 * Use MEDCouplingField::getNumberOfTuplesExpected instead of this method. This method will be removed soon, because it is
1882 * confusing compared to getNumberOfComponents() and getNumberOfValues() behaviour.
1884 * Returns number of tuples in \a this field, that depends on
1885 * - the number of entities in the underlying mesh
1886 * - \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field (e.g. number
1887 * of Gauss points if \a this->getTypeOfField() ==
1888 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT").
1890 * The returned value does \b not \b depend on the number of tuples in the data array
1891 * (which has to be equal to the returned value), \b contrary to
1892 * getNumberOfComponents() and getNumberOfValues() that retrieve information from the
1893 * data array (Sorry, it is confusing !).
1894 * So \b this \b method \b behaves \b exactly \b as MEDCouplingField::getNumberOfTuplesExpected \b method.
1896 * \warning No checkConsistencyLight() is done here.
1897 * For more info on the data arrays, see \ref arrays.
1898 * \return int - the number of tuples.
1899 * \throw If the mesh is not set.
1900 * \throw If the spatial discretization of \a this field is NULL.
1901 * \throw If the spatial discretization is not fully defined.
1902 * \sa MEDCouplingField::getNumberOfTuplesExpected
1904 int MEDCouplingFieldDouble::getNumberOfTuples() const
1906 //std::cerr << " ******* MEDCouplingFieldDouble::getNumberOfTuples is deprecated : use MEDCouplingField::getNumberOfTuplesExpected instead ! ******" << std::endl;
1908 throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !");
1909 if(!((const MEDCouplingFieldDiscretization *)_type))
1910 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getNumberOfTuples !");
1911 return _type->getNumberOfTuples(_mesh);
1915 * Returns number of atomic double values in the data array of \a this field.
1916 * For more info on the data arrays, see \ref arrays.
1917 * \return int - (number of tuples) * (number of components) of the
1919 * \throw If the data array is not set.
1921 int MEDCouplingFieldDouble::getNumberOfValues() const
1924 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfValues : No array specified !");
1925 return getArray()->getNbOfElems();
1929 * Sets own modification time by the most recently modified element of data (the mesh,
1930 * the data array etc). For more info, see \ref MEDCouplingTimeLabelPage.
1932 void MEDCouplingFieldDouble::updateTime() const
1934 MEDCouplingField::updateTime();
1935 updateTimeWith(*_time_discr);
1938 std::size_t MEDCouplingFieldDouble::getHeapMemorySizeWithoutChildren() const
1940 return MEDCouplingField::getHeapMemorySizeWithoutChildren();
1943 std::vector<const BigMemoryObject *> MEDCouplingFieldDouble::getDirectChildrenWithNull() const
1945 std::vector<const BigMemoryObject *> ret(MEDCouplingField::getDirectChildrenWithNull());
1948 std::vector<const BigMemoryObject *> ret2(_time_discr->getDirectChildrenWithNull());
1949 ret.insert(ret.end(),ret2.begin(),ret2.end());
1955 * Sets \ref NatureOfField.
1956 * \param [in] nat - an item of enum MEDCoupling::NatureOfField.
1958 void MEDCouplingFieldDouble::setNature(NatureOfField nat)
1960 MEDCouplingField::setNature(nat);
1962 _type->checkCompatibilityWithNature(nat);
1966 * This method synchronizes time information (time, iteration, order, time unit) regarding the information in \c this->_mesh.
1967 * \throw If no mesh is set in this. Or if \a this is not compatible with time setting (typically NO_TIME)
1969 void MEDCouplingFieldDouble::synchronizeTimeWithMesh()
1972 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::synchronizeTimeWithMesh : no mesh set in this !");
1974 double val=_mesh->getTime(it,ordr);
1975 std::string timeUnit(_mesh->getTimeUnit());
1976 setTime(val,it,ordr);
1977 setTimeUnit(timeUnit);
1981 * Returns a value of \a this field of type either
1982 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" or
1983 * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
1984 * \param [in] cellId - an id of cell of interest.
1985 * \param [in] nodeIdInCell - a node index within the cell.
1986 * \param [in] compoId - an index of component.
1987 * \return double - the field value corresponding to the specified parameters.
1988 * \throw If the data array is not set.
1989 * \throw If the mesh is not set.
1990 * \throw If the spatial discretization of \a this field is NULL.
1991 * \throw If \a this field if of type other than
1992 * \ref MEDCoupling::ON_GAUSS_PT "ON_GAUSS_PT" or
1993 * \ref MEDCoupling::ON_GAUSS_NE "ON_GAUSS_NE".
1995 double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) const
1997 if(!((const MEDCouplingFieldDiscretization *)_type))
1998 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getIJK !");
1999 return _type->getIJK(_mesh,getArray(),cellId,nodeIdInCell,compoId);
2003 * Sets the data array.
2004 * \param [in] array - the data array holding values of \a this field. It's size
2005 * should correspond to the mesh and
2006 * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
2007 * (see getNumberOfTuples()), but this size is not checked here.
2009 void MEDCouplingFieldDouble::setArray(DataArrayDouble *array)
2011 _time_discr->setArray(array,this);
2015 * Sets the data array holding values corresponding to an end of a time interval
2016 * for which \a this field is defined.
2017 * \param [in] array - the data array holding values of \a this field. It's size
2018 * should correspond to the mesh and
2019 * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
2020 * (see getNumberOfTuples()), but this size is not checked here.
2022 void MEDCouplingFieldDouble::setEndArray(DataArrayDouble *array)
2024 _time_discr->setEndArray(array,this);
2028 * Sets all data arrays needed to define the field values.
2029 * \param [in] arrs - a vector of DataArrayDouble's holding values of \a this
2030 * field. Size of each array should correspond to the mesh and
2031 * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
2032 * (see getNumberOfTuples()), but this size is not checked here.
2033 * \throw If number of arrays in \a arrs does not correspond to type of
2034 * \ref MEDCouplingTemporalDisc "temporal discretization" of \a this field.
2036 void MEDCouplingFieldDouble::setArrays(const std::vector<DataArrayDouble *>& arrs)
2038 _time_discr->setArrays(arrs,this);
2041 void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
2044 _time_discr->getTinySerializationStrInformation(tinyInfo);
2045 tinyInfo.push_back(_name);
2046 tinyInfo.push_back(_desc);
2047 tinyInfo.push_back(getTimeUnit());
2051 * This method retrieves some critical values to resize and prepare remote instance.
2052 * The first two elements returned in tinyInfo correspond to the parameters to give in constructor.
2053 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
2055 void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
2057 if(!((const MEDCouplingFieldDiscretization *)_type))
2058 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
2060 tinyInfo.push_back((int)_type->getEnum());
2061 tinyInfo.push_back((int)_time_discr->getEnum());
2062 tinyInfo.push_back((int)_nature);
2063 _time_discr->getTinySerializationIntInformation(tinyInfo);
2064 std::vector<int> tinyInfo2;
2065 _type->getTinySerializationIntInformation(tinyInfo2);
2066 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
2067 tinyInfo.push_back((int)tinyInfo2.size());
2071 * This method retrieves some critical values to resize and prepare remote instance.
2072 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
2074 void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
2076 if(!((const MEDCouplingFieldDiscretization *)_type))
2077 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
2079 _time_discr->getTinySerializationDbleInformation(tinyInfo);
2080 std::vector<double> tinyInfo2;
2081 _type->getTinySerializationDbleInformation(tinyInfo2);
2082 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
2083 tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it
2087 * This method has to be called to the new instance filled by CORBA, MPI, File...
2088 * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied.
2089 * @param dataInt out parameter. If not null the pointer is already owned by \a this after the call of this method. In this case no decrRef must be applied.
2090 * @param arrays out parameter is a vector resized to the right size. The pointers in the vector is already owned by \a this after the call of this method.
2091 * No decrRef must be applied to every instances in returned vector.
2092 * \sa checkForUnserialization
2094 void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays)
2096 if(!((const MEDCouplingFieldDiscretization *)_type))
2097 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
2099 std::vector<int> tinyInfoITmp(tinyInfoI);
2100 int sz=tinyInfoITmp.back();
2101 tinyInfoITmp.pop_back();
2102 std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
2103 std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
2104 _time_discr->resizeForUnserialization(tinyInfoI2,arrays);
2105 std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
2106 _type->resizeForUnserialization(tinyInfoITmp3,dataInt);
2110 * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this
2111 * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data.
2112 * \sa resizeForUnserialization
2114 void MEDCouplingFieldDouble::checkForUnserialization(const std::vector<int>& tinyInfoI, const DataArrayInt *dataInt, const std::vector<DataArrayDouble *>& arrays)
2116 if(!((const MEDCouplingFieldDiscretization *)_type))
2117 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
2118 std::vector<int> tinyInfoITmp(tinyInfoI);
2119 int sz=tinyInfoITmp.back();
2120 tinyInfoITmp.pop_back();
2121 std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
2122 std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
2123 _time_discr->checkForUnserialization(tinyInfoI2,arrays);
2124 std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
2125 _type->checkForUnserialization(tinyInfoITmp3,dataInt);
2128 void MEDCouplingFieldDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
2130 if(!((const MEDCouplingFieldDiscretization *)_type))
2131 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
2132 std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
2134 std::vector<double> tmp(tinyInfoD);
2135 int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it
2137 std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
2138 std::vector<double> tmp2(tmp.end()-sz,tmp.end());
2140 _time_discr->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
2141 _nature=(NatureOfField)tinyInfoI[2];
2142 _type->finishUnserialization(tmp2);
2143 int nbOfElemS=(int)tinyInfoS.size();
2144 _name=tinyInfoS[nbOfElemS-3];
2145 _desc=tinyInfoS[nbOfElemS-2];
2146 setTimeUnit(tinyInfoS[nbOfElemS-1]);
2150 * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller.
2151 * The values returned must be consulted only in readonly mode.
2153 void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays) const
2155 if(!((const MEDCouplingFieldDiscretization *)_type))
2156 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");
2157 _time_discr->getArrays(arrays);
2158 _type->getSerializationIntArray(dataInt);
2162 * Tries to set an \a other mesh as the support of \a this field. An attempt fails, if
2163 * a current and the \a other meshes are different with use of specified equality
2164 * criteria, and then an exception is thrown.
2165 * \param [in] other - the mesh to use as the field support if this mesh can be
2166 * considered equal to the current mesh.
2167 * \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
2168 * it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
2169 * is used for mesh comparison.
2170 * \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
2171 * It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
2172 * \param [in] eps - a precision used at node renumbering (if needed) to compare field
2173 * values at merged nodes. If the values differ more than \a eps, an
2174 * exception is thrown.
2175 * \throw If the mesh is not set.
2176 * \throw If \a other == NULL.
2177 * \throw If any of the meshes is not well defined.
2178 * \throw If the two meshes do not match.
2179 * \throw If field values at merged nodes (if any) deffer more than \a eps.
2181 * \if ENABLE_EXAMPLES
2182 * \ref cpp_mcfielddouble_changeUnderlyingMesh "Here is a C++ example".<br>
2183 * \ref py_mcfielddouble_changeUnderlyingMesh "Here is a Python example".
2186 void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps)
2188 if(_mesh==0 || other==0)
2189 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::changeUnderlyingMesh : is expected to operate on not null meshes !");
2190 DataArrayInt *cellCor=0,*nodeCor=0;
2191 other->checkGeoEquivalWith(_mesh,levOfCheck,precOnMesh,cellCor,nodeCor);
2192 MCAuto<DataArrayInt> cellCor2(cellCor),nodeCor2(nodeCor);
2194 renumberCellsWithoutMesh(cellCor->getConstPointer(),false);
2196 renumberNodesWithoutMesh(nodeCor->getConstPointer(),nodeCor->getMaxValueInArray()+1,eps);
2201 * Subtracts another field from \a this one in case when the two fields have different
2202 * supporting meshes. The subtraction is performed provided that the tho meshes can be
2203 * considered equal with use of specified equality criteria, else an exception is thrown.
2204 * If the meshes match, the mesh of \a f is set to \a this field (\a this is permuted if
2205 * necessary) and field values are subtracted. No interpolation is done here, only an
2206 * analysis of two underlying mesh is done to see if the meshes are geometrically
2208 * The job of this method consists in calling
2209 * \a this->changeUnderlyingMesh() with \a f->getMesh() as the first parameter, and then
2210 * \a this -= \a f.<br>
2211 * This method requires that \a f and \a this are coherent (checkConsistencyLight()) and that \a f
2212 * and \a this are coherent for a merge.<br>
2213 * "DM" in the method name stands for "different meshes".
2214 * \param [in] f - the field to subtract from this.
2215 * \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
2216 * it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
2217 * is used for mesh comparison.
2218 * \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
2219 * It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
2220 * \param [in] eps - a precision used at node renumbering (if needed) to compare field
2221 * values at merged nodes. If the values differ more than \a eps, an
2222 * exception is thrown.
2223 * \throw If \a f == NULL.
2224 * \throw If any of the meshes is not set or is not well defined.
2225 * \throw If the two meshes do not match.
2226 * \throw If the two fields are not coherent for merge.
2227 * \throw If field values at merged nodes (if any) deffer more than \a eps.
2229 * \if ENABLE_EXAMPLES
2230 * \ref cpp_mcfielddouble_substractInPlaceDM "Here is a C++ example".<br>
2231 * \ref py_mcfielddouble_substractInPlaceDM "Here is a Python example".
2233 * \sa changeUnderlyingMesh().
2235 void MEDCouplingFieldDouble::substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps)
2237 checkConsistencyLight();
2239 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : input field is NULL !");
2240 f->checkConsistencyLight();
2241 if(!areCompatibleForMerge(f))
2242 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : Fields are not compatible ; unable to apply mergeFields on them !");
2243 changeUnderlyingMesh(f->getMesh(),levOfCheck,precOnMesh,eps);
2248 * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2249 * underlying mesh is replaced by a new mesh instance where the coincident nodes are merged.
2250 * \param [in] eps - a precision used to compare nodes of the two meshes.
2251 * \param [in] epsOnVals - a precision used to compare field
2252 * values at merged nodes. If the values differ more than \a epsOnVals, an
2253 * exception is thrown.
2254 * \return bool - \c true if some nodes have been merged and hence \a this field lies
2256 * \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2257 * \throw If the mesh is not well defined.
2258 * \throw If the spatial discretization of \a this field is NULL.
2259 * \throw If the data array is not set.
2260 * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2262 bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals)
2264 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2266 throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2267 if(!((const MEDCouplingFieldDiscretization *)_type))
2268 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes !");
2269 MCAuto<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCopy());
2272 MCAuto<DataArrayInt> arr=meshC2->mergeNodes(eps,ret,ret2);
2273 if(!ret)//no nodes have been merged.
2275 std::vector<DataArrayDouble *> arrays;
2276 _time_discr->getArrays(arrays);
2277 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2279 _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2285 * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2286 * underlying mesh is replaced by a new mesh instance where the coincident nodes are
2288 * In contrast to mergeNodes(), location of merged nodes is changed to be at their barycenter.
2289 * \param [in] eps - a precision used to compare nodes of the two meshes.
2290 * \param [in] epsOnVals - a precision used to compare field
2291 * values at merged nodes. If the values differ more than \a epsOnVals, an
2292 * exception is thrown.
2293 * \return bool - \c true if some nodes have been merged and hence \a this field lies
2295 * \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2296 * \throw If the mesh is not well defined.
2297 * \throw If the spatial discretization of \a this field is NULL.
2298 * \throw If the data array is not set.
2299 * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2301 bool MEDCouplingFieldDouble::mergeNodesCenter(double eps, double epsOnVals)
2303 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2305 throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2306 if(!((const MEDCouplingFieldDiscretization *)_type))
2307 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodesCenter !");
2308 MCAuto<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCopy());
2311 MCAuto<DataArrayInt> arr=meshC2->mergeNodesCenter(eps,ret,ret2);
2312 if(!ret)//no nodes have been merged.
2314 std::vector<DataArrayDouble *> arrays;
2315 _time_discr->getArrays(arrays);
2316 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2318 _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2324 * Removes from the underlying mesh nodes not used in any cell. If some nodes are
2325 * removed, the underlying mesh is replaced by a new mesh instance where the unused
2326 * nodes are removed.<br>
2327 * \param [in] epsOnVals - a precision used to compare field
2328 * values at merged nodes. If the values differ more than \a epsOnVals, an
2329 * exception is thrown.
2330 * \return bool - \c true if some nodes have been removed and hence \a this field lies
2332 * \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2333 * \throw If the mesh is not well defined.
2334 * \throw If the spatial discretization of \a this field is NULL.
2335 * \throw If the data array is not set.
2336 * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2338 bool MEDCouplingFieldDouble::zipCoords(double epsOnVals)
2340 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2342 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2343 if(!((const MEDCouplingFieldDiscretization *)_type))
2344 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipCoords !");
2345 MCAuto<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCopy());
2346 int oldNbOfNodes=meshC2->getNumberOfNodes();
2347 MCAuto<DataArrayInt> arr=meshC2->zipCoordsTraducer();
2348 if(meshC2->getNumberOfNodes()!=oldNbOfNodes)
2350 std::vector<DataArrayDouble *> arrays;
2351 _time_discr->getArrays(arrays);
2352 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2354 _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2362 * Removes duplicates of cells from the understanding mesh. If some cells are
2363 * removed, the underlying mesh is replaced by a new mesh instance where the cells
2364 * duplicates are removed.<br>
2365 * \param [in] compType - specifies a cell comparison technique. Meaning of its
2366 * valid values [0,1,2] is explained in the description of
2367 * MEDCouplingPointSet::zipConnectivityTraducer() which is called by this method.
2368 * \param [in] epsOnVals - a precision used to compare field
2369 * values at merged cells. If the values differ more than \a epsOnVals, an
2370 * exception is thrown.
2371 * \return bool - \c true if some cells have been removed and hence \a this field lies
2373 * \throw If the mesh is not an instance of MEDCouplingUMesh.
2374 * \throw If the mesh is not well defined.
2375 * \throw If the spatial discretization of \a this field is NULL.
2376 * \throw If the data array is not set.
2377 * \throw If field values at merged cells (if any) deffer more than \a epsOnVals.
2379 bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals)
2381 const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(_mesh);
2383 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipConnectivity : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2384 if(!((const MEDCouplingFieldDiscretization *)_type))
2385 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipConnectivity !");
2386 MCAuto<MEDCouplingUMesh> meshC2((MEDCouplingUMesh *)meshC->deepCopy());
2387 int oldNbOfCells=meshC2->getNumberOfCells();
2388 MCAuto<DataArrayInt> arr=meshC2->zipConnectivityTraducer(compType);
2389 if(meshC2->getNumberOfCells()!=oldNbOfCells)
2391 std::vector<DataArrayDouble *> arrays;
2392 _time_discr->getArrays(arrays);
2393 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2395 _type->renumberValuesOnCells(epsOnVals,meshC,arr->getConstPointer(),meshC2->getNumberOfCells(),*iter);
2403 * This method calls MEDCouplingUMesh::buildSlice3D method. So this method makes the assumption that underlying mesh exists.
2404 * For the moment, this method is implemented for fields on cells.
2406 * \return a newly allocated field double containing the result that the user should deallocate.
2408 MEDCouplingFieldDouble *MEDCouplingFieldDouble::extractSlice3D(const double *origin, const double *vec, double eps) const
2410 const MEDCouplingMesh *mesh=getMesh();
2412 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : underlying mesh is null !");
2413 if(getTypeOfField()!=ON_CELLS)
2414 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : only implemented for fields on cells !");
2415 const MCAuto<MEDCouplingUMesh> umesh(mesh->buildUnstructured());
2416 MCAuto<MEDCouplingFieldDouble> ret=clone(false);
2417 ret->setMesh(umesh);
2418 DataArrayInt *cellIds=0;
2419 MCAuto<MEDCouplingUMesh> mesh2=umesh->buildSlice3D(origin,vec,eps,cellIds);
2420 MCAuto<DataArrayInt> cellIds2=cellIds;
2421 ret->setMesh(mesh2);
2422 MCAuto<DataArrayInt> tupleIds=computeTupleIdsToSelectFromCellIds(cellIds->begin(),cellIds->end());
2423 std::vector<DataArrayDouble *> arrays;
2424 _time_discr->getArrays(arrays);
2426 std::vector<DataArrayDouble *> newArr(arrays.size());
2427 std::vector< MCAuto<DataArrayDouble> > newArr2(arrays.size());
2428 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,i++)
2432 newArr2[i]=(*iter)->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
2433 newArr[i]=newArr2[i];
2436 ret->setArrays(newArr);
2441 * Divides every cell of the underlying mesh into simplices (triangles in 2D and
2442 * tetrahedra in 3D). If some cells are divided, the underlying mesh is replaced by a new
2443 * mesh instance containing the simplices.<br>
2444 * \param [in] policy - specifies a pattern used for splitting. For its description, see
2445 * MEDCouplingUMesh::simplexize().
2446 * \return bool - \c true if some cells have been divided and hence \a this field lies
2448 * \throw If \a policy has an invalid value. For valid values, see the description of
2449 * MEDCouplingUMesh::simplexize().
2450 * \throw If MEDCouplingMesh::simplexize() is not applicable to the underlying mesh.
2451 * \throw If the mesh is not well defined.
2452 * \throw If the spatial discretization of \a this field is NULL.
2453 * \throw If the data array is not set.
2455 bool MEDCouplingFieldDouble::simplexize(int policy)
2458 throw INTERP_KERNEL::Exception("No underlying mesh on this field to perform simplexize !");
2459 if(!((const MEDCouplingFieldDiscretization *)_type))
2460 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform simplexize !");
2461 int oldNbOfCells=_mesh->getNumberOfCells();
2462 MCAuto<MEDCouplingMesh> meshC2(_mesh->deepCopy());
2463 MCAuto<DataArrayInt> arr=meshC2->simplexize(policy);
2464 int newNbOfCells=meshC2->getNumberOfCells();
2465 if(oldNbOfCells==newNbOfCells)
2467 std::vector<DataArrayDouble *> arrays;
2468 _time_discr->getArrays(arrays);
2469 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2471 _type->renumberValuesOnCellsR(_mesh,arr->getConstPointer(),arr->getNbOfElems(),*iter);
2477 * Creates a new MEDCouplingFieldDouble filled with the doubly contracted product of
2478 * every tensor of \a this 6-componental field.
2479 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2480 * each tuple is calculated from the tuple <em>(t)</em> of \a this field as
2481 * follows: \f$ t[0]^2+t[1]^2+t[2]^2+2*t[3]^2+2*t[4]^2+2*t[5]^2\f$.
2482 * This new field lies on the same mesh as \a this one. The caller is to delete
2483 * this field using decrRef() as it is no more needed.
2484 * \throw If \a this->getNumberOfComponents() != 6.
2485 * \throw If the spatial discretization of \a this field is NULL.
2487 MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const
2489 if(!((const MEDCouplingFieldDiscretization *)_type))
2490 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform doublyContractedProduct !");
2491 MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct();
2492 td->copyTinyAttrFrom(*_time_discr);
2493 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2494 ret->setName("DoublyContractedProduct");
2495 ret->setMesh(getMesh());
2500 * Creates a new MEDCouplingFieldDouble filled with the determinant of a square
2501 * matrix defined by every tuple of \a this field, having either 4, 6 or 9 components.
2502 * The case of 6 components corresponds to that of the upper triangular matrix.
2503 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2504 * each tuple is the determinant of matrix of the corresponding tuple of \a this
2505 * field. This new field lies on the same mesh as \a this one. The caller is to
2506 * delete this field using decrRef() as it is no more needed.
2507 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2508 * \throw If the spatial discretization of \a this field is NULL.
2510 MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const
2512 if(!((const MEDCouplingFieldDiscretization *)_type))
2513 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform determinant !");
2514 MEDCouplingTimeDiscretization *td=_time_discr->determinant();
2515 td->copyTinyAttrFrom(*_time_discr);
2516 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2517 ret->setName("Determinant");
2518 ret->setMesh(getMesh());
2524 * Creates a new MEDCouplingFieldDouble with 3 components filled with 3 eigenvalues of
2525 * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2526 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2527 * having 3 components, whose each tuple contains the eigenvalues of the matrix of
2528 * corresponding tuple of \a this field. This new field lies on the same mesh as
2529 * \a this one. The caller is to delete this field using decrRef() as it is no
2531 * \throw If \a this->getNumberOfComponents() != 6.
2532 * \throw If the spatial discretization of \a this field is NULL.
2534 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const
2536 if(!((const MEDCouplingFieldDiscretization *)_type))
2537 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenValues !");
2538 MEDCouplingTimeDiscretization *td=_time_discr->eigenValues();
2539 td->copyTinyAttrFrom(*_time_discr);
2540 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2541 ret->setName("EigenValues");
2542 ret->setMesh(getMesh());
2547 * Creates a new MEDCouplingFieldDouble with 9 components filled with 3 eigenvectors of
2548 * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2549 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2550 * having 9 components, whose each tuple contains the eigenvectors of the matrix of
2551 * corresponding tuple of \a this field. This new field lies on the same mesh as
2552 * \a this one. The caller is to delete this field using decrRef() as it is no
2554 * \throw If \a this->getNumberOfComponents() != 6.
2555 * \throw If the spatial discretization of \a this field is NULL.
2557 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const
2559 if(!((const MEDCouplingFieldDiscretization *)_type))
2560 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenVectors !");
2561 MEDCouplingTimeDiscretization *td=_time_discr->eigenVectors();
2562 td->copyTinyAttrFrom(*_time_discr);
2563 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2564 ret->setName("EigenVectors");
2565 ret->setMesh(getMesh());
2570 * Creates a new MEDCouplingFieldDouble filled with the inverse matrix of
2571 * a matrix defined by every tuple of \a this field having either 4, 6 or 9
2572 * components. The case of 6 components corresponds to that of the upper triangular
2574 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2575 * having the same number of components as \a this one, whose each tuple
2576 * contains the inverse matrix of the matrix of corresponding tuple of \a this
2577 * field. This new field lies on the same mesh as \a this one. The caller is to
2578 * delete this field using decrRef() as it is no more needed.
2579 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2580 * \throw If the spatial discretization of \a this field is NULL.
2582 MEDCouplingFieldDouble *MEDCouplingFieldDouble::inverse() const
2584 if(!((const MEDCouplingFieldDiscretization *)_type))
2585 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform inverse !");
2586 MEDCouplingTimeDiscretization *td=_time_discr->inverse();
2587 td->copyTinyAttrFrom(*_time_discr);
2588 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2589 ret->setName("Inversion");
2590 ret->setMesh(getMesh());
2595 * Creates a new MEDCouplingFieldDouble filled with the trace of
2596 * a matrix defined by every tuple of \a this field having either 4, 6 or 9
2597 * components. The case of 6 components corresponds to that of the upper triangular
2599 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2600 * having 1 component, whose each tuple is the trace of the matrix of
2601 * corresponding tuple of \a this field.
2602 * This new field lies on the same mesh as \a this one. The caller is to
2603 * delete this field using decrRef() as it is no more needed.
2604 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2605 * \throw If the spatial discretization of \a this field is NULL.
2607 MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const
2609 if(!((const MEDCouplingFieldDiscretization *)_type))
2610 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform trace !");
2611 MEDCouplingTimeDiscretization *td=_time_discr->trace();
2612 td->copyTinyAttrFrom(*_time_discr);
2613 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2614 ret->setName("Trace");
2615 ret->setMesh(getMesh());
2620 * Creates a new MEDCouplingFieldDouble filled with the stress deviator tensor of
2621 * a stress tensor defined by every tuple of \a this 6-componental field.
2622 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2623 * having same number of components and tuples as \a this field,
2624 * whose each tuple contains the stress deviator tensor of the stress tensor of
2625 * corresponding tuple of \a this field. This new field lies on the same mesh as
2626 * \a this one. The caller is to delete this field using decrRef() as it is no
2628 * \throw If \a this->getNumberOfComponents() != 6.
2629 * \throw If the spatial discretization of \a this field is NULL.
2631 MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const
2633 if(!((const MEDCouplingFieldDiscretization *)_type))
2634 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform deviator !");
2635 MEDCouplingTimeDiscretization *td=_time_discr->deviator();
2636 td->copyTinyAttrFrom(*_time_discr);
2637 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2638 ret->setName("Deviator");
2639 ret->setMesh(getMesh());
2644 * Creates a new MEDCouplingFieldDouble filled with the magnitude of
2645 * every vector of \a this field.
2646 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2647 * having one component, whose each tuple is the magnitude of the vector
2648 * of corresponding tuple of \a this field. This new field lies on the
2649 * same mesh as \a this one. The caller is to
2650 * delete this field using decrRef() as it is no more needed.
2651 * \throw If the spatial discretization of \a this field is NULL.
2653 MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const
2655 if(!((const MEDCouplingFieldDiscretization *)_type))
2656 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform magnitude !");
2657 MEDCouplingTimeDiscretization *td=_time_discr->magnitude();
2658 td->copyTinyAttrFrom(*_time_discr);
2659 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2660 ret->setName("Magnitude");
2661 ret->setMesh(getMesh());
2666 * Creates a new scalar MEDCouplingFieldDouble filled with the maximal value among
2667 * values of every tuple of \a this field.
2668 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2669 * This new field lies on the same mesh as \a this one. The caller is to
2670 * delete this field using decrRef() as it is no more needed.
2671 * \throw If the spatial discretization of \a this field is NULL.
2673 MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const
2675 if(!((const MEDCouplingFieldDiscretization *)_type))
2676 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform maxPerTuple !");
2677 MEDCouplingTimeDiscretization *td=_time_discr->maxPerTuple();
2678 td->copyTinyAttrFrom(*_time_discr);
2679 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2680 std::ostringstream oss;
2681 oss << "Max_" << getName();
2682 ret->setName(oss.str());
2683 ret->setMesh(getMesh());
2688 * Changes number of components in \a this field. If \a newNbOfComp is less
2689 * than \a this->getNumberOfComponents() then each tuple
2690 * is truncated to have \a newNbOfComp components, keeping first components. If \a
2691 * newNbOfComp is more than \a this->getNumberOfComponents() then
2692 * each tuple is populated with \a dftValue to have \a newNbOfComp components.
2693 * \param [in] newNbOfComp - number of components for the new field to have.
2694 * \param [in] dftValue - value assigned to new values added to \a this field.
2695 * \throw If \a this is not allocated.
2697 void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftValue)
2699 _time_discr->changeNbOfComponents(newNbOfComp,dftValue);
2703 * Creates a new MEDCouplingFieldDouble composed of selected components of \a this field.
2704 * The new MEDCouplingFieldDouble has the same number of tuples but includes components
2705 * specified by \a compoIds parameter. So that getNbOfElems() of the result field
2706 * can be either less, same or more than \a this->getNumberOfValues().
2707 * \param [in] compoIds - sequence of zero based indices of components to include
2708 * into the new field.
2709 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble that the caller
2710 * is to delete using decrRef() as it is no more needed.
2711 * \throw If a component index (\a i) is not valid:
2712 * \a i < 0 || \a i >= \a this->getNumberOfComponents().
2714 MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std::vector<int>& compoIds) const
2716 if(!((const MEDCouplingFieldDiscretization *)_type))
2717 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform keepSelectedComponents !");
2718 MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds);
2719 td->copyTinyAttrFrom(*_time_discr);
2720 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2721 ret->setName(getName());
2722 ret->setMesh(getMesh());
2728 * Copy all components in a specified order from another field.
2729 * The number of tuples in \a this and the other field can be different.
2730 * \param [in] f - the field to copy data from.
2731 * \param [in] compoIds - sequence of zero based indices of components, data of which is
2733 * \throw If the two fields have different number of data arrays.
2734 * \throw If a data array is set in one of fields and is not set in the other.
2735 * \throw If \a compoIds.size() != \a a->getNumberOfComponents().
2736 * \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
2738 void MEDCouplingFieldDouble::setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector<int>& compoIds)
2740 _time_discr->setSelectedComponents(f->_time_discr,compoIds);
2744 * Sorts value within every tuple of \a this field.
2745 * \param [in] asc - if \a true, the values are sorted in ascending order, else,
2746 * in descending order.
2747 * \throw If a data array is not allocated.
2749 void MEDCouplingFieldDouble::sortPerTuple(bool asc)
2751 _time_discr->sortPerTuple(asc);
2755 * Creates a new MEDCouplingFieldDouble by concatenating two given fields.
2757 * the first field precede values of the second field within the result field.
2758 * \param [in] f1 - the first field.
2759 * \param [in] f2 - the second field.
2760 * \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2761 * MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef()
2762 * as it is no more needed.
2763 * \throw If the fields are not compatible for the merge.
2764 * \throw If the spatial discretization of \a f1 is NULL.
2765 * \throw If the time discretization of \a f1 is NULL.
2767 * \if ENABLE_EXAMPLES
2768 * \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2769 * \ref py_mcfielddouble_MergeFields "Here is a Python example".
2772 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2774 if(!f1->areCompatibleForMerge(f2))
2775 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MergeFields on them ! Check support mesh, field nature, and spatial and time discretisation.");
2776 const MEDCouplingMesh *m1(f1->getMesh()),*m2(f2->getMesh());
2777 if(!f1->_time_discr)
2778 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no time discr of f1 !");
2780 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no spatial discr of f1 !");
2781 MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr);
2782 td->copyTinyAttrFrom(*f1->_time_discr);
2783 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2784 ret->setName(f1->getName());
2785 ret->setDescription(f1->getDescription());
2788 MCAuto<MEDCouplingMesh> m=m1->mergeMyselfWith(m2);
2795 * Creates a new MEDCouplingFieldDouble by concatenating all given fields.
2796 * Values of the *i*-th field precede values of the (*i*+1)-th field within the result.
2797 * If there is only one field in \a a, a deepCopy() (except time information of mesh and
2798 * field) of the field is returned.
2799 * Generally speaking the first field in \a a is used to assign tiny attributes of the
2801 * \param [in] a - a vector of fields (MEDCouplingFieldDouble) to concatenate.
2802 * \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2803 * MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef()
2804 * as it is no more needed.
2805 * \throw If \a a is empty.
2806 * \throw If the fields are not compatible for the merge.
2808 * \if ENABLE_EXAMPLES
2809 * \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2810 * \ref py_mcfielddouble_MergeFields "Here is a Python example".
2813 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector<const MEDCouplingFieldDouble *>& a)
2816 throw INTERP_KERNEL::Exception("FieldDouble::MergeFields : size of array must be >= 1 !");
2817 std::vector< MCAuto<MEDCouplingUMesh> > ms(a.size());
2818 std::vector< const MEDCouplingUMesh *> ms2(a.size());
2819 std::vector< const MEDCouplingTimeDiscretization *> tds(a.size());
2820 std::vector<const MEDCouplingFieldDouble *>::const_iterator it=a.begin();
2821 const MEDCouplingFieldDouble *ref=(*it++);
2823 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : presence of NULL instance in first place of input vector !");
2824 for(;it!=a.end();it++)
2825 if(!ref->areCompatibleForMerge(*it))
2826 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MergeFields on them! Check support mesh, field nature, and spatial and time discretisation.");
2827 for(int i=0;i<(int)a.size();i++)
2830 { ms[i]=a[i]->getMesh()->buildUnstructured(); ms2[i]=ms[i]; }
2832 { ms[i]=0; ms2[i]=0; }
2833 tds[i]=a[i]->_time_discr;
2835 MEDCouplingTimeDiscretization *td=tds[0]->aggregate(tds);
2836 td->copyTinyAttrFrom(*(a[0]->_time_discr));
2837 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone());
2838 ret->setName(a[0]->getName());
2839 ret->setDescription(a[0]->getDescription());
2842 MCAuto<MEDCouplingUMesh> m=MEDCouplingUMesh::MergeUMeshes(ms2);
2843 m->copyTinyInfoFrom(ms2[0]);
2850 * Creates a new MEDCouplingFieldDouble by concatenating components of two given fields.
2851 * The number of components in the result field is a sum of the number of components of
2852 * given fields. The number of tuples in the result field is same as that of each of given
2854 * Number of tuples in the given fields must be the same.
2855 * \param [in] f1 - a field to include in the result field.
2856 * \param [in] f2 - another field to include in the result field.
2857 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2858 * The caller is to delete this result field using decrRef() as it is no more
2860 * \throw If the fields are not compatible for a meld (areCompatibleForMeld()).
2861 * \throw If any of data arrays is not allocated.
2862 * \throw If \a f1->getNumberOfTuples() != \a f2->getNumberOfTuples()
2864 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MeldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2866 if(!f1->areCompatibleForMeld(f2))
2867 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MeldFields on them ! Check support mesh, field nature, and spatial and time discretisation.");
2868 MEDCouplingTimeDiscretization *td=f1->_time_discr->meld(f2->_time_discr);
2869 td->copyTinyAttrFrom(*f1->_time_discr);
2870 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2871 ret->setMesh(f1->getMesh());
2876 * Returns a new MEDCouplingFieldDouble containing a dot product of two given fields,
2877 * so that the i-th tuple of the result field is a sum of products of j-th components of
2878 * i-th tuples of given fields (\f$ f_i = \sum_{j=1}^n f1_j * f2_j \f$).
2879 * Number of tuples and components in the given fields must be the same.
2880 * \param [in] f1 - a given field.
2881 * \param [in] f2 - another given field.
2882 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2883 * The caller is to delete this result field using decrRef() as it is no more
2885 * \throw If either \a f1 or \a f2 is NULL.
2886 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2887 * differ not only in values.
2889 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2892 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DotFields : input field is NULL !");
2893 if(!f1->areStrictlyCompatibleForMulDiv(f2))
2894 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply DotFields on them! Check support mesh, and spatial and time discretisation.");
2895 MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr);
2896 td->copyTinyAttrFrom(*f1->_time_discr);
2897 MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
2898 ret->setMesh(f1->getMesh());
2903 * Returns a new MEDCouplingFieldDouble containing a cross product of two given fields,
2905 * the i-th tuple of the result field is a 3D vector which is a cross
2906 * product of two vectors defined by the i-th tuples of given fields.
2907 * Number of tuples in the given fields must be the same.
2908 * Number of components in the given fields must be 3.
2909 * \param [in] f1 - a given field.
2910 * \param [in] f2 - another given field.
2911 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2912 * The caller is to delete this result field using decrRef() as it is no more
2914 * \throw If either \a f1 or \a f2 is NULL.
2915 * \throw If \a f1->getNumberOfComponents() != 3
2916 * \throw If \a f2->getNumberOfComponents() != 3
2917 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2918 * differ not only in values.
2920 MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2923 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::CrossProductFields : input field is NULL !");
2924 if(!f1->areStrictlyCompatibleForMulDiv(f2))
2925 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply CrossProductFields on them! Check support mesh, and spatial and time discretisation.");
2926 MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr);
2927 td->copyTinyAttrFrom(*f1->_time_discr);
2928 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
2929 ret->setMesh(f1->getMesh());
2934 * Returns a new MEDCouplingFieldDouble containing maximal values of two given fields.
2935 * Number of tuples and components in the given fields must be the same.
2936 * \param [in] f1 - a field to compare values with another one.
2937 * \param [in] f2 - another field to compare values with the first one.
2938 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2939 * The caller is to delete this result field using decrRef() as it is no more
2941 * \throw If either \a f1 or \a f2 is NULL.
2942 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2943 * differ not only in values.
2945 * \if ENABLE_EXAMPLES
2946 * \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2947 * \ref py_mcfielddouble_MaxFields "Here is a Python example".
2950 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2953 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MaxFields : input field is NULL !");
2954 if(!f1->areStrictlyCompatible(f2))
2955 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MaxFields on them! Check support mesh, field nature, and spatial and time discretisation.");
2956 MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr);
2957 td->copyTinyAttrFrom(*f1->_time_discr);
2958 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2959 ret->setMesh(f1->getMesh());
2964 * Returns a new MEDCouplingFieldDouble containing minimal values of two given fields.
2965 * Number of tuples and components in the given fields must be the same.
2966 * \param [in] f1 - a field to compare values with another one.
2967 * \param [in] f2 - another field to compare values with the first one.
2968 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2969 * The caller is to delete this result field using decrRef() as it is no more
2971 * \throw If either \a f1 or \a f2 is NULL.
2972 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2973 * differ not only in values.
2975 * \if ENABLE_EXAMPLES
2976 * \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2977 * \ref py_mcfielddouble_MaxFields "Here is a Python example".
2980 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2983 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MinFields : input field is NULL !");
2984 if(!f1->areStrictlyCompatible(f2))
2985 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MinFields on them! Check support mesh, field nature, and spatial and time discretisation.");
2986 MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr);
2987 td->copyTinyAttrFrom(*f1->_time_discr);
2988 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2989 ret->setMesh(f1->getMesh());
2994 * Returns a copy of \a this field in which sign of all values is reversed.
2995 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble
2996 * containing the same number of tuples and components as \a this field.
2997 * The caller is to delete this result field using decrRef() as it is no more
2999 * \throw If the spatial discretization of \a this field is NULL.
3000 * \throw If a data array is not allocated.
3002 MEDCouplingFieldDouble *MEDCouplingFieldDouble::negate() const
3004 if(!((const MEDCouplingFieldDiscretization *)_type))
3005 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform negate !");
3006 MEDCouplingTimeDiscretization *td=_time_discr->negate();
3007 td->copyTinyAttrFrom(*_time_discr);
3008 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
3009 ret->setMesh(getMesh());
3014 * Returns a new MEDCouplingFieldDouble containing sum values of corresponding values of
3015 * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] + _f2_ [ i, j ] ).
3016 * Number of tuples and components in the given fields must be the same.
3017 * \param [in] f1 - a field to sum up.
3018 * \param [in] f2 - another field to sum up.
3019 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
3020 * The caller is to delete this result field using decrRef() as it is no more
3022 * \throw If either \a f1 or \a f2 is NULL.
3023 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3024 * differ not only in values.
3026 MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3029 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::AddFields : input field is NULL !");
3030 if(!f1->areStrictlyCompatible(f2))
3031 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply AddFields on them! Check support mesh, field nature, and spatial and time discretisation.");
3032 MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr);
3033 td->copyTinyAttrFrom(*f1->_time_discr);
3034 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3035 ret->setMesh(f1->getMesh());
3040 * Adds values of another MEDCouplingFieldDouble to values of \a this one
3041 * ( _this_ [ i, j ] += _other_ [ i, j ] ) using DataArrayDouble::addEqual().
3042 * The two fields must have same number of tuples, components and same underlying mesh.
3043 * \param [in] other - the field to add to \a this one.
3044 * \return const MEDCouplingFieldDouble & - a reference to \a this field.
3045 * \throw If \a other is NULL.
3046 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3047 * differ not only in values.
3049 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other)
3051 if(!areStrictlyCompatible(&other))
3052 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply += on them! Check support mesh, field nature, and spatial and time discretisation.");
3053 _time_discr->addEqual(other._time_discr);
3058 * Returns a new MEDCouplingFieldDouble containing subtraction of corresponding values of
3059 * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] - _f2_ [ i, j ] ).
3060 * Number of tuples and components in the given fields must be the same.
3061 * \param [in] f1 - a field to subtract from.
3062 * \param [in] f2 - a field to subtract.
3063 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
3064 * The caller is to delete this result field using decrRef() as it is no more
3066 * \throw If either \a f1 or \a f2 is NULL.
3067 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3068 * differ not only in values.
3070 MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3073 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::SubstractFields : input field is NULL !");
3074 if(!f1->areStrictlyCompatible(f2))
3075 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply SubstractFields on them! Check support mesh, field nature, and spatial and time discretisation.");
3076 MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr);
3077 td->copyTinyAttrFrom(*f1->_time_discr);
3078 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3079 ret->setMesh(f1->getMesh());
3084 * Subtract values of another MEDCouplingFieldDouble from values of \a this one
3085 * ( _this_ [ i, j ] -= _other_ [ i, j ] ) using DataArrayDouble::substractEqual().
3086 * The two fields must have same number of tuples, components and same underlying mesh.
3087 * \param [in] other - the field to subtract from \a this one.
3088 * \return const MEDCouplingFieldDouble & - a reference to \a this field.
3089 * \throw If \a other is NULL.
3090 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
3091 * differ not only in values.
3093 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other)
3095 if(!areStrictlyCompatible(&other))
3096 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply -= on them! Check support mesh, field nature, and spatial and time discretisation.");
3097 _time_discr->substractEqual(other._time_discr);
3102 * Returns a new MEDCouplingFieldDouble containing product values of
3103 * two given fields. There are 2 valid cases.
3104 * 1. The fields have same number of tuples and components. Then each value of
3105 * the result field (_f_) is a product of the corresponding values of _f1_ and
3106 * _f2_, i.e. _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, j ].
3107 * 2. The fields have same number of tuples and one field, say _f2_, has one
3109 * _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, 0 ].
3111 * The two fields must have same number of tuples and same underlying mesh.
3112 * \param [in] f1 - a factor field.
3113 * \param [in] f2 - another factor field.
3114 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, with no nature set.
3115 * The caller is to delete this result field using decrRef() as it is no more
3117 * \throw If either \a f1 or \a f2 is NULL.
3118 * \throw If the fields are not compatible for multiplication (areCompatibleForMul()),
3119 * i.e. they differ not only in values and possibly number of components.
3121 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3124 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MultiplyFields : input field is NULL !");
3125 if(!f1->areCompatibleForMul(f2))
3126 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MultiplyFields on them! Check support mesh, and spatial and time discretisation.");
3127 MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr);
3128 td->copyTinyAttrFrom(*f1->_time_discr);
3129 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
3130 ret->setMesh(f1->getMesh());
3135 * Multiply values of another MEDCouplingFieldDouble to values of \a this one
3136 * using DataArrayDouble::multiplyEqual().
3137 * The two fields must have same number of tuples and same underlying mesh.
3138 * There are 2 valid cases.
3139 * 1. The fields have same number of components. Then each value of
3140 * \a other is multiplied to the corresponding value of \a this field, i.e.
3141 * _this_ [ i, j ] *= _other_ [ i, j ].
3142 * 2. The _other_ field has one component. Then
3143 * _this_ [ i, j ] *= _other_ [ i, 0 ].
3145 * The two fields must have same number of tuples and same underlying mesh.
3146 * \param [in] other - an field to multiply to \a this one.
3147 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, with no nature set.
3148 * The caller is to delete this result field using decrRef() as it is no more
3150 * \throw If \a other is NULL.
3151 * \throw If the fields are not strictly compatible for multiplication
3152 * (areCompatibleForMul()),
3153 * i.e. they differ not only in values and possibly in number of components.
3155 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other)
3157 if(!areCompatibleForMul(&other))
3158 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply *= on them! Check support mesh, and spatial and time discretisation.");
3159 _time_discr->multiplyEqual(other._time_discr);
3165 * Returns a new MEDCouplingFieldDouble containing division of two given fields.
3166 * There are 2 valid cases.
3167 * 1. The fields have same number of tuples and components. Then each value of
3168 * the result field (_f_) is a division of the corresponding values of \a f1 and
3169 * \a f2, i.e. _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, j ].
3170 * 2. The fields have same number of tuples and _f2_ has one component. Then
3171 * _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, 0 ].
3173 * \param [in] f1 - a numerator field.
3174 * \param [in] f2 - a denominator field.
3175 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, with no nature set.
3176 * The caller is to delete this result field using decrRef() as it is no more
3178 * \throw If either \a f1 or \a f2 is NULL.
3179 * \throw If the fields are not compatible for division (areCompatibleForDiv()),
3180 * i.e. they differ not only in values and possibly in number of components.
3182 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3185 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DivideFields : input field is NULL !");
3186 if(!f1->areCompatibleForDiv(f2))
3187 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply DivideFields on them! Check support mesh, and spatial and time discretisation.");
3188 MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr);
3189 td->copyTinyAttrFrom(*f1->_time_discr);
3190 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
3191 ret->setMesh(f1->getMesh());
3196 * Divide values of \a this field by values of another MEDCouplingFieldDouble
3197 * using DataArrayDouble::divideEqual().
3198 * The two fields must have same number of tuples and same underlying mesh.
3199 * There are 2 valid cases.
3200 * 1. The fields have same number of components. Then each value of
3201 * \a this field is divided by the corresponding value of \a other one, i.e.
3202 * _this_ [ i, j ] /= _other_ [ i, j ].
3203 * 2. The \a other field has one component. Then
3204 * _this_ [ i, j ] /= _other_ [ i, 0 ].
3206 * \warning No check of division by zero is performed!
3207 * \param [in] other - an field to divide \a this one by.
3208 * \throw If \a other is NULL.
3209 * \throw If the fields are not compatible for division (areCompatibleForDiv()),
3210 * i.e. they differ not only in values and possibly in number of components.
3212 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other)
3214 if(!areCompatibleForDiv(&other))
3215 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply /= on them! Check support mesh, and spatial and time discretisation.");
3216 _time_discr->divideEqual(other._time_discr);
3222 * Directly called by MEDCouplingFieldDouble::operator^.
3224 * \sa MEDCouplingFieldDouble::operator^
3226 MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3229 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::PowFields : input field is NULL !");
3230 if(!f1->areCompatibleForMul(f2))
3231 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply PowFields on them! Check support mesh, and spatial and time discretisation.");
3232 MEDCouplingTimeDiscretization *td=f1->_time_discr->pow(f2->_time_discr);
3233 td->copyTinyAttrFrom(*f1->_time_discr);
3234 MCAuto<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone());
3235 ret->setMesh(f1->getMesh());
3240 * Directly call MEDCouplingFieldDouble::PowFields static method.
3242 * \sa MEDCouplingFieldDouble::PowFields
3244 MEDCouplingFieldDouble *MEDCouplingFieldDouble::operator^(const MEDCouplingFieldDouble& other) const
3246 return PowFields(this,&other);
3249 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCouplingFieldDouble& other)
3251 if(!areCompatibleForDiv(&other))
3252 throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply ^= on them! Check support mesh, and spatial and time discretisation.");
3253 _time_discr->powEqual(other._time_discr);
3259 * Writes the field series \a fs and the mesh the fields lie on in the VTK file \a fileName.
3260 * If \a fs is empty no file is written.
3261 * The result file is valid provided that no exception is thrown.
3262 * \warning All the fields must be named and lie on the same non NULL mesh.
3263 * \param [in] fileName - the name of a VTK file to write in.
3264 * \param [in] fs - the fields to write.
3265 * \param [in] isBinary - specifies the VTK format of the written file. By default true (Binary mode)
3266 * \throw If \a fs[ 0 ] == NULL.
3267 * \throw If the fields lie not on the same mesh.
3268 * \throw If the mesh is not set.
3269 * \throw If any of the fields has no name.
3271 * \if ENABLE_EXAMPLES
3272 * \ref cpp_mcfielddouble_WriteVTK "Here is a C++ example".<br>
3273 * \ref py_mcfielddouble_WriteVTK "Here is a Python example".
3276 std::string MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const std::vector<const MEDCouplingFieldDouble *>& fs, bool isBinary)
3279 return std::string();
3280 std::size_t nfs=fs.size();
3282 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field is NULL !");
3283 const MEDCouplingMesh *m=fs[0]->getMesh();
3285 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field lies on NULL mesh !");
3286 for(std::size_t i=1;i<nfs;i++)
3287 if(fs[i]->getMesh()!=m)
3288 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are not lying on a same mesh ! Expected by VTK ! MEDCouplingFieldDouble::setMesh or MEDCouplingFieldDouble::changeUnderlyingMesh can help to that.");
3290 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are lying on a same mesh but it is empty !");
3291 std::string ret(m->getVTKFileNameOf(fileName));
3292 MCAuto<DataArrayByte> byteArr;
3294 { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); }
3295 std::ostringstream coss,noss;
3296 for(std::size_t i=0;i<nfs;i++)
3298 const MEDCouplingFieldDouble *cur=fs[i];
3299 std::string name(cur->getName());
3302 std::ostringstream oss; oss << "MEDCouplingFieldDouble::WriteVTK : Field in pos #" << i << " has no name !";
3303 throw INTERP_KERNEL::Exception(oss.str().c_str());
3305 TypeOfField typ=cur->getTypeOfField();
3307 cur->getArray()->writeVTK(coss,8,cur->getName(),byteArr);
3308 else if(typ==ON_NODES)
3309 cur->getArray()->writeVTK(noss,8,cur->getName(),byteArr);
3311 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : only node and cell fields supported for the moment !");
3313 m->writeVTKAdvanced(ret,coss.str(),noss.str(),byteArr);
3317 void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const
3319 stream << "MEDCouplingFieldDouble C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
3323 nat=MEDCouplingNatureOfField::GetRepr(_nature);
3324 stream << "Nature of field : " << nat << ".\n";
3326 catch(INTERP_KERNEL::Exception& /*e*/)
3328 const MEDCouplingFieldDiscretization *fd(_type);
3330 stream << "No spatial discretization set !";
3332 fd->reprQuickOverview(stream);
3333 stream << std::endl;
3335 stream << "\nNo mesh support defined !";
3338 std::ostringstream oss;
3339 _mesh->reprQuickOverview(oss);
3340 std::string tmp(oss.str());
3341 stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
3345 const DataArrayDouble *arr=_time_discr->getArray();
3348 stream << "\n\nArray info : ";
3349 arr->reprQuickOverview(stream);
3353 stream << "\n\nNo data array set !";