Line data Source code
1 : /*
2 : * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 :
34 : // extern headers
35 : #include <iostream>
36 : #include <sstream>
37 : #include <string>
38 :
39 : // include bridge
40 : #include "bridge/bridge.h"
41 : #include "bridge/util.h"
42 : #include "bridge/util_algebra_dependent.h"
43 :
44 : // preconditioner
45 : #include "lib_algebra/lib_algebra.h"
46 : #include "lib_algebra/operator/preconditioner/preconditioners.h"
47 : #include "lib_algebra/operator/preconditioner/ilut_scalar.h"
48 : #include "lib_algebra/operator/linear_solver/agglomerating_solver.h"
49 : #include "lib_algebra/operator/preconditioner/block_gauss_seidel.h"
50 :
51 : #include "lib_algebra/ordering_strategies/algorithms/IOrderingAlgorithm.h"
52 :
53 : #include "../util_overloaded.h"
54 : using namespace std;
55 :
56 : namespace ug{
57 :
58 : namespace bridge{
59 : namespace Preconditioner{
60 :
61 : /**
62 : * \defgroup precond_bridge Preconditioner Bridge
63 : * \ingroup algebra_bridge
64 : * \{
65 : */
66 :
67 : /**
68 : * Class exporting the functionality. All functionality that is to
69 : * be used in scripts or visualization must be registered here.
70 : */
71 :
72 :
73 :
74 : struct Functionality
75 : {
76 :
77 : /*
78 : template <typename TDomain, typename TAlgebra>
79 : static void DomainAlgebra(Registry& reg, string grp)
80 : {
81 : string suffix = GetDomainAlgebraSuffix<TDomain,TAlgebra>();
82 : string tag = GetDomainAlgebraTag<TDomain,TAlgebra>();
83 :
84 : }
85 : */
86 :
87 : template<typename TAlgebra, typename TGSType>
88 21 : static void RegisterBlockGaussSeidel(Registry& reg, string grp, string name)
89 : {
90 21 : string suffix = GetAlgebraSuffix<TAlgebra>();
91 21 : string tag = GetAlgebraTag<TAlgebra>();
92 :
93 : typedef TGSType T;
94 : typedef IPreconditioner<TAlgebra> TBase;
95 : string namesuffix = name+suffix;
96 42 : reg.add_class_<T,TBase>(namesuffix, grp, name)
97 21 : .add_constructor()
98 42 : .ADD_CONSTRUCTOR( (int) )("depth")
99 42 : .add_method("set_depth", &T::set_depth)
100 21 : .set_construct_as_smart_pointer(true);
101 :
102 42 : reg.add_class_to_group(namesuffix, name, tag);
103 21 : }
104 :
105 : template<typename TAlgebra, bool forward, bool backward>
106 9 : static void RegisterBlockGaussSeidelIterative(Registry& reg, string grp, string name)
107 : {
108 9 : string suffix = GetAlgebraSuffix<TAlgebra>();
109 9 : string tag = GetAlgebraTag<TAlgebra>();
110 :
111 : typedef BlockGaussSeidelIterative<TAlgebra, forward, backward> T;
112 : typedef IPreconditioner<TAlgebra> TBase;
113 : string namesuffix = name+suffix;
114 18 : reg.add_class_<T,TBase>(namesuffix, grp, name)
115 9 : .add_constructor()
116 18 : . ADD_CONSTRUCTOR( (int, int) )("depth#steps")
117 27 : .add_method("set_depth", &T::set_depth)
118 27 : .add_method("set_iterative_steps", &T::set_iterative_steps)
119 9 : .set_construct_as_smart_pointer(true);
120 18 : reg.add_class_to_group(namesuffix, name, tag);
121 9 : }
122 :
123 : /**
124 : * Function called for the registration of Algebra dependent parts.
125 : * All Functions and Classes depending on Algebra
126 : * are to be placed here when registering. The method is called for all
127 : * available Algebra types, based on the current build options.
128 : *
129 : * @param reg registry
130 : * @param parentGroup group for sorting of functionality
131 : */
132 : template <typename TAlgebra>
133 3 : static void Algebra(Registry& reg, string grp)
134 : {
135 3 : string suffix = GetAlgebraSuffix<TAlgebra>();
136 3 : string tag = GetAlgebraTag<TAlgebra>();
137 :
138 : // typedefs for this algebra
139 : typedef typename TAlgebra::vector_type vector_type;
140 :
141 :
142 : // Jacobi
143 : {
144 : typedef Jacobi<TAlgebra> T;
145 : typedef IPreconditioner<TAlgebra> TBase;
146 3 : string name = string("Jacobi").append(suffix);
147 9 : reg.add_class_<T,TBase>(name, grp, "Jacobi Preconditioner")
148 3 : .add_constructor()
149 6 : .template add_constructor<void (*)(number)>("DampingFactor")
150 : //.add_method("set_block", &T::set_block, "", "block", "if true, use block smoothing (default), else diagonal smoothing")
151 3 : .set_construct_as_smart_pointer(true);
152 9 : reg.add_class_to_group(name, "Jacobi", tag);
153 : }
154 :
155 : // GaussSeidelBase
156 : {
157 : typedef GaussSeidelBase<TAlgebra> T;
158 : typedef IPreconditioner<TAlgebra> TBase;
159 3 : string name = string("GaussSeidelBase").append(suffix);
160 9 : reg.add_class_<T,TBase>(name, grp, "Gauss-Seidel Base")
161 9 : .add_method("enable_consistent_interfaces", &T::enable_consistent_interfaces, "", "enable", "makes the matrix and defect consistent at the proc. interfaces")
162 12 : .add_method("enable_overlap", &T::enable_overlap, "", "enable", "Enables matrix overlap. This also means that interfaces are consistent.")
163 : //.add_method("set_ordering_algorithm", &T::set_ordering_algorithm, "", "",
164 : // "sets an ordering algorithm")
165 9 : .add_method("set_sor_relax", &T::set_sor_relax,
166 : "", "sor relaxation", "sets sor relaxation parameter");
167 9 : reg.add_class_to_group(name, "GaussSeidelBase", tag);
168 : }
169 :
170 : // GaussSeidel
171 : {
172 : typedef GaussSeidel<TAlgebra> T;
173 : typedef GaussSeidelBase<TAlgebra> TBase;
174 3 : string name = string("GaussSeidel").append(suffix);
175 9 : reg.add_class_<T,TBase>(name, grp, "Gauss-Seidel Preconditioner")
176 3 : .add_constructor()
177 3 : .set_construct_as_smart_pointer(true);
178 9 : reg.add_class_to_group(name, "GaussSeidel", tag);
179 : }
180 :
181 : // Symmetric GaussSeidel
182 : {
183 : typedef SymmetricGaussSeidel<TAlgebra> T;
184 : typedef GaussSeidelBase<TAlgebra> TBase;
185 3 : string name = string("SymmetricGaussSeidel").append(suffix);
186 9 : reg.add_class_<T,TBase>(name, grp, "Symmetric Gauss Seidel Preconditioner")
187 3 : .add_constructor()
188 3 : .set_construct_as_smart_pointer(true);
189 9 : reg.add_class_to_group(name, "SymmetricGaussSeidel", tag);
190 : }
191 :
192 : // Backward GaussSeidel
193 : {
194 : typedef BackwardGaussSeidel<TAlgebra> T;
195 : typedef GaussSeidelBase<TAlgebra> TBase;
196 3 : string name = string("BackwardGaussSeidel").append(suffix);
197 9 : reg.add_class_<T,TBase>(name, grp, "Backward Gauss Seidel Preconditioner")
198 3 : .add_constructor()
199 3 : .set_construct_as_smart_pointer(true);
200 9 : reg.add_class_to_group(name, "BackwardGaussSeidel", tag);
201 : }
202 :
203 : // BlockGaussSeidel
204 : {
205 9 : RegisterBlockGaussSeidel<TAlgebra, BlockGaussSeidel<TAlgebra, true, false> >(reg, grp, "BlockGaussSeidel");
206 9 : RegisterBlockGaussSeidel<TAlgebra, BlockGaussSeidel<TAlgebra, false, true> >(reg, grp, "BackwardBlockGaussSeidel");
207 9 : RegisterBlockGaussSeidel<TAlgebra, BlockGaussSeidel<TAlgebra, true, true> >(reg, grp, "SymmetricBlockGaussSeidel");
208 :
209 9 : RegisterBlockGaussSeidel<TAlgebra, SparseBlockGaussSeidel<TAlgebra, true, false> >(reg, grp, "SparseBlockGaussSeidel");
210 9 : RegisterBlockGaussSeidel<TAlgebra, SparseBlockGaussSeidel2<TAlgebra, true, false> >(reg, grp, "SparseBlockGaussSeidel2");
211 9 : RegisterBlockGaussSeidel<TAlgebra, SparseBlockGaussSeidel<TAlgebra, false, true> >(reg, grp, "SparseBackwardBlockGaussSeidel");
212 9 : RegisterBlockGaussSeidel<TAlgebra, SparseBlockGaussSeidel<TAlgebra, true, true> >(reg, grp, "SparseSymmetricBlockGaussSeidel");
213 :
214 9 : RegisterBlockGaussSeidelIterative<TAlgebra, true, false>(reg, grp, "BlockGaussSeidelIterative");
215 9 : RegisterBlockGaussSeidelIterative<TAlgebra, false, true>(reg, grp, "BackwardBlockGaussSeidelIterative");
216 9 : RegisterBlockGaussSeidelIterative<TAlgebra, true, true>(reg, grp, "SymmetricBlockGaussSeidelIterative");
217 : }
218 :
219 : // ILU
220 : {
221 : typedef ILU<TAlgebra> T;
222 : typedef IPreconditioner<TAlgebra> TBase;
223 3 : string name = string("ILU").append(suffix);
224 9 : reg.add_class_<T,TBase>(name, grp, "Incomplete LU Decomposition")
225 3 : .add_constructor()
226 9 : .add_method("set_beta", &T::set_beta, "", "beta")
227 12 : .add_method("set_sort_eps", &T::set_sort_eps, "", "eps")
228 12 : .add_method("set_inversion_eps", &T::set_inversion_eps, "", "eps")
229 12 : .add_method("set_ordering_algorithm", &T::set_ordering_algorithm, "", "",
230 : "sets an ordering algorithm")
231 12 : .add_method("set_sort", &T::set_sort, "", "bSort", "if bSort=true, use a cuthill-mckey sorting to reduce fill-in. default false")
232 12 : .add_method("set_disable_preprocessing", &T::set_disable_preprocessing, "", "disable",
233 : "set whether preprocessing (notably, LU factorization) is to be disabled - usable when the operator has not changed; use with care")
234 12 : .add_method("enable_consistent_interfaces", &T::enable_consistent_interfaces, "", "enable", "Make Matrix consistent for connections in interfaces.")
235 9 : .add_method("enable_overlap", &T::enable_overlap, "", "enable", "Enables matrix overlap. This also means that interfaces are consistent.")
236 3 : .set_construct_as_smart_pointer(true);
237 9 : reg.add_class_to_group(name, "ILU", tag);
238 : }
239 :
240 : // ILU Threshold
241 : {
242 : typedef ILUTPreconditioner<TAlgebra> T;
243 : typedef IPreconditioner<TAlgebra> TBase;
244 3 : string name = string("ILUT").append(suffix);
245 9 : reg.add_class_<T,TBase>(name, grp, "Incomplete LU Decomposition with threshold")
246 3 : .add_constructor()
247 6 : .template add_constructor<void (*)(number)>("threshold parameter")
248 9 : .add_method("set_threshold", &T::set_threshold,
249 : "", "threshold", "sets threshold of incomplete LU factorisation")
250 12 : .add_method("set_info", &T::set_info,
251 : "", "info", "sets storage information output")
252 12 : .add_method("set_ordering_algorithm", &T::set_ordering_algorithm, "", "",
253 : "sets an ordering algorithm")
254 9 : .add_method("set_sort", &T::set_sort, "", "bSort", "if bSort=true, use a cuthill-mckey sorting to reduce fill-in. default true")
255 3 : .set_construct_as_smart_pointer(true);
256 9 : reg.add_class_to_group(name, "ILUT", tag);
257 : }
258 :
259 : // ILU Threshold Scalar
260 : {
261 : typedef ILUTScalarPreconditioner<TAlgebra> T;
262 : typedef IPreconditioner<TAlgebra> TBase;
263 3 : string name = string("ILUTScalar").append(suffix);
264 9 : reg.add_class_<T,TBase>(name, grp, "Scalar Incomplete LU Decomposition with threshold")
265 3 : .add_constructor()
266 6 : .template add_constructor<void (*)(number)>("threshold parameter")
267 9 : .add_method("set_threshold", &T::set_threshold,
268 : "", "threshold", "sets threshold of incomplete LU factorisation")
269 12 : .add_method("set_info", &T::set_info,
270 : "", "info", "sets storage information output")
271 9 : .add_method("set_sort", &T::set_sort, "", "bSort", "if bSort=true, use a cuthill-mckey sorting to reduce fill-in")
272 3 : .set_construct_as_smart_pointer(true);
273 9 : reg.add_class_to_group(name, "ILUTScalar", tag);
274 : }
275 :
276 : // LinearIteratorProduct
277 : {
278 : typedef LinearIteratorProduct<vector_type, vector_type> T;
279 : typedef ILinearIterator<vector_type> TBase;
280 3 : string name = string("LinearIteratorProduct").append(suffix);
281 9 : reg.add_class_<T,TBase>(name, grp,
282 : "Linear Iterator consisting of several LinearIterations")
283 3 : .add_constructor()
284 6 : .template add_constructor<void (*)(const std::vector<SmartPtr<ILinearIterator<vector_type,vector_type> > >&)>()
285 9 : .add_method("add_iterator",static_cast<void (T::*)(SmartPtr<TBase>)>(&T::add_iterator),
286 : "", "add iterator", "sets iterator")
287 9 : .add_method("add_iterator",static_cast<void (T::*)(SmartPtr<TBase>,size_t nr)>(&T::add_iterator),
288 : "", "add iterator", "sets iterator")
289 3 : .set_construct_as_smart_pointer(true);
290 9 : reg.add_class_to_group(name, "LinearIteratorProduct", tag);
291 : }
292 :
293 : // LinearIteratorSum
294 : {
295 : typedef LinearIteratorSum<vector_type, vector_type> T;
296 : typedef ILinearIterator<vector_type> TBase;
297 3 : string name = string("LinearIteratorSum").append(suffix);
298 9 : reg.add_class_<T,TBase>(name, grp,
299 : "Linear Iterator consisting of several LinearIterations")
300 3 : .add_constructor()
301 6 : .template add_constructor<void (*)(const std::vector<SmartPtr<ILinearIterator<vector_type,vector_type> > >&)>()
302 9 : .add_method("add_iterator",static_cast<void (T::*)(SmartPtr<TBase>)>(&T::add_iterator),
303 : "", "add iterator", "sets iterator")
304 9 : .add_method("add_iterator",static_cast<void (T::*)(SmartPtr<TBase>,size_t nr)>(&T::add_iterator),
305 : "", "add iterator", "sets iterator")
306 3 : .set_construct_as_smart_pointer(true);
307 9 : reg.add_class_to_group(name, "LinearIteratorSum", tag);
308 : }
309 :
310 : // Vanka
311 : {
312 : typedef Vanka<TAlgebra> T;
313 : typedef IPreconditioner<TAlgebra> TBase;
314 3 : string name = string("Vanka").append(suffix);
315 9 : reg.add_class_<T,TBase>(name, grp, "Vanka Preconditioner")
316 3 : .add_constructor()
317 6 : .add_method("set_relax", &T::set_relax, "", "relax")
318 3 : .set_construct_as_smart_pointer(true);
319 9 : reg.add_class_to_group(name, "Vanka", tag);
320 : }
321 :
322 : // Diag Vanka
323 : {
324 : typedef DiagVanka<TAlgebra> T;
325 : typedef IPreconditioner<TAlgebra> TBase;
326 3 : string name = string("DiagVanka").append(suffix);
327 9 : reg.add_class_<T,TBase>(name, grp, "Diagonal Vanka Preconditioner")
328 3 : .add_constructor()
329 6 : .add_method("set_relax", &T::set_relax, "", "relax")
330 3 : .set_construct_as_smart_pointer(true);
331 9 : reg.add_class_to_group(name, "DiagVanka", tag);
332 : }
333 :
334 : // AgglomeratingIterator
335 : {
336 : typedef AgglomeratingIterator<TAlgebra> T;
337 : typedef ILinearIterator<vector_type> TBase;
338 3 : string name = string("AgglomeratingIterator").append(suffix);
339 9 : reg.add_class_<T,TBase>(name, grp, "AgglomeratingIterator")
340 6 : .template add_constructor<void (*)(SmartPtr<ILinearIterator<vector_type> > )>("pLinIterator")
341 3 : .set_construct_as_smart_pointer(true);
342 9 : reg.add_class_to_group(name, "AgglomeratingIterator", tag);
343 : }
344 :
345 : // AgglomeratingPreconditioner
346 : {
347 : typedef AgglomeratingPreconditioner<TAlgebra> T;
348 : typedef IPreconditioner<TAlgebra> TBase;
349 3 : string name = string("AgglomeratingPreconditioner").append(suffix);
350 9 : reg.add_class_<T,TBase>(name, grp, "AgglomeratingPreconditioner")
351 6 : .template add_constructor<void (*)(SmartPtr<ILinearIterator<vector_type> > )>("pPreconditioner")
352 3 : .set_construct_as_smart_pointer(true);
353 9 : reg.add_class_to_group(name, "AgglomeratingPreconditioner", tag);
354 : }
355 :
356 3 : }
357 :
358 :
359 : }; // end Functionality
360 :
361 : // end group precond_bridge
362 : /// \}
363 :
364 : }// end Preconditioner
365 :
366 : /// \addtogroup precond_bridge
367 1 : void RegisterBridge_Preconditioner(Registry& reg, string grp)
368 : {
369 1 : grp.append("/Algebra/Preconditioner");
370 : typedef Preconditioner::Functionality Functionality;
371 :
372 : try{
373 1 : RegisterAlgebraDependent<Functionality>(reg,grp);
374 : }
375 0 : UG_REGISTRY_CATCH_THROW(grp);
376 1 : }
377 :
378 : } // namespace bridge
379 : } // namespace ug
|