*** empty log message ***
This commit is contained in:
parent
ab71bf66c4
commit
f957c14af4
4 changed files with 95 additions and 0 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
41
Cantera/matlab/cantera/@Func/Func.m
Normal file
41
Cantera/matlab/cantera/@Func/Func.m
Normal file
|
|
@ -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');
|
||||
|
||||
|
||||
12
Cantera/matlab/cantera/polynom.m
Normal file
12
Cantera/matlab/cantera/polynom.m
Normal file
|
|
@ -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
|
||||
|
||||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue