Changeset ab63b6


Ignore:
Timestamp:
Dec 8, 2011, 12:53:48 PM (14 years ago)
Author:
Julian Iseringhausen <isering@…>
Children:
138f86
Parents:
facba0
Message:

Ensure that interpolating splines are normalized wrt the grid.

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

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/interface/interface_particles.cpp

    rfacba0 rab63b6  
    100100#endif
    101101
    102   for (iter=particles.begin(); iter!=particles.end(); ++iter) {
    103 
    104     // Compute global and local grid index of the lower left corner of the grid cell containing the particle
    105     index_global = static_cast<Index>((iter->Pos() - temp_grid->Extent().Begin()) / temp_grid->Extent().MeshWidth());
    106     index_local = index_global - temp_grid->Global().BeginLocal() + temp_grid->Local().Begin();
    107 
    108     // Iterate over all grid points which lie in the support of the interpolating B-Spline
    109     for (index.X()=-1*near_field_cells-1; index.X()<=near_field_cells+1; ++index.X())
    110       for (index.Y()=-1*near_field_cells-1; index.Y()<=near_field_cells+1; ++index.Y())
    111         for (index.Z()=-1*near_field_cells-1; index.Z()<=near_field_cells+1; ++index.Z()) {
    112 
    113           // Compute distance from grid point to particle
    114           length = ( iter->Pos() - grid.Extent().Begin() - grid.Extent().MeshWidth() * (index_global+index) ).Length();
    115 
    116           // If grid point lies in the support of the B-Spline, do charge interpolation
    117           if (length < r_cut)
    118             (*temp_grid)(index_local+index) += spl.EvaluateSpline(length) * iter->Charge();
    119 
    120         }
    121 
    122   }
     102  for (iter=particles.begin(); iter!=particles.end(); ++iter)
     103    spl.SetSpline(*temp_grid, *iter, near_field_cells);
    123104
    124105  // Communicate charges over halo
  • src/samples/bspline.hpp

    rfacba0 rab63b6  
    1212
    1313#include "base/helper.hpp"
     14#include "base/index.hpp"
     15#include "base/particle.hpp"
    1416#include "base/polynomial.hpp"
    1517#include "base/vector.hpp"
     18#include "grid/grid.hpp"
    1619
    1720namespace VMG
     
    2932        return spline_nom[i](val) / spline_denom[i](val);
    3033    return 0.0;
     34  }
     35
     36  void SetSpline(Grid& grid, const Particle::Particle p, const int& near_field_cells)
     37  {
     38    Index i, index_global, index_local;
     39    vmg_float temp_val, length;
     40    std::vector<vmg_float> vals;
     41    std::vector<vmg_float>::const_iterator iter;
     42
     43    vmg_float int_val = 0.0;
     44
     45    index_global = static_cast<Index>((p.Pos() - grid.Extent().Begin()) / grid.Extent().MeshWidth());
     46    index_local = index_global - grid.Global().BeginLocal() + grid.Local().Begin();
     47
     48    // Iterate over all grid points which lie in the support of the interpolating B-Spline
     49    for (i.X()=-1*near_field_cells-1; i.X()<=near_field_cells+1; ++i.X())
     50      for (i.Y()=-1*near_field_cells-1; i.Y()<=near_field_cells+1; ++i.Y())
     51        for (i.Z()=-1*near_field_cells-1; i.Z()<=near_field_cells+1; ++i.Z()) {
     52
     53          // Compute distance from grid point to particle
     54          length = ( p.Pos() - grid.Extent().Begin() - grid.Extent().MeshWidth() * (index_global+i) ).Length();
     55
     56          temp_val = EvaluateSpline(length);
     57          vals.push_back(temp_val * p.Charge());
     58          int_val += temp_val;
     59
     60        }
     61
     62    int_val = 1.0 / (Helper::pow(grid.MeshWidth(), 3) * int_val);
     63
     64    iter = vals.begin();
     65
     66    for (i.X()=-1*near_field_cells-1; i.X()<=near_field_cells+1; ++i.X())
     67      for (i.Y()=-1*near_field_cells-1; i.Y()<=near_field_cells+1; ++i.Y())
     68        for (i.Z()=-1*near_field_cells-1; i.Z()<=near_field_cells+1; ++i.Z())
     69          grid(index_local+i) += *iter++ * int_val;
     70
    3171  }
    3272
Note: See TracChangeset for help on using the changeset viewer.