| 1 | /*
 | 
|---|
| 2 |  *    vmg - a versatile multigrid solver
 | 
|---|
| 3 |  *    Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
 | 
|---|
| 4 |  *
 | 
|---|
| 5 |  *  vmg is free software: you can redistribute it and/or modify
 | 
|---|
| 6 |  *  it under the terms of the GNU General Public License as published by
 | 
|---|
| 7 |  *  the Free Software Foundation, either version 3 of the License, or
 | 
|---|
| 8 |  *  (at your option) any later version.
 | 
|---|
| 9 |  *
 | 
|---|
| 10 |  *  vmg is distributed in the hope that it will be useful,
 | 
|---|
| 11 |  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 12 |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 13 |  *  GNU General Public License for more details.
 | 
|---|
| 14 |  *
 | 
|---|
| 15 |  *  You should have received a copy of the GNU General Public License
 | 
|---|
| 16 |  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| 17 |  */
 | 
|---|
| 18 | 
 | 
|---|
| 19 | /**
 | 
|---|
| 20 |  * @file   cycle.hpp
 | 
|---|
| 21 |  * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
 | 
|---|
| 22 |  * @date   Wed Jun 27 14:45:29 2012
 | 
|---|
| 23 |  *
 | 
|---|
| 24 |  * @brief  Base class for multigrid cycles.
 | 
|---|
| 25 |  *
 | 
|---|
| 26 |  */
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 29 | #include <libvmg_config.h>
 | 
|---|
| 30 | #endif
 | 
|---|
| 31 | 
 | 
|---|
| 32 | #include "base/command_list.hpp"
 | 
|---|
| 33 | #include "cycles/cycle.hpp"
 | 
|---|
| 34 | 
 | 
|---|
| 35 | using namespace VMG;
 | 
|---|
| 36 | 
 | 
|---|
| 37 | void Cycle::AddCycle(CommandList& list, int numLevels, int gamma)
 | 
|---|
| 38 | {
 | 
|---|
| 39 |   for (int i=0; i<numLevels-1; i++) {
 | 
|---|
| 40 |     list.AddCommand("Smooth", "PRESMOOTHSTEPS");
 | 
|---|
| 41 |     list.AddCommand("Restrict");
 | 
|---|
| 42 |   }
 | 
|---|
| 43 | 
 | 
|---|
| 44 |   list.AddCommand("Solve");
 | 
|---|
| 45 | 
 | 
|---|
| 46 |   for (int i=1; i<gamma; i++) {
 | 
|---|
| 47 | 
 | 
|---|
| 48 |     for (int j=0; j<numLevels-2; j++) {
 | 
|---|
| 49 | 
 | 
|---|
| 50 |       for (int k=0; k<=j; k++) {
 | 
|---|
| 51 |         list.AddCommand("Prolongate");
 | 
|---|
| 52 |         list.AddCommand("Smooth", "PRESMOOTHSTEPS");
 | 
|---|
| 53 |       }
 | 
|---|
| 54 | 
 | 
|---|
| 55 |       for (int k=0; k<=j; k++) {
 | 
|---|
| 56 |         list.AddCommand("Smooth", "PRESMOOTHSTEPS");
 | 
|---|
| 57 |         list.AddCommand("Restrict");
 | 
|---|
| 58 |       }
 | 
|---|
| 59 | 
 | 
|---|
| 60 |       list.AddCommand("Solve");
 | 
|---|
| 61 | 
 | 
|---|
| 62 |     }
 | 
|---|
| 63 | 
 | 
|---|
| 64 |     for (int j=numLevels-4; j>=0; j--) {
 | 
|---|
| 65 | 
 | 
|---|
| 66 |       for (int k=0; k<=j; k++) {
 | 
|---|
| 67 |         list.AddCommand("Prolongate");
 | 
|---|
| 68 |         list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
 | 
|---|
| 69 |       }
 | 
|---|
| 70 | 
 | 
|---|
| 71 |       for (int k=0; k<=j; k++) {
 | 
|---|
| 72 |         list.AddCommand("Smooth", "PRESMOOTHSTEPS");
 | 
|---|
| 73 |         list.AddCommand("Restrict");
 | 
|---|
| 74 |       }
 | 
|---|
| 75 | 
 | 
|---|
| 76 |       list.AddCommand("Solve");
 | 
|---|
| 77 |     }
 | 
|---|
| 78 | 
 | 
|---|
| 79 |   }
 | 
|---|
| 80 | 
 | 
|---|
| 81 |   for (int i=0; i<numLevels-1; i++) {
 | 
|---|
| 82 |     list.AddCommand("Prolongate");
 | 
|---|
| 83 |     list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
 | 
|---|
| 84 |   }
 | 
|---|
| 85 | }
 | 
|---|
| 86 | 
 | 
|---|
| 87 | void Cycle::AddCycleDebug(CommandList& list, int numLevels, int gamma)
 | 
