Incoherent Summing with Custom XY#
This is an example of using incoherent summing (‘domains’) from custom XY models.
The domain custom XY model is similar to a normal custom models, except that the input (function arguments) of the custom function contains an additional ‘domains’ parameter as described in Custom Models with Domains.
This parameter tells the function which is the current domain, so the appropriate layer stack can be generated.
This example can be run as a script or interactively using the instructions below.
Note
The custom model used is a MATLAB model - examples/domains/customXY/domainsXY.m.
Run Script:
root = getappdata(0, 'root');
cd(fullfile(root, 'examples', 'domains', 'customXY'));
domainsCustomXYScript
Run Interactively:
root = getappdata(0, 'root');
cd(fullfile(root, 'examples', 'domains', 'customXY'));
edit domainsCustomXYSheet.mlx
Simple example of a layer containing domains using a custom XY model
Domains custom XY models operate in the same way as custom layer models, in that there is an additional input to the custom model specifying the domain to be calculated....
This is then used within the function to calculate the correct SLD profile for each contrast and domain.
In this example, we simulate a hydrogenated layer on a silicon substrate, containing domains of a larger SLD, against D2O, SMW and water.
Start by making the project and adding the parameters..
problem = createProject(calcType="domains");
problem.modelType = 'custom XY';
problem.geometry = 'substrate/liquid';
% Make some parameters...
params = {{'Oxide thick', 10, 20, 50, true}
{'Layer thick', 1, 30, 500, true}
{'Layer SLD', -0.5e-6, -0.5e-6 0, true}
{'Layer rough', 2, 5, 7, true}
{'Domain rho ', 1e-6, 1e-6, 5e-6, true}};
problem.addParameterGroup(params);
..and set the SLD's of the bulk phases for our samples.
% Set the bulk SLD
problem.setBulkIn(1,'name','Silicon','Value',2.073e-6,'max',2.073e-6,'fit',false);
% Add another couple of bulk-out's
problem.addBulkOut('SLD SMW', 2e-6, 2.073e-6, 2.1e-6);
problem.addBulkOut('SLD H2O', -0.6e-6, -0.56e-6, -0.5e-6);
% and modify scalefactor for Solid / Liquid ...
problem.setScalefactor(1,'min',0.8,'Value',1,'max',1.1,'fit',true);
The custom file takes the parameters and build the model as usual, changing the SLD of the layer depending on whether we are calculating the layer (domain = 1), or the domain (domain = 2).
type domainsXY
Finally, add the custom file to the project, and make our three contrasts..
% Add the custom file...
problem.addCustomFile('Domain Layer', 'domainsXY.m', 'matlab', pwd);
% Make a contrast
problem.addContrast('name', 'D2O',...
'background', 'Background 1',...
'resolution', 'Resolution 1',...
'scalefactor', 'Scalefactor 1',...
'Bulkin', 'Silicon',...
'Bulkout', 'SLD D2O',....
'domainRatio', 'Domain Ratio 1',...
'data', 'Simulation',...
'model', 'Domain Layer');
problem.addContrast('name', 'SMW',...
'background', 'Background 1',...
'resolution', 'Resolution 1',...
'scalefactor', 'Scalefactor 1',...
'Bulkin', 'Silicon',...
'Bulkout', 'SLD SMW',....
'domainRatio', 'Domain Ratio 1',...
'data', 'Simulation',...
'model', 'Domain Layer');
problem.addContrast('name', 'H2O',...
'background', 'Background 1',...
'resolution', 'Resolution 1',...
'scalefactor', 'Scalefactor 1',...
'Bulkin', 'Silicon',...
'Bulkout', 'SLD H2O',....
'domainRatio', 'Domain Ratio 1',...
'data', 'Simulation',...
'model', 'Domain Layer');
Finally, run the simulation and plot the results....
controls = controlsClass();
[problem, results] = RAT(problem,controls);
plotRefSLD(problem,results);