├── +MCmatlab ├── @depositionCriteria │ └── depositionCriteria.m ├── @fluorescenceMonteCarloSimulation │ └── fluorescenceMonteCarloSimulation.m ├── @geometry │ └── geometry.m ├── @heatSimulation │ └── heatSimulation.m ├── @lightCollector │ └── lightCollector.m ├── @lightSource │ └── lightSource.m ├── @mediumProperties │ └── mediumProperties.m ├── @model │ ├── combineModels.m │ ├── model.m │ ├── plotMCmatlabGeom.m │ ├── plotMCmatlabHeat.m │ ├── plotMCmatlabMC.m │ ├── private │ │ ├── MCmatlab.mexa64 │ │ ├── MCmatlab.mexmaca64 │ │ ├── MCmatlab.mexmaci64 │ │ ├── MCmatlab.mexw64 │ │ ├── MCmatlab_CUDA.mexw64 │ │ ├── MCmatlab_singlethreaded.mexa64 │ │ ├── cudart64_101.dll │ │ ├── finiteElementHeatPropagator.mexa64 │ │ ├── finiteElementHeatPropagator.mexmaca64 │ │ ├── finiteElementHeatPropagator.mexmaci64 │ │ ├── finiteElementHeatPropagator.mexw64 │ │ ├── finiteElementHeatPropagator_CUDA.mexw64 │ │ ├── finiteElementHeatPropagator_singlethreaded.mexa64 │ │ ├── getDownsampledParamVals.mexa64 │ │ ├── getDownsampledParamVals.mexmaca64 │ │ ├── getDownsampledParamVals.mexmaci64 │ │ ├── getDownsampledParamVals.mexw64 │ │ ├── getOpticalMediaProperties.m │ │ ├── getThermalMediaProperties.m │ │ ├── imfilter.m │ │ ├── imgradientxyz.m │ │ ├── inferno.m │ │ ├── libgomp_64-1.dll │ │ ├── makec2f.m │ │ ├── plotCuboidSurfaces.m │ │ ├── plotFarField.m │ │ ├── plotMediaProperties.m │ │ ├── redrawCuboidSurfaces.m │ │ ├── redrawFarField.m │ │ ├── smoothn license.txt │ │ └── smoothn.m │ ├── runMonteCarlo.m │ └── simulateHeatDistribution.m ├── @monteCarloSimulation │ └── monteCarloSimulation.m ├── @sourceIntensityDistribution │ └── sourceIntensityDistribution.m ├── NdimSliderPlot.m ├── NdimSliderPlotRedraw.m ├── closeMCmatlabFigures.m ├── inferno.m ├── makec2f.m ├── plotAzFz.m ├── plotRadialReflectanceTransmittance.m ├── src │ ├── MCmatlab.c │ ├── MCmatlablib.c │ ├── clang_openmp_maci64.xml │ ├── dSFMT-src-2.2.3 │ │ ├── CHANGE-LOG.txt │ │ ├── FILES.txt │ │ ├── LICENSE.txt │ │ ├── Makefile │ │ ├── README.jp.txt │ │ ├── README.txt │ │ ├── check.sh │ │ ├── dSFMT-common.h │ │ ├── dSFMT-params.h │ │ ├── dSFMT-params11213.h │ │ ├── dSFMT-params1279.h │ │ ├── dSFMT-params132049.h │ │ ├── dSFMT-params19937.h │ │ ├── dSFMT-params216091.h │ │ ├── dSFMT-params2203.h │ │ ├── dSFMT-params4253.h │ │ ├── dSFMT-params44497.h │ │ ├── dSFMT-params521.h │ │ ├── dSFMT-params86243.h │ │ ├── dSFMT.11213.out.txt │ │ ├── dSFMT.1279.out.txt │ │ ├── dSFMT.132049.out.txt │ │ ├── dSFMT.19937.out.txt │ │ ├── dSFMT.216091.out.txt │ │ ├── dSFMT.2203.out.txt │ │ ├── dSFMT.4253.out.txt │ │ ├── dSFMT.44497.out.txt │ │ ├── dSFMT.521.out.txt │ │ ├── dSFMT.86243.out.txt │ │ ├── dSFMT.c │ │ ├── dSFMT.h │ │ ├── foo.txt │ │ ├── html │ │ │ ├── annotated.html │ │ │ ├── bc_s.png │ │ │ ├── bdwn.png │ │ │ ├── classes.html │ │ │ ├── closed.png │ │ │ ├── d_s_f_m_t-common_8h.html │ │ │ ├── d_s_f_m_t-common_8h_source.html │ │ │ ├── d_s_f_m_t_8c.html │ │ │ ├── d_s_f_m_t_8h.html │ │ │ ├── d_s_f_m_t_8h_source.html │ │ │ ├── doxygen.css │ │ │ ├── doxygen.png │ │ │ ├── files.html │ │ │ ├── functions.html │ │ │ ├── functions_vars.html │ │ │ ├── globals.html │ │ │ ├── globals_defs.html │ │ │ ├── globals_func.html │ │ │ ├── globals_type.html │ │ │ ├── globals_vars.html │ │ │ ├── howto-compile.html │ │ │ ├── index.html │ │ │ ├── jquery.js │ │ │ ├── mainpage_8txt.html │ │ │ ├── nav_f.png │ │ │ ├── nav_h.png │ │ │ ├── open.png │ │ │ ├── struct_d_s_f_m_t___t.html │ │ │ ├── tab_a.png │ │ │ ├── tab_b.png │ │ │ ├── tab_h.png │ │ │ ├── tab_s.png │ │ │ ├── tabs.css │ │ │ └── union_w128___t.html │ │ ├── test-sse2-M19937.exe │ │ ├── test-std-M19937.exe │ │ └── test.c │ ├── enable-openmp-on-macos.md │ ├── finiteElementHeatPropagator.c │ ├── getDownsampledParamVals.c │ ├── lambert.c │ ├── libut.lib │ ├── openmp files for mex compiler │ │ ├── libgomp.a │ │ ├── libgomp.spec │ │ └── libgomp_64-1.dll │ └── print.h └── x264 │ ├── x264_linux │ ├── x264_macOS │ └── x264_win64.exe ├── .gitattributes ├── .gitignore ├── Example10_MediaPropertyParametricSweep.m ├── Example11_MultipleHeatSims.m ├── Example12_SaturableAbsorber.m ├── Example13_TdependentVHC.m ├── Example14_Thermochromism.m ├── Example15_ThermallyInducedScattering.m ├── Example16_CUDAacceleration.m ├── Example17_CurvedRefractionReflection.m ├── Example18_STLimport.m ├── Example19_DepositionCriteria.m ├── Example1_StandardTissue.m ├── Example20_ReflectanceStatisticsAndCyclicBoundaries.m ├── Example21_CustomPhaseFunctions.m ├── Example22_CombiningModelObjects.m ├── Example23_BroadbandMonteCarlo.m ├── Example24_AzFzReflectanceTransmittance.m ├── Example25_DepositionCriteria2.m ├── Example26_DistributedSource.m ├── Example2_BeamDefinitions.m ├── Example3_RefractionReflection.m ├── Example4_BloodVessel.m ├── Example5_FluorescenceAndImaging.m ├── Example6_TimeTagging.m ├── Example7_FarField.m ├── Example8_CollectedFluenceRate.m ├── Example9_GeometryParametricSweep.m ├── LICENSE ├── README.md ├── Test1_AllFRTDependences.m ├── helperfuncs ├── Grid.m ├── LuciferYellowCHinWater-abs.txt ├── LuciferYellowCHinWater-ems.txt ├── Mesh voxelization license.txt ├── Mesh voxelization readme.md ├── Raster.m ├── RayRaster.m ├── calc_mua.m ├── calc_mus.m ├── compute_normals.m ├── convert_triangle_geometry_format.m ├── findInsideVoxels.m ├── fix_vertex_ordering.m ├── initializeMCmatlabModel.m ├── read_stl.m └── spectralLIB.mat ├── sample.stl └── version /+MCmatlab/@depositionCriteria/depositionCriteria.m: -------------------------------------------------------------------------------- 1 | classdef depositionCriteria 2 | % List of criteria for when a photon's weight loss should be deposited in 3 | % any output arrays. All the criteria have to be met simultaneously - there 4 | % is an implied AND between them all. 5 | 6 | % The minMediumIdxToConsider and maxMediumIdxToConsider are different in 7 | % that they specify which media the above criteria are for. For example, if 8 | % you've specified minScatterings = 2, minMediumIdxToConsider = 4 and 9 | % maxMediumIdxToConsider = 5, then only photons that have experienced at 10 | % least 2 scattering events in media 4 and/or 5 will deposit their 11 | % weight in the output arrays. It doesn't matter how many scattering events 12 | % have happened in other media. 13 | 14 | % Interface transitions and refractions will be considered if the medium 15 | % transitioned *into* has index between minMediumIdxToConsider and 16 | % maxMediumIdxToConsider. 17 | 18 | % The user can rearrange the media in the media definition as required so 19 | % that the set of media that he/she wants to consider in deposition 20 | % criteria are in a contiguous interval. 21 | 22 | % If evaluateOnlyAtEndOfLife is false, the photons will deposit weight into 23 | % the output arrays only in those segments of the paths where the criteria 24 | % are satisfied. If it is true, weight is deposited along the full path if 25 | % the criteria are satisfied at the end of the photon's life span. 26 | 27 | % If evaluateOnlyAtEndOfLife is true, you may also specify onlyCollected. 28 | % It is an extra criterion that states that the photon must have been 29 | % collected on the light collector. 30 | 31 | properties 32 | minScatterings (1,1) double {mustBeInteger,mustBeNonnegative} = 0 33 | maxScatterings (1,1) double {mustBeNonnegativeIntegerOrPositiveInfinite} = Inf 34 | minRefractions (1,1) double {mustBeInteger,mustBeNonnegative} = 0 35 | maxRefractions (1,1) double {mustBeNonnegativeIntegerOrPositiveInfinite} = Inf 36 | minReflections (1,1) double {mustBeInteger,mustBeNonnegative} = 0 37 | maxReflections (1,1) double {mustBeNonnegativeIntegerOrPositiveInfinite} = Inf 38 | minInterfaceTransitions (1,1) double {mustBeInteger,mustBeNonnegative} = 0 39 | maxInterfaceTransitions (1,1) double {mustBeNonnegativeIntegerOrPositiveInfinite} = Inf 40 | 41 | minMediumIdxToConsider (1,1) double {mustBePositiveIntegerOrPositiveInfinite} = 1 42 | maxMediumIdxToConsider (1,1) double {mustBePositiveIntegerOrPositiveInfinite} = Inf 43 | 44 | onlyCollected (1,1) logical = false 45 | evaluateOnlyAtEndOfLife (1,1) logical = true 46 | end 47 | 48 | properties (Hidden) % Calculated based on minMediumIdxToConsider and maxMediumIdxToConsider 49 | minSubmediaIdx (1,1) double 50 | maxSubmediaIdx (1,1) double 51 | end 52 | end 53 | 54 | function mustBePositiveIntegerOrPositiveInfinite(x) 55 | if x <= 0 || (isfinite(x) && rem(x,1) ~= 0) 56 | error('Error: Value must be a positive integer or infinity.'); 57 | end 58 | end 59 | function mustBeNonnegativeIntegerOrPositiveInfinite(x) 60 | if x < 0 || (isfinite(x) && rem(x,1) ~= 0) 61 | error('Error: Value must be a non-negative integer or infinity.'); 62 | end 63 | end -------------------------------------------------------------------------------- /+MCmatlab/@heatSimulation/heatSimulation.m: -------------------------------------------------------------------------------- 1 | classdef heatSimulation 2 | %HEATSIMULATION This class includes all properties and methods 3 | %related to the heat simulation in an MCmatlab.model. 4 | 5 | properties 6 | %% Input properties 7 | silentMode (1,1) logical = false % Disables command window text and progress indication 8 | useAllCPUs (1,1) logical = false % If false, MCmatlab will leave one processor unused. Useful for doing other work on the PC while simulations are running. 9 | useGPU (1,1) logical = false % Use CUDA acceleration for NVIDIA GPUs 10 | makeMovie (1,1) logical = false % Requires silentMode = false. 11 | deferMovieWrite (1,1) logical = false 12 | largeTimeSteps (1,1) logical = false % If true, calculations will be faster, but some voxel temperatures may be slightly less precise. Test for yourself whether this precision is acceptable for your application. 13 | 14 | heatBoundaryType (1,1) double {mustBeInteger, mustBeInRange(heatBoundaryType,0,1)} = 0 % 0: Insulating boundaries, 1: Constant-temperature boundaries (heat-sinked) 15 | durationOn (1,1) double {mustBeNonnegative} = 0 % [s] Pulse on-duration 16 | durationOff (1,1) double {mustBeNonnegative} = 0 % [s] Pulse off-duration 17 | durationEnd (1,1) double {mustBeNonnegative} = 0 % [s] Non-illuminated relaxation time to add to the end of the simulation to let temperature diffuse after the pulse train 18 | 19 | nPulses (1,1) double {mustBeInteger, mustBePositive} = 1 % Number of consecutive pulses, each with an illumination phase and a diffusion phase. If simulating only illumination or only diffusion, use n_pulses = 1. 20 | 21 | plotTempLimits (1,2) {mustBeTwoNonInfs} = [NaN NaN] % [deg C] Expected range of temperatures, used only for setting the color scale in the plot 22 | nUpdates (1,1) {mustBeInteger, mustBePositive} = 10 % Number of times data is extracted for plots during each pulse. A minimum of 1 update is performed in each phase (2 for each pulse consisting of an illumination phase and a diffusion phase) 23 | mediaPropRecalcPeriod (1,1) {mustBeInteger, mustBeNonnegative} = 0 % Every N updates, the media properties will be recalculated (including, if needed, re-running MC and FMC steps) 24 | 25 | slicePositions (1,3) {mustBeInRange(slicePositions,0,1)} = [.5 1 1] % Relative slice positions [x y z] for the 3D plots on a scale from 0 to 1 26 | tempSensorPositions (:,3) {mustBeFinite} % Each row is a temperature sensor's absolute [x y z] coordinates. Leave the matrix empty ([]) to disable temperature sensors. 27 | 28 | %% Input and calculated properties 29 | T (:,:,:) single {mustBeFinite} = 37 % [deg C] Temperature, both an input and an output, can be scalar or 3D array 30 | 31 | %% Calculated properties 32 | mediaProperties = NaN 33 | 34 | M = NaN 35 | 36 | Omega single = 0 37 | maxMediaTemps = NaN 38 | sensorsTimeVector = NaN 39 | sensorTemps = NaN 40 | movieFrames = NaN 41 | end 42 | 43 | properties (Hidden, Dependent) 44 | Tinitial 45 | end 46 | 47 | methods 48 | function obj = heatSimulation() 49 | %HEATSIMULATION Construct an instance of this class 50 | end 51 | function obj = set.Tinitial(obj,x) 52 | obj.T = x; 53 | warning('Tinitial has been deprecated. Set the initial temperature, either as a scalar or 3D array, directly to the model.HS.T property. model.HS.T thus functions both as an input and output property.'); 54 | end 55 | function x = get.Tinitial(obj); x = obj.T; end 56 | end 57 | end 58 | 59 | function mustBeTwoNonInfs(x) 60 | x = x(:); 61 | if ~(numel(x) == 2 && isnumeric(x)) 62 | error('Value must be an array of two numerics'); 63 | end 64 | if any(isinf(x)) 65 | error('Array must not contain Infs'); 66 | end 67 | if ~(any(isnan(x)) || x(2) > x(1)) 68 | error('Second element must be larger than the first, or one of them must be NaN'); 69 | end 70 | end 71 | 72 | function mustBeFiniteOrNaNScalar(x) 73 | x = x(:); 74 | if isscalar(x) 75 | if isnan(x) || isfinite(x) 76 | % Valid input 77 | else 78 | error('Value must be either a scalar NaN or a finite scalar or array.'); 79 | end 80 | else 81 | if all(isfinite(x)) 82 | % Valid input 83 | else 84 | error('Value must be either a scalar NaN or a finite scalar or array.'); 85 | end 86 | end 87 | end 88 | 89 | function mustBeInRange(x,a,b) 90 | if any(x(:) < a) || any(x(:) > b) 91 | error('Error: Values must be in range %f to %f.',a,b); 92 | end 93 | end -------------------------------------------------------------------------------- /+MCmatlab/@lightCollector/lightCollector.m: -------------------------------------------------------------------------------- 1 | classdef lightCollector 2 | %LIGHTCOLLECTOR This class contains all properties related to a 3 | %light collector of an MCmatlab.model. 4 | % This class defines the properties of a lightcollector to be used in 5 | % monteCarloSimulation or fluorescenceMonteCarloSimulation. 6 | 7 | properties 8 | %% Input properties 9 | x (1,1) double {mustBeFinite} = 0 % [cm] x position of either the center of the objective lens focal plane or the fiber tip 10 | y (1,1) double {mustBeFinite} = 0 % [cm] y position 11 | z (1,1) double {mustBeFinite} = 0 % [cm] z position 12 | 13 | theta (1,1) double {mustBeFinite} = 0 % [rad] Polar angle of direction the light collector is facing 14 | phi (1,1) double {mustBeFinite} = pi/2 % [rad] Azimuthal angle of direction the light collector is facing 15 | 16 | f (1,1) double {mustBePositive} = Inf % [cm] Focal length of the objective lens (if light collector is a fiber, set this to Inf). 17 | diam (1,1) double {mustBePositive} = 1 % [cm] Diameter of the light collector aperture. For an ideal thin lens, this is 2*f*tan(asin(NA)). 18 | fieldSize (1,1) double {mustBePositive} = 1 % [cm] Field Size of the imaging system (diameter of area in object plane that gets imaged). Only used for finite f. 19 | NA (1,1) double {mustBePositive} = 0.22 % [-] Fiber NA. Only used for infinite f. 20 | res (1,1) double {mustBeInteger, mustBeNonnegative} = 0 % X and Y resolution of light collector in pixels, only used for finite f 21 | 22 | tStart (1,1) double {mustBeFinite} = 0 % [s] Start of the detection time interval 23 | tEnd (1,1) double {mustBeFinite} = 1e-12 % [s] End of the detection time interval 24 | nTimeBins (1,1) double {mustBeInteger, mustBeNonnegative} = 0 % Number of bins between tStart and tEnd. If zero, the measurement is not time-resolved. 25 | 26 | %% Calculated properties 27 | image = NaN 28 | X = NaN 29 | Y = NaN 30 | t = NaN 31 | end 32 | 33 | methods 34 | function obj = lightCollector() 35 | %LIGHTCOLLECTOR Construct an instance of this class 36 | 37 | end 38 | end 39 | end 40 | 41 | -------------------------------------------------------------------------------- /+MCmatlab/@lightSource/lightSource.m: -------------------------------------------------------------------------------- 1 | classdef lightSource 2 | %BEAM This class includes all properties and methods 3 | %related to a beam in an MCmatlab.model.monteCarloSimulation. 4 | 5 | properties 6 | %% Input properties 7 | sourceType (1,1) double {mustBeInteger, mustBeInRange(sourceType,0,5)} = 0 % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 8 | 9 | xFocus (1,1) double {mustBeFinite} = 0 10 | yFocus (1,1) double {mustBeFinite} = 0 11 | zFocus (1,1) double {mustBeFinite} = 0 12 | 13 | theta (1,1) double {mustBeFinite} = 0 % [rad] Polar angle of beam center axis 14 | phi (1,1) double {mustBeFinite} = 0 % [rad] Azimuthal angle of beam center axis 15 | psi (1,1) double {mustBeFinite} = 0 % [rad] Axial rotation angle of beam, relevant only for XY distributed beams 16 | 17 | emitterLength (1,1) double {mustBeNonnegative} = 0 % [cm] Length of isotropic emitter (line or point) 18 | 19 | focalPlaneIntensityDistribution (1,1) MCmatlab.sourceIntensityDistribution 20 | angularIntensityDistribution (1,1) MCmatlab.sourceIntensityDistribution 21 | 22 | end 23 | 24 | properties (Hidden, Dependent) 25 | beamType 26 | NF 27 | FF 28 | FPID 29 | AID 30 | end 31 | 32 | methods 33 | function x = get.beamType(obj) 34 | warning('beamType has been renamed sourceType. The ability to reference sourceType through beamType will be deprecated in a future version.'); 35 | x = obj.sourceType; 36 | end 37 | function obj = set.beamType(obj,x) 38 | warning('beamType has been renamed sourceType. The ability to reference sourceType through beamType will be deprecated in a future version.'); 39 | obj.sourceType = x; 40 | end 41 | function x = get.NF(obj) 42 | warning('NF has been renamed focalPlaneIntensityDistribution (FPID). The ability to reference focalPlaneIntensityDistribution through NF will be deprecated in a future version.'); 43 | x = obj.focalPlaneIntensityDistribution; 44 | end 45 | function obj = set.NF(obj,x) 46 | warning('NF has been renamed focalPlaneIntensityDistribution (FPID). The ability to reference focalPlaneIntensityDistribution through NF will be deprecated in a future version.'); 47 | obj.focalPlaneIntensityDistribution = x; 48 | end 49 | function x = get.FF(obj) 50 | warning('FF has been renamed angularIntensityDistribution (AID). The ability to reference angularIntensityDistribution through FF will be deprecated in a future version.'); 51 | x = obj.angularIntensityDistribution; 52 | end 53 | function obj = set.FF(obj,x) 54 | warning('FF has been renamed angularIntensityDistribution (AID). The ability to reference angularIntensityDistribution through FF will be deprecated in a future version.'); 55 | obj.angularIntensityDistribution = x; 56 | end 57 | function x = get.FPID(obj ); x = obj.focalPlaneIntensityDistribution; end 58 | function obj = set.FPID(obj,x); obj.focalPlaneIntensityDistribution = x; end 59 | function x = get.AID(obj ); x = obj.angularIntensityDistribution; end 60 | function obj = set.AID(obj,x); obj.angularIntensityDistribution = x; end 61 | end 62 | end 63 | 64 | function mustBeInRange(x,a,b) 65 | if any(x(:) < a) || any(x(:) > b) 66 | error('Error: Values must be in range %f to %f.',a,b); 67 | end 68 | end -------------------------------------------------------------------------------- /+MCmatlab/@model/plotMCmatlabGeom.m: -------------------------------------------------------------------------------- 1 | function model = plotMCmatlabGeom(model) 2 | % Displays 3 | % Geometry cuboid 4 | % Media optical, thermal and fluorescence properties 5 | % 6 | % Requires 7 | % NdimSliderPlot.m 8 | % 9 | 10 | %%%%% 11 | % Copyright 2017, 2018 by Dominik Marti and Anders K. Hansen, DTU Fotonik 12 | % This function was inspired by lookmcxyz.m of the mcxyz MC program hosted at omlc.org 13 | % 14 | % This file is part of MCmatlab. 15 | % 16 | % MCmatlab is free software: you can redistribute it and/or modify 17 | % it under the terms of the GNU General Public License as published by 18 | % the Free Software Foundation, either version 3 of the License, or 19 | % (at your option) any later version. 20 | % 21 | % MCmatlab is distributed in the hope that it will be useful, 22 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | % GNU General Public License for more details. 25 | % 26 | % You should have received a copy of the GNU General Public License 27 | % along with MCmatlab. If not, see . 28 | %%%%% 29 | 30 | try 31 | matlabDrivePath = matlabdrive; 32 | catch 33 | matlabDrivePath = 'MATLAB Drive is not installed'; 34 | end 35 | if strcmp(matlabDrivePath,'/MATLAB Drive') && strcmp(matlabroot, '/MATLAB') 36 | % dirty hack to check whether we are on MATLAB online, 37 | % where the Figures window tabs can't be on the side of the figure window 38 | com.mathworks.mde.desk.MLDesktop.getInstance.setDocumentBarPosition('Figures',1); % Set Figures window tabs to be on top 39 | else 40 | com.mathworks.mde.desk.MLDesktop.getInstance.setDocumentBarPosition('Figures',7); % Set Figures window tabs to be on left side 41 | end 42 | model.G = model.G.updateGeometry; 43 | 44 | %% Make geometry plot 45 | mediaProperties = model.G.mediaPropertiesFunc(model.G.mediaPropParams); 46 | if ~isa(mediaProperties,'MCmatlab.mediumProperties') 47 | error('Error: The syntax for defining media properties has changed slightly. You must now put "mediaProperties = MCmatlab.mediumProperties;" as the first line of the mediaProperties function. See the examples for details.'); 48 | end 49 | [uniqueMedia,~,M_trimmed] = unique(model.G.M_raw); 50 | M_trimmed = reshape(M_trimmed,model.G.nx,model.G.ny,model.G.nz); 51 | mediaProperties_trimmed = mediaProperties(uniqueMedia); 52 | h_f = MCmatlab.NdimSliderPlot(M_trimmed,... 53 | 'nFig',1,... 54 | 'axisValues',{model.G.x,model.G.y,model.G.z},... 55 | 'axisLabels',{'x [cm]','y [cm]','z [cm]','Geometry illustration'},... 56 | 'indexLabels',{mediaProperties_trimmed.name},... 57 | 'linColormap',lines(256),... 58 | 'axisEqual',true,... 59 | 'reversedAxes',3); 60 | h_f.Name = 'Geometry illustration'; 61 | 62 | drawnow; 63 | figure(1); 64 | end 65 | -------------------------------------------------------------------------------- /+MCmatlab/@model/plotMCmatlabHeat.m: -------------------------------------------------------------------------------- 1 | function model = plotMCmatlabHeat(model) 2 | % Requires 3 | % plotVolumetric.m 4 | % 5 | % See also simulateHeatDistribution 6 | 7 | %%%%% 8 | % Copyright 2017, 2018 by Dominik Marti and Anders K. Hansen, DTU Fotonik 9 | % 10 | % This file is part of MCmatlab. 11 | % 12 | % MCmatlab is free software: you can redistribute it and/or modify 13 | % it under the terms of the GNU General Public License as published by 14 | % the Free Software Foundation, either version 3 of the License, or 15 | % (at your option) any later version. 16 | % 17 | % MCmatlab is distributed in the hope that it will be useful, 18 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | % GNU General Public License for more details. 21 | % 22 | % You should have received a copy of the GNU General Public License 23 | % along with MCmatlab. If not, see . 24 | %%%%% 25 | 26 | try 27 | matlabDrivePath = matlabdrive; 28 | catch 29 | matlabDrivePath = 'MATLAB Drive is not installed'; 30 | end 31 | if strcmp(matlabDrivePath,'/MATLAB Drive') && strcmp(matlabroot, '/MATLAB') 32 | % dirty hack to check whether we are on MATLAB online, 33 | % where the Figures window tabs can't be on the side of the figure window 34 | com.mathworks.mde.desk.MLDesktop.getInstance.setDocumentBarPosition('Figures',1); % Set Figures window tabs to be on top 35 | else 36 | com.mathworks.mde.desk.MLDesktop.getInstance.setDocumentBarPosition('Figures',7); % Set Figures window tabs to be on left side 37 | end 38 | model.G = model.G.updateGeometry; 39 | 40 | G = model.G; 41 | mP_fH = model.G.mediaPropertiesFunc(G.mediaPropParams); % Unsplit media 42 | [unqMediaIdxs,~,M_trim] = unique(G.M_raw); 43 | M_trim = reshape(M_trim,[G.nx G.ny G.nz]); 44 | mP_fHtrim = mP_fH(unqMediaIdxs); 45 | nM = numel(mP_fHtrim); 46 | names = {mP_fHtrim.name}; 47 | numTemperatureSensors = size(model.HS.tempSensorPositions,1); 48 | 49 | %% Write out the highest temperatures in each medium 50 | fprintf('--------------------plotMCmatlabHeat---------------------\n'); 51 | for iM=1:nM 52 | if isfinite(model.HS.maxMediaTemps(iM)) 53 | fprintf('Highest temperature obtained in %s is %.2f°C\n',names{iM},model.HS.maxMediaTemps(iM)); 54 | end 55 | end 56 | 57 | %% Plot the geometry showing the temperature sensor locations and the sensor data 58 | if numTemperatureSensors 59 | h_f = MCmatlab.NdimSliderPlot(G.M_raw,... 60 | 'nFig',23,... 61 | 'axisValues',{G.x,G.y,G.z},... 62 | 'axisLabels',{'x [cm]','y [cm]','z [cm]','Geometry illustration'},... 63 | 'indexLabels',names,... 64 | 'linColormap',lines(256),... 65 | 'axisEqual',true,... 66 | 'reversedAxes',3,... 67 | 'slicePositions',model.HS.slicePositions); 68 | h_f.Name = 'Temperature sensor illustration'; 69 | title('Temperature sensor illustration'); 70 | 71 | for i=numTemperatureSensors:-1:1 72 | indices = round((model.HS.tempSensorPositions(i,:)+[G.Lx G.Ly 0]/2)./[G.dx G.dy G.dz] + [0.5 0.5 0.5]); % +[1 1 1] to go from zero-index reference to one-index reference and -[0.5 0.5 0.5] to go from voxel corner position to voxel center positions 73 | indices = min([G.nx G.ny G.nz],max([1 1 1],indices)); % Coerce to the cuboid 74 | linindex = sub2ind(size(G.M_raw),indices(1),indices(2),indices(3)); 75 | sensorNumbers{i,1} = num2str(i); 76 | sensorLabels{i,1} = [num2str(i) ', ' mP_fHtrim(G.M_raw(linindex)).name]; 77 | end 78 | text(model.HS.tempSensorPositions(:,1),model.HS.tempSensorPositions(:,2),model.HS.tempSensorPositions(:,3),sensorNumbers,'HorizontalAlignment','center','VerticalAlignment','middle','FontSize',18); 79 | 80 | h_f = figure(24); 81 | clf reset; 82 | set(h_f,'WindowStyle','Docked'); 83 | h_f.Color = 'w'; 84 | h_f.Name = 'Temperature sensor data'; 85 | plot(model.HS.sensorsTimeVector,model.HS.sensorTemps,'LineWidth',2); 86 | set(gca,'FontSize',16); 87 | xlabel('Time [sec]'); 88 | ylabel('Temperature [deg C]'); 89 | title('Temperature sensor data'); 90 | xlim(model.HS.sensorsTimeVector([1 end])); 91 | legend(sensorLabels,'Location','best'); 92 | grid on;grid minor; 93 | end 94 | 95 | %% Plot thermal damage 96 | % Let c be the concentration of undamaged molecules or living cells 97 | % Omega = ln(c(t=0)/c(t=tau)) = int(A*exp(-E/(RT(t))),t=0..tau) 98 | % c(0)/c(t) = exp(Omega) <=> c(t) = c(0)*exp(-Omega) 99 | % So the fractional portion of damaged molecules/cells is: 100 | % (c(0)-c(t))/c(0) = (c0-c0*exp(-Omega))/c0 = 1 - exp(-Omega) 101 | if ~isnan(model.HS.Omega(1)) 102 | M_damage = M_trim; 103 | M_damage(model.HS.Omega > 1) = nM + 1; 104 | namesWithDamage = [names 'damage']; 105 | h_f = MCmatlab.NdimSliderPlot(M_damage,... 106 | 'nFig',25,... 107 | 'axisValues',{G.x,G.y,G.z},... 108 | 'axisLabels',{'x [cm]','y [cm]','z [cm]','Thermal damage illustration'},... 109 | 'indexLabels',namesWithDamage,... 110 | 'linColormap',lines(256),... 111 | 'axisEqual',true,... 112 | 'reversedAxes',3,... 113 | 'slicePositions',model.HS.slicePositions); 114 | h_f.Name = 'Thermal damage illustration'; 115 | title('Thermal damage illustration'); 116 | fprintf('%.2e cm^3 was thermally damaged.\n',G.dx*G.dy*G.dz*sum(model.HS.Omega(:) > 1)); 117 | 118 | h_f = MCmatlab.NdimSliderPlot(1-exp(-model.HS.Omega),... 119 | 'nFig',26,... 120 | 'axisValues',{G.x,G.y,G.z},... 121 | 'axisLabels',{'x [cm]','y [cm]','z [cm]','Fractional damage'},... 122 | 'axisEqual',true,... 123 | 'reversedAxes',3,... 124 | 'slicePositions',model.HS.slicePositions); 125 | h_f.Name = 'Fractional damage'; 126 | title('Fractional damage (1 - e^{-\Omega})'); 127 | end 128 | drawnow; 129 | end 130 | 131 | -------------------------------------------------------------------------------- /+MCmatlab/@model/private/MCmatlab.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/MCmatlab.mexa64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/MCmatlab.mexmaca64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/MCmatlab.mexmaca64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/MCmatlab.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/MCmatlab.mexmaci64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/MCmatlab.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/MCmatlab.mexw64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/MCmatlab_CUDA.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/MCmatlab_CUDA.mexw64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/MCmatlab_singlethreaded.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/MCmatlab_singlethreaded.mexa64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/cudart64_101.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/cudart64_101.dll -------------------------------------------------------------------------------- /+MCmatlab/@model/private/finiteElementHeatPropagator.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/finiteElementHeatPropagator.mexa64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/finiteElementHeatPropagator.mexmaca64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/finiteElementHeatPropagator.mexmaca64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/finiteElementHeatPropagator.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/finiteElementHeatPropagator.mexmaci64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/finiteElementHeatPropagator.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/finiteElementHeatPropagator.mexw64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/finiteElementHeatPropagator_CUDA.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/finiteElementHeatPropagator_CUDA.mexw64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/finiteElementHeatPropagator_singlethreaded.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/finiteElementHeatPropagator_singlethreaded.mexa64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/getDownsampledParamVals.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/getDownsampledParamVals.mexa64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/getDownsampledParamVals.mexmaca64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/getDownsampledParamVals.mexmaca64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/getDownsampledParamVals.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/getDownsampledParamVals.mexmaci64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/getDownsampledParamVals.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/getDownsampledParamVals.mexw64 -------------------------------------------------------------------------------- /+MCmatlab/@model/private/getThermalMediaProperties.m: -------------------------------------------------------------------------------- 1 | function model = getThermalMediaProperties(model) 2 | % Returns the reduced medium matrix, using only numbers from 1 up to the number of used media, and 3 | % the known media properties (optical, thermal and/or fluorescence) at the specified wavelength. 4 | % 5 | % See also mediaPropertiesLibrary 6 | 7 | %%%%% 8 | % Copyright 2017, 2018 by Dominik Marti and Anders K. Hansen, DTU Fotonik 9 | % This function was inspired by makeTissueList.m of the mcxyz program hosted at omlc.org 10 | % 11 | % This file is part of MCmatlab. 12 | % 13 | % MCmatlab is free software: you can redistribute it and/or modify 14 | % it under the terms of the GNU General Public License as published by 15 | % the Free Software Foundation, either version 3 of the License, or 16 | % (at your option) any later version. 17 | % 18 | % MCmatlab is distributed in the hope that it will be useful, 19 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | % GNU General Public License for more details. 22 | % 23 | % You should have received a copy of the GNU General Public License 24 | % along with MCmatlab. If not, see . 25 | %%%%% 26 | 27 | G = model.G; 28 | mP_fH = G.mediaPropertiesFunc(G.mediaPropParams); 29 | [uniqueMedia,~,M_trim] = unique(G.M_raw); 30 | M_trim = reshape(M_trim,model.G.nx,model.G.ny,model.G.nz); 31 | mP_fHtrim = mP_fH(uniqueMedia); 32 | nM = numel(mP_fHtrim); 33 | if numel(unique({mP_fHtrim.name})) ~= nM 34 | error('Error: Two media have the same name.'); 35 | end 36 | 37 | T = model.HS.T; 38 | 39 | FD = NaN([G.nx G.ny G.nz],'single'); 40 | FD(:) = 1 - exp(-model.HS.Omega); % Fractional damage of molecules/cells. model.HS.Omega may be scalar 0 or 3D 41 | 42 | %% Loop through different media and split if it has a dependence on T 43 | nSMtotal = 0; 44 | for iM = 1:nM 45 | nSMtotal = nSMtotal + mP_fHtrim(iM).nBins; 46 | end 47 | if nSMtotal > 256 48 | error('Error: The total number of (sub-)media may not exceed 256'); 49 | end 50 | mP = struct(); 51 | mP.name = cell(nSMtotal,1); 52 | mP.VHC = NaN(nSMtotal,1); 53 | mP.TC = NaN(nSMtotal,1); 54 | mP.A = NaN(nSMtotal,1); 55 | mP.E = NaN(nSMtotal,1); 56 | 57 | VHC3D = NaN(G.nx, G.ny, G.nz, 'single'); 58 | TC3D = NaN(G.nx, G.ny, G.nz, 'single'); 59 | M = zeros(size(M_trim),'uint8'); 60 | iSM = 1; % Position in mediaProperties 61 | for iM=1:nM 62 | idxs3D = M_trim(:) == iM; 63 | try VHC3D(idxs3D) = mP_fHtrim(iM).VHC(T(idxs3D),FD(idxs3D)); 64 | catch; error('Error: The VHC function of medium %s is throwing an error. If you have specified the function with two input arguments, it must be able to accept both arguments (temperature T and fractional damage FD) as 3D arrays. Therefore, remember to use element-wise arithmetic operators (.* instead of *, ./ instead of / etc.)',mP_fHtrim(iM).name); 65 | end 66 | try TC3D(idxs3D) = mP_fHtrim(iM).TC(T(idxs3D),FD(idxs3D)); 67 | catch; error('Error: The TC function of medium %s is throwing an error. If you have specified the function with two input arguments, it must be able to accept both arguments (temperature T and fractional damage FD) as 3D arrays. Therefore, remember to use element-wise arithmetic operators (.* instead of *, ./ instead of / etc.)',mP_fHtrim(iM).name); 68 | end 69 | if any(~isfinite(VHC3D(idxs3D))) || any(VHC3D(:) <= 0) 70 | error('The VHC function of medium %s returns values that are not finite and positive.',mP_fHtrim(iM).name); 71 | elseif any(~isfinite(TC3D(idxs3D))) || any(TC3D(:) <= 0) 72 | error('The TC function of medium %s returns values that are not finite and positive.',mP_fHtrim(iM).name); 73 | end 74 | 75 | paramVals = NaN(3,sum(M_trim(:) == iM),'single'); % Number of columns is number of voxels with this medium, and rows are (VHC, YC, 1) 76 | paramVals(1,:) = VHC3D(idxs3D); 77 | paramVals(2,:) = TC3D(idxs3D); 78 | paramVals(3,:) = 1; 79 | nSM = mP_fHtrim(iM).nBins; % Number of sub-media to split the iM'th medium into 80 | [downsampledParamVals,binidx] = getDownsampledParamVals(paramVals,nSM); 81 | [~,sortidx] = sortrows(downsampledParamVals.'); 82 | downsampledParamVals = downsampledParamVals(:,sortidx.'); % Sort the downsampled parameter values 83 | I_rev = zeros(nSM,1); 84 | I_rev(sortidx) = 1:nSM; 85 | binidx = I_rev(binidx); % binidx is rearranged according to the same sort 86 | 87 | M(idxs3D) = iSM + binidx - 1; 88 | mP.name(iSM:iSM+nSM-1) = {deal(mP_fHtrim(iM).name)}; 89 | mP.VHC (iSM:iSM+nSM-1) = double(downsampledParamVals(1,:)); 90 | mP.TC (iSM:iSM+nSM-1) = double(downsampledParamVals(2,:)); 91 | mP.A (iSM:iSM+nSM-1) = deal(mP_fHtrim(iM).A); 92 | mP.E (iSM:iSM+nSM-1) = deal(mP_fHtrim(iM).E); 93 | iSM = iSM + nSM; 94 | end 95 | 96 | model.HS.mediaProperties = mP; 97 | model.HS.M = M; 98 | end -------------------------------------------------------------------------------- /+MCmatlab/@model/private/libgomp_64-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/private/libgomp_64-1.dll -------------------------------------------------------------------------------- /+MCmatlab/@model/private/makec2f.m: -------------------------------------------------------------------------------- 1 | function c2 = makec2f 2 | 3 | % makecolormap.m 4 | 5 | % ----> c3(64,3) 6 | % red 7 | % yellow 8 | % black 9 | % cyan 10 | % blue 11 | c2 = zeros(64,3); 12 | 13 | % for ii=1:10 % black to grey 14 | % c2(ii,1) = 0.1 + 0.4*ii/10; % red 15 | % c2(ii,2) = 0.1 + 0.4*ii/10; % green 16 | % c2(ii,3) = 0.1 + 0.4*ii/10; % blue 17 | % end 18 | for ii=1:10 % black to grey 19 | c2(ii,1) = 0.0 + 0.5*ii/10; % red 20 | c2(ii,2) = 0.0 + 0.5*ii/10; % green 21 | c2(ii,3) = 0.0 + 0.5*ii/10; % blue 22 | end 23 | for ii=11:20 % grey to blue 24 | c2(ii,1) = 0.5*(1-(ii-10)/10); % red 25 | c2(ii,2) = 0.5*(1-(ii-10)/10); % green 26 | c2(ii,3) = 0.5 + 0.5*(ii-10)/10; % blue 27 | end 28 | a = 21; b = 32; 29 | for ii=a:b % blue to cyan 30 | c2(ii,1) = 0; 31 | c2(ii,2) = (ii-a+1)/(b-a+1); 32 | c2(ii,3) = 1; 33 | end 34 | % a = 29; b = 32; 35 | % for ii=a:b % cyan 36 | % c2(ii,1) = 0; 37 | % c2(ii,2) = 1; 38 | % c2(ii,3) = 1; 39 | % end 40 | % a = 33; b = 37; 41 | % for ii=a:b % cyan to green 42 | % c2(ii,1) = 0; 43 | % c2(ii,2) = 1; 44 | % c2(ii,3) = 1 - (ii-a+1)/(b-a+1); 45 | % end 46 | a = 33; b = 45; 47 | for ii=a:b % green to yellow 48 | c2(ii,1) = (ii-a+1)/(b-a+1); 49 | c2(ii,2) = 1; 50 | c2(ii,3) = 0; 51 | end 52 | a = 46; b = 53; 53 | for ii=a:b % yellow 54 | c2(ii,1) = 1; 55 | c2(ii,2) = 1; 56 | c2(ii,3) = 0; 57 | end 58 | a = 54; b = 64; 59 | for ii=a:b % yellow to red 60 | c2(ii,1) = 1; 61 | c2(ii,2) = 1 - (ii-a+1)/(b-a+1); 62 | c2(ii,3) = 0; 63 | end 64 | -------------------------------------------------------------------------------- /+MCmatlab/@model/private/plotFarField.m: -------------------------------------------------------------------------------- 1 | function [h_f,h_a] = plotFarField(nFig,axisValues,data,axisLabels) 2 | % arguments 3 | % nFig (1,1) double {mustBeInteger} % An integer denoting which figure number to make the plot in 4 | % axisValues (1,:) cell % A (1,N) cell array, each element containing a 1D array of the values of the independent variable, excluding the far field angles theta and phi. 5 | % data % An N+2 dimensional array of the values of the dependent variable, where the first two dimensions correspond to theta and phi angles. 6 | % axisLabels (1,:) cell % A (1,N) cell array, each element containing the label of one dimension. 7 | % end 8 | 9 | %% Convert data to single precision to reduce memory footprint 10 | data = single(data); 11 | 12 | %% Find out which dimensions are non-singleton, which correspond to axes in the figure, and which are slider dimensions 13 | nD = find(size(data) > 1,1,'last'); % Number of dimensions in data (not counting trailing singleton dimensions, because MATLAB automatically cuts them off) 14 | NonSiDims = find(size(data) > 1); % Indices of non-singleton dimensions 15 | nNonSi = numel(NonSiDims); % Number of non-singleton dimensions in data 16 | AxDims = [1 2]; 17 | nAx = numel(AxDims); % Number of (independent variable) axes to use in the figure 18 | 19 | if isempty(data) 20 | error('Error: Input array is empty') 21 | elseif isscalar(data) 22 | error('Error: Input array is a scalar') 23 | elseif isvector(data) 24 | error('Error: Input array is 1D'); 25 | elseif numel(axisLabels) < nD - 2 26 | error('Error: Not enough axis labels specified.'); 27 | elseif numel(axisValues) < nD - 2 28 | error('Error: Not enough axis value arrays specified'); 29 | end 30 | 31 | nSl = nNonSi - nAx; % Number of sliders needed 32 | nNonSl = nNonSi - nSl; % Number of non-slider non-singleton dimensions 33 | 34 | %% Permute the data array 35 | % We will place the axis dimensions first, then the non-singleton 36 | % dimensions and finally the singleton dimensions, which will 37 | % subsequently automatically be discarded by MATLAB. The permuted array 38 | % therefore has no singleton dimensions. 39 | permuteDimOrder = [AxDims setdiff(NonSiDims,AxDims) setdiff(1:nD,NonSiDims)]; 40 | data = permute(data,permuteDimOrder); 41 | axisValues = axisValues(permuteDimOrder(3:nNonSi)-2); 42 | axisLabels = axisLabels(permuteDimOrder(3:nNonSi)-2); 43 | 44 | %% Create figure and put in the necessary uicontrols such as sliders 45 | h_f = figure(nFig); 46 | set(h_f,'WindowStyle','Docked'); 47 | clf reset; 48 | h_f.Color = 'w'; 49 | h_a = axes; 50 | 51 | h_sliders = gobjects(1,nSl); 52 | h_centerbuttons = gobjects(1,nSl); 53 | h_slidertexts = gobjects(1,nSl); 54 | subscriptIdxs = cell(1,nNonSi); 55 | for iD = 1:nNonSl % For all non-slider dimensions 56 | subscriptIdxs{iD} = 1:size(data,iD); 57 | end 58 | for iSl = 1:nSl % For all slider dimensions 59 | iD = iSl + nNonSl; 60 | n = size(data,iD); % Size of the dimension 61 | i = round(n/2); 62 | h_centerbuttons(iSl) = uicontrol('Parent',h_f,'Style','pushbutton','String','Center','Position',[10,iSl*20-10,40,20]); 63 | warning('off','MATLAB:hg:UIControlSliderStepValueDifference'); 64 | h_sliders(iSl) = uicontrol('Parent',h_f,'Style','slider','Position',[55,iSl*20-10,100,20],... 65 | 'value',i, 'min',1, 'max',n,'SliderStep',[1/(n-1) max(1/(n-1),0.1)]); 66 | warning('on','MATLAB:hg:UIControlSliderStepValueDifference'); 67 | string = [axisLabels{iSl} ' = ' num2str(axisValues{iSl}(i),'%.3g')]; 68 | h_slidertexts(iSl) = uicontrol('style','text','String',string,... 69 | 'horizontalAlignment','left','BackgroundColor','w','Position',[160,7 + (iSl-1)*20,5.5*numel(string),20]); 70 | subscriptIdxs{iD} = i; 71 | end 72 | h_checkbox = uicontrol('Parent',h_f,'Style','checkbox','String','log plot','BackgroundColor','w','Position',[10,nSl*20 + 13,55,20]); 73 | 74 | %% Do the plotting 75 | nFF = size(data,1); 76 | theta_vec = linspace(0,pi,nFF+1).'; % MCorFMC.farFieldTheta contains the theta values at the centers of the far field pixels, but we will not use those here since we need the corner positions to calculate the solid angle of the pixels 77 | solidAngle_vec = 2*pi*(cos(theta_vec(1:end-1)) - cos(theta_vec(2:end)))/nFF; % Solid angle extended by each far field pixel, as function of theta 78 | [ux,uy,minus_uz] = sphere(nFF); % This MATLAB function gives us the correct ux,uy,uz coordinates of the corners of the far field pixels, except that uz has the wrong sign 79 | uz = -minus_uz; 80 | sizes = num2cell(size(data)); 81 | data = data./repmat(solidAngle_vec,1,sizes{2:end}); 82 | data(1 ,:,:) = repelem(mean(data(1 ,:,:)),nFF,1); 83 | data(end,:,:) = repelem(mean(data(end,:,:)),nFF,1); 84 | maxelement = max(data(:)); 85 | if maxelement == 0 86 | maxelement = 1; 87 | end 88 | h_f.UserData = data; 89 | 90 | h_2D = surf(ux,uy,uz,h_f.UserData(subscriptIdxs{:}),'EdgeColor','none'); 91 | xlabel('u_x'); 92 | ylabel('u_y'); 93 | zlabel('u_z'); 94 | h_a.DataAspectRatio = [1 1 1]; 95 | h_a.ZDir = 'reverse'; 96 | colorbar; 97 | caxis([0 maxelement]); 98 | 99 | linColormap = inferno; 100 | logColormap = makec2f; 101 | colormap(linColormap); 102 | rotate3d on 103 | setAxes3DPanAndZoomStyle(zoom(gca),gca,'camera'); 104 | set(gca,'fontsize',18); 105 | 106 | vars = struct('h_2D',h_2D,... 107 | 'h_centerbuttons',h_centerbuttons,... 108 | 'h_sliders',h_sliders,'h_slidertexts',h_slidertexts, ... 109 | 'h_checkbox',h_checkbox,'linColormap',linColormap,... 110 | 'logColormap',logColormap,'axisValues',{axisValues},... 111 | 'axisLabels',{axisLabels},'maxelement',maxelement); 112 | 113 | set([h_centerbuttons h_sliders h_checkbox],'Callback',{@redrawFarField,vars}); 114 | end -------------------------------------------------------------------------------- /+MCmatlab/@model/private/redrawCuboidSurfaces.m: -------------------------------------------------------------------------------- 1 | function redrawCuboidSurfaces(src,~,v) 2 | lambdatext = [955 ' [nm]']; % The 955 is the unicode number for the lambda character. Because the editors of MATLAB versions prior to 2020a do not support unicode, we have to make the lambda in this sneaky way. 3 | 4 | if src == v.h_centerbutton 5 | set(v.h_slider,'Value',(numel(v.l)-1)/2 + 1); 6 | end 7 | 8 | plotLog = get(v.h_checkbox,'Value'); 9 | lsi = floor(get(v.h_slider,'Value')); % lambda slice index 10 | ls = v.l(lsi); 11 | string = [lambdatext ' = ' num2str(ls,'%.3g')]; 12 | 13 | v.h_slidertext.String = string; 14 | prevpos = get(v.h_slidertext,'Position'); 15 | newpos = [prevpos(1:2) 5.5*numel(string) prevpos(4)]; 16 | set(v.h_slidertext,'Position',newpos); 17 | 18 | h_f = get(v.h_checkbox,'Parent'); 19 | 20 | if plotLog 21 | colormap(makec2f); 22 | maxelement = log10(max(max(max([h_f.UserData{:}])))); 23 | if(isfinite(maxelement)) 24 | caxisvec = [maxelement-4 maxelement]; 25 | else 26 | caxisvec = [-3 1]; 27 | end 28 | if ishandle(v.h_xneg) 29 | v.h_xneg.CData = squeeze(log10(h_f.UserData{1}(:,:,lsi))); 30 | v.h_xneg.Parent.CLim = caxisvec; 31 | end 32 | if ishandle(v.h_yneg) 33 | v.h_yneg.CData = squeeze(log10(h_f.UserData{2}(:,:,lsi))); 34 | v.h_yneg.Parent.CLim = caxisvec; 35 | end 36 | if ishandle(v.h_zneg) 37 | v.h_zneg.CData = squeeze(log10(h_f.UserData{3}(:,:,lsi))); 38 | v.h_zneg.Parent.CLim = caxisvec; 39 | end 40 | if ishandle(v.h_xpos) 41 | v.h_xpos.CData = squeeze(log10(h_f.UserData{4}(:,:,lsi))); 42 | v.h_xpos.Parent.CLim = caxisvec; 43 | end 44 | if ishandle(v.h_ypos) 45 | v.h_ypos.CData = squeeze(log10(h_f.UserData{5}(:,:,lsi))); 46 | v.h_ypos.Parent.CLim = caxisvec; 47 | end 48 | if ishandle(v.h_zpos) 49 | v.h_zpos.CData = squeeze(log10(h_f.UserData{6}(:,:,lsi))); 50 | v.h_zpos.Parent.CLim = caxisvec; 51 | end 52 | else 53 | colormap(v.linearColormap); 54 | maxelement = max(max(max([h_f.UserData{:}]))); 55 | caxisvec = [0 maxelement]; 56 | if ishandle(v.h_xneg) 57 | v.h_xneg.CData = squeeze(h_f.UserData{1}(:,:,lsi)); 58 | v.h_xneg.Parent.CLim = caxisvec; 59 | end 60 | if ishandle(v.h_yneg) 61 | v.h_yneg.CData = squeeze(h_f.UserData{2}(:,:,lsi)); 62 | v.h_yneg.Parent.CLim = caxisvec; 63 | end 64 | if ishandle(v.h_zneg) 65 | v.h_zneg.CData = squeeze(h_f.UserData{3}(:,:,lsi)); 66 | v.h_zneg.Parent.CLim = caxisvec; 67 | end 68 | if ishandle(v.h_xpos) 69 | v.h_xpos.CData = squeeze(h_f.UserData{4}(:,:,lsi)); 70 | v.h_xpos.Parent.CLim = caxisvec; 71 | end 72 | if ishandle(v.h_ypos) 73 | v.h_ypos.CData = squeeze(h_f.UserData{5}(:,:,lsi)); 74 | v.h_ypos.Parent.CLim = caxisvec; 75 | end 76 | if ishandle(v.h_zpos) 77 | v.h_zpos.CData = squeeze(h_f.UserData{6}(:,:,lsi)); 78 | v.h_zpos.Parent.CLim = caxisvec; 79 | end 80 | end 81 | 82 | drawnow; 83 | return 84 | -------------------------------------------------------------------------------- /+MCmatlab/@model/private/redrawFarField.m: -------------------------------------------------------------------------------- 1 | function redrawFarField(src,~,v) 2 | h_f = gcbf; 3 | nSl = numel(v.h_sliders); 4 | nNonSi = find(size(h_f.UserData) > 1,1,'last'); 5 | nNonSl = nNonSi - nSl; 6 | 7 | %% Set slider if source was one of the center buttons 8 | for iSl = find(src == v.h_centerbuttons) 9 | set(v.h_sliders(iSl),'Value',(numel(v.axisValues{iSl})-1)/2 + 1); 10 | end 11 | 12 | %% Set text if source was one of the sliders or center buttons 13 | for iSl = [find(src == v.h_sliders) find(src == v.h_centerbuttons)] 14 | string = [v.axisLabels{iSl} ' = ' num2str(v.axisValues{iSl}(floor(get(v.h_sliders(iSl),'Value'))),'%.3g')]; 15 | set(v.h_slidertexts(iSl),'String',string); 16 | prevpos = get(v.h_slidertexts(iSl),'Position'); 17 | newpos = [prevpos(1:2) 5.5*numel(string) prevpos(4)]; 18 | set(v.h_slidertexts(iSl),'Position',newpos); 19 | end 20 | 21 | %% Calculate new set of subscript indices to plot 22 | subscriptIdxs = cell(1,nNonSi); 23 | for iD = 1:nNonSl % For all non-slider dimensions 24 | subscriptIdxs{iD} = 1:size(h_f.UserData,iD); 25 | end 26 | for iSl = 1:nSl % For all slider dimensions 27 | iD = iSl + nNonSl; 28 | subscriptIdxs{iD} = floor(get(v.h_sliders(iSl),'Value')); 29 | end 30 | 31 | %% Update plot 32 | h_ax = v.h_2D.Parent; 33 | v.h_2D.CData = h_f.UserData(subscriptIdxs{:}); 34 | if v.h_checkbox.Value 35 | h_ax.ColorScale = 'log'; 36 | caxis(h_ax,[v.maxelement/10000 v.maxelement]); 37 | colormap(v.logColormap); 38 | else 39 | h_ax.ColorScale = 'lin'; 40 | caxis(h_ax,[0 v.maxelement]); 41 | colormap(v.linColormap); 42 | end 43 | 44 | drawnow; 45 | end 46 | -------------------------------------------------------------------------------- /+MCmatlab/@model/private/smoothn license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2020, Damien Garcia 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution 13 | * Neither the name of CREATIS, Lyon, France nor the names of its 14 | contributors may be used to endorse or promote products derived from this 15 | software without specific prior written permission. 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /+MCmatlab/@model/simulateHeatDistribution.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/@model/simulateHeatDistribution.m -------------------------------------------------------------------------------- /+MCmatlab/@sourceIntensityDistribution/sourceIntensityDistribution.m: -------------------------------------------------------------------------------- 1 | classdef sourceIntensityDistribution 2 | % sourceIntensityDistribution Summary of this class goes here 3 | % Detailed explanation goes here 4 | 5 | properties 6 | radialDistr (1,:) double {mustBe012OrNaNOrNonnegativeArray} = NaN % Radial near or far field distribution - 0: Top-hat, 1: Gaussian, 2: Cosine (Lambertian), Array: Custom. Doesn't need to be normalized. 7 | radialWidth (1,1) double {mustBeNonnegativeOrNaN} = NaN % [cm] Radial near field 1/e^2 radius if top-hat or Gaussian or half-width of the full distribution if custom 8 | % [rad] Radial far field 1/e^2 half-angle if top-hat or Gaussian or half-angle of the full distribution if custom. For a diffraction limited Gaussian beam, this should be set to model.MC.wavelength*1e-9/(pi*model.MC.beam.NF.radialWidth*1e-2)) 9 | XDistr (1,:) double {mustBe012OrNaNOrNonnegativeArray} = NaN % X near or far field distribution - 0: Top-hat, 1: Gaussian, 2: Cosine (Lambertian), Array: Custom. Doesn't need to be normalized. 10 | XWidth (1,1) double {mustBeNonnegativeOrNaN} = NaN % [cm] X near field 1/e^2 radius if top-hat or Gaussian or half-width of the full distribution if custom 11 | % [rad] X far field 1/e^2 half-angle if top-hat or Gaussian or half-angle of the full distribution if custom 12 | YDistr (1,:) double {mustBe012OrNaNOrNonnegativeArray} = NaN % Y near or far field distribution - 0: Top-hat, 1: Gaussian, 2: Cosine (Lambertian), Array: Custom. Doesn't need to be normalized. 13 | YWidth (1,1) double {mustBeNonnegativeOrNaN} = NaN % [cm] Y near field 1/e^2 radius if top-hat or Gaussian or half-width of the full distribution if custom 14 | % [rad] Y far field 1/e^2 half-angle if top-hat or Gaussian or half-angle of the full distribution if custom 15 | end 16 | 17 | methods 18 | 19 | end 20 | end 21 | 22 | function mustBe012OrNaNOrNonnegativeArray(x) 23 | x = x(:); 24 | if isscalar(x) 25 | if (x == 0) || (x == 1) || (x == 2) || isnan(x) 26 | % Input valid 27 | else 28 | error('Value must be either 0, 1, 2, NaN, or an array.'); 29 | end 30 | elseif isvector(x) 31 | if all(isfinite(x)) && all(x >= 0) 32 | % Input valid 33 | else 34 | error('Array must contain only finite, nonnegative numbers.'); 35 | end 36 | end 37 | end 38 | 39 | function mustBeNonnegativeOrNaN(x) 40 | x = x(:); 41 | if ~any(isnan(x)) && (~any(isfinite(x)) || any(x < 0)) 42 | error('Value must be nonnegative or NaN.'); 43 | end 44 | end -------------------------------------------------------------------------------- /+MCmatlab/NdimSliderPlotRedraw.m: -------------------------------------------------------------------------------- 1 | function NdimSliderPlotRedraw(src,~,v) 2 | h_f = src.Parent; 3 | nSl = numel(v.h_sliders); 4 | nNonSi = find(size(h_f.UserData) > 1,1,'last'); 5 | nNonSl = nNonSi - nSl; 6 | if nNonSl == 0 7 | nAx = 3; 8 | else 9 | nAx = nNonSl; 10 | end 11 | 12 | %% Set slider if source was one of the center buttons 13 | for iSl = find(src == v.h_centerbuttons) 14 | iD = iSl + nNonSl; 15 | set(v.h_sliders(iSl),'Value',(numel(v.axisValues{iD})-1)/2 + 1); 16 | end 17 | 18 | %% Set text if source was one of the sliders or center buttons 19 | for iSl = [find(src == v.h_sliders) find(src == v.h_centerbuttons)] 20 | iD = iSl + nNonSl; 21 | string = [v.axisLabels{iD} ' = ' num2str(v.axisValues{iD}(floor(get(v.h_sliders(iSl),'Value'))),'%.3g')]; 22 | set(v.h_slidertexts(iSl),'String',string); 23 | prevpos = get(v.h_slidertexts(iSl),'Position'); 24 | newpos = [prevpos(1:2) 5.5*numel(string) prevpos(4)]; 25 | set(v.h_slidertexts(iSl),'Position',newpos); 26 | end 27 | 28 | %% Calculate new set of subscript indices to plot 29 | subscriptIdxs = cell(1,nNonSi); 30 | for iD = 1:nNonSl % For all non-slider dimensions 31 | subscriptIdxs{iD} = 1:size(h_f.UserData,iD); 32 | end 33 | for iSl = 1:nSl % For all slider dimensions 34 | iD = iSl + nNonSl; 35 | subscriptIdxs{iD} = floor(get(v.h_sliders(iSl),'Value')); 36 | end 37 | 38 | %% Calculate plot limits 39 | if ~isnan(v.plotLimits(1)) 40 | plotLimLower = v.plotLimits(1); 41 | else 42 | plotLimLower = min(h_f.UserData(:)); 43 | end 44 | if ~isnan(v.plotLimits(2)) 45 | plotLimUpper = v.plotLimits(2); 46 | else 47 | plotLimUpper = max(h_f.UserData(:)); 48 | end 49 | if plotLimUpper <= plotLimLower 50 | plotLimUpper = plotLimLower + 1; 51 | end 52 | 53 | %% Update plot 54 | switch nAx 55 | case 1 56 | h_ax = v.h_1D.Parent; 57 | v.h_1D.YData = h_f.UserData(subscriptIdxs{:}); 58 | if v.h_checkbox.Value 59 | h_ax.YScale = 'log'; 60 | ylim(h_ax,[plotLimUpper/10000 plotLimUpper]); 61 | else 62 | h_ax.YScale = 'lin'; 63 | ylim(h_ax,[plotLimLower plotLimUpper]); 64 | end 65 | case 2 66 | h_ax = v.h_2D.Parent; 67 | if isgraphics(v.h_2D,'Image') 68 | v.h_2D.CData = h_f.UserData(subscriptIdxs{:}).'; 69 | else 70 | v.h_2D.CData = h_f.UserData(subscriptIdxs{:}); 71 | end 72 | if v.h_checkbox.Visible 73 | if v.h_checkbox.Value 74 | h_ax.ColorScale = 'log'; 75 | caxis(h_ax,[plotLimUpper/10000 plotLimUpper]); 76 | colormap(v.logColormap); 77 | else 78 | h_ax.ColorScale = 'lin'; 79 | caxis(h_ax,[plotLimLower plotLimUpper]); 80 | colormap(v.linColormap); 81 | end 82 | end 83 | case 3 84 | h_ax = v.h_surfxslice.Parent; 85 | [nx,ny,nz,~] = size(h_f.UserData); 86 | xl = v.x(1); % x low 87 | xh = v.x(end); % x high 88 | yl = v.y(1); % y low 89 | yh = v.y(end); % y high 90 | zl = v.z(1); % z low 91 | zh = v.z(end); % z high 92 | [xsi,ysi,zsi] = subscriptIdxs{1:3}; 93 | xs = v.x(xsi); ys = v.y(ysi); zs = v.z(zsi); 94 | if ismember(src,[v.h_sliders(1) v.h_centerbuttons(1)]) 95 | set(v.h_surfxslice,'XData',xs*ones(ny,nz)); 96 | set(v.h_xline,'XData',[xs xs xs xs xs xs xs]); 97 | set(v.h_zline,'XData',[xs xh xh xl xl xs xs]); 98 | end 99 | if ismember(src,[v.h_sliders(2) v.h_centerbuttons(2)]) 100 | set(v.h_surfyslice,'YData',ys*ones(nx,nz)); 101 | set(v.h_yline,'YData',[ys ys ys ys ys ys ys]); 102 | set(v.h_xline,'YData',[ys yh yh yl yl ys ys]); 103 | end 104 | if ismember(src,[v.h_sliders(3) v.h_centerbuttons(3)]) 105 | set(v.h_surfzslice,'ZData',zs*ones(nx,ny)); 106 | set(v.h_zline,'ZData',[zs zs zs zs zs zs zs]); 107 | set(v.h_yline,'ZData',[zs zh zh zl zl zs zs]); 108 | end 109 | if ismember(src,[v.h_sliders([1 4:end]) v.h_centerbuttons([1 4:end])]) 110 | set(v.h_surfxslice,'CData',squeeze(h_f.UserData(xsi,:,:,subscriptIdxs{4:end}))); 111 | end 112 | if ismember(src,[v.h_sliders([2 4:end]) v.h_centerbuttons([2 4:end])]) 113 | set(v.h_surfyslice,'CData',squeeze(h_f.UserData(:,ysi,:,subscriptIdxs{4:end}))); 114 | end 115 | if ismember(src,[v.h_sliders([3 4:end]) v.h_centerbuttons([3 4:end])]) 116 | set(v.h_surfzslice,'CData',squeeze(h_f.UserData(:,:,zsi,subscriptIdxs{4:end}))); 117 | end 118 | if ismember(src,[v.h_sliders(4:end) v.h_centerbuttons(4:end)]) 119 | set(v.h_surfxback,'CData',squeeze(h_f.UserData(v.xbi,:,:,subscriptIdxs{4:end}))); 120 | set(v.h_surfyback,'CData',squeeze(h_f.UserData(:,v.ybi,:,subscriptIdxs{4:end}))); 121 | set(v.h_surfzback,'CData',squeeze(h_f.UserData(:,:,v.zbi,subscriptIdxs{4:end}))); 122 | end 123 | if v.h_checkbox.Visible 124 | if v.h_checkbox.Value 125 | h_ax.ColorScale = 'log'; 126 | caxis(h_ax,[plotLimUpper/10000 plotLimUpper]); 127 | colormap(v.logColormap); 128 | else 129 | h_ax.ColorScale = 'lin'; 130 | caxis(h_ax,[plotLimLower plotLimUpper]); 131 | colormap(v.linColormap); 132 | end 133 | end 134 | end 135 | drawnow; 136 | end 137 | -------------------------------------------------------------------------------- /+MCmatlab/closeMCmatlabFigures.m: -------------------------------------------------------------------------------- 1 | function closeMCmatlabFigures() 2 | allFigs = findall(groot,'type','figure'); 3 | for iF = 1:numel(allFigs) 4 | if ismember(allFigs(iF).Name,... 5 | {'Geometry illustration',... 6 | 'Media properties',... 7 | 'Normalized absorption',... 8 | 'Normalized fluence rate',... 9 | 'Photon paths',... % 5 10 | 'Light collector illustration',... 11 | 'Emitters',... 12 | 'Collected light',... 13 | 'Far field',... 14 | 'Normalized boundary irradiance',... % 10 15 | 'Fluorescence emitters',... 16 | ... 17 | 'Normalized fluorescence absorption',... 18 | 'Normalized fluorescence fluence rate',... 19 | 'Fluorescence photon paths',... % 15 20 | 'Fluorescence light collector illustration',... 21 | 'Normalized fluence rate of collected fluorescence light',... 22 | 'Collected fluorescence light',... 23 | 'Fluorescence far field',... 24 | 'Normalized fluorescence boundary irradiance',... % 20 25 | 'Temperature evolution',... 26 | ... 27 | 'Temperature sensor illustration',... 28 | 'Temperature sensor data',... 29 | 'Thermal damage illustration',... % 25 30 | 'Fractional damage',... 31 | 'STL wireframes'}) 32 | close(allFigs(iF)); 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /+MCmatlab/makec2f.m: -------------------------------------------------------------------------------- 1 | function c2 = makec2f 2 | 3 | % makecolormap.m 4 | 5 | % ----> c3(64,3) 6 | % red 7 | % yellow 8 | % black 9 | % cyan 10 | % blue 11 | c2 = zeros(64,3); 12 | 13 | % for ii=1:10 % black to grey 14 | % c2(ii,1) = 0.1 + 0.4*ii/10; % red 15 | % c2(ii,2) = 0.1 + 0.4*ii/10; % green 16 | % c2(ii,3) = 0.1 + 0.4*ii/10; % blue 17 | % end 18 | for ii=1:10 % black to grey 19 | c2(ii,1) = 0.0 + 0.5*ii/10; % red 20 | c2(ii,2) = 0.0 + 0.5*ii/10; % green 21 | c2(ii,3) = 0.0 + 0.5*ii/10; % blue 22 | end 23 | for ii=11:20 % grey to blue 24 | c2(ii,1) = 0.5*(1-(ii-10)/10); % red 25 | c2(ii,2) = 0.5*(1-(ii-10)/10); % green 26 | c2(ii,3) = 0.5 + 0.5*(ii-10)/10; % blue 27 | end 28 | a = 21; b = 32; 29 | for ii=a:b % blue to cyan 30 | c2(ii,1) = 0; 31 | c2(ii,2) = (ii-a+1)/(b-a+1); 32 | c2(ii,3) = 1; 33 | end 34 | % a = 29; b = 32; 35 | % for ii=a:b % cyan 36 | % c2(ii,1) = 0; 37 | % c2(ii,2) = 1; 38 | % c2(ii,3) = 1; 39 | % end 40 | % a = 33; b = 37; 41 | % for ii=a:b % cyan to green 42 | % c2(ii,1) = 0; 43 | % c2(ii,2) = 1; 44 | % c2(ii,3) = 1 - (ii-a+1)/(b-a+1); 45 | % end 46 | a = 33; b = 45; 47 | for ii=a:b % green to yellow 48 | c2(ii,1) = (ii-a+1)/(b-a+1); 49 | c2(ii,2) = 1; 50 | c2(ii,3) = 0; 51 | end 52 | a = 46; b = 53; 53 | for ii=a:b % yellow 54 | c2(ii,1) = 1; 55 | c2(ii,2) = 1; 56 | c2(ii,3) = 0; 57 | end 58 | a = 54; b = 64; 59 | for ii=a:b % yellow to red 60 | c2(ii,1) = 1; 61 | c2(ii,2) = 1 - (ii-a+1)/(b-a+1); 62 | c2(ii,3) = 0; 63 | end 64 | -------------------------------------------------------------------------------- /+MCmatlab/plotAzFz.m: -------------------------------------------------------------------------------- 1 | function plotAzFz(model) 2 | MCmatlab.NdimSliderPlot(model.G.dx*model.G.dy*sum(sum(model.MC.NA ,1),2),'nFig',41,'axisLabels',{'','','z [cm]','Az [cm^{-1}]'},'axisValues',{[],[],model.G.z}); 3 | MCmatlab.NdimSliderPlot(model.G.dx*model.G.dy*sum(sum(model.MC.NFR,1),2),'nFig',42,'axisLabels',{'','','z [cm]','Fz [-]'},'axisValues',{[],[],model.G.z}); 4 | end -------------------------------------------------------------------------------- /+MCmatlab/plotRadialReflectanceTransmittance.m: -------------------------------------------------------------------------------- 1 | function plotRadialReflectanceTransmittance(model) 2 | [X,Y] = ndgrid(model.G.x,model.G.y); 3 | R = sqrt(X.^2 + Y.^2); 4 | Runq = unique(R(:)); 5 | Refl = NaN(size(Runq)); 6 | Tran = NaN(size(Runq)); 7 | for i = 1:numel(Runq) 8 | Refl(i) = mean(model.MC.NI_zneg(R == Runq(i))); 9 | Tran(i) = mean(model.MC.NI_zpos(R == Runq(i))); 10 | end 11 | Refl = [flipud(Refl(Runq ~= 0)) ; Refl]; 12 | Tran = [flipud(Tran(Runq ~= 0)) ; Tran]; 13 | Runq = [-flipud(Runq(Runq ~= 0)) ; Runq]; 14 | MCmatlab.NdimSliderPlot(Refl,'nFig',43,'axisLabels',{'r [cm]','Reflectance [cm^{-2}]'},'axisValues',{Runq}); 15 | MCmatlab.NdimSliderPlot(Tran,'nFig',44,'axisLabels',{'r [cm]','Transmittance [cm^{-2}]'},'axisValues',{Runq}); 16 | end -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/CHANGE-LOG.txt: -------------------------------------------------------------------------------- 1 | ver 2.2.3 2 | ------- 3 | change Makefile for nmake 4 | 5 | ver 2.2.2 6 | ------- 7 | fix MSC 2012 compile error. 8 | 9 | ver 2.2.1 10 | ------- 11 | The code for ALTIVEC is changed, to fit to the ISA manual. 12 | This was reported by Tao Yao, thanks. 13 | 14 | ver 2.2.0 15 | ------- 16 | move do_recursion to dSFMT-common.h 17 | 18 | ver 2.1.1 19 | ------- 20 | The initialization of the constants for sse2 is changed. 21 | Old version may cause trouble in parallel environment like OpenMP. 22 | 23 | ver 2.1 24 | ------- 25 | This version supports the periods from 2^521-1 to 2^216091-1. 26 | We added new function dsfmt_genrand_uint32, which returns 32-bit 27 | unsigned integer. If you need many floating point pseudo random 28 | numbers and a few integers, you don't need to use another 29 | integer generator. 30 | 31 | ver 2.0 32 | ------- 33 | The recursion formula of dSFMT is changed. 34 | The supported periods are changed. 35 | The output sequences are completely changed. 36 | The generation speed is improved. 37 | The variable for initialization check is removed, because it causes 38 | an execution error in cygwin. 39 | 40 | ver 1.3.1 41 | ------- 42 | change dSFMT.h not to include dSFMT-params.h 43 | change Makefile to clean test files. 44 | 45 | ver 1.3 46 | ------- 47 | add `dsfmt_' prefix to functions. 48 | changed to structure base code. 49 | put Intel Compiler into silence. 50 | bug fix checking BIG_ENDIAN and BYTE_ORDER 51 | change test.c not to include dSFMT.c 52 | dSFMT-alti.h and dSFMT-sse2.h are marged into dSFMT.c 53 | 54 | ver 1.2.1 55 | ------- 56 | add #include to dSFMT.c 57 | 58 | ver 1.2 59 | ------- 60 | The precision specifier of printf was too large in test.c 61 | CAUTION! *.out.txt is changed. 62 | add dSFMT-params216091.h 63 | gcc compile option changed form -O9 to -O3. 64 | add AltiVec parameter format for systems which are not OSX. 65 | change Makefile for systems which are not OSX and support AltiVec. 66 | change sample2 of howto-compile for Free BSD. 67 | change period certification code more smart. 68 | change source files for BORLANDC and Visual Studio. 69 | 70 | ver 1.1.1 71 | ------- 72 | BUG in dSFMT-sse2.h is fixed. 73 | This bug didn't change the result. 74 | Change test.c 75 | 76 | ver 1.1 77 | ------- 78 | add dSFMT-params132049.h 79 | fix bug in period_certification. It's a bug but result is the same for 80 | all parameter files. 81 | change macro definition names and global variables. Thank you, Adam Piatyszek. 82 | remove L suffix from floating point constants. It's Saito's misunderstanding. 83 | fix bug of sfmt_idxof definition for BIG ENDIAN machine. 84 | 85 | ver 1.0.1 86 | ------- 87 | change name dSFMT-alti.c to SFMT-alti.h 88 | change name dSFMT-sse2.c to SFMT-sse2.h 89 | This version is not released. 90 | 91 | ver 1.0 92 | ------- 93 | The first version. 94 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/FILES.txt: -------------------------------------------------------------------------------- 1 | This archive contails following directories and files. 2 | 3 | TOP DIRECTORY 4 | FILES.txt: This file. 5 | CHANGE-LOG.txt change log. 6 | LICENSE.txt: License file. 7 | Makefile: Makefile for test programs. 8 | dSFMT.h: Header file. 9 | dSFMT-common.h: Header file. 10 | dSFMT-params.h: parameter file control for various Mersenne expornent 11 | dSFMT-params521.h: parameters for period of 2^{521}-1 12 | dSFMT-params1279.h: parameters for period of 2^{1279}-1 13 | dSFMT-params2203.h: parameters for period of 2^{2203}-1 14 | dSFMT-params4253.h: parameters for period of 2^{4253}-1 15 | dSFMT-params11213.h: parameters for period of 2^{11213}-1 16 | dSFMT-params19937.h: parameters for period of 2^{19937}-1 17 | dSFMT.c: C code for standard C (c99) and unix like systems. 18 | test.c: Test driver for standard C. 19 | check.sh: Test shell script. 20 | dSFMT.521.out.txt: correct output of dSFMT MEXP=521 21 | dSFMT.1279.out.txt: correct output of dSFMT MEXP=1279 22 | dSFMT.2203.out.txt: correct output of dSFMT MEXP=2203 23 | dSFMT.4253.out.txt: correct output of dSFMT MEXP=4253 24 | dSFMT.11213.out.txt: correct output of dSFMT MEXP=11213 25 | dSFMT.19937.out.txt: correct output of dSFMT MEXP=19937 26 | 27 | html DIRECTORY: The documents generated by doxygen. 28 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007, 2008, 2009 Mutsuo Saito, Makoto Matsumoto 2 | and Hiroshima University. 3 | Copyright (c) 2011, 2002 Mutsuo Saito, Makoto Matsumoto, Hiroshima 4 | University and The University of Tokyo. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above 14 | copyright notice, this list of conditions and the following 15 | disclaimer in the documentation and/or other materials provided 16 | with the distribution. 17 | * Neither the name of the Hiroshima University nor the names of 18 | its contributors may be used to endorse or promote products 19 | derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/README.jp.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/README.jp.txt -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/README.txt: -------------------------------------------------------------------------------- 1 | ================================================================= 2 | dSFMT ver. 2.2.1 3 | 2011.11.10 4 | 5 | double precision SIMD oriented Fast Mersenne Twister(dSFMT) 6 | based on IEEE 754 floating point format. 7 | 8 | Mutsuo Saito (Hiroshima University) and 9 | Makoto Matsumoto (Hiroshima University) 10 | 11 | Copyright (C) 2007, 2008, 2009 Mutsuo Saito, Makoto Matsumoto and 12 | Hiroshima University. 13 | Copyright (C) 2011, 2013 Mutsuo Saito, Makoto Matsumoto, Hiroshima 14 | University and The University of Tokyo. 15 | All rights reserved. 16 | 17 | The (modified) BSD License is applied to this software, see 18 | LICENSE.txt 19 | ================================================================= 20 | The documents written in English is the official one. 21 | 22 | dSFMT ver. 2.0 and ver. 2.1 are completely different from dSFMT ver 1.xx. 23 | The algorithm is changed. 24 | 25 | This program only works on systems which have IEEE754 floating point 26 | format. 27 | 28 | This version uses `struct' of C language. 29 | Don't use different DSFMT_MEXP for compiling dSFMT.c and your program. 30 | 31 | To see documents, see html/index.html. 32 | 33 | To make test program, see html/howto-compile.html. 34 | If your CPU is BIG ENDIAN and your compiler is not gcc, 35 | define DSFMT_BIG_ENDIAN preprocessor macro, please. 36 | 37 | If you want to redistribute and/or change source files, see LICENSE.txt. 38 | 39 | When you change these files and redistribute them, PLEASE write your 40 | e-mail address in redistribution and write to contact YOU first if 41 | users of your changed source encounter troubles. 42 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | prefix=$1 3 | tmp=tmp.$$ 4 | exps="521 1279 2203 4253 11213 19937 44497 86243 132049 216091" 5 | for mexp in $exps; do 6 | compare=dSFMT.${mexp}.out.txt 7 | command=${prefix}-M${mexp} 8 | ./$command -v > $tmp 9 | if diff -q -w $tmp $compare; then 10 | echo $command output check OK 11 | rm -f $tmp 12 | else 13 | echo $command output check NG! 14 | rm -f $tmp 15 | exit 1 16 | fi 17 | done 18 | exit 0 19 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /** 3 | * @file dSFMT-common.h 4 | * 5 | * @brief SIMD oriented Fast Mersenne Twister(SFMT) pseudorandom 6 | * number generator with jump function. This file includes common functions 7 | * used in random number generation and jump. 8 | * 9 | * @author Mutsuo Saito (Hiroshima University) 10 | * @author Makoto Matsumoto (The University of Tokyo) 11 | * 12 | * Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima 13 | * University. 14 | * Copyright (C) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima 15 | * University and The University of Tokyo. 16 | * All rights reserved. 17 | * 18 | * The 3-clause BSD License is applied to this software, see 19 | * LICENSE.txt 20 | */ 21 | #ifndef DSFMT_COMMON_H 22 | #define DSFMT_COMMON_H 23 | 24 | #include "dSFMT.h" 25 | 26 | #if defined(HAVE_SSE2) 27 | # include 28 | union X128I_T { 29 | uint64_t u[2]; 30 | __m128i i128; 31 | }; 32 | union X128D_T { 33 | double d[2]; 34 | __m128d d128; 35 | }; 36 | /** mask data for sse2 */ 37 | static const union X128I_T sse2_param_mask = {{DSFMT_MSK1, DSFMT_MSK2}}; 38 | #endif 39 | 40 | #if defined(HAVE_ALTIVEC) 41 | inline static void do_recursion(w128_t *r, w128_t *a, w128_t * b, 42 | w128_t *lung) { 43 | const vector unsigned char sl1 = ALTI_SL1; 44 | const vector unsigned char sl1_perm = ALTI_SL1_PERM; 45 | const vector unsigned int sl1_msk = ALTI_SL1_MSK; 46 | const vector unsigned char sr1 = ALTI_SR; 47 | const vector unsigned char sr1_perm = ALTI_SR_PERM; 48 | const vector unsigned int sr1_msk = ALTI_SR_MSK; 49 | const vector unsigned char perm = ALTI_PERM; 50 | const vector unsigned int msk1 = ALTI_MSK; 51 | vector unsigned int w, x, y, z; 52 | 53 | z = a->s; 54 | w = lung->s; 55 | x = vec_perm(w, (vector unsigned int)perm, perm); 56 | y = vec_perm(z, (vector unsigned int)sl1_perm, sl1_perm); 57 | y = vec_sll(y, sl1); 58 | y = vec_and(y, sl1_msk); 59 | w = vec_xor(x, b->s); 60 | w = vec_xor(w, y); 61 | x = vec_perm(w, (vector unsigned int)sr1_perm, sr1_perm); 62 | x = vec_srl(x, sr1); 63 | x = vec_and(x, sr1_msk); 64 | y = vec_and(w, msk1); 65 | z = vec_xor(z, y); 66 | r->s = vec_xor(z, x); 67 | lung->s = w; 68 | } 69 | #elif defined(HAVE_SSE2) 70 | /** 71 | * This function represents the recursion formula. 72 | * @param r output 128-bit 73 | * @param a a 128-bit part of the internal state array 74 | * @param b a 128-bit part of the internal state array 75 | * @param d a 128-bit part of the internal state array (I/O) 76 | */ 77 | inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *u) { 78 | __m128i v, w, x, y, z; 79 | 80 | x = a->si; 81 | z = _mm_slli_epi64(x, DSFMT_SL1); 82 | y = _mm_shuffle_epi32(u->si, SSE2_SHUFF); 83 | z = _mm_xor_si128(z, b->si); 84 | y = _mm_xor_si128(y, z); 85 | 86 | v = _mm_srli_epi64(y, DSFMT_SR); 87 | w = _mm_and_si128(y, sse2_param_mask.i128); 88 | v = _mm_xor_si128(v, x); 89 | v = _mm_xor_si128(v, w); 90 | r->si = v; 91 | u->si = y; 92 | } 93 | #else 94 | /** 95 | * This function represents the recursion formula. 96 | * @param r output 128-bit 97 | * @param a a 128-bit part of the internal state array 98 | * @param b a 128-bit part of the internal state array 99 | * @param lung a 128-bit part of the internal state array (I/O) 100 | */ 101 | inline static void do_recursion(w128_t *r, w128_t *a, w128_t * b, 102 | w128_t *lung) { 103 | uint64_t t0, t1, L0, L1; 104 | 105 | t0 = a->u[0]; 106 | t1 = a->u[1]; 107 | L0 = lung->u[0]; 108 | L1 = lung->u[1]; 109 | lung->u[0] = (t0 << DSFMT_SL1) ^ (L1 >> 32) ^ (L1 << 32) ^ b->u[0]; 110 | lung->u[1] = (t1 << DSFMT_SL1) ^ (L0 >> 32) ^ (L0 << 32) ^ b->u[1]; 111 | r->u[0] = (lung->u[0] >> DSFMT_SR) ^ (lung->u[0] & DSFMT_MSK1) ^ t0; 112 | r->u[1] = (lung->u[1] >> DSFMT_SR) ^ (lung->u[1] & DSFMT_MSK2) ^ t1; 113 | } 114 | #endif 115 | #endif 116 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS_H 2 | #define DSFMT_PARAMS_H 3 | 4 | #include "dSFMT.h" 5 | 6 | /*---------------------- 7 | the parameters of DSFMT 8 | following definitions are in dSFMT-paramsXXXX.h file. 9 | ----------------------*/ 10 | /** the pick up position of the array. 11 | #define DSFMT_POS1 122 12 | */ 13 | 14 | /** the parameter of shift left as four 32-bit registers. 15 | #define DSFMT_SL1 18 16 | */ 17 | 18 | /** the parameter of shift right as four 32-bit registers. 19 | #define DSFMT_SR1 12 20 | */ 21 | 22 | /** A bitmask, used in the recursion. These parameters are introduced 23 | * to break symmetry of SIMD. 24 | #define DSFMT_MSK1 (uint64_t)0xdfffffefULL 25 | #define DSFMT_MSK2 (uint64_t)0xddfecb7fULL 26 | */ 27 | 28 | /** These definitions are part of a 128-bit period certification vector. 29 | #define DSFMT_PCV1 UINT64_C(0x00000001) 30 | #define DSFMT_PCV2 UINT64_C(0x00000000) 31 | */ 32 | 33 | #define DSFMT_LOW_MASK UINT64_C(0x000FFFFFFFFFFFFF) 34 | #define DSFMT_HIGH_CONST UINT64_C(0x3FF0000000000000) 35 | #define DSFMT_SR 12 36 | 37 | /* for sse2 */ 38 | #if defined(HAVE_SSE2) 39 | #define SSE2_SHUFF 0x1b 40 | #elif defined(HAVE_ALTIVEC) 41 | #if defined(__APPLE__) /* For OSX */ 42 | #define ALTI_SR (vector unsigned char)(4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4) 43 | #define ALTI_SR_PERM \ 44 | (vector unsigned char)(15,0,1,2,3,4,5,6,15,8,9,10,11,12,13,14) 45 | #define ALTI_SR_MSK \ 46 | (vector unsigned int)(0x000fffffU,0xffffffffU,0x000fffffU,0xffffffffU) 47 | #define ALTI_PERM \ 48 | (vector unsigned char)(12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3) 49 | #else 50 | #define ALTI_SR {4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4} 51 | #define ALTI_SR_PERM {15,0,1,2,3,4,5,6,15,8,9,10,11,12,13,14} 52 | #define ALTI_SR_MSK {0x000fffffU,0xffffffffU,0x000fffffU,0xffffffffU} 53 | #define ALTI_PERM {12,13,14,15,8,9,10,11,4,5,6,7,0,1,2,3} 54 | #endif 55 | #endif 56 | 57 | #if DSFMT_MEXP == 521 58 | #include "dSFMT-params521.h" 59 | #elif DSFMT_MEXP == 1279 60 | #include "dSFMT-params1279.h" 61 | #elif DSFMT_MEXP == 2203 62 | #include "dSFMT-params2203.h" 63 | #elif DSFMT_MEXP == 4253 64 | #include "dSFMT-params4253.h" 65 | #elif DSFMT_MEXP == 11213 66 | #include "dSFMT-params11213.h" 67 | #elif DSFMT_MEXP == 19937 68 | #include "dSFMT-params19937.h" 69 | #elif DSFMT_MEXP == 44497 70 | #include "dSFMT-params44497.h" 71 | #elif DSFMT_MEXP == 86243 72 | #include "dSFMT-params86243.h" 73 | #elif DSFMT_MEXP == 132049 74 | #include "dSFMT-params132049.h" 75 | #elif DSFMT_MEXP == 216091 76 | #include "dSFMT-params216091.h" 77 | #else 78 | #ifdef __GNUC__ 79 | #error "DSFMT_MEXP is not valid." 80 | #undef DSFMT_MEXP 81 | #else 82 | #undef DSFMT_MEXP 83 | #endif 84 | 85 | #endif 86 | 87 | #endif /* DSFMT_PARAMS_H */ 88 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params11213.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS11213_H 2 | #define DSFMT_PARAMS11213_H 3 | 4 | /* #define DSFMT_N 107 */ 5 | /* #define DSFMT_MAXDEGREE 11256 */ 6 | #define DSFMT_POS1 37 7 | #define DSFMT_SL1 19 8 | #define DSFMT_MSK1 UINT64_C(0x000ffffffdf7fffd) 9 | #define DSFMT_MSK2 UINT64_C(0x000dfffffff6bfff) 10 | #define DSFMT_MSK32_1 0x000fffffU 11 | #define DSFMT_MSK32_2 0xfdf7fffdU 12 | #define DSFMT_MSK32_3 0x000dffffU 13 | #define DSFMT_MSK32_4 0xfff6bfffU 14 | #define DSFMT_FIX1 UINT64_C(0xd0ef7b7c75b06793) 15 | #define DSFMT_FIX2 UINT64_C(0x9c50ff4caae0a641) 16 | #define DSFMT_PCV1 UINT64_C(0x8234c51207c80000) 17 | #define DSFMT_PCV2 UINT64_C(0x0000000000000001) 18 | #define DSFMT_IDSTR "dSFMT2-11213:37-19:ffffffdf7fffd-dfffffff6bfff" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3} 32 | #define ALTI_SL1_PERM \ 33 | {2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS11213_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params1279.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS1279_H 2 | #define DSFMT_PARAMS1279_H 3 | 4 | /* #define DSFMT_N 12 */ 5 | /* #define DSFMT_MAXDEGREE 1376 */ 6 | #define DSFMT_POS1 9 7 | #define DSFMT_SL1 19 8 | #define DSFMT_MSK1 UINT64_C(0x000efff7ffddffee) 9 | #define DSFMT_MSK2 UINT64_C(0x000fbffffff77fff) 10 | #define DSFMT_MSK32_1 0x000efff7U 11 | #define DSFMT_MSK32_2 0xffddffeeU 12 | #define DSFMT_MSK32_3 0x000fbfffU 13 | #define DSFMT_MSK32_4 0xfff77fffU 14 | #define DSFMT_FIX1 UINT64_C(0xb66627623d1a31be) 15 | #define DSFMT_FIX2 UINT64_C(0x04b6c51147b6109b) 16 | #define DSFMT_PCV1 UINT64_C(0x7049f2da382a6aeb) 17 | #define DSFMT_PCV2 UINT64_C(0xde4ca84a40000001) 18 | #define DSFMT_IDSTR "dSFMT2-1279:9-19:efff7ffddffee-fbffffff77fff" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3} 32 | #define ALTI_SL1_PERM \ 33 | {2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS1279_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params132049.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS132049_H 2 | #define DSFMT_PARAMS132049_H 3 | 4 | /* #define DSFMT_N 1269 */ 5 | /* #define DSFMT_MAXDEGREE 132104 */ 6 | #define DSFMT_POS1 371 7 | #define DSFMT_SL1 23 8 | #define DSFMT_MSK1 UINT64_C(0x000fb9f4eff4bf77) 9 | #define DSFMT_MSK2 UINT64_C(0x000fffffbfefff37) 10 | #define DSFMT_MSK32_1 0x000fb9f4U 11 | #define DSFMT_MSK32_2 0xeff4bf77U 12 | #define DSFMT_MSK32_3 0x000fffffU 13 | #define DSFMT_MSK32_4 0xbfefff37U 14 | #define DSFMT_FIX1 UINT64_C(0x4ce24c0e4e234f3b) 15 | #define DSFMT_FIX2 UINT64_C(0x62612409b5665c2d) 16 | #define DSFMT_PCV1 UINT64_C(0x181232889145d000) 17 | #define DSFMT_PCV2 UINT64_C(0x0000000000000001) 18 | #define DSFMT_IDSTR "dSFMT2-132049:371-23:fb9f4eff4bf77-fffffbfefff37" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xff800000U,0xffffffffU,0xff800000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7} 32 | #define ALTI_SL1_PERM \ 33 | {2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xff800000U,0xffffffffU,0xff800000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS132049_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params19937.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS19937_H 2 | #define DSFMT_PARAMS19937_H 3 | 4 | /* #define DSFMT_N 191 */ 5 | /* #define DSFMT_MAXDEGREE 19992 */ 6 | #define DSFMT_POS1 117 7 | #define DSFMT_SL1 19 8 | #define DSFMT_MSK1 UINT64_C(0x000ffafffffffb3f) 9 | #define DSFMT_MSK2 UINT64_C(0x000ffdfffc90fffd) 10 | #define DSFMT_MSK32_1 0x000ffaffU 11 | #define DSFMT_MSK32_2 0xfffffb3fU 12 | #define DSFMT_MSK32_3 0x000ffdffU 13 | #define DSFMT_MSK32_4 0xfc90fffdU 14 | #define DSFMT_FIX1 UINT64_C(0x90014964b32f4329) 15 | #define DSFMT_FIX2 UINT64_C(0x3b8d12ac548a7c7a) 16 | #define DSFMT_PCV1 UINT64_C(0x3d84e1ac0dc82880) 17 | #define DSFMT_PCV2 UINT64_C(0x0000000000000001) 18 | #define DSFMT_IDSTR "dSFMT2-19937:117-19:ffafffffffb3f-ffdfffc90fffd" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3} 32 | #define ALTI_SL1_PERM \ 33 | {2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS19937_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params216091.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS216091_H 2 | #define DSFMT_PARAMS216091_H 3 | 4 | /* #define DSFMT_N 2077 */ 5 | /* #define DSFMT_MAXDEGREE 216136 */ 6 | #define DSFMT_POS1 1890 7 | #define DSFMT_SL1 23 8 | #define DSFMT_MSK1 UINT64_C(0x000bf7df7fefcfff) 9 | #define DSFMT_MSK2 UINT64_C(0x000e7ffffef737ff) 10 | #define DSFMT_MSK32_1 0x000bf7dfU 11 | #define DSFMT_MSK32_2 0x7fefcfffU 12 | #define DSFMT_MSK32_3 0x000e7fffU 13 | #define DSFMT_MSK32_4 0xfef737ffU 14 | #define DSFMT_FIX1 UINT64_C(0xd7f95a04764c27d7) 15 | #define DSFMT_FIX2 UINT64_C(0x6a483861810bebc2) 16 | #define DSFMT_PCV1 UINT64_C(0x3af0a8f3d5600000) 17 | #define DSFMT_PCV2 UINT64_C(0x0000000000000001) 18 | #define DSFMT_IDSTR "dSFMT2-216091:1890-23:bf7df7fefcfff-e7ffffef737ff" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xff800000U,0xffffffffU,0xff800000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7} 32 | #define ALTI_SL1_PERM \ 33 | {2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xff800000U,0xffffffffU,0xff800000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS216091_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params2203.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS2203_H 2 | #define DSFMT_PARAMS2203_H 3 | 4 | /* #define DSFMT_N 20 */ 5 | /* #define DSFMT_MAXDEGREE 2208 */ 6 | #define DSFMT_POS1 7 7 | #define DSFMT_SL1 19 8 | #define DSFMT_MSK1 UINT64_C(0x000fdffff5edbfff) 9 | #define DSFMT_MSK2 UINT64_C(0x000f77fffffffbfe) 10 | #define DSFMT_MSK32_1 0x000fdfffU 11 | #define DSFMT_MSK32_2 0xf5edbfffU 12 | #define DSFMT_MSK32_3 0x000f77ffU 13 | #define DSFMT_MSK32_4 0xfffffbfeU 14 | #define DSFMT_FIX1 UINT64_C(0xb14e907a39338485) 15 | #define DSFMT_FIX2 UINT64_C(0xf98f0735c637ef90) 16 | #define DSFMT_PCV1 UINT64_C(0x8000000000000000) 17 | #define DSFMT_PCV2 UINT64_C(0x0000000000000001) 18 | #define DSFMT_IDSTR "dSFMT2-2203:7-19:fdffff5edbfff-f77fffffffbfe" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3} 32 | #define ALTI_SL1_PERM \ 33 | {2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS2203_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params4253.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS4253_H 2 | #define DSFMT_PARAMS4253_H 3 | 4 | /* #define DSFMT_N 40 */ 5 | /* #define DSFMT_MAXDEGREE 4288 */ 6 | #define DSFMT_POS1 19 7 | #define DSFMT_SL1 19 8 | #define DSFMT_MSK1 UINT64_C(0x0007b7fffef5feff) 9 | #define DSFMT_MSK2 UINT64_C(0x000ffdffeffefbfc) 10 | #define DSFMT_MSK32_1 0x0007b7ffU 11 | #define DSFMT_MSK32_2 0xfef5feffU 12 | #define DSFMT_MSK32_3 0x000ffdffU 13 | #define DSFMT_MSK32_4 0xeffefbfcU 14 | #define DSFMT_FIX1 UINT64_C(0x80901b5fd7a11c65) 15 | #define DSFMT_FIX2 UINT64_C(0x5a63ff0e7cb0ba74) 16 | #define DSFMT_PCV1 UINT64_C(0x1ad277be12000000) 17 | #define DSFMT_PCV2 UINT64_C(0x0000000000000001) 18 | #define DSFMT_IDSTR "dSFMT2-4253:19-19:7b7fffef5feff-ffdffeffefbfc" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3} 32 | #define ALTI_SL1_PERM \ 33 | {2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS4253_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params44497.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS44497_H 2 | #define DSFMT_PARAMS44497_H 3 | 4 | /* #define DSFMT_N 427 */ 5 | /* #define DSFMT_MAXDEGREE 44536 */ 6 | #define DSFMT_POS1 304 7 | #define DSFMT_SL1 19 8 | #define DSFMT_MSK1 UINT64_C(0x000ff6dfffffffef) 9 | #define DSFMT_MSK2 UINT64_C(0x0007ffdddeefff6f) 10 | #define DSFMT_MSK32_1 0x000ff6dfU 11 | #define DSFMT_MSK32_2 0xffffffefU 12 | #define DSFMT_MSK32_3 0x0007ffddU 13 | #define DSFMT_MSK32_4 0xdeefff6fU 14 | #define DSFMT_FIX1 UINT64_C(0x75d910f235f6e10e) 15 | #define DSFMT_FIX2 UINT64_C(0x7b32158aedc8e969) 16 | #define DSFMT_PCV1 UINT64_C(0x4c3356b2a0000000) 17 | #define DSFMT_PCV2 UINT64_C(0x0000000000000001) 18 | #define DSFMT_IDSTR "dSFMT2-44497:304-19:ff6dfffffffef-7ffdddeefff6f" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3} 32 | #define ALTI_SL1_PERM \ 33 | {2,3,4,5,6,7,30,30,10,11,12,13,14,15,0,1} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xfff80000U,0xffffffffU,0xfff80000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS44497_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params521.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS521_H 2 | #define DSFMT_PARAMS521_H 3 | 4 | /* #define DSFMT_N 4 */ 5 | /* #define DSFMT_MAXDEGREE 544 */ 6 | #define DSFMT_POS1 3 7 | #define DSFMT_SL1 25 8 | #define DSFMT_MSK1 UINT64_C(0x000fbfefff77efff) 9 | #define DSFMT_MSK2 UINT64_C(0x000ffeebfbdfbfdf) 10 | #define DSFMT_MSK32_1 0x000fbfefU 11 | #define DSFMT_MSK32_2 0xff77efffU 12 | #define DSFMT_MSK32_3 0x000ffeebU 13 | #define DSFMT_MSK32_4 0xfbdfbfdfU 14 | #define DSFMT_FIX1 UINT64_C(0xcfb393d661638469) 15 | #define DSFMT_FIX2 UINT64_C(0xc166867883ae2adb) 16 | #define DSFMT_PCV1 UINT64_C(0xccaa588000000000) 17 | #define DSFMT_PCV2 UINT64_C(0x0000000000000001) 18 | #define DSFMT_IDSTR "dSFMT2-521:3-25:fbfefff77efff-ffeebfbdfbfdf" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xfe000000U,0xffffffffU,0xfe000000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} 32 | #define ALTI_SL1_PERM \ 33 | {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xfe000000U,0xffffffffU,0xfe000000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS521_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/dSFMT-params86243.h: -------------------------------------------------------------------------------- 1 | #ifndef DSFMT_PARAMS86243_H 2 | #define DSFMT_PARAMS86243_H 3 | 4 | /* #define DSFMT_N 829 */ 5 | /* #define DSFMT_MAXDEGREE 86344 */ 6 | #define DSFMT_POS1 231 7 | #define DSFMT_SL1 13 8 | #define DSFMT_MSK1 UINT64_C(0x000ffedff6ffffdf) 9 | #define DSFMT_MSK2 UINT64_C(0x000ffff7fdffff7e) 10 | #define DSFMT_MSK32_1 0x000ffedfU 11 | #define DSFMT_MSK32_2 0xf6ffffdfU 12 | #define DSFMT_MSK32_3 0x000ffff7U 13 | #define DSFMT_MSK32_4 0xfdffff7eU 14 | #define DSFMT_FIX1 UINT64_C(0x1d553e776b975e68) 15 | #define DSFMT_FIX2 UINT64_C(0x648faadf1416bf91) 16 | #define DSFMT_PCV1 UINT64_C(0x5f2cd03e2758a373) 17 | #define DSFMT_PCV2 UINT64_C(0xc0b7eb8410000001) 18 | #define DSFMT_IDSTR "dSFMT2-86243:231-13:ffedff6ffffdf-ffff7fdffff7e" 19 | 20 | 21 | /* PARAMETERS FOR ALTIVEC */ 22 | #if defined(__APPLE__) /* For OSX */ 23 | #define ALTI_SL1 (vector unsigned char)(5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5) 24 | #define ALTI_SL1_PERM \ 25 | (vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0) 26 | #define ALTI_SL1_MSK \ 27 | (vector unsigned int)(0xffffffffU,0xffffe000U,0xffffffffU,0xffffe000U) 28 | #define ALTI_MSK (vector unsigned int)(DSFMT_MSK32_1, \ 29 | DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4) 30 | #else /* For OTHER OSs(Linux?) */ 31 | #define ALTI_SL1 {5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5} 32 | #define ALTI_SL1_PERM \ 33 | {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0} 34 | #define ALTI_SL1_MSK \ 35 | {0xffffffffU,0xffffe000U,0xffffffffU,0xffffe000U} 36 | #define ALTI_MSK \ 37 | {DSFMT_MSK32_1, DSFMT_MSK32_2, DSFMT_MSK32_3, DSFMT_MSK32_4} 38 | #endif 39 | 40 | #endif /* DSFMT_PARAMS86243_H */ 41 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/annotated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: Data Structures 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 |
53 |
54 |
55 |
Data Structures
56 |
57 |
58 |
Here are the data structures with brief descriptions:
59 | 60 | 61 |
DSFMT_T128-bit internal state array
W128_T128-bit data structure
62 |
63 | 64 | 65 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/bc_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/bc_s.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/bdwn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/bdwn.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: Data Structure Index 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 |
53 |
54 |
55 |
Data Structure Index
56 |
57 |
58 |
D | W
59 | 60 | 63 | 64 | 65 | 66 |
  D  