|---|
| 88 | {
 | 
|---|
| 89 |   for (int i=0; i<numLevels-1; i++) {
 | 
|---|
| 90 |     list.AddCommand("PrintGrid", "RHS");
 | 
|---|
| 91 |     list.AddCommand("Smooth", "PRESMOOTHSTEPS");
 | 
|---|
| 92 |     list.AddCommand("PrintGrid", "SOL");
 | 
|---|
| 93 |     list.AddCommand("PrintDefect");
 | 
|---|
| 94 |     list.AddCommand("Restrict");
 | 
|---|
| 95 |   }
 | 
|---|
| 96 | 
 | 
|---|
| 97 |   list.AddCommand("PrintGrid", "RHS");
 | 
|---|
| 98 |   list.AddCommand("Solve");
 | 
|---|
| 99 |   list.AddCommand("PrintGrid", "SOL");
 | 
|---|
| 100 |   list.AddCommand("PrintDefect");
 | 
|---|
| 101 | 
 | 
|---|
| 102 |   for (int i=1; i<gamma; i++) {
 | 
|---|
| 103 | 
 | 
|---|
| 104 |     for (int j=0; j<numLevels-2; j++) {
 | 
|---|
| 105 | 
 | 
|---|
| 106 |       for (int k=0; k<=j; k++) {
 | 
|---|
| 107 |         list.AddCommand("Prolongate");
 | 
|---|
| 108 |         list.AddCommand("PrintGrid", "RHS");
 | 
|---|
| 109 |         list.AddCommand("Smooth", "PRESMOOTHSTEPS");
 | 
|---|
| 110 |         list.AddCommand("PrintGrid", "SOL");
 | 
|---|
| 111 |         list.AddCommand("PrintDefect");
 | 
|---|
| 112 |       }
 | 
|---|
| 113 | 
 | 
|---|
| 114 |       for (int k=0; k<=j; k++) {
 | 
|---|
| 115 |         list.AddCommand("PrintGrid", "RHS");
 | 
|---|
| 116 |         list.AddCommand("Smooth", "PRESMOOTHSTEPS");
 | 
|---|
| 117 |         list.AddCommand("PrintGrid", "SOL");
 | 
|---|
| 118 |         list.AddCommand("PrintDefect");
 | 
|---|
| 119 |         list.AddCommand("Restrict");
 | 
|---|
| 120 |       }
 | 
|---|
| 121 | 
 | 
|---|
| 122 |       list.AddCommand("PrintGrid", "RHS");
 | 
|---|
| 123 |       list.AddCommand("Solve");
 | 
|---|
| 124 |       list.AddCommand("PrintGrid", "SOL");
 | 
|---|
| 125 |       list.AddCommand("PrintDefect");
 | 
|---|
| 126 | 
 | 
|---|
| 127 |     }
 | 
|---|
| 128 | 
 | 
|---|
| 129 |     for (int j=numLevels-4; j>=0; j--) {
 | 
|---|
| 130 | 
 | 
|---|
| 131 |       for (int k=0; k<=j; k++) {
 | 
|---|
| 132 |         list.AddCommand("Prolongate");
 | 
|---|
| 133 |         list.AddCommand("PrintGrid", "RHS");
 | 
|---|
| 134 |         list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
 | 
|---|
| 135 |         list.AddCommand("PrintGrid", "SOL");
 | 
|---|
| 136 |         list.AddCommand("PrintDefect");
 | 
|---|
| 137 |       }
 | 
|---|
| 138 | 
 | 
|---|
| 139 |       for (int k=0; k<=j; k++) {
 | 
|---|
| 140 |         list.AddCommand("PrintGrid", "RHS");
 | 
|---|
| 141 |         list.AddCommand("Smooth", "PRESMOOTHSTEPS");
 | 
|---|
| 142 |         list.AddCommand("PrintGrid", "SOL");
 | 
|---|
| 143 |         list.AddCommand("PrintDefect");
 | 
|---|
| 144 |         list.AddCommand("Restrict");
 | 
|---|
| 145 |       }
 | 
|---|
| 146 | 
 | 
|---|
| 147 |       list.AddCommand("PrintGrid", "RHS");
 | 
|---|
| 148 |       list.AddCommand("Solve");
 | 
|---|
| 149 |       list.AddCommand("PrintGrid", "SOL");
 | 
|---|
| 150 |       list.AddCommand("PrintDefect");
 | 
|---|
| 151 |     }
 | 
|---|
| 152 | 
 | 
|---|
| 153 |   }
 | 
|---|
| 154 | 
 | 
|---|
| 155 |   for (int i=0; i<numLevels-1; i++) {
 | 
|---|
| 156 |     list.AddCommand("Prolongate");
 | 
|---|
| 157 |     list.AddCommand("PrintGrid", "RHS");
 | 
|---|
| 158 |     list.AddCommand("Smooth", "POSTSMOOTHSTEPS");
 | 
|---|
| 159 |     list.AddCommand("PrintGrid", "SOL");
 | 
|---|
| 160 |     list.AddCommand("PrintDefect");
 | 
|---|
| 161 |   }
 | 
|---|
| 162 | }
 | 
|---|