Skip to content

Commit

Permalink
[Func1] Remove superfluous argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jul 1, 2023
1 parent e5d56a8 commit 41513af
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 77 deletions.
3 changes: 1 addition & 2 deletions include/cantera/clib/ctfunc.h
Expand Up @@ -16,8 +16,7 @@ extern "C" {

CANTERA_CAPI int func_new(int type, size_t n, size_t lenp, const double* p);
CANTERA_CAPI int func_new_basic(const char* type, double c);
CANTERA_CAPI int func_new_advanced(
const char* type, size_t lenp, const double* p, size_t n);
CANTERA_CAPI int func_new_advanced(const char* type, size_t lenp, const double* p);
CANTERA_CAPI int func_new_compound(const char* type, int a, int b);
CANTERA_CAPI int func_new_modified(const char* type, int a, double c);
CANTERA_CAPI int func_del(int i);
Expand Down
22 changes: 11 additions & 11 deletions include/cantera/numerics/Func1.h
Expand Up @@ -274,7 +274,7 @@ class Sin1 : public Func1
}

//! Constructor uses single parameter (frequency)
Sin1(const vector<double>& params, size_t n=npos);
Sin1(const vector<double>& params);

Sin1(const Sin1& b) :
Func1(b) {
Expand Down Expand Up @@ -323,7 +323,7 @@ class Cos1 : public Func1
}

//! Constructor uses single parameter (frequency)
Cos1(const vector<double>& params, size_t n=npos);
Cos1(const vector<double>& params);

Cos1(const Cos1& b) :
Func1(b) {
Expand Down Expand Up @@ -368,7 +368,7 @@ class Exp1 : public Func1
}

//! Constructor uses single parameter (exponent factor)
Exp1(const vector<double>& params, size_t n=npos);
Exp1(const vector<double>& params);

Exp1(const Exp1& b) :
Func1(b) {
Expand Down Expand Up @@ -413,7 +413,7 @@ class Log1 : public Func1
}

//! Constructor uses single parameter (factor)
Log1(const vector<double>& params, size_t n=npos);
Log1(const vector<double>& params);

virtual string type() const {
return "log";
Expand Down Expand Up @@ -442,7 +442,7 @@ class Pow1 : public Func1
}

//! Constructor uses single parameter (exponent)
Pow1(const vector<double>& params, size_t n=npos);
Pow1(const vector<double>& params);

Pow1(const Pow1& b) :
Func1(b) {
Expand Down Expand Up @@ -495,7 +495,7 @@ class Tabulated1 : public Func1

//! Constructor uses \f$ 2 n\f$ parameters in the following order:
//! \f$ [t_0, t_1, \dots, t_{n-1}, f_0, f_1, \dots, f_{n-1}] \f$
Tabulated1(const vector<double>& params, size_t n);
Tabulated1(const vector<double>& params);

//! Set the interpolation method
//! @param method Evaluation method. If \c "linear" (default), a linear
Expand Down Expand Up @@ -540,7 +540,7 @@ class Const1 : public Func1
}

//! Constructor uses single parameter (constant)
Const1(const vector<double>& params, size_t n=npos);
Const1(const vector<double>& params);

