source: src/samples/techniques.hpp@ b51c3b

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

Fix energy calculation.

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

  • Property mode set to 100644
File size: 15.0 KB
Line 
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");
34 init->AddCommand("ForceDiscreteCompatibility");
35 init->AddCommand("CheckConsistency", "RHS");
36 init->AddCommand("CopyBoundary", "RHS:SOL");
37 init->AddCommand("InitializeIterationCounter");
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
45 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
46 loop->AddCommand("CheckResidual", "RESIDUAL");
47 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
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");
67 init->AddCommand("ForceDiscreteCompatibility");
68 init->AddCommand("CheckConsistency", "RHS");
69 init->AddCommand("CopyBoundary", "RHS:SOL");
70 init->AddCommand("InitializeIterationCounter");
71 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
72 init->AddCommand("PrintAllSettings");
73
74 loop->AddCommand("ClearCoarseLevels", "RHS");
75 loop->AddCommand("ClearCoarseLevels", "SOL");
76
77 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
78
79 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
80 loop->AddCommand("CheckResidual", "RESIDUAL");
81 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
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");
100 init->AddCommand("ForceDiscreteCompatibility");
101 init->AddCommand("CheckConsistency", "RHS");
102 init->AddCommand("InitializeIterationCounter");
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
110 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
111 loop->AddCommand("CheckResidual", "RESIDUAL");
112 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
113 loop->AddCommand("CheckIterationCounter");
114
115 finalize->AddCommand("ExportSolution");
116
117 init->Register("COMMANDLIST_INIT");
118 loop->Register("COMMANDLIST_LOOP");
119 finalize->Register("COMMANDLIST_FINALIZE");
120 }
121
122 static void SetCorrectionSchemePeriodicDebug(int minLevel, int maxLevel, int gamma)
123 {
124 CommandList* init = new CommandList();
125 CommandList* loop = new CommandList();
126 CommandList* finalize = new CommandList();
127
128 init->AddCommand("ClearGrid", "RHS");
129 init->AddCommand("ClearGrid", "SOL");
130 init->AddCommand("ImportRightHandSide");
131 init->AddCommand("ForceDiscreteCompatibility");
132 init->AddCommand("CheckConsistency", "RHS");
133 init->AddCommand("InitializeIterationCounter");
134 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
135 init->AddCommand("PrintAllSettings");
136
137 loop->AddCommand("ClearCoarseLevels", "SOL");
138 loop->AddCommand("ClearCoarseLevels", "RHS");
139
140 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
141
142 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
143 loop->AddCommand("CheckResidual", "RESIDUAL");
144 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
145 loop->AddCommand("CheckIterationCounter");
146
147 finalize->AddCommand("ExportSolution");
148
149 init->Register("COMMANDLIST_INIT");
150 loop->Register("COMMANDLIST_LOOP");
151 finalize->Register("COMMANDLIST_FINALIZE");
152 }
153
154 static void SetCorrectionSchemePeriodicParticle(int minLevel, int maxLevel, int gamma)
155 {
156 CommandList* init = new CommandList();
157 CommandList* loop = new CommandList();
158 CommandList* finalize = new CommandList();
159
160 init->AddCommand("ClearGrid", "RHS");
161 init->AddCommand("ClearGrid", "SOL");
162 init->AddCommand("ImportRightHandSide");
163 init->AddCommand("CheckConsistency", "RHS");
164 init->AddCommand("InitializeIterationCounter");
165 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
166
167 loop->AddCommand("ClearCoarseLevels", "SOL");
168 loop->AddCommand("ClearCoarseLevels", "RHS");
169
170 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
171
172 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
173 loop->AddCommand("CheckResidual", "RESIDUAL");
174 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
175 loop->AddCommand("CheckIterationCounter");
176
177 finalize->AddCommand("ExportSolution");
178
179 init->Register("COMMANDLIST_INIT");
180 loop->Register("COMMANDLIST_LOOP");
181 finalize->Register("COMMANDLIST_FINALIZE");
182 }
183
184 static void SetCorrectionSchemePeriodicParticleDebug(int minLevel, int maxLevel, int gamma)
185 {
186 CommandList* init = new CommandList();
187 CommandList* loop = new CommandList();
188 CommandList* finalize = new CommandList();
189
190 init->AddCommand("ClearGrid", "RHS");
191 init->AddCommand("ClearGrid", "SOL");
192 init->AddCommand("ImportRightHandSide");
193 init->AddCommand("CheckConsistency", "RHS");
194 init->AddCommand("InitializeIterationCounter");
195 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
196 init->AddCommand("PrintAllSettings");
197
198 loop->AddCommand("ClearCoarseLevels", "SOL");
199 loop->AddCommand("ClearCoarseLevels", "RHS");
200
201 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
202
203 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
204 loop->AddCommand("CheckResidual", "RESIDUAL");
205 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
206 loop->AddCommand("CheckIterationCounter");
207
208 finalize->AddCommand("ExportSolution");
209
210 init->Register("COMMANDLIST_INIT");
211 loop->Register("COMMANDLIST_LOOP");
212 finalize->Register("COMMANDLIST_FINALIZE");
213 }
214
215 static void SetFullApproximationSchemeDirichlet(int minLevel, int maxLevel, int gamma)
216 {
217 CommandList* init = new CommandList();
218 CommandList* loop = new CommandList();
219 CommandList* finalize = new CommandList();
220
221 init->AddCommand("ClearGrid", "RHS");
222 init->AddCommand("ClearGrid", "SOL");
223 init->AddCommand("ImportRightHandSide");
224 init->AddCommand("ForceDiscreteCompatibility");
225 init->AddCommand("CheckConsistency", "RHS");
226 init->AddCommand("CopyBoundary", "RHS:SOL");
227 init->AddCommand("InitializeIterationCounter");
228 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
229
230 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
231
232 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
233 loop->AddCommand("CheckResidual", "RESIDUAL");
234 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
235 loop->AddCommand("CheckIterationCounter");
236
237 finalize->AddCommand("ExportSolution");
238
239 init->Register("COMMANDLIST_INIT");
240 loop->Register("COMMANDLIST_LOOP");
241 finalize->Register("COMMANDLIST_FINALIZE");
242 }
243
244 static void SetFullApproximationSchemeDirichletDebug(int minLevel, int maxLevel, int gamma)
245 {
246 CommandList* init = new CommandList();
247 CommandList* loop = new CommandList();
248 CommandList* finalize = new CommandList();
249
250 init->AddCommand("ClearGrid", "RHS");
251 init->AddCommand("ClearGrid", "SOL");
252 init->AddCommand("ImportRightHandSide");
253 init->AddCommand("ForceDiscreteCompatibility");
254 init->AddCommand("CheckConsistency", "RHS");
255 init->AddCommand("CopyBoundary", "RHS:SOL");
256 init->AddCommand("InitializeIterationCounter");
257 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
258 init->AddCommand("PrintAllSettings");
259
260 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
261
262 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
263 loop->AddCommand("CheckResidual", "RESIDUAL");
264 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
265 loop->AddCommand("CheckIterationCounter");
266
267 finalize->AddCommand("ExportSolution");
268
269 init->Register("COMMANDLIST_INIT");
270 loop->Register("COMMANDLIST_LOOP");
271 finalize->Register("COMMANDLIST_FINALIZE");
272 }
273
274 static void SetFullApproximationSchemePeriodic(int minLevel, int maxLevel, int gamma)
275 {
276 CommandList* init = new CommandList();
277 CommandList* loop = new CommandList();
278 CommandList* finalize = new CommandList();
279
280 init->AddCommand("ClearGrid", "RHS");
281 init->AddCommand("ClearGrid", "SOL");
282 init->AddCommand("ImportRightHandSide");
283 init->AddCommand("ForceDiscreteCompatibility");
284 init->AddCommand("CheckConsistency", "RHS");
285 init->AddCommand("InitializeIterationCounter");
286 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
287
288 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
289
290 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
291 loop->AddCommand("CheckResidual", "RESIDUAL");
292 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
293 loop->AddCommand("CheckIterationCounter");
294
295 finalize->AddCommand("ExportSolution");
296
297 init->Register("COMMANDLIST_INIT");
298 loop->Register("COMMANDLIST_LOOP");
299 finalize->Register("COMMANDLIST_FINALIZE");
300 }
301
302 static void SetFullApproximationSchemePeriodicDebug(int minLevel, int maxLevel, int gamma)
303 {
304 CommandList* init = new CommandList();
305 CommandList* loop = new CommandList();
306 CommandList* finalize = new CommandList();
307
308 init->AddCommand("ClearGrid", "RHS");
309 init->AddCommand("ClearGrid", "SOL");
310 init->AddCommand("ImportRightHandSide");
311 init->AddCommand("ForceDiscreteCompatibility");
312 init->AddCommand("CheckConsistency", "RHS");
313 init->AddCommand("InitializeIterationCounter");
314 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
315 init->AddCommand("PrintAllSettings");
316
317 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
318
319 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
320 loop->AddCommand("CheckResidual", "RESIDUAL");
321 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
322 loop->AddCommand("CheckIterationCounter");
323
324 finalize->AddCommand("ExportSolution");
325
326 init->Register("COMMANDLIST_INIT");
327 loop->Register("COMMANDLIST_LOOP");
328 finalize->Register("COMMANDLIST_FINALIZE");
329 }
330
331private:
332 static void AddCycleGamma(CommandList& list, int numLevels, int gamma)
333 {
334 for (int i=0; i<numLevels-1; i++) {
335 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
336 list.AddCommand("Restrict");
337 }
338
339 list.AddCommand("Solve");
340
341 for (int i=1; i<gamma; i++) {
342
343 for (int j=0; j<numLevels-2; j++) {
344
345 for (int k=0; k<=j; k++) {
346 list.AddCommand("Prolongate");
347 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
348 }
349
350 for (int k=0; k<=j; k++) {
351 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
352 list.AddCommand("Restrict");
353 }
354
355 list.AddCommand("Solve");
356
357 }
358
359 for (int j=numLevels-4; j>=0; j--) {
360
361 for (int k=0; k<=j; k++) {
362 list.AddCommand("Prolongate");
363 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
364 }
365
366 for (int k=0; k<=j; k++) {
367 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
368 list.AddCommand("Restrict");
369 }
370
371 list.AddCommand("Solve");
372 }
373
374 }
375
376 for (int i=0; i<numLevels-1; i++) {
377 list.AddCommand("Prolongate");
378 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
379 }
380 }
381
382 static void AddCycleGammaDebug(CommandList& list, int numLevels, int gamma)
383 {
384 for (int i=0; i<numLevels-1; i++) {
385 list.AddCommand("PrintGrid", "RHS");
386 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
387 list.AddCommand("PrintGrid", "SOL");
388 list.AddCommand("PrintDefect");
389 list.AddCommand("Restrict");
390 }
391
392 list.AddCommand("PrintGrid", "RHS");
393 list.AddCommand("Solve");
394 list.AddCommand("PrintGrid", "SOL");
395 list.AddCommand("PrintDefect");
396
397 for (int i=1; i<gamma; i++) {
398
399 for (int j=0; j<numLevels-2; j++) {
400
401 for (int k=0; k<=j; k++) {
402 list.AddCommand("Prolongate");
403 list.AddCommand("PrintGrid", "RHS");
404 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
405 list.AddCommand("PrintGrid", "SOL");
406 list.AddCommand("PrintDefect");
407 }
408
409 for (int k=0; k<=j; k++) {
410 list.AddCommand("PrintGrid", "RHS");
411 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
412 list.AddCommand("PrintGrid", "SOL");
413 list.AddCommand("PrintDefect");
414 list.AddCommand("Restrict");
415 }
416
417 list.AddCommand("PrintGrid", "RHS");
418 list.AddCommand("Solve");
419 list.AddCommand("PrintGrid", "SOL");
420 list.AddCommand("PrintDefect");
421
422 }
423
424 for (int j=numLevels-4; j>=0; j--) {
425
426 for (int k=0; k<=j; k++) {
427 list.AddCommand("Prolongate");
428 list.AddCommand("PrintGrid", "RHS");
429 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
430 list.AddCommand("PrintGrid", "SOL");
431 list.AddCommand("PrintDefect");
432 }
433
434 for (int k=0; k<=j; k++) {
435 list.AddCommand("PrintGrid", "RHS");
436 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
437 list.AddCommand("PrintGrid", "SOL");
438 list.AddCommand("PrintDefect");
439 list.AddCommand("Restrict");
440 }
441
442 list.AddCommand("PrintGrid", "RHS");
443 list.AddCommand("Solve");
444 list.AddCommand("PrintGrid", "SOL");
445 list.AddCommand("PrintDefect");
446 }
447
448 }
449
450 for (int i=0; i<numLevels-1; i++) {
451 list.AddCommand("Prolongate");
452 list.AddCommand("PrintGrid", "RHS");
453 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
454 list.AddCommand("PrintGrid", "SOL");
455 list.AddCommand("PrintDefect");
456 }
457 }
458};
459
460}
461
462#endif /* TECHNIQUES_HPP_ */
Note: See TracBrowser for help on using the repository browser.