From e1748828adb21bedcd35fc1c0311260eec0f0499 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Fri, 23 Jun 2023 15:31:26 -0600 Subject: [PATCH] [Func1] Refactor derivative rules --- include/cantera/numerics/Func1.h | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/cantera/numerics/Func1.h b/include/cantera/numerics/Func1.h index 1916992666..7047d6b550 100644 --- a/include/cantera/numerics/Func1.h +++ b/include/cantera/numerics/Func1.h @@ -478,6 +478,11 @@ class Sum1 : public Func1 Func1& d2 = m_f2->derivative(); return newSumFunction(d1, d2); } + + virtual shared_ptr derivative3() const { + return newSumFunction(m_f1_shared->derivative3(), m_f2_shared->derivative3()); + } + virtual int order() const { return 0; } @@ -544,6 +549,11 @@ class Diff1 : public Func1 virtual Func1& derivative() const { return newDiffFunction(m_f1->derivative(), m_f2->derivative()); } + + virtual shared_ptr derivative3() const { + return newDiffFunction(m_f1_shared->derivative3(), m_f2_shared->derivative3()); + } + virtual int order() const { return 0; } @@ -615,6 +625,13 @@ class Product1 : public Func1 Func1& a2 = newProdFunction(m_f2->duplicate(), m_f1->derivative()); return newSumFunction(a1, a2); } + + virtual shared_ptr derivative3() const { + auto a1 = newProdFunction(m_f1_shared, m_f2_shared->derivative3()); + auto a2 = newProdFunction(m_f2_shared, m_f1_shared->derivative3()); + return newSumFunction(a1, a2); + } + virtual int order() const { return 1; } @@ -691,6 +708,10 @@ class TimesConstant1 : public Func1 return *d; } + virtual shared_ptr derivative3() const { + return newTimesConstFunction(m_f1_shared->derivative3(), m_c); + } + virtual std::string write(const std::string& arg) const; virtual int order() const { @@ -750,6 +771,11 @@ class PlusConstant1 : public Func1 virtual Func1& derivative() const { return m_f1->derivative(); } + + virtual shared_ptr derivative3() const { + return m_f1_shared->derivative3(); + } + virtual std::string write(const std::string& arg) const; virtual int order() const { @@ -822,6 +848,14 @@ class Ratio1 : public Func1 return newRatioFunction(s, p); } + virtual shared_ptr derivative3() const { + auto a1 = newProdFunction(m_f1_shared->derivative3(), m_f2_shared); + auto a2 = newProdFunction(m_f1_shared, m_f2_shared->derivative3()); + auto s = newDiffFunction(a1, a2); + auto p = newProdFunction(m_f2_shared, m_f2_shared); + return newRatioFunction(s, p); + } + virtual std::string write(const std::string& arg) const; virtual int order() const { @@ -894,6 +928,13 @@ class Composite1 : public Func1 return *p; } + virtual shared_ptr derivative3() const { + auto d1 = m_f1_shared->derivative3(); + auto d2 = m_f2_shared->derivative3(); + auto d3 = newCompositeFunction(d1, m_f2_shared); + return newProdFunction(d3, d2); + } + virtual std::string write(const std::string& arg) const; virtual int order() const {