comparison +grid/blockEvalOn.m @ 736:d991f8a0b61c feature/poroelastic

Add grid.blockEvalOn for functions with different functional expressions for different grid blocks
author Martin Almquist <malmquist@stanford.edu>
date Wed, 25 Apr 2018 14:56:17 -0700
parents
children
comparison
equal deleted inserted replaced
735:eac5fb4b63db 736:d991f8a0b61c
1 % Useful for evaulating forcing functions with different functional expressions for each block
2 % f: cell array of function handles fi
3 % f_i = f_i(x1,y,...,t)
4 % t: time point. If not specified, it is assumed that the functions take only spatial arguments.
5 function gf = blockEvalOn(g, f, t)
6 default_arg('t',[]);
7
8 grids = g.grids;
9 nBlocks = length(grids);
10 gf = cell(nBlocks,1);
11
12 if isempty(t)
13 for i = 1:nBlocks
14 grid.evalOn(grids{i}, f{i} );
15 end
16 else
17 dim = nargin(f{1}) - 1;
18 for i = 1:nBlocks
19 switch dim
20 case 1
21 gf{i} = grid.evalOn(grids{i}, @(x)f{i}(x,t) );
22 case 2
23 gf{i} = grid.evalOn(grids{i}, @(x,y)f{i}(x,y,t) );
24 case 3
25 gf{i} = grid.evalOn(grids{i}, @(x,y,z)f{i}(x,y,z,t) );
26 end
27 end
28 end
29
30 gf = blockmatrix.toMatrix(gf);