[cceb8c] | 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 |
|
---|
| 18 | namespace VMG {
|
---|
| 19 | class Grid;
|
---|
| 20 | class GridIterator;
|
---|
| 21 |
|
---|
| 22 | namespace Particle {
|
---|
| 23 | class BSpline;
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | /** This class smears out a given (peak-like) charge value by using a radial
|
---|
| 28 | * b-spline of compile-defined degree and runtime-defined width ("near field
|
---|
| 29 | * cells").
|
---|
| 30 | *
|
---|
| 31 | * This is used to smear out the electronic charge distribution in the same
|
---|
| 32 | * way as is done with the (point-like) nuclei charge distribution to increase
|
---|
| 33 | * accuracy for the long-range calculations.
|
---|
| 34 | *
|
---|
| 35 | * The trick relies on two distant and non-overlapping charge distributions
|
---|
| 36 | * behave actually as two point charges and vice versa. Core electron charge
|
---|
| 37 | * distributions are strongly peaked and hence almost appear like the point-like
|
---|
| 38 | * nuclei charge distributions. Hence, we perform the same trick as is done
|
---|
| 39 | * with the nuclei. The charges are smeared out to such a degree that charge
|
---|
| 40 | * distributions do not overlap except within a single fragment. Within
|
---|
| 41 | * fragments the short-range Coulomb energy and forces is calculated accurately.
|
---|
| 42 | * In between fragments the long-range calculations via vmg is used and hence
|
---|
| 43 | * charges there may not overlap. The maximum distance allowed and hence the
|
---|
| 44 | * maximum near field cells can be obtained from the Interfragmenter class.
|
---|
| 45 | *
|
---|
| 46 | * This class is a singleton as we only need to precalculate the spline values
|
---|
| 47 | * for a given nfc once and then may use of all FragmentJobs.
|
---|
| 48 | *
|
---|
| 49 | * The code here is taken from vmg's units/particles/bspline.cpp::SetSpline().
|
---|
| 50 | */
|
---|
| 51 | class ChargeSmearer : public Singleton<ChargeSmearer>
|
---|
| 52 | {
|
---|
| 53 | friend class Singleton<ChargeSmearer>;
|
---|
| 54 |
|
---|
| 55 | private:
|
---|
| 56 | /** Private cstor for ChargeSmearer.
|
---|
| 57 | *
|
---|
| 58 | * Must be private as is singleton.
|
---|
| 59 | *
|
---|
| 60 | */
|
---|
| 61 | ChargeSmearer();
|
---|
| 62 |
|
---|
| 63 | /** Dstor for ChargeSmearer.
|
---|
| 64 | *
|
---|
| 65 | */
|
---|
| 66 | ~ChargeSmearer();
|
---|
| 67 |
|
---|
| 68 | public:
|
---|
| 69 | /** Setter for the values defining the grid and the spline extent.
|
---|
| 70 | *
|
---|
| 71 | * This function recalculates the spline values but only if the
|
---|
| 72 | * values have changed with respect to the old ones.
|
---|
| 73 | *
|
---|
| 74 | * \param _spl spline to evaluate
|
---|
| 75 | * \param _nfc near field cells
|
---|
| 76 | * \param _meshwdith mesh spacing
|
---|
| 77 | */
|
---|
| 78 | void initializeSplineArray(
|
---|
| 79 | const VMG::Particle::BSpline &_spl,
|
---|
| 80 | const unsigned int _nfc,
|
---|
| 81 | const double _meshwidth);
|
---|
| 82 |
|
---|
| 83 | /** Getter for the width of the smearing area, i.e. number of near field
|
---|
| 84 | * cells.
|
---|
| 85 | *
|
---|
| 86 | * \return number of near field cells, i.e. 2nfc+1 equals width of array
|
---|
| 87 | */
|
---|
| 88 | unsigned int getNearFielCells() const
|
---|
| 89 | { return nfc; }
|
---|
| 90 |
|
---|
| 91 | /** Getter for the meshwidth.
|
---|
| 92 | *
|
---|
| 93 | * \return meshwidth
|
---|
| 94 | */
|
---|
| 95 | unsigned int getMeshwidth() const
|
---|
| 96 | { return meshwidth; }
|
---|
| 97 |
|
---|
| 98 | /** Smears out the given charge \a _value with the current \a nfc and bspline
|
---|
| 99 | * on the \a _grid.
|
---|
| 100 | *
|
---|
| 101 | * \param _grid grid to smear out charge on
|
---|
| 102 | * \param _iter central node on grid where to add smearing
|
---|
| 103 | * \param _charge charge to smear out
|
---|
| 104 | */
|
---|
| 105 | void operator()(
|
---|
| 106 | VMG::Grid& _grid,
|
---|
| 107 | const VMG::GridIterator &_iter,
|
---|
| 108 | const double _charge) const;
|
---|
| 109 |
|
---|
| 110 | private:
|
---|
| 111 | //!> near field radius for bspline
|
---|
| 112 | unsigned int nfc;
|
---|
| 113 |
|
---|
| 114 | //!> mesh width of the grid
|
---|
| 115 | double meshwidth;
|
---|
| 116 |
|
---|
| 117 | //!> contains the array of pre-compiled spline values
|
---|
| 118 | double *vals;
|
---|
| 119 |
|
---|
| 120 | //!> integrated value of spline array for normalization
|
---|
| 121 | double int_val;
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | #endif /* CHARGESMEARER_HPP_ */
|
---|