Changeset ac6d04 for src/level/level_operator_cs.cpp
- Timestamp:
- Apr 10, 2012, 1:55:49 PM (14 years ago)
- Children:
- a40eea
- Parents:
- d24c2f
- File:
-
- 1 edited
-
src/level/level_operator_cs.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/level/level_operator_cs.cpp
rd24c2f rac6d04 22 22 using namespace VMG; 23 23 24 void LevelOperatorCS::Restrict( Grid& sol_f, Grid& rhs_f, Grid& sol_c, Grid& rhs_c)24 void LevelOperatorCS::Restrict(Multigrid& sol, Multigrid& rhs) 25 25 { 26 #ifdef DEBUG_MATRIX_CHECKS 27 sol_f.IsConsistent(); 28 rhs_f.IsConsistent(); 29 #endif 26 Grid::iterator iter_f, iter_c; 30 27 31 #ifdef DEBUG 32 sol_f.IsCompatible(rhs_f); 33 #endif 28 Comm& comm = *MG::GetComm(); 34 29 35 Grid::iterator iter_f, iter_c; 36 Stencil::iterator stencil_iter; 37 vmg_float res; 30 Grid& sol_f = sol(sol.Level()); 31 Grid& rhs_f = rhs(rhs.Level()); 32 33 Grid& sol_c_dist = sol(sol.Level()-1); 34 Grid& rhs_c_dist = rhs(rhs.Level()-1); 35 36 Grid& sol_c_undist = comm.GetCoarserGrid(sol); 37 Grid& rhs_c_undist = comm.GetCoarserGrid(rhs); 38 38 39 39 const Stencil& op = OperatorRestrict(); 40 40 41 Index begin_f = rhs_f.Local().Begin() + 2*rhs_c.Global().BeginLocal() - rhs_f.Global().BeginLocal(); 42 Index end_f = rhs_f.Local().End(); 41 const Index begin_f_global = rhs_f.Global().LocalBegin() + rhs_f.Global().LocalBegin() % 2; 42 const Index end_f_global = rhs_f.Global().LocalEnd() - (rhs_f.Global().LocalEnd() - 1) % 2; 43 44 assert(begin_f_global % 2 == 0); 45 assert(end_f_global % 2 == 1); 46 47 Index begin_f = begin_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin(); 48 Index end_f = end_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin(); 43 49 44 50 /* Modify fine begin/end to align the points on both levels correctly */ 45 if (rhs_c.Global().BoundaryType() == GlobalCoarsened) 46 for (int i=0; i<3; ++i) { 51 if (rhs_c_undist.Global().BoundaryType() == GlobalCoarsened) { 52 begin_f += rhs_f.Local().BoundarySize1(); 53 end_f -= rhs_f.Local().BoundarySize2(); 54 } 47 55 48 if (rhs_c.Local().HasBoundary1()[i]) 49 ++begin_f[i]; 50 51 if (rhs_c.Local().HasBoundary2()[i]) 52 --end_f[i]; 53 54 } 56 const Index begin_c = rhs_c_undist.Local().Begin() + begin_f_global / 2 - rhs_c_undist.Global().LocalBegin(); 57 const Index end_c = rhs_c_undist.Local().Begin() + end_f_global / 2 - rhs_c_undist.Global().LocalBegin() + 1; 55 58 56 59 const GridIteratorSet bounds_f(begin_f, end_f); 57 const GridIteratorSet bounds_c( rhs_c.Local().AlignmentBegin(), rhs_c.Local().AlignmentEnd());60 const GridIteratorSet bounds_c(begin_c, end_c); 58 61 59 62 // Compute residual … … 61 64 temp->SetProperties(sol_f); 62 65 temp->ImportFromResidual(sol_f, rhs_f); 66 comm.CommToGhosts(*temp); 63 67 64 if (rhs_c.Global().BoundaryType() == GlobalCoarsened)65 rhs_c .ClearBoundary();68 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_f!=bounds_f.End(); iter_f+=2, ++iter_c) 69 rhs_c_undist(*iter_c) = op.Apply(*temp, *iter_f); 66 70 67 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {71 comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1); 68 72 69 res = op.GetDiag() * temp->GetVal(*iter_f); 73 if (rhs_c_dist.Global().BoundaryType() == GlobalCoarsened) 74 rhs_c_dist.ClearBoundary(); 70 75 71 for (stencil_iter=op.begin(); stencil_iter!=op.end(); ++stencil_iter) 72 res += stencil_iter->Val() * temp->GetVal(iter_f->X() + stencil_iter->Disp().X(), 73 iter_f->Y() + stencil_iter->Disp().Y(), 74 iter_f->Z() + stencil_iter->Disp().Z()); 75 76 rhs_c(*iter_c) = res; 77 78 } 79 80 #ifdef DEBUG_MATRIX_CHECKS 81 rhs_c.IsConsistent(); 82 #endif 76 sol.ToCoarserLevel(); 77 rhs.ToCoarserLevel(); 83 78 } 84 79 85 void LevelOperatorCS::Prolongate( Grid& sol_f, Grid& rhs_f, Grid& sol_c, Grid& rhs_c)80 void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs) 86 81 { 87 #ifdef DEBUG_MATRIX_CHECKS88 sol_c.IsConsistent();89 rhs_c.IsConsistent();90 sol_f.IsConsistent();91 rhs_f.IsConsistent();92 #endif93 94 #ifdef DEBUG95 sol_c.IsCompatible(rhs_c);96 sol_f.IsCompatible(rhs_f);97 #endif98 99 82 Grid::iterator iter_f, iter_c; 100 83 Stencil::iterator stencil_iter; 101 84 vmg_float val; 102 85 86 Comm& comm = *MG::GetComm(); 87 88 Grid& sol_c = sol(sol.Level()); 89 Grid& rhs_c = rhs(rhs.Level()); 90 91 Grid& sol_f_dist = sol(sol.Level()+1); 92 Grid& rhs_f_dist = rhs(rhs.Level()+1); 93 94 Grid& sol_f_undist = comm.GetFinerGrid(sol); 95 Grid& rhs_f_undist = comm.GetFinerGrid(rhs); 96 103 97 const Stencil& op = OperatorProlongate(); 104 Comm* comm = MG::GetComm();105 98 106 Index begin_f = sol_f .Local().Begin() + 2*sol_c.Global().BeginLocal() - sol_f.Global().BeginLocal();107 Index end_f = sol_f .Local().End();99 Index begin_f = sol_f_undist.Local().Begin() + 2*sol_c.Global().LocalBegin() - sol_f_undist.Global().LocalBegin(); 100 Index end_f = sol_f_undist.Local().End(); 108 101 109 if (sol_c.Global().BoundaryType() == GlobalCoarsened) 110 for (int i=0; i<3; ++i) { 111 112 if (rhs_f.Local().HasBoundary1()[i]) 113 ++begin_f[i]; 114 115 if (rhs_f.Local().HasBoundary2()[i]) 116 --end_f[i]; 117 118 } 102 if (sol_c.Global().BoundaryType() == GlobalCoarsened) { 103 begin_f += rhs_f_undist.Local().BoundarySize1(); 104 end_f -= rhs_f_undist.Local().BoundarySize2(); 105 } 119 106 120 107 const GridIteratorSet bounds_f(begin_f, end_f); 121 const GridIteratorSet bounds_c(sol_c.Local(). AlignmentBegin(), sol_c.Local().AlignmentEnd());108 const GridIteratorSet bounds_c(sol_c.Local().FinerBeginFoo(), sol_c.Local().FinerEndFoo()); 122 109 123 Index apply_stencil_begin, apply_stencil_end;110 sol_f_undist.ClearHalo(); 124 111 125 for (int i=0; i<3; ++i) { 126 apply_stencil_begin[i] = (sol_f.Local().HasBoundary1()[i] ? 1 : 0); 127 apply_stencil_end[i] = (sol_f.Local().HasBoundary2()[i] ? sol_f.Local().End()[i] : sol_f.Local().SizeTotal()[i]); 128 } 129 130 sol_f.ClearHalo(); 112 comm.CommSubgrid(sol_f_dist, sol_f_undist, 0); 131 113 132 114 for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) { 133 115 val = sol_c.GetVal(*iter_c); 134 sol_f (*iter_f) += op.GetDiag() * val;116 sol_f_undist(*iter_f) += op.GetDiag() * val; 135 117 for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter) 136 sol_f (iter_f->X() + stencil_iter->Disp().X(),137 iter_f->Y() + stencil_iter->Disp().Y(),138 iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;118 sol_f_undist(iter_f->X() + stencil_iter->Disp().X(), 119 iter_f->Y() + stencil_iter->Disp().Y(), 120 iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val; 139 121 } 140 122 141 comm->CommFromGhosts(sol_f); 123 comm.CommFromGhosts(sol_f_undist); 124 comm.CommSubgrid(sol_f_undist, sol_f_dist, 1); 125 126 sol.ToFinerLevel(); 127 rhs.ToFinerLevel(); 142 128 }
Note:
See TracChangeset
for help on using the changeset viewer.
