7
7
*/
8
8
9
9
#include " cf1ion.hpp"
10
- #include < iostream>
11
10
12
11
namespace libMcPhase {
13
12
14
13
static const std::array<std::array<int , 4 >, 12 > idq = { {{2 ,2 ,0 ,4 }, {2 ,1 ,1 ,3 }, {4 ,4 ,5 ,13 }, {4 ,3 ,6 ,12 }, {4 ,2 ,7 ,11 }, {4 ,1 ,8 ,10 },
15
14
{6 ,6 ,14 ,26 }, {6 ,5 ,15 ,25 }, {6 ,4 ,16 ,24 }, {6 ,3 ,17 ,23 }, {6 ,2 ,18 ,22 }, {6 ,1 ,19 ,21 }} };
16
15
static const std::array<std::array<int , 2 >, 3 > idq0 = { {{2 ,2 }, {4 ,9 }, {6 ,20 }} };
17
16
17
+ // --------------------------------------------------------------------------------------------------------------- //
18
+ // Setter/getter methods for cfpars class
19
+ // --------------------------------------------------------------------------------------------------------------- //
20
+ void cf1ion::set (const Blm blm, double val) {
21
+ cfpars::set (blm, val);
22
+ m_ham_calc = false ;
23
+ m_ev_calc = false ;
24
+ }
25
+
26
+ void cf1ion::set (int l, int m, double val) {
27
+ cfpars::set (l, m, val);
28
+ m_ham_calc = false ;
29
+ m_ev_calc = false ;
30
+ }
31
+
32
+ void cf1ion::set_unit (cfpars::Units const newunit) {
33
+ cfpars::set_unit (newunit);
34
+ m_ham_calc = false ;
35
+ m_ev_calc = false ;
36
+ }
37
+
38
+ void cf1ion::set_type (const cfpars::Type newtype) {
39
+ cfpars::set_type (newtype);
40
+ m_ham_calc = false ;
41
+ m_ev_calc = false ;
42
+ }
43
+
44
+ void cf1ion::set_name (const std::string &ionname) {
45
+ cfpars::set_name (ionname);
46
+ m_ham_calc = false ;
47
+ m_ev_calc = false ;
48
+ }
49
+
50
+ void cf1ion::set_J (const double J) {
51
+ cfpars::set_J (J);
52
+ m_ham_calc = false ;
53
+ m_ev_calc = false ;
54
+ }
55
+
18
56
// --------------------------------------------------------------------------------------------------------------- //
19
57
// General methods for the cf1ion class
20
58
// --------------------------------------------------------------------------------------------------------------- //
21
59
RowMatrixXcd cf1ion::hamiltonian (bool upper) {
60
+ if (m_ham_calc) {
61
+ return m_hamiltonian;
62
+ }
22
63
if (m_J2 <= 0 ) {
23
64
throw std::runtime_error (" Invalid value of J - must be strictly greater than zero" );
24
65
}
25
66
26
67
int dimj = m_J2 + 1 ;
27
- RowMatrixXcd ham = RowMatrixXcd::Zero (dimj, dimj);
68
+ m_hamiltonian = RowMatrixXcd::Zero (dimj, dimj);
28
69
// For J=1/2, all Stevens operators are zero
29
70
if (dimj == 2 ) {
30
- return ham;
71
+ m_ham_calc = true ;
72
+ return m_hamiltonian;
31
73
}
32
74
33
75
// The crystal field potential operator is given by:
@@ -84,11 +126,10 @@ RowMatrixXcd cf1ion::hamiltonian(bool upper) {
84
126
// First the diagonal elements (q=0 terms)
85
127
for (auto iq: idq0) {
86
128
int k = iq[0 ], m = iq[1 ];
87
- std::cout << " k=" << k << " , m=" << m << " , m_Bi[m]=" << m_Bi[m] << " , rme[k]=" << rme[k] << " , m_econv=" << m_econv << " \n " ;
88
129
if (std::fabs (m_Bi[m]) > 1e-12 ) {
89
130
for (int i=0 ; i<dimj; i++) {
90
131
int mj = 2 *i - m_J2;
91
- ham (i,i) += pow (-1 ., (m_J2-mj)/2 .) * m_racah.threej (m_J2, 2 *k, m_J2, -mj, 0 , mj) * rme[k] * m_Bi[m] * m_econv;
132
+ m_hamiltonian (i,i) += pow (-1 ., (m_J2-mj)/2 .) * m_racah.threej (m_J2, 2 *k, m_J2, -mj, 0 , mj) * rme[k] * m_Bi[m] * m_econv;
92
133
}
93
134
}
94
135
}
@@ -100,14 +141,14 @@ RowMatrixXcd cf1ion::hamiltonian(bool upper) {
100
141
for (int i=0 ; i<(dimj-q); i++) {
101
142
int mj = 2 *i - m_J2, mjp = 2 *(i+q) - m_J2;
102
143
double tjp = m_racah.threej (m_J2, 2 *k, m_J2, -mj, 2 *q, mjp) - m_racah.threej (m_J2, 2 *k, m_J2, -mj, -2 *q, mjp);
103
- ham (i+q,i) += std::complex<double >(0 ., pow (-1 ., (m_J2-mj)/2 .) * tjp * rme[k] * m_Bi[m] * m_econv);
144
+ m_hamiltonian (i+q,i) += std::complex<double >(0 ., pow (-1 ., (m_J2-mj)/2 .) * tjp * rme[k] * m_Bi[m] * m_econv);
104
145
}
105
146
}
106
147
if (std::fabs (m_Bi[p]) > 1e-12 ) {
107
148
for (int i=0 ; i<(dimj-q); i++) {
108
149
int mj = 2 *i - m_J2, mjp = 2 *(i+q) - m_J2;
109
150
double tjp = m_racah.threej (m_J2, 2 *k, m_J2, -mj, 2 *q, mjp) + m_racah.threej (m_J2, 2 *k, m_J2, -mj, -2 *q, mjp);
110
- ham (i+q,i) += pow (-1 ., (m_J2-mj)/2 .) * tjp * rme[k] * m_Bi[p] * m_econv;
151
+ m_hamiltonian (i+q,i) += pow (-1 ., (m_J2-mj)/2 .) * tjp * rme[k] * m_Bi[p] * m_econv;
111
152
}
112
153
}
113
154
}
@@ -116,19 +157,23 @@ RowMatrixXcd cf1ion::hamiltonian(bool upper) {
116
157
if (upper) {
117
158
for (int i=0 ; i<dimj; i++) {
118
159
for (int j=i+1 ; j<dimj; j++) {
119
- ham (i,j) = std::conj (ham (j,i));
160
+ m_hamiltonian (i,j) = std::conj (m_hamiltonian (j,i));
120
161
}
121
162
}
122
163
}
123
164
124
- return ham;
165
+ m_ham_calc = true ;
166
+ return m_hamiltonian;
125
167
}
126
168
127
169
std::tuple<RowMatrixXcd, VectorXd> cf1ion::eigensystem () {
128
- SelfAdjointEigenSolver<RowMatrixXcd> es (hamiltonian (false ));
129
- RowMatrixXcd eigenvectors = es.eigenvectors ();
130
- VectorXd eigenvalues = es.eigenvalues ();
131
- return std::tuple<RowMatrixXcd, VectorXd>(eigenvectors, eigenvalues);
170
+ if (!m_ev_calc) {
171
+ SelfAdjointEigenSolver<RowMatrixXcd> es (hamiltonian (false ));
172
+ m_eigenvectors = es.eigenvectors ();
173
+ m_eigenvalues = es.eigenvalues ();
174
+ m_ev_calc = true ;
175
+ }
176
+ return std::tuple<RowMatrixXcd, VectorXd>(m_eigenvectors, m_eigenvalues);
132
177
}
133
178
134
179
} // namespace libMcPhase
0 commit comments