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