MADNESS 0.10.1
masks_and_boxes.h
Go to the documentation of this file.
1/*
2 * masks_and_boxes.h
3 *
4 * Created on: 16 May 2019
5 * Author: fbischoff
6 */
7
8#ifndef SRC_APPS_CHEM_MASKS_AND_BOXES_H_
9#define SRC_APPS_CHEM_MASKS_AND_BOXES_H_
10
11
13#include <math.h>
14
15namespace madness {
16
17/// construct a smooth approximation for the piecewise function f(x)={{x, x<1}, {1,x>1}}.
18/// see https://doi.org/10.1186/s40064-016-3278-y
20
21 /// return a smooth transition of linear r to a constant at radius r
22
23 /// @param[in] r norm of the n-dimensional vector
24 /// @param[in] tightness see the compute_tightness() function
25 /// @param[in] max_radius where the curve flattens
26 /// @return factor multiply your vector with the factor xyz->xyz*factor
27 static double compute_factor(const double& r, const double& tightness, const double& rmax) {
28
29 const double a=0.5;
30 const double b=0.5;
31 const double c=-0.5;
32 const double beta=1.0;
33 const double A=a-c*beta;
34 const double B=b+c;
35 const double C=2.0*c/tightness;
36
37 const double f=rmax * (A +B*r/rmax + C*log(1.0+exp(-tightness*(r/rmax-beta))));
38 const double factor=(r>1.e-10) ? f/r : 1.0; // prevent division by zero
39 return factor;
40 }
41
42 /// compute the tightness parameter given the deviation at 0.8 radius
43
44 /// simple linear fit
45 static double compute_tightness(const double deviation_at_dot_8_radius, const double rmax) {
46 const double a=-1.0577335859862533;
47 const double b=-1.0/0.09618399253086536;
48 return (log10(deviation_at_dot_8_radius/rmax)-a)*b;
49 }
50
51};
52
53
54
55/// an 2-dimensional smooth mask that is 1 inside the radius and 0 outside
56template<std::size_t NDIM>
58
60
61 const double radius;
62 const double tightness=11.5; // 99.9% accurate at 0.8 radius
63 const coordT offset=coordT(0.0);
65
66 spherical_box(const double r, const double deviation,
67 const coordT o={0.0,0.0,0.0}, const coordT B_dir={0.0,0.0,1.0}) :
68 radius(r), tightness(compute_tightness(deviation)), offset(o), B_direction(B_dir) {}
69
70 double operator()(const coordT& xyz) const {
71 // project out all contributions from xyz along the direction of the B field
72 coordT tmp=(xyz-offset)*B_direction;
73 const double inner=tmp[0]+tmp[1]+tmp[2];
74 coordT proj=(xyz-offset)-B_direction*inner;
75 double r=proj.normf();
76 double v1=1.0/(1.0+exp(-tightness*(r-radius)));
77 return 1.0-v1;
78 }
79
80 /// compute the tightness parameter given the deviation at 0.8 radius
81 static double compute_tightness(const double deviation_at_dot_8_radius) {
82 return 5.0/3.0*log((1.0-deviation_at_dot_8_radius)/deviation_at_dot_8_radius);
83 }
84
85};
86
87
88}
89
90
91#endif /* SRC_APPS_CHEM_MASKS_AND_BOXES_H_ */
Definition test_ar.cc:118
Definition test_ar.cc:141
Definition test_ar.cc:170
A simple, fixed dimension vector.
Definition vector.h:64
T normf() const
Calculate the 2-norm of the vector elements.
Definition vector.h:400
const double beta
Definition gygi_soltion.cc:62
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
NDIM & f
Definition mra.h:2416
double inner(response_space &a, response_space &b)
Definition response_functions.h:442
static const double b
Definition nonlinschro.cc:119
static const double a
Definition nonlinschro.cc:118
static const double c
Definition relops.cc:10
Definition masks_and_boxes.h:19
static double compute_tightness(const double deviation_at_dot_8_radius, const double rmax)
compute the tightness parameter given the deviation at 0.8 radius
Definition masks_and_boxes.h:45
static double compute_factor(const double &r, const double &tightness, const double &rmax)
return a smooth transition of linear r to a constant at radius r
Definition masks_and_boxes.h:27
an 2-dimensional smooth mask that is 1 inside the radius and 0 outside
Definition masks_and_boxes.h:57
static double compute_tightness(const double deviation_at_dot_8_radius)
compute the tightness parameter given the deviation at 0.8 radius
Definition masks_and_boxes.h:81
const coordT B_direction
Definition masks_and_boxes.h:64
double operator()(const coordT &xyz) const
Definition masks_and_boxes.h:70
spherical_box(const double r, const double deviation, const coordT o={0.0, 0.0, 0.0}, const coordT B_dir={0.0, 0.0, 1.0})
Definition masks_and_boxes.h:66
const double tightness
Definition masks_and_boxes.h:62
const double radius
Definition masks_and_boxes.h:61
Vector< double, NDIM > coordT
Definition masks_and_boxes.h:59
const coordT offset
Definition masks_and_boxes.h:63
Implement the madness:Vector class, an extension of std::array that supports some mathematical operat...