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

Point Detector Tally #3109

Open
wants to merge 79 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
21efc8d
changed output, now printing xs in every collision
Itay-max Oct 25, 2022
8269657
created get pdf value and didnt use it
Itay-max Oct 25, 2022
9d1f196
implemented u_com and tried making a ghost particle for each collisio…
Itay-max Oct 25, 2022
64f1d40
succefuly calculated mean free path using a ghost parrticle. memory p…
Itay-max Oct 25, 2022
22a54ca
cant kill particles
Itay-max Oct 25, 2022
4e3ab1d
finally fixed the problem of generating the gost particle and trackin…
Itay-max Oct 25, 2022
f48ef19
added a new estimtor named point - works
Itay-max Oct 25, 2022
c2dfc90
tried adding Mu lab calcs but coulndt compile
Itay-max Oct 25, 2022
23a7d14
added arik function but only took one solution for mu com
Itay-max Oct 25, 2022
6ac128f
implementd two solution for comCM
Itay-max Oct 25, 2022
913273d
getting similar results to mcnp but assuming target is in rest
Itay-max Oct 25, 2022
65f3033
added v_t = velcity of target particle as a property of particle data
Itay-max Oct 25, 2022
52d337e
using v_t for calcualtion of p2 , no longer assuming target in rest
Itay-max Oct 25, 2022
bff894c
changed p2 calc and verified it by maxwell boltzman distirbution
Itay-max Oct 25, 2022
eb3fcb8
printing temprature
Itay-max Oct 25, 2022
bcae8f7
Merge branch 'Ecalc' of https://github.com/itayhorin/openmc into Ecalc
Itay-max Oct 25, 2022
d860ce7
Merge pull request #1 from itayhorin/Ecalc
Itay-max Oct 25, 2022
8b70afb
Merge branch 'develop' of https://github.com/Itay-max/openmc into dev…
Jul 27, 2023
be52bad
working point tally for elastic scattering
Nov 13, 2023
ab940cf
Merge branch 'develop' of https://github.com/itay-space/openmc into d…
Nov 13, 2023
ad47f6b
trying to add contribution from source
Nov 16, 2023
bf1f515
flux from source is calcualted in tally scoring
Nov 18, 2023
bcab472
added get_MFP function and trying to read inelastic angle energy dist…
Nov 19, 2023
4b0b402
energy filter works for point det
Nov 23, 2023
60df643
trying to get pdf from inelastic disrtibutions
Nov 28, 2023
ca6f94c
calculating pdfs in a diffenent function
Nov 28, 2023
cf30f45
doing kinemtics and calcuating pdf for elastic scattering in a new fu…
Nov 28, 2023
f96377e
get the positin of the detector in a new function
Nov 28, 2023
6c90155
detector position in a new function
Nov 28, 2023
e44d140
working on detector positin function
Nov 28, 2023
666bf5e
looping on the ghost particles and calcuting their flux contibution a…
Nov 28, 2023
f8de667
Made sure the target veloity is initialzied to zero in inelastic scat…
Nov 28, 2023
a969cd4
Added mu_cm calcuation for KalbachMann distrubition.
Nov 29, 2023
310e660
calculating pdf_lab using derivative and chagning function to void so…
Nov 29, 2023
42b87c6
Now filling ghost particles and getting pdfs from Uncorrelated angle …
Nov 29, 2023
a6c51f9
Now creating also ghost particle from nbodyphase space distribution
Nov 30, 2023
1439772
fixed all calcualtions in inelastic, accidently took mu_cm from sampling
Nov 30, 2023
e7aae35
only taking solutions that conserve energy.
Nov 30, 2023
db48c1c
multiply the weight with yield for example n,2n is 2
Dec 3, 2023
8a3e48e
calculating pdf and generating ghost particles in Correlated distribu…
Dec 3, 2023
1c519fc
trying to creat ghost particles from fission
Dec 5, 2023
77ffc54
scoring ghost particles from fission is working now
Dec 5, 2023
690c705
added tools to make discrete mu distrubtion to pdf values
Dec 6, 2023
7b8135d
added pdfs calculations for IncoherentElastic and CoherentElasticAE +…
Dec 6, 2023
023baab
added pdf calculations for Discrete Incohernet both for elastic and i…
Dec 6, 2023
daf65f3
added pdf for incohernet inelastic
Dec 6, 2023
c33df5a
printing the thermal distribution used.
Dec 6, 2023
e86efdd
distinguish from non s(a,b) elastic scattering to prevent double scoring
Dec 6, 2023
bd53fb7
creating the ghost particle from s(a,b) and getting pdf in physics.cpp
Dec 6, 2023
f5fde24
scoring the ghost particle in a designated function
Dec 10, 2023
cb09cb7
scoring the ghost paritcles in S(a,b)
Dec 10, 2023
56698e6
added pdf contribution from coherentleastic. and can print to file pd…
Dec 13, 2023
16db49e
initialized p.event._index_mt every collision to distinguish between …
Dec 23, 2023
93dfd87
fixed coherentElastic
Dec 26, 2023
2a37ce7
trying arik's function
Dec 28, 2023
a8124ef
added inelastic function
Dec 28, 2023
13801e1
also included fission to be in the new scoring method
Dec 29, 2023
809769b
Had a bug in the formula for cond and insq. wasa using p1_cm instaed …
Jan 2, 2024
090a111
merged elastic and inelatic by repalcing m4
Jan 2, 2024
5f21e9f
added option to add point detector via python api
Jan 2, 2024
549c66e
same q for both sols and also using approx more often
Jan 2, 2024
4848fb7
modified tolernace param to use approx
Jan 7, 2024
e14851b
implemented multiple detectors
Jan 7, 2024
4e58b2c
trying to add exclusion sphere and also no need for score fission net…
Jan 16, 2024
612ff60
fixed the MFP function so now the exculsion sphere works
Jan 18, 2024
f05488f
contibution is now only from external source
Jan 30, 2024
41221f6
User now have to specify R0 (dor the exclusion sphere radius) and als…
May 13, 2024
075b87c
We Fixed cohernetElastic!
Jun 6, 2024
b3cb01a
discrete distribution was not implemented
Aug 4, 2024
9881ab0
Point tally detector development
Aug 6, 2024
26f4fd1
fixed: Expected function implmention (virtual)
Aug 13, 2024
aa1e4e6
Merge branch 'deploy' of https://github.com/itay-space/openmc into de…
Aug 13, 2024
f0480c4
Fixed H1 2 soultions and not scoring while particle is outside of geo…
Nov 5, 2024
5a57f2e
Merge branch 'exclusion_sphere' into HEAD
Nov 10, 2024
132be34
applied clang-format-15
Nov 10, 2024
e5ac4d4
Applied PEP8
Nov 10, 2024
b0e4073
Merge branch 'develop' of https://github.com/itay-space/openmc into d…
Nov 14, 2024
77b53dc
Merge branch 'develop' into deploy
Nov 14, 2024
6975156
Implementd contribution from muitlpe sources, and verified al working…
Nov 26, 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
implementd two solution for comCM
  • Loading branch information
