-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] simulate multiple sources, close #163
- Loading branch information
Showing
23 changed files
with
860 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"Session":{ | ||
"ID":"multisrc", | ||
"DoAutoThread":1, | ||
"Photons":10000000 | ||
}, | ||
"Forward":{ | ||
"T0":0, | ||
"T1":5e-09, | ||
"Dt":5e-09 | ||
}, | ||
"Optode":{ | ||
"Source":{ | ||
"Pos":[ | ||
[50,30,0,1], | ||
[44.14213562373095,44.14213562373095,0,1], | ||
[30,50,0,1], | ||
[15.85786437626905,44.14213562373095,0,1], | ||
[10,30.00000000000001,0,1], | ||
[15.85786437626905,15.85786437626905,0,1], | ||
[29.99999999999999,10,0,1], | ||
[44.14213562373094,15.85786437626904,0,1], | ||
[25,25,0,4] | ||
], | ||
"Dir":[ | ||
[-0.5,0,0.8660254037844386,20], | ||
[-0.3535533905932738,-0.3535533905932737,0.8660254037844386,20], | ||
[-1.110223024625157e-16,-0.5,0.8660254037844386,20], | ||
[0.3535533905932737,-0.3535533905932738,0.8660254037844386,20], | ||
[0.5,-1.387778780781446e-16,0.8660254037844386,20], | ||
[0.3535533905932739,0.3535533905932736,0.8660254037844386,20], | ||
[2.220446049250313e-16,0.5,0.8660254037844386,20], | ||
[-0.3535533905932736,0.353553390593274,0.8660254037844386,20], | ||
[0,0,1,0] | ||
], | ||
"Param1":[ | ||
[-8,3,0,0], | ||
[-7.778174593052023,-3.535533905932737,0,0], | ||
[-3.000000000000002,-8,0,0], | ||
[3.535533905932736,-7.778174593052024,0,0], | ||
[8,-3.000000000000004,0,0], | ||
[7.778174593052025,3.535533905932735,0,0], | ||
[3.000000000000004,7.999999999999999,0,0], | ||
[-3.535533905932733,7.778174593052025,0,0], | ||
[10,0,0,0] | ||
], | ||
"Param2":[ | ||
[3,3,0,0], | ||
[4.440892098500626e-16,4.242640687119286,0,0], | ||
[-3,3.000000000000001,0,0], | ||
[-4.242640687119286,1.332267629550188e-15,0,0], | ||
[-3.000000000000001,-2.999999999999999,0,0], | ||
[-1.77635683940025e-15,-4.242640687119286,0,0], | ||
[2.999999999999999,-3.000000000000002,0,0], | ||
[4.242640687119286,-2.664535259100376e-15,0,0], | ||
[0,10,0,0] | ||
], | ||
"Type":"planar" | ||
} | ||
}, | ||
"Domain":{ | ||
"OriginType":0, | ||
"Media":[ | ||
{ | ||
"mua":0, | ||
"mus":0, | ||
"g":1, | ||
"n":1 | ||
}, | ||
{ | ||
"mua":0.005, | ||
"mus":0.2, | ||
"g":0, | ||
"n":1.37 | ||
} | ||
], | ||
"MediaFormat":"byte", | ||
"Dim":[60,60,40], | ||
"VolumeFile":"" | ||
}, | ||
"Shapes":[ | ||
{"Grid": {"Tag":1, "Size":[60,60,40]}} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
..\..\bin\mcx.exe -f multisrc.json -D P %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
../../bin/mcx -f multisrc.json -D P $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
% MCXLAB - Monte Carlo eXtreme for MATLAB/Octave by Qianqina Fang | ||
% | ||
% In this example, we show how to simultaneously simulate multiple sources | ||
% of the same type. | ||
% | ||
% Specifically, we create a complex source made of an array of 9 planar | ||
% sources - where 8 of the sources form a circular array by rotating one | ||
% of the sources around the center of the bottom-face center; the 9th | ||
% source is manually placed at the center of the array. | ||
% | ||
% One can individually control the settings for each of the sources, | ||
% including the position (srcpos), launch direction (srcdir), and | ||
% additional parameters (srcparam1/srcparam2). | ||
|
||
% By default, each source entry launches an equal fraction of photons, | ||
% determined by cfg.nphoton/size(cfg.srcpos(1,:)). However, one can set the | ||
% 4-th element of the srcpos() for each sourc to create different weights | ||
% for each source. Here, we set the central source 4x of the intensity | ||
% compared to other circular-array sources (weight of 1). This allows mcx | ||
% to allocate 4/(8+4) = 1/3 of the total photons (cfg.nphoton) to the central | ||
% source while each other source launches 1/12 of the total photon packets. | ||
% | ||
% Worth to mention that we also set the 4th element of cfg.srcdir, i.e. the | ||
% focal length, to create a convergent beam for each planar source. | ||
% | ||
% This file is part of Monte Carlo eXtreme (MCX) URL:http://mcx.sf.net | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
% only clear cfg to avoid accidentally clearing other useful data | ||
clear cfg cfgs | ||
|
||
cfg.nphoton=1e7; | ||
cfg.vol=uint8(ones(60,60,40)); | ||
cfg.srctype='planar'; | ||
|
||
Rs=20; | ||
delta=pi/4; | ||
|
||
ang=0:delta:(2*pi-delta); | ||
rotmat2d=[cos(delta), -sin(delta); sin(delta), cos(delta)]; | ||
offset2d=[30 30]; | ||
|
||
% first create an array of planar sources by rotating around origin | ||
|
||
% the 4th element of srcpos sets the initial weight | ||
cfg.srcpos=repmat([Rs, 0, 0, 1], length(ang), 1); | ||
|
||
% the 4th element of srcdir sets the focal length (positive: convergent) | ||
cfg.srcdir=repmat([-0.5, 0, sqrt(3)/2, 20], length(ang), 1); | ||
cfg.srcparam1=repmat([-8,3,0,0], length(ang), 1); | ||
cfg.srcparam2=repmat([3,3,0,0], length(ang), 1); | ||
|
||
for i=2:length(ang) | ||
cfg.srcpos(i,1:2)=(rotmat2d*cfg.srcpos(i-1,1:2)')'; | ||
cfg.srcdir(i,1:2)=(rotmat2d*cfg.srcdir(i-1,1:2)')'; | ||
cfg.srcparam1(i,1:2)=(rotmat2d*cfg.srcparam1(i-1,1:2)')'; | ||
cfg.srcparam2(i,1:2)=(rotmat2d*cfg.srcparam2(i-1,1:2)')'; | ||
end | ||
|
||
% translate the circular array to the desired offset | ||
cfg.srcpos(:,1)=cfg.srcpos(:,1)+offset2d(1); | ||
cfg.srcpos(:,2)=cfg.srcpos(:,2)+offset2d(2); | ||
|
||
% manually add the 9th source to the center | ||
|
||
cfg.srcpos(end+1, :)=[offset2d(1)-Rs/4,offset2d(2)-Rs/4,0,4]; % initial weight is 4 | ||
cfg.srcdir(end+1, :)=[0, 0 1 0]; | ||
cfg.srcparam1(end+1, :)=[Rs/2,0,0,0]; | ||
cfg.srcparam2(end+1, :)=[0,Rs/2,0,0]; | ||
|
||
cfg.gpuid=1; | ||
% cfg.gpuid='11'; % use two GPUs together | ||
cfg.autopilot=1; | ||
cfg.prop=[0 0 1 1;0.005 0.2 0 1.37]; | ||
cfg.tstart=0; | ||
cfg.tend=5e-9; | ||
cfg.tstep=5e-9; | ||
|
||
flux=mcxlab(cfg); | ||
|
||
mcxplotvol(log10(flux.data)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.