InverseLight / ValoMC

Monte Carlo software for simulating light propagation
https://inverselight.github.io/ValoMC/
Other
43 stars 14 forks source link

Error in an Example of 'Frequency domain calculation' #10

Open ghost opened 3 years ago

ghost commented 3 years ago

First of all, thanks for making and distributing the valuable tool.

Currently, I am just going through the examples offered to understand what is going on with the simulation tool.

While other examples ran seamlessly, I encountered an error while running the example of 'Frequency domain calculation'.

Specifically, I got an error message while running the lines shown below: % Search positions for the light sources in the walls lightsource1 = findBoundaries(vmcmesh, 'location', [-10 -15]); lightsource2 = findBoundaries(vmcmesh, 'location', [10 -15]);

The error messages are:

Error using - Matrix dimensions must agree.

Error in findBoundaries>findLineSegmentsNearest (line 228) m=(pos - locations(ii,:)) .^2;

Error in findBoundaries (line 70) elements = findLineSegmentsNearest(vmcmesh, varargin{1});

After going through the code of 'findBoundaries', I just changed [-10 -15] as [-10; -15] as a temporary solution and I found that the code could run without any issues (I found that it would take an hour or so and I am not sure whether or not it is normal. FYI, I do not enable OpenMP).

In the post by nipat298, I found that a possible modification of the code.

Could you shed light on difference between modifying the code following nipat298's post and my temporary solution?

Also, is there any recommendation regarding the issue?

Thanks, Myeongsu

nipat298 commented 3 years ago

When you change [-10 -15] to [-10; -15], it is now a column vector. So your code now behaves as if you have 2 locations with the coordinates (-10,-10) and (-15,-15).

In Matlab, you can operate on vectors/matrices with scalars and no error will be returned. Which is what the code does in your case. x_pos = pos(:,1) , y_pos = pos(:,2) are the x and y point coordinates contained in pos. You want to compute

m = [(x_pos - x_loc(ii)).^2 (y_pos -y_loc(ii)).^2]

In the code modification, I force the 'locations' matrix to be of the same size as 'pos', which resolves the error.

ghost commented 3 years ago

Thanks for your quick response!

Then I will modify the code as you suggested for simulation.