61 |
  W  
62 |
DSFMT_T   W128_T   
67 |
D | W
68 |
69 | 70 | 71 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/closed.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/doxygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/doxygen.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/files.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: File List 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 |
53 |
54 |
55 |
File List
56 |
57 |
58 |
Here is a list of all files with brief descriptions:
59 | 60 | 61 | 62 |
dSFMT-common.h [code]SIMD oriented Fast Mersenne Twister(SFMT) pseudorandom number generator with jump function
dSFMT.cDouble precision SIMD-oriented Fast Mersenne Twister (dSFMT) based on IEEE 754 format
dSFMT.h [code]Double precision SIMD oriented Fast Mersenne Twister(dSFMT) pseudorandom number generator based on IEEE 754 format
63 |
64 | 65 | 66 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: Data Fields 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 | 58 |
59 |
60 |
Here is a list of all struct and union fields with links to the structures/unions they belong to:
77 |
78 | 79 | 80 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/functions_vars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: Data Fields - Variables 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 | 58 |
59 |
60 |   77 |
78 | 79 | 80 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/globals_defs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: Globals 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 | 61 |
62 |
63 |  
    64 |
  • DSFMT_MEXP 65 | : dSFMT.h 66 |
  • 67 |
  • DSFMT_N 68 | : dSFMT.h 69 |
  • 70 |
  • DSFMT_N32 71 | : dSFMT.h 72 |
  • 73 |
  • DSFMT_N64 74 | : dSFMT.h 75 |
  • 76 |
  • DSFMT_PRE_INLINE 77 | : dSFMT.h 78 |
  • 79 |
  • DSFMT_PST_INLINE 80 | : dSFMT.h 81 |
  • 82 |
  • inline 83 | : dSFMT.h 84 |
  • 85 |
  • PRIu64 86 | : dSFMT.h 87 |
  • 88 |
  • PRIx64 89 | : dSFMT.h 90 |
  • 91 |
  • UINT64_C 92 | : dSFMT.h 93 |
  • 94 |
