Changeset b303d0


Ignore:
Timestamp:
Sep 6, 2015, 10:25:02 PM (10 years ago)
Author:
Frederik Heber <heber@…>
Children:
3f6604
Parents:
ebc866
git-author:
Frederik Heber <heber@…> (03/13/15 15:02:44)
git-committer:
Frederik Heber <heber@…> (09/06/15 22:25:02)
Message:

tempcommit: Fixes to SubtractSelfInducedForces().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/units/particle/bspline.hpp

    rebc866 rb303d0  
    210210        const vmg_float& h_z = grid.Extent().MeshWidth().Z();
    211211
    212         int int_val = 0.;
     212        vmg_float int_val = 0.;
    213213    vmg_float dir_x = pos_beg_x;
    214214    for (int i=-1*near_field_cells; i<=near_field_cells; ++i) {
     
    218218        for (int k=-1*near_field_cells; k<=near_field_cells; ++k) {
    219219
    220           // Compute distance from grid point to particle
    221           int_val += EvaluateSpline(std::sqrt(dir_x*dir_x+dir_y*dir_y+dir_z*dir_z));
     220                  const double length_sq = dir_x*dir_x+dir_y*dir_y+dir_z*dir_z;
     221                  if (fabs(length_sq) > std::numeric_limits<double>::epsilon()) {
     222                          // Compute distance from grid point to particle
     223                          int_val += EvaluateSpline(std::sqrt(length_sq));
     224                  }
    222225
    223226          dir_z += h_z;
     
    229232    // Reciprocal value of the numerically integrated spline
    230233    if (fabs(int_val) > std::numeric_limits<double>::epsilon())
    231         int_val = 1.0 / (int_val * h_x * h_y * h_z);
     234        int_val = 1. / (int_val * h_x * h_y * h_z);
    232235    else
    233         int_val = 1.0;
     236        int_val = 1. / (h_x * h_y * h_z);
    234237
    235238    // Iterate over all grid points which lie in the support of the interpolating B-Spline
     239    vmg_float test_int_val = 0.;
    236240        dir_x = pos_beg_x;
    237241        for (int i=-1*near_field_cells; i<=near_field_cells; ++i) {
     
    245249                  if (fabs(length_sq) > std::numeric_limits<double>::epsilon()) {
    246250                    const double length = std::sqrt(length_sq);
    247 //                  temp_val = EvaluateField(length);
    248 //                  p.Field()[0] -= p.Charge() * dir_x * temp_val;
    249 //                  p.Field()[1] -= p.Charge() * dir_y * temp_val;
    250 //                  p.Field()[2] -= p.Charge() * dir_z * temp_val;
    251                     temp_val = int_val * EvaluateSpline(length);
    252                     p.Field()[0] -= p.Charge()*p.Charge() * temp_val * temp_val * dir_x / (length_sq*length);
    253                     p.Field()[1] -= p.Charge()*p.Charge() * temp_val * temp_val * dir_y / (length_sq*length);
    254                     p.Field()[2] -= p.Charge()*p.Charge() * temp_val * temp_val * dir_z / (length_sq*length);
     251
     252                    temp_val = h_x * h_y * h_z * int_val * EvaluateSpline(length);
     253                    test_int_val += temp_val;
     254                    p.Field()[0] -= p.Charge()* temp_val * dir_x / (length_sq*length);
     255                    p.Field()[1] -= p.Charge()* temp_val * dir_y / (length_sq*length);
     256                    p.Field()[2] -= p.Charge()* temp_val * dir_z / (length_sq*length);
    255257                  } else {
    256258                          std::cerr << "Value very small " << length_sq << "=("
     
    267269          dir_x += h_x;
    268270        }
     271        if ( fabs(test_int_val -1.) > std::numeric_limits<double>::epsilon()*1e4 ) {
     272                std::cerr << "Integrated spline value should be 1 but is " << test_int_val << std::endl;
     273                assert(0);
     274        }
    269275  }
    270276
Note: See TracChangeset for help on using the changeset viewer.