Itay-max committed Oct 25, 2022
commit 6ac128f92793a858444f484cd20561dc1e25861d
Empty file added bla
Empty file.
2 changes: 1 addition & 1 deletion include/openmc/tallies/tally_scoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void Vcros(double A[4],double B[4],double C[4]);
void Vunit(double A[4] ,double B[4]);


void getMu_COM(double x_det , double y_det , double z_det ,Particle p_col , double awr , double incoming_mass, double ReturnArray[],int diff_mode,double dl );
void getMu_COM(double x_det , double y_det , double z_det ,Particle p_col , double awr , double ReturnArray[],int diff_mode,double dl );

//! Analog tallies are triggered at every collision, not every event.
//
Expand Down
283 changes: 271 additions & 12 deletions src/tallies/tally_scoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2432,14 +2432,12 @@ void score_point_tally(Particle& p)
std::cout << "mass in ev " << p.getMass() << std::endl ;
// Determine the collision estimate of the flux
bool verbose=true;
double ReturnArray[2];
double ReturnArray[4];
double flux = 0.0;
const auto& nuc {data::nuclides[p.event_nuclide()]};
double awr = nuc->awr_;
//auto [value1, value2] = getMu_COM(0,0,0,p,awr,p.getMass(),ReturnArray);
//double ResultsArray = getMu_COM(0,0,0,p,awr,p.getMass());
double dl = 1e-5;
getMu_COM(0,0,0,p,awr,p.getMass(),ReturnArray , 0, dl);
getMu_COM(0,0,0,p,awr,ReturnArray , 0, dl);
const auto& rx {nuc->reactions_[0]};
auto& d = rx->products_[0].distribution_[0];
auto d_ = dynamic_cast<UncorrelatedAngleEnergy*>(d.get());
Expand All @@ -2449,24 +2447,27 @@ void score_point_tally(Particle& p)
double theta_lab = std::acos(cos_lab);
double sin_lab = std::sin(theta_lab);
double mu_COM_or_itay = (std::sqrt(awr*awr - sin_lab*sin_lab)*cos_lab - sin_lab*sin_lab)/awr;
double mu_COM = ReturnArray[0];
double ReturnArrayPlus[2];
double ReturnArrayMinus[2];
double mu_COM1 = ReturnArray[0];
double E1 = ReturnArray[2];
double mu_COM2 = ReturnArray[1];
double E2 = ReturnArray[3];
//double ReturnArrayPlus[4];
//double ReturnArrayMinus[4];
//getMu_COM(0,0,0,p,awr,p.getMass(),ReturnArrayPlus ,1 , 1e-5 );
//getMu_COM(0,0,0,p,awr,p.getMass(),ReturnArrayMinus ,-1 , 1e-5 );
//double MuPlus = ReturnArrayPlus[0]; // not sure about changing mu lab correctly
//double MuMinus = ReturnArrayMinus[0];
double theta_pdf = d_->angle().get_pdf_value(p.E_last(),mu_COM,p.current_seed());
double theta_pdf = d_->angle().get_pdf_value(p.E_last(),mu_COM1,p.current_seed());

