Ignore:
Timestamp:
Apr 27, 2012, 11:34:57 PM (14 years ago)
Author:
Julian Iseringhausen <isering@…>
Children:
1a92cf
Parents:
b2154a3
Message:

vmg: Implement fourth-order discretization of the Poisson equation.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1762 5161e1c8-67bf-11de-9fd5-51895aff932f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/interface/interface_particles.cpp

    rb2154a3 r4571da  
    2020#endif
    2121
     22#include <algorithm>
    2223#include <cmath>
    2324#include <cstring>
     
    8586    for (index.Y()=0; index.Y()<grid.Local().Size().Y(); ++index.Y())
    8687      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());
    8889
    8990#ifdef DEBUG_OUTPUT
     
    99100void InterfaceParticles::ExportSolution(Grid& grid)
    100101{
    101   Index index;
     102  Index i;
    102103  vmg_float length;
    103   Vector dist_vec;
    104104
    105105#ifdef DEBUG_OUTPUT
     
    107107  vmg_float e_long = 0.0;
    108108  vmg_float e_self = 0.0;
    109   vmg_float e_short = 0.0;
    110   vmg_float e_shortcorr = 0.0;
     109  vmg_float e_short_peak = 0.0;
     110  vmg_float e_short_spline = 0.0;
    111111#endif
    112112
     
    125125  InterpolatePolynomial ip(interpolation_degree);
    126126
    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);
    137131
    138132  /*
     
    143137  Grid& particle_grid = comm.GetParticleGrid();
    144138
    145   for (index.X()=0; index.X()<grid.Local().Size().X(); ++index.X())
    146     for (index.Y()=0; index.Y()<grid.Local().Size().Y(); ++index.Y())
    147       for (index.Z()=0; index.Z()<grid.Local().Size().Z(); ++index.Z())
    148         particle_grid(index + 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());
    149143
    150144  comm.CommToGhosts(particle_grid);
     
    170164
    171165#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());
    174167      e_self += 0.5 * (*p1)->Charge() * (*p1)->Charge() * spl.GetAntiDerivativeAtZero();
    175168#endif
    176169
    177       for (index.X()=-1*near_field_cells-1; index.X()<=near_field_cells+1; ++index.X())
    178         for (index.Y()=-1*near_field_cells-1; index.Y()<=near_field_cells+1; ++index.Y())
    179           for (index.Z()=-1*near_field_cells-1; index.Z()<=near_field_cells+1; ++index.Z()) {
    180 
    181             std::list<Particle::Particle*>& lc_2 = lc(*iter+index);
     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);
    182175
    183176            for (p2=lc_2.begin(); p2!=lc_2.end(); ++p2)
     
    186179                length = ((*p2)->Pos() - (*p1)->Pos()).Length();
    187180
    188                 //TODO Rewrite this equation more efficiently
    189181                if (length < r_cut) {
    190182                  (*p1)->Pot() += (*p2)->Charge() / length * (1.0 + spl.EvaluatePotential(length));
    191183
    192184#ifdef DEBUG_OUTPUT
    193                   e_short += 0.5 * (*p1)->Charge() * (*p2)->Charge() / length;
    194                   e_shortcorr -= 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);
    195187#endif
    196188                }
     
    205197  vmg_float* q = factory.GetObjectStorageArray<vmg_float>("PARTICLE_CHARGE_ARRAY");
    206198
    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];
    210206  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);
    222214
    223215#endif /* DEBUG_OUTPUT */
Note: See TracChangeset for help on using the changeset viewer.