1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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"
26 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
27 #include "MEDCouplingNatureOfField.hxx"
29 #include "InterpKernelAutoPtr.hxx"
36 using namespace ParaMEDMEM;
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 ParaMEDMEM::ON_CELLS "ON_CELLS",
44 * \ref ParaMEDMEM::ON_NODES "ON_NODES",
45 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT",
46 * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
47 * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
48 * \param [in] td - the type of time discretization of the created field, one of
49 * (\ref ParaMEDMEM::NO_TIME "NO_TIME",
50 * \ref ParaMEDMEM::ONE_TIME "ONE_TIME",
51 * \ref ParaMEDMEM::LINEAR_TIME "LINEAR_TIME",
52 * \ref ParaMEDMEM::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 ParaMEDMEM::NO_TIME "NO_TIME",
73 * \ref ParaMEDMEM::ONE_TIME "ONE_TIME",
74 * \ref ParaMEDMEM::LINEAR_TIME "LINEAR_TIME",
75 * \ref ParaMEDMEM::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 char *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 const char *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() throw(INTERP_KERNEL::Exception)
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 deepCpy() 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 deepCpy().
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 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(recDeepCpy);
166 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mCpy=_mesh->deepCpy();
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::deepCpy() 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 ParaMEDMEM::NO_TIME "NO_TIME",
195 * \ref ParaMEDMEM::ONE_TIME "ONE_TIME",
196 * \ref ParaMEDMEM::LINEAR_TIME "LINEAR_TIME",
197 * \ref ParaMEDMEM::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 * \ref cpp_mcfielddouble_buildNewTimeReprFromThis "Here is a C++ example."<br>
204 * \ref py_mcfielddouble_buildNewTimeReprFromThis "Here is a Python example."
207 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const
209 MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(td,deepCopy);
210 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization> disc;
213 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),tdo,disc.retn());
214 ret->setMesh(getMesh());
215 ret->setName(getName());
216 ret->setDescription(getDescription());
221 * Copies tiny info (component names, name and description) from an \a other field to
223 * \warning The underlying mesh is not renamed (for safety reason).
224 * \param [in] other - the field to copy the tiny info from.
225 * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
227 void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception)
229 MEDCouplingField::copyTinyStringsFrom(other);
230 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
233 _time_discr->copyTinyStringsFrom(*otherC->_time_discr);
238 * Copies only times, order and iteration from an \a other field to
239 * \a this one. The underlying mesh is not impacted by this method.
240 * Arrays are not impacted neither.
241 * \param [in] other - the field to tiny attributes from.
242 * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
244 void MEDCouplingFieldDouble::copyTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception)
248 _time_discr->copyTinyAttrFrom(*other->_time_discr);
253 void MEDCouplingFieldDouble::copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception)
255 copyTinyStringsFrom(other);
256 copyTinyAttrFrom(other);
260 * Returns a string describing \a this field. This string is outputted by \c print
261 * Python command. The string includes info on
264 * - \ref MEDCouplingSpatialDisc "spatial discretization",
265 * - \ref MEDCouplingTemporalDisc "time discretization",
266 * - \ref NatureOfField,
270 * \return std::string - the string describing \a this field.
272 std::string MEDCouplingFieldDouble::simpleRepr() const
274 std::ostringstream ret;
275 ret << "FieldDouble with name : \"" << getName() << "\"\n";
276 ret << "Description of field is : \"" << getDescription() << "\"\n";
278 { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; }
280 { ret << "FieldDouble has no spatial discretization !\n"; }
282 { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; }
284 { ret << "FieldDouble has no time discretization !\n"; }
285 ret << "FieldDouble nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
288 if(getArray()->isAllocated())
290 int nbOfCompo=getArray()->getNumberOfComponents();
291 ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
292 ret << "FieldDouble default array has following info on components : ";
293 for(int i=0;i<nbOfCompo;i++)
294 ret << "\"" << getArray()->getInfoOnComponent(i) << "\" ";
299 ret << "Array set but not allocated !\n";
303 ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
305 ret << "Mesh support information : No mesh set !\n";
310 * Returns a string describing \a this field. The string includes info on
313 * - \ref MEDCouplingSpatialDisc "spatial discretization",
314 * - \ref MEDCouplingTemporalDisc "time discretization",
317 * - contents of data arrays.
319 * \return std::string - the string describing \a this field.
321 std::string MEDCouplingFieldDouble::advancedRepr() const
323 std::ostringstream ret;
324 ret << "FieldDouble with name : \"" << getName() << "\"\n";
325 ret << "Description of field is : \"" << getDescription() << "\"\n";
327 { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; }
329 { ret << "FieldDouble has no space discretization set !\n"; }
331 { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; }
333 { ret << "FieldDouble has no time discretization set !\n"; }
335 ret << "FieldDouble default array has " << getArray()->getNumberOfComponents() << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
337 ret << "Mesh support information :\n__________________________\n" << _mesh->advancedRepr();
339 ret << "Mesh support information : No mesh set !\n";
340 std::vector<DataArrayDouble *> arrays;
341 _time_discr->getArrays(arrays);
343 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,arrayId++)
345 ret << "Array #" << arrayId << " :\n__________\n";
347 (*iter)->reprWithoutNameStream(ret);
349 ret << "Array empty !";
355 void MEDCouplingFieldDouble::writeVTK(const char *fileName) const throw(INTERP_KERNEL::Exception)
357 std::vector<const MEDCouplingFieldDouble *> fs(1,this);
358 MEDCouplingFieldDouble::WriteVTK(fileName,fs);
361 bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const throw(INTERP_KERNEL::Exception)
364 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::isEqualIfNotWhy : other instance is NULL !");
365 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
368 reason="field given in input is not castable in MEDCouplingFieldDouble !";
371 if(!MEDCouplingField::isEqualIfNotWhy(other,meshPrec,valsPrec,reason))
373 if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,valsPrec,reason))
375 reason.insert(0,"In FieldDouble time discretizations differ :");
382 * Checks equality of \a this and \a other field. Only numeric data is considered,
383 * i.e. names, description etc are not compared.
384 * \param [in] other - the field to compare with.
385 * \param [in] meshPrec - a precision used to compare node coordinates of meshes.
386 * \param [in] valsPrec - a precision used to compare data arrays of the two fields.
387 * \return bool - \c true if the two fields are equal, \c false else.
388 * \throw If \a other == NULL.
389 * \throw If the spatial discretization of \a this field is NULL.
391 bool MEDCouplingFieldDouble::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
393 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
396 if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec))
398 if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,valsPrec))
404 * This method states if \a this and 'other' are compatibles each other before performing any treatment.
405 * This method is good for methods like : mergeFields.
406 * This method is not very demanding compared to areStrictlyCompatible that is better for operation on fields.
408 bool MEDCouplingFieldDouble::areCompatibleForMerge(const MEDCouplingField *other) const
410 if(!MEDCouplingField::areCompatibleForMerge(other))
412 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
415 if(!_time_discr->areCompatible(otherC->_time_discr))
421 * This method is more strict than MEDCouplingField::areCompatibleForMerge method.
422 * This method is used for operation on fields to operate a first check before attempting operation.
424 bool MEDCouplingFieldDouble::areStrictlyCompatible(const MEDCouplingField *other) const
427 if(!MEDCouplingField::areStrictlyCompatible(other))
429 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
432 if(!_time_discr->areStrictlyCompatible(otherC->_time_discr,tmp))
438 * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatible method except that
439 * number of components between \a this and 'other' can be different here (for operator*).
441 bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other) const
443 if(!MEDCouplingField::areStrictlyCompatible(other))
445 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
448 if(!_time_discr->areStrictlyCompatibleForMul(otherC->_time_discr))
454 * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatible method except that
455 * number of components between \a this and 'other' can be different here (for operator/).
457 bool MEDCouplingFieldDouble::areCompatibleForDiv(const MEDCouplingField *other) const
459 if(!MEDCouplingField::areStrictlyCompatible(other))
461 const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
464 if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr))
470 * This method is invocated before any attempt of melding. This method is very close to areStrictlyCompatible,
471 * except that \a this and other can have different number of components.
473 bool MEDCouplingFieldDouble::areCompatibleForMeld(const MEDCouplingFieldDouble *other) const
475 if(!MEDCouplingField::areStrictlyCompatible(other))
477 if(!_time_discr->areCompatibleForMeld(other->_time_discr))
483 * Permutes values of \a this field according to a given permutation array for cells
484 * renumbering. The underlying mesh is deeply copied and its cells are also permuted.
485 * The number of cells remains the same; for that the permutation array \a old2NewBg
486 * should not contain equal ids.
487 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
488 * to be equal to \a this->getMesh()->getNumberOfCells().
489 * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
490 * array, so that its maximal cell id to correspond to (be less than) the number
491 * of cells in mesh. This new array is then used for the renumbering. If \a
492 * check == \c false, \a old2NewBg is used as is, that is less secure as validity
493 * of ids in \a old2NewBg is not checked.
494 * \throw If the mesh is not set.
495 * \throw If the spatial discretization of \a this field is NULL.
496 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
497 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
499 * \ref cpp_mcfielddouble_renumberCells "Here is a C++ example".<br>
500 * \ref py_mcfielddouble_renumberCells "Here is a Python example".
502 void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
504 renumberCellsWithoutMesh(old2NewBg,check);
505 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_mesh->deepCpy();
506 m->renumberCells(old2NewBg,check);
512 * Permutes values of \a this field according to a given permutation array for cells
513 * renumbering. The underlying mesh is \b not permuted.
514 * The number of cells remains the same; for that the permutation array \a old2NewBg
515 * should not contain equal ids.
516 * This method performs a part of job of renumberCells(). The reasonable use of this
517 * method is only for multi-field instances lying on the same mesh to avoid a
518 * systematic duplication and renumbering of _mesh attribute.
519 * \warning Use this method with a lot of care!
520 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
521 * to be equal to \a this->getMesh()->getNumberOfCells().
522 * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
523 * array, so that its maximal cell id to correspond to (be less than) the number
524 * of cells in mesh. This new array is then used for the renumbering. If \a
525 * check == \c false, \a old2NewBg is used as is, that is less secure as validity
526 * of ids in \a old2NewBg is not checked.
527 * \throw If the mesh is not set.
528 * \throw If the spatial discretization of \a this field is NULL.
529 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
530 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
532 void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
535 throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !");
536 if(!((const MEDCouplingFieldDiscretization *)_type))
537 throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
539 _type->renumberCells(old2NewBg,check);
540 std::vector<DataArrayDouble *> arrays;
541 _time_discr->getArrays(arrays);
542 std::vector<DataArray *> arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin());
543 _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check);
549 * Permutes values of \a this field according to a given permutation array for node
550 * renumbering. The underlying mesh is deeply copied and its nodes are also permuted.
551 * The number of nodes can change, contrary to renumberCells().
552 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
553 * to be equal to \a this->getMesh()->getNumberOfNodes().
554 * \param [in] eps - a precision used to compare field values at merged nodes. If
555 * the values differ more than \a eps, an exception is thrown.
556 * \throw If the mesh is not set.
557 * \throw If the spatial discretization of \a this field is NULL.
558 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
559 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
560 * \throw If values at merged nodes deffer more than \a eps.
562 * \ref cpp_mcfielddouble_renumberNodes "Here is a C++ example".<br>
563 * \ref py_mcfielddouble_renumberNodes "Here is a Python example".
565 void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg, double eps) throw(INTERP_KERNEL::Exception)
567 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
569 throw INTERP_KERNEL::Exception("Invalid mesh to apply renumberNodes on it !");
570 int nbOfNodes=meshC->getNumberOfNodes();
571 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
572 int newNbOfNodes=*std::max_element(old2NewBg,old2NewBg+nbOfNodes)+1;
573 renumberNodesWithoutMesh(old2NewBg,newNbOfNodes,eps);
574 meshC2->renumberNodes(old2NewBg,newNbOfNodes);
579 * Permutes values of \a this field according to a given permutation array for nodes
580 * renumbering. The underlying mesh is \b not permuted.
581 * The number of nodes can change, contrary to renumberCells().
582 * A given epsilon specifies a threshold of error in case of two nodes are merged but
583 * the difference of values on these nodes are higher than \a eps.
584 * This method performs a part of job of renumberNodes(), excluding node renumbering
585 * in mesh. The reasonable use of this
586 * method is only for multi-field instances lying on the same mesh to avoid a
587 * systematic duplication and renumbering of _mesh attribute.
588 * \warning Use this method with a lot of care!
589 * \warning In case of an exception thrown, the contents of the data array can be
590 * partially modified until the exception occurs.
591 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
592 * to be equal to \a this->getMesh()->getNumberOfNodes().
593 * \param [in] newNbOfNodes - a number of nodes in the mesh after renumbering.
594 * \param [in] eps - a precision used to compare field values at merged nodes. If
595 * the values differ more than \a eps, an exception is thrown.
596 * \throw If the mesh is not set.
597 * \throw If the spatial discretization of \a this field is NULL.
598 * \throw If values at merged nodes deffer more than \a eps.
600 void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps) throw(INTERP_KERNEL::Exception)
602 if(!((const MEDCouplingFieldDiscretization *)_type))
603 throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
604 std::vector<DataArrayDouble *> arrays;
605 _time_discr->getArrays(arrays);
606 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
608 _type->renumberValuesOnNodes(eps,old2NewBg,newNbOfNodes,*iter);
612 * Returns all tuple ids of \a this scalar field that fit the range [\a vmin,
613 * \a vmax]. This method calls DataArrayDouble::getIdsInRange().
614 * \param [in] vmin - a lower boundary of the range. Tuples with values less than \a
615 * vmin are not included in the result array.
616 * \param [in] vmax - an upper boundary of the range. Tuples with values more than \a
617 * vmax are not included in the result array.
618 * \return DataArrayInt * - a new instance of DataArrayInt holding ids of selected
619 * tuples. The caller is to delete this array using decrRef() as it is no
621 * \throw If the data array is not set.
622 * \throw If \a this->getNumberOfComponents() != 1.
624 DataArrayInt *MEDCouplingFieldDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception)
627 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getIdsInRange : no default array set !");
628 return getArray()->getIdsInRange(vmin,vmax);
632 * Builds a newly created field, that the caller will have the responsability to deal with (decrRef()).
633 * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done.
634 * 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.
635 * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (
636 * \ref ParaMEDMEM::ON_CELLS "ON_CELLS",
637 * \ref ParaMEDMEM::ON_NODES "ON_NODES",
638 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT",
639 * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
640 * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
642 * 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].
643 * Then the returned field will lie on mesh having 3 cells and the returned field will contain 3 tuples.<br>
644 * 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>
645 * 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>
646 * 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().
648 * 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].
649 * 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
650 * will contain 6 tuples and \a this field will lie on this restricted mesh.
652 * \param [in] part - an array of cell ids to include to the result field.
653 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The caller is to delete this field using decrRef() as it is no more needed.
655 * \ref cpp_mcfielddouble_subpart1 "Here is a C++ example".<br>
656 * \ref py_mcfielddouble_subpart1 "Here is a Python example".
657 * \sa MEDCouplingFieldDouble::buildSubPartRange
660 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *part) const throw(INTERP_KERNEL::Exception)
663 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : not empty array must be passed to this method !");
664 return buildSubPart(part->begin(),part->end());
668 * Builds a newly created field, that the caller will have the responsability to deal with.
669 * \n This method makes the assumption that \a this field is correctly defined when this method is called (\a this->checkCoherency() returns without any exception thrown), **no check of this will be done**.
670 * \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.
671 * \n Parameter [\a partBg, \a partEnd ) specifies **cell ids whatever the spatial discretization** of \a this (
672 * \ref ParaMEDMEM::ON_CELLS "ON_CELLS",
673 * \ref ParaMEDMEM::ON_NODES "ON_NODES",
674 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT",
675 * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
676 * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
678 * 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].
679 * Then the returned field will lie on mesh having 3 cells and will contain 3 tuples.
680 *- 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().
681 *- 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().
682 *- 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().
684 * 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].
685 * 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
686 * will contain 6 tuples and \a this field will lie on this restricted mesh.
688 * \param [in] partBg - start (included) of input range of cell ids to select [ \a partBg, \a partEnd )
689 * \param [in] partEnd - end (not included) of input range of cell ids to select [ \a partBg, \a partEnd )
690 * \return a newly allocated field the caller should deal with.
692 * \throw if there is presence of an invalid cell id in [ \a partBg, \a partEnd ) regarding the number of cells of \a this->getMesh().
694 * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."<br>
695 * \ref py_mcfielddouble_subpart1 "Here a Python example."
696 * \sa ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
698 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const throw(INTERP_KERNEL::Exception)
700 if(!((const MEDCouplingFieldDiscretization *)_type))
701 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
702 DataArrayInt *arrSelect;
703 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
704 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arrSelect2(arrSelect);
705 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
706 const MEDCouplingFieldDiscretization *disc=getDiscretization();
708 ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization>(disc->clonePart(partBg,partEnd)));
710 std::vector<DataArrayDouble *> arrays;
711 _time_discr->getArrays(arrays);
712 std::vector<DataArrayDouble *> arrs;
713 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrsSafe;
714 const int *arrSelBg=arrSelect->begin();
715 const int *arrSelEnd=arrSelect->end();
716 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
718 DataArrayDouble *arr=0;
720 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
721 arrs.push_back(arr); arrsSafe.push_back(arr);
723 ret->_time_discr->setArrays(arrs,0);
728 * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is
729 * given using a range given \a begin, \a end and \a step to optimize the part computation.
731 * \sa MEDCouplingFieldDouble::buildSubPart
733 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int end, int step) const throw(INTERP_KERNEL::Exception)
735 if(!((const MEDCouplingFieldDiscretization *)_type))
736 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
737 DataArrayInt *arrSelect;
738 int beginOut,endOut,stepOut;
739 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect);
740 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arrSelect2(arrSelect);
741 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
742 const MEDCouplingFieldDiscretization *disc=getDiscretization();
744 ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization>(disc->clonePartRange(begin,end,step)));
746 std::vector<DataArrayDouble *> arrays;
747 _time_discr->getArrays(arrays);
748 std::vector<DataArrayDouble *> arrs;
749 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrsSafe;
750 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
752 DataArrayDouble *arr=0;
757 const int *arrSelBg=arrSelect->begin();
758 const int *arrSelEnd=arrSelect->end();
759 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
762 arr=(*iter)->selectByTupleId2(beginOut,endOut,stepOut);
764 arrs.push_back(arr); arrsSafe.push_back(arr);
766 ret->_time_discr->setArrays(arrs,0);
771 * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field.
772 * \return ParaMEDMEM::TypeOfTimeDiscretization - an enum item describing the time
773 * discretization type.
775 TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const
777 return _time_discr->getEnum();
780 MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),
781 _time_discr(MEDCouplingTimeDiscretization::New(td))
786 * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! **
788 MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false),
789 _time_discr(MEDCouplingTimeDiscretization::New(td))
793 MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingField(other,deepCopy),
794 _time_discr(other._time_discr->performCpy(deepCopy))
798 MEDCouplingFieldDouble::MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td)
802 MEDCouplingFieldDouble::~MEDCouplingFieldDouble()
808 * Checks if \a this field is correctly defined, else an exception is thrown.
809 * \throw If the mesh is not set.
810 * \throw If the data array is not set.
811 * \throw If the spatial discretization of \a this field is NULL.
812 * \throw If \a this->getTimeTolerance() < 0.
813 * \throw If the temporal discretization data is incorrect.
814 * \throw If mesh data does not correspond to field data.
816 void MEDCouplingFieldDouble::checkCoherency() const throw(INTERP_KERNEL::Exception)
819 throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !");
820 if(!((const MEDCouplingFieldDiscretization *)_type))
821 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::checkCoherency : no spatial discretization !");
822 _time_discr->checkCoherency();
823 _type->checkCoherencyBetween(_mesh,getArray());
827 * Accumulate values of a given component of \a this field.
828 * \param [in] compId - the index of the component of interest.
829 * \return double - a sum value of *compId*-th component.
830 * \throw If the data array is not set.
831 * \throw If \a the condition ( 0 <= \a compId < \a this->getNumberOfComponents() ) is
834 double MEDCouplingFieldDouble::accumulate(int compId) const
837 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
838 return getArray()->accumulate(compId);
842 * Accumulates values of each component of \a this array.
843 * \param [out] res - an array of length \a this->getNumberOfComponents(), allocated
844 * by the caller, that is filled by this method with sum value for each
846 * \throw If the data array is not set.
848 void MEDCouplingFieldDouble::accumulate(double *res) const
851 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
852 getArray()->accumulate(res);
856 * Returns the maximal value within \a this scalar field. Values of all arrays stored
857 * in \a this->_time_discr are checked.
858 * \return double - the maximal value among all values of \a this field.
859 * \throw If \a this->getNumberOfComponents() != 1
860 * \throw If the data array is not set.
861 * \throw If there is an empty data array in \a this field.
863 double MEDCouplingFieldDouble::getMaxValue() const throw(INTERP_KERNEL::Exception)
865 std::vector<DataArrayDouble *> arrays;
866 _time_discr->getArrays(arrays);
867 double ret=-std::numeric_limits<double>::max();
868 bool isExistingArr=false;
869 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
875 ret=std::max(ret,(*iter)->getMaxValue(loc));
879 throw INTERP_KERNEL::Exception("getMaxValue : No arrays defined !");
884 * Returns the maximal value and all its locations within \a this scalar field.
885 * Only the first of available data arrays is checked.
886 * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
887 * tuples holding the maximal value. The caller is to delete it using
888 * decrRef() as it is no more needed.
889 * \return double - the maximal value among all values of the first array of \a this filed.
890 * \throw If \a this->getNumberOfComponents() != 1.
891 * \throw If there is an empty data array in \a this field.
893 double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
895 std::vector<DataArrayDouble *> arrays;
896 _time_discr->getArrays(arrays);
897 double ret=-std::numeric_limits<double>::max();
898 bool isExistingArr=false;
900 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1;
901 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
907 ret=std::max(ret,(*iter)->getMaxValue2(tmp));
908 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmpSafe(tmp);
909 if(!((const DataArrayInt *)ret1))
914 throw INTERP_KERNEL::Exception("getMaxValue2 : No arrays defined !");
915 tupleIds=ret1.retn();
920 * Returns the minimal value within \a this scalar field. Values of all arrays stored
921 * in \a this->_time_discr are checked.
922 * \return double - the minimal value among all values of \a this field.
923 * \throw If \a this->getNumberOfComponents() != 1
924 * \throw If the data array is not set.
925 * \throw If there is an empty data array in \a this field.
927 double MEDCouplingFieldDouble::getMinValue() const throw(INTERP_KERNEL::Exception)
929 std::vector<DataArrayDouble *> arrays;
930 _time_discr->getArrays(arrays);
931 double ret=std::numeric_limits<double>::max();
932 bool isExistingArr=false;
933 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
939 ret=std::min(ret,(*iter)->getMinValue(loc));
943 throw INTERP_KERNEL::Exception("getMinValue : No arrays defined !");
948 * Returns the minimal value and all its locations within \a this scalar field.
949 * Only the first of available data arrays is checked.
950 * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
951 * tuples holding the minimal value. The caller is to delete it using
952 * decrRef() as it is no more needed.
953 * \return double - the minimal value among all values of the first array of \a this filed.
954 * \throw If \a this->getNumberOfComponents() != 1.
955 * \throw If there is an empty data array in \a this field.
957 double MEDCouplingFieldDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
959 std::vector<DataArrayDouble *> arrays;
960 _time_discr->getArrays(arrays);
961 double ret=-std::numeric_limits<double>::max();
962 bool isExistingArr=false;
964 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1;
965 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
971 ret=std::max(ret,(*iter)->getMinValue2(tmp));
972 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmpSafe(tmp);
973 if(!((const DataArrayInt *)ret1))
978 throw INTERP_KERNEL::Exception("getMinValue2 : No arrays defined !");
979 tupleIds=ret1.retn();
984 * Returns the average value of \a this scalar field.
985 * \return double - the average value over all values of the data array.
986 * \throw If \a this->getNumberOfComponents() != 1
987 * \throw If the data array is not set or it is empty.
989 double MEDCouplingFieldDouble::getAverageValue() const throw(INTERP_KERNEL::Exception)
992 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getAverageValue : no default array defined !");
993 return getArray()->getAverageValue();
997 * This method returns the euclidean norm of \a this field.
999 * \sqrt{\sum_{0 \leq i < nbOfEntity}val[i]*val[i]}
1001 * \throw If the data array is not set.
1003 double MEDCouplingFieldDouble::norm2() const throw(INTERP_KERNEL::Exception)
1006 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::norm2 : no default array defined !");
1007 return getArray()->norm2();
1011 * This method returns the max norm of \a this field.
1013 * \max_{0 \leq i < nbOfEntity}{abs(val[i])}
1015 * \throw If the data array is not set.
1017 double MEDCouplingFieldDouble::normMax() const throw(INTERP_KERNEL::Exception)
1020 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::normMax : no default array defined !");
1021 return getArray()->normMax();
1025 * Computes sums of values of each component of \a this field wighted with
1026 * values returned by buildMeasureField().
1027 * \param [out] res - pointer to an array of result sum values, of size at least \a
1028 * this->getNumberOfComponents(), that is to be allocated by the caller.
1029 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1030 * buildMeasureField() that makes this method slower. If a user is sure that all
1031 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1032 * \c false that speeds up this method.
1033 * \throw If the mesh is not set.
1034 * \throw If the data array is not set.
1036 void MEDCouplingFieldDouble::getWeightedAverageValue(double *res, bool isWAbs) const throw(INTERP_KERNEL::Exception)
1039 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getWeightedAverageValue : no default array defined !");
1040 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> w=buildMeasureField(isWAbs);
1041 double deno=w->getArray()->accumulate(0);
1042 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=getArray()->deepCpy();
1043 arr->multiplyEqual(w->getArray());
1044 std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::multiplies<double>(),1./deno));
1045 arr->accumulate(res);
1049 * Computes a sum of values of a given component of \a this field wighted with
1050 * values returned by buildMeasureField().
1051 * \param [in] compId - an index of the component of interest.
1052 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1053 * buildMeasureField() that makes this method slower. If a user is sure that all
1054 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1055 * \c false that speeds up this method.
1056 * \throw If the mesh is not set.
1057 * \throw If the data array is not set.
1058 * \throw If \a compId is not valid.
1059 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1061 double MEDCouplingFieldDouble::getWeightedAverageValue(int compId, bool isWAbs) const throw(INTERP_KERNEL::Exception)
1063 int nbComps=getArray()->getNumberOfComponents();
1064 if(compId<0 || compId>=nbComps)
1066 std::ostringstream oss; oss << "MEDCouplingFieldDouble::getWeightedAverageValue : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1067 throw INTERP_KERNEL::Exception(oss.str().c_str());
1069 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1070 getWeightedAverageValue(res,isWAbs);
1075 * Returns the \c normL1 of values of a given component of \a this field:
1077 * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1079 * \param [in] compId - an index of the component of interest.
1080 * \throw If the mesh is not set.
1081 * \throw If the spatial discretization of \a this field is NULL.
1082 * \throw If \a compId is not valid.
1083 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1085 double MEDCouplingFieldDouble::normL1(int compId) const throw(INTERP_KERNEL::Exception)
1088 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1 !");
1089 if(!((const MEDCouplingFieldDiscretization *)_type))
1090 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1091 int nbComps=getArray()->getNumberOfComponents();
1092 if(compId<0 || compId>=nbComps)
1094 std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL1 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1095 throw INTERP_KERNEL::Exception(oss.str().c_str());
1097 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1098 _type->normL1(_mesh,getArray(),res);
1103 * Returns the \c normL1 of values of each component of \a this field:
1105 * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1107 * \param [out] res - pointer to an array of result values, of size at least \a
1108 * this->getNumberOfComponents(), that is to be allocated by the caller.
1109 * \throw If the mesh is not set.
1110 * \throw If the spatial discretization of \a this field is NULL.
1112 void MEDCouplingFieldDouble::normL1(double *res) const throw(INTERP_KERNEL::Exception)
1115 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1");
1116 if(!((const MEDCouplingFieldDiscretization *)_type))
1117 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1118 _type->normL1(_mesh,getArray(),res);
1122 * Returns the \c normL2 of values of a given component of \a this field:
1124 * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1126 * \param [in] compId - an index of the component of interest.
1127 * \throw If the mesh is not set.
1128 * \throw If the spatial discretization of \a this field is NULL.
1129 * \throw If \a compId is not valid.
1130 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1132 double MEDCouplingFieldDouble::normL2(int compId) const throw(INTERP_KERNEL::Exception)
1135 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1136 if(!((const MEDCouplingFieldDiscretization *)_type))
1137 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1138 int nbComps=getArray()->getNumberOfComponents();
1139 if(compId<0 || compId>=nbComps)
1141 std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL2 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1142 throw INTERP_KERNEL::Exception(oss.str().c_str());
1144 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1145 _type->normL2(_mesh,getArray(),res);
1150 * Returns the \c normL2 of values of each component of \a this field:
1152 * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1154 * \param [out] res - pointer to an array of result values, of size at least \a
1155 * this->getNumberOfComponents(), that is to be allocated by the caller.
1156 * \throw If the mesh is not set.
1157 * \throw If the spatial discretization of \a this field is NULL.
1159 void MEDCouplingFieldDouble::normL2(double *res) const throw(INTERP_KERNEL::Exception)
1162 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1163 if(!((const MEDCouplingFieldDiscretization *)_type))
1164 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1165 _type->normL2(_mesh,getArray(),res);
1169 * Computes a sum of values of a given component of \a this field multiplied by
1170 * values returned by buildMeasureField().
1171 * This method is useful to check the conservativity of interpolation method.
1172 * \param [in] compId - an index of the component of interest.
1173 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1174 * buildMeasureField() that makes this method slower. If a user is sure that all
1175 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1176 * \c false that speeds up this method.
1177 * \throw If the mesh is not set.
1178 * \throw If the data array is not set.
1179 * \throw If \a compId is not valid.
1180 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1182 double MEDCouplingFieldDouble::integral(int compId, bool isWAbs) const throw(INTERP_KERNEL::Exception)
1185 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral");
1186 if(!((const MEDCouplingFieldDiscretization *)_type))
1187 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral !");
1188 int nbComps=getArray()->getNumberOfComponents();
1189 if(compId<0 || compId>=nbComps)
1191 std::ostringstream oss; oss << "MEDCouplingFieldDouble::integral : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1192 throw INTERP_KERNEL::Exception(oss.str().c_str());
1194 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1195 _type->integral(_mesh,getArray(),isWAbs,res);
1200 * Computes a sum of values of each component of \a this field multiplied by
1201 * values returned by buildMeasureField().
1202 * This method is useful to check the conservativity of interpolation method.
1203 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1204 * buildMeasureField() that makes this method slower. If a user is sure that all
1205 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1206 * \c false that speeds up this method.
1207 * \param [out] res - pointer to an array of result sum values, of size at least \a
1208 * this->getNumberOfComponents(), that is to be allocated by the caller.
1209 * \throw If the mesh is not set.
1210 * \throw If the data array is not set.
1211 * \throw If the spatial discretization of \a this field is NULL.
1213 void MEDCouplingFieldDouble::integral(bool isWAbs, double *res) const throw(INTERP_KERNEL::Exception)
1216 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral2");
1217 if(!((const MEDCouplingFieldDiscretization *)_type))
1218 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral2 !");
1219 _type->integral(_mesh,getArray(),isWAbs,res);
1223 * Returns a value at a given cell of a structured mesh. The cell is specified by its
1225 * \param [in] i - a index of node coordinates array along X axis. The cell is
1226 * located between the i-th and ( i + 1 )-th nodes along X axis.
1227 * \param [in] j - a index of node coordinates array along Y axis. The cell is
1228 * located between the j-th and ( j + 1 )-th nodes along Y axis.
1229 * \param [in] k - a index of node coordinates array along Z axis. The cell is
1230 * located between the k-th and ( k + 1 )-th nodes along Z axis.
1231 * \param [out] res - pointer to an array returning a feild value, of size at least
1232 * \a this->getNumberOfComponents(), that is to be allocated by the caller.
1233 * \throw If the spatial discretization of \a this field is NULL.
1234 * \throw If the mesh is not set.
1235 * \throw If the mesh is not a structured one.
1237 * \ref cpp_mcfielddouble_getValueOnPos "Here is a C++ example".<br>
1238 * \ref py_mcfielddouble_getValueOnPos "Here is a Python example".
1240 void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) const throw(INTERP_KERNEL::Exception)
1242 const DataArrayDouble *arr=_time_discr->getArray();
1244 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnPos");
1245 if(!((const MEDCouplingFieldDiscretization *)_type))
1246 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1247 _type->getValueOnPos(arr,_mesh,i,j,k,res);
1251 * Returns a value of \a this at a given point using spatial discretization.
1252 * \param [in] spaceLoc - the point of interest.
1253 * \param [out] res - pointer to an array returning a feild value, of size at least
1254 * \a this->getNumberOfComponents(), that is to be allocated by the caller.
1255 * \throw If the spatial discretization of \a this field is NULL.
1256 * \throw If the mesh is not set.
1257 * \throw If \a spaceLoc is out of the spatial discretization.
1259 * \ref cpp_mcfielddouble_getValueOn "Here is a C++ example".<br>
1260 * \ref py_mcfielddouble_getValueOn "Here is a Python example".
1262 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) const throw(INTERP_KERNEL::Exception)
1264 const DataArrayDouble *arr=_time_discr->getArray();
1266 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1267 if(!((const MEDCouplingFieldDiscretization *)_type))
1268 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1269 _type->getValueOn(arr,_mesh,spaceLoc,res);
1273 * Returns values of \a this at given points using spatial discretization.
1274 * \param [in] spaceLoc - coordinates of points of interest in full-interlace
1275 * mode. This array is to be of size ( \a nbOfPoints * \a this->getNumberOfComponents() ).
1276 * \param [in] nbOfPoints - number of points of interest.
1277 * \return DataArrayDouble * - a new instance of DataArrayDouble holding field
1278 * values relating to the input points. This array is of size \a nbOfPoints
1279 * tuples per \a this->getNumberOfComponents() components. The caller is to
1280 * delete this array using decrRef() as it is no more needed.
1281 * \throw If the spatial discretization of \a this field is NULL.
1282 * \throw If the mesh is not set.
1283 * \throw If any point in \a spaceLoc is out of the spatial discretization.
1285 * \ref cpp_mcfielddouble_getValueOnMulti "Here is a C++ example".<br>
1286 * \ref py_mcfielddouble_getValueOnMulti "Here is a Python example".
1288 DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, int nbOfPoints) const throw(INTERP_KERNEL::Exception)
1290 const DataArrayDouble *arr=_time_discr->getArray();
1292 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnMulti");
1293 if(!((const MEDCouplingFieldDiscretization *)_type))
1294 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnMulti !");
1295 return _type->getValueOnMulti(arr,_mesh,spaceLoc,nbOfPoints);
1299 * Returns a value of \a this field at a given point at a given time using spatial discretization.
1300 * If the time is not covered by \a this->_time_discr, an exception is thrown.
1301 * \param [in] spaceLoc - the point of interest.
1302 * \param [in] time - the time of interest.
1303 * \param [out] res - pointer to an array returning a feild value, of size at least
1304 * \a this->getNumberOfComponents(), that is to be allocated by the caller.
1305 * \throw If the spatial discretization of \a this field is NULL.
1306 * \throw If the mesh is not set.
1307 * \throw If \a spaceLoc is out of the spatial discretization.
1308 * \throw If \a time is not covered by \a this->_time_discr.
1310 * \ref cpp_mcfielddouble_getValueOn_time "Here is a C++ example".<br>
1311 * \ref py_mcfielddouble_getValueOn_time "Here is a Python example".
1313 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, double *res) const throw(INTERP_KERNEL::Exception)
1315 std::vector< const DataArrayDouble *> arrs=_time_discr->getArraysForTime(time);
1317 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1318 if(!((const MEDCouplingFieldDiscretization *)_type))
1319 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOn !");
1320 std::vector<double> res2;
1321 for(std::vector< const DataArrayDouble *>::const_iterator iter=arrs.begin();iter!=arrs.end();iter++)
1323 int sz=(int)res2.size();
1324 res2.resize(sz+(*iter)->getNumberOfComponents());
1325 _type->getValueOn(*iter,_mesh,spaceLoc,&res2[sz]);
1327 _time_discr->getValueForTime(time,res2,res);
1331 * Apply a liner function to a given component of \a this field, so that
1332 * a component value <em>(x)</em> becomes \f$ a * x + b \f$.
1333 * \param [in] a - the first coefficient of the function.
1334 * \param [in] b - the second coefficient of the function.
1335 * \param [in] compoId - the index of component to modify.
1336 * \throw If the data array(s) is(are) not set.
1338 void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId)
1340 _time_discr->applyLin(a,b,compoId);
1344 * This method sets \a this to a uniform scalar field with one component.
1345 * All tuples will have the same value 'value'.
1346 * An exception is thrown if no underlying mesh is defined.
1348 MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) throw(INTERP_KERNEL::Exception)
1351 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !");
1352 if(!((const MEDCouplingFieldDiscretization *)_type))
1353 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform operator = !");
1354 int nbOfTuple=_type->getNumberOfTuples(_mesh);
1355 _time_discr->setOrCreateUniformValueOnAllComponents(nbOfTuple,value);
1360 * Creates data array(s) of \a this field by using a C function for value generation.
1361 * \param [in] nbOfComp - the number of components for \a this field to have.
1362 * \param [in] func - the function used to compute values of \a this field.
1363 * This function is to compute a field value basing on coordinates of value
1365 * \throw If the mesh is not set.
1366 * \throw If \a func returns \c false.
1367 * \throw If the spatial discretization of \a this field is NULL.
1369 * \ref cpp_mcfielddouble_fillFromAnalytic_c_func "Here is a C++ example".
1371 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate func) throw(INTERP_KERNEL::Exception)
1374 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1375 if(!((const MEDCouplingFieldDiscretization *)_type))
1376 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1377 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1378 _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1382 * Creates data array(s) of \a this field by using a function for value generation.<br>
1383 * The function is applied to coordinates of value location points. For example, if
1384 * \a this field is on cells, the function is applied to cell barycenters.
1385 * For more info on supported expressions that can be used in the function, see \ref
1386 * MEDCouplingArrayApplyFuncExpr. <br>
1387 * The function can include arbitrary named variables
1388 * (e.g. "x","y" or "va44") to refer to components of point coordinates. Names of
1389 * variables are sorted in \b alphabetical \b order to associate a variable name with a
1390 * component. For example, in the expression "2*x+z", "x" stands for the component #0
1391 * and "z" stands for the component #1 (\b not #2)!<br>
1392 * In a general case, a value resulting from the function evaluation is assigned to all
1393 * components of a field value. But there is a possibility to have its own expression for
1394 * each component within one function. For this purpose, there are predefined variable
1395 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1396 * the component #0 etc). A factor of such a variable is added to the
1397 * corresponding component only.<br>
1398 * For example, \a nbOfComp == 4, coordinates of a 3D point are (1.,3.,7.), then
1399 * - "2*x + z" produces (5.,5.,5.,5.)
1400 * - "2*x + 0*y + z" produces (9.,9.,9.,9.)
1401 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1402 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1404 * \param [in] nbOfComp - the number of components for \a this field to have.
1405 * \param [in] func - the function used to compute values of \a this field.
1406 * This function is used to compute a field value basing on coordinates of value
1407 * location point. For example, if \a this field is on cells, the function
1408 * is applied to cell barycenters.
1409 * \throw If the mesh is not set.
1410 * \throw If the spatial discretization of \a this field is NULL.
1411 * \throw If computing \a func fails.
1413 * \ref cpp_mcfielddouble_fillFromAnalytic "Here is a C++ example".<br>
1414 * \ref py_mcfielddouble_fillFromAnalytic "Here is a Python example".
1416 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception)
1419 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1420 if(!((const MEDCouplingFieldDiscretization *)_type))
1421 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1422 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1423 _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1427 * Creates data array(s) of \a this field by using a function for value generation.<br>
1428 * The function is applied to coordinates of value location points. For example, if
1429 * \a this field is on cells, the function is applied to cell barycenters.<br>
1430 * This method differs from
1431 * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) "fillFromAnalytic()"
1432 * by the way how variable
1433 * names, used in the function, are associated with components of coordinates of field
1434 * location points; here, a variable name corresponding to a component is retrieved from
1435 * a corresponding node coordinates array (where it is set via
1436 * DataArrayDouble::setInfoOnComponent()).<br>
1437 * For more info on supported expressions that can be used in the function, see \ref
1438 * MEDCouplingArrayApplyFuncExpr. <br>
1439 * In a general case, a value resulting from the function evaluation is assigned to all
1440 * components of a field value. But there is a possibility to have its own expression for
1441 * each component within one function. For this purpose, there are predefined variable
1442 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1443 * the component #0 etc). A factor of such a variable is added to the
1444 * corresponding component only.<br>
1445 * For example, \a nbOfComp == 4, names of spatial components are "x", "y" and "z",
1446 * coordinates of a 3D point are (1.,3.,7.), then
1447 * - "2*x + z" produces (9.,9.,9.,9.)
1448 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1449 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1451 * \param [in] nbOfComp - the number of components for \a this field to have.
1452 * \param [in] func - the function used to compute values of \a this field.
1453 * This function is used to compute a field value basing on coordinates of value
1454 * location point. For example, if \a this field is on cells, the function
1455 * is applied to cell barycenters.
1456 * \throw If the mesh is not set.
1457 * \throw If the spatial discretization of \a this field is NULL.
1458 * \throw If computing \a func fails.
1460 * \ref cpp_mcfielddouble_fillFromAnalytic2 "Here is a C++ example".<br>
1461 * \ref py_mcfielddouble_fillFromAnalytic2 "Here is a Python example".
1463 void MEDCouplingFieldDouble::fillFromAnalytic2(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception)
1466 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !");
1467 if(!((const MEDCouplingFieldDiscretization *)_type))
1468 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic2 !");
1469 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1470 _time_discr->fillFromAnalytic2(loc,nbOfComp,func);
1474 * Creates data array(s) of \a this field by using a function for value generation.<br>
1475 * The function is applied to coordinates of value location points. For example, if
1476 * \a this field is on cells, the function is applied to cell barycenters.<br>
1477 * This method differs from
1478 * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) "fillFromAnalytic()"
1479 * by the way how variable
1480 * names, used in the function, are associated with components of coordinates of field
1481 * location points; here, a component index of a variable is defined by a
1482 * rank of the variable within the input array \a varsOrder.<br>
1483 * For more info on supported expressions that can be used in the function, see \ref
1484 * MEDCouplingArrayApplyFuncExpr.
1485 * In a general case, a value resulting from the function evaluation is assigned to all
1486 * components of a field value. But there is a possibility to have its own expression for
1487 * each component within one function. For this purpose, there are predefined variable
1488 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1489 * the component #0 etc). A factor of such a variable is added to the
1490 * corresponding component only.<br>
1491 * For example, \a nbOfComp == 4, names of
1492 * spatial components are given in \a varsOrder: ["x", "y","z"], coordinates of a
1493 * 3D point are (1.,3.,7.), then
1494 * - "2*x + z" produces (9.,9.,9.,9.)
1495 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1496 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1498 * \param [in] nbOfComp - the number of components for \a this field to have.
1499 * \param [in] func - the function used to compute values of \a this field.
1500 * This function is used to compute a field value basing on coordinates of value
1501 * location point. For example, if \a this field is on cells, the function
1502 * is applied to cell barycenters.
1503 * \throw If the mesh is not set.
1504 * \throw If the spatial discretization of \a this field is NULL.
1505 * \throw If computing \a func fails.
1507 * \ref cpp_mcfielddouble_fillFromAnalytic3 "Here is a C++ example".<br>
1508 * \ref py_mcfielddouble_fillFromAnalytic3 "Here is a Python example".
1510 void MEDCouplingFieldDouble::fillFromAnalytic3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func) throw(INTERP_KERNEL::Exception)
1513 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !");
1514 if(!((const MEDCouplingFieldDiscretization *)_type))
1515 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic3 !");
1516 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1517 _time_discr->fillFromAnalytic3(loc,nbOfComp,varsOrder,func);
1521 * Modifies values of \a this field by applying a C function to each tuple of all
1523 * \param [in] nbOfComp - the number of components for \a this field to have.
1524 * \param [in] func - the function used to compute values of \a this field.
1525 * This function is to compute a field value basing on a current field value.
1526 * \throw If \a func returns \c false.
1528 * \ref cpp_mcfielddouble_applyFunc_c_func "Here is a C++ example".
1530 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, FunctionToEvaluate func)
1532 _time_discr->applyFunc(nbOfComp,func);
1536 * Fill \a this field with a given value.<br>
1537 * This method is a specialization of other overloaded methods. When \a nbOfComp == 1
1538 * this method is equivalent to ParaMEDMEM::MEDCouplingFieldDouble::operator=().
1539 * \param [in] nbOfComp - the number of components for \a this field to have.
1540 * \param [in] val - the value to assign to every atomic value of \a this field.
1541 * \throw If the spatial discretization of \a this field is NULL.
1542 * \throw If the mesh is not set.
1544 * \ref cpp_mcfielddouble_applyFunc_val "Here is a C++ example".<br>
1545 * \ref py_mcfielddouble_applyFunc_val "Here is a Python example".
1547 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val)
1550 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::applyFunc : no mesh defined !");
1551 if(!((const MEDCouplingFieldDiscretization *)_type))
1552 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform applyFunc !");
1553 int nbOfTuple=_type->getNumberOfTuples(_mesh);
1554 _time_discr->setUniformValue(nbOfTuple,nbOfComp,val);
1558 * Modifies values of \a this field by applying a function to each tuple of all
1560 * For more info on supported expressions that can be used in the function, see \ref
1561 * MEDCouplingArrayApplyFuncExpr. <br>
1562 * The function can include arbitrary named variables
1563 * (e.g. "x","y" or "va44") to refer to components of a field value. Names of
1564 * variables are sorted in \b alphabetical \b order to associate a variable name with a
1565 * component. For example, in the expression "2*x+z", "x" stands for the component #0
1566 * and "z" stands for the component #1 (\b not #2)!<br>
1567 * In a general case, a value resulting from the function evaluation is assigned to all
1568 * components of a field value. But there is a possibility to have its own expression for
1569 * each component within one function. For this purpose, there are predefined variable
1570 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1571 * the component #0 etc). A factor of such a variable is added to the
1572 * corresponding component only.<br>
1573 * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1574 * - "2*x + z" produces (5.,5.,5.,5.)
1575 * - "2*x + 0*y + z" produces (9.,9.,9.,9.)
1576 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1577 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1579 * \param [in] nbOfComp - the number of components for \a this field to have.
1580 * \param [in] func - the function used to compute values of \a this field.
1581 * This function is to compute a field value basing on a current field value.
1582 * \throw If computing \a func fails.
1584 * \ref cpp_mcfielddouble_applyFunc "Here is a C++ example".<br>
1585 * \ref py_mcfielddouble_applyFunc "Here is a Python example".
1587 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception)
1589 _time_discr->applyFunc(nbOfComp,func);
1594 * Modifies values of \a this field by applying a function to each tuple of all
1596 * For more info on supported expressions that can be used in the function, see \ref
1597 * MEDCouplingArrayApplyFuncExpr. <br>
1598 * This method differs from
1599 * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) "applyFunc()"
1600 * by the way how variable
1601 * names, used in the function, are associated with components of field values;
1602 * here, a variable name corresponding to a component is retrieved from
1603 * component information of an array (where it is set via
1604 * DataArrayDouble::setInfoOnComponent()).<br>
1605 * In a general case, a value resulting from the function evaluation is assigned to all
1606 * components of a field value. But there is a possibility to have its own expression for
1607 * each component within one function. For this purpose, there are predefined variable
1608 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1609 * the component #0 etc). A factor of such a variable is added to the
1610 * corresponding component only.<br>
1611 * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1612 * - "2*x + z" produces (5.,5.,5.,5.)
1613 * - "2*x + 0*y + z" produces (9.,9.,9.,9.)
1614 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1615 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1617 * \param [in] nbOfComp - the number of components for \a this field to have.
1618 * \param [in] func - the function used to compute values of \a this field.
1619 * This function is to compute a new field value basing on a current field value.
1620 * \throw If computing \a func fails.
1622 * \ref cpp_mcfielddouble_applyFunc2 "Here is a C++ example".<br>
1623 * \ref py_mcfielddouble_applyFunc2 "Here is a Python example".
1625 void MEDCouplingFieldDouble::applyFunc2(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception)
1627 _time_discr->applyFunc2(nbOfComp,func);
1631 * Modifies values of \a this field by applying a function to each tuple of all
1633 * This method differs from
1634 * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) "applyFunc()"
1635 * by the way how variable
1636 * names, used in the function, are associated with components of field values;
1637 * here, a component index of a variable is defined by a
1638 * rank of the variable within the input array \a varsOrder.<br>
1639 * For more info on supported expressions that can be used in the function, see \ref
1640 * MEDCouplingArrayApplyFuncExpr.
1641 * In a general case, a value resulting from the function evaluation is assigned to all
1642 * components of a field value. But there is a possibility to have its own expression for
1643 * each component within one function. For this purpose, there are predefined variable
1644 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1645 * the component #0 etc). A factor of such a variable is added to the
1646 * corresponding component only.<br>
1647 * For example, \a nbOfComp == 4, names of
1648 * components are given in \a varsOrder: ["x", "y","z"], components of a
1649 * 3D vector are (1.,3.,7.), then
1650 * - "2*x + z" produces (9.,9.,9.,9.)
1651 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1652 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1654 * \param [in] nbOfComp - the number of components for \a this field to have.
1655 * \param [in] func - the function used to compute values of \a this field.
1656 * This function is to compute a new field value basing on a current field value.
1657 * \throw If computing \a func fails.
1659 * \ref cpp_mcfielddouble_applyFunc3 "Here is a C++ example".<br>
1660 * \ref py_mcfielddouble_applyFunc3 "Here is a Python example".
1662 void MEDCouplingFieldDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func) throw(INTERP_KERNEL::Exception)
1664 _time_discr->applyFunc3(nbOfComp,varsOrder,func);
1668 * Modifies values of \a this field by applying a function to each atomic value of all
1669 * data arrays. The function computes a new single value basing on an old single value.
1670 * For more info on supported expressions that can be used in the function, see \ref
1671 * MEDCouplingArrayApplyFuncExpr. <br>
1672 * The function can include **only one** arbitrary named variable
1673 * (e.g. "x","y" or "va44") to refer to a field atomic value. <br>
1674 * In a general case, a value resulting from the function evaluation is assigned to
1675 * a single field value. But there is a possibility to have its own expression for
1676 * each component within one function. For this purpose, there are predefined variable
1677 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1678 * the component #0 etc). A factor of such a variable is added to the
1679 * corresponding component only.<br>
1680 * For example, components of a field value are (1.,3.,7.), then
1681 * - "2*x - 1" produces (1.,5.,13.)
1682 * - "2*x*IVec + (x+3)*KVec" produces (2.,0.,10.)
1683 * - "2*x*IVec + (x+3)*KVec + 1" produces (3.,1.,11.)
1685 * \param [in] func - the function used to compute values of \a this field.
1686 * This function is to compute a field value basing on a current field value.
1687 * \throw If computing \a func fails.
1689 * \ref cpp_mcfielddouble_applyFunc_same_nb_comp "Here is a C++ example".<br>
1690 * \ref py_mcfielddouble_applyFunc_same_nb_comp "Here is a Python example".
1692 void MEDCouplingFieldDouble::applyFunc(const char *func) throw(INTERP_KERNEL::Exception)
1694 _time_discr->applyFunc(func);
1698 * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1699 * The field will contain exactly the same number of components after the call.
1700 * Use is not warranted for the moment !
1702 void MEDCouplingFieldDouble::applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception)
1704 _time_discr->applyFuncFast32(func);
1708 * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1709 * The field will contain exactly the same number of components after the call.
1710 * Use is not warranted for the moment !
1712 void MEDCouplingFieldDouble::applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception)
1714 _time_discr->applyFuncFast64(func);
1718 * Returns number of components in the data array. For more info on the data arrays,
1719 * see \ref MEDCouplingArrayPage.
1720 * \return int - the number of components in the data array.
1721 * \throw If the data array is not set.
1723 int MEDCouplingFieldDouble::getNumberOfComponents() const throw(INTERP_KERNEL::Exception)
1726 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfComponents : No array specified !");
1727 return getArray()->getNumberOfComponents();
1731 * Returns number of tuples in \a this field, that depends on
1732 * - the number of entities in the underlying mesh
1733 * - \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field (e.g. number
1734 * of Gauss points if \a this->getTypeOfField() ==
1735 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT").
1737 * The returned value does **not depend** on the number of tuples in the data array
1738 * (which has to be equal to the returned value), \b contrary to
1739 * getNumberOfComponents() and getNumberOfValues() that retrieve information from the
1741 * \warning No checkCoherency() is done here.
1742 * For more info on the data arrays, see \ref MEDCouplingArrayPage.
1743 * \return int - the number of tuples.
1744 * \throw If the mesh is not set.
1745 * \throw If the spatial discretization of \a this field is NULL.
1746 * \throw If the spatial discretization is not fully defined.
1748 int MEDCouplingFieldDouble::getNumberOfTuples() const throw(INTERP_KERNEL::Exception)
1751 throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !");
1752 if(!((const MEDCouplingFieldDiscretization *)_type))
1753 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getNumberOfTuples !");
1754 return _type->getNumberOfTuples(_mesh);
1758 * Returns number of atomic double values in the data array of \a this field.
1759 * For more info on the data arrays, see \ref MEDCouplingArrayPage.
1760 * \return int - (number of tuples) * (number of components) of the
1762 * \throw If the data array is not set.
1764 int MEDCouplingFieldDouble::getNumberOfValues() const throw(INTERP_KERNEL::Exception)
1767 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfValues : No array specified !");
1768 return getArray()->getNbOfElems();
1772 * Sets own modification time by the most recently modified element of data (the mesh,
1773 * the data array etc). For more info, see \ref MEDCouplingTimeLabelPage.
1775 void MEDCouplingFieldDouble::updateTime() const
1777 MEDCouplingField::updateTime();
1778 updateTimeWith(*_time_discr);
1781 std::size_t MEDCouplingFieldDouble::getHeapMemorySize() const
1785 ret+=_time_discr->getHeapMemorySize();
1786 return MEDCouplingField::getHeapMemorySize()+ret;
1790 * Sets \ref NatureOfField.
1791 * \param [in] nat - an item of enum ParaMEDMEM::NatureOfField.
1793 void MEDCouplingFieldDouble::setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception)
1795 MEDCouplingField::setNature(nat);
1797 _type->checkCompatibilityWithNature(nat);
1801 * This method synchronizes time information (time, iteration, order, time unit) regarding the information in \c this->_mesh.
1802 * \throw If no mesh is set in this. Or if \a this is not compatible with time setting (typically NO_TIME)
1804 void MEDCouplingFieldDouble::synchronizeTimeWithMesh() throw(INTERP_KERNEL::Exception)
1807 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::synchronizeTimeWithMesh : no mesh set in this !");
1809 double val=_mesh->getTime(it,ordr);
1810 std::string timeUnit(_mesh->getTimeUnit());
1811 setTime(val,it,ordr);
1812 setTimeUnit(timeUnit.c_str());
1816 * Returns a value of \a this field of type either
1817 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" or
1818 * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
1819 * \param [in] cellId - an id of cell of interest.
1820 * \param [in] nodeIdInCell - a node index within the cell.
1821 * \param [in] compoId - an index of component.
1822 * \return double - the field value corresponding to the specified parameters.
1823 * \throw If the data array is not set.
1824 * \throw If the mesh is not set.
1825 * \throw If the spatial discretization of \a this field is NULL.
1826 * \throw If \a this field if of type other than
1827 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" or
1828 * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
1830 double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) const
1832 if(!((const MEDCouplingFieldDiscretization *)_type))
1833 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getIJK !");
1834 return _type->getIJK(_mesh,getArray(),cellId,nodeIdInCell,compoId);
1838 * Sets the data array.
1839 * \param [in] array - the data array holding values of \a this field. It's size
1840 * should correspond to the mesh and
1841 * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
1842 * (see getNumberOfTuples()), but this size is not checked here.
1844 void MEDCouplingFieldDouble::setArray(DataArrayDouble *array)
1846 _time_discr->setArray(array,this);
1850 * Sets the data array holding values corresponding to an end of a time interval
1851 * for which \a this field is defined.
1852 * \param [in] array - the data array holding values of \a this field. It's size
1853 * should correspond to the mesh and
1854 * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
1855 * (see getNumberOfTuples()), but this size is not checked here.
1857 void MEDCouplingFieldDouble::setEndArray(DataArrayDouble *array)
1859 _time_discr->setEndArray(array,this);
1863 * Sets all data arrays needed to define the field values.
1864 * \param [in] arrs - a vector of DataArrayDouble's holding values of \a this
1865 * field. Size of each array should correspond to the mesh and
1866 * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
1867 * (see getNumberOfTuples()), but this size is not checked here.
1868 * \throw If number of arrays in \a arrs does not correspond to type of
1869 * \ref MEDCouplingTemporalDisc "temporal discretization" of \a this field.
1871 void MEDCouplingFieldDouble::setArrays(const std::vector<DataArrayDouble *>& arrs) throw(INTERP_KERNEL::Exception)
1873 _time_discr->setArrays(arrs,this);
1876 void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
1879 _time_discr->getTinySerializationStrInformation(tinyInfo);
1880 tinyInfo.push_back(_name);
1881 tinyInfo.push_back(_desc);
1882 tinyInfo.push_back(getTimeUnit());
1886 * This method retrieves some critical values to resize and prepare remote instance.
1887 * The first two elements returned in tinyInfo correspond to the parameters to give in constructor.
1888 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
1890 void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1892 if(!((const MEDCouplingFieldDiscretization *)_type))
1893 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
1895 tinyInfo.push_back((int)_type->getEnum());
1896 tinyInfo.push_back((int)_time_discr->getEnum());
1897 tinyInfo.push_back((int)_nature);
1898 _time_discr->getTinySerializationIntInformation(tinyInfo);
1899 std::vector<int> tinyInfo2;
1900 _type->getTinySerializationIntInformation(tinyInfo2);
1901 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
1902 tinyInfo.push_back((int)tinyInfo2.size());
1906 * This method retrieves some critical values to resize and prepare remote instance.
1907 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
1909 void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1911 if(!((const MEDCouplingFieldDiscretization *)_type))
1912 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
1914 _time_discr->getTinySerializationDbleInformation(tinyInfo);
1915 std::vector<double> tinyInfo2;
1916 _type->getTinySerializationDbleInformation(tinyInfo2);
1917 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
1918 tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it
1922 * This method has to be called to the new instance filled by CORBA, MPI, File...
1923 * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied.
1924 * @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.
1925 * @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.
1926 * No decrRef must be applied to every instances in returned vector.
1928 void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays)
1930 if(!((const MEDCouplingFieldDiscretization *)_type))
1931 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
1933 std::vector<int> tinyInfoITmp(tinyInfoI);
1934 int sz=tinyInfoITmp.back();
1935 tinyInfoITmp.pop_back();
1936 std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
1937 std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
1938 _time_discr->resizeForUnserialization(tinyInfoI2,arrays);
1939 std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
1940 _type->resizeForUnserialization(tinyInfoITmp3,dataInt);
1943 void MEDCouplingFieldDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1945 if(!((const MEDCouplingFieldDiscretization *)_type))
1946 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
1947 std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
1949 std::vector<double> tmp(tinyInfoD);
1950 int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it
1952 std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
1953 std::vector<double> tmp2(tmp.end()-sz,tmp.end());
1955 _time_discr->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
1956 _nature=(NatureOfField)tinyInfoI[2];
1957 _type->finishUnserialization(tmp2);
1958 int nbOfElemS=(int)tinyInfoS.size();
1959 _name=tinyInfoS[nbOfElemS-3];
1960 _desc=tinyInfoS[nbOfElemS-2];
1961 setTimeUnit(tinyInfoS[nbOfElemS-1].c_str());
1965 * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller.
1966 * The values returned must be consulted only in readonly mode.
1968 void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays) const
1970 if(!((const MEDCouplingFieldDiscretization *)_type))
1971 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");
1972 _time_discr->getArrays(arrays);
1973 _type->getSerializationIntArray(dataInt);
1977 * Tries to set an \a other mesh as the support of \a this field. An attempt fails, if
1978 * a current and the \a other meshes are different with use of specified equality
1979 * criteria, and then an exception is thrown.
1980 * \param [in] other - the mesh to use as the field support if this mesh can be
1981 * considered equal to the current mesh.
1982 * \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
1983 * it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
1984 * is used for mesh comparison.
1985 * \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
1986 * It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
1987 * \param [in] eps - a precision used at node renumbering (if needed) to compare field
1988 * values at merged nodes. If the values differ more than \a eps, an
1989 * exception is thrown.
1990 * \throw If the mesh is not set.
1991 * \throw If \a other == NULL.
1992 * \throw If any of the meshes is not well defined.
1993 * \throw If the two meshes do not match.
1994 * \throw If field values at merged nodes (if any) deffer more than \a eps.
1996 * \ref cpp_mcfielddouble_changeUnderlyingMesh "Here is a C++ example".<br>
1997 * \ref py_mcfielddouble_changeUnderlyingMesh "Here is a Python example".
1999 void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps) throw(INTERP_KERNEL::Exception)
2001 if(_mesh==0 || other==0)
2002 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::changeUnderlyingMesh : is expected to operate on not null meshes !");
2003 DataArrayInt *cellCor=0,*nodeCor=0;
2004 other->checkGeoEquivalWith(_mesh,levOfCheck,precOnMesh,cellCor,nodeCor);
2005 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellCor2(cellCor),nodeCor2(nodeCor);
2007 renumberCellsWithoutMesh(cellCor->getConstPointer(),false);
2009 renumberNodesWithoutMesh(nodeCor->getConstPointer(),nodeCor->getMaxValueInArray()+1,eps);
2010 setMesh(const_cast<MEDCouplingMesh *>(other));
2014 * Subtracts another field from \a this one in case when the two fields have different
2015 * supporting meshes. The subtraction is performed provided that the tho meshes can be
2016 * considered equal with use of specified equality criteria, else an exception is thrown.
2017 * If the meshes match, the mesh of \a f is set to \a this field (\a this is permuted if
2018 * necessary) and field values are subtracted. No interpolation is done here, only an
2019 * analysis of two underlying mesh is done to see if the meshes are geometrically
2021 * The job of this method consists in calling
2022 * \a this->changeUnderlyingMesh() with \a f->getMesh() as the first parameter, and then
2023 * \a this -= \a f.<br>
2024 * This method requires that \a f and \a this are coherent (checkCoherency()) and that \a f
2025 * and \a this are coherent for a merge.<br>
2026 * "DM" in the method name stands for "different meshes".
2027 * \param [in] f - the field to subtract from this.
2028 * \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
2029 * it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
2030 * is used for mesh comparison.
2031 * \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
2032 * It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
2033 * \param [in] eps - a precision used at node renumbering (if needed) to compare field
2034 * values at merged nodes. If the values differ more than \a eps, an
2035 * exception is thrown.
2036 * \throw If \a f == NULL.
2037 * \throw If any of the meshes is not set or is not well defined.
2038 * \throw If the two meshes do not match.
2039 * \throw If the two fields are not coherent for merge.
2040 * \throw If field values at merged nodes (if any) deffer more than \a eps.
2042 * \ref cpp_mcfielddouble_substractInPlaceDM "Here is a C++ example".<br>
2043 * \ref py_mcfielddouble_substractInPlaceDM "Here is a Python example".
2044 * \sa changeUnderlyingMesh().
2046 void MEDCouplingFieldDouble::substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps) throw(INTERP_KERNEL::Exception)
2050 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : input field is NULL !");
2051 f->checkCoherency();
2052 if(!areCompatibleForMerge(f))
2053 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : Fields are not compatible ; unable to apply mergeFields on them !");
2054 changeUnderlyingMesh(f->getMesh(),levOfCheck,precOnMesh,eps);
2059 * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2060 * underlying mesh is replaced by a new mesh instance where the coincident nodes are merged.
2061 * \param [in] eps - a precision used to compare nodes of the two meshes.
2062 * \param [in] epsOnVals - a precision used to compare field
2063 * values at merged nodes. If the values differ more than \a epsOnVals, an
2064 * exception is thrown.
2065 * \return bool - \c true if some nodes have been merged and hence \a this field lies
2067 * \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2068 * \throw If the mesh is not well defined.
2069 * \throw If the spatial discretization of \a this field is NULL.
2070 * \throw If the data array is not set.
2071 * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2073 bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals) throw(INTERP_KERNEL::Exception)
2075 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2077 throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2078 if(!((const MEDCouplingFieldDiscretization *)_type))
2079 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes !");
2080 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
2083 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->mergeNodes(eps,ret,ret2);
2084 if(!ret)//no nodes have been merged.
2086 std::vector<DataArrayDouble *> arrays;
2087 _time_discr->getArrays(arrays);
2088 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2090 _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2096 * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2097 * underlying mesh is replaced by a new mesh instance where the coincident nodes are
2099 * In contrast to mergeNodes(), location of merged nodes is changed to be at their barycenter.
2100 * \param [in] eps - a precision used to compare nodes of the two meshes.
2101 * \param [in] epsOnVals - a precision used to compare field
2102 * values at merged nodes. If the values differ more than \a epsOnVals, an
2103 * exception is thrown.
2104 * \return bool - \c true if some nodes have been merged and hence \a this field lies
2106 * \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2107 * \throw If the mesh is not well defined.
2108 * \throw If the spatial discretization of \a this field is NULL.
2109 * \throw If the data array is not set.
2110 * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2112 bool MEDCouplingFieldDouble::mergeNodes2(double eps, double epsOnVals) throw(INTERP_KERNEL::Exception)
2114 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2116 throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2117 if(!((const MEDCouplingFieldDiscretization *)_type))
2118 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes2 !");
2119 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
2122 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->mergeNodes2(eps,ret,ret2);
2123 if(!ret)//no nodes have been merged.
2125 std::vector<DataArrayDouble *> arrays;
2126 _time_discr->getArrays(arrays);
2127 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2129 _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2135 * Removes from the underlying mesh nodes not used in any cell. If some nodes are
2136 * removed, the underlying mesh is replaced by a new mesh instance where the unused
2137 * nodes are removed.<br>
2138 * \param [in] epsOnVals - a precision used to compare field
2139 * values at merged nodes. If the values differ more than \a epsOnVals, an
2140 * exception is thrown.
2141 * \return bool - \c true if some nodes have been removed and hence \a this field lies
2143 * \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2144 * \throw If the mesh is not well defined.
2145 * \throw If the spatial discretization of \a this field is NULL.
2146 * \throw If the data array is not set.
2147 * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2149 bool MEDCouplingFieldDouble::zipCoords(double epsOnVals) throw(INTERP_KERNEL::Exception)
2151 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2153 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2154 if(!((const MEDCouplingFieldDiscretization *)_type))
2155 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipCoords !");
2156 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
2157 int oldNbOfNodes=meshC2->getNumberOfNodes();
2158 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->zipCoordsTraducer();
2159 if(meshC2->getNumberOfNodes()!=oldNbOfNodes)
2161 std::vector<DataArrayDouble *> arrays;
2162 _time_discr->getArrays(arrays);
2163 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2165 _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2173 * Removes duplicates of cells from the understanding mesh. If some cells are
2174 * removed, the underlying mesh is replaced by a new mesh instance where the cells
2175 * duplicates are removed.<br>
2176 * \param [in] compType - specifies a cell comparison technique. Meaning of its
2177 * valid values [0,1,2] is explained in the description of
2178 * MEDCouplingPointSet::zipConnectivityTraducer() which is called by this method.
2179 * \param [in] epsOnVals - a precision used to compare field
2180 * values at merged cells. If the values differ more than \a epsOnVals, an
2181 * exception is thrown.
2182 * \return bool - \c true if some cells have been removed and hence \a this field lies
2184 * \throw If the mesh is not an instance of MEDCouplingUMesh.
2185 * \throw If the mesh is not well defined.
2186 * \throw If the spatial discretization of \a this field is NULL.
2187 * \throw If the data array is not set.
2188 * \throw If field values at merged cells (if any) deffer more than \a epsOnVals.
2190 bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals) throw(INTERP_KERNEL::Exception)
2192 const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(_mesh);
2194 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipConnectivity : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2195 if(!((const MEDCouplingFieldDiscretization *)_type))
2196 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipConnectivity !");
2197 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> meshC2((MEDCouplingUMesh *)meshC->deepCpy());
2198 int oldNbOfCells=meshC2->getNumberOfCells();
2199 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->zipConnectivityTraducer(compType);
2200 if(meshC2->getNumberOfCells()!=oldNbOfCells)
2202 std::vector<DataArrayDouble *> arrays;
2203 _time_discr->getArrays(arrays);
2204 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2206 _type->renumberValuesOnCells(epsOnVals,meshC,arr->getConstPointer(),meshC2->getNumberOfCells(),*iter);
2214 * This method calls MEDCouplingUMesh::buildSlice3D method. So this method makes the assumption that underlying mesh exists.
2215 * For the moment, this method is implemented for fields on cells.
2217 * \return a newly allocated field double containing the result that the user should deallocate.
2219 MEDCouplingFieldDouble *MEDCouplingFieldDouble::extractSlice3D(const double *origin, const double *vec, double eps) const throw(INTERP_KERNEL::Exception)
2221 const MEDCouplingMesh *mesh=getMesh();
2223 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : underlying mesh is null !");
2224 if(getTypeOfField()!=ON_CELLS)
2225 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : only implemented for fields on cells !");
2226 const MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> umesh(mesh->buildUnstructured());
2227 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);
2228 ret->setMesh(umesh);
2229 DataArrayInt *cellIds=0;
2230 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2=umesh->buildSlice3D(origin,vec,eps,cellIds);
2231 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds2=cellIds;
2232 ret->setMesh(mesh2);
2233 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tupleIds=computeTupleIdsToSelectFromCellIds(cellIds->begin(),cellIds->end());
2234 std::vector<DataArrayDouble *> arrays;
2235 _time_discr->getArrays(arrays);
2237 std::vector<DataArrayDouble *> newArr(arrays.size());
2238 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > newArr2(arrays.size());
2239 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,i++)
2243 newArr2[i]=(*iter)->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
2244 newArr[i]=newArr2[i];
2247 ret->setArrays(newArr);
2252 * Divides every cell of the underlying mesh into simplices (triangles in 2D and
2253 * tetrahedra in 3D). If some cells are divided, the underlying mesh is replaced by a new
2254 * mesh instance containing the simplices.<br>
2255 * \param [in] policy - specifies a pattern used for splitting. For its description, see
2256 * MEDCouplingUMesh::simplexize().
2257 * \return bool - \c true if some cells have been divided and hence \a this field lies
2259 * \throw If \a policy has an invalid value. For valid values, see the description of
2260 * MEDCouplingUMesh::simplexize().
2261 * \throw If MEDCouplingMesh::simplexize() is not applicable to the underlying mesh.
2262 * \throw If the mesh is not well defined.
2263 * \throw If the spatial discretization of \a this field is NULL.
2264 * \throw If the data array is not set.
2266 bool MEDCouplingFieldDouble::simplexize(int policy) throw(INTERP_KERNEL::Exception)
2269 throw INTERP_KERNEL::Exception("No underlying mesh on this field to perform simplexize !");
2270 if(!((const MEDCouplingFieldDiscretization *)_type))
2271 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform simplexize !");
2272 int oldNbOfCells=_mesh->getNumberOfCells();
2273 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> meshC2(_mesh->deepCpy());
2274 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->simplexize(policy);
2275 int newNbOfCells=meshC2->getNumberOfCells();
2276 if(oldNbOfCells==newNbOfCells)
2278 std::vector<DataArrayDouble *> arrays;
2279 _time_discr->getArrays(arrays);
2280 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2282 _type->renumberValuesOnCellsR(_mesh,arr->getConstPointer(),arr->getNbOfElems(),*iter);
2288 * Creates a new MEDCouplingFieldDouble filled with the doubly contracted product of
2289 * every tensor of \a this 6-componental field.
2290 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2291 * each tuple is calculated from the tuple <em>(t)</em> of \a this field as
2292 * follows: \f$ t[0]^2+t[1]^2+t[2]^2+2*t[3]^2+2*t[4]^2+2*t[5]^2\f$.
2293 * This new field lies on the same mesh as \a this one. The caller is to delete
2294 * this field using decrRef() as it is no more needed.
2295 * \throw If \a this->getNumberOfComponents() != 6.
2296 * \throw If the spatial discretization of \a this field is NULL.
2298 MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
2300 if(!((const MEDCouplingFieldDiscretization *)_type))
2301 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform doublyContractedProduct !");
2302 MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct();
2303 td->copyTinyAttrFrom(*_time_discr);
2304 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2305 ret->setName("DoublyContractedProduct");
2306 ret->setMesh(getMesh());
2311 * Creates a new MEDCouplingFieldDouble filled with the determinant of a square
2312 * matrix defined by every tuple of \a this field, having either 4, 6 or 9 components.
2313 * The case of 6 components corresponds to that of the upper triangular matrix.
2314 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2315 * each tuple is the determinant of matrix of the corresponding tuple of \a this
2316 * field. This new field lies on the same mesh as \a this one. The caller is to
2317 * delete this field using decrRef() as it is no more needed.
2318 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2319 * \throw If the spatial discretization of \a this field is NULL.
2321 MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const throw(INTERP_KERNEL::Exception)
2323 if(!((const MEDCouplingFieldDiscretization *)_type))
2324 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform determinant !");
2325 MEDCouplingTimeDiscretization *td=_time_discr->determinant();
2326 td->copyTinyAttrFrom(*_time_discr);
2327 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2328 ret->setName("Determinant");
2329 ret->setMesh(getMesh());
2335 * Creates a new MEDCouplingFieldDouble with 3 components filled with 3 eigenvalues of
2336 * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2337 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2338 * having 3 components, whose each tuple contains the eigenvalues of the matrix of
2339 * corresponding tuple of \a this field. This new field lies on the same mesh as
2340 * \a this one. The caller is to delete this field using decrRef() as it is no
2342 * \throw If \a this->getNumberOfComponents() != 6.
2343 * \throw If the spatial discretization of \a this field is NULL.
2345 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const throw(INTERP_KERNEL::Exception)
2347 if(!((const MEDCouplingFieldDiscretization *)_type))
2348 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenValues !");
2349 MEDCouplingTimeDiscretization *td=_time_discr->eigenValues();
2350 td->copyTinyAttrFrom(*_time_discr);
2351 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2352 ret->setName("EigenValues");
2353 ret->setMesh(getMesh());
2358 * Creates a new MEDCouplingFieldDouble with 9 components filled with 3 eigenvectors of
2359 * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2360 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2361 * having 9 components, whose each tuple contains the eigenvectors of the matrix of
2362 * corresponding tuple of \a this field. This new field lies on the same mesh as
2363 * \a this one. The caller is to delete this field using decrRef() as it is no
2365 * \throw If \a this->getNumberOfComponents() != 6.
2366 * \throw If the spatial discretization of \a this field is NULL.
2368 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const throw(INTERP_KERNEL::Exception)
2370 if(!((const MEDCouplingFieldDiscretization *)_type))
2371 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenVectors !");
2372 MEDCouplingTimeDiscretization *td=_time_discr->eigenVectors();
2373 td->copyTinyAttrFrom(*_time_discr);
2374 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2375 ret->setName("EigenVectors");
2376 ret->setMesh(getMesh());
2381 * Creates a new MEDCouplingFieldDouble filled with the inverse matrix of
2382 * a matrix defined by every tuple of \a this field having either 4, 6 or 9
2383 * components. The case of 6 components corresponds to that of the upper triangular
2385 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2386 * having the same number of components as \a this one, whose each tuple
2387 * contains the inverse matrix of the matrix of corresponding tuple of \a this
2388 * field. This new field lies on the same mesh as \a this one. The caller is to
2389 * delete this field using decrRef() as it is no more needed.
2390 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2391 * \throw If the spatial discretization of \a this field is NULL.
2393 MEDCouplingFieldDouble *MEDCouplingFieldDouble::inverse() const throw(INTERP_KERNEL::Exception)
2395 if(!((const MEDCouplingFieldDiscretization *)_type))
2396 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform inverse !");
2397 MEDCouplingTimeDiscretization *td=_time_discr->inverse();
2398 td->copyTinyAttrFrom(*_time_discr);
2399 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2400 ret->setName("Inversion");
2401 ret->setMesh(getMesh());
2406 * Creates a new MEDCouplingFieldDouble filled with the trace of
2407 * a matrix defined by every tuple of \a this field having either 4, 6 or 9
2408 * components. The case of 6 components corresponds to that of the upper triangular
2410 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2411 * having 1 component, whose each tuple is the trace of the matrix of
2412 * corresponding tuple of \a this field.
2413 * This new field lies on the same mesh as \a this one. The caller is to
2414 * delete this field using decrRef() as it is no more needed.
2415 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2416 * \throw If the spatial discretization of \a this field is NULL.
2418 MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const throw(INTERP_KERNEL::Exception)
2420 if(!((const MEDCouplingFieldDiscretization *)_type))
2421 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform trace !");
2422 MEDCouplingTimeDiscretization *td=_time_discr->trace();
2423 td->copyTinyAttrFrom(*_time_discr);
2424 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2425 ret->setName("Trace");
2426 ret->setMesh(getMesh());
2431 * Creates a new MEDCouplingFieldDouble filled with the stress deviator tensor of
2432 * a stress tensor defined by every tuple of \a this 6-componental field.
2433 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2434 * having same number of components and tuples as \a this field,
2435 * whose each tuple contains the stress deviator tensor of the stress tensor of
2436 * corresponding tuple of \a this field. This new field lies on the same mesh as
2437 * \a this one. The caller is to delete this field using decrRef() as it is no
2439 * \throw If \a this->getNumberOfComponents() != 6.
2440 * \throw If the spatial discretization of \a this field is NULL.
2442 MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const throw(INTERP_KERNEL::Exception)
2444 if(!((const MEDCouplingFieldDiscretization *)_type))
2445 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform deviator !");
2446 MEDCouplingTimeDiscretization *td=_time_discr->deviator();
2447 td->copyTinyAttrFrom(*_time_discr);
2448 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2449 ret->setName("Deviator");
2450 ret->setMesh(getMesh());
2455 * Creates a new MEDCouplingFieldDouble filled with the magnitude of
2456 * every vector of \a this field.
2457 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2458 * having one component, whose each tuple is the magnitude of the vector
2459 * of corresponding tuple of \a this field. This new field lies on the
2460 * same mesh as \a this one. The caller is to
2461 * delete this field using decrRef() as it is no more needed.
2462 * \throw If the spatial discretization of \a this field is NULL.
2464 MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const throw(INTERP_KERNEL::Exception)
2466 if(!((const MEDCouplingFieldDiscretization *)_type))
2467 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform magnitude !");
2468 MEDCouplingTimeDiscretization *td=_time_discr->magnitude();
2469 td->copyTinyAttrFrom(*_time_discr);
2470 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2471 ret->setName("Magnitude");
2472 ret->setMesh(getMesh());
2477 * Creates a new scalar MEDCouplingFieldDouble filled with the maximal value among
2478 * values of every tuple of \a this field.
2479 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2480 * This new field lies on the same mesh as \a this one. The caller is to
2481 * delete this field using decrRef() as it is no more needed.
2482 * \throw If the spatial discretization of \a this field is NULL.
2484 MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception)
2486 if(!((const MEDCouplingFieldDiscretization *)_type))
2487 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform maxPerTuple !");
2488 MEDCouplingTimeDiscretization *td=_time_discr->maxPerTuple();
2489 td->copyTinyAttrFrom(*_time_discr);
2490 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2491 std::ostringstream oss;
2492 oss << "Max_" << getName();
2493 ret->setName(oss.str().c_str());
2494 ret->setMesh(getMesh());
2499 * Changes number of components in \a this field. If \a newNbOfComp is less
2500 * than \a this->getNumberOfComponents() then each tuple
2501 * is truncated to have \a newNbOfComp components, keeping first components. If \a
2502 * newNbOfComp is more than \a this->getNumberOfComponents() then
2503 * each tuple is populated with \a dftValue to have \a newNbOfComp components.
2504 * \param [in] newNbOfComp - number of components for the new field to have.
2505 * \param [in] dftValue - value assigned to new values added to \a this field.
2506 * \throw If \a this is not allocated.
2508 void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftValue) throw(INTERP_KERNEL::Exception)
2510 _time_discr->changeNbOfComponents(newNbOfComp,dftValue);
2514 * Creates a new MEDCouplingFieldDouble composed of selected components of \a this field.
2515 * The new MEDCouplingFieldDouble has the same number of tuples but includes components
2516 * specified by \a compoIds parameter. So that getNbOfElems() of the result field
2517 * can be either less, same or more than \a this->getNumberOfValues().
2518 * \param [in] compoIds - sequence of zero based indices of components to include
2519 * into the new field.
2520 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble that the caller
2521 * is to delete using decrRef() as it is no more needed.
2522 * \throw If a component index (\a i) is not valid:
2523 * \a i < 0 || \a i >= \a this->getNumberOfComponents().
2525 MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
2527 if(!((const MEDCouplingFieldDiscretization *)_type))
2528 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform keepSelectedComponents !");
2529 MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds);
2530 td->copyTinyAttrFrom(*_time_discr);
2531 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2532 ret->setName(getName());
2533 ret->setMesh(getMesh());
2539 * Copy all components in a specified order from another field.
2540 * The number of tuples in \a this and the other field can be different.
2541 * \param [in] f - the field to copy data from.
2542 * \param [in] compoIds - sequence of zero based indices of components, data of which is
2544 * \throw If the two fields have different number of data arrays.
2545 * \throw If a data array is set in one of fields and is not set in the other.
2546 * \throw If \a compoIds.size() != \a a->getNumberOfComponents().
2547 * \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
2549 void MEDCouplingFieldDouble::setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
2551 _time_discr->setSelectedComponents(f->_time_discr,compoIds);
2555 * Sorts value within every tuple of \a this field.
2556 * \param [in] asc - if \a true, the values are sorted in ascending order, else,
2557 * in descending order.
2558 * \throw If a data array is not allocated.
2560 void MEDCouplingFieldDouble::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception)
2562 _time_discr->sortPerTuple(asc);
2566 * Creates a new MEDCouplingFieldDouble by concatenating two given fields.
2568 * the first field precede values of the second field within the result field.
2569 * \param [in] f1 - the first field.
2570 * \param [in] f2 - the second field.
2571 * \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2572 * MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef()
2573 * as it is no more needed.
2574 * \throw If the fields are not compatible for the merge.
2575 * \throw If \a f2->getMesh() == NULL.
2576 * \throw If the spatial discretization of \a f1 is NULL.
2577 * \throw If the time discretization of \a f1 is NULL.
2579 * \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2580 * \ref py_mcfielddouble_MergeFields "Here is a Python example".
2582 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2584 if(!f1->areCompatibleForMerge(f2))
2585 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !");
2586 const MEDCouplingMesh *m1=f1->getMesh();
2587 const MEDCouplingMesh *m2=f2->getMesh();
2589 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no underlying mesh of f1 !");
2590 if(!f1->_time_discr)
2591 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no time discr of f1 !");
2593 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no spatial discr of f1 !");
2594 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=m1->mergeMyselfWith(m2);
2595 MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr);
2596 td->copyTinyAttrFrom(*f1->_time_discr);
2597 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2599 ret->setName(f1->getName());
2600 ret->setDescription(f1->getDescription());
2605 * Creates a new MEDCouplingFieldDouble by concatenating all given fields.
2606 * Values of the *i*-th field precede values of the (*i*+1)-th field within the result.
2607 * If there is only one field in \a a, a deepCopy() (except time information of mesh and
2608 * field) of the field is returned.
2609 * Generally speaking the first field in \a a is used to assign tiny attributes of the
2611 * \param [in] a - a vector of fields (MEDCouplingFieldDouble) to concatenate.
2612 * \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2613 * MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef()
2614 * as it is no more needed.
2615 * \throw If \a a is empty.
2616 * \throw If the fields are not compatible for the merge.
2617 * \throw If \a a[ i ]->getMesh() == NULL.
2619 * \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2620 * \ref py_mcfielddouble_MergeFields "Here is a Python example".
2622 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector<const MEDCouplingFieldDouble *>& a) throw(INTERP_KERNEL::Exception)
2625 throw INTERP_KERNEL::Exception("FieldDouble::MergeFields : size of array must be >= 1 !");
2626 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > ms(a.size());
2627 std::vector< const MEDCouplingUMesh *> ms2(a.size());
2628 std::vector< const MEDCouplingTimeDiscretization *> tds(a.size());
2629 std::vector<const MEDCouplingFieldDouble *>::const_iterator it=a.begin();
2630 const MEDCouplingFieldDouble *ref=(*it++);
2632 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : presence of NULL instance in first place of input vector !");
2633 for(;it!=a.end();it++)
2634 if(!ref->areCompatibleForMerge(*it))
2635 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !");
2636 for(int i=0;i<(int)a.size();i++)
2638 if(!a[i]->getMesh())
2639 throw INTERP_KERNEL::Exception("MergeFields : A field as no underlying mesh !");
2640 ms[i]=a[i]->getMesh()->buildUnstructured();
2642 tds[i]=a[i]->_time_discr;
2644 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDCouplingUMesh::MergeUMeshes(ms2);
2645 m->setName(ms2[0]->getName()); m->setDescription(ms2[0]->getDescription());
2646 MEDCouplingTimeDiscretization *td=tds[0]->aggregate(tds);
2647 td->copyTinyAttrFrom(*(a[0]->_time_discr));
2648 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone());
2650 ret->setName(a[0]->getName());
2651 ret->setDescription(a[0]->getDescription());
2656 * Creates a new MEDCouplingFieldDouble by concatenating components of two given fields.
2657 * The number of components in the result field is a sum of the number of components of
2658 * given fields. The number of tuples in the result field is same as that of each of given
2660 * Number of tuples in the given fields must be the same.
2661 * \param [in] f1 - a field to include in the result field.
2662 * \param [in] f2 - another field to include in the result field.
2663 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2664 * The caller is to delete this result field using decrRef() as it is no more
2666 * \throw If the fields are not compatible for a meld (areCompatibleForMeld()).
2667 * \throw If any of data arrays is not allocated.
2668 * \throw If \a f1->getNumberOfTuples() != \a f2->getNumberOfTuples()
2670 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MeldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2672 if(!f1->areCompatibleForMeld(f2))
2673 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MeldFields on them !");
2674 MEDCouplingTimeDiscretization *td=f1->_time_discr->meld(f2->_time_discr);
2675 td->copyTinyAttrFrom(*f1->_time_discr);
2676 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2677 ret->setMesh(f1->getMesh());
2682 * Returns a new MEDCouplingFieldDouble containing a dot product of two given fields,
2683 * so that the i-th tuple of the result field is a sum of products of j-th components of
2684 * i-th tuples of given fields (\f$ f_i = \sum_{j=1}^n f1_j * f2_j \f$).
2685 * Number of tuples and components in the given fields must be the same.
2686 * \param [in] f1 - a given field.
2687 * \param [in] f2 - another given field.
2688 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2689 * The caller is to delete this result field using decrRef() as it is no more
2691 * \throw If either \a f1 or \a f2 is NULL.
2692 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2693 * differ not only in values.
2695 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2698 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DotFields : input field is NULL !");
2699 if(!f1->areStrictlyCompatible(f2))
2700 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DotFields on them !");
2701 MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr);
2702 td->copyTinyAttrFrom(*f1->_time_discr);
2703 MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2704 ret->setMesh(f1->getMesh());
2709 * Returns a new MEDCouplingFieldDouble containing a cross product of two given fields,
2711 * the i-th tuple of the result field is a 3D vector which is a cross
2712 * product of two vectors defined by the i-th tuples of given fields.
2713 * Number of tuples in the given fields must be the same.
2714 * Number of components in the given fields must be 3.
2715 * \param [in] f1 - a given field.
2716 * \param [in] f2 - another given field.
2717 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2718 * The caller is to delete this result field using decrRef() as it is no more
2720 * \throw If either \a f1 or \a f2 is NULL.
2721 * \throw If \a f1->getNumberOfComponents() != 3
2722 * \throw If \a f2->getNumberOfComponents() != 3
2723 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2724 * differ not only in values.
2726 MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2729 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::CrossProductFields : input field is NULL !");
2730 if(!f1->areStrictlyCompatible(f2))
2731 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply CrossProductFields on them !");
2732 MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr);
2733 td->copyTinyAttrFrom(*f1->_time_discr);
2734 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2735 ret->setMesh(f1->getMesh());
2740 * Returns a new MEDCouplingFieldDouble containing maximal values of two given fields.
2741 * Number of tuples and components in the given fields must be the same.
2742 * \param [in] f1 - a field to compare values with another one.
2743 * \param [in] f2 - another field to compare values with the first one.
2744 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2745 * The caller is to delete this result field using decrRef() as it is no more
2747 * \throw If either \a f1 or \a f2 is NULL.
2748 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2749 * differ not only in values.
2751 * \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2752 * \ref py_mcfielddouble_MaxFields "Here is a Python example".
2754 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2757 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MaxFields : input field is NULL !");
2758 if(!f1->areStrictlyCompatible(f2))
2759 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MaxFields on them !");
2760 MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr);
2761 td->copyTinyAttrFrom(*f1->_time_discr);
2762 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2763 ret->setMesh(f1->getMesh());
2768 * Returns a new MEDCouplingFieldDouble containing minimal values of two given fields.
2769 * Number of tuples and components in the given fields must be the same.
2770 * \param [in] f1 - a field to compare values with another one.
2771 * \param [in] f2 - another field to compare values with the first one.
2772 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2773 * The caller is to delete this result field using decrRef() as it is no more
2775 * \throw If either \a f1 or \a f2 is NULL.
2776 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2777 * differ not only in values.
2779 * \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2780 * \ref py_mcfielddouble_MaxFields "Here is a Python example".
2782 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2785 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MinFields : input field is NULL !");
2786 if(!f1->areStrictlyCompatible(f2))
2787 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MinFields on them !");
2788 MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr);
2789 td->copyTinyAttrFrom(*f1->_time_discr);
2790 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2791 ret->setMesh(f1->getMesh());
2796 * Returns a copy of \a this field in which sign of all values is reversed.
2797 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble
2798 * containing the same number of tuples and components as \a this field.
2799 * The caller is to delete this result field using decrRef() as it is no more
2801 * \throw If the spatial discretization of \a this field is NULL.
2802 * \throw If a data array is not allocated.
2804 MEDCouplingFieldDouble *MEDCouplingFieldDouble::negate() const throw(INTERP_KERNEL::Exception)
2806 if(!((const MEDCouplingFieldDiscretization *)_type))
2807 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform negate !");
2808 MEDCouplingTimeDiscretization *td=_time_discr->negate();
2809 td->copyTinyAttrFrom(*_time_discr);
2810 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2811 ret->setMesh(getMesh());
2816 * Returns a new MEDCouplingFieldDouble containing sum values of corresponding values of
2817 * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] + _f2_ [ i, j ] ).
2818 * Number of tuples and components in the given fields must be the same.
2819 * \param [in] f1 - a field to sum up.
2820 * \param [in] f2 - another field to sum up.
2821 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2822 * The caller is to delete this result field using decrRef() as it is no more
2824 * \throw If either \a f1 or \a f2 is NULL.
2825 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2826 * differ not only in values.
2828 MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2831 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::AddFields : input field is NULL !");
2832 if(!f1->areStrictlyCompatible(f2))
2833 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply AddFields on them !");
2834 MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr);
2835 td->copyTinyAttrFrom(*f1->_time_discr);
2836 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2837 ret->setMesh(f1->getMesh());
2842 * Adds values of another MEDCouplingFieldDouble to values of \a this one
2843 * ( _this_ [ i, j ] += _other_ [ i, j ] ) using DataArrayDouble::addEqual().
2844 * The two fields must have same number of tuples, components and same underlying mesh.
2845 * \param [in] other - the field to add to \a this one.
2846 * \return const MEDCouplingFieldDouble & - a reference to \a this field.
2847 * \throw If \a other is NULL.
2848 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2849 * differ not only in values.
2851 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
2853 if(!areStrictlyCompatible(&other))
2854 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply += on them !");
2855 _time_discr->addEqual(other._time_discr);
2860 * Returns a new MEDCouplingFieldDouble containing subtraction of corresponding values of
2861 * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] - _f2_ [ i, j ] ).
2862 * Number of tuples and components in the given fields must be the same.
2863 * \param [in] f1 - a field to subtract from.
2864 * \param [in] f2 - a field to subtract.
2865 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2866 * The caller is to delete this result field using decrRef() as it is no more
2868 * \throw If either \a f1 or \a f2 is NULL.
2869 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2870 * differ not only in values.
2872 MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2875 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::SubstractFields : input field is NULL !");
2876 if(!f1->areStrictlyCompatible(f2))
2877 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply SubstractFields on them !");
2878 MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr);
2879 td->copyTinyAttrFrom(*f1->_time_discr);
2880 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2881 ret->setMesh(f1->getMesh());
2886 * Subtract values of another MEDCouplingFieldDouble from values of \a this one
2887 * ( _this_ [ i, j ] -= _other_ [ i, j ] ) using DataArrayDouble::substractEqual().
2888 * The two fields must have same number of tuples, components and same underlying mesh.
2889 * \param [in] other - the field to subtract from \a this one.
2890 * \return const MEDCouplingFieldDouble & - a reference to \a this field.
2891 * \throw If \a other is NULL.
2892 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2893 * differ not only in values.
2895 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
2897 if(!areStrictlyCompatible(&other))
2898 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply -= on them !");
2899 _time_discr->substractEqual(other._time_discr);
2904 * Returns a new MEDCouplingFieldDouble containing product values of
2905 * two given fields. There are 2 valid cases.
2906 * 1. The fields have same number of tuples and components. Then each value of
2907 * the result field (_f_) is a product of the corresponding values of _f1_ and
2908 * _f2_, i.e. _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, j ].
2909 * 2. The fields have same number of tuples and one field, say _f2_, has one
2911 * _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, 0 ].
2913 * The two fields must have same number of tuples and same underlying mesh.
2914 * \param [in] f1 - a factor field.
2915 * \param [in] f2 - another factor field.
2916 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2917 * The caller is to delete this result field using decrRef() as it is no more
2919 * \throw If either \a f1 or \a f2 is NULL.
2920 * \throw If the fields are not compatible for production (areCompatibleForMul()),
2921 * i.e. they differ not only in values and possibly number of components.
2923 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2926 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MultiplyFields : input field is NULL !");
2927 if(!f1->areCompatibleForMul(f2))
2928 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MultiplyFields on them !");
2929 MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr);
2930 td->copyTinyAttrFrom(*f1->_time_discr);
2931 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2932 ret->setMesh(f1->getMesh());
2937 * Multiply values of another MEDCouplingFieldDouble to values of \a this one
2938 * using DataArrayDouble::multiplyEqual().
2939 * The two fields must have same number of tuples and same underlying mesh.
2940 * There are 2 valid cases.
2941 * 1. The fields have same number of components. Then each value of
2942 * \a other is multiplied to the corresponding value of \a this field, i.e.
2943 * _this_ [ i, j ] *= _other_ [ i, j ].
2944 * 2. The _other_ field has one component. Then
2945 * _this_ [ i, j ] *= _other_ [ i, 0 ].
2947 * The two fields must have same number of tuples and same underlying mesh.
2948 * \param [in] other - an field to multiply to \a this one.
2949 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2950 * The caller is to delete this result field using decrRef() as it is no more
2952 * \throw If \a other is NULL.
2953 * \throw If the fields are not strictly compatible for production
2954 * (areCompatibleForMul()),
2955 * i.e. they differ not only in values and possibly in number of components.
2957 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
2959 if(!areCompatibleForMul(&other))
2960 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply *= on them !");
2961 _time_discr->multiplyEqual(other._time_discr);
2966 * Returns a new MEDCouplingFieldDouble containing division of two given fields.
2967 * There are 2 valid cases.
2968 * 1. The fields have same number of tuples and components. Then each value of
2969 * the result field (_f_) is a division of the corresponding values of \a f1 and
2970 * \a f2, i.e. _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, j ].
2971 * 2. The fields have same number of tuples and _f2_ has one component. Then
2972 * _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, 0 ].
2974 * \param [in] f1 - a numerator field.
2975 * \param [in] f2 - a denominator field.
2976 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2977 * The caller is to delete this result field using decrRef() as it is no more
2979 * \throw If either \a f1 or \a f2 is NULL.
2980 * \throw If the fields are not compatible for division (areCompatibleForDiv()),
2981 * i.e. they differ not only in values and possibly in number of components.
2983 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
2986 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DivideFields : input field is NULL !");
2987 if(!f1->areCompatibleForDiv(f2))
2988 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DivideFields on them !");
2989 MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr);
2990 td->copyTinyAttrFrom(*f1->_time_discr);
2991 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2992 ret->setMesh(f1->getMesh());
2997 * Divide values of \a this field by values of another MEDCouplingFieldDouble
2998 * using DataArrayDouble::divideEqual().
2999 * The two fields must have same number of tuples and same underlying mesh.
3000 * There are 2 valid cases.
3001 * 1. The fields have same number of components. Then each value of
3002 * \a this field is divided by the corresponding value of \a other one, i.e.
3003 * _this_ [ i, j ] /= _other_ [ i, j ].
3004 * 2. The \a other field has one component. Then
3005 * _this_ [ i, j ] /= _other_ [ i, 0 ].
3007 * \warning No check of division by zero is performed!
3008 * \param [in] other - an field to divide \a this one by.
3009 * \throw If \a other is NULL.
3010 * \throw If the fields are not compatible for division (areCompatibleForDiv()),
3011 * i.e. they differ not only in values and possibly in number of components.
3013 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
3015 if(!areCompatibleForDiv(&other))
3016 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !");
3017 _time_discr->divideEqual(other._time_discr);
3022 * Directly called by MEDCouplingFieldDouble::operator^.
3024 * \sa MEDCouplingFieldDouble::operator^
3026 MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception)
3029 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::PowFields : input field is NULL !");
3030 if(!f1->areCompatibleForMul(f2))
3031 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply PowFields on them !");
3032 MEDCouplingTimeDiscretization *td=f1->_time_discr->pow(f2->_time_discr);
3033 td->copyTinyAttrFrom(*f1->_time_discr);
3034 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3035 ret->setMesh(f1->getMesh());
3040 * Directly call MEDCouplingFieldDouble::PowFields static method.
3042 * \sa MEDCouplingFieldDouble::PowFields
3044 MEDCouplingFieldDouble *MEDCouplingFieldDouble::operator^(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception)
3046 return PowFields(this,&other);
3049 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
3051 if(!areCompatibleForDiv(&other))
3052 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !");
3053 _time_discr->powEqual(other._time_discr);
3058 * Writes the field series \a fs and the mesh the fields lie on in the VTK file \a fileName.
3059 * If \a fs is empty no file is written.
3060 * The result file is valid provided that no exception is thrown.
3061 * \warning All the fields must be named and lie on the same non NULL mesh.
3062 * \param [in] fileName - the name of a VTK file to write in.
3063 * \param [in] fs - the fields to write.
3064 * \throw If \a fs[ 0 ] == NULL.
3065 * \throw If the fields lie not on the same mesh.
3066 * \throw If the mesh is not set.
3067 * \throw If any of the fields has no name.
3069 * \ref cpp_mcfielddouble_WriteVTK "Here is a C++ example".<br>
3070 * \ref py_mcfielddouble_WriteVTK "Here is a Python example".
3072 void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector<const MEDCouplingFieldDouble *>& fs) throw(INTERP_KERNEL::Exception)
3076 std::size_t nfs=fs.size();
3078 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field is NULL !");
3079 const MEDCouplingMesh *m=fs[0]->getMesh();
3081 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field lies on NULL mesh !");
3082 for(std::size_t i=1;i<nfs;i++)
3083 if(fs[i]->getMesh()!=m)
3084 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.");
3086 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are lying on a same mesh but it is empty !");
3087 std::ostringstream coss,noss;
3088 for(std::size_t i=0;i<nfs;i++)
3090 const MEDCouplingFieldDouble *cur=fs[i];
3091 std::string name(cur->getName());
3094 std::ostringstream oss; oss << "MEDCouplingFieldDouble::WriteVTK : Field in pos #" << i << " has no name !";
3095 throw INTERP_KERNEL::Exception(oss.str().c_str());
3097 TypeOfField typ=cur->getTypeOfField();
3099 cur->getArray()->writeVTK(coss,8,cur->getName());
3100 else if(typ==ON_NODES)
3101 cur->getArray()->writeVTK(noss,8,cur->getName());
3103 m->writeVTKAdvanced(fileName,coss.str(),noss.str());
3106 void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const throw(INTERP_KERNEL::Exception)
3108 stream << "MEDCouplingFieldDouble C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
3112 nat=MEDCouplingNatureOfField::GetRepr(_nature);
3113 stream << "Nature of field : " << nat << ".\n";
3115 catch(INTERP_KERNEL::Exception& e)
3117 const MEDCouplingFieldDiscretization *fd(_type);
3119 stream << "No spatial discretization set !";
3121 fd->reprQuickOverview(stream);
3122 stream << std::endl;
3124 stream << "\nNo mesh support defined !";
3127 std::ostringstream oss;
3128 _mesh->reprQuickOverview(oss);
3129 std::string tmp(oss.str());
3130 stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
3134 const DataArrayDouble *arr=_time_discr->getArray();
3137 stream << "\n\nArray info : ";
3138 arr->reprQuickOverview(stream);
3142 stream << "\n\nNo data array set !";