From f8f5e879a2ba74ad63ea8dee1cd0da94f9fd5ec4 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 23 Aug 2016 11:41:55 +0200 Subject: [PATCH] Simplify life for FieldInt users --- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 12 +- src/MEDCoupling/MEDCouplingFieldInt.cxx | 89 ++++++ src/MEDCoupling/MEDCouplingFieldInt.hxx | 8 + .../MEDCouplingTimeDiscretization.cxx | 30 +- .../MEDCouplingTimeDiscretization.hxx | 2 + .../MEDCouplingBasicsTest5.py | 45 ++- src/MEDCoupling_Swig/MEDCouplingCommon.i | 6 + src/MEDLoader/MEDFileField.cxx | 273 +++++++++++++++++- src/MEDLoader/MEDFileField.hxx | 14 + src/MEDLoader/Swig/MEDLoaderCommon.i | 12 + 10 files changed, 469 insertions(+), 22 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index dc3693c3e..00cda93f4 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -327,7 +327,7 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::cellToNodeDiscretization() const void MEDCouplingFieldDouble::copyTinyStringsFrom(const MEDCouplingField *other) { MEDCouplingField::copyTinyStringsFrom(other); - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + const MEDCouplingFieldDouble *otherC(dynamic_cast(other)); if(otherC) { _time_discr->copyTinyStringsFrom(*otherC->_time_discr); @@ -461,7 +461,7 @@ bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, doub { if(!other) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::isEqualIfNotWhy : other instance is NULL !"); - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + const MEDCouplingFieldDouble *otherC(dynamic_cast(other)); if(!otherC) { reason="field given in input is not castable in MEDCouplingFieldDouble !"; @@ -489,7 +489,7 @@ bool MEDCouplingFieldDouble::isEqualIfNotWhy(const MEDCouplingField *other, doub */ bool MEDCouplingFieldDouble::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const { - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + const MEDCouplingFieldDouble *otherC(dynamic_cast(other)); if(!otherC) return false; if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec)) @@ -508,7 +508,7 @@ bool MEDCouplingFieldDouble::areCompatibleForMerge(const MEDCouplingField *other { if(!MEDCouplingField::areCompatibleForMerge(other)) return false; - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + const MEDCouplingFieldDouble *otherC(dynamic_cast(other)); if(!otherC) return false; if(!_time_discr->areCompatible(otherC->_time_discr)) @@ -525,7 +525,7 @@ bool MEDCouplingFieldDouble::areStrictlyCompatible(const MEDCouplingField *other std::string tmp; if(!MEDCouplingField::areStrictlyCompatible(other)) return false; - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + const MEDCouplingFieldDouble *otherC(dynamic_cast(other)); if(!otherC) return false; if(!_time_discr->areStrictlyCompatible(otherC->_time_discr,tmp)) @@ -557,7 +557,7 @@ bool MEDCouplingFieldDouble::areCompatibleForDiv(const MEDCouplingField *other) { if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other)) return false; - const MEDCouplingFieldDouble *otherC=dynamic_cast(other); + const MEDCouplingFieldDouble *otherC(dynamic_cast(other)); if(!otherC) return false; if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr)) diff --git a/src/MEDCoupling/MEDCouplingFieldInt.cxx b/src/MEDCoupling/MEDCouplingFieldInt.cxx index aab9a45f1..ce07e67e7 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.cxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.cxx @@ -140,3 +140,92 @@ MEDCouplingFieldInt::~MEDCouplingFieldInt() MEDCouplingFieldInt::MEDCouplingFieldInt(const MEDCouplingFieldTemplate& ft, TypeOfTimeDiscretization td):MEDCouplingField(ft,false),_time_discr(MEDCouplingTimeDiscretizationInt::New(td)) { } + +MEDCouplingFieldInt *MEDCouplingFieldInt::deepCopy() const +{ + return cloneWithMesh(true); +} + +MEDCouplingFieldInt *MEDCouplingFieldInt::cloneWithMesh(bool recDeepCpy) const +{ + MCAuto ret(clone(recDeepCpy)); + if(_mesh) + { + MCAuto mCpy(_mesh->deepCopy()); + ret->setMesh(mCpy); + } + return ret.retn(); +} + +MEDCouplingFieldInt *MEDCouplingFieldInt::clone(bool recDeepCpy) const +{ + return new MEDCouplingFieldInt(*this,recDeepCpy); +} + +bool MEDCouplingFieldInt::isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec, std::string& reason) const +{ + if(!other) + throw INTERP_KERNEL::Exception("MEDCouplingFieldInt::isEqualIfNotWhy : other instance is NULL !"); + const MEDCouplingFieldInt *otherC(dynamic_cast(other)); + if(!otherC) + { + reason="field given in input is not castable in MEDCouplingFieldInt !"; + return false; + } + if(!MEDCouplingField::isEqualIfNotWhy(other,meshPrec,valsPrec,reason)) + return false; + if(!_time_discr->isEqualIfNotWhy(otherC->_time_discr,reason)) + { + reason.insert(0,"In FieldInt time discretizations differ :"); + return false; + } + return true; +} + +bool MEDCouplingFieldInt::isEqualWithoutConsideringStr(const MEDCouplingField *other, double meshPrec, double valsPrec) const +{ + const MEDCouplingFieldInt *otherC(dynamic_cast(other)); + if(!otherC) + return false; + if(!MEDCouplingField::isEqualWithoutConsideringStr(other,meshPrec,valsPrec)) + return false; + if(!_time_discr->isEqualWithoutConsideringStr(otherC->_time_discr)) + return false; + return true; +} + +void MEDCouplingFieldInt::copyTinyStringsFrom(const MEDCouplingField *other) +{ + MEDCouplingField::copyTinyStringsFrom(other); + const MEDCouplingFieldInt *otherC(dynamic_cast(other)); + if(otherC) + { + _time_discr->copyTinyStringsFrom(*otherC->_time_discr); + } +} + +bool MEDCouplingFieldInt::areStrictlyCompatible(const MEDCouplingField *other) const +{ + std::string tmp; + if(!MEDCouplingField::areStrictlyCompatible(other)) + return false; + const MEDCouplingFieldInt *otherC(dynamic_cast(other)); + if(!otherC) + return false; + if(!_time_discr->areStrictlyCompatible(otherC->_time_discr,tmp)) + return false; + return true; +} + +bool MEDCouplingFieldInt::areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const +{ + if(!MEDCouplingField::areStrictlyCompatibleForMulDiv(other)) + return false; + const MEDCouplingFieldInt *otherC(dynamic_cast(other)); + if(!otherC) + return false; + if(!_time_discr->areStrictlyCompatibleForDiv(otherC->_time_discr)) + return false; + return true; +} + diff --git a/src/MEDCoupling/MEDCouplingFieldInt.hxx b/src/MEDCoupling/MEDCouplingFieldInt.hxx index 71dbda7bf..6a401ef4f 100644 --- a/src/MEDCoupling/MEDCouplingFieldInt.hxx +++ b/src/MEDCoupling/MEDCouplingFieldInt.hxx @@ -47,6 +47,14 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void setArray(DataArrayInt *array); MEDCOUPLING_EXPORT const DataArrayInt *getArray() const; MEDCOUPLING_EXPORT DataArrayInt *getArray(); + MEDCOUPLING_EXPORT MEDCouplingFieldInt *deepCopy() const; + MEDCOUPLING_EXPORT MEDCouplingFieldInt *clone(bool recDeepCpy) const; + MEDCOUPLING_EXPORT MEDCouplingFieldInt *cloneWithMesh(bool recDeepCpy) const; + 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 void copyTinyStringsFrom(const MEDCouplingField *other); + MEDCOUPLING_EXPORT bool areStrictlyCompatible(const MEDCouplingField *other) const; + MEDCOUPLING_EXPORT bool areStrictlyCompatibleForMulDiv(const MEDCouplingField *other) const; protected: MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td); MEDCouplingFieldInt(const MEDCouplingFieldInt& other, bool deepCopy); diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx index 2262cd871..43c156434 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.cxx @@ -805,7 +805,7 @@ MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt() { } -MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate(other,deepCopy) +MEDCouplingTimeDiscretizationInt::MEDCouplingTimeDiscretizationInt(const MEDCouplingTimeDiscretizationInt& other, bool deepCopy):MEDCouplingTimeDiscretizationTemplate(other,deepCopy),_tk(other._tk) { } @@ -833,6 +833,34 @@ MEDCouplingTimeDiscretizationInt *MEDCouplingTimeDiscretizationInt::New(TypeOfTi } } +bool MEDCouplingTimeDiscretizationInt::isEqualIfNotWhy(const MEDCouplingTimeDiscretizationInt *other, std::string& reason) const +{ + if(!other) + { + reason="Time discretization is NULL."; + return false; + } + if(!MEDCouplingTimeDiscretizationTemplate::areStrictlyCompatible(other,reason)) + return false; + if(!_tk.isEqualIfNotWhy(other->_tk,_time_tolerance,reason)) + return false; + if(_array==other->_array) + return true; + return _array->isEqualIfNotWhy(*other->_array,reason); +} + +bool MEDCouplingTimeDiscretizationInt::isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationInt *other) const +{ + std::string tmp; + if(!areStrictlyCompatible(other,tmp)) + return false; + std::string reason; + if(!_tk.isEqualIfNotWhy(other->_tk,_time_tolerance,reason)) + return false; + if(_array==other->_array) + return true; + return _array->isEqualWithoutConsideringStr(*other->_array); +} //////////////////////// diff --git a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx index f50af41c7..310a9f95c 100644 --- a/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingTimeDiscretization.hxx @@ -208,6 +208,8 @@ namespace MEDCoupling std::string getStringRepr() const; TypeOfTimeDiscretization getEnum() const { return DISCRETIZATION; } MEDCouplingTimeDiscretizationInt *performCopyOrIncrRef(bool deepCopy) const; + bool isEqualIfNotWhy(const MEDCouplingTimeDiscretizationInt *other, std::string& reason) const; + bool isEqualWithoutConsideringStr(const MEDCouplingTimeDiscretizationInt *other) const; private: static const TypeOfTimeDiscretization DISCRETIZATION=ONE_TIME; MEDCOUPLING_EXPORT static const char REPR[]; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index 534079086..ad084d3d0 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -4332,7 +4332,50 @@ class MEDCouplingBasicsTest5(unittest.TestCase): self.assertTrue(rd.isEqual(DataArrayInt([0,4,0,3,0,2,0,2,0,0,1,2,1,2,1,6,1,5,1,1,2,8,2,7,3,3,4,4,5,5,6,6,7,7,8,8]))) self.assertTrue(rdi.isEqual(DataArrayInt([0,2,4,6,8,9,10,12,14,16,18,19,20,22,24,25,27,28,29,31,33,35,36]))) pass - + + def testFieldIntIsOnStage2(self): + """ Very important test to check that isEqual of MEDCouplingFieldInt is OK !""" + m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1,2,3,4])) + m1=m1.buildUnstructured() ; m1.setName("mesh") + f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setMesh(m1) + arr1=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)]) ; arr1.setInfoOnComponents(["aa","bbb"]) + f1.setArray(arr1) ; f1.setName("f1") ; f1.setTime(2.,3,4) + # + m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1,2,3,4])) + m2=m2.buildUnstructured() ; m2.setName("mesh") + f2=MEDCouplingFieldInt(ON_CELLS) ; f2.setMesh(m2) + 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.)) + f1.getArray()[:]*=2 + 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.)) + # + f1.setName("F1") + self.assertTrue(not f1.isEqual(f2,1e-12,0.)) + f1.setName("f1") + 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.)) + f1.getArray().setInfoOnComponents(["aa","bbb"]) + self.assertTrue(f1.isEqual(f2,1e-12,0.)) + # + f3=f2.deepCopy() + 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) + pass + pass + pass if __name__ == '__main__': diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 61088db71..27e421491 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -231,6 +231,9 @@ using namespace INTERP_KERNEL; %newobject MEDCoupling::MEDCouplingFieldDouble::getValueOnMulti; %newobject MEDCoupling::MEDCouplingFieldInt::New; %newobject MEDCoupling::MEDCouplingFieldInt::getArray; +%newobject MEDCoupling::MEDCouplingFieldInt::deepCopy; +%newobject MEDCoupling::MEDCouplingFieldInt::clone; +%newobject MEDCoupling::MEDCouplingFieldInt::cloneWithMesh; %newobject MEDCoupling::MEDCouplingFieldTemplate::New; %newobject MEDCoupling::MEDCouplingMesh::deepCopy; %newobject MEDCoupling::MEDCouplingMesh::clone; @@ -5185,6 +5188,9 @@ namespace MEDCoupling 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); + MEDCouplingFieldInt *deepCopy() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *clone(bool recDeepCpy) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *cloneWithMesh(bool recDeepCpy) const throw(INTERP_KERNEL::Exception); %extend { MEDCouplingFieldInt(TypeOfField type, TypeOfTimeDiscretization td=ONE_TIME) { diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 2b362ece3..3162a357d 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -26,6 +26,7 @@ #include "MEDFileFieldOverView.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingFieldDiscretization.hxx" #include "InterpKernelAutoPtr.hxx" @@ -1270,11 +1271,25 @@ const MEDFileFieldPerMesh *MEDFileFieldPerMeshPerType::getFather() const void MEDFileFieldPerMeshPerType::getDimension(int& dim) const { - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); - int curDim=(int)cm.getDimension(); + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type)); + int curDim((int)cm.getDimension()); dim=std::max(dim,curDim); } +bool MEDFileFieldPerMeshPerType::isUniqueLevel(int& dim) const +{ + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(_geo_type)); + int curDim((int)cm.getDimension()); + if(dim!=std::numeric_limits::max()) + { + if(dim!=curDim) + return false; + } + else + dim=curDim; + return true; +} + void MEDFileFieldPerMeshPerType::fillTypesOfFieldAvailable(std::set& types) const { for(std::vector< MCAuto >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++) @@ -1775,6 +1790,14 @@ void MEDFileFieldPerMesh::getDimension(int& dim) const (*it)->getDimension(dim); } +bool MEDFileFieldPerMesh::isUniqueLevel(int& dim) const +{ + for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + if(!(*it)->isUniqueLevel(dim)) + return false; + return true; +} + void MEDFileFieldPerMesh::fillTypesOfFieldAvailable(std::set& types) const { for(std::vector< MCAuto< MEDFileFieldPerMeshPerType > >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) @@ -4738,6 +4761,37 @@ bool MEDFileAnyTypeField1TSWithoutSDA::presenceOfMultiDiscPerGeoType() const return false; } +MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto& arrOut, const MEDFileFieldNameScope& nasc) const +{ + static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to extract a field ! Call getFieldOnMeshAtLevel method instead to deal with complexity !"; + if(_field_per_mesh.empty()) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is empty ! Nothing to extract !"); + if(_field_per_mesh.size()>1) + throw INTERP_KERNEL::Exception(MSG0); + if(_field_per_mesh[0].isNull()) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is inconsistent !"); + const MEDFileFieldPerMesh *pm(_field_per_mesh[0]); + std::set types; + pm->fillTypesOfFieldAvailable(types); + if(types.size()!=1) + throw INTERP_KERNEL::Exception(MSG0); + TypeOfField type(*types.begin()); + int meshDimRelToMax(0); + if(type==ON_NODES) + meshDimRelToMax=0; + else + { + int myDim(std::numeric_limits::max()); + bool isUnique(pm->isUniqueLevel(myDim)); + if(!isUnique) + throw INTERP_KERNEL::Exception(MSG0); + meshDimRelToMax=myDim-mesh->getMeshDimension(); + if(meshDimRelToMax>0) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the mesh attached to field is not compatible with the field !"); + } + return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,0/*renumPol*/,glob,mesh,arrOut,nasc); +} + /*! * Returns a new MEDCouplingFieldDouble of given type lying on a given support. * \param [in] type - a spatial discretization of the new field. @@ -4792,8 +4846,7 @@ MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldAtLevel(TypeOf MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto& arrOut, const MEDFileFieldNameScope& nasc) const { MCAuto m(mesh->getMeshAtLevel(meshDimRelToMax,false)); - const DataArrayInt *d=mesh->getNumberFieldAtLevel(meshDimRelToMax); - const DataArrayInt *e=mesh->getNumberFieldAtLevel(1); + const DataArrayInt *d(mesh->getNumberFieldAtLevel(meshDimRelToMax)),*e(mesh->getNumberFieldAtLevel(1)); if(meshDimRelToMax==1) (static_cast((MEDCouplingMesh *)m))->setMeshDimension(0); return MEDFileAnyTypeField1TSWithoutSDA::getFieldOnMeshAtLevel(type,renumPol,glob,m,d,e,arrOut,nasc); @@ -6452,6 +6505,23 @@ MEDFileField1TS::MEDFileField1TS() _content=new MEDFileField1TSWithoutSDA; } +/*! + * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance + * method should be called (getFieldOnMeshAtLevel for example). + * But for normal usage of field in MED file world this method is the most efficient to fetch data. + * + * \param [in] mesh - the mesh the field is lying on + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * caller is to delete this field using decrRef() as it is no more needed. + */ +MEDCouplingFieldDouble *MEDFileField1TS::field(const MEDFileMesh *mesh) const +{ + MCAuto arrOut; + MCAuto ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull())); + MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); + return ret.retn(); +} + /*! * Returns a new MEDCouplingFieldDouble of a given type lying on * mesh entities of a given dimension of the first mesh in MED file. If \a this field @@ -6480,7 +6550,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(TypeOfField type, int m if(getFileName().empty()) throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6512,7 +6582,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, in if(getFileName().empty()) throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtTopLevel : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtTopLevel method instead !"); MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldAtTopLevel(type,std::string(),renumPol,this,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6540,7 +6610,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtTopLevel(TypeOfField type, in MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol) const { MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldOnMeshAtLevel(type,renumPol,this,mesh,0,0,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6569,7 +6639,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const { MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,this,mesh,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6605,7 +6675,7 @@ MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevelOld(TypeOfField type, co if(getFileName().empty()) throw INTERP_KERNEL::Exception("MEDFileField1TS::getFieldAtLevelOld : Request for a method that can be used for instances coming from file loading ! Use getFieldOnMeshAtLevel method instead !"); MCAuto arrOut; - MCAuto ret=contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull()); + MCAuto ret(contentNotNull()->getFieldAtLevel(type,meshDimRelToMax,mname,renumPol,this,arrOut,*contentNotNull())); MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); return ret.retn(); } @@ -6827,6 +6897,26 @@ void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldDouble *fiel contentNotNull()->setFieldNoProfileSBT(field,arrOfVals,*this,*contentNotNull()); } +/*! + * Adds a MEDCouplingFieldInt to \a this. The underlying mesh of the given field is + * checked if its elements are sorted suitable for writing to MED file ("STB" stands for + * "Sort By Type"), if not, an exception is thrown. + * For more info, see \ref AdvMEDLoaderAPIFieldRW + * \param [in] field - the field to add to \a this. + * \throw If the name of \a field is empty. + * \throw If the data array of \a field is not set. + * \throw If the data array is already allocated but has different number of components + * than \a field. + * \throw If the underlying mesh of \a field has no name. + * \throw If elements in the mesh are not in the order suitable for writing to the MED file. + */ +void MEDFileIntField1TS::setFieldNoProfileSBT(const MEDCouplingFieldInt *field) +{ + MCAuto field2(ConvertFieldIntToFieldDouble(field)); + setFileName(""); + contentNotNull()->setFieldNoProfileSBT(field2,field->getArray(),*this,*contentNotNull()); +} + /*! * Adds a MEDCouplingFieldDouble to \a this. As described in \ref MEDLoaderMainC a field in MED file sense * can be an aggregation of several MEDCouplingFieldDouble instances. @@ -6856,6 +6946,35 @@ void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, co contentNotNull()->setFieldProfile(field,arrOfVals,mesh,meshDimRelToMax,profile,*this,*contentNotNull()); } +/*! + * Adds a MEDCouplingFieldInt to \a this. As described in \ref MEDLoaderMainC a field in MED file sense + * can be an aggregation of several MEDCouplingFieldDouble instances. + * The mesh support of input parameter \a field is ignored here, it can be NULL. + * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax, + * and \a profile. + * + * This method will check that the field based on the computed support is coherent. If not an exception will be thrown. + * A new profile is added only if no equal profile is missing. + * For more info, see \ref AdvMEDLoaderAPIFieldRW + * \param [in] field - the field to add to \a this. + * \param [in] mesh - the supporting mesh of \a field. + * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES). + * \param [in] profile - ids of mesh entities on which corresponding field values lie. + * \throw If either \a field or \a mesh or \a profile has an empty name. + * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh. + * \throw If the data array of \a field is not set. + * \throw If the data array of \a this is already allocated but has different number of + * components than \a field. + * \throw If elements in \a mesh are not in the order suitable for writing to the MED file. + * \sa setFieldNoProfileSBT() + */ +void MEDFileIntField1TS::setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) +{ + MCAuto field2(ConvertFieldIntToFieldDouble(field)); + setFileName(""); + contentNotNull()->setFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this,*contentNotNull()); +} + const MEDFileIntField1TSWithoutSDA *MEDFileIntField1TS::contentNotNull() const { const MEDFileAnyTypeField1TSWithoutSDA *pt(_content); @@ -6883,7 +7002,7 @@ MEDCouplingFieldDouble *MEDFileIntField1TS::getFieldAtLevel(TypeOfField type, in DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto& arr) { - if(!((DataArray *)arr)) + if(arr.isNull()) throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ReturnSafelyDataArrayInt : input DataArray is NULL !"); DataArrayInt *arrC=dynamic_cast((DataArray *)arr); if(!arrC) @@ -6892,11 +7011,51 @@ DataArrayInt *MEDFileIntField1TS::ReturnSafelyDataArrayInt(MCAuto& ar return arrC; } +MCAuto MEDFileIntField1TS::SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto& arr) +{ + int t1,t2; + double t0(f->getTime(t1,t2)); + MCAuto arr2(DynamicCastSafe(arr)); + MCAuto ft(MEDCouplingFieldTemplate::New(*f)); + MCAuto ret(MEDCouplingFieldInt::New(*ft)); + ret->setTime(t0,t1,t2); ret->setArray(arr2); + return ret.retn(); +} + +MCAuto MEDFileIntField1TS::ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f) +{ + if(!f) + throw INTERP_KERNEL::Exception("MEDFileIntField1TS::ConvertFieldIntToFieldDouble : null input field !"); + int t1,t2; + double t0(f->getTime(t1,t2)); + MCAuto ft(MEDCouplingFieldTemplate::New(*f)); + MCAuto ret(MEDCouplingFieldDouble::New(*ft)); + ret->setTime(t0,t1,t2); + return ret; +} + MEDFileIntField1TS *MEDFileIntField1TS::extractPart(const std::map >& extractDef, MEDFileMesh *mm) const { throw INTERP_KERNEL::Exception("MEDFileIntField1TS::extractPart : not implemented yet !"); } +/*! + * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance + * method should be called (getFieldOnMeshAtLevel for example). + * But for normal usage of field in MED file world this method is the most efficient to fetch data. + * + * \param [in] mesh - the mesh the field is lying on + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The + * caller is to delete this field using decrRef() as it is no more needed. + */ +MEDCouplingFieldInt *MEDFileIntField1TS::field(const MEDFileMesh *mesh) const +{ + MCAuto arrOut; + MCAuto ret(contentNotNull()->fieldOnMesh(this,mesh,arrOut,*contentNotNull())); + MCAuto ret2(SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); +} + /*! * Returns a new MEDCouplingFieldDouble of a given type lying on * the top level cells of the first mesh in MED file. If \a this field @@ -9195,6 +9354,26 @@ MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type return ret.retn(); } +/*! + * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance + * method should be called (getFieldOnMeshAtLevel for example). + * But for normal usage of field in MED file world this method is the most efficient to fetch data. + * + * \param [in] iteration - the iteration number of a required time step. + * \param [in] order - the iteration order number of required time step. + * \param [in] mesh - the mesh the field is lying on + * \return MEDCouplingFieldDouble * - a new instance of MEDCouplingFieldDouble. The + * caller is to delete this field using decrRef() as it is no more needed. + */ +MEDCouplingFieldDouble *MEDFileFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const +{ + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + MCAuto arrOut; + MCAuto ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase())); + MEDFileField1TS::SetDataArrayDoubleInField(ret,arrOut); + return ret.retn(); +} + /*! * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on * a given support. @@ -9219,7 +9398,7 @@ MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldAtTopLevel(TypeOfField type */ MEDCouplingFieldDouble *MEDFileFieldMultiTS::getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol) const { - const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order); + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); const MEDFileField1TSWithoutSDA *myF1TSC=dynamic_cast(&myF1TS); if(!myF1TSC) throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::getFieldOnMeshAtLevel : mismatch of type of field !"); @@ -9562,6 +9741,26 @@ void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS * throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::checkCoherencyOfType : the input field1TS is not a INT32 type !"); } +/*! + * This is the simplest version to fetch a field for MED structure. One drawback : if \a this is a complex field (multi spatial discretization inside a same field) this method will throw exception and more advance + * method should be called (getFieldOnMeshAtLevel for example). + * But for normal usage of field in MED file world this method is the most efficient to fetch data. + * + * \param [in] iteration - the iteration number of a required time step. + * \param [in] order - the iteration order number of required time step. + * \param [in] mesh - the mesh the field is lying on + * \return MEDCouplingFieldInt * - a new instance of MEDCouplingFieldInt. The + * caller is to delete this field using decrRef() as it is no more needed. + */ +MEDCouplingFieldInt *MEDFileIntFieldMultiTS::field(int iteration, int order, const MEDFileMesh *mesh) const +{ + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + MCAuto arrOut; + MCAuto ret(myF1TS.fieldOnMesh(this,mesh,arrOut,*contentNotNullBase())); + MCAuto ret2(MEDFileIntField1TS::SetDataArrayDoubleInIntField(ret,arrOut)); + return ret2.retn(); +} + /*! * Returns a new MEDCouplingFieldDouble of a given type, of a given time step, lying on * mesh entities of a given dimension of the first mesh in MED file. @@ -9587,12 +9786,12 @@ void MEDFileIntFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS * */ MEDCouplingFieldDouble *MEDFileIntFieldMultiTS::getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol) const { - const MEDFileAnyTypeField1TSWithoutSDA& myF1TS=contentNotNullBase()->getTimeStepEntry(iteration,order); - const MEDFileIntField1TSWithoutSDA *myF1TSC=dynamic_cast(&myF1TS); + const MEDFileAnyTypeField1TSWithoutSDA& myF1TS(contentNotNullBase()->getTimeStepEntry(iteration,order)); + const MEDFileIntField1TSWithoutSDA *myF1TSC(dynamic_cast(&myF1TS)); if(!myF1TSC) throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::getFieldAtLevel : mismatch of type of field expecting INT32 !"); MCAuto arr; - MCAuto ret=myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase()); + MCAuto ret(myF1TSC->getFieldAtLevel(type,meshDimRelToMax,std::string(),renumPol,this,arr,*contentNotNullBase())); arrOut=MEDFileIntField1TS::ReturnSafelyDataArrayInt(arr); return ret.retn(); } @@ -9771,6 +9970,24 @@ MEDFileAnyTypeField1TS *MEDFileIntFieldMultiTS::getTimeStepAtPos(int pos) const throw INTERP_KERNEL::Exception(oss.str().c_str()); } +/*! + * Adds a MEDCouplingFieldInt to \a this as another time step. The underlying mesh of + * the given field is checked if its elements are sorted suitable for writing to MED file + * ("STB" stands for "Sort By Type"), if not, an exception is thrown. + * For more info, see \ref AdvMEDLoaderAPIFieldRW + * \param [in] field - the field to add to \a this. + * \throw If the name of \a field is empty. + * \throw If the data array of \a field is not set. + * \throw If existing time steps have different name or number of components than \a field. + * \throw If the underlying mesh of \a field has no name. + * \throw If elements in the mesh are not in the order suitable for writing to the MED file. + */ +void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldInt *field) +{ + MCAuto field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field)); + contentNotNull()->appendFieldNoProfileSBT(field2,field->getArray(),*this); +} + /*! * Adds a MEDCouplingFieldDouble to \a this as another time step. The underlying mesh of * the given field is checked if its elements are sorted suitable for writing to MED file @@ -9788,6 +10005,34 @@ void MEDFileIntFieldMultiTS::appendFieldNoProfileSBT(const MEDCouplingFieldDoubl contentNotNull()->appendFieldNoProfileSBT(field,arrOfVals,*this); } +/*! + * Adds a MEDCouplingFieldDouble to \a this as another time step. + * The mesh support of input parameter \a field is ignored here, it can be NULL. + * The support of field \a field is expected to be those computed with the input parameter \a mesh, \a meshDimRelToMax, + * and \a profile. + * + * This method will check that the field based on the computed support is coherent. If not an exception will be thrown. + * A new profile is added only if no equal profile is missing. + * For more info, see \ref AdvMEDLoaderAPIFieldRW + * \param [in] field - the field to add to \a this. The field double values and mesh support are ignored. + * \param [in] arrOfVals - the values of the field \a field used. + * \param [in] mesh - the supporting mesh of \a field. + * \param [in] meshDimRelToMax - a relative dimension of mesh entities \a field lies on (useless if field spatial discretization is ON_NODES). + * \param [in] profile - ids of mesh entities on which corresponding field values lie. + * \throw If either \a field or \a mesh or \a profile has an empty name. + * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a mesh. + * \throw If the data array of \a field is not set. + * \throw If the data array of \a this is already allocated but has different number of + * components than \a field. + * \throw If elements in \a mesh are not in the order suitable for writing to the MED file. + * \sa setFieldNoProfileSBT() + */ +void MEDFileIntFieldMultiTS::appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) +{ + MCAuto field2(MEDFileIntField1TS::ConvertFieldIntToFieldDouble(field)); + contentNotNull()->appendFieldProfile(field2,field->getArray(),mesh,meshDimRelToMax,profile,*this); +} + /*! * Adds a MEDCouplingFieldDouble to \a this as another time step. * The mesh support of input parameter \a field is ignored here, it can be NULL. diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index f12ef235d..9a3da283e 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -28,6 +28,7 @@ #include "MCAuto.hxx" #include "MEDCouplingRefCountObject.hxx" +#include "MEDCouplingFieldInt.hxx" #include "MEDCouplingMemArray.hxx" #include "NormalizedUnstructuredMesh.hxx" @@ -192,6 +193,7 @@ namespace MEDCoupling void loadBigArraysRecursively(med_idt fid, const MEDFileFieldNameScope& nasc); void writeLL(med_idt fid, const MEDFileFieldNameScope& nasc) const; void getDimension(int& dim) const; + bool isUniqueLevel(int& dim) const; void fillTypesOfFieldAvailable(std::set& types) const; void fillFieldSplitedByType(std::vector< std::pair >& dads, std::vector& types, std::vector& pfls, std::vector& locs) const; int getIteration() const; @@ -255,6 +257,7 @@ namespace MEDCoupling void fillTypesOfFieldAvailable(std::set& types) const; std::vector< std::vector< std::pair > > getFieldSplitedByType(std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const; void getDimension(int& dim) const; + bool isUniqueLevel(int& dim) const; double getTime() const; int getIteration() const; int getOrder() const; @@ -517,6 +520,7 @@ namespace MEDCoupling MEDLOADER_EXPORT virtual DataArray *getOrCreateAndGetArray() = 0; MEDLOADER_EXPORT virtual const DataArray *getOrCreateAndGetArray() const = 0; public: + MEDLOADER_EXPORT MEDCouplingFieldDouble *fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto& arrOut, const MEDFileFieldNameScope& nasc) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto &arrOut, const MEDFileFieldNameScope& nasc) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto &arrOut, const MEDFileFieldNameScope& nasc) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, const std::string& mName, int renumPol, const MEDFileFieldGlobsReal *glob, MCAuto &arrOut, const MEDFileFieldNameScope& nasc) const; @@ -726,6 +730,7 @@ namespace MEDCoupling MEDLOADER_EXPORT static MEDFileField1TS *New(); MEDLOADER_EXPORT MEDFileIntField1TS *convertToInt(bool isDeepCpyGlobs=true) const; // + MEDLOADER_EXPORT MEDCouplingFieldDouble *field(const MEDFileMesh *mesh) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const; @@ -772,6 +777,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileField1TS *convertToDouble(bool isDeepCpyGlobs=true) const; MEDLOADER_EXPORT MEDFileAnyTypeField1TS *shallowCpy() const; // + MEDLOADER_EXPORT MEDCouplingFieldInt *field(const MEDFileMesh *mesh) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, DataArrayInt* &arrOut, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol=0) const; @@ -779,11 +785,15 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; MEDLOADER_EXPORT DataArrayInt *getFieldWithProfile(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const; // + MEDLOADER_EXPORT void setFieldNoProfileSBT(const MEDCouplingFieldInt *field); MEDLOADER_EXPORT void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals); + MEDLOADER_EXPORT void setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile); MEDLOADER_EXPORT void setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile); MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArray() const; public: MEDLOADER_EXPORT static DataArrayInt *ReturnSafelyDataArrayInt(MCAuto& arr); + MEDLOADER_EXPORT static MCAuto SetDataArrayDoubleInIntField(MEDCouplingFieldDouble *f, MCAuto& arr); + MEDLOADER_EXPORT static MCAuto ConvertFieldIntToFieldDouble(const MEDCouplingFieldInt *f); public: MEDLOADER_EXPORT MEDFileIntField1TS *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const; private: @@ -1029,6 +1039,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStep(int iteration, int order) const; MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStepGivenTime(double time, double eps=1e-8) const; // + MEDLOADER_EXPORT MEDCouplingFieldDouble *field(int iteration, int order, const MEDFileMesh *mesh) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const; @@ -1070,6 +1081,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileAnyTypeField1TS *getTimeStepAtPos(int pos) const; MEDLOADER_EXPORT MEDFileFieldMultiTS *convertToDouble(bool isDeepCpyGlobs=true) const; // + MEDLOADER_EXPORT MEDCouplingFieldInt *field(int iteration, int order, const MEDFileMesh *mesh) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol=0) const; MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt* &arrOut, int renumPol=0) const; @@ -1077,7 +1089,9 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDCouplingFieldDouble *getFieldAtLevelOld(TypeOfField type, int iteration, int order, const std::string& mname, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const; MEDLOADER_EXPORT DataArrayInt *getFieldWithProfile(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, DataArrayInt *&pfl) const; // + MEDLOADER_EXPORT void appendFieldNoProfileSBT(const MEDCouplingFieldInt *field); MEDLOADER_EXPORT void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals); + MEDLOADER_EXPORT void appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile); MEDLOADER_EXPORT void appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile); // MEDLOADER_EXPORT DataArrayInt *getUndergroundDataArray(int iteration, int order) const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 08396b5bf..3944fbb22 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -159,6 +159,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileAnyTypeFieldMultiTS::buildNewEmpty; %newobject MEDCoupling::MEDFileFieldMultiTS::New; %newobject MEDCoupling::MEDFileFieldMultiTS::LoadSpecificEntities; +%newobject MEDCoupling::MEDFileFieldMultiTS::field; %newobject MEDCoupling::MEDFileFieldMultiTS::getFieldAtLevel; %newobject MEDCoupling::MEDFileFieldMultiTS::getFieldAtTopLevel; %newobject MEDCoupling::MEDFileFieldMultiTS::getFieldOnMeshAtLevel; @@ -166,6 +167,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileFieldMultiTS::getUndergroundDataArray; %newobject MEDCoupling::MEDFileFieldMultiTS::convertToInt; %newobject MEDCoupling::MEDFileIntFieldMultiTS::New; +%newobject MEDCoupling::MEDFileIntFieldMultiTS::field; %newobject MEDCoupling::MEDFileIntFieldMultiTS::LoadSpecificEntities; %newobject MEDCoupling::MEDFileIntFieldMultiTS::getUndergroundDataArray; %newobject MEDCoupling::MEDFileIntFieldMultiTS::convertToDouble; @@ -175,6 +177,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileAnyTypeField1TS::deepCopy; %newobject MEDCoupling::MEDFileAnyTypeField1TS::extractPart; %newobject MEDCoupling::MEDFileField1TS::New; +%newobject MEDCoupling::MEDFileField1TS::field; %newobject MEDCoupling::MEDFileField1TS::getFieldAtLevel; %newobject MEDCoupling::MEDFileField1TS::getFieldAtTopLevel; %newobject MEDCoupling::MEDFileField1TS::getFieldOnMeshAtLevel; @@ -183,6 +186,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileField1TS::convertToInt; %newobject MEDCoupling::MEDFileIntField1TS::New; +%newobject MEDCoupling::MEDFileIntField1TS::field; %newobject MEDCoupling::MEDFileIntField1TS::getUndergroundDataArray; %newobject MEDCoupling::MEDFileIntField1TS::convertToDouble; @@ -1991,6 +1995,7 @@ namespace MEDCoupling static MEDFileField1TS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception); static MEDFileField1TS *New(); MEDCoupling::MEDFileIntField1TS *convertToInt(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *field(const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); @@ -2126,8 +2131,11 @@ namespace MEDCoupling static MEDFileIntField1TS *New(const std::string& fileName, const std::string& fieldName, int iteration, int order, bool loadAll=true) throw(INTERP_KERNEL::Exception); MEDCoupling::MEDFileField1TS *convertToDouble(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); // + void setFieldNoProfileSBT(const MEDCouplingFieldInt *field) throw(INTERP_KERNEL::Exception); void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception); + void setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); void setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldInt *field(const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); %extend { MEDFileIntField1TS() throw(INTERP_KERNEL::Exception) @@ -2632,6 +2640,7 @@ namespace MEDCoupling static MEDFileFieldMultiTS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception); static MEDFileFieldMultiTS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception); // + MEDCouplingFieldDouble *field(int iteration, int order, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); @@ -2782,9 +2791,12 @@ namespace MEDCoupling static MEDFileIntFieldMultiTS *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception); static MEDFileIntFieldMultiTS *New(const std::string& fileName, const std::string& fieldName, bool loadAll=true) throw(INTERP_KERNEL::Exception); // + void appendFieldNoProfileSBT(const MEDCouplingFieldInt *field) throw(INTERP_KERNEL::Exception); void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception); + void appendFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); void appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); MEDCoupling::MEDFileFieldMultiTS *convertToDouble(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *field(int iteration, int order, const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); %extend { MEDFileIntFieldMultiTS() -- 2.39.2