mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
Changed Functor into its standalone class.
This commit is contained in:
parent
9e64da1bcd
commit
3c822e4d5e
@ -80,11 +80,11 @@ classdef Func < handle
|
||||
% helper function to pass the correct parameters to the C
|
||||
% library
|
||||
if itype < 20
|
||||
[m, n] = size(p);
|
||||
lenp = m * n;
|
||||
[msize, nsize] = size(p);
|
||||
lenp = msize * nsize;
|
||||
nn = callct('func_new', itype, n, lenp, p);
|
||||
elseif itype < 45
|
||||
m = n;
|
||||
m = p;
|
||||
nn = callct('func_new', itype, n, m, 0);
|
||||
else
|
||||
nn = callct('func_new', itype, n, 0, p);
|
||||
@ -164,6 +164,12 @@ classdef Func < handle
|
||||
% :return:
|
||||
% Returns the value of the function evaluated at ``s``
|
||||
%
|
||||
|
||||
if length(s) > 1
|
||||
aa = eval(['a.', s(1).subs]);
|
||||
b = subsref(aa, s(2:end));
|
||||
return
|
||||
end
|
||||
if strcmp(s.type, '()')
|
||||
ind = s.subs{:};
|
||||
b = zeros(1, length(ind));
|
||||
@ -172,12 +178,14 @@ classdef Func < handle
|
||||
b(k) = callct('func_value', a.id, ind(k));
|
||||
end
|
||||
|
||||
elseif strcmp(s.type, '.')
|
||||
b = eval(['a.', s.subs]);
|
||||
else error('Specify value for x as p(x)');
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function s = get.char(f)
|
||||
function s = char(f)
|
||||
% Get the formatted string to display the function.
|
||||
%
|
||||
% s = f.char
|
||||
@ -188,17 +196,17 @@ classdef Func < handle
|
||||
% Formatted string displaying the function
|
||||
%
|
||||
if strcmp(f.typ, 'sum')
|
||||
s = ['(' char(f.f1) ') + (' char(f.f2) ')'];
|
||||
s = ['(' (f.f1.char) ') + (' f.f2.char ')'];
|
||||
elseif strcmp(f.typ, 'diff')
|
||||
s = ['(' char(f.f1) ') - (' char(f.f2) ')'];
|
||||
s = ['(' f.f1.char ') - (' f.f2.char ')'];
|
||||
elseif strcmp(f.typ, 'prod')
|
||||
s = ['(' char(f.f1) ') * (' char(f.f2) ')'];
|
||||
s = ['(' f.f1.char ') * (' f.f2.char ')'];
|
||||
elseif strcmp(f.typ, 'ratio')
|
||||
s = ['(' char(f.f1) ') / (' char(f.f2) ')'];
|
||||
elseif all(p.coeffs == 0)
|
||||
s = ['(' f.f1.char ') / (' f.f2.char ')'];
|
||||
elseif all(f.coeffs == 0)
|
||||
s = '0';
|
||||
elseif strcmp(f.typ, 'polynomial')
|
||||
d = length(p.coeffs) - 1;
|
||||
d = length(f.coeffs) - 1;
|
||||
s = [];
|
||||
nn = 0;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
function g = gaussian(peak, center, width)
|
||||
% Create a Gaussian :mat:func:`Func` instance.
|
||||
classdef gaussian < Func
|
||||
% Gaussian - Create a Gaussian :mat:func:`Func` instance.
|
||||
%
|
||||
% g = gaussian(peak, center, width)
|
||||
% f = gaussian(peak, center, width)
|
||||
%
|
||||
% :param peak:
|
||||
% The peak value
|
||||
@ -12,6 +12,12 @@ function g = gaussian(peak, center, width)
|
||||
% function at center +/- (width)/2 is one-half
|
||||
% the peak value.
|
||||
%
|
||||
methods
|
||||
|
||||
function f = gaussian(peak, center, width)
|
||||
f = f@Func('gaussian', 0, [peak, center, width]);
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
g = Func('gaussian', 0, [peak, center, width]);
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ equil();
|
||||
isentropic();
|
||||
reactor1();
|
||||
reactor2();
|
||||
surfreactor;
|
||||
surf_reactor;
|
||||
periodic_cstr;
|
||||
plug_flow_reactor;
|
||||
lithium_ion_battery
|
||||
|
Loading…
Reference in New Issue
Block a user