SET(medcoupling_SOURCES
MEDCouplingField.cxx
MEDCouplingFieldDouble.cxx
+ MEDCouplingFieldInt.cxx
MEDCouplingUMesh.cxx
MEDCoupling1GTUMesh.cxx
MEDCouplingMemArray.cxx
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; }
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)
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;
*/
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());
}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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
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__':
#include "MEDCoupling1GTUMesh.hxx"
#include "MEDCouplingField.hxx"
#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldInt.hxx"
#include "MEDCouplingFieldTemplate.hxx"
#include "MEDCouplingGaussLocalization.hxx"
#include "MCAuto.hxx"
%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;
}
}
};
+
+ 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
{