mirror of
https://github.com/gwm17/catima.git
synced 2024-11-22 18:28:51 -05:00
Add forward and reverse energy loss integrators using similar methods to those of the Yale SPANC integrators
This commit is contained in:
parent
99471cfc0c
commit
56c624f24b
86
gwm_integrators.cpp
Normal file
86
gwm_integrators.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "catima/gwm_integrators.h"
|
||||
|
||||
namespace catima {
|
||||
|
||||
double integrate_energyloss(Projectile& proj, const Material& mat, const Config& c)
|
||||
{
|
||||
static double s_estep_max = 0.001;
|
||||
static int s_depth_max = 100;
|
||||
int depth = 0;
|
||||
double e_in = proj.T; // MeV/u
|
||||
double e_final = e_in;
|
||||
double x_step = 0.25*mat.thickness(); //g/cm^2
|
||||
double x_traversed = 0.0;
|
||||
double e_step = dedx(proj, mat, c)*x_step;
|
||||
|
||||
while(true)
|
||||
{
|
||||
if(e_step/e_final > s_estep_max && depth < s_depth_max)
|
||||
{
|
||||
++depth;
|
||||
x_step *= 0.5;
|
||||
e_step = dedx(proj, mat, c)*x_step;
|
||||
}
|
||||
else if(x_step + x_traversed >= mat.thickness())
|
||||
{
|
||||
x_step = mat.thickness() - x_traversed;
|
||||
e_step = dedx(proj, mat, c)*x_step;
|
||||
e_final -= e_step;
|
||||
proj.T = e_final;
|
||||
return (e_in - e_final)*proj.A;
|
||||
}
|
||||
else if(depth == s_depth_max)
|
||||
{
|
||||
return e_in*proj.A;
|
||||
}
|
||||
else
|
||||
{
|
||||
e_step = dedx(proj, mat, c)*x_step;
|
||||
e_final -= e_step;
|
||||
proj.T = e_final;
|
||||
x_traversed += x_step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double reverse_integrate_energyloss(Projectile& proj, const Material& mat, const Config& c)
|
||||
{
|
||||
static double s_estep_max = 0.001;
|
||||
static int s_depth_max = 100;
|
||||
int depth = 0;
|
||||
double e_out = proj.T; //MeV/u
|
||||
double e_initial = e_out;
|
||||
double x_step = 0.25*mat.thickness(); //g/cm^2
|
||||
double x_traversed = 0.0;
|
||||
double e_step = dedx(proj, mat, c)*x_step;
|
||||
|
||||
while(true)
|
||||
{
|
||||
if(e_step/e_initial > s_estep_max && depth < s_depth_max)
|
||||
{
|
||||
++depth;
|
||||
x_step *= 0.5;
|
||||
e_step = dedx(proj, mat, c)*x_step;
|
||||
}
|
||||
else if(x_step + x_traversed >= mat.thickness())
|
||||
{
|
||||
x_step = mat.thickness() - x_traversed;
|
||||
e_step = dedx(proj, mat, c)*x_step;
|
||||
e_initial += e_step;
|
||||
proj.T = e_initial;
|
||||
return (e_initial - e_out)*proj.A;
|
||||
}
|
||||
else if(depth == s_depth_max)
|
||||
{
|
||||
return e_out*proj.A;
|
||||
}
|
||||
else
|
||||
{
|
||||
e_step = dedx(proj, mat, c)*x_step;
|
||||
e_initial += e_step;
|
||||
proj.T = e_initial;
|
||||
x_traversed += x_step;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
gwm_integrators.h
Normal file
13
gwm_integrators.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef GWM_INTEGRATORS_H
|
||||
#define GWM_INTEGRATORS_H
|
||||
|
||||
#include "catima/catima.h"
|
||||
|
||||
namespace catima {
|
||||
|
||||
double integrate_energyloss(Projectile& proj, const Material& mat, const Config& c=default_config);
|
||||
|
||||
double reverse_integrate_energyloss(Projectile& proj, const Material& mat, const Config& c=default_config);
|
||||
}
|
||||
|
||||
#endif
|
18
gwm_test/Makefile
Normal file
18
gwm_test/Makefile
Normal file
|
@ -0,0 +1,18 @@
|
|||
CC=g++
|
||||
EXE=gwm_test
|
||||
CXX_FLAGS= -std=c++17 -g -Wall
|
||||
|
||||
CATIMA_PATH=../build/
|
||||
LIB_PATH=$(CATIMA_PATH)lib/
|
||||
INCLUDE_PATH=$(CATIMA_PATH)include/
|
||||
CPP=gwm_test.cpp
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(EXE)
|
||||
|
||||
$(EXE): $(CPP)
|
||||
$(CC) $(CXX_FLAGS) -I$(INCLUDE_PATH) $^ $(LIB_PATH)libcatima.a -o $@
|
||||
|
||||
clean:
|
||||
$(RM) $(EXE)
|
17
gwm_test/gwm_test.cpp
Normal file
17
gwm_test/gwm_test.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "catima/gwm_integrators.h"
|
||||
#include "catima/nucdata.h"
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout<<"-------Testing GWM Energy Loss Integration-------"<<std::endl;
|
||||
catima::Projectile p1(catima::element_atomic_weight(1), 1.0, 0, 3.0);
|
||||
catima::Material mat1(catima::get_material(6));
|
||||
mat1.density(2.23).thickness(500.0*1e-6);
|
||||
|
||||
double result = catima::integrate_energyloss(p1, mat1);
|
||||
std::cout<<"Energy loss (MeV): "<<result<<" Final energy: "<<p1.T<<std::endl;
|
||||
result = catima::reverse_integrate_energyloss(p1, mat1);
|
||||
std::cout<<"Reverse Energy loss (MeV): "<<result<<" Initial energy: "<<p1.T<<std::endl;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user