/** * @file bspline.hpp * @author Julian Iseringhausen * @date Mon Nov 21 13:27:22 2011 * * @brief B-Splines for molecular dynamics. * */ #ifndef BSPLINE_HPP_ #define BSPLINE_HPP_ #include "base/helper.hpp" #include "base/index.hpp" #include "base/polynomial.hpp" #include "base/vector.hpp" #include "grid/grid.hpp" #include "units/particle/particle.hpp" namespace VMG { namespace Particle { class BSpline { public: BSpline(const vmg_float& width); vmg_float EvaluateSpline(const vmg_float& val) const { for (unsigned int i=0; i= grid.Extent().Begin().X() && p.Pos().X() < grid.Extent().End().X()); assert(p.Pos().Y() >= grid.Extent().Begin().Y() && p.Pos().Y() < grid.Extent().End().Y()); assert(p.Pos().Z() >= grid.Extent().Begin().Z() && p.Pos().Z() < grid.Extent().End().Z()); std::vector vals(Helper::intpow(2*near_field_cells+1,3)); vmg_float temp_val; vmg_float int_val = 0.0; int c = 0; const int index_global_x = (p.Pos().X() - grid.Extent().Begin().X()) / grid.Extent().MeshWidth().X(); const int index_global_y = (p.Pos().Y() - grid.Extent().Begin().Y()) / grid.Extent().MeshWidth().Y(); const int index_global_z = (p.Pos().Z() - grid.Extent().Begin().Z()) / grid.Extent().MeshWidth().Z(); assert(index_global_x >= grid.Global().LocalBegin().X() && index_global_x < grid.Global().LocalEnd().X()); assert(index_global_y >= grid.Global().LocalBegin().Y() && index_global_y < grid.Global().LocalEnd().Y()); assert(index_global_z >= grid.Global().LocalBegin().Z() && index_global_z < grid.Global().LocalEnd().Z()); const int index_local_x = index_global_x - grid.Global().LocalBegin().X() + grid.Local().Begin().X(); const int index_local_y = index_global_y - grid.Global().LocalBegin().Y() + grid.Local().Begin().Y(); const int index_local_z = index_global_z - grid.Global().LocalBegin().Z() + grid.Local().Begin().Z(); assert(index_local_x >= grid.Local().Begin().X() && index_local_x < grid.Local().End().X()); assert(index_local_y >= grid.Local().Begin().Y() && index_local_y < grid.Local().End().Y()); assert(index_local_z >= grid.Local().Begin().Z() && index_local_z < grid.Local().End().Z()); const vmg_float pos_beg_x = p.Pos().X() - grid.Extent().Begin().X() - grid.Extent().MeshWidth().X() * (index_global_x - near_field_cells); const vmg_float pos_beg_y = p.Pos().Y() - grid.Extent().Begin().Y() - grid.Extent().MeshWidth().Y() * (index_global_y - near_field_cells); const vmg_float pos_beg_z = p.Pos().Z() - grid.Extent().Begin().Z() - grid.Extent().MeshWidth().Z() * (index_global_z - near_field_cells); const vmg_float h_x = grid.Extent().MeshWidth().X(); const vmg_float h_y = grid.Extent().MeshWidth().Y(); const vmg_float h_z = grid.Extent().MeshWidth().Z(); // Iterate over all grid points which lie in the support of the interpolating B-Spline vmg_float dir_x, dir_y, dir_z; dir_x = pos_beg_x; for (int i=-1*near_field_cells; i<=near_field_cells; ++i) { dir_y = pos_beg_y; for (int j=-1*near_field_cells; j<=near_field_cells; ++j) { dir_z = pos_beg_z; for (int k=-1*near_field_cells; k<=near_field_cells; ++k) { // Compute distance from grid point to particle temp_val = EvaluateSpline(std::sqrt(dir_x*dir_x+dir_y*dir_y+dir_z*dir_z)); vals[c++] = temp_val * p.Charge(); int_val += temp_val; dir_z -= h_z; } dir_y -= h_y; } dir_x -= h_x; } // Reciprocal value of the numerically integrated spline int_val = 1.0 / (int_val * h_x * h_y * h_z); c = 0; for (int i=-1*near_field_cells; i<=near_field_cells; ++i) for (int j=-1*near_field_cells; j<=near_field_cells; ++j) for (int k=-1*near_field_cells; k<=near_field_cells; ++k) grid(index_local_x + i, index_local_y + j, index_local_z + k) += vals[c++] * int_val; } vmg_float EvaluatePotential(const vmg_float& val) const { for (unsigned int i=0; i spline_nom, spline_denom; std::vector potential_nom, potential_denom; std::vector field_nom, field_denom; vmg_float antid; std::vector intervals; vmg_float R; }; } } #endif /* BSPLINE_HPP_ */