1 %# Copyright (C) 2007-2012, Thomas Treichl <treichl@users.sourceforge.net>
2 %# OdePkg - A package for solving ordinary differential equations and more
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.
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.
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/>.
18 %# @deftypefn {Function File} {[@var{solution}] =} odepkg_testsuite_implakzo (@var{@@solver}, @var{reltol})
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 a cell array @var{solution} with performance informations about the chemical AKZO Nobel testsuite of implicit differential algebraic equations after solving (IDE--test).
22 %# Run examples with the command
24 %# demo odepkg_testsuite_implakzo
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.
32 function vret = odepkg_testsuite_implakzo (vhandle, vrtol)
34 if (nargin ~= 2) %# Check number and types of all input arguments
35 help ('odepkg_testsuite_implakzo');
36 error ('OdePkg:InvalidArgument', ...
37 'Number of input arguments must be exactly two');
38 elseif (~isa (vhandle, 'function_handle') || ~isscalar (vrtol))
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 AKZO, testing solver %7s with relative', ...
49 ' tolerance %2.0e\n'], func2str (vret{1}), vrtol); fflush (1);
51 %# Setting the integration algorithms option values
52 vstart = 0.0; %# The point of time when solving is started
53 vstop = 180.0; %# The point of time when solving is stoped
54 [vinity, vinityd] = odepkg_testsuite_implakzoinit; %# The initial values
56 vopt = odeset ('Refine', 0, 'RelTol', vret{2}, 'AbsTol', vret{3}, ...
57 'InitialStep', vret{4}, 'Stats', 'on', 'NormControl', 'off', ...
58 'Jacobian', @odepkg_testsuite_implakzojac, 'MaxStep', vstop-vstart);
59 %# ,'OutputFcn', @odeplot, 'MaxStep', 1);
61 %# Calculate the algorithm, start timer and do solving
62 tic; vsol = feval (vhandle, @odepkg_testsuite_implakzofun, ...
63 [vstart, vstop], vinity, vinityd', vopt);
64 vret{12} = toc; %# The value for the elapsed time
65 vref = odepkg_testsuite_implakzoref; %# Get the reference solution vector
66 if (exist ('OCTAVE_VERSION') ~= 0)
71 vret{5} = odepkg_testsuite_calcmescd (vlst, vref, vret{3}, vret{2});
72 vret{6} = odepkg_testsuite_calcscd (vlst, vref, vret{3}, vret{2});
73 vret{7} = vsol.stats.nsteps + vsol.stats.nfailed; %# The value for all evals
74 vret{8} = vsol.stats.nsteps; %# The value for success evals
75 vret{9} = vsol.stats.nfevals; %# The value for fun calls
76 vret{10} = vsol.stats.npds; %# The value for partial derivations
77 vret{11} = vsol.stats.ndecomps; %# The value for LU decompositions
79 %# Return the results for the for the chemical AKZO problem
80 function res = odepkg_testsuite_implakzofun (t, y, yd, varargin)
81 k1 = 18.7; k2 = 0.58; k3 = 0.09; k4 = 0.42;
82 kbig = 34.4; kla = 3.3; ks = 115.83; po2 = 0.9;
85 r1 = k1 * y(1)^4 * sqrt (y(2));
86 r2 = k2 * y(3) * y(4);
87 r3 = k2 / kbig * y(1) * y(5);
88 r4 = k3 * y(1) * y(4)^2;
89 r5 = k4 * y(6)^2 * sqrt (y(2));
90 fin = kla * (po2 / hen - y(2));
92 res(1,1) = -2 * r1 + r2 - r3 - r4 - yd(1);
93 res(2,1) = -0.5 * r1 - r4 - 0.5 * r5 + fin - yd(2);
94 res(3,1) = r1 - r2 + r3 - yd(3);
95 res(4,1) = - r2 + r3 - 2 * r4 - yd(4);
96 res(5,1) = r2 - r3 + r5 - yd(5);
97 res(6,1) = ks * y(1) * y(4) - y(6) - yd(6);
99 %# Return the INITIAL values for the chemical AKZO problem
100 function [y0, yd0] = odepkg_testsuite_implakzoinit ()
101 y0 = [0.444, 0.00123, 0, 0.007, 0, 115.83 * 0.444 * 0.007];
102 yd0 = [-0.051, -0.014, 0.025, 0, 0.002, 0];
104 %# Return the JACOBIAN matrix for the chemical AKZO problem
105 function [dfdy, dfdyd] = odepkg_testsuite_implakzojac (t, y, varargin)
106 k1 = 18.7; k2 = 0.58; k3 = 0.09; k4 = 0.42;
107 kbig = 34.4; kla = 3.3; ks = 115.83; po2 = 0.9;
111 %# error ('odepkg_testsuite_implakzojac: Second input argument is negative');
116 r11 = 4 * k1 * y(1)^3 * sqrt (y(2));
117 r12 = 0.5 * k1 * y(1)^4 / sqrt (y(2));
120 r31 = (k2 / kbig) * y(5);
121 r35 = (k2 / kbig) * y(1);
123 r44 = 2 * k3 * y(1) * y(4);
124 r52 = 0.5 * k4 * y(6)^2 / sqrt (y(2));
125 r56 = 2 * k4 * y(6) * sqrt (y(2));
128 dfdy(1,1) = -2 * r11 - r31 - r41;
129 dfdy(1,2) = -2 * r12;
131 dfdy(1,4) = r24 - r44;
133 dfdy(2,1) = -0.5 * r11 - r41;
134 dfdy(2,2) = -0.5 * r12 - 0.5 * r52 + fin2;
136 dfdy(2,6) = -0.5 * r56;
137 dfdy(3,1) = r11 + r31;
142 dfdy(4,1) = r31 - 2 * r41;
144 dfdy(4,4) = -r24 - 2 * r44;
152 dfdy(6,1) = ks * y(4);
153 dfdy(6,4) = ks * y(1);
156 dfdyd = - [ 1, 0, 0, 0, 0, 0;
163 %# For the implicit form of the chemical AKZO Nobel problem a mass
164 %# matrix is not needed. This mass matrix is needed if the problem
165 %# is formulated in explicit form (cf. odepkg_testsuite_cemakzo.m).
166 %# function mass = odepkg_testsuite_implakzomass (t, y, varargin)
167 %# mass = [ 1, 0, 0, 0, 0, 0;
172 %# 0, 0, 0, 0, 0, 0 ];
174 %# Return the REFERENCE values for the chemical AKZO problem
175 function y = odepkg_testsuite_implakzoref ()
176 y(1,1) = 0.11507949206617e+0;
177 y(2,1) = 0.12038314715677e-2;
178 y(3,1) = 0.16115628874079e+0;
179 y(4,1) = 0.36561564212492e-3;
180 y(5,1) = 0.17080108852644e-1;
181 y(6,1) = 0.48735313103074e-2;
184 %! vsolver = {@odebdi};
185 %! for vcnt=1:length (vsolver)
186 %! vakzo{vcnt,1} = odepkg_testsuite_implakzo (vsolver{vcnt}, 1e-7);
190 %# Local Variables: ***