Changeset 4571da for src/interface/interface_particles.cpp
- Timestamp:
- Apr 27, 2012, 11:34:57 PM (14 years ago)
- Children:
- 1a92cf
- Parents:
- b2154a3
- File:
-
- 1 edited
-
src/interface/interface_particles.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/interface/interface_particles.cpp
rb2154a3 r4571da 20 20 #endif 21 21 22 #include <algorithm> 22 23 #include <cmath> 23 24 #include <cstring> … … 85 86 for (index.Y()=0; index.Y()<grid.Local().Size().Y(); ++index.Y()) 86 87 for (index.Z()=0; index.Z()<grid.Local().Size().Z(); ++index.Z()) 87 grid(index + grid.Local().Begin()) = 4.0 * Math::pi * particle_grid.GetVal(index + particle_grid.Local().Begin());88 grid(index + grid.Local().Begin()) = 4.0 * Math::pi * particle_grid.GetVal(index + particle_grid.Local().Begin()); 88 89 89 90 #ifdef DEBUG_OUTPUT … … 99 100 void InterfaceParticles::ExportSolution(Grid& grid) 100 101 { 101 Index i ndex;102 Index i; 102 103 vmg_float length; 103 Vector dist_vec;104 104 105 105 #ifdef DEBUG_OUTPUT … … 107 107 vmg_float e_long = 0.0; 108 108 vmg_float e_self = 0.0; 109 vmg_float e_short = 0.0;110 vmg_float e_short corr= 0.0;109 vmg_float e_short_peak = 0.0; 110 vmg_float e_short_spline = 0.0; 111 111 #endif 112 112 … … 125 125 InterpolatePolynomial ip(interpolation_degree); 126 126 127 const vmg_float r_cut = (near_field_cells+0.5) * grid.Extent().MeshWidth().Max(); 128 129 /* 130 * Initialize potential 131 */ 132 for (vmg_int i=0; i<num_particles_local; ++i) { 133 p[i] = 0.0; 134 for (vmg_int j=0;j<3;++j) 135 f[3*i+j] = 0.; 136 } 127 const vmg_float r_cut = near_field_cells * grid.Extent().MeshWidth().Max(); 128 129 // Initialize field 130 std::fill(f, f+3*num_particles_local, 0.0); 137 131 138 132 /* … … 143 137 Grid& particle_grid = comm.GetParticleGrid(); 144 138 145 for (i ndex.X()=0; index.X()<grid.Local().Size().X(); ++index.X())146 for (i ndex.Y()=0; index.Y()<grid.Local().Size().Y(); ++index.Y())147 for (i ndex.Z()=0; index.Z()<grid.Local().Size().Z(); ++index.Z())148 particle_grid(i ndex + particle_grid.Local().Begin()) = grid.GetVal(index+ grid.Local().Begin());139 for (i.X()=0; i.X()<grid.Local().Size().X(); ++i.X()) 140 for (i.Y()=0; i.Y()<grid.Local().Size().Y(); ++i.Y()) 141 for (i.Z()=0; i.Z()<grid.Local().Size().Z(); ++i.Z()) 142 particle_grid(i + particle_grid.Local().Begin()) = grid.GetVal(i + grid.Local().Begin()); 149 143 150 144 comm.CommToGhosts(particle_grid); … … 170 164 171 165 #ifdef DEBUG_OUTPUT 172 // TODO The scaling with 1/2 may not be correct. Check that. 173 e_long += 0.5 * (*p1)->Charge() * Helper::InterpolateTrilinear((*p1)->Pos(), particle_grid); 166 e_long += 0.5 * (*p1)->Charge() * ip.Evaluate((*p1)->Pos()); 174 167 e_self += 0.5 * (*p1)->Charge() * (*p1)->Charge() * spl.GetAntiDerivativeAtZero(); 175 168 #endif 176 169 177 for (i ndex.X()=-1*near_field_cells-1; index.X()<=near_field_cells+1; ++index.X())178 for (i ndex.Y()=-1*near_field_cells-1; index.Y()<=near_field_cells+1; ++index.Y())179 for (i ndex.Z()=-1*near_field_cells-1; index.Z()<=near_field_cells+1; ++index.Z()) {180 181 std::list<Particle::Particle*>& lc_2 = lc(*iter+i ndex);170 for (i.X()=-1*near_field_cells; i.X()<=near_field_cells; ++i.X()) 171 for (i.Y()=-1*near_field_cells; i.Y()<=near_field_cells; ++i.Y()) 172 for (i.Z()=-1*near_field_cells; i.Z()<=near_field_cells; ++i.Z()) { 173 174 std::list<Particle::Particle*>& lc_2 = lc(*iter+i); 182 175 183 176 for (p2=lc_2.begin(); p2!=lc_2.end(); ++p2) … … 186 179 length = ((*p2)->Pos() - (*p1)->Pos()).Length(); 187 180 188 //TODO Rewrite this equation more efficiently189 181 if (length < r_cut) { 190 182 (*p1)->Pot() += (*p2)->Charge() / length * (1.0 + spl.EvaluatePotential(length)); 191 183 192 184 #ifdef DEBUG_OUTPUT 193 e_short += 0.5 * (*p1)->Charge() * (*p2)->Charge() / length;194 e_short corr -= 0.5 * (*p1)->Charge() * (*p2)->Charge() / length * spl.EvaluatePotential(length);185 e_short_peak += 0.5 * (*p1)->Charge() * (*p2)->Charge() / length; 186 e_short_spline += 0.5 * (*p1)->Charge() * (*p2)->Charge() / length * spl.EvaluatePotential(length); 195 187 #endif 196 188 } … … 205 197 vmg_float* q = factory.GetObjectStorageArray<vmg_float>("PARTICLE_CHARGE_ARRAY"); 206 198 207 for (int i=0; i<num_particles_local; ++i) 208 e += 0.5 * p[i] * q[i]; 209 199 e_long = comm.GlobalSumRoot(e_long); 200 e_short_peak = comm.GlobalSumRoot(e_short_peak); 201 e_short_spline = comm.GlobalSumRoot(e_short_spline); 202 e_self = comm.GlobalSumRoot(e_self); 203 204 for (int j=0; j<num_particles_local; ++j) 205 e += 0.5 * p[j] * q[j]; 210 206 e = comm.GlobalSumRoot(e); 211 e_long = comm.GlobalSumRoot(e_long); 212 e_self = comm.GlobalSumRoot(e_self); 213 e_short = comm.GlobalSumRoot(e_short); 214 e_shortcorr = comm.GlobalSumRoot(e_shortcorr); 215 216 comm.PrintStringOnce("E_long: %e", e_long); 217 comm.PrintStringOnce("E_short: %e", e_short); 218 comm.PrintStringOnce("E_shortcorr: %e", e_shortcorr); 219 comm.PrintStringOnce("E_short*: %e", e - e_long + e_self); 220 comm.PrintStringOnce("E_self: %e", e_self); 221 comm.PrintStringOnce("E_total: %e", e); 207 208 comm.PrintStringOnce("E_long: %e", e_long); 209 comm.PrintStringOnce("E_short_peak: %e", e_short_peak); 210 comm.PrintStringOnce("E_short_spline: %e", e_short_spline); 211 comm.PrintStringOnce("E_self: %e", e_self); 212 comm.PrintStringOnce("E_total: %e", e); 213 comm.PrintStringOnce("E_total*: %e", e_long + e_short_peak + e_short_spline - e_self); 222 214 223 215 #endif /* DEBUG_OUTPUT */
Note:
See TracChangeset
for help on using the changeset viewer.
