Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Photon sharing and dual grid give inconsistent output when used with more than one pattern (demo_photon_sharing.m) #97

Closed
andreafarina opened this issue Sep 19, 2024 · 6 comments

Comments

@andreafarina
Copy link
Contributor

Dear Qinqian,
I've tried to change the cfg.method from 'elem' to 'grid' to test the dual grid in demo_photon_sharing.m. As expected the flux.data output is a 5D array having the following dimensions: [Num_pattern, Nx, Ny, Nz, NTime]. After summing up the last (time) I tried to plot the fluence in the z dimension for each pattern. I obtain inconsistent results, which does not happen if only one pattern is simulated in the source. Probably there is some bug in reshaping the output data.
Thanks a lot!
Andrea

Screenshot 2024-09-19 at 01 34 40
@fangq
Copy link
Owner

fangq commented Sep 21, 2024

thanks @andreafarina for reporting this - can you provide a reproducer code to show the problem?

@andreafarina
Copy link
Contributor Author

andreafarina commented Sep 21, 2024

For sure! It is a slight variation of the example demo_photon_sharing.m adapted to grid instead of elem.

cfg.nphoton=3e6;
[cfg.node face cfg.elem]=meshabox([0 0 0],[60 60 20],2, 2);
cfg.elemprop=ones(size(cfg.elem,1),1);
cfg.srcpos=[10 10 -2];
cfg.srcdir=[0 0 1];
cfg.srctype='pattern';
cfg.srcparam1=[40.0 0.0 0.0 40];
cfg.srcparam2=[0.0 40.0 0.0 40];
cfg.prop=[0 0 1 1;0.01 10 0.9 1.37];
cfg.tstart=0;
cfg.tend=5e-9;
cfg.tstep=1e-10;
cfg.gpuid=-1;
cfg.method='grid';
cfg.debuglevel='TP';

%% 5 patterns represented by a 3D matrix

pat=zeros(40,40,5);
pat(:,:,1) = ones(40);  % full field illumination pattern
pat(1:20,:,2) = 1;      % pattern with left half bright
pat(:,1:20,3) = 1;      % pattern with top half bright
pat(11:30,11:30,4) = 1; % pattern with bright square in the middle
pat(16:25,:,5) = 1;  
pat(:,16:25,5) = 1;     % pattern with a bright cross

cfg.srcpattern = pat;

%% run the simulation

flux=mmclab(cfg);

data = flux.data;
disp(['size(flux.data) = ',num2str(size(flux.data))]);
% 5D array: [Npatt,Nx,Ny,Nz,Ntime]
cwdata = squeeze(sum(data,5)); %sum over time


%% look z = 3
z = 3;
for i = 1:size(cwdata,1) % changed cw to cwdata to avoid an error
    figure(1),
    subplot(2,3,i),
    imagesc(squeeze(cwdata(i,:,:,z))),
    title(['pattern ',num2str(i)]),
    axis image
end

@fangq fangq closed this as completed in 2a7e9dd Sep 21, 2024
@fangq
Copy link
Owner

fangq commented Sep 21, 2024

@andreafarina, I was able to reproduce the issue and fixed it with the following commit

2a7e9dd

the screenshot of the output is attached below.

the photon-sharing feature is now supported with DMMC on the CPU - still need to work on GPU port of photon-sharing (#86).

please test and let me know if you see any additional problem.

dmmc_photonsharing

@andreafarina
Copy link
Contributor Author

Thanks a lot!! It works now!!
Best regards!
Andrea

@fangq
Copy link
Owner

fangq commented Oct 15, 2024

@andreafarina, FYI, the photon-sharing feature is now working on the GPU (for both OpenCL and CUDA).

see #86 and #99 - please note that the srcpattern array now uses the 1st dimension (left-most) as the pattern dimension, instead of the right-most dimension. This way, it is consistent with the photon-sharing in mcx.

@andreafarina
Copy link
Contributor Author

@fangq thank you very much! It works great! And I can run also using CUDA with the make cudamex mex file generated. There is still the error in matlab Unrecognized function or variable 'stdout'. but it arrives at the end and the patterns are ok.
It's still not clear to me, as described in #98 (comment) how to work with the mmciii.mexa64 trinity binary generated with CMake and why the reply with cuda doesn't work...
Thank you again for the fix!
Best regards

Andrea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants