diff --git a/opm/material/common/MathToolbox.hpp b/opm/material/common/MathToolbox.hpp index a469e95b4..bfc2cc2e3 100644 --- a/opm/material/common/MathToolbox.hpp +++ b/opm/material/common/MathToolbox.hpp @@ -205,6 +205,10 @@ public: static Scalar exp(Scalar arg) { return std::exp(arg); } + //! The 10 logarithm of a value + static Scalar log10(Scalar arg) + { return std::log10(arg); } + //! The natural logarithm of a value static Scalar log(Scalar arg) { return std::log(arg); } @@ -319,6 +323,10 @@ template Evaluation log(const Evaluation& value) { return Opm::MathToolbox::log(value); } +template +Evaluation log10(const Evaluation& value) +{ return Opm::MathToolbox::log10(value); } + template typename ReturnEval_::type pow(const Evaluation1& base, const Evaluation2& exp) diff --git a/opm/material/densead/Math.hpp b/opm/material/densead/Math.hpp index 871d067a1..78d8e9d66 100644 --- a/opm/material/densead/Math.hpp +++ b/opm/material/densead/Math.hpp @@ -399,6 +399,24 @@ Evaluation log(const Evaluation +Evaluation log10(const Evaluation& x) +{ + typedef MathToolbox ValueTypeToolbox; + + Evaluation result(x); + + result.setValue(ValueTypeToolbox::log10(x.value())); + + // derivatives use the chain rule + const ValueType& df_dx = 1/x.value() * ValueTypeToolbox::log10(ValueTypeToolbox::exp(1.0)); + for (int curVarIdx = 0; curVarIdx < result.size(); ++curVarIdx) + result.setDerivative(curVarIdx, df_dx*x.derivative(curVarIdx)); + + return result; +} + } // namespace DenseAd // a kind of traits class for the automatic differentiation case. (The toolbox for the @@ -513,6 +531,9 @@ public: static Evaluation log(const Evaluation& arg) { return Opm::DenseAd::log(arg); } + static Evaluation log10(const Evaluation& arg) + { return Opm::DenseAd::log10(arg); } + template static Evaluation pow(const Evaluation& arg1, const RhsValueType& arg2) { return Opm::DenseAd::pow(arg1, arg2); } diff --git a/tests/test_densead.cpp b/tests/test_densead.cpp index c11f07db0..bf26df19f 100644 --- a/tests/test_densead.cpp +++ b/tests/test_densead.cpp @@ -572,6 +572,11 @@ struct TestEnvBase static_cast(std::log), 1e-6, 1e9); + std::cout << " Testing log10()\n"; + test1DFunction(Opm::DenseAd::log10, + static_cast(std::log10), + 1e-6, 1e9); + while (false) { Scalar val1 OPM_UNUSED = 0.0; Scalar val2 OPM_UNUSED = 1.0; @@ -622,6 +627,8 @@ struct TestEnvBase resultEval = Opm::sqrt(eval1); resultEval = Opm::exp(eval1); resultEval = Opm::log(eval1); + resultEval = Opm::log10(eval1); + } }