Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion API/checkIndices.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function checkIndices(problemStruct, customFiles)
numDomainRatios = length(problemStruct.domainRatios);
for i = 1:length(problemStruct.contrastDomainRatios)
index = problemStruct.contrastDomainRatios(i);
if (index < 1 && index ~= -1) || index > numDomainRatios
if index < 1 || index > numDomainRatios
throw(exceptions.indexOutOfRange(sprintf('contrastDomainRatios(%i) is %i, which is outside the range of domainRatio', i, index)));
end
end
Expand Down
4 changes: 2 additions & 2 deletions API/parseClassToStructs.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@
if isa(project, 'domainsClass')
problemStruct.domainRatios = inputStruct.domainRatioValues;
else
problemStruct.domainRatios = ones(1,0);
problemStruct.domainRatios = zeros(1,1);
end

if isa(project, 'domainsClass') && isa(project.domainContrasts, 'domainContrastsClass')
problemStruct.numberOfDomainContrasts = inputStruct.numberOfDomainContrasts;
problemStruct.domainContrastLayers = inputStruct.domainContrastLayers;
else
problemStruct.numberOfDomainContrasts = 0;
problemStruct.domainContrastLayers = cell(1, 0);
problemStruct.domainContrastLayers = cell(1,0);
end

% Initialise the lists of fitting parameters
Expand Down
4 changes: 1 addition & 3 deletions API/projectClass/contrastsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
contrastBackgroundActions = cell(1,nContrasts);
contrastBulkIns = ones(1,nContrasts);
contrastBulkOuts = ones(1,nContrasts);
contrastDomainRatios = zeros(1,nContrasts);
contrastDomainRatios = ones(1,nContrasts);
contrastScalefactors = ones(1,nContrasts);
contrastResolutions = ones(1,nContrasts);
resample = ones(1,nContrasts);
Expand Down Expand Up @@ -123,8 +123,6 @@

if isfield(thisContrast, 'domainRatio')
contrastDomainRatios(i) = obj.findParameterIndex(thisContrast.domainRatio, allowedNames.domainRatioNames, "domain ratio");
else
contrastDomainRatios(i) = -1;
end

contrastBackgrounds(i) = obj.findParameterIndex(thisContrast.background, allowedNames.backgroundNames, "background");
Expand Down
87 changes: 40 additions & 47 deletions targetFunctions/+domainsTF/domainsReflectivity.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function [reflectivity,simulation,shiftedData,backgrounds,resolutions,...
domainSldProfiles,domainLayers,domainResampledLayers,qzshifts,...
scalefactors,bulkIns,bulkOuts,subRoughs,chis...
] = domainsReflectivity(problemStruct,controls)
sldProfiles,layers,resampledLayers,qzshifts,scalefactors,bulkIns,...
bulkOuts,subRoughs,chis] = domainsReflectivity(problemStruct,controls)
% This is the main domains reflectivity calculation.
% It extracts the required parameters for the contrasts
% from the input arrays, then passes the main calculation to
Expand All @@ -11,13 +10,12 @@

% Extract parameters from problemStruct
[numberOfContrasts, geometry, contrastBackgroundIndices,...
contrastResolutionIndices, contrastDomainRatioIndices, backgroundParamValues,...
resolutionParamValues, qzshifts, scalefactors, bulkIns, bulkOuts,...
domainRatioValues, dataPresent, nParams, paramValues, resample,...
contrastBackgroundTypes, contrastBackgroundActions,...
contrastResolutionIndices, backgroundParamValues, resolutionParamValues,...
qzshifts, scalefactors, bulkIns, bulkOuts, domainRatios, dataPresent,...
nParams, paramValues, resample, contrastBackgroundTypes, contrastBackgroundActions,...
contrastResolutionTypes, contrastCustomFiles, useImaginary, repeatLayers,...
data, dataLimits, simulationLimits, inputContrastLayers, layersDetails,...
customFiles, domainContrastLayers] = extractProblemParams(problemStruct);
data, dataLimits, simulationLimits, inputContrastLayers, customFiles,...
domainContrastLayers] = extractProblemParams(problemStruct);

