Skip to content
Snippets Groups Projects
Commit 90ffe5c0 authored by Elias Pipping's avatar Elias Pipping
Browse files

Tests: Clean up output and add benchmarking

parent 6fa42ab1
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@
#include <iostream>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/timer.hh>
#include <dune/solvers/solvers/loopsolver.hh>
#include <dune/solvers/iterationsteps/blockgssteps.hh>
......@@ -22,10 +23,11 @@ public:
{}
bool
analyse(typename Problem::Vector const &candidate, std::string testCase) {
analyse(typename Problem::Vector const &candidate,
SolverResult solverResult, double t, std::string testCase) {
const auto twoNormDiff = p_.twoNorm.diff(p_.u_ex, candidate);
std::cout << "Defect two norm |u-u_n| for solver \"" << testCase
<< "\": " << twoNormDiff << std::endl;
printf("%f | %3zu | %11g | %11g | %s\n", t, solverResult.iterations,
solverResult.conv_rate, twoNormDiff, testCase.c_str());
if (twoNormDiff > tolerance_) {
std::cerr << "### Error too large for solver \"" << testCase << "\"."
<< std::endl;
......@@ -59,84 +61,90 @@ struct CGTestSuite
SymmetricSampleProblem<1, typename GridType::LevelGridView>;
Problem p(grid.levelGridView(grid.maxLevel()));
const auto verbosity = Solver::REDUCED;
const auto verbosity = Solver::QUIET;
const bool relativeErrors = false;
Analyser<Problem> analyser(p, solveTol);
// Test that ignoreNodes are honoured.
{
std::string const testCase = "Dune::Solvers::CGStep ";
typename Problem::Vector u_copy = p.u;
for (size_t i = 0; i < p.u.size(); ++i)
if (p.ignore[i].any())
u_copy[i] += 1.0;
typename Problem::Vector rhs_copy = p.rhs;
Dune::Solvers::CGStep<typename Problem::Matrix,
typename Problem::Vector> cgStep(p.A, u_copy,
rhs_copy);
typename Problem::Vector>
cgStep(p.A, u_copy, rhs_copy);
cgStep.setIgnore(p.ignore);
::LoopSolver<typename Problem::Vector> solver(
&cgStep, maxIterations, stepTol, &p.twoNorm, verbosity,
&cgStep, maxIterations, stepTol, &p.twoNorm, Solver::QUIET,
relativeErrors);
solver.check();
solver.preprocess();
solver.solve();
passed &= analyser.analyse(u_copy, testCase);
for (size_t i = 0; i < p.u.size(); ++i)
if (p.ignore[i].any())
if (std::abs(u_copy[i] - 1.0 - p.u_ex[i]) > solveTol) {
std::cerr << "### error: ignoredNodes not respected!"
<< std::endl;
passed = false;
break;
}
}
// Test if we get the right solution and benchmark
Analyser<Problem> analyser(p, solveTol);
Dune::Timer timer;
printf("time [s] | #it | conv. rate | abs. error | preconditioner\n");
{
std::string const testCase = "Dune::Solvers::CGStep, preconditioned";
std::string const testCase = "none";
typename Problem::Vector u_copy = p.u;
typename Problem::Vector rhs_copy = p.rhs;
auto blockgs =
Dune::Solvers::BlockGSStepFactory<typename Problem::Matrix,
typename Problem::Vector>::
create(Dune::Solvers::BlockGS::LocalSolvers::gs(),
Dune::Solvers::BlockGS::Direction::SYMMETRIC);
Dune::Solvers::CGStep<typename Problem::Matrix,
typename Problem::Vector> cgStep(p.A, u_copy,
rhs_copy,
blockgs);
rhs_copy);
cgStep.setIgnore(p.ignore);
::LoopSolver<typename Problem::Vector> solver(
&cgStep, maxIterations, stepTol, &p.twoNorm, verbosity,
relativeErrors);
solver.check();
timer.reset();
solver.preprocess();
solver.solve();
passed &= analyser.analyse(u_copy, testCase);
passed &= analyser.analyse(u_copy, solver.getResult(),
timer.elapsed(), testCase);
}
// Test that ignoreNodes are honoured.
{
std::string const testCase = "BlockGS";
typename Problem::Vector u_copy = p.u;
for (size_t i = 0; i < p.u.size(); ++i)
if (p.ignore[i].any())
u_copy[i] += 1.0;
typename Problem::Vector rhs_copy = p.rhs;
auto blockgs =
Dune::Solvers::BlockGSStepFactory<typename Problem::Matrix,
typename Problem::Vector>::
create(Dune::Solvers::BlockGS::LocalSolvers::gs(),
Dune::Solvers::BlockGS::Direction::SYMMETRIC);
Dune::Solvers::CGStep<typename Problem::Matrix,
typename Problem::Vector>
cgStep(p.A, u_copy, rhs_copy);
typename Problem::Vector> cgStep(p.A, u_copy,
rhs_copy,
blockgs);
cgStep.setIgnore(p.ignore);
::LoopSolver<typename Problem::Vector> solver(
&cgStep, maxIterations, stepTol, &p.twoNorm, Solver::QUIET,
&cgStep, maxIterations, stepTol, &p.twoNorm, verbosity,
relativeErrors);
solver.check();
timer.reset();
solver.preprocess();
solver.solve();
for (size_t i = 0; i < p.u.size(); ++i)
if (p.ignore[i].any())
if (std::abs(u_copy[i] - 1.0 - p.u_ex[i]) > solveTol) {
std::cerr << "### error: ignoredNodes not respected!"
<< std::endl;
passed = false;
break;
}
passed &= analyser.analyse(u_copy, solver.getResult(),
timer.elapsed(), testCase);
}
return passed;
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment