Mercurial > repos > public > sbplib
comparison +scheme/bcSetup.m @ 786:18ce4b1ab3e1 bcSetupExperiment
Move verification to a separate function
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 24 Jul 2018 16:12:39 -0700 |
parents | c02b6d03c77c |
children | fef739088f20 |
comparison
equal
deleted
inserted
replaced
785:c02b6d03c77c | 786:18ce4b1ab3e1 |
---|---|
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 | 20 |
20 % Setup storage arrays | 21 % Setup storage arrays |
21 closure = spzeros(size(diffOp)); | 22 closure = spzeros(size(diffOp)); |
22 gridDataPenalties = {}; | 23 gridDataPenalties = {}; |
23 gridDataFunctions = {}; | 24 gridDataFunctions = {}; |
25 symbolicDataFunctions = {}; | 26 symbolicDataFunctions = {}; |
26 symbolicDataCoords = {}; | 27 symbolicDataCoords = {}; |
27 | 28 |
28 % Collect closures, penalties and data | 29 % Collect closures, penalties and data |
29 for i = 1:length(bcs) | 30 for i = 1:length(bcs) |
30 assertType(bcs{i}, 'struct'); | |
31 [localClosure, penalty] = diffOp.boundary_condition(bcs{i}.boundary, bcs{i}.type); | 31 [localClosure, penalty] = diffOp.boundary_condition(bcs{i}.boundary, bcs{i}.type); |
32 closure = closure + localClosure; | 32 closure = closure + localClosure; |
33 | 33 |
34 if ~isfield(bcs{i},'data') || isempty(bcs{i}.data) | 34 if ~isfield(bcs{i},'data') || isempty(bcs{i}.data) |
35 % Skip to next loop if there is no data | 35 % Skip to next loop if there is no data |
36 continue | 36 continue |
37 end | 37 end |
38 assertType(bcs{i}.data, 'function_handle'); | |
39 | 38 |
40 % Find dimension | 39 % Find dimension |
41 dim = size(diffOp.grid.getBoundary(bcs{i}.boundary), 2); | 40 dim = size(diffOp.grid.getBoundary(bcs{i}.boundary), 2); |
42 | 41 |
43 if nargin(bcs{i}.data) == 1 | 42 if nargin(bcs{i}.data) == 1 |
72 v = S_sign * v; | 71 v = S_sign * v; |
73 end | 72 end |
74 S = @S_fun; | 73 S = @S_fun; |
75 end | 74 end |
76 | 75 |
77 function parseData() | 76 function verifyBcFormat(bcs) |
77 for i = 1:length(bcs) | |
78 assertType(bcs{i}, 'struct'); | |
79 assertStructFields(bcs{i}, {'type', 'boundary'}); | |
78 | 80 |
81 if ~isfield(bcs{i}, 'data') || isempty(bcs{i}.data) | |
82 continue | |
83 end | |
84 | |
85 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); | |
87 end | |
88 end | |
79 end | 89 end |
80 |