Line data Source code
1 : /*
2 : * Copyright (c) 2011-2018: 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 : // extern headers
34 : #include <iostream>
35 : #include <sstream>
36 : #include <string>
37 :
38 :
39 : // include bridge
40 : #include "bridge/bridge.h"
41 : #include "bridge/util.h"
42 : #include "bridge/util_domain_algebra_dependent.h"
43 :
44 : // lib_disc includes
45 : #include "lib_disc/function_spaces/grid_function.h"
46 : #include "lib_disc/function_spaces/approximation_space.h"
47 :
48 : #include "lib_disc/operator/linear_operator/std_injection.h"
49 : #include "lib_disc/operator/linear_operator/average_component.h"
50 : #include "lib_disc/operator/linear_operator/std_transfer.h"
51 : #include "lib_disc/operator/linear_operator/multi_grid_solver/mg_solver.h"
52 : #include "lib_disc/operator/linear_operator/element_gauss_seidel/element_gauss_seidel.h"
53 : #include "lib_disc/operator/linear_operator/element_gauss_seidel/component_gauss_seidel.h"
54 : #include "lib_disc/operator/linear_operator/subspace_correction/sequential_subspace_correction.h"
55 : #include "lib_disc/operator/linear_operator/uzawa/uzawa.h"
56 :
57 : using namespace std;
58 :
59 : namespace ug{
60 : namespace bridge{
61 : namespace MultiGrid{
62 :
63 : /**
64 : * \defgroup multigrid_bridge Multi Grid Bridge
65 : * \ingroup disc_bridge
66 : * \{
67 : */
68 :
69 : /**
70 : * Class exporting the functionality. All functionality that is to
71 : * be used in scripts or visualization must be registered here.
72 : */
73 : struct Functionality
74 : {
75 :
76 : /**
77 : * Function called for the registration of Domain and Algebra dependent parts.
78 : * All Functions and Classes depending on both Domain and Algebra
79 : * are to be placed here when registering. The method is called for all
80 : * available Domain and Algebra types, based on the current build options.
81 : *
82 : * @param reg registry
83 : * @param parentGroup group for sorting of functionality
84 : */
85 : template <typename TDomain, typename TAlgebra>
86 9 : static void DomainAlgebra(Registry& reg, string grp)
87 : {
88 : string suffix = GetDomainAlgebraSuffix<TDomain,TAlgebra>();
89 : string tag = GetDomainAlgebraTag<TDomain,TAlgebra>();
90 :
91 : // typedef
92 : typedef typename TAlgebra::vector_type vector_type;
93 : typedef ApproximationSpace<TDomain> approximation_space_type;
94 :
95 9 : grp.append("/MultiGrid");
96 :
97 :
98 : // ITransferOperator
99 : {
100 : typedef ITransferOperator<TDomain, TAlgebra> T;
101 9 : string name = string("ITransferOperator").append(suffix);
102 27 : reg.add_class_<T>(name, grp);
103 27 : reg.add_class_to_group(name, "ITransferOperator", tag);
104 : }
105 :
106 : // ITransferPostProcess
107 : {
108 : typedef ITransferPostProcess<TDomain, TAlgebra> T;
109 9 : string name = string("ITransferPostProcess").append(suffix);
110 27 : reg.add_class_<T>(name, grp);
111 27 : reg.add_class_to_group(name, "ITransferPostProcess", tag);
112 : }
113 :
114 : // Standard Transfer
115 : {
116 : typedef StdTransfer<TDomain, TAlgebra> T;
117 : typedef ITransferOperator<TDomain, TAlgebra> TBase;
118 : typedef typename T::GF GF;
119 9 : string name = string("StdTransfer").append(suffix);
120 27 : reg.add_class_<T, TBase>(name, grp)
121 9 : .add_constructor()
122 27 : .add_method("set_restriction_damping", &T::set_restriction_damping)
123 36 : .add_method("set_prolongation_damping", &T::set_prolongation_damping)
124 36 : .add_method("add_constraint", &T::add_constraint)
125 36 : .add_method("set_debug", &T::set_debug)
126 36 : .add_method("set_use_transposed", &T::set_use_transposed)
127 36 : .add_method("enable_p1_lagrange_optimization", &T::enable_p1_lagrange_optimization)
128 36 : .add_method("p1_lagrange_optimization_enabled", &T::p1_lagrange_optimization_enabled)
129 27 : .add_method("prolongate", static_cast<void (T::*) (GF&, const GF&)> (&T::prolongate))
130 18 : .add_method("do_restrict", static_cast<void (T::*) (GF&, const GF&)> (&T::do_restrict))
131 9 : .set_construct_as_smart_pointer(true);
132 27 : reg.add_class_to_group(name, "StdTransfer", tag);
133 : }
134 :
135 : // Standard Injection
136 : {
137 : typedef StdInjection<TDomain, TAlgebra> T;
138 : typedef ITransferOperator<TDomain, TAlgebra> TBase;
139 9 : string name = string("StdInjection").append(suffix);
140 27 : reg.add_class_<T, TBase>(name, grp)
141 9 : .add_constructor()
142 27 : .add_method("init", &T::init)
143 36 : .add_method("do_restrict", &T::do_restrict)
144 27 : .template add_constructor<void (*)(SmartPtr<approximation_space_type>)>("Approximation Space")
145 9 : .set_construct_as_smart_pointer(true);
146 27 : reg.add_class_to_group(name, "StdInjection", tag);
147 : }
148 :
149 : // Average Transfer Post Process
150 : {
151 : typedef AverageComponent<TDomain, TAlgebra> T;
152 : typedef ITransferPostProcess<TDomain, TAlgebra> TBase;
153 9 : string name = string("AverageComponent").append(suffix);
154 27 : reg.add_class_<T, TBase>(name, grp)
155 18 : .template add_constructor<void (*)(const std::string&)>("Components")
156 18 : .template add_constructor<void (*)(const std::vector<std::string>&)>("Components")
157 9 : .set_construct_as_smart_pointer(true);
158 27 : reg.add_class_to_group(name, "AverageComponent", tag);
159 : }
160 :
161 : // MGStats
162 : {
163 : typedef MGStats<TDomain, TAlgebra> T;
164 9 : string name = string("MGStats").append(suffix);
165 27 : reg.add_class_<T>(name, grp)
166 9 : .add_constructor()
167 27 : .add_method("set_exit_on_error", &T::set_exit_on_error, "", "exitOnError")
168 36 : .add_method("set_write_err_vecs", &T::set_write_err_vecs, "", "writeErrVecs")
169 36 : .add_method("set_write_err_diffs", &T::set_write_err_diffs, "", "writeErrDiffs")
170 36 : .add_method("set_filename_prefix", &T::set_filename_prefix, "", "filename")
171 36 : .add_method("set_active_stages", &T::set_active_stages, "", "activeStages")
172 27 : .add_method("save_stats_to_file",
173 : static_cast<void (T::*)()>(&T::save_stats_to_file), "", "")
174 18 : .add_method("save_stats_to_file",
175 : static_cast<void (T::*)(const char*)>(&T::save_stats_to_file),
176 : "", "filename")
177 27 : .add_method("print", &T::print, "", "")
178 27 : .add_method("clear", &T::clear, "", "")
179 9 : .set_construct_as_smart_pointer(true);
180 27 : reg.add_class_to_group(name, "MGStats", tag);
181 : }
182 :
183 : // AssembledMultiGridCycle
184 : {
185 : typedef AssembledMultiGridCycle<TDomain, TAlgebra> T;
186 : typedef ILinearIterator<vector_type> TBase;
187 9 : string name = string("GeometricMultiGrid").append(suffix);
188 27 : reg.add_class_<T, TBase>(name, grp)
189 18 : .template add_constructor<void (*)(SmartPtr<ApproximationSpace<TDomain> >)>("Approximation Space")
190 18 : .template add_constructor<void (*)()>()
191 27 : .add_method("set_mg_stats", &T::set_mg_stats, "", "MGStats")
192 36 : .add_method("set_approximation_space", &T::set_approximation_space, "", "Approximation space")
193 36 : .add_method("set_discretization", &T::set_discretization, "", "Discretization")
194 36 : .add_method("set_base_level", &T::set_base_level, "", "Base Level")
195 36 : .add_method("set_surface_level", &T::set_surface_level, "", "Surface Level")
196 36 : .add_method("set_gathered_base_solver_if_ambiguous", &T::set_gathered_base_solver_if_ambiguous,"", "Specifies if gathered base solver used in case of Ambiguity")
197 36 : .add_method("set_base_solver", &T::set_base_solver,"","Base Solver")
198 36 : .add_method("set_smoother", &T::set_smoother,"", "Smoother")
199 36 : .add_method("set_presmoother", &T::set_presmoother,"", "Smoother")
200 36 : .add_method("set_postsmoother", &T::set_postsmoother,"", "Smoother")
201 27 : .add_method("set_cycle_type", static_cast<void (T::*)(int)>(&T::set_cycle_type),"", "Cycle Type")
202 18 : .add_method("set_cycle_type", static_cast<void (T::*)(const std::string&)>(&T::set_cycle_type),"", "Cycle Type")
203 27 : .add_method("set_num_presmooth", &T::set_num_presmooth,"", "Number PreSmooth Steps")
204 36 : .add_method("set_num_postsmooth", &T::set_num_postsmooth,"", "Number PostSmooth Steps")
205 36 : .add_method("set_transfer", &T::set_transfer,"", "Transfer")
206 36 : .add_method("set_prolongation", &T::set_prolongation,"", "Prolongation")
207 36 : .add_method("set_restriction", &T::set_restriction,"", "Restriction")
208 36 : .add_method("set_projection", &T::set_projection,"", "Projection")
209 36 : .add_method("clear_transfer_post_process", &T::clear_transfer_post_process,"", "Remove all the Post Process routines")
210 36 : .add_method("add_prolongation_post_process", &T::add_prolongation_post_process,"", "Prolongation Post Process")
211 36 : .add_method("add_restriction_post_process", &T::add_restriction_post_process,"", "Restriction Post Process")
212 36 : .add_method("set_debug", &T::set_debug)
213 36 : .add_method("set_emulate_full_refined_grid", &T::set_emulate_full_refined_grid)
214 36 : .add_method("set_rap", &T::set_rap)
215 36 : .add_method("set_smooth_on_surface_rim", &T::set_smooth_on_surface_rim)
216 36 : .add_method("set_comm_comp_overlap", &T::set_comm_comp_overlap)
217 27 : .add_method("ignore_init_for_base_solver", static_cast<void (T::*)(bool)>(&T::ignore_init_for_base_solver), "", "ignore")
218 18 : .add_method("ignore_init_for_base_solver", static_cast<bool (T::*)() const>(&T::ignore_init_for_base_solver), "is ignored", "")
219 27 : .add_method("set_matrix_structure_is_const", &T::set_matrix_structure_is_const)
220 27 : .add_method("force_reinit", &T::force_reinit)
221 9 : .set_construct_as_smart_pointer(true);
222 27 : reg.add_class_to_group(name, "GeometricMultiGrid", tag);
223 : }
224 :
225 : // ElementGaussSeidel
226 : {
227 : typedef ElementGaussSeidel<TDomain, TAlgebra> T;
228 : typedef IPreconditioner<TAlgebra> TBase;
229 9 : string name = string("ElementGaussSeidel").append(suffix);
230 27 : reg.add_class_<T,TBase>(name, grp, "Vanka Preconditioner")
231 9 : .add_constructor()
232 18 : .template add_constructor<void (*)(number)>("relax")
233 18 : .template add_constructor<void (*)(const std::string&)>("patch_type")
234 18 : .template add_constructor<void (*)(number, const std::string&)>("relax#patch_type")
235 27 : .add_method("set_relax", &T::set_relax, "", "relax")
236 36 : .add_method("select_schur_cmp", &T::select_schur_cmp, "", "")
237 27 : .add_method("set_elim_offdiag", &T::set_elim_offdiag, "", "")
238 9 : .set_construct_as_smart_pointer(true);
239 27 : reg.add_class_to_group(name, "ElementGaussSeidel", tag);
240 : }
241 :
242 : // ComponentGaussSeidel
243 : {
244 : typedef ComponentGaussSeidel<TDomain, TAlgebra> T;
245 : typedef IPreconditioner<TAlgebra> TBase;
246 9 : string name = string("ComponentGaussSeidel").append(suffix);
247 27 : reg.add_class_<T,TBase>(name, grp, "Vanka Preconditioner")
248 18 : .template add_constructor<void (*)(const std::vector<std::string>&)>("Cmps")
249 18 : .template add_constructor<void (*)(number, const std::vector<std::string>&)>("relax#Cmps")
250 18 : .template add_constructor<void (*)(number, const std::vector<std::string>&, const std::vector<int>&, const std::vector<number>&)>("relax#Cmps")
251 27 : .add_method("set_alpha", &T::set_alpha, "", "alpha")
252 36 : .add_method("set_beta", &T::set_beta, "", "beta")
253 27 : .add_method("set_weights", &T::set_weights, "", "weights")
254 9 : .set_construct_as_smart_pointer(true);
255 27 : reg.add_class_to_group(name, "ComponentGaussSeidel", tag);
256 : }
257 :
258 : // SequentialSubspaceCorrection
259 : {
260 : typedef SequentialSubspaceCorrection<TDomain, TAlgebra> T;
261 : typedef IPreconditioner<TAlgebra> TBase;
262 9 : string name = string("SequentialSubspaceCorrection").append(suffix);
263 27 : reg.add_class_<T,TBase>(name, grp, "Sequential subspace correction")
264 18 : .template add_constructor<void (*)(number)>("omega")
265 18 : .add_method("set_vertex_subspace", &T::set_vertex_subspace, "", "subspace")
266 9 : .set_construct_as_smart_pointer(true);
267 27 : reg.add_class_to_group(name, "SequentialSubspaceCorrection", tag);
268 : }
269 :
270 :
271 : // ILocalSubspace (i.e. base class for any 'subspace' in subspace correction methods)
272 : {
273 : typedef ILocalSubspace<TDomain, TAlgebra,Vertex> TVertexSubspace;
274 9 : string name = string("ILocalSubspace").append(suffix);
275 27 : reg.add_class_<TVertexSubspace>(name, grp, "ILocalSubspace base");
276 27 : reg.add_class_to_group(name, "ILocalSubspace", tag);
277 :
278 : // VertexCenteredVankaSubspace
279 : {
280 : typedef VertexCenteredVankaSubspace<TDomain, TAlgebra> T;
281 : // typedef IPreconditioner<TAlgebra> TBase;
282 9 : string name = string("VertexCenteredVankaSubspace").append(suffix);
283 27 : reg.add_class_<T,TVertexSubspace>(name, grp, "Vertex centered Vanka")
284 18 : .template add_constructor<void (*)(const std::vector<std::string>&, const std::vector<std::string>&)>("primary functions, secondary functions")
285 9 : .set_construct_as_smart_pointer(true);
286 27 : reg.add_class_to_group(name, "VertexCenteredVankaSubspace", tag);
287 : }
288 : }
289 :
290 : // Uzawa (smoother/iteration)
291 : {
292 : typedef UzawaBase<TDomain, TAlgebra> T;
293 : typedef ILinearIterator<typename TAlgebra::vector_type> TBase;
294 : typedef DebugWritingObject<TAlgebra> TBase2;
295 9 : string name = string("UzawaBase").append(suffix);
296 :
297 27 : reg.add_class_<T, TBase, TBase2>(name, grp)
298 18 : .ADD_CONSTRUCTOR( (const std::vector<std::string>&) ) ("String IDs for Schur complement")
299 18 : .ADD_CONSTRUCTOR( (const char *) ) ("String ID for Schur")
300 27 : .add_method("set_forward_iter", &T::set_forward_iter, "forward iteration", "beta")
301 36 : .add_method("set_schur_iter", &T::set_schur_iter, "Schur iteration", "beta")
302 36 : .add_method("set_backward_iter", &T::set_backward_iter, "backward iteration", "beta")
303 27 : .add_method("set_schur_operator_update", &T::set_schur_operator_update, "update for Schur", "beta")
304 9 : .set_construct_as_smart_pointer(true);
305 :
306 27 : reg.add_class_to_group(name, "UzawaBase", tag);
307 : }
308 :
309 :
310 9 : }
311 :
312 : };
313 :
314 : // end group multigrid_bridge
315 : /// \}
316 :
317 : }// namespace MultiGrid
318 :
319 : /// \addtogroup multigrid_bridge
320 1 : void RegisterBridge_MultiGrid(Registry& reg, string grp)
321 : {
322 1 : grp.append("/Discretization");
323 : typedef MultiGrid::Functionality Functionality;
324 :
325 : try{
326 1 : RegisterDomainAlgebraDependent<Functionality>(reg,grp);
327 : }
328 0 : UG_REGISTRY_CATCH_THROW(grp);
329 1 : }
330 :
331 : }// end of namespace ug
332 : }// end of namespace interface
|