Ignore:
Timestamp:
Apr 24, 2012, 2:26:14 PM (14 years ago)
Author:
Julian Iseringhausen <isering@…>
Children:
b51c3b
Parents:
e3dbbf
Message:

Fix energy calculation.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/interface/interface_particles.cpp

    re3dbbf r716da7  
    2525#include "base/helper.hpp"
    2626#include "base/index.hpp"
     27#include "base/interpolate_polynomial.hpp"
    2728#include "base/linked_cell_list.hpp"
    2829#include "base/math.hpp"
     
    101102  vmg_float length;
    102103  Vector dist_vec;
     104  InterpolatePolynomial ip(8);
    103105
    104106#ifdef DEBUG_OUTPUT
     
    119121  const int& near_field_cells = factory.GetObjectStorageVal<int>("PARTICLE_NEAR_FIELD_CELLS");
    120122  vmg_float* p = factory.GetObjectStorageArray<vmg_float>("PARTICLE_POTENTIAL_ARRAY");
    121   vmg_float* f = factory.GetObjectStorageArray<vmg_float>("PARTICLE_FORCE_ARRAY");
     123  vmg_float* f = factory.GetObjectStorageArray<vmg_float>("PARTICLE_FIELD_ARRAY");
    122124
    123125  const vmg_float r_cut = (near_field_cells+0.5) * grid.Extent().MeshWidth().Max();
     
    152154  for (p_iter=particles.begin(); p_iter!=particles.end(); ++p_iter) {
    153155
     156    const Index global_index = (p_iter->Pos() - particle_grid.Extent().Begin()) / particle_grid.Extent().MeshWidth();
     157    const Index local_index = global_index - particle_grid.Global().LocalBegin() + particle_grid.Local().Begin();
     158
     159    ip.ComputeCoefficients(particle_grid, local_index);
     160
    154161    // Interpolate long range part of potential minus self-interaction
    155     p_iter->Pot() = Helper::InterpolateTrilinear(p_iter->Pos(), particle_grid)
    156       - p_iter->Charge() * spl.GetAntiDerivativeAtZero();
     162    p_iter->Pot() = ip.Evaluate(p_iter->Pos()) - p_iter->Charge() * spl.GetAntiDerivativeAtZero();
     163    p_iter->Field() = ip.EvaluateGradient(p_iter->Pos());
    157164
    158165#ifdef DEBUG_OUTPUT
     
    171178  Grid::iterator iter;
    172179
    173   comm.CommLCListToGhosts(grid, lc);
     180  comm.CommLCListToGhosts(lc);
    174181
    175182  for (iter=lc.Iterators().Local().Begin(); iter!=lc.Iterators().Local().End(); ++iter) {
     
    179186        for (index.Y()=-1*near_field_cells-1; index.Y()<=near_field_cells+1; ++index.Y())
    180187          for (index.Z()=-1*near_field_cells-1; index.Z()<=near_field_cells+1; ++index.Z()) {
     188
    181189            std::list<Particle::Particle*>& lc_2 = lc(*iter+index);
     190
    182191            for (p2=lc_2.begin(); p2!=lc_2.end(); ++p2)
    183192              if (*p1 != *p2) {
     
    187196                //TODO Rewrite this equation more efficiently
    188197                if (length < r_cut) {
    189                   (*p1)->Pot() += (*p2)->Charge() / length * (1.0 - spl.EvaluatePotential(length));
     198                  (*p1)->Pot() += (*p2)->Charge() / length * (1.0 + spl.EvaluatePotential(length));
    190199
    191200#ifdef DEBUG_OUTPUT
     
    193202                  e_shortcorr -= 0.5 * (*p1)->Charge() * (*p2)->Charge() / length * spl.EvaluatePotential(length);
    194203#endif
    195 
    196204                }
    197205              }
Note: See TracChangeset for help on using the changeset viewer.