/usr/share/octave/packages/bim-1.1.5/bim1a_advection_diffusion.m is in octave-bim 1.1.5-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | ## Copyright (C) 2006,2007,2008,2009,2010 Carlo de Falco, Massimiliano Culpo
##
## This file is part of:
## BIM - Diffusion Advection Reaction PDE Solver
##
## BIM is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## BIM is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with BIM; If not, see <http://www.gnu.org/licenses/>.
##
## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
## author: Massimiliano Culpo <culpo _AT_ users.sourceforge.net>
## -*- texinfo -*-
##
## @deftypefn {Function File} @
## {[@var{A}]} = @
## bim1a_advection_diffusion(@var{mesh},@var{alpha},@var{gamma},@var{eta},@var{beta})
##
## Build the Scharfetter-Gummel stabilized stiffness matrix for a
## diffusion-advection problem.
##
## The equation taken into account is:
##
## - div (@var{alpha} * @var{gamma} (@var{eta} grad (u) - @var{beta} u)) = f
##
## where @var{alpha} is an element-wise constant scalar function,
## @var{eta} and @var{gamma} are piecewise linear conforming scalar
## functions, @var{beta} is an element-wise constant vector function.
##
## Instead of passing the vector field @var{beta} directly one can pass
## a piecewise linear conforming scalar function @var{phi} as the last
## input. In such case @var{beta} = grad @var{phi} is assumed.
##
## If @var{phi} is a single scalar value @var{beta} is assumed to be 0
## in the whole domain.
##
## @seealso{bim1a_rhs, bim1a_reaction, bim1a_laplacian, bim2a_advection_diffusion}
## @end deftypefn
function A = bim1a_advection_diffusion (x,alpha,gamma,eta,beta)
## Check input
if (nargin != 5)
error ("bim1a_advection_diffusion: wrong number of input parameters.");
elseif (! isvector (x))
error ("bim1a_advection_diffusion: first argument is not a valid vector.");
endif
nnodes = numel (x);
nelem = nnodes - 1;
## Turn scalar input to a vector of appropriate size
if (isscalar (alpha))
alpha = alpha * ones (nelem, 1);
endif
if (isscalar (gamma))
gamma = gamma * ones (nnodes, 1);
endif
if (isscalar (eta))
eta = eta * ones (nnodes, 1);
endif
if (! (isvector (alpha) && isvector (gamma) && isvector (eta)))
error ("bim1a_advection_diffusion: coefficients are not valid vectors.");
elseif (numel (alpha) != nelem)
error ("bim1a_advection_diffusion: length of alpha is not equal to the number of elements.");
elseif (numel (gamma) != nnodes)
error ("bim1a_advection_diffusion: length of gamma is not equal to the number of nodes.");
elseif (numel (eta) != nnodes)
error ("bim1a_advection_diffusion: length of eta is not equal to the number of nodes.");
endif
areak = reshape (diff (x), [], 1);
if (numel (beta) == 1)
vk = 0;
elseif (numel (beta) == nelem)
vk = beta .* areak;
elseif (numel (beta) == nnodes)
vk = diff (beta);
else
error ("bim1a_advection_diffusion: coefficient beta has wrong dimensions.");
endif
gammaetak = bimu_logm ((gamma .* eta)(1:end-1), (gamma .* eta)(2:end));
veta = diff (eta);
etak = bimu_logm (eta(1:end-1), eta(2:end));
ck = alpha .* gammaetak .* etak ./ areak;
[bpk, bmk] = bimu_bernoulli ((vk - veta) ./ etak);
dm1 = [-(ck.*bmk); NaN];
dp1 = [NaN; -(ck.*bpk)];
d0 = [(ck(1).*bmk(1)); ((ck.*bmk)(2:end) + (ck.*bpk)(1:end-1)); (ck(end).*bpk(end))];
A = spdiags([dm1, d0, dp1],-1:1,nnodes,nnodes);
endfunction
%!test
%! x = linspace(0,1,101);
%! A = bim1a_advection_diffusion(x,1,1,1,0);
%! alpha = ones(100,1);
%! gamma = ones(101,1);
%! eta = gamma;
%! B = bim1a_advection_diffusion(x,alpha,gamma,eta,0);
%! assert(A,B)
|