//double derivative = std::abs(MuPlus-MuMinus)/(2*dl);
double derivative =1;
double theta_pdf_lab = theta_pdf * derivative;
//double E_ghost = p.E_last()*(1+awr*awr+2*awr*mu_COM)/(1+awr)/(1+awr);

//double m_incoming =MASS_NEUTRON_EV;
double E_ghost = ReturnArray[1];
double E_ghost = E1;

if(!std::isnan(mu_COM))
if(true)//(!std::isnan(mu_COM1))
{
Particle ghost_particle=Particle();
ghost_particle.initilze_ghost_particle(p,u_lab,E_ghost);
Expand Down Expand Up @@ -2519,7 +2520,8 @@ void score_point_tally(Particle& p)
fmt::print("parent particle E = {}\n",p.E_last());
fmt::print("ghost particle E = {}\n",ghost_particle.E());
fmt::print("ghost particle u = {0} , {1} , {2}\n",ghost_particle.u().x,ghost_particle.u().y,ghost_particle.u().z);
fmt::print("ghost particle Mu COM Arik= {}\n",mu_COM);
fmt::print("ghost particle Mu COM 1 Arik= {}\n",mu_COM1);
fmt::print("ghost particle Mu COM 2 Arik= {}\n",mu_COM2);
fmt::print("ghost particle Mu COM Or and Itay = {}\n",mu_COM_or_itay);
fmt::print("flux = {}\n",flux);
fmt::print("theta cm pdf ={} \n",theta_pdf);
Expand Down Expand Up @@ -2635,7 +2637,7 @@ void score_surface_tally(Particle& p, const vector<int>& tallies)
}



/*


void getMu_COM(double x_det , double y_det , double z_det ,Particle p_col , double awr , double incoming_mass ,double ReturnArray[],int diff_mode,double dl )
Expand Down Expand Up @@ -2882,6 +2884,263 @@ void Vcros(double A[4],double B[4],double C[4])

return;
}
*/


//Author: Arik Kreisel


