/usr/share/octave/packages/bim-1.1.5/bim2c_global_flux.m is in octave-bim 1.1.5-2.
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | ## 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{jx},@var{jy}]} = @
## bim2c_global_flux(@var{mesh},@var{u},@var{alpha},@var{gamma},@var{eta},@var{beta})
##
## Compute the flux associated with the Scharfetter-Gummel approximation
## of the scalar field @var{u}.
##
## The vector field is defined as:
##
## J(@var{u}) = @var{alpha}* @var{gamma} * (@var{eta} * grad @var{u} - @var{beta} * @var{u}))
##
## where @var{alpha} is an element-wise constant scalar function,
## @var{eta} and @var{gamma} are piecewise linear conforming scalar
## functions, while @var{beta} is element-wise constant vector function.
##
## J(@var{u}) 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{bim2c_pde_gradient,bim2a_advection_diffusion}
## @end deftypefn
function [jx, jy] = bim2c_global_flux(mesh,u,alpha,gamma,eta,beta)
## Check input
if nargin != 6
error("bim2c_global_flux: wrong number of input parameters.");
elseif !(isstruct(mesh) && isfield(mesh,"p") &&
isfield (mesh,"t") && isfield(mesh,"e"))
error("bim2c_global_flux: first input is not a valid mesh structure.");
endif
nnodes = columns(mesh.p);
nelem = columns(mesh.t);
if !( isvector(u) && isvector(alpha) && isvector(gamma) && isvector(eta) )
error("bim2c_global_flux: coefficients are not valid vectors.");
elseif (numel (u) != nnodes)
error("bim2c_global_flux: length of u is not equal to the number of nodes.");
elseif (numel (alpha) != nelem)
error("bim2c_global_flux: length of alpha is not equal to the number of elements.");
elseif (numel (gamma) != nnodes)
error("bim2c_global_flux: length of gamma is not equal to the number of nodes.");
elseif (numel (eta) != nnodes)
error("bim2c_global_flux: length of eta is not equal to the number of nodes.");
endif
nelem = columns(mesh.t);
nnodes = columns(mesh.p);
uloc = u(mesh.t(1:3,:));
shgx = reshape(mesh.shg(1,:,:),3,nelem);
shgy = reshape(mesh.shg(2,:,:),3,nelem);
x = reshape(mesh.p(1,mesh.t(1:3,:)),3,[]);
dx = [ (x(3,:)-x(2,:)) ;
(x(1,:)-x(3,:)) ;
(x(2,:)-x(1,:)) ];
y = reshape(mesh.p(2,mesh.t(1:3,:)),3,[]);
dy = [ (y(3,:)-y(2,:)) ;
(y(1,:) -y(3,:)) ;
(y(2,:) -y(1,:)) ];
if all(size(beta)==1)
v12=0;v23=0;v31=0;
elseif all(size(beta)==[2,nelem])
v23 = beta(1,:) .* dx(1,:) + beta(2,:) .* dy(1,:);
v31 = beta(1,:) .* dx(2,:) + beta(2,:) .* dy(2,:);
v12 = beta(1,:) .* dx(3,:) + beta(2,:) .* dy(3,:);
elseif all(size(beta)==[nnodes,1])
betaloc = beta(mesh.t(1:3,:));
v23 = betaloc(3,:)-betaloc(2,:);
v31 = betaloc(1,:)-betaloc(3,:);
v12 = betaloc(2,:)-betaloc(1,:);
else
error("bim2c_global_flux: coefficient beta has wrong dimensions.");
endif
etaloc = eta(mesh.t(1:3,:));
eta23 = etaloc(3,:)-etaloc(2,:);
eta31 = etaloc(1,:)-etaloc(3,:);
eta12 = etaloc(2,:)-etaloc(1,:);
etalocm1 = bimu_logm(etaloc(2,:),etaloc(3,:));
etalocm2 = bimu_logm(etaloc(3,:),etaloc(1,:));
etalocm3 = bimu_logm(etaloc(1,:),etaloc(2,:));
gammaloc = gamma(mesh.t(1:3,:));
geloc = gammaloc.*etaloc;
gelocm1 = bimu_logm(geloc(2,:),geloc(3,:));
gelocm2 = bimu_logm(geloc(3,:),geloc(1,:));
gelocm3 = bimu_logm(geloc(1,:),geloc(2,:));
[bp23,bm23] = bimu_bernoulli( (v23 - eta23)./etalocm1);
[bp31,bm31] = bimu_bernoulli( (v31 - eta31)./etalocm2);
[bp12,bm12] = bimu_bernoulli( (v12 - eta12)./etalocm3);
gfigfj = [ shgx(3,:) .* shgx(2,:) + shgy(3,:) .* shgy(2,:) ;
shgx(1,:) .* shgx(3,:) + shgy(1,:) .* shgy(3,:) ;
shgx(2,:) .* shgx(1,:) + shgy(2,:) .* shgy(1,:) ];
jx = - alpha' .* ( gelocm1 .* etalocm1 .* dx(1,:) .* ...
gfigfj(1,:) .* ...
( bp23 .* uloc(3,:)./etaloc(3,:) -...
bm23 .* uloc(2,:)./etaloc(2,:)) +... %% 1
gelocm2 .* etalocm2 .* dx(2,:) .* ...
gfigfj(2,:) .* ...
(bp31 .* uloc(1,:)./etaloc(1,:) -...
bm31 .* uloc(3,:)./etaloc(3,:)) +... %% 2
gelocm3 .* etalocm3 .* dx(3,:) .* ...
gfigfj(3,:) .* ...
(bp12 .* uloc(2,:)./etaloc(2,:) -...
bm12 .* uloc(1,:)./etaloc(1,:)) ... %% 3
);
jy = - alpha' .* ( gelocm1 .* etalocm1 .* dy(1,:) .* ...
gfigfj(1,:) .* ...
( bp23 .* uloc(3,:)./etaloc(3,:) -...
bm23 .* uloc(2,:)./etaloc(2,:)) +... %% 1
gelocm2 .* etalocm2 .* dy(2,:) .* ...
gfigfj(2,:) .* ...
(bp31 .* uloc(1,:)./etaloc(1,:) -...
bm31 .* uloc(3,:)./etaloc(3,:)) +... %% 2
gelocm3 .* etalocm3 .* dy(3,:) .* ...
gfigfj(3,:) .* ...
(bp12 .* uloc(2,:)./etaloc(2,:) -...
bm12 .* uloc(1,:)./etaloc(1,:)) ... %% 3
);
endfunction
|