source: src/samples/bspline.hpp@ e3dbbf

Last change on this file since e3dbbf was ac6d04, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

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

  • Property mode set to 100644
File size: 3.6 KB
RevLine 
[dfed1c]1/**
2 * @file bspline.hpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Nov 21 13:27:22 2011
5 *
6 * @brief B-Splines for molecular dynamics.
7 *
8 */
9
10#ifndef BSPLINE_HPP_
11#define BSPLINE_HPP_
12
13#include "base/helper.hpp"
[ab63b6]14#include "base/index.hpp"
15#include "base/particle.hpp"
[dfed1c]16#include "base/polynomial.hpp"
17#include "base/vector.hpp"
[ab63b6]18#include "grid/grid.hpp"
[dfed1c]19
20namespace VMG
21{
22
23class BSpline
24{
25public:
26 BSpline(const vmg_float& width);
27
28 vmg_float EvaluateSpline(const vmg_float& val)
29 {
30 for (unsigned int i=0; i<intervals.size(); ++i)
31 if (val < intervals[i])
32 return spline_nom[i](val) / spline_denom[i](val);
33 return 0.0;
34 }
35
[ab63b6]36 void SetSpline(Grid& grid, const Particle::Particle p, const int& near_field_cells)
37 {
[ac6d04]38 assert(p.Pos().X() >= grid.Extent().Begin().X() && p.Pos().X() < grid.Extent().End().X());
39 assert(p.Pos().Y() >= grid.Extent().Begin().Y() && p.Pos().Y() < grid.Extent().End().Y());
40 assert(p.Pos().Z() >= grid.Extent().Begin().Z() && p.Pos().Z() < grid.Extent().End().Z());
41
[ab63b6]42 Index i, index_global, index_local;
43 vmg_float temp_val, length;
44 std::vector<vmg_float> vals;
45 std::vector<vmg_float>::const_iterator iter;
46
47 vmg_float int_val = 0.0;
48
49 index_global = static_cast<Index>((p.Pos() - grid.Extent().Begin()) / grid.Extent().MeshWidth());
[ac6d04]50 assert(index_global.X() >= grid.Global().LocalBegin().X() && index_global.X() < grid.Global().LocalEnd().X());
51 assert(index_global.Y() >= grid.Global().LocalBegin().Y() && index_global.Y() < grid.Global().LocalEnd().Y());
52 assert(index_global.Z() >= grid.Global().LocalBegin().Z() && index_global.Z() < grid.Global().LocalEnd().Z());
53
54 index_local = index_global - grid.Global().LocalBegin() + grid.Local().Begin();
55 assert(index_local.X() >= grid.Local().Begin().X() && index_local.X() < grid.Local().End().X());
56 assert(index_local.Y() >= grid.Local().Begin().Y() && index_local.Y() < grid.Local().End().Y());
57 assert(index_local.Z() >= grid.Local().Begin().Z() && index_local.Z() < grid.Local().End().Z());
[ab63b6]58
59 // Iterate over all grid points which lie in the support of the interpolating B-Spline
[ac6d04]60 for (i.X()=-1*near_field_cells; i.X()<=near_field_cells; ++i.X())
61 for (i.Y()=-1*near_field_cells; i.Y()<=near_field_cells; ++i.Y())
62 for (i.Z()=-1*near_field_cells; i.Z()<=near_field_cells; ++i.Z()) {
[ab63b6]63
64 // Compute distance from grid point to particle
65 length = ( p.Pos() - grid.Extent().Begin() - grid.Extent().MeshWidth() * (index_global+i) ).Length();
66
67 temp_val = EvaluateSpline(length);
68 vals.push_back(temp_val * p.Charge());
69 int_val += temp_val;
70
[ac6d04]71 assert(temp_val >= 0.0);
72
[ab63b6]73 }
74
[ac6d04]75 // Reciprocal value of the numerically integrated spline
76 int_val = 1.0 / (int_val * grid.Extent().MeshWidth().Product());
[ab63b6]77
78 iter = vals.begin();
[ac6d04]79 for (i.X()=-1*near_field_cells; i.X()<=near_field_cells; ++i.X())
80 for (i.Y()=-1*near_field_cells; i.Y()<=near_field_cells; ++i.Y())
81 for (i.Z()=-1*near_field_cells; i.Z()<=near_field_cells; ++i.Z())
[ab63b6]82 grid(index_local+i) += *iter++ * int_val;
83
[ac6d04]84 assert(iter == vals.end());
[ab63b6]85 }
86
[dfed1c]87 vmg_float EvaluatePotential(const vmg_float& val)
88 {
89 for (unsigned int i=0; i<intervals.size(); ++i)
90 if (val < intervals[i])
91 return potential_nom[i](val) / potential_denom[i](val);
92 return potential_nom.back()(val) / potential_denom.back()(val);
93 }
94
[ac6d04]95 const vmg_float& GetAntiDerivativeAtZero() const
[dfed1c]96 {
97 return antid;
98 }
99
100private:
101 std::vector<Polynomial> spline_nom, spline_denom;
102 std::vector<Polynomial> potential_nom, potential_denom;
103 vmg_float antid;
104 std::vector<vmg_float> intervals;
105
106 vmg_float R;
107};
108
109}
110
111#endif /* BSPLINE_HPP_ */
Note: See TracBrowser for help on using the repository browser.