Changeset dfed1c for src/grid/tempgrid.cpp
- Timestamp:
- Nov 22, 2011, 9:22:10 PM (14 years ago)
- Children:
- facba0
- Parents:
- 66f24d
- File:
-
- 1 edited
-
src/grid/tempgrid.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/grid/tempgrid.cpp
r66f24d rdfed1c 8 8 */ 9 9 10 11 10 #ifdef HAVE_CONFIG_H 12 11 #include <config.h> … … 16 15 #include "base/stencil.hpp" 17 16 #include "comm/comm.hpp" 17 #include "grid/grid_index_translations.hpp" 18 18 #include "grid/tempgrid.hpp" 19 #include "interface/interface.hpp" 19 20 #include "mg.hpp" 20 21 … … 27 28 extent = rhs.Extent(); 28 29 29 delete [] grid; 30 31 grid = new vmg_float[local.SizeTotal().Product()]; 30 iterators.SetSubgrids(rhs.Local()); 31 32 level = rhs.Level(); 33 34 Allocate(); 32 35 } 33 36 … … 38 41 extent = extent_; 39 42 40 delete [] grid; 41 42 grid = new vmg_float[local.SizeTotal().Product()]; 43 } 44 45 void TempGrid::ImportFromResidual(const Grid& sol, const Grid& rhs) 43 iterators.SetSubgrids(local_); 44 45 Allocate(); 46 } 47 48 void TempGrid::SetPropertiesToGlobalCoarseGrid() 49 { 50 Interface* interface = MG::GetInterface(); 51 52 global = interface->Global().back(); 53 extent = interface->Extent().back(); 54 55 for (int i=0; i<3; ++i) { 56 57 if (interface->BoundaryConditions()[i] == Dirichlet || 58 interface->BoundaryConditions()[i] == Open) { 59 60 local.Size()[i] = global.SizeGlobal()[i] - 2; 61 local.SizeTotal()[i] = global.SizeGlobal()[i]; 62 local.Begin()[i] = 1; 63 local.End()[i] = local.SizeTotal()[i] - 1; 64 local.HaloBegin1()[i] = 0; 65 local.HaloEnd1()[i] = 0; 66 local.HaloBegin2()[i] = 0; 67 local.HaloEnd2()[i] = 0; 68 local.BoundaryBegin1()[i] = 0; 69 local.BoundaryEnd1()[i] = 1; 70 local.BoundaryBegin2()[i] = local.SizeTotal()[i] - 1; 71 local.BoundaryEnd2()[i] = local.SizeTotal()[i]; 72 73 }else if (interface->BoundaryConditions()[i] == Periodic) { 74 75 local.Size()[i] = global.SizeGlobal()[i]; 76 local.SizeTotal()[i] = global.SizeGlobal()[i]; 77 local.Begin()[i] = 0; 78 local.End()[i] = global.SizeGlobal()[i]; 79 local.HaloBegin1()[i] = 0; 80 local.HaloEnd1()[i] = 0; 81 local.HaloBegin2()[i] = 0; 82 local.HaloEnd2()[i] = 0; 83 local.BoundaryBegin1()[i] = 0; 84 local.BoundaryEnd1()[i] = 0; 85 local.BoundaryBegin2()[i] = 0; 86 local.BoundaryEnd2()[i] = 0; 87 88 } 89 90 } 91 92 level = interface->MinLevel(); 93 94 iterators.SetSubgrids(local); 95 96 Allocate(); 97 } 98 99 void TempGrid::SetPropertiesToFiner(const Grid& grid, const Boundary& boundary) 100 { 101 assert(grid.Father() != NULL); 102 assert(grid.Level() < grid.Father()->MaxLevel()); 103 104 const Index off = GridIndexTranslations::EndOffset(boundary); 105 106 this->Global().BeginFinest() = grid.Global().BeginFinest(); 107 this->Global().EndFinest() = grid.Global().EndFinest(); 108 this->Global().SizeFinest() = grid.Global().SizeFinest(); 109 this->Global().SizeGlobal() = 2 * (grid.Global().SizeGlobal()-off) + off; 110 this->Global().BeginLocal() = grid.Global().BeginLocal(); 111 this->Global().EndLocal() = grid.Global().EndLocal(); 112 113 GridIndexTranslations::CoarseToFine(this->Global().BeginLocal(), this->Global().EndLocal(), this->Global().SizeGlobal()); 114 115 this->Global().SizeLocal() = this->Global().EndLocal() - this->Global().BeginLocal(); 116 this->Global().BoundaryType() = (*(grid.Father()))(grid.Level()+1).Global().BoundaryType(); 117 118 this->Local().Size() = this->Global().SizeLocal(); 119 this->Local().SizeTotal() = this->Global().SizeLocal(); 120 this->Local().Begin() = 0; 121 this->Local().End() = this->Global().SizeLocal(); 122 123 for (int i=0; i<3; ++i) { 124 125 if (grid.Local().HaloEnd1()[i] - grid.Local().HaloBegin1()[i] > 0) { 126 this->Local().SizeTotal()[i] += 1; 127 this->Local().Begin()[i] += 1; 128 this->Local().End()[i] += 1; 129 this->Local().HaloBegin1()[i] = 0; 130 this->Local().HaloEnd1()[i] = 1; 131 }else { 132 this->Local().HaloBegin1()[i] = 0; 133 this->Local().HaloEnd1()[i] = 0; 134 } 135 136 if (grid.Local().BoundaryEnd1()[i] - grid.Local().BoundaryBegin1()[i] > 0) { 137 this->Local().Size()[i] -= 1; 138 this->Local().Begin()[i] += 1; 139 this->Local().BoundaryBegin1()[i] = 0; 140 this->Local().BoundaryEnd1()[i] = 1; 141 }else { 142 this->Local().BoundaryBegin1()[i] = 0; 143 this->Local().BoundaryEnd1()[i] = 0; 144 } 145 146 if (grid.Local().HaloEnd2()[i] - grid.Local().HaloBegin2()[i] > 0) { 147 this->Local().SizeTotal()[i] += 1; 148 this->Local().HaloBegin2()[i] = this->Local().End()[i]; 149 this->Local().HaloEnd2()[i] = this->Local().End()[i] + 1; 150 }else { 151 this->Local().HaloBegin2()[i] = 0; 152 this->Local().HaloEnd2()[i] = 0; 153 } 154 155 if (grid.Local().BoundaryEnd2()[i] - grid.Local().BoundaryBegin2()[i] > 0) { 156 this->Local().Size()[i] -= 1; 157 this->Local().End()[i] -= 1; 158 this->Local().BoundaryBegin2()[i] = this->Local().End()[i]; 159 this->Local().BoundaryEnd2()[i] = this->Local().End()[i]+1; 160 }else { 161 this->Local().BoundaryBegin2()[i] = 0; 162 this->Local().BoundaryEnd2()[i] = 0; 163 } 164 165 } 166 167 this->Local().AlignmentBegin() = this->Local().Begin(); 168 this->Local().AlignmentEnd() = this->local.End(); 169 170 this->Extent().Size() = grid.Extent().Size(); 171 this->Extent().SizeFactor() = grid.Extent().SizeFactor(); 172 this->Extent().Begin() = grid.Extent().Begin(); 173 this->Extent().End() = grid.Extent().End(); 174 this->Extent().MeshWidth() = 0.5 * grid.Extent().MeshWidth(); 175 176 this->level = grid.Level() + 1; 177 178 iterators.SetSubgrids(local); 179 180 Allocate(); 181 } 182 183 void TempGrid::SetPropertiesToCoarser(const Grid& grid, const Boundary& boundary) 184 { 185 assert(grid.Father() != NULL); 186 assert(grid.Level() > grid.Father()->MinLevel()); 187 188 const Index off = GridIndexTranslations::EndOffset(boundary); 189 190 this->level = grid.Level() - 1; 191 192 this->Global().BeginFinest() = grid.Global().BeginFinest(); 193 this->Global().EndFinest() = grid.Global().EndFinest(); 194 this->Global().SizeFinest() = grid.Global().SizeFinest(); 195 196 this->Global().BeginLocal() = grid.Global().BeginLocal(); 197 this->Global().EndLocal() = grid.Global().EndLocal(); 198 199 GridIndexTranslations::FineToCoarse(this->Global().BeginLocal(), this->Global().EndLocal()); 200 201 this->Global().SizeLocal() = this->Global().EndLocal() - this->Global().BeginLocal(); 202 this->Global().SizeGlobal() = (grid.Global().SizeGlobal()-off)/2 + off; 203 this->Global().BoundaryType() = (*(grid.Father()))(grid.Level()-1).Global().BoundaryType(); 204 205 this->Local().SizeTotal() = this->Global().SizeLocal(); 206 this->Local().Size() = this->Global().SizeLocal(); 207 this->Local().Begin() = 0; 208 this->Local().End() = this->Global().SizeLocal(); 209 210 for (int i=0; i<3; ++i) { 211 212 if (grid.Local().HaloEnd1()[i] - grid.Local().HaloBegin1()[i] > 0) { 213 this->Local().SizeTotal()[i] += 1; 214 this->Local().Begin()[i] += 1; 215 this->Local().End()[i] += 1; 216 this->Local().HaloBegin1()[i] = 0; 217 this->Local().HaloEnd1()[i] = 1; 218 }else { 219 this->Local().HaloBegin1()[i] = 0; 220 this->Local().HaloEnd1()[i] = 0; 221 } 222 223 if (grid.Local().BoundaryEnd1()[i] - grid.Local().BoundaryBegin1()[i] > 0) { 224 this->Local().Size()[i] -= 1; 225 this->Local().Begin()[i] += 1; 226 this->Local().BoundaryBegin1()[i] = 0; 227 this->Local().BoundaryEnd1()[i] = 1; 228 }else { 229 this->Local().BoundaryBegin1()[i] = 0; 230 this->Local().BoundaryEnd1()[i] = 0; 231 } 232 233 if (grid.Local().HaloEnd2()[i] - grid.Local().HaloBegin2()[i] > 0) { 234 this->Local().SizeTotal()[i] += 1; 235 this->Local().HaloBegin2()[i] = this->Local().End()[i]; 236 this->Local().HaloEnd2()[i] = this->Local().End()[i] + 1; 237 }else { 238 this->Local().HaloBegin2()[i] = 0; 239 this->Local().HaloEnd2()[i] = 0; 240 } 241 242 if (grid.Local().BoundaryEnd2()[i] - grid.Local().BoundaryBegin2()[i] > 0) { 243 this->Local().Size()[i] -= 1; 244 this->Local().End()[i] -= 1; 245 this->Local().BoundaryBegin2()[i] = this->Local().End()[i]; 246 this->Local().BoundaryEnd2()[i] = this->Local().End()[i]+1; 247 }else { 248 this->Local().BoundaryBegin2()[i] = 0; 249 this->Local().BoundaryEnd2()[i] = 0; 250 } 251 252 } 253 254 this->Local().AlignmentBegin() = this->Local().Begin(); 255 this->Local().AlignmentEnd() = this->local.End(); 256 257 this->Extent().Size() = grid.Extent().Size(); 258 this->Extent().SizeFactor() = grid.Extent().SizeFactor(); 259 this->Extent().Begin() = grid.Extent().Begin(); 260 this->Extent().End() = grid.Extent().End(); 261 this->Extent().MeshWidth() = 2.0 * grid.Extent().MeshWidth(); 262 263 iterators.SetSubgrids(local); 264 265 Allocate(); 266 } 267 268 void TempGrid::ImportFromResidual(Grid& sol, Grid& rhs) 46 269 { 47 270 #ifdef DEBUG … … 50 273 #endif 51 274 275 Grid::iterator grid_iter; 276 Stencil::iterator stencil_iter; 52 277 vmg_float residual; 53 278 Index i; … … 58 283 this->Clear(); 59 284 60 for (i.X()=Local().Begin().X(); i.X()<Local().End().X(); ++i.X())61 for (i.Y()=Local().Begin().Y(); i.Y()<Local().End().Y(); ++i.Y()) 62 for (i.Z()=Local().Begin().Z(); i.Z()<Local().End().Z(); ++i.Z()) {63 64 residual = rhs.GetVal(i) - prefactor * A.GetDiag() * sol.GetVal(i);65 66 for (Stencil::iterator iter=A.begin(); iter!=A.end(); iter++)67 residual -= prefactor * iter->val * sol.GetVal(i+iter);68 69 (*this)(i) = residual;70 71 }285 MG::GetComm()->CommToGhosts(sol); 286 287 for (grid_iter=Iterators().Local().Begin(); grid_iter!=Iterators().Local().End(); ++grid_iter) { 288 289 residual = rhs.GetVal(*grid_iter) - prefactor * A.GetDiag() * sol.GetVal(*grid_iter); 290 291 for (stencil_iter=A.begin(); stencil_iter!=A.end(); ++stencil_iter) 292 residual -= prefactor * stencil_iter->Val() * sol.GetVal(*grid_iter + stencil_iter->Disp()); 293 294 (*this)(*grid_iter) = residual; 295 296 } 72 297 73 298 MG::GetComm()->CommToGhosts(*this); 74 299 } 75 300 301 void TempGrid::Allocate() 302 { 303 const int size = local.SizeTotal().Product(); 304 305 if (size > size_max) { 306 size_max = size; 307 delete [] grid; 308 grid = new vmg_float[size]; 309 } 310 } 311 312 TempGrid::TempGrid() 313 { 314 size_max = 0; 315 } 316 76 317 TempGrid::~TempGrid() 77 318 {
Note:
See TracChangeset
for help on using the changeset viewer.
