comparison +scheme/bcSetup.m @ 787:fef739088f20 bcSetupExperiment

Move more stuff into verifyFormat
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 24 Jul 2018 16:27:36 -0700
parents 18ce4b1ab3e1
children b3ea4cccaf15
comparison
equal deleted inserted replaced
786:18ce4b1ab3e1 787:fef739088f20
14 function [closure, S] = bcSetup(diffOp, bcs, S_sign) 14 function [closure, S] = bcSetup(diffOp, bcs, S_sign)
15 default_arg('S_sign', 1); 15 default_arg('S_sign', 1);
16 assertType(bcs, 'cell'); 16 assertType(bcs, 'cell');
17 assert(S_sign == 1 || S_sign == -1, 'S_sign must be either 1 or -1'); 17 assert(S_sign == 1 || S_sign == -1, 'S_sign must be either 1 or -1');
18 18
19 verifyBcFormat(bcs); 19 verifyBcFormat(bcs, diffOp);
20 20
21 % Setup storage arrays 21 % Setup storage arrays
22 closure = spzeros(size(diffOp)); 22 closure = spzeros(size(diffOp));
23 gridDataPenalties = {}; 23 gridDataPenalties = {};
24 gridDataFunctions = {}; 24 gridDataFunctions = {};
39 % Find dimension 39 % Find dimension
40 dim = size(diffOp.grid.getBoundary(bcs{i}.boundary), 2); 40 dim = size(diffOp.grid.getBoundary(bcs{i}.boundary), 2);
41 41
42 if nargin(bcs{i}.data) == 1 42 if nargin(bcs{i}.data) == 1
43 % Grid data 43 % Grid data
44 boundarySize = [size(diffOp.grid.getBoundary(bcs{i}.boundary),1),1];
45 assertSize(bcs{i}.data(0), boundarySize); % Eval for t = 0 and make sure the function returns a grid vector of the correct size.
46 gridDataPenalties{end+1} = penalty; 44 gridDataPenalties{end+1} = penalty;
47 gridDataFunctions{end+1} = bcs{i}.data; 45 gridDataFunctions{end+1} = bcs{i}.data;
48 elseif nargin(bcs{i}.data) == 1+dim 46 elseif nargin(bcs{i}.data) == 1+dim
49 % Symbolic data 47 % Symbolic data
50 coord = diffOp.grid.getBoundary(bcs{i}.boundary); 48 coord = diffOp.grid.getBoundary(bcs{i}.boundary);
51 symbolicDataPenalties{end+1} = penalty; 49 symbolicDataPenalties{end+1} = penalty;
52 symbolicDataFunctions{end+1} = bcs{i}.data; 50 symbolicDataFunctions{end+1} = bcs{i}.data;
53 symbolicDataCoords{end+1} = num2cell(coord ,1); 51 symbolicDataCoords{end+1} = num2cell(coord ,1);
54 else
55 error('sbplib:scheme:bcSetup:DataWrongNumberOfArguments', 'bcs{%d}.data has the wrong number of input arguments. Must be either only time or time and space.', i);
56 end 52 end
57 end 53 end
58 54
59 % Setup penalty function 55 % Setup penalty function
60 O = spzeros(size(diffOp),1); 56 O = spzeros(size(diffOp),1);
71 v = S_sign * v; 67 v = S_sign * v;
72 end 68 end
73 S = @S_fun; 69 S = @S_fun;
74 end 70 end
75 71
76 function verifyBcFormat(bcs) 72 function verifyBcFormat(bcs, diffOp)
77 for i = 1:length(bcs) 73 for i = 1:length(bcs)
78 assertType(bcs{i}, 'struct'); 74 assertType(bcs{i}, 'struct');
79 assertStructFields(bcs{i}, {'type', 'boundary'}); 75 assertStructFields(bcs{i}, {'type', 'boundary'});
80 76
81 if ~isfield(bcs{i}, 'data') || isempty(bcs{i}.data) 77 if ~isfield(bcs{i}, 'data') || isempty(bcs{i}.data)
83 end 79 end
84 80
85 if ~isa(bcs{i}.data, 'function_handle') 81 if ~isa(bcs{i}.data, 'function_handle')
86 error('bcs{%d}.data should be a function of time or a function of time and space',i); 82 error('bcs{%d}.data should be a function of time or a function of time and space',i);
87 end 83 end
84
85 b = diffOp.grid.getBoundary(bc.boundart);
86
87 dim = size(b,2);
88
89 if nargin(bc.data) == 1
90 % Grid data (only function of time)
91 assertSize(bc.data(0), 1, size(b));
92 elseif nargin(bc.data) ~= 1+dim
93 error('sbplib:scheme:bcSetup:DataWrongNumberOfArguments', 'bcs{%d}.data has the wrong number of input arguments. Must be either only time or time and space.', i);
94 end
88 end 95 end
89 end 96 end