Mercurial > repos > public > sbplib
changeset 923:d232483eb72f feature/utux2D
Remove interfaceOptions class
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Sun, 02 Dec 2018 17:19:48 -0800 |
parents | 1d91c2a8aada |
children | 93a5c59dd2fb |
files | +multiblock/DiffOp.m +multiblock/InterfaceOptions.m +multiblock/nonConformingInterfaceOptions.m |
diffstat | 3 files changed, 5 insertions(+), 247 deletions(-) [+] |
line wrap: on
line diff
diff -r 1d91c2a8aada -r d232483eb72f +multiblock/DiffOp.m --- a/+multiblock/DiffOp.m Sun Dec 02 17:10:07 2018 -0800 +++ b/+multiblock/DiffOp.m Sun Dec 02 17:19:48 2018 -0800 @@ -10,7 +10,7 @@ end methods - function obj = DiffOp(doHand, grid, order, doParam, interfaceOptions) + function obj = DiffOp(doHand, grid, order, doParam, intfOpts) % doHand -- may either be a function handle or a cell array of % function handles for each grid. The function handle(s) % should be on the form do = doHand(grid, order, ...) @@ -25,15 +25,10 @@ % doHand(..., doParam{i}{:}) Otherwise doParam is sent as % extra parameters to all doHand: doHand(..., doParam{:}) % - % interfaceOptions (optional) -- An instance of class multiblock.InterfaceOptions - % OR - % nBlocks x nBlocks cell array of opts for + % intfOpts (optional) -- nBlocks x nBlocks cell array of options for % every interface. default_arg('doParam', []) - default_arg('interfaceOptions', multiblock.InterfaceOptions(grid) ); % Empty options - if isa(interfaceOptions, 'multiblock.InterfaceOptions'); - interfaceOptions = interfaceOptions.getOptions; - end + default_arg('intfOpts', cell(grid.nBlocks(), grid.nBlocks()) ); [getHand, getParam] = parseInput(doHand, grid, doParam); @@ -74,13 +69,11 @@ continue end - intfOpts = interfaceOptions{i,j}; - - [ii, ij] = obj.diffOps{i}.interface(intf{1}, obj.diffOps{j}, intf{2}, intfOpts{1}); + [ii, ij] = obj.diffOps{i}.interface(intf{1}, obj.diffOps{j}, intf{2}, intfOpts{i,j}); D{i,i} = D{i,i} + ii; D{i,j} = D{i,j} + ij; - [jj, ji] = obj.diffOps{j}.interface(intf{2}, obj.diffOps{i}, intf{1}, intfOpts{2}); + [jj, ji] = obj.diffOps{j}.interface(intf{2}, obj.diffOps{i}, intf{1}, intfOpts{i,j}); D{j,j} = D{j,j} + jj; D{j,i} = D{j,i} + ji; end
diff -r 1d91c2a8aada -r d232483eb72f +multiblock/InterfaceOptions.m --- a/+multiblock/InterfaceOptions.m Sun Dec 02 17:10:07 2018 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -% An object of class InterfaceOptions can be passed as argument to multiblock.Diffop -% to specify details of the interface couplings. -% -% An InterfaceOptions object is essentially a cell array of options, -% equipped with methods that make it easier to change options. -classdef InterfaceOptions < handle - properties - % optsCell -- nBlocks x nBlocks cell array (same size as grid.connections) - % Must have the same sparsity pattern as grid.connections - optsCell - end - - methods - - % grid -- mutliblock.grid - % intialOpts -- cell array of interface options - function obj = InterfaceOptions(grid, initialOpts) - - default_arg('initialOpts', []); - - % If no initialOpts are given, create empty options cell. - % The cell matrix is non-empty where connections is non-empty. - if isempty(initialOpts) - opts = grid.connections; - for i = 1:numel(grid.connections) - if ~isempty(grid.connections{i}) - opts{i} = cell(1, 2); - opts{i}{1} = struct; - opts{i}{2} = struct; - end - end - - % If no grid is given, assume that initialOpts is correct and use it. - elseif isempty(grid) - opts = initialOpts; - - % Check that grid.connections and initialOpts match, and then use initialOpts. - else - assert(numel(grid.connections) == numel(initialOpts),... - 'InterfaceOptions: grid.connections and initialOpts do not match'); - opts = initialOpts; - end - obj.optsCell = opts; - end - - % Returns the cell matrix that contains the options - function opts = getOptions(obj) - opts = obj.optsCell; - end - - - % Sets the option optStr to val, for the coupling berween blocks i and j - % If i and j are omitted, all couplings get optStr = val. - % - % optStr -- string - % val -- anything - % i,j -- integers (or empty) - function setOption(obj, optStr, val, i ,j) - default_arg('i',[]); - default_arg('j',[]); - - opts = obj.optsCell; - - if isempty(i) && ~isempty(j) - error('If i is empty, j must also be empty.'); - - elseif isempty(j) && ~isempty(i) - error('If j is empty, i must also be empty.'); - - % If i and j are empty, set the option for all interfaces - elseif isempty(i) && isempty(j) - for k = 1:numel(opts) - if ~isempty(opts{k}) - opts{k}{1} = setfield(opts{k}{1}, optStr, val); - opts{k}{2} = setfield(opts{k}{2}, optStr, val); - end - end - - % Both i and j are nonempty, set property only for that interface - else - if ~isempty(opts{i,j}) - opts{i,j}{1} = setfield(opts{i,j}{1}, optStr, val); - opts{i,j}{2} = setfield(opts{i,j}{2}, optStr, val); - elseif ~isempty(opts{j,i}) - opts{j,i}{1} = setfield(opts{j,i}{1}, optStr, val); - opts{j,i}{2} = setfield(opts{j,i}{2}, optStr, val); - else - error(sprintf('Blocks %d and %d do not seem to be coupled',i,j) ); - end - end - - obj.optsCell = opts; - end - - - % Merges with another InterfaceOptions-object. - % Errors if there are merge conflicts. - % TODO: merge with preference? - function merge(obj, obj2) - localOpts = obj.getOptions(); - remoteOpts = obj2.getOptions(); - - assert( numel(localOpts) == numel(remoteOpts), ... - 'multiblock.InterfaceOptions: The two InterfaceOptions do not have the same dimension.'); - - for i = 1:numel(localOpts) - if ~isempty(remoteOpts{i}) - if isempty(localOpts{i}) - error('multiblock.InterfaceOptions: The two InterfaceOptions must have the same interface connections'); - else - for j = 1:2 - remoteStruct = remoteOpts{i}{j}; - localStruct = localOpts{i}{j}; - localFields = fieldnames(localStruct); - - % Assert the we don't have any identical field names, which would lead to overwriting - for k = 1:numel(localFields) - if isfield(remoteStruct, localFields{k}) - error('multiblock.InterfaceOptions: Cannot perform union of InterfaceOptions with common options'); - end - end - - % Take fields from remote and deal to local - remoteFields = fieldnames(remoteStruct); - for k = 1:numel(remoteFields) - name = remoteFields{k}; - val = getfield(remoteStruct, name); - localStruct = setfield(localStruct, name, val); - end - - localOpts{i}{j} = localStruct; - end - end - end - end - - obj.optsCell = localOpts; - end - - - end -end
diff -r 1d91c2a8aada -r d232483eb72f +multiblock/nonConformingInterfaceOptions.m --- a/+multiblock/nonConformingInterfaceOptions.m Sun Dec 02 17:10:07 2018 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -% g: multiblock grid -% order: cell array of the orders of accuracy used in the different blocks, -% or a scalar for the same order everywhere. -% interpOpSet: string, e.g 'MC' or 'AWW' The same interpOpSet is used everywhere. -% -% Returns an InterfaceOptions object that can be used as the 'interfaceOptions' argument to multiblock.DiffOp -function options = nonConformingInterfaceOptions(g, orders, interpOpSet) -default_arg(interpOpSet, 'AWW'); -nBlocks = g.nBlocks; -conn = g.connections; - -% If order is a scalar, the same order is used in all blocks -if ~iscell(orders) - o = orders; - orders = cell(1,nBlocks); - for i = 1:nBlocks - orders{i} = o; - end -end - -interpOpts = cell(nBlocks, nBlocks); -for i = 1:nBlocks - for j = 1:nBlocks - intf = conn{i,j}; - if isempty(intf) - continue - end - - mi = length( g.getBoundary({i, intf{1}}) ) - 1; - mj = length( g.getBoundary({j, intf{2}}) ) - 1; - - if mi == mj - % Matching grids, no interpolation required (presumably) - continue; - elseif mi/mj == 2 - % Block i is finer - - switch interpOpSet - case 'MC' - interpOpSet = sbp.InterpMC(mj+1, mi+1, orders{j}, orders{i}); - I_i2j_good = interpOpSet.IF2C; - I_i2j_bad = interpOpSet.IF2C; - I_j2i_good = interpOpSet.IC2F; - I_j2i_bad = interpOpSet.IC2F; - - case 'AWW' - interpOpSetF2C = sbp.InterpAWW(mj+1, mi+1, orders{j}, orders{i}, 'F2C'); - interpOpSetC2F = sbp.InterpAWW(mj+1, mi+1, orders{j}, orders{i}, 'C2F'); - I_i2j_good = interpOpSetF2C.IF2C; - I_i2j_bad = interpOpSetC2F.IF2C; - I_j2i_good = interpOpSetC2F.IC2F; - I_j2i_bad = interpOpSetF2C.IC2F; - end - - elseif mj/mi == 2 - % Block j is finer - - switch interpOpSet - case 'MC' - interpOpSet = sbp.InterpMC(mi+1, mj+1, orders{i}, orders{j}); - I_i2j_good = interpOpSet.IC2F; - I_i2j_bad = interpOpSet.IC2F; - I_j2i_good = interpOpSet.IF2C; - I_j2i_bad = interpOpSet.IF2C; - - case 'AWW' - interpOpSetF2C = sbp.InterpAWW(mi+1, mj+1, orders{i}, orders{j}, 'F2C'); - interpOpSetC2F = sbp.InterpAWW(mi+1, mj+1, orders{i}, orders{j}, 'C2F'); - I_i2j_good = interpOpSetC2F.IC2F; - I_i2j_bad = interpOpSetF2C.IC2F; - I_j2i_good = interpOpSetF2C.IF2C; - I_j2i_bad = interpOpSetC2F.IF2C; - end - else - error(sprintf('Interpolation operators for grid ratio %f have not yet been constructed', mi/mj)); - end - - interpOpts{i,j} = cell(2,1); - interpOpts{i,j}{1}.I_local2neighbor.good = I_i2j_good; - interpOpts{i,j}{1}.I_local2neighbor.bad = I_i2j_bad; - interpOpts{i,j}{1}.I_neighbor2local.good = I_j2i_good; - interpOpts{i,j}{1}.I_neighbor2local.bad = I_j2i_bad; - - interpOpts{i,j}{2}.I_local2neighbor.good = I_j2i_good; - interpOpts{i,j}{2}.I_local2neighbor.bad = I_j2i_bad; - interpOpts{i,j}{2}.I_neighbor2local.good = I_i2j_good; - interpOpts{i,j}{2}.I_neighbor2local.bad = I_i2j_bad; - - options = multiblock.InterfaceOptions(g, interpOpts); - - end -end -