From: Anthony Geay Date: Fri, 22 Jul 2016 08:31:27 +0000 (+0200) Subject: Very first implementation of MEDCouplingFieldInt. X-Git-Tag: V8_1_0a1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aa6820a40a441fcd2b90b0b4d29fd077f6638b56;p=tools%2Fmedcoupling.git Very first implementation of MEDCouplingFieldInt. --- diff --git a/src/MEDCoupling/CMakeLists.txt b/src/MEDCoupling/CMakeLists.txt index 65be9e5a8..826cbc6df 100644 --- a/src/MEDCoupling/CMakeLists.txt +++ b/src/MEDCoupling/CMakeLists.txt @@ -35,6 +35,7 @@ INCLUDE_DIRECTORIES( SET(medcoupling_SOURCES MEDCouplingField.cxx MEDCouplingFieldDouble.cxx + MEDCouplingFieldInt.cxx MEDCouplingUMesh.cxx MEDCoupling1GTUMesh.cxx MEDCouplingMemArray.cxx diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index 641c4f909..810f4d379 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -33,6 +33,8 @@ namespace MEDCoupling MCAuto(const MCAuto& other):_ptr(0) { referPtr(other._ptr); } MCAuto(T *ptr=0):_ptr(ptr) { } ~MCAuto() { destroyPtr(); } + bool isNull() const { return _ptr==0; } + bool isNotNull() const { return !isNull(); } bool operator==(const MCAuto& other) const { return _ptr==other._ptr; } bool operator==(const T *other) const { return _ptr==other; } MCAuto &operator=(const MCAuto& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; } diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 4b9c9cdcf..293d8aede 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -26,6 +26,14 @@ using namespace MEDCoupling; +void MEDCouplingField::checkConsistencyLight() const +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !"); + if(_type.isNull()) + throw INTERP_KERNEL::Exception("MEDCouplingField::checkConsistencyLight : no spatial discretization !"); +} + bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const { if(!other) diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index 9d4b9824f..dc71d95f9 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -44,7 +44,7 @@ namespace MEDCoupling class MEDCouplingField : public RefCountObject, public TimeLabel { public: - MEDCOUPLING_EXPORT virtual void checkConsistencyLight() const = 0; + MEDCOUPLING_EXPORT virtual void checkConsistencyLight() const; MEDCOUPLING_EXPORT virtual bool areCompatibleForMerge(const MEDCouplingField *other) const; MEDCOUPLING_EXPORT virtual bool areStrictlyCompatible(const MEDCouplingField *other) const; MEDCOUPLING_EXPORT virtual bool areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const; diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index fd1fd062f..b3e56754c 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -924,10 +924,7 @@ MEDCouplingFieldDouble::~MEDCouplingFieldDouble() */ void MEDCouplingFieldDouble::checkConsistencyLight() const { - if(!_mesh) - throw INTERP_KERNEL::Exception("Field invalid because no mesh specified !"); - if(!((const MEDCouplingFieldDiscretization *)_type)) - throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::checkConsistencyLight : no spatial discretization !"); + MEDCouplingField::checkConsistencyLight(); _time_discr->checkConsistencyLight(); _type->checkCoherencyBetween(_mesh,getArray()); } diff --git a/src/MEDCoupling/MEDCouplingFieldInt.cxx b/src/MEDCoupling/MEDCouplingFieldInt.cxx new file mode 100644 index 000000000..06c4447b1 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingFieldInt.cxx @@ -0,0 +1,111 @@ +// Copyright (C) 2007-2016 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, 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Yann Pora (EDF R&D) + +#include "MEDCouplingFieldInt.hxx" + +using namespace MEDCoupling; + +MEDCouplingFieldInt *MEDCouplingFieldInt::New(TypeOfField type, TypeOfTimeDiscretization td) +{ + return new MEDCouplingFieldInt(type,td); +} + +void MEDCouplingFieldInt::checkConsistencyLight() const +{ + MEDCouplingField::checkConsistencyLight(); + if(_array.isNull()) + throw INTERP_KERNEL::Exception("MEDCouplingFieldInt::checkConsistencyLight : array is null !"); + _type->checkCoherencyBetween(_mesh,getArray()); +} + +std::string MEDCouplingFieldInt::simpleRepr() const +{ + return std::string(); +} + +void MEDCouplingFieldInt::reprQuickOverview(std::ostream& stream) const +{ +} + +void MEDCouplingFieldInt::setTimeUnit(const std::string& unit) +{ + _time_discr->setTimeUnit(unit); +} + +std::string MEDCouplingFieldInt::getTimeUnit() const +{ + return _time_discr->getTimeUnit(); +} + +void MEDCouplingFieldInt::setTime(double val, int iteration, int order) +{ + _time_discr->setTime(val,iteration,order); +} + +double MEDCouplingFieldInt::getTime(int& iteration, int& order) const +{ + return _time_discr->getTime(iteration,order); +} + +void MEDCouplingFieldInt::setArray(DataArrayInt *array) +{ + MCAuto array2(array); + if(array2.isNotNull()) + array2->incrRef(); + _array=array2; + //_time_discr->setArray(array,this); +} + +const DataArrayInt *MEDCouplingFieldInt::getArray() const +{ + return _array; +} + +DataArrayInt *MEDCouplingFieldInt::getArray() +{ + return _array; +} + +MEDCouplingFieldInt::MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingField(type),_time_discr(MEDCouplingTimeDiscretization::New(td)) +{ +} + +MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy):MEDCouplingField(other,deepCopy),_time_discr(other._time_discr->performCopyOrIncrRef(deepCopy)) +{ + if(other._array.isNull()) + return ; + if(deepCopy) + { + _array=other._array->deepCopy(); + } + else + { + _array=other._array; + } +} + +MEDCouplingFieldInt::MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type):MEDCouplingField(type,n),_time_discr(td) +{ +} + +MEDCouplingFieldInt::~MEDCouplingFieldInt() +{ + delete _time_discr; +} diff --git a/src/MEDCoupling/MEDCouplingFieldInt.hxx b/src/MEDCoupling/MEDCouplingFieldInt.hxx new file mode 100644 index 000000000..5986efb60 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingFieldInt.hxx @@ -0,0 +1,58 @@ +// Copyright (C) 2007-2016 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, 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Yann Pora (EDF R&D) + +#ifndef __PARAMEDMEM_MEDCOUPLINGFIELDINT_HXX__ +#define __PARAMEDMEM_MEDCOUPLINGFIELDINT_HXX__ + +#include "MEDCoupling.hxx" +#include "MEDCouplingField.hxx" +#include "MEDCouplingTimeDiscretization.hxx" +#include "MEDCouplingMemArray.hxx" + +#include + +namespace MEDCoupling +{ + class MEDCouplingFieldInt : public MEDCouplingField + { + public: + MEDCOUPLING_EXPORT static MEDCouplingFieldInt *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); + MEDCOUPLING_EXPORT void checkConsistencyLight() const; + MEDCOUPLING_EXPORT std::string simpleRepr() const; + MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; + MEDCOUPLING_EXPORT void setTimeUnit(const std::string& unit); + MEDCOUPLING_EXPORT std::string getTimeUnit() const; + MEDCOUPLING_EXPORT void setTime(double val, int iteration, int order); + MEDCOUPLING_EXPORT double getTime(int& iteration, int& order) const; + MEDCOUPLING_EXPORT void setArray(DataArrayInt *array); + MEDCOUPLING_EXPORT const DataArrayInt *getArray() const; + MEDCOUPLING_EXPORT DataArrayInt *getArray(); + protected: + MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td); + MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy); + MEDCouplingFieldInt(NatureOfField n, MEDCouplingTimeDiscretization *td, MEDCouplingFieldDiscretization *type); + ~MEDCouplingFieldInt(); + private: + MEDCouplingTimeDiscretization *_time_discr; + MCAuto _array;// agy : don't panic ! this is temporary ! templatization of time discr is planned ! + }; +} + +#endif diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index f6306b3a5..a0821c1bf 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -4280,6 +4280,27 @@ class MEDCouplingBasicsTest5(unittest.TestCase): self.assertTrue(arrI2.isEqual(arrI)) pass + def testFieldIntIsOnStage1(self): + """ My first test with field int.""" + m=MEDCouplingCMesh() + m.setName("mesh") + arrX=DataArrayDouble([0,1,2,3]) + m.setCoords(arrX,arrX) + f=MEDCouplingFieldInt(ON_CELLS) + f.setMesh(m) + arr=DataArrayInt(8) ; arr.iota() ;f.setArray(arr) + self.assertRaises(InterpKernelException,f.checkConsistencyLight) + arr=DataArrayInt(9) ; arr.iota() ;f.setArray(arr) + f.checkConsistencyLight() + f.setTimeUnit("ms") + self.assertEqual(f.getTimeUnit(),"ms") + f.setTime(3.2,5,6) + a,b,c=f.getTime() + self.assertEqual(b,5) + self.assertEqual(c,6) + self.assertEqual(a,3.2,12) + pass + pass if __name__ == '__main__': diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 6a76ed360..eaaa5eb64 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -37,6 +37,7 @@ #include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingField.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingFieldInt.hxx" #include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingGaussLocalization.hxx" #include "MCAuto.hxx" @@ -228,6 +229,8 @@ using namespace INTERP_KERNEL; %newobject MEDCoupling::MEDCouplingFieldDouble::nodeToCellDiscretization; %newobject MEDCoupling::MEDCouplingFieldDouble::cellToNodeDiscretization; %newobject MEDCoupling::MEDCouplingFieldDouble::getValueOnMulti; +%newobject MEDCoupling::MEDCouplingFieldInt::New; +%newobject MEDCoupling::MEDCouplingFieldInt::getArray; %newobject MEDCoupling::MEDCouplingFieldTemplate::New; %newobject MEDCoupling::MEDCouplingMesh::deepCopy; %newobject MEDCoupling::MEDCouplingMesh::clone; @@ -5148,6 +5151,53 @@ namespace MEDCoupling } } }; + + class MEDCouplingFieldInt : public MEDCouplingField + { + public: + static MEDCouplingFieldInt *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME); + void setTimeUnit(const std::string& unit) throw(INTERP_KERNEL::Exception); + std::string getTimeUnit() const throw(INTERP_KERNEL::Exception); + void setTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); + void setArray(DataArrayInt *array) throw(INTERP_KERNEL::Exception); + %extend { + MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME) + { + return MEDCouplingFieldInt::New(type,td); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + std::string __repr__() const throw(INTERP_KERNEL::Exception) + { + std::ostringstream oss; + self->reprQuickOverview(oss); + return oss.str(); + } + + DataArrayInt *getArray() throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret=self->getArray(); + if(ret) + ret->incrRef(); + return ret; + } + + PyObject *getTime() throw(INTERP_KERNEL::Exception) + { + int tmp1,tmp2; + double tmp0=self->getTime(tmp1,tmp2); + PyObject *res = PyList_New(3); + PyList_SetItem(res,0,SWIG_From_double(tmp0)); + PyList_SetItem(res,1,SWIG_From_int(tmp1)); + PyList_SetItem(res,2,SWIG_From_int(tmp2)); + return res; + } + } + }; class MEDCouplingDefinitionTime {