]> Creatis software - CreaPhase.git/blob - octave_packages/odepkg-0.8.2/odepkg_testsuite_transistor.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / odepkg-0.8.2 / odepkg_testsuite_transistor.m
1 %# Copyright (C) 2007-2012, Thomas Treichl <treichl@users.sourceforge.net>
2 %# OdePkg - A package for solving ordinary differential equations and more
3 %#
4 %# This program is free software; you can redistribute it and/or modify
5 %# it under the terms of the GNU General Public License as published by
6 %# the Free Software Foundation; either version 2 of the License, or
7 %# (at your option) any later version.
8 %#
9 %# This program is distributed in the hope that it will be useful,
10 %# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 %# GNU General Public License for more details.
13 %#
14 %# You should have received a copy of the GNU General Public License
15 %# along with this program; If not, see <http://www.gnu.org/licenses/>.
16
17 %# -*- texinfo -*-
18 %# @deftypefn {Function File} {[@var{solution}] =} odepkg_testsuite_transistor (@var{@@solver}, @var{reltol})
19 %#
20 %# If this function is called with two input arguments and the first input argument @var{@@solver} is a function handle describing an OdePkg solver and the second input argument @var{reltol} is a double scalar describing the relative error tolerance then return the cell array @var{solution} with performance informations about the TRANSISTOR testsuite of differential algebraic equations after solving (DAE--test).
21 %#
22 %# Run examples with the command
23 %# @example
24 %# demo odepkg_testsuite_transistor
25 %# @end example
26 %#
27 %# This function has been ported from the "Test Set for IVP solvers" which is developed by the INdAM Bari unit project group "Codes and Test Problems for Differential Equations", coordinator F. Mazzia.
28 %# @end deftypefn
29 %#
30 %# @seealso{odepkg}
31
32 function vret = odepkg_testsuite_transistor (vhandle, vrtol)
33
34   if (nargin ~= 2) %# Check number and types of all input arguments
35     help  ('odepkg_testsuite_transistor');
36     error ('OdePkg:InvalidArgument', ...
37            'Number of input arguments must be exactly two');
38   elseif (~isa (vhandle, 'function_handle') || ~isscalar (vrtol))
39     print_usage;
40   end
41
42   vret{1} = vhandle; %# The handle for the solver that is used
43   vret{2} = vrtol;   %# The value for the realtive tolerance
44   vret{3} = vret{2}; %# The value for the absolute tolerance
45   vret{4} = vret{2}; %# The value for the first time step
46   %# Write a debug message on the screen, because this testsuite function
47   %# may be called more than once from a loop over all solvers present
48   fprintf (1, ['Testsuite TRANSISTOR, testing solver %7s with relative', ...
49     ' tolerance %2.0e\n'], func2str (vret{1}), vrtol); fflush (1);
50
51   %# Setting the integration algorithms option values
52   vstart = 0.0;   %# The point of time when solving is started
53   vstop  = 0.2;   %# The point of time when solving is stoped
54   vinit  = odepkg_testsuite_transistorinit; %# The initial values
55   vmass  = odepkg_testsuite_transistormass; %# The mass matrix
56
57   vopt = odeset ('Refine', 0, 'RelTol', vret{2}, 'AbsTol', vret{3}, ...
58     'InitialStep', vret{4}, 'Stats', 'on', 'NormControl', 'off', ...
59     'Jacobian', @odepkg_testsuite_transistorjac, 'Mass', vmass, ...
60     'MaxStep', vstop-vstart);
61
62   %# Calculate the algorithm, start timer and do solving
63   tic; vsol = feval (vhandle, @odepkg_testsuite_transistorfun, ...
64     [vstart, vstop], vinit, vopt);
65   vret{12} = toc;                    %# The value for the elapsed time
66   vref = odepkg_testsuite_transistorref; %# Get the reference solution vector
67   if (exist ('OCTAVE_VERSION') ~= 0)
68     vlst = vsol.y(end,:);
69   else
70     vlst = vsol.y(:,end);
71   end
72   vret{5}  = odepkg_testsuite_calcmescd (vlst, vref, vret{3}, vret{2});
73   vret{6}  = odepkg_testsuite_calcscd (vlst, vref, vret{3}, vret{2});
74   vret{7}  = vsol.stats.nsteps + vsol.stats.nfailed; %# The value for all evals
75   vret{8}  = vsol.stats.nsteps;   %# The value for success evals
76   vret{9}  = vsol.stats.nfevals;  %# The value for fun calls
77   vret{10} = vsol.stats.npds;     %# The value for partial derivations
78   vret{11} = vsol.stats.ndecomps; %# The value for LU decompositions
79
80 %# Returns the results for the TRANSISTOR problem
81 function f = odepkg_testsuite_transistorfun (t, y, varargin)
82   ub = 6; uf = 0.026; alpha = 0.99; beta = 1d-6;
83   r0 = 1000; r1 = 9000; r2 = 9000; r3 = 9000;
84   r4 = 9000; r5 = 9000; r6 = 9000; r7 = 9000;
85   r8 = 9000; r9 = 9000;
86
87   uet  = 0.1 * sin(200 * pi * t);
88   fac1 = beta * (exp((y(2) - y(3)) / uf) - 1);
89   fac2 = beta * (exp((y(5) - y(6)) / uf) - 1);
90
91   f(1,1) = (y(1) - uet) / r0;
92   f(2,1) = y(2) / r1 + (y(2) - ub) / r2 + (1 - alpha) * fac1;
93   f(3,1) = y(3) / r3 - fac1;
94   f(4,1) = (y(4) - ub) / r4 + alpha * fac1;
95   f(5,1) = y(5) / r5 + (y(5) - ub) / r6 + (1 - alpha) * fac2;
96   f(6,1) = y(6) / r7 - fac2;
97   f(7,1) = (y(7) - ub) / r8 + alpha * fac2;
98   f(8,1) = y(8) / r9;
99
100 %# Returns the INITIAL values for the TRANSISTOR problem
101 function vinit = odepkg_testsuite_transistorinit ()
102   vinit = [0, 3, 3, 6, 3, 3, 6, 0];
103
104 %# Returns the JACOBIAN matrix for the TRANSISTOR problem
105 function dfdy = odepkg_testsuite_transistorjac (t, y, varargin)
106   ub = 6; uf = 0.026; alpha = 0.99; beta = 1d-6;
107   r0 = 1000; r1 = 9000; r2 = 9000; r3 = 9000;
108   r4 = 9000; r5 = 9000; r6 = 9000; r7 = 9000;
109   r8 = 9000; r9 = 9000;
110
111   fac1p = beta * exp ((y(2) - y(3)) / uf) / uf;
112   fac2p = beta * exp ((y(5) - y(6)) / uf) / uf;
113
114   dfdy(1,1) =   1 / r0;
115   dfdy(2,2) =   1 / r1 + 1 / r2 + (1 - alpha) * fac1p;
116   dfdy(2,3) = - (1 - alpha) * fac1p;
117   dfdy(3,2) = - fac1p;
118   dfdy(3,3) =   1 / r3 + fac1p;
119   dfdy(4,2) =   alpha * fac1p;
120   dfdy(4,3) = - alpha * fac1p;
121   dfdy(4,4) =   1 / r4;
122   dfdy(5,5) =   1 / r5 + 1 / r6 + (1 - alpha) * fac2p;
123   dfdy(5,6) = - (1 - alpha) * fac2p;
124   dfdy(6,5) = - fac2p;
125   dfdy(6,6) =   1 / r7 + fac2p;
126   dfdy(7,5) =   alpha * fac2p;
127   dfdy(7,6) = - alpha * fac2p;
128   dfdy(7,7) =   1 / r8;
129   dfdy(8,8) =   1 / r9;
130
131 %# Returns the MASS matrix for the TRANSISTOR problem
132 function mass = odepkg_testsuite_transistormass (t, y, varargin)
133   mass =  [-1e-6,  1e-6,     0,     0,     0,     0,     0,      0; ...
134             1e-6, -1e-6,     0,     0,     0,     0,     0,      0; ...
135                0,     0, -2e-6,     0,     0,     0,     0,      0; ...
136                0,     0,     0, -3e-6,  3e-6,     0,     0,      0; ...
137                0,     0,     0,  3e-6, -3e-6,     0,     0,      0; ...
138                0,     0,     0,     0,     0, -4e-6,     0,      0; ...
139                0,     0,     0,     0,     0,     0, -5e-6,   5e-6; ...
140                0,     0,     0,     0,     0,     0,  5e-6,  -5e-6];
141
142 %# Returns the REFERENCE values for the TRANSISTOR problem
143 function y = odepkg_testsuite_transistorref ()
144   y(1,1) = -0.55621450122627e-2;
145   y(2,1) =  0.30065224719030e+1;
146   y(3,1) =  0.28499587886081e+1;
147   y(4,1) =  0.29264225362062e+1;
148   y(5,1) =  0.27046178650105e+1;
149   y(6,1) =  0.27618377783931e+1;
150   y(7,1) =  0.47709276316167e+1;
151   y(8,1) =  0.12369958680915e+1;
152
153 %!demo
154 %! vsolver = {@odebda, @oders, @ode2r, @ode5r, @odesx};
155 %! for vcnt=1:length (vsolver)
156 %!   vtrans{vcnt,1} = odepkg_testsuite_transistor (vsolver{vcnt}, 1e-7);
157 %! end
158 %! vtrans
159
160 %# Local Variables: ***
161 %# mode: octave ***
162 %# End: ***