source: src/samples/techniques.hpp@ 4571da

Last change on this file since 4571da was 4571da, checked in by Julian Iseringhausen <isering@…>, 14 years ago

vmg: Implement fourth-order discretization of the Poisson equation.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1762 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 15.2 KB
RevLine 
[48b662]1/**
2 * @file techniques.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Apr 18 13:06:42 2011
5 *
6 * @brief Some examples for multigrid methods this library
7 * might be used for.
8 *
9 */
10
11#ifndef TECHNIQUES_HPP_
12#define TECHNIQUES_HPP_
13
14#include <sstream>
15#include <string>
16
17#include "base/command_list.hpp"
18
19namespace VMG
20{
21
22class Techniques
23{
24public:
25 static void SetCorrectionSchemeDirichlet(int minLevel, int maxLevel, int gamma)
26 {
27 CommandList* init = new CommandList();
28 CommandList* loop = new CommandList();
29 CommandList* finalize = new CommandList();
30
31 init->AddCommand("ClearGrid", "RHS");
32 init->AddCommand("ClearGrid", "SOL");
33 init->AddCommand("ImportRightHandSide");
[dfed1c]34 init->AddCommand("ForceDiscreteCompatibility");
[48b662]35 init->AddCommand("CheckConsistency", "RHS");
36 init->AddCommand("CopyBoundary", "RHS:SOL");
[dfed1c]37 init->AddCommand("InitializeIterationCounter");
[48b662]38 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
39
40 loop->AddCommand("ClearCoarseLevels", "RHS");
41 loop->AddCommand("ClearCoarseLevels", "SOL");
42
43 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
44
[dfed1c]45 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
46 loop->AddCommand("CheckResidual", "RESIDUAL");
47 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
[48b662]48 loop->AddCommand("CheckIterationCounter");
49
50 finalize->AddCommand("ExportSolution");
51
52 init->Register("COMMANDLIST_INIT");
53 loop->Register("COMMANDLIST_LOOP");
54 finalize->Register("COMMANDLIST_FINALIZE");
55 }
56
57
58 static void SetCorrectionSchemeDirichletDebug(int minLevel, int maxLevel, int gamma)
59 {
60 CommandList* init = new CommandList();
61 CommandList* loop = new CommandList();
62 CommandList* finalize = new CommandList();
63
64 init->AddCommand("ClearGrid", "RHS");
65 init->AddCommand("ClearGrid", "SOL");
66 init->AddCommand("ImportRightHandSide");
[dfed1c]67 init->AddCommand("ForceDiscreteCompatibility");
[48b662]68 init->AddCommand("CheckConsistency", "RHS");
69 init->AddCommand("CopyBoundary", "RHS:SOL");
[dfed1c]70 init->AddCommand("InitializeIterationCounter");
[48b662]71 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
[dfed1c]72 init->AddCommand("PrintAllSettings");
[48b662]73
74 loop->AddCommand("ClearCoarseLevels", "RHS");
75 loop->AddCommand("ClearCoarseLevels", "SOL");
76
77 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
78
[dfed1c]79 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
80 loop->AddCommand("CheckResidual", "RESIDUAL");
81 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
[48b662]82 loop->AddCommand("CheckIterationCounter");
83
84 finalize->AddCommand("ExportSolution");
85
86 init->Register("COMMANDLIST_INIT");
87 loop->Register("COMMANDLIST_LOOP");
88 finalize->Register("COMMANDLIST_FINALIZE");
89 }
90
91 static void SetCorrectionSchemePeriodic(int minLevel, int maxLevel, int gamma)
92 {
93 CommandList* init = new CommandList();
94 CommandList* loop = new CommandList();
95 CommandList* finalize = new CommandList();
96
97 init->AddCommand("ClearGrid", "RHS");
98 init->AddCommand("ClearGrid", "SOL");
99 init->AddCommand("ImportRightHandSide");
[dfed1c]100 init->AddCommand("ForceDiscreteCompatibility");
[48b662]101 init->AddCommand("CheckConsistency", "RHS");
[dfed1c]102 init->AddCommand("InitializeIterationCounter");
[48b662]103 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
104
105 loop->AddCommand("ClearCoarseLevels", "SOL");
106 loop->AddCommand("ClearCoarseLevels", "RHS");
107
108 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
109
[4571da]110 loop->AddCommand("SetAverageToZero", "SOL");
[dfed1c]111 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
112 loop->AddCommand("CheckResidual", "RESIDUAL");
113 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
[48b662]114 loop->AddCommand("CheckIterationCounter");
115
116 finalize->AddCommand("ExportSolution");
117
118 init->Register("COMMANDLIST_INIT");
119 loop->Register("COMMANDLIST_LOOP");
120 finalize->Register("COMMANDLIST_FINALIZE");
121 }
122
123 static void SetCorrectionSchemePeriodicDebug(int minLevel, int maxLevel, int gamma)
124 {
125 CommandList* init = new CommandList();
126 CommandList* loop = new CommandList();
127 CommandList* finalize = new CommandList();
128
129 init->AddCommand("ClearGrid", "RHS");
130 init->AddCommand("ClearGrid", "SOL");
131 init->AddCommand("ImportRightHandSide");
[dfed1c]132 init->AddCommand("ForceDiscreteCompatibility");
[48b662]133 init->AddCommand("CheckConsistency", "RHS");
[dfed1c]134 init->AddCommand("InitializeIterationCounter");
[48b662]135 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
[dfed1c]136 init->AddCommand("PrintAllSettings");
[48b662]137
138 loop->AddCommand("ClearCoarseLevels", "SOL");
139 loop->AddCommand("ClearCoarseLevels", "RHS");
140
141 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
142
[4571da]143 loop->AddCommand("SetAverageToZero", "SOL");
[dfed1c]144 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
145 loop->AddCommand("CheckResidual", "RESIDUAL");
146 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
[716da7]147 loop->AddCommand("CheckIterationCounter");
148
149 finalize->AddCommand("ExportSolution");
150
151 init->Register("COMMANDLIST_INIT");
152 loop->Register("COMMANDLIST_LOOP");
153 finalize->Register("COMMANDLIST_FINALIZE");
154 }
155
156 static void SetCorrectionSchemePeriodicParticle(int minLevel, int maxLevel, int gamma)
157 {
158 CommandList* init = new CommandList();
159 CommandList* loop = new CommandList();
160 CommandList* finalize = new CommandList();
161
162 init->AddCommand("ClearGrid", "RHS");
163 init->AddCommand("ClearGrid", "SOL");
164 init->AddCommand("ImportRightHandSide");
165 init->AddCommand("CheckConsistency", "RHS");
166 init->AddCommand("InitializeIterationCounter");
167 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
168
169 loop->AddCommand("ClearCoarseLevels", "SOL");
170 loop->AddCommand("ClearCoarseLevels", "RHS");
171
172 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
173
[4571da]174 loop->AddCommand("SetAverageToZero", "SOL");
[716da7]175 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
176 loop->AddCommand("CheckResidual", "RESIDUAL");
177 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
178 loop->AddCommand("CheckIterationCounter");
179
180 finalize->AddCommand("ExportSolution");
181
182 init->Register("COMMANDLIST_INIT");
183 loop->Register("COMMANDLIST_LOOP");
184 finalize->Register("COMMANDLIST_FINALIZE");
185 }
186
187 static void SetCorrectionSchemePeriodicParticleDebug(int minLevel, int maxLevel, int gamma)
188 {
189 CommandList* init = new CommandList();
190 CommandList* loop = new CommandList();
191 CommandList* finalize = new CommandList();
192
193 init->AddCommand("ClearGrid", "RHS");
194 init->AddCommand("ClearGrid", "SOL");
195 init->AddCommand("ImportRightHandSide");
196 init->AddCommand("CheckConsistency", "RHS");
197 init->AddCommand("InitializeIterationCounter");
198 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
199 init->AddCommand("PrintAllSettings");
200
201 loop->AddCommand("ClearCoarseLevels", "SOL");
202 loop->AddCommand("ClearCoarseLevels", "RHS");
203
204 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
205
[4571da]206 loop->AddCommand("SetAverageToZero", "SOL");
[716da7]207 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
208 loop->AddCommand("CheckResidual", "RESIDUAL");
209 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
[48b662]210 loop->AddCommand("CheckIterationCounter");
211
212 finalize->AddCommand("ExportSolution");
213
214 init->Register("COMMANDLIST_INIT");
215 loop->Register("COMMANDLIST_LOOP");
216 finalize->Register("COMMANDLIST_FINALIZE");
217 }
218
219 static void SetFullApproximationSchemeDirichlet(int minLevel, int maxLevel, int gamma)
220 {
221 CommandList* init = new CommandList();
222 CommandList* loop = new CommandList();
223 CommandList* finalize = new CommandList();
224
225 init->AddCommand("ClearGrid", "RHS");
226 init->AddCommand("ClearGrid", "SOL");
227 init->AddCommand("ImportRightHandSide");
[dfed1c]228 init->AddCommand("ForceDiscreteCompatibility");
[48b662]229 init->AddCommand("CheckConsistency", "RHS");
230 init->AddCommand("CopyBoundary", "RHS:SOL");
[dfed1c]231 init->AddCommand("InitializeIterationCounter");
[48b662]232 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
233
234 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
235
[dfed1c]236 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
237 loop->AddCommand("CheckResidual", "RESIDUAL");
238 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
[48b662]239 loop->AddCommand("CheckIterationCounter");
240
241 finalize->AddCommand("ExportSolution");
242
243 init->Register("COMMANDLIST_INIT");
244 loop->Register("COMMANDLIST_LOOP");
245 finalize->Register("COMMANDLIST_FINALIZE");
246 }
247
248 static void SetFullApproximationSchemeDirichletDebug(int minLevel, int maxLevel, int gamma)
249 {
250 CommandList* init = new CommandList();
251 CommandList* loop = new CommandList();
252 CommandList* finalize = new CommandList();
253
254 init->AddCommand("ClearGrid", "RHS");
255 init->AddCommand("ClearGrid", "SOL");
256 init->AddCommand("ImportRightHandSide");
[dfed1c]257 init->AddCommand("ForceDiscreteCompatibility");
[48b662]258 init->AddCommand("CheckConsistency", "RHS");
259 init->AddCommand("CopyBoundary", "RHS:SOL");
[dfed1c]260 init->AddCommand("InitializeIterationCounter");
[48b662]261 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
[dfed1c]262 init->AddCommand("PrintAllSettings");
[48b662]263
264 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
265
[dfed1c]266 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
267 loop->AddCommand("CheckResidual", "RESIDUAL");
268 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
[48b662]269 loop->AddCommand("CheckIterationCounter");
270
271 finalize->AddCommand("ExportSolution");
272
273 init->Register("COMMANDLIST_INIT");
274 loop->Register("COMMANDLIST_LOOP");
275 finalize->Register("COMMANDLIST_FINALIZE");
276 }
277
278 static void SetFullApproximationSchemePeriodic(int minLevel, int maxLevel, int gamma)
279 {
280 CommandList* init = new CommandList();
281 CommandList* loop = new CommandList();
282 CommandList* finalize = new CommandList();
283
284 init->AddCommand("ClearGrid", "RHS");
285 init->AddCommand("ClearGrid", "SOL");
286 init->AddCommand("ImportRightHandSide");
[dfed1c]287 init->AddCommand("ForceDiscreteCompatibility");
[48b662]288 init->AddCommand("CheckConsistency", "RHS");
[dfed1c]289 init->AddCommand("InitializeIterationCounter");
[48b662]290 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
291
292 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
293
[dfed1c]294 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
295 loop->AddCommand("CheckResidual", "RESIDUAL");
296 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
[48b662]297 loop->AddCommand("CheckIterationCounter");
298
299 finalize->AddCommand("ExportSolution");
300
301 init->Register("COMMANDLIST_INIT");
302 loop->Register("COMMANDLIST_LOOP");
303 finalize->Register("COMMANDLIST_FINALIZE");
304 }
305
306 static void SetFullApproximationSchemePeriodicDebug(int minLevel, int maxLevel, int gamma)
307 {
308 CommandList* init = new CommandList();
309 CommandList* loop = new CommandList();
310 CommandList* finalize = new CommandList();
311
312 init->AddCommand("ClearGrid", "RHS");
313 init->AddCommand("ClearGrid", "SOL");
314 init->AddCommand("ImportRightHandSide");
[dfed1c]315 init->AddCommand("ForceDiscreteCompatibility");
[48b662]316 init->AddCommand("CheckConsistency", "RHS");
[dfed1c]317 init->AddCommand("InitializeIterationCounter");
[48b662]318 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
[dfed1c]319 init->AddCommand("PrintAllSettings");
[48b662]320
321 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
322
[dfed1c]323 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
324 loop->AddCommand("CheckResidual", "RESIDUAL");
325 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
[48b662]326 loop->AddCommand("CheckIterationCounter");
327
328 finalize->AddCommand("ExportSolution");
329
330 init->Register("COMMANDLIST_INIT");
331 loop->Register("COMMANDLIST_LOOP");
332 finalize->Register("COMMANDLIST_FINALIZE");
333 }
334
335private:
336 static void AddCycleGamma(CommandList& list, int numLevels, int gamma)
337 {
338 for (int i=0; i<numLevels-1; i++) {
339 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
340 list.AddCommand("Restrict");
341 }
342
343 list.AddCommand("Solve");
344
345 for (int i=1; i<gamma; i++) {
346
347 for (int j=0; j<numLevels-2; j++) {
348
349 for (int k=0; k<=j; k++) {
350 list.AddCommand("Prolongate");
351 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
352 }
353
354 for (int k=0; k<=j; k++) {
355 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
356 list.AddCommand("Restrict");
357 }
358
359 list.AddCommand("Solve");
360
361 }
362
363 for (int j=numLevels-4; j>=0; j--) {
364
365 for (int k=0; k<=j; k++) {
366 list.AddCommand("Prolongate");
367 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
368 }
369
370 for (int k=0; k<=j; k++) {
371 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
372 list.AddCommand("Restrict");
373 }
374
375 list.AddCommand("Solve");
376 }
377
378 }
379
380 for (int i=0; i<numLevels-1; i++) {
381 list.AddCommand("Prolongate");
382 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
383 }
384 }
385
386 static void AddCycleGammaDebug(CommandList& list, int numLevels, int gamma)
387 {
388 for (int i=0; i<numLevels-1; i++) {
389 list.AddCommand("PrintGrid", "RHS");
390 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
391 list.AddCommand("PrintGrid", "SOL");
392 list.AddCommand("PrintDefect");
393 list.AddCommand("Restrict");
394 }
395
396 list.AddCommand("PrintGrid", "RHS");
397 list.AddCommand("Solve");
[dfed1c]398 list.AddCommand("PrintGrid", "SOL");
399 list.AddCommand("PrintDefect");
[48b662]400
401 for (int i=1; i<gamma; i++) {
402
403 for (int j=0; j<numLevels-2; j++) {
404
405 for (int k=0; k<=j; k++) {
406 list.AddCommand("Prolongate");
407 list.AddCommand("PrintGrid", "RHS");
408 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
409 list.AddCommand("PrintGrid", "SOL");
410 list.AddCommand("PrintDefect");
411 }
412
413 for (int k=0; k<=j; k++) {
414 list.AddCommand("PrintGrid", "RHS");
415 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
416 list.AddCommand("PrintGrid", "SOL");
417 list.AddCommand("PrintDefect");
418 list.AddCommand("Restrict");
419 }
420
421 list.AddCommand("PrintGrid", "RHS");
422 list.AddCommand("Solve");
423 list.AddCommand("PrintGrid", "SOL");
424 list.AddCommand("PrintDefect");
425
426 }
427
428 for (int j=numLevels-4; j>=0; j--) {
429
430 for (int k=0; k<=j; k++) {
431 list.AddCommand("Prolongate");
432 list.AddCommand("PrintGrid", "RHS");
433 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
434 list.AddCommand("PrintGrid", "SOL");
435 list.AddCommand("PrintDefect");
436 }
437
438 for (int k=0; k<=j; k++) {
439 list.AddCommand("PrintGrid", "RHS");
440 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
441 list.AddCommand("PrintGrid", "SOL");
442 list.AddCommand("PrintDefect");
443 list.AddCommand("Restrict");
444 }
445
446 list.AddCommand("PrintGrid", "RHS");
447 list.AddCommand("Solve");
448 list.AddCommand("PrintGrid", "SOL");
449 list.AddCommand("PrintDefect");
450 }
451
452 }
453
454 for (int i=0; i<numLevels-1; i++) {
455 list.AddCommand("Prolongate");
456 list.AddCommand("PrintGrid", "RHS");
457 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
458 list.AddCommand("PrintGrid", "SOL");
459 list.AddCommand("PrintDefect");
460 }
461 }
462};
463
464}
465
466#endif /* TECHNIQUES_HPP_ */
Note: See TracBrowser for help on using the repository browser.