add enablerutherford scattering flag to opal collimatorphysics

This commit is contained in:
Uldis Locans
2017-04-27 10:54:02 +02:00
parent 432d2f5e4e
commit 61919ae53c
9 changed files with 38 additions and 23 deletions

View File

@ -16,7 +16,8 @@ public:
virtual ~DKSCollimatorPhysics() { } virtual ~DKSCollimatorPhysics() { }
virtual int CollimatorPhysics(void *mem_ptr, void *par_ptr, int numpartices) = 0; virtual int CollimatorPhysics(void *mem_ptr, void *par_ptr, int numpartices,
bool enableRutherforScattering = true) = 0;
virtual int CollimatorPhysicsSoA(void *label_ptr, void *localID_ptr, virtual int CollimatorPhysicsSoA(void *label_ptr, void *localID_ptr,
void *rx_ptr, void *ry_ptr, void *rz_ptr, void *rx_ptr, void *ry_ptr, void *rz_ptr,

View File

@ -23,9 +23,10 @@
#define X0_M 9 #define X0_M 9
#define I_M 10 #define I_M 10
#define DT_M 11 #define DT_M 11
#define LOWENERGY_THR 12
#define BLOCK_SIZE 128 #define BLOCK_SIZE 128
#define NUMPAR 12 #define NUMPAR 13
__device__ inline double dot(double3 &d1, double3 &d2) { __device__ inline double dot(double3 &d1, double3 &d2) {
@ -89,7 +90,7 @@ __device__ inline void energyLoss(double &Eng, bool &pdead, curandState &state,
Eng = Eng + delta_E / 1E3; Eng = Eng + delta_E / 1E3;
} }
pdead = ((Eng<1E-4) || (dEdx>0)); pdead = ( (Eng < par[LOWENERGY_THR]) || (dEdx > 0) );
} }
@ -125,7 +126,9 @@ __device__ inline void Rot(double &px, double &pz, double &x, double &z, double
pz = -pxz*sin(Psixz)*sin(thetacou) + pxz*cos(Psixz)*cos(thetacou); pz = -pxz*sin(Psixz)*sin(thetacou) + pxz*cos(Psixz)*cos(thetacou);
} }
__device__ inline void coulombScat(double3 &R, double3 &P, curandState &state, double* par) { __device__ inline void coulombScat(double3 &R, double3 &P, curandState &state, double* par,
bool enableRutherfordScattering)
{
double Eng = sqrt(dot(P, P) + 1.0) * M_P - M_P; double Eng = sqrt(dot(P, P) + 1.0) * M_P - M_P;
double gamma = (Eng + M_P) / M_P; double gamma = (Eng + M_P) / M_P;
@ -153,7 +156,7 @@ __device__ inline void coulombScat(double3 &R, double3 &P, curandState &state, d
Rot(P.x, P.z, R.x, R.z, xplane, normP, thetacou, deltas, 1, par); Rot(P.x, P.z, R.x, R.z, xplane, normP, thetacou, deltas, 1, par);
double P2 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m); double P2 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m);
if(P2 < 0.0047) { if( (P2 < 0.0047) && enableRutherfordScattering) {
double P3 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m); double P3 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m);
double thetaru = 2.5 * sqrt(1 / P3) * sqrt(2.0) * theta0; double thetaru = 2.5 * sqrt(1 / P3) * sqrt(2.0) * theta0;
double P4 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m); double P4 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m);
@ -179,7 +182,7 @@ __device__ inline void coulombScat(double3 &R, double3 &P, curandState &state, d
Rot(P.y,P.z,R.y,R.z, yplane, normP, thetacou, deltas, 2, par); Rot(P.y,P.z,R.y,R.z, yplane, normP, thetacou, deltas, 2, par);
P2 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m); P2 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m);
if(P2 < 0.0047) { if( (P2 < 0.0047) && enableRutherfordScattering) {
double P3 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m); double P3 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m);
double thetaru = 2.5 * sqrt(1 / P3) * sqrt(2.0) * theta0; double thetaru = 2.5 * sqrt(1 / P3) * sqrt(2.0) * theta0;
double P4 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m); double P4 = curand_uniform_double(&state);//gsl_rng_uniform(rGen_m);
@ -193,7 +196,7 @@ __device__ inline void coulombScat(double3 &R, double3 &P, curandState &state, d
template <typename T> template <typename T>
__global__ void kernelCollimatorPhysics(T *data, double *par, curandState *state, __global__ void kernelCollimatorPhysics(T *data, double *par, curandState *state,
int numparticles) int numparticles, bool enableRutherfordScattering)
{ {
//get global id and thread id //get global id and thread id
@ -235,7 +238,7 @@ __global__ void kernelCollimatorPhysics(T *data, double *par, curandState *state
P.x = P.x * ptot / sq; P.x = P.x * ptot / sq;
P.y = P.y * ptot / sq; P.y = P.y * ptot / sq;
P.z = P.z * ptot / sq; P.z = P.z * ptot / sq;
coulombScat(R[tid], P, s, p); coulombScat(R[tid], P, s, p, enableRutherfordScattering);
data[idx].Pincol = P; data[idx].Pincol = P;
} else { } else {
@ -258,7 +261,8 @@ __global__ void kernelCollimatorPhysics(T *data, double *par, curandState *state
} }
__global__ void kernelCollimatorPhysics2(CUDA_PART2_SMALL data, double *par, __global__ void kernelCollimatorPhysics2(CUDA_PART2_SMALL data, double *par,
curandState *state, int numparticles) curandState *state, int numparticles,
bool enableRutherfordScattering)
{ {
//get global id and thread id //get global id and thread id
@ -296,7 +300,7 @@ __global__ void kernelCollimatorPhysics2(CUDA_PART2_SMALL data, double *par,
P.x = P.x * ptot / sq; P.x = P.x * ptot / sq;
P.y = P.y * ptot / sq; P.y = P.y * ptot / sq;
P.z = P.z * ptot / sq; P.z = P.z * ptot / sq;
coulombScat(R[tid], P, s, p); coulombScat(R[tid], P, s, p, enableRutherfordScattering);
data.Pincol[idx] = P; data.Pincol[idx] = P;
} else { } else {
@ -663,7 +667,8 @@ struct less_then
} }
}; };
int CudaCollimatorPhysics::CollimatorPhysics(void *mem_ptr, void *par_ptr, int numparticles) int CudaCollimatorPhysics::CollimatorPhysics(void *mem_ptr, void *par_ptr, int numparticles,
bool enableRutherfordScattering)
{ {
int threads = BLOCK_SIZE; int threads = BLOCK_SIZE;
@ -676,7 +681,8 @@ int CudaCollimatorPhysics::CollimatorPhysics(void *mem_ptr, void *par_ptr, int n
kernelCollimatorPhysics<<<blocks, threads, smem_size>>>((CUDA_PART_SMALL*)mem_ptr, kernelCollimatorPhysics<<<blocks, threads, smem_size>>>((CUDA_PART_SMALL*)mem_ptr,
(double*)par_ptr, (double*)par_ptr,
m_base->cuda_getCurandStates(), m_base->cuda_getCurandStates(),
numparticles); numparticles,
enableRutherfordScattering);
cudaError_t err = cudaGetLastError(); cudaError_t err = cudaGetLastError();
if (err != cudaSuccess) if (err != cudaSuccess)

View File

@ -110,7 +110,7 @@ public:
* *
*/ */
int CollimatorPhysics(void *mem_ptr, void *par_ptr, int CollimatorPhysics(void *mem_ptr, void *par_ptr,
int numpartices); int numpartices, bool enableRutherforScattering = true);
int CollimatorPhysicsSoA(void *label_ptr, void *localID_ptr, int CollimatorPhysicsSoA(void *label_ptr, void *localID_ptr,
void *rx_ptr, void *ry_ptr, void *rz_ptr, void *rx_ptr, void *ry_ptr, void *rz_ptr,

View File

@ -209,18 +209,20 @@ int DKSOPAL::callMultiplyComplexFields(void *mem_ptr1, void *mem_ptr2, int size,
int DKSOPAL::callCollimatorPhysics(void *mem_ptr, void *par_ptr, int DKSOPAL::callCollimatorPhysics(void *mem_ptr, void *par_ptr,
int numparticles, int numparams, int numparticles, int numparams,
int &numaddback, int &numdead) int &numaddback, int &numdead,
bool enableRutherforScattering)
{ {
return dkscol->CollimatorPhysics(mem_ptr, par_ptr, numparticles); return dkscol->CollimatorPhysics(mem_ptr, par_ptr, numparticles, enableRutherforScattering);
} }
int DKSOPAL::callCollimatorPhysics2(void *mem_ptr, void *par_ptr, int numparticles) int DKSOPAL::callCollimatorPhysics2(void *mem_ptr, void *par_ptr, int numparticles,
bool enableRutherforScattering)
{ {
return dkscol->CollimatorPhysics(mem_ptr, par_ptr, numparticles); return dkscol->CollimatorPhysics(mem_ptr, par_ptr, numparticles, enableRutherforScattering);
} }

View File

@ -159,14 +159,16 @@ public:
*/ */
int callCollimatorPhysics(void *mem_ptr, void *par_ptr, int callCollimatorPhysics(void *mem_ptr, void *par_ptr,
int numparticles, int numparams, int numparticles, int numparams,
int &numaddback, int &numdead); int &numaddback, int &numdead,
bool enableRutherfordScattering = true);
/** /**
* Monte carlo code for the degrader from OPAL classic/5.0/src/Solvers/CollimatorPhysics.cpp on device. * Monte carlo code for the degrader from OPAL classic/5.0/src/Solvers/CollimatorPhysics.cpp on device.
* For specifics check OPAL docs and CudaCollimatorPhysics class documentation. * For specifics check OPAL docs and CudaCollimatorPhysics class documentation.
* TODO: opencl and mic implementations. * TODO: opencl and mic implementations.
*/ */
int callCollimatorPhysics2(void *mem_ptr, void *par_ptr, int numparticles); int callCollimatorPhysics2(void *mem_ptr, void *par_ptr, int numparticles,
bool enableRutherfordScattering = true);
/** /**
* Monte carlo code for the degrader from OPAL classic/5.0/src/Solvers/CollimatorPhysics.cpp on device. * Monte carlo code for the degrader from OPAL classic/5.0/src/Solvers/CollimatorPhysics.cpp on device.

View File

@ -368,7 +368,9 @@ void energyLoss(double &Eng, double &dEdx, double *par, double *randv, int ri) {
} }
int MICCollimatorPhysics::CollimatorPhysics(void *mem_ptr, void *par_ptr, int numparticles) { int MICCollimatorPhysics::CollimatorPhysics(void *mem_ptr, void *par_ptr, int numparticles,
bool enableRutherforScattering)
{
//cast device memory pointers to appropriate types //cast device memory pointers to appropriate types
MIC_PART_SMALL *data = (MIC_PART_SMALL*) mem_ptr; MIC_PART_SMALL *data = (MIC_PART_SMALL*) mem_ptr;

View File

@ -40,7 +40,8 @@ public:
~MICCollimatorPhysics() { }; ~MICCollimatorPhysics() { };
int CollimatorPhysics(void *mem_ptr, void *par_ptr, int numparticles); int CollimatorPhysics(void *mem_ptr, void *par_ptr, int numparticles,
bool enableRutherforScattering = true);
int CollimatorPhysicsSoA(void *label_ptr, void *localID_ptr, int CollimatorPhysicsSoA(void *label_ptr, void *localID_ptr,
void *rx_ptr, void *ry_ptr, void *rz_ptr, void *rx_ptr, void *ry_ptr, void *rz_ptr,

View File

@ -34,7 +34,7 @@ TODO:
2. boost.compute sort for user defined structure crashes 2. boost.compute sort for user defined structure crashes
*/ */
int OpenCLCollimatorPhysics::CollimatorPhysics(void *mem_ptr, void *par_ptr, int OpenCLCollimatorPhysics::CollimatorPhysics(void *mem_ptr, void *par_ptr,
int numparticles) int numparticles, bool enableRutherforScattering)
{ {
/* /*
//set number of total threads, and number threads per block //set number of total threads, and number threads per block

View File

@ -52,7 +52,8 @@ public:
} }
/* execute degrader code on device */ /* execute degrader code on device */
int CollimatorPhysics(void *mem_ptr, void *par_ptr, int numparticles); int CollimatorPhysics(void *mem_ptr, void *par_ptr, int numparticles,
bool enableRutherforScattering = true);
int CollimatorPhysicsSoA(void *label_ptr, void *localID_ptr, int CollimatorPhysicsSoA(void *label_ptr, void *localID_ptr,
void *rx_ptr, void *ry_ptr, void *rz_ptr, void *rx_ptr, void *ry_ptr, void *rz_ptr,