I want to use MCXLAB to simulate a 20mW uniform continuous light source illuminating a simplified biological tissue model, observing its light distribution and attenuation curve. However, when normalized, I observe that the magnitude of the output flux results is extremely large (approximately 10^8). Reviewing other posts, I see the default flux unit is 1/mm²/s. How should I modify my code to ensure the output flux corresponds to my 20mW light source and is converted to the unit mW/cm²?
Here is my code.
%% MCXLAB模型仿真
clear; clc; close all;
addpath('D:\mcxlab');
addpath('D:\mcxlab\matlab');
%% 1. 基本仿真参数
cfg.nphoton = 5e7;
cfg.tstart = 0;
cfg.tend = 5e-9;
cfg.tstep = 5e-9;
cfg.unitinmm = 0.01;
cfg.autopilot = 1;
cfg.gpuid = 1;
cfg.outputtype = 'flux';
%% 2. 体素模型 200×200×255
dimx = 200; dimy = 200; dimz = 255;
cfg.vol = zeros(dimx, dimy, dimz, 'uint8');
cfg.vol(:,:, 1:30) = 1; % 0.00–0.30 mm Scalp
cfg.vol(:,:,31:55) = 2; % 0.30–0.55 mm Skull
cfg.vol(:,:,56:155) = 3; % 0.55–1.55 mm CSF + Cortex
cfg.vol(:,:,156:255) = 4; % 1.55–2.55 mm Deep brain
%% 3. 光学参数(单位 mm⁻¹)
cfg.prop = [
0 0 1 1; % 0: 空气(外部)
0.018, 19.0, 0.9, 1.37; % 1: Scalp
0.016, 16.0, 0.9, 1.43; % 2: Skull
0.036, 22.0, 0.9, 1.37; % 3: Cortex
0.036, 22.0, 0.9, 1.37 % 4: Hippocampus
];
%% 4. 均匀面光源(200×200 体素全覆盖)
cfg.srctype = 'planar';
cfg.srcpos = [0, 0, 0]; % 左下角
cfg.srcdir = [0, 0, 1, 0];
cfg.srcparam1 = [dimx, 0, 0, 0]; % x 方向 200 体素
cfg.srcparam2 = [0, dimy, 0, 0]; % y 方向 200 体素
cfg.issrcfrom0 = 1;
%% 5. 边界与输出设置
cfg.isreflect = 1; % 开启外部边界反射
cfg.isnormalized = 1; % 默认就是 1(归一化)
%% 6. 运行仿真
tic;
f = mcxlab(cfg);
toc;
%% 7. 中心横断面(y=100)—— 正确量级
fluence_rate_cw = squeeze(f.data(:,100,:,1));
figure('Position',[100 100 950 700]);
imagesc(log10(fluence_rate_cw'));
colormap(jet); colorbar;
caxis([6.5 8.5]);
hold on;
% 层边界(白色虚线)
for z = [30 55 155 255]
plot([1 200], [z z], 'w--', 'LineWidth', 1.5);
end
% 坐标轴换成 mm
set(gca,'XTick',0:50:200,'XTickLabel',0:0.5:2);
set(gca,'YTick',0:50:255,'YTickLabel',0:0.5:2.55);
xlabel('X (mm)'); ylabel('Depth (mm)');
title('Log_{10}(Fluence Rate) - Center Slice (Uniform Planar Source)');
axis image;
% 1/e 深度
z_profile = squeeze(mean(mean(squeeze(f.data(:,:,:,1)), 1), 2));
[peak_val,peak_idx] = max(z_profile);
threshold = peak_val/exp(1);
idx1e = find(z_profile(peak_idx:end) <= threshold,1,'first') + peak_idx - 1;
depth_1e = (idx1e-0.5)*cfg.unitinmm;
plot([1 200], [idx1e idx1e], 'b-', 'LineWidth', 2.5);
text(10, idx1e-8, sprintf('1/e depth: %.2f mm', depth_1e), ...
'Color','blue','FontSize',12,'FontWeight','bold');
% 诊断 fluence 范围
fluence_log_data = log10(fluence_rate_cw);
min_val = min(fluence_log_data(fluence_log_data > 0));
max_val = max(fluence_log_data(:));
fprintf('实际 Log10(Fluence) 范围是:[%.2f, %.2f]\n', min_val, max_val);
%% 8. 衰减曲线
z_mm = ((1:dimz)-0.5)*cfg.unitinmm; % 真实深度 mm
figure;
semilogy(z_mm, z_profile, 'b-', 'LineWidth', 2); hold on;
semilogy(z_mm(peak_idx), peak_val, 'ro', 'MarkerSize', 8, 'MarkerFaceColor','r');
semilogy([0 2.6], [threshold threshold], 'r--','LineWidth',1.5);
semilogy(depth_1e, threshold, 'rp','MarkerSize',12,'MarkerFaceColor','r');
grid on; xlabel('Depth (mm)'); ylabel('Fluence Rate ');
title(sprintf('Center Profile - 1/e depth = %.2f mm (Peak = %.2e)', depth_1e, peak_val));
xlim([0 2.6]);
legend('Fluence rate','Peak','1/e threshold','1/e depth','Location','southwest');
fprintf('=== 诊断信息 ===\n');
fprintf('f.data 维度: %s\n', mat2str(size(f.data)));
fprintf('峰值 fluence rate = %.3e\n', peak_val);
fprintf('1/e 穿透深度 = %.2f mm\n', depth_1e);