95 |
96 | 97 | 98 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/globals_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: Globals 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 | 61 |
62 |
63 |  
    64 |
  • dsfmt_t 65 | : dSFMT.h 66 |
  • 67 |
  • w128_t 68 | : dSFMT.h 69 |
  • 70 |
71 |
72 | 73 | 74 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/globals_vars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: Globals 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 | 61 |
62 |
63 |  
    64 |
  • dsfmt_global_data 65 | : dSFMT.h 66 | , dSFMT.c 67 |
  • 68 |
  • dsfmt_global_mexp 69 | : dSFMT.h 70 |
  • 71 |
  • dsfmt_mexp 72 | : dSFMT.c 73 |
  • 74 |
75 |
76 | 77 | 78 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/mainpage_8txt.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: mainpage.txt File Reference 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 |
53 |
54 |
55 |
mainpage.txt File Reference
56 |
57 |
58 |
59 | 60 | 61 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/nav_f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/nav_f.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/nav_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/nav_h.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/open.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/struct_d_s_f_m_t___t.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: DSFMT_T Struct Reference 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 |
53 |
54 | 56 |
57 |
DSFMT_T Struct Reference
58 |
59 |
60 | 61 |

the 128-bit internal state array 62 | More...

63 | 64 |

#include <dSFMT.h>

