diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 35d422fba377f09514fe0ac6ee1c4e2bd0a952d8..4df00efed959261d1329eb1b22676a3104636cfc 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -1560,3 +1560,36 @@ int Msg::GetMaxThreads(){ return 1; } int Msg::GetThreadNum(){ return 0; } #endif + +MsgProgressStatus::MsgProgressStatus(int num) + : totalElementToTreat_(num), currentI_(0), nextIToCheck_(0), + initialTime_(Cpu()), lastTime_(initialTime_), lastPercentage_(0) +{} + +void MsgProgressStatus::next() +{ + ++currentI_; + if (currentI_ < nextIToCheck_) return; + + unsigned int currentPercentage = currentI_*100/totalElementToTreat_; + // check every percentage only + nextIToCheck_ = (currentPercentage+1) * totalElementToTreat_ / 100 + 1; + + double currentTime = Cpu(); + if ((currentPercentage < 5 && currentTime - lastTime_ > 15.) || + (currentPercentage > lastPercentage_ + 4 && currentTime - lastTime_ > 10.)) { + lastPercentage_ = currentPercentage; + lastTime_ = currentTime; + const double remaining = (currentTime-initialTime_) / (currentI_+1) * + (totalElementToTreat_ - currentI_-1); + if (remaining < 60*2) + Msg::StatusBar(true, "%d%% (remaining time ~%g seconds)", + currentPercentage, remaining); + else if (remaining < 60*60*2) + Msg::StatusBar(true, "%d%% (remaining time ~%g minutes)", + currentPercentage, remaining/60); + else + Msg::StatusBar(true, "%d%% (remaining time ~%g hours)", + currentPercentage, remaining/3600); + } +} \ No newline at end of file diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h index b016a9311034503f15961dcc3b0b36e251c2b4ae..8ebf65b3d16b98719401e8f7fe07f081a549dbc1 100644 --- a/Common/GmshMessage.h +++ b/Common/GmshMessage.h @@ -152,4 +152,20 @@ class Msg { static void ImportPhysicalGroupsInOnelab(); }; +// a class to print the progression and estimated remaining time +class MsgProgressStatus +{ +private: + int totalElementToTreat_, currentI_, nextIToCheck_; + double initialTime_, lastTime_; + int lastPercentage_; + int progressMeterStep_; +public: + MsgProgressStatus(int numElementToTreat); + ~MsgProgressStatus(); + + void setInitialTime(double time) {initialTime_ = time;} + void next(); +}; + #endif diff --git a/Plugin/AnalyseCurvedMesh.cpp b/Plugin/AnalyseCurvedMesh.cpp index 372e9a1e9b7944941edf43075f1be26352cc82eb..c85cafc660ac259413b928f439d81849f564dc1e 100644 --- a/Plugin/AnalyseCurvedMesh.cpp +++ b/Plugin/AnalyseCurvedMesh.cpp @@ -22,39 +22,6 @@ class bezierBasis; -ProgressStatus::ProgressStatus(int num) - : totalElementToTreat_(num), currentI_(0), nextIToCheck_(0), - initialTime_(Cpu()), lastTime_(initialTime_), lastPercentage_(0) -{} - -void ProgressStatus::check() -{ - ++currentI_; - if (currentI_ < nextIToCheck_) return; - - unsigned int currentPercentage = currentI_*100/totalElementToTreat_; - nextIToCheck_ = (currentPercentage+1) * totalElementToTreat_ / 100 + 1; - //nextIToCheck_ += totalElementToTreat_ / 100; - - double currentTime = Cpu(); - if ((currentPercentage < 5 && currentTime - lastTime_ > 15.) || - (currentPercentage > lastPercentage_ + 4 && currentTime - lastTime_ > 10.)) { - lastPercentage_ = currentPercentage; - lastTime_ = currentTime; - const double remaining = (currentTime-initialTime_) / (currentI_+1) * - (totalElementToTreat_ - currentI_-1); - if (remaining < 60*2) - Msg::StatusBar(true, "%d%% (remaining time ~%g seconds)", - currentPercentage, remaining); - else if (remaining < 60*60*2) - Msg::StatusBar(true, "%d%% (remaining time ~%g minutes)", - currentPercentage, remaining/60); - else - Msg::StatusBar(true, "%d%% (remaining time ~%g hours)", - currentPercentage, remaining/3600); - } -} - StringXNumber CurvedMeshOptions_Number[] = { {GMSH_FULLRC, "Jacobian determinant", NULL, 1}, {GMSH_FULLRC, "Scaled Jacobian", NULL, 0}, @@ -355,7 +322,7 @@ void GMSH_AnalyseCurvedMeshPlugin::_computeMinMaxJandValidity(int dim) default: break; } - ProgressStatus progress(num); + MsgProgressStatus progress(num); _data.reserve(_data.size()+num); for (unsigned i = 0; i < num; ++i) { @@ -366,7 +333,7 @@ void GMSH_AnalyseCurvedMeshPlugin::_computeMinMaxJandValidity(int dim) if (min < 0 && max < 0) { Msg::Warning("Element %d is completely inverted", el->getNum()); } - progress.check(); + progress.next(); } delete normals; } @@ -377,7 +344,7 @@ void GMSH_AnalyseCurvedMeshPlugin::_computeMinScaledJac(int dim) { if (_computedS[dim-1]) return; - ProgressStatus progress(_data.size()); + MsgProgressStatus progress(_data.size()); for (unsigned int i = 0; i < _data.size(); ++i) { MElement *const el = _data[i].element(); @@ -388,7 +355,7 @@ void GMSH_AnalyseCurvedMeshPlugin::_computeMinScaledJac(int dim) else { _data[i].setMinS(jacobianBasedQuality::minScaledJacobian(el, true)); } - progress.check(); + progress.next(); } _computedS[dim-1] = true; @@ -398,7 +365,7 @@ void GMSH_AnalyseCurvedMeshPlugin::_computeMinIsotropy(int dim) { if (_computedI[dim-1]) return; - ProgressStatus progress(_data.size()); + MsgProgressStatus progress(_data.size()); for (unsigned int i = 0; i < _data.size(); ++i) { MElement *const el = _data[i].element(); @@ -409,7 +376,7 @@ void GMSH_AnalyseCurvedMeshPlugin::_computeMinIsotropy(int dim) else { _data[i].setMinI(jacobianBasedQuality::minIsotropyMeasure(el, true)); } - progress.check(); + progress.next(); } _computedI[dim-1] = true; diff --git a/Plugin/AnalyseCurvedMesh.h b/Plugin/AnalyseCurvedMesh.h index f7abb42d8b7ae60842b944c0dff29594c2f7bbaa..17aa641503509de110cc41d4c77580666cfcd786 100644 --- a/Plugin/AnalyseCurvedMesh.h +++ b/Plugin/AnalyseCurvedMesh.h @@ -36,18 +36,6 @@ public: double minI() { return _minI; } }; -class ProgressStatus -{ -private: - int totalElementToTreat_, currentI_, nextIToCheck_; - double initialTime_, lastTime_; - int lastPercentage_; -public: - ProgressStatus(int num); - void setInitialTime(double time) {initialTime_ = time;} - void check(); -}; - class GMSH_AnalyseCurvedMeshPlugin : public GMSH_PostPlugin { private :