Mercurial > repos > public > sbplib
comparison +scheme/+bc/forcingSetup.m @ 877:7ceaea27d944 bcSetupExperiment
Clean up bc.forcingSetup
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 01 Nov 2018 16:01:33 +0100 |
parents | 93489ddb73e8 |
children | 51cc7b05b4ab |
comparison
equal
deleted
inserted
replaced
876:93489ddb73e8 | 877:7ceaea27d944 |
---|---|
1 % Setup the forcing function for the given boundary conditions and data. | |
2 % S_sign allows changing the sign of the function to put on different sides in the system of ODEs. | |
3 % default is 1, which the same side as the diffOp. | |
1 function S = forcingSetup(diffOp, penalties, bcs, S_sign) | 4 function S = forcingSetup(diffOp, penalties, bcs, S_sign) |
2 default_arg('S_sign', 1); | 5 default_arg('S_sign', 1); |
3 | 6 |
4 assertType(bcs, 'cell'); | 7 assertType(bcs, 'cell'); |
5 assertIsMember(S_sign, [1, -1]); | 8 assertIsMember(S_sign, [1, -1]); |
6 | 9 |
7 scheme.bc.verifyFormat(bcs, diffOp); | 10 scheme.bc.verifyFormat(bcs, diffOp); |
8 | 11 |
9 % % Setup storage arrays | 12 [gridData, symbolicData] = parseAndSortData(bcs, penalties, diffOp); |
10 % closure = spzeros(size(diffOp)); | |
11 % gridData = {}; | |
12 % symbolicData = {}; | |
13 | |
14 % Loop over bcs and collect data | |
15 for i = 1:length(bcs) | |
16 % [ok, isSym, data] = parseData(bcs{i}, penalties{i}, diffOp.grid) | |
17 | |
18 % if ~ok | |
19 % % There was no data | |
20 % continue | |
21 % end | |
22 | |
23 % if isSym | |
24 % gridData{end+1} = data; | |
25 % else | |
26 % symbolicData{end+1} = data; | |
27 % end | |
28 end | |
29 | |
30 | 13 |
31 % Setup penalty function | 14 % Setup penalty function |
32 O = spzeros(size(diffOp),1); | 15 O = spzeros(size(diffOp),1); |
33 function v = S_fun(t) | 16 function v = S_fun(t) |
34 v = O; | 17 v = O; |
41 end | 24 end |
42 | 25 |
43 v = S_sign * v; | 26 v = S_sign * v; |
44 end | 27 end |
45 S = @S_fun; | 28 S = @S_fun; |
29 end | |
30 | |
31 % Go through a cell array of boundary condition specifications and return cell arrays | |
32 % of structs for grid and symbolic data. | |
33 function [gridData, symbolicData] = parseAndSortData(bcs, penalties, diffOp) | |
34 for i = 1:length(bcs) | |
35 [ok, isSymbolic, data] = parseData(bcs{i}, penalties{i}, diffOp.grid) | |
36 | |
37 if ~ok | |
38 continue % There was no data | |
39 end | |
40 | |
41 if isSymbolic | |
42 gridData{end+1} = data; | |
43 else | |
44 symbolicData{end+1} = data; | |
45 end | |
46 end | |
46 end | 47 end |
47 | 48 |
48 function [ok, isSymbolic, dataStruct] = parseData(bc, penalty, grid) | 49 function [ok, isSymbolic, dataStruct] = parseData(bc, penalty, grid) |
49 if ~isfield(bc,'data') || isempty(bc.data) | 50 if ~isfield(bc,'data') || isempty(bc.data) |
50 isSymbolic = []; | 51 isSymbolic = []; |