KASKADE 7 development version
add.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2022-2022 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef ADD_HH
14#define ADD_HH
15
16#include <cassert>
17#include <vector>
18
20#include "mg/bddc.hh"
21#include "utilities/timing.hh"
22
29{
42 template <class Index>
43 std::vector<std::vector<Index>> algebraicDomainDecomposition(NumaCRSPattern<Index> const& A, int n);
44
45 template <class Scalar, class Index>
46 std::vector<NumaBCRSMatrix<Dune::FieldMatrix<Scalar,1,1>,Index>>
48 std::vector<std::vector<Index>> const& subIndices,
49 Scalar tolerance, int maxIter);
50
51
62 template <class Scalar, int m, class Index>
63 std::tuple< std::vector<NumaBCRSMatrix<Dune::FieldMatrix<Scalar,m,m>,Index>>,
64 std::vector<Dune::BlockVector<Dune::FieldVector<Scalar,m>>>,
65 std::vector<std::vector<Index>>,
66 std::vector<std::vector<LocalDof>> >
69 Scalar tolerance=1000*std::numeric_limits<Scalar>::epsilon(),
70 int maxIter=100)
71 {
74
75 ScopedTimingSection tsec("matrixDomainDecomposition");
76
77 auto& timer = tsec.timer();
78 timer.start("partitioning");
79 assert(n >= 1);
80 assert(A.N() == A.M());
81 auto subIndices = algebraicDomainDecomposition(*A.getPattern(),n);
82 timer.stop("partitioning");
83
84 timer.start("rhs decomposition");
85 std::vector<std::vector<LocalDof>> localDofs(A.N());
86 for (int k=0; k<n; ++k)
87 for (int iloc=0; iloc<subIndices[k].size(); ++iloc)
88 {
89 Index iglob = subIndices[k][iloc];
90 localDofs[iglob].push_back({k,iloc});
91 }
92 timer.stop("rhs decomposition");
93
94 std::vector<Matrix> As;
95 if constexpr (m==1)
96 As = algebraicMatrixDecomposition(A,subIndices,tolerance,maxIter);
97 else
98 assert("needs to be implemented"==0);
99
100 std::vector<Vector> Fs(n);
101 for (int k=0; k<n; ++k)
102 {
103 Fs[k].resize(subIndices[k].size());
104 for (Index i=0; i<subIndices[k].size(); ++i)
105 {
106 Index iglob = subIndices[k][i];
107 int nsub = localDofs[iglob].size();
108 Fs[k][i] = f[iglob] / nsub;
109 }
110 }
111
112 // Finally remove the interior dofs belonging to only one subdomain - they're of no
113 // further interest.
114 localDofs.erase(std::remove_if(begin(localDofs),end(localDofs),
115 [](auto const& lds) { return lds.size() <= 1; }),
116 end(localDofs));
117
118 return std::tuple(As,Fs,subIndices,localDofs);
119 }
120
121}
122
123#endif
Basic components for (potentially distributed) Balanced Domain Decomposition with Constraints precond...
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
A NUMA-aware compressed row storage sparsity pattern.
A scope guard object that automatically closes a timing section on destruction.
Definition: timing.hh:181
Timings & timer()
Returns the used timer.
struct Times const * start(std::string const &name)
Starts or continues the timing of given section.
std::tuple< std::vector< NumaBCRSMatrix< Dune::FieldMatrix< Scalar, m, m >, Index > >, std::vector< Dune::BlockVector< Dune::FieldVector< Scalar, m > > >, std::vector< std::vector< Index > >, std::vector< std::vector< LocalDof > > > matrixDomainDecommposition(NumaBCRSMatrix< Dune::FieldMatrix< Scalar, m, m >, Index > const &A, Dune::BlockVector< Dune::FieldVector< Scalar, m > > const &f, int n, Scalar tolerance=1000 *std::numeric_limits< Scalar >::epsilon(), int maxIter=100)
Definition: add.hh:67
std::vector< std::vector< Index > > algebraicDomainDecomposition(NumaCRSPattern< Index > const &A, int n)
Creates a decomposition of indices into overlapping subsets that can be used for constructing nonover...
std::vector< NumaBCRSMatrix< Dune::FieldMatrix< Scalar, 1, 1 >, Index > > algebraicMatrixDecomposition(NumaBCRSMatrix< Dune::FieldMatrix< Scalar, 1, 1 >, Index > const &A, std::vector< std::vector< Index > > const &subIndices, Scalar tolerance, int maxIter)
Dune::FieldVector< Scalar, dim > Vector