Debian Codegraph @

dune/istl/paamg/construction.hh

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 #ifndef DUNE_AMGCONSTRUCTION_HH
6 #define DUNE_AMGCONSTRUCTION_HH
7
8 #include <dune/istl/bvector.hh>
9 #include <dune/istl/operators.hh>
10 #include <dune/istl/owneroverlapcopy.hh>
11 #include <dune/istl/solvercategory.hh>
12 #include "pinfo.hh"
13
14 namespace Dune
15 {
16 namespace Amg
17 {
18
19 /**
20 * @addtogroup ISTL_PAAMG
21 *
22 * @{
23 */
24
25 /** @file
26 * @author Markus Blatt
27 * @brief Helper classes for the construction of classes without
28 * empty constructor.
29 */
30 /**
31 * @brief Traits class for generically constructing non default
32 * constructable types.
33 *
34 * Needed because BCRSMatrix and Vector do a deep copy which is
35 * too expensive.
36 */
37 template<typename T>
38 struct ConstructionTraits
39 {
40 /**
41 * @brief A type holding all the arguments needed to call the
42 * constructor.
43 */
44 typedef const void* Arguments;
45
46 /**
47 * @brief Construct an object with the specified arguments.
48 *
49 * In the default implementation the copy constructor is called.
50 * @param args The arguments for the construction.
51 */
52 static inline std::shared_ptr<T> construct(Arguments& /*args*/)
53 {
54 return std::make_shared<T>();
55 }
56 };
57
58 template<class T, class A>
59 struct ConstructionTraits<BlockVector<T,A> >
60 {
61 typedef const int Arguments;
62 static inline std::shared_ptr<BlockVector<T,A>> construct(Arguments& n)
63 {
64 return std::make_shared<BlockVector<T,A>>(n);
65 }
66 };
67
68 template<class M, class C>
69 struct ParallelOperatorArgs
70 {
71 ParallelOperatorArgs(std::shared_ptr<M> matrix, const C& comm)
72 : matrix_(matrix), comm_(comm)
73 {}
74
75 std::shared_ptr<M> matrix_;
76 const C& comm_;
77 };
78
79 #if HAVE_MPI
80 struct OwnerOverlapCopyCommunicationArgs
81 {
82 OwnerOverlapCopyCommunicationArgs(MPI_Comm comm, SolverCategory::Category cat)
83 : comm_(comm), cat_(cat)
84 {}
85
86 MPI_Comm comm_;
87 SolverCategory::Category cat_;
88 };
89 #endif
90
91 struct SequentialCommunicationArgs
92 {
93 SequentialCommunicationArgs(Communication<void*> comm, [[maybe_unused]] int cat)
94 : comm_(comm)
95 {}
96
97 Communication<void*> comm_;
98 };
99
100 } // end Amg namspace
101
102 // forward declaration
103 template<class M, class X, class Y, class C>
104 class OverlappingSchwarzOperator;
105
106 template<class M, class X, class Y, class C>
107 class NonoverlappingSchwarzOperator;
108
109 namespace Amg
110 {
111 template<class M, class X, class Y, class C>
112 struct ConstructionTraits<OverlappingSchwarzOperator<M,X,Y,C> >
113 {
114 typedef ParallelOperatorArgs<M,C> Arguments;
115
116 static inline std::shared_ptr<OverlappingSchwarzOperator<M,X,Y,C>> construct(const Arguments& args)
117 {
118 return std::make_shared<OverlappingSchwarzOperator<M,X,Y,C>>
119 (args.matrix_, args.comm_);
120 }
121 };
122
123 template<class M, class X, class Y, class C>
124 struct ConstructionTraits<NonoverlappingSchwarzOperator<M,X,Y,C> >
125 {
126 typedef ParallelOperatorArgs<M,C> Arguments;
127
128 static inline std::shared_ptr<NonoverlappingSchwarzOperator<M,X,Y,C>> construct(const Arguments& args)
129 {
130 return std::make_shared<NonoverlappingSchwarzOperator<M,X,Y,C>>
131 (args.matrix_, args.comm_);
132 }
133 };
134
135 template<class M, class X, class Y>
136 struct MatrixAdapterArgs
137 {
138 MatrixAdapterArgs(std::shared_ptr<M> matrix, const SequentialInformation)
139 : matrix_(matrix)
140 {}
141
142 std::shared_ptr<M> matrix_;
143 };
144
145 template<class M, class X, class Y>
146 struct ConstructionTraits<MatrixAdapter<M,X,Y> >
147 {
148 typedef const MatrixAdapterArgs<M,X,Y> Arguments;
149
150 static inline std::shared_ptr<MatrixAdapter<M,X,Y>> construct(Arguments& args)
151 {
152 return std::make_shared<MatrixAdapter<M,X,Y>>(args.matrix_);
153 }
154 };
155
156 template<>
157 struct ConstructionTraits<SequentialInformation>
158 {
159 typedef const SequentialCommunicationArgs Arguments;
160 static inline std::shared_ptr<SequentialInformation> construct(Arguments& args)
161 {
162 return std::make_shared<SequentialInformation>(args.comm_);
163 }
164 };
165
166
167 #if HAVE_MPI
168
169 template<class T1, class T2>
170 struct ConstructionTraits<OwnerOverlapCopyCommunication<T1,T2> >
171 {
172 typedef const OwnerOverlapCopyCommunicationArgs Arguments;
173
174 static inline std::shared_ptr<OwnerOverlapCopyCommunication<T1,T2>> construct(Arguments& args)
175 {
176 return std::make_shared<OwnerOverlapCopyCommunication<T1,T2>>(args.comm_, args.cat_);
177 }
178 };
179
180 #endif
181
182 /** @} */
183 } // namespace Amg
184 } // namespace Dune
185 #endif