]> Creatis software - CreaPhase.git/blob - octave_packages/ocs-0.1.3/sbn/Mresistors.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / ocs-0.1.3 / sbn / Mresistors.m
1 ## Copyright (C) 2006,2007,2008  Carlo de Falco, Culpo Massimiliano
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 ## author: culpo@math.uni-wuppertal.de
21
22 ## -*- texinfo -*-
23 ##
24 ## @deftypefn{Function File} @
25 ## {[@var{a},@var{b},@var{c}]=}Mresistors(@var{string},@var{parameters},@
26 ## @var{parameternames},@var{extvar},@var{intvar},@var{t})
27 ##
28 ## SBN file implementing models for resistors.
29 ## 
30 ## @var{string} is used to select among models. Parameters are listed
31 ## as inner items. Possible models are:
32 ##
33 ## @enumerate
34 ## @item @var{string} = "LIN" (Linear resistor)
35 ## @itemize @minus
36 ## @item R -> resistance value
37 ## @end itemize
38 ## @item @var{string} = "THERMAL" (Linear resistor with termal pin)
39 ## @itemize @minus
40 ## @item R0   -> reference resistance value at temperature @code{TNOM}
41 ## @item TC1  -> coefficient for first order Taylor expansion
42 ## @item TC2  -> coefficient for second order Taylor expansion
43 ## @item TNOM -> reference temperature
44 ## @end itemize
45 ## @item @var{string} = "THERMAL1D" (1D Thermal resistor)
46 ## @itemize @minus
47 ## @item L  -> length of 1D domain
48 ## @item N  -> number of discretized elements
49 ## @item cv -> PDE coefficient for dynamic part
50 ## @item k  -> PDE coefficient for diffusion part
51 ## @end itemize
52 ## @end enumerate
53 ##
54 ## See the @cite{IFF file format specifications} for details about 
55 ## the output structures.
56 ##
57 ## @seealso{prs_iff,asm_initialize_system,asm_build_system}
58 ## @end deftypefn
59
60
61 function [a,b,c] =Mresistors(string,parameters,parameternames,extvar,intvar,t)
62   
63   switch string 
64     ## LCR part
65     case "LIN"
66       for ii=1:length(parameternames)
67         eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])      
68       endfor
69       
70       vp = extvar(1);
71       vm = extvar(2);
72       
73       a = zeros(2);
74       b = [1 -1 ;-1 1]/R;
75       c = -[0; 0];
76       
77       break
78       ##NLCpart
79     case "THERMAL"
80
81       for ii=1:length(parameternames)
82         eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])      
83       endfor
84       
85       v1 = extvar(1);
86       v2 = extvar(2);
87       T  = extvar(3);
88       
89       RT = R0*(1 + TC1*(T-TNOM) + TC2*(T - TNOM)^2);
90       dRdT = R0*(TC1 + 2*TC2*(T-TNOM));
91       
92       i1 = (v1-v2)/RT;
93       i2 = (v2-v1)/RT;
94       P  = -(v1-v2)^2/RT;
95       
96       a = zeros(3);
97       b = [ 1/RT -1/RT (v2-v1)*dRdT/RT^2;... 
98            -1/RT 1/RT  (v1-v2)*dRdT/RT^2;...
99            -2*(v1-v2)/RT -2*(v2-v1)/RT (v1-v2)^2*dRdT/RT^2];
100       c = [i1 i2 P]';
101       
102       break;
103       
104       case "THERMAL1D"
105          
106          for ii=1:length(parameternames)
107                 eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])      
108          endfor
109
110          h = L/N;
111          
112          A       = (cv*S*h)*speye(N+1);
113          
114          B       = spdiags([ -ones(N+1,1) 2*ones(N+1,1) -ones(N+1,1)],-1:1,N+1,N+1);
115          B(1 ,1)     = 1;
116          B(N+1 ,N+1) = 1;
117          
118          ext=[1 N+1];
119          int=[2:N];
120          
121          a = [A(ext,ext), A(ext,int); A(int,ext), A(int,int)];    
122          b = k*(S/h)*[B(ext,ext), B(ext,int); B(int,ext), B(int,int)];
123          c = zeros(N+1,1);
124       
125       break;
126       
127       otherwise
128       error (["unknown section:" string])
129   endswitch
130
131 endfunction