// 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: #ifdef TEST_AGGLO #define UNKNOWNS 10 #endif #include "anisotropic.hh" #include #include #include #include #include #include #include #include template class DoubleStepPreconditioner : public Dune::Preconditioner { public: typedef typename T::domain_type X; typedef typename T::range_type Y; enum {category = T::category}; DoubleStepPreconditioner(T& preconditioner_, C& comm) : preconditioner(&preconditioner_), comm_(comm) {} virtual void pre (X& x, Y& b) { preconditioner->pre(x,b); } virtual void apply(X& v, const Y& d) { preconditioner->apply(v,d); comm_.copyOwnerToAll(v,v); } virtual void post (X& x) { preconditioner->post(x); } private: T* preconditioner; C& comm_; }; class MPIError { public: /** @brief Constructor. */ MPIError(std::string s, int e) : errorstring(s), errorcode(e){} /** @brief The error string. */ std::string errorstring; /** @brief The mpi error code. */ int errorcode; }; void MPI_err_handler([[maybe_unused]] MPI_Comm *comm, int *err_code, ...) { char *err_string=new char[MPI_MAX_ERROR_STRING]; int err_length; MPI_Error_string(*err_code, err_string, &err_length); std::string s(err_string, err_length); std::cerr << "An MPI Error occurred:"< void testAmg(int N, int coarsenTarget) { std::cout<<"==================================================="< > Criterion; typedef Dune::SeqSSOR Smoother; //typedef Dune::SeqJac Smoother; //typedef Dune::SeqILU0 Smoother; //typedef Dune::SeqILUn Smoother; typedef Dune::BlockPreconditioner ParSmoother; typedef typename Dune::Amg::SmootherTraits::Arguments SmootherArgs; Dune::OverlappingSchwarzScalarProduct sp(comm); Dune::InverseOperatorResult r, r1; double buildtime; SmootherArgs smootherArgs; smootherArgs.iterations = 1; Criterion criterion(15,coarsenTarget); criterion.setDefaultValuesIsotropic(2); typedef Dune::Amg::AMG AMG; AMG amg(fop, criterion, smootherArgs, comm); buildtime = watch.elapsed(); if(rank==0) std::cout<<"Building hierarchy took "< amgCG(fop, sp, amg, 10e-8, 300, (rank==0) ? 2 : 0); watch.reset(); amgCG.apply(x,b,r); amg.recalculateHierarchy(); MPI_Barrier(MPI_COMM_WORLD); double solvetime = watch.elapsed(); b=0; x=100; setBoundary(x, b, N, comm.indexSet()); Dune::CGSolver amgCG1(fop, sp, amg, 10e-8, 300, (rank==0) ? 2 : 0); amgCG1.apply(x,b,r); if(!r.converged && rank==0) std::cerr<<" AMG Cg solver did not converge!"< struct AMGTester { static void test(int N, int coarsenTarget) { testAmg(N, coarsenTarget); const int next = (BSStart+BSStep>BSEnd) ? BSEnd : BSStart+BSStep; AMGTester::test(N, coarsenTarget); } } ; template struct AMGTester { static void test(int N, int coarsenTarget) { testAmg(N, coarsenTarget); } }; int main(int argc, char** argv) { MPI_Init(&argc, &argv); MPI_Errhandler handler; MPI_Comm_create_errhandler(MPI_err_handler, &handler); MPI_Comm_set_errhandler(MPI_COMM_WORLD, handler); int N=100; int coarsenTarget=200; if(argc>1) N = atoi(argv[1]); if(argc>2) coarsenTarget = atoi(argv[2]); #ifdef TEST_AGGLO N=UNKNOWNS; #endif AMGTester<1,1>::test(N, coarsenTarget); //AMGTester<1,5>::test(N, coarsenTarget); // AMGTester<10,10>::test(N, coarsenTarget); MPI_Finalize(); }