65 | 66 | 68 | 69 | 70 |

67 | Data Fields

w128_t status [DSFMT_N+1]
int idx
71 |

Detailed Description

72 |

the 128-bit internal state array

73 |

Field Documentation

74 | 75 |
76 |
77 | 78 | 79 | 80 | 81 |
int DSFMT_T::idx
82 |
83 | 88 |
89 | 90 | 104 |
The documentation for this struct was generated from the following file: 107 |
108 | 109 | 110 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/tab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/tab_a.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/tab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/tab_b.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/tab_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/tab_h.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/tab_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/html/tab_s.png -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/tabs.css: -------------------------------------------------------------------------------- 1 | .tabs, .tabs2, .tabs3 { 2 | background-image: url('tab_b.png'); 3 | width: 100%; 4 | z-index: 101; 5 | font-size: 13px; 6 | } 7 | 8 | .tabs2 { 9 | font-size: 10px; 10 | } 11 | .tabs3 { 12 | font-size: 9px; 13 | } 14 | 15 | .tablist { 16 | margin: 0; 17 | padding: 0; 18 | display: table; 19 | } 20 | 21 | .tablist li { 22 | float: left; 23 | display: table-cell; 24 | background-image: url('tab_b.png'); 25 | line-height: 36px; 26 | list-style: none; 27 | } 28 | 29 | .tablist a { 30 | display: block; 31 | padding: 0 20px; 32 | font-weight: bold; 33 | background-image:url('tab_s.png'); 34 | background-repeat:no-repeat; 35 | background-position:right; 36 | color: #283A5D; 37 | text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); 38 | text-decoration: none; 39 | outline: none; 40 | } 41 | 42 | .tabs3 .tablist a { 43 | padding: 0 10px; 44 | } 45 | 46 | .tablist a:hover { 47 | background-image: url('tab_h.png'); 48 | background-repeat:repeat-x; 49 | color: #fff; 50 | text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); 51 | text-decoration: none; 52 | } 53 | 54 | .tablist li.current a { 55 | background-image: url('tab_a.png'); 56 | background-repeat:repeat-x; 57 | color: #fff; 58 | text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); 59 | } 60 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/html/union_w128___t.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | dSFMT: W128_T Union Reference 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 |
25 |
dSFMT 26 |  2.2 27 |
28 | 29 |
36 |
37 | 38 | 39 | 46 | 52 |
53 |
54 | 56 |
57 |
W128_T Union Reference
58 |
59 |
60 | 61 |

128-bit data structure 62 | More...

63 | 64 |

#include <dSFMT.h>

65 | 66 | 68 | 69 | 70 | 71 |

67 | Data Fields

uint64_t u [2]
uint32_t u32 [4]
double d [2]
72 |

Detailed Description

73 |

128-bit data structure

74 |

Field Documentation

75 | 76 |
77 |
78 | 79 | 80 | 81 | 82 |
double W128_T::d[2]
83 |
84 | 89 |
90 | 91 |
92 |
93 | 94 | 95 | 96 | 97 |
uint64_t W128_T::u[2]
98 |
99 |
100 | 101 |

Referenced by convert_o0o1(), do_recursion(), initial_mask(), and period_certification().

102 | 103 |
104 |
105 | 106 |
107 |
108 | 109 | 110 | 111 | 112 |
uint32_t W128_T::u32[4]
113 |
114 |
115 | 116 |

Referenced by dsfmt_chk_init_by_array(), and dsfmt_chk_init_gen_rand().

117 | 118 |
119 |
120 |
The documentation for this union was generated from the following file: 123 |
124 | 125 | 126 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/test-sse2-M19937.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/test-sse2-M19937.exe -------------------------------------------------------------------------------- /+MCmatlab/src/dSFMT-src-2.2.3/test-std-M19937.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/dSFMT-src-2.2.3/test-std-M19937.exe -------------------------------------------------------------------------------- /+MCmatlab/src/enable-openmp-on-macos.md: -------------------------------------------------------------------------------- 1 | # Enabling OpenMP on macOS for MCmatlab 2 | 3 | Thanks to Will Grissom who figured this method out for his tool kpTx (https://github.com/wgrissom) 4 | 5 | The following strategy has been tested on: 6 | - MATLAB R2022a running on macOS Ventura 13.0 7 | - MATLAB R2023b running on macOS Sonoma 14.0 8 | - MATLAB R2024b running on macOS Sequoia 15.0 9 | 10 | ## Prerequisites 11 | 12 | 1. Install XCode from the App Store and subsequently install the Apple Command Line Tools: 13 | (enter the following command in the terminal) 14 | ``` 15 | xcode-select --install 16 | ``` 17 | 18 | 2. Install Homebrew: 19 | (enter the following command in the terminal) 20 | ``` 21 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 22 | ``` 23 | 24 | 3. Use Homebrew to install LLVM and OpenMP: 25 | (enter the following command in the terminal) 26 | ``` 27 | brew install llvm libomp 28 | ``` 29 | 30 | ## Compilation Steps 31 | 32 | 1. Configure MATLAB to use the custom XML configuration file: 33 | (enter the following command on the MATLAB command line) 34 | ``` 35 | mex -setup:+MCmatlab/src/clang_openmp_maci64.xml C 36 | ``` 37 | (clang_openmp_maci64.xml is included in this repository) 38 | 39 | 2. Compile the MEX file with OpenMP support: 40 | (enter the following command on the MATLAB command line) 41 | ``` 42 | mex COPTIMFLAGS='$COPTIMFLAGS -O3 -ffast-math -fno-finite-math-only -fopenmp -std=c11 -Wall' LDOPTIMFLAGS='$LDOPTIMFLAGS -O3 -ffast-math -fno-finite-math-only -fopenmp -std=c11 -Wall' -outdir +MCmatlab/@model/private ./+MCmatlab/src/MCmatlab.c 43 | ``` 44 | 45 | ## Optimization Flags Explanation 46 | 47 | The command line flags override the XML configuration and provide: 48 | - `-O3`: Highest standard optimization level 49 | - `-ffast-math`: Aggressive floating-point optimizations 50 | - `-fno-finite-math-only`: Don't assume arguments and results are not NaN/Inf (which -ffast-math would otherwise do) 51 | - `-fopenmp`: Enable OpenMP multithreading 52 | - `-std=c11`: Use C11 language standard 53 | - `-Wall`: Enable all common warnings 54 | 55 | The following sites were helpful in figuring this out: 56 | 57 | https://github.com/wgrissom/kpTx, and therein 58 | https://stackoverflow.com/questions/37362414/openmp-with-mex-in-matlab-on-mac 59 | https://stackoverflow.com/questions/43555410/enable-openmp-support-in-clang-in-mac-os-x-sierra-mojave -------------------------------------------------------------------------------- /+MCmatlab/src/finiteElementHeatPropagator.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/finiteElementHeatPropagator.c -------------------------------------------------------------------------------- /+MCmatlab/src/lambert.c: -------------------------------------------------------------------------------- 1 | /* specfunc/lambert.c 2 | * 3 | * Copyright (C) 2007 Brian Gough 4 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Gerard Jungman 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or (at 9 | * your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | */ 20 | 21 | /* Author: G. Jungman */ 22 | 23 | /* Started with code donated by K. Briggs; added 24 | * error estimates, GSL foo, and minor tweaks. 25 | * Some Lambert-ology from 26 | * [Corless, Gonnet, Hare, and Jeffrey, "On Lambert's W Function".] 27 | */ 28 | 29 | // Shamelessly modified for simpler integration into MCmatlab by Anders Hansen, DTU Fotonik, February 2018 30 | 31 | /* Halley iteration (eqn. 5.12, Corless et al) */ 32 | #ifdef __NVCC__ 33 | __device__ 34 | #endif 35 | static double 36 | halley_iteration( 37 | double x, 38 | double w_initial, 39 | unsigned int max_iters 40 | ) 41 | { 42 | double w = w_initial; 43 | unsigned int i; 44 | 45 | for(i=0; i 0) { 53 | t = (t/p)/e; /* Newton iteration */ 54 | } else { 55 | t /= e*p - 0.5*(p + 1.0)*t/p; /* Halley iteration */ 56 | }; 57 | 58 | w -= t; 59 | 60 | tol = 10 * DBL_EPSILON * fmax(fabs(w), 1.0/(fabs(p)*e)); 61 | 62 | if(fabs(t) < tol) return w; 63 | } 64 | 65 | /* should never get here */ 66 | return 0; 67 | } 68 | 69 | 70 | /* series which appears for q near zero; 71 | * only the argument is different for the different branches 72 | */ 73 | #ifdef __NVCC__ 74 | __device__ 75 | #endif 76 | static double 77 | series_eval(double r) 78 | { 79 | static const double c[12] = { 80 | -1.0, 81 | 2.331643981597124203363536062168, 82 | -1.812187885639363490240191647568, 83 | 1.936631114492359755363277457668, 84 | -2.353551201881614516821543561516, 85 | 3.066858901050631912893148922704, 86 | -4.175335600258177138854984177460, 87 | 5.858023729874774148815053846119, 88 | -8.401032217523977370984161688514, 89 | 12.250753501314460424, 90 | -18.100697012472442755, 91 | 27.029044799010561650 92 | }; 93 | const double t_8 = c[8] + r*(c[9] + r*(c[10] + r*c[11])); 94 | const double t_5 = c[5] + r*(c[6] + r*(c[7] + r*t_8)); 95 | const double t_1 = c[1] + r*(c[2] + r*(c[3] + r*(c[4] + r*t_5))); 96 | return c[0] + r*t_1; 97 | } 98 | 99 | 100 | #ifdef __NVCC__ 101 | __device__ 102 | #endif 103 | double 104 | gsl_sf_lambert_W0(double x) 105 | { 106 | const double q = x + exp(-1.0); 107 | 108 | if(x == 0.0) { 109 | return 0.0; 110 | } 111 | else if(q < 0.0) { 112 | /* Strictly speaking this is an error. But because of the 113 | * arithmetic operation connecting x and q, I am a little 114 | * lenient in case of some epsilon overshoot. The following 115 | * answer is quite accurate in that case. Anyway, we have 116 | * to return GSL_EDOM. 117 | */ 118 | return -1.0; 119 | } 120 | else if(q == 0.0) { 121 | return -1.0; 122 | } 123 | else if(q < 1.0e-03) { 124 | /* series near -1/E in sqrt(q) */ 125 | const double r = sqrt(q); 126 | return series_eval(r); 127 | } 128 | else { 129 | static const unsigned int MAX_ITERS = 10; 130 | double w; 131 | 132 | if (x < 1.0) { 133 | /* obtain initial approximation from series near x=0; 134 | * no need for extra care, since the Halley iteration 135 | * converges nicely on this branch 136 | */ 137 | const double p = sqrt(2.0 * exp(1.0) * q); 138 | w = -1.0 + p*(1.0 + p*(-1.0/3.0 + p*11.0/72.0)); 139 | } 140 | else { 141 | /* obtain initial approximation from rough asymptotic */ 142 | w = log(x); 143 | if(x > 3.0) w -= log(w); 144 | } 145 | 146 | return halley_iteration(x, w, MAX_ITERS); 147 | } 148 | } 149 | 150 | #ifdef __NVCC__ 151 | __device__ 152 | #endif 153 | double 154 | gsl_sf_lambert_Wm1(double x) 155 | { 156 | if(x > 0.0) { 157 | return gsl_sf_lambert_W0(x); 158 | } 159 | else if(x == 0.0) { 160 | return 0.0; 161 | } 162 | else { 163 | static const unsigned int MAX_ITERS = 32; 164 | const double q = x + exp(-1.0); 165 | double w; 166 | 167 | if (q < 0.0) { 168 | /* As in the W0 branch above, return some reasonable answer anyway. */ 169 | return -1.0; 170 | } 171 | 172 | if(x < -1.0e-6) { 173 | /* Obtain initial approximation from series about q = 0, 174 | * as long as we're not very close to x = 0. 175 | * Use full series and try to bail out if q is too small, 176 | * since the Halley iteration has bad convergence properties 177 | * in finite arithmetic for q very small, because the 178 | * increment alternates and p is near zero. 179 | */ 180 | const double r = -sqrt(q); 181 | w = series_eval(r); 182 | if(q < 3.0e-3) { 183 | /* this approximation is good enough */ 184 | return w; 185 | } 186 | } 187 | else { 188 | /* Obtain initial approximation from asymptotic near zero. */ 189 | const double L_1 = log(-x); 190 | const double L_2 = log(-L_1); 191 | w = L_1 - L_2 + L_2/L_1; 192 | } 193 | 194 | return halley_iteration(x, w, MAX_ITERS); 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /+MCmatlab/src/libut.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/libut.lib -------------------------------------------------------------------------------- /+MCmatlab/src/openmp files for mex compiler/libgomp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/openmp files for mex compiler/libgomp.a -------------------------------------------------------------------------------- /+MCmatlab/src/openmp files for mex compiler/libgomp.spec: -------------------------------------------------------------------------------- 1 | # This spec file is read by gcc when linking. It is used to specify the 2 | # standard libraries we need in order to link with libgomp. 3 | *link_gomp: -lgomp %{static: } 4 | -------------------------------------------------------------------------------- /+MCmatlab/src/openmp files for mex compiler/libgomp_64-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/src/openmp files for mex compiler/libgomp_64-1.dll -------------------------------------------------------------------------------- /+MCmatlab/x264/x264_linux: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/x264/x264_linux -------------------------------------------------------------------------------- /+MCmatlab/x264/x264_macOS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/x264/x264_macOS -------------------------------------------------------------------------------- /+MCmatlab/x264/x264_win64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/+MCmatlab/x264/x264_win64.exe -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.fig binary 2 | *.mat binary 3 | *.mdl binary diff merge=mlAutoMerge 4 | *.mdlp binary 5 | *.mexa64 binary 6 | *.mexw64 binary 7 | *.mexmaci64 binary 8 | *.mlapp binary 9 | *.mldatx binary 10 | *.mlproj binary 11 | *.mlx binary 12 | *.p binary 13 | *.sfx binary 14 | *.sldd binary 15 | *.slreqx binary merge=mlAutoMerge 16 | *.slmx binary merge=mlAutoMerge 17 | *.sltx binary 18 | *.slxc binary 19 | *.slx binary merge=mlAutoMerge 20 | *.slxp binary 21 | 22 | ## Other common binary file types 23 | *.docx binary 24 | *.exe binary 25 | *.jpg binary 26 | *.pdf binary 27 | *.png binary 28 | *.xlsx binary 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.asv 2 | *.mkv -------------------------------------------------------------------------------- /Example10_MediaPropertyParametricSweep.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/Example10_MediaPropertyParametricSweep.m -------------------------------------------------------------------------------- /Example13_TdependentVHC.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/Example13_TdependentVHC.m -------------------------------------------------------------------------------- /Example17_CurvedRefractionReflection.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % This example illustrates refraction and reflection using the smoothed and 3 | % interpolated Sobel filter method published by A. Tran and S. Jacques in 4 | % J. of Biomedical Optics, 25(2), 025001 (2020) 5 | % https://doi.org/10.1117/1.JBO.25.2.025001). 6 | % 7 | % This example reproduces figure 3 of that paper. A hemispherical droplet 8 | % of water is surrounded by air and an infinite plane wave is incident on 9 | % it. The two media, of course, have different refractive indices and the 10 | % normal vectors of the droplet surface are calculated using a Sobel filter 11 | % and smoothed at a length scale of model.MC.smoothingLengthScale. 12 | % 13 | % The focusing effect of the droplet is clearly visible when looking at the 14 | % photon paths. The probability of reflection is greater near the edges due 15 | % to the grazing angles of incidence. You will see some voxelization 16 | % artifacts in the light distribution near the edges of the droplet, which 17 | % are unavoidable with this method but will be less significant if the 18 | % resolution is increased. 19 | 20 | %% MCmatlab abbreviations 21 | % G: Geometry, MC: Monte Carlo, FMC: Fluorescence Monte Carlo, HS: Heat 22 | % simulation, M: Media array, FR: Fluence rate, FD: Fractional damage. 23 | % 24 | % There are also some optional abbreviations you can use when referencing 25 | % object/variable names: LS = lightSource, LC = lightCollector, FPID = 26 | % focalPlaneIntensityDistribution, AID = angularIntensityDistribution, NI = 27 | % normalizedIrradiance, NFR = normalizedFluenceRate. 28 | % 29 | % For example, "model.MC.LS.FPID.radialDistr" is the same as 30 | % "model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr" 31 | 32 | %% Geometry definition 33 | MCmatlab.closeMCmatlabFigures(); 34 | model = MCmatlab.model; 35 | 36 | model.G.nx = 201; % Number of bins in the x direction 37 | model.G.ny = 201; % Number of bins in the y direction 38 | model.G.nz = 101; % Number of bins in the z direction 39 | model.G.Lx = .1; % [cm] x size of simulation cuboid 40 | model.G.Ly = .1; % [cm] y size of simulation cuboid 41 | model.G.Lz = .05; % [cm] z size of simulation cuboid 42 | 43 | model.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 44 | model.G.geomFunc = @geometryDefinition; % The distribution of media in the cuboid, also defined as a function at the end of this file. 45 | 46 | model = plot(model,'G'); 47 | 48 | %% Monte Carlo simulation 49 | model.MC.useAllCPUs = true; % If false, MCmatlab will leave one processor unused. Useful for doing other work on the PC while simulations are running. 50 | 51 | model.MC.simulationTimeRequested = .1; % [min] Time duration of the simulation 52 | model.MC.nExamplePaths = 100; % (Default: 0) This number of photons will have their paths stored and shown after completion, for illustrative purposes 53 | 54 | model.MC.matchedInterfaces = false; % If false, uses the refractive indices as defined in mediaPropertiesFunc at the end of this file 55 | model.MC.smoothingLengthScale = model.G.Lx*10; % [cm] The characteristic length scale to smoothe the map of surface normal vectors over, for use when simulating refraction and reflection angles 56 | 57 | model.MC.boundaryType = 1; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping, 3: Top and bottom boundaries are escaping, while the side boundaries are cyclic 58 | model.MC.wavelength = 532; % [nm] Excitation wavelength, used for determination of optical properties for excitation light 59 | 60 | model.MC.lightSource.sourceType = 2; % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 61 | 62 | model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr = 1; % Radial focal plane intensity distribution - 0: Top-hat, 1: Gaussian, Array: Custom. Doesn't need to be normalized. 63 | model.MC.lightSource.focalPlaneIntensityDistribution.radialWidth = .01; % [cm] Radial focal plane 1/e^2 radius if top-hat or Gaussian or half-width of the full distribution if custom 64 | model.MC.lightSource.angularIntensityDistribution.radialDistr = 1; % Radial angular intensity distribution - 0: Top-hat, 1: Gaussian, 2: Cosine (Lambertian), Array: Custom. Doesn't need to be normalized. 65 | model.MC.lightSource.angularIntensityDistribution.radialWidth = 0; % [rad] Radial angular 1/e^2 half-angle if top-hat or Gaussian or half-angle of the full distribution if custom. For a diffraction limited Gaussian beam, this should be set to model.MC.wavelength*1e-9/(pi*model.MC.lightSource.focalPlaneIntensityDistribution.radialWidth*1e-2)) 66 | model.MC.lightSource.xFocus = 0; % [cm] x position of focus 67 | model.MC.lightSource.yFocus = 0; % [cm] y position of focus 68 | model.MC.lightSource.zFocus = model.G.Lz; % [cm] z position of focus 69 | model.MC.lightSource.theta = 0; % [rad] Polar angle of beam center axis 70 | model.MC.lightSource.phi = 0; % [rad] Azimuthal angle of beam center axis 71 | 72 | 73 | model = runMonteCarlo(model); 74 | model = plot(model,'MC'); 75 | 76 | %% Geometry function(s) (see readme for details) 77 | function M = geometryDefinition(X,Y,Z,parameters) 78 | M = ones(size(X)); % Air background 79 | M(X.^2 + Y.^2 + (Z - Z(end)).^2 < 0.04^2) = 2; % Water 80 | end 81 | 82 | %% Media Properties function (see readme for details) 83 | function mediaProperties = mediaPropertiesFunc(parameters) 84 | mediaProperties = MCmatlab.mediumProperties; 85 | 86 | j=1; 87 | mediaProperties(j).name = 'air'; 88 | mediaProperties(j).mua = 1e-8; % [cm^-1] 89 | mediaProperties(j).mus = 1e-8; % [cm^-1] 90 | mediaProperties(j).g = 1; 91 | mediaProperties(j).n = 1; 92 | 93 | j=2; 94 | mediaProperties(j).name = 'water'; 95 | mediaProperties(j).mua = 0.00036; % [cm^-1] 96 | mediaProperties(j).mus = 10; % [cm^-1] 97 | mediaProperties(j).g = 1.0; 98 | mediaProperties(j).n = 1.3; 99 | end -------------------------------------------------------------------------------- /Example19_DepositionCriteria.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % This example illustrates that deposition criteria can be specified to determine when 3 | % photon packets should contribute to output data, for example one could 4 | % specify the number of scattering events must be at least 1 and at most 3. 5 | % See also examples 8 and 25 for more use of the deposition criteria. 6 | % 7 | % The list of criteria are: 8 | % Minimum and maximum # of scattering events 9 | % Minimum and maximum # of refraction events (for non-matched interfaces) 10 | % Minimum and maximum # of reflection events (for non-matched interfaces) 11 | % Minimum and maximum # of interface transition events 12 | % 13 | % There is an implied AND between all these critera. 14 | % 15 | % When a photon packet fulfills the criteria, its "weight loss" 16 | % (absorption) will be counted in the normalized fluence rate 3D array, in 17 | % the image 2D array, in the 2D boundary irradiance arrays and in the 18 | % angular-resolved far field data. Also it will be registered as a 19 | % potential example photon path. 20 | % 21 | % The default criteria are zeros for the minima and infinities for the 22 | % maxima. That means that by default, all photon packets deposit weight 23 | % into the output arrays regardless of the number of scatterings, 24 | % refractions etc. 25 | % 26 | % Changing deposition criteria does not change the underlying propagation 27 | % and absorption of photons packets in the simulation. It only means that 28 | % data will only be registered (deposited) into the output arrays when the 29 | % photon packets fulfill the criteria. 30 | % 31 | % If the setting model.MC.depositionCriteria.evaluateOnlyAtEndOfLife is 32 | % true, as it is by default, the deposition criteria will only be checked 33 | % when the photon "dies" and then the entire photon path gets counted if 34 | % the criteria is met. If the setting is false, the criteria are evaluated 35 | % at every step along the entire path and weight is deposited into the 36 | % outputs whenever the criteria are met. That means weight will not be 37 | % deposited into the outputs in the part of the path that lies before it 38 | % started to fulfill the criteria or the part that lies after it no longer 39 | % fulfills the criteria. 40 | % 41 | % In this example, we use the same geometry and settings as example 1, 42 | % except that we add some photon paths and we choose only to plot data for 43 | % photons that have been scattered exactly once by setting 44 | % model.MC.depositionCriteria.minScatterings = 1, 45 | % model.MC.depositionCriteria.maxScatterings = 1 and 46 | % model.MC.depositionCriteria.evaluateOnlyAtEndOfLife = false. 47 | % 48 | % Notice how you can see the linear paths of photons scattered away from 49 | % the center column. 50 | % 51 | % See the readme.md file for all the properties of the depositionCriteria 52 | % object. 53 | 54 | %% MCmatlab abbreviations 55 | % G: Geometry, MC: Monte Carlo, FMC: Fluorescence Monte Carlo, HS: Heat 56 | % simulation, M: Media array, FR: Fluence rate, FD: Fractional damage. 57 | % 58 | % There are also some optional abbreviations you can use when referencing 59 | % object/variable names: LS = lightSource, LC = lightCollector, FPID = 60 | % focalPlaneIntensityDistribution, AID = angularIntensityDistribution, NI = 61 | % normalizedIrradiance, NFR = normalizedFluenceRate. 62 | % 63 | % For example, "model.MC.LS.FPID.radialDistr" is the same as 64 | % "model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr" 65 | 66 | %% Geometry definition 67 | MCmatlab.closeMCmatlabFigures(); 68 | model = MCmatlab.model; 69 | 70 | model.G.nx = 101; % Number of bins in the x direction 71 | model.G.ny = 101; % Number of bins in the y direction 72 | model.G.nz = 150; % Number of bins in the z direction 73 | model.G.Lx = .1; % [cm] x size of simulation cuboid 74 | model.G.Ly = .1; % [cm] y size of simulation cuboid 75 | model.G.Lz = .15; % [cm] z size of simulation cuboid 76 | 77 | model.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 78 | model.G.geomFunc = @geometryDefinition; % Function to use for defining the distribution of media in the cuboid. Defined at the end of this m file. 79 | 80 | model = plot(model,'G'); 81 | 82 | %% Monte Carlo simulation 83 | model.MC.simulationTimeRequested = .1; % [min] Time duration of the simulation 84 | model.MC.matchedInterfaces = true; % Assumes all refractive indices are the same 85 | model.MC.boundaryType = 1; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping, 3: Top and bottom boundaries are escaping, while the side boundaries are cyclic 86 | model.MC.wavelength = 532; % [nm] Excitation wavelength, used for determination of optical properties for excitation light 87 | 88 | model.MC.lightSource.sourceType = 0; % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 89 | 90 | model.MC.lightSource.xFocus = 0; % [cm] x position of focus 91 | model.MC.lightSource.yFocus = 0; % [cm] y position of focus 92 | model.MC.lightSource.zFocus = model.G.Lz/2; % [cm] z position of focus 93 | 94 | model.MC.lightSource.theta = 0; % [rad] Polar angle of beam center axis 95 | model.MC.lightSource.phi = 0; % [rad] Azimuthal angle of beam center axis 96 | 97 | model.MC.nExamplePaths = 25; 98 | model.MC.depositionCriteria.minScatterings = 1; % Don't collect data for non-scattered photons 99 | model.MC.depositionCriteria.maxScatterings = 1; % Don't collect data for photons with more than 1 scattering 100 | model.MC.depositionCriteria.evaluateOnlyAtEndOfLife = false; 101 | 102 | model = runMonteCarlo(model); 103 | model = plot(model,'MC'); 104 | 105 | %% Geometry function(s) (see readme for details) 106 | function M = geometryDefinition(X,Y,Z,parameters) 107 | zSurface = 0.03; 108 | M = ones(size(X)); % Air 109 | M(Z > zSurface) = 2; % "Standard" tissue 110 | end 111 | 112 | %% Media Properties function (see readme for details) 113 | function mediaProperties = mediaPropertiesFunc(parameters) 114 | mediaProperties = MCmatlab.mediumProperties; 115 | 116 | j=1; 117 | mediaProperties(j).name = 'air'; 118 | mediaProperties(j).mua = 1e-8; % [cm^-1] 119 | mediaProperties(j).mus = 1e-8; % [cm^-1] 120 | mediaProperties(j).g = 1; 121 | 122 | j=2; 123 | mediaProperties(j).name = 'standard tissue'; 124 | mediaProperties(j).mua = 1; % [cm^-1] 125 | mediaProperties(j).mus = 10; % [cm^-1] 126 | mediaProperties(j).g = 0; 127 | end -------------------------------------------------------------------------------- /Example1_StandardTissue.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % In this introductory example, a block of "standard tissue" (mu_a = 1, 3 | % mu_s = 100, g = 0.9) is illuminated by a pencil beam (infinitely thin 4 | % beam). A small slice of air is present in the top of the simulation 5 | % volume. nx and ny are set to odd values so that when the pencil beam is 6 | % launched at x = y = 0 and travels straight down, it travels along a 7 | % well-defined center column of voxels (the middle of the 51st column). Use 8 | % the log10 plot checkbox in the visualizations to better see the fluence 9 | % rate and absorption distribution in the MC result. 10 | 11 | %% MCmatlab abbreviations 12 | % G: Geometry, MC: Monte Carlo, FMC: Fluorescence Monte Carlo, HS: Heat 13 | % simulation, M: Media array, FR: Fluence rate, FD: Fractional damage. 14 | % 15 | % There are also some optional abbreviations you can use when referencing 16 | % object/variable names: LS = lightSource, LC = lightCollector, FPID = 17 | % focalPlaneIntensityDistribution, AID = angularIntensityDistribution, NI = 18 | % normalizedIrradiance, NFR = normalizedFluenceRate. 19 | % 20 | % For example, "model.MC.LS.FPID.radialDistr" is the same as 21 | % "model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr" 22 | 23 | %% Geometry definition 24 | MCmatlab.closeMCmatlabFigures(); 25 | model = MCmatlab.model; 26 | 27 | model.G.nx = 101; % Number of bins in the x direction 28 | model.G.ny = 101; % Number of bins in the y direction 29 | model.G.nz = 150; % Number of bins in the z direction 30 | model.G.Lx = .1; % [cm] x size of simulation cuboid 31 | model.G.Ly = .1; % [cm] y size of simulation cuboid 32 | model.G.Lz = .15; % [cm] z size of simulation cuboid 33 | 34 | model.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 35 | model.G.geomFunc = @geometryDefinition; % Function to use for defining the distribution of media in the cuboid. Defined at the end of this m file. 36 | 37 | model = plot(model,'G'); 38 | 39 | %% Monte Carlo simulation 40 | model.MC.simulationTimeRequested = .1; % [min] Time duration of the simulation 41 | model.MC.matchedInterfaces = true; % Assumes all refractive indices are the same 42 | model.MC.boundaryType = 1; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping, 3: Top and bottom boundaries are escaping, while the side boundaries are cyclic 43 | model.MC.wavelength = 532; % [nm] Excitation wavelength, used for determination of optical properties for excitation light 44 | 45 | model.MC.lightSource.sourceType = 0; % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 46 | 47 | % For a pencil beam, the "focus" is just a point that the beam goes 48 | % through, here set to be the center of the cuboid: 49 | model.MC.lightSource.xFocus = 0; % [cm] x position of focus 50 | model.MC.lightSource.yFocus = 0; % [cm] y position of focus 51 | model.MC.lightSource.zFocus = model.G.Lz/2; % [cm] z position of focus 52 | 53 | model.MC.lightSource.theta = 0; % [rad] Polar angle of beam center axis 54 | model.MC.lightSource.phi = 0; % [rad] Azimuthal angle of beam center axis 55 | 56 | 57 | % These lines will run the Monte Carlo simulation with the provided 58 | % parameters and subsequently plot the results: 59 | model = runMonteCarlo(model); 60 | model = plot(model,'MC'); 61 | 62 | %% Geometry function(s) (see readme for details) 63 | % A geometry function takes as input X,Y,Z matrices as returned by the 64 | % "ndgrid" MATLAB function as well as any parameters the user may have 65 | % provided in the definition of Ginput. It returns the media matrix M, 66 | % containing numerical values indicating the media type (as defined in 67 | % mediaPropertiesFunc) at each voxel location. 68 | function M = geometryDefinition(X,Y,Z,parameters) 69 | zSurface = 0.03; 70 | M = ones(size(X)); % Air 71 | M(Z > zSurface) = 2; % "Standard" tissue 72 | end 73 | 74 | %% Media Properties function (see readme for details) 75 | % The media properties function defines all the optical and thermal 76 | % properties of the media involved by filling out and returning a 77 | % "mediaProperties" array of "mediumProperties" objects with various 78 | % properties. The j indices are the numbers that are referred to in the 79 | % geometry function (in this case, 1 for "air" and 2 for "standard tissue") 80 | % See the readme file or the examples for a list of properties you may 81 | % specify. Most properties may be specified as a numeric constant or as 82 | % function handles. 83 | % 84 | % The function must take one input; the cell array containing any special 85 | % parameters you might specify above in the model file, for example 86 | % parameters that you might loop over in a for loop. In most simulations 87 | % this "parameters" cell array is empty. Dependence on wavelength is shown 88 | % in examples 4 and 23. Dependence on excitation fluence rate FR, 89 | % temperature T or fractional heat damage FD can be specified as in 90 | % examples 12-15. 91 | function mediaProperties = mediaPropertiesFunc(parameters) 92 | % Always leave the following line in place to initialize the 93 | % mediaProperties array: 94 | mediaProperties = MCmatlab.mediumProperties; 95 | 96 | % Put in your own media property definitions below: 97 | j=1; 98 | mediaProperties(j).name = 'air'; 99 | mediaProperties(j).mua = 1e-8; % Absorption coefficient [cm^-1] 100 | mediaProperties(j).mus = 1e-8; % Scattering coefficient [cm^-1] 101 | mediaProperties(j).g = 1; % Henyey-Greenstein scattering anisotropy 102 | 103 | j=2; 104 | mediaProperties(j).name = 'standard tissue'; 105 | mediaProperties(j).mua = 1; % Absorption coefficient [cm^-1] 106 | mediaProperties(j).mus = 100; % Scattering coefficient [cm^-1] 107 | mediaProperties(j).g = 0.9; % Henyey-Greenstein scattering anisotropy 108 | end -------------------------------------------------------------------------------- /Example20_ReflectanceStatisticsAndCyclicBoundaries.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % In this example, we show two things: The use of cyclic boundary 3 | % conditions and how to calculate the reflectance of a sample, including 4 | % how to provide an estimate of the statistical error of the value. 5 | % 6 | % The geometry is similar to that of example 1, although we will run it 7 | % both with and without matched interfaces here. We place a thin layer of 8 | % air, 1 voxel thick, at the top of the cuboid and fill the rest with 9 | % "standard tissue". The thin layer of air is necessary to enforce specular 10 | % reflectance of the incident beam and to include the reflection and 11 | % refraction effects at the surface. 12 | % 13 | % We want to calculate the total and diffuse reflectance of the tissue, so 14 | % we don't want photons to escape at the side walls and disappear from the 15 | % simulation. One possibility for how to avoid this is to use a cuboid with 16 | % very large Lx and Ly. Another is to use cyclic boundary conditions, which 17 | % we employ here by setting model.MC.boundaryType = 3. With cyclic boundary 18 | % conditions, all photons that hit a side wall will immediately enter the 19 | % cuboid again on the opposite wall. Because our geometry is supposed to 20 | % represent a slab of tissue with infinite horizontal extent, this is a 21 | % valid way for us to avoid losing photons to side wall effects. 22 | % 23 | % We will calculate the reflectance by integrating the 24 | % model.MC.normalizedIrradiance_zneg 2D array, which contains all the power 25 | % that has hit the top cuboid boundary from the inside. In principle, the x 26 | % and y resolution can be set as low as the minimum value, 2x2 and still 27 | % get the same result (try it). For visualization purposes, however, we 28 | % keep nx and ny at reasonable values of 101 in this example. Also Lx and 29 | % Ly could be set arbitrarily low due to the use of the cyclic boundaryType. 30 | % 31 | % The reflectance that we calculate is the total reflectance, including the 32 | % specular reflection that we get when simulating without matched 33 | % interfaces. We can obtain the diffuse reflectance by subtracting the 34 | % Fresnel reflectivity, ((1 - 1.4)/(1 + 1.4))^2, from the total 35 | % reflectance. Another way of avoiding the specular reflectance would 36 | % have been to set depositionCriteria.minInterfaceTransitions = 1, but we 37 | % do not use that method here. 38 | % 39 | % To get some statistics, we launch 1e6 photons 5 times and collect the 40 | % diffuse reflectance value for each run. Then we finally write out the 41 | % mean and the standard error of the mean for both the calculation with 42 | % matched interfaces and without. 43 | 44 | %% Geometry definition 45 | MCmatlab.closeMCmatlabFigures(); 46 | model = MCmatlab.model; 47 | 48 | model.G.nx = 101; % Number of bins in the x direction 49 | model.G.ny = 101; % Number of bins in the y direction 50 | model.G.nz = 100; % Number of bins in the z direction 51 | model.G.Lx = .5; % [cm] x size of simulation cuboid 52 | model.G.Ly = .5; % [cm] y size of simulation cuboid 53 | model.G.Lz = 2; % [cm] z size of simulation cuboid 54 | 55 | model.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 56 | model.G.geomFunc = @geometryDefinition; % Function to use for defining the distribution of media in the cuboid. Defined at the end of this m file. 57 | 58 | model = plot(model,'G'); 59 | 60 | %% Monte Carlo simulation 61 | model.MC.nPhotonsRequested = 1e5; % Number of photons requested 62 | model.MC.boundaryType = 3; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping 63 | model.MC.wavelength = 532; % [nm] Excitation wavelength, used for determination of optical properties for excitation light 64 | 65 | model.MC.lightSource.sourceType = 0; % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 66 | model.MC.lightSource.xFocus = 0; % [cm] x position of focus 67 | model.MC.lightSource.yFocus = 0; % [cm] y position of focus 68 | model.MC.lightSource.zFocus = 0; % [cm] z position of focus 69 | 70 | % Set up arrays to collect statistics in: 71 | n = 5; % Times to run 72 | Rd_matched = NaN(1,n); 73 | Rd_mismatched = NaN(1,n); 74 | 75 | % First run with matched interfaces: 76 | model.MC.matchedInterfaces = true; % Assumes all refractive indices are the same 77 | tic 78 | for iRun = 1:n 79 | model = runMonteCarlo(model); 80 | 81 | Rd_matched(iRun) = sum(model.MC.normalizedIrradiance_zneg(:))*model.G.dx*model.G.dy; % Diffuse reflectance 82 | end 83 | t_Matched = toc; 84 | 85 | % Then run with mismatched interfaces: 86 | model.MC.matchedInterfaces = false; 87 | tic 88 | for iRun = 1:n 89 | model = runMonteCarlo(model); 90 | 91 | Rt_mismatched = sum(model.MC.normalizedIrradiance_zneg(:))*model.G.dx*model.G.dy; % Total reflectance 92 | Rd_mismatched(iRun) = Rt_mismatched - ((1 - 1.4)/(1 + 1.4))^2; % Diffuse reflectance 93 | end 94 | t_Mismatched = toc; 95 | 96 | model = plot(model,'MC'); 97 | 98 | %% Print outputs: 99 | fprintf('\nRd matched = %.6f +- %.6f (n = %d, total time elapsed = %d s)\n' ,mean(Rd_matched ),std(Rd_matched )/sqrt(n),n,round(t_Matched )); 100 | fprintf('Rd mismatched = %.6f +- %.6f (n = %d, total time elapsed = %d s)\n\n',mean(Rd_mismatched),std(Rd_mismatched)/sqrt(n),n,round(t_Mismatched)); 101 | 102 | %% Geometry function(s) (see readme for details) 103 | function M = geometryDefinition(X,Y,Z,parameters) 104 | M = 2*ones(size(X)); % "Standard" tissue 105 | M(:,:,1) = 1; % air 106 | end 107 | 108 | %% Media Properties function (see readme for details) 109 | function mediaProperties = mediaPropertiesFunc(parameters) 110 | mediaProperties = MCmatlab.mediumProperties; 111 | 112 | j=1; 113 | mediaProperties(j).name = 'air'; 114 | mediaProperties(j).mua = 1e-8; % [cm^-1] 115 | mediaProperties(j).mus = 100; % [cm^-1] 116 | mediaProperties(j).g = 1; 117 | mediaProperties(j).n = 1; 118 | 119 | j=2; 120 | mediaProperties(j).name = 'standard tissue'; 121 | mediaProperties(j).mua = 1; % [cm^-1] 122 | mediaProperties(j).mus = 100; % [cm^-1] 123 | mediaProperties(j).g = 0.90; 124 | mediaProperties(j).n = 1.4; 125 | end -------------------------------------------------------------------------------- /Example21_CustomPhaseFunctions.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % In this example, we showcase the use of custom phase functions (i.e., 3 | % other phase functions than Henyey-Greenstein). 4 | % 5 | % We will use the farField output array to see the angular distribution of 6 | % scattered light, so we set model.MC.farFieldRes = 21. Our light source 7 | % will be a pencil beam, going straight down the center column of voxels. 8 | % 9 | % To show the scattering distribution, we use a special geometry in which 10 | % we first fill the cuboid with air, then fill the center column with a 11 | % medium with custom scattering phase function. We choose small values for 12 | % Lx and Ly to ensure that the scattering column is very narrow, so as to 13 | % reduce the likelihood of multiple scattering. To ensure that 14 | % non-scattered photons do not get registered in the farField array we set 15 | % depositionCriteria.minScatterings = 1. See example 19 for how deposition 16 | % criteria work. 17 | % 18 | % For the custom phase function for the scatterer, instead of setting the 19 | % "g" property in the media properties function we set instead the 20 | % customPhaseFunc property, which has to be a function of lambda and theta. 21 | % The customPhaseFunc values do not need to be normalized. MCmatlab will 22 | % evaluate the expression and use an efficient lookup table algorithm to 23 | % find the scattering angle at every scattering event. 24 | % 25 | % In this example, we set the custom phase function to that of Rayleigh 26 | % scattering of unpolarized light. This distribution has equal scattering 27 | % per solid angle in the forward and backward directions, and half of that 28 | % in the sideways directions. This is also what we see in the far field 29 | % plot (figure 9). 30 | 31 | %% MCmatlab abbreviations 32 | % G: Geometry, MC: Monte Carlo, FMC: Fluorescence Monte Carlo, HS: Heat 33 | % simulation, M: Media array, FR: Fluence rate, FD: Fractional damage. 34 | % 35 | % There are also some optional abbreviations you can use when referencing 36 | % object/variable names: LS = lightSource, LC = lightCollector, FPID = 37 | % focalPlaneIntensityDistribution, AID = angularIntensityDistribution, NI = 38 | % normalizedIrradiance, NFR = normalizedFluenceRate. 39 | % 40 | % For example, "model.MC.LS.FPID.radialDistr" is the same as 41 | % "model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr" 42 | 43 | %% Geometry definition 44 | MCmatlab.closeMCmatlabFigures(); 45 | model = MCmatlab.model; 46 | 47 | model.G.nx = 101; % Number of bins in the x direction 48 | model.G.ny = 101; % Number of bins in the y direction 49 | model.G.nz = 150; % Number of bins in the z direction 50 | model.G.Lx = .02; % [cm] x size of simulation cuboid 51 | model.G.Ly = .02; % [cm] y size of simulation cuboid 52 | model.G.Lz = .15; % [cm] z size of simulation cuboid 53 | 54 | model.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 55 | model.G.geomFunc = @geometryDefinition; % Function to use for defining the distribution of media in the cuboid. Defined at the end of this m file. 56 | 57 | model = plot(model,'G'); 58 | 59 | %% Monte Carlo simulation 60 | model.MC.simulationTimeRequested = .1; % [min] Time duration of the simulation 61 | model.MC.matchedInterfaces = true; % Assumes all refractive indices are the same 62 | model.MC.boundaryType = 1; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping, 3: Top and bottom boundaries are escaping, while the side boundaries are cyclic 63 | model.MC.wavelength = 532; % [nm] Excitation wavelength, used for determination of optical properties for excitation light 64 | 65 | model.MC.farFieldRes = 21; 66 | 67 | model.MC.lightSource.sourceType = 0; % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 68 | 69 | model.MC.lightSource.xFocus = 0; % [cm] x position of focus 70 | model.MC.lightSource.yFocus = 0; % [cm] y position of focus 71 | model.MC.lightSource.zFocus = model.G.Lz/2; % [cm] z position of focus 72 | 73 | model.MC.lightSource.theta = 0; % [rad] Polar angle of beam center axis 74 | model.MC.lightSource.phi = 0; % [rad] Azimuthal angle of beam center axis 75 | 76 | model.MC.depositionCriteria.minScatterings = 1; 77 | 78 | 79 | model = runMonteCarlo(model); 80 | model = plot(model,'MC'); 81 | figure(9); % Show the far field plot 82 | 83 | %% Geometry function(s) (see readme for details) 84 | function M = geometryDefinition(X,Y,Z,parameters) 85 | M = ones(size(X)); % Air 86 | M(51,51,:) = 2; % Scatterer 87 | end 88 | 89 | %% Media Properties function (see readme for details) 90 | function mediaProperties = mediaPropertiesFunc(parameters) 91 | mediaProperties = MCmatlab.mediumProperties; 92 | 93 | j=1; 94 | mediaProperties(j).name = 'Air'; 95 | mediaProperties(j).mua = 1e-8; % [cm^-1] 96 | mediaProperties(j).mus = 1e-8; % [cm^-1] 97 | mediaProperties(j).g = 1; 98 | 99 | j=2; 100 | mediaProperties(j).name = 'Rayleigh scatterer'; 101 | mediaProperties(j).mua = 1e-8; % [cm^-1] 102 | mediaProperties(j).mus = 10; % [cm^-1] 103 | mediaProperties(j).customPhaseFunc = @func1; 104 | function phasefunc = func1(lambda,theta) 105 | phasefunc = 1 + cos(theta)^2; 106 | end 107 | end -------------------------------------------------------------------------------- /Example22_CombiningModelObjects.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % In this example, we demonstrate that model outputs can be combined with 3 | % each other using the combineModels() function. This can be useful, for 4 | % example, when you want to have multiple input light sources, such as 5 | % beams. It can also be useful for heavy simulations that require a lot of 6 | % statistics, so you might have run the same simulation on multiple 7 | % different PCs and would like to combine the results. 8 | % 9 | % This example is almost the same as example 1, except that we start by 10 | % naming the model "model1" instead of the usual "model". It has a shifted 11 | % y position of the input pencil beam and a power (model1.MC.P) of 1 12 | % watt. 13 | % 14 | % Then we copy this model into a new model called "model2", and we give 15 | % model2 a new beam y position and a different power, 0.1 watts. 16 | % 17 | % We run the Monte Carlo simulation on both of these models individually, 18 | % and then use the combineModels() function to combine the results into one 19 | % model called "combinedModel". 20 | % 21 | % This combined model object now contains properties where the input objects'... 22 | % - nPhotons and simulationTime have been added 23 | % - examplePaths have been concatenated 24 | % - image, normalizedFluenceRate, farField and all the normalizedIrradiance 25 | % arrays have been set to weighted means 26 | % If all the light sources (model.MC.LS) and input powers (model.MC.P) are 27 | % identical we assume that the objects are being combined simply to gather 28 | % more statistics, so the weights used for the mean are the numbers of 29 | % photons in each simulation, nPhotons. If they are not identical, we 30 | % assume that we are combining simulations with different light sources, as 31 | % is the case in this example, and the weights used are the powers, 32 | % model.MC.P. 33 | % 34 | % When plotting the combined model output, you see the two pencil beams in 35 | % the cuboid, with one having five times the power of the other. 36 | 37 | %% MCmatlab abbreviations 38 | % G: Geometry, MC: Monte Carlo, FMC: Fluorescence Monte Carlo, HS: Heat 39 | % simulation, M: Media array, FR: Fluence rate, FD: Fractional damage. 40 | % 41 | % There are also some optional abbreviations you can use when referencing 42 | % object/variable names: LS = lightSource, LC = lightCollector, FPID = 43 | % focalPlaneIntensityDistribution, AID = angularIntensityDistribution, NI = 44 | % normalizedIrradiance, NFR = normalizedFluenceRate. 45 | % 46 | % For example, "model.MC.LS.FPID.radialDistr" is the same as 47 | % "model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr" 48 | 49 | %% Geometry definition 50 | MCmatlab.closeMCmatlabFigures(); 51 | model1 = MCmatlab.model; 52 | 53 | model1.G.nx = 101; % Number of bins in the x direction 54 | model1.G.ny = 101; % Number of bins in the y direction 55 | model1.G.nz = 150; % Number of bins in the z direction 56 | model1.G.Lx = .1; % [cm] x size of simulation cuboid 57 | model1.G.Ly = .1; % [cm] y size of simulation cuboid 58 | model1.G.Lz = .15; % [cm] z size of simulation cuboid 59 | 60 | model1.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 61 | model1.G.geomFunc = @geometryDefinition; % Function to use for defining the distribution of media in the cuboid. Defined at the end of this m file. 62 | 63 | model1 = plot(model1,'G'); 64 | 65 | %% Monte Carlo simulation 66 | model1.MC.simulationTimeRequested = .1; % [min] Time duration of the simulation 67 | model1.MC.matchedInterfaces = true; % Assumes all refractive indices are the same 68 | model1.MC.boundaryType = 1; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping, 3: Top and bottom boundaries are escaping, while the side boundaries are cyclic 69 | model1.MC.wavelength = 532; % [nm] Excitation wavelength, used for determination of optical properties for excitation light 70 | 71 | model1.MC.lightSource.sourceType = 0; % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 72 | model1.MC.lightSource.xFocus = 0; % [cm] x position of focus 73 | model1.MC.lightSource.yFocus = -0.01; % [cm] y position of focus 74 | model1.MC.lightSource.zFocus = model1.G.Lz/2; % [cm] z position of focus 75 | 76 | model1.MC.lightSource.theta = 0; % [rad] Polar angle of beam center axis 77 | model1.MC.lightSource.phi = 0; % [rad] Azimuthal angle of beam center axis 78 | 79 | % Set the power of model1 80 | model1.MC.P = 1; 81 | 82 | % Copy the model to another object. We now have two identical, but 83 | % separate, model objects 84 | model2 = model1; 85 | 86 | % Change model2 to have a different yFocus and a different power than 87 | % model1, but otherwise they are still the same 88 | model2.MC.lightSource.yFocus = 0.01; 89 | model2.MC.P = 0.2; 90 | 91 | % Run MC on the two objects individually 92 | model1 = runMonteCarlo(model1); 93 | model2 = runMonteCarlo(model2); 94 | 95 | % Combine the two models. combineModels will add up the 96 | combinedModel = combineModels([model1, model2],'MC'); % First argument is an array of model objects. Second argument is either 'MC' or 'FMC'. 97 | 98 | 99 | combinedModel = plot(combinedModel,'MC'); 100 | 101 | %% Geometry function(s) (see readme for details) 102 | function M = geometryDefinition(X,Y,Z,parameters) 103 | zSurface = 0.03; 104 | M = ones(size(X)); % Air 105 | M(Z > zSurface) = 2; % "Standard" tissue 106 | end 107 | 108 | %% Media Properties function (see readme for details) 109 | function mediaProperties = mediaPropertiesFunc(parameters) 110 | mediaProperties = MCmatlab.mediumProperties; 111 | 112 | j=1; 113 | mediaProperties(j).name = 'air'; 114 | mediaProperties(j).mua = 1e-8; % [cm^-1] 115 | mediaProperties(j).mus = 1e-8; % [cm^-1] 116 | mediaProperties(j).g = 1; 117 | 118 | j=2; 119 | mediaProperties(j).name = 'standard tissue'; 120 | mediaProperties(j).mua = 1; % [cm^-1] 121 | mediaProperties(j).mus = 100; % [cm^-1] 122 | mediaProperties(j).g = 0.9; 123 | end -------------------------------------------------------------------------------- /Example24_AzFzReflectanceTransmittance.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % This example shows the use of the helper functions MCmatlab.plotAzFz() 3 | % and MCmatlab.plotRadialReflectanceTransmittance(). They generate plots 4 | % similar to those made by MCML, available at omlc.org. Use the log scale 5 | % button to see the details in the wings of the distributions. 6 | % 7 | % The radially resolved reflectance and transmittance plots only make sense 8 | % if your problem is radially symmetric around x = y = 0. Furthermore, when 9 | % launching simulations for these plots, it's advised to use an odd number 10 | % for nx and ny, to ensure a data point at a radial distance of 0. 11 | 12 | %% MCmatlab abbreviations 13 | % G: Geometry, MC: Monte Carlo, FMC: Fluorescence Monte Carlo, HS: Heat 14 | % simulation, M: Media array, FR: Fluence rate, FD: Fractional damage. 15 | % 16 | % There are also some optional abbreviations you can use when referencing 17 | % object/variable names: LS = lightSource, LC = lightCollector, FPID = 18 | % focalPlaneIntensityDistribution, AID = angularIntensityDistribution, NI = 19 | % normalizedIrradiance, NFR = normalizedFluenceRate. 20 | % 21 | % For example, "model.MC.LS.FPID.radialDistr" is the same as 22 | % "model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr" 23 | 24 | %% Geometry definition 25 | MCmatlab.closeMCmatlabFigures(); 26 | model = MCmatlab.model; 27 | 28 | model.G.nx = 101; % Number of bins in the x direction 29 | model.G.ny = 101; % Number of bins in the y direction 30 | model.G.nz = 150; % Number of bins in the z direction 31 | model.G.Lx = 5; % [cm] x size of simulation cuboid 32 | model.G.Ly = 5; % [cm] y size of simulation cuboid 33 | model.G.Lz = 1; % [cm] z size of simulation cuboid 34 | 35 | model.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 36 | model.G.geomFunc = @geometryDefinition; % Function to use for defining the distribution of media in the cuboid. Defined at the end of this m file. 37 | 38 | model = plot(model,'G'); 39 | 40 | %% Monte Carlo simulation 41 | model.MC.simulationTimeRequested = .1; % [min] Time duration of the simulation 42 | model.MC.matchedInterfaces = true; % Assumes all refractive indices are the same 43 | model.MC.boundaryType = 1; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping, 3: Top and bottom boundaries are escaping, while the side boundaries are cyclic 44 | model.MC.wavelength = 532; % [nm] Excitation wavelength, used for determination of optical properties for excitation light 45 | 46 | model.MC.lightSource.sourceType = 0; % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 47 | 48 | model.MC.lightSource.xFocus = 0; % [cm] x position of focus 49 | model.MC.lightSource.yFocus = 0; % [cm] y position of focus 50 | model.MC.lightSource.zFocus = model.G.Lz/2; % [cm] z position of focus 51 | model.MC.lightSource.theta = 0; % [rad] Polar angle of beam center axis 52 | model.MC.lightSource.phi = 0; % [rad] Azimuthal angle of beam center axis 53 | 54 | model = runMonteCarlo(model); 55 | model = plot(model,'MC'); 56 | 57 | % Make MCML-like Az, Fz, reflectance and transmission plots 58 | MCmatlab.plotAzFz(model); 59 | MCmatlab.plotRadialReflectanceTransmittance(model); 60 | 61 | %% Geometry function(s) (see readme for details) 62 | function M = geometryDefinition(X,Y,Z,parameters) 63 | M = ones(size(X)); % Tissue 1 64 | M(Z > 0.2) = 2; % Tissue 2 65 | end 66 | 67 | %% Media Properties function (see readme for details) 68 | function mediaProperties = mediaPropertiesFunc(parameters) 69 | mediaProperties = MCmatlab.mediumProperties; 70 | 71 | j=1; 72 | mediaProperties(j).name = 'Tissue 1'; 73 | mediaProperties(j).mua = 0.4; % Absorption coefficient [cm^-1] 74 | mediaProperties(j).mus = 100; % Scattering coefficient [cm^-1] 75 | mediaProperties(j).g = 0.9; % Henyey-Greenstein scattering anisotropy 76 | 77 | j=2; 78 | mediaProperties(j).name = 'Tissue 2'; 79 | mediaProperties(j).mua = 0.2; % Absorption coefficient [cm^-1] 80 | mediaProperties(j).mus = 100; % Scattering coefficient [cm^-1] 81 | mediaProperties(j).g = 0.9; % Henyey-Greenstein scattering anisotropy 82 | end -------------------------------------------------------------------------------- /Example26_DistributedSource.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % In this example, we show that MCmatlab can launch excitation photons from 3 | % a user-specified spatial and spectral distribution of sources, similar to 4 | % how fluorescence photons are launched. The distribution may be wavelength 5 | % dependent. It is stored in model.MC.sourceDistribution and must be 3- or 6 | % 4-dimensional (nx, ny, nz) or (nx, ny, nz, nLambda). 7 | 8 | % The distribution of emitters gets plotted in figure 7. 9 | 10 | %% MCmatlab abbreviations 11 | % G: Geometry, MC: Monte Carlo, FMC: Fluorescence Monte Carlo, HS: Heat 12 | % simulation, M: Media array, FR: Fluence rate, FD: Fractional damage. 13 | % 14 | % There are also some optional abbreviations you can use when referencing 15 | % object/variable names: LS = lightSource, LC = lightCollector, FPID = 16 | % focalPlaneIntensityDistribution, AID = angularIntensityDistribution, NI = 17 | % normalizedIrradiance, NFR = normalizedFluenceRate. 18 | % 19 | % For example, "model.MC.LS.FPID.radialDistr" is the same as 20 | % "model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr" 21 | 22 | %% Geometry definition 23 | MCmatlab.closeMCmatlabFigures(); 24 | model = MCmatlab.model; 25 | 26 | model.G.nx = 101; % Number of bins in the x direction 27 | model.G.ny = 101; % Number of bins in the y direction 28 | model.G.nz = 150; % Number of bins in the z direction 29 | model.G.Lx = .1; % [cm] x size of simulation cuboid 30 | model.G.Ly = .1; % [cm] y size of simulation cuboid 31 | model.G.Lz = .15; % [cm] z size of simulation cuboid 32 | 33 | model.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 34 | model.G.geomFunc = @geometryDefinition; % Function to use for defining the distribution of media in the cuboid. Defined at the end of this m file. 35 | 36 | model = plot(model,'G'); 37 | 38 | %% Monte Carlo simulation 39 | model.MC.simulationTimeRequested = .1; % [min] Time duration of the simulation 40 | model.MC.matchedInterfaces = true; % Assumes all refractive indices are the same 41 | model.MC.boundaryType = 1; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping, 3: Top and bottom boundaries are escaping, while the side boundaries are cyclic 42 | model.MC.wavelength = linspace(400,600,41); % [nm] Excitation wavelength, used for determination of optical properties for excitation light 43 | 44 | % For our spatial-spectral 4D array for our source distribution, we 45 | % arbitrarily choose a sphere buried in the tissue, with a Gaussian 46 | % spectral distribution. The distribution will automatically be normalized 47 | % once runMonteCarlo() is called: 48 | [X,Y,Z,lambda] = ndgrid(model.G.x, model.G.y, model.G.z, model.MC.wavelength); 49 | model.MC.sourceDistribution = exp(-(lambda-500).^2/50^2).*(X.^2+Y.^2+(Z-0.1).^2 < 0.01^2); 50 | 51 | 52 | model = runMonteCarlo(model); 53 | model = plot(model,'MC'); 54 | 55 | %% Geometry function(s) (see readme for details) 56 | function M = geometryDefinition(X,Y,Z,parameters) 57 | zSurface = 0.03; 58 | M = ones(size(X)); % Air 59 | M(Z > zSurface) = 2; % "Standard" tissue 60 | end 61 | 62 | %% Media Properties function (see readme for details) 63 | function mediaProperties = mediaPropertiesFunc(parameters) 64 | mediaProperties = MCmatlab.mediumProperties; 65 | 66 | j=1; 67 | mediaProperties(j).name = 'air'; 68 | mediaProperties(j).mua = 1e-8; % Absorption coefficient [cm^-1] 69 | mediaProperties(j).mus = 1e-8; % Scattering coefficient [cm^-1] 70 | mediaProperties(j).g = 1; % Henyey-Greenstein scattering anisotropy 71 | 72 | j=2; 73 | mediaProperties(j).name = 'standard tissue'; 74 | mediaProperties(j).mua = 1; % Absorption coefficient [cm^-1] 75 | mediaProperties(j).mus = 100; % Scattering coefficient [cm^-1] 76 | mediaProperties(j).g = 0.9; % Henyey-Greenstein scattering anisotropy 77 | end -------------------------------------------------------------------------------- /Example3_RefractionReflection.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % This example illustrates simulation of refraction and reflection 3 | % according to Fresnel's equations. This requires the matchedInterfaces flag 4 | % to be set to false. The geometry consists of three layers: At the bottom 5 | % is a reflector such as metal (n = infinity), at the top is air (n = 1) 6 | % and in between is water (n = 1.3). The light source is an isotropically 7 | % emitting (equally emitting in all directions) source located inside the 8 | % water layer. The rays can be seen to be reflected from the bottom 9 | % interface and also to an extent from the top interface, although some 10 | % light is also refracted out of the water. 11 | % 12 | % This example also shown the optional "useAllCPUs" flag that can be set on 13 | % the MC simulations to slightly increase speed. Default is false, which 14 | % means the solver leaves one CPU unused, making it easier to perform other 15 | % work on the PC while simulations are running. Note that multithreading is 16 | % anyway only supported on Windows. On Mac, useAllCPUs is ignored. 17 | % 18 | % Additionally, the optional "nExamplePaths" parameter is demonstrated, a 19 | % value specifying the number of photons whose paths should be stored and 20 | % shown as lines in a 3D plot after completion. 21 | 22 | %% MCmatlab abbreviations 23 | % G: Geometry, MC: Monte Carlo, FMC: Fluorescence Monte Carlo, HS: Heat 24 | % simulation, M: Media array, FR: Fluence rate, FD: Fractional damage. 25 | % 26 | % There are also some optional abbreviations you can use when referencing 27 | % object/variable names: LS = lightSource, LC = lightCollector, FPID = 28 | % focalPlaneIntensityDistribution, AID = angularIntensityDistribution, NI = 29 | % normalizedIrradiance, NFR = normalizedFluenceRate. 30 | % 31 | % For example, "model.MC.LS.FPID.radialDistr" is the same as 32 | % "model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr" 33 | 34 | %% Geometry definition 35 | MCmatlab.closeMCmatlabFigures(); 36 | model = MCmatlab.model; 37 | 38 | model.G.nx = 100; % Number of bins in the x direction 39 | model.G.ny = 100; % Number of bins in the y direction 40 | model.G.nz = 100; % Number of bins in the z direction 41 | model.G.Lx = .1; % [cm] x size of simulation cuboid 42 | model.G.Ly = .1; % [cm] y size of simulation cuboid 43 | model.G.Lz = .1; % [cm] z size of simulation cuboid 44 | 45 | model.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 46 | model.G.geomFunc = @geometryDefinition; % The distribution of media in the cuboid, also defined as a function at the end of this file. 47 | 48 | model = plot(model,'G'); 49 | 50 | %% Monte Carlo simulation 51 | model.MC.useAllCPUs = true; % If false, MCmatlab will leave one processor unused. Useful for doing other work on the PC while simulations are running. 52 | model.MC.simulationTimeRequested = .1; % [min] Time duration of the simulation 53 | model.MC.nExamplePaths = 100; % (Default: 0) This number of photons will have their paths stored and shown after completion, for illustrative purposes 54 | 55 | model.MC.matchedInterfaces = false; % If false, uses the refractive indices as defined in mediaPropertiesFunc at the end of this file 56 | model.MC.boundaryType = 1; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping, 3: Top and bottom boundaries are escaping, while the side boundaries are cyclic 57 | model.MC.wavelength = 532; % [nm] Excitation wavelength, used for determination of optical properties for excitation light 58 | 59 | model.MC.lightSource.sourceType = 1; % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 60 | model.MC.lightSource.xFocus = 0; % [cm] x position of focus 61 | model.MC.lightSource.yFocus = 0; % [cm] y position of focus 62 | model.MC.lightSource.zFocus = 0.04; % [cm] z position of focus 63 | 64 | 65 | model = runMonteCarlo(model); 66 | model = plot(model,'MC'); 67 | figure(5); % Focus on the photon paths 68 | 69 | %% Geometry function(s) (see readme for details) 70 | function M = geometryDefinition(X,Y,Z,parameters) 71 | M = ones(size(X)); % Air background 72 | M(Z>0.03) = 2; % Water 73 | M(Z>0.09) = 3; % Reflector 74 | end 75 | 76 | %% Media Properties function (see readme for details) 77 | function mediaProperties = mediaPropertiesFunc(parameters) 78 | mediaProperties = MCmatlab.mediumProperties; 79 | 80 | j=1; 81 | mediaProperties(j).name = 'air'; 82 | mediaProperties(j).mua = 1e-8; % [cm^-1] 83 | mediaProperties(j).mus = 1e-8; % [cm^-1] 84 | mediaProperties(j).g = 1; 85 | mediaProperties(j).n = 1; 86 | 87 | j=2; 88 | mediaProperties(j).name = 'water'; 89 | mediaProperties(j).mua = 0.00036; % [cm^-1] 90 | mediaProperties(j).mus = 10; % [cm^-1] 91 | mediaProperties(j).g = 1.0; 92 | mediaProperties(j).n = 1.3; 93 | 94 | j=3; 95 | mediaProperties(j).name = 'reflector'; 96 | mediaProperties(j).mua = 1; % [cm^-1] 97 | mediaProperties(j).mus = 1; % [cm^-1] 98 | mediaProperties(j).g = 0; 99 | mediaProperties(j).n = Inf; 100 | end -------------------------------------------------------------------------------- /Example6_TimeTagging.m: -------------------------------------------------------------------------------- 1 | %% Description 2 | % This example is concerned with time-tagging of the photons. The 3 | % time-of-flight is registered and binned when(if) the photon hits the 4 | % detector, which in this demonstration is spatially-resolved in addition 5 | % to time-resolved. Therefore, the output "image" is 3D, with two spatial 6 | % dimensions and one time-of-flight dimension. The geometry consists of big 7 | % scattering voxels placed diagonally along the xyz direction and along the 8 | % yz direction, illuminated with an infinite plane wave. The xyz-diagonally 9 | % placed voxels are all in the focal plane of the detection lens, so they 10 | % all appear sharp in the time-resolved image, while the yz-diagonally 11 | % placed voxels are not all in the focal plane and some of them are 12 | % therefore blurred out in the image. Scattering from voxels at larger z 13 | % depths are seen to arrive at later times. 14 | 15 | %% MCmatlab abbreviations 16 | % G: Geometry, MC: Monte Carlo, FMC: Fluorescence Monte Carlo, HS: Heat 17 | % simulation, M: Media array, FR: Fluence rate, FD: Fractional damage. 18 | % 19 | % There are also some optional abbreviations you can use when referencing 20 | % object/variable names: LS = lightSource, LC = lightCollector, FPID = 21 | % focalPlaneIntensityDistribution, AID = angularIntensityDistribution, NI = 22 | % normalizedIrradiance, NFR = normalizedFluenceRate. 23 | % 24 | % For example, "model.MC.LS.FPID.radialDistr" is the same as 25 | % "model.MC.lightSource.focalPlaneIntensityDistribution.radialDistr" 26 | 27 | %% Geometry definition 28 | MCmatlab.closeMCmatlabFigures(); 29 | model = MCmatlab.model; 30 | 31 | model.G.nx = 20; % Number of bins in the x direction 32 | model.G.ny = 20; % Number of bins in the y direction 33 | model.G.nz = 20; % Number of bins in the z direction 34 | model.G.Lx = .1; % [cm] x size of simulation cuboid 35 | model.G.Ly = .1; % [cm] y size of simulation cuboid 36 | model.G.Lz = .1; % [cm] z size of simulation cuboid 37 | 38 | model.G.mediaPropertiesFunc = @mediaPropertiesFunc; % Media properties defined as a function at the end of this file 39 | model.G.geomFunc = @geometryDefinition; % Function to use for defining the distribution of media in the cuboid. Defined at the end of this m file. 40 | 41 | model = plot(model,'G'); 42 | 43 | %% Monte Carlo simulation 44 | model.MC.useAllCPUs = true; % If false, MCmatlab will leave one processor unused. Useful for doing other work on the PC while simulations are running. 45 | model.MC.simulationTimeRequested = .5; % [min] Time duration of the simulation 46 | 47 | model.MC.matchedInterfaces = true; % Assumes all refractive indices are the same 48 | model.MC.boundaryType = 1; % 0: No escaping boundaries, 1: All cuboid boundaries are escaping, 2: Top cuboid boundary only is escaping, 3: Top and bottom boundaries are escaping, while the side boundaries are cyclic 49 | model.MC.wavelength = 532; % [nm] Excitation wavelength, used for determination of optical properties for excitation light 50 | 51 | model.MC.lightSource.sourceType = 2; % 0: Pencil beam, 1: Isotropically emitting line or point source, 2: Infinite plane wave, 3: Laguerre-Gaussian LG01 beam, 4: Radial-factorizable beam (e.g., a Gaussian beam), 5: X/Y factorizable beam (e.g., a rectangular LED emitter) 52 | model.MC.lightSource.xFocus = 0; % [cm] x position of focus 53 | model.MC.lightSource.yFocus = 0; % [cm] y position of focus 54 | model.MC.lightSource.zFocus = model.G.Lz/2; % [cm] z position of focus 55 | model.MC.lightSource.theta = 0; % [rad] Polar angle of beam center axis 56 | model.MC.lightSource.phi = 0; % [rad] Azimuthal angle of beam center axis 57 | 58 | model.MC.useLightCollector = true; 59 | model.MC.lightCollector.x = 0; % [cm] x position of either the center of the objective lens focal plane or the fiber tip 60 | model.MC.lightCollector.y = 0; % [cm] y position 61 | model.MC.lightCollector.z = model.G.Lz/2; % [cm] z position 62 | 63 | model.MC.lightCollector.theta = atan(1/sqrt(2)); % [rad] Polar angle of direction the light collector is facing 64 | model.MC.lightCollector.phi = -3*pi/4; % [rad] Azimuthal angle of direction the light collector is facing 65 | 66 | model.MC.lightCollector.f = .2; % [cm] Focal length of the objective lens (if light collector is a fiber, set this to Inf). 67 | model.MC.lightCollector.diam = .2; % [cm] Diameter of the light collector aperture. For an ideal thin lens, this is 2*f*tan(asin(NA)). 68 | model.MC.lightCollector.fieldSize = .2; % [cm] Field Size of the imaging system (diameter of area in object plane that gets imaged). Only used for finite f. 69 | model.MC.lightCollector.NA = 0.22; % [-] Fiber NA. Only used for infinite f. 70 | 71 | model.MC.lightCollector.res = 100; % X and Y resolution of light collector in pixels, only used for finite f 72 | 73 | model.MC.lightCollector.tStart = -1.5e-13; % [s] Start of the detection time-of-flight interval 74 | model.MC.lightCollector.tEnd = 5.5e-12; % [s] End of the detection time-of-flight interval 75 | model.MC.lightCollector.nTimeBins = 100; % Number of bins between tStart and tEnd. If zero, the measurement is not time-resolved. 76 | 77 | 78 | model = runMonteCarlo(model); 79 | model = plot(model,'MC'); 80 | figure(8); % Focus on the collected light plot 81 | 82 | %% Geometry function(s) (see readme for details) 83 | function M = geometryDefinition(X,Y,Z,parameters) 84 | [nx,ny,~] = size(X); 85 | M = ones(size(X)); % Air background 86 | M(1:(nx*(ny+1)+1):end) = 2; % Set xyz diagonal positions to test scatterer 87 | M(1:(nx*(ny+1)):end) = 2; % Set yz diagonal positions to test scatterer 88 | end 89 | 90 | %% Media Properties function (see readme for details) 91 | function mediaProperties = mediaPropertiesFunc(parameters) 92 | mediaProperties = MCmatlab.mediumProperties; 93 | j=1; 94 | mediaProperties(j).name = 'air'; 95 | mediaProperties(j).mua = 1e-8; % [cm^-1] 96 | mediaProperties(j).mus = 1e-8; % [cm^-1] 97 | mediaProperties(j).g = 1; 98 | 99 | j=2; 100 | mediaProperties(j).name = 'test scatterer'; 101 | mediaProperties(j).mua = 0.0000001; % [cm^-1] 102 | mediaProperties(j).mus = 100; % [cm^-1] 103 | mediaProperties(j).g = 0; 104 | end -------------------------------------------------------------------------------- /helperfuncs/Grid.m: -------------------------------------------------------------------------------- 1 | classdef Grid < handle 2 | % Grid is a class used to represent basic information about a grid, 3 | % including how @dimension_count, the @points along each axis, its 4 | % @shape in terms of number of points per dimension, and its @origin, 5 | % i.e. the vector composed of minimums of @points along each dimension. 6 | % 7 | % Inputs: 8 | % - Any number of real, finite, increasing double vectors. Each 9 | % represents the grid points along the same number of dimensional 10 | % axes. 11 | % - OR - 12 | % - A cell vector, each element of whcih contains a real, finite, 13 | % increasing double vector, as above. 14 | 15 | properties ( SetAccess = private ) 16 | points(1,:) cell 17 | end 18 | 19 | properties ( SetAccess = private, Dependent ) 20 | dimension_count(1,1) uint32 21 | shape(1,:) uint32 22 | origin(1,:) double 23 | end 24 | 25 | methods 26 | function obj = Grid( varargin ) 27 | assert( 1 <= nargin ); 28 | if iscell( varargin{ 1 } ) 29 | in = varargin{ 1 }; 30 | else 31 | in = varargin; 32 | end 33 | 34 | for i = 1 : nargin 35 | v = in{ i }; 36 | assert( isa( v, 'double' ) ); 37 | assert( 1 <= numel( v ) ); 38 | assert( isvector( v ) ); 39 | assert( isreal( v ) ); 40 | assert( all( isfinite( v ) ) ); 41 | if 1 < numel( v ) 42 | assert( all( 0 < diff( v ) ) ); 43 | end 44 | in{ i } = v( : ); 45 | end 46 | obj.points = in; 47 | end 48 | 49 | function value = create_zeros( obj, type ) 50 | value = zeros( obj.shape, type ); 51 | end 52 | 53 | function value = get.dimension_count( obj ) 54 | value = numel( obj.points ); 55 | end 56 | 57 | function value = get.shape( obj ) 58 | value = nan( 1, obj.dimension_count ); 59 | for i = 1 : obj.dimension_count 60 | value( i ) = numel( obj.points{ i } ); 61 | end 62 | value = uint32( value ); 63 | assert( ~any( isnan( value ) ) ); 64 | end 65 | 66 | function value = get.origin( obj ) 67 | value = nan( 1, obj.dimension_count ); 68 | for i = 1 : obj.dimension_count 69 | d = obj.points{ i }; 70 | value( i ) = d( 1 ); 71 | end 72 | assert( ~any( isnan( value ) ) ); 73 | end 74 | end 75 | 76 | methods ( Access = private ) 77 | function value = get_end( obj ) 78 | value = nan( 1, obj.dimension_count ); 79 | for i = 1 : obj.dimension_count 80 | d = obj.points{ i }; 81 | value( i ) = d( end ); 82 | end 83 | assert( ~any( isnan( value ) ) ); 84 | end 85 | end 86 | 87 | end 88 | 89 | -------------------------------------------------------------------------------- /helperfuncs/Mesh voxelization license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Adam H. Aitkenhead 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the distribution 13 | * Neither the name of the The Christie NHS Foundation Trust nor the names 14 | of its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /helperfuncs/Raster.m: -------------------------------------------------------------------------------- 1 | classdef Raster < handle 2 | % Raster is a class that implements the ray intersection method of 3 | % Patil S. and Ravi B [see Patil S and Ravi B. Voxel-based 4 | % representation, display and thickness analysis of intricate shapes. 5 | % Ninth International Conference on Computer Aided Design and Computer 6 | % Graphics (CAD/CG 2005)]. 7 | % 8 | % It is adapted and heavily modified from the original work 9 | % mesh_voxelisation by Adam H. Aitkenhead. [see 10 | % fileexchange/27390-mesh-voxelisation]. 11 | % 12 | % Inputs: 13 | % - @grid, a Grid object. 14 | % - @fv, a typical MATLAB-style FV-struct. Must be manifold and 15 | % watertight to ensure proper operation. Some corrections exist, but 16 | % should not be relied on. 17 | % - @rays, a character array containing any subset of 'xyz'. The empty 18 | % subset is replaced by 'xyz'. 19 | % 20 | % Properties: 21 | % - @interior, a 3D logical array with dimensions M x N x P, where M is 22 | % the number of elements along the grid x-axis, N along y, and P along 23 | % Z. True values represent points in the interior of @fv. 24 | % - @faces, a table with three columns. The column "indices" 25 | % represents the linear indices into @interior where ray intersections 26 | % occurred. The column "faces" represents the faces involved in the 27 | % intersections. The column "dimension" represents the ray direction 28 | % the intersection occurred along. 29 | % - @normals, a table with four columns. The column "indices" 30 | % represents the linear indices into @interior where the normal is 31 | % given for faces in @faces. The columns "x", "y", and "z" represent 32 | % the components of the normal vector along each axis. 33 | 34 | properties ( SetAccess = private ) 35 | interior(:,:,:) logical 36 | faces table 37 | end 38 | 39 | properties ( SetAccess = private, Dependent ) 40 | normals table 41 | end 42 | 43 | methods 44 | function obj = Raster( grid, fv, filename, A, v ) %, rays ) 45 | assert( isa( grid, 'Grid' ) ); 46 | assert( grid.dimension_count == 3 ); 47 | 48 | assert( isstruct( fv ) ); 49 | assert( isfield( fv, 'faces' ) ); 50 | assert( isfield( fv, 'vertices' ) ); 51 | 52 | % if isstring( rays ) 53 | % rays = char( rays ); 54 | % end 55 | % if isempty( rays ) 56 | % rays = 'xyz'; 57 | % end 58 | % assert( ischar( rays ) ); 59 | % assert( all( ismember( numel( rays ), 1 : 3 ) ) ); 60 | % assert( all( ismember( rays, 'xyz' ) ) ); 61 | 62 | mesh = convert_triangle_geometry_format( fv ); 63 | % dimensions = find( ismember( 'xyz', rays ) ); 64 | 65 | dimensions = find( 1 < cellfun( @numel, grid.points ) ); 66 | 67 | obj.grid = grid; 68 | obj.mesh = mesh; 69 | obj.dimensions = dimensions; 70 | 71 | obj.generate(); 72 | end 73 | 74 | function value = get.normals( obj ) 75 | if isempty( obj.faces ) 76 | value = table(); 77 | return; 78 | end 79 | n = compute_normals( obj.mesh ); 80 | f = obj.faces; 81 | value = f( :, : ); 82 | value.faces = []; 83 | value.dimension = []; 84 | value.x = n( f.faces, 1 ); 85 | value.y = n( f.faces, 2 ); 86 | value.z = n( f.faces, 3 ); 87 | value = varfun( ... 88 | @sum, ... 89 | value, ... 90 | 'groupingvariables', { 'indices' } ... 91 | ); 92 | value.GroupCount = []; 93 | value.Properties.VariableNames{'sum_x'} = 'x'; 94 | value.Properties.VariableNames{'sum_y'} = 'y'; 95 | value.Properties.VariableNames{'sum_z'} = 'z'; 96 | t = value{ :, { 'x' 'y' 'z' } }; 97 | v = vecnorm( t, 2, 2 ); 98 | t = t ./ v; 99 | value{ :, { 'x' 'y' 'z' } } = t; 100 | end 101 | end 102 | 103 | properties ( Access = private ) 104 | grid Grid 105 | mesh(:,3,3) double {mustBeReal,mustBeFinite} 106 | dimensions(1,:) double 107 | end 108 | 109 | methods ( Access = private ) 110 | function generate( obj ) 111 | v = false( obj.grid.shape ); 112 | f = table(); 113 | for i = obj.dimensions 114 | c = obj.cast( i ); 115 | p_inv = obj.get_inverse_permutation( i ); 116 | v = v + permute( c.interior_array, p_inv ); 117 | face_list = c.get_face_list( p_inv ); 118 | if ~isempty( face_list ) 119 | face_list.dimension(:) = i; 120 | f = [ f; face_list ]; %#ok 121 | end 122 | end 123 | v = v >= numel( obj.dimensions ) ./ 2; 124 | 125 | obj.interior = v; 126 | obj.faces = f; 127 | end 128 | 129 | function rr = cast( obj, dimension ) 130 | p = obj.get_permutation( dimension ); 131 | rr = RayRaster( ... 132 | obj.grid.points{ p }, ... 133 | obj.mesh( :, p, : ) ... 134 | ); 135 | end 136 | end 137 | 138 | properties ( Access = private, Constant ) 139 | PERMUTATIONS = [ ... 140 | 2 3 1; ... 141 | 3 1 2; ... 142 | 1 2 3 ... 143 | ]; 144 | INVERSE_PERMUTATIONS = [ ... 145 | 3 1 2; ... 146 | 2 3 1; ... 147 | 1 2 3 ... 148 | ]; 149 | end 150 | 151 | methods ( Access = private, Static ) 152 | function p = get_permutation( dimension ) 153 | p = Raster.PERMUTATIONS( dimension, : ); 154 | end 155 | 156 | function p = get_inverse_permutation( dimension ) 157 | p = Raster.INVERSE_PERMUTATIONS( dimension, : ); 158 | end 159 | end 160 | 161 | end 162 | 163 | -------------------------------------------------------------------------------- /helperfuncs/calc_mua.m: -------------------------------------------------------------------------------- 1 | function mua = calc_mua(wavelength,S,B,W,F,M) 2 | persistent muadeoxy muafat muamel muaoxy muawater musp nmLIB 3 | if isempty(muadeoxy) 4 | load('spectralLIB.mat','muadeoxy','muafat','muamel','muaoxy','muawater','musp','nmLIB'); %#ok 5 | end 6 | mua_deoxy = interp1(nmLIB,muadeoxy,wavelength); 7 | mua_fat = interp1(nmLIB,muafat,wavelength); 8 | mua_mel = interp1(nmLIB,muamel,wavelength); 9 | mua_oxy = interp1(nmLIB,muaoxy,wavelength); 10 | mua_water = interp1(nmLIB,muawater,wavelength); 11 | 12 | % Jacques "Optical properties of biological tissues: a review" eq. 12: 13 | mua = B*S*mua_oxy + B*(1-S)*mua_deoxy + W*mua_water + F*mua_fat + M*mua_mel; % Equation 12 without the bilirubin and beta-Carotene terms 14 | end -------------------------------------------------------------------------------- /helperfuncs/calc_mus.m: -------------------------------------------------------------------------------- 1 | function mus = calc_mus(wavelength,aPrime,fRay,bMie,g) 2 | fMie = 1 - fRay; 3 | musPrime= aPrime*(fRay*(wavelength/500)^(-4) + fMie*(wavelength/500)^(-bMie)); % Jacques "Optical properties of biological tissues: a review" eq. 2 4 | mus = musPrime/(1-g); 5 | end -------------------------------------------------------------------------------- /helperfuncs/compute_normals.m: -------------------------------------------------------------------------------- 1 | function normals = compute_normals( mesh ) 2 | % Modified by William Warriner 22 Aug 2019 3 | % from COMPUTE_mesh_normals by Adam H. Aitkenhead 4 | 5 | % Inputs: 6 | % - @mesh is either an FV-struct, or a real, finite, 3D double array with 7 | % dimensions (:,3,3) representing face-vertex data with only triangular 8 | % faces. The first dimension represents faces, the second represents 9 | % dimensions (x,y,z), and the third represents vertices making up the 10 | % faces. 11 | % 12 | % Outputs: 13 | % - @normals is a real, finite, double array with dimensions (:,3) 14 | % representing the normal vectors of the faces in @mesh. 15 | 16 | if isstruct( mesh ) 17 | mesh = convert_triangle_geometry_format( mesh ); 18 | end 19 | 20 | e1 = mesh( :, :, 2 ) - mesh( :, :, 1 ); 21 | e2 = mesh( :, :, 3 ) - mesh( :, :, 1 ); 22 | normals = cross( e1, e2 ); 23 | normals = normals ./ vecnorm( normals, 2, 2 ); 24 | 25 | end 26 | 27 | 28 | -------------------------------------------------------------------------------- /helperfuncs/convert_triangle_geometry_format.m: -------------------------------------------------------------------------------- 1 | function varargout = convert_triangle_geometry_format( varargin ) 2 | % Modified by William Warriner 22 Aug 2019 3 | % from CONVERT_meshformat by Adam H. Aitkenhead. 4 | 5 | % Inputs: 6 | % - @mesh, a real, finite, 3D double array with dimensions (:,3,3) 7 | % representing face-vertex data with only triangular faces. The first 8 | % dimension represents faces, the second represents dimensions (x,y,z), and 9 | % the third represents vertices making up the faces. 10 | % - OR - 11 | % - @vertices, a real, finite, 2D double array with dimensions (:,3) whose 12 | % rows represent vertices, and whose columns represent dimensions (x,y,z). 13 | % - @faces, a real, finite, positive, 2D double array with dimensions (:,3) 14 | % whose rows represent facets, and whose columns represent indices into the 15 | % rows of @vertices. 16 | % - OR - 17 | % - @fv, a struct with fields faces and vertices, which have the same 18 | % requirements as the inputs @vertices and @faces above. 19 | 20 | % Outputs: 21 | % - @mesh, as in the inputs. Output if the input is either the pair @faces 22 | % and @vertices, or the singular @fv. 23 | % - OR - 24 | % - @fv, as in the inputs. Output if the input is @mesh. 25 | 26 | assert( ismember( nargin, [ 1 2 ] ) ); 27 | 28 | first = varargin{ 1 }; 29 | if nargin == 1 && isstruct( first ) 30 | faces = first.faces; 31 | vertices = first.vertices; 32 | mesh = []; 33 | elseif nargin == 2 34 | faces = varargin{ 2 }; 35 | vertices = first; 36 | mesh = []; 37 | elseif nargin == 1 38 | faces = []; 39 | vertices = []; 40 | mesh = first; 41 | else 42 | assert( false ) 43 | end 44 | 45 | if isempty( mesh ) 46 | mesh = zeros( size( faces, 1 ), 3, 3 ); 47 | for i = 1 : size( faces, 1 ) 48 | mesh( i, :, 1 ) = vertices( faces( i, 1 ), : ); 49 | mesh( i, :, 2 ) = vertices( faces( i, 2 ), : ); 50 | mesh( i, :, 3 ) = vertices( faces( i, 3 ), : ); 51 | end 52 | varargout{ 1 } = mesh; 53 | elseif isempty( faces ) && isempty( vertices ) 54 | vertices = [ mesh( :, :, 1 ); mesh( :, :, 2 ); mesh( :, :, 3 ) ]; 55 | vertices = unique( vertices, 'rows' ); 56 | faces = zeros( size( mesh, 1 ), 3 ); 57 | for face = 1 : size( mesh, 1 ) 58 | for vertex = 1 : 3 59 | index = find( vertices( :, 1 ) == mesh( face, 1, vertex ) ); 60 | index = index( vertices( index, 2 ) == mesh( face, 2, vertex ) ); 61 | index = index( vertices( index, 3 ) == mesh( face, 3, vertex ) ); 62 | faces( face, vertex ) = index; 63 | end 64 | end 65 | fv.faces = faces; 66 | fv.vertices = vertices; 67 | varargout{ 1 } = fv; 68 | else 69 | assert( false ) 70 | end 71 | 72 | end 73 | 74 | -------------------------------------------------------------------------------- /helperfuncs/findInsideVoxels.m: -------------------------------------------------------------------------------- 1 | function inside = findInsideVoxels(X,Y,Z,filename,A,v) 2 | if ~isequal(size(A),[3 3]) 3 | error('The multiplication matrix A (argument 5) must have dimensions 3x3. If you don''t want any scaling, rotation or mirroring, you can input the identity matrix, eye(3).'); 4 | end 5 | if numel(v) ~= 3 6 | error('The translation vector v (argument 6) must be either a 1x3 or 3x1 array. If you don''t want to translate the points, you can input [0 0 0].'); 7 | end 8 | 9 | v = v(:); 10 | fv = read_stl(filename, A, v); 11 | gridObj = Grid(double(X(:,1,1)),double(Y(1,:,1)),double(squeeze(Z(1,1,:)))); 12 | rasterObj = Raster(gridObj, fv); 13 | inside = rasterObj.interior; 14 | end -------------------------------------------------------------------------------- /helperfuncs/fix_vertex_ordering.m: -------------------------------------------------------------------------------- 1 | function mesh = fix_vertex_ordering( mesh ) 2 | % Written by William Warriner 22 Aug 2019 3 | % from COMPUTE_mesh_normals by Adam H. Aitkenhead 4 | 5 | % Inputs: 6 | % - @mesh is either an FV-struct, or a real, finite, 3D double array with 7 | % dimensions (:,3,3) representing face-vertex data with only triangular 8 | % faces. The first dimension represents faces, the second represents 9 | % dimensions (x,y,z), and the third represents vertices making up the 10 | % faces. 11 | % 12 | % Outputs: 13 | % - @mesh is the same as the input, except the vertex ordering is such 14 | % that the mesh has a consistent winding. 15 | 16 | fv_out = false; 17 | if isstruct( mesh ) 18 | fv_out = true; 19 | mesh = convert_triangle_geometry_format( mesh ); 20 | end 21 | 22 | face_count = size( mesh, 1 ); 23 | warning_done = false; 24 | start = 1; 25 | point_a = 1; 26 | checked = false( face_count, 1 ); 27 | waiting = false( face_count, 1 ); 28 | while min( checked ) == 0 29 | checked( start ) = 1; 30 | point_b = point_a + 1; 31 | if point_b == 4 32 | point_b = 1; 33 | end 34 | 35 | % Find points which match point_a 36 | same_x = mesh( :, 1, : ) == mesh( start, 1, point_a ); 37 | same_y = mesh( :, 2, : ) == mesh( start, 2, point_a ); 38 | same_z = mesh( :, 3, : ) == mesh( start, 3, point_a ); 39 | [ lhs, rhs ] = find( same_x & same_y & same_z ); 40 | match_a = [ lhs, rhs ]; 41 | match_a = match_a( match_a( :, 1 ) ~= start, : ); 42 | 43 | % Find points which match edge_b 44 | same_x = mesh( :, 1, : ) == mesh( start, 1, point_b ); 45 | same_y = mesh( :, 2, : ) == mesh( start, 2, point_b ); 46 | same_z = mesh( :, 3, : ) == mesh( start, 3, point_b ); 47 | [lhs,rhs] = find( same_x & same_y & same_z ); 48 | match_b = [ lhs, rhs ]; 49 | match_b = match_b( match_b( :, 1 ) ~= start, : ); 50 | 51 | % Find edges which match both edge_a and edge_b -> adjacent edge 52 | [ member_a, member_b ] = ismember( match_a( :, 1 ), match_b( :, 1 ) ); 53 | match_face = match_a( member_a, 1 ); 54 | 55 | if numel( match_face ) ~= 1 56 | if ~warning_done 57 | warning( 'Mesh is not manifold.' ) 58 | warning_done = true; 59 | end 60 | else 61 | match_a = match_a( member_a, 2 ); 62 | match_b = match_b( member_b( member_a ), 2 ); 63 | if ~checked( match_face ) && ~waiting( match_face ) 64 | % Ensure adjacent edge traveled in opposite direction 65 | if match_b - match_a == 1 || match_b - match_a == -2 66 | [ ... 67 | mesh( match_face, :, match_a ), ... 68 | mesh( match_face, :, match_b ) ... 69 | ] = deal( ... 70 | mesh( match_face, :, match_b ), ... 71 | mesh( match_face, :, match_a ) ... 72 | ); 73 | end 74 | end 75 | end 76 | waiting( match_face ) = true; 77 | 78 | if point_a < 3 79 | point_a = point_a + 1; 80 | elseif point_a == 3 81 | point_a = 1; 82 | checked( start ) = true; 83 | start = find( waiting & ~checked, 1, 'first' ); 84 | end 85 | end 86 | 87 | if fv_out 88 | mesh = convert_triangle_geometry_format( mesh ); 89 | end 90 | 91 | end 92 | 93 | -------------------------------------------------------------------------------- /helperfuncs/initializeMCmatlabModel.m: -------------------------------------------------------------------------------- 1 | function model = initializeMCmatlabModel() 2 | 3 | model = MCmatlab.model; 4 | 5 | end -------------------------------------------------------------------------------- /helperfuncs/spectralLIB.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ankrh/MCmatlab/792f766fefa74459587db4aa728e4c2913bed8e7/helperfuncs/spectralLIB.mat -------------------------------------------------------------------------------- /version: -------------------------------------------------------------------------------- 1 | 4.4.10 --------------------------------------------------------------------------------