]> Creatis software - CreaPhase.git/blob - octave_packages/ocs-0.1.3/sbn/Mcapacitors.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / ocs-0.1.3 / sbn / Mcapacitors.m
1 ## Copyright (C) 2006,2007,2008  Carlo de Falco            
2 ##
3 ## This file is part of:
4 ## OCS - A Circuit Simulator for Octave
5 ##
6 ## OCS is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program (see the file LICENSE); if not,
17 ## see <http://www.gnu.org/licenses/>.
18 ##
19 ## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> 
20
21 ## -*- texinfo -*-
22 ##
23 ## @deftypefn{Function File} @
24 ## {[@var{a},@var{b},@var{c}]=} Mcapacitors(@var{string},@var{parameters},@
25 ## @var{parameternames},@var{extvar},@var{intvar},@var{t})
26 ##
27 ## SBN file implementing models for capacitors.
28 ##
29 ## @var{string} is used to select among models. Parameters are listed
30 ## as inner items. Possible models are:
31 ##
32 ## @enumerate
33 ## @item @var{string} = "LIN"  (Linear Capacitor)
34 ## @itemize @minus
35 ## @item C -> capacitance value
36 ## @end itemize
37 ## @item @var{string} = "MULTICAP" (Multipole Capacitor)
38 ## @itemize @minus
39 ## @item C -> capacitance values
40 ## @end itemize
41 ## @item @var{string} = "PDE_NMOS" (Drift-Diffusion PDE NMOS capacitor)
42 ## @itemize @minus
43 ## @item tbulk  -> bulk thickness
44 ## @item tox    -> oxide thickness
45 ## @item Nnodes -> number of nodes of 1D grid 
46 ## @item Na     -> bulk doping
47 ## @item toll   -> absolute tolerance
48 ## @item maxit  -> max iterations number
49 ## @item Area   -> device area
50 ## @end itemize
51 ## @end enumerate
52 ##
53 ## See the @cite{IFF file format specifications} for details about 
54 ## the output structures.
55 ##
56 ## @seealso{prs_iff,asm_initialize_system,asm_build_system}
57 ## @end deftypefn
58
59 function [a,b,c] = Mcapacitors(string,parameters,parameternames,extvar,intvar,t)
60   
61   if isempty(intvar)
62     intvar = 0;
63   endif
64
65   switch string 
66       ##LCR part
67     case "LIN"
68       for ii=1:length(parameternames)
69         eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])      
70       endfor
71             
72       a = [0 0 1; 0 0 -1; 0 0 0];
73       b = [0 0 0;0 0 0;-C C 1];
74       c = [0 0 0]';
75       break
76
77     case "MULTICAP"
78       
79       n = length(extvar);
80       C = reshape(parameters,n,n);
81       
82       a = [zeros(n) eye(n); zeros(n) zeros(n)];
83       b = [zeros(n) zeros(n); -C eye(n)];
84       c = [zeros(2*n,1)]';
85       
86       break  
87
88       ##NLC part
89     case "PDE_NMOS"
90       
91       constants
92       
93       tbulk =  1.5e-6;
94       tox   =  90e-9;
95       len = tbulk + tox;
96       Nnodes = 300;
97       Na=1e21;
98       toll  = 1e-10;
99       maxit = 1000;
100       Area = 1e-12;
101
102       for ii=1:length(parameternames)
103         eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])      
104       endfor
105       
106       Vg = extvar(1) - extvar(2);
107       q  = intvar(1);
108
109       [Q,C]=Mnmoscap(tbulk,tox,Area,Vg,Na,Nnodes,toll,maxit);
110       
111       a = [0 0 1; 0 0 -1; 0 0 0];
112       b = [0 0 0;0 0 0;C -C -1];
113       c = [0 0 Q-q]';
114       break  
115
116     otherwise
117       error (["unknown section:" string])
118   endswitch
119
120 endfunction
121 ## Non-linear 1D MOS structure.
122 ## FIXME: requires SECS1D!!!
123 function [Q,C]=Mnmoscap(tbulk,tox,Area,Vg,Na,Nnodes,toll,maxit);
124   
125   constants 
126
127   Nelements = Nnodes - 1;
128   len = tox+tbulk;
129   x = linspace(0,len,Nnodes)';
130   sinodes = find(x<=tbulk);
131   Nsinodes = length(sinodes);
132   NelementsSi = Nsinodes-1;
133   D = - Na* ones(Nsinodes,1);
134   pp = Na ;
135   p = pp* ones(Nsinodes,1);
136   n = (ni^2)./p;
137   Fn = 0*n;
138   Fp = 0*n;
139
140   V = -Phims + Vg * ones(Nnodes,1);
141   V(sinodes) = Fn + Vth*log(n/ni);
142   
143   ## Scaling
144   xs  = len;
145   ns  = norm(D,inf);
146   Din = D/ns;
147   Vs  = Vth;
148   xin   = x/xs;
149   nin   = n/ns;
150   pin   = p/ns;
151   Vin   = V/Vs;
152   Fnin  = (Fn - Vs * log(ni/ns))/Vs;
153   Fpin  = (Fp + Vs * log(ni/ns))/Vs;
154   
155   l2    = (Vs*esio2)/(q*ns*xs^2)* ones(Nelements,1);
156   l2(1:NelementsSi)    = (Vs*esi)/(q*ns*xs^2);
157   
158   ## Solution of Nonlinear Poisson equation
159   [V,nout,pout,res,niter] = DDGnlpoisson (xin,sinodes,Vin,nin,...
160                                        pin,Fnin,Fpin,Din,l2,...
161                                        toll,maxit,0);
162     
163   L = Ucomplap(xin,Nnodes,[],Nelements,l2);
164   C22 = L(end,end);
165   C12 = L(2:end-1,end);
166   C11 = L(2:end-1,2:end-1);
167
168   drdv  = zeros(Nnodes,1);    drdv(sinodes) = nout + pout;
169   coeff = zeros(Nelements,1); coeff(1:NelementsSi) = 1;
170   M     = Ucompmass(xin,Nnodes,[],[],drdv,coeff);
171   C     = C22 - C12'*((C11+M(2:end-1,2:end-1))\C12);
172   Q     =(C12'*V(2:end-1)+C22*V(end));
173
174   ## Descaling
175   C = Area*C*(q*ns*xs/Vs);
176   Q = Area*Q*(q*ns*xs);
177
178 endfunction