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

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....
functionStart.png
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
function [SLD, subRough] = domainsXY(params,bulk_in,bulk_out,contrast,domain) debugPlot = false; % optional debug plot % Split up the parameters for convenience... subRough = params(1); oxideThick = params(2); layerThick = params(3); layerSLD = params(4); layerRough = params(5); domainSLD = params(6); % Make an array of z values for our model... z = 0:1:140; % Make the volume fraction distribution for our Silicon substrate.... [vfSilicon, siSurf] = makeLayer(z,-25,50,1,subRough,subRough); % ..and the Oxide.... [vfOxide, oxSurface] = makeLayer(z,siSurf,oxideThick,1,subRough,subRough); % ..also our layer. [vfLayer, laySurface] = makeLayer(z,oxSurface,layerThick,1,subRough,layerRough); % Evereything that is not already occupied will be filled will water.. totalVF = vfSilicon + vfOxide + vfLayer; vfWater = 1 - totalVF; % Now convert the Volume Fractions to SLD's... siSLD = vfSilicon * bulk_in; oxSLD = vfOxide * 3.41e-6; % Layer SLD depends on whether we are calculating the domain or not... switch domain case 1 laySLD = vfLayer * layerSLD; otherwise laySLD = vfLayer * domainSLD; end %...finally the water. waterSLD = vfWater * bulk_out(contrast); % Make the total SLD by just adding them all up.. totalSLD = siSLD + oxSLD + laySLD + waterSLD; % The output is just a [n x 2] array of z against SLD.. SLD = [z(:) totalSLD(:)]; % (optional debug plot.....) if debugPlot figure(1); clf; subplot(2,1,1); plot(z,vfSilicon(:)); hold on plot(z,vfOxide(:)); plot(z,vfLayer(:)); plot(z,vfWater(:)); title('Volume Fractions') subplot(2,1,2) plot(z,siSLD(:)); hold on plot(z,oxSLD(:)); plot(z,laySLD(:)); plot(z,waterSLD(:)); hold on plot(z,totalSLD,'k-','LineWidth',2); title('SLDs') end end % ------------------------------------------------------------------------- function [VF, thisLaySurf] = makeLayer(z, prevLaySurf, thickness,.... height, Sigma_L, Sigma_R) % This procudes a layer, with a defined thickness, height and roughness. % Each side of the layer has it's own roughness value % Find the edges..... l = prevLaySurf; r = prevLaySurf + thickness; % Make our heaviside a = (z-l)./((2^0.5) * Sigma_L); b = (z-r)./((2^0.5) * Sigma_R); VF = (height/2)*(erf(a)-erf(b)); thisLaySurf = r; end
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);
Starting RAT ________________________________________________________________________________________________ Elapsed time is 0.081115 seconds. Finished RAT ______________________________________________________________________________________________
 
plotRefSLD(problem,results);