From f1fb3386582f7cee0897d2f812290f66b3dfbf92 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 4 Jan 2018 13:32:32 +0100 Subject: [PATCH] useful copyTimeInfoFrom --- src/MEDLoader/MEDFileField.cxx | 13 ++++++------ src/MEDLoader/MEDFileField.txx | 16 ++++++++++++++ src/MEDLoader/MEDFileField1TS.hxx | 2 ++ src/MEDLoader/MEDFileFieldInternal.cxx | 12 +++++++++++ src/MEDLoader/MEDFileFieldInternal.hxx | 1 + src/MEDLoader/Swig/MEDLoaderCommon.i | 3 +++ src/MEDLoader/Swig/MEDLoaderTest3.py | 4 ++++ .../TestPyWrapGathered_medcoupling.py | 21 +++++++++++++++++++ src/PyWrapping/medcoupling_pycode | 11 +++++++++- 9 files changed, 76 insertions(+), 7 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 18d7b263a..c310994f7 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -650,9 +650,10 @@ void MEDFileFieldLin2QuadVisitor::newPerMeshPerTypePerDisc(const MEDFileFieldPer throw INTERP_KERNEL::Exception("Not managed yet for ON_CELLS ON_GAUSS_NE and ON_GAUSS_PT"); _1ts_update_requested=true; MEDFileAnyTypeField1TSWithoutSDA *ct(_cur_f1ts->contentNotNullBase()); - MEDFileFieldPerMeshPerTypePerDisc *pmtdToModify(ct->getLeafGivenMeshAndTypeAndLocId(_lin->getName(),_gt,pmptpd->getLocId())); + int locId(pmptpd->getFather()->locIdOfLeaf(pmptpd)); + MEDFileFieldPerMeshPerTypePerDisc *pmtdToModify(ct->getLeafGivenMeshAndTypeAndLocId(_lin->getName(),_gt,locId)); std::string pflName(pmptpd->getProfile()); - if(pflName==_pfl) + if(pflName==_pfl && _matrix.isNotNull()) { updateData(pmtdToModify); return ; @@ -689,14 +690,14 @@ void MEDFileFieldLin2QuadVisitor::newPerMeshPerTypePerDisc(const MEDFileFieldPer DataArrayInt *nodeConn(allSeg3->getNodalConnectivity()); nodeConn->rearrange(3); { - std::vector v(1,1); + std::vector v(1,2); midPts=nodeConn->keepSelectedComponents(v); } cellSeg3Ids=DataArrayInt::FindPermutationFromFirstToSecond(midPts,_new_pts_ids); { std::vector v(2); v[0]=0; v[1]=1; MCAuto tmp(nodeConn->keepSelectedComponents(v)); - _matrix=tmp->selectByTupleId(tmp->begin(),tmp->end()); + _matrix=tmp->selectByTupleId(cellSeg3Ids->begin(),cellSeg3Ids->end()); } nodeConn->rearrange(1); } @@ -735,7 +736,7 @@ void MEDFileFieldLin2QuadVisitor::newTimeStepEntry(const MEDFileAnyTypeField1TSW return ; MCAuto contentCpy(ts->deepCopy()); MCAuto contentCpy2(DynamicCastSafe(contentCpy)); - if(contentCpy2.isNotNull()) + if(contentCpy2.isNull()) return; _cur_f1ts=MEDFileField1TS::New(*contentCpy2,true); _cur_f1ts->shallowCpyGlobs(*_lin_globs); @@ -773,7 +774,7 @@ void MEDFileFieldLin2QuadVisitor::endTimeStepEntry(const MEDFileAnyTypeField1TSW MCAuto part0(arr->selectByTupleId(*pts0)); MCAuto part1(arr->selectByTupleId(*pts1)); res=DataArrayDouble::Add(part0,part1); - res->applyLin(1.,0.); + res->applyLin(0.5,0.); } res=DataArrayDouble::Aggregate(arr,res); _cur_f1ts->setArray(res); diff --git a/src/MEDLoader/MEDFileField.txx b/src/MEDLoader/MEDFileField.txx index dfa83a340..ab4a0d178 100644 --- a/src/MEDLoader/MEDFileField.txx +++ b/src/MEDLoader/MEDFileField.txx @@ -199,6 +199,16 @@ namespace MEDCoupling } } + template + void MEDFileField1TSTemplateWithoutSDA::copyTimeInfoFrom(const typename Traits::FieldType *mcf) + { + if(!mcf) + throw INTERP_KERNEL::Exception("MEDFileField1TSTemplateWithoutSDA::copyTimeInfoFrom : input field is nullptr !"); + int b(0),c(0); + double a(mcf->getTime(b,c)); + setTime(b,c,a); + } + /////////////////////////////////////////////////////// template @@ -444,6 +454,12 @@ namespace MEDCoupling return ret.retn(); } + template + void MEDFileTemplateField1TS::copyTimeInfoFrom(const typename Traits::FieldType *mcf) + { + contentNotNull()->copyTimeInfoFrom(mcf); + } + /*! * 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). diff --git a/src/MEDLoader/MEDFileField1TS.hxx b/src/MEDLoader/MEDFileField1TS.hxx index 55d681f3a..54f75f887 100644 --- a/src/MEDLoader/MEDFileField1TS.hxx +++ b/src/MEDLoader/MEDFileField1TS.hxx @@ -160,6 +160,7 @@ namespace MEDCoupling MEDLOADER_EXPORT const DataArray *getOrCreateAndGetArray() const; MEDLOADER_EXPORT DataArray *getUndergroundDataArray() const; MEDLOADER_EXPORT void aggregate(const typename std::vector< typename MLFieldTraits::F1TSWSDAType const * >& f1tss, const std::vector< std::vector< std::pair > >& dts); + MEDLOADER_EXPORT void copyTimeInfoFrom(const typename Traits::FieldType *mcf); protected: MCAuto< typename Traits::ArrayType > _arr; }; @@ -355,6 +356,7 @@ namespace MEDCoupling MEDLOADER_EXPORT static MCAuto::FieldType> SetDataArrayInField(MEDCouplingFieldDouble *f, MCAuto& arr); MEDLOADER_EXPORT static MCAuto ToFieldTemplateWithTime(const typename Traits::FieldType *f); public: + MEDLOADER_EXPORT void copyTimeInfoFrom(const typename Traits::FieldType *mcf); MEDLOADER_EXPORT typename Traits::FieldType *field(const MEDFileMesh *mesh) const; MEDLOADER_EXPORT typename Traits::FieldType *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const; MEDLOADER_EXPORT typename Traits::FieldType *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const; diff --git a/src/MEDLoader/MEDFileFieldInternal.cxx b/src/MEDLoader/MEDFileFieldInternal.cxx index 2660a5a76..2a138059b 100644 --- a/src/MEDLoader/MEDFileFieldInternal.cxx +++ b/src/MEDLoader/MEDFileFieldInternal.cxx @@ -1612,6 +1612,18 @@ const MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypeCommon::getLe return static_cast(0); } +int MEDFileFieldPerMeshPerTypeCommon::locIdOfLeaf(const MEDFileFieldPerMeshPerTypePerDisc *leaf) const +{ + int ret(0); + for(std::vector< MCAuto >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++,ret++) + { + const MEDFileFieldPerMeshPerTypePerDisc *cand(*it); + if(cand==leaf) + return ret; + } + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypeCommon::locIdOfLeaf : not found such a leaf in this !"); +} + void MEDFileFieldPerMeshPerTypeCommon::fillValues(int& startEntryId, std::vector< std::pair,std::pair > >& entries) const { int i=0; diff --git a/src/MEDLoader/MEDFileFieldInternal.hxx b/src/MEDLoader/MEDFileFieldInternal.hxx index 2335038c9..8c2e47903 100644 --- a/src/MEDLoader/MEDFileFieldInternal.hxx +++ b/src/MEDLoader/MEDFileFieldInternal.hxx @@ -253,6 +253,7 @@ namespace MEDCoupling MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenLocId(int locId); const MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenLocId(int locId) const; int getNumberOfLoc() const { return _field_pm_pt_pd.size(); } + int locIdOfLeaf(const MEDFileFieldPerMeshPerTypePerDisc *leaf) const; void fillValues(int& startEntryId, std::vector< std::pair,std::pair > >& entries) const; void setLeaves(const std::vector< MCAuto< MEDFileFieldPerMeshPerTypePerDisc > >& leaves); bool keepOnlySpatialDiscretization(TypeOfField tof, int &globalNum, std::vector< std::pair >& its); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 78147f4a0..014eade6e 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -2222,6 +2222,7 @@ namespace MEDCoupling static MEDFileField1TS *New(DataArrayByte *db) throw(INTERP_KERNEL::Exception); static MEDFileField1TS *New(); MEDCoupling::MEDFileIntField1TS *convertToInt(bool isDeepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); + void copyTimeInfoFrom(MEDCouplingFieldDouble *mcf) 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); @@ -2339,6 +2340,7 @@ namespace MEDCoupling // void setFieldNoProfileSBT(const MEDCouplingFieldInt *field) throw(INTERP_KERNEL::Exception); void setFieldProfile(const MEDCouplingFieldInt *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); + void copyTimeInfoFrom(MEDCouplingFieldInt *mcf) throw(INTERP_KERNEL::Exception); MEDCouplingFieldInt *field(const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldInt *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldInt *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception); @@ -2409,6 +2411,7 @@ namespace MEDCoupling // void setFieldNoProfileSBT(const MEDCouplingFieldFloat *field) throw(INTERP_KERNEL::Exception); void setFieldProfile(const MEDCouplingFieldFloat *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); + void copyTimeInfoFrom(MEDCouplingFieldFloat *mcf) throw(INTERP_KERNEL::Exception); MEDCouplingFieldFloat *field(const MEDFileMesh *mesh) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldFloat *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldFloat *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index e61c9028a..dde857ea1 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -576,6 +576,10 @@ class MEDLoaderTest3(unittest.TestCase): ff1.setTime(3,4,2.3) itt,orr,ti=ff1.getTime() self.assertEqual(3,itt); self.assertEqual(4,orr); self.assertAlmostEqual(2.3,ti,14); + f1.setTime(5.5,7,8) + ff1.copyTimeInfoFrom(f1) + itt,orr,ti=ff1.getTime() + self.assertEqual(7,itt); self.assertEqual(8,orr); self.assertAlmostEqual(5.5,ti,14); da,infos=ff1.getUndergroundDataArrayExt() f2.getArray().setName(da.getName())#da has the same name than f2 self.assertTrue(da.isEqual(f2.getArray(),1e-12)) diff --git a/src/PyWrapping/TestPyWrapGathered_medcoupling.py b/src/PyWrapping/TestPyWrapGathered_medcoupling.py index dd39f8dae..4c91bab5b 100644 --- a/src/PyWrapping/TestPyWrapGathered_medcoupling.py +++ b/src/PyWrapping/TestPyWrapGathered_medcoupling.py @@ -98,6 +98,27 @@ class medcouplingTest(unittest.TestCase): interface=CommInterface() pass + def test5(self): + f=MEDCouplingFieldDouble(ON_NODES) + f.setTime(1.25,3,6) + a,b,c=f.getTime() + self.assertEqual(b,3) ; self.assertEqual(c,6) ; self.assertAlmostEqual(a,1.25,14); + f1ts=MEDFileField1TS() + f1ts.setTime(10,13,10.75) + f.copyTimeInfoFrom(f1ts) + a,b,c=f.getTime() + self.assertEqual(b,10) ; self.assertEqual(c,13) ; self.assertAlmostEqual(a,10.75,14); + f2=MEDCouplingFieldInt(ON_NODES) + f2.copyTimeInfoFrom(f1ts) + a,b,c=f2.getTime() + self.assertEqual(b,10) ; self.assertEqual(c,13) ; self.assertAlmostEqual(a,10.75,14); + f3=MEDCouplingFieldFloat(ON_NODES) + f3.copyTimeInfoFrom(f1ts) + a,b,c=f3.getTime() + self.assertEqual(b,10) ; self.assertEqual(c,13) ; self.assertAlmostEqual(a,10.75,14); + pass + + def partitionerTesterHelper(self,algoSelected): arr=DataArrayDouble(10) ; arr.iota() m=MEDCouplingCMesh() ; m.setCoords(arr,arr) diff --git a/src/PyWrapping/medcoupling_pycode b/src/PyWrapping/medcoupling_pycode index a3dfe1a20..a286b9116 100644 --- a/src/PyWrapping/medcoupling_pycode +++ b/src/PyWrapping/medcoupling_pycode @@ -82,10 +82,19 @@ def MEDCouplingMesh_write(self,fileName): def MEDCouplingField_write(self,fileName): MEDCouplingWriterHelper(self,fileName,WriteField) + +def MEDCouplingFieldT_copyTimeInfoFrom(self,mlf1ts): + assert(isinstance(mlf1ts,MEDFileAnyTypeField1TS)) + a,b,c=mlf1ts.getTime() + self.setTime(c,a,b) + pass MEDCouplingMesh.write=MEDCouplingMesh_write del MEDCouplingMesh_write MEDCouplingField.write=MEDCouplingField_write del MEDCouplingField_write - +MEDCouplingFieldDouble.copyTimeInfoFrom=MEDCouplingFieldT_copyTimeInfoFrom +MEDCouplingFieldInt.copyTimeInfoFrom=MEDCouplingFieldT_copyTimeInfoFrom +MEDCouplingFieldFloat.copyTimeInfoFrom=MEDCouplingFieldT_copyTimeInfoFrom +del MEDCouplingFieldT_copyTimeInfoFrom %} -- 2.39.2