comparison +multiblock/evalOn.m @ 806:f779b5aca5eb feature/poroelastic

Add type assertions, fix bug, edit documentation and formatting
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 27 Jul 2018 09:49:24 -0700
parents 1caeb4dffdf9
children cee0b381d714
comparison
equal deleted inserted replaced
805:1caeb4dffdf9 806:f779b5aca5eb
1 % Useful for evaulating forcing functions with different functional expressions for each block 1 % Evaluate different function handle for each block in a multiblock.Grid
2 % f: cell array of function handles fi 2 % Function handles may optionaly take a time argument
3 % f_i = f_i(x1,y,...,t) 3 % f -- cell array of function handles
4 % t: time point. If not specified, it is assumed that the functions take only spatial arguments. 4 % f{i} = f_i(x,y,...,t)
5 % t -- optional time point. If not specified, it is assumed that the functions take only spatial arguments.
5 function gf = evalOn(g, f, t) 6 function gf = evalOn(g, f, t)
6 default_arg('t',[]); 7 assertType(g, 'multiblock.Grid');
8 assertType(f, 'cell');
9
10 default_arg('t', []);
7 11
8 grids = g.grids; 12 grids = g.grids;
9 nBlocks = length(grids); 13 nBlocks = length(grids);
10 gf = cell(nBlocks,1); 14 gf = cell(nBlocks, 1);
11 15
12 if isempty(t) 16 if isempty(t)
13 for i = 1:nBlocks 17 for i = 1:nBlocks
14 grid.evalOn(grids{i}, f{i} ); 18 gf{i} = grid.evalOn(grids{i}, f{i});
15 end 19 end
16 else 20 else
17 dim = nargin(f{1}) - 1; 21 dim = nargin(f{1}) - 1;
18 for i = 1:nBlocks 22 for i = 1:nBlocks
19 switch dim 23 switch dim
20 case 1 24 case 1
21 gf{i} = grid.evalOn(grids{i}, @(x)f{i}(x,t) ); 25 gf{i} = grid.evalOn(grids{i}, @(x)f{i}(x,t));
22 case 2 26 case 2
23 gf{i} = grid.evalOn(grids{i}, @(x,y)f{i}(x,y,t) ); 27 gf{i} = grid.evalOn(grids{i}, @(x,y)f{i}(x,y,t));
24 case 3 28 case 3
25 gf{i} = grid.evalOn(grids{i}, @(x,y,z)f{i}(x,y,z,t) ); 29 gf{i} = grid.evalOn(grids{i}, @(x,y,z)f{i}(x,y,z,t));
26 end 30 end
27 end 31 end
28 end 32 end
29 33
30 gf = blockmatrix.toMatrix(gf); 34 gf = blockmatrix.toMatrix(gf);