Skip to content

Commit ac76ff7

Browse files
committed
fix cyclic bc, add mcxlab demo
1 parent 228e0b5 commit ac76ff7

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
% MCXLAB - Monte Carlo eXtreme for MATLAB/Octave by Qianqina Fang
3+
%
4+
% In this example, we show how to simulate an infinite slab using cyclic
5+
% boundary condition
6+
%
7+
% This file is part of Monte Carlo eXtreme (MCX) URL:http://mcx.space
8+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9+
10+
clear cfg;
11+
cfg.nphoton=1e8;
12+
cfg.issrcfrom0=1;
13+
cfg.vol=uint8(ones(60,60,20));
14+
cfg.srcdir=[0 0 1];
15+
cfg.gpuid=1;
16+
cfg.autopilot=1;
17+
cfg.prop=[0 0 1 1;0.005 1 0.8 1.37];
18+
cfg.tstart=0;
19+
cfg.seed=99999;
20+
21+
% a uniform planar source outside the volume
22+
cfg.srctype='planar';
23+
cfg.srcpos=[0 0 0];
24+
cfg.srcparam1=[60 0 0 0];
25+
cfg.srcparam2=[0 60 0 0];
26+
cfg.tend=5e-9;
27+
cfg.tstep=5e-9;
28+
cfg.bc='ccrccr';
29+
flux=mcxlab(cfg);
30+
31+
fcw=flux.data*cfg.tstep;
32+
imagesc(log10(abs(squeeze(fcw(:,30,:)))))
33+
axis equal; colorbar
34+
title('a uniform planar source incident along an infinite slab');

src/mcx_core.cu

+11-9
Original file line numberDiff line numberDiff line change
@@ -1280,15 +1280,17 @@ kernel void mcx_main_loop(uint media[],OutputType field[],float genergy[],uint n
12801280
/** launch new photon when exceed time window or moving from non-zero voxel to zero voxel without reflection */
12811281
if((mediaid==0 && (((isdet & 0xF)==0 && (!gcfg->doreflect || (gcfg->doreflect && n1==gproperty[0].w))) || (isdet==bcAbsorb || isdet==bcCylic) )) || f.t>gcfg->twin1){
12821282
if(isdet==bcCylic){
1283-
if(flipdir==0) p.x=mcx_nextafterf(roundf(p.x+((idx1d==OUTSIDE_VOLUME_MIN) ? gcfg->maxidx.x: -gcfg->maxidx.x)),(v.x > 0.f)-(v.x < 0.f));
1284-
if(flipdir==1) p.y=mcx_nextafterf(roundf(p.y+((idx1d==OUTSIDE_VOLUME_MIN) ? gcfg->maxidx.y: -gcfg->maxidx.y)),(v.y > 0.f)-(v.y < 0.f));
1285-
if(flipdir==2) p.z=mcx_nextafterf(roundf(p.z+((idx1d==OUTSIDE_VOLUME_MIN) ? gcfg->maxidx.z: -gcfg->maxidx.z)),(v.z > 0.f)-(v.z < 0.f));
1286-
idx1d=(int(floorf(p.z))*gcfg->dimlen.y+int(floorf(p.y))*gcfg->dimlen.x+int(floorf(p.x)));
1287-
mediaid=media[idx1d];
1288-
isdet=mediaid & DET_MASK; /** upper 16bit is the mask of the covered detector */
1289-
mediaid &= MED_MASK; /** lower 16bit is the medium index */
1290-
GPUDEBUG(("Cylic boundary condition, moving photon in dir %d at %d flag, new pos=[%f %f %f]\n",flipdir,isdet,p.x,p.y,p.z));
1291-
continue;
1283+
if(flipdir==0) p.x=mcx_nextafterf(roundf(p.x+((idx1d==OUTSIDE_VOLUME_MIN) ? gcfg->maxidx.x: -gcfg->maxidx.x)),(v.x > 0.f)-(v.x < 0.f));
1284+
if(flipdir==1) p.y=mcx_nextafterf(roundf(p.y+((idx1d==OUTSIDE_VOLUME_MIN) ? gcfg->maxidx.y: -gcfg->maxidx.y)),(v.y > 0.f)-(v.y < 0.f));
1285+
if(flipdir==2) p.z=mcx_nextafterf(roundf(p.z+((idx1d==OUTSIDE_VOLUME_MIN) ? gcfg->maxidx.z: -gcfg->maxidx.z)),(v.z > 0.f)-(v.z < 0.f));
1286+
if(!(p.x<0.f||p.y<0.f||p.z<0.f||p.x>=gcfg->maxidx.x||p.y>=gcfg->maxidx.y||p.z>=gcfg->maxidx.z)){
1287+
idx1d=(int(floorf(p.z))*gcfg->dimlen.y+int(floorf(p.y))*gcfg->dimlen.x+int(floorf(p.x)));
1288+
mediaid=media[idx1d];
1289+
isdet=mediaid & DET_MASK; /** upper 16bit is the mask of the covered detector */
1290+
mediaid &= MED_MASK; /** lower 16bit is the medium index */
1291+
GPUDEBUG(("Cylic boundary condition, moving photon in dir %d at %d flag, new pos=[%f %f %f]\n",flipdir,isdet,p.x,p.y,p.z));
1292+
continue;
1293+
}
12921294
}
12931295
GPUDEBUG(("direct relaunch at idx=[%d] mediaid=[%d], ref=[%d] bcflag=%d timegate=%d\n",idx1d,mediaid,gcfg->doreflect,isdet,f.t>gcfg->twin1));
12941296
if(launchnewphoton<mcxsource>(&p,&v,&f,&rv,&prop,&idx1d,field,&mediaid,&w0,(mediaidold & DET_MASK),ppath,

0 commit comments

Comments
 (0)