Debian Codegraph @

dune/istl/paamg/test/pamgmmtest.cc

raw
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5
6 #include <memory>
7 #include <dune/common/parallel/mpihelper.hh>
8
9 #include <dune/istl/bcrsmatrix.hh>
10 #include <dune/istl/owneroverlapcopy.hh>
11 #include <dune/istl/matrixmarket.hh>
12 #include <dune/istl/matrixredistribute.hh>
13 #include <dune/istl/repartition.hh>
14 #include <dune/istl/paamg/amg.hh>
15
16 typedef double RT;
17
18 using namespace Dune;
19
20 typedef BCRSMatrix<FieldMatrix<RT,1,1>> BCRSMat;
21 typedef std::size_t GlobalId;
22 typedef OwnerOverlapCopyCommunication<GlobalId> Comm;
23 typedef RedistributeInformation<Comm> RedistInfo;
24
25 std::string matrixfile = "gr_30_30";
26
27 void loadMatrix(std::shared_ptr<BCRSMat>& pA){
28 pA = std::make_shared<BCRSMat>();
29 if(MPIHelper::getCommunication().rank() == 0){
30 Dune::loadMatrixMarket(*pA, matrixfile);
31 }
32 }
33
34 std::shared_ptr<Comm> repartMatrix(const std::shared_ptr<BCRSMat>& pA_orig, std::shared_ptr<BCRSMat>& pA, MPI_Comm comm, int size){
35 typedef typename Dune::Amg::MatrixGraph<BCRSMat> MatrixGraph;
36 RedistInfo ri;
37 std::shared_ptr<Comm> pComm;
38 Comm oocomm(comm);
39 Dune::graphRepartition(MatrixGraph(*pA_orig), oocomm,
40 size,
41 pComm, ri.getInterface(), 1);
42 ri.setSetup();
43 pA = std::make_shared<BCRSMat>();
44 redistributeMatrix(*pA_orig, *pA, oocomm, *pComm, ri);
45 return pComm;
46 }
47
48
49 int main(int argc, char** argv){
50 auto& mpihelper = MPIHelper::instance(argc, argv);
51 auto world = mpihelper.getCommunication();
52
53 int size = mpihelper.size();
54 int rank = mpihelper.rank();
55 std::shared_ptr<BCRSMat> mat, mat_reparted;
56 loadMatrix(mat);
57 std::shared_ptr<Comm> comm = repartMatrix(mat, mat_reparted, world, size);
58 typedef FieldVector<RT,1> VectorBlock;
59 typedef BlockVector<VectorBlock> Vector;
60 typedef OverlappingSchwarzOperator<BCRSMat, Vector, Vector, Comm> Operator;
61 std::shared_ptr<Operator> op = std::make_shared<Operator>(*mat_reparted, *comm);
62 typedef Amg::CoarsenCriterion<Amg::SymmetricCriterion<BCRSMat,Amg::FirstDiagonal> >
63 Criterion;
64 Criterion criterion(15,200);
65 typedef SeqSSOR<BCRSMat, Vector, Vector> Smoother;
66 typedef BlockPreconditioner<Vector, Vector, Comm, Smoother> ParSmoother;
67 typedef typename Amg::SmootherTraits<ParSmoother>::Arguments SmootherArgs;
68 SmootherArgs smootherArgs;
69 smootherArgs.iterations = 1;
70 Amg::AMG<Operator, Vector, ParSmoother, Comm> prec(*op, criterion, smootherArgs, *comm);
71 OverlappingSchwarzScalarProduct<Vector, Comm> sp(*comm);
72 CGSolver<Vector> solver(*op, sp, prec, 1e-5, 300, rank==0);
73 Vector x(mat_reparted->M()), b(mat_reparted->N());
74 x = 1.0;
75 op->apply(x, b);
76 x = 0.0;
77 InverseOperatorResult res;
78 solver.apply(x, b, res);
79
80 return 0;
81 }