Const1(const Const1& b) :
Func1(b) {
Expand Down Expand Up @@ -1098,7 +1098,7 @@ class Gaussian1 : public Func1

//! Constructor uses 3 parameters in the following order:
//! \f$ [A, t_0, \mathrm{fwhm}] \f$
Gaussian1(const vector<double>& params, size_t n=npos);
Gaussian1(const vector<double>& params);

Gaussian1(const Gaussian1& b) :
Func1(b) {
Expand Down Expand Up @@ -1171,7 +1171,7 @@ class Poly1 : public Func1

//! Constructor uses \f$ n + 1 \f$ parameters in the following order:
//! \f$ [a_n, \dots, a_1, a_0] \f$
Poly1(const vector<double>& params, size_t n);
Poly1(const vector<double>& params);

Poly1(const Poly1& b) :
Func1(b) {
Expand Down Expand Up @@ -1231,7 +1231,7 @@ class Fourier1 : public Func1

//! Constructor uses \f$ 2 n + 2 \f$ parameters in the following order:
//! \f$ [a_0, a_1, \dots, a_n, \omega, b_1, \dots, b_n] \f$
Fourier1(const vector<double>& params, size_t n);
Fourier1(const vector<double>& params);

Fourier1(const Fourier1& b) :
Func1(b) {
Expand Down Expand Up @@ -1299,7 +1299,7 @@ class Arrhenius1 : public Func1

//! Constructor uses \f$ 3 n\f$ parameters in the following order:
//! \f$ [A_1, b_1, E_1, A_2, b_2, E_2, \dots, A_n, b_n, E_n] \f$
Arrhenius1(const vector<double>& params, size_t n=1);
Arrhenius1(const vector<double>& params);

Arrhenius1(const Arrhenius1& b) :
Func1() {
Expand Down
6 changes: 2 additions & 4 deletions include/cantera/numerics/Func1Factory.h
Expand Up @@ -20,7 +20,7 @@ namespace Cantera
//! shared_ptr<Func1> d1 = newFunc1("sin", {1.0});
//! ```
//! @since New in Cantera 3.0
class Func1Factory : public Factory<Func1, const vector<double>&, size_t>
class Func1Factory : public Factory<Func1, const vector<double>&>
{
public:
/**
Expand Down Expand Up @@ -121,11 +121,9 @@ shared_ptr<Func1> newFunc1(const string& func1Type, double coeff=1.);
//! Create a new advanced functor object (see \ref func1advanced).
//! @param func1Type String identifying functor type.
//! @param params Parameter vector; definition depends on functor type.
//! @param n Integer; definition depends on function type and may or may not be used.
//! @ingroup func1advanced
//! @since New in Cantera 3.0
shared_ptr<Func1> newFunc1(const string& func1Type,
const vector<double>& params, size_t n=1);
shared_ptr<Func1> newFunc1(const string& func1Type, const vector<double>& params);

//! Create a new compound functor object (see \ref func1compound).
//! @param func1Type String identifying functor type.
Expand Down
12 changes: 6 additions & 6 deletions src/clib/ctfunc.cpp
Expand Up @@ -41,16 +41,16 @@ extern "C" {
r = newFunc1("constant", params[0]);
} else if (type == FourierFuncType) {
vector<double> par(params, params + lenp);
r = newFunc1("Fourier", par, n);
r = newFunc1("Fourier", par);
} else if (type == GaussianFuncType) {
vector<double> par(params, params + lenp);
r = newFunc1("Gaussian", par, n);
r = newFunc1("Gaussian", par);
} else if (type == PolyFuncType) {
vector<double> par(params, params + lenp);
r = newFunc1("polynomial", par, n);
r = newFunc1("polynomial", par);
} else if (type == ArrheniusFuncType) {
vector<double> par(params, params + lenp);
r = newFunc1("Arrhenius", par, n);
r = newFunc1("Arrhenius", par);
} else if (type == PeriodicFuncType) {
r = newFunc1("periodic", FuncCabinet::at(nn), params[0]);
} else if (type == SumFuncType) {
Expand Down Expand Up @@ -85,11 +85,11 @@ extern "C" {
}
}

int func_new_advanced(const char* type, size_t lenp, const double* params, size_t n)
int func_new_advanced(const char* type, size_t lenp, const double* params)
{
try {
vector<double> par(params, params + lenp);
return FuncCabinet::add(newFunc1(type, par, n));
return FuncCabinet::add(newFunc1(type, par));
} catch (...) {
return handleAllExceptions(-1, ERR);
}
Expand Down
60 changes: 29 additions & 31 deletions src/numerics/Func1.cpp
Expand Up @@ -147,7 +147,7 @@ void Func1::setParent(Func1* p)

/*****************************************************************************/

Sin1::Sin1(const vector<double>& params, size_t n)
Sin1::Sin1(const vector<double>& params)
{
if (params.size() != 1) {
throw CanteraError("Sin1::Sin1",
Expand Down Expand Up @@ -189,7 +189,7 @@ shared_ptr<Func1> Sin1::derivative3() const

/*****************************************************************************/

Cos1::Cos1(const vector<double>& params, size_t n)
Cos1::Cos1(const vector<double>& params)
{
if (params.size() != 1) {
throw CanteraError("Cos1::Cos1",
Expand Down Expand Up @@ -231,7 +231,7 @@ std::string Cos1::write(const std::string& arg) const

/**************************************************************************/

Exp1::Exp1(const vector<double>& params, size_t n)
Exp1::Exp1(const vector<double>& params)
{
if (params.size() != 1) {
throw CanteraError("Exp1::Exp1",
Expand Down Expand Up @@ -276,7 +276,7 @@ std::string Exp1::write(const std::string& arg) const
}
}

Log1::Log1(const vector<double>& params, size_t n)
Log1::Log1(const vector<double>& params)
{
if (params.size() != 1) {
throw CanteraError("Log1::Log1",
Expand Down Expand Up @@ -304,7 +304,7 @@ std::string Log1::write(const std::string& arg) const

/******************************************************************************/

Pow1::Pow1(const vector<double>& params, size_t n)
Pow1::Pow1(const vector<double>& params)
{
if (params.size() != 1) {
throw CanteraError("Pow1::Pow1",
Expand Down Expand Up @@ -349,7 +349,7 @@ shared_ptr<Func1> Pow1::derivative3() const

/******************************************************************************/

Const1::Const1(const vector<double>& params, size_t n)
Const1::Const1(const vector<double>& params)
{
if (params.size() != 1) {
throw CanteraError("Const1::Const1",
Expand All @@ -358,31 +358,28 @@ Const1::Const1(const vector<double>& params, size_t n)
m_c = params[0];
}

Poly1::Poly1(const vector<double>& params, size_t n)
Poly1::Poly1(const vector<double>& params)
{
if (n < 0) {
if (params.size() == 0) {
throw CanteraError("Poly1::Poly1",
"Parameter n must be at least 0.");
}
if (params.size() != n + 1) {
throw CanteraError("Poly1::Poly1",
"Constructor needs exactly n + 1 = {} parameters (with n={}).", n + 1, n);
"Constructor needs an array that is not empty.");
}
size_t n = params.size() - 1;
m_cpoly.resize(n + 1);
copy(params.data(), params.data() + m_cpoly.size(), m_cpoly.begin());
}

Fourier1::Fourier1(const vector<double>& params, size_t n)
Fourier1::Fourier1(const vector<double>& params)
{
if (n < 1) {
if (params.size() < 4) {
throw CanteraError("Fourier1::Fourier1",
"Parameter n must be at least 1.");
"Constructor needs an array with at least 4 entries.");
}
if (params.size() != 2 * n + 2) {
if (params.size() % 2 != 0) {
throw CanteraError("Fourier1::Fourier1",
"Constructor needs exactly 2 * n + 2 = {} parameters (with n={}).",
2 * n + 2, n);
"Constructor needs an array with an even number of entries.");
}
size_t n = params.size() / 2 - 1;
m_omega = params[n + 1];
m_a0_2 = 0.5 * params[0];
m_ccos.resize(n);
Expand All @@ -391,7 +388,7 @@ Fourier1::Fourier1(const vector<double>& params, size_t n)
copy(params.data() + n + 2, params.data() + 2 * n + 2, m_csin.begin());
}

Gaussian1::Gaussian1(const vector<double>& params, size_t n)
Gaussian1::Gaussian1(const vector<double>& params)
{
if (params.size() != 3) {
throw CanteraError("Gaussian1::Gaussian1",
Expand All @@ -402,17 +399,17 @@ Gaussian1::Gaussian1(const vector<double>& params, size_t n)
m_tau = params[2] / (2. * sqrt(log(2.)));
}

Arrhenius1::Arrhenius1(const vector<double>& params, size_t n)
Arrhenius1::Arrhenius1(const vector<double>& params)
{
if (n < 1) {
if (params.size() < 3) {
throw CanteraError("Arrhenius1::Arrhenius1",
"Parameter n must be at least 1.");
"Constructor needs an array with at least 3 entries.");
}
if (params.size() != 3 * n) {
if (params.size() % 3 != 0) {
throw CanteraError("Arrhenius1::Arrhenius1",
"Constructor needs exactly 3 * n parameters grouped as (Ai, bi, Ei) for "
"i=0..n-1.");
"Constructor needs an array with multiples of 3 entries.");
}
size_t n = params.size() / 3;
m_A.resize(n);
m_b.resize(n);
m_E.resize(n);
Expand Down Expand Up @@ -440,16 +437,17 @@ Tabulated1::Tabulated1(size_t n, const double* tvals, const double* fvals,
setMethod(method);
}

Tabulated1::Tabulated1(const vector<double>& params, size_t n) : m_isLinear(true)
Tabulated1::Tabulated1(const vector<double>& params) : m_isLinear(true)
{
if (n < 1) {
if (params.size() < 4) {
throw CanteraError("Tabulated1::Tabulated1",
"Parameter n must be at least 1.");
"Constructor needs an array with at least 4 entries.");
}
if (params.size() != 2 * n) {
if (params.size() % 2 != 0) {
throw CanteraError("Tabulated1::Tabulated1",
"Constructor needs exactly 2 * n = {} parameters (with n={}).", 2 * n, n);
"Constructor needs an array with an even number of entries.");
}
size_t n = params.size() / 2;
m_tvec.resize(n);
copy(params.data(), params.data() + n, m_tvec.begin());
for (auto it = std::begin(m_tvec) + 1; it != std::end(m_tvec); it++) {
Expand Down
45 changes: 22 additions & 23 deletions src/numerics/Func1Factory.cpp
Expand Up @@ -13,44 +13,44 @@ std::mutex Func1Factory::s_mutex;

Func1Factory::Func1Factory()
{
reg("functor", [](const vector<double>& params, size_t n) {
reg("functor", [](const vector<double>& params) {
return new Func1();
});
reg("sin", [](const vector<double>& params, size_t n) {
reg("sin", [](const vector<double>& params) {
return new Sin1(params);
});
reg("cos", [](const vector<double>& params, size_t n) {
reg("cos", [](const vector<double>& params) {
return new Cos1(params);
});
reg("exp", [](const vector<double>& params, size_t n) {
reg("exp", [](const vector<double>& params) {
return new Exp1(params);
});
reg("log", [](const vector<double>& params, size_t n) {
reg("log", [](const vector<double>& params) {
return new Log1(params);
});
reg("pow", [](const vector<double>& params, size_t n) {
reg("pow", [](const vector<double>& params) {
return new Pow1(params);
});
reg("constant", [](const vector<double>& params, size_t n) {
reg("constant", [](const vector<double>& params) {
return new Const1(params);
});
reg("polynomial", [](const vector<double>& params, size_t n) {
return new Poly1(params, n);
reg("polynomial", [](const vector<double>& params) {
return new Poly1(params);
});
reg("Fourier", [](const vector<double>& params, size_t n) {
return new Fourier1(params, n);
reg("Fourier", [](const vector<double>& params) {
return new Fourier1(params);
});
reg("Gaussian", [](const vector<double>& params, size_t n) {
return new Gaussian1(params, n);
reg("Gaussian", [](const vector<double>& params) {
return new Gaussian1(params);
});
reg("Arrhenius", [](const vector<double>& params, size_t n) {
return new Arrhenius1(params, n);
reg("Arrhenius", [](const vector<double>& params) {
return new Arrhenius1(params);
});
reg("tabulated-linear", [](const vector<double>& params, size_t n) {
return new Tabulated1(params, n);
reg("tabulated-linear", [](const vector<double>& params) {
return new Tabulated1(params);
});
reg("tabulated-previous", [](const vector<double>& params, size_t n) {
auto fcn = new Tabulated1(params, n);
reg("tabulated-previous", [](const vector<double>& params) {
auto fcn = new Tabulated1(params);
fcn->setMethod("previous");
return fcn;
});
Expand Down Expand Up @@ -145,14 +145,13 @@ void Math1FactoryB::deleteFactory()
shared_ptr<Func1> newFunc1(const string& func1Type, double coeff)
{
return shared_ptr<Func1>(
Func1Factory::factory()->create(func1Type, {coeff}, npos));
Func1Factory::factory()->create(func1Type, {coeff}));
}

shared_ptr<Func1> newFunc1(const string& func1Type,
const vector<double>& params, size_t n)
shared_ptr<Func1> newFunc1(const string& func1Type, const vector<double>& params)
{
return shared_ptr<Func1>(
Func1Factory::factory()->create(func1Type, params, n));
Func1Factory::factory()->create(func1Type, params));
}

shared_ptr<Func1> newFunc1(const string& func1Type, const shared_ptr<Func1> f1,
Expand Down

0 comments on commit 41513af

Please sign in to comment.