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()
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().c_str());
216 ret->setDescription(getDescription().c_str());
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)
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)
248 _time_discr->copyTinyAttrFrom(*other->_time_discr);
253 void MEDCouplingFieldDouble::copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other)
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, bool isBinary) const
357 std::vector<const MEDCouplingFieldDouble *> fs(1,this);
358 MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary);
361 bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const
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 * ** Warning, this method modifies the mesh aggreagated by \a this (by performing a deep copy ) **.
489 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
490 * to be equal to \a this->getMesh()->getNumberOfCells().
491 * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
492 * array, so that its maximal cell id to correspond to (be less than) the number
493 * of cells in mesh. This new array is then used for the renumbering. If \a
494 * check == \c false, \a old2NewBg is used as is, that is less secure as validity
495 * of ids in \a old2NewBg is not checked.
496 * \throw If the mesh is not set.
497 * \throw If the spatial discretization of \a this field is NULL.
498 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
499 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
501 * \ref cpp_mcfielddouble_renumberCells "Here is a C++ example".<br>
502 * \ref py_mcfielddouble_renumberCells "Here is a Python example".
504 void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check)
506 renumberCellsWithoutMesh(old2NewBg,check);
507 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_mesh->deepCpy();
508 m->renumberCells(old2NewBg,check);
514 * Permutes values of \a this field according to a given permutation array for cells
515 * renumbering. The underlying mesh is \b not permuted.
516 * The number of cells remains the same; for that the permutation array \a old2NewBg
517 * should not contain equal ids.
518 * This method performs a part of job of renumberCells(). The reasonable use of this
519 * method is only for multi-field instances lying on the same mesh to avoid a
520 * systematic duplication and renumbering of _mesh attribute.
521 * \warning Use this method with a lot of care!
522 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
523 * to be equal to \a this->getMesh()->getNumberOfCells().
524 * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
525 * array, so that its maximal cell id to correspond to (be less than) the number
526 * of cells in mesh. This new array is then used for the renumbering. If \a
527 * check == \c false, \a old2NewBg is used as is, that is less secure as validity
528 * of ids in \a old2NewBg is not checked.
529 * \throw If the mesh is not set.
530 * \throw If the spatial discretization of \a this field is NULL.
531 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
532 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
534 void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool check)
537 throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !");
538 if(!((const MEDCouplingFieldDiscretization *)_type))
539 throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
541 _type->renumberCells(old2NewBg,check);
542 std::vector<DataArrayDouble *> arrays;
543 _time_discr->getArrays(arrays);
544 std::vector<DataArray *> arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin());
545 _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check);
551 * Permutes values of \a this field according to a given permutation array for node
552 * renumbering. The underlying mesh is deeply copied and its nodes are also permuted.
553 * The number of nodes can change, contrary to renumberCells().
554 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
555 * to be equal to \a this->getMesh()->getNumberOfNodes().
556 * \param [in] eps - a precision used to compare field values at merged nodes. If
557 * the values differ more than \a eps, an exception is thrown.
558 * \throw If the mesh is not set.
559 * \throw If the spatial discretization of \a this field is NULL.
560 * \throw If \a check == \c true and \a old2NewBg contains equal ids.
561 * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
562 * \throw If values at merged nodes deffer more than \a eps.
564 * \ref cpp_mcfielddouble_renumberNodes "Here is a C++ example".<br>
565 * \ref py_mcfielddouble_renumberNodes "Here is a Python example".
567 void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg, double eps)
569 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
571 throw INTERP_KERNEL::Exception("Invalid mesh to apply renumberNodes on it !");
572 int nbOfNodes=meshC->getNumberOfNodes();
573 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
574 int newNbOfNodes=*std::max_element(old2NewBg,old2NewBg+nbOfNodes)+1;
575 renumberNodesWithoutMesh(old2NewBg,newNbOfNodes,eps);
576 meshC2->renumberNodes(old2NewBg,newNbOfNodes);
581 * Permutes values of \a this field according to a given permutation array for nodes
582 * renumbering. The underlying mesh is \b not permuted.
583 * The number of nodes can change, contrary to renumberCells().
584 * A given epsilon specifies a threshold of error in case of two nodes are merged but
585 * the difference of values on these nodes are higher than \a eps.
586 * This method performs a part of job of renumberNodes(), excluding node renumbering
587 * in mesh. The reasonable use of this
588 * method is only for multi-field instances lying on the same mesh to avoid a
589 * systematic duplication and renumbering of _mesh attribute.
590 * \warning Use this method with a lot of care!
591 * \warning In case of an exception thrown, the contents of the data array can be
592 * partially modified until the exception occurs.
593 * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
594 * to be equal to \a this->getMesh()->getNumberOfNodes().
595 * \param [in] newNbOfNodes - a number of nodes in the mesh after renumbering.
596 * \param [in] eps - a precision used to compare field values at merged nodes. If
597 * the values differ more than \a eps, an exception is thrown.
598 * \throw If the mesh is not set.
599 * \throw If the spatial discretization of \a this field is NULL.
600 * \throw If values at merged nodes deffer more than \a eps.
602 void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps)
604 if(!((const MEDCouplingFieldDiscretization *)_type))
605 throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
606 std::vector<DataArrayDouble *> arrays;
607 _time_discr->getArrays(arrays);
608 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
610 _type->renumberValuesOnNodes(eps,old2NewBg,newNbOfNodes,*iter);
614 * Returns all tuple ids of \a this scalar field that fit the range [\a vmin,
615 * \a vmax]. This method calls DataArrayDouble::getIdsInRange().
616 * \param [in] vmin - a lower boundary of the range. Tuples with values less than \a
617 * vmin are not included in the result array.
618 * \param [in] vmax - an upper boundary of the range. Tuples with values more than \a
619 * vmax are not included in the result array.
620 * \return DataArrayInt * - a new instance of DataArrayInt holding ids of selected
621 * tuples. The caller is to delete this array using decrRef() as it is no
623 * \throw If the data array is not set.
624 * \throw If \a this->getNumberOfComponents() != 1.
626 DataArrayInt *MEDCouplingFieldDouble::getIdsInRange(double vmin, double vmax) const
629 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getIdsInRange : no default array set !");
630 return getArray()->getIdsInRange(vmin,vmax);
634 * Builds a newly created field, that the caller will have the responsability to deal with (decrRef()).
635 * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done.
636 * 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.
637 * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (
638 * \ref ParaMEDMEM::ON_CELLS "ON_CELLS",
639 * \ref ParaMEDMEM::ON_NODES "ON_NODES",
640 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT",
641 * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
642 * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
644 * 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].
645 * Then the returned field will lie on mesh having 3 cells and the returned field will contain 3 tuples.<br>
646 * 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>
647 * 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>
648 * 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().
650 * 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].
651 * 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
652 * will contain 6 tuples and \a this field will lie on this restricted mesh.
654 * \param [in] part - an array of cell ids to include to the result field.
655 * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The caller is to delete this field using decrRef() as it is no more needed.
657 * \ref cpp_mcfielddouble_subpart1 "Here is a C++ example".<br>
658 * \ref py_mcfielddouble_subpart1 "Here is a Python example".
659 * \sa MEDCouplingFieldDouble::buildSubPartRange
662 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *part) const
665 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : not empty array must be passed to this method !");
666 return buildSubPart(part->begin(),part->end());
670 * Builds a newly created field, that the caller will have the responsability to deal with.
671 * \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**.
672 * \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.
673 * \n Parameter [\a partBg, \a partEnd ) specifies **cell ids whatever the spatial discretization** of \a this (
674 * \ref ParaMEDMEM::ON_CELLS "ON_CELLS",
675 * \ref ParaMEDMEM::ON_NODES "ON_NODES",
676 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT",
677 * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
678 * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
680 * 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].
681 * Then the returned field will lie on mesh having 3 cells and will contain 3 tuples.
682 *- 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().
683 *- 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().
684 *- 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().
686 * 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].
687 * 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
688 * will contain 6 tuples and \a this field will lie on this restricted mesh.
690 * \param [in] partBg - start (included) of input range of cell ids to select [ \a partBg, \a partEnd )
691 * \param [in] partEnd - end (not included) of input range of cell ids to select [ \a partBg, \a partEnd )
692 * \return a newly allocated field the caller should deal with.
694 * \throw if there is presence of an invalid cell id in [ \a partBg, \a partEnd ) regarding the number of cells of \a this->getMesh().
696 * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."<br>
697 * \ref py_mcfielddouble_subpart1 "Here a Python example."
698 * \sa ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
700 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const
702 if(!((const MEDCouplingFieldDiscretization *)_type))
703 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
704 DataArrayInt *arrSelect;
705 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
706 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arrSelect2(arrSelect);
707 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
708 const MEDCouplingFieldDiscretization *disc=getDiscretization();
710 ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization>(disc->clonePart(partBg,partEnd)));
712 std::vector<DataArrayDouble *> arrays;
713 _time_discr->getArrays(arrays);
714 std::vector<DataArrayDouble *> arrs;
715 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrsSafe;
716 const int *arrSelBg=arrSelect->begin();
717 const int *arrSelEnd=arrSelect->end();
718 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
720 DataArrayDouble *arr=0;
722 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
723 arrs.push_back(arr); arrsSafe.push_back(arr);
725 ret->_time_discr->setArrays(arrs,0);
730 * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is
731 * given using a range given \a begin, \a end and \a step to optimize the part computation.
733 * \sa MEDCouplingFieldDouble::buildSubPart
735 MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int end, int step) const
737 if(!((const MEDCouplingFieldDiscretization *)_type))
738 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
739 DataArrayInt *arrSelect;
740 int beginOut,endOut,stepOut;
741 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect);
742 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arrSelect2(arrSelect);
743 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
744 const MEDCouplingFieldDiscretization *disc=getDiscretization();
746 ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization>(disc->clonePartRange(begin,end,step)));
748 std::vector<DataArrayDouble *> arrays;
749 _time_discr->getArrays(arrays);
750 std::vector<DataArrayDouble *> arrs;
751 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrsSafe;
752 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
754 DataArrayDouble *arr=0;
759 const int *arrSelBg=arrSelect->begin();
760 const int *arrSelEnd=arrSelect->end();
761 arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
764 arr=(*iter)->selectByTupleId2(beginOut,endOut,stepOut);
766 arrs.push_back(arr); arrsSafe.push_back(arr);
768 ret->_time_discr->setArrays(arrs,0);
773 * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field.
774 * \return ParaMEDMEM::TypeOfTimeDiscretization - an enum item describing the time
775 * discretization type.
777 TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const
779 return _time_discr->getEnum();
782 MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),
783 _time_discr(MEDCouplingTimeDiscretization::New(td))
788 * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! **
790 MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false),
791 _time_discr(MEDCouplingTimeDiscretization::New(td))
795 MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingField(other,deepCopy),
796 _time_discr(other._time_discr->performCpy(deepCopy))
800 MEDCouplingFieldDouble::MEDCouplingFieldDouble(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td)
804 MEDCouplingFieldDouble::~MEDCouplingFieldDouble()
810 * Checks if \a this field is correctly defined, else an exception is thrown.
811 * \throw If the mesh is not set.
812 * \throw If the data array is not set.
813 * \throw If the spatial discretization of \a this field is NULL.
814 * \throw If \a this->getTimeTolerance() < 0.
815 * \throw If the temporal discretization data is incorrect.
816 * \throw If mesh data does not correspond to field data.
818 void MEDCouplingFieldDouble::checkCoherency() const
821 throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !");
822 if(!((const MEDCouplingFieldDiscretization *)_type))
823 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::checkCoherency : no spatial discretization !");
824 _time_discr->checkCoherency();
825 _type->checkCoherencyBetween(_mesh,getArray());
829 * Accumulate values of a given component of \a this field.
830 * \param [in] compId - the index of the component of interest.
831 * \return double - a sum value of *compId*-th component.
832 * \throw If the data array is not set.
833 * \throw If \a the condition ( 0 <= \a compId < \a this->getNumberOfComponents() ) is
836 double MEDCouplingFieldDouble::accumulate(int compId) const
839 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
840 return getArray()->accumulate(compId);
844 * Accumulates values of each component of \a this array.
845 * \param [out] res - an array of length \a this->getNumberOfComponents(), allocated
846 * by the caller, that is filled by this method with sum value for each
848 * \throw If the data array is not set.
850 void MEDCouplingFieldDouble::accumulate(double *res) const
853 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::accumulate : no default array defined !");
854 getArray()->accumulate(res);
858 * Returns the maximal value within \a this scalar field. Values of all arrays stored
859 * in \a this->_time_discr are checked.
860 * \return double - the maximal value among all values of \a this field.
861 * \throw If \a this->getNumberOfComponents() != 1
862 * \throw If the data array is not set.
863 * \throw If there is an empty data array in \a this field.
865 double MEDCouplingFieldDouble::getMaxValue() const
867 std::vector<DataArrayDouble *> arrays;
868 _time_discr->getArrays(arrays);
869 double ret=-std::numeric_limits<double>::max();
870 bool isExistingArr=false;
871 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
877 ret=std::max(ret,(*iter)->getMaxValue(loc));
881 throw INTERP_KERNEL::Exception("getMaxValue : No arrays defined !");
886 * Returns the maximal value and all its locations within \a this scalar field.
887 * Only the first of available data arrays is checked.
888 * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
889 * tuples holding the maximal value. The caller is to delete it using
890 * decrRef() as it is no more needed.
891 * \return double - the maximal value among all values of the first array of \a this filed.
892 * \throw If \a this->getNumberOfComponents() != 1.
893 * \throw If there is an empty data array in \a this field.
895 double MEDCouplingFieldDouble::getMaxValue2(DataArrayInt*& tupleIds) const
897 std::vector<DataArrayDouble *> arrays;
898 _time_discr->getArrays(arrays);
899 double ret=-std::numeric_limits<double>::max();
900 bool isExistingArr=false;
902 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1;
903 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
909 ret=std::max(ret,(*iter)->getMaxValue2(tmp));
910 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmpSafe(tmp);
911 if(!((const DataArrayInt *)ret1))
916 throw INTERP_KERNEL::Exception("getMaxValue2 : No arrays defined !");
917 tupleIds=ret1.retn();
922 * Returns the minimal value within \a this scalar field. Values of all arrays stored
923 * in \a this->_time_discr are checked.
924 * \return double - the minimal value among all values of \a this field.
925 * \throw If \a this->getNumberOfComponents() != 1
926 * \throw If the data array is not set.
927 * \throw If there is an empty data array in \a this field.
929 double MEDCouplingFieldDouble::getMinValue() const
931 std::vector<DataArrayDouble *> arrays;
932 _time_discr->getArrays(arrays);
933 double ret=std::numeric_limits<double>::max();
934 bool isExistingArr=false;
935 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
941 ret=std::min(ret,(*iter)->getMinValue(loc));
945 throw INTERP_KERNEL::Exception("getMinValue : No arrays defined !");
950 * Returns the minimal value and all its locations within \a this scalar field.
951 * Only the first of available data arrays is checked.
952 * \param [out] tupleIds - a new instance of DataArrayInt containg indices of
953 * tuples holding the minimal value. The caller is to delete it using
954 * decrRef() as it is no more needed.
955 * \return double - the minimal value among all values of the first array of \a this filed.
956 * \throw If \a this->getNumberOfComponents() != 1.
957 * \throw If there is an empty data array in \a this field.
959 double MEDCouplingFieldDouble::getMinValue2(DataArrayInt*& tupleIds) const
961 std::vector<DataArrayDouble *> arrays;
962 _time_discr->getArrays(arrays);
963 double ret=-std::numeric_limits<double>::max();
964 bool isExistingArr=false;
966 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1;
967 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
973 ret=std::max(ret,(*iter)->getMinValue2(tmp));
974 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmpSafe(tmp);
975 if(!((const DataArrayInt *)ret1))
980 throw INTERP_KERNEL::Exception("getMinValue2 : No arrays defined !");
981 tupleIds=ret1.retn();
986 * Returns the average value of \a this scalar field.
987 * \return double - the average value over all values of the data array.
988 * \throw If \a this->getNumberOfComponents() != 1
989 * \throw If the data array is not set or it is empty.
991 double MEDCouplingFieldDouble::getAverageValue() const
994 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getAverageValue : no default array defined !");
995 return getArray()->getAverageValue();
999 * This method returns the euclidean norm of \a this field.
1001 * \sqrt{\sum_{0 \leq i < nbOfEntity}val[i]*val[i]}
1003 * \throw If the data array is not set.
1005 double MEDCouplingFieldDouble::norm2() const
1008 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::norm2 : no default array defined !");
1009 return getArray()->norm2();
1013 * This method returns the max norm of \a this field.
1015 * \max_{0 \leq i < nbOfEntity}{abs(val[i])}
1017 * \throw If the data array is not set.
1019 double MEDCouplingFieldDouble::normMax() const
1022 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::normMax : no default array defined !");
1023 return getArray()->normMax();
1027 * Computes sums of values of each component of \a this field wighted with
1028 * values returned by buildMeasureField().
1029 * \param [out] res - pointer to an array of result sum values, of size at least \a
1030 * this->getNumberOfComponents(), that is to be allocated by the caller.
1031 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1032 * buildMeasureField() that makes this method slower. If a user is sure that all
1033 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1034 * \c false that speeds up this method.
1035 * \throw If the mesh is not set.
1036 * \throw If the data array is not set.
1038 void MEDCouplingFieldDouble::getWeightedAverageValue(double *res, bool isWAbs) const
1041 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getWeightedAverageValue : no default array defined !");
1042 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> w=buildMeasureField(isWAbs);
1043 double deno=w->getArray()->accumulate(0);
1044 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=getArray()->deepCpy();
1045 arr->multiplyEqual(w->getArray());
1046 std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::multiplies<double>(),1./deno));
1047 arr->accumulate(res);
1051 * Computes a sum of values of a given component of \a this field wighted with
1052 * values returned by buildMeasureField().
1053 * \param [in] compId - an index of the component of interest.
1054 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1055 * buildMeasureField() that makes this method slower. If a user is sure that all
1056 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1057 * \c false that speeds up this method.
1058 * \throw If the mesh is not set.
1059 * \throw If the data array is not set.
1060 * \throw If \a compId is not valid.
1061 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1063 double MEDCouplingFieldDouble::getWeightedAverageValue(int compId, bool isWAbs) const
1065 int nbComps=getArray()->getNumberOfComponents();
1066 if(compId<0 || compId>=nbComps)
1068 std::ostringstream oss; oss << "MEDCouplingFieldDouble::getWeightedAverageValue : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1069 throw INTERP_KERNEL::Exception(oss.str().c_str());
1071 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1072 getWeightedAverageValue(res,isWAbs);
1077 * Returns the \c normL1 of values of a given component of \a this field:
1079 * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1081 * \param [in] compId - an index of the component of interest.
1082 * \throw If the mesh is not set.
1083 * \throw If the spatial discretization of \a this field is NULL.
1084 * \throw If \a compId is not valid.
1085 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1087 double MEDCouplingFieldDouble::normL1(int compId) const
1090 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1 !");
1091 if(!((const MEDCouplingFieldDiscretization *)_type))
1092 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1093 int nbComps=getArray()->getNumberOfComponents();
1094 if(compId<0 || compId>=nbComps)
1096 std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL1 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1097 throw INTERP_KERNEL::Exception(oss.str().c_str());
1099 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1100 _type->normL1(_mesh,getArray(),res);
1105 * Returns the \c normL1 of values of each component of \a this field:
1107 * \frac{\sum_{0 \leq i < nbOfEntity}|val[i]*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}
1109 * \param [out] res - pointer to an array of result values, of size at least \a
1110 * this->getNumberOfComponents(), that is to be allocated by the caller.
1111 * \throw If the mesh is not set.
1112 * \throw If the spatial discretization of \a this field is NULL.
1114 void MEDCouplingFieldDouble::normL1(double *res) const
1117 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL1");
1118 if(!((const MEDCouplingFieldDiscretization *)_type))
1119 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL1 !");
1120 _type->normL1(_mesh,getArray(),res);
1124 * Returns the \c normL2 of values of a given component of \a this field:
1126 * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1128 * \param [in] compId - an index of the component of interest.
1129 * \throw If the mesh is not set.
1130 * \throw If the spatial discretization of \a this field is NULL.
1131 * \throw If \a compId is not valid.
1132 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1134 double MEDCouplingFieldDouble::normL2(int compId) const
1137 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1138 if(!((const MEDCouplingFieldDiscretization *)_type))
1139 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1140 int nbComps=getArray()->getNumberOfComponents();
1141 if(compId<0 || compId>=nbComps)
1143 std::ostringstream oss; oss << "MEDCouplingFieldDouble::normL2 : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1144 throw INTERP_KERNEL::Exception(oss.str().c_str());
1146 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1147 _type->normL2(_mesh,getArray(),res);
1152 * Returns the \c normL2 of values of each component of \a this field:
1154 * \sqrt{\frac{\sum_{0 \leq i < nbOfEntity}|val[i]^{2}*Vol[i]|}{\sum_{0 \leq i < nbOfEntity}|Vol[i]|}}
1156 * \param [out] res - pointer to an array of result values, of size at least \a
1157 * this->getNumberOfComponents(), that is to be allocated by the caller.
1158 * \throw If the mesh is not set.
1159 * \throw If the spatial discretization of \a this field is NULL.
1161 void MEDCouplingFieldDouble::normL2(double *res) const
1164 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform normL2");
1165 if(!((const MEDCouplingFieldDiscretization *)_type))
1166 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform normL2 !");
1167 _type->normL2(_mesh,getArray(),res);
1171 * Computes a sum of values of a given component of \a this field multiplied by
1172 * values returned by buildMeasureField().
1173 * This method is useful to check the conservativity of interpolation method.
1174 * \param [in] compId - an index of the component of interest.
1175 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1176 * buildMeasureField() that makes this method slower. If a user is sure that all
1177 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1178 * \c false that speeds up this method.
1179 * \throw If the mesh is not set.
1180 * \throw If the data array is not set.
1181 * \throw If \a compId is not valid.
1182 A valid range is ( 0 <= \a compId < \a this->getNumberOfComponents() ).
1184 double MEDCouplingFieldDouble::integral(int compId, bool isWAbs) const
1187 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral");
1188 if(!((const MEDCouplingFieldDiscretization *)_type))
1189 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral !");
1190 int nbComps=getArray()->getNumberOfComponents();
1191 if(compId<0 || compId>=nbComps)
1193 std::ostringstream oss; oss << "MEDCouplingFieldDouble::integral : Invalid compId specified : No such nb of components ! Should be in [0," << nbComps << ") !";
1194 throw INTERP_KERNEL::Exception(oss.str().c_str());
1196 INTERP_KERNEL::AutoPtr<double> res=new double[nbComps];
1197 _type->integral(_mesh,getArray(),isWAbs,res);
1202 * Computes a sum of values of each component of \a this field multiplied by
1203 * values returned by buildMeasureField().
1204 * This method is useful to check the conservativity of interpolation method.
1205 * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by
1206 * buildMeasureField() that makes this method slower. If a user is sure that all
1207 * cells of the underlying mesh have correct orientation, he can put \a isWAbs ==
1208 * \c false that speeds up this method.
1209 * \param [out] res - pointer to an array of result sum values, of size at least \a
1210 * this->getNumberOfComponents(), that is to be allocated by the caller.
1211 * \throw If the mesh is not set.
1212 * \throw If the data array is not set.
1213 * \throw If the spatial discretization of \a this field is NULL.
1215 void MEDCouplingFieldDouble::integral(bool isWAbs, double *res) const
1218 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform integral2");
1219 if(!((const MEDCouplingFieldDiscretization *)_type))
1220 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform integral2 !");
1221 _type->integral(_mesh,getArray(),isWAbs,res);
1225 * Returns a value at a given cell of a structured mesh. The cell is specified by its
1227 * \param [in] i - a index of node coordinates array along X axis. The cell is
1228 * located between the i-th and ( i + 1 )-th nodes along X axis.
1229 * \param [in] j - a index of node coordinates array along Y axis. The cell is
1230 * located between the j-th and ( j + 1 )-th nodes along Y axis.
1231 * \param [in] k - a index of node coordinates array along Z axis. The cell is
1232 * located between the k-th and ( k + 1 )-th nodes along Z axis.
1233 * \param [out] res - pointer to an array returning a feild value, of size at least
1234 * \a this->getNumberOfComponents(), that is to be allocated by the caller.
1235 * \throw If the spatial discretization of \a this field is NULL.
1236 * \throw If the mesh is not set.
1237 * \throw If the mesh is not a structured one.
1239 * \ref cpp_mcfielddouble_getValueOnPos "Here is a C++ example".<br>
1240 * \ref py_mcfielddouble_getValueOnPos "Here is a Python example".
1242 void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) const
1244 const DataArrayDouble *arr=_time_discr->getArray();
1246 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnPos");
1247 if(!((const MEDCouplingFieldDiscretization *)_type))
1248 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1249 _type->getValueOnPos(arr,_mesh,i,j,k,res);
1253 * Returns a value of \a this at a given point using spatial discretization.
1254 * \param [in] spaceLoc - the point of interest.
1255 * \param [out] res - pointer to an array returning a feild value, of size at least
1256 * \a this->getNumberOfComponents(), that is to be allocated by the caller.
1257 * \throw If the spatial discretization of \a this field is NULL.
1258 * \throw If the mesh is not set.
1259 * \throw If \a spaceLoc is out of the spatial discretization.
1261 * \ref cpp_mcfielddouble_getValueOn "Here is a C++ example".<br>
1262 * \ref py_mcfielddouble_getValueOn "Here is a Python example".
1264 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) const
1266 const DataArrayDouble *arr=_time_discr->getArray();
1268 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1269 if(!((const MEDCouplingFieldDiscretization *)_type))
1270 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnPos !");
1271 _type->getValueOn(arr,_mesh,spaceLoc,res);
1275 * Returns values of \a this at given points using spatial discretization.
1276 * \param [in] spaceLoc - coordinates of points of interest in full-interlace
1277 * mode. This array is to be of size ( \a nbOfPoints * \a this->getNumberOfComponents() ).
1278 * \param [in] nbOfPoints - number of points of interest.
1279 * \return DataArrayDouble * - a new instance of DataArrayDouble holding field
1280 * values relating to the input points. This array is of size \a nbOfPoints
1281 * tuples per \a this->getNumberOfComponents() components. The caller is to
1282 * delete this array using decrRef() as it is no more needed.
1283 * \throw If the spatial discretization of \a this field is NULL.
1284 * \throw If the mesh is not set.
1285 * \throw If any point in \a spaceLoc is out of the spatial discretization.
1287 * \ref cpp_mcfielddouble_getValueOnMulti "Here is a C++ example".<br>
1288 * \ref py_mcfielddouble_getValueOnMulti "Here is a Python example".
1290 DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, int nbOfPoints) const
1292 const DataArrayDouble *arr=_time_discr->getArray();
1294 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOnMulti");
1295 if(!((const MEDCouplingFieldDiscretization *)_type))
1296 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOnMulti !");
1297 return _type->getValueOnMulti(arr,_mesh,spaceLoc,nbOfPoints);
1301 * Returns a value of \a this field at a given point at a given time using spatial discretization.
1302 * If the time is not covered by \a this->_time_discr, an exception is thrown.
1303 * \param [in] spaceLoc - the point of interest.
1304 * \param [in] time - the time of interest.
1305 * \param [out] res - pointer to an array returning a feild value, of size at least
1306 * \a this->getNumberOfComponents(), that is to be allocated by the caller.
1307 * \throw If the spatial discretization of \a this field is NULL.
1308 * \throw If the mesh is not set.
1309 * \throw If \a spaceLoc is out of the spatial discretization.
1310 * \throw If \a time is not covered by \a this->_time_discr.
1312 * \ref cpp_mcfielddouble_getValueOn_time "Here is a C++ example".<br>
1313 * \ref py_mcfielddouble_getValueOn_time "Here is a Python example".
1315 void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, double *res) const
1317 std::vector< const DataArrayDouble *> arrs=_time_discr->getArraysForTime(time);
1319 throw INTERP_KERNEL::Exception("No mesh underlying this field to perform getValueOn");
1320 if(!((const MEDCouplingFieldDiscretization *)_type))
1321 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getValueOn !");
1322 std::vector<double> res2;
1323 for(std::vector< const DataArrayDouble *>::const_iterator iter=arrs.begin();iter!=arrs.end();iter++)
1325 int sz=(int)res2.size();
1326 res2.resize(sz+(*iter)->getNumberOfComponents());
1327 _type->getValueOn(*iter,_mesh,spaceLoc,&res2[sz]);
1329 _time_discr->getValueForTime(time,res2,res);
1333 * Apply a liner function to a given component of \a this field, so that
1334 * a component value <em>(x)</em> becomes \f$ a * x + b \f$.
1335 * \param [in] a - the first coefficient of the function.
1336 * \param [in] b - the second coefficient of the function.
1337 * \param [in] compoId - the index of component to modify.
1338 * \throw If the data array(s) is(are) not set.
1340 void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId)
1342 _time_discr->applyLin(a,b,compoId);
1346 * This method sets \a this to a uniform scalar field with one component.
1347 * All tuples will have the same value 'value'.
1348 * An exception is thrown if no underlying mesh is defined.
1350 MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) throw(INTERP_KERNEL::Exception)
1353 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !");
1354 if(!((const MEDCouplingFieldDiscretization *)_type))
1355 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform operator = !");
1356 int nbOfTuple=_type->getNumberOfTuples(_mesh);
1357 _time_discr->setOrCreateUniformValueOnAllComponents(nbOfTuple,value);
1362 * Creates data array(s) of \a this field by using a C function for value generation.
1363 * \param [in] nbOfComp - the number of components for \a this field to have.
1364 * \param [in] func - the function used to compute values of \a this field.
1365 * This function is to compute a field value basing on coordinates of value
1367 * \throw If the mesh is not set.
1368 * \throw If \a func returns \c false.
1369 * \throw If the spatial discretization of \a this field is NULL.
1371 * \ref cpp_mcfielddouble_fillFromAnalytic_c_func "Here is a C++ example".
1373 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate func)
1376 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1377 if(!((const MEDCouplingFieldDiscretization *)_type))
1378 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1379 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1380 _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1384 * Creates data array(s) of \a this field by using a function for value generation.<br>
1385 * The function is applied to coordinates of value location points. For example, if
1386 * \a this field is on cells, the function is applied to cell barycenters.
1387 * For more info on supported expressions that can be used in the function, see \ref
1388 * MEDCouplingArrayApplyFuncExpr. <br>
1389 * The function can include arbitrary named variables
1390 * (e.g. "x","y" or "va44") to refer to components of point coordinates. Names of
1391 * variables are sorted in \b alphabetical \b order to associate a variable name with a
1392 * component. For example, in the expression "2*x+z", "x" stands for the component #0
1393 * and "z" stands for the component #1 (\b not #2)!<br>
1394 * In a general case, a value resulting from the function evaluation is assigned to all
1395 * components of a field value. But there is a possibility to have its own expression for
1396 * each component within one function. For this purpose, there are predefined variable
1397 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1398 * the component #0 etc). A factor of such a variable is added to the
1399 * corresponding component only.<br>
1400 * For example, \a nbOfComp == 4, coordinates of a 3D point are (1.,3.,7.), then
1401 * - "2*x + z" produces (5.,5.,5.,5.)
1402 * - "2*x + 0*y + z" produces (9.,9.,9.,9.)
1403 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1404 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1406 * \param [in] nbOfComp - the number of components for \a this field to have.
1407 * \param [in] func - the function used to compute values of \a this field.
1408 * This function is used to compute a field value basing on coordinates of value
1409 * location point. For example, if \a this field is on cells, the function
1410 * is applied to cell barycenters.
1411 * \throw If the mesh is not set.
1412 * \throw If the spatial discretization of \a this field is NULL.
1413 * \throw If computing \a func fails.
1415 * \ref cpp_mcfielddouble_fillFromAnalytic "Here is a C++ example".<br>
1416 * \ref py_mcfielddouble_fillFromAnalytic "Here is a Python example".
1418 void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func)
1421 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !");
1422 if(!((const MEDCouplingFieldDiscretization *)_type))
1423 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic !");
1424 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1425 _time_discr->fillFromAnalytic(loc,nbOfComp,func);
1429 * Creates data array(s) of \a this field by using a function for value generation.<br>
1430 * The function is applied to coordinates of value location points. For example, if
1431 * \a this field is on cells, the function is applied to cell barycenters.<br>
1432 * This method differs from
1433 * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) "fillFromAnalytic()"
1434 * by the way how variable
1435 * names, used in the function, are associated with components of coordinates of field
1436 * location points; here, a variable name corresponding to a component is retrieved from
1437 * a corresponding node coordinates array (where it is set via
1438 * DataArrayDouble::setInfoOnComponent()).<br>
1439 * For more info on supported expressions that can be used in the function, see \ref
1440 * MEDCouplingArrayApplyFuncExpr. <br>
1441 * In a general case, a value resulting from the function evaluation is assigned to all
1442 * components of a field value. But there is a possibility to have its own expression for
1443 * each component within one function. For this purpose, there are predefined variable
1444 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1445 * the component #0 etc). A factor of such a variable is added to the
1446 * corresponding component only.<br>
1447 * For example, \a nbOfComp == 4, names of spatial components are "x", "y" and "z",
1448 * coordinates of a 3D point are (1.,3.,7.), then
1449 * - "2*x + z" produces (9.,9.,9.,9.)
1450 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1451 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1453 * \param [in] nbOfComp - the number of components for \a this field to have.
1454 * \param [in] func - the function used to compute values of \a this field.
1455 * This function is used to compute a field value basing on coordinates of value
1456 * location point. For example, if \a this field is on cells, the function
1457 * is applied to cell barycenters.
1458 * \throw If the mesh is not set.
1459 * \throw If the spatial discretization of \a this field is NULL.
1460 * \throw If computing \a func fails.
1462 * \ref cpp_mcfielddouble_fillFromAnalytic2 "Here is a C++ example".<br>
1463 * \ref py_mcfielddouble_fillFromAnalytic2 "Here is a Python example".
1465 void MEDCouplingFieldDouble::fillFromAnalytic2(int nbOfComp, const char *func)
1468 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !");
1469 if(!((const MEDCouplingFieldDiscretization *)_type))
1470 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic2 !");
1471 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1472 _time_discr->fillFromAnalytic2(loc,nbOfComp,func);
1476 * Creates data array(s) of \a this field by using a function for value generation.<br>
1477 * The function is applied to coordinates of value location points. For example, if
1478 * \a this field is on cells, the function is applied to cell barycenters.<br>
1479 * This method differs from
1480 * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) "fillFromAnalytic()"
1481 * by the way how variable
1482 * names, used in the function, are associated with components of coordinates of field
1483 * location points; here, a component index of a variable is defined by a
1484 * rank of the variable within the input array \a varsOrder.<br>
1485 * For more info on supported expressions that can be used in the function, see \ref
1486 * MEDCouplingArrayApplyFuncExpr.
1487 * In a general case, a value resulting from the function evaluation is assigned to all
1488 * components of a field value. But there is a possibility to have its own expression for
1489 * each component within one function. For this purpose, there are predefined variable
1490 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1491 * the component #0 etc). A factor of such a variable is added to the
1492 * corresponding component only.<br>
1493 * For example, \a nbOfComp == 4, names of
1494 * spatial components are given in \a varsOrder: ["x", "y","z"], coordinates of a
1495 * 3D point are (1.,3.,7.), then
1496 * - "2*x + z" produces (9.,9.,9.,9.)
1497 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1498 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1500 * \param [in] nbOfComp - the number of components for \a this field to have.
1501 * \param [in] func - the function used to compute values of \a this field.
1502 * This function is used to compute a field value basing on coordinates of value
1503 * location point. For example, if \a this field is on cells, the function
1504 * is applied to cell barycenters.
1505 * \throw If the mesh is not set.
1506 * \throw If the spatial discretization of \a this field is NULL.
1507 * \throw If computing \a func fails.
1509 * \ref cpp_mcfielddouble_fillFromAnalytic3 "Here is a C++ example".<br>
1510 * \ref py_mcfielddouble_fillFromAnalytic3 "Here is a Python example".
1512 void MEDCouplingFieldDouble::fillFromAnalytic3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func)
1515 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !");
1516 if(!((const MEDCouplingFieldDiscretization *)_type))
1517 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform fillFromAnalytic3 !");
1518 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> loc=_type->getLocalizationOfDiscValues(_mesh);
1519 _time_discr->fillFromAnalytic3(loc,nbOfComp,varsOrder,func);
1523 * Modifies values of \a this field by applying a C function to each tuple of all
1525 * \param [in] nbOfComp - the number of components for \a this field to have.
1526 * \param [in] func - the function used to compute values of \a this field.
1527 * This function is to compute a field value basing on a current field value.
1528 * \throw If \a func returns \c false.
1530 * \ref cpp_mcfielddouble_applyFunc_c_func "Here is a C++ example".
1532 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, FunctionToEvaluate func)
1534 _time_discr->applyFunc(nbOfComp,func);
1538 * Fill \a this field with a given value.<br>
1539 * This method is a specialization of other overloaded methods. When \a nbOfComp == 1
1540 * this method is equivalent to ParaMEDMEM::MEDCouplingFieldDouble::operator=().
1541 * \param [in] nbOfComp - the number of components for \a this field to have.
1542 * \param [in] val - the value to assign to every atomic value of \a this field.
1543 * \throw If the spatial discretization of \a this field is NULL.
1544 * \throw If the mesh is not set.
1546 * \ref cpp_mcfielddouble_applyFunc_val "Here is a C++ example".<br>
1547 * \ref py_mcfielddouble_applyFunc_val "Here is a Python example".
1549 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val)
1552 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::applyFunc : no mesh defined !");
1553 if(!((const MEDCouplingFieldDiscretization *)_type))
1554 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform applyFunc !");
1555 int nbOfTuple=_type->getNumberOfTuples(_mesh);
1556 _time_discr->setUniformValue(nbOfTuple,nbOfComp,val);
1560 * Modifies values of \a this field by applying a function to each tuple of all
1562 * For more info on supported expressions that can be used in the function, see \ref
1563 * MEDCouplingArrayApplyFuncExpr. <br>
1564 * The function can include arbitrary named variables
1565 * (e.g. "x","y" or "va44") to refer to components of a field value. Names of
1566 * variables are sorted in \b alphabetical \b order to associate a variable name with a
1567 * component. For example, in the expression "2*x+z", "x" stands for the component #0
1568 * and "z" stands for the component #1 (\b not #2)!<br>
1569 * In a general case, a value resulting from the function evaluation is assigned to all
1570 * components of a field value. But there is a possibility to have its own expression for
1571 * each component within one function. For this purpose, there are predefined variable
1572 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1573 * the component #0 etc). A factor of such a variable is added to the
1574 * corresponding component only.<br>
1575 * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1576 * - "2*x + z" produces (5.,5.,5.,5.)
1577 * - "2*x + 0*y + z" produces (9.,9.,9.,9.)
1578 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1579 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1581 * \param [in] nbOfComp - the number of components for \a this field to have.
1582 * \param [in] func - the function used to compute values of \a this field.
1583 * This function is to compute a field value basing on a current field value.
1584 * \throw If computing \a func fails.
1586 * \ref cpp_mcfielddouble_applyFunc "Here is a C++ example".<br>
1587 * \ref py_mcfielddouble_applyFunc "Here is a Python example".
1589 void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func)
1591 _time_discr->applyFunc(nbOfComp,func);
1596 * Modifies values of \a this field by applying a function to each tuple of all
1598 * For more info on supported expressions that can be used in the function, see \ref
1599 * MEDCouplingArrayApplyFuncExpr. <br>
1600 * This method differs from
1601 * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) "applyFunc()"
1602 * by the way how variable
1603 * names, used in the function, are associated with components of field values;
1604 * here, a variable name corresponding to a component is retrieved from
1605 * component information of an array (where it is set via
1606 * DataArrayDouble::setInfoOnComponent()).<br>
1607 * In a general case, a value resulting from the function evaluation is assigned to all
1608 * components of a field value. But there is a possibility to have its own expression for
1609 * each component within one function. For this purpose, there are predefined variable
1610 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1611 * the component #0 etc). A factor of such a variable is added to the
1612 * corresponding component only.<br>
1613 * For example, \a nbOfComp == 4, components of a field value are (1.,3.,7.), then
1614 * - "2*x + z" produces (5.,5.,5.,5.)
1615 * - "2*x + 0*y + z" produces (9.,9.,9.,9.)
1616 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,4.)
1617 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,4.)
1619 * \param [in] nbOfComp - the number of components for \a this field to have.
1620 * \param [in] func - the function used to compute values of \a this field.
1621 * This function is to compute a new field value basing on a current field value.
1622 * \throw If computing \a func fails.
1624 * \ref cpp_mcfielddouble_applyFunc2 "Here is a C++ example".<br>
1625 * \ref py_mcfielddouble_applyFunc2 "Here is a Python example".
1627 void MEDCouplingFieldDouble::applyFunc2(int nbOfComp, const char *func)
1629 _time_discr->applyFunc2(nbOfComp,func);
1633 * Modifies values of \a this field by applying a function to each tuple of all
1635 * This method differs from
1636 * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) "applyFunc()"
1637 * by the way how variable
1638 * names, used in the function, are associated with components of field values;
1639 * here, a component index of a variable is defined by a
1640 * rank of the variable within the input array \a varsOrder.<br>
1641 * For more info on supported expressions that can be used in the function, see \ref
1642 * MEDCouplingArrayApplyFuncExpr.
1643 * In a general case, a value resulting from the function evaluation is assigned to all
1644 * components of a field value. But there is a possibility to have its own expression for
1645 * each component within one function. For this purpose, there are predefined variable
1646 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1647 * the component #0 etc). A factor of such a variable is added to the
1648 * corresponding component only.<br>
1649 * For example, \a nbOfComp == 4, names of
1650 * components are given in \a varsOrder: ["x", "y","z"], components of a
1651 * 3D vector are (1.,3.,7.), then
1652 * - "2*x + z" produces (9.,9.,9.,9.)
1653 * - "2*x*IVec + (x+z)*LVec" produces (2.,0.,0.,8.)
1654 * - "2*y*IVec + z*KVec + x" produces (7.,1.,1.,8.)
1656 * \param [in] nbOfComp - the number of components for \a this field to have.
1657 * \param [in] func - the function used to compute values of \a this field.
1658 * This function is to compute a new field value basing on a current field value.
1659 * \throw If computing \a func fails.
1661 * \ref cpp_mcfielddouble_applyFunc3 "Here is a C++ example".<br>
1662 * \ref py_mcfielddouble_applyFunc3 "Here is a Python example".
1664 void MEDCouplingFieldDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func)
1666 _time_discr->applyFunc3(nbOfComp,varsOrder,func);
1670 * Modifies values of \a this field by applying a function to each atomic value of all
1671 * data arrays. The function computes a new single value basing on an old single value.
1672 * For more info on supported expressions that can be used in the function, see \ref
1673 * MEDCouplingArrayApplyFuncExpr. <br>
1674 * The function can include **only one** arbitrary named variable
1675 * (e.g. "x","y" or "va44") to refer to a field atomic value. <br>
1676 * In a general case, a value resulting from the function evaluation is assigned to
1677 * a single field value. But there is a possibility to have its own expression for
1678 * each component within one function. For this purpose, there are predefined variable
1679 * names (IVec, JVec, KVec, LVec etc) each dedicated to a certain component (IVec, to
1680 * the component #0 etc). A factor of such a variable is added to the
1681 * corresponding component only.<br>
1682 * For example, components of a field value are (1.,3.,7.), then
1683 * - "2*x - 1" produces (1.,5.,13.)
1684 * - "2*x*IVec + (x+3)*KVec" produces (2.,0.,10.)
1685 * - "2*x*IVec + (x+3)*KVec + 1" produces (3.,1.,11.)
1687 * \param [in] func - the function used to compute values of \a this field.
1688 * This function is to compute a field value basing on a current field value.
1689 * \throw If computing \a func fails.
1691 * \ref cpp_mcfielddouble_applyFunc_same_nb_comp "Here is a C++ example".<br>
1692 * \ref py_mcfielddouble_applyFunc_same_nb_comp "Here is a Python example".
1694 void MEDCouplingFieldDouble::applyFunc(const char *func)
1696 _time_discr->applyFunc(func);
1700 * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1701 * The field will contain exactly the same number of components after the call.
1702 * Use is not warranted for the moment !
1704 void MEDCouplingFieldDouble::applyFuncFast32(const char *func)
1706 _time_discr->applyFuncFast32(func);
1710 * Applyies the function specified by the string repr 'func' on each tuples on all arrays contained in _time_discr.
1711 * The field will contain exactly the same number of components after the call.
1712 * Use is not warranted for the moment !
1714 void MEDCouplingFieldDouble::applyFuncFast64(const char *func)
1716 _time_discr->applyFuncFast64(func);
1720 * Returns number of components in the data array. For more info on the data arrays,
1721 * see \ref MEDCouplingArrayPage.
1722 * \return int - the number of components in the data array.
1723 * \throw If the data array is not set.
1725 int MEDCouplingFieldDouble::getNumberOfComponents() const
1728 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfComponents : No array specified !");
1729 return getArray()->getNumberOfComponents();
1733 * Returns number of tuples in \a this field, that depends on
1734 * - the number of entities in the underlying mesh
1735 * - \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field (e.g. number
1736 * of Gauss points if \a this->getTypeOfField() ==
1737 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT").
1739 * The returned value does **not depend** on the number of tuples in the data array
1740 * (which has to be equal to the returned value), \b contrary to
1741 * getNumberOfComponents() and getNumberOfValues() that retrieve information from the
1743 * \warning No checkCoherency() is done here.
1744 * For more info on the data arrays, see \ref MEDCouplingArrayPage.
1745 * \return int - the number of tuples.
1746 * \throw If the mesh is not set.
1747 * \throw If the spatial discretization of \a this field is NULL.
1748 * \throw If the spatial discretization is not fully defined.
1750 int MEDCouplingFieldDouble::getNumberOfTuples() const
1753 throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !");
1754 if(!((const MEDCouplingFieldDiscretization *)_type))
1755 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getNumberOfTuples !");
1756 return _type->getNumberOfTuples(_mesh);
1760 * Returns number of atomic double values in the data array of \a this field.
1761 * For more info on the data arrays, see \ref MEDCouplingArrayPage.
1762 * \return int - (number of tuples) * (number of components) of the
1764 * \throw If the data array is not set.
1766 int MEDCouplingFieldDouble::getNumberOfValues() const
1769 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getNumberOfValues : No array specified !");
1770 return getArray()->getNbOfElems();
1774 * Sets own modification time by the most recently modified element of data (the mesh,
1775 * the data array etc). For more info, see \ref MEDCouplingTimeLabelPage.
1777 void MEDCouplingFieldDouble::updateTime() const
1779 MEDCouplingField::updateTime();
1780 updateTimeWith(*_time_discr);
1783 std::size_t MEDCouplingFieldDouble::getHeapMemorySizeWithoutChildren() const
1785 return MEDCouplingField::getHeapMemorySizeWithoutChildren();
1788 std::vector<const BigMemoryObject *> MEDCouplingFieldDouble::getDirectChildren() const
1790 std::vector<const BigMemoryObject *> ret(MEDCouplingField::getDirectChildren());
1793 std::vector<const BigMemoryObject *> ret2(_time_discr->getDirectChildren());
1794 ret.insert(ret.end(),ret2.begin(),ret2.end());
1800 * Sets \ref NatureOfField.
1801 * \param [in] nat - an item of enum ParaMEDMEM::NatureOfField.
1803 void MEDCouplingFieldDouble::setNature(NatureOfField nat)
1805 MEDCouplingField::setNature(nat);
1807 _type->checkCompatibilityWithNature(nat);
1811 * This method synchronizes time information (time, iteration, order, time unit) regarding the information in \c this->_mesh.
1812 * \throw If no mesh is set in this. Or if \a this is not compatible with time setting (typically NO_TIME)
1814 void MEDCouplingFieldDouble::synchronizeTimeWithMesh()
1817 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::synchronizeTimeWithMesh : no mesh set in this !");
1819 double val=_mesh->getTime(it,ordr);
1820 std::string timeUnit(_mesh->getTimeUnit());
1821 setTime(val,it,ordr);
1822 setTimeUnit(timeUnit.c_str());
1826 * Returns a value of \a this field of type either
1827 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" or
1828 * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
1829 * \param [in] cellId - an id of cell of interest.
1830 * \param [in] nodeIdInCell - a node index within the cell.
1831 * \param [in] compoId - an index of component.
1832 * \return double - the field value corresponding to the specified parameters.
1833 * \throw If the data array is not set.
1834 * \throw If the mesh is not set.
1835 * \throw If the spatial discretization of \a this field is NULL.
1836 * \throw If \a this field if of type other than
1837 * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT" or
1838 * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE".
1840 double MEDCouplingFieldDouble::getIJK(int cellId, int nodeIdInCell, int compoId) const
1842 if(!((const MEDCouplingFieldDiscretization *)_type))
1843 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getIJK !");
1844 return _type->getIJK(_mesh,getArray(),cellId,nodeIdInCell,compoId);
1848 * Sets the data array.
1849 * \param [in] array - the data array holding values of \a this field. It's size
1850 * should correspond to the mesh and
1851 * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
1852 * (see getNumberOfTuples()), but this size is not checked here.
1854 void MEDCouplingFieldDouble::setArray(DataArrayDouble *array)
1856 _time_discr->setArray(array,this);
1860 * Sets the data array holding values corresponding to an end of a time interval
1861 * for which \a this field is defined.
1862 * \param [in] array - the data array holding values of \a this field. It's size
1863 * should correspond to the mesh and
1864 * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
1865 * (see getNumberOfTuples()), but this size is not checked here.
1867 void MEDCouplingFieldDouble::setEndArray(DataArrayDouble *array)
1869 _time_discr->setEndArray(array,this);
1873 * Sets all data arrays needed to define the field values.
1874 * \param [in] arrs - a vector of DataArrayDouble's holding values of \a this
1875 * field. Size of each array should correspond to the mesh and
1876 * \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field
1877 * (see getNumberOfTuples()), but this size is not checked here.
1878 * \throw If number of arrays in \a arrs does not correspond to type of
1879 * \ref MEDCouplingTemporalDisc "temporal discretization" of \a this field.
1881 void MEDCouplingFieldDouble::setArrays(const std::vector<DataArrayDouble *>& arrs)
1883 _time_discr->setArrays(arrs,this);
1886 void MEDCouplingFieldDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
1889 _time_discr->getTinySerializationStrInformation(tinyInfo);
1890 tinyInfo.push_back(_name);
1891 tinyInfo.push_back(_desc);
1892 tinyInfo.push_back(getTimeUnit());
1896 * This method retrieves some critical values to resize and prepare remote instance.
1897 * The first two elements returned in tinyInfo correspond to the parameters to give in constructor.
1898 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
1900 void MEDCouplingFieldDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
1902 if(!((const MEDCouplingFieldDiscretization *)_type))
1903 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationIntInformation !");
1905 tinyInfo.push_back((int)_type->getEnum());
1906 tinyInfo.push_back((int)_time_discr->getEnum());
1907 tinyInfo.push_back((int)_nature);
1908 _time_discr->getTinySerializationIntInformation(tinyInfo);
1909 std::vector<int> tinyInfo2;
1910 _type->getTinySerializationIntInformation(tinyInfo2);
1911 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
1912 tinyInfo.push_back((int)tinyInfo2.size());
1916 * This method retrieves some critical values to resize and prepare remote instance.
1917 * @param tinyInfo out parameter resized correctly after the call. The length of this vector is tiny.
1919 void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector<double>& tinyInfo) const
1921 if(!((const MEDCouplingFieldDiscretization *)_type))
1922 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform getTinySerializationDbleInformation !");
1924 _time_discr->getTinySerializationDbleInformation(tinyInfo);
1925 std::vector<double> tinyInfo2;
1926 _type->getTinySerializationDbleInformation(tinyInfo2);
1927 tinyInfo.insert(tinyInfo.end(),tinyInfo2.begin(),tinyInfo2.end());
1928 tinyInfo.push_back((int)tinyInfo2.size());//very bad, lack of time to improve it
1932 * This method has to be called to the new instance filled by CORBA, MPI, File...
1933 * @param tinyInfoI is the value retrieves from distant result of getTinySerializationIntInformation on source instance to be copied.
1934 * @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.
1935 * @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.
1936 * No decrRef must be applied to every instances in returned vector.
1938 void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI, DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays)
1940 if(!((const MEDCouplingFieldDiscretization *)_type))
1941 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !");
1943 std::vector<int> tinyInfoITmp(tinyInfoI);
1944 int sz=tinyInfoITmp.back();
1945 tinyInfoITmp.pop_back();
1946 std::vector<int> tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz);
1947 std::vector<int> tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end());
1948 _time_discr->resizeForUnserialization(tinyInfoI2,arrays);
1949 std::vector<int> tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end());
1950 _type->resizeForUnserialization(tinyInfoITmp3,dataInt);
1953 void MEDCouplingFieldDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<double>& tinyInfoD, const std::vector<std::string>& tinyInfoS)
1955 if(!((const MEDCouplingFieldDiscretization *)_type))
1956 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform finishUnserialization !");
1957 std::vector<int> tinyInfoI2(tinyInfoI.begin()+3,tinyInfoI.end());
1959 std::vector<double> tmp(tinyInfoD);
1960 int sz=(int)tinyInfoD.back();//very bad, lack of time to improve it
1962 std::vector<double> tmp1(tmp.begin(),tmp.end()-sz);
1963 std::vector<double> tmp2(tmp.end()-sz,tmp.end());
1965 _time_discr->finishUnserialization(tinyInfoI2,tmp1,tinyInfoS);
1966 _nature=(NatureOfField)tinyInfoI[2];
1967 _type->finishUnserialization(tmp2);
1968 int nbOfElemS=(int)tinyInfoS.size();
1969 _name=tinyInfoS[nbOfElemS-3];
1970 _desc=tinyInfoS[nbOfElemS-2];
1971 setTimeUnit(tinyInfoS[nbOfElemS-1].c_str());
1975 * Contrary to MEDCouplingPointSet class the returned arrays are \b not the responsabilities of the caller.
1976 * The values returned must be consulted only in readonly mode.
1978 void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector<DataArrayDouble *>& arrays) const
1980 if(!((const MEDCouplingFieldDiscretization *)_type))
1981 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform serialize !");
1982 _time_discr->getArrays(arrays);
1983 _type->getSerializationIntArray(dataInt);
1987 * Tries to set an \a other mesh as the support of \a this field. An attempt fails, if
1988 * a current and the \a other meshes are different with use of specified equality
1989 * criteria, and then an exception is thrown.
1990 * \param [in] other - the mesh to use as the field support if this mesh can be
1991 * considered equal to the current mesh.
1992 * \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
1993 * it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
1994 * is used for mesh comparison.
1995 * \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
1996 * It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
1997 * \param [in] eps - a precision used at node renumbering (if needed) to compare field
1998 * values at merged nodes. If the values differ more than \a eps, an
1999 * exception is thrown.
2000 * \throw If the mesh is not set.
2001 * \throw If \a other == NULL.
2002 * \throw If any of the meshes is not well defined.
2003 * \throw If the two meshes do not match.
2004 * \throw If field values at merged nodes (if any) deffer more than \a eps.
2006 * \ref cpp_mcfielddouble_changeUnderlyingMesh "Here is a C++ example".<br>
2007 * \ref py_mcfielddouble_changeUnderlyingMesh "Here is a Python example".
2009 void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps)
2011 if(_mesh==0 || other==0)
2012 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::changeUnderlyingMesh : is expected to operate on not null meshes !");
2013 DataArrayInt *cellCor=0,*nodeCor=0;
2014 other->checkGeoEquivalWith(_mesh,levOfCheck,precOnMesh,cellCor,nodeCor);
2015 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellCor2(cellCor),nodeCor2(nodeCor);
2017 renumberCellsWithoutMesh(cellCor->getConstPointer(),false);
2019 renumberNodesWithoutMesh(nodeCor->getConstPointer(),nodeCor->getMaxValueInArray()+1,eps);
2020 setMesh(const_cast<MEDCouplingMesh *>(other));
2024 * Subtracts another field from \a this one in case when the two fields have different
2025 * supporting meshes. The subtraction is performed provided that the tho meshes can be
2026 * considered equal with use of specified equality criteria, else an exception is thrown.
2027 * If the meshes match, the mesh of \a f is set to \a this field (\a this is permuted if
2028 * necessary) and field values are subtracted. No interpolation is done here, only an
2029 * analysis of two underlying mesh is done to see if the meshes are geometrically
2031 * The job of this method consists in calling
2032 * \a this->changeUnderlyingMesh() with \a f->getMesh() as the first parameter, and then
2033 * \a this -= \a f.<br>
2034 * This method requires that \a f and \a this are coherent (checkCoherency()) and that \a f
2035 * and \a this are coherent for a merge.<br>
2036 * "DM" in the method name stands for "different meshes".
2037 * \param [in] f - the field to subtract from this.
2038 * \param [in] levOfCheck - defines equality criteria used for mesh comparison. For
2039 * it's meaning explanation, see MEDCouplingMesh::checkGeoEquivalWith() which
2040 * is used for mesh comparison.
2041 * \param [in] precOnMesh - a precision used to compare nodes of the two meshes.
2042 * It is used as \a prec parameter of MEDCouplingMesh::checkGeoEquivalWith().
2043 * \param [in] eps - a precision used at node renumbering (if needed) to compare field
2044 * values at merged nodes. If the values differ more than \a eps, an
2045 * exception is thrown.
2046 * \throw If \a f == NULL.
2047 * \throw If any of the meshes is not set or is not well defined.
2048 * \throw If the two meshes do not match.
2049 * \throw If the two fields are not coherent for merge.
2050 * \throw If field values at merged nodes (if any) deffer more than \a eps.
2052 * \ref cpp_mcfielddouble_substractInPlaceDM "Here is a C++ example".<br>
2053 * \ref py_mcfielddouble_substractInPlaceDM "Here is a Python example".
2054 * \sa changeUnderlyingMesh().
2056 void MEDCouplingFieldDouble::substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps)
2060 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : input field is NULL !");
2061 f->checkCoherency();
2062 if(!areCompatibleForMerge(f))
2063 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::substractInPlaceDM : Fields are not compatible ; unable to apply mergeFields on them !");
2064 changeUnderlyingMesh(f->getMesh(),levOfCheck,precOnMesh,eps);
2069 * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2070 * underlying mesh is replaced by a new mesh instance where the coincident nodes are merged.
2071 * \param [in] eps - a precision used to compare nodes of the two meshes.
2072 * \param [in] epsOnVals - a precision used to compare field
2073 * values at merged nodes. If the values differ more than \a epsOnVals, an
2074 * exception is thrown.
2075 * \return bool - \c true if some nodes have been merged and hence \a this field lies
2077 * \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2078 * \throw If the mesh is not well defined.
2079 * \throw If the spatial discretization of \a this field is NULL.
2080 * \throw If the data array is not set.
2081 * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2083 bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals)
2085 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2087 throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2088 if(!((const MEDCouplingFieldDiscretization *)_type))
2089 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes !");
2090 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
2093 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->mergeNodes(eps,ret,ret2);
2094 if(!ret)//no nodes have been merged.
2096 std::vector<DataArrayDouble *> arrays;
2097 _time_discr->getArrays(arrays);
2098 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2100 _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2106 * Merges coincident nodes of the underlying mesh. If some nodes are coincident, the
2107 * underlying mesh is replaced by a new mesh instance where the coincident nodes are
2109 * In contrast to mergeNodes(), location of merged nodes is changed to be at their barycenter.
2110 * \param [in] eps - a precision used to compare nodes of the two meshes.
2111 * \param [in] epsOnVals - a precision used to compare field
2112 * values at merged nodes. If the values differ more than \a epsOnVals, an
2113 * exception is thrown.
2114 * \return bool - \c true if some nodes have been merged and hence \a this field lies
2116 * \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2117 * \throw If the mesh is not well defined.
2118 * \throw If the spatial discretization of \a this field is NULL.
2119 * \throw If the data array is not set.
2120 * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2122 bool MEDCouplingFieldDouble::mergeNodes2(double eps, double epsOnVals)
2124 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2126 throw INTERP_KERNEL::Exception("Invalid support mesh to apply mergeNodes on it : must be a MEDCouplingPointSet one !");
2127 if(!((const MEDCouplingFieldDiscretization *)_type))
2128 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform mergeNodes2 !");
2129 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
2132 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->mergeNodes2(eps,ret,ret2);
2133 if(!ret)//no nodes have been merged.
2135 std::vector<DataArrayDouble *> arrays;
2136 _time_discr->getArrays(arrays);
2137 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2139 _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2145 * Removes from the underlying mesh nodes not used in any cell. If some nodes are
2146 * removed, the underlying mesh is replaced by a new mesh instance where the unused
2147 * nodes are removed.<br>
2148 * \param [in] epsOnVals - a precision used to compare field
2149 * values at merged nodes. If the values differ more than \a epsOnVals, an
2150 * exception is thrown.
2151 * \return bool - \c true if some nodes have been removed and hence \a this field lies
2153 * \throw If the mesh is of type not inheriting from MEDCouplingPointSet.
2154 * \throw If the mesh is not well defined.
2155 * \throw If the spatial discretization of \a this field is NULL.
2156 * \throw If the data array is not set.
2157 * \throw If field values at merged nodes (if any) deffer more than \a epsOnVals.
2159 bool MEDCouplingFieldDouble::zipCoords(double epsOnVals)
2161 const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
2163 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipCoords : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2164 if(!((const MEDCouplingFieldDiscretization *)_type))
2165 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipCoords !");
2166 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
2167 int oldNbOfNodes=meshC2->getNumberOfNodes();
2168 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->zipCoordsTraducer();
2169 if(meshC2->getNumberOfNodes()!=oldNbOfNodes)
2171 std::vector<DataArrayDouble *> arrays;
2172 _time_discr->getArrays(arrays);
2173 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2175 _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter);
2183 * Removes duplicates of cells from the understanding mesh. If some cells are
2184 * removed, the underlying mesh is replaced by a new mesh instance where the cells
2185 * duplicates are removed.<br>
2186 * \param [in] compType - specifies a cell comparison technique. Meaning of its
2187 * valid values [0,1,2] is explained in the description of
2188 * MEDCouplingPointSet::zipConnectivityTraducer() which is called by this method.
2189 * \param [in] epsOnVals - a precision used to compare field
2190 * values at merged cells. If the values differ more than \a epsOnVals, an
2191 * exception is thrown.
2192 * \return bool - \c true if some cells have been removed and hence \a this field lies
2194 * \throw If the mesh is not an instance of MEDCouplingUMesh.
2195 * \throw If the mesh is not well defined.
2196 * \throw If the spatial discretization of \a this field is NULL.
2197 * \throw If the data array is not set.
2198 * \throw If field values at merged cells (if any) deffer more than \a epsOnVals.
2200 bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals)
2202 const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(_mesh);
2204 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::zipConnectivity : Invalid support mesh to apply zipCoords on it : must be a MEDCouplingPointSet one !");
2205 if(!((const MEDCouplingFieldDiscretization *)_type))
2206 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform zipConnectivity !");
2207 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> meshC2((MEDCouplingUMesh *)meshC->deepCpy());
2208 int oldNbOfCells=meshC2->getNumberOfCells();
2209 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->zipConnectivityTraducer(compType);
2210 if(meshC2->getNumberOfCells()!=oldNbOfCells)
2212 std::vector<DataArrayDouble *> arrays;
2213 _time_discr->getArrays(arrays);
2214 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2216 _type->renumberValuesOnCells(epsOnVals,meshC,arr->getConstPointer(),meshC2->getNumberOfCells(),*iter);
2224 * This method calls MEDCouplingUMesh::buildSlice3D method. So this method makes the assumption that underlying mesh exists.
2225 * For the moment, this method is implemented for fields on cells.
2227 * \return a newly allocated field double containing the result that the user should deallocate.
2229 MEDCouplingFieldDouble *MEDCouplingFieldDouble::extractSlice3D(const double *origin, const double *vec, double eps) const
2231 const MEDCouplingMesh *mesh=getMesh();
2233 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : underlying mesh is null !");
2234 if(getTypeOfField()!=ON_CELLS)
2235 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::extractSlice3D : only implemented for fields on cells !");
2236 const MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> umesh(mesh->buildUnstructured());
2237 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);
2238 ret->setMesh(umesh);
2239 DataArrayInt *cellIds=0;
2240 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh2=umesh->buildSlice3D(origin,vec,eps,cellIds);
2241 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIds2=cellIds;
2242 ret->setMesh(mesh2);
2243 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tupleIds=computeTupleIdsToSelectFromCellIds(cellIds->begin(),cellIds->end());
2244 std::vector<DataArrayDouble *> arrays;
2245 _time_discr->getArrays(arrays);
2247 std::vector<DataArrayDouble *> newArr(arrays.size());
2248 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > newArr2(arrays.size());
2249 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,i++)
2253 newArr2[i]=(*iter)->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
2254 newArr[i]=newArr2[i];
2257 ret->setArrays(newArr);
2262 * Divides every cell of the underlying mesh into simplices (triangles in 2D and
2263 * tetrahedra in 3D). If some cells are divided, the underlying mesh is replaced by a new
2264 * mesh instance containing the simplices.<br>
2265 * \param [in] policy - specifies a pattern used for splitting. For its description, see
2266 * MEDCouplingUMesh::simplexize().
2267 * \return bool - \c true if some cells have been divided and hence \a this field lies
2269 * \throw If \a policy has an invalid value. For valid values, see the description of
2270 * MEDCouplingUMesh::simplexize().
2271 * \throw If MEDCouplingMesh::simplexize() is not applicable to the underlying mesh.
2272 * \throw If the mesh is not well defined.
2273 * \throw If the spatial discretization of \a this field is NULL.
2274 * \throw If the data array is not set.
2276 bool MEDCouplingFieldDouble::simplexize(int policy)
2279 throw INTERP_KERNEL::Exception("No underlying mesh on this field to perform simplexize !");
2280 if(!((const MEDCouplingFieldDiscretization *)_type))
2281 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform simplexize !");
2282 int oldNbOfCells=_mesh->getNumberOfCells();
2283 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> meshC2(_mesh->deepCpy());
2284 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=meshC2->simplexize(policy);
2285 int newNbOfCells=meshC2->getNumberOfCells();
2286 if(oldNbOfCells==newNbOfCells)
2288 std::vector<DataArrayDouble *> arrays;
2289 _time_discr->getArrays(arrays);
2290 for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
2292 _type->renumberValuesOnCellsR(_mesh,arr->getConstPointer(),arr->getNbOfElems(),*iter);
2298 * Creates a new MEDCouplingFieldDouble filled with the doubly contracted product of
2299 * every tensor of \a this 6-componental field.
2300 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2301 * each tuple is calculated from the tuple <em>(t)</em> of \a this field as
2302 * follows: \f$ t[0]^2+t[1]^2+t[2]^2+2*t[3]^2+2*t[4]^2+2*t[5]^2\f$.
2303 * This new field lies on the same mesh as \a this one. The caller is to delete
2304 * this field using decrRef() as it is no more needed.
2305 * \throw If \a this->getNumberOfComponents() != 6.
2306 * \throw If the spatial discretization of \a this field is NULL.
2308 MEDCouplingFieldDouble *MEDCouplingFieldDouble::doublyContractedProduct() const
2310 if(!((const MEDCouplingFieldDiscretization *)_type))
2311 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform doublyContractedProduct !");
2312 MEDCouplingTimeDiscretization *td=_time_discr->doublyContractedProduct();
2313 td->copyTinyAttrFrom(*_time_discr);
2314 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2315 ret->setName("DoublyContractedProduct");
2316 ret->setMesh(getMesh());
2321 * Creates a new MEDCouplingFieldDouble filled with the determinant of a square
2322 * matrix defined by every tuple of \a this field, having either 4, 6 or 9 components.
2323 * The case of 6 components corresponds to that of the upper triangular matrix.
2324 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, whose
2325 * each tuple is the determinant of matrix of the corresponding tuple of \a this
2326 * field. This new field lies on the same mesh as \a this one. The caller is to
2327 * delete this field using decrRef() as it is no more needed.
2328 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2329 * \throw If the spatial discretization of \a this field is NULL.
2331 MEDCouplingFieldDouble *MEDCouplingFieldDouble::determinant() const
2333 if(!((const MEDCouplingFieldDiscretization *)_type))
2334 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform determinant !");
2335 MEDCouplingTimeDiscretization *td=_time_discr->determinant();
2336 td->copyTinyAttrFrom(*_time_discr);
2337 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2338 ret->setName("Determinant");
2339 ret->setMesh(getMesh());
2345 * Creates a new MEDCouplingFieldDouble with 3 components filled with 3 eigenvalues of
2346 * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2347 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2348 * having 3 components, whose each tuple contains the eigenvalues of the matrix of
2349 * corresponding tuple of \a this field. This new field lies on the same mesh as
2350 * \a this one. The caller is to delete this field using decrRef() as it is no
2352 * \throw If \a this->getNumberOfComponents() != 6.
2353 * \throw If the spatial discretization of \a this field is NULL.
2355 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenValues() const
2357 if(!((const MEDCouplingFieldDiscretization *)_type))
2358 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenValues !");
2359 MEDCouplingTimeDiscretization *td=_time_discr->eigenValues();
2360 td->copyTinyAttrFrom(*_time_discr);
2361 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2362 ret->setName("EigenValues");
2363 ret->setMesh(getMesh());
2368 * Creates a new MEDCouplingFieldDouble with 9 components filled with 3 eigenvectors of
2369 * an upper triangular matrix defined by every tuple of \a this 6-componental field.
2370 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2371 * having 9 components, whose each tuple contains the eigenvectors of the matrix of
2372 * corresponding tuple of \a this field. This new field lies on the same mesh as
2373 * \a this one. The caller is to delete this field using decrRef() as it is no
2375 * \throw If \a this->getNumberOfComponents() != 6.
2376 * \throw If the spatial discretization of \a this field is NULL.
2378 MEDCouplingFieldDouble *MEDCouplingFieldDouble::eigenVectors() const
2380 if(!((const MEDCouplingFieldDiscretization *)_type))
2381 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform eigenVectors !");
2382 MEDCouplingTimeDiscretization *td=_time_discr->eigenVectors();
2383 td->copyTinyAttrFrom(*_time_discr);
2384 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2385 ret->setName("EigenVectors");
2386 ret->setMesh(getMesh());
2391 * Creates a new MEDCouplingFieldDouble filled with the inverse matrix of
2392 * a matrix defined by every tuple of \a this field having either 4, 6 or 9
2393 * components. The case of 6 components corresponds to that of the upper triangular
2395 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2396 * having the same number of components as \a this one, whose each tuple
2397 * contains the inverse matrix of the matrix of corresponding tuple of \a this
2398 * field. This new field lies on the same mesh as \a this one. The caller is to
2399 * delete this field using decrRef() as it is no more needed.
2400 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2401 * \throw If the spatial discretization of \a this field is NULL.
2403 MEDCouplingFieldDouble *MEDCouplingFieldDouble::inverse() const
2405 if(!((const MEDCouplingFieldDiscretization *)_type))
2406 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform inverse !");
2407 MEDCouplingTimeDiscretization *td=_time_discr->inverse();
2408 td->copyTinyAttrFrom(*_time_discr);
2409 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2410 ret->setName("Inversion");
2411 ret->setMesh(getMesh());
2416 * Creates a new MEDCouplingFieldDouble filled with the trace of
2417 * a matrix defined by every tuple of \a this field having either 4, 6 or 9
2418 * components. The case of 6 components corresponds to that of the upper triangular
2420 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2421 * having 1 component, whose each tuple is the trace of the matrix of
2422 * corresponding tuple of \a this field.
2423 * This new field lies on the same mesh as \a this one. The caller is to
2424 * delete this field using decrRef() as it is no more needed.
2425 * \throw If \a this->getNumberOfComponents() is not in [4,6,9].
2426 * \throw If the spatial discretization of \a this field is NULL.
2428 MEDCouplingFieldDouble *MEDCouplingFieldDouble::trace() const
2430 if(!((const MEDCouplingFieldDiscretization *)_type))
2431 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform trace !");
2432 MEDCouplingTimeDiscretization *td=_time_discr->trace();
2433 td->copyTinyAttrFrom(*_time_discr);
2434 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2435 ret->setName("Trace");
2436 ret->setMesh(getMesh());
2441 * Creates a new MEDCouplingFieldDouble filled with the stress deviator tensor of
2442 * a stress tensor defined by every tuple of \a this 6-componental field.
2443 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2444 * having same number of components and tuples as \a this field,
2445 * whose each tuple contains the stress deviator tensor of the stress tensor of
2446 * corresponding tuple of \a this field. This new field lies on the same mesh as
2447 * \a this one. The caller is to delete this field using decrRef() as it is no
2449 * \throw If \a this->getNumberOfComponents() != 6.
2450 * \throw If the spatial discretization of \a this field is NULL.
2452 MEDCouplingFieldDouble *MEDCouplingFieldDouble::deviator() const
2454 if(!((const MEDCouplingFieldDiscretization *)_type))
2455 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform deviator !");
2456 MEDCouplingTimeDiscretization *td=_time_discr->deviator();
2457 td->copyTinyAttrFrom(*_time_discr);
2458 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2459 ret->setName("Deviator");
2460 ret->setMesh(getMesh());
2465 * Creates a new MEDCouplingFieldDouble filled with the magnitude of
2466 * every vector of \a this field.
2467 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble,
2468 * having one component, whose each tuple is the magnitude of the vector
2469 * of corresponding tuple of \a this field. This new field lies on the
2470 * same mesh as \a this one. The caller is to
2471 * delete this field using decrRef() as it is no more needed.
2472 * \throw If the spatial discretization of \a this field is NULL.
2474 MEDCouplingFieldDouble *MEDCouplingFieldDouble::magnitude() const
2476 if(!((const MEDCouplingFieldDiscretization *)_type))
2477 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform magnitude !");
2478 MEDCouplingTimeDiscretization *td=_time_discr->magnitude();
2479 td->copyTinyAttrFrom(*_time_discr);
2480 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2481 ret->setName("Magnitude");
2482 ret->setMesh(getMesh());
2487 * Creates a new scalar MEDCouplingFieldDouble filled with the maximal value among
2488 * values of every tuple of \a this field.
2489 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2490 * This new field lies on the same mesh as \a this one. The caller is to
2491 * delete this field using decrRef() as it is no more needed.
2492 * \throw If the spatial discretization of \a this field is NULL.
2494 MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const
2496 if(!((const MEDCouplingFieldDiscretization *)_type))
2497 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform maxPerTuple !");
2498 MEDCouplingTimeDiscretization *td=_time_discr->maxPerTuple();
2499 td->copyTinyAttrFrom(*_time_discr);
2500 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2501 std::ostringstream oss;
2502 oss << "Max_" << getName();
2503 ret->setName(oss.str().c_str());
2504 ret->setMesh(getMesh());
2509 * Changes number of components in \a this field. If \a newNbOfComp is less
2510 * than \a this->getNumberOfComponents() then each tuple
2511 * is truncated to have \a newNbOfComp components, keeping first components. If \a
2512 * newNbOfComp is more than \a this->getNumberOfComponents() then
2513 * each tuple is populated with \a dftValue to have \a newNbOfComp components.
2514 * \param [in] newNbOfComp - number of components for the new field to have.
2515 * \param [in] dftValue - value assigned to new values added to \a this field.
2516 * \throw If \a this is not allocated.
2518 void MEDCouplingFieldDouble::changeNbOfComponents(int newNbOfComp, double dftValue)
2520 _time_discr->changeNbOfComponents(newNbOfComp,dftValue);
2524 * Creates a new MEDCouplingFieldDouble composed of selected components of \a this field.
2525 * The new MEDCouplingFieldDouble has the same number of tuples but includes components
2526 * specified by \a compoIds parameter. So that getNbOfElems() of the result field
2527 * can be either less, same or more than \a this->getNumberOfValues().
2528 * \param [in] compoIds - sequence of zero based indices of components to include
2529 * into the new field.
2530 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble that the caller
2531 * is to delete using decrRef() as it is no more needed.
2532 * \throw If a component index (\a i) is not valid:
2533 * \a i < 0 || \a i >= \a this->getNumberOfComponents().
2535 MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std::vector<int>& compoIds) const
2537 if(!((const MEDCouplingFieldDiscretization *)_type))
2538 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform keepSelectedComponents !");
2539 MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds);
2540 td->copyTinyAttrFrom(*_time_discr);
2541 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2542 ret->setName(getName().c_str());
2543 ret->setMesh(getMesh());
2549 * Copy all components in a specified order from another field.
2550 * The number of tuples in \a this and the other field can be different.
2551 * \param [in] f - the field to copy data from.
2552 * \param [in] compoIds - sequence of zero based indices of components, data of which is
2554 * \throw If the two fields have different number of data arrays.
2555 * \throw If a data array is set in one of fields and is not set in the other.
2556 * \throw If \a compoIds.size() != \a a->getNumberOfComponents().
2557 * \throw If \a compoIds[i] < 0 or \a compoIds[i] > \a this->getNumberOfComponents().
2559 void MEDCouplingFieldDouble::setSelectedComponents(const MEDCouplingFieldDouble *f, const std::vector<int>& compoIds)
2561 _time_discr->setSelectedComponents(f->_time_discr,compoIds);
2565 * Sorts value within every tuple of \a this field.
2566 * \param [in] asc - if \a true, the values are sorted in ascending order, else,
2567 * in descending order.
2568 * \throw If a data array is not allocated.
2570 void MEDCouplingFieldDouble::sortPerTuple(bool asc)
2572 _time_discr->sortPerTuple(asc);
2576 * Creates a new MEDCouplingFieldDouble by concatenating two given fields.
2578 * the first field precede values of the second field within the result field.
2579 * \param [in] f1 - the first field.
2580 * \param [in] f2 - the second field.
2581 * \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2582 * MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef()
2583 * as it is no more needed.
2584 * \throw If the fields are not compatible for the merge.
2585 * \throw If the spatial discretization of \a f1 is NULL.
2586 * \throw If the time discretization of \a f1 is NULL.
2588 * \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2589 * \ref py_mcfielddouble_MergeFields "Here is a Python example".
2591 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2593 if(!f1->areCompatibleForMerge(f2))
2594 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !");
2595 const MEDCouplingMesh *m1(f1->getMesh()),*m2(f2->getMesh());
2596 if(!f1->_time_discr)
2597 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no time discr of f1 !");
2599 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no spatial discr of f1 !");
2600 MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr);
2601 td->copyTinyAttrFrom(*f1->_time_discr);
2602 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2603 ret->setName(f1->getName().c_str());
2604 ret->setDescription(f1->getDescription().c_str());
2607 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=m1->mergeMyselfWith(m2);
2614 * Creates a new MEDCouplingFieldDouble by concatenating all given fields.
2615 * Values of the *i*-th field precede values of the (*i*+1)-th field within the result.
2616 * If there is only one field in \a a, a deepCopy() (except time information of mesh and
2617 * field) of the field is returned.
2618 * Generally speaking the first field in \a a is used to assign tiny attributes of the
2620 * \param [in] a - a vector of fields (MEDCouplingFieldDouble) to concatenate.
2621 * \return MEDCouplingFieldDouble * - the result field. It is a new instance of
2622 * MEDCouplingFieldDouble. The caller is to delete this mesh using decrRef()
2623 * as it is no more needed.
2624 * \throw If \a a is empty.
2625 * \throw If the fields are not compatible for the merge.
2627 * \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".<br>
2628 * \ref py_mcfielddouble_MergeFields "Here is a Python example".
2630 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector<const MEDCouplingFieldDouble *>& a)
2633 throw INTERP_KERNEL::Exception("FieldDouble::MergeFields : size of array must be >= 1 !");
2634 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > ms(a.size());
2635 std::vector< const MEDCouplingUMesh *> ms2(a.size());
2636 std::vector< const MEDCouplingTimeDiscretization *> tds(a.size());
2637 std::vector<const MEDCouplingFieldDouble *>::const_iterator it=a.begin();
2638 const MEDCouplingFieldDouble *ref=(*it++);
2640 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : presence of NULL instance in first place of input vector !");
2641 for(;it!=a.end();it++)
2642 if(!ref->areCompatibleForMerge(*it))
2643 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !");
2644 for(int i=0;i<(int)a.size();i++)
2647 { ms[i]=a[i]->getMesh()->buildUnstructured(); ms2[i]=ms[i]; }
2649 { ms[i]=0; ms2[i]=0; }
2650 tds[i]=a[i]->_time_discr;
2652 MEDCouplingTimeDiscretization *td=tds[0]->aggregate(tds);
2653 td->copyTinyAttrFrom(*(a[0]->_time_discr));
2654 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone());
2655 ret->setName(a[0]->getName().c_str());
2656 ret->setDescription(a[0]->getDescription().c_str());
2659 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDCouplingUMesh::MergeUMeshes(ms2);
2660 m->copyTinyInfoFrom(ms2[0]);
2667 * Creates a new MEDCouplingFieldDouble by concatenating components of two given fields.
2668 * The number of components in the result field is a sum of the number of components of
2669 * given fields. The number of tuples in the result field is same as that of each of given
2671 * Number of tuples in the given fields must be the same.
2672 * \param [in] f1 - a field to include in the result field.
2673 * \param [in] f2 - another field to include in the result field.
2674 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2675 * The caller is to delete this result field using decrRef() as it is no more
2677 * \throw If the fields are not compatible for a meld (areCompatibleForMeld()).
2678 * \throw If any of data arrays is not allocated.
2679 * \throw If \a f1->getNumberOfTuples() != \a f2->getNumberOfTuples()
2681 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MeldFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2683 if(!f1->areCompatibleForMeld(f2))
2684 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MeldFields on them !");
2685 MEDCouplingTimeDiscretization *td=f1->_time_discr->meld(f2->_time_discr);
2686 td->copyTinyAttrFrom(*f1->_time_discr);
2687 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2688 ret->setMesh(f1->getMesh());
2693 * Returns a new MEDCouplingFieldDouble containing a dot product of two given fields,
2694 * so that the i-th tuple of the result field is a sum of products of j-th components of
2695 * i-th tuples of given fields (\f$ f_i = \sum_{j=1}^n f1_j * f2_j \f$).
2696 * Number of tuples and components in the given fields must be the same.
2697 * \param [in] f1 - a given field.
2698 * \param [in] f2 - another given field.
2699 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2700 * The caller is to delete this result field using decrRef() as it is no more
2702 * \throw If either \a f1 or \a f2 is NULL.
2703 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2704 * differ not only in values.
2706 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2709 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DotFields : input field is NULL !");
2710 if(!f1->areStrictlyCompatible(f2))
2711 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DotFields on them !");
2712 MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr);
2713 td->copyTinyAttrFrom(*f1->_time_discr);
2714 MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2715 ret->setMesh(f1->getMesh());
2720 * Returns a new MEDCouplingFieldDouble containing a cross product of two given fields,
2722 * the i-th tuple of the result field is a 3D vector which is a cross
2723 * product of two vectors defined by the i-th tuples of given fields.
2724 * Number of tuples in the given fields must be the same.
2725 * Number of components in the given fields must be 3.
2726 * \param [in] f1 - a given field.
2727 * \param [in] f2 - another given field.
2728 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2729 * The caller is to delete this result field using decrRef() as it is no more
2731 * \throw If either \a f1 or \a f2 is NULL.
2732 * \throw If \a f1->getNumberOfComponents() != 3
2733 * \throw If \a f2->getNumberOfComponents() != 3
2734 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2735 * differ not only in values.
2737 MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2740 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::CrossProductFields : input field is NULL !");
2741 if(!f1->areStrictlyCompatible(f2))
2742 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply CrossProductFields on them !");
2743 MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr);
2744 td->copyTinyAttrFrom(*f1->_time_discr);
2745 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2746 ret->setMesh(f1->getMesh());
2751 * Returns a new MEDCouplingFieldDouble containing maximal values of two given fields.
2752 * Number of tuples and components in the given fields must be the same.
2753 * \param [in] f1 - a field to compare values with another one.
2754 * \param [in] f2 - another field to compare values with the first one.
2755 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2756 * The caller is to delete this result field using decrRef() as it is no more
2758 * \throw If either \a f1 or \a f2 is NULL.
2759 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2760 * differ not only in values.
2762 * \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2763 * \ref py_mcfielddouble_MaxFields "Here is a Python example".
2765 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2768 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MaxFields : input field is NULL !");
2769 if(!f1->areStrictlyCompatible(f2))
2770 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MaxFields on them !");
2771 MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr);
2772 td->copyTinyAttrFrom(*f1->_time_discr);
2773 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2774 ret->setMesh(f1->getMesh());
2779 * Returns a new MEDCouplingFieldDouble containing minimal values of two given fields.
2780 * Number of tuples and components in the given fields must be the same.
2781 * \param [in] f1 - a field to compare values with another one.
2782 * \param [in] f2 - another field to compare values with the first one.
2783 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2784 * The caller is to delete this result field using decrRef() as it is no more
2786 * \throw If either \a f1 or \a f2 is NULL.
2787 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2788 * differ not only in values.
2790 * \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".<br>
2791 * \ref py_mcfielddouble_MaxFields "Here is a Python example".
2793 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2796 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MinFields : input field is NULL !");
2797 if(!f1->areStrictlyCompatible(f2))
2798 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MinFields on them !");
2799 MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr);
2800 td->copyTinyAttrFrom(*f1->_time_discr);
2801 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2802 ret->setMesh(f1->getMesh());
2807 * Returns a copy of \a this field in which sign of all values is reversed.
2808 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble
2809 * containing the same number of tuples and components as \a this field.
2810 * The caller is to delete this result field using decrRef() as it is no more
2812 * \throw If the spatial discretization of \a this field is NULL.
2813 * \throw If a data array is not allocated.
2815 MEDCouplingFieldDouble *MEDCouplingFieldDouble::negate() const
2817 if(!((const MEDCouplingFieldDiscretization *)_type))
2818 throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform negate !");
2819 MEDCouplingTimeDiscretization *td=_time_discr->negate();
2820 td->copyTinyAttrFrom(*_time_discr);
2821 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone());
2822 ret->setMesh(getMesh());
2827 * Returns a new MEDCouplingFieldDouble containing sum values of corresponding values of
2828 * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] + _f2_ [ i, j ] ).
2829 * Number of tuples and components in the given fields must be the same.
2830 * \param [in] f1 - a field to sum up.
2831 * \param [in] f2 - another field to sum up.
2832 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2833 * The caller is to delete this result field using decrRef() as it is no more
2835 * \throw If either \a f1 or \a f2 is NULL.
2836 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2837 * differ not only in values.
2839 MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2842 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::AddFields : input field is NULL !");
2843 if(!f1->areStrictlyCompatible(f2))
2844 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply AddFields on them !");
2845 MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr);
2846 td->copyTinyAttrFrom(*f1->_time_discr);
2847 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2848 ret->setMesh(f1->getMesh());
2853 * Adds values of another MEDCouplingFieldDouble to values of \a this one
2854 * ( _this_ [ i, j ] += _other_ [ i, j ] ) using DataArrayDouble::addEqual().
2855 * The two fields must have same number of tuples, components and same underlying mesh.
2856 * \param [in] other - the field to add to \a this one.
2857 * \return const MEDCouplingFieldDouble & - a reference to \a this field.
2858 * \throw If \a other is NULL.
2859 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2860 * differ not only in values.
2862 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
2864 if(!areStrictlyCompatible(&other))
2865 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply += on them !");
2866 _time_discr->addEqual(other._time_discr);
2871 * Returns a new MEDCouplingFieldDouble containing subtraction of corresponding values of
2872 * two given fields ( _f_ [ i, j ] = _f1_ [ i, j ] - _f2_ [ i, j ] ).
2873 * Number of tuples and components in the given fields must be the same.
2874 * \param [in] f1 - a field to subtract from.
2875 * \param [in] f2 - a field to subtract.
2876 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2877 * The caller is to delete this result field using decrRef() as it is no more
2879 * \throw If either \a f1 or \a f2 is NULL.
2880 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2881 * differ not only in values.
2883 MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2886 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::SubstractFields : input field is NULL !");
2887 if(!f1->areStrictlyCompatible(f2))
2888 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply SubstractFields on them !");
2889 MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr);
2890 td->copyTinyAttrFrom(*f1->_time_discr);
2891 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2892 ret->setMesh(f1->getMesh());
2897 * Subtract values of another MEDCouplingFieldDouble from values of \a this one
2898 * ( _this_ [ i, j ] -= _other_ [ i, j ] ) using DataArrayDouble::substractEqual().
2899 * The two fields must have same number of tuples, components and same underlying mesh.
2900 * \param [in] other - the field to subtract from \a this one.
2901 * \return const MEDCouplingFieldDouble & - a reference to \a this field.
2902 * \throw If \a other is NULL.
2903 * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they
2904 * differ not only in values.
2906 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
2908 if(!areStrictlyCompatible(&other))
2909 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply -= on them !");
2910 _time_discr->substractEqual(other._time_discr);
2915 * Returns a new MEDCouplingFieldDouble containing product values of
2916 * two given fields. There are 2 valid cases.
2917 * 1. The fields have same number of tuples and components. Then each value of
2918 * the result field (_f_) is a product of the corresponding values of _f1_ and
2919 * _f2_, i.e. _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, j ].
2920 * 2. The fields have same number of tuples and one field, say _f2_, has one
2922 * _f_ [ i, j ] = _f1_ [ i, j ] * _f2_ [ i, 0 ].
2924 * The two fields must have same number of tuples and same underlying mesh.
2925 * \param [in] f1 - a factor field.
2926 * \param [in] f2 - another factor field.
2927 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2928 * The caller is to delete this result field using decrRef() as it is no more
2930 * \throw If either \a f1 or \a f2 is NULL.
2931 * \throw If the fields are not compatible for production (areCompatibleForMul()),
2932 * i.e. they differ not only in values and possibly number of components.
2934 MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2937 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MultiplyFields : input field is NULL !");
2938 if(!f1->areCompatibleForMul(f2))
2939 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MultiplyFields on them !");
2940 MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr);
2941 td->copyTinyAttrFrom(*f1->_time_discr);
2942 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
2943 ret->setMesh(f1->getMesh());
2948 * Multiply values of another MEDCouplingFieldDouble to values of \a this one
2949 * using DataArrayDouble::multiplyEqual().
2950 * The two fields must have same number of tuples and same underlying mesh.
2951 * There are 2 valid cases.
2952 * 1. The fields have same number of components. Then each value of
2953 * \a other is multiplied to the corresponding value of \a this field, i.e.
2954 * _this_ [ i, j ] *= _other_ [ i, j ].
2955 * 2. The _other_ field has one component. Then
2956 * _this_ [ i, j ] *= _other_ [ i, 0 ].
2958 * The two fields must have same number of tuples and same underlying mesh.
2959 * \param [in] other - an field to multiply to \a this one.
2960 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2961 * The caller is to delete this result field using decrRef() as it is no more
2963 * \throw If \a other is NULL.
2964 * \throw If the fields are not strictly compatible for production
2965 * (areCompatibleForMul()),
2966 * i.e. they differ not only in values and possibly in number of components.
2968 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
2970 if(!areCompatibleForMul(&other))
2971 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply *= on them !");
2972 _time_discr->multiplyEqual(other._time_discr);
2977 * Returns a new MEDCouplingFieldDouble containing division of two given fields.
2978 * There are 2 valid cases.
2979 * 1. The fields have same number of tuples and components. Then each value of
2980 * the result field (_f_) is a division of the corresponding values of \a f1 and
2981 * \a f2, i.e. _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, j ].
2982 * 2. The fields have same number of tuples and _f2_ has one component. Then
2983 * _f_ [ i, j ] = _f1_ [ i, j ] / _f2_ [ i, 0 ].
2985 * \param [in] f1 - a numerator field.
2986 * \param [in] f2 - a denominator field.
2987 * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble.
2988 * The caller is to delete this result field using decrRef() as it is no more
2990 * \throw If either \a f1 or \a f2 is NULL.
2991 * \throw If the fields are not compatible for division (areCompatibleForDiv()),
2992 * i.e. they differ not only in values and possibly in number of components.
2994 MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
2997 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DivideFields : input field is NULL !");
2998 if(!f1->areCompatibleForDiv(f2))
2999 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DivideFields on them !");
3000 MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr);
3001 td->copyTinyAttrFrom(*f1->_time_discr);
3002 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3003 ret->setMesh(f1->getMesh());
3008 * Divide values of \a this field by values of another MEDCouplingFieldDouble
3009 * using DataArrayDouble::divideEqual().
3010 * The two fields must have same number of tuples and same underlying mesh.
3011 * There are 2 valid cases.
3012 * 1. The fields have same number of components. Then each value of
3013 * \a this field is divided by the corresponding value of \a other one, i.e.
3014 * _this_ [ i, j ] /= _other_ [ i, j ].
3015 * 2. The \a other field has one component. Then
3016 * _this_ [ i, j ] /= _other_ [ i, 0 ].
3018 * \warning No check of division by zero is performed!
3019 * \param [in] other - an field to divide \a this one by.
3020 * \throw If \a other is NULL.
3021 * \throw If the fields are not compatible for division (areCompatibleForDiv()),
3022 * i.e. they differ not only in values and possibly in number of components.
3024 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
3026 if(!areCompatibleForDiv(&other))
3027 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !");
3028 _time_discr->divideEqual(other._time_discr);
3033 * Directly called by MEDCouplingFieldDouble::operator^.
3035 * \sa MEDCouplingFieldDouble::operator^
3037 MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2)
3040 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::PowFields : input field is NULL !");
3041 if(!f1->areCompatibleForMul(f2))
3042 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply PowFields on them !");
3043 MEDCouplingTimeDiscretization *td=f1->_time_discr->pow(f2->_time_discr);
3044 td->copyTinyAttrFrom(*f1->_time_discr);
3045 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone());
3046 ret->setMesh(f1->getMesh());
3051 * Directly call MEDCouplingFieldDouble::PowFields static method.
3053 * \sa MEDCouplingFieldDouble::PowFields
3055 MEDCouplingFieldDouble *MEDCouplingFieldDouble::operator^(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception)
3057 return PowFields(this,&other);
3060 const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception)
3062 if(!areCompatibleForDiv(&other))
3063 throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !");
3064 _time_discr->powEqual(other._time_discr);
3069 * Writes the field series \a fs and the mesh the fields lie on in the VTK file \a fileName.
3070 * If \a fs is empty no file is written.
3071 * The result file is valid provided that no exception is thrown.
3072 * \warning All the fields must be named and lie on the same non NULL mesh.
3073 * \param [in] fileName - the name of a VTK file to write in.
3074 * \param [in] fs - the fields to write.
3075 * \param [in] isBinary - specifies the VTK format of the written file. By default true (Binary mode)
3076 * \throw If \a fs[ 0 ] == NULL.
3077 * \throw If the fields lie not on the same mesh.
3078 * \throw If the mesh is not set.
3079 * \throw If any of the fields has no name.
3081 * \ref cpp_mcfielddouble_WriteVTK "Here is a C++ example".<br>
3082 * \ref py_mcfielddouble_WriteVTK "Here is a Python example".
3084 void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector<const MEDCouplingFieldDouble *>& fs, bool isBinary)
3088 std::size_t nfs=fs.size();
3090 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field is NULL !");
3091 const MEDCouplingMesh *m=fs[0]->getMesh();
3093 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field lies on NULL mesh !");
3094 for(std::size_t i=1;i<nfs;i++)
3095 if(fs[i]->getMesh()!=m)
3096 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.");
3098 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : Fields are lying on a same mesh but it is empty !");
3099 MEDCouplingAutoRefCountObjectPtr<DataArrayByte> byteArr;
3101 { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); }
3102 std::ostringstream coss,noss;
3103 for(std::size_t i=0;i<nfs;i++)
3105 const MEDCouplingFieldDouble *cur=fs[i];
3106 std::string name(cur->getName());
3109 std::ostringstream oss; oss << "MEDCouplingFieldDouble::WriteVTK : Field in pos #" << i << " has no name !";
3110 throw INTERP_KERNEL::Exception(oss.str().c_str());
3112 TypeOfField typ=cur->getTypeOfField();
3114 cur->getArray()->writeVTK(coss,8,cur->getName().c_str(),byteArr);
3115 else if(typ==ON_NODES)
3116 cur->getArray()->writeVTK(noss,8,cur->getName().c_str(),byteArr);
3118 throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : only node and cell fields supported for the moment !");
3120 m->writeVTKAdvanced(fileName,coss.str(),noss.str(),byteArr);
3123 void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const
3125 stream << "MEDCouplingFieldDouble C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl;
3129 nat=MEDCouplingNatureOfField::GetRepr(_nature);
3130 stream << "Nature of field : " << nat << ".\n";
3132 catch(INTERP_KERNEL::Exception& /*e*/)
3134 const MEDCouplingFieldDiscretization *fd(_type);
3136 stream << "No spatial discretization set !";
3138 fd->reprQuickOverview(stream);
3139 stream << std::endl;
3141 stream << "\nNo mesh support defined !";
3144 std::ostringstream oss;
3145 _mesh->reprQuickOverview(oss);
3146 std::string tmp(oss.str());
3147 stream << "\nMesh info : " << tmp.substr(0,tmp.find('\n'));
3151 const DataArrayDouble *arr=_time_discr->getArray();
3154 stream << "\n\nArray info : ";
3155 arr->reprQuickOverview(stream);
3159 stream << "\n\nNo data array set !";