ampsci
c++ program for high-precision atomic structure calculations of single-valence systems
Loading...
Searching...
No Matches
BoundState.hpp
1#pragma once
2#include "AdamsMoulton.hpp"
3#include "Physics/PhysConst_constants.hpp"
4#include "Wavefunction/DiracSpinor.hpp"
5#include <memory>
6#include <utility>
7#include <vector>
8class Grid;
9
11namespace DiracODE {
12
13//==============================================================================
15
24void boundState(DiracSpinor &Fa, const double en0, const std::vector<double> &v,
25 const std::vector<double> &H_off_diag = {},
26 const double alpha = PhysConst::alpha, double eps = 1.0e-14,
27 const DiracSpinor *const VxFa = nullptr,
28 const DiracSpinor *const Fa0 = nullptr, double zion = 1,
29 double mass = 1.0);
30
31inline DiracSpinor boundState(int n, int kappa, const double en0,
32 const std::shared_ptr<const Grid> &gr,
33 const std::vector<double> &v,
34 const std::vector<double> &H_off_diag = {},
35 const double alpha = PhysConst::alpha,
36 double eps = 1.0e-14,
37 const DiracSpinor *const VxFa = nullptr,
38 const DiracSpinor *const Fa0 = nullptr,
39 double zion = 1, double mass = 1.0) {
40 DiracSpinor Fnk = DiracSpinor(n, kappa, gr);
41 boundState(Fnk, en0, v, H_off_diag, alpha, eps, VxFa, Fa0, zion, mass);
42 return Fnk;
43}
44
46void regularAtOrigin(DiracSpinor &Fa, const double en,
47 const std::vector<double> &v,
48 const std::vector<double> &H_off_diag, const double alpha,
49 const DiracSpinor *const VxFa = nullptr,
50 const DiracSpinor *const Fa0 = nullptr, double zion = 1,
51 double mass = 1.0);
52
54void regularAtInfinity(DiracSpinor &Fa, const double en,
55 const std::vector<double> &v,
56 const std::vector<double> &H_off_diag,
57 const double alpha,
58 const DiracSpinor *const VxFa = nullptr,
59 const DiracSpinor *const Fa0 = nullptr, double zion = 1,
60 double mass = 1.0);
61
62namespace Internal {
63
64//==============================================================================
65// Parameters used for Adams-Moulton mehtod:
66namespace Param {
67
68// K (# steps) for Adams-Moulton method (between 1 and 12)
69constexpr std::size_t K_Adams = 7;
70// Parameter to determine 'assymptotically large r [kinda..]' (=800)
71constexpr double cALR = 550.0;
72// Max # attempts at converging [sove bs] (30)
73constexpr int max_its = 99;
74// 'large' energy variations (0.1 => 10%)
75constexpr double lfrac_de = 0.12;
76// Num points past ctp +/- d_ctp.
77constexpr int d_ctp = 4;
78
79// order of the expansion coeficients in large-r asymptotic expansion (15 orig.)
80constexpr int nx = 15;
81// convergance for expansion in asymptotic expansion (10^-8)
82constexpr double nx_eps = 1.e-12;
83
84// weighting function for meshing in/out solutions
85// nb: must be positive, but i may be negative [ctp - d_ctp]
86constexpr auto weight = [](std::size_t i) {
87 return 1.0 / static_cast<double>(i * i + 1);
88};
89
90static_assert(
91 Param::K_Adams >= 1 && Param::K_Adams <= AdamsMoulton::K_max,
92 "\nFAIL in DiracODE: parameter K_Adams must be between 5 and 8\n");
93
94} // namespace Param
95
96//==============================================================================
98struct DiracDerivative : AdamsMoulton::DerivativeMatrix<std::size_t, double> {
99
100 DiracDerivative(const Grid &in_grid, const std::vector<double> &in_v,
101 const int in_k, const double in_en, const double in_alpha,
102 const std::vector<double> &V_off_diag = {},
103 const DiracSpinor *const VxFa = nullptr,
104 const DiracSpinor *const iFa0 = nullptr, double zion = 1,
105 double in_mass = 1.0);
106 const Grid *const pgr;
107 const std::vector<double> *const v;
108 const std::vector<double> *const Hmag;
109 const DiracSpinor *const VxFa;
110 const DiracSpinor *const Fa0;
111 const double zion = 1.0;
112 const int k;
113 const double en, alpha, cc;
114 double mass;
115
116 double a(std::size_t i) const final;
117 double b(std::size_t i) const final;
118 double c(std::size_t i) const final;
119 double d(std::size_t i) const final;
120 double Sf(std::size_t i) const final;
121 double Sg(std::size_t i) const final;
122
123 DiracDerivative(const DiracDerivative &) = delete;
124 void operator=(const DiracDerivative &) = delete;
125};
126
127//==============================================================================
128// To keep track of current/previous energy guesses
129struct TrackEnGuess {
130 // Number of times there was too many/too few nodes:
131 int count_toomany = 0;
132 int count_toofew = 0;
133 // Upper and lower energy window before correct # nodes
134 double high_en = 0.0;
135 double low_en = 0.0;
136};
137
138//==============================================================================
139// Finds "practical infinity" index, where f(r) drops effectively to zero
140std::size_t findPracticalInfinity(const double en, const std::vector<double> &v,
141 const std::vector<double> &r,
142 const double alr);
143
144// Finds "classical turning point" index, where |V(r)| = |E|
145std::size_t findClassicalTurningPoint(const double en,
146 const std::vector<double> &v,
147 std::size_t pinf, std::size_t d_ctp);
148
149// Finds a trial Dirac solution for given energy that has correct boundary conditions.
150/*
151If it's not an exact solution, there will be a 'kink' in the wavefunction
152around ctp (classical turning point), where the inward and outward solutons
153were joind. The difference between g for these, dg=(gout-gin), is stored, and
154is used for PT
155*/
156void trialDiracSolution(std::vector<double> &f, std::vector<double> &g,
157 std::vector<double> &dg, const double en, const int ka,
158 const std::vector<double> &v,
159 const std::vector<double> &H_off_diag, const Grid &gr,
160 std::size_t ctp, std::size_t d_ctp, std::size_t pinf,
161 const double alpha,
162 const DiracSpinor *const VxFa = nullptr,
163 const DiracSpinor *const Fa0 = nullptr, double zion = 1,
164 double mass = 1.0);
165
166// Counts the nodes a given function f
167int countNodes(const std::vector<double> &f, const std::size_t maxi);
168
169// Makes a large update to energy; updates 'TrackEnGuess'
170void largeEnergyChange(double *en, TrackEnGuess *sofar, double frac_de,
171 bool toomany_nodes);
172
173// Makes a small update to energy using perturbation theory, given f and dg
174double smallEnergyChangePT(const double en, const double anorm,
175 const std::vector<double> &f,
176 const std::vector<double> &dg, std::size_t ctp,
177 std::size_t d_ctp, const double alpha,
178 const TrackEnGuess &sofar);
179
180// Solves Dirac equation by integrating outwards from zero.
181// Integrates only to 'final' (not inclusive). If final=0, goes to f.size()
182// Solution has correct boundary condition at r=0, but not at large r.
183void solve_Dirac_outwards(std::vector<double> &f, std::vector<double> &g,
184 const DiracDerivative &Hd, std::size_t final = 0);
185
186// Solves Dirac equation by integrating inwards from 'pinf' to 'ctp'
187// Solution has correct boundary condition at large r, but not at small r.
188void solve_Dirac_inwards(std::vector<double> &f, std::vector<double> &g,
189 const DiracDerivative &Hd, std::size_t ctp,
190 std::size_t pinf, double mass = 1.0);
191
192// Meshes the two solutions from inwards/outwards integration.
193// Produces solution that has correct boundary conditions at 0 and infinity,
194// but may not be smooth at the joining point.
195void joinInOutSolutions(std::vector<double> &f, std::vector<double> &g,
196 std::vector<double> &dg,
197 const std::vector<double> &f_in,
198 const std::vector<double> &g_in, std::size_t ctp,
199 std::size_t d_ctp, std::size_t pinf);
200
201} // namespace Internal
202} // namespace DiracODE
Stores radial Dirac spinor: F_nk = (f, g)
Definition DiracSpinor.hpp:41
Holds grid, including type + Jacobian (dr/du)
Definition Grid.hpp:31
Functions and classes used to solve the Dirac equation.
Definition AsymptoticSpinor.hpp:8
void regularAtInfinity(DiracSpinor &Fa, const double en, const std::vector< double > &v, const std::vector< double > &H_mag, const double alpha, const DiracSpinor *const VxFa, const DiracSpinor *const Fa0, double zion, double mass)
For given energy en, solves (local) DE with correct boundary conditions at infinity.
Definition BoundState.cpp:170
void regularAtOrigin(DiracSpinor &Fa, const double en, const std::vector< double > &v, const std::vector< double > &H_mag, const double alpha, const DiracSpinor *const VxFa, const DiracSpinor *const Fa0, double zion, double mass)
For given energy en, solves DE with correct boundary conditions at the origin.
Definition BoundState.cpp:149
void boundState(DiracSpinor &Fn, const double en0, const std::vector< double > &v, const std::vector< double > &H_mag, const double alpha, double eps_goal, const DiracSpinor *const VxFa, const DiracSpinor *const Fa0, double zion, double mass)
Solves bound-state problem for local potential (en < 0)
Definition BoundState.cpp:23
constexpr double alpha
Fine-structure constant: alpha = 1/137.035 999 177(21) [CODATA 2022].
Definition PhysConst_constants.hpp:24
Pure-virtual struct, holds the derivative matrix for 2x2 system of ODEs. Derive from this,...
Definition AdamsMoulton.hpp:79
Matrix which defines Dirac derivative: (dF/dr) = D*F.
Definition BoundState.hpp:98
double a(std::size_t i) const final
a,b,c,d are derivative matrix functions; all must be user implemented
Definition BoundState.cpp:501
double Sf(std::size_t i) const final
Sf and Sg are optional inhomogenous terms.
Definition BoundState.cpp:513