// 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: // If we test with simd we need to deactivate the direct solver. // In that case we use a define to do this in the next line. @DEFINE_DEACTIVATE_AMG_DIRECTSOLVER@ #include #include #include #include #include #include #include #include #include #include // direct solvers #include #include #include #include #include // preconditioners #include #include // solvers #include #include #include using Vector = Dune::BlockVector<@BLOCK@>; template struct MatrixBlock{ typedef V type; }; template struct MatrixBlock>{ typedef Dune::FieldMatrix,n,n> type; }; using Matrix = Dune::BCRSMatrix::type>; template void testSeq(const Dune::ParameterTree& config, Comm c){ if(c.rank() == 0){ std::set deactivate_solvers; #if !HAVE_SUITESPARSE_CHOLMOD deactivate_solvers.insert("Cholmod"); #endif #if !HAVE_SUITESPARSE_LDL deactivate_solvers.insert("LDL"); #endif #if !HAVE_SUITESPARSE_UMFPACK deactivate_solvers.insert("UMFPack"); #endif #if !HAVE_SUITESPARSE_SPQR deactivate_solvers.insert("SPQR"); #endif #if !HAVE_SUPERLU deactivate_solvers.insert("SuperLU"); #endif Matrix mat; int N = config.get("N", 10); setupLaplacian(mat, N); Vector x(mat.M()), b(mat.N()); using Operator = Dune::MatrixAdapter; std::shared_ptr op = std::make_shared(mat); for(const std::string& test : config.getSubKeys()){ if(deactivate_solvers.find(test) != deactivate_solvers.end()) continue; Dune::ParameterTree solverConfig = config.sub(test); std::cout << " ============== " << test << " ============== " << std::endl; try{ std::shared_ptr> solver = getSolverFromFactory(op, solverConfig); x = 0; b = 1; Dune::InverseOperatorResult res; solver->apply(x,b,res); if(!res.converged) DUNE_THROW(Dune::Exception, test << " not converged!"); }catch(Dune::UnsupportedType& e){ std::cout << e.what() << std::endl; } } } } template void testOverlapping(const Dune::ParameterTree& config, Comm c){ using Communication = Dune::OwnerOverlapCopyCommunication; using Operator = Dune::OverlappingSchwarzOperator; using MatrixBlock = typename Operator::matrix_type::block_type; int N = config.get("N", 100); int n; Communication comm(MPI_COMM_WORLD); Matrix mat =setupAnisotropic2d(N, comm.indexSet(), comm.communicator(), &n, 1); Vector x(mat.M()), b(mat.N()); b=0; x=100; setBoundary(x, b, N, comm.indexSet()); comm.remoteIndices().template rebuild(); std::shared_ptr op = std::make_shared(mat, comm); for(const std::string& test : config.getSubKeys()){ Dune::ParameterTree solverConfig = config.sub(test); std::cout << " ============== " << test << " ============== " << std::endl; try{ std::shared_ptr> solver = getSolverFromFactory(op, solverConfig); x = 0; b = 1; Dune::InverseOperatorResult res; solver->apply(x,b,res); if(!res.converged) DUNE_THROW(Dune::Exception, test << " not converged!"); }catch(Dune::UnsupportedType& e){ std::cout << e.what() << std::endl; } } } template void testNonoverlapping(const Dune::ParameterTree& config, Comm c){ using Communication = Dune::OwnerOverlapCopyCommunication; using Operator = Dune::NonoverlappingSchwarzOperator; using MatrixBlock = typename Operator::matrix_type::block_type; int N = config.get("N", 100); int n; Communication comm(MPI_COMM_WORLD, Dune::SolverCategory::nonoverlapping); /// \todo Make discretization mimic onoverlapping. Matrix mat =setupAnisotropic2d(N, comm.indexSet(), comm.communicator(), &n, 1); Vector x(mat.M()), b(mat.N()); b=0; x=100; setBoundary(x, b, N, comm.indexSet()); comm.remoteIndices().template rebuild(); std::shared_ptr op = std::make_shared(mat, comm); for(const std::string& test : config.getSubKeys()){ Dune::ParameterTree solverConfig = config.sub(test); std::cout << " ============== " << test << " ============== " << std::endl; try{ std::shared_ptr> solver = getSolverFromFactory(op, solverConfig); x = 0; b = 1; Dune::InverseOperatorResult res; solver->apply(x,b,res); if(!res.converged) DUNE_THROW(Dune::Exception, test << " not converged!"); }catch(Dune::UnsupportedType& e){ std::cout << e.what() << std::endl; } } } int main(int argc, char** argv){ auto& mpihelper = Dune::MPIHelper::instance(argc, argv); Dune::ParameterTree config; Dune::ParameterTreeParser::readINITree("solverfactorytest.ini", config); Dune::ParameterTreeParser::readOptions(argc, argv, config); Dune::initSolverFactories>(); using Communication = Dune::OwnerOverlapCopyCommunication; Dune::initSolverFactories>(); Dune::initSolverFactories>(); std::cout << std::endl << " Testing sequential tests... " << std::endl; testSeq(config.sub("sequential"), mpihelper.getCommunication()); std::cout << std::endl << " Testing overlapping tests... " << std::endl; testOverlapping(config.sub("overlapping"), mpihelper.getCommunication()); // Still need to implement proper discretization for non-overlapping // std::cout << std::endl << " Testing nonoverlapping tests... " << std::endl; // testNonoverlapping(config.sub("overlapping"), mpihelper.getCommunication()); return 0; }