Debian Codegraph @

dune/istl/paamg/test/hierarchytest.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 <dune/common/parallel/mpihelper.hh>
7 #include <dune/common/parallel/mpicommunication.hh>
8 #include <dune/istl/paamg/matrixhierarchy.hh>
9 #include <dune/istl/paamg/smoother.hh>
10 #include <dune/istl/preconditioners.hh>
11 #include <dune/istl/owneroverlapcopy.hh>
12 #include <dune/istl/schwarz.hh>
13 #include "anisotropic.hh"
14
15 template<int blockSize>
16 void testHierarchy(int N)
17 {
18 typedef int LocalId;
19 typedef int GlobalId;
20 typedef Dune::OwnerOverlapCopyCommunication<LocalId,GlobalId> Communication;
21 typedef Communication::ParallelIndexSet ParallelIndexSet;
22 typedef Dune::FieldMatrix<double,blockSize,blockSize> MatrixBlock;
23 typedef Dune::BCRSMatrix<MatrixBlock> BCRSMat;
24 typedef Dune::FieldVector<double,blockSize> VectorBlock;
25 typedef Dune::BlockVector<VectorBlock> Vector;
26
27 int n;
28 Communication pinfo(Dune::MPIHelper::getCommunicator());
29 ParallelIndexSet& indices = pinfo.indexSet();
30
31 typedef Dune::RemoteIndices<ParallelIndexSet> RemoteIndices;
32 RemoteIndices& remoteIndices = pinfo.remoteIndices();
33
34 BCRSMat mat = setupAnisotropic2d<MatrixBlock>(N, indices, Dune::MPIHelper::getCommunication(), &n);
35 Vector b(indices.size());
36
37 remoteIndices.rebuild<false>();
38
39 typedef Dune::NegateSet<Communication::OwnerSet> OverlapFlags;
40 typedef Dune::OverlappingSchwarzOperator<BCRSMat,Vector,Vector,Communication> Operator;
41 typedef Dune::Amg::MatrixHierarchy<Operator,Communication> Hierarchy;
42 typedef Dune::Amg::Hierarchy<Vector> VHierarchy;
43
44 Operator op(mat, pinfo);
45 Hierarchy hierarchy(
46 Dune::stackobject_to_shared_ptr(op),
47 Dune::stackobject_to_shared_ptr(pinfo));
48 VHierarchy vh(
49 Dune::stackobject_to_shared_ptr(b));
50
51 typedef Dune::Amg::CoarsenCriterion<Dune::Amg::SymmetricCriterion<BCRSMat,Dune::Amg::FirstDiagonal> >
52 Criterion;
53
54 Criterion criterion(100,4);
55 Dune::Timer timer;
56
57 hierarchy.template build<OverlapFlags>(criterion);
58 hierarchy.coarsenVector(vh);
59
60 std::cout<<"Building hierarchy took "<<timer.elapsed()<<std::endl;
61
62 std::cout<<"=== Vector hierarchy has "<<vh.levels()<<" levels! ==="<<std::endl;
63 timer.reset();
64
65 hierarchy.recalculateGalerkin(OverlapFlags());
66
67 std::cout<<"Recalculation took "<<timer.elapsed()<<std::endl;
68 std::vector<std::size_t> data;
69
70 hierarchy.getCoarsestAggregatesOnFinest(data);
71 }
72
73
74 int main(int argc, char** argv)
75 {
76 Dune::MPIHelper::instance(argc, argv);
77
78 constexpr int blockSize = 1;
79 int N=10;
80
81 if(argc>1)
82 N = atoi(argv[1]);
83
84 testHierarchy<blockSize>(N);
85 }