Skip to content

Commit

Permalink
[nsd/11arraydesign] Speed up Linf norm calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
yungyuc committed Dec 18, 2022
1 parent 15e9823 commit b9c35ce
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions nsd/11arraydesign/code/solve_cpp_simplearray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ void import_numpy()
}
}

}
} /* end namespace python */

}
} /* end namespace modmesh */

template <typename T>
T calc_norm_amax(modmesh::SimpleArray<T> const & arr0, modmesh::SimpleArray<T> const & arr1)
Expand Down Expand Up @@ -61,15 +61,21 @@ solve1(modmesh::SimpleArray<double> u)
double norm;
while (!converged)
{
norm = 0.0;
++step;
for (size_t it=1; it<nx-1; ++it)
{
for (size_t jt=1; jt<nx-1; ++jt)
{
un(it,jt) = (u(it+1,jt) + u(it-1,jt) + u(it,jt+1) + u(it,jt-1)) / 4;
double const v = std::abs(un(it,jt) - u(it,jt));
if (v > norm)
{
norm = v;
}
}
}
norm = calc_norm_amax(u, un);
// additional loop slows down: norm = calc_norm_amax(u, un);
if (norm < 1.e-5) { converged = true; }
u = un;
}
Expand Down

0 comments on commit b9c35ce

Please sign in to comment.