36 "Needs to be overloaded by Func1 specialization.");
41 if (
type() ==
"functor" ||
type() != other->type() || m_c != other->m_c) {
48 if (!m_f1->isIdentical(other->m_f1)) {
56 if (!m_f2->isIdentical(other->m_f2)) {
67 "Deprecated in Cantera 3.1; replaced by version using shared_ptr<Func1>.");
84Sin1::Sin1(
const vector<double>& params)
86 if (params.size() != 1) {
88 "Constructor needs exactly one parameter (frequency).");
96 return fmt::format(
"\\sin({})", arg);
98 return fmt::format(
"\\sin({}{})", m_c, arg);
104 auto c = make_shared<Cos1>(m_c);
110Cos1::Cos1(
const vector<double>& params)
112 if (params.size() != 1) {
114 "Constructor needs exactly one parameter (frequency).");
121 auto s = make_shared<Sin1>(m_c);
128 return fmt::format(
"\\cos({})", arg);
130 return fmt::format(
"\\cos({}{})", m_c, arg);
136Exp1::Exp1(
const vector<double>& params)
138 if (params.size() != 1) {
140 "Constructor needs exactly one parameter (exponent factor).");
147 auto f = make_shared<Exp1>(m_c);
157 return fmt::format(
"\\exp({})", arg);
159 return fmt::format(
"\\exp({}{})", m_c, arg);
163Log1::Log1(
const vector<double>& params)
165 if (params.size() != 1) {
167 "Constructor needs exactly one parameter (factor).");
174 auto f = make_shared<Pow1>(-1.);
184 return fmt::format(
"\\log({})", arg);
186 return fmt::format(
"\\log({}{})", m_c, arg);
191Pow1::Pow1(
const vector<double>& params)
193 if (params.size() != 1) {
195 "Constructor needs exactly one parameter (exponent).");
203 return make_shared<Const1>(0.0);
206 return make_shared<Const1>(1.0);
208 auto f = make_shared<Pow1>(m_c - 1.);
214Const1::Const1(
const vector<double>& params)
216 if (params.size() != 1) {
218 "Constructor needs exactly one parameter (constant).");
223Poly13::Poly13(
const vector<double>& params)
225 if (params.size() == 0) {
227 "Constructor needs an array that is not empty.");
229 size_t n = params.size() - 1;
230 m_cpoly.resize(n + 1);
231 copy(params.data(), params.data() + m_cpoly.size(), m_cpoly.begin());
238 if (m_cpoly[m_cpoly.size()-1] != 0.) {
239 out = fmt::format(
"{}", m_cpoly[m_cpoly.size()-1]);
241 for (
size_t n=1; n<m_cpoly.size(); n++) {
242 if (m_cpoly[m_cpoly.size()-1-n] == 0.) {
246 if (m_cpoly[m_cpoly.size()-1-n] == 1.) {
247 term = fmt::format(
"{}", arg);
248 }
else if (m_cpoly[m_cpoly.size()-1-n] == -1.) {
249 term = fmt::format(
"-{}", arg);
251 term = fmt::format(
"{}{}", m_cpoly[m_cpoly.size()-1-n], arg);
254 term = fmt::format(
"{}^{{{}}}", term, n);
256 term = fmt::format(
"{}^{}", term, n);
260 }
else if (out[0] ==
'-') {
261 out = fmt::format(
"{} - {}", term, out.substr(1));
263 out = fmt::format(
"{} + {}", term, out);
269Fourier1::Fourier1(
const vector<double>& params)
271 if (params.size() < 4) {
273 "Constructor needs an array with at least 4 entries.");
275 if (params.size() % 2 != 0) {
277 "Constructor needs an array with an even number of entries.");
279 size_t n = params.size() / 2 - 1;
280 m_omega = params[n + 1];
281 m_a0_2 = 0.5 * params[0];
284 copy(params.data() + 1, params.data() + n + 1, m_ccos.begin());
285 copy(params.data() + n + 2, params.data() + 2 * n + 2, m_csin.begin());
288Gaussian1::Gaussian1(
const vector<double>& params)
290 if (params.size() != 3) {
292 "Constructor needs exactly 3 parameters (amplitude, center, width).");
296 m_tau = params[2] / (2. * sqrt(log(2.)));
299Arrhenius1::Arrhenius1(
const vector<double>& params)
301 if (params.size() < 3) {
303 "Constructor needs an array with at least 3 entries.");
305 if (params.size() % 3 != 0) {
307 "Constructor needs an array with multiples of 3 entries.");
309 size_t n = params.size() / 3;
313 for (
size_t i = 0; i < n; i++) {
315 m_A[i] = params[loc];
316 m_b[i] = params[loc + 1];
317 m_E[i] = params[loc + 2];
322 const string& method)
325 std::copy(tvals, tvals + n,
m_tvec.begin());
326 for (
auto it = std::begin(
m_tvec) + 1; it != std::end(
m_tvec); it++) {
327 if (*(it - 1) > *it) {
329 "time values are not increasing monotonically.");
333 std::copy(fvals, fvals + n,
m_fvec.begin());
339 if (params.size() < 4) {
341 "Constructor needs an array with at least 4 entries.");
343 if (params.size() % 2 != 0) {
345 "Constructor needs an array with an even number of entries.");
347 size_t n = params.size() / 2;
349 copy(params.data(), params.data() + n,
m_tvec.begin());
350 for (
auto it = std::begin(
m_tvec) + 1; it != std::end(
m_tvec); it++) {
351 if (*(it - 1) > *it) {
353 "Time values are not monotonically increasing.");
357 copy(params.data() + n, params.data() + 2 * n,
m_fvec.begin());
362 if (method ==
"linear") {
364 }
else if (method ==
"previous") {
368 "Interpolation method '{}' is not implemented.", method);
373 size_t siz =
m_tvec.size();
377 }
else if (t >=
m_tvec[siz-1]) {
381 while (t >
m_tvec[ix+1]) {
398 size_t siz =
m_tvec.size();
402 for (
size_t i=1; i<siz; i++) {
405 tvec.push_back(
m_tvec[i-1]);
409 tvec.push_back(
m_tvec[siz-1]);
413 tvec.push_back(
m_tvec[0]);
414 tvec.push_back(
m_tvec[siz-1]);
418 return make_shared<Tabulated1>(tvec.size(), &tvec[0], &dvec[0],
"previous");
425 return fmt::format(
"\\mathrm{{{}}}({})",
type(), arg);
431 return "\\sqrt{" + arg +
"}";
434 return "\\frac{1}{\\sqrt{" + arg +
"}}";
437 return fmt::format(
"\\left({}\\right)^{{{}}}", arg, m_c);
445 return fmt::format(
"\\mathrm{{Tabulated}}({})", arg);
450 return fmt::format(
"{}", m_c);
455 return "\\frac{" + m_f1->write(arg) +
"}{" + m_f2->write(arg) +
"}";
468 string s = m_f1->write(arg);
469 if (m_f1->order() <
order()) {
470 s =
"\\left(" + s +
"\\right)";
472 string s2 = m_f2->write(arg);
473 if (m_f2->order() <
order()) {
474 s2 =
"\\left(" + s2 +
"\\right)";
487 string s1 = m_f1->write(arg);
488 string s2 = m_f2->write(arg);
490 return s1 +
" - " + s2.substr(1,s2.size());
492 return s1 +
" + " + s2;
498 string s1 = m_f1->write(arg);
499 string s2 = m_f2->write(arg);
501 return s1 +
" + " + s2.substr(1,s2.size());
503 return s1 +
" - " + s2;
509 string g = m_f2->write(arg);
510 return m_f1->write(g);
514 auto d1 = m_f1->derivative();
515 auto d2 = m_f2->derivative();
522 string s = m_f1->write(arg);
523 if (m_f1->order() <
order()) {
524 s =
"\\left(" + s +
"\\right)";
533 if (n >=
'0' && n <=
'9') {
534 s =
"\\left(" + s +
"\\right)";
536 return fmt::format(
"{}{}", m_c, s);
542 return m_f1->write(arg);
544 return fmt::format(
"{} + {}", m_f1->write(arg), m_c);
550 "Func1::isProportional",
551 "Deprecated in Cantera 3.1; replaced by internal function.");
561 "Func1::isProportional",
562 "Deprecated in Cantera 3.1; replaced by internal function.");
572bool isConstant(
const shared_ptr<Func1>& f)
574 return f->type() ==
"constant";
577bool isZero(
const shared_ptr<Func1>& f)
579 return f->type() ==
"constant" && f->c() == 0.0;
582bool isOne(
const shared_ptr<Func1>& f)
584 return f->type() ==
"constant" && f->c() == 1.0;
587bool isTimesConst(
const shared_ptr<Func1>& f)
589 return f->type() ==
"times-constant";
592bool isExp(
const shared_ptr<Func1>& f)
594 return f->type() ==
"exp";
597bool isPow(
const shared_ptr<Func1>& f)
599 return f->type() ==
"pow";
602pair<bool, double> isProportional(
603 const shared_ptr<Func1>&f1,
const shared_ptr<Func1>&f2)
605 bool tc1 = isTimesConst(f1);
606 bool tc2 = isTimesConst(f2);
608 if (f1->isIdentical(f2)) {
614 if (f1->isIdentical((f2->func1_shared()))) {
615 return {
true, f2->c()};
620 if (f2->isIdentical((f1->func1_shared()))) {
621 return {
true, 1. / f1->c()};
625 if (f2->func1_shared()->isIdentical((f1->func1_shared()))) {
626 return {
true, f2->c() / f1->c()};
635 if (f1->isIdentical(f2)) {
644 if (isConstant(f2)) {
647 if (isConstant(f1)) {
650 auto [prop, c] = isProportional(f1, f2);
653 return make_shared<Const1>(0.);
657 return make_shared<Sum1>(f1, f2);
668 if (f1->isIdentical(f2)) {
669 return make_shared<Const1>(0.);
671 if (isConstant(f2)) {
674 auto [prop, c] = isProportional(f1, f2);
677 return make_shared<Const1>(0.);
681 return make_shared<Diff1>(f1, f2);
692 if (isZero(f1) || isZero(f2)) {
693 return make_shared<Const1>(0.);
695 if (isConstant(f1) && isConstant(f2)) {
696 return make_shared<Const1>(f1->c() * f2->c());
698 if (isConstant(f1)) {
701 if (isConstant(f2)) {
704 if (isPow(f1) && isPow(f2)) {
705 return make_shared<Pow1>(f1->c() + f2->c());
707 if (isExp(f1) && isExp(f2)) {
708 return make_shared<Exp1>(f1->c() + f2->c());
711 bool tc1 = isTimesConst(f1);
712 bool tc2 = isTimesConst(f2);
719 ff1 = f1->func1_shared();
725 ff2 = f2->func1_shared();
729 if (c1 * c2 != 1.0) {
734 return make_shared<Product1>(f1, f2);
743 return make_shared<Const1>(0.);
746 throw CanteraError(
"newRatioFunction",
"Division by zero.");
748 if (f1->isIdentical(f2)) {
749 return make_shared<Const1>(1.);
751 if (isConstant(f2)) {
754 if (isPow(f1) && isPow(f2)) {
755 return make_shared<Pow1>(f1->c() - f2->c());
757 if (isExp(f1) && isExp(f2)) {
758 return make_shared<Exp1>(f1->c() - f2->c());
760 return make_shared<Ratio1>(f1, f2);
766 return make_shared<Const1>(0.0);
768 if (isConstant(f1)) {
771 if (isPow(f1) && f1->c() == 1.0) {
774 if (isPow(f1) && f1->c() == 0.0) {
775 return make_shared<Const1>(1.);
777 if (isPow(f1) && isPow(f2)) {
778 return make_shared<Pow1>(f1->c() * f2->c());
780 return make_shared<Composite1>(f1, f2);
786 return make_shared<Const1>(0.0);
791 if (f->type() ==
"times-constant") {
792 return make_shared<TimesConstant1>(f->func1_shared(), f->c() * c);
794 return make_shared<TimesConstant1>(f, c);
803 return make_shared<Const1>(f->c() + c);
805 if (f->type() ==
"plus-constant") {
806 return make_shared<PlusConstant1>(f->func1_shared(), f->c() + c);
808 return make_shared<PlusConstant1>(f, c);
Base class for exceptions thrown by Cantera classes.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
string write(const string &arg) const override
Write LaTeX string describing function.
string write(const string &arg) const override
Write LaTeX string describing function.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
string write(const string &arg) const override
Write LaTeX string describing function.
string write(const string &arg) const override
Write LaTeX string describing function.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
string write(const string &arg) const override
Write LaTeX string describing function.
Base class for 'functor' classes that evaluate a function of one variable.
string typeName() const
Returns a string with the class name of the functor.
virtual shared_ptr< Func1 > derivative() const
Creates a derivative to the current function.
virtual string type() const
Returns a string describing the type of the function.
virtual double eval(double t) const
Evaluate the function.
shared_ptr< Func1 > func1_shared() const
Accessor function for m_f1.
virtual double isProportional(TimesConstant1 &other)
virtual string write(const string &arg) const
Write LaTeX string describing function.
double operator()(double t) const
Calls method eval to evaluate the function.
virtual bool isIdentical(shared_ptr< Func1 > other) const
Routine to determine if two functions are the same.
virtual int order() const
Return the order of the function, if it makes sense.
double c() const
Accessor function for the stored constant m_c.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
string write(const string &arg) const override
Write LaTeX string describing function.
An error indicating that an unimplemented function has been called.
string write(const string &arg) const override
Write LaTeX string describing function.
string write(const string &arg) const override
Write LaTeX string describing function.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
string write(const string &arg) const override
Write LaTeX string describing function.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
int order() const override
Return the order of the function, if it makes sense.
string write(const string &arg) const override
Write LaTeX string describing function.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
string write(const string &arg) const override
Write LaTeX string describing function.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
string write(const string &arg) const override
Write LaTeX string describing function.
string write(const string &arg) const override
Write LaTeX string describing function.
double eval(double t) const override
Evaluate the function.
shared_ptr< Func1 > derivative() const override
Creates a derivative to the current function.
string write(const string &arg) const override
Write LaTeX string describing function.
void setMethod(const string &method)
Set the interpolation method.
vector< double > m_tvec
Vector of time values.
bool m_isLinear
Boolean indicating interpolation method.
vector< double > m_fvec
Vector of function values.
Tabulated1(size_t n, const double *tvals, const double *fvals, const string &method="linear")
Constructor.
Implements the product of a function and a constant.
int order() const override
Return the order of the function, if it makes sense.
string write(const string &arg) const override
Write LaTeX string describing function.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
shared_ptr< Func1 > newCompositeFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Composite of two functions.
shared_ptr< Func1 > newProdFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Product of two functions.
shared_ptr< Func1 > newDiffFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Difference of two functions.
shared_ptr< Func1 > newTimesConstFunction(shared_ptr< Func1 > f, double c)
Product of function and constant.
shared_ptr< Func1 > newSumFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Sum of two functions.
shared_ptr< Func1 > newRatioFunction(shared_ptr< Func1 > f1, shared_ptr< Func1 > f2)
Ratio of two functions.
shared_ptr< Func1 > newPlusConstFunction(shared_ptr< Func1 > f, double c)
Sum of function and constant.
string demangle(const std::type_info &type)
Convert a type name to a human readable string, using boost::core::demangle if available.
Namespace for the Cantera kernel.
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Contains declarations for string manipulation functions within Cantera.