// 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 #include #include #include #include #include #include #include "anisotropic.hh" template void testCoarsenIndices(int N) { int procs, rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &procs); typedef Dune::OwnerOverlapCopyCommunication ParallelInformation; typedef typename ParallelInformation::ParallelIndexSet ParallelIndexSet; typedef typename ParallelInformation::RemoteIndices RemoteIndices; typedef Dune::FieldMatrix Block; typedef Dune::BCRSMatrix BCRSMat; int n; ParallelInformation pinfo(MPI_COMM_WORLD); ParallelIndexSet& indices = pinfo.indexSet(); RemoteIndices& remoteIndices = pinfo.remoteIndices(); typedef Dune::Communication Comm; Comm cc(MPI_COMM_WORLD); BCRSMat mat = setupAnisotropic2d(N, indices, cc, &n); pinfo.remoteIndices().template rebuild(); typedef Dune::Amg::MatrixGraph MatrixGraph; typedef Dune::Amg::SubGraph,std::vector > SubGraph; typedef Dune::Amg::PropertiesGraph PropertiesGraph; typedef typename PropertiesGraph::VertexDescriptor Vertex; typedef Dune::Amg::SymmetricCriterion Criterion; MatrixGraph mg(mat); std::vector excluded(mat.N()); typedef ParallelIndexSet::iterator IndexIterator; IndexIterator iend = indices.end(); typename std::vector::iterator iter=excluded.begin(); for(IndexIterator index = indices.begin(); index != iend; ++index, ++iter) *iter = (index->local().attribute()==GridAttributes::copy); SubGraph sg(mg, excluded); PropertiesGraph pg(sg, Dune::IdentityMap(), sg.getEdgeIndexMap()); Dune::Amg::AggregatesMap aggregatesMap(pg.noVertices()); std::cout << "fine indices: "<::Type visitedMap = Dune::get(Dune::Amg::VertexVisitedTag(), pg); pinfo.buildGlobalLookup(aggregatesMap.noVertices()); int noCoarseVertices = Dune::Amg::IndicesCoarsener >::coarsen(pinfo, pg, visitedMap, aggregatesMap, coarseInfo, noAggregates); coarseInfo.buildGlobalLookup(noCoarseVertices); std::cout << rank <<": coarse indices: " <(), Dune::EnumItem()); Communicator communicator; typedef Dune::Amg::GlobalAggregatesMap GlobalMap; GlobalMap gmap(aggregatesMap, coarseInfo.globalLookup()); communicator.build(interface); Dune::Amg::printAggregates2d(aggregatesMap, n, N, std::cout); communicator.template forward >(gmap); std::cout<<"Communicated: "; Dune::Amg::printAggregates2d(aggregatesMap, n, N, std::cout); Dune::Amg::GalerkinProduct productBuilder; typedef Dune::IteratorPropertyMap VisitedMap2; /* Vector visited; visited.reserve(mg.maxVertex()); Iterator visitedIterator=visited.begin(); */ std::cout<()); delete[] visitedIterator; pinfo.freeGlobalLookup(); productBuilder.calculate(mat, aggregatesMap, *coarseMat, coarseInfo, Dune::EnumItem()); if(N<5) { Dune::printmatrix(std::cout,mat,"fine","row",9,1); Dune::printmatrix(std::cout,*coarseMat,"coarse","row",9,1); } } int main(int argc, char **argv) { MPI_Init(&argc, &argv); int N=5; if(argc>1) N = atoi(argv[1]); std::cout << "Galerkin test with N=" << N << std::endl; testCoarsenIndices<1>(N); MPI_Finalize(); }