void getMu_COM(double x_det , double y_det , double z_det ,Particle p_col , double awr ,double ReturnArray[],int diff_mode,double dl )
{

double cs=0;
int m=0;

double m1= p_col.getMass()/1e6; // mass of incoming particle in MeV
double E1_tot = p_col.E_last()/1e6 + m1; // total Energy of incoming particle in MeV
double p1_tot = std::sqrt(E1_tot*E1_tot - m1*m1);
double r1[4] = {0, x_det, y_det, z_det}; // detector position lab {ignor, x, y, z}
double r2[4]= {0, p_col.r().x, p_col.r().y, p_col.r().z}; // collision position lab {ignor, x, y, z}
double r3[4]; // r1-r2 vector from collision to detector
double m2= m1*awr; // mass of target matirial
double m3= m1; // mass of outgoing particle to detector
double m4= m2; // mass of recoil target system
double p1[3]={p1_tot*p_col.u_last().x,p1_tot* p_col.u_last().y,p1_tot* p_col.u_last().z}; // 3 momentum of incoming particle
double p2[3]={0, 0, 0}; //3 momentum of target in lab

// calculate
double Fp1[4]; //four momentum of incoming particle in LAB
double Fp2[4]; //four momentum of target in LAB
double Fp3[4]; //four momentum of particle going to the detector in LAB
double UFp3[4]; //unit 3 momentum of particle going to the detector
double CM[4]; //four momentum of center of mass frame in lab
double LAB[4]; //four momentum of lab in center of mass frame
double mCM; // mass of center of mass system
double pCM; // momentum of center of mass system
double p3LAB[2]; // momentum of out particle

double CMFp1[4]; //four momentum of incoming particle in CM
double CMFp2[4]; //four momentum of incoming target in CM
double CMFp3[4]; //four momentum of out particle in CM
double CMFp4[4]; //four momentum of out target in CM
double Fp4[4]; //four momentum of out target in LAB
double CMUp1[4]; //unit three vector of incoming particle in CM
double CMUp3[4]; //unit three vector of out particle in CM
double cosCM; // cosine of out going particle to detector in CM frame
double cosLAB; // cosine of out going particle to detector in LAB frame
double CME3; // Energy of out particle in CM
double CMp3; // momentum of out particle in CM
double Ur3[4], UCM[4], ULAB[4];
double aa, bb, cc;


Fp1[0]=0;
Fp2[0]=0;
CM[0]=0;
LAB[0]=0;
r3[0]=0;


for(int i=0; i<3; i++){
Fp1[i+1]=p1[i];
Fp2[i+1]=p2[i];
CM[i+1]=Fp1[i+1]+Fp2[i+1];
LAB[i+1]=-CM[i+1];
r3[i+1]=r1[i+1]-r2[i+1];
}

Fp1[0]=sqrt(Fp1[1]*Fp1[1]+Fp1[2]*Fp1[2]+Fp1[3]*Fp1[3]+m1*m1);
Fp2[0]=sqrt(Fp2[1]*Fp2[1]+Fp2[2]*Fp2[2]+Fp2[3]*Fp2[3]+m2*m2);
CM[0]=Fp1[0]+Fp2[0];
LAB[0]=CM[0];
r3[0]=0;

mCM=sqrt(CM[0]*CM[0]-CM[1]*CM[1]-CM[2]*CM[2]-CM[3]*CM[3]);
pCM=sqrt(CM[1]*CM[1]+CM[2]*CM[2]+CM[3]*CM[3]);
CME3=(mCM*mCM-m4*m4+m3*m3)/(2*mCM); // energy of out going particle in CM
CMp3=sqrt(CME3*CME3-m3*m3);

std::cout<<" mCM= "<<mCM<<" pCM= "<<pCM<<" CME3= "<<CME3<<std::endl;

boostf(CM,Fp1,CMFp1);
boostf(CM,Fp2,CMFp2);

Vunit(CM,UCM);
Vunit(LAB,ULAB);
Vunit(r3,Ur3);
cosLAB=Vdot(UCM,Ur3);

std::cout<<"cosLAB= "<<cosLAB<<std::endl;
Vunit(CMFp1,CMUp1);


aa=pCM*pCM*cosLAB*cosLAB-CM[0]*CM[0];
bb=2*pCM*cosLAB*CME3*mCM;
cc=CME3*mCM*CME3*mCM-m3*m3*CM[0]*CM[0];

int j=1;

if(bb*bb-4*aa*cc<0) {
std::cout<<" detector out of range" <<std::endl;
return; //continue;
}
p3LAB[0]=(-bb+sqrt(bb*bb-4*aa*cc))/2.0/aa;
if(p3LAB[0]<=0) {p3LAB[0]=(-bb-sqrt(bb*bb-4*aa*cc))/2/aa;
if(p3LAB[0]<=0) {
std::cout<<" detector out of range" <<std::endl;
return; //continue;
}
}
else if(p3LAB[0]>0){p3LAB[1]=(-bb-sqrt(bb*bb-4*aa*cc))/2/aa;
if(p3LAB[1]>0) j=j+1;
}

std::cout<<" p3LAB1= "<<(-bb+sqrt(bb*bb-4*aa*cc))/2.0/aa<<" p3LAB2= "<<(-bb-sqrt(bb*bb-4*aa*cc))/2.0/aa<<std::endl;

for (int l=0;l<j;l++){

std::cout<<"l= "<<l<<std::endl;

Fp3[0]=sqrt(p3LAB[l]*p3LAB[l]+m3*m3);
for(int i=0; i<3; i++){
Fp3[i+1]=p3LAB[l]*Ur3[i+1];
}

boostf(CM,Fp3,CMFp3);
Vunit(CMFp3,CMUp3);
cosCM=Vdot(UCM,CMUp3); // input to openMC Cross section calculation
ReturnArray[l] = cosCM;
ReturnArray[l+2] = (Fp3[0]-m3)*1e6; //retrun Energy in eV

std::cout<<"cosCM= "<<cosCM<<std::endl;

std::cout<<" ----------- sanity tests for solution "<< l <<" -----------------------------------"<<std::endl;

Vunit(Fp3,UFp3);

std::cout<<Vdot(UCM,UFp3)<<" = cosLAB = "<<cosLAB<<std::endl;

std::cout<<CMFp3[0]<<" m3 energy in CM "<<CME3<<std::endl;

CMFp4[0]=0;
for(int i=0; i<3; i++){
CMFp4[i+1]=-CMFp3[i+1];
}
CMFp4[0]=sqrt(m4*m4+CMFp4[1]*CMFp4[1]+CMFp4[2]*CMFp4[2]+CMFp4[3]*CMFp4[3]);
boostf(LAB,CMFp4,Fp4);

for(int i=0; i<4; i++){
std::cout<<i<<" "<<CM[i]<<" = energy momentum conserv in LAB = "<<Fp4[i]+Fp3[i]<<std::endl;
std::cout<<i<<" "<<CMFp1[i]+CMFp2[i]<<" = energy momentum conserv in CM = "<<CMFp4[i]+CMFp3[i]<<std::endl;
}



double test[4];
boostf(LAB,CMFp3,test);
for (int i=0; i<4; i++){
std::cout<<i<<" "<<test[i]<<std::endl;
std::cout<<i<<" "<<Fp3[i]<<std::endl;
}

std::cout <<" m3 enerrgy in lab ="<<Fp3[0]<<std::endl;
std::cout <<" m4 enerrgy in lab ="<<Fp4[0]<<std::endl;
std::cout <<" sqrt(E3^2-P3^2) in lab ="<<sqrt(Fp3[0]*Fp3[0]-Fp3[1]*Fp3[1]-Fp3[2]*Fp3[2]-Fp3[3]*Fp3[3])<<std::endl;
std::cout <<" sqrt(E4^2-P4^2) in lab ="<<sqrt(Fp4[0]*Fp4[0]-Fp4[1]*Fp4[1]-Fp4[2]*Fp4[2]-Fp4[3]*Fp4[3])<<std::endl;
std::cout <<" m1 enerrgy in lab ="<<Fp1[0]<<std::endl;

double tanLab=sqrt(1-cosCM*cosCM)/(CM[0]/mCM*(pCM*CME3/CM[0]/CMp3+cosCM));
double fCOSlab=cos(atan(tanLab));


std::cout<<"cos( atan( tanLab= "<<cos(atan(tanLab))<<std::endl;

}

}


