1 function [V,n,p,res,niter] = DDGOXnlpoisson (mesh,Dsides,Sinodes,SiDnodes,...
2 Sielements,Vin,nin,pin,...
3 Fnin,Fpin,D,l2,l2ox,...
7 % [V,n,p,res,niter] = DDGOXnlpoisson (mesh,Dsides,Sinodes,Vin,nin,pin,...
8 % Fnin,Fpin,D,l2,l2ox,toll,maxit,verbose)
10 % solves $$ -\lambda^2 V'' + (n(V,Fn) - p(V,Fp) -D)$$
14 % This file is part of
16 % SECS2D - A 2-D Drift--Diffusion Semiconductor Device Simulator
17 % -------------------------------------------------------------------
18 % Copyright (C) 2004-2006 Carlo de Falco
22 % SECS2D is free software; you can redistribute it and/or modify
23 % it under the terms of the GNU General Public License as published by
24 % the Free Software Foundation; either version 2 of the License, or
25 % (at your option) any later version.
27 % SECS2D is distributed in the hope that it will be useful,
28 % but WITHOUT ANY WARRANTY; without even the implied warranty of
29 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 % GNU General Public License for more details.
32 % You should have received a copy of the GNU General Public License
33 % along with SECS2D; If not, see <http://www.gnu.org/licenses/>.
35 global DDGOXNLPOISSON_LAP DDGOXNLPOISSON_MASS DDGOXNLPOISSON_RHS
37 %% Set some useful constants
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 %% convert input vectors to columns
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 if Ucolumns(D)>Urows(D)
50 if Ucolumns(nin)>Urows(nin)
54 if Ucolumns(pin)>Urows(pin)
58 if Ucolumns(Vin)>Urows(Vin)
62 if Ucolumns(Fnin)>Urows(Fnin)
66 if Ucolumns(Fpin)>Urows(Fpin)
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 %% setup FEM data structures
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 Nnodes = length(nodes);
76 Nelements = length(elements);
78 % Set list of nodes with Dirichelet BCs
79 Dnodes = Unodesonside(mesh,Dsides);
81 % Set values of Dirichelet BCs
82 Bc = zeros(length(Dnodes),1);
83 % Set list of nodes without Dirichelet BCs
84 Varnodes = setdiff([1:Nnodes],Dnodes);
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 %% we're going to solve
91 %% $$ - \lambda^2 (\delta V)'' + (\frac{\partial n}{\partial V} - \frac{\partial p}{\partial V})= -R $$
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 %% set $$ n_1 = nin $$ and $$ V = Vin $$
99 n = exp(V(Sinodes)-Fn);
100 p = exp(-V(Sinodes)+Fp);
101 n(SiDnodes) = nin(SiDnodes);
102 p(SiDnodes) = pin(SiDnodes);
106 %%% Compute LHS matrices
109 %% let's compute FEM approximation of $$ L = - \frac{d^2}{x^2} $$
110 if (isempty(DDGOXNLPOISSON_LAP))
111 coeff = l2ox * ones(Nelements,1);
112 coeff(Sielements)=l2;
113 DDGOXNLPOISSON_LAP = Ucomplap (mesh,coeff);
116 %% compute $$ Mv = ( n + p) $$
117 %% and the (lumped) mass matrix M
118 if (isempty(DDGOXNLPOISSON_MASS))
119 coeffe = zeros(Nelements,1);
120 coeffe(Sielements)=1;
121 DDGOXNLPOISSON_MASS = Ucompmass2(mesh,ones(Nnodes,1),coeffe);
123 freecarr=zeros(Nnodes,1);
124 freecarr(Sinodes)=(n + p);
126 M = DDGOXNLPOISSON_MASS*spdiag(Mv);
129 %%% Compute RHS vector (-residual)
132 %% now compute $$ T0 = \frac{q}{\epsilon} (n - p - D) $$
133 if (isempty(DDGOXNLPOISSON_RHS))
134 coeffe = zeros(Nelements,1);
135 coeffe(Sielements)=1;
136 DDGOXNLPOISSON_RHS = Ucompconst (mesh,ones(Nnodes,1),coeffe);
138 totcharge = zeros(Nnodes,1);
139 totcharge(Sinodes)=(n - p - D);
141 T0 = Tv0 .* DDGOXNLPOISSON_RHS;
143 %% now we're ready to build LHS matrix and RHS of the linear system for 1st Newton step
144 A = DDGOXNLPOISSON_LAP + M;
145 R = DDGOXNLPOISSON_LAP * V + T0;
147 %% Apply boundary conditions
152 %% we need $$ \norm{R_1} $$ and $$ \norm{R_k} $$ for the convergence test
153 normr(1) = norm(R,inf);
159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 %% START OF THE NEWTON CYCLE
163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 fprintf(1,'\n***\nNewton iteration: %d, reldVnorm = %e\n***\n',newtit,reldVnorm);
170 dV(Varnodes) =(A)\(-R);
175 %% Start of th damping procedure
180 fprintf(1,'\ndamping iteration: %d, residual norm = %e\n',dit,normrnew);
184 n = exp(Vnew(Sinodes)-Fn);
185 p = exp(-Vnew(Sinodes)+Fp);
186 n(SiDnodes) = nin(SiDnodes);
187 p(SiDnodes) = pin(SiDnodes);
191 %%% Compute LHS matrices
194 %% let's compute FEM approximation of $$ L = - \frac{d^2}{x^2} $$
195 %L = Ucomplap (mesh,ones(Nelements,1));
197 %% compute $$ Mv = ( n + p) $$
198 %% and the (lumped) mass matrix M
199 freecarr=zeros(Nnodes,1);
200 freecarr(Sinodes)=(n + p);
202 M = DDGOXNLPOISSON_MASS*spdiag(Mv);
205 %%% Compute RHS vector (-residual)
208 %% now compute $$ T0 = \frac{q}{\epsilon} (n - p - D) $$
209 totcharge( Sinodes)=(n - p - D);
211 T0 = Tv0 .* DDGOXNLPOISSON_RHS;%T0 = Ucompconst (mesh,Tv0,ones(Nelements,1));
213 %% now we're ready to build LHS matrix and RHS of the linear system for 1st Newton step
214 A = DDGOXNLPOISSON_LAP + M;
215 R = DDGOXNLPOISSON_LAP * Vnew + T0;
217 %% Apply boundary conditions
222 %% compute $$ | R_{k+1} | $$ for the convergence test
223 normrnew= norm(R,inf);
225 % check if more damping is needed
226 if (normrnew > normr(newtit))
230 fprintf(1,'\nexiting damping cycle because residual norm = %e \n-----------\n',normrnew);
237 normr(newtit+1) = normrnew;
238 dVnorm = norm(tk*dV,inf);
240 % check if convergence has been reached
241 reldVnorm = dVnorm / norm(V,inf);
242 if (reldVnorm <= toll)
244 fprintf(1,'\nexiting newton cycle because reldVnorm= %e \n',reldVnorm);