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 gaussian broadening to SLIT source #214

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions src/mcx_core.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,29 @@ __device__ inline int launchnewphoton(MCXpos* p, MCXdir* v, Stokes* s, MCXtime*
rotatevector(v, 1.f, 0.f, sphi, cphi);
}

if (MCX_SRC_SLIT && (launchsrc->param2.x > 0.f || launchsrc->param2.y > 0.f)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first condition should be gcfg->srctype == MCX_SRC_SLIT. I will post my fix, just leave here for a note.

float sphi, cphi;
r = TWO_PI * rand_uniform01(t);
sincosf(r, &sphi, &cphi);
r = sqrtf(2.f * rand_next_scatlen(t));
// gaussian broadening factor in direction perpendicular to both slit and v directions
float gauss_perp = launchsrc->param2.x * r * cphi;
// gaussian broadening factor in direction of slit
float gauss_parallel = launchsrc->param2.y * r * sphi;
float parallel_norm = rnorm3df(launchsrc->param1.x, launchsrc->param1.y, launchsrc->param1.z);
float3 perp = float3(launchsrc->param1.y * v->z - launchsrc->param1.z * v->y,
launchsrc->param1.z * v->x - launchsrc->param1.x * v->z,
launchsrc->param1.x * v->y - launchsrc->param1.y * v->x);
float perp_norm = rnorm3df(perp.x, perp.y, perp.z);
v->x += gauss_perp * perp.x * perp_norm + gauss_parallel * launchsrc->param1.x * parallel_norm;
v->y += gauss_perp * perp.y * perp_norm + gauss_parallel * launchsrc->param1.y * parallel_norm;
v->z += gauss_perp * perp.z * perp_norm + gauss_parallel * launchsrc->param1.z * parallel_norm;
r = rnorm3df(v->x, v->y, v->z);
v->x *= r;
v->y *= r;
v->z *= r;
}

*rv = float3(rv->x + (launchsrc->param1.x) * 0.5f,
rv->y + (launchsrc->param1.y) * 0.5f,
rv->z + (launchsrc->param1.z) * 0.5f);
Expand Down
Loading