calcSld = controls.calcSldDuringFit;
parallel = controls.parallel;
Expand All @@ -26,7 +24,6 @@
resampleNPoints = controls.resampleNPoints;

% Allocate the memory for the output arrays before the main loop
domainRatios = zeros(numberOfContrasts,1);
subRoughs = zeros(numberOfContrasts,1);
chis = zeros(numberOfContrasts,1);

Expand All @@ -35,21 +32,20 @@
shiftedData = cell(numberOfContrasts,1);
backgrounds = cell(numberOfContrasts,1);
resolutions = cell(numberOfContrasts,1);

domainSldProfiles = cell(numberOfContrasts,2);
domainLayers = cell(numberOfContrasts,2);
domainResampledLayers = cell(numberOfContrasts,2);

sldProfiles = cell(numberOfContrasts,1);
layers = cell(numberOfContrasts,1);
resampledLayers = cell(numberOfContrasts,1);
sldProfiles = cell(numberOfContrasts,2);
layers = cell(numberOfContrasts,2);
resampledLayers = cell(numberOfContrasts,2);

contrastLayers1 = cell(numberOfContrasts,1);
contrastLayers2 = cell(numberOfContrasts,1);

contrastSlds1 = cell(numberOfContrasts,1);
contrastSlds2 = cell(numberOfContrasts,1);

domainSldProfiles = cell(numberOfContrasts,1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the reason for the name flip is to sync this function with the normal? but its confusing to see the domiains... variables have a single column. Don't know if we can rename to something else

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the reason I switched them. For matlab coder we have to have them as a variable with up to two columns so I'm not sure there's much we can do.

domainLayers = cell(numberOfContrasts,1);
domainResampledLayers = cell(numberOfContrasts,1);

for i = 1:numberOfContrasts

shiftedData{i} = zeros(1,3);
Expand All @@ -63,17 +59,12 @@
contrastSlds1{i} = zeros(1,3);
contrastSlds2{i} = zeros(1,3);

domainLayers{i,1} = zeros(1,6);
domainLayers{i,2} = zeros(1,6);
layers{i,1} = zeros(1,6);
layers{i,2} = zeros(1,6);

domainResampledLayers{i,1} = zeros(1,6);
domainResampledLayers{i,2} = zeros(1,6);
resampledLayers{i,1} = zeros(1,6);
resampledLayers{i,2} = zeros(1,6);

% Get the domain ratio for this contrast
if isempty(contrastDomainRatioIndices(i))
contrastDomainRatioIndices(i) = 1;
end
domainRatios(i) = domainRatioValues(contrastDomainRatioIndices(i));
end

%% Obtain model specific parameters
Expand All @@ -86,7 +77,7 @@
% parameters to all the layers in the layers list. This only
% needs to be done once, and so is done outside the contrasts
% loop
layerValues = allocateParamsToLayers(paramValues, layersDetails);
layerValues = allocateParamsToLayers(paramValues, problemStruct.layersDetails);

for i = 1:numberOfContrasts

Expand Down Expand Up @@ -145,12 +136,13 @@
data{i},dataLimits{i},simulationLimits{i},numSimulationPoints);

[reflectivity{i},simulation{i},shiftedData{i},...
sldProfiles{i},layers{i},resampledLayers{i},...
chis(i)] = contrastCustomXYCalculation(bulkIns(i),...
bulkOuts(i),domainRatios(i),shiftedData{i},simulationXData,...
dataIndices,backgrounds{i},resolutions{i},...
contrastBackgroundActions{i},nParams,parallel,resampleMinAngle,...
resampleNPoints,subRoughs(i),contrastSlds1{i},contrastSlds2{i});
domainSldProfiles{i},domainLayers{i},...
domainResampledLayers{i},chis(i)...
] = contrastCustomXYCalculation(bulkIns(i),bulkOuts(i),...
domainRatios(i),shiftedData{i},simulationXData,dataIndices,...
backgrounds{i},resolutions{i},contrastBackgroundActions{i},...
nParams,parallel,resampleMinAngle,resampleNPoints,...
subRoughs(i),contrastSlds1{i},contrastSlds2{i});

