36 "Needs to be overloaded by Func1 specialization.");
41 if (
type() != other.
type() || m_c != other.m_c) {
76Sin1::Sin1(
const vector<double>& params)
78 if (params.size() != 1) {
80 "Constructor needs exactly one parameter (frequency).");
88 return fmt::format(
"\\sin({})", arg);
90 return fmt::format(
"\\sin({}{})", m_c, arg);
96 auto c = make_shared<Cos1>(m_c);
102Cos1::Cos1(
const vector<double>& params)
104 if (params.size() != 1) {
106 "Constructor needs exactly one parameter (frequency).");
113 auto s = make_shared<Sin1>(m_c);
120 return fmt::format(
"\\cos({})", arg);
122 return fmt::format(
"\\cos({}{})", m_c, arg);
128Exp1::Exp1(
const vector<double>& params)
130 if (params.size() != 1) {
132 "Constructor needs exactly one parameter (exponent factor).");
139 auto f = make_shared<Exp1>(m_c);
149 return fmt::format(
"\\exp({})", arg);
151 return fmt::format(
"\\exp({}{})", m_c, arg);
155Log1::Log1(
const vector<double>& params)
157 if (params.size() != 1) {
159 "Constructor needs exactly one parameter (factor).");
166 auto f = make_shared<Pow1>(-1.);
176 return fmt::format(
"\\log({})", arg);
178 return fmt::format(
"\\log({}{})", m_c, arg);
183Pow1::Pow1(
const vector<double>& params)
185 if (params.size() != 1) {
187 "Constructor needs exactly one parameter (exponent).");
195 return make_shared<Const1>(0.0);
198 return make_shared<Const1>(1.0);
200 auto f = make_shared<Pow1>(m_c - 1.);
206Const1::Const1(
const vector<double>& params)
208 if (params.size() != 1) {
210 "Constructor needs exactly one parameter (constant).");
215Poly1::Poly1(
const vector<double>& params)
217 if (params.size() == 0) {
219 "Constructor needs an array that is not empty.");
221 size_t n = params.size() - 1;
222 m_cpoly.resize(n + 1);
223 copy(params.data(), params.data() + m_cpoly.size(), m_cpoly.begin());
226Fourier1::Fourier1(
const vector<double>& params)
228 if (params.size() < 4) {
230 "Constructor needs an array with at least 4 entries.");
232 if (params.size() % 2 != 0) {
234 "Constructor needs an array with an even number of entries.");
236 size_t n = params.size() / 2 - 1;
237 m_omega = params[n + 1];
238 m_a0_2 = 0.5 * params[0];
241 copy(params.data() + 1, params.data() + n + 1, m_ccos.begin());
242 copy(params.data() + n + 2, params.data() + 2 * n + 2, m_csin.begin());
245Gaussian1::Gaussian1(
const vector<double>& params)
247 if (params.size() != 3) {
249 "Constructor needs exactly 3 parameters (amplitude, center, width).");
253 m_tau = params[2] / (2. * sqrt(log(2.)));
256Arrhenius1::Arrhenius1(
const vector<double>& params)
258 if (params.size() < 3) {
260 "Constructor needs an array with at least 3 entries.");
262 if (params.size() % 3 != 0) {
264 "Constructor needs an array with multiples of 3 entries.");
266 size_t n = params.size() / 3;
270 for (
size_t i = 0; i < n; i++) {
272 m_A[i] = params[loc];
273 m_b[i] = params[loc + 1];
274 m_E[i] = params[loc + 2];
279 const string& method)
282 std::copy(tvals, tvals + n,
m_tvec.begin());
283 for (
auto it = std::begin(
m_tvec) + 1; it != std::end(
m_tvec); it++) {
284 if (*(it - 1) > *it) {
286 "time values are not increasing monotonically.");
290 std::copy(fvals, fvals + n,
m_fvec.begin());
296 if (params.size() < 4) {
298 "Constructor needs an array with at least 4 entries.");
300 if (params.size() % 2 != 0) {
302 "Constructor needs an array with an even number of entries.");
304 size_t n = params.size() / 2;
306 copy(params.data(), params.data() + n,
m_tvec.begin());
307 for (
auto it = std::begin(
m_tvec) + 1; it != std::end(
m_tvec); it++) {
308 if (*(it - 1) > *it) {
310 "Time values are not monotonically increasing.");
314 copy(params.data() + n, params.data() + 2 * n,
m_fvec.begin());
319 if (method ==
"linear") {
321 }
else if (method ==
"previous") {
325 "Interpolation method '{}' is not implemented.", method);
330 size_t siz =
m_tvec.size();
334 }
else if (t >=
m_tvec[siz-1]) {
338 while (t >
m_tvec[ix+1]) {
355 size_t siz =
m_tvec.size();
359 for (
size_t i=1; i<siz; i++) {
362 tvec.push_back(
m_tvec[i-1]);
366 tvec.push_back(
m_tvec[siz-1]);
370 tvec.push_back(
m_tvec[0]);
371 tvec.push_back(
m_tvec[siz-1]);
375 return make_shared<Tabulated1>(tvec.size(), &tvec[0], &dvec[0],
"previous");
382 return fmt::format(
"\\mathrm{{{}}}({})",
type(), arg);
388 return "\\sqrt{" + arg +
"}";
391 return "\\frac{1}{\\sqrt{" + arg +
"}}";
394 return fmt::format(
"\\left({}\\right)^{{{}}}", arg, m_c);
402 return fmt::format(
"\\mathrm{{Tabulated}}({})", arg);
407 return fmt::format(
"{}", m_c);
412 return "\\frac{" + m_f1->
write(arg) +
"}{"
413 + m_f2->
write(arg) +
"}";
426 string s = m_f1->
write(arg);
428 s =
"\\left(" + s +
"\\right)";
430 string s2 = m_f2->
write(arg);
432 s2 =
"\\left(" + s2 +
"\\right)";
445 string s1 = m_f1->
write(arg);
446 string s2 = m_f2->
write(arg);
448 return s1 +
" - " + s2.substr(1,s2.size());
450 return s1 +
" + " + s2;
456 string s1 = m_f1->
write(arg);
457 string s2 = m_f2->
write(arg);
459 return s1 +
" + " + s2.substr(1,s2.size());
461 return s1 +
" - " + s2;
467 string g = m_f2->
write(arg);
468 return m_f1->
write(g);
472 auto d1 = m_f1_shared->derivative();
473 auto d2 = m_f2_shared->derivative();
480 string s = m_f1->
write(arg);
482 s =
"\\left(" + s +
"\\right)";
491 if (n >=
'0' && n <=
'9') {
492 s =
"\\left(" + s +
"\\right)";
494 return fmt::format(
"{}{}", m_c, s);
500 return m_f1->
write(arg);
502 return fmt::format(
"{} + {}", m_f1->
write(arg), m_c);
513double Func1::isProportional(Func1& other)
524bool isConstant(
const shared_ptr<Func1>& f)
526 return f->type() ==
"constant";
529bool isZero(
const shared_ptr<Func1>& f)
531 return f->type() ==
"constant" && f->c() == 0.0;
534bool isOne(
const shared_ptr<Func1>& f)
536 return f->type() ==
"constant" && f->c() == 1.0;
539bool isTimesConst(
const shared_ptr<Func1>& f)
541 return f->type() ==
"times-constant";
544bool isExp(
const shared_ptr<Func1>& f)
546 return f->type() ==
"exp";
549bool isPow(
const shared_ptr<Func1>& f)
551 return f->type() ==
"pow";
558 if (f1->isIdentical(*f2)) {
567 double c = f1->isProportional(*f2);
570 return make_shared<Const1>(0.);
574 return make_shared<Sum1>(f1, f2);
586 if (f1->isIdentical(*f2)) {
587 return make_shared<Const1>(0.);
589 double c = f1->isProportional(*f2);
592 return make_shared<Const1>(0.);
597 return make_shared<Diff1>(f1, f2);
608 if (isZero(f1) || isZero(f2)) {
609 return make_shared<Const1>(0.);
611 if (isConstant(f1) && isConstant(f2)) {
612 return make_shared<Const1>(f1->c() * f2->c());
614 if (isConstant(f1)) {
617 if (isConstant(f2)) {
620 if (isPow(f1) && isPow(f2)) {
621 return make_shared<Pow1>(f1->c() + f2->c());
623 if (isExp(f1) && isExp(f2)) {
624 return make_shared<Exp1>(f1->c() + f2->c());
627 bool tc1 = isTimesConst(f1);
628 bool tc2 = isTimesConst(f2);
635 ff1 = f1->func1_shared();
641 ff2 = f2->func1_shared();
645 if (c1 * c2 != 1.0) {
650 return make_shared<Product1>(f1, f2);
659 return make_shared<Const1>(0.);
661 if (f1->isIdentical(*f2)) {
662 return make_shared<Const1>(1.);
664 if (isPow(f1) && isPow(f2)) {
665 return make_shared<Pow1>(f1->c() - f2->c());
667 if (isExp(f1) && isExp(f2)) {
668 return make_shared<Exp1>(f1->c() - f2->c());
670 return make_shared<Ratio1>(f1, f2);
676 return make_shared<Const1>(0.0);
678 if (isConstant(f1)) {
681 if (isPow(f1) && f1->c() == 1.0) {
684 if (isPow(f1) && f1->c() == 0.0) {
685 return make_shared<Const1>(1.);
687 if (isPow(f1) && isPow(f2)) {
688 return make_shared<Pow1>(f1->c() * f2->c());
690 return make_shared<Composite1>(f1, f2);
696 return make_shared<Const1>(0.0);
701 if (f->type() ==
"times-constant") {
702 return make_shared<TimesConstant1>(f->func1_shared(), f->c() * c);
704 return make_shared<TimesConstant1>(f, c);
713 return make_shared<Const1>(f->c() + c);
715 if (f->type() ==
"plus-constant") {
716 return make_shared<PlusConstant1>(f->func1_shared(), f->c() + c);
718 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_shared.
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 int order() const
Return the order of the function, if it makes sense.
bool isIdentical(Func1 &other) const
Routine to determine if two functions are the same.
double c() const
Accessor function for the stored constant.
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.
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.
Contains declarations for string manipulation functions within Cantera.