Mercurial > repos > public > sbplib
view +scheme/bcSetup.m @ 742:08f3ffe63f48 feature/poroelastic Heimisson2018 elastic1.0
Add metric scale factors to properties in heat and elastic curvilinear
author | Martin Almquist <malmquist@stanford.edu> |
---|---|
date | Fri, 11 May 2018 13:11:32 -0700 |
parents | eac5fb4b63db |
children | 1f6b2fb69225 |
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 coord = diffOp.grid.getBoundary(bc{i}.boundary); if iscell(bc{i}.data) for j = 1:length(bc{i}.data) assertType(bc{i}.data{j}, 'function_handle'); assertNumberOfArguments(bc{i}.data{j}, 1+size(coord,2)); end else assertType(bc{i}.data, 'function_handle'); assertNumberOfArguments(bc{i}.data, 1+size(coord,2)); end 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) if iscell(penalties{i}) for j = 1:length(penalties{i}) v = v + penalties{i}{j}*dataFunctions{i}{j}(t, dataParams{i}{:}); end else v = v + penalties{i}*dataFunctions{i}(t, dataParams{i}{:}); end end v = S_sign * v; end S = @S_fun; end