+
+/*!
+ * Creates a new MEDCouplingFieldDouble, of given spatial type and time discretization.
+ * For more info, see \ref MEDCouplingFirstSteps3.
+ * \param [in] type - the type of spatial discretization of the created field, one of
+ * (\ref ParaMEDMEM::ON_CELLS "ON_CELLS",
+ * \ref ParaMEDMEM::ON_NODES "ON_NODES",
+ * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT",
+ * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
+ * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
+ * \param [in] td - the type of time discretization of the created field, one of
+ * (\ref ParaMEDMEM::NO_TIME "NO_TIME",
+ * \ref ParaMEDMEM::ONE_TIME "ONE_TIME",
+ * \ref ParaMEDMEM::LINEAR_TIME "LINEAR_TIME",
+ * \ref ParaMEDMEM::CONST_ON_TIME_INTERVAL "CONST_ON_TIME_INTERVAL").
+ * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ */
+MEDCouplingFieldDouble* MEDCouplingFieldDouble::New(TypeOfField type, TypeOfTimeDiscretization td)
+{
+ return new MEDCouplingFieldDouble(type,td);
+}
+
+/*!
+ * Creates a new MEDCouplingFieldDouble, of a given time discretization and with a
+ * spatial type and supporting mesh copied from a given
+ * \ref MEDCouplingFieldTemplatesPage "field template".
+ * For more info, see \ref MEDCouplingFirstSteps3.
+ * \warning This method does not deeply copy neither the mesh nor the spatial
+ * discretization. Only a shallow copy (reference) is done for the mesh and the spatial
+ * discretization!
+ * \param [in] ft - the \ref MEDCouplingFieldTemplatesPage "field template" defining
+ * the spatial discretization and the supporting mesh.
+ * \param [in] td - the type of time discretization of the created field, one of
+ * (\ref ParaMEDMEM::NO_TIME "NO_TIME",
+ * \ref ParaMEDMEM::ONE_TIME "ONE_TIME",
+ * \ref ParaMEDMEM::LINEAR_TIME "LINEAR_TIME",
+ * \ref ParaMEDMEM::CONST_ON_TIME_INTERVAL "CONST_ON_TIME_INTERVAL").
+ * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td)
+{
+ return new MEDCouplingFieldDouble(ft,td);
+}
+
+/*!
+ * Sets a time \a unit of \a this field. For more info, see \ref MEDCouplingFirstSteps3.
+ * \param [in] unit \a unit (string) in which time is measured.
+ */
+void MEDCouplingFieldDouble::setTimeUnit(const std::string& unit)
+{
+ _time_discr->setTimeUnit(unit);
+}
+
+/*!
+ * Returns a time unit of \a this field.
+ * \return a string describing units in which time is measured.
+ */
+std::string MEDCouplingFieldDouble::getTimeUnit() const
+{
+ return _time_discr->getTimeUnit();
+}
+
+/*!
+ * This method if possible the time information (time unit, time iteration, time unit and time value) with its support
+ * that is to say its mesh.
+ *
+ * \throw If \c this->_mesh is null an exception will be thrown. An exception will also be throw if the spatial discretization is
+ * NO_TIME.
+ */
+void MEDCouplingFieldDouble::synchronizeTimeWithSupport()
+{
+ _time_discr->synchronizeTimeWith(_mesh);
+}
+
+/*!
+ * Returns a new MEDCouplingFieldDouble which is a copy of \a this one. The data
+ * of \a this field is copied either deep or shallow depending on \a recDeepCpy
+ * parameter. But the underlying mesh is always shallow copied.
+ * Data that can be copied either deeply or shallow are:
+ * - \ref MEDCouplingTemporalDisc "temporal discretization" data that holds array(s)
+ * of field values,
+ * - \ref MEDCouplingSpatialDisc "a spatial discretization".
+ *
+ * \c clone(false) is rather dedicated for advanced users that want to limit the amount
+ * of memory. It allows the user to perform methods like operator+(), operator*()
+ * etc. with \a this and the returned field. If the user wants to duplicate deeply the
+ * underlying mesh he should call cloneWithMesh() method or deepCpy() instead.
+ * \warning The underlying \b mesh of the returned field is **always the same**
+ * (pointer) as \a this one **whatever the value** of \a recDeepCpy parameter.
+ * \param [in] recDeepCpy - if \c true, the copy of the underlying data arrays is
+ * deep, else all data arrays of \a this field are shared by the new field.
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \sa cloneWithMesh()
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::clone(bool recDeepCpy) const
+{
+ return new MEDCouplingFieldDouble(*this,recDeepCpy);
+}
+
+/*!
+ * Returns a new MEDCouplingFieldDouble which is a copy of \a this one. The data
+ * of \a this field is copied either deep or shallow depending on \a recDeepCpy
+ * parameter. But the underlying mesh is always deep copied.
+ * Data that can be copied either deeply or shallow are:
+ * - \ref MEDCouplingTemporalDisc "temporal discretization" data that holds array(s)
+ * of field values,
+ * - \ref MEDCouplingSpatialDisc "a spatial discretization".
+ *
+ * This method behaves exactly like clone() except that here the underlying **mesh is
+ * always deeply duplicated**, whatever the value \a recDeepCpy parameter.
+ * The result of \c cloneWithMesh(true) is exactly the same as that of deepCpy().
+ * So the resulting field can not be used together with \a this one in the methods
+ * like operator+(), operator*() etc. To avoid deep copying the underlying mesh,
+ * the user can call clone().
+ * \param [in] recDeepCpy - if \c true, the copy of the underlying data arrays is
+ * deep, else all data arrays of \a this field are shared by the new field.
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \sa clone()
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::cloneWithMesh(bool recDeepCpy) const
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(recDeepCpy);
+ if(_mesh)
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mCpy=_mesh->deepCpy();
+ ret->setMesh(mCpy);
+ }
+ return ret.retn();
+}
+
+/*!
+ * Returns a new MEDCouplingFieldDouble which is a deep copy of \a this one **including
+ * the mesh**.
+ * The result of this method is exactly the same as that of \c cloneWithMesh(true).
+ * So the resulting field can not be used together with \a this one in the methods
+ * like operator+(), operator*() etc. To avoid deep copying the underlying mesh,
+ * the user can call clone().
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ * \sa cloneWithMesh()
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::deepCpy() const
+{
+ return cloneWithMesh(true);
+}
+
+/*!
+ * Creates a new MEDCouplingFieldDouble of given
+ * \ref MEDCouplingTemporalDisc "temporal discretization". The result field either
+ * shares the data array(s) with \a this field, or holds a deep copy of it, depending on
+ * \a deepCopy parameter. But the underlying \b mesh is always **shallow copied**.
+ * \param [in] td - the type of time discretization of the created field, one of
+ * (\ref ParaMEDMEM::NO_TIME "NO_TIME",
+ * \ref ParaMEDMEM::ONE_TIME "ONE_TIME",
+ * \ref ParaMEDMEM::LINEAR_TIME "LINEAR_TIME",
+ * \ref ParaMEDMEM::CONST_ON_TIME_INTERVAL "CONST_ON_TIME_INTERVAL").
+ * \param [in] deepCopy - if \c true, the copy of the underlying data arrays is
+ * deep, else all data arrays of \a this field are shared by the new field.
+ * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed.
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcfielddouble_buildNewTimeReprFromThis "Here is a C++ example."<br>
+ * \ref py_mcfielddouble_buildNewTimeReprFromThis "Here is a Python example."
+ * \endif
+ * \sa clone()
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const
+{
+ MEDCouplingTimeDiscretization *tdo=_time_discr->buildNewTimeReprFromThis(td,deepCopy);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization> disc;
+ if(_type)
+ disc=_type->clone();
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=new MEDCouplingFieldDouble(getNature(),tdo,disc.retn());
+ ret->setMesh(getMesh());
+ ret->setName(getName());
+ ret->setDescription(getDescription());
+ return ret.retn();
+}
+
+/*!
+ * This method converts a field on nodes (\a this) to a cell field (returned field). The convertion is a \b non \b conservative remapping !
+ * This method is useful only for users that need a fast convertion from node to cell spatial discretization. The algorithm applied is simply to attach
+ * to each cell the average of values on nodes constituting this cell.
+ *
+ * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed. The returned field will share the same mesh object object than those in \a this.
+ * \throw If \a this spatial discretization is empty or not ON_NODES.
+ * \throw If \a this is not coherent (see MEDCouplingFieldDouble::checkCoherency).
+ *
+ * \warning This method is a \b non \b conservative method of remapping from node spatial discretization to cell spatial discretization.
+ * If a conservative method of interpolation is required ParaMEDMEM::MEDCouplingRemapper class should be used instead with "P1P0" method.
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::nodeToCellDiscretization() const
+{
+ checkCoherency();
+ TypeOfField tf(getTypeOfField());
+ if(tf!=ON_NODES)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::nodeToCellDiscretization : this field is expected to be on ON_NODES !");
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret(clone(false));
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretizationP0> nsp(new MEDCouplingFieldDiscretizationP0);
+ ret->setDiscretization(nsp);
+ const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkCoherency call
+ int nbCells(m->getNumberOfCells());
+ std::vector<DataArrayDouble *> arrs(getArrays());
+ std::size_t sz(arrs.size());
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > outArrsSafe(sz); std::vector<DataArrayDouble *> outArrs(sz);
+ for(std::size_t j=0;j<sz;j++)
+ {
+ int nbCompo(arrs[j]->getNumberOfComponents());
+ outArrsSafe[j]=DataArrayDouble::New(); outArrsSafe[j]->alloc(nbCells,nbCompo);
+ outArrsSafe[j]->copyStringInfoFrom(*arrs[j]);
+ outArrs[j]=outArrsSafe[j];
+ double *pt(outArrsSafe[j]->getPointer());
+ const double *srcPt(arrs[j]->begin());
+ for(int i=0;i<nbCells;i++,pt+=nbCompo)
+ {
+ std::vector<int> nodeIds;
+ m->getNodeIdsOfCell(i,nodeIds);
+ std::fill(pt,pt+nbCompo,0.);
+ std::size_t nbNodesInCell(nodeIds.size());
+ for(std::size_t k=0;k<nbNodesInCell;k++)
+ std::transform(srcPt+nodeIds[k]*nbCompo,srcPt+(nodeIds[k]+1)*nbCompo,pt,pt,std::plus<double>());
+ if(nbNodesInCell!=0)
+ std::transform(pt,pt+nbCompo,pt,std::bind2nd(std::multiplies<double>(),1./((double)nbNodesInCell)));
+ else
+ {
+ std::ostringstream oss; oss << "MEDCouplingFieldDouble::nodeToCellDiscretization : Cell id #" << i << " has been detected to have no nodes !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ }
+ ret->setArrays(outArrs);
+ return ret.retn();
+}
+
+/*!
+ * This method converts a field on cell (\a this) to a node field (returned field). The convertion is a \b non \b conservative remapping !
+ * This method is useful only for users that need a fast convertion from cell to node spatial discretization. The algorithm applied is simply to attach
+ * to each node the average of values on cell sharing this node. If \a this lies on a mesh having orphan nodes the values applied on them will be NaN (division by 0.).
+ *
+ * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
+ * caller is to delete this field using decrRef() as it is no more needed. The returned field will share the same mesh object object than those in \a this.
+ * \throw If \a this spatial discretization is empty or not ON_CELLS.
+ * \throw If \a this is not coherent (see MEDCouplingFieldDouble::checkCoherency).
+ *
+ * \warning This method is a \b non \b conservative method of remapping from cell spatial discretization to node spatial discretization.
+ * If a conservative method of interpolation is required ParaMEDMEM::MEDCouplingRemapper class should be used instead with "P0P1" method.
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::cellToNodeDiscretization() const
+{
+ checkCoherency();
+ TypeOfField tf(getTypeOfField());
+ if(tf!=ON_CELLS)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::cellToNodeDiscretization : this field is expected to be on ON_CELLS !");
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret(clone(false));
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretizationP1> nsp(new MEDCouplingFieldDiscretizationP1);
+ ret->setDiscretization(nsp);
+ const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkCoherency call
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rn(DataArrayInt::New()),rni(DataArrayInt::New());
+ m->getReverseNodalConnectivity(rn,rni);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rni2(rni->deltaShiftIndex());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> rni3(rni2->convertToDblArr()); rni2=0;
+ std::vector<DataArrayDouble *> arrs(getArrays());
+ std::size_t sz(arrs.size());
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > outArrsSafe(sz); std::vector<DataArrayDouble *> outArrs(sz);
+ for(std::size_t j=0;j<sz;j++)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(arrs[j]->selectByTupleIdSafe(rn->begin(),rn->end()));
+ outArrsSafe[j]=(tmp->accumulatePerChunck(rni->begin(),rni->end())); tmp=0;
+ outArrsSafe[j]->divideEqual(rni3);
+ outArrsSafe[j]->copyStringInfoFrom(*arrs[j]);
+ outArrs[j]=outArrsSafe[j];
+ }
+ ret->setArrays(outArrs);
+ return ret.retn();
+}
+
+/*!
+ * Copies tiny info (component names, name and description) from an \a other field to
+ * \a this one.
+ * \warning The underlying mesh is not renamed (for safety reason).
+ * \param [in] other - the field to copy the tiny info from.
+ * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
+ */
+void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingField *other)
+{
+ MEDCouplingField::copyTinyStringsFrom(other);
+ const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
+ if(otherC)
+ {
+ _time_discr->copyTinyStringsFrom(*otherC->_time_discr);
+ }
+}
+
+/*!
+ * Copies only times, order and iteration from an \a other field to
+ * \a this one. The underlying mesh is not impacted by this method.
+ * Arrays are not impacted neither.
+ * \param [in] other - the field to tiny attributes from.
+ * \throw If \a this->getNumberOfComponents() != \a other->getNumberOfComponents()
+ */
+void MEDCouplingFieldDouble::copyTinyAttrFrom(const MEDCouplingFieldDouble *other)
+{
+ if(other)
+ {
+ _time_discr->copyTinyAttrFrom(*other->_time_discr);
+ }
+}
+
+void MEDCouplingFieldDouble::copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other)
+{
+ copyTinyStringsFrom(other);
+ copyTinyAttrFrom(other);
+}
+
+/*!
+ * Returns a string describing \a this field. This string is outputted by \c print
+ * Python command. The string includes info on
+ * - name,
+ * - description,
+ * - \ref MEDCouplingSpatialDisc "spatial discretization",
+ * - \ref MEDCouplingTemporalDisc "time discretization",
+ * - \ref NatureOfField,
+ * - components,
+ * - mesh.
+ *
+ * \return std::string - the string describing \a this field.
+ */
+std::string MEDCouplingFieldDouble::simpleRepr() const
+{
+ std::ostringstream ret;
+ ret << "FieldDouble with name : \"" << getName() << "\"\n";
+ ret << "Description of field is : \"" << getDescription() << "\"\n";
+ if(_type)
+ { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; }
+ else
+ { ret << "FieldDouble has no spatial discretization !\n"; }
+ if(_time_discr)
+ { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; }
+ else
+ { ret << "FieldDouble has no time discretization !\n"; }
+ ret << "FieldDouble nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
+ if(getArray())
+ {
+ if(getArray()->isAllocated())
+ {
+ int nbOfCompo=getArray()->getNumberOfComponents();
+ ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
+ ret << "FieldDouble default array has following info on components : ";
+ for(int i=0;i<nbOfCompo;i++)
+ ret << "\"" << getArray()->getInfoOnComponent(i) << "\" ";
+ ret << "\n";
+ }
+ else
+ {
+ ret << "Array set but not allocated !\n";
+ }
+ }
+ if(_mesh)
+ ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
+ else
+ ret << "Mesh support information : No mesh set !\n";
+ return ret.str();
+}
+
+/*!
+ * Returns a string describing \a this field. The string includes info on
+ * - name,
+ * - description,
+ * - \ref MEDCouplingSpatialDisc "spatial discretization",
+ * - \ref MEDCouplingTemporalDisc "time discretization",
+ * - components,
+ * - mesh,
+ * - contents of data arrays.
+ *
+ * \return std::string - the string describing \a this field.
+ */
+std::string MEDCouplingFieldDouble::advancedRepr() const
+{
+ std::ostringstream ret;
+ ret << "FieldDouble with name : \"" << getName() << "\"\n";
+ ret << "Description of field is : \"" << getDescription() << "\"\n";
+ if(_type)
+ { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; }
+ else
+ { ret << "FieldDouble has no space discretization set !\n"; }
+ if(_time_discr)
+ { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; }
+ else
+ { ret << "FieldDouble has no time discretization set !\n"; }
+ if(getArray())
+ ret << "FieldDouble default array has " << getArray()->getNumberOfComponents() << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
+ if(_mesh)
+ ret << "Mesh support information :\n__________________________\n" << _mesh->advancedRepr();
+ else
+ ret << "Mesh support information : No mesh set !\n";
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ int arrayId=0;
+ for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++,arrayId++)
+ {
+ ret << "Array #" << arrayId << " :\n__________\n";
+ if(*iter)
+ (*iter)->reprWithoutNameStream(ret);
+ else
+ ret << "Array empty !";
+ ret << "\n";
+ }
+ return ret.str();
+}
+
+std::string MEDCouplingFieldDouble::writeVTK(const std::string& fileName, bool isBinary) const
+{
+ std::vector<const MEDCouplingFieldDouble *> fs(1,this);
+ return MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary);
+}
+
+bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const
+{
+ if(!other)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::isEqualIfNotWhy : other instance is NULL !");
+ const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
+ if(!otherC)
+ {
+ reason="field given in input is not castable in MEDCouplingFieldDouble !";
+ return false;
+ }
+ if(!MEDCouplingField::isEqualIfNotWhy(other,meshPrec,valsPrec,reason))
+ return false;
+ if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,valsPrec,reason))
+ {
+ reason.insert(0,"In FieldDouble time discretizations differ :");
+ return false;
+ }
+ return true;
+}
+
+/*!
+ * Checks equality of \a this and \a other field. Only numeric data is considered,
+ * i.e. names, description etc are not compared.
+ * \param [in] other - the field to compare with.
+ * \param [in] meshPrec - a precision used to compare node coordinates of meshes.
+ * \param [in] valsPrec - a precision used to compare data arrays of the two fields.
+ * \return bool - \c true if the two fields are equal, \c false else.
+ * \throw If \a other == NULL.
+ * \throw If the spatial discretization of \a this field is NULL.
+ */
+bool MEDCouplingFieldDouble::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
+{
+ const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
+ if(!otherC)
+ return false;
+ if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec))
+ return false;
+ if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,valsPrec))
+ return false;
+ return true;
+}
+
+/*!
+ * This method states if \a this and 'other' are compatibles each other before performing any treatment.
+ * This method is good for methods like : mergeFields.
+ * This method is not very demanding compared to areStrictlyCompatible that is better for operation on fields.
+ */
+bool MEDCouplingFieldDouble::areCompatibleForMerge(const MEDCouplingField *other) const
+{
+ if(!MEDCouplingField::areCompatibleForMerge(other))
+ return false;
+ const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
+ if(!otherC)
+ return false;
+ if(!_time_discr->areCompatible(otherC->_time_discr))
+ return false;
+ return true;
+}
+
+/*!
+ * This method is more strict than MEDCouplingField::areCompatibleForMerge method.
+ * This method is used for operation on fields to operate a first check before attempting operation.
+ */
+bool MEDCouplingFieldDouble::areStrictlyCompatible(const MEDCouplingField *other) const
+{
+ std::string tmp;
+ if(!MEDCouplingField::areStrictlyCompatible(other))
+ return false;
+ const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
+ if(!otherC)
+ return false;
+ if(!_time_discr->areStrictlyCompatible(otherC->_time_discr,tmp))
+ return false;
+ return true;
+}
+
+/*!
+ * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatibleForMulDiv method except that
+ * number of components between \a this and 'other' can be different here (for operator*).
+ */
+bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other) const
+{
+ if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other))
+ return false;
+ const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
+ if(!otherC)
+ return false;
+ if(!_time_discr->areStrictlyCompatibleForMul(otherC->_time_discr))
+ return false;
+ return true;
+}
+
+/*!
+ * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatibleForMulDiv method except that
+ * number of components between \a this and 'other' can be different here (for operator/).
+ */
+bool MEDCouplingFieldDouble::areCompatibleForDiv(const MEDCouplingField *other) const
+{
+ if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other))
+ return false;
+ const MEDCouplingFieldDouble *otherC=dynamic_cast<const MEDCouplingFieldDouble *>(other);
+ if(!otherC)
+ return false;
+ if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr))
+ return false;
+ return true;
+}
+
+/*!
+ * This method is invocated before any attempt of melding. This method is very close to areStrictlyCompatible,
+ * except that \a this and other can have different number of components.
+ */
+bool MEDCouplingFieldDouble::areCompatibleForMeld(const MEDCouplingFieldDouble *other) const
+{
+ if(!MEDCouplingField::areStrictlyCompatible(other))
+ return false;
+ if(!_time_discr->areCompatibleForMeld(other->_time_discr))
+ return false;
+ return true;
+}
+
+/*!
+ * Permutes values of \a this field according to a given permutation array for cells
+ * renumbering. The underlying mesh is deeply copied and its cells are also permuted.
+ * The number of cells remains the same; for that the permutation array \a old2NewBg
+ * should not contain equal ids.
+ * ** Warning, this method modifies the mesh aggreagated by \a this (by performing a deep copy ) **.
+ *
+ * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
+ * to be equal to \a this->getMesh()->getNumberOfCells().
+ * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
+ * array, so that its maximal cell id to correspond to (be less than) the number
+ * of cells in mesh. This new array is then used for the renumbering. If \a
+ * check == \c false, \a old2NewBg is used as is, that is less secure as validity
+ * of ids in \a old2NewBg is not checked.
+ * \throw If the mesh is not set.
+ * \throw If the spatial discretization of \a this field is NULL.
+ * \throw If \a check == \c true and \a old2NewBg contains equal ids.
+ * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcfielddouble_renumberCells "Here is a C++ example".<br>
+ * \ref py_mcfielddouble_renumberCells "Here is a Python example".
+ * \endif
+ */
+void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check)
+{
+ renumberCellsWithoutMesh(old2NewBg,check);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_mesh->deepCpy();
+ m->renumberCells(old2NewBg,check);
+ setMesh(m);
+ updateTime();
+}
+
+/*!
+ * Permutes values of \a this field according to a given permutation array for cells
+ * renumbering. The underlying mesh is \b not permuted.
+ * The number of cells remains the same; for that the permutation array \a old2NewBg
+ * should not contain equal ids.
+ * This method performs a part of job of renumberCells(). The reasonable use of this
+ * method is only for multi-field instances lying on the same mesh to avoid a
+ * systematic duplication and renumbering of _mesh attribute.
+ * \warning Use this method with a lot of care!
+ * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
+ * to be equal to \a this->getMesh()->getNumberOfCells().
+ * \param [in] check - if \c true, \a old2NewBg is transformed to a new permutation
+ * array, so that its maximal cell id to correspond to (be less than) the number
+ * of cells in mesh. This new array is then used for the renumbering. If \a
+ * check == \c false, \a old2NewBg is used as is, that is less secure as validity
+ * of ids in \a old2NewBg is not checked.
+ * \throw If the mesh is not set.
+ * \throw If the spatial discretization of \a this field is NULL.
+ * \throw If \a check == \c true and \a old2NewBg contains equal ids.
+ * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
+ */
+void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool check)
+{
+ if(!_mesh)
+ throw INTERP_KERNEL::Exception("Expecting a defined mesh to be able to operate a renumbering !");
+ if(!((const MEDCouplingFieldDiscretization *)_type))
+ throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
+ //
+ _type->renumberCells(old2NewBg,check);
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ std::vector<DataArray *> arrays2(arrays.size()); std::copy(arrays.begin(),arrays.end(),arrays2.begin());
+ _type->renumberArraysForCell(_mesh,arrays2,old2NewBg,check);
+ //
+ updateTime();
+}
+
+/*!
+ * Permutes values of \a this field according to a given permutation array for node
+ * renumbering. The underlying mesh is deeply copied and its nodes are also permuted.
+ * The number of nodes can change, contrary to renumberCells().
+ * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
+ * to be equal to \a this->getMesh()->getNumberOfNodes().
+ * \param [in] eps - a precision used to compare field values at merged nodes. If
+ * the values differ more than \a eps, an exception is thrown.
+ * \throw If the mesh is not set.
+ * \throw If the spatial discretization of \a this field is NULL.
+ * \throw If \a check == \c true and \a old2NewBg contains equal ids.
+ * \throw If mesh nature does not allow renumbering (e.g. structured mesh).
+ * \throw If values at merged nodes deffer more than \a eps.
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcfielddouble_renumberNodes "Here is a C++ example".<br>
+ * \ref py_mcfielddouble_renumberNodes "Here is a Python example".
+ * \endif
+ */
+void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg, double eps)
+{
+ const MEDCouplingPointSet *meshC=dynamic_cast<const MEDCouplingPointSet *>(_mesh);
+ if(!meshC)
+ throw INTERP_KERNEL::Exception("Invalid mesh to apply renumberNodes on it !");
+ int nbOfNodes=meshC->getNumberOfNodes();
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> meshC2((MEDCouplingPointSet *)meshC->deepCpy());
+ int newNbOfNodes=*std::max_element(old2NewBg,old2NewBg+nbOfNodes)+1;
+ renumberNodesWithoutMesh(old2NewBg,newNbOfNodes,eps);
+ meshC2->renumberNodes(old2NewBg,newNbOfNodes);
+ setMesh(meshC2);
+}
+
+/*!
+ * Permutes values of \a this field according to a given permutation array for nodes
+ * renumbering. The underlying mesh is \b not permuted.
+ * The number of nodes can change, contrary to renumberCells().
+ * A given epsilon specifies a threshold of error in case of two nodes are merged but
+ * the difference of values on these nodes are higher than \a eps.
+ * This method performs a part of job of renumberNodes(), excluding node renumbering
+ * in mesh. The reasonable use of this
+ * method is only for multi-field instances lying on the same mesh to avoid a
+ * systematic duplication and renumbering of _mesh attribute.
+ * \warning Use this method with a lot of care!
+ * \warning In case of an exception thrown, the contents of the data array can be
+ * partially modified until the exception occurs.
+ * \param [in] old2NewBg - the permutation array in "Old to New" mode. Its length is
+ * to be equal to \a this->getMesh()->getNumberOfNodes().
+ * \param [in] newNbOfNodes - a number of nodes in the mesh after renumbering.
+ * \param [in] eps - a precision used to compare field values at merged nodes. If
+ * the values differ more than \a eps, an exception is thrown.
+ * \throw If the mesh is not set.
+ * \throw If the spatial discretization of \a this field is NULL.
+ * \throw If values at merged nodes deffer more than \a eps.
+ */
+void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps)
+{
+ if(!((const MEDCouplingFieldDiscretization *)_type))
+ throw INTERP_KERNEL::Exception("Expecting a spatial discretization to be able to operate a renumbering !");
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
+ if(*iter)
+ _type->renumberValuesOnNodes(eps,old2NewBg,newNbOfNodes,*iter);
+}
+
+/*!
+ * Returns all tuple ids of \a this scalar field that fit the range [\a vmin,
+ * \a vmax]. This method calls DataArrayDouble::getIdsInRange().
+ * \param [in] vmin - a lower boundary of the range. Tuples with values less than \a
+ * vmin are not included in the result array.
+ * \param [in] vmax - an upper boundary of the range. Tuples with values more than \a
+ * vmax are not included in the result array.
+ * \return DataArrayInt * - a new instance of DataArrayInt holding ids of selected
+ * tuples. The caller is to delete this array using decrRef() as it is no
+ * more needed.
+ * \throw If the data array is not set.
+ * \throw If \a this->getNumberOfComponents() != 1.
+ */
+DataArrayInt *MEDCouplingFieldDouble::getIdsInRange(double vmin, double vmax) const
+{
+ if(getArray()==0)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::getIdsInRange : no default array set !");
+ return getArray()->getIdsInRange(vmin,vmax);
+}
+
+/*!
+ * Builds a newly created field, that the caller will have the responsability to deal with (decrRef()).
+ * This method makes the assumption that the field is correctly defined when this method is called, no check of this will be done.
+ * 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.
+ * Parameter \a part specifies **cell ids whatever the spatial discretization of this** (
+ * \ref ParaMEDMEM::ON_CELLS "ON_CELLS",
+ * \ref ParaMEDMEM::ON_NODES "ON_NODES",
+ * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT",
+ * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
+ * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
+ *
+ * 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].
+ * Then the returned field will lie on mesh having 3 cells and the returned field will contain 3 tuples.<br>
+ * 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>
+ * 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>
+ * 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().
+ *
+ * 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].
+ * 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
+ * will contain 6 tuples and \a this field will lie on this restricted mesh.
+ *
+ * \param [in] part - an array of cell ids to include to the result field.
+ * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The caller is to delete this field using decrRef() as it is no more needed.
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcfielddouble_subpart1 "Here is a C++ example".<br>
+ * \ref py_mcfielddouble_subpart1 "Here is a Python example".
+ * \endif
+ * \sa MEDCouplingFieldDouble::buildSubPartRange
+ */
+
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *part) const
+{
+ if(part==0)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : not empty array must be passed to this method !");
+ return buildSubPart(part->begin(),part->end());
+}
+
+/*!
+ * Builds a newly created field, that the caller will have the responsability to deal with.
+ * \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**.
+ * \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.
+ * \n Parameter [\a partBg, \a partEnd ) specifies **cell ids whatever the spatial discretization** of \a this (
+ * \ref ParaMEDMEM::ON_CELLS "ON_CELLS",
+ * \ref ParaMEDMEM::ON_NODES "ON_NODES",
+ * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT",
+ * \ref ParaMEDMEM::ON_GAUSS_NE "ON_GAUSS_NE",
+ * \ref ParaMEDMEM::ON_NODES_KR "ON_NODES_KR").
+ *
+ * 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].
+ * Then the returned field will lie on mesh having 3 cells and will contain 3 tuples.
+ *- 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().
+ *- 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().
+ *- 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().
+ *
+ * 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].
+ * 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
+ * will contain 6 tuples and \a this field will lie on this restricted mesh.
+ *
+ * \param [in] partBg - start (included) of input range of cell ids to select [ \a partBg, \a partEnd )
+ * \param [in] partEnd - end (not included) of input range of cell ids to select [ \a partBg, \a partEnd )
+ * \return a newly allocated field the caller should deal with.
+ *
+ * \throw if there is presence of an invalid cell id in [ \a partBg, \a partEnd ) regarding the number of cells of \a this->getMesh().
+ *
+ * \if ENABLE_EXAMPLES
+ * \ref cpp_mcfielddouble_subpart1 "Here a C++ example."<br>
+ * \ref py_mcfielddouble_subpart1 "Here a Python example."
+ * \endif
+ * \sa ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart(const DataArrayInt *) const, MEDCouplingFieldDouble::buildSubPartRange
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const
+{
+ if(!((const MEDCouplingFieldDiscretization *)_type))
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
+ DataArrayInt *arrSelect;
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arrSelect2(arrSelect);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
+ const MEDCouplingFieldDiscretization *disc=getDiscretization();
+ if(disc)
+ ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization>(disc->clonePart(partBg,partEnd)));
+ ret->setMesh(m);
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ std::vector<DataArrayDouble *> arrs;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrsSafe;
+ const int *arrSelBg=arrSelect->begin();
+ const int *arrSelEnd=arrSelect->end();
+ for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
+ {
+ DataArrayDouble *arr=0;
+ if(*iter)
+ arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
+ arrs.push_back(arr); arrsSafe.push_back(arr);
+ }
+ ret->_time_discr->setArrays(arrs,0);
+ return ret.retn();
+}
+
+/*!
+ * This method is equivalent to MEDCouplingFieldDouble::buildSubPart, the only difference is that the input range of cell ids is
+ * given using a range given \a begin, \a end and \a step to optimize the part computation.
+ *
+ * \sa MEDCouplingFieldDouble::buildSubPart
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPartRange(int begin, int end, int step) const
+{
+ if(!((const MEDCouplingFieldDiscretization *)_type))
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::buildSubPart : Expecting a not NULL spatial discretization !");
+ DataArrayInt *arrSelect;
+ int beginOut,endOut,stepOut;
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=_type->buildSubMeshDataRange(_mesh,begin,end,step,beginOut,endOut,stepOut,arrSelect);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arrSelect2(arrSelect);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=clone(false);//quick shallow copy.
+ const MEDCouplingFieldDiscretization *disc=getDiscretization();
+ if(disc)
+ ret->setDiscretization(MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretization>(disc->clonePartRange(begin,end,step)));
+ ret->setMesh(m);
+ std::vector<DataArrayDouble *> arrays;
+ _time_discr->getArrays(arrays);
+ std::vector<DataArrayDouble *> arrs;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > arrsSafe;
+ for(std::vector<DataArrayDouble *>::const_iterator iter=arrays.begin();iter!=arrays.end();iter++)
+ {
+ DataArrayDouble *arr=0;
+ if(*iter)
+ {
+ if(arrSelect)
+ {
+ const int *arrSelBg=arrSelect->begin();
+ const int *arrSelEnd=arrSelect->end();
+ arr=(*iter)->selectByTupleIdSafe(arrSelBg,arrSelEnd);
+ }
+ else
+ arr=(*iter)->selectByTupleId2(beginOut,endOut,stepOut);
+ }
+ arrs.push_back(arr); arrsSafe.push_back(arr);
+ }
+ ret->_time_discr->setArrays(arrs,0);
+ return ret.retn();
+}
+
+/*!
+ * Returns a type of \ref MEDCouplingTemporalDisc "time discretization" of \a this field.
+ * \return ParaMEDMEM::TypeOfTimeDiscretization - an enum item describing the time
+ * discretization type.
+ */
+TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const