diff --git a/bin/genEvalSpecializations.py b/bin/genEvalSpecializations.py index b4042f14e..2e63592d9 100755 --- a/bin/genEvalSpecializations.py +++ b/bin/genEvalSpecializations.py @@ -330,6 +330,13 @@ public: // create a function evaluation for a "naked" depending variable (i.e., f(x) = x) {% if numDerivs < 0 %}\ + template + static Evaluation createVariable(const RhsValueType& value OPM_UNUSED, int varPos OPM_UNUSED) + { + throw std::logic_error("Dynamically sized evaluations require that the number of " + "derivatives is specified when creating an evaluation"); + } + template static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) { @@ -337,6 +344,14 @@ public: // which is represented by the value (which is set to 1.0) return Evaluation(nVars, value, varPos); } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(x.size(), value, varPos); + } {% else %}\ template static Evaluation createVariable(const RhsValueType& value, int varPos) @@ -345,6 +360,26 @@ public: // which is represented by the value (which is set to 1.0) return Evaluation(value, varPos); } + + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != {{numDerivs}}) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with {{numDerivs}} derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } {% endif %}\ @@ -356,11 +391,46 @@ public: { return Evaluation(nVars, value); } -{% else %}\ + // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). template static Evaluation createConstant(const RhsValueType& value) + { + throw std::logic_error("Dynamically-sized evaluation objects require to specify the number of derivatives."); + } + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x, const RhsValueType& value) + { + return Evaluation(x.size(), value); + } +{% else %}\ + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != {{numDerivs}}) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with {{numDerivs}} derivatives"); + return Evaluation(value); + } + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const RhsValueType& value) + { + return Evaluation(value); + } + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) { return Evaluation(value); } diff --git a/opm/material/common/MathToolbox.hpp b/opm/material/common/MathToolbox.hpp index bfc2cc2e3..07fa41cf5 100644 --- a/opm/material/common/MathToolbox.hpp +++ b/opm/material/common/MathToolbox.hpp @@ -37,6 +37,7 @@ #include #include #include +#include namespace Opm { /* @@ -112,6 +113,32 @@ public: static Scalar createConstant(Scalar value) { return value; } + /*! + * \brief Given a scalar value, return an evaluation of a constant function that + * features a given number of derivatives + * + * For this toolbox, an evaluation is the value, so this method is the identity + * function. In general, this returns an evaluation object for which all derivatives + * are zero. + */ + static Scalar createConstant(unsigned numDerivatives, Scalar value) + { + if (numDerivatives != 0) + throw std::logic_error("Plain floating point objects cannot represent any derivatives"); + return value; + } + + /*! + * \brief Given a scalar value, return an evaluation of a constant function that is + * compatible to a "template" variable. + * + * For this toolbox, an evaluation is the value, so this method is the identity + * function. In general, this returns an evaluation object for which all derivatives + * are zero. + */ + static Scalar createConstant(Scalar x OPM_UNUSED, Scalar value) + { return value; } + /*! * \brief Given a scalar value, return an evaluation of a linear function. * @@ -119,8 +146,19 @@ public: * regard to x. For scalars (which do not consider derivatives), this method does * nothing. */ - static Scalar createVariable(Scalar value, unsigned /*varIdx*/) - { return value; } + static Scalar createVariable(Scalar value OPM_UNUSED, unsigned varIdx OPM_UNUSED) + { throw std::logic_error("Plain floating point objects cannot represent variables"); } + + /*! + * \brief Given a scalar value, return an evaluation of a linear function that is + * compatible with a "template" evaluation. + * + * i.e., Create an evaluation which represents f(x) = x and the derivatives with + * regard to x. For scalars (which do not consider derivatives), this method does + * nothing. + */ + static Scalar createVariable(Scalar x OPM_UNUSED, Scalar value OPM_UNUSED, unsigned varIdx OPM_UNUSED) + { throw std::logic_error("Plain floating point objects cannot represent variables"); } /*! * \brief Given a function evaluation, constrain it to its value (if necessary). @@ -249,6 +287,22 @@ template Evaluation constant(const Scalar& value) { return Opm::MathToolbox::createConstant(value); } +template +Evaluation constant(unsigned numDeriv, const Scalar& value) +{ return Opm::MathToolbox::createConstant(numDeriv, value); } + +template +Evaluation constant(const Evaluation& x, const Scalar& value) +{ return Opm::MathToolbox::createConstant(x, value); } + +template +Evaluation variable(unsigned numDeriv, const Scalar& value, unsigned idx) +{ return Opm::MathToolbox::createVariable(numDeriv, value, idx); } + +template +Evaluation variable(const Evaluation& x, const Scalar& value, unsigned idx) +{ return Opm::MathToolbox::createVariable(x, value, idx); } + template Evaluation variable(const Scalar& value, unsigned idx) { return Opm::MathToolbox::createVariable(value, idx); } diff --git a/opm/material/densead/DynamicEvaluation.hpp b/opm/material/densead/DynamicEvaluation.hpp index 41e7a879f..fbc5ca3e2 100644 --- a/opm/material/densead/DynamicEvaluation.hpp +++ b/opm/material/densead/DynamicEvaluation.hpp @@ -177,6 +177,13 @@ public: { return Evaluation(x.size(), 1.); } // create a function evaluation for a "naked" depending variable (i.e., f(x) = x) + template + static Evaluation createVariable(const RhsValueType& value OPM_UNUSED, int varPos OPM_UNUSED) + { + throw std::logic_error("Dynamically sized evaluations require that the number of " + "derivatives is specified when creating an evaluation"); + } + template static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) { @@ -185,6 +192,14 @@ public: return Evaluation(nVars, value, varPos); } + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(x.size(), value, varPos); + } + // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -194,6 +209,22 @@ public: return Evaluation(nVars, value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const RhsValueType& value) + { + throw std::logic_error("Dynamically-sized evaluation objects require to specify the number of derivatives."); + } + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x, const RhsValueType& value) + { + return Evaluation(x.size(), value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation.hpp b/opm/material/densead/Evaluation.hpp index cec58018d..ce20a553f 100644 --- a/opm/material/densead/Evaluation.hpp +++ b/opm/material/densead/Evaluation.hpp @@ -170,6 +170,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 0) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 0 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 0) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 0 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -179,6 +210,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation1.hpp b/opm/material/densead/Evaluation1.hpp index ee5f911de..67f0c2d5e 100644 --- a/opm/material/densead/Evaluation1.hpp +++ b/opm/material/densead/Evaluation1.hpp @@ -161,6 +161,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 1) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 1 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 1) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 1 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -170,6 +201,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation10.hpp b/opm/material/densead/Evaluation10.hpp index 40c075d8e..4b479c30f 100644 --- a/opm/material/densead/Evaluation10.hpp +++ b/opm/material/densead/Evaluation10.hpp @@ -170,6 +170,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 10) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 10 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 10) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 10 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -179,6 +210,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation11.hpp b/opm/material/densead/Evaluation11.hpp index 13f234941..f3d2e820f 100644 --- a/opm/material/densead/Evaluation11.hpp +++ b/opm/material/densead/Evaluation11.hpp @@ -171,6 +171,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 11) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 11 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 11) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 11 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -180,6 +211,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation12.hpp b/opm/material/densead/Evaluation12.hpp index f12a489e8..3be86d5e2 100644 --- a/opm/material/densead/Evaluation12.hpp +++ b/opm/material/densead/Evaluation12.hpp @@ -172,6 +172,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 12) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 12 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 12) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 12 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -181,6 +212,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation2.hpp b/opm/material/densead/Evaluation2.hpp index 16e5fba81..c8f45c2dd 100644 --- a/opm/material/densead/Evaluation2.hpp +++ b/opm/material/densead/Evaluation2.hpp @@ -162,6 +162,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 2) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 2 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 2) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 2 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -171,6 +202,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation3.hpp b/opm/material/densead/Evaluation3.hpp index 241cebc2d..d1fecbb44 100644 --- a/opm/material/densead/Evaluation3.hpp +++ b/opm/material/densead/Evaluation3.hpp @@ -163,6 +163,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 3) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 3 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 3) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 3 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -172,6 +203,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation4.hpp b/opm/material/densead/Evaluation4.hpp index 14aa47994..61b81ca7f 100644 --- a/opm/material/densead/Evaluation4.hpp +++ b/opm/material/densead/Evaluation4.hpp @@ -164,6 +164,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 4) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 4 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 4) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 4 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -173,6 +204,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation5.hpp b/opm/material/densead/Evaluation5.hpp index 2ca40f674..a2dd0d66d 100644 --- a/opm/material/densead/Evaluation5.hpp +++ b/opm/material/densead/Evaluation5.hpp @@ -165,6 +165,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 5) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 5 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 5) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 5 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -174,6 +205,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation6.hpp b/opm/material/densead/Evaluation6.hpp index f855a5835..5f2df05bb 100644 --- a/opm/material/densead/Evaluation6.hpp +++ b/opm/material/densead/Evaluation6.hpp @@ -166,6 +166,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 6) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 6 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 6) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 6 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -175,6 +206,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation7.hpp b/opm/material/densead/Evaluation7.hpp index 84f5facbb..7fb83e2c8 100644 --- a/opm/material/densead/Evaluation7.hpp +++ b/opm/material/densead/Evaluation7.hpp @@ -167,6 +167,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 7) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 7 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 7) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 7 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -176,6 +207,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation8.hpp b/opm/material/densead/Evaluation8.hpp index 809c85148..9b2657afe 100644 --- a/opm/material/densead/Evaluation8.hpp +++ b/opm/material/densead/Evaluation8.hpp @@ -168,6 +168,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 8) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 8 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 8) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 8 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -177,6 +208,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Evaluation9.hpp b/opm/material/densead/Evaluation9.hpp index 9b79a1c72..ff38db66b 100644 --- a/opm/material/densead/Evaluation9.hpp +++ b/opm/material/densead/Evaluation9.hpp @@ -169,6 +169,37 @@ public: return Evaluation(value, varPos); } + template + static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) + { + if (nVars != 9) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 9 derivatives"); + + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(nVars, value, varPos); + } + + template + static Evaluation createVariable(const Evaluation& x, const RhsValueType& value, int varPos) + { + // copy function value and set all derivatives to 0, except for the variable + // which is represented by the value (which is set to 1.0) + return Evaluation(value, varPos); + } + + + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(int nVars, const RhsValueType& value) + { + if (nVars != 9) + throw std::logic_error("This statically-sized evaluation can only represent objects" + " with 9 derivatives"); + return Evaluation(value); + } // "evaluate" a constant function (i.e. a function that does not depend on the set of // relevant variables, f(x) = c). @@ -178,6 +209,14 @@ public: return Evaluation(value); } + // "evaluate" a constant function (i.e. a function that does not depend on the set of + // relevant variables, f(x) = c). + template + static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value) + { + return Evaluation(value); + } + // print the value and the derivatives of the function evaluation void print(std::ostream& os = std::cout) const { diff --git a/opm/material/densead/Math.hpp b/opm/material/densead/Math.hpp index febffca36..fa0bd30e8 100644 --- a/opm/material/densead/Math.hpp +++ b/opm/material/densead/Math.hpp @@ -449,6 +449,12 @@ public: static Evaluation createConstant(ValueType value) { return Evaluation::createConstant(value); } + static Evaluation createConstant(unsigned numDeriv, const ValueType value) + { return Evaluation::createConstant(numDeriv, value); } + + static Evaluation createConstant(const Evaluation& x, const ValueType value) + { return Evaluation::createConstant(x, value); } + static Evaluation createVariable(ValueType value, int varIdx) { return Evaluation::createVariable(value, varIdx); }