Skip to content

Commit

Permalink
[Func1] Refactor derivative rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jun 29, 2023
1 parent e630d29 commit e174882
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions include/cantera/numerics/Func1.h
Expand Up @@ -478,6 +478,11 @@ class Sum1 : public Func1
Func1& d2 = m_f2->derivative();
return newSumFunction(d1, d2);
}

virtual shared_ptr<Func1> derivative3() const {
return newSumFunction(m_f1_shared->derivative3(), m_f2_shared->derivative3());
}

virtual int order() const {
return 0;
}
Expand Down Expand Up @@ -544,6 +549,11 @@ class Diff1 : public Func1
virtual Func1& derivative() const {
return newDiffFunction(m_f1->derivative(), m_f2->derivative());
}

virtual shared_ptr<Func1> derivative3() const {
return newDiffFunction(m_f1_shared->derivative3(), m_f2_shared->derivative3());
}

virtual int order() const {
return 0;
}
Expand Down Expand Up @@ -615,6 +625,13 @@ class Product1 : public Func1
Func1& a2 = newProdFunction(m_f2->duplicate(), m_f1->derivative());
return newSumFunction(a1, a2);
}

virtual shared_ptr<Func1> 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;
}
Expand Down Expand Up @@ -691,6 +708,10 @@ class TimesConstant1 : public Func1
return *d;
}

virtual shared_ptr<Func1> derivative3() const {
return newTimesConstFunction(m_f1_shared->derivative3(), m_c);
}

virtual std::string write(const std::string& arg) const;

virtual int order() const {
Expand Down Expand Up @@ -750,6 +771,11 @@ class PlusConstant1 : public Func1
virtual Func1& derivative() const {
return m_f1->derivative();
}

virtual shared_ptr<Func1> derivative3() const {
return m_f1_shared->derivative3();
}

virtual std::string write(const std::string& arg) const;

virtual int order() const {
Expand Down Expand Up @@ -822,6 +848,14 @@ class Ratio1 : public Func1
return newRatioFunction(s, p);
}

virtual shared_ptr<Func1> 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 {
Expand Down Expand Up @@ -894,6 +928,13 @@ class Composite1 : public Func1
return *p;
}

virtual shared_ptr<Func1> 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 {
Expand Down

0 comments on commit e174882

Please sign in to comment.