source: src/samples/techniques.hpp@ 66f24d

Last change on this file since 66f24d was 48b662, checked in by Olaf Lenz <olenz@…>, 14 years ago

Moved files in scafacos_fcs one level up.

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

  • Property mode set to 100644
File size: 10.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("CheckConsistency", "RHS");
35 init->AddCommand("CopyBoundary", "RHS:SOL");
36 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
37
38 loop->AddCommand("ClearCoarseLevels", "RHS");
39 loop->AddCommand("ClearCoarseLevels", "SOL");
40
41 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
42
43 loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL");
44 loop->AddCommand("CheckIterationCounter");
45
46 finalize->AddCommand("ExportSolution");
47
48 init->Register("COMMANDLIST_INIT");
49 loop->Register("COMMANDLIST_LOOP");
50 finalize->Register("COMMANDLIST_FINALIZE");
51 }
52
53
54 static void SetCorrectionSchemeDirichletDebug(int minLevel, int maxLevel, int gamma)
55 {
56 CommandList* init = new CommandList();
57 CommandList* loop = new CommandList();
58 CommandList* finalize = new CommandList();
59
60 init->AddCommand("ClearGrid", "RHS");
61 init->AddCommand("ClearGrid", "SOL");
62 init->AddCommand("ImportRightHandSide");
63 init->AddCommand("CheckConsistency", "RHS");
64 init->AddCommand("CopyBoundary", "RHS:SOL");
65 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
66
67 loop->AddCommand("ClearCoarseLevels", "RHS");
68 loop->AddCommand("ClearCoarseLevels", "SOL");
69
70 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
71
72 loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL");
73 loop->AddCommand("CheckIterationCounter");
74
75 finalize->AddCommand("ExportSolution");
76
77 init->Register("COMMANDLIST_INIT");
78 loop->Register("COMMANDLIST_LOOP");
79 finalize->Register("COMMANDLIST_FINALIZE");
80 }
81
82 static void SetCorrectionSchemePeriodic(int minLevel, int maxLevel, int gamma)
83 {
84 CommandList* init = new CommandList();
85 CommandList* loop = new CommandList();
86 CommandList* finalize = new CommandList();
87
88 init->AddCommand("ClearGrid", "RHS");
89 init->AddCommand("ClearGrid", "SOL");
90 init->AddCommand("ImportRightHandSide");
91 init->AddCommand("CheckConsistency", "RHS");
92 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
93
94 loop->AddCommand("ClearCoarseLevels", "SOL");
95 loop->AddCommand("ClearCoarseLevels", "RHS");
96
97 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
98
99 loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL");
100 loop->AddCommand("CheckIterationCounter");
101
102 finalize->AddCommand("ExportSolution");
103
104 init->Register("COMMANDLIST_INIT");
105 loop->Register("COMMANDLIST_LOOP");
106 finalize->Register("COMMANDLIST_FINALIZE");
107 }
108
109 static void SetCorrectionSchemePeriodicDebug(int minLevel, int maxLevel, int gamma)
110 {
111 CommandList* init = new CommandList();
112 CommandList* loop = new CommandList();
113 CommandList* finalize = new CommandList();
114
115 init->AddCommand("ClearGrid", "RHS");
116 init->AddCommand("ClearGrid", "SOL");
117 init->AddCommand("ImportRightHandSide");
118 init->AddCommand("CheckConsistency", "RHS");
119 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
120
121 loop->AddCommand("ClearCoarseLevels", "SOL");
122 loop->AddCommand("ClearCoarseLevels", "RHS");
123
124 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
125
126 loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL");
127 loop->AddCommand("CheckIterationCounter");
128
129 finalize->AddCommand("ExportSolution");
130
131 init->Register("COMMANDLIST_INIT");
132 loop->Register("COMMANDLIST_LOOP");
133 finalize->Register("COMMANDLIST_FINALIZE");
134 }
135
136 static void SetFullApproximationSchemeDirichlet(int minLevel, int maxLevel, int gamma)
137 {
138 CommandList* init = new CommandList();
139 CommandList* loop = new CommandList();
140 CommandList* finalize = new CommandList();
141
142 init->AddCommand("ClearGrid", "RHS");
143 init->AddCommand("ClearGrid", "SOL");
144 init->AddCommand("ImportRightHandSide");
145 init->AddCommand("CheckConsistency", "RHS");
146 init->AddCommand("CopyBoundary", "RHS:SOL");
147 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
148
149 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
150
151 loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL");
152 loop->AddCommand("CheckIterationCounter");
153
154 finalize->AddCommand("ExportSolution");
155
156 init->Register("COMMANDLIST_INIT");
157 loop->Register("COMMANDLIST_LOOP");
158 finalize->Register("COMMANDLIST_FINALIZE");
159 }
160
161 static void SetFullApproximationSchemeDirichletDebug(int minLevel, int maxLevel, int gamma)
162 {
163 CommandList* init = new CommandList();
164 CommandList* loop = new CommandList();
165 CommandList* finalize = new CommandList();
166
167 init->AddCommand("ClearGrid", "RHS");
168 init->AddCommand("ClearGrid", "SOL");
169 init->AddCommand("ImportRightHandSide");
170 init->AddCommand("CheckConsistency", "RHS");
171 init->AddCommand("CopyBoundary", "RHS:SOL");
172 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
173
174 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
175
176 loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL");
177 loop->AddCommand("CheckIterationCounter");
178
179 finalize->AddCommand("ExportSolution");
180
181 init->Register("COMMANDLIST_INIT");
182 loop->Register("COMMANDLIST_LOOP");
183 finalize->Register("COMMANDLIST_FINALIZE");
184 }
185
186 static void SetFullApproximationSchemePeriodic(int minLevel, int maxLevel, int gamma)
187 {
188 CommandList* init = new CommandList();
189 CommandList* loop = new CommandList();
190 CommandList* finalize = new CommandList();
191
192 init->AddCommand("ClearGrid", "RHS");
193 init->AddCommand("ClearGrid", "SOL");
194 init->AddCommand("ImportRightHandSide");
195 init->AddCommand("CheckConsistency", "RHS");
196 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
197
198 AddCycleGamma(*loop, maxLevel-minLevel+1, gamma);
199
200 loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL");
201 loop->AddCommand("CheckIterationCounter");
202
203 finalize->AddCommand("ExportSolution");
204
205 init->Register("COMMANDLIST_INIT");
206 loop->Register("COMMANDLIST_LOOP");
207 finalize->Register("COMMANDLIST_FINALIZE");
208 }
209
210 static void SetFullApproximationSchemePeriodicDebug(int minLevel, int maxLevel, int gamma)
211 {
212 CommandList* init = new CommandList();
213 CommandList* loop = new CommandList();
214 CommandList* finalize = new CommandList();
215
216 init->AddCommand("ClearGrid", "RHS");
217 init->AddCommand("ClearGrid", "SOL");
218 init->AddCommand("ImportRightHandSide");
219 init->AddCommand("CheckConsistency", "RHS");
220 init->AddCommand("InitializeResidualNorm", "INITIAL_RESIDUAL");
221
222 AddCycleGammaDebug(*loop, maxLevel-minLevel+1, gamma);
223
224 loop->AddCommand("CheckRelativeResidual", "INITIAL_RESIDUAL");
225 loop->AddCommand("CheckIterationCounter");
226
227 finalize->AddCommand("ExportSolution");
228
229 init->Register("COMMANDLIST_INIT");
230 loop->Register("COMMANDLIST_LOOP");
231 finalize->Register("COMMANDLIST_FINALIZE");
232 }
233
234private:
235 static void AddCycleGamma(CommandList& list, int numLevels, int gamma)
236 {
237 for (int i=0; i<numLevels-1; i++) {
238 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
239 list.AddCommand("Restrict");
240 }
241
242 list.AddCommand("Solve");
243
244 for (int i=1; i<gamma; i++) {
245
246 for (int j=0; j<numLevels-2; j++) {
247
248 for (int k=0; k<=j; k++) {
249 list.AddCommand("Prolongate");
250 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
251 }
252
253 for (int k=0; k<=j; k++) {
254 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
255 list.AddCommand("Restrict");
256 }
257
258 list.AddCommand("Solve");
259
260 }
261
262 for (int j=numLevels-4; j>=0; j--) {
263
264 for (int k=0; k<=j; k++) {
265 list.AddCommand("Prolongate");
266 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
267 }
268
269 for (int k=0; k<=j; k++) {
270 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
271 list.AddCommand("Restrict");
272 }
273
274 list.AddCommand("Solve");
275 }
276
277 }
278
279 for (int i=0; i<numLevels-1; i++) {
280 list.AddCommand("Prolongate");
281 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
282 }
283 }
284
285 static void AddCycleGammaDebug(CommandList& list, int numLevels, int gamma)
286 {
287 for (int i=0; i<numLevels-1; i++) {
288 list.AddCommand("PrintGrid", "RHS");
289 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
290 list.AddCommand("PrintGrid", "SOL");
291 list.AddCommand("PrintDefect");
292 list.AddCommand("Restrict");
293 }
294
295 list.AddCommand("PrintGrid", "RHS");
296 list.AddCommand("Solve");
297
298 for (int i=1; i<gamma; i++) {
299
300 for (int j=0; j<numLevels-2; j++) {
301
302 for (int k=0; k<=j; k++) {
303 list.AddCommand("Prolongate");
304 list.AddCommand("PrintGrid", "RHS");
305 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
306 list.AddCommand("PrintGrid", "SOL");
307 list.AddCommand("PrintDefect");
308 }
309
310 for (int k=0; k<=j; k++) {
311 list.AddCommand("PrintGrid", "RHS");
312 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
313 list.AddCommand("PrintGrid", "SOL");
314 list.AddCommand("PrintDefect");
315 list.AddCommand("Restrict");
316 }
317
318 list.AddCommand("PrintGrid", "RHS");
319 list.AddCommand("Solve");
320 list.AddCommand("PrintGrid", "SOL");
321 list.AddCommand("PrintDefect");
322
323 }
324
325 for (int j=numLevels-4; j>=0; j--) {
326
327 for (int k=0; k<=j; k++) {
328 list.AddCommand("Prolongate");
329 list.AddCommand("PrintGrid", "RHS");
330 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
331 list.AddCommand("PrintGrid", "SOL");
332 list.AddCommand("PrintDefect");
333 }
334
335 for (int k=0; k<=j; k++) {
336 list.AddCommand("PrintGrid", "RHS");
337 list.AddCommand("Smooth", "PRESMOOTHSTEPS");
338 list.AddCommand("PrintGrid", "SOL");
339 list.AddCommand("PrintDefect");
340 list.AddCommand("Restrict");
341 }
342
343 list.AddCommand("PrintGrid", "RHS");
344 list.AddCommand("Solve");
345 list.AddCommand("PrintGrid", "SOL");
346 list.AddCommand("PrintDefect");
347 }
348
349 }
350
351 for (int i=0; i<numLevels-1; i++) {
352 list.AddCommand("Prolongate");
353 list.AddCommand("PrintGrid", "RHS");
354 list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
355 list.AddCommand("PrintGrid", "SOL");
356 list.AddCommand("PrintDefect");
357 }
358 }
359};
360
361}
362
363#endif /* TECHNIQUES_HPP_ */
Note: See TracBrowser for help on using the repository browser.