source: src/samples/techniques.hpp@ dfed1c

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

Major vmg update.

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

  • Property mode set to 100644
File size: 12.8 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 SetFullApproximationSchemeDirichlet(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("ForceDiscreteCompatibility");
164 init->AddCommand("CheckConsistency", "RHS");
165 init->AddCommand("CopyBoundary", "RHS:SOL");
166 init->AddCommand("InitializeIterationCounter");
167 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
168
169 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
170
171 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
172 loop->AddCommand("CheckResidual", "RESIDUAL");
173 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
174 loop->AddCommand("CheckIterationCounter");
175
176 finalize->AddCommand("ExportSolution");
177
178 init->Register("COMMANDLIST_INIT");
179 loop->Register("COMMANDLIST_LOOP");
180 finalize->Register("COMMANDLIST_FINALIZE");
181 }
182
183 static void SetFullApproximationSchemeDirichletDebug(int minLevel, int maxLevel, int gamma)
184 {
185 CommandList* init = new CommandList();
186 CommandList* loop = new CommandList();
187 CommandList* finalize = new CommandList();
188
189 init->AddCommand("ClearGrid", "RHS");
190 init->AddCommand("ClearGrid", "SOL");
191 init->AddCommand("ImportRightHandSide");
192 init->AddCommand("ForceDiscreteCompatibility");
193 init->AddCommand("CheckConsistency", "RHS");
194 init->AddCommand("CopyBoundary", "RHS:SOL");
195 init->AddCommand("InitializeIterationCounter");
196 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
197 init->AddCommand("PrintAllSettings");
198
199 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
200
201 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
202 loop->AddCommand("CheckResidual", "RESIDUAL");
203 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
204 loop->AddCommand("CheckIterationCounter");
205
206 finalize->AddCommand("ExportSolution");
207
208 init->Register("COMMANDLIST_INIT");
209 loop->Register("COMMANDLIST_LOOP");
210 finalize->Register("COMMANDLIST_FINALIZE");
211 }
212
213 static void SetFullApproximationSchemePeriodic(int minLevel, int maxLevel, int gamma)
214 {
215 CommandList* init = new CommandList();
216 CommandList* loop = new CommandList();
217 CommandList* finalize = new CommandList();
218
219 init->AddCommand("ClearGrid", "RHS");
220 init->AddCommand("ClearGrid", "SOL");
221 init->AddCommand("ImportRightHandSide");
222 init->AddCommand("ForceDiscreteCompatibility");
223 init->AddCommand("CheckConsistency", "RHS");
224 init->AddCommand("InitializeIterationCounter");
225 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
226
227 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
228
229 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
230 loop->AddCommand("CheckResidual", "RESIDUAL");
231 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
232 loop->AddCommand("CheckIterationCounter");
233
234 finalize->AddCommand("ExportSolution");
235
236 init->Register("COMMANDLIST_INIT");
237 loop->Register("COMMANDLIST_LOOP");
238 finalize->Register("COMMANDLIST_FINALIZE");
239 }
240
241 static void SetFullApproximationSchemePeriodicDebug(int minLevel, int maxLevel, int gamma)
242 {
243 CommandList* init = new CommandList();
244 CommandList* loop = new CommandList();
245 CommandList* finalize = new CommandList();
246
247 init->AddCommand("ClearGrid", "RHS");
248 init->AddCommand("ClearGrid", "SOL");
249 init->AddCommand("ImportRightHandSide");
250 init->AddCommand("ForceDiscreteCompatibility");
251 init->AddCommand("CheckConsistency", "RHS");
252 init->AddCommand("InitializeIterationCounter");
253 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
254 init->AddCommand("PrintAllSettings");
255
256 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
257
258 loop->AddCommand("ComputeResidualNorm", "RESIDUAL");
259 loop->AddCommand("CheckResidual", "RESIDUAL");
260 loop->AddCommand("CheckRelativeResidual", "RESIDUAL:INITIAL_RESIDUAL");
261 loop->AddCommand("CheckIterationCounter");
262
263 finalize->AddCommand("ExportSolution");
264
265 init->Register("COMMANDLIST_INIT");
266 loop->Register("COMMANDLIST_LOOP");
267 finalize->Register("COMMANDLIST_FINALIZE");
268 }
269
270private:
271 static void AddCycleGamma(CommandList& list, int numLevels, int gamma)
272 {
273 for (int i=0; i<numLevels-1; i++) {
274 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
275 list.AddCommand("Restrict");
276 }
277
278 list.AddCommand("Solve");
279
280 for (int i=1; i<gamma; i++) {
281
282 for (int j=0; j<numLevels-2; j++) {
283
284 for (int k=0; k<=j; k++) {
285 list.AddCommand("Prolongate");
286 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
287 }
288
289 for (int k=0; k<=j; k++) {
290 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
291 list.AddCommand("Restrict");
292 }
293
294 list.AddCommand("Solve");
295
296 }
297
298 for (int j=numLevels-4; j>=0; j--) {
299
300 for (int k=0; k<=j; k++) {
301 list.AddCommand("Prolongate");
302 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
303 }
304
305 for (int k=0; k<=j; k++) {
306 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
307 list.AddCommand("Restrict");
308 }
309
310 list.AddCommand("Solve");
311 }
312
313 }
314
315 for (int i=0; i<numLevels-1; i++) {
316 list.AddCommand("Prolongate");
317 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
318 }
319 }
320
321 static void AddCycleGammaDebug(CommandList& list, int numLevels, int gamma)
322 {
323 for (int i=0; i<numLevels-1; i++) {
324 list.AddCommand("PrintGrid", "RHS");
325 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
326 list.AddCommand("PrintGrid", "SOL");
327 list.AddCommand("PrintDefect");
328 list.AddCommand("Restrict");
329 }
330
331 list.AddCommand("PrintGrid", "RHS");
332 list.AddCommand("Solve");
333 list.AddCommand("PrintGrid", "SOL");
334 list.AddCommand("PrintDefect");
335
336 for (int i=1; i<gamma; i++) {
337
338 for (int j=0; j<numLevels-2; j++) {
339
340 for (int k=0; k<=j; k++) {
341 list.AddCommand("Prolongate");
342 list.AddCommand("PrintGrid", "RHS");
343 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
344 list.AddCommand("PrintGrid", "SOL");
345 list.AddCommand("PrintDefect");
346 }
347
348 for (int k=0; k<=j; k++) {
349 list.AddCommand("PrintGrid", "RHS");
350 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
351 list.AddCommand("PrintGrid", "SOL");
352 list.AddCommand("PrintDefect");
353 list.AddCommand("Restrict");
354 }
355
356 list.AddCommand("PrintGrid", "RHS");
357 list.AddCommand("Solve");
358 list.AddCommand("PrintGrid", "SOL");
359 list.AddCommand("PrintDefect");
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("PrintGrid", "RHS");
368 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
369 list.AddCommand("PrintGrid", "SOL");
370 list.AddCommand("PrintDefect");
371 }
372
373 for (int k=0; k<=j; k++) {
374 list.AddCommand("PrintGrid", "RHS");
375 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
376 list.AddCommand("PrintGrid", "SOL");
377 list.AddCommand("PrintDefect");
378 list.AddCommand("Restrict");
379 }
380
381 list.AddCommand("PrintGrid", "RHS");
382 list.AddCommand("Solve");
383 list.AddCommand("PrintGrid", "SOL");
384 list.AddCommand("PrintDefect");
385 }
386
387 }
388
389 for (int i=0; i<numLevels-1; i++) {
390 list.AddCommand("Prolongate");
391 list.AddCommand("PrintGrid", "RHS");
392 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
393 list.AddCommand("PrintGrid", "SOL");
394 list.AddCommand("PrintDefect");
395 }
396 }
397};
398
399}
400
401#endif /* TECHNIQUES_HPP_ */
Note: See TracBrowser for help on using the repository browser.