1 function [V,n,p,res,niter] = QDDGOXnlpoisson (mesh,Dsides,Sinodes,SiDnodes,...
2 Sielements,Vin,nin,pin,...
3 Fnin,Fpin,Gin,Gpin,D,l2,l2ox,...
7 % [V,n,p,res,niter] = QDDGOXnlpoisson (mesh,Dsides,Sinodes,SiDnodes,...
8 % Sielements,Vin,nin,pin,...
9 % Fnin,Fpin,Gin,Gpin,D,l2,l2ox,...
12 % solves $$ -\lambda^2 V'' + (n(V,Fn) - p(V,Fp) -D)$$
15 global DDGOXNLPOISSON_LAP DDGOXNLPOISSON_MASS DDGOXNLPOISSON_RHS
17 %% Set some useful constants
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 %% convert input vectors to columns
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 if Ucolumns(D)>Urows(D)
30 if Ucolumns(nin)>Urows(nin)
34 if Ucolumns(pin)>Urows(pin)
38 if Ucolumns(Vin)>Urows(Vin)
42 if Ucolumns(Fnin)>Urows(Fnin)
46 if Ucolumns(Fpin)>Urows(Fpin)
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %% setup FEM data structures
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 Nnodes = length(nodes);
56 Nelements = length(elements);
60 for ii = 1:length(Dsides)
61 Dedges=[Dedges,find(mesh.e(5,:)==Dsides(ii))];
64 % Set list of nodes with Dirichelet BCs
65 Dnodes = mesh.e(1:2,Dedges);
66 Dnodes = [Dnodes(1,:) Dnodes(2,:)];
67 Dnodes = unique(Dnodes);
69 % Set values of Dirichelet BCs
70 Bc = zeros(length(Dnodes),1);
71 % Set list of nodes without Dirichelet BCs
72 Varnodes = setdiff([1:Nnodes],Dnodes);
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %% we're going to solve
79 %% $$ - \lambda^2 (\delta V)'' + (\frac{\partial n}{\partial V} - \frac{\partial p}{\partial V})= -R $$
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 %% set $$ n_1 = nin $$ and $$ V = Vin $$
89 n = exp(V(Sinodes)+G-Fn);
90 p = exp(-V(Sinodes)-Gp+Fp);
91 n(SiDnodes) = nin(SiDnodes);
92 p(SiDnodes) = pin(SiDnodes);
96 %%% Compute LHS matrices
99 %% let's compute FEM approximation of $$ L = - \frac{d^2}{x^2} $$
100 if (isempty(DDGOXNLPOISSON_LAP))
101 coeff = l2ox * ones(Nelements,1);
102 coeff(Sielements)=l2;
103 DDGOXNLPOISSON_LAP = Ucomplap (mesh,coeff);
106 %% compute $$ Mv = ( n + p) $$
107 %% and the (lumped) mass matrix M
108 if (isempty(DDGOXNLPOISSON_MASS))
109 Cvect = zeros(Nelements,1);
111 DDGOXNLPOISSON_MASS = Ucompmass2 (mesh,ones(Nnodes,1),Cvect);
113 freecarr=zeros(Nnodes,1);
114 freecarr(Sinodes)=(n + p);
117 M = DDGOXNLPOISSON_MASS*sparse(diag(Mv));
120 %%% Compute RHS vector (-residual)
123 %% now compute $$ T0 = \frac{q}{\epsilon} (n - p - D) $$
124 if (isempty(DDGOXNLPOISSON_RHS))
125 DDGOXNLPOISSON_RHS = Ucompconst (mesh,ones(Nnodes,1),ones(Nelements,1));
127 totcharge = zeros(Nnodes,1);
128 totcharge(Sinodes)=(n - p - D);
130 T0 = Tv0 .* DDGOXNLPOISSON_RHS;
132 %% now we're ready to build LHS matrix and RHS of the linear system for 1st Newton step
133 A = DDGOXNLPOISSON_LAP + M;
134 R = DDGOXNLPOISSON_LAP * V + T0;
136 %% Apply boundary conditions
141 %% we need $$ \norm{R_1} $$ and $$ \norm{R_k} $$ for the convergence test
142 normr(1) = norm(R,inf);
148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 %% START OF THE NEWTON CYCLE
152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 fprintf(1,'\n***\nNewton iteration: %d, reldVnorm = %e\n***\n',newtit,reldVnorm);
159 dV(Varnodes) =(A)\(-R);
164 %% Start of th damping procedure
169 fprintf(1,'\ndamping iteration: %d, residual norm = %e\n',dit,normrnew);
173 n = exp(Vnew(Sinodes)+G-Fn);
174 p = exp(-Vnew(Sinodes)-Gp+Fp);
175 n(SiDnodes) = nin(SiDnodes);
176 p(SiDnodes) = pin(SiDnodes);
180 %%% Compute LHS matrices
183 %% let's compute FEM approximation of $$ L = - \frac{d^2}{x^2} $$
184 %L = Ucomplap (mesh,ones(Nelements,1));
186 %% compute $$ Mv = ( n + p) $$
187 %% and the (lumped) mass matrix M
188 freecarr=zeros(Nnodes,1);
189 freecarr(Sinodes)=(n + p);
191 M = DDGOXNLPOISSON_MASS*sparse(diag(Mv));%M = Ucompmass (mesh,Mv);
194 %%% Compute RHS vector (-residual)
197 %% now compute $$ T0 = \frac{q}{\epsilon} (n - p - D) $$
198 totcharge( Sinodes)=(n - p - D);
200 T0 = Tv0 .* DDGOXNLPOISSON_RHS;%T0 = Ucompconst (mesh,Tv0,ones(Nelements,1));
202 %% now we're ready to build LHS matrix and RHS of the linear system for 1st Newton step
203 A = DDGOXNLPOISSON_LAP + M;
204 R = DDGOXNLPOISSON_LAP * Vnew + T0;
206 %% Apply boundary conditions
211 %% compute $$ | R_{k+1} | $$ for the convergence test
212 normrnew= norm(R,inf);
214 % check if more damping is needed
215 if (normrnew > normr(newtit))
219 fprintf(1,'\nexiting damping cycle because residual norm = %e \n-----------\n',normrnew);
226 normr(newtit+1) = normrnew;
227 dVnorm = norm(tk*dV,inf);
229 % check if convergence has been reached
230 reldVnorm = dVnorm / norm(V,inf);
231 if (reldVnorm <= toll)
233 fprintf(1,'\nexiting newton cycle because reldVnorm= %e \n',reldVnorm);