This file is indexed.

/usr/share/octave/packages/bim-1.1.5/bim2a_axisymmetric_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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
## Copyright (C) 2006-2014  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>
##  author: Matteo porro       <meoo85 _AT_ users.sourceforge.net>
##  author: Emanuela Abbate    <emanuela.abbate _AT_ mail.polimi.it>

## -*- texinfo -*-
## @deftypefn {Function File} @
## {[@var{A}]} = @
## bim2a_axisymmetric_advection_diffusion(@var{mesh},@var{alpha},@var{gamma},@var{eta},@var{beta})
##
## Build the Scharfetter-Gummel stabilized stiffness matrix for a
## diffusion-advection problem in cylindrical coordinates with axisymmetric 
## configuration. Rotational symmetry is assumed with respect to be the vertical
## axis r=0. Only plane geometries that DO NOT intersect the symmetry axis 
## are admitted.
##
##@example
##@group
##    |   ____                 _|____ 
##    |  |    \               \ |    |
##  z |  |     \  OK           \|    |   NO!
##    |  |______\               |\___|
##    |     r                   |
#@end group 
#@end example
##
## The equation taken into account is:
##
## 1/r * d(r * Fr)/dr + dFz/dz = f
##
## with
##
## F = [Fr, Fz]' = - @var{alpha} * @var{gamma} ( @var{eta} grad (u) - @var{beta} u )
##
## 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{bim2a_axisymmetric_rhs, bim2a_axisymmetric_reaction, 
## bim2a_advection_diffusion, bim2c_mesh_properties}
## @end deftypefn

