// 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 #include #include #include #include #include #include "laplacian.hh" #include #include #include #include #include #include #include template Dune::TestSuite test(int argc, char** argv) { Dune::TestSuite suite; #if HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK int N=4; if(argc>1) N = atoi(argv[1]); std::cout<<"testing for N="< BCRSMat; typedef Dune::BlockVector BVector; typedef Dune::MatrixAdapter Operator; BCRSMat mat; Operator fop(mat); BVector b(N*N), x(N*N); setupLaplacian(mat,N); b=0; x=100; //setBoundary(x,b,N); /* for (BCRSMat::RowIterator row = mat.begin(); row != mat.end(); ++row) (*row)[row.index()]+=row.index(); */ // create the subdomains int domainSize=2; if(argc>2) domainSize = atoi(argv[2]); int overlap = 0; int domainsPerDim=(N+domainSize-1)/domainSize; // set up the overlapping domains typedef Dune::SeqOverlappingSchwarz Schwarz; typedef typename Schwarz::subdomain_vector subdomain_vector; subdomain_vector domains(domainsPerDim*domainsPerDim); // set up the rowToDomain vector typedef typename Schwarz::rowtodomain_vector rowtodomain_vector; rowtodomain_vector rowToDomain(N*N); for(int j=0; j < N; ++j) for(int i=0; i < N; ++i) { int xdomain = i/domainSize; int ydomain = j/domainSize; int mainDomain=ydomain*domainsPerDim+xdomain; int id=j*N+i; domains[mainDomain].insert(id); rowToDomain[id].push_back(mainDomain); // check left domain int domain = (i-overlap)/domainSize; int neighbourDomain=ydomain*domainsPerDim+domain; if(domain>=0 && domain=0 && domain=0 && domain=0 && domain::value_type ::const_iterator entry_iterator; std::cout<<"domain "<begin(); entry != iter->end(); ++entry) { std::cout<<" "<<*entry; } std::cout< > prec0(mat, domains, 1); Dune::LoopSolver solver0(fop, prec0, 1e-2,100,2); solver0.apply(x,b, res); suite.check(res.converged) << "solver0 did not converge"; b=0; x=100; Dune::SeqOverlappingSchwarz > prec1(mat, domains, 1, false); Dune::LoopSolver solver1(fop, prec1, 1e-2,100,2); solver1.apply(x,b, res); suite.check(res.converged) << "solver1 did not converge"; #endif // HAVE_SUITESPARSE_UMFPACK #if HAVE_SUPERLU std::cout << "Do testing with SuperLU" << std::endl; x=100; b=0; Dune::SeqOverlappingSchwarz > slu_prec0(mat, domains, 1); Dune::LoopSolver slu_solver(fop, slu_prec0, 1e-2,100,2); slu_solver.apply(x,b, res); suite.check(res.converged) << "slu_solver did not converge"; x=100; b=0; Dune::SeqOverlappingSchwarz > slu_prec1(mat, domains, 1, false); Dune::LoopSolver slu_solver1(fop, slu_prec1, 1e-2,100,2); slu_solver1.apply(x,b, res); suite.check(res.converged) << "slu_solver1 did not converge"; #endif x=100; b=0; std::cout << "Do testing with DynamicMatrixSubdomainSolver" << std::endl; Dune::SeqOverlappingSchwarz > dyn_prec0(mat, domains, 1); Dune::LoopSolver dyn_solver(fop, dyn_prec0, 1e-2,100,2); dyn_solver.apply(x,b, res); suite.check(res.converged) << "dyn_solver did not converge"; std::cout<<"Additive Schwarz not on the fly (domains vector)"< prec0o(mat, domains, 1, false); Dune::LoopSolver solver0o(fop, prec0o, 1e-2,100,2); solver0o.apply(x,b, res); suite.check(res.converged) << "solver0o did not converge"; std::cout << "Multiplicative Schwarz (domains vector)"< prec1m(mat, domains, 1); Dune::LoopSolver solver1m(fop, prec1m, 1e-2,100,2); solver1m.apply(x,b, res); suite.check(res.converged) << "solver1m did not converge"; std::cout<<"Additive Schwarz (rowToDomain vector)"<begin(); d!=i->end(); ++d) std::cout<<*d<<" "; std::cout< prec2(mat, rowToDomain, 1); Dune::LoopSolver solver2(fop, prec2, 1e-2,100,2); solver2.apply(x,b, res); suite.check(res.converged) << "solver2 did not converge"; std::cout << "Multiplicative Schwarz (rowToDomain vector)"< prec3(mat, rowToDomain, 1); Dune::LoopSolver solver3(fop, prec3, 1e-2,100,2); solver3.apply(x,b, res); suite.check(res.converged) << "solver3 did not converge"; std::cout << "SOR"< sor(mat, 1,1); Dune::LoopSolver solver4(fop, sor, 1e-2,100,2); solver4.apply(x,b, res); suite.check(res.converged) << "solver4 did not converge"; #endif // HAVE_SUPERLU || HAVE_SUITESPARSE_UMFPACK return suite; } int main(int argc, char** argv){ Dune::TestSuite suite; suite.subTest(test, Dune::FieldVector>(argc, argv)); suite.subTest(test(argc, argv)); return suite.exit(); }