diff --git a/include/cantera/clib/ctfunc.h b/include/cantera/clib/ctfunc.h index b326f0ec46..19692c7a11 100644 --- a/include/cantera/clib/ctfunc.h +++ b/include/cantera/clib/ctfunc.h @@ -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); diff --git a/include/cantera/numerics/Func1.h b/include/cantera/numerics/Func1.h index 81ecbd47e6..2c82e8b84f 100644 --- a/include/cantera/numerics/Func1.h +++ b/include/cantera/numerics/Func1.h @@ -274,7 +274,7 @@ class Sin1 : public Func1 } //! Constructor uses single parameter (frequency) - Sin1(const vector& params, size_t n=npos); + Sin1(const vector& params); Sin1(const Sin1& b) : Func1(b) { @@ -323,7 +323,7 @@ class Cos1 : public Func1 } //! Constructor uses single parameter (frequency) - Cos1(const vector& params, size_t n=npos); + Cos1(const vector& params); Cos1(const Cos1& b) : Func1(b) { @@ -368,7 +368,7 @@ class Exp1 : public Func1 } //! Constructor uses single parameter (exponent factor) - Exp1(const vector& params, size_t n=npos); + Exp1(const vector& params); Exp1(const Exp1& b) : Func1(b) { @@ -413,7 +413,7 @@ class Log1 : public Func1 } //! Constructor uses single parameter (factor) - Log1(const vector& params, size_t n=npos); + Log1(const vector& params); virtual string type() const { return "log"; @@ -442,7 +442,7 @@ class Pow1 : public Func1 } //! Constructor uses single parameter (exponent) - Pow1(const vector& params, size_t n=npos); + Pow1(const vector& params); Pow1(const Pow1& b) : Func1(b) { @@ -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& params, size_t n); + Tabulated1(const vector& params); //! Set the interpolation method //! @param method Evaluation method. If \c "linear" (default), a linear @@ -540,7 +540,7 @@ class Const1 : public Func1 } //! Constructor uses single parameter (constant) - Const1(const vector& params, size_t n=npos); + Const1(const vector& params); Const1(const Const1& b) : Func1(b) { @@ -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& params, size_t n=npos); + Gaussian1(const vector& params); Gaussian1(const Gaussian1& b) : Func1(b) { @@ -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& params, size_t n); + Poly1(const vector& params); Poly1(const Poly1& b) : Func1(b) { @@ -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& params, size_t n); + Fourier1(const vector& params); Fourier1(const Fourier1& b) : Func1(b) { @@ -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& params, size_t n=1); + Arrhenius1(const vector& params); Arrhenius1(const Arrhenius1& b) : Func1() { diff --git a/include/cantera/numerics/Func1Factory.h b/include/cantera/numerics/Func1Factory.h index 0190c25908..f6ec5c0a16 100644 --- a/include/cantera/numerics/Func1Factory.h +++ b/include/cantera/numerics/Func1Factory.h @@ -20,7 +20,7 @@ namespace Cantera //! shared_ptr d1 = newFunc1("sin", {1.0}); //! ``` //! @since New in Cantera 3.0 -class Func1Factory : public Factory&, size_t> +class Func1Factory : public Factory&> { public: /** @@ -121,11 +121,9 @@ shared_ptr 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 newFunc1(const string& func1Type, - const vector& params, size_t n=1); +shared_ptr newFunc1(const string& func1Type, const vector& params); //! Create a new compound functor object (see \ref func1compound). //! @param func1Type String identifying functor type. diff --git a/src/clib/ctfunc.cpp b/src/clib/ctfunc.cpp index 641d1d9c4c..a05e83ae1f 100644 --- a/src/clib/ctfunc.cpp +++ b/src/clib/ctfunc.cpp @@ -41,16 +41,16 @@ extern "C" { r = newFunc1("constant", params[0]); } else if (type == FourierFuncType) { vector par(params, params + lenp); - r = newFunc1("Fourier", par, n); + r = newFunc1("Fourier", par); } else if (type == GaussianFuncType) { vector par(params, params + lenp); - r = newFunc1("Gaussian", par, n); + r = newFunc1("Gaussian", par); } else if (type == PolyFuncType) { vector par(params, params + lenp); - r = newFunc1("polynomial", par, n); + r = newFunc1("polynomial", par); } else if (type == ArrheniusFuncType) { vector 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) { @@ -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 par(params, params + lenp); - return FuncCabinet::add(newFunc1(type, par, n)); + return FuncCabinet::add(newFunc1(type, par)); } catch (...) { return handleAllExceptions(-1, ERR); } diff --git a/src/numerics/Func1.cpp b/src/numerics/Func1.cpp index 8b192cb2b9..012b6567d7 100644 --- a/src/numerics/Func1.cpp +++ b/src/numerics/Func1.cpp @@ -147,7 +147,7 @@ void Func1::setParent(Func1* p) /*****************************************************************************/ -Sin1::Sin1(const vector& params, size_t n) +Sin1::Sin1(const vector& params) { if (params.size() != 1) { throw CanteraError("Sin1::Sin1", @@ -189,7 +189,7 @@ shared_ptr Sin1::derivative3() const /*****************************************************************************/ -Cos1::Cos1(const vector& params, size_t n) +Cos1::Cos1(const vector& params) { if (params.size() != 1) { throw CanteraError("Cos1::Cos1", @@ -231,7 +231,7 @@ std::string Cos1::write(const std::string& arg) const /**************************************************************************/ -Exp1::Exp1(const vector& params, size_t n) +Exp1::Exp1(const vector& params) { if (params.size() != 1) { throw CanteraError("Exp1::Exp1", @@ -276,7 +276,7 @@ std::string Exp1::write(const std::string& arg) const } } -Log1::Log1(const vector& params, size_t n) +Log1::Log1(const vector& params) { if (params.size() != 1) { throw CanteraError("Log1::Log1", @@ -304,7 +304,7 @@ std::string Log1::write(const std::string& arg) const /******************************************************************************/ -Pow1::Pow1(const vector& params, size_t n) +Pow1::Pow1(const vector& params) { if (params.size() != 1) { throw CanteraError("Pow1::Pow1", @@ -349,7 +349,7 @@ shared_ptr Pow1::derivative3() const /******************************************************************************/ -Const1::Const1(const vector& params, size_t n) +Const1::Const1(const vector& params) { if (params.size() != 1) { throw CanteraError("Const1::Const1", @@ -358,31 +358,28 @@ Const1::Const1(const vector& params, size_t n) m_c = params[0]; } -Poly1::Poly1(const vector& params, size_t n) +Poly1::Poly1(const vector& 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& params, size_t n) +Fourier1::Fourier1(const vector& 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); @@ -391,7 +388,7 @@ Fourier1::Fourier1(const vector& params, size_t n) copy(params.data() + n + 2, params.data() + 2 * n + 2, m_csin.begin()); } -Gaussian1::Gaussian1(const vector& params, size_t n) +Gaussian1::Gaussian1(const vector& params) { if (params.size() != 3) { throw CanteraError("Gaussian1::Gaussian1", @@ -402,17 +399,17 @@ Gaussian1::Gaussian1(const vector& params, size_t n) m_tau = params[2] / (2. * sqrt(log(2.))); } -Arrhenius1::Arrhenius1(const vector& params, size_t n) +Arrhenius1::Arrhenius1(const vector& 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); @@ -440,16 +437,17 @@ Tabulated1::Tabulated1(size_t n, const double* tvals, const double* fvals, setMethod(method); } -Tabulated1::Tabulated1(const vector& params, size_t n) : m_isLinear(true) +Tabulated1::Tabulated1(const vector& 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++) { diff --git a/src/numerics/Func1Factory.cpp b/src/numerics/Func1Factory.cpp index b6002b1730..8b071775cf 100644 --- a/src/numerics/Func1Factory.cpp +++ b/src/numerics/Func1Factory.cpp @@ -13,44 +13,44 @@ std::mutex Func1Factory::s_mutex; Func1Factory::Func1Factory() { - reg("functor", [](const vector& params, size_t n) { + reg("functor", [](const vector& params) { return new Func1(); }); - reg("sin", [](const vector& params, size_t n) { + reg("sin", [](const vector& params) { return new Sin1(params); }); - reg("cos", [](const vector& params, size_t n) { + reg("cos", [](const vector& params) { return new Cos1(params); }); - reg("exp", [](const vector& params, size_t n) { + reg("exp", [](const vector& params) { return new Exp1(params); }); - reg("log", [](const vector& params, size_t n) { + reg("log", [](const vector& params) { return new Log1(params); }); - reg("pow", [](const vector& params, size_t n) { + reg("pow", [](const vector& params) { return new Pow1(params); }); - reg("constant", [](const vector& params, size_t n) { + reg("constant", [](const vector& params) { return new Const1(params); }); - reg("polynomial", [](const vector& params, size_t n) { - return new Poly1(params, n); + reg("polynomial", [](const vector& params) { + return new Poly1(params); }); - reg("Fourier", [](const vector& params, size_t n) { - return new Fourier1(params, n); + reg("Fourier", [](const vector& params) { + return new Fourier1(params); }); - reg("Gaussian", [](const vector& params, size_t n) { - return new Gaussian1(params, n); + reg("Gaussian", [](const vector& params) { + return new Gaussian1(params); }); - reg("Arrhenius", [](const vector& params, size_t n) { - return new Arrhenius1(params, n); + reg("Arrhenius", [](const vector& params) { + return new Arrhenius1(params); }); - reg("tabulated-linear", [](const vector& params, size_t n) { - return new Tabulated1(params, n); + reg("tabulated-linear", [](const vector& params) { + return new Tabulated1(params); }); - reg("tabulated-previous", [](const vector& params, size_t n) { - auto fcn = new Tabulated1(params, n); + reg("tabulated-previous", [](const vector& params) { + auto fcn = new Tabulated1(params); fcn->setMethod("previous"); return fcn; }); @@ -145,14 +145,13 @@ void Math1FactoryB::deleteFactory() shared_ptr newFunc1(const string& func1Type, double coeff) { return shared_ptr( - Func1Factory::factory()->create(func1Type, {coeff}, npos)); + Func1Factory::factory()->create(func1Type, {coeff})); } -shared_ptr newFunc1(const string& func1Type, - const vector& params, size_t n) +shared_ptr newFunc1(const string& func1Type, const vector& params) { return shared_ptr( - Func1Factory::factory()->create(func1Type, params, n)); + Func1Factory::factory()->create(func1Type, params)); } shared_ptr newFunc1(const string& func1Type, const shared_ptr f1,