// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: /*#include"xreal.h" namespace std { HPA::xreal abs(const HPA::xreal& t) { return t>=0?t:-t; } }; */ #include "anisotropic.hh" #include #include #include #include #include #include #include #include #include typedef double XREAL; // typedef std::complex XREAL; /* typedef HPA::xreal XREAL; namespace Dune { template<> struct DoubleConverter { static double toDouble(const HPA::xreal& t) { return t._2double(); } }; } */ namespace Dune { using Mat = BCRSMatrix>; using Vec = BlockVector>; using LinOp = MatrixAdapter; using Comm = Amg::SequentialInformation; // explicit template instantiation of FastAMG preconditioner template class Amg::AMG, Comm>; template class Amg::AMG, Comm>; template class Amg::AMG, Comm>; template class Amg::AMG, Comm>; } // end namespace Dune template void randomize(const M& mat, V& b) { V x=b; srand((unsigned)std::clock()); typedef typename V::iterator iterator; for(iterator i=x.begin(); i != x.end(); ++i) *i=(rand() / (RAND_MAX + 1.0)); mat.mv(static_cast(x), b); } template Dune::InverseOperatorResult testAMG(int N, int coarsenTarget, int ml, int gamma = 1) { std::cout<<"N="<::real_type>::value, Dune::Amg::FirstDiagonal, Dune::Amg::RowSum >::type Norm; typedef Dune::Amg::CoarsenCriterion > Criterion; typedef Dune::SeqSSOR Smoother; //typedef Dune::SeqSOR Smoother; //typedef Dune::SeqJac Smoother; //typedef Dune::SeqOverlappingSchwarz Smoother; //typedef Dune::SeqOverlappingSchwarz Smoother; //typedef Dune::SeqOverlappingSchwarz Smoother; typedef typename Dune::Amg::SmootherTraits::Arguments SmootherArgs; SmootherArgs smootherArgs; smootherArgs.iterations = 1; //smootherArgs.overlap=SmootherArgs::vertex; //smootherArgs.overlap=SmootherArgs::none; //smootherArgs.overlap=SmootherArgs::aggregate; smootherArgs.relaxationFactor = 1; Criterion criterion(15,coarsenTarget); criterion.setDefaultValuesIsotropic(2); criterion.setAlpha(.67); criterion.setBeta(1.0e-4); criterion.setGamma(gamma); criterion.setMaxLevel(ml); criterion.setSkipIsolated(false); // specify pre/post smoother steps criterion.setNoPreSmoothSteps(1); criterion.setNoPostSmoothSteps(1); Dune::SeqScalarProduct sp; typedef Dune::Amg::AMG AMG; Smoother smoother(mat,1,1); AMG amg(fop, criterion, smootherArgs); double buildtime = watch.elapsed(); std::cout<<"Building hierarchy took "< amgCG(fop,amg,1e-6,80,2); //Dune::LoopSolver amgCG(fop, amg, 1e-4, 10000, 2); watch.reset(); Dune::InverseOperatorResult r; amgCG.apply(x,b,r); XREAL solvetime = watch.elapsed(); std::cout<<"AMG solving took "<1) N = atoi(argv[1]); if(argc>2) coarsenTarget = atoi(argv[2]); if(argc>3) ml = atoi(argv[3]); Dune::InverseOperatorResult gamma1_res; for(int gamma = 1; gamma<=2;++gamma){ { using Matrix = Dune::BCRSMatrix; using Vector = Dune::BlockVector; Dune::InverseOperatorResult res = testAMG(N, coarsenTarget, ml, gamma); if(gamma==1){ gamma1_res = res; }else{ assert(res.conv_rate < gamma1_res.conv_rate); } } } { using Matrix = Dune::BCRSMatrix >; using Vector = Dune::BlockVector >; testAMG(N, coarsenTarget, ml); } { using Matrix = Dune::BCRSMatrix >; using Vector = Dune::BlockVector >; testAMG(N, coarsenTarget, ml); } return 0; } catch (std::exception &e) { std::cout << "ERROR: " << e.what() << std::endl; return 1; } catch (...) { std::cerr << "Dune reported an unknown error." << std::endl; exit(1); }