Skip to content

Commit

Permalink
Add convergence check
Browse files Browse the repository at this point in the history
  • Loading branch information
paxbun committed Oct 26, 2021
1 parent bcc5575 commit 3f80b2b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions server/core/Source/SuccessiveOverRelaxationSpace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <leth/SuccessiveOverRelaxationSpace.hh>

#include <cmath>
#include <cstdio>

char const* SuccessiveOverRelaxationSpace::GetName() noexcept
{
return "SOR";
Expand All @@ -15,11 +18,12 @@ void SuccessiveOverRelaxationSpace::SolveEquation(std::vector<float> const& A,
constexpr float omega { 1.12f };

size_t const numVars { x.size() };
for (size_t iter { 0 }; iter < 100; ++iter)
for (size_t iter { 0 }; iter < 10000; ++iter)
{
bool converge { true };
for (size_t i { 0 }; i < numVars; ++i)
{
float before { x[i] };
float const before { x[i] };

x[i] = b[i];

Expand All @@ -30,6 +34,12 @@ void SuccessiveOverRelaxationSpace::SolveEquation(std::vector<float> const& A,
x[i] *= omega;
x[i] /= A[i * numVars + i];
x[i] += (1 - omega) * before;

if (std::abs(x[i] - before) >= 0.001)
converge = false;
}

if (converge)
break;
}
}

0 comments on commit 3f80b2b

Please sign in to comment.