void boostf( double A[4], double B[4], double X[4])
{
//
// boosts B(labfram) to A rest frame and gives output in X
//
double W;
int j;

if ((A[0]*A[0]-A[1]*A[1]-A[2]*A[2]-A[3]*A[3])<=0) {
std::cout <<"negative sqrt in boostf"<<A[0]<<A[1]<<A[2]<<A[3]<<std::endl;}

W=sqrt(A[0]*A[0]-A[1]*A[1]-A[2]*A[2]-A[3]*A[3]);

if(W==0 || W==(-A[0])) std::cout <<"divid by 0 in boostf"<<std::endl;

X[0]=(B[0]*A[0]-B[3]*A[3]-B[2]*A[2]-B[1]*A[1])/W;
for(j=1; j<=3; j++) {
X[j]=B[j]-A[j]*(B[0]+X[0])/(A[0]+W);
}

return;
}




double Vdot(double A[4],double B[4])
{
int j;

double dot = 0;

for(j=1; j<=3; j++) {
dot = dot + A[j]*B[j];
}


return dot;
}


void Vunit(double A[4] ,double B[4])
{
double fff;
int j;

fff = 0;

for(j=1; j<=3; j++) {
fff = fff + A[j]*A[j];
}

if (fff==0) {
std::cout <<"in vunit divid by zero" << std::endl;
return;
}

for(j=1; j<=3; j++) {
B[j] = A[j]/sqrt(fff);
}
B[0] = 0;

return;
}


void Vcros(double A[4],double B[4],double C[4])
{
C[1] = A[2]*B[3]-A[3]*B[2];
C[2] = A[3]*B[1]-A[1]*B[3];
C[3] = A[1]*B[2]-A[2]*B[1];
C[0] = 0;

if (C[1]==0 && C[2]==0 && C[3]==0.) {
std::cout << "vcross zero" << std::endl;
}

return;
}




} // namespace openmc