MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_FacadeBGS2x2_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef PACKAGES_MUELU_SRC_INTERFACE_FACADECLASSES_BGS2x2_DEF_HPP_
11 #define PACKAGES_MUELU_SRC_INTERFACE_FACADECLASSES_BGS2x2_DEF_HPP_
12 
15 
16 #include "MueLu_Exceptions.hpp"
17 
19 
20 namespace MueLu {
21 
22 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
24 }
25 
26 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
28  // obtain ParameterList with default input parameters for this facade class
29  // Note all parameters are of type string (we use it for string replacement)
30  std::string defaultString =
31  "<ParameterList name=\"Input\">"
32  "<Parameter name=\"MueLu preconditioner\" type=\"string\" value=\"undefined\"/>"
33  "<Parameter name=\"Block 1: dofs per node\" type=\"int\" value=\"1\"/>"
34  "<Parameter name=\"Block 2: dofs per node\" type=\"int\" value=\"1\"/>"
35  "<Parameter name=\"Block 1: smoother\" type=\"string\" value=\"Symmetric Gauss-Seidel\"/>"
36  "<Parameter name=\"Block 1: level-of-fill\" type=\"int\" value=\"0\"/>"
37  "<Parameter name=\"Block 1: relaxation: sweeps\" type=\"int\" value=\"1\"/>"
38  "<Parameter name=\"Block 1: relaxation: damping factor\" type=\"double\" value=\"1.0\"/>"
39  "<Parameter name=\"Block 1: transfer smoothing\" type=\"bool\" value=\"true\"/>"
40  "<Parameter name=\"Block 2: smoother\" type=\"string\" value=\"Symmetric Gauss-Seidel\"/>"
41  "<Parameter name=\"Block 2: level-of-fill\" type=\"int\" value=\"0\"/>"
42  "<Parameter name=\"Block 2: relaxation: sweeps\" type=\"int\" value=\"1\"/>"
43  "<Parameter name=\"Block 2: relaxation: damping factor\" type=\"double\" value=\"1.0\"/>"
44  "<Parameter name=\"Block 2: transfer smoothing\" type=\"bool\" value=\"true\"/>"
45  "<Parameter name=\"BGS: damping factor\" type=\"double\" value=\"1.0\"/>"
46  "<Parameter name=\"max levels\" type=\"int\" value=\"5\"/>"
47  "<Parameter name=\"coarse: max size\" type=\"int\" value=\"25000\"/>"
48  "<Parameter name=\"verbosity\" type=\"string\" value=\"High\"/>"
49  "</ParameterList>";
50  Teuchos::RCP<ParameterList> defaultList = Teuchos::getParametersFromXmlString(defaultString);
51  // validate user input parameters (and set defaults if necessary)
52  Teuchos::ParameterList inputParameters = paramList;
53  inputParameters.validateParametersAndSetDefaults(*defaultList);
54  TEUCHOS_TEST_FOR_EXCEPTION(inputParameters.get<std::string>("MueLu preconditioner") == "undefined", MueLu::Exceptions::RuntimeError, "FacadeBGS2x2: undefined MueLu preconditioner. Set the \"MueLu preconditioner\" parameter correctly in your input file.");
55 
56  // create copy of template string which is updated with in-place string replacements
57  // template string for preconditioner layout (factory based parameters)
58  std::string finalString =
59 
60  "<ParameterList name=\"MueLu\">"
61  " <ParameterList name=\"Factories\">"
62  " <ParameterList name=\"mySubBlockAFactory1\">"
63  " <Parameter name=\"factory\" type=\"string\" value=\"SubBlockAFactory\"/>"
64  " <Parameter name=\"block row\" type=\"int\" value=\"0\"/>"
65  " <Parameter name=\"block col\" type=\"int\" value=\"0\"/>"
66  " <Parameter name=\"Range map: Striding info\" type=\"string\" value=\"{ XXXBlock 1: dofs per nodeYYY }\"/>"
67  " <Parameter name=\"Domain map: Striding info\" type=\"string\" value=\"{ XXXBlock 1: dofs per nodeYYY }\"/>"
68  " </ParameterList>"
69  ""
70  " <ParameterList name=\"myAggFact1\">"
71  " <Parameter name=\"factory\" type=\"string\" value=\"UncoupledAggregationFactory\"/>"
72  " <Parameter name=\"aggregation: min agg size\" type=\"int\" value=\"5\"/>"
73  " <Parameter name=\"aggregation: max selected neighbors\" type=\"int\" value=\"1\"/>"
74  " </ParameterList>"
75  ""
76  " <!-- tell the tentative prolongator that we have 2 DOFs per node on the coarse levels -->"
77  " <ParameterList name=\"myCoarseMap1\">"
78  " <Parameter name=\"factory\" type=\"string\" value=\"CoarseMapFactory\"/>"
79  " <Parameter name=\"Striding info\" type=\"string\" value=\"{ XXXBlock 1: dofs per nodeYYY }\"/>"
80  " <Parameter name=\"Strided block id\" type=\"int\" value=\"-1\"/>"
81  " </ParameterList>"
82  ""
83  " <ParameterList name=\"myTentativePFact1\">"
84  " <Parameter name=\"factory\" type=\"string\" value=\"TentativePFactory\"/>"
85  " <Parameter name=\"A\" type=\"string\" value=\"mySubBlockAFactory1\"/>"
86  " <Parameter name=\"Aggregates\" type=\"string\" value=\"myAggFact1\"/>"
87  " <Parameter name=\"CoarseMap\" type=\"string\" value=\"myCoarseMap1\"/>"
88  " </ParameterList>"
89  ""
90  " <ParameterList name=\"myPFact1\">"
91  " <Parameter name=\"factory\" type=\"string\" value=\"PgPFactory\"/>"
92  " <Parameter name=\"A\" type=\"string\" value=\"mySubBlockAFactory1\"/>"
93  " <Parameter name=\"P\" type=\"string\" value=\"myTentativePFact1\"/>"
94  " </ParameterList>"
95  ""
96  " <ParameterList name=\"myRFact1\">"
97  " <Parameter name=\"factory\" type=\"string\" value=\"GenericRFactory\"/>"
98  " <Parameter name=\"P\" type=\"string\" value=\"myPFact1\"/>"
99  " </ParameterList>"
100  ""
101  " <!-- We have to use Nullspace1 here. If \"Nullspace1\" is not set the"
102  " Factory creates the default null space containing of constant"
103  " vectors -->"
104  " <ParameterList name=\"myNspFact1\">"
105  " <Parameter name=\"factory\" type=\"string\" value=\"NullspaceFactory\"/>"
106  " <Parameter name=\"Fine level nullspace\" type=\"string\" value=\"Nullspace1\"/>"
107  " <Parameter name=\"Nullspace1\" type=\"string\" value=\"myTentativePFact1\"/>"
108  " </ParameterList>"
109  ""
110  " <!-- BLOCK 2 (for submatrix A_{11}) PRESSURE PART -->"
111  " <ParameterList name=\"mySubBlockAFactory2\">"
112  " <Parameter name=\"factory\" type=\"string\" value=\"SubBlockAFactory\"/>"
113  " <Parameter name=\"block row\" type=\"int\" value=\"1\"/>"
114  " <Parameter name=\"block col\" type=\"int\" value=\"1\"/>"
115  " <Parameter name=\"Range map: Striding info\" type=\"string\" value=\"{ XXXBlock 2: dofs per nodeYYY }\"/>"
116  " <Parameter name=\"Domain map: Striding info\" type=\"string\" value=\"{ XXXBlock 2: dofs per nodeYYY }\"/>"
117  " </ParameterList>"
118  ""
119  " <!-- tell the tentative prolongator that we have 2 DOFs per node on the coarse levels -->"
120  " <ParameterList name=\"myCoarseMap2\">"
121  " <Parameter name=\"factory\" type=\"string\" value=\"CoarseMapFactory\"/>"
122  " <Parameter name=\"Striding info\" type=\"string\" value=\"{ XXXBlock 2: dofs per nodeYYY }\"/>"
123  " <Parameter name=\"Strided block id\" type=\"int\" value=\"-1\"/>"
124  " </ParameterList>"
125  ""
126  " <ParameterList name=\"myTentativePFact2\">"
127  " <Parameter name=\"factory\" type=\"string\" value=\"TentativePFactory\"/>"
128  " <Parameter name=\"A\" type=\"string\" value=\"mySubBlockAFactory2\"/>"
129  " <Parameter name=\"Aggregates\" type=\"string\" value=\"myAggFact1\"/>"
130  " <Parameter name=\"CoarseMap\" type=\"string\" value=\"myCoarseMap2\"/>"
131  " </ParameterList>"
132  ""
133  " <ParameterList name=\"myPFact2\">"
134  " <Parameter name=\"factory\" type=\"string\" value=\"SaPFactory\"/>"
135  " <Parameter name=\"A\" type=\"string\" value=\"mySubBlockAFactory2\"/>"
136  " <Parameter name=\"P\" type=\"string\" value=\"myTentativePFact2\"/>"
137  " </ParameterList>"
138  ""
139  " <ParameterList name=\"myRFact2\">"
140  " <Parameter name=\"factory\" type=\"string\" value=\"TransPFactory\"/>"
141  " <Parameter name=\"P\" type=\"string\" value=\"myPFact2\"/>"
142  " </ParameterList>"
143  ""
144  " <ParameterList name=\"myNspFact2\">"
145  " <Parameter name=\"factory\" type=\"string\" value=\"NullspaceFactory\"/>"
146  " <Parameter name=\"Fine level nullspace\" type=\"string\" value=\"Nullspace2\"/>"
147  " <Parameter name=\"Nullspace2\" type=\"string\" value=\"myTentativePFact2\"/>"
148  " </ParameterList>"
149  ""
150  " <!-- FACTORY MANAGERS -->"
151  ""
152  " <!-- Multigrid setup for velocity block (A_{00}) -->"
153  " <ParameterList name=\"myFirstGroup\">"
154  " <Parameter name=\"group\" type=\"string\" value=\"FactoryManager\"/>"
155  " <Parameter name=\"A\" type=\"string\" value=\"mySubBlockAFactory1\"/>"
156  " <Parameter name=\"P\" type=\"string\" value=\"myPFact1\"/>"
157  " <Parameter name=\"R\" type=\"string\" value=\"myRFact1\"/>"
158  " <Parameter name=\"Aggregates\" type=\"string\" value=\"myAggFact1\"/>"
159  " <Parameter name=\"Nullspace\" type=\"string\" value=\"myNspFact1\"/>"
160  " <Parameter name=\"CoarseMap\" type=\"string\" value=\"myCoarseMap1\"/>"
161  " </ParameterList>"
162  ""
163  " <!-- Multigrid setup for pressure block (A_{11}) -->"
164  " <ParameterList name=\"mySecondGroup\">"
165  " <Parameter name=\"group\" type=\"string\" value=\"FactoryManager\"/>"
166  " <Parameter name=\"A\" type=\"string\" value=\"mySubBlockAFactory2\"/>"
167  " <Parameter name=\"P\" type=\"string\" value=\"myPFact2\"/>"
168  " <Parameter name=\"R\" type=\"string\" value=\"myRFact2\"/>"
169  " <Parameter name=\"Aggregates\" type=\"string\" value=\"myAggFact1\"/><!-- reuse aggs from PRESSURE block! -->"
170  " <Parameter name=\"Nullspace\" type=\"string\" value=\"myNspFact2\"/>"
171  " <Parameter name=\"CoarseMap\" type=\"string\" value=\"myCoarseMap2\"/>"
172  " </ParameterList>"
173  ""
174  " <!-- BLOCK TRANSFER operators -->"
175  ""
176  " <ParameterList name=\"myBlockedPFact\">"
177  " <Parameter name=\"factory\" type=\"string\" value=\"BlockedPFactory\"/>"
178  " <!-- factory manager for block 1 -->"
179  " <ParameterList name=\"block1\">"
180  " <Parameter name=\"group\" type=\"string\" value=\"myFirstGroup\"/>"
181  " </ParameterList>"
182  " <!-- factory manager for block 2 -->"
183  " <ParameterList name=\"block2\">"
184  " <Parameter name=\"group\" type=\"string\" value=\"mySecondGroup\"/>"
185  " </ParameterList>"
186  " </ParameterList>"
187  ""
188  " <ParameterList name=\"myBlockedRFact\">"
189  " <Parameter name=\"factory\" type=\"string\" value=\"GenericRFactory\"/>"
190  " <Parameter name=\"P\" type=\"string\" value=\"myBlockedPFact\"/>"
191  " </ParameterList>"
192  ""
193  " <ParameterList name=\"myBlockedRAPFact\">"
194  " <Parameter name=\"factory\" type=\"string\" value=\"BlockedRAPFactory\"/>"
195  " <Parameter name=\"P\" type=\"string\" value=\"myBlockedPFact\"/>"
196  " <Parameter name=\"R\" type=\"string\" value=\"myBlockedRFact\"/>"
197  " </ParameterList>"
198  ""
199  " <!-- BLOCK SMOOTHERS -->"
200  " <ParameterList name=\"mySmooFact1\">"
201  " <Parameter name=\"factory\" type=\"string\" value=\"TrilinosSmoother\"/>"
202  " <Parameter name=\"type\" type=\"string\" value=\"RELAXATION\"/>"
203  " <ParameterList name=\"ParameterList\">"
204  " <Parameter name=\"relaxation: type\" type=\"string\" value=\"XXXBlock 1: relaxation: typeYYY\"/>"
205  " <Parameter name=\"relaxation: sweeps\" type=\"int\" value=\"XXXBlock 1: relaxation: sweepsYYY\"/>"
206  " <Parameter name=\"relaxation: damping factor\" type=\"double\" value=\"XXXBlock 1: relaxation: damping factorYYY\"/>"
207  " </ParameterList>"
208  " </ParameterList>"
209  ""
210  " <ParameterList name=\"mySmooILUFact1\">"
211  " <Parameter name=\"factory\" type=\"string\" value=\"TrilinosSmoother\"/>"
212  " <Parameter name=\"type\" type=\"string\" value=\"ILU\"/>"
213  " <ParameterList name=\"ParameterList\">"
214  " <Parameter name=\"fact: level-of-fill\" type=\"int\" value=\"XXXBlock 1: level-of-fillYYY\"/>"
215  " </ParameterList>"
216  " </ParameterList>"
217  ""
218  " <ParameterList name=\"mySmooDirectFact1\">"
219  " <Parameter name=\"factory\" type=\"string\" value=\"DirectSolver\"/>"
220  " </ParameterList>"
221  ""
222  " <ParameterList name=\"mySmooFact2\">"
223  " <Parameter name=\"factory\" type=\"string\" value=\"TrilinosSmoother\"/>"
224  " <Parameter name=\"type\" type=\"string\" value=\"RELAXATION\"/>"
225  " <ParameterList name=\"ParameterList\">"
226  " <Parameter name=\"relaxation: type\" type=\"string\" value=\"XXXBlock 2: relaxation: typeYYY\"/>"
227  " <Parameter name=\"relaxation: sweeps\" type=\"int\" value=\"XXXBlock 2: relaxation: sweepsYYY\"/>"
228  " <Parameter name=\"relaxation: damping factor\" type=\"double\" value=\"XXXBlock 2: relaxation: damping factorYYY\"/>"
229  " </ParameterList>"
230  " </ParameterList>"
231  ""
232  " <ParameterList name=\"mySmooILUFact2\">"
233  " <Parameter name=\"factory\" type=\"string\" value=\"TrilinosSmoother\"/>"
234  " <Parameter name=\"type\" type=\"string\" value=\"ILU\"/>"
235  " <ParameterList name=\"ParameterList\">"
236  " <Parameter name=\"fact: level-of-fill\" type=\"int\" value=\"XXXBlock 2: level-of-fillYYY\"/>"
237  " </ParameterList>"
238  " </ParameterList>"
239  ""
240  " <ParameterList name=\"mySmooDirectFact2\">"
241  " <Parameter name=\"factory\" type=\"string\" value=\"DirectSolver\"/>"
242  " </ParameterList>"
243  ""
244  " <ParameterList name=\"myBlockSmoother\">"
245  " <Parameter name=\"factory\" type=\"string\" value=\"BlockedGaussSeidelSmoother\"/>"
246  " <Parameter name=\"Sweeps\" type=\"int\" value=\"1\"/>"
247  " <Parameter name=\"Damping factor\" type=\"double\" value=\"XXXBGS: damping factorYYY\"/>"
248  " <!-- factory manager for block 1 -->"
249  " <ParameterList name=\"block1\">"
250  " <Parameter name=\"A\" type=\"string\" value=\"mySubBlockAFactory1\"/>"
251  " <Parameter name=\"Smoother\" type=\"string\" value=\"XYZSmoother1XYZ\"/>"
252  " </ParameterList>"
253  " <!-- factory manager for block 2 -->"
254  " <ParameterList name=\"block2\">"
255  " <Parameter name=\"A\" type=\"string\" value=\"mySubBlockAFactory2\"/>"
256  " <Parameter name=\"Smoother\" type=\"string\" value=\"XYZSmoother2XYZ\"/>"
257  " </ParameterList>"
258  " </ParameterList>"
259  ""
260  " </ParameterList>"
261  " <!-- end Factories -->"
262  ""
263  " <!-- Definition of the multigrid preconditioner -->"
264  " <ParameterList name=\"Hierarchy\">"
265  ""
266  " <Parameter name=\"max levels\" type=\"int\" value=\"XXXmax levelsYYY\"/>"
267  " <Parameter name=\"coarse: max size\" type=\"int\" value=\"XXXcoarse: max sizeYYY\"/>"
268  " <Parameter name=\"verbosity\" type=\"string\" value=\"XXXverbosityYYY\"/>"
269  ""
270  " <ParameterList name=\"AllLevel\">"
271  " <Parameter name=\"startLevel\" type=\"int\" value=\"0\"/>"
272  " <Parameter name=\"Smoother\" type=\"string\" value=\"myBlockSmoother\"/>"
273  " <Parameter name=\"CoarseSolver\" type=\"string\" value=\"myBlockSmoother\"/>"
274  " <Parameter name=\"P\" type=\"string\" value=\"myBlockedPFact\"/>"
275  " <Parameter name=\"R\" type=\"string\" value=\"myBlockedRFact\"/>"
276  " <Parameter name=\"A\" type=\"string\" value=\"myBlockedRAPFact\"/>"
277  " </ParameterList>"
278  ""
279  " </ParameterList>"
280  "</ParameterList>";
281 
282  // logical code for more complicated distinctions
283 
284  std::string smoother1 = inputParameters.get<std::string>("Block 1: smoother");
285  if (smoother1 == "ILU") {
286  this->ReplaceString(finalString, "XYZSmoother1XYZ", "mySmooILUFact1");
287  } else if (smoother1 == "Symmetric Gauss-Seidel" || smoother1 == "SGS") {
288  this->ReplaceString(finalString, "XXXBlock 1: relaxation: typeYYY", "Symmetric Gauss-Seidel");
289  this->ReplaceString(finalString, "XYZSmoother1XYZ", "mySmooFact1");
290  } else if (smoother1 == "Symmetric Gauss-Seidel" || smoother1 == "GS") {
291  this->ReplaceString(finalString, "XXXBlock 1: relaxation: typeYYY", "Gauss-Seidel");
292  this->ReplaceString(finalString, "XYZSmoother1XYZ", "mySmooFact1");
293  } else if (smoother1 == "Jacobi") {
294  this->ReplaceString(finalString, "XXXBlock 1: relaxation: typeYYY", "Jacobi");
295  this->ReplaceString(finalString, "XYZSmoother1XYZ", "mySmooFact1");
296  } else if (smoother1 == "Direct") {
297  this->ReplaceString(finalString, "XYZSmoother1XYZ", "mySmooDirectFact1");
298  } else {
299  this->GetOStream(Errors) << "Invalid smoother type for block 1: " << smoother1 << ". Valid options are: \"SGS\", \"GS\", \"Jacobi\", \"ILU\" or \"Direct\"." << std::endl;
300  }
301 
302  std::string smoother2 = inputParameters.get<std::string>("Block 2: smoother");
303  if (smoother2 == "ILU") {
304  this->ReplaceString(finalString, "XYZSmoother2XYZ", "mySmooILUFact2");
305  } else if (smoother2 == "Symmetric Gauss-Seidel" || smoother2 == "SGS") {
306  this->ReplaceString(finalString, "XXXBlock 2: relaxation: typeYYY", "Symmetric Gauss-Seidel");
307  this->ReplaceString(finalString, "XYZSmoother2XYZ", "mySmooFact2");
308  } else if (smoother2 == "Symmetric Gauss-Seidel" || smoother2 == "GS") {
309  this->ReplaceString(finalString, "XXXBlock 2: relaxation: typeYYY", "Gauss-Seidel");
310  this->ReplaceString(finalString, "XYZSmoother2XYZ", "mySmooFact2");
311  } else if (smoother2 == "Jacobi") {
312  this->ReplaceString(finalString, "XXXBlock 2: relaxation: typeYYY", "Gauss-Seidel");
313  this->ReplaceString(finalString, "XYZSmoother2XYZ", "mySmooFact2");
314  } else if (smoother2 == "Direct") {
315  this->ReplaceString(finalString, "XYZSmoother2XYZ", "mySmooDirectFact2");
316  } else {
317  this->GetOStream(Errors) << "Invalid smoother type for block 2: " << smoother2 << ". Valid options are: \"SGS\", \"GS\", \"Jacobi\", \"ILU\" or \"Direct\"." << std::endl;
318  }
319 
320  if (inputParameters.get<bool>("Block 1: transfer smoothing") == true) {
321  this->ReplaceString(finalString, "XXXBlock 1: prolongatorYYY", "myPFact1");
322  this->ReplaceString(finalString, "XXXBlock 1: restrictor YYY", "myRFact1");
323  } else {
324  this->ReplaceString(finalString, "XXXBlock 1: prolongatorYYY", "myTentativePFact1");
325  this->ReplaceString(finalString, "XXXBlock 1: restrictor YYY", "myTransPFact1");
326  }
327  if (inputParameters.get<bool>("Block 2: transfer smoothing") == true) {
328  this->ReplaceString(finalString, "XXXBlock 2: prolongatorYYY", "myPFact2");
329  this->ReplaceString(finalString, "XXXBlock 2: restrictor YYY", "myRFact2");
330  } else {
331  this->ReplaceString(finalString, "XXXBlock 2: prolongatorYYY", "myTentativePFact2");
332  this->ReplaceString(finalString, "XXXBlock 2: restrictor YYY", "myTransPFact2");
333  }
334 
335  // end logical code
336 
337  // loop over all input parameters
338  for (Teuchos::ParameterList::ConstIterator it = inputParameters.begin(); it != inputParameters.end(); it++) {
339  // form replacement string
340  std::string par_name = inputParameters.name(it);
341  std::stringstream ss;
342  ss << "XXX" << par_name << "YYY";
343 
344  // update final string with parameters
345  Teuchos::ParameterEntry par_entry = inputParameters.entry(it);
346  this->ReplaceString(finalString,
347  ss.str(), Teuchos::toString(par_entry.getAny()));
348  }
349 
350  Teuchos::RCP<ParameterList> ret = Teuchos::getParametersFromXmlString(finalString);
351  return ret;
352 }
353 
354 } // end namespace MueLu
355 #endif // PACKAGES_MUELU_SRC_INTERFACE_FACADECLASSES_BGS2x2_DEF_HPP_
const std::string & name() const
ConstIterator end() const
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
params_t::ConstIterator ConstIterator
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
ConstIterator begin() const
const ParameterEntry & entry(ConstIterator i) const
any & getAny(bool activeQry=true)
Teuchos::RCP< Teuchos::ParameterList > SetParameterList(const Teuchos::ParameterList &paramList)
Set parameter list for FacadeClass interpreter.
Exception throws to report errors in the internal logical of the program.
std::string toString(const T &t)