Changeset 894a5f for src/smoother/gsrb.cpp
- Timestamp:
- Feb 2, 2012, 1:58:12 PM (14 years ago)
- Children:
- 32ff22
- Parents:
- 01be70
- File:
-
- 1 edited
-
src/smoother/gsrb.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/smoother/gsrb.cpp
r01be70 r894a5f 12 12 #endif 13 13 14 #include <sstream> 15 14 16 #include "base/discretization.hpp" 15 #include "base/timer.hpp"16 17 #include "base/stencil.hpp" 17 18 #include "comm/comm.hpp" … … 20 21 21 22 using namespace VMG; 23 24 static inline void ComputePartial(Grid& sol, Grid& rhs, const Stencil& mat, 25 const Index& begin, const Index& end, 26 const vmg_float& prefactor, const vmg_float& diag_inv, 27 const int& off) 28 { 29 int i,j,k; 30 vmg_float temp; 31 Stencil::iterator iter; 32 33 for (i=begin.X(); i<end.X(); ++i) 34 for (j=begin.Y(); j<end.Y(); ++j) 35 for (k=begin.Z()+((i+j+off)%2); k<end.Z(); k+=2) { 36 37 temp = prefactor * rhs.GetVal(i,j,k); 38 39 for (iter=mat.begin(); iter!=mat.end(); ++iter) 40 temp -= iter->Val() * sol.GetVal(i+iter->Disp().X(), 41 j+iter->Disp().Y(), 42 k+iter->Disp().Z()); 43 44 sol(i,j,k) = temp * diag_inv; 45 46 } 47 } 22 48 23 49 void GaussSeidelRB::Compute(Grid& sol, Grid& rhs) … … 32 58 #endif 33 59 34 Timer::Start("SmootherWithoutCommunication"); 60 const Stencil& mat = MG::GetDiscretization()->GetStencil(); 61 const vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(sol); 62 const vmg_float diag_inv = 1.0 / mat.GetDiag(); 63 const int off = rhs.Global().BeginLocal().Sum() - rhs.Local().HasHalo1().Sum(); 64 Comm& comm = *MG::GetComm(); 35 65 36 Index i; 37 vmg_float temp; 38 const Stencil& A = MG::GetDiscretization()->GetStencil(); 39 const vmg_float prefactor_inv = 1.0 / MG::GetDiscretization()->OperatorPrefactor(sol); 40 const vmg_float diag_inv = 1.0 / A.GetDiag(); 41 const int off = rhs.Global().BeginLocal().Sum() - rhs.Local().HasHalo1().Sum(); 66 /* 67 * Compute first halfstep 68 */ 42 69 43 for (i.X()=rhs.Local().Begin().X(); i.X()<rhs.Local().End().X(); ++i.X()) 44 for (i.Y()=rhs.Local().Begin().Y(); i.Y()<rhs.Local().End().Y(); ++i.Y()) 45 for (i.Z()=rhs.Local().Begin().Z() + ((i.X()+i.Y()+off+1) % 2); i.Z()<rhs.Local().End().Z(); i.Z()+=2) { 70 // Start asynchronous communication 71 comm.CommToGhostsAsyncStart(sol); 46 72 47 temp = prefactor_inv * rhs.GetVal(i); 73 // Smooth part not depending on ghost cells 74 ComputePartial(sol, rhs, mat, 75 rhs.Local().Begin()+1, rhs.Local().End()-1, 76 prefactor_inv, diag_inv, off+1); 48 77 49 for (Stencil::iterator iter=A.begin(); iter!=A.end(); ++iter) 50 temp -= iter->Val() * sol.GetVal(i + iter->Disp());78 // Finish asynchronous communication 79 comm.CommToGhostsAsyncFinish(); 51 80 52 sol(i) = temp * diag_inv; 81 /* 82 * Smooth near boundary cells 83 */ 53 84 54 } 85 ComputePartial(sol, rhs, mat, 86 rhs.Local().Begin(), 87 Index(rhs.Local().Begin().X()+1, rhs.Local().End().Y(), rhs.Local().End().Z()), 88 prefactor_inv, diag_inv, off+1); 55 89 56 Timer::Stop("SmootherWithoutCommunication"); 90 ComputePartial(sol, rhs, mat, 91 Index(rhs.Local().End().X()-1, rhs.Local().Begin().Y(), rhs.Local().Begin().Z()), 92 rhs.Local().End(), 93 prefactor_inv, diag_inv, off+1); 57 94 58 MG::GetComm()->CommToGhosts(sol); 95 ComputePartial(sol, rhs, mat, 96 Index(rhs.Local().Begin().X()+1, rhs.Local().Begin().Y(), rhs.Local().Begin().Z()), 97 Index(rhs.Local().End().X()-1, rhs.Local().Begin().Y()+1, rhs.Local().End().Z()), 98 prefactor_inv, diag_inv, off+1); 59 99 60 Timer::Start("SmootherWithoutCommunication"); 100 ComputePartial(sol, rhs, mat, 101 Index(rhs.Local().Begin().X()+1, rhs.Local().End().Y()-1, rhs.Local().Begin().Z()), 102 Index(rhs.Local().End().X()-1, rhs.Local().End().Y(), rhs.Local().End().Z()), 103 prefactor_inv, diag_inv, off+1); 61 104 62 for (i.X()=rhs.Local().Begin().X(); i.X()<rhs.Local().End().X(); ++i.X()) 63 for (i.Y()=rhs.Local().Begin().Y(); i.Y()<rhs.Local().End().Y(); ++i.Y()) 64 for (i.Z()=rhs.Local().Begin().Z() + ((i.X()+i.Y()+off) % 2); i.Z()<rhs.Local().End().Z(); i.Z()+=2) { 105 ComputePartial(sol, rhs, mat, 106 Index(rhs.Local().Begin().X()+1, rhs.Local().Begin().Y()+1, rhs.Local().Begin().Z()), 107 Index(rhs.Local().End().X()-1, rhs.Local().End().Y()-1, rhs.Local().Begin().Z()+1), 108 prefactor_inv, diag_inv, off+1); 65 109 66 temp = prefactor_inv * rhs.GetVal(i); 110 ComputePartial(sol, rhs, mat, 111 Index(rhs.Local().Begin().X()+1, rhs.Local().Begin().Y()+1, rhs.Local().End().Z()-1), 112 Index(rhs.Local().End().X()-1, rhs.Local().End().Y()-1, rhs.Local().End().Z()), 113 prefactor_inv, diag_inv, off+1); 67 114 68 for (Stencil::iterator iter=A.begin(); iter!=A.end(); ++iter) 69 temp -= iter->Val() * sol.GetVal(i + iter->Disp()); 115 /* 116 * Compute second halfstep 117 */ 70 118 71 sol(i) = temp * diag_inv; 119 // Start asynchronous communication 120 comm.CommToGhostsAsyncStart(sol); 72 121 73 } 122 // Smooth part not depending on ghost cells 123 ComputePartial(sol, rhs, mat, 124 rhs.Local().Begin()+1, rhs.Local().End()-1, 125 prefactor_inv, diag_inv, off); 74 126 75 Timer::Stop("SmootherWithoutCommunication"); 127 // Finish asynchronous communication 128 comm.CommToGhostsAsyncFinish(); 129 130 /* 131 * Smooth near boundary cells 132 */ 133 134 ComputePartial(sol, rhs, mat, 135 rhs.Local().Begin(), 136 Index(rhs.Local().Begin().X()+1, rhs.Local().End().Y(), rhs.Local().End().Z()), 137 prefactor_inv, diag_inv, off); 138 139 ComputePartial(sol, rhs, mat, 140 Index(rhs.Local().End().X()-1, rhs.Local().Begin().Y(), rhs.Local().Begin().Z()), 141 rhs.Local().End(), 142 prefactor_inv, diag_inv, off); 143 144 ComputePartial(sol, rhs, mat, 145 Index(rhs.Local().Begin().X()+1, rhs.Local().Begin().Y(), rhs.Local().Begin().Z()), 146 Index(rhs.Local().End().X()-1, rhs.Local().Begin().Y()+1, rhs.Local().End().Z()), 147 prefactor_inv, diag_inv, off); 148 149 ComputePartial(sol, rhs, mat, 150 Index(rhs.Local().Begin().X()+1, rhs.Local().End().Y()-1, rhs.Local().Begin().Z()), 151 Index(rhs.Local().End().X()-1, rhs.Local().End().Y(), rhs.Local().End().Z()), 152 prefactor_inv, diag_inv, off); 153 154 ComputePartial(sol, rhs, mat, 155 Index(rhs.Local().Begin().X()+1, rhs.Local().Begin().Y()+1, rhs.Local().Begin().Z()), 156 Index(rhs.Local().End().X()-1, rhs.Local().End().Y()-1, rhs.Local().Begin().Z()+1), 157 prefactor_inv, diag_inv, off); 158 159 ComputePartial(sol, rhs, mat, 160 Index(rhs.Local().Begin().X()+1, rhs.Local().Begin().Y()+1, rhs.Local().End().Z()-1), 161 Index(rhs.Local().End().X()-1, rhs.Local().End().Y()-1, rhs.Local().End().Z()), 162 prefactor_inv, diag_inv, off); 76 163 }
Note:
See TracChangeset
for help on using the changeset viewer.
