Mercurial > repos > public > sbplib
view +scheme/bcSetup.m @ 675:90bf651abc7c feature/poroelastic
Add Dirichlet BC to dilation. Stable with variable coeff and conv study yields p+1/2 which probably is ok.
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Thu, 18 Jan 2018 13:36:56 -0800 |
parents | 9dd49d622a4c |
children | facb8ffb5c34 eac5fb4b63db |
line wrap: on
line source
% function [closure, S] = bcSetup(diffOp, bc) % Takes a diffOp and a cell array of boundary condition definitions. % Each bc is a struct with the fields % * type -- Type of boundary condition % * boundary -- Boundary identifier % * data -- A function_handle with time and space coordinates as a parameters, for example f(t,x,y) for a 2D problem % Also takes S_sign which modifies the sign of S, [-1,1] % Returns a closure matrix and a forcing function S function [closure, S] = bcSetup(diffOp, bc, S_sign) default_arg('S_sign', 1); assertType(bc, 'cell'); assert(S_sign == 1 || S_sign == -1, 'S_sign must be either 1 or -1'); closure = spzeros(size(diffOp)); penalties = {}; dataFunctions = {}; dataParams = {}; for i = 1:length(bc) assertType(bc{i}, 'struct'); [localClosure, penalty] = diffOp.boundary_condition(bc{i}.boundary, bc{i}.type); closure = closure + localClosure; if isempty(bc{i}.data) continue end assertType(bc{i}.data, 'function_handle'); coord = diffOp.grid.getBoundary(bc{i}.boundary); assertNumberOfArguments(bc{i}.data, 1+size(coord,2)); penalties{end+1} = penalty; dataFunctions{end+1} = bc{i}.data; dataParams{end+1} = num2cell(coord ,1); end O = spzeros(size(diffOp),1); function v = S_fun(t) v = O; for i = 1:length(dataFunctions) v = v + penalties{i}*dataFunctions{i}(t, dataParams{i}{:}); end v = S_sign * v; end S = @S_fun; end