function [A] = bim2a_axisymmetric_advection_diffusion (mesh, alpha, gamma, eta, beta)

  ## Check input
  if nargin != 5
    error("bim2a_axisymmetric_advection_diffusion: wrong number of input parameters.");
  elseif !(isstruct(mesh) && isfield(mesh,"p") &&
	         isfield (mesh,"t") && isfield(mesh,"e"))
    error("bim2a_axisymmetric_advection_diffusion: first input is not a valid mesh structure.");
  elseif !(all(mesh.p(1,:) >= 0) || all(mesh.p(1,:) <= 0))
    error("bim2a_axisymmetric_advection_diffusion: the input mesh cannot intersect the rotation axis r=0.");
  endif
  
  nnodes = columns(mesh.p);
  nelem  = columns(mesh.t);

  ## 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("bim2a_axisymmetric_advection_diffusion: coefficients are not valid vectors.");
  elseif length(alpha) != nelem
    error("bim2a_axisymmetric_advection_diffusion: length of alpha is not equal to the number of elements.");
  elseif length(gamma) != nnodes
    error("bim2a_axisymmetric_advection_diffusion: length of gamma is not equal to the number of nodes.");
  elseif length(eta) != nnodes
    error("bim2a_axisymmetric_advection_diffusion: length of eta is not equal to the number of nodes.");
  endif
  
  x = abs(mesh.p(1,:));
  x = x(mesh.t(1:3,:));
  y = mesh.p(2,:);
  y = y(mesh.t(1:3,:));
   
  alphaareak = reshape (alpha.*mesh.area,1,1,nelem);
  shg        = mesh.shg(:,:,:);
  
  ## Build local Laplacian matrix
  Lloc = zeros(3,3,nelem);	
  
  for inode = 1:3
    for jnode = 1:3
      ginode(inode,jnode,:) = mesh.t(inode,:);
      gjnode(inode,jnode,:) = mesh.t(jnode,:);
      Lloc(inode,jnode,:)   = sum( shg(:,inode,:) .* shg(:,jnode,:),1) .* alphaareak;
    endfor
  endfor
    
  if all(size(beta)==1)
    v12 = 0;
    v23 = 0;
    v31 = 0; 
  elseif all(size(beta)==[2,nelem])
    v12 = beta(1,:) .* (x(2,:)-x(1,:)) + beta(2,:) .* (y(2,:)-y(1,:));
    v23 = beta(1,:) .* (x(3,:)-x(2,:)) + beta(2,:) .* (y(3,:)-y(2,:));
    v31 = beta(1,:) .* (x(1,:)-x(3,:)) + beta(2,:) .* (y(1,:)-y(3,:)); 
  elseif all(size(beta)==[nnodes,1])
    betaloc = beta(mesh.t(1:3,:));
    v12     = betaloc(2,:)-betaloc(1,:);
    v23     = betaloc(3,:)-betaloc(2,:);
    v31     = betaloc(1,:)-betaloc(3,:); 
  else
    error("bim2a_axisymmetric_advection_diffusion: coefficient beta has wrong dimensions.");
  endif
  
  etaloc = eta(mesh.t(1:3,:));
  
  eta12 = etaloc(2,:) - etaloc(1,:);
  eta23 = etaloc(3,:) - etaloc(2,:);
  eta31 = etaloc(1,:) - etaloc(3,:);
  
  r12 = (x(2,:) + x(1,:)) / 2;
  r23 = (x(3,:) + x(2,:)) / 2;
  r31 = (x(1,:) + x(3,:)) / 2;
  
  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,:));
  
  [bp12,bm12] = bimu_bernoulli ((v12 - eta12) ./ etalocm3);
  [bp23,bm23] = bimu_bernoulli ((v23 - eta23) ./ etalocm1);
  [bp31,bm31] = bimu_bernoulli ((v31 - eta31) ./ etalocm2);
  
  bp12 = reshape(r12.*gelocm3.*etalocm3.*bp12,1,1,nelem).*Lloc(1,2,:);
  bm12 = reshape(r12.*gelocm3.*etalocm3.*bm12,1,1,nelem).*Lloc(1,2,:);
  bp23 = reshape(r23.*gelocm1.*etalocm1.*bp23,1,1,nelem).*Lloc(2,3,:);
  bm23 = reshape(r23.*gelocm1.*etalocm1.*bm23,1,1,nelem).*Lloc(2,3,:);
  bp31 = reshape(r31.*gelocm2.*etalocm2.*bp31,1,1,nelem).*Lloc(3,1,:);
  bm31 = reshape(r31.*gelocm2.*etalocm2.*bm31,1,1,nelem).*Lloc(3,1,:);
  
  Sloc(1,1,:) = (-bm12-bp31)./reshape(etaloc(1,:),1,1,nelem);
  Sloc(1,2,:) = bp12./reshape(etaloc(2,:),1,1,nelem);
  Sloc(1,3,:) = bm31./reshape(etaloc(3,:),1,1,nelem);
  
  Sloc(2,1,:) = bm12./reshape(etaloc(1,:),1,1,nelem);
  Sloc(2,2,:) = (-bp12-bm23)./reshape(etaloc(2,:),1,1,nelem); 
  Sloc(2,3,:) = bp23./reshape(etaloc(3,:),1,1,nelem);
  
  Sloc(3,1,:) = bp31./reshape(etaloc(1,:),1,1,nelem);
  Sloc(3,2,:) = bm23./reshape(etaloc(2,:),1,1,nelem);
  Sloc(3,3,:) = (-bm31-bp23)./reshape(etaloc(3,:),1,1,nelem);
  
  A = sparse(ginode(:),gjnode(:),Sloc(:));

endfunction

