/usr/share/octave/packages/secs2d-0.0.8/QDDGOX/QDDGOXcompdens.m is in octave-secs2d 0.0.8-5.
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 | function w = QDDGOXcompdens(mesh,Dsides,win,vin,fermiin,d2,toll,maxit,verbose);
% w = QDDGOXcompdens(mesh,Dsides,win,vin,fermiin,d2,toll,maxit,verbose);
global QDDGOXCOMPDENS_LAP QDDGOXCOMPDENS_MASS QDDGOXCOMPDENS_RHS
%% Set some usefull constants
VErank = 4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% convert input vectors to columns
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if Ucolumns(win)>Urows(win)
win=win';
end
if Ucolumns(vin)>Urows(vin)
vin=vin';
end
if Ucolumns(fermiin)>Urows(fermiin)
fermiin=fermiin';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% convert grid info to FEM form
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nodes = mesh.p;
Nnodes = size(nodes,2);
elements = mesh.t(1:3,:);
Nelements = size(elements,2);
Dedges =[];
for ii = 1:length(Dsides)
Dedges=[Dedges,find(mesh.e(5,:)==Dsides(ii))];
end
% Set list of nodes with Dirichelet BCs
Dnodes = mesh.e(1:2,Dedges);
Dnodes = [Dnodes(1,:) Dnodes(2,:)];
Dnodes = unique(Dnodes);
Dvals = win(Dnodes);
Varnodes = setdiff([1:Nnodes],Dnodes);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% initialization:
%% we're going to solve
%% $$ -\delta^2 \Lap w_{k+1} + B'(w_k) \delta w_{k+1} = 2 * w_k$$
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% set $$ w_1 = win $$
w = win;
wnew = win;
%% let's compute FEM approximation of $$ L = - \aleph \frac{d^2}{x^2} $$
if (isempty(QDDGOXCOMPDENS_LAP))
QDDGOXCOMPDENS_LAP = Ucomplap (mesh,ones(Nelements,1));
end
L = d2*QDDGOXCOMPDENS_LAP;
%% now compute $$ G_k = F - V + 2 V_{th} log(w) $$
if (isempty(QDDGOXCOMPDENS_MASS))
QDDGOXCOMPDENS_MASS = Ucompmass2 (mesh,ones(Nnodes,1),ones(Nelements,1));
end
G = fermiin - vin + 2*log(w);
Bmat = QDDGOXCOMPDENS_MASS*sparse(diag(G));
nrm = 1;
%%%%%%%%%%%%%%%%%%%%%%%%
%%% NEWTON ITERATION START
%%%%%%%%%%%%%%%%%%%%%%%%
converged = 0;
for jnewt =1:ceil(maxit/VErank)
for k=1:VErank
[w(:,k+1),converged,G,L,Bmat]=onenewtit(w(:,k),G,fermiin,vin,L,Bmat,jnewt,mesh,Dnodes,Varnodes,Dvals,Nnodes,Nelements,toll);
if converged
break
end
end
if converged
break
end
w = Urrextrapolation(w);
end
%%%%%%%%%%%%%%%%%%%%%%%%
%%% NEWTON ITERATION END
%%%%%%%%%%%%%%%%%%%%%%%%
w = w(:,end);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% ONE NEWTON ITERATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [w,converged,G,L,Bmat]=onenewtit(w,G,fermiin,vin,L,Bmat,jnewt,mesh,Dnodes,Varnodes,Dvals,Nnodes,Nelements,toll);
global QDDGOXCOMPDENS_LAP QDDGOXCOMPDENS_MASS QDDGOXCOMPDENS_RHS
dampit = 5;
dampcoeff = 2;
converged = 0;
wnew = w;
res0 = norm((L + Bmat) * w,inf);
%% chose $ t_k $ to ensure positivity of $w$
mm = -min(G);
pause(1)
if (mm>2)
tk = max( 1/(mm));
else
tk = 1;
end
tmpmat = QDDGOXCOMPDENS_MASS*2;
if (isempty(QDDGOXCOMPDENS_RHS))
QDDGOXCOMPDENS_RHS = Ucompconst (mesh,ones(Nnodes,1),ones(Nelements,1));
end
tmpvect= 2*QDDGOXCOMPDENS_RHS.*w;
%%%%%%%%%%%%%%%%%%%%%%%%
%%% DAMPING ITERATION START
%%%%%%%%%%%%%%%%%%%%%%%%
for idamp = 1:dampit
%% Compute $ B1mat = \frac{2}{t_k} $
%% and the (lumped) mass matrix B1mat(w_k)
B1mat = tmpmat/tk;
%% now we're ready to build LHS matrix and RHS of the linear system for 1st Newton step
A = L + B1mat + Bmat;
b = tmpvect/tk;
%% Apply boundary conditions
A (Dnodes,:) = 0;
b (Dnodes) = 0;
b = b - A (:,Dnodes) * Dvals;
A(Dnodes,:)= [];
A(:,Dnodes)= [];
b(Dnodes) = [];
wnew(Varnodes) = A\b;
%% compute $$ G_{k+1} = F - V + 2 V_{th} log(w) $$
G = fermiin - vin + 2*log(wnew);
Bmat = QDDGOXCOMPDENS_MASS*sparse(diag(G));
res = norm((L + Bmat) * wnew,inf);
if (res<res0)
break
else
tk = tk/dampcoeff;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%
%%% DAMPING ITERATION END
%%%%%%%%%%%%%%%%%%%%%%%%
nrm = norm(wnew-w);
if (nrm < toll)
w= wnew;
converged = 1;
else
w=wnew;
end
|