Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dbs to radiative splitting #974

Draft
wants to merge 58 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3b51ec3
First commit.
blakewalters Mar 7, 2020
2d05a10
Commit no. 2
blakewalters Apr 27, 2020
86f4c71
Commit I think third.
blakewalters Jun 15, 2020
6eefb24
Commit 4.
blakewalters Jul 28, 2020
5f955a1
Commit n+1
blakewalters Aug 24, 2020
c4a4ed7
All required functions in egs_advanced_application.
blakewalters Sep 21, 2020
0191dae
Trying to get it to compile.
blakewalters Oct 19, 2020
f847359
Compiles but hangs during run.
blakewalters Oct 29, 2020
5ceb688
Ensure latch bit 31 set to mark phat/non-phat particles.
blakewalters Nov 16, 2020
9bf7b73
Include Rayleigh interactions and eliminate some
blakewalters Nov 23, 2020
61f325d
Need to figure out how to not require
blakewalters Dec 15, 2020
058308a
Added output to Makefile.
blakewalters Jan 4, 2021
dec8b35
Override key macros from egs_interface2.macros.
blakewalters Feb 8, 2021
f48ea09
Forgot egs_radiative_splitting.macros file.
blakewalters Feb 8, 2021
a2e15ae
Midway through changes to implement all
blakewalters Mar 29, 2021
9458759
Major changes including:
blakewalters Apr 26, 2021
7dd7941
EGS_AdvancedAppliction::getParticleFromStack changed from void->EGS_P…
blakewalters Apr 26, 2021
293a399
Forgot to add array_sizes.h
blakewalters Apr 29, 2021
906ca73
Fixed a few bugs re:
blakewalters May 17, 2021
616d3bd
Add Ernesto's changes from 05/18/2021.
blakewalters May 31, 2021
27d18d7
Eliminate array dimension macros from AO.
blakewalters Jun 1, 2021
0a6eadf
Fixed bugs in updateParticleOnStack and getParticleFromStack:
blakewalters Jun 21, 2021
74b5e93
Pass values to getRngAzimuth by reference.
Jul 15, 2022
dd5d1e7
Fix incorrect updating of latch of initiating e- after brems.
Aug 26, 2022
b5fb044
"Essential" debug statements.
Sep 27, 2022
e22d7b4
Fix calls to alias_sample1 and egs_rayleigh_sampling.
Nov 22, 2022
41d45ef
Another fix: Did not properly copy region no. over during Rayleigh sp…
Nov 29, 2022
5a5e7fc
Replaced app->isWhere(x) with irl=app->top_p.ir everywhere.
Dec 2, 2022
97a4389
Debug statements.
Jan 16, 2023
f4647cd
Debug output.
Feb 7, 2023
3228194
Change $MXBRSPLIT back to default value.
Feb 21, 2023
13f3a58
Put interacting particle on top of stack.
Mar 4, 2023
c6e6f27
Remove debug output.
Mar 10, 2023
c6fbdf5
Revert to develop versions of egsnrc.mortran, egs_application.cpp
Mar 11, 2023
b663d3f
Halfway to changing SmartCompton to use BEAMnrc implementation.
Mar 21, 2023
265f016
Make SmartCompton identical to BEAMnrc implementation...2nd commit.
Mar 31, 2023
1d8cef0
Changed SmartCompton to BEAMnrc implementation...1st crack.
Mar 31, 2023
b9fb2c9
More changes to doSmartCompton to match BEAMnrc implementation.
Apr 14, 2023
bbe2fdc
Final changes to doSmartCompton to match BEAMnrc implementation.
Apr 21, 2023
f30144b
Some debugging statements.
Apr 22, 2023
682f922
Likely some debug statements.
May 5, 2023
ee747a7
Ooops, introduced bug in BEAMnrc implementation of SmartCompton.
May 12, 2023
07901a2
Remove debug stop from egs_phsp_scoring.
May 12, 2023
4fe6a53
Get rid of commented out debug statement.
May 12, 2023
0bf67af
Revert to default value of $MAXBRSPLIT.
May 12, 2023
189bf10
Get rid of repeat definition of getNp().
May 12, 2023
eb03a95
Fixed bug in doSmartBrems latch setting.
May 30, 2023
671bcdb
Implement beampp version of doSmartCompton.
Sep 1, 2023
aff3a1e
Fixed bug setting region no. for phat photon in doSmartCompton.
Sep 13, 2023
79ed4c4
Mid debug 12/05/2023.
Dec 5, 2023
b43a33f
Restore functionality after debug.
Jan 15, 2024
5e425f0
Subject all nonphat photons to RR before interacting.
Apr 2, 2024
d54adf5
Fix sampling indices in doSmartBrems.
May 16, 2024
b164dac
Rename some variables. A bit of cleanup.
May 17, 2024
3fb4dc3
Small changes, plus disable smartCompton.
May 21, 2024
631eb33
Latest fixes including eliminate unnecessary fat photon from smart br…
May 27, 2024
7f88689
Formatting!
Jun 3, 2024
c03fa23
(Re)implement doSmartCompton based on BEAMnrc algorithm.
Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement beampp version of doSmartCompton.
  • Loading branch information