%!test
%! n         = 3;
%! [mesh]    = msh2m_structured_mesh(linspace(1,2,n+1),linspace(0,1,n+1),1,1:4);
%! mesh      = bim2c_mesh_properties(mesh);
%! uex       = @(r,z) exp(r);
%! duexdr    = @(r,z) uex(r,z);
%! d2uexdr2  = @(r,z) uex(r,z);
%! duexdz    = @(r,z) 0*uex(r,z);
%! d2uexdz2  = @(r,z) 0*uex(r,z);
%! Dnodes    = bim2c_unknowns_on_side(mesh,[2,4]);
%! Nnodes    = columns(mesh.p);
%! Nelements = columns(mesh.t);
%! Varnodes  = setdiff(1:Nnodes,Dnodes);
%! D = 1; vr = 1; vz = 0;
%! alpha  = D*ones(Nelements,1);
%! gamma  = ones(Nnodes,1);
%! eta    = ones(Nnodes,1);
%! beta   = 1/D*[vr*ones(1,Nelements); vz*ones(1,Nelements)];
%! f = @(r,z) -D./r.*duexdr(r,z) - D.*d2uexdr2(r,z) ...
%!           + vr./r .* uex(r,z) + vr * duexdr(r,z) ...
%!           - D.*d2uexdz2(r,z) + vz * duexdz(r,z);
%! rhs = bim2a_axisymmetric_rhs(mesh, ones(Nelements,1), f(mesh.p(1,:), mesh.p(2,:)));
%! S   = bim2a_axisymmetric_advection_diffusion(mesh,alpha,gamma,eta,beta);
%! u   = zeros(Nnodes,1); u(Dnodes) = uex(mesh.p(1,Dnodes), mesh.p(2,Dnodes));
%! u(Varnodes) = S(Varnodes,Varnodes)\(rhs(Varnodes) - S(Varnodes,Dnodes)*u(Dnodes));
%! assert(u,uex(mesh.p(1,:), mesh.p(2,:))',1e-7)

%!test
%! n         = 20;
%! [mesh]    = msh2m_structured_mesh(linspace(1,2,n+1),linspace(0,1,n+1),1,1:4);
%! mesh      = bim2c_mesh_properties(mesh);
%! uex       = @(r,z) exp(r) .* exp(1-z);
%! duexdr    = @(r,z) uex(r,z);
%! d2uexdr2  = @(r,z) uex(r,z);
%! duexdz    = @(r,z) -uex(r,z);
%! d2uexdz2  = @(r,z) uex(r,z);
%! Dnodes    = bim2c_unknowns_on_side(mesh,[1,2,3,4]);
%! Nnodes    = columns(mesh.p);
%! Nelements = columns(mesh.t);
%! Varnodes  = setdiff(1:Nnodes,Dnodes);
%! D = 1; vr = 1; vz = 1;
%! alpha  = D*ones(Nelements,1);
%! gamma  = ones(Nnodes,1);
%! eta    = ones(Nnodes,1);
%! beta   = 1/D*[vr*ones(1,Nelements); vz*ones(1,Nelements)];
%! f = @(r,z) -D./r.*duexdr(r,z) - D.*d2uexdr2(r,z) ...
%!           + vr./r .* uex(r,z) + vr * duexdr(r,z) ...
%!           - D.*d2uexdz2(r,z) + vz * duexdz(r,z);
%! rhs = bim2a_axisymmetric_rhs(mesh, ones(Nelements,1), f(mesh.p(1,:), mesh.p(2,:)));
%! S   = bim2a_axisymmetric_advection_diffusion(mesh,alpha,gamma,eta,beta);
%! u   = zeros(Nnodes,1); u(Dnodes) = uex(mesh.p(1,Dnodes), mesh.p(2,Dnodes));
%! u(Varnodes) = S(Varnodes,Varnodes)\(rhs(Varnodes) - S(Varnodes,Dnodes)*u(Dnodes));
%! assert(u,uex(mesh.p(1,:), mesh.p(2,:))',1e-3)

%!test
%! n         = 10;
%! [mesh]    = msh2m_structured_mesh(linspace(1,2,n+1),linspace(0,1,n+1),1,1:4);
%! mesh      = bim2c_mesh_properties(mesh);
%! uex       = @(r,z) exp(r) .* exp(1-z);
%! duexdr    = @(r,z) uex(r,z);
%! d2uexdr2  = @(r,z) uex(r,z);
%! duexdz    = @(r,z) -uex(r,z);
%! d2uexdz2  = @(r,z) uex(r,z);
%! Dnodes    = bim2c_unknowns_on_side(mesh,[1,2,3,4]);
%! Nnodes    = columns(mesh.p);
%! Nelements = columns(mesh.t);
%! Varnodes  = setdiff(1:Nnodes,Dnodes);
%! D      = 1;
%! alpha  = D*ones(Nelements,1);
%! gamma  = ones(Nnodes,1);
%! eta    = ones(Nnodes,1);
%! beta   = 1/D * mesh.p(1,:)';
%! f = @(r,z) -D./r.*duexdr(r,z) - D.*d2uexdr2(r,z) ...
%!           + 1./r .* uex(r,z) + duexdr(r,z) ...
%!           - D.*d2uexdz2(r,z);
%! rhs = bim2a_axisymmetric_rhs(mesh, ones(Nelements,1), f(mesh.p(1,:), mesh.p(2,:)));
%! S   = bim2a_axisymmetric_advection_diffusion(mesh,alpha,gamma,eta,beta);
%! u   = zeros(Nnodes,1); u(Dnodes) = uex(mesh.p(1,Dnodes), mesh.p(2,Dnodes));
%! u(Varnodes) = S(Varnodes,Varnodes)\(rhs(Varnodes) - S(Varnodes,Dnodes)*u(Dnodes));
%! assert(u,uex(mesh.p(1,:), mesh.p(2,:))',1e-3)

%!test
%! n         = 10;
%! [mesh]    = msh2m_structured_mesh(linspace(1,2,n+1),linspace(0,1,n+1),1,1:4);
%! mesh      = bim2c_mesh_properties(mesh);
%! uex       = @(r,z) exp(r) .* exp(1-z);
%! duexdr    = @(r,z) uex(r,z);
%! d2uexdr2  = @(r,z) uex(r,z);
%! duexdz    = @(r,z) -uex(r,z);
%! d2uexdz2  = @(r,z) uex(r,z);
%! Dnodes    = bim2c_unknowns_on_side(mesh,[1,2,3,4]);
%! Nnodes    = columns(mesh.p);
%! Nelements = columns(mesh.t);
%! Varnodes  = setdiff(1:Nnodes,Dnodes);
%! D         = 1;
%! alpha     = D*ones(Nelements,1);
%! gamma     = ones(Nnodes,1);
%! eta       = ones(Nnodes,1);
%! beta      = 1/D * 1/2*(mesh.p(1,:)').^2;
%! f         = @(r,z) 1./r.*(1+r).*(r-D) .* uex(r,z);
%! rhs = bim2a_axisymmetric_rhs(mesh, ones(Nelements,1), f(mesh.p(1,:), mesh.p(2,:)));
%! S   = bim2a_axisymmetric_advection_diffusion(mesh,alpha,gamma,eta,beta);
%! u   = zeros(Nnodes,1); u(Dnodes) = uex(mesh.p(1,Dnodes), mesh.p(2,Dnodes));
%! u(Varnodes) = S(Varnodes,Varnodes)\(rhs(Varnodes) - S(Varnodes,Dnodes)*u(Dnodes));
%! assert(u,uex(mesh.p(1,:), mesh.p(2,:))',1e-3)

%!test
%! n         = 3;
%! [mesh]    = msh2m_structured_mesh(linspace(-2,-1,n+1),linspace(0,1,n+1),1,1:4);
%! mesh      = bim2c_mesh_properties(mesh);
%! uex       = @(r,z) exp(r);
%! duexdr    = @(r,z) uex(r,z);
%! d2uexdr2  = @(r,z) uex(r,z);
%! duexdz    = @(r,z) 0*uex(r,z);
%! d2uexdz2  = @(r,z) 0*uex(r,z);
%! Dnodes    = bim2c_unknowns_on_side(mesh,[2,4]);
%! Nnodes    = columns(mesh.p);
%! Nelements = columns(mesh.t);
%! Varnodes  = setdiff(1:Nnodes,Dnodes);
%! D = 1; vr = 1; vz = 0;
%! alpha     = D*ones(Nelements,1);
%! gamma     = ones(Nnodes,1);
%! eta       = ones(Nnodes,1);
%! beta      = 1/D*[vr*ones(1,Nelements); vz*ones(1,Nelements)];
%! f = @(r,z) -D./r.*duexdr(r,z) - D.*d2uexdr2(r,z) ...
%!           + vr./r .* uex(r,z) + vr * duexdr(r,z) ...
%!           - D.*d2uexdz2(r,z) + vz * duexdz(r,z);
%! rhs = bim2a_axisymmetric_rhs(mesh, ones(Nelements,1), f(abs(mesh.p(1,:)), mesh.p(2,:)));
%! S   = bim2a_axisymmetric_advection_diffusion(mesh,alpha,gamma,eta,beta);
%! u   = zeros(Nnodes,1); u(Dnodes) = uex(abs(mesh.p(1,Dnodes)), mesh.p(2,Dnodes));
%! u(Varnodes) = S(Varnodes,Varnodes)\(rhs(Varnodes) - S(Varnodes,Dnodes)*u(Dnodes));
%! assert(u,uex(abs(mesh.p(1,:)), mesh.p(2,:))',1e-7)

%!test
%! n         = 10;
%! [mesh]    = msh2m_structured_mesh(linspace(-2,-1,n+1),linspace(0,1,n+1),1,1:4);
%! mesh      = bim2c_mesh_properties(mesh);
%! uex       = @(r,z) exp(r) .* exp(1-z);
%! duexdr    = @(r,z) uex(r,z);
%! d2uexdr2  = @(r,z) uex(r,z);
%! duexdz    = @(r,z) -uex(r,z);
%! d2uexdz2  = @(r,z) uex(r,z);
%! Dnodes    = bim2c_unknowns_on_side(mesh,[1,2,3,4]);
%! Nnodes    = columns(mesh.p);
%! Nelements = columns(mesh.t);
%! Varnodes  = setdiff(1:Nnodes,Dnodes);
%! D         = 1;
%! alpha     = D*ones(Nelements,1);
%! gamma     = ones(Nnodes,1);
%! eta       = ones(Nnodes,1);
%! beta      = 1/D * 1/2*(mesh.p(1,:)').^2;
%! f         = @(r,z) 1./r.*(1+r).*(r-D) .* uex(r,z);
%! rhs = bim2a_axisymmetric_rhs(mesh, ones(Nelements,1), f(abs(mesh.p(1,:)), mesh.p(2,:)));
%! S   = bim2a_axisymmetric_advection_diffusion(mesh,alpha,gamma,eta,beta);
%! u   = zeros(Nnodes,1); u(Dnodes) = uex(abs(mesh.p(1,Dnodes)), mesh.p(2,Dnodes));
%! u(Varnodes) = S(Varnodes,Varnodes)\(rhs(Varnodes) - S(Varnodes,Dnodes)*u(Dnodes));
%! assert(u,uex(abs(mesh.p(1,:)), mesh.p(2,:))',1e-3)

%!test
%! [mesh] = msh2m_structured_mesh([0:.1:1],[0:.1:1],1,1:4);
%! mesh   = bim2c_mesh_properties(mesh);
%! x = mesh.p(1,:)'; y = mesh.p(2,:)';
%! Dnodes = bim2c_unknowns_on_side(mesh,[1:4]);
%! Nnodes = columns(mesh.p); Nelements = columns(mesh.t);
%! alpha  = ones(Nelements,1); eta=ones(Nnodes,1);
%! beta   = 0;
%! gamma  = ones(Nnodes,1);
%! A = bim2a_axisymmetric_advection_diffusion(mesh,1,1,1,0);
%! B = bim2a_axisymmetric_advection_diffusion(mesh,alpha,gamma,eta,beta);
%! assert(A,B)