Commit 34e2a397 authored by Thomas Weber's avatar Thomas Weber

Imported Upstream version 0.0.8

parents
This diff is collapsed.
This diff is collapsed.
Name: SECS1D
Version: 0.0.8
Date: 2008-08-23
Author: Carlo de Falco
Maintainer: Carlo de Falco
Title: SEmi Conductor Simulator in 1D
Description: A Drift-Diffusion simulator for 1d semiconductor devices
Categories: Electrical Engineering
Depends: octave (>= 2.9.17)
Autoload: no
License: GPL version 2 or later
Url: http://www.comson.org/dem
secs1D >> SEmiConductor Simulator in 1D
DDG
DDGelectron_driftdiffusion
DDGgummelmap
DDGhole_driftdiffusion
DDGn2phin
DDGnlpoisson
DDGp2phip
DDGphin2n
DDGphip2p
DDGplotresults
DDN
DDNnewtonmap
Utilities
constants
Ubern
Ubernoulli
Ucompconst
Ucomplap
Ucompmass
Udriftdiffusion
Umediaarmonica
Uscharfettergummel
secs1d
## Generic Makefile to allow the octave-forge packages to be build and
## installed using "configure; make all; make install". This Makefile
## includes the capability to install to a temporary location, and install
## an on_uninstall.m file that prevents the user removing this package
## with Octave's package manager. This is useful for for the distribution's
## various package managers and is forced by defining DESTDIR and DISTPKG.
PKGDIR := $(shell pwd | sed -e 's|^.*/||')
TMPDIR ?= /tmp
PACKAGE ?= $(TMPDIR)/$(PKGDIR).tar.gz
PKG := $(shell echo $(PKGDIR) | sed -e 's|^\(.*\)-.*|\1|')
all: build package
build:
@if [ -e src/Makefile ]; then \
$(MAKE) -C src all; \
fi
package: build
@if [ -e src/Makefile ]; then \
mv src/Makefile src/Makefile.disable; \
fi; \
if [ -e src/configure ]; then \
mv src/configure src/configure.disable; \
fi; \
cd ..; tar -czf $(PACKAGE) $(PKGDIR); \
install:
@cd ../; \
if [ "X${DISTPKG}X" != "XX" ]; then \
stripcmd="unlink(pkg('local_list'));unlink(pkg('global_list'));"; \
fi; \
if [ "X$(DESTDIR)X" = "XX" ]; then \
pkgdir=`octave -H -q --no-site-file --eval "warning('off','all');pkg('install','$(PACKAGE)');l=pkg('list');disp(l{cellfun(@(x)strcmp(x.name,'$(PKG)'),l)}.dir);$$stripcmd;"`; \
else \
shareprefix=$(DESTDIR)/`octave -H -q --no-site-file --eval "disp(fullfile(OCTAVE_HOME(),'share','octave'));"`; \
libexecprefix=$(DESTDIR)/`octave -H -q --no-site-file --eval "disp(fullfile(octave_config_info('libexecdir'),'octave'));"`; \
octprefix=$$shareprefix/packages; \
archprefix=$$libexecprefix/packages; \
if [ ! -e $$octprefix ]; then \
mkdir -p $$octprefix; \
fi; \
if [ ! -e $$archprefix ]; then \
mkdir -p $$archprefix; \
fi; \
octave -H -q --no-site-file --eval "warning('off','all');pkg('prefix','$$octprefix','$$archprefix');pkg('global_list',fullfile('$$shareprefix','octave_packages'));pkg('local_list',fullfile('$$shareprefix','octave_packages'));pkg('install','-nodeps','-verbose','$(PACKAGE)');"; \
pkgdir=`octave -H -q --no-site-file --eval "warning('off','all');pkg('prefix','$$octprefix','$$archprefix');pkg('global_list',fullfile('$$shareprefix','octave_packages'));pkg('local_list',fullfile('$$shareprefix','octave_packages'));l=pkg('list');disp(l{cellfun(@(x)strcmp(x.name,'$(PKG)'),l)}.dir);$$stripcmd;"`; \
fi; \
if [ "X${DISTPKG}X" != "XX" ]; then \
if [ -e $$pkgdir/packinfo/on_uninstall.m ]; then \
mv $$pkgdir/packinfo/on_uninstall.m \
$$pkgdir/packinfo/on_uninstall.m.orig; \
fi; \
echo "function on_uninstall (desc)" > $$pkgdir/packinfo/on_uninstall.m; \
echo " error ('Can not uninstall %s installed by the $(DISTPKG) package manager', desc.name);" >> $$pkgdir/packinfo/on_uninstall.m; \
echo "endfunction" >> $$pkgdir/packinfo/on_uninstall.m; \
echo "#! /bin/sh -f" > $$pkgdir/packinfo/dist_admin; \
echo "if [ \"\$$1\" == \"install\" ]; then" >> $$pkgdir/packinfo/dist_admin; \
echo " octave -H -q --no-site-file --eval \"pkg('rebuild');\"" >> $$pkgdir/packinfo/dist_admin; \
echo "else" >> $$pkgdir/packinfo/dist_admin; \
echo " pkgdir=\`octave -H -q --no-site-file --eval \"pkg('rebuild');l=pkg('list');disp(l{cellfun(@(x)strcmp(x.name,'$(PKG)'),l)}.dir);\"\`" >> $$pkgdir/packinfo/dist_admin; \
echo " rm \$$pkgdir/packinfo/on_uninstall.m" >> $$pkgdir/packinfo/dist_admin; \
echo " if [ -e \$$pkgdir/packinfo/on_uninstall.m.orig ]; then" >> $$pkgdir/packinfo/dist_admin; \
echo " mv \$$pkgdir/packinfo/on_uninstall.m.orig \$$pkgdir/packinfo/on_uninstall.m" >> $$pkgdir/packinfo/dist_admin; \
echo " cd \$$pkgdir/packinfo" >> $$pkgdir/packinfo/dist_admin; \
echo " octave -q -H --no-site-file --eval \"l=pkg('list');on_uninstall(l{cellfun(@(x)strcmp(x.name,'$(PKG)'),l)});\"" >> $$pkgdir/packinfo/dist_admin; \
echo " fi" >> $$pkgdir/packinfo/dist_admin; \
echo "fi" >> $$pkgdir/packinfo/dist_admin; \
chmod a+x $$pkgdir/packinfo/dist_admin; \
fi;
clean:
rm $(PACKAGE)
$(MAKE) -C src clean
#! /bin/sh -f
if [ -e src/configure ]; then
cd src
./configure $*
fi
function n=DDGelectron_driftdiffusion(psi,x,ng,p,ni,tn,tp,un)
% n=DDGelectron_driftdiffusion(psi,x,ng,p)
% Solves the continuity equation for electrons
% input: psi electric potential
% x integration domain
% ng initial guess and BCs for electron density
% p hole density (for SRH recombination)
% output: n updated electron density
## This file is part of
##
## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
## -------------------------------------------------------------------
## Copyright (C) 2004-2007 Carlo de Falco
##
##
##
## SECS1D 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.
##
## SECS1D 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 SECS1D; If not, see <http://www.gnu.org/licenses/>.
nodes = x;
Nnodes =length(nodes);
elements = [[1:Nnodes-1]' [2:Nnodes]'];
Nelements=size(elements,1);
Bcnodes = [1;Nnodes];
nl = ng(1);
nr = ng(Nnodes);
h=nodes(elements(:,2))-nodes(elements(:,1));
c=1./h;
Bneg=Ubernoulli(-(psi(2:Nnodes)-psi(1:Nnodes-1)),1);
Bpos=Ubernoulli( (psi(2:Nnodes)-psi(1:Nnodes-1)),1);
d0 = [c(1).*Bneg(1); c(1:end-1).*Bpos(1:end-1)+c(2:end).*Bneg(2:end); c(end)*Bpos(end)];
d1 = [1000;-c.* Bpos];
dm1 = [-c.* Bneg;1000];
A = spdiags([dm1 d0 d1],-1:1,Nnodes,Nnodes);
b = zeros(Nnodes,1);%- A * ng;
% SRH Recombination term
SRHD = tp * (ng + ni) + tn * (p + ni);
SRHL = p ./ SRHD;
SRHR = ni.^2 ./ SRHD;
ASRH = Ucompmass (nodes,Nnodes,elements,Nelements,SRHL,ones(Nelements,1));
bSRH = Ucompconst (nodes,Nnodes,elements,Nelements,SRHR,ones(Nelements,1));
A = A + ASRH;
b = b + bSRH;
% Boundary conditions
b(Bcnodes) = [];
b(1) = - A(2,1) * nl;
b(end) = - A(end-1,end) * nr;
A(Bcnodes,:) = [];
A(:,Bcnodes) = [];
n = [nl; A\b ;nr];
% Last Revision:
% $Author: adb014 $
% $Date: 2008-02-04 16:26:27 +0100 (man, 04 feb 2008) $
function [odata,it,res] =...
DDGgummelmap (x,idata,toll,maxit,ptoll,pmaxit,verbose)
%
% [odata,it,res] =...
% DDGgummelmap (x,idata,toll,maxit,ptoll,pmaxit,verbose)
%
% Solves the scaled stationary bipolar DD equation system
% using Gummel algorithm
%
% input: x spatial grid
% idata.D doping profile
% idata.p initial guess for hole concentration
% idata.n initial guess for electron concentration
% idata.V initial guess for electrostatic potential
% idata.Fn initial guess for electron Fermi potential
% idata.Fp initial guess for hole Fermi potential
% idata.l2 scaled electric permittivity (diffusion coefficient in Poisson equation)
% idata.un scaled electron mobility
% idata.up scaled electron mobility
% idata.nis scaled intrinsic carrier density
% idata.tn scaled electron lifetime
% idata.tp scaled hole lifetime
% toll tolerance for Gummel iterarion convergence test
% maxit maximum number of Gummel iterarions
% ptoll tolerance for Newton iterarion convergence test for non linear Poisson
% pmaxit maximum number of Newton iterarions
% verbose verbosity level: 0,1,2
%
% output: odata.n electron concentration
% odata.p hole concentration
% odata.V electrostatic potential
% odata.Fn electron Fermi potential
% odata.Fp hole Fermi potential
% it number of Gummel iterations performed
% res total potential increment at each step
## This file is part of
##
## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
## -------------------------------------------------------------------
## Copyright (C) 2004-2007 Carlo de Falco
##
##
##
## SECS1D 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.
##
## SECS1D 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 SECS1D; If not, see <http://www.gnu.org/licenses/>.
odata = idata;
Nnodes=rows(x);
D = idata.D;
vout(:,1) = idata.V;
hole_density (:,1) = idata.p;
electron_density (:,1)= idata.n;
fermin (:,1)=idata.Fn;
fermip (:,1)=idata.Fp;
for i=1:1:maxit
if (verbose>1)
fprintf(1,'*****************************************************************\n');
fprintf(1,'**** start of gummel iteration number: %d\n',i);
fprintf(1,'*****************************************************************\n');
end
if (verbose>1)
fprintf(1,'solving non linear poisson equation\n\n');
end
[vout(:,2),electron_density(:,2),hole_density(:,2)] =...
DDGnlpoisson (x,[1:Nnodes],vout (:,1),electron_density(:,1),hole_density(:,1),...
fermin(:,1),fermip(:,1),D,idata.l2,ptoll,pmaxit,verbose);
if (verbose>1)
fprintf (1,'\n\nupdating electron qfl\n\n');
end
electron_density(:,3)=...
DDGelectron_driftdiffusion(vout(:,2), x, electron_density(:,2),hole_density(:,2),idata.nis,idata.tn,idata.tp,idata.un);
fermin(:,2) = DDGn2phin(vout(:,2),electron_density(:,3));
fermin(1,2) = idata.Fn(1);
fermin(end:2) = idata.Fn(end);
if (verbose>1)
fprintf(1,'updating hole qfl\n\n');
end
hole_density(:,3)=...
DDGhole_driftdiffusion(vout(:,2), x, hole_density(:,2),electron_density(:,2),idata.nis,idata.tn,idata.tp,idata.up);
fermip(:,2) = DDGp2phip(vout(:,2),hole_density(:,3));
fermip(1,2) = idata.Fp(1);
fermip(end,2) = idata.Fp(end);
if (verbose>1)
fprintf(1,'checking for convergence\n\n');
end
nrfn= norm(fermin(:,2)-fermin(:,1),inf);
nrfp= norm (fermip(:,2)-fermip(:,1),inf);
nrv = norm (vout(:,2)-vout(:,1),inf);
nrm(i) = max([nrfn;nrfp;nrv]);
if (verbose>1)
fprintf (1,' max(|phin_(k+1)-phinn_(k)| , |phip_(k+1)-phip_(k)| , |v_(k+1)- v_(k)| )= %d\n',nrm(i));
end
if (nrm(i)<toll)
break
end
vout(:,1) = vout(:,end);
hole_density (:,1) = hole_density (:,end) ;
electron_density (:,1)= electron_density (:,end);
fermin (:,1)= fermin (:,end);
fermip (:,1)= fermip (:,end);
if(verbose)
DDGplotresults(x,electron_density,hole_density,vout,fermin,fermip);
end
end
it = i;
res = nrm;
if (verbose>0)
fprintf(1,'\n\nInitial guess computed by DD: # of Gummel iterations = %d\n\n',it);
end
odata.n = electron_density(:,end);
odata.p = hole_density(:,end);
odata.V = vout(:,end);
odata.Fn = fermin(:,end);
odata.Fp = fermip(:,end);
function p=DDGhole_driftdiffusion(psi,x,pg,n,ni,tn,tp,up)
% p=DDGhole_driftdiffusion(psi,x,pg,n)
% Solves the continuity equation for holes
% input: psi electric potential
% x spatial grid
% pg initial guess and BCs for hole density
% n electron density (to compute SRH recombination)
% output: p updated hole density
## This file is part of
##
## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
## -------------------------------------------------------------------
## Copyright (C) 2004-2007 Carlo de Falco
##
##
##
## SECS1D 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.
##
## SECS1D 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 SECS1D; If not, see <http://www.gnu.org/licenses/>.
nodes = x;
Nnodes =length(nodes);
elements = [[1:Nnodes-1]' [2:Nnodes]'];
Nelements=size(elements,1);
Bcnodes = [1;Nnodes];
pl = pg(1);
pr = pg(Nnodes);
h=nodes(elements(:,2))-nodes(elements(:,1));
c=up./h;
Bneg=Ubernoulli(-(psi(2:Nnodes)-psi(1:Nnodes-1)),1);
Bpos=Ubernoulli( (psi(2:Nnodes)-psi(1:Nnodes-1)),1);
d0 = [c(1).*Bpos(1); c(1:end-1).*Bneg(1:end-1)+c(2:end).*Bpos(2:end); c(end)*Bneg(end)];
d1 = [1000;-c.* Bneg];
dm1 = [-c.* Bpos;1000];
A = spdiags([dm1 d0 d1],-1:1,Nnodes,Nnodes);
b = zeros(Nnodes,1);% - A * pg;
% SRH Recombination term
SRHD = tp * (n + ni) + tn * (pg + ni);
SRHL = n ./ SRHD;
SRHR = ni.^2 ./ SRHD;
ASRH = Ucompmass (nodes,Nnodes,elements,Nelements,SRHL,ones(Nelements,1));
bSRH = Ucompconst (nodes,Nnodes,elements,Nelements,SRHR,ones(Nelements,1));
A = A + ASRH;
b = b + bSRH;
% Boundary conditions
b(Bcnodes) = [];
b(1) = - A(2,1) * pl;
b(end) = - A(end-1,end) * pr;
A(Bcnodes,:) = [];
A(:,Bcnodes) = [];
p = [pl; A\b ;pr];
% Last Revision:
% $Author: adb014 $
% $Date: 2008-02-04 16:26:27 +0100 (man, 04 feb 2008) $
function phin = DDGn2phin (V,n);
% phin = DDGn2phin (V,n);
% computes the qfl for electrons using Maxwell-Boltzmann
% statistics.
## This file is part of
##
## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
## -------------------------------------------------------------------
## Copyright (C) 2004-2007 Carlo de Falco
##
##
##
## SECS1D 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.
##
## SECS1D 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 SECS1D; If not, see <http://www.gnu.org/licenses/>.
% load constants
nmin = 0;
n = n .* (n>nmin) + nmin * (n<=nmin);
phin = V - log(n) ;
% Last Revision:
% $Author: adb014 $
% $Date: 2008-02-04 16:26:27 +0100 (man, 04 feb 2008) $
function [V,n,p,res,niter] = DDGnlpoisson (x,sinodes,Vin,nin,...
pin,Fnin,Fpin,D,l2,toll,maxit,verbose)
% [V,n,p,res,niter] = DDGnlpoisson (x,sinodes,Vin,nin,...
% pin,Fnin,Fpin,D,l2,toll,maxit,verbose)
% Solves the non linear Poisson equation
% $$ - lamda^2 *V'' + (n(V,Fn) - p(V,Fp) -D)=0 $$
% input: x spatial grid
% sinodes index of the nodes of the grid which are in the
% semiconductor subdomain
% (remaining nodes are assumed to be in the oxide subdomain)
% Vin initial guess for the electrostatic potential
% nin initial guess for electron concentration
% pin initial guess for hole concentration
% Fnin initial guess for electron Fermi potential
% Fpin initial guess for hole Fermi potential
% D doping profile
% l2 scaled electric permittivity (diffusion coefficient)
% toll tolerance for convergence test
% maxit maximum number of Newton iterations
% verbose verbosity level: 0,1,2
% output: V electrostatic potential
% n electron concentration
% p hole concentration
% res residual norm at each step
% niter number of Newton iterations
## This file is part of
##
## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
## -------------------------------------------------------------------
## Copyright (C) 2004-2007 Carlo de Falco
##
##
##
## SECS1D 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.
##
## SECS1D 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 SECS1D; If not, see <http://www.gnu.org/licenses/>.
%% Set some useful constants
dampit = 10;
dampcoeff = 2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% convert grid info to FEM form
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ndiricheletnodes = 2;
nodes = x;
sielements = sinodes(1:end-1);
Nnodes = length(nodes);
totdofs = Nnodes - Ndiricheletnodes ;
elements = [[1:Nnodes-1]' , [2:Nnodes]'];
Nelements = size(elements,1);
BCnodes = [1;Nnodes];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% initialization:
%% we're going to solve
%% $$ - lamda^2*(\delta V)'' + (\frac{\partial n}{\partial V} -
%% \frac{\partial p}{\partial V})= -R $$
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% set $$ n_1 = nin $$ and $$ V = Vin $$
V = Vin;
Fn = Fnin;
Fp = Fpin;
n = DDGphin2n(V(sinodes),Fn);
p = DDGphip2p(V(sinodes),Fp);
if (sinodes(1)==1)
n(1)=nin(1);
p(1)=pin(1);
end
if (sinodes(end)==Nnodes)
n(end)=nin(end);
p(end)=pin(end);
end
%%%
%%% Compute LHS matrices
%%%
%% let's compute FEM approximation of $$ L = - \frac{d^2}{x^2} $$
L = Ucomplap (nodes,Nnodes,elements,Nelements,l2.*ones(Nelements,1));
%% compute $$ Mv = ( n + p) $$
%% and the (lumped) mass matrix M
Mv = zeros(Nnodes,1);
Mv(sinodes) = (n + p);
Cv = zeros(Nelements,1);
Cv(sielements)= 1;
M = Ucompmass (nodes,Nnodes,elements,Nelements,Mv,Cv);
%%%
%%% Compute RHS vector (-residual)
%%%
%% now compute $$ T0 = (n - p - D) $$
Tv0 = zeros(Nnodes,1);
Tv0(sinodes) = (n - p - D);
Cv = zeros(Nelements,1);
Cv(sielements)= 1;
T0 = Ucompconst (nodes,Nnodes,elements,Nelements,Tv0,Cv);
%% now we're ready to build LHS matrix and RHS of the linear system for 1st Newton step
A = L + M;
R = L * V + T0;
%% Apply boundary conditions
A(BCnodes,:) = [];
A(:,BCnodes) = [];
R(BCnodes) = [];
%% we need $$ \norm{R_1} $$ and $$ \norm{R_k} $$ for the convergence test
normr(1) = norm(R,inf);
relresnorm = 1;
reldVnorm = 1;
normrnew = normr(1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% START OF THE NEWTON CYCLE
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for newtit=1:maxit
if verbose
fprintf(1,'\n newton iteration: %d, reldVnorm = %e',newtit,reldVnorm);
end
dV =[0;(A)\(-R);0];
%%%%%%%%%%%%%%%%%%
%% Start of the damping procedure
%%%%%%%%%%%%%%%%%%
tk = 1;
for dit = 1:dampit
if verbose
fprintf(1,'\n damping iteration: %d, residual norm = %e',dit,normrnew);
end
Vnew = V + tk * dV;
n = DDGphin2n(Vnew(sinodes),Fn);
p = DDGphip2p(Vnew(sinodes),Fp);
if (sinodes(1)==1)
n(1)=nin(1);
p(1)=pin(1);
end
if (sinodes(end)==Nnodes)
n(end)=nin(end);
p(end)=pin(end);
end
%%%
%%% Compute LHS matrices
%%%
%% let's compute FEM approximation of $$ L = - \frac{d^2}{x^2} $$
%L = Ucomplap (nodes,Nnodes,elements,Nelements,ones(Nelements,1));
%% compute $$ Mv = ( n + p) $$
%% and the (lumped) mass matrix M
Mv = zeros(Nnodes,1);
Mv(sinodes) = (n + p);
Cv = zeros(Nelements,1);
Cv(sielements)= 1;
M = Ucompmass (nodes,Nnodes,elements,Nelements,Mv,Cv);
%%%
%%% Compute RHS vector (-residual)
%%%
%% now compute $$ T0 = (n - p - D) $$
Tv0 = zeros(Nnodes,1);
Tv0(sinodes) = (n - p - D);
Cv = zeros(Nelements,1);
Cv(sielements)= 1;
T0 = Ucompconst (nodes,Nnodes,elements,Nelements,Tv0,Cv);
%% now we're ready to build LHS matrix and RHS of the linear system for 1st Newton step
Anew = L + M;
Rnew = L * Vnew + T0;
%% Apply boundary conditions
Anew(BCnodes,:) = [];
Anew(:,BCnodes) = [];
Rnew(BCnodes) = [];
if ((dit>1)&(norm(Rnew,inf)>=norm(R,inf)))
if verbose
fprintf(1,'\nexiting damping cycle \n');
end
break
else
A = Anew;
R = Rnew;
end
%% compute $$ | R_{k+1} | $$ for the convergence test
normrnew= norm(R,inf);
% check if more damping is needed
if (normrnew > normr(newtit))
tk = tk/dampcoeff;
else
if verbose
fprintf(1,'\nexiting damping cycle because residual norm = %e \n',normrnew);
end
break
end
end
V = Vnew;