Changeset 894a5f for src/interface/interface_particles.cpp
- Timestamp:
- Feb 2, 2012, 1:58:12 PM (14 years ago)
- Children:
- 32ff22
- Parents:
- 01be70
- File:
-
- 1 edited
-
src/interface/interface_particles.cpp (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/interface/interface_particles.cpp
r01be70 r894a5f 22 22 #include "base/index.hpp" 23 23 #include "base/linked_cell_list.hpp" 24 #include "base/timer.hpp"25 24 #include "base/vector.hpp" 26 25 #include "comm/comm.hpp" … … 35 34 void InterfaceParticles::ImportRightHandSide(Multigrid& multigrid) 36 35 { 37 Timer::Start("Particle/Grid Interpolation");38 39 36 Index index_global, index_local, index; 40 37 Vector pos_rel, pos_abs, grid_val; 41 38 42 39 Factory& factory = MG::GetFactory(); 40 Comm& comm = *MG::GetComm(); 43 41 44 42 const int& near_field_cells = factory.GetObjectStorageVal<int>("PARTICLE_NEAR_FIELD_CELLS"); 45 43 46 TempGrid* temp_grid = GetTempGrid(0);47 44 Grid& grid = multigrid(multigrid.GlobalMaxLevel()); 48 LocalIndices local = grid.Local(); 49 50 // We don't need a boundary on this grid 51 local.End() -= local.Begin(); 52 local.Begin() = 0; 53 local.BoundaryBegin1() = local.BoundaryEnd1() = 0; 54 local.BoundaryBegin2() = local.BoundaryEnd2() = 0; 55 56 // Set grid size of intermediate temporary grid 57 for (int i=0; i<3; ++i) { 58 59 if (local.HasHalo1()[i]) { 60 local.HaloBegin1()[i] = 0; 61 local.HaloEnd1()[i] = local.Begin()[i] = near_field_cells+1; 62 local.End()[i] = local.Begin()[i] + local.Size()[i]; 63 } 64 65 if (local.HasHalo2()[i]) { 66 local.HaloBegin2()[i] = local.End()[i]; 67 local.HaloEnd2()[i] = local.HaloBegin2()[i] + near_field_cells+1; 68 } 69 70 } 71 72 local.SizeTotal() = local.Size() + 73 local.HaloEnd1() - local.HaloBegin1() + 74 local.HaloEnd2() - local.HaloBegin2(); 75 76 temp_grid->SetProperties(grid.Global(), local, grid.Extent()); 77 temp_grid->Clear(); 45 Grid& particle_grid = comm.GetParticleGrid(); 46 47 particle_grid.Clear(); 78 48 79 49 /* … … 81 51 */ 82 52 particles.clear(); 83 MG::GetComm()->CommParticles(grid, particles);53 comm.CommParticles(grid, particles); 84 54 85 55 /* … … 93 63 particle_charges += iter->Charge(); 94 64 particle_charges = MG::GetComm()->GlobalSumRoot(particle_charges); 95 MG::GetComm()->PrintStringOnce("Particle list charge sum: %e", particle_charges);65 comm.PrintStringOnce("Particle list charge sum: %e", particle_charges); 96 66 #endif 97 67 98 68 for (iter=particles.begin(); iter!=particles.end(); ++iter) 99 spl.SetSpline( *temp_grid, *iter, near_field_cells);69 spl.SetSpline(particle_grid, *iter, near_field_cells); 100 70 101 71 // Communicate charges over halo 102 MG::GetComm()->CommFromGhosts(*temp_grid);72 comm.CommFromGhosts(particle_grid); 103 73 104 74 // Assign charge values to the right hand side … … 106 76 for (index.Y()=0; index.Y()<grid.Local().Size().Y(); ++index.Y()) 107 77 for (index.Z()=0; index.Z()<grid.Local().Size().Z(); ++index.Z()) 108 grid(index + grid.Local().Begin()) = temp_grid->GetVal(index + temp_grid->Local().Begin()); 109 110 Timer::Stop("Particle/Grid Interpolation"); 78 grid(index + grid.Local().Begin()) = particle_grid.GetVal(index + particle_grid.Local().Begin()); 111 79 112 80 #ifdef DEBUG_OUTPUT … … 116 84 charge_sum += grid.GetVal(*grid_iter); 117 85 charge_sum = MG::GetComm()->GlobalSum(charge_sum); 118 MG::GetComm()->PrintStringOnce("Grid charge sum: %e", charge_sum);86 comm.PrintStringOnce("Grid charge sum: %e", charge_sum); 119 87 #endif 120 88 } … … 122 90 void InterfaceParticles::ExportSolution(Grid& grid) 123 91 { 124 Timer::Start("Grid/Particle Interpolation");125 126 92 Index index; 127 93 vmg_float length; … … 135 101 136 102 Factory& factory = MG::GetFactory(); 137 Comm * comm =MG::GetComm();103 Comm& comm = *MG::GetComm(); 138 104 139 105 /* … … 161 127 * The parameters of this grid have been set in the import step. 162 128 */ 163 TempGrid* temp_grid = GetTempGrid(0);129 Grid& particle_grid = comm.GetParticleGrid(); 164 130 165 131 for (index.X()=0; index.X()<grid.Local().Size().X(); ++index.X()) 166 132 for (index.Y()=0; index.Y()<grid.Local().Size().Y(); ++index.Y()) 167 133 for (index.Z()=0; index.Z()<grid.Local().Size().Z(); ++index.Z()) 168 (*temp_grid)(index + temp_grid->Local().Begin()) = grid.GetVal(index + grid.Local().Begin());169 170 comm ->CommToGhosts(*temp_grid);134 particle_grid(index + particle_grid.Local().Begin()) = grid.GetVal(index + grid.Local().Begin()); 135 136 comm.CommToGhosts(particle_grid); 171 137 172 138 /* … … 177 143 178 144 // Interpolate long range part of potential 179 p_iter->Pot() = 0.5 * (Helper::InterpolateTrilinear(p_iter->Pos(), *temp_grid) - p_iter->Charge() * spl.GetAntiDerivativeZero());180 181 #ifdef DEBUG_OUTPUT 182 e_long += 0.5 * p_iter->Charge() * Helper::InterpolateTrilinear(p_iter->Pos(), *temp_grid);145 p_iter->Pot() = 0.5 * (Helper::InterpolateTrilinear(p_iter->Pos(), particle_grid) - p_iter->Charge() * spl.GetAntiDerivativeZero()); 146 147 #ifdef DEBUG_OUTPUT 148 e_long += 0.5 * p_iter->Charge() * Helper::InterpolateTrilinear(p_iter->Pos(), particle_grid); 183 149 e_self += 0.5 * p_iter->Charge() * p_iter->Charge() * spl.GetAntiDerivativeZero(); 184 150 #endif … … 186 152 } 187 153 188 comm ->CommAddPotential(particles);154 comm.CommAddPotential(particles); 189 155 190 156 /* … … 195 161 Grid::iterator iter; 196 162 197 comm ->CommLCListGhosts(grid, lc);163 comm.CommLCListGhosts(grid, lc); 198 164 199 165 for (iter=lc.Iterators().Local().Begin(); iter!=lc.Iterators().Local().End(); ++iter) … … 213 179 } 214 180 215 comm->CommAddPotential(lc); 216 217 Timer::Stop("Grid/Particle Interpolation"); 181 comm.CommAddPotential(lc); 218 182 219 183 #ifdef DEBUG_OUTPUT … … 223 187 e += p[i] * q[i]; 224 188 225 e = comm ->GlobalSumRoot(e);226 e_long = comm ->GlobalSumRoot(e_long);227 e_self = comm ->GlobalSumRoot(e_self);228 229 comm ->PrintStringOnce("E_long: %e", e_long);230 comm ->PrintStringOnce("E_short: %e", e - e_long + e_self);231 comm ->PrintStringOnce("E_self: %e", e_self);232 comm ->PrintStringOnce("E_total: %e", e);189 e = comm.GlobalSumRoot(e); 190 e_long = comm.GlobalSumRoot(e_long); 191 e_self = comm.GlobalSumRoot(e_self); 192 193 comm.PrintStringOnce("E_long: %e", e_long); 194 comm.PrintStringOnce("E_short: %e", e - e_long + e_self); 195 comm.PrintStringOnce("E_self: %e", e_self); 196 comm.PrintStringOnce("E_total: %e", e); 233 197 234 198 #endif /* DEBUG_OUTPUT */
Note:
See TracChangeset
for help on using the changeset viewer.
