Fresnel's law at media boundaries with mismatched refractive indices

73 views
Skip to first unread message

Yu Shimojo

unread,
Feb 19, 2025, 4:19:31 AM2/19/25
to mcx-users
Dear Dr. Fang,

I'm Yu. Thank you very much for your great work on MCX.
I am a mcx user and I would like to calculate fluence distributions in the skin by considering light reflection and transmission at boundaries with mismatched refractive indices, as shown in this paper (https://doi.org/10.1117/1.JBO.25.2.025001), because the skin has curved and oblique structures such as blood vessels.
I'd appreciate it if you could tell me whether the mcx considers the Fresnel's law at media boundaries with mismatched refractive indices, and if so, how to set this option in the execution.

Thank you very much for your time.
Best regards,
Yu

下条裕

unread,
Feb 19, 2025, 10:05:06 AM2/19/25
to mcx-users
Hello Dr. Fang,

I'm Yu. Thank you very much for your great work on MCX.
I am a mcx user and I would like to calculate fluence distributions in the skin by considering light reflection and transmission at boundaries with mismatched refractive indices, as shown in this paper (https://doi.org/10.1117/1.JBO.25.2.025001), because the skin has curved and oblique structures such as blood vessels.
I would appreciate it if you could tell me whether the mcx considers the Fresnel's law at media boundaries with mismatched refractive indices, and if so, how to set this option in the execution.

Qianqian Fang

unread,
Feb 19, 2025, 10:38:42 AM2/19/25
to mcx-...@googlegroups.com, Yu Shimojo

hi Yu,

mcx uses Fresnel's law to handle n-mismatched boundaries by default, you do not need to set anything in order to use it. you can, however, set cfg.isreflect=0 to disable it when needed.

for the paper you referred to, please check out our SVMC paper addressing the same issue

https://www.osapublishing.org/boe/abstract.cfm?uri=boe-11-11-6262

the paper you linked only has the ability to reduce errors due to reflections at voxelated boundaries (in our paper, we called it Type-II error), but can not mitigate the "partial volume" effect at internal boundaries (we called it Type-I error). see the Introduction section of our SVMC paper

you can find all benchmarks (B1, B2, B3) in our SVMC paper in this folder

https://github.com/fangq/mcx/tree/v2025/mcxlab/examples

Qianqian


On 2/19/25 04:19, Yu Shimojo wrote:

You don't often get email from shimoshi...@gmail.com. Learn why this is important

--
You received this message because you are subscribed to the Google Groups "mcx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mcx-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mcx-users/b9460243-8d8b-4bb5-bedd-76d82afdab0cn%40googlegroups.com.

Yu Shimojo

unread,
Feb 20, 2025, 7:35:57 AM2/20/25
to mcx-users
Hello Dr. Fang,

Thank you very much for your quick response!
I tried the benchmarks in your SVMC paper and confirmed that they worked.
To understand the SVMC more, I set a simple condition that a light beam incident to a boundary between water and glass media (figure1).
I confirmed that it worked when I set a pencil beam for source type (figures 2,3,4) but it showed an error for a disk beam, as shown below.
(I want to use a disk bema for my study.)

MCXLAB ERROR -74 in unit mcx_core.cu:3488: misaligned address
Error from thread (0): misaligned address
C++ Error: MCXLAB Terminated due to an exception!

Could you please tell me what caused this problem?
Here is a shared link for the figures1-4 and my source code.

Thank you for your time.
Best regards,
Yu

Qianqian Fang

unread,
Feb 20, 2025, 10:59:06 PM2/20/25
to mcx-...@googlegroups.com, Yu Shimojo

hi Yu,

I was able to run your test script (after uncomment your Nx/Ny/Nz), the disk source runs fine, and produced expected results on my machine. see my screenshot

I am also attaching the printed logs. 

can you try other demo scripts in mcxlab and do you see this error?

Qianqian


SVMC preprocessing complete, Elapsed time is 0.278214 seconds.
Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
mcx.nphoton=1e+08;
mcx.seed=1961459715;
mcx.srctype='disk';
mcx.srcpos=[50 50 0 1];
mcx.srcparam1=[20 0 0 0];
mcx.srcdir=[0 0 1 0];
mcx.issrcfrom0=1;
mcx.medianum=3;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-10;
mcx.isreflect=1;
mcx.unitinmm=0.1;
mcx.outputtype='fluence';
mcx.gpuid=1;
mcx.autopilot=1;
mcx.dim=[100 100 100];
mcx.mediabyte=4;
###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#          Copyright (c) 2009-2025 Qianqian Fang <q.fang at neu.edu>          #
#                https://mcx.space/  &  https://neurojson.io                  #
#                                                                             #
# Computational Optics & Translational Imaging (COTI) Lab- http://fanglab.org #
#   Department of Bioengineering, Northeastern University, Boston, MA, USA    #
###############################################################################
#    The MCX Project is funded by the NIH/NIGMS under grant R01-GM114365      #
###############################################################################
#  Open-source codes and reusable scientific data are essential for research, #
# MCX proudly developed human-readable JSON-based data formats for easy reuse.#
#                                                                             #
#Please visit our free scientific data sharing portal at https://neurojson.io #
# and consider sharing your public datasets in standardized JSON/JData format #
###############################################################################
$Rev::d98d88 $ v2025 $Date::2025-01-26 13:14:33 -05$ by $Author::Qianqian Fang$
###############################################################################
- code name: [Jumbo Jolt] compiled by nvcc [11.5] for CUDA-arch [350] on [Feb 20 2025]
- compiled with: RNG [xorshift128+] with Seed Length [4]

GPU=1 (NVIDIA GeForce RTX 4070 Laptop GPU) threadph=678 extra=24832 np=100000000 nthread=147456 maxgate=10 repetition=1
initializing streams ...    init complete : 1 ms
requesting 1280 bytes of shared memory
launching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ...
kernel complete:      929 ms
retrieving fields ...     transfer complete:    956 ms
normalizing raw data ...    source 1, normalization factor alpha=0.000001
data normalization complete : 1060 ms
simulated 100000000 photons (100000000) with 147456 threads (repeat x1)
MCX simulation speed: 110375.28 photon/ms
total simulated energy: 100000000.00    absorbed: 0.00000%
(loss due to initial specular reflection is excluded in the total)
Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
mcx.nphoton=1e+08;
mcx.seed=1961459715;
mcx.srctype='disk';
mcx.srcpos=[50 50 0 1];
mcx.srcparam1=[20 0 0 0];
mcx.srcdir=[0 0 1 0];
mcx.issrcfrom0=1;
mcx.medianum=3;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-10;
mcx.isreflect=1;
mcx.unitinmm=0.1;
mcx.outputtype='fluence';
mcx.gpuid=1;
mcx.autopilot=1;
mcx.dim=[100 100 100];
mcx.mediabyte=97;
###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#          Copyright (c) 2009-2025 Qianqian Fang <q.fang at neu.edu>          #
#                https://mcx.space/  &  https://neurojson.io                  #
#                                                                             #
# Computational Optics & Translational Imaging (COTI) Lab- http://fanglab.org #
#   Department of Bioengineering, Northeastern University, Boston, MA, USA    #
###############################################################################
#    The MCX Project is funded by the NIH/NIGMS under grant R01-GM114365      #
###############################################################################
#  Open-source codes and reusable scientific data are essential for research, #
# MCX proudly developed human-readable JSON-based data formats for easy reuse.#
#                                                                             #
#Please visit our free scientific data sharing portal at https://neurojson.io #
# and consider sharing your public datasets in standardized JSON/JData format #
###############################################################################
$Rev::d98d88 $ v2025 $Date::2025-01-26 13:14:33 -05$ by $Author::Qianqian Fang$
###############################################################################
- code name: [Jumbo Jolt] compiled by nvcc [11.5] for CUDA-arch [350] on [Feb 20 2025]
- compiled with: RNG [xorshift128+] with Seed Length [4]

GPU=1 (NVIDIA GeForce RTX 4070 Laptop GPU) threadph=678 extra=24832 np=100000000 nthread=147456 maxgate=10 repetition=1
initializing streams ...    init complete : 2 ms
requesting 1280 bytes of shared memory
launching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ...
kernel complete:      2201 ms
retrieving fields ...     transfer complete:    2230 ms
normalizing raw data ...    source 1, normalization factor alpha=0.000001
data normalization complete : 2329 ms
simulated 100000000 photons (100000000) with 147456 threads (repeat x1)
MCX simulation speed: 45934.77 photon/ms
total simulated energy: 100000000.00    absorbed: 0.00000%
(loss due to initial specular reflection is excluded in the total)

disk_test.png

Yu Shimojo

unread,
Feb 21, 2025, 2:49:33 AM2/21/25
to mcx-users
Hello Dr. Fang,

Thank you for your response.
I tried the benchmarks in your SVMC paper with a disk source but all showed an error during running the svmc part, as shown in the previous mail.
I am attaching the one of the printed logs and a script (demo_svmc_cubesph.m). 
But I was able to run other demo scripts with a disk source such as demo_mcxyz_skinvessel.m.
I would appreciate it if you could tell me the cause of this error.

Thank you for your help.
Best regards,
Yu

>> demo_svmc_cubesph
SVMC preprocessing complete, 経過時間は 0.455159 秒です。

Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
mcx.nphoton=1e+08;
mcx.seed=1749605794;
mcx.issrcfrom0=1;
mcx.srctype='disk';
mcx.srcpos=[61 61 0 1];

mcx.srcdir=[0 0 1 0];
mcx.srcparam1=[10 0 0 0];
mcx.medianum=2;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-10;
mcx.isreflect=1;
mcx.unitinmm=0.5;
mcx.outputtype='fluence';
mcx.gpuid=1;
mcx.autopilot=1;
mcx.dim=[120 120 120];
mcx.mediabyte=1;

###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#          Copyright (c) 2009-2025 Qianqian Fang <q.fang at neu.edu>          #
#                https://mcx.space/  &  https://neurojson.io                  #
#                                                                             #
# Computational Optics & Translational Imaging (COTI) Lab- http://fanglab.org #
#   Department of Bioengineering, Northeastern University, Boston, MA, USA    #
###############################################################################
#    The MCX Project is funded by the NIH/NIGMS under grant R01-GM114365      #
###############################################################################
#  Open-source codes and reusable scientific data are essential for research, #
# MCX proudly developed human-readable JSON-based data formats for easy reuse.#
#                                                                             #
#Please visit our free scientific data sharing portal at https://neurojson.io #
# and consider sharing your public datasets in standardized JSON/JData format #
###############################################################################
$Rev::0fa060 $ v2025 $Date::2025-02-13 17:38:58 -05$ by $Author::Qianqian Fang$
###############################################################################
- code name: [Jumbo Jolt] compiled by nvcc [7.5] for CUDA-arch [350] on [Feb 13 2025]

- compiled with: RNG [xorshift128+] with Seed Length [4]

GPU=1 (NVIDIA GeForce RTX 4090 Laptop GPU) threadph=321 extra=73984 np=100000000 nthread=311296 maxgate=10 repetition=1

initializing streams ... init complete : 2 ms
requesting 1280 bytes of shared memory
launching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ...
kernel complete:   1251 ms
retrieving fields ... transfer complete: 1272 ms
normalizing raw data ... source 1, normalization factor alpha=0.000000
data normalization complete : 1429 ms
simulated 100000000 photons (100000000) with 311296 threads (repeat x1)
MCX simulation speed: 82169.27 photon/ms
total simulated energy: 100000000.00 absorbed: 21.62711%

(loss due to initial specular reflection is excluded in the total)
Launching MCXLAB - Monte Carlo eXtreme for MATLAB & GNU Octave ...
Running simulations for configuration #1 ...
mcx.nphoton=1e+08;
mcx.seed=1749605794;
mcx.issrcfrom0=1;
mcx.srctype='disk';
mcx.srcpos=[30.5 30.5 0 1];

mcx.srcdir=[0 0 1 0];
mcx.srcparam1=[10 0 0 0];
mcx.medianum=2;
mcx.tstart=0;
mcx.tend=5e-09;
mcx.tstep=5e-10;
mcx.isreflect=1;
mcx.unitinmm=1;
mcx.outputtype='fluence';
mcx.gpuid=1;
mcx.autopilot=1;
mcx.dim=[60 60 60];

mcx.mediabyte=97;
###############################################################################
#                      Monte Carlo eXtreme (MCX) -- CUDA                      #
#          Copyright (c) 2009-2025 Qianqian Fang <q.fang at neu.edu>          #
#                https://mcx.space/  &  https://neurojson.io                  #
#                                                                             #
# Computational Optics & Translational Imaging (COTI) Lab- http://fanglab.org #
#   Department of Bioengineering, Northeastern University, Boston, MA, USA    #
###############################################################################
#    The MCX Project is funded by the NIH/NIGMS under grant R01-GM114365      #
###############################################################################
#  Open-source codes and reusable scientific data are essential for research, #
# MCX proudly developed human-readable JSON-based data formats for easy reuse.#
#                                                                             #
#Please visit our free scientific data sharing portal at https://neurojson.io #
# and consider sharing your public datasets in standardized JSON/JData format #
###############################################################################
$Rev::0fa060 $ v2025 $Date::2025-02-13 17:38:58 -05$ by $Author::Qianqian Fang$
###############################################################################
- code name: [Jumbo Jolt] compiled by nvcc [7.5] for CUDA-arch [350] on [Feb 13 2025]

- compiled with: RNG [xorshift128+] with Seed Length [4]

GPU=1 (NVIDIA GeForce RTX 4090 Laptop GPU) threadph=321 extra=73984 np=100000000 nthread=311296 maxgate=10 repetition=1

initializing streams ... init complete : 1 ms
requesting 1280 bytes of shared memory
launching MCX simulation for time window [0.00e+00ns 5.00e+00ns] ...
simulation run# 1 ...
MCXLAB ERROR -74 in unit mcx_core.cu:3488: misaligned address
Error from thread (0): misaligned address
C++ Error: MCXLAB Terminated due to an exception!

yu shimojo

unread,
Feb 21, 2025, 2:59:08 PM2/21/25
to mcx-...@googlegroups.com
Hello Dr. Fang,

I was able to solve the problem by compiling the mcxlab on my machine. 
I had used a downloaded execution file to run mcx, which may have caused the problem. 
Thank you again for your time.
Best regards,

Yu

2025年2月21日(金) 16:49 Yu Shimojo <shimoshi...@gmail.com>:
You received this message because you are subscribed to a topic in the Google Groups "mcx-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mcx-users/KdRah18Iznw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mcx-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mcx-users/fd388247-abba-46b3-8e00-9aff0ca2c117n%40googlegroups.com.

Fang, Qianqian

unread,
Feb 23, 2025, 10:59:10 AM2/23/25
to mcx-...@googlegroups.com
Hi Yu, I was able to reproduce the misaligned memory error on my 4090 as well.

It appears that the issue was caused by using an older version of CUDA, 7.5, for compiling the Linux mcx and mcxlab binaries. In the past, we found that CUDA 7.5, despite being old, produces slightly faster simulations without any noticeable side effects. Now, it appears that this may not be true for newer GPUs.

I just recompiled all Linux binaries using CUDA 9 and updated the released packages. The memory misalignment error disappeared with CUDA 9 generated binaries.

Windows/Mac were not affected by this as they were using CUDA 9/10 already. Also, the Github CI builds at https://mcx.space/nightly/github/ were also built with CUDA 9 by default.

Let me know if you see any other issues.

Qianqian


From: mcx-...@googlegroups.com <mcx-...@googlegroups.com> on behalf of yu shimojo <shimoshi...@gmail.com>
Sent: Friday, February 21, 2025 2:58 PM
To: mcx-...@googlegroups.com <mcx-...@googlegroups.com>
Subject: Re: [mcx-users] Re: Fresnel's law at media boundaries with mismatched refractive indices
 
Reply all
Reply to author
Forward
0 new messages