From 4a1c7fd89de2b12b526d3935e65214330a6a59fd Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 22 Jun 2012 09:47:50 +0000 Subject: [PATCH] __getitem__ MEDFileFieldMultiTS. API modification for unification getTime, setTime and getTimeSteps in MEDLoader all is now normalized to iteration,order,valTime. MEDCoupling is normalized valTime,iteration,order. --- src/MEDLoader/MEDFileField.cxx | 95 +++++++++++++++++++++++++++++++++- src/MEDLoader/MEDFileField.hxx | 12 ++++- src/MEDLoader/MEDFileMesh.hxx | 2 +- 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index a13ad7ea0..5340bb3e4 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -3251,6 +3251,11 @@ MEDFileField1TS *MEDFileField1TS::New(const char *fileName, const char *fieldNam return new MEDFileField1TS(fileName,fieldName,iteration,order); } +MEDFileField1TS *MEDFileField1TS::New(const MEDFileField1TSWithoutDAS& other) +{ + return new MEDFileField1TS(other); +} + MEDFileField1TS *MEDFileField1TS::New() { return new MEDFileField1TS; @@ -3363,6 +3368,10 @@ catch(INTERP_KERNEL::Exception& e) throw e; } +MEDFileField1TS::MEDFileField1TS(const MEDFileField1TSWithoutDAS& other):MEDFileField1TSWithoutDAS(other) +{ +} + MEDFileField1TS::MEDFileField1TS() { } @@ -3687,7 +3696,7 @@ std::vector< std::pair > MEDFileFieldMultiTSWithoutDAS::getTimeSteps(st } else { - std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutDAS::getTimeSteps : At rank #" << i << " time step is not defined !"; + std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutDAS::getTimeSteps : At rank #" << i << " time step is not defined. Invoke eraseEmptyTS method !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -3776,6 +3785,58 @@ int MEDFileFieldMultiTSWithoutDAS::getNumberOfTS() const return _time_steps.size(); } +void MEDFileFieldMultiTSWithoutDAS::eraseEmptyTS() throw(INTERP_KERNEL::Exception) +{ + std::vector< MEDCouplingAutoRefCountObjectPtr > newTS; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + { + const MEDFileField1TSWithoutDAS *tmp=(*it); + if(tmp) + newTS.push_back(*it); + } + _time_steps=newTS; +} + +int MEDFileFieldMultiTSWithoutDAS::getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception) +{ + int ret=0; + std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutDAS::getPosOfTimeStep : No such time step (" << iteration << "," << order << ") !\nPossibilities are : "; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++) + { + const MEDFileField1TSWithoutDAS *tmp(*it); + if(tmp) + { + int it,ord; + tmp->getTime(it,ord); + if(it==iteration && order==ord) + return ret; + else + oss << "(" << it << "," << ord << "), "; + } + } + throw INTERP_KERNEL::Exception(oss.str().c_str()); +} + +int MEDFileFieldMultiTSWithoutDAS::getPosGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception) +{ + int ret=0; + std::ostringstream oss; oss << "MEDFileFieldMultiTSWithoutDAS::getPosGivenTime : No such time step " << time << "! \nPossibilities are : "; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,ret++) + { + const MEDFileField1TSWithoutDAS *tmp(*it); + if(tmp) + { + int it,ord; + double ti=tmp->getTime(it,ord); + if(fabs(time-ti) > MEDFileFieldMultiTSWithoutDAS::getIterations() const { int lgth=_time_steps.size(); @@ -3954,6 +4015,38 @@ MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const MEDFileFieldMultiTSWithoutDA return new MEDFileFieldMultiTS(other); } +MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception) +{ + if(pos<0 || pos>=(int)_time_steps.size()) + { + std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : request for pos #" << pos << " whereas should be in [0," << _time_steps.size() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileField1TSWithoutDAS *item=_time_steps[pos]; + if(item==0) + { + std::ostringstream oss; oss << "MEDFileFieldMultiTS::getTimeStepAtPos : request for pos #" << pos << ", this pos id exists but the underlying Field1TS is null !"; + oss << "\nTry to use following method eraseEmptyTS !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + MEDCouplingAutoRefCountObjectPtr ret=MEDFileField1TS::New(*item); + ret->shallowCpyGlobs(*this); + ret->incrRef(); + return ret; +} + +MEDFileField1TS *MEDFileFieldMultiTS::getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception) +{ + int pos=getPosOfTimeStep(iteration,order); + return getTimeStepAtPos(pos); +} + +MEDFileField1TS *MEDFileFieldMultiTS::getTimeStepGivenTime(double time, double eps) const throw(INTERP_KERNEL::Exception) +{ + int pos=getPosGivenTime(time,eps); + return getTimeStepAtPos(pos); +} + std::string MEDFileFieldMultiTS::simpleRepr() const { std::ostringstream oss; diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 222591b84..01d8d7cdf 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -379,7 +379,7 @@ namespace ParaMEDMEM int getIteration() const { return _iteration; } int getOrder() const { return _order; } double getTime(int& iteration, int& order) const { iteration=_iteration; order=_order; return _dt; } - void setTime(double val, int iteration, int order) { _dt=val; _iteration=iteration; _order=order; } + void setTime(int iteration, int order, double val) { _dt=val; _iteration=iteration; _order=order; } std::string getName() const; void setName(const char *name); void simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const; @@ -452,6 +452,7 @@ namespace ParaMEDMEM { public: static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + static MEDFileField1TS *New(const MEDFileField1TSWithoutDAS& other); static MEDFileField1TS *New(); std::string simpleRepr() const; void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); @@ -478,6 +479,7 @@ namespace ParaMEDMEM void changePflsRefsNamesGen(const std::vector< std::pair, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception); void changeLocsRefsNamesGen(const std::vector< std::pair, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception); MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + MEDFileField1TS(const MEDFileField1TSWithoutDAS& other); MEDFileField1TS(); }; @@ -486,7 +488,10 @@ namespace ParaMEDMEM public: static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, int ft, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); int getNumberOfTS() const; + void eraseEmptyTS() throw(INTERP_KERNEL::Exception); std::vector< std::pair > getIterations() const; + int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception); + int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception); int getNonEmptyLevels(int iteration, int order, const char *mname, std::vector& levs) const throw(INTERP_KERNEL::Exception); std::vector< std::vector > getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception); std::vector< std::vector< std::pair > > getFieldSplitedByType(int iteration, int order, const char *mname, std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const throw(INTERP_KERNEL::Exception); @@ -534,6 +539,11 @@ namespace ParaMEDMEM static MEDFileFieldMultiTS *New(); static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); static MEDFileFieldMultiTS *New(const MEDFileFieldMultiTSWithoutDAS& other); + // + MEDFileField1TS *getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception); + MEDFileField1TS *getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception); + MEDFileField1TS *getTimeStepGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception); + // std::string simpleRepr() const; void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 662fc4b1f..83ff5c90c 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -46,7 +46,7 @@ namespace ParaMEDMEM void setIteration(int it) { _iteration=it; } int getIteration() const { return _iteration; } void setTimeValue(double time) { _time=time; } - void setTime(double time, int dt, int it) { _time=time; _iteration=dt; _order=it; } + void setTime(int dt, int it, double time) { _time=time; _iteration=dt; _order=it; } double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; } double getTimeValue() const { return _time; } void setTimeUnit(const char *unit) { _dt_unit=unit; } -- 2.39.2