Blake Walters authored and Blake Walters committed May 31, 2024
commit 671bcdb7057bef5189eb38f1be64878f36e9c816
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ int EGS_RadiativeSplitting::doInteractions(int iarg, int &killed)
{
//label as nonphat to be passed on to descendents
latch = latch & ~(1 << 0);
app->setLatch(latch);
app->top_p.latch=latch; //have to set this because it is used in doSmartCompton
app->setLatch(latch); //reset latch of interacting photon
doSmartCompton(nint);
}
else //straight-up compton
Expand Down Expand Up @@ -766,8 +765,6 @@ void EGS_RadiativeSplitting::getCostMinMax(const EGS_Vector &xx, const EGS_Vecto
double st2 = u*u + v*v;
double st = sqrt(st2);

/*

// handle odd cases st=0 and/or ro=0
if( st2 < 1e-10 ) {
double dmin = sqrt(d2 + (r-ro)*(r-ro)),
Expand All @@ -788,8 +785,6 @@ void EGS_RadiativeSplitting::getCostMinMax(const EGS_Vector &xx, const EGS_Vecto
return;
}

*/

EGS_Float dmin = ro <= fs ? d : sqrt(d2 + (fs-ro)*(fs-ro));
EGS_Float dmax = sqrt(d2 + (fs+ro)*(fs+ro));
EGS_Float aux = w*d - u*xo - v*yo;
Expand Down Expand Up @@ -1155,7 +1150,7 @@ void EGS_RadiativeSplitting::uniformPhotons(int nsample, int n_split, EGS_Float
void EGS_RadiativeSplitting::doSmartCompton(int nint)
{

//This is based on (i.e. copied from) the BEAMnrc implementation
//This is based on the beampp implementation

//get properties of interacting particle
int np = app->getNp();
Expand All @@ -1175,28 +1170,46 @@ void EGS_RadiativeSplitting::doSmartCompton(int nint)

EGS_Float Ko = E/app->getRM();
EGS_Float broi = 1+2*Ko, Ko2 = Ko*Ko;

//
// calculate probability for method 1: picking points within
// the circle and rejecting with probability sigma(direction)/sigma_max
//
EGS_Float dmin = ro <= fs ? d : sqrt(d*d + (ro-fs)*(ro-fs));
EGS_Float wnew = fs*fs*d/(2*dmin*dmin*dmin);
EGS_Float alpha1_t = log(broi);
EGS_Float eps1_t = 1./broi, eps2_t = 1;
EGS_Float eps1_t = 1/broi, eps2_t = 1;
EGS_Float w2 = alpha1_t*(Ko2-2*Ko-2)+(eps2_t-eps1_t)*
(1./eps1_t/eps2_t + broi + Ko2*(eps1_t+eps2_t)/2);
EGS_Float eps12_t = eps1_t*eps1_t; EGS_Float alpha2_t = (eps2_t*eps2_t-eps12_t);
EGS_Float alpha_t = alpha1_t/(alpha1_t+alpha2_t/2);
EGS_Float eps1 = 1./(1+Ko*(1-ct_min)), eps2 = 1./(1+Ko*(1-ct_max));
EGS_Float eps1_0 = eps1, eps2_0 = eps2;
EGS_Float fnorm = w2/(Ko2*Ko);
EGS_Float a = 1 + Ko*(1-ct_max); EGS_Float a2 = a*a;
EGS_Float f1 = (1/a + a - 1 + ct_max*ct_max)/a2;
a = 1 + Ko*(1-ct_min); a2 = a*a;
EGS_Float f2 = (1/a + a - 1 + ct_min*ct_min)/a2;
EGS_Float fmax = f1 > f2 ? f1 : f2;
wnew *= fmax/fnorm;

//
// calculate probability for method 2: picking directions
// between ct_min and ct_max and rejecting those not going towards
// the circle
//
EGS_Float eps1 = 1/(1+Ko*(1-ct_min)), eps2 = 1/(1+Ko*(1-ct_max));
EGS_Float alpha1 = log(eps2/eps1);
EGS_Float w1 = alpha1*(Ko2-2*Ko-2)+(eps2-eps1)*(1./eps1/eps2 + broi
+ Ko2*(eps1+eps2)/2);
EGS_Float eps12 = eps1*eps1, alpha2 = (eps2*eps2-eps12);
EGS_Float alpha = alpha1/(alpha1+alpha2/2);
EGS_Float rej1 = 1-(1-eps1)*(broi*eps1-1)/(Ko*Ko*eps1*(1+eps1*eps1));
EGS_Float rej2 = 1-(1-eps2)*(broi*eps2-1)/(Ko*Ko*eps2*(1+eps2*eps2));
EGS_Float rejmax = max(rej1,rej2);

//determine no. of interactions to sample
EGS_Float wc = w1/w2;
EGS_Float asample = wc*nint; int nsample = (int) asample;

//
// number of interactions to sample
//
bool method1; EGS_Float wprob;
if( wnew <= wc ) { method1 = true; wprob = wnew; }
else { method1 = false; wprob = wc; }
EGS_Float asample = wprob*nint; int nsample = (int) asample;
asample -= nsample; if( app->getRngUniform() < asample ) ++nsample;


// prepare rotations--not totally sure why this is needed
EGS_Float sinpsi, sindel, cosdel; bool need_rotation;
sinpsi = u.x*u.x + u.y*u.y;
Expand All @@ -1209,111 +1222,126 @@ void EGS_RadiativeSplitting::doSmartCompton(int nint)
//
// sample interactions towards circle
//

EGS_Float br,sint,cost,cphi,sphi; //declared out here because they are also used for the electron below
EGS_Particle p;

for(int j=0; j<=nsample; j++)
{
EGS_Float temp, rejf;

if (j==nsample)
{
//for fat photon directed away from field
eps1 = eps1_t; eps2 = 1; eps12 = eps12_t;
alpha1 = alpha1_t; alpha2 = alpha2_t; alpha = alpha_t;
rejmax = 1;
app->deleteParticleFromStack(np); //overwrite interacting photon
if( method1 ) {
for(int j=0; j<nsample; j++) {
EGS_Float x1, y1; int iw;
do {
x1 = 2*app->getRngUniform()-1; y1 = 2*app->getRngUniform()-1;
} while ( x1*x1 + y1*y1 > 1 );
x1 *= fs; y1 *= fs; iw = 1;
EGS_Float un = x1 - x.x, vn = y1 - x.y, wn = d;
EGS_Float dist = sqrt(un*un + vn*vn + wn*wn);
EGS_Float disti = 1/dist;
un *= disti; vn *= disti; wn *= disti;
EGS_Float cost = u.x*un + u.y*vn + u.z*wn;
EGS_Float aux = dmin*disti;
a = 1/(1 + Ko*(1-cost));
if( E*a > AP ) {
EGS_Float frej = (1/a+a-1+cost*cost)*a*a*aux*aux*aux;
if( app->getRngUniform()*fmax < frej ) {
EGS_Particle p;
p.x=x;
p.u = EGS_Vector(un,vn,wn);
p.ir=irl;
p.wt=wt;
p.latch=latch;
p.q=0;
p.E=E*a;
app->addParticleToStack(p,dnear);
}
}

}
}
else {
EGS_Float eps12 = eps1*eps1, alpha2 = (eps2*eps2-eps12);
EGS_Float alpha = alpha1/(alpha1+alpha2/2);
EGS_Float rej1 = 1-(1-eps1)*(broi*eps1-1)/(Ko*Ko*eps1*(1+eps1*eps1));
EGS_Float rej2 = 1-(1-eps2)*(broi*eps2-1)/(Ko*Ko*eps2*(1+eps2*eps2));
EGS_Float rejmax = max(rej1,rej2);
for(int j=0; j<nsample; j++) {
EGS_Float br,temp, cost, sint, rejf;
do {
if( app->getRngUniform() < alpha )
br = eps1*exp(alpha1*app->getRngUniform());
else
br = sqrt(eps12 + app->getRngUniform()*alpha2);
temp = (1-br)/(Ko*br); sint = temp*(2-temp);
rejf = 1 - br*sint/(1+br*br);
} while ( app->getRngUniform()*rejmax > rejf );

if ( temp < 2 )
{
} while ( app->getRngUniform()*rejmax > rejf || sint < 0 );
if( E*br > AP ) {
cost = 1 - temp; sint = sqrt(sint);
}
else
{
cost = -1; sint = 0;
}
app->getRngAzimuth(cphi,sphi);

int ns=0;
if (j==nsample)
{
//potential phat photon directed away from the field
if (br > eps1_0 && br < eps2_0)
{
break;
}
ns = nint;
}

EGS_Float un,vn,wn;
if( need_rotation )
{
EGS_Float us = sint*cphi, vs = sint*sphi;
un = u.z*cosdel*us - sindel*vs + u.x*cost;
vn = u.z*sindel*us + cosdel*vs + u.y*cost;
wn = u.z*cost - sinpsi*us;
}
else
{
un = sint*cphi;
vn = sint*sphi;
wn = u.z*cost;
}

if (j<nsample)
{
ns = nint;
//potential thin photon directed into the field
EGS_Float cphi,sphi;
app->getRngAzimuth(cphi,sphi);
EGS_Float un,vn,wn;
if( need_rotation ) {
EGS_Float us = sint*cphi, vs = sint*sphi;
un = u.z*cosdel*us - sindel*vs + u.x*cost;
vn = u.z*sindel*us + cosdel*vs + u.y*cost;
wn = u.z*cost - sinpsi*us;
} else { un = sint*cphi; vn = sint*sphi; wn = u.z*cost; }
int ns = 0;
if( wn > 0 ) {
EGS_Float aux = (ssd - x.z)/wn;
EGS_Float x1 = x.x + un*aux, y1 = x.y + vn*aux;
if( x1*x1 + y1*y1 < fs*fs ) ns = 1;
}
if (ns > 1)
{
//not sure if we really need this because smart compton should have taken
//care of the phat photon directed away from the field in the logic above, right?
if (app->getRngUniform()*ns > 1)
{
ns = 0;
}
if( ns > 0 ) {
EGS_Particle p;
p.x=x;
p.u = EGS_Vector(un,vn,wn);
p.ir=irl;
p.wt=wt;
p.latch=latch;
p.q=0;
p.E=E*a;
app->addParticleToStack(p,dnear);
}
}
}
}

if( ns > 0 ) {
//add the photon to the stack
p.x = x;
p.u = EGS_Vector(un,vn,wn);
p.ir = irl;
p.wt = wt*ns;
p.latch = latch;
if (ns > 1)
{
//label photon as phat
p.latch = latch | (1 << 0);
}
p.q = 0;
p.E = E*br;
// get potential high weight photon directed away from the field and compton electron.

eps1 = eps1_t; eps2 = eps2_t; alpha1 = alpha1_t;
EGS_Float eps12 = eps1*eps1; EGS_Float alpha2 = (eps2*eps2-eps12);
EGS_Float alpha = alpha1/(alpha1+alpha2/2);
EGS_Float br,temp, cost, sint, rejf;
do {
if( app->getRngUniform() < alpha )
br = eps1*exp(alpha1*app->getRngUniform());
else
br = sqrt(eps12 + app->getRngUniform()*alpha2);
temp = (1-br)/(Ko*br); sint = temp*(2-temp);
rejf = 1 - br*sint/(1+br*br);
} while ( app->getRngUniform() > rejf || sint < 0 );
cost = 1 - temp; sint = sqrt(sint);
EGS_Float cphi,sphi; app->getRngAzimuth(cphi,sphi);
if( E*br > AP) {
//this is a potential high wt photon directed away from the field
EGS_Float un,vn,wn;
if( need_rotation ) {
EGS_Float us = sint*cphi, vs = sint*sphi;
un = u.z*cosdel*us - sindel*vs + u.x*cost;
vn = u.z*sindel*us + cosdel*vs + u.y*cost;
wn = u.z*cost - sinpsi*us;
} else { un = sint*cphi; vn = sint*sphi; wn = u.z*cost; }
bool take_it = true;
if( wn > 0) {
EGS_Float t = (ssd-x.z)/wn;
EGS_Float x1 = x.x + un*t, y1 = x.y + vn*t;
if( x1*x1 + y1*y1 <= fs*fs ) take_it = false;
}
if( take_it ) {
EGS_Particle p;
p.x=x;
p.u=EGS_Vector(un,vn,wn);
p.wt=wt*nint;
p.latch=latch | (1 << 0);
p.q=0; p.E = E*br;
app->addParticleToStack(p,dnear);

EGS_Float dist = (ssd - p.x.z)/p.u.z;
EGS_Float r_dist = (p.x.x + p.u.x*dist)*(p.x.x + p.u.x*dist) +
(p.x.y + p.u.y*dist)*(p.x.y + p.u.y*dist);
r_dist = sqrt(r_dist);
}
}

//now the electron--Note: br, cost will have the values set for the phat photon
EGS_Float Eelec = E*(1-br);
EGS_Float aux = 1 + br*br - 2*br*cost;
Expand All @@ -1326,15 +1354,15 @@ void EGS_RadiativeSplitting::doSmartCompton(int nint)
vn = u.z*sindel*us + cosdel*vs + u.y*cost;
wn = u.z*cost - sinpsi*us;
}
EGS_Particle p;
p.x = x;
p.u = EGS_Vector(un,vn,wn);
p.ir = irl;
p.wt = wt*nint;
p.latch = latch | (1 << 0);
p.q = -1;
p.E = Eelec + app->getRM();
//replace original interacting photon with this particle
app->updateParticleOnStack(np,p,dnear);
app->addParticleToStack(p,dnear);
}

void EGS_RadiativeSplitting::initSmartKM(EGS_Float Emax) {
Expand Down