Skip to content

Commit

Permalink
conditions for simulation finished refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-airshaper committed Jul 21, 2022
1 parent 9fdcbeb commit 865935b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
38 changes: 24 additions & 14 deletions convergenceDetection.C
Original file line number Diff line number Diff line change
Expand Up @@ -220,35 +220,45 @@ void Foam::functionObjects::convergenceDetection::writeDataFile(
os << endl;
}

bool Foam::functionObjects::convergenceDetection::reachedMaxIterations()
{
return currentIteration_ >= (maxStepConvergence_ + maxStepAveraging_);
}

bool Foam::functionObjects::convergenceDetection::minIterationsForAveraging()
{
return currentIteration_ >= static_cast<int>(1.1 * averagingStartedAt_) &&
currentIteration_ >= static_cast<int>(averagingMinIter_ + averagingStartedAt_);
}

bool Foam::functionObjects::convergenceDetection::checkAveragingCriteria()
{
return checkCriteriaForAveraging() < conditionAveraging_ &&
checkCriteriaForAveraging() > 0.0 &&
currentIteration_ > static_cast<int>(1.25 * averagingStartedAt_) &&
!simulationFinished_
}

void Foam::functionObjects::convergenceDetection::checkIfFinished()
{
double caclculatedPolynomGradAveraging = calculatePolynomGradAveraging();

polyVectorAveraging_.push_back(caclculatedPolynomGradAveraging);

// Info << "checkCriteriaForAveraging(): " << checkCriteriaForAveraging() << " conditionAveraging_: " << conditionAveraging_ << endl;

if (checkCriteriaForAveraging() < conditionAveraging_ &&
checkCriteriaForAveraging() > 0.0 &&
currentIteration_ > static_cast<int>(1.25 * averagingStartedAt_) &&
!simulationFinished_)
if (checkAveragingCriteria() ||
reachedMaxIterations())
{
if (currentIteration_ > static_cast<int>(1.1 * averagingStartedAt_) &&
currentIteration_ > static_cast<int>(averagingMinIter_ + averagingStartedAt_))
if (minIterationsForAveraging())
{
Info << "###########" << endl;
Info << "Simulation should stop!!!!" << endl;
Info << "###########" << endl;
Info << "Polynom Grad: " << checkCriteriaForAveraging() << endl;
Info << "Condition for averaging: " << conditionAveraging_ << endl;
Info << "Condition is: " << (checkCriteriaForAveraging() < conditionAveraging_) << endl;
Info << "###########" << endl;

time().stopAt(Time::saWriteNow);
simulationFinished_ = true;
}
// Info << "###########" << endl;
// Info << "Simulation should stop!!!!" << endl;
// Info << "###########" << endl;
// OFstream os(time().globalPath() + "/FINISHED");
}
}

Expand Down
3 changes: 3 additions & 0 deletions convergenceDetection.H
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ namespace Foam
virtual void checkConvergence();
virtual void checkIfForcesExploded();
virtual void createDataFile();
virtual bool reachedMaxIterations();
virtual bool minIterationsForAveraging();
virtual bool checkAveragingCriteria();
virtual void writeDataFileHeader(const word &header, const word &tabbedName, OFstream &os) const;
virtual void writeDataFile(OFstream &os, double &value) const;
virtual std::vector<double> polyfit(const std::vector<double> x,
Expand Down

0 comments on commit 865935b

Please sign in to comment.