Salome HOME
Very first implementation of MEDCouplingFieldInt. V8_1_0a1
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 22 Jul 2016 08:31:27 +0000 (10:31 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 22 Jul 2016 08:31:27 +0000 (10:31 +0200)
src/MEDCoupling/CMakeLists.txt
src/MEDCoupling/MCAuto.hxx
src/MEDCoupling/MEDCouplingField.cxx
src/MEDCoupling/MEDCouplingField.hxx
src/MEDCoupling/MEDCouplingFieldDouble.cxx
src/MEDCoupling/MEDCouplingFieldInt.cxx [new file with mode: 0644]
src/MEDCoupling/MEDCouplingFieldInt.hxx [new file with mode: 0644]
src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 65be9e5a8e4eb1515bf14d638aaca8bdaacbda40..826cbc6dff7805fc61fc4717a21506cddb23b2d1 100644 (file)
@@ -35,6 +35,7 @@ INCLUDE_DIRECTORIES(
 SET(medcoupling_SOURCES
   MEDCouplingField.cxx
   MEDCouplingFieldDouble.cxx
+  MEDCouplingFieldInt.cxx
   MEDCouplingUMesh.cxx
   MEDCoupling1GTUMesh.cxx
   MEDCouplingMemArray.cxx
index 641c4f9096794b058cfa713eac59e9d57c52b713..810f4d3799fdd50fc209c729e34f09bfbcf1c7e6 100644 (file)
@@ -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; }
index 4b9c9cdcf1c7030d82855567a804ffc2a88740cf..293d8aede9692c3c2e945b99b95a63f8c5e2b9e9 100644 (file)
 
 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)
index 9d4b9824f8445f442a282d68ce945390738f58fb..dc71d95f906e69b0eda615ed99146040ff80da7d 100644 (file)
@@ -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;
index fd1fd062f64d937c24957ff14548dd9c2df71034..b3e56754cf4500cf5471c161809501b9eb8d5630 100644 (file)
@@ -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 (file)
index 0000000..06c4447
--- /dev/null
@@ -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<DataArrayInt> 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 (file)
index 0000000..5986efb
--- /dev/null
@@ -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 <string>
+
+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<DataArrayInt> _array;// agy : don't panic ! this is temporary ! templatization of time discr is planned !
+  };
+}
+
+#endif
index f6306b3a5615a4cbd26f6057b72522e419f50415..a0821c1bf1ce9c928df88f1edbf835d27173ca5b 100644 (file)
@@ -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__':
index 6a76ed3607e0010b72ac7a3172389dbdd67ea13d..eaaa5eb64a0b231a85eb6c4dd57c49281cf1af08 100644 (file)
@@ -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
   {