From aedf2c69319768f36ecd8a144f5ac07124d245a7 Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 9 Apr 2013 14:59:15 +0000 Subject: [PATCH] Extend operator __neg__ of MEDCouplingFieldDouble --- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 11 ++++++++++ src/MEDCoupling/MEDCouplingFieldDouble.hxx | 1 + .../MEDCouplingTimeDiscretization.cxx | 21 +++++++++++++++++++ .../MEDCouplingTimeDiscretization.hxx | 1 + src/MEDCoupling_Swig/MEDCouplingCommon.i | 8 +++++++ 5 files changed, 42 insertions(+) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index afa52106d..8eefe13df 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -1852,6 +1852,17 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::MinFields(const MEDCouplingField return ret; } +MEDCouplingFieldDouble *MEDCouplingFieldDouble::negate() const throw(INTERP_KERNEL::Exception) +{ + if(!((const MEDCouplingFieldDiscretization *)_type)) + throw INTERP_KERNEL::Exception("No spatial discretization underlying this field to perform negate !"); + MEDCouplingTimeDiscretization *td=_time_discr->negate(); + td->copyTinyAttrFrom(*_time_discr); + MEDCouplingFieldDouble *ret=new MEDCouplingFieldDouble(getNature(),td,_type->clone()); + ret->setMesh(getMesh()); + return ret; +} + MEDCouplingFieldDouble *MEDCouplingFieldDouble::AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception) { if(!f1) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 8d245f56d..5eb82cf67 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -171,6 +171,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return MaxFields(this,&other); } static MEDCouplingFieldDouble *MinFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return MinFields(this,&other); } + MEDCouplingFieldDouble *negate() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception) { return AddFields(this,&other); } const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *AddFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 7ae3e992e..eb185f85c 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -517,6 +517,27 @@ MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::magnitude() const return ret; } +MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::negate() const throw(INTERP_KERNEL::Exception) +{ + std::vector arrays; + getArrays(arrays); + std::vector< MEDCouplingAutoRefCountObjectPtr > arrays2(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + { + if(arrays[j]) + arrays2[j]=arrays[j]->negate(); + else + arrays2[j]=0; + } + std::vector arrays3(arrays.size()); + for(int j=0;j<(int)arrays.size();j++) + arrays3[j]=arrays2[j]; + MEDCouplingTimeDiscretization *ret=MEDCouplingTimeDiscretization::New(getEnum()); + ret->setTimeUnit(getTimeUnit()); + ret->setArrays(arrays3,0); + return ret; +} + MEDCouplingTimeDiscretization *MEDCouplingTimeDiscretization::maxPerTuple() const throw(INTERP_KERNEL::Exception) { std::vector arrays; diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index 97d134e40..116d20d29 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -128,6 +128,7 @@ namespace ParaMEDMEM virtual MEDCouplingTimeDiscretization *trace() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *deviator() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *magnitude() const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingTimeDiscretization *negate() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *maxPerTuple() const throw(INTERP_KERNEL::Exception); virtual MEDCouplingTimeDiscretization *keepSelectedComponents(const std::vector& compoIds) const throw(INTERP_KERNEL::Exception); virtual void setSelectedComponents(const MEDCouplingTimeDiscretization *other, const std::vector& compoIds) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 1c7efd9d4..6374da1f1 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -129,9 +129,11 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingFieldDouble::MultiplyFields; %newobject ParaMEDMEM::MEDCouplingFieldDouble::DivideFields; %newobject ParaMEDMEM::MEDCouplingFieldDouble::min; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::negate; %newobject ParaMEDMEM::MEDCouplingFieldDouble::getIdsInRange; %newobject ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart; %newobject ParaMEDMEM::MEDCouplingFieldDouble::__getitem__; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::__neg__; %newobject ParaMEDMEM::MEDCouplingFieldDouble::__add__; %newobject ParaMEDMEM::MEDCouplingFieldDouble::__sub__; %newobject ParaMEDMEM::MEDCouplingFieldDouble::__mul__; @@ -2946,6 +2948,7 @@ namespace ParaMEDMEM static MEDCouplingFieldDouble *MultiplyFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); static MEDCouplingFieldDouble *DivideFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *negate() const throw(INTERP_KERNEL::Exception); %extend { MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME) { @@ -3673,6 +3676,11 @@ namespace ParaMEDMEM } } + MEDCouplingFieldDouble *__neg__() const throw(INTERP_KERNEL::Exception) + { + return self->negate(); + } + PyObject *___iadd___(PyObject *trueSelf, const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception) { *self+=other; -- 2.39.2