throw INTERP_KERNEL::Exception("MEDCouplingField::checkConsistencyLight : no spatial discretization !");
}
-bool MEDCouplingField::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const
+bool MEDCouplingField::isEqualIfNotWhyProtected(const MEDCouplingField *other, double meshPrec, std::string& reason) const
{
if(!other)
throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualIfNotWhy : other instance is NULL !");
reason=oss.str();
return false;
}
- if(!_type->isEqualIfNotWhy(other->_type,valsPrec,reason))
+ if(!_type->isEqualIfNotWhy(other->_type,meshPrec,reason))
{
reason.insert(0,"Spatial discretizations differ :");
return false;
return ret;
}
-/*!
- * Checks if \a this and another MEDCouplingField are fully equal.
- * \param [in] other - the field to compare with \a this one.
- * \param [in] meshPrec - precision used to compare node coordinates of the underlying mesh.
- * \param [in] valsPrec - precision used to compare field values.
- * \return bool - \c true if the two fields are equal, \c false else.
- * \throw If \a other is NULL.
- */
-bool MEDCouplingField::isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const
-{
- std::string tmp;
- return isEqualIfNotWhy(other,meshPrec,valsPrec,tmp);
-}
-
/*!
* Checks if \a this and another MEDCouplingField are equal. The textual
* information like names etc. is not considered.
* \param [in] other - the field to compare with \a this one.
* \param [in] meshPrec - precision used to compare node coordinates of the underlying mesh.
- * \param [in] valsPrec - precision used to compare field values.
* \return bool - \c true if the two fields are equal, \c false else.
* \throw If \a other is NULL.
* \throw If the spatial discretization of \a this field is NULL.
*/
-bool MEDCouplingField::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
+bool MEDCouplingField::isEqualWithoutConsideringStrProtected(const MEDCouplingField *other, double meshPrec) const
{
if(!other)
throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : input field is NULL !");
if(!_type)
throw INTERP_KERNEL::Exception("MEDCouplingField::isEqualWithoutConsideringStr : spatial discretization of this is NULL !");
- if(!_type->isEqualWithoutConsideringStr(other->_type,valsPrec))
+ if(!_type->isEqualWithoutConsideringStr(other->_type,meshPrec))
return false;
if(_nature!=other->_nature)
return false;
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;
- MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const;
- MEDCOUPLING_EXPORT virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const;
- MEDCOUPLING_EXPORT virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const;
MEDCOUPLING_EXPORT virtual void copyTinyStringsFrom(const MEDCouplingField *other);
MEDCOUPLING_EXPORT void setMesh(const MEDCoupling::MEDCouplingMesh *mesh);
MEDCOUPLING_EXPORT const MEDCoupling::MEDCouplingMesh *getMesh() const { return _mesh; }
MEDCOUPLING_EXPORT MEDCouplingField(const MEDCouplingField& other, bool deepCopy=true);
MEDCOUPLING_EXPORT MEDCouplingField(MEDCouplingFieldDiscretization *type, NatureOfField nature=NoNature);
MEDCOUPLING_EXPORT virtual ~MEDCouplingField();
+ MEDCOUPLING_EXPORT bool isEqualIfNotWhyProtected(const MEDCouplingField *other, double meshPrec, std::string& reason) const;
+ MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrProtected(const MEDCouplingField *other, double meshPrec) const;
protected:
std::string _name;
std::string _desc;
#include "MEDCouplingFieldTemplate.hxx"
#include "MEDCouplingFieldT.txx"
#include "MEDCouplingFieldInt.hxx"
+#include "MEDCouplingFieldFloat.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingTimeDiscretization.hxx"
#include "MEDCouplingFieldDiscretization.hxx"
return getArray()->findIdsInRange(vmin,vmax);
}
-MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const
+template<class U>
+typename Traits<U>::FieldType *ConvertToUField(const MEDCouplingFieldDouble *self)
{
- MCAuto<MEDCouplingFieldTemplate> tmp(MEDCouplingFieldTemplate::New(*this));
+ MCAuto<MEDCouplingFieldTemplate> tmp(MEDCouplingFieldTemplate::New(*self));
int t1,t2;
- double t0(getTime(t1,t2));
- MCAuto<MEDCouplingFieldInt> ret(MEDCouplingFieldInt::New(*tmp,getTimeDiscretization()));
+ double t0(self->getTime(t1,t2));
+ MCAuto<typename Traits<U>::FieldType > ret(Traits<U>::FieldType::New(*tmp,self->getTimeDiscretization()));
ret->setTime(t0,t1,t2);
- if(getArray())
+ if(self->getArray())
{
- MCAuto<DataArrayInt> arr(getArray()->convertToIntArr());
+ MCAuto<typename Traits<U>::ArrayType> arr(self->getArray()->convertToOtherTypeOfArr<U>());
ret->setArray(arr);
}
return ret.retn();
}
+MEDCouplingFieldInt *MEDCouplingFieldDouble::convertToIntField() const
+{
+ return ConvertToUField<int>(this);
+}
+
+MEDCouplingFieldFloat *MEDCouplingFieldDouble::convertToFloatField() const
+{
+ return ConvertToUField<float>(this);
+}
+
MEDCouplingFieldDouble::MEDCouplingFieldDouble(TypeOfField type, TypeOfTimeDiscretization td):MEDCouplingFieldT<double>(type,MEDCouplingTimeDiscretization::New(td))
{
}
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *nodeToCellDiscretization() const;
MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cellToNodeDiscretization() const;
MEDCOUPLING_EXPORT MEDCouplingFieldInt *convertToIntField() const;
+ MEDCOUPLING_EXPORT MEDCouplingFieldFloat *convertToFloatField() const;
MEDCOUPLING_EXPORT double getIJK(int cellId, int nodeIdInCell, int compoId) const;
MEDCOUPLING_EXPORT double accumulate(int compId) const;
MEDCOUPLING_EXPORT void accumulate(double *res) const;
MEDCOUPLING_EXPORT double getStartTime(int& iteration, int& order) const { return _time_discr->getStartTime(iteration,order); }
MEDCOUPLING_EXPORT double getEndTime(int& iteration, int& order) const { return _time_discr->getEndTime(iteration,order); }
MEDCOUPLING_EXPORT T getIJ(int tupleId, int compoId) const { return getArray()->getIJ(tupleId,compoId); }
- MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const;
- MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const;
+ MEDCOUPLING_EXPORT virtual bool isEqual(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec) const;
+ MEDCOUPLING_EXPORT virtual bool isEqualIfNotWhy(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec, std::string& reason) const;
+ MEDCOUPLING_EXPORT virtual bool isEqualWithoutConsideringStr(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec) const;
MEDCOUPLING_EXPORT void copyTinyStringsFrom(const MEDCouplingField *other);
MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingField *other) const;
MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const;
}
return ret.retn();
}
+
+ template<class T>
+ bool MEDCouplingFieldT<T>::isEqual(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec) const
+ {
+ std::string tmp;
+ return isEqualIfNotWhy(other,meshPrec,valsPrec,tmp);
+ }
template<class T>
- bool MEDCouplingFieldT<T>::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const
+ bool MEDCouplingFieldT<T>::isEqualIfNotWhy(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec, std::string& reason) const
{
if(!other)
throw INTERP_KERNEL::Exception("MEDCouplingFieldT::isEqualIfNotWhy : other instance is NULL !");
- const MEDCouplingFieldT<T> *otherC(dynamic_cast<const MEDCouplingFieldT<T> *>(other));
- if(!otherC)
- {
- reason="field given in input is not castable in MEDCouplingFieldT !";
- return false;
- }
- if(!MEDCouplingField::isEqualIfNotWhy(other,meshPrec,valsPrec,reason))
+ if(!isEqualIfNotWhyProtected(other,meshPrec,reason))
return false;
- if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,T(valsPrec),reason))
+ if(!_time_discr->isEqualIfNotWhy(other->_time_discr,T(valsPrec),reason))
{
reason.insert(0,"In FieldT time discretizations differ :");
return false;
* \throw If the spatial discretization of \a this field is NULL.
*/
template<class T>
- bool MEDCouplingFieldT<T>::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const
+ bool MEDCouplingFieldT<T>::isEqualWithoutConsideringStr(const MEDCouplingFieldT<T> *other, double meshPrec, T valsPrec) const
{
- const MEDCouplingFieldT<T> *otherC(dynamic_cast<const MEDCouplingFieldT<T> *>(other));
- if(!otherC)
+ if(!other)
return false;
- if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec))
+ if(!isEqualWithoutConsideringStrProtected(other,meshPrec))
return false;
- if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr,T(valsPrec)))
+ if(!_time_discr->isEqualWithoutConsideringStr(other->_time_discr,valsPrec))
return false;
return true;
}
return new MEDCouplingFieldTemplate(f,false);
}
+bool MEDCouplingFieldTemplate::isEqualIfNotWhy(const MEDCouplingFieldTemplate *other, double meshPrec, std::string& reason) const
+{
+ return isEqualIfNotWhyProtected(other,meshPrec,reason);
+}
+
+bool MEDCouplingFieldTemplate::isEqual(const MEDCouplingFieldTemplate *other, double meshPrec) const
+{
+ std::string tmp;
+ return isEqualIfNotWhyProtected(other,meshPrec,tmp);
+}
+
+bool MEDCouplingFieldTemplate::isEqualWithoutConsideringStr(const MEDCouplingFieldTemplate *other, double meshPrec) const
+{
+ return isEqualWithoutConsideringStrProtected(other,meshPrec);
+}
+
/*!
* The user should \b not use this method. Only useful for CORBA serialization/unserialization.
*/
MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *NewWithoutCheck(const MEDCouplingFieldDouble& f);
MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *NewWithoutCheck(const MEDCouplingFieldFloat& f);
MEDCOUPLING_EXPORT static MEDCouplingFieldTemplate *NewWithoutCheck(const MEDCouplingFieldInt& f);
+ MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const MEDCouplingFieldTemplate *other, double meshPrec, std::string& reason) const;
+ MEDCOUPLING_EXPORT bool isEqual(const MEDCouplingFieldTemplate *other, double meshPrec) const;
+ MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const MEDCouplingFieldTemplate *other, double meshPrec) const;
MEDCOUPLING_EXPORT std::string simpleRepr() const;
MEDCOUPLING_EXPORT std::string advancedRepr() const;
MEDCOUPLING_EXPORT void checkConsistencyLight() const;
MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT void reprNotTooLongWithoutNameStream(std::ostream& stream) const;
MEDCOUPLING_EXPORT std::string reprNotTooLong() const;
+ template<class U>
+ MCAuto< typename Traits<U>::ArrayType > convertToOtherTypeOfArr() const;
protected:
static typename Traits<T>::ArrayType *PerformCopyOrIncrRef(bool dCpy, const typename Traits<T>::ArrayType& self);
template<class OP>
MCAuto<DataArrayInt32> findIdsAdv(const OP& op) const;
private:
- template<class U>
- MCAuto< typename Traits<U>::ArrayType > convertToOtherTypeOfArr() const;
template<class FCT>
void somethingEqual(const typename Traits<T>::ArrayType *other);
};
bool MEDCouplingTimeDiscretizationFloat::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationTemplate<float> *other, float prec, std::string& reason) const
{
- if(prec!=0)
- throw INTERP_KERNEL::Exception("isEqualIfNotWhy : only precision equal to 0 supported for int !");
if(!other)
{
reason="Time discretization is NULL.";
arr2=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr2.setInfoOnComponents(["aa","bbb"])
f2.setArray(arr2) ; f2.setName("f1") ; f2.setTime(2.,3,4)
#
- self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ self.assertTrue(f1.isEqual(f2,1e-12,0))
f1.getArray()[:]*=2
- self.assertTrue(not f1.isEqual(f2,1e-12,0.))
- self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,0.))
+ self.assertTrue(not f1.isEqual(f2,1e-12,0))
+ self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,0))
f1.getArray()[:]/=2
- self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ self.assertTrue(f1.isEqual(f2,1e-12,0))
#
f1.setName("F1")
- self.assertTrue(not f1.isEqual(f2,1e-12,0.))
+ self.assertTrue(not f1.isEqual(f2,1e-12,0))
f1.setName("f1")
- self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ self.assertTrue(f1.isEqual(f2,1e-12,0))
#
f1.getArray().setInfoOnComponents(["aa","bbbb"])
- self.assertTrue(not f1.isEqual(f2,1e-12,0.))
- self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,0.))
+ self.assertTrue(not f1.isEqual(f2,1e-12,0))
+ self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,0))
f1.getArray().setInfoOnComponents(["aa","bbb"])
- self.assertTrue(f1.isEqual(f2,1e-12,0.))
+ self.assertTrue(f1.isEqual(f2,1e-12,0))
#
f3=f2.deepCopy()
- self.assertTrue(f1.isEqual(f3,1e-12,0.))
+ self.assertTrue(f1.isEqual(f3,1e-12,0))
#
for fd,expected in ((ON_NODES,False),(ON_CELLS,True)):
f4=MEDCouplingFieldInt(fd) ; f4.setMesh(m2) ; f4.setTime(2.,3,4)
arr4=DataArrayInt([(0,1),(2,3),(4,5),(6,7),(8,9),(10,11),(12,13),(14,15),(16,17),(18,19),(20,21),(22,23)]) ; arr4.setInfoOnComponents(["aa","bbb"])
f4.setArray(arr4) ; f4.setName("f1")
- self.assertEqual(f1.isEqual(f4,1e-12,0.),expected)
+ self.assertEqual(f1.isEqual(f4,1e-12,0),expected)
pass
pass
%newobject MEDCoupling::MEDCouplingFieldDouble::MergeFields;
%newobject MEDCoupling::MEDCouplingFieldDouble::MeldFields;
%newobject MEDCoupling::MEDCouplingFieldDouble::convertToIntField;
+%newobject MEDCoupling::MEDCouplingFieldDouble::convertToFloatField;
%newobject MEDCoupling::MEDCouplingFieldDouble::doublyContractedProduct;
%newobject MEDCoupling::MEDCouplingFieldDouble::determinant;
%newobject MEDCoupling::MEDCouplingFieldDouble::eigenValues;
public:
virtual void checkConsistencyLight() const throw(INTERP_KERNEL::Exception);
virtual bool areCompatibleForMerge(const MEDCouplingField *other) const throw(INTERP_KERNEL::Exception);
- virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception);
- virtual bool isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception);
virtual void copyTinyStringsFrom(const MEDCouplingField *other) throw(INTERP_KERNEL::Exception);
void setMesh(const MEDCoupling::MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception);
void setName(const char *name) throw(INTERP_KERNEL::Exception);
return convertIntArrToPyList3(ret);
}
- PyObject *isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception)
- {
- std::string ret1;
- bool ret0=self->isEqualIfNotWhy(other,meshPrec,valsPrec,ret1);
- PyObject *ret=PyTuple_New(2);
- PyObject *ret0Py=ret0?Py_True:Py_False;
- Py_XINCREF(ret0Py);
- PyTuple_SetItem(ret,0,ret0Py);
- PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str()));
- return ret;
- }
-
PyObject *buildSubMeshData(PyObject *li) const throw(INTERP_KERNEL::Exception)
{
DataArrayInt *ret1=0;
static MEDCouplingFieldTemplate *New(TypeOfField type);
std::string simpleRepr() const throw(INTERP_KERNEL::Exception);
std::string advancedRepr() const throw(INTERP_KERNEL::Exception);
+ bool isEqual(const MEDCouplingFieldTemplate *other, double meshPrec) const throw(INTERP_KERNEL::Exception);
+ bool isEqualWithoutConsideringStr(const MEDCouplingFieldTemplate *other, double meshPrec) const throw(INTERP_KERNEL::Exception);
%extend
{
MEDCouplingFieldTemplate(const MEDCouplingFieldDouble& f) throw(INTERP_KERNEL::Exception)
self->reprQuickOverview(oss);
return oss.str();
}
+
+ PyObject *isEqualIfNotWhy(const MEDCouplingFieldTemplate *other, double meshPrec) const throw(INTERP_KERNEL::Exception)
+ {
+ std::string ret1;
+ bool ret0=self->isEqualIfNotWhy(other,meshPrec,ret1);
+ PyObject *ret=PyTuple_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyTuple_SetItem(ret,0,ret0Py);
+ PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str()));
+ return ret;
+ }
}
};
class MEDCouplingFieldInt;
+ class MEDCouplingFieldFloat;
class MEDCouplingFieldDouble : public MEDCoupling::MEDCouplingField
{
public:
static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME);
static MEDCouplingFieldDouble *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME);
+ bool isEqual(const MEDCouplingFieldDouble *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception);
+ bool isEqualWithoutConsideringStr(const MEDCouplingFieldDouble *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception);
void setTimeUnit(const std::string& unit);
std::string getTimeUnit() const;
void synchronizeTimeWithSupport() throw(INTERP_KERNEL::Exception);
std::string advancedRepr() const throw(INTERP_KERNEL::Exception);
std::string writeVTK(const std::string& fileName, bool isBinary=true) const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldInt *convertToIntField() const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldFloat *convertToFloatField() const throw(INTERP_KERNEL::Exception);
MEDCouplingFieldDouble *clone(bool recDeepCpy) const;
MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const;
MEDCouplingFieldDouble *deepCopy() const;
self->reprQuickOverview(oss);
return oss.str();
}
+
+ PyObject *isEqualIfNotWhy(const MEDCouplingFieldDouble *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception)
+ {
+ std::string ret1;
+ bool ret0=self->isEqualIfNotWhy(other,meshPrec,valsPrec,ret1);
+ PyObject *ret=PyTuple_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyTuple_SetItem(ret,0,ret0Py);
+ PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str()));
+ return ret;
+ }
MEDCouplingFieldDouble *voronoize(double eps) const throw(INTERP_KERNEL::Exception)
{
public:
static MEDCouplingFieldInt *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME);
static MEDCouplingFieldInt *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME);
+ bool isEqual(const MEDCouplingFieldInt *other, double meshPrec, int valsPrec) const throw(INTERP_KERNEL::Exception);
+ bool isEqualWithoutConsideringStr(const MEDCouplingFieldInt *other, double meshPrec, int valsPrec) const throw(INTERP_KERNEL::Exception);
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);
return MEDCouplingFieldInt::New(ft,td);
}
+ PyObject *isEqualIfNotWhy(const MEDCouplingFieldInt *other, double meshPrec, int valsPrec) const throw(INTERP_KERNEL::Exception)
+ {
+ std::string ret1;
+ bool ret0=self->isEqualIfNotWhy(other,meshPrec,valsPrec,ret1);
+ PyObject *ret=PyTuple_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyTuple_SetItem(ret,0,ret0Py);
+ PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str()));
+ return ret;
+ }
+
std::string __str__() const throw(INTERP_KERNEL::Exception)
{
return self->simpleRepr();
public:
static MEDCouplingFieldFloat *New(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME);
static MEDCouplingFieldFloat *New(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td=ONE_TIME);
+ bool isEqual(const MEDCouplingFieldFloat *other, double meshPrec, float valsPrec) const throw(INTERP_KERNEL::Exception);
+ bool isEqualWithoutConsideringStr(const MEDCouplingFieldFloat *other, double meshPrec, float valsPrec) const throw(INTERP_KERNEL::Exception);
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);
return MEDCouplingFieldFloat::New(ft,td);
}
+ PyObject *isEqualIfNotWhy(const MEDCouplingFieldFloat *other, double meshPrec, float valsPrec) const throw(INTERP_KERNEL::Exception)
+ {
+ std::string ret1;
+ bool ret0=self->isEqualIfNotWhy(other,meshPrec,valsPrec,ret1);
+ PyObject *ret=PyTuple_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyTuple_SetItem(ret,0,ret0Py);
+ PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str()));
+ return ret;
+ }
+
std::string __str__() const throw(INTERP_KERNEL::Exception)
{
return self->simpleRepr();
convertFPStarLikePyObjToCpp_2<double>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayDouble,SWIGTYPE_p_MEDCoupling__DataArrayDoubleTuple);
}
+/*!
+ * if value int -> cpp val sw=1
+ * if value double -> cpp val sw=1
+ * if value DataArrayDouble -> cpp DataArrayDouble sw=2
+ * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
+ * if value list[int,double] -> cpp std::vector<double> sw=4
+ * if value tuple[int,double] -> cpp std::vector<double> sw=4
+ */
+static void convertFloatStarLikePyObjToCpp_2(PyObject *value, int& sw, float& val, MEDCoupling::DataArrayFloat *&d, MEDCoupling::DataArrayFloatTuple *&e, std::vector<float>& f)
+{
+ convertFPStarLikePyObjToCpp_2<float>(value,sw,val,d,e,f,SWIGTYPE_p_MEDCoupling__DataArrayFloat,SWIGTYPE_p_MEDCoupling__DataArrayFloatTuple);
+}
+
/*!
* if python int -> cpp int sw=1
* if python list[int] -> cpp vector<int> sw=2
return DataArrayT_isub__internal<T>(trueSelf,obj,self,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
}
+template<class T>
+typename MEDCoupling::Traits<T>::ArrayType *DataArrayFPT_rmul(typename MEDCoupling::Traits<T>::ArrayType *self, PyObject *obj)
+{
+ const char msg[]="Unexpected situation in __rmul__ !";
+ T val;
+ typename MEDCoupling::Traits<T>::ArrayType *a;
+ typename MEDCoupling::Traits<T>::ArrayTuple *aa;
+ std::vector<T> bb;
+ int sw;
+ convertFPStarLikePyObjToCpp_2<T>(obj,sw,val,a,aa,bb,SWIGTITraits<T>::TI,SWIGTITraits<T>::TI_TUPLE);
+ switch(sw)
+ {
+ case 1:
+ {
+ typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> ret(self->deepCopy());
+ ret->applyLin(val,0.);
+ return ret.retn();
+ }
+ case 3:
+ {
+ typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(aa->buildDA(1,self->getNumberOfComponents()));
+ return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
+ }
+ case 4:
+ {
+ typename MEDCoupling::MCAuto<typename MEDCoupling::Traits<T>::ArrayType> aaa(MEDCoupling::Traits<T>::ArrayType::New()); aaa->useArray(&bb[0],false,MEDCoupling::CPP_DEALLOC,1,(int)bb.size());
+ return MEDCoupling::Traits<T>::ArrayType::Multiply(self,aaa);
+ }
+ default:
+ throw INTERP_KERNEL::Exception(msg);
+ }
+}
+
#endif
%newobject MEDCoupling::DataArrayFloat::iterator;
%newobject MEDCoupling::DataArrayFloat::__iter__;
%newobject MEDCoupling::DataArrayFloat::Meld;
+%newobject MEDCoupling::DataArrayFloat::__rmul__;
%newobject MEDCoupling::DataArrayInt::New;
%newobject MEDCoupling::DataArrayInt::__iter__;
%newobject MEDCoupling::DataArrayInt::performCopyOrIncrRef;
int nbOfComp(self->getNumberOfComponents()),nbOfTuples(self->getNumberOfTuples());
return convertDblArrToPyListOfTuple<float>(vals,nbOfComp,nbOfTuples);
}
+
+ PyObject *isEqualIfNotWhy(const DataArrayFloat& other, float prec) const throw(INTERP_KERNEL::Exception)
+ {
+ std::string ret1;
+ bool ret0=self->isEqualIfNotWhy(other,prec,ret1);
+ PyObject *ret=PyTuple_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyTuple_SetItem(ret,0,ret0Py);
+ PyTuple_SetItem(ret,1,PyString_FromString(ret1.c_str()));
+ return ret;
+ }
PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception)
{
return DataArrayT_imul<float>(trueSelf,obj,self);
}
+ DataArrayFloat *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception)
+ {
+ return DataArrayFPT_rmul<float>(self,obj);
+ }
+
PyObject *___idiv___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
{
return DataArrayT_idiv<float>(trueSelf,obj,self);
DataArrayDouble *__rmul__(PyObject *obj) throw(INTERP_KERNEL::Exception)
{
- const char msg[]="Unexpected situation in __rmul__ !";
- double val;
- DataArrayDouble *a;
- DataArrayDoubleTuple *aa;
- std::vector<double> bb;
- int sw;
- convertDoubleStarLikePyObjToCpp_2(obj,sw,val,a,aa,bb);
- switch(sw)
- {
- case 1:
- {
- MCAuto<DataArrayDouble> ret=self->deepCopy();
- ret->applyLin(val,0.);
- return ret.retn();
- }
- case 3:
- {
- MCAuto<DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
- return DataArrayDouble::Multiply(self,aaa);
- }
- case 4:
- {
- MCAuto<DataArrayDouble> aaa=DataArrayDouble::New(); aaa->useArray(&bb[0],false,CPP_DEALLOC,1,(int)bb.size());
- return DataArrayDouble::Multiply(self,aaa);
- }
- default:
- throw INTERP_KERNEL::Exception(msg);
- }
+ return DataArrayFPT_rmul<double>(self,obj);
}
PyObject *___imul___(PyObject *trueSelf, PyObject *obj) throw(INTERP_KERNEL::Exception)
goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
return ;
}
- throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !");
+ DataArrayFloat *arrF(dynamic_cast<DataArrayFloat *>(arr));
+ if(arrF)
+ {
+ float *startFeeding(arrF->getPointer()+_start*nbOfCompo);
+ goReadZeValuesInFile(fid,fieldName,nbOfCompo,iteration,order,menti,mgeoti,reinterpret_cast<unsigned char*>(startFeeding));
+ return ;
+ }
+ throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 FLOAT32 or INT32 !");
}
/*!
throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : no array set !");
if(!arr->isAllocated())
throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : the array to be written is not allocated !");
- const DataArrayDouble *arrD=dynamic_cast<const DataArrayDouble *>(arr);
- const DataArrayInt *arrI=dynamic_cast<const DataArrayInt *>(arr);
+ const DataArrayDouble *arrD(dynamic_cast<const DataArrayDouble *>(arr));
+ const DataArrayInt *arrI(dynamic_cast<const DataArrayInt *>(arr));
+ const DataArrayFloat *arrF(dynamic_cast<const DataArrayFloat *>(arr));
const unsigned char *locToWrite=0;
if(arrD)
locToWrite=reinterpret_cast<const unsigned char *>(arrD->getConstPointer()+_start*arr->getNumberOfComponents());
else if(arrI)
locToWrite=reinterpret_cast<const unsigned char *>(arrI->getConstPointer()+_start*arr->getNumberOfComponents());
+ else if(arrF)
+ locToWrite=reinterpret_cast<const unsigned char *>(arrF->getConstPointer()+_start*arr->getNumberOfComponents());
else
- throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 and INT32 !");
+ throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::writeLL : not recognized type of values ! Supported are FLOAT64 FLOAT32 and INT32 !");
MEDFILESAFECALLERWR0(MEDfieldValueWithProfileWr,(fid,nasc.getName().c_str(),getIteration(),getOrder(),getTime(),menti,mgeoti,
MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval,
locToWrite));
ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
break;
}
- case MED_NODE://6432
+ case MED_FLOAT32:
{
ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
break;
ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
break;
}
- case MED_NODE://6432
+ case MED_FLOAT32:
{
ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,-1/*iteration*/,-1/*order*/,std::vector<std::string>());
break;
ret->_content=c; c->incrRef();
return ret.retn();
}
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
+ if(dynamic_cast<const MEDFileFloatField1TSWithoutSDA *>(c))
+ {
+ MCAuto<MEDFileFloatField1TS> ret(MEDFileFloatField1TS::New());
+ ret->_content=c; c->incrRef();
+ return ret.retn();
+ }
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
}
MEDFileAnyTypeField1TS *MEDFileAnyTypeField1TS::BuildNewInstanceFromContent(MEDFileAnyTypeField1TSWithoutSDA *c, med_idt fid)
ret=MEDFileIntField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
break;
}
- case MED_NODE://6432
+ case MED_FLOAT32:
{
ret=MEDFileFloatField1TSWithoutSDA::New(fieldName,meshName,-1,iteration,order,std::vector<std::string>());
break;
_time_steps[i]=MEDFileIntField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
break;
}
- case MED_NODE://6432
+ case MED_FLOAT32:
{
_time_steps[i]=MEDFileFloatField1TSWithoutSDA::New(getName(),getMeshName(),i+1,numdt,numo,_infos);
break;
ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
break;
}
- case MED_NODE://6432
+ case MED_FLOAT32:
{
ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,i,loadAll,ms,entities);
break;
ret=new MEDFileIntFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
break;
}
- case MED_NODE://6432
+ case MED_FLOAT32:
{
ret=new MEDFileFloatFieldMultiTSWithoutSDA(fid,0,loadAll,ms,0);
break;
ret->_content=c; c->incrRef();
return ret.retn();
}
- throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 and INT32 has been built but not intercepted !");
+ if(dynamic_cast<const MEDFileFloatFieldMultiTSWithoutSDA *>(c))
+ {
+ MCAuto<MEDFileFloatFieldMultiTS> ret(MEDFileFloatFieldMultiTS::New());
+ ret->_content=c; c->incrRef();
+ return ret.retn();
+ }
+ throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent : internal error ! a content of type different from FLOAT64 FLOAT32 and INT32 has been built but not intercepted !");
}
MEDFileAnyTypeFieldMultiTS *MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent(MEDFileAnyTypeFieldMultiTSWithoutSDA *c, med_idt fid)
_fields[i]=MEDFileIntFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
break;
}
- case MED_NODE://6432
+ case MED_FLOAT32:
{
_fields[i]=MEDFileFloatFieldMultiTSWithoutSDA::New(fid,fieldName,meshName,typcha,infos,nbOfStep,dtunit,loadAll,ms,entities);
break;
MCAuto<MEDFileAnyTypeFieldMultiTS> ret;
const MEDFileFieldMultiTSWithoutSDA *fmtsC(dynamic_cast<const MEDFileFieldMultiTSWithoutSDA *>(fmts));
const MEDFileIntFieldMultiTSWithoutSDA *fmtsC2(dynamic_cast<const MEDFileIntFieldMultiTSWithoutSDA *>(fmts));
+ const MEDFileFloatFieldMultiTSWithoutSDA *fmtsC3(dynamic_cast<const MEDFileFloatFieldMultiTSWithoutSDA *>(fmts));
if(fmtsC)
ret=MEDFileFieldMultiTS::New(*fmtsC,false);
else if(fmtsC2)
ret=MEDFileIntFieldMultiTS::New(*fmtsC2,false);
+ else if(fmtsC3)
+ ret=MEDFileFloatFieldMultiTS::New(*fmtsC3,false);
else
{
- std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor integer (INT32) !";
+ std::ostringstream oss; oss << "MEDFileFields::getFieldAtPos : At pos #" << i << " field is neither double (FLOAT64) nor float (FLOAT32) nor integer (INT32) !";
throw INTERP_KERNEL::Exception(oss.str());
}
ret->shallowCpyGlobs(*this);
{
friend class MEDFileTemplateField1TS<float>;
private:
- med_field_type getMEDFileFieldType() const { return MED_INT32; }//6432
+ med_field_type getMEDFileFieldType() const { return MED_FLOAT32; }
MEDLOADER_EXPORT MEDFileFloatField1TS *shallowCpy() const { return new MEDFileFloatField1TS(*this); }
private:
~MEDFileFloatField1TS() { }
protected:
MEDFileFloatFieldMultiTSWithoutSDA(const std::string& fieldName, const std::string& meshName):MEDFileNDTemplateFieldMultiTSWithoutSDA<float>(fieldName,meshName) { }
MEDFileFloatFieldMultiTSWithoutSDA(med_idt fid, const std::string& fieldName, const std::string& meshName, med_field_type fieldTyp, const std::vector<std::string>& infos, int nbOfStep, const std::string& dtunit, bool loadAll, const MEDFileMeshes *ms, const MEDFileEntities *entities):MEDFileNDTemplateFieldMultiTSWithoutSDA<float>(fid,fieldName,meshName,fieldTyp,infos,nbOfStep,dtunit,loadAll,ms,entities) { }
- med_field_type getMEDFileFieldType() const { return MED_INT32; }//6432
+ med_field_type getMEDFileFieldType() const { return MED_FLOAT32; }
public:
MEDLOADER_EXPORT MEDFileFloatFieldMultiTSWithoutSDA() { }
};
PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception)
{
- DataArrayInt *ret1=0;
- DataArrayDouble *ret0=self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1);
- PyObject *ret=PyTuple_New(2);
- PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
- PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
- return ret;
+ return MEDFileField1TS_getFieldWithProfile<double>(self,type,meshDimRelToMax,mesh);
}
PyObject *getFieldSplitedByType2(const std::string& mname=std::string()) const throw(INTERP_KERNEL::Exception)
PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception)
{
- DataArrayInt *ret1=0;
- DataArrayInt *ret0=self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1);
- PyObject *ret=PyTuple_New(2);
- PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
- PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
- return ret;
+ return MEDFileField1TS_getFieldWithProfile<int>(self,type,meshDimRelToMax,mesh);
}
DataArrayInt *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
PyObject *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception)
{
- DataArrayInt *ret1=0;
- DataArrayFloat *ret0=self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1);
- PyObject *ret=PyTuple_New(2);
- PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
- PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayFloat, SWIG_POINTER_OWN | 0 ));
- return ret;
+ return MEDFileField1TS_getFieldWithProfile<float>(self,type,meshDimRelToMax,mesh);
}
DataArrayFloat *getUndergroundDataArray() const throw(INTERP_KERNEL::Exception)
self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12))
pass
+ def testFloat32InMEDFileFieldStar1(self):
+ """Like testInt32InMEDFileFieldStar1 but with float32 :)"""
+ fname="Pyfile114.med"
+ f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
+ f1=f1.convertToFloatField()
+ m1=f1.getMesh()
+ mm1=MEDFileUMesh.New()
+ mm1.setCoords(m1.getCoords())
+ mm1.setMeshAtLevel(0,m1)
+ mm1.setName(m1.getName())
+ mm1.write(fname,2)
+ ff1=MEDFileFloatField1TS()
+ ff1.setFieldNoProfileSBT(f1)
+ a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
+ self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12))
+ ff1.write(fname,0)
+ ff2=MEDFileAnyTypeField1TS.New(fname)
+ self.assertEqual(ff2.getName(),"VectorFieldOnCells")
+ self.assertEqual(ff2.getTime(),[0,1,2.0])
+ self.assertTrue(isinstance(ff2,MEDFileFloatField1TS))
+ a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
+ self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12))
+ ff2.setTime(1,2,3.)
+ c=ff2.getUndergroundDataArray() ; c*=2
+ ff2.write(fname,0) # 2 time steps in
+ ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
+ self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
+ self.assertEqual(len(ffs1),2)
+ self.assertTrue(isinstance(ffs1,MEDFileFloatFieldMultiTS))
+ a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12))
+ a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12))
+ it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
+ a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
+ self.assertTrue(a.getArray().isEqual(2*f1.getArray(),1e-7))
+ f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2
+ bc=DataArrayFloat(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
+ for it in ffs1:
+ a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
+ bc+=a.getArray()
+ pass
+ self.assertTrue(bc.isEqual(3*f1.getArray(),1e-7))
+ nf1=MEDCouplingFieldFloat(ON_NODES)
+ nf1.setTime(9.,10,-1)
+ nf1.setMesh(f1.getMesh())
+ narr=DataArrayFloat(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
+ nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
+ nff1=MEDFileFloatField1TS.New()
+ nff1.setFieldNoProfileSBT(nf1)
+ self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
+ self.assertEqual(nff1.getTime(),[10,-1,9.0])
+ nff1.write(fname,0)
+ #
+ nf2=MEDCouplingFieldFloat(ON_NODES)
+ nf2.setTime(19.,20,-11)
+ nf2.setMesh(f1.getMesh())
+ narr2=DataArrayFloat(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
+ nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
+ nff2=MEDFileFloatField1TS.New()
+ npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
+ nff2.setFieldProfile(nf2,mm1,0,npfl)
+ nff2.getFieldWithProfile(ON_NODES,0,mm1)
+ a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
+ self.assertTrue(b.isEqual(npfl))
+ self.assertTrue(a.isEqual(narr2,1e-7))
+ nff2.write(fname,0)
+ nff2bis=MEDFileFloatField1TS(fname,"VectorFieldOnNodesPfl")
+ a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
+ self.assertTrue(b.isEqual(npfl))
+ self.assertTrue(a.isEqual(narr2,1e-7))
+ #
+ nf3=MEDCouplingFieldDouble(ON_NODES)
+ nf3.setName("VectorFieldOnNodesDouble")
+ nf3.setTime(29.,30,-21)
+ nf3.setMesh(f1.getMesh())
+ nf3.setArray(f1.getMesh().getCoords())
+ nff3=MEDFileField1TS.New()
+ nff3.setFieldNoProfileSBT(nf3)
+ nff3.write(fname,0)
+ fs=MEDFileFields(fname)
+ self.assertEqual(len(fs),4)
+ ffs=[it for it in fs]
+ self.assertTrue(isinstance(ffs[0],MEDFileFloatFieldMultiTS))
+ self.assertTrue(isinstance(ffs[1],MEDFileFloatFieldMultiTS))
+ self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
+ self.assertTrue(isinstance(ffs[3],MEDFileFloatFieldMultiTS))
+ #
+ self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray(),1e-7))
+ self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray(),1e-7))
+ self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2,1e-7))
+ self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr,1e-7))
+ self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
+ #
+ nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
+ self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
+ self.assertRaises(InterpKernelException,MEDFileFloatFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
+ self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
+ MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
+ self.assertRaises(InterpKernelException,MEDFileFloatField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
+ MEDFileFloatField1TS.New(fname,"VectorFieldOnNodes",10,-1)
+ self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
+ #
+ self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
+ self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
+ self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
+ self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
+ pass
+
pass
if __name__ == "__main__":
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
#include <vector>
}
}
+template<class T>
+PyObject *MEDFileField1TS_getFieldWithProfile(const typename MLFieldTraits<T>::F1TSType *self, TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh)
+{
+ DataArrayInt *ret1(NULL);
+ typename MEDCoupling::Traits<T>::ArrayType *ret0(self->getFieldWithProfile(type,meshDimRelToMax,mesh,ret1));
+ PyObject *ret(PyTuple_New(2));
+ PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTITraits<T>::TI, SWIG_POINTER_OWN | 0 ));
+ PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+ return ret;
+}
+