end

Expand All @@ -168,12 +160,13 @@
data{i},dataLimits{i},simulationLimits{i},numSimulationPoints);

[reflectivity{i},simulation{i},shiftedData{i},...
sldProfiles{i},layers{i},resampledLayers{i},...
chis(i)] = contrastCustomXYCalculation(bulkIns(i),...
bulkOuts(i),domainRatios(i),shiftedData{i},simulationXData,...
dataIndices,backgrounds{i},resolutions{i},...
contrastBackgroundActions{i},nParams,parallel,resampleMinAngle,...
resampleNPoints,subRoughs(i),contrastSlds1{i},contrastSlds2{i});
domainSldProfiles{i},domainLayers{i},...
domainResampledLayers{i},chis(i)...
] = contrastCustomXYCalculation(bulkIns(i),bulkOuts(i),...
domainRatios(i),shiftedData{i},simulationXData,dataIndices,...
backgrounds{i},resolutions{i},contrastBackgroundActions{i},...
nParams,parallel,resampleMinAngle,resampleNPoints,...
subRoughs(i),contrastSlds1{i},contrastSlds2{i});

end

Expand All @@ -195,7 +188,7 @@
data{i},dataLimits{i},simulationLimits{i},numSimulationPoints);

[reflectivity{i},simulation{i},shiftedData{i},...
sldProfiles{i},layers{i},resampledLayers{i},...
domainSldProfiles{i},domainLayers{i},domainResampledLayers{i},...
chis(i)] = contrastLayersCalculation(bulkIns(i),bulkOuts(i),...
domainRatios(i),shiftedData{i},simulationXData,dataIndices,...
backgrounds{i},resolutions{i},repeatLayers(i),...
Expand All @@ -220,7 +213,7 @@
data{i},dataLimits{i},simulationLimits{i},numSimulationPoints);

[reflectivity{i},simulation{i},shiftedData{i},...
sldProfiles{i},layers{i},resampledLayers{i},...
domainSldProfiles{i},domainLayers{i},domainResampledLayers{i},...
chis(i)] = contrastLayersCalculation(bulkIns(i),bulkOuts(i),...
domainRatios(i),shiftedData{i},simulationXData,dataIndices,...
backgrounds{i},resolutions{i},repeatLayers(i),...
Expand All @@ -236,18 +229,18 @@

for i = 1:numberOfContrasts
for j = 1:2
domainSldProfiles{i,j} = sldProfiles{i}{j};
domainLayers{i,j} = layers{i}{j};
domainResampledLayers{i,j} = resampledLayers{i}{j};
sldProfiles{i,j} = domainSldProfiles{i}{j};
layers{i,j} = domainLayers{i}{j};
resampledLayers{i,j} = domainResampledLayers{i}{j};
end
end

% Remove dummy imaginary column if present
if ~useImaginary
for i=1:numberOfContrasts
for j = 1:2
domainLayers{i,j}(:,3) = [];
domainResampledLayers{i,j}(:,3) = [];
layers{i,j}(:,3) = [];
resampledLayers{i,j}(:,3) = [];
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions targetFunctions/+normalTF/normalReflectivity.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

% Extract parameters from problemStruct
[numberOfContrasts, geometry, contrastBackgroundIndices,...
contrastResolutionIndices, ~, backgroundParamValues, resolutionParamValues,...
contrastResolutionIndices, backgroundParamValues, resolutionParamValues,...
qzshifts, scalefactors, bulkIns, bulkOuts, ~, dataPresent, nParams,...
paramValues, resample, contrastBackgroundTypes, contrastBackgroundActions,...
contrastResolutionTypes, contrastCustomFiles, useImaginary, repeatLayers,...
data, dataLimits, simulationLimits, contrastLayersIndices, layersDetails,...
customFiles, ~] = extractProblemParams(problemStruct);
data, dataLimits, simulationLimits, contrastLayersIndices, customFiles,...
~] = extractProblemParams(problemStruct);

calcSld = controls.calcSldDuringFit;
parallel = controls.parallel;
Expand Down Expand Up @@ -57,7 +57,7 @@
% parameters to all the layers in the layers list. This only
% needs to be done once, and so is done outside the contrasts
% loop
layerValues = allocateParamsToLayers(paramValues, layersDetails);
layerValues = allocateParamsToLayers(paramValues, problemStruct.layersDetails);

for i = 1:numberOfContrasts

Expand Down
14 changes: 8 additions & 6 deletions targetFunctions/common/extractProblemParams.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function [numberOfContrasts, geometry, contrastBackgroundParams,...
contrastResolutionParams, contrastDomainRatios, backgroundParams, resolutionParams, qzshifts, scalefactors, bulkIns, bulkOuts,...
domainRatios, dataPresent, nParams, params, resample, contrastBackgroundTypes, contrastBackgroundActions, contrastResolutionTypes,...
contrastCustomFiles, useImaginary, repeatLayers, data, dataLimits, simulationLimits, contrastLayers, layersDetails, customFiles, domainContrastLayers] = extractProblemParams(problemStruct)
contrastResolutionParams, backgroundParams, resolutionParams, qzshifts,...
scalefactors, bulkIns, bulkOuts, domainRatios, dataPresent, nParams, params,...
resample, contrastBackgroundTypes, contrastBackgroundActions, contrastResolutionTypes,...
contrastCustomFiles, useImaginary, repeatLayers, data, dataLimits, simulationLimits,...
contrastLayers, customFiles, domainContrastLayers] = extractProblemParams(problemStruct)

resample = problemStruct.resample;
data = problemStruct.data;
Expand All @@ -17,16 +19,13 @@
contrastBackgroundActions = problemStruct.contrastBackgroundActions;
contrastResolutionParams = problemStruct.contrastResolutionParams;
contrastResolutionTypes = problemStruct.contrastResolutionTypes;
contrastDomainRatios = problemStruct.contrastDomainRatios;
backgroundParams = problemStruct.backgroundParams;
resolutionParams = problemStruct.resolutionParams;
nParams = length(problemStruct.params);
params = problemStruct.params;
contrastLayers = problemStruct.contrastLayers;
customFiles = problemStruct.customFiles;
contrastCustomFiles = problemStruct.contrastCustomFiles;
layersDetails = problemStruct.layersDetails;
domainRatios = problemStruct.domainRatios;
domainContrastLayers = problemStruct.domainContrastLayers;


Expand All @@ -38,15 +37,18 @@
contrastScalefactors = problemStruct.contrastScalefactors;
contrastBulkIns = problemStruct.contrastBulkIns;
contrastBulkOuts = problemStruct.contrastBulkOuts;
contrastDomainRatios = problemStruct.contrastDomainRatios;

scalefactorValues = problemStruct.scalefactors;
bulkInValues = problemStruct.bulkIns;
bulkOutValues = problemStruct.bulkOuts;
domainRatioValues = problemStruct.domainRatios;

% Find the actual values from the indices given in each contrast
qzshifts = qzshiftValues(contrastQzshifts)';
scalefactors = scalefactorValues(contrastScalefactors)';
bulkIns = bulkInValues(contrastBulkIns)';
bulkOuts = bulkOutValues(contrastBulkOuts)';
domainRatios = domainRatioValues(contrastDomainRatios)';

end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYInputs.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
% (c) TF Parameters
[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,...
layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis...
] = normalTF.normalReflectivity(problemStruct,controls);
] = domainsTF.domainsReflectivity(problemStruct,controls);

TFParams.reflectivity = reflectivity;
TFParams.simulation = simulation;
Expand Down Expand Up @@ -99,7 +99,7 @@
% (c) TF Parameters
[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,...
layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis...
] = normalTF.normalReflectivity(problemStruct,controls);
] = domainsTF.domainsReflectivity(problemStruct,controls);

TFParams.reflectivity = reflectivity;
TFParams.simulation = simulation;
Expand Down Expand Up @@ -155,7 +155,7 @@
% (c) TF Parameters
[reflectivity,simulation,shiftedData,backgrounds,resolutions,sldProfiles,...
layers,resampledLayers,qzshifts,scalefactors,bulkIn,bulkOut,subRoughs,chis...
] = normalTF.normalReflectivity(problemStruct,controls);
] = domainsTF.domainsReflectivity(problemStruct,controls);

TFParams.reflectivity = reflectivity;
TFParams.simulation = simulation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,26 @@ function testCheckIndices(testCase)
end

function testExtractProblemParams(testCase)
[numberOfContrasts, geometry, contrastBackgroundParams, contrastResolutionParams, contrastDomainRatios, backgroundParams, resolutionParams,...
[numberOfContrasts, geometry, contrastBackgroundParams, contrastResolutionParams, backgroundParams, resolutionParams,...
~, scalefactors, bulkIns, bulkOuts, domainRatios, dataPresent, nParams, params, resample, backgroundTypes, backgroundActions, resolutionTypes,...
contrastCustomFiles, useImaginary, repeatLayers, data, dataLimits, simulationLimits, contrastLayers, layersDetails, customFiles, domainContrastLayers...
contrastCustomFiles, useImaginary, repeatLayers, data, dataLimits, simulationLimits, contrastLayers, customFiles, domainContrastLayers...
] = extractProblemParams(testCase.problemStruct);

testScalefactors = testCase.problemStruct.scalefactors(testCase.problemStruct.contrastScalefactors)';
testBulkIns = testCase.problemStruct.bulkIns(testCase.problemStruct.contrastBulkIns)';
testBulkOuts = testCase.problemStruct.bulkOuts(testCase.problemStruct.contrastBulkOuts)';
testDomainRatios = testCase.problemStruct.domainRatios(testCase.problemStruct.contrastDomainRatios)';

testCase.verifyEqual(numberOfContrasts, testCase.problemStruct.numberOfContrasts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(geometry, testCase.problemStruct.geometry, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(contrastBackgroundParams, testCase.problemStruct.contrastBackgroundParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(contrastResolutionParams, testCase.problemStruct.contrastResolutionParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(contrastDomainRatios, testCase.problemStruct.contrastDomainRatios, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(backgroundParams, testCase.problemStruct.backgroundParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(resolutionParams, testCase.problemStruct.resolutionParams, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(scalefactors, testScalefactors, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(bulkIns, testBulkIns, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(bulkOuts, testBulkOuts, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(domainRatios, testCase.problemStruct.domainRatios, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(domainRatios, testDomainRatios, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(dataPresent, testCase.problemStruct.dataPresent, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(nParams, length(testCase.problemStruct.params), 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(params, testCase.problemStruct.params, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
Expand All @@ -288,7 +288,6 @@ function testExtractProblemParams(testCase)
testCase.verifyEqual(dataLimits, testCase.problemStruct.dataLimits, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(simulationLimits, testCase.problemStruct.simulationLimits, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(contrastLayers, testCase.problemStruct.contrastLayers, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(layersDetails, testCase.problemStruct.layersDetails, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(customFiles, testCase.problemStruct.customFiles, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);
testCase.verifyEqual(domainContrastLayers, testCase.problemStruct.domainContrastLayers, 'RelTol', testCase.tolerance, 'AbsTol', testCase.absTolerance);

Expand Down
Binary file modified tests/normalTFReflectivityCalculation/absorptionInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/absorptionOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/absorptionTFParams.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customLayersInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customLayersOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customLayersTFParams.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customXYInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customXYOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/customXYTFParams.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/standardLayersInputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/standardLayersOutputs.mat
Binary file not shown.
Binary file modified tests/normalTFReflectivityCalculation/standardLayersTFParams.mat
Binary file not shown.
Loading