// 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 #include typedef double RT; using namespace Dune; typedef BCRSMatrix> BCRSMat; typedef std::size_t GlobalId; typedef OwnerOverlapCopyCommunication Comm; typedef RedistributeInformation RedistInfo; std::string matrixfile = "gr_30_30"; void loadMatrix(std::shared_ptr& pA){ pA = std::make_shared(); if(MPIHelper::getCommunication().rank() == 0){ Dune::loadMatrixMarket(*pA, matrixfile); } } std::shared_ptr repartMatrix(const std::shared_ptr& pA_orig, std::shared_ptr& pA, MPI_Comm comm, int size){ typedef typename Dune::Amg::MatrixGraph MatrixGraph; RedistInfo ri; std::shared_ptr pComm; Comm oocomm(comm); Dune::graphRepartition(MatrixGraph(*pA_orig), oocomm, size, pComm, ri.getInterface(), 1); ri.setSetup(); pA = std::make_shared(); redistributeMatrix(*pA_orig, *pA, oocomm, *pComm, ri); return pComm; } int main(int argc, char** argv){ auto& mpihelper = MPIHelper::instance(argc, argv); auto world = mpihelper.getCommunication(); int size = mpihelper.size(); int rank = mpihelper.rank(); std::shared_ptr mat, mat_reparted; loadMatrix(mat); std::shared_ptr comm = repartMatrix(mat, mat_reparted, world, size); typedef FieldVector VectorBlock; typedef BlockVector Vector; typedef OverlappingSchwarzOperator Operator; std::shared_ptr op = std::make_shared(*mat_reparted, *comm); typedef Amg::CoarsenCriterion > Criterion; Criterion criterion(15,200); typedef SeqSSOR Smoother; typedef BlockPreconditioner ParSmoother; typedef typename Amg::SmootherTraits::Arguments SmootherArgs; SmootherArgs smootherArgs; smootherArgs.iterations = 1; Amg::AMG prec(*op, criterion, smootherArgs, *comm); OverlappingSchwarzScalarProduct sp(*comm); CGSolver solver(*op, sp, prec, 1e-5, 300, rank==0); Vector x(mat_reparted->M()), b(mat_reparted->N()); x = 1.0; op->apply(x, b); x = 0.0; InverseOperatorResult res; solver.apply(x, b, res); return 0; }