X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingFieldDouble.cxx;h=b62261758b13128698674f07f82eff32873b47fe;hb=d7738d8c9d71b3002133b6267e2329a1f1daf97e;hp=4b3fad76b74b139dde07bd7420bf3da3469d6028;hpb=44e895361cc768555bc65bf01cac7311f3f373d9;p=modules%2Fmed.git diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 4b3fad76b..b62261758 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -85,7 +85,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::New(const MEDCouplingFieldTempla * 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 char *unit) +void MEDCouplingFieldDouble::setTimeUnit(const std::string& unit) { _time_discr->setTimeUnit(unit); } @@ -94,7 +94,7 @@ void MEDCouplingFieldDouble::setTimeUnit(const char *unit) * Returns a time unit of \a this field. * \return a string describing units in which time is measured. */ -const char *MEDCouplingFieldDouble::getTimeUnit() const +std::string MEDCouplingFieldDouble::getTimeUnit() const { return _time_discr->getTimeUnit(); } @@ -200,8 +200,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::deepCpy() const * \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."
* \ref py_mcfielddouble_buildNewTimeReprFromThis "Here is a Python example." + * \endif * \sa clone() */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const @@ -212,8 +214,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildNewTimeReprFromThis(TypeOfT disc=_type->clone(); MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),tdo,disc.retn()); ret->setMesh(getMesh()); - ret->setName(getName().c_str()); - ret->setDescription(getDescription().c_str()); + ret->setName(getName()); + ret->setDescription(getDescription()); return ret.retn(); } @@ -296,7 +298,6 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::cellToNodeDiscretization() const MEDCouplingAutoRefCountObjectPtr nsp(new MEDCouplingFieldDiscretizationP1); ret->setDiscretization(nsp); const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkCoherency call - int nbCells(m->getNumberOfCells()),nbNodes(m->getNumberOfNodes()); MEDCouplingAutoRefCountObjectPtr rn(DataArrayInt::New()),rni(DataArrayInt::New()); m->getReverseNodalConnectivity(rn,rni); MEDCouplingAutoRefCountObjectPtr rni2(rni->deltaShiftIndex()); @@ -306,7 +307,6 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::cellToNodeDiscretization() const std::vector< MEDCouplingAutoRefCountObjectPtr > outArrsSafe(sz); std::vector outArrs(sz); for(std::size_t j=0;jgetNumberOfComponents()); MEDCouplingAutoRefCountObjectPtr tmp(arrs[j]->selectByTupleIdSafe(rn->begin(),rn->end())); outArrsSafe[j]=(tmp->accumulatePerChunck(rni->begin(),rni->end())); tmp=0; outArrsSafe[j]->divideEqual(rni3); @@ -347,7 +347,6 @@ void MEDCouplingFieldDouble::copyTinyAttrFrom(const MEDCouplingFieldDouble *othe { _time_discr->copyTinyAttrFrom(*other->_time_discr); } - } void MEDCouplingFieldDouble::copyAllTinyAttrFrom(const MEDCouplingFieldDouble *other) @@ -452,10 +451,10 @@ std::string MEDCouplingFieldDouble::advancedRepr() const return ret.str(); } -void MEDCouplingFieldDouble::writeVTK(const char *fileName, bool isBinary) const +std::string MEDCouplingFieldDouble::writeVTK(const std::string& fileName, bool isBinary) const { std::vector fs(1,this); - MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary); + return MEDCouplingFieldDouble::WriteVTK(fileName,fs,isBinary); } bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const @@ -535,12 +534,12 @@ bool MEDCouplingFieldDouble::areStrictlyCompatible(const MEDCouplingField *other } /*! - * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatible method except that + * 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::areStrictlyCompatible(other)) + if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other)) return false; const MEDCouplingFieldDouble *otherC=dynamic_cast(other); if(!otherC) @@ -551,12 +550,12 @@ bool MEDCouplingFieldDouble::areCompatibleForMul(const MEDCouplingField *other) } /*! - * Method with same principle than MEDCouplingFieldDouble::areStrictlyCompatible method except that + * 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::areStrictlyCompatible(other)) + if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other)) return false; const MEDCouplingFieldDouble *otherC=dynamic_cast(other); if(!otherC) @@ -598,8 +597,10 @@ bool MEDCouplingFieldDouble::areCompatibleForMeld(const MEDCouplingFieldDouble * * \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".
* \ref py_mcfielddouble_renumberCells "Here is a Python example". + * \endif */ void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check) { @@ -633,10 +634,10 @@ void MEDCouplingFieldDouble::renumberCells(const int *old2NewBg, bool check) */ 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 !"); + 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 arrays; @@ -661,8 +662,10 @@ void MEDCouplingFieldDouble::renumberCellsWithoutMesh(const int *old2NewBg, bool * \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".
* \ref py_mcfielddouble_renumberNodes "Here is a Python example". + * \endif */ void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg, double eps) { @@ -754,8 +757,10 @@ DataArrayInt *MEDCouplingFieldDouble::getIdsInRange(double vmin, double vmax) co * \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".
* \ref py_mcfielddouble_subpart1 "Here is a Python example". + * \endif * \sa MEDCouplingFieldDouble::buildSubPartRange */ @@ -793,8 +798,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt * * \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."
* \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 @@ -880,7 +887,7 @@ TypeOfTimeDiscretization MEDCouplingFieldDouble::getTimeDiscretization() const } MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type), - _time_discr(MEDCouplingTimeDiscretization::New(td)) + _time_discr(MEDCouplingTimeDiscretization::New(td)) { } @@ -888,12 +895,12 @@ MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscr * ** WARINING : This method do not deeply copy neither mesh nor spatial discretization. Only a shallow copy (reference) is done for mesh and spatial discretization ! ** */ MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false), - _time_discr(MEDCouplingTimeDiscretization::New(td)) + _time_discr(MEDCouplingTimeDiscretization::New(td)) { } MEDCouplingFieldDouble::MEDCouplingFieldDouble(const MEDCouplingFieldDouble& other, bool deepCopy):MEDCouplingField(other,deepCopy), - _time_discr(other._time_discr->performCpy(deepCopy)) + _time_discr(other._time_discr->performCpy(deepCopy)) { } @@ -1124,14 +1131,14 @@ double MEDCouplingFieldDouble::normMax() const } /*! - * Computes sums of values of each component of \a this field wighted with + * Computes the weighted average of values of each component of \a this field, the weights being the * values returned by buildMeasureField(). * \param [out] res - pointer to an array of result sum values, of size at least \a * this->getNumberOfComponents(), that is to be allocated by the caller. - * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by - * buildMeasureField() that makes this method slower. If a user is sure that all - * cells of the underlying mesh have correct orientation, he can put \a isWAbs == - * \c false that speeds up this method. + * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weights computed by + * buildMeasureField(). It makes this method slower. If you are sure that all + * the cells of the underlying mesh have a correct orientation (no negative volume), you can put \a isWAbs == + * \c false to speed up the method. * \throw If the mesh is not set. * \throw If the data array is not set. */ @@ -1143,18 +1150,19 @@ void MEDCouplingFieldDouble::getWeightedAverageValue(double *res, bool isWAbs) c double deno=w->getArray()->accumulate(0); MEDCouplingAutoRefCountObjectPtr arr=getArray()->deepCpy(); arr->multiplyEqual(w->getArray()); - std::transform(arr->begin(),arr->end(),arr->getPointer(),std::bind2nd(std::multiplies(),1./deno)); arr->accumulate(res); + int nCompo = getArray()->getNumberOfComponents(); + std::transform(res,res+nCompo,res,std::bind2nd(std::multiplies(),1./deno)); } /*! - * Computes a sum of values of a given component of \a this field wighted with + * Computes the weighted average of values of a given component of \a this field, the weights being the * values returned by buildMeasureField(). * \param [in] compId - an index of the component of interest. - * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weighs computed by - * buildMeasureField() that makes this method slower. If a user is sure that all - * cells of the underlying mesh have correct orientation, he can put \a isWAbs == - * \c false that speeds up this method. + * \param [in] isWAbs - if \c true (default), \c abs() is applied to the weights computed by + * buildMeasureField(). It makes this method slower. If you are sure that all + * the cells of the underlying mesh have a correct orientation (no negative volume), you can put \a isWAbs == + * \c false to speed up the method. * \throw If the mesh is not set. * \throw If the data array is not set. * \throw If \a compId is not valid. @@ -1336,8 +1344,10 @@ void MEDCouplingFieldDouble::integral(bool isWAbs, double *res) const * \throw If the mesh is not set. * \throw If the mesh is not a structured one. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_getValueOnPos "Here is a C++ example".
* \ref py_mcfielddouble_getValueOnPos "Here is a Python example". + * \endif */ void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) const { @@ -1358,8 +1368,10 @@ void MEDCouplingFieldDouble::getValueOnPos(int i, int j, int k, double *res) con * \throw If the mesh is not set. * \throw If \a spaceLoc is out of the spatial discretization. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_getValueOn "Here is a C++ example".
* \ref py_mcfielddouble_getValueOn "Here is a Python example". + * \endif */ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) const { @@ -1384,8 +1396,10 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double *res) con * \throw If the mesh is not set. * \throw If any point in \a spaceLoc is out of the spatial discretization. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_getValueOnMulti "Here is a C++ example".
* \ref py_mcfielddouble_getValueOnMulti "Here is a Python example". + * \endif */ DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, int nbOfPoints) const { @@ -1409,8 +1423,10 @@ DataArrayDouble *MEDCouplingFieldDouble::getValueOnMulti(const double *spaceLoc, * \throw If \a spaceLoc is out of the spatial discretization. * \throw If \a time is not covered by \a this->_time_discr. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_getValueOn_time "Here is a C++ example".
* \ref py_mcfielddouble_getValueOn_time "Here is a Python example". + * \endif */ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, double *res) const { @@ -1430,7 +1446,7 @@ void MEDCouplingFieldDouble::getValueOn(const double *spaceLoc, double time, dou } /*! - * Apply a liner function to a given component of \a this field, so that + * Apply a linear function to a given component of \a this field, so that * a component value (x) becomes \f$ a * x + b \f$. * \param [in] a - the first coefficient of the function. * \param [in] b - the second coefficient of the function. @@ -1442,12 +1458,24 @@ void MEDCouplingFieldDouble::applyLin(double a, double b, int compoId) _time_discr->applyLin(a,b,compoId); } +/*! + * Apply a linear function to all components of \a this field, so that + * values (x) becomes \f$ a * x + b \f$. + * \param [in] a - the first coefficient of the function. + * \param [in] b - the second coefficient of the function. + * \throw If the data array(s) is(are) not set. + */ +void MEDCouplingFieldDouble::applyLin(double a, double b) +{ + _time_discr->applyLin(a,b); +} + /*! * This method sets \a this to a uniform scalar field with one component. * All tuples will have the same value 'value'. * An exception is thrown if no underlying mesh is defined. */ -MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) throw(INTERP_KERNEL::Exception) +MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::operator= : no mesh defined !"); @@ -1468,7 +1496,9 @@ MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator=(double value) throw(IN * \throw If \a func returns \c false. * \throw If the spatial discretization of \a this field is NULL. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_fillFromAnalytic_c_func "Here is a C++ example". + * \endif */ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate func) { @@ -1512,10 +1542,12 @@ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, FunctionToEvaluate f * \throw If the spatial discretization of \a this field is NULL. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_fillFromAnalytic "Here is a C++ example".
* \ref py_mcfielddouble_fillFromAnalytic "Here is a Python example". + * \endif */ -void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) +void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func) { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic : no mesh defined !"); @@ -1530,7 +1562,7 @@ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) * The function is applied to coordinates of value location points. For example, if * \a this field is on cells, the function is applied to cell barycenters.
* This method differs from - * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) "fillFromAnalytic()" + * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func) "fillFromAnalytic()" * by the way how variable * names, used in the function, are associated with components of coordinates of field * location points; here, a variable name corresponding to a component is retrieved from @@ -1559,10 +1591,12 @@ void MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) * \throw If the spatial discretization of \a this field is NULL. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_fillFromAnalytic2 "Here is a C++ example".
* \ref py_mcfielddouble_fillFromAnalytic2 "Here is a Python example". + * \endif */ -void MEDCouplingFieldDouble::fillFromAnalytic2(int nbOfComp, const char *func) +void MEDCouplingFieldDouble::fillFromAnalytic2(int nbOfComp, const std::string& func) { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !"); @@ -1577,7 +1611,7 @@ void MEDCouplingFieldDouble::fillFromAnalytic2(int nbOfComp, const char *func) * The function is applied to coordinates of value location points. For example, if * \a this field is on cells, the function is applied to cell barycenters.
* This method differs from - * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const char *func) "fillFromAnalytic()" + * \ref ParaMEDMEM::MEDCouplingFieldDouble::fillFromAnalytic(int nbOfComp, const std::string& func) "fillFromAnalytic()" * by the way how variable * names, used in the function, are associated with components of coordinates of field * location points; here, a component index of a variable is defined by a @@ -1606,10 +1640,12 @@ void MEDCouplingFieldDouble::fillFromAnalytic2(int nbOfComp, const char *func) * \throw If the spatial discretization of \a this field is NULL. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_fillFromAnalytic3 "Here is a C++ example".
* \ref py_mcfielddouble_fillFromAnalytic3 "Here is a Python example". + * \endif */ -void MEDCouplingFieldDouble::fillFromAnalytic3(int nbOfComp, const std::vector& varsOrder, const char *func) +void MEDCouplingFieldDouble::fillFromAnalytic3(int nbOfComp, const std::vector& varsOrder, const std::string& func) { if(!_mesh) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::fillFromAnalytic2 : no mesh defined !"); @@ -1627,7 +1663,9 @@ void MEDCouplingFieldDouble::fillFromAnalytic3(int nbOfComp, const std::vector * \ref py_mcfielddouble_applyFunc_val "Here is a Python example". + * \endif */ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val) { @@ -1683,10 +1723,12 @@ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, double val) * This function is to compute a field value basing on a current field value. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_applyFunc "Here is a C++ example".
* \ref py_mcfielddouble_applyFunc "Here is a Python example". + * \endif */ -void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) +void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) { _time_discr->applyFunc(nbOfComp,func); } @@ -1698,7 +1740,7 @@ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) * For more info on supported expressions that can be used in the function, see \ref * MEDCouplingArrayApplyFuncExpr.
* This method differs from - * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) "applyFunc()" + * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) "applyFunc()" * by the way how variable * names, used in the function, are associated with components of field values; * here, a variable name corresponding to a component is retrieved from @@ -1721,10 +1763,12 @@ void MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) * This function is to compute a new field value basing on a current field value. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_applyFunc2 "Here is a C++ example".
* \ref py_mcfielddouble_applyFunc2 "Here is a Python example". + * \endif */ -void MEDCouplingFieldDouble::applyFunc2(int nbOfComp, const char *func) +void MEDCouplingFieldDouble::applyFunc2(int nbOfComp, const std::string& func) { _time_discr->applyFunc2(nbOfComp,func); } @@ -1733,7 +1777,7 @@ void MEDCouplingFieldDouble::applyFunc2(int nbOfComp, const char *func) * Modifies values of \a this field by applying a function to each tuple of all * data arrays. * This method differs from - * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const char *func) "applyFunc()" + * \ref ParaMEDMEM::MEDCouplingFieldDouble::applyFunc(int nbOfComp, const std::string& func) "applyFunc()" * by the way how variable * names, used in the function, are associated with components of field values; * here, a component index of a variable is defined by a @@ -1758,10 +1802,12 @@ void MEDCouplingFieldDouble::applyFunc2(int nbOfComp, const char *func) * This function is to compute a new field value basing on a current field value. * \throw If computing \a func fails. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_applyFunc3 "Here is a C++ example".
* \ref py_mcfielddouble_applyFunc3 "Here is a Python example". + * \endif */ -void MEDCouplingFieldDouble::applyFunc3(int nbOfComp, const std::vector& varsOrder, const char *func) +void MEDCouplingFieldDouble::applyFunc3(int nbOfComp, const std::vector& varsOrder, const std::string& func) { _time_discr->applyFunc3(nbOfComp,varsOrder,func); } @@ -1788,10 +1834,12 @@ void MEDCouplingFieldDouble::applyFunc3(int nbOfComp, const std::vector * \ref py_mcfielddouble_applyFunc_same_nb_comp "Here is a Python example". + * \endif */ -void MEDCouplingFieldDouble::applyFunc(const char *func) +void MEDCouplingFieldDouble::applyFunc(const std::string& func) { _time_discr->applyFunc(func); } @@ -1801,7 +1849,7 @@ void MEDCouplingFieldDouble::applyFunc(const char *func) * The field will contain exactly the same number of components after the call. * Use is not warranted for the moment ! */ -void MEDCouplingFieldDouble::applyFuncFast32(const char *func) +void MEDCouplingFieldDouble::applyFuncFast32(const std::string& func) { _time_discr->applyFuncFast32(func); } @@ -1811,7 +1859,7 @@ void MEDCouplingFieldDouble::applyFuncFast32(const char *func) * The field will contain exactly the same number of components after the call. * Use is not warranted for the moment ! */ -void MEDCouplingFieldDouble::applyFuncFast64(const char *func) +void MEDCouplingFieldDouble::applyFuncFast64(const std::string& func) { _time_discr->applyFuncFast64(func); } @@ -1830,25 +1878,32 @@ int MEDCouplingFieldDouble::getNumberOfComponents() const } /*! + * Use MEDCouplingField::getNumberOfTuplesExpected instead of this method. This method will be removed soon, because it is + * confusing compared to getNumberOfComponents() and getNumberOfValues() behaviour. + * * Returns number of tuples in \a this field, that depends on * - the number of entities in the underlying mesh * - \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field (e.g. number * of Gauss points if \a this->getTypeOfField() == * \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT"). * - * The returned value does **not depend** on the number of tuples in the data array + * The returned value does \b not \b depend on the number of tuples in the data array * (which has to be equal to the returned value), \b contrary to * getNumberOfComponents() and getNumberOfValues() that retrieve information from the - * data array. + * data array (Sorry, it is confusing !). + * So \b this \b method \b behaves \b exactly \b as MEDCouplingField::getNumberOfTuplesExpected \b method. + * * \warning No checkCoherency() is done here. * For more info on the data arrays, see \ref MEDCouplingArrayPage. * \return int - the number of tuples. * \throw If the mesh is not set. * \throw If the spatial discretization of \a this field is NULL. * \throw If the spatial discretization is not fully defined. + * \sa MEDCouplingField::getNumberOfTuplesExpected */ int MEDCouplingFieldDouble::getNumberOfTuples() const { + //std::cerr << " ******* MEDCouplingFieldDouble::getNumberOfTuples is deprecated : use MEDCouplingField::getNumberOfTuplesExpected instead ! ******" << std::endl; if(!_mesh) throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !"); if(!((const MEDCouplingFieldDiscretization *)_type)) @@ -1885,12 +1940,12 @@ std::size_t MEDCouplingFieldDouble::getHeapMemorySizeWithoutChildren() const return MEDCouplingField::getHeapMemorySizeWithoutChildren(); } -std::vector MEDCouplingFieldDouble::getDirectChildren() const +std::vector MEDCouplingFieldDouble::getDirectChildrenWithNull() const { - std::vector ret(MEDCouplingField::getDirectChildren()); + std::vector ret(MEDCouplingField::getDirectChildrenWithNull()); if(_time_discr) { - std::vector ret2(_time_discr->getDirectChildren()); + std::vector ret2(_time_discr->getDirectChildrenWithNull()); ret.insert(ret.end(),ret2.begin(),ret2.end()); } return ret; @@ -1919,7 +1974,7 @@ void MEDCouplingFieldDouble::synchronizeTimeWithMesh() double val=_mesh->getTime(it,ordr); std::string timeUnit(_mesh->getTimeUnit()); setTime(val,it,ordr); - setTimeUnit(timeUnit.c_str()); + setTimeUnit(timeUnit); } /*! @@ -2034,6 +2089,7 @@ void MEDCouplingFieldDouble::getTinySerializationDbleInformation(std::vector& tinyInfoI, DataArrayInt *&dataInt, std::vector& arrays) { @@ -2050,6 +2106,25 @@ void MEDCouplingFieldDouble::resizeForUnserialization(const std::vector& ti _type->resizeForUnserialization(tinyInfoITmp3,dataInt); } +/*! + * This method is extremely close to resizeForUnserialization except that here the arrays in \a dataInt and in \a arrays are attached in \a this + * after having checked that size is correct. This method is used in python pickeling context to avoid copy of data. + * \sa resizeForUnserialization + */ +void MEDCouplingFieldDouble::checkForUnserialization(const std::vector& tinyInfoI, const DataArrayInt *dataInt, const std::vector& arrays) +{ + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform resizeForUnserialization !"); + std::vector tinyInfoITmp(tinyInfoI); + int sz=tinyInfoITmp.back(); + tinyInfoITmp.pop_back(); + std::vector tinyInfoITmp2(tinyInfoITmp.begin(),tinyInfoITmp.end()-sz); + std::vector tinyInfoI2(tinyInfoITmp2.begin()+3,tinyInfoITmp2.end()); + _time_discr->checkForUnserialization(tinyInfoI2,arrays); + std::vector tinyInfoITmp3(tinyInfoITmp.end()-sz,tinyInfoITmp.end()); + _type->checkForUnserialization(tinyInfoITmp3,dataInt); +} + void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoD, const std::vector& tinyInfoS) { if(!((const MEDCouplingFieldDiscretization *)_type)) @@ -2068,7 +2143,7 @@ void MEDCouplingFieldDouble::finishUnserialization(const std::vector& tinyI int nbOfElemS=(int)tinyInfoS.size(); _name=tinyInfoS[nbOfElemS-3]; _desc=tinyInfoS[nbOfElemS-2]; - setTimeUnit(tinyInfoS[nbOfElemS-1].c_str()); + setTimeUnit(tinyInfoS[nbOfElemS-1]); } /*! @@ -2103,8 +2178,10 @@ void MEDCouplingFieldDouble::serialize(DataArrayInt *&dataInt, std::vector * \ref py_mcfielddouble_changeUnderlyingMesh "Here is a Python example". + * \endif */ void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double precOnMesh, double eps) { @@ -2117,7 +2194,7 @@ void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, renumberCellsWithoutMesh(cellCor->getConstPointer(),false); if(nodeCor) renumberNodesWithoutMesh(nodeCor->getConstPointer(),nodeCor->getMaxValueInArray()+1,eps); - setMesh(const_cast(other)); + setMesh(other); } /*! @@ -2149,8 +2226,10 @@ void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, * \throw If the two fields are not coherent for merge. * \throw If field values at merged nodes (if any) deffer more than \a eps. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_substractInPlaceDM "Here is a C++ example".
* \ref py_mcfielddouble_substractInPlaceDM "Here is a Python example". + * \endif * \sa changeUnderlyingMesh(). */ void MEDCouplingFieldDouble::substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double precOnMesh, double eps) @@ -2600,7 +2679,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::maxPerTuple() const MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); std::ostringstream oss; oss << "Max_" << getName(); - ret->setName(oss.str().c_str()); + ret->setName(oss.str()); ret->setMesh(getMesh()); return ret.retn(); } @@ -2639,7 +2718,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::keepSelectedComponents(const std MEDCouplingTimeDiscretization *td=_time_discr->keepSelectedComponents(compoIds); td->copyTinyAttrFrom(*_time_discr); MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); - ret->setName(getName().c_str()); + ret->setName(getName()); ret->setMesh(getMesh()); return ret.retn(); } @@ -2685,13 +2764,15 @@ void MEDCouplingFieldDouble::sortPerTuple(bool asc) * \throw If the spatial discretization of \a f1 is NULL. * \throw If the time discretization of \a f1 is NULL. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".
* \ref py_mcfielddouble_MergeFields "Here is a Python example". + * \endif */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) { if(!f1->areCompatibleForMerge(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MergeFields on them ! Check support mesh, field nature, and spatial and time discretisation."); const MEDCouplingMesh *m1(f1->getMesh()),*m2(f2->getMesh()); if(!f1->_time_discr) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MergeFields : no time discr of f1 !"); @@ -2700,8 +2781,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFie MEDCouplingTimeDiscretization *td=f1->_time_discr->aggregate(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); - ret->setName(f1->getName().c_str()); - ret->setDescription(f1->getDescription().c_str()); + ret->setName(f1->getName()); + ret->setDescription(f1->getDescription()); if(m1) { MEDCouplingAutoRefCountObjectPtr m=m1->mergeMyselfWith(m2); @@ -2724,8 +2805,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const MEDCouplingFie * \throw If \a a is empty. * \throw If the fields are not compatible for the merge. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_MergeFields "Here is a C++ example".
* \ref py_mcfielddouble_MergeFields "Here is a Python example". + * \endif */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vector& a) { @@ -2740,7 +2823,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vectorareCompatibleForMerge(*it)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MergeFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MergeFields on them! Check support mesh, field nature, and spatial and time discretisation."); for(int i=0;i<(int)a.size();i++) { if(a[i]->getMesh()) @@ -2752,8 +2835,8 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vectoraggregate(tds); td->copyTinyAttrFrom(*(a[0]->_time_discr)); MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(a[0]->getNature(),td,a[0]->_type->clone()); - ret->setName(a[0]->getName().c_str()); - ret->setDescription(a[0]->getDescription().c_str()); + ret->setName(a[0]->getName()); + ret->setDescription(a[0]->getDescription()); if(ms2[0]) { MEDCouplingAutoRefCountObjectPtr m=MEDCouplingUMesh::MergeUMeshes(ms2); @@ -2781,7 +2864,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MergeFields(const std::vectorareCompatibleForMeld(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MeldFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MeldFields on them ! Check support mesh, field nature, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->meld(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); @@ -2807,11 +2890,11 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::DotFields(const MEDCouplingField { if(!f1) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DotFields : input field is NULL !"); - if(!f1->areStrictlyCompatible(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DotFields on them !"); + if(!f1->areStrictlyCompatibleForMulDiv(f2)) + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply DotFields on them! Check support mesh, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->dot(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret; } @@ -2838,11 +2921,11 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCoup { if(!f1) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::CrossProductFields : input field is NULL !"); - if(!f1->areStrictlyCompatible(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply CrossProductFields on them !"); + if(!f1->areStrictlyCompatibleForMulDiv(f2)) + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply CrossProductFields on them! Check support mesh, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->crossProduct(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); } @@ -2859,15 +2942,17 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::CrossProductFields(const MEDCoup * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they * differ not only in values. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".
* \ref py_mcfielddouble_MaxFields "Here is a Python example". + * \endif */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) { if(!f1) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MaxFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MaxFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MaxFields on them! Check support mesh, field nature, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->max(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); @@ -2887,15 +2972,17 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MaxFields(const MEDCouplingField * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they * differ not only in values. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_MaxFields "Here is a C++ example".
* \ref py_mcfielddouble_MaxFields "Here is a Python example". + * \endif */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) { if(!f1) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MinFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MinFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MinFields on them! Check support mesh, field nature, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->min(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); @@ -2941,7 +3028,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingField if(!f1) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::AddFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply AddFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply AddFields on them! Check support mesh, field nature, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->add(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); @@ -2959,10 +3046,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingField * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they * differ not only in values. */ -const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator+=(const MEDCouplingFieldDouble& other) { if(!areStrictlyCompatible(&other)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply += on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply += on them! Check support mesh, field nature, and spatial and time discretisation."); _time_discr->addEqual(other._time_discr); return *this; } @@ -2985,7 +3072,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplin if(!f1) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::SubstractFields : input field is NULL !"); if(!f1->areStrictlyCompatible(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply SubstractFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply SubstractFields on them! Check support mesh, field nature, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->substract(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); @@ -3003,10 +3090,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::SubstractFields(const MEDCouplin * \throw If the fields are not strictly compatible (areStrictlyCompatible()), i.e. they * differ not only in values. */ -const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCouplingFieldDouble& other) { if(!areStrictlyCompatible(&other)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply -= on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply -= on them! Check support mesh, field nature, and spatial and time discretisation."); _time_discr->substractEqual(other._time_discr); return *this; } @@ -3024,11 +3111,11 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator-=(const MEDCoupli * The two fields must have same number of tuples and same underlying mesh. * \param [in] f1 - a factor field. * \param [in] f2 - another factor field. - * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble. + * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, with no nature set. * The caller is to delete this result field using decrRef() as it is no more * needed. * \throw If either \a f1 or \a f2 is NULL. - * \throw If the fields are not compatible for production (areCompatibleForMul()), + * \throw If the fields are not compatible for multiplication (areCompatibleForMul()), * i.e. they differ not only in values and possibly number of components. */ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) @@ -3036,10 +3123,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCoupling if(!f1) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::MultiplyFields : input field is NULL !"); if(!f1->areCompatibleForMul(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply MultiplyFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply MultiplyFields on them! Check support mesh, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->multiply(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); } @@ -3057,19 +3144,20 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MultiplyFields(const MEDCoupling * * The two fields must have same number of tuples and same underlying mesh. * \param [in] other - an field to multiply to \a this one. - * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble. + * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, with no nature set. * The caller is to delete this result field using decrRef() as it is no more * needed. * \throw If \a other is NULL. - * \throw If the fields are not strictly compatible for production + * \throw If the fields are not strictly compatible for multiplication * (areCompatibleForMul()), * i.e. they differ not only in values and possibly in number of components. */ -const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCouplingFieldDouble& other) { if(!areCompatibleForMul(&other)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply *= on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply *= on them! Check support mesh, and spatial and time discretisation."); _time_discr->multiplyEqual(other._time_discr); + _nature = NoNature; return *this; } @@ -3084,7 +3172,7 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator*=(const MEDCoupli * * \param [in] f1 - a numerator field. * \param [in] f2 - a denominator field. - * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble. + * \return MEDCouplingFieldDouble * - the new instance of MEDCouplingFieldDouble, with no nature set. * The caller is to delete this result field using decrRef() as it is no more * needed. * \throw If either \a f1 or \a f2 is NULL. @@ -3096,10 +3184,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFi if(!f1) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::DivideFields : input field is NULL !"); if(!f1->areCompatibleForDiv(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply DivideFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply DivideFields on them! Check support mesh, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->divide(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); } @@ -3121,11 +3209,12 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::DivideFields(const MEDCouplingFi * \throw If the fields are not compatible for division (areCompatibleForDiv()), * i.e. they differ not only in values and possibly in number of components. */ -const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator/=(const MEDCouplingFieldDouble& other) { if(!areCompatibleForDiv(&other)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply /= on them! Check support mesh, and spatial and time discretisation."); _time_discr->divideEqual(other._time_discr); + _nature = NoNature; return *this; } @@ -3139,10 +3228,10 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingField if(!f1) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::PowFields : input field is NULL !"); if(!f1->areCompatibleForMul(f2)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply PowFields on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply PowFields on them! Check support mesh, and spatial and time discretisation."); MEDCouplingTimeDiscretization *td=f1->_time_discr->pow(f2->_time_discr); td->copyTinyAttrFrom(*f1->_time_discr); - MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(f1->getNature(),td,f1->_type->clone()); + MEDCouplingAutoRefCountObjectPtr ret=new MEDCouplingFieldDouble(NoNature,td,f1->_type->clone()); ret->setMesh(f1->getMesh()); return ret.retn(); } @@ -3152,16 +3241,17 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::PowFields(const MEDCouplingField * * \sa MEDCouplingFieldDouble::PowFields */ -MEDCouplingFieldDouble *MEDCouplingFieldDouble::operator^(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) +MEDCouplingFieldDouble *MEDCouplingFieldDouble::operator^(const MEDCouplingFieldDouble& other) const { return PowFields(this,&other); } -const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) +const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCouplingFieldDouble& other) { if(!areCompatibleForDiv(&other)) - throw INTERP_KERNEL::Exception("Fields are not compatible ; unable to apply /= on them !"); + throw INTERP_KERNEL::Exception("Fields are not compatible. Unable to apply ^= on them! Check support mesh, and spatial and time discretisation."); _time_discr->powEqual(other._time_discr); + _nature = NoNature; return *this; } @@ -3178,13 +3268,15 @@ const MEDCouplingFieldDouble &MEDCouplingFieldDouble::operator^=(const MEDCoupli * \throw If the mesh is not set. * \throw If any of the fields has no name. * + * \if ENABLE_EXAMPLES * \ref cpp_mcfielddouble_WriteVTK "Here is a C++ example".
* \ref py_mcfielddouble_WriteVTK "Here is a Python example". + * \endif */ -void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vector& fs, bool isBinary) +std::string MEDCouplingFieldDouble::WriteVTK(const std::string& fileName, const std::vector& fs, bool isBinary) { if(fs.empty()) - return; + return std::string(); std::size_t nfs=fs.size(); if(!fs[0]) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : 1st instance of field is NULL !"); @@ -3196,6 +3288,7 @@ void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vectorgetVTKFileNameOf(fileName)); MEDCouplingAutoRefCountObjectPtr byteArr; if(isBinary) { byteArr=DataArrayByte::New(); byteArr->alloc(0,1); } @@ -3211,13 +3304,14 @@ void MEDCouplingFieldDouble::WriteVTK(const char *fileName, const std::vectorgetTypeOfField(); if(typ==ON_CELLS) - cur->getArray()->writeVTK(coss,8,cur->getName().c_str(),byteArr); + cur->getArray()->writeVTK(coss,8,cur->getName(),byteArr); else if(typ==ON_NODES) - cur->getArray()->writeVTK(noss,8,cur->getName().c_str(),byteArr); + cur->getArray()->writeVTK(noss,8,cur->getName(),byteArr); else throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::WriteVTK : only node and cell fields supported for the moment !"); } - m->writeVTKAdvanced(fileName,coss.str(),noss.str(),byteArr); + m->writeVTKAdvanced(ret,coss.str(),noss.str(),byteArr); + return ret; } void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const @@ -3225,12 +3319,12 @@ void MEDCouplingFieldDouble::reprQuickOverview(std::ostream& stream) const stream << "MEDCouplingFieldDouble C++ instance at " << this << ". Name : \"" << _name << "\"." << std::endl; const char *nat=0; try - { + { nat=MEDCouplingNatureOfField::GetRepr(_nature); stream << "Nature of field : " << nat << ".\n"; - } + } catch(INTERP_KERNEL::Exception& /*e*/) - { } + { } const MEDCouplingFieldDiscretization *fd(_type); if(!fd) stream << "No spatial discretization set !";