From f957c14af48573d283c2ec12c430501fcf66605c Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Mon, 23 Feb 2004 05:48:26 +0000 Subject: [PATCH] *** empty log message *** --- Cantera/clib/src/ctfunc.cpp | 3 +++ Cantera/matlab/cantera/@Func/Func.m | 41 +++++++++++++++++++++++++++++ Cantera/matlab/cantera/polynom.m | 12 +++++++++ Cantera/src/Func1.h | 39 +++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 Cantera/matlab/cantera/@Func/Func.m create mode 100644 Cantera/matlab/cantera/polynom.m diff --git a/Cantera/clib/src/ctfunc.cpp b/Cantera/clib/src/ctfunc.cpp index 9c39f34ef..2bdb85926 100755 --- a/Cantera/clib/src/ctfunc.cpp +++ b/Cantera/clib/src/ctfunc.cpp @@ -56,6 +56,9 @@ extern "C" { else if (type == SumFuncType) { r = new Func1Sum(*_func(n), *_func(m)); } + else if (type == DiffFuncType) { + r = new Func1Diff(*_func(n), *_func(m)); + } else if (type == ProdFuncType) { r = new Func1Product(*_func(n), *_func(m)); } diff --git a/Cantera/matlab/cantera/@Func/Func.m b/Cantera/matlab/cantera/@Func/Func.m new file mode 100644 index 000000000..24727ba30 --- /dev/null +++ b/Cantera/matlab/cantera/@Func/Func.m @@ -0,0 +1,41 @@ +function x = Func(typ, n, p) +% +if ~isa(typ, 'char') + error('Function type must be a string') +end + +x.f1 = 0; +x.f2 = 0; +x.coeffs = 0; + +itype = -1; +if strcmp(typ, 'polynomial') + itype = 2; +elseif strcmp(typ,'fourier') + itype = 1; +elseif strcmp(typ,'arrhenius') + itype = 3; +end + +if itype > 0 + x.coeffs = p; + x.index = funcmethods(0,itype,n,p); +else + if strcmp(typ,'sum') + itype = 20; + elseif strcmp(typ,'diff') + itype = 25; + elseif strcmp(typ,'prod') + itype = 30; + elseif strcmp(typ,'ratio') + itype = 40; + end + x.f1 = n; + x.f2 = p; + x.index = funcmethods(0,itype,n.index,p.index); +end + +x.typ = typ; +x = class(x,'Func'); + + diff --git a/Cantera/matlab/cantera/polynom.m b/Cantera/matlab/cantera/polynom.m new file mode 100644 index 000000000..52a0b64f1 --- /dev/null +++ b/Cantera/matlab/cantera/polynom.m @@ -0,0 +1,12 @@ +function poly = polynom(coeffs) +% POLY - create a polynomial Func instance +% +[n m] = size(coeffs); +if n == 1 + poly = Func('polynomial',m - 1,coeffs) +elseif m == 1 + poly = Func('polynomial',n - 1,coeffs) +else + error('wrong shape for coefficient array') +end + diff --git a/Cantera/src/Func1.h b/Cantera/src/Func1.h index 6325e742c..4bb03ab39 100644 --- a/Cantera/src/Func1.h +++ b/Cantera/src/Func1.h @@ -24,6 +24,7 @@ namespace Cantera { const int PolyFuncType = 2; const int ArrheniusFuncType = 3; const int SumFuncType = 20; + const int DiffFuncType = 25; const int ProdFuncType = 30; const int RatioFuncType = 40; @@ -65,6 +66,23 @@ namespace Cantera { return r; } +// virtual string show(doublereal t) { +// int n; +// string s = ""; +// doublereal r = m_c[m_n-1]; +// for (n = m_n-1; n >= 0; n--) { +// s += fp2str(m_c[n]); +// if (n > 0) s += "*x"; +// if (n > 1) s += "^"+int2str(n); +// if (n > 0) { +// if (m_c[n] < 0.0) s += " - "; +// else +// r *= t; +// r += m_c[m_n - n - 1]; +// } +// return r; +// } + protected: int m_n; vector_fp m_c; @@ -159,6 +177,26 @@ namespace Cantera { private: }; + + /** + * Difference of two functions. + */ + class Func1Diff : public Func1 { + public: + Func1Diff(Func1& f1, Func1& f2) { + m_f1 = &f1; + m_f2 = &f2; + } + virtual ~Func1Diff() {} + virtual doublereal eval(doublereal t) { + return m_f1->eval(t) - m_f2->eval(t); + } + protected: + Func1 *m_f1, *m_f2; + private: + }; + + /** * Product of two functions. */ @@ -177,6 +215,7 @@ namespace Cantera { private: }; + /** * Ratio of two functions. */