Skip to content

Commit

Permalink
[feat] simulate multiple sources, close #163
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Dec 31, 2023
1 parent 59f18a7 commit 7e1aec0
Show file tree
Hide file tree
Showing 23 changed files with 860 additions and 132 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Major updates are marked with a "*"

== MCX v2023.11 (Interstellar Ion - 2.2), FangQ <q.fang (a) neu.edu> ==
== MCX v2024.1 (Interstellar Ion - 2.2), FangQ <q.fang (a) neu.edu> ==

2023-11-07 [a710ab3] allow converting integer cfg.vol to json
2023-10-31 [d6c64e4] [test] fix rng test after make double
Expand Down
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=============================================================
Monte Carlo eXtreme (MCX) Suite
version 2023.11
version 2024.1
=============================================================

Copyright (c) 2009-2023 Qianqian Fang <q.fang at neu.edu>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Monte Carlo eXtreme (MCX) - CUDA Edition

- Author: Qianqian Fang (q.fang at neu.edu)
- License: GNU General Public License version 3 (GPLv3)
- Version: 2.2.pre (v2023.11, Interstellar Ion)
- Version: 2.2.pre (v2024.1, Interstellar Ion)
- Website: <http://mcx.space>

![Mex and Binaries](https://github.com/fangq/mcx/actions/workflows/build_all.yml/badge.svg)\
Expand Down
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

*Author: Qianqian Fang <q.fang at neu.edu>
*License: GNU General Public License version 3 (GPLv3)
*Version: 2.2.pre (v2023.11, Interstellar Ion)
*Version: 2.2.pre (v2024.1, Interstellar Ion)
*Website: http://mcx.space

---------------------------------------------------------------------
Expand Down
84 changes: 84 additions & 0 deletions example/multisrc/multisrc.json
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]}}
]
}
1 change: 1 addition & 0 deletions example/multisrc/run_multisrc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
..\..\bin\mcx.exe -f multisrc.json -D P %*
2 changes: 2 additions & 0 deletions example/multisrc/run_multisrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
../../bin/mcx -f multisrc.json -D P $@
2 changes: 1 addition & 1 deletion mcxlab/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Major updates are marked with a "*"

== MCX v2023.11 (Interstellar Ion - 2.2), FangQ <q.fang (a) neu.edu> ==
== MCX v2024.1 (Interstellar Ion - 2.2), FangQ <q.fang (a) neu.edu> ==

2023-11-07 [a710ab3] allow converting integer cfg.vol to json
2023-10-31 [d6c64e4] [test] fix rng test after make double
Expand Down
2 changes: 1 addition & 1 deletion mcxlab/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Author: Qianqian Fang <q.fang at neu.edu>
License: GNU General Public License version 3 (GPLv3)
Version: this package is part of Monte Carlo eXtreme (MCX) v2023.11
Version: this package is part of Monte Carlo eXtreme (MCX) v2024.1

<toc>

Expand Down
82 changes: 82 additions & 0 deletions mcxlab/examples/demo_multsrc.m
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));
5 changes: 5 additions & 0 deletions mcxlab/mcxlab.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
% of the srcdir direction; if the focal length is -inf, the launch
% angle will be computed based on the Lambertian (cosine) distribution.
%
% Starting v2024, cfg.{srcpos,srcdir,srcparam1,srcparam2} accept multiple sources,
% with each source corresponding to a single row of the array. For all 4 components,
% srcpos/srcdir support 3 or 4 columns, and srcparam1/srcparam2 support 4 columns.
% If any of the 4 compnents present, they should have matching row number.
%
%== MC simulation settings ==
% cfg.seed: seed for the random number generator (integer) [0]
% if set to a uint8 array, the binary data in each column is used
Expand Down
2 changes: 1 addition & 1 deletion mcxstudio/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Author: Qianqian Fang <q.fang at neu.edu>
License: GNU General Public License version 3 (GPLv3)
Version: 1.2.pre (v2023.11)
Version: 1.2.pre (v2024.1)
Website: http://mcx.space

---------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pmcx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- Copyright: (C) Matin Raayai Ardakani (2022-2023) <raayaiardakani.m at northeastern.edu>, Qianqian Fang (2019-2023) <q.fang at neu.edu>, Fan-Yu Yen (2023) <yen.f at northeastern.edu>
- License: GNU Public License V3 or later
- Version: 0.2.8
- Version: 0.2.9
- URL: https://pypi.org/project/pmcx/
- Github: https://github.com/fangq/mcx

Expand Down
2 changes: 1 addition & 1 deletion pmcx/pmcx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# from .files import loadmc2, loadmch, load, save
from .bench import bench

__version__ = "0.2.8"
__version__ = "0.2.9"

__all__ = (
"gpuinfo",
Expand Down
2 changes: 1 addition & 1 deletion pmcx/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def build_extension(self, ext):
setup(
name="pmcx",
packages=["pmcx"],
version="0.2.8",
version="0.2.9",
requires=["numpy"],
license="GPLv3+",
author="Matin Raayai Ardakani, Qianqian Fang, Fan-Yu Yen",
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ NVCCOMP=$(OMP)
CUDA_STATIC=--cudart static -Xcompiler "-static-libgcc -static-libstdc++"

CFLAGS+=-std=c99
CPPFLAGS+=-g -Wall #-DNO_LZMA # -DUSE_OS_TIMER
CPPFLAGS+=-g -Wall -pedantic #-DNO_LZMA # -DUSE_OS_TIMER

OBJSUFFIX=.o
EXESUFFIX=
Expand Down
2 changes: 1 addition & 1 deletion src/mcx_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifndef _MCEXTREME_CONSTANT_H
#define _MCEXTREME_CONSTANT_H

#define MCX_VERSION "v2023.11"
#define MCX_VERSION "v2024.1"
#define MCX_VERSION_MAJOR 2
#define MCX_VERSION_MINOR 2

Expand Down
Loading

0 comments on commit 7e1aec0

Please sign in to comment.