comparison +scheme/bcSetup.m @ 943:21394c78c72e feature/utux2D

Merge with default
author Martin Almquist <malmquist@stanford.edu>
date Tue, 04 Dec 2018 15:24:36 -0800
parents b45a6dcb61ac
children 386ef449df51
comparison
equal deleted inserted replaced
942:35701c85e356 943:21394c78c72e
1 % function [closure, S] = bcSetup(diffOp, bc)
2 % Takes a diffOp and a cell array of boundary condition definitions. 1 % Takes a diffOp and a cell array of boundary condition definitions.
3 % Each bc is a struct with the fields 2 % Each bc is a struct with the fields
4 % * type -- Type of boundary condition 3 % * type -- Type of boundary condition
5 % * boundary -- Boundary identifier 4 % * boundary -- Boundary identifier
6 % * data -- A function_handle with time and space coordinates as a parameters, for example f(t,x,y) for a 2D problem 5 % * data -- A function_handle for a function which provides boundary data.(see below)
7 % Also takes S_sign which modifies the sign of S, [-1,1] 6 % Also takes S_sign which modifies the sign of the penalty function, [-1,1]
8 % Returns a closure matrix and a forcing function S 7 % Returns a closure matrix and a forcing function S.
9 function [closure, S] = bcSetup(diffOp, bc, S_sign) 8 %
9 % The boundary data function can either be a function of time or a function of time and space coordinates.
10 % In the case where it only depends on time it should return the data as grid function for the boundary.
11 % In the case where it also takes space coordinates the number of space coordinates should match the number of dimensions of the problem domain.
12 % For example in the 2D case: f(t,x,y).
13 function [closure, S] = bcSetup(diffOp, bcs, S_sign)
10 default_arg('S_sign', 1); 14 default_arg('S_sign', 1);
11 assertType(bc, 'cell'); 15 assertType(bcs, 'cell');
12 assert(S_sign == 1 || S_sign == -1, 'S_sign must be either 1 or -1'); 16 assert(S_sign == 1 || S_sign == -1, 'S_sign must be either 1 or -1');
13 17
14 18 [closure, penalties] = scheme.bc.closureSetup(diffOp, bcs);
15 closure = spzeros(size(diffOp)); 19 S = scheme.bc.forcingSetup(diffOp, penalties, bcs, S_sign);
16 penalties = {};
17 dataFunctions = {};
18 dataParams = {};
19
20 for i = 1:length(bc)
21 assertType(bc{i}, 'struct');
22 [localClosure, penalty] = diffOp.boundary_condition(bc{i}.boundary, bc{i}.type);
23 closure = closure + localClosure;
24
25 if isempty(bc{i}.data)
26 continue
27 end
28 assertType(bc{i}.data, 'function_handle');
29
30 coord = diffOp.grid.getBoundary(bc{i}.boundary);
31 assertNumberOfArguments(bc{i}.data, 1+size(coord,2));
32
33 penalties{end+1} = penalty;
34 dataFunctions{end+1} = bc{i}.data;
35 dataParams{end+1} = num2cell(coord ,1);
36 end
37
38 O = spzeros(size(diffOp),1);
39 function v = S_fun(t)
40 v = O;
41 for i = 1:length(dataFunctions)
42 v = v + penalties{i}*dataFunctions{i}(t, dataParams{i}{:});
43 end
44
45 v = S_sign * v;
46 end
47 S = @S_fun;
48 end 20 end