source: src/Jobs/ChargeSmearer.hpp@ ff4fff9

CombiningParticlePotentialParsing
Last change on this file since ff4fff9 was 62d092, checked in by Frederik Heber <heber@…>, 9 years ago

Rewrote ChargeSmearer to use visitor pattern.

  • this is used for going over the bspline domain.
  • we need it when the support does not fit onto grid and when we need to recalculate the normalization.
  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * ChargeSmearer.hpp
3 *
4 * Created on: Sep 2, 2015
5 * Author: heber
6 */
7
8#ifndef CHARGESMEARER_HPP_
9#define CHARGESMEARER_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include "CodePatterns/Singleton.hpp"
17
18namespace VMG {
19 class Grid;
20 class GridIterator;
21 class Index;
22
23 namespace Particle {
24 class BSpline;
25 }
26}
27
28/** This class smears out a given (peak-like) charge value by using a radial
29 * b-spline of compile-defined degree and runtime-defined width ("near field
30 * cells").
31 *
32 * This is used to smear out the electronic charge distribution in the same
33 * way as is done with the (point-like) nuclei charge distribution to increase
34 * accuracy for the long-range calculations.
35 *
36 * The trick relies on two distant and non-overlapping charge distributions
37 * behave actually as two point charges and vice versa. Core electron charge
38 * distributions are strongly peaked and hence almost appear like the point-like
39 * nuclei charge distributions. Hence, we perform the same trick as is done
40 * with the nuclei. The charges are smeared out to such a degree that charge
41 * distributions do not overlap except within a single fragment. Within
42 * fragments the short-range Coulomb energy and forces is calculated accurately.
43 * In between fragments the long-range calculations via vmg is used and hence
44 * charges there may not overlap. The maximum distance allowed and hence the
45 * maximum near field cells can be obtained from the Interfragmenter class.
46 *
47 * This class is a singleton as we only need to precalculate the spline values
48 * for a given nfc once and then may use of all FragmentJobs.
49 *
50 * The code here is taken from vmg's units/particles/bspline.cpp::SetSpline().
51 */
52class ChargeSmearer : public Singleton<ChargeSmearer>
53{
54 friend class Singleton<ChargeSmearer>;
55
56private:
57 /** Private cstor for ChargeSmearer.
58 *
59 * Must be private as is singleton.
60 *
61 */
62 ChargeSmearer();
63
64 /** Dstor for ChargeSmearer.
65 *
66 */
67 ~ChargeSmearer();
68
69public:
70 /** Setter for the values defining the grid and the spline extent.
71 *
72 * This function recalculates the spline values but only if the
73 * values have changed with respect to the old ones.
74 *
75 * \param _spl spline to evaluate
76 * \param _nfc near field cells
77 * \param _meshwdith mesh spacing
78 */
79 void initializeSplineArray(
80 const VMG::Particle::BSpline &_spl,
81 const unsigned int _nfc,
82 const double _meshwidth);
83
84 /** Getter for the width of the smearing area, i.e. number of near field
85 * cells.
86 *
87 * \return number of near field cells, i.e. 2nfc+1 equals width of array
88 */
89 unsigned int getNearFielCells() const
90 { return nfc; }
91
92 /** Getter for the meshwidth.
93 *
94 * \return meshwidth
95 */
96 unsigned int getMeshwidth() const
97 { return meshwidth; }
98
99 /** Smears out the given charge \a _value with the current \a nfc and bspline
100 * on the \a _grid.
101 *
102 * \param _grid grid to smear out charge on
103 * \param _iter central node on grid where to add smearing
104 * \param _charge charge to smear out
105 */
106 void operator()(
107 VMG::Grid& _grid,
108 const VMG::GridIterator &_iter,
109 const double _charge) const;
110
111private:
112 //!> typedef for the visitor functor
113 typedef boost::function<void (const VMG::Index &, const double)> visitor_t;
114
115 /** Visitor pattern for going over bspline support and executing the given
116 * functor at each valid node.
117 *
118 * \param _iter iterator giving central node for support on grid
119 * \param _visitor visitor functor to execute at each node (that's still inside grid)
120 */
121 void visitBSplineDomain(
122 const VMG::GridIterator &_iter,
123 const visitor_t &_visitor
124 ) const;
125
126private:
127 //!> near field radius for bspline
128 unsigned int nfc;
129
130 //!> mesh width of the grid
131 double meshwidth;
132
133 //!> contains the array of pre-compiled spline values
134 double *vals;
135
136 //!> integrated value of spline array for normalization
137 double int_val;
138};
139
140
141#endif /* CHARGESMEARER_HPP_ */
Note: See TracBrowser for help on using the repository browser.