BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSElectronOccupancy.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSElectronOccupancy.hh"
20#include "BDSElectronQuantumLevel.hh"
21#include "BDSUtilities.hh"
22
23#include "G4Types.hh"
24
25BDSElectronOccupancy::BDSElectronOccupancy(G4int maxn)
26{
27 G4double spinUp=0.5;
28 G4double spinDown=-0.5;
29 for(G4int i=1; i<=maxn; i++)
30 {
31 for(G4int j=0; j<i; j++)
32 {
33 G4double jSpinOrbit1 = abs(j+spinUp);
34 G4double jSpinOrbit2 = abs(j+spinDown);
35 if(jSpinOrbit1==jSpinOrbit2)
36 {
37 stateList.push_back(new BDSElectronQuantumLevel(i,j,jSpinOrbit1));
38 }
39 else
40 {
41 stateList.push_back(new BDSElectronQuantumLevel(i,j,jSpinOrbit2));
42 stateList.push_back(new BDSElectronQuantumLevel(i,j,jSpinOrbit1));
43 }
44 }
45 }
46
47 sort(stateList.begin(),stateList.end(),CompareEnergy);
48
49}
50
51BDSElectronOccupancy::~BDSElectronOccupancy()
52{stateList.clear();}
53
54void BDSElectronOccupancy::CreateNewLevel(G4int n, G4int l, G4int j)
55{
56 stateList.push_back(new BDSElectronQuantumLevel(n,l,j));
57}
58
59G4bool BDSElectronOccupancy::CompareEnergy(BDSElectronQuantumLevel* level1, BDSElectronQuantumLevel* level2)
60{
61 return (level1->GetLevelEnergy()>level2->GetLevelEnergy());
62}
63
64void BDSElectronOccupancy::PopulateLevels()
65{
66 G4int size=stateList.size();
67 G4int currentElectrons = totalElectrons;
68 for(G4int i=0; i<size; i++) {
69 if (currentElectrons > 0) {
70 G4int max = stateList[i]->GetMaxOccupancy();
71 G4int current = stateList[i]->GetCurrentOccupancy();
72 if (max > current) {
73 if ((max - current) < currentElectrons) {
74 stateList[i]->AddElectrons(max - current);
75 currentElectrons = currentElectrons - (max - current);
76 }
77 else
78 {
79 stateList[i]->AddElectrons(currentElectrons);
80 currentElectrons = 0;
81 }
82 }
83 }
84 }
85
86}
87
88void BDSElectronOccupancy::AddElectrons(G4int number)
89{
90 G4int size=stateList.size();
91 G4int currentElectrons = number;
92 for(G4int i=0; i<size; i++) {
93 if (currentElectrons > 0) {
94 G4int max = stateList[i]->GetMaxOccupancy();
95 G4int current = stateList[i]->GetCurrentOccupancy();
96 if (max > current) {
97 if ((max - current) < currentElectrons) {
98 stateList[i]->AddElectrons(max - current);
99 currentElectrons = currentElectrons - (max - current);
100 }
101 else
102 {
103 stateList[i]->AddElectrons(currentElectrons);
104 currentElectrons = 0;
105 }
106 }
107 }
108 }
109
110}
111
112void BDSElectronOccupancy::AddElectrons(G4int n, G4int l, G4double j, G4int number)
113{
114
115 G4int size=stateList.size();
116 G4int currentNumber=number;
117 for(G4int i=0; i<size;i++)
118 {
119 if(stateList[i]->GetnPrincipleNumnber()==n&&stateList[i]->GetlAngularNumber()==l&&stateList[i]->GetjSpinOrbitCoupling()==j)
120 {
121 if(currentNumber>0)
122 {
123 G4int currentAvailable = stateList[i]->GetMaxOccupancy()-stateList[i]->GetCurrentOccupancy();
124 if (currentAvailable > currentNumber) {
125 stateList[i]->AddElectrons(currentNumber);
126 currentNumber=0;
127 }
128 //else error
129 }
130 }
131
132
133 }
134}
135
136void BDSElectronOccupancy::RemoveElectrons(G4int n, G4int l, G4double j,G4int number)
137{
138 G4int currentNumber=number;
139 G4int size=stateList.size();
140 for(G4int i=0; i<size; i++)
141 {
142 if(stateList[i]->GetnPrincipleNumnber() == n && stateList[i]->GetlAngularNumber() == l&&stateList[i]->GetjSpinOrbitCoupling()==j)
143 {
144 if(currentNumber>0) {
145 if (stateList[i]->GetCurrentOccupancy() > 0)
146 {
147 stateList[i]->RemoveElectrons(number);
148 currentNumber=currentNumber-number;
149 }
150 }
151 }
152 }
153}
154
155G4bool BDSElectronOccupancy::StatePopulated(G4int n, G4int l, G4double j)
156{
157 G4int size=stateList.size();
158 for(int i=0; i<size;i++)
159 {
160
161 if (stateList[i]->GetnPrincipleNumnber() == n && stateList[i]->GetlAngularNumber() == l&&stateList[i]->GetjSpinOrbitCoupling()==j)
162 {
163 if(stateList[i]->GetCurrentOccupancy()>0){
164 return true;
165 }
166
167 }
168 }
169 return false;
170}
171
172void BDSElectronOccupancy::SetStateLifetime(G4int n, G4int l, G4double lifetime)
173{
174 G4int size=stateList.size();
175 for(int i=0; i<size; i++)
176 {
177 if (stateList[i]->GetnPrincipleNumnber() == n && stateList[i]->GetlAngularNumber() == l)
178 {
179 if(stateList[i]->GetCurrentOccupancy()>0)
180 {
181 stateList[i]->SetExcitedLifetime(lifetime);
182 }
183 }
184 }
185}
186
187void BDSElectronOccupancy::SetTimeOfExciation(G4double timeOfExcitationIn, G4int n, G4int l, G4double j)
188{
189 G4int size=stateList.size();
190 for(int i=0; i<size; i++)
191 {
192 if (stateList[i]->GetnPrincipleNumnber() == n && stateList[i]->GetlAngularNumber() == l && stateList[i]->GetjSpinOrbitCoupling()==j)
193 {
194 stateList[i]->SetTimeOfExcitement(timeOfExcitationIn);
195 }
196 }
197}
198
199G4double BDSElectronOccupancy::GetStateLifetime(G4int n, G4int l, G4double j)
200{
201 G4int size=stateList.size();
202 for(int i=0; i<size; i++)
203 {
204 if (stateList[i]->GetnPrincipleNumnber() == n && stateList[i]->GetlAngularNumber() == l && stateList[i]->GetjSpinOrbitCoupling()==j)
205 {
206 return stateList[i]->GetExcitedLifetime();
207 }
208 }
209 return 0;
210
211}
212
213G4double BDSElectronOccupancy::GetTimeOfExcitation(G4int n, G4int l, G4double j){
214 G4int size=stateList.size();
215 for(int i=0; i<size; i++)
216 {
217 if (stateList[i]->GetnPrincipleNumnber() == n && stateList[i]->GetlAngularNumber() == l && stateList[i]->GetjSpinOrbitCoupling()==j)
218 {
219 return stateList[i]->GetTimeOfExcitement();
220 }
221 }
222 return 0;
223}
Electron Quantum levels for more than just n quantum number.