Merge pull request #340 from andlaus/unify_eval_creation

unify the creation of evalutions
This commit is contained in:
Atgeirr Flø Rasmussen 2019-06-14 09:16:29 +02:00 committed by GitHub
commit 6cfd9b5740
17 changed files with 671 additions and 3 deletions

View File

@ -330,6 +330,13 @@ public:
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x) // create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
{% if numDerivs < 0 %}\ {% if numDerivs < 0 %}\
template <class RhsValueType>
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 <class RhsValueType> template <class RhsValueType>
static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) 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) // which is represented by the value (which is set to 1.0)
return Evaluation(nVars, value, varPos); return Evaluation(nVars, value, varPos);
} }
template <class RhsValueType>
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 %}\ {% else %}\
template <class RhsValueType> template <class RhsValueType>
static Evaluation createVariable(const RhsValueType& value, int varPos) 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) // which is represented by the value (which is set to 1.0)
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 %}\ {% endif %}\
@ -356,11 +391,46 @@ public:
{ {
return Evaluation(nVars, value); return Evaluation(nVars, value);
} }
{% else %}\
// "evaluate" a constant function (i.e. a function that does not depend on the set of // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
template <class RhsValueType> template <class RhsValueType>
static Evaluation createConstant(const RhsValueType& value) 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 <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{ {
return Evaluation(value); return Evaluation(value);
} }

View File

@ -37,6 +37,7 @@
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include <type_traits> #include <type_traits>
#include <stdexcept>
namespace Opm { namespace Opm {
/* /*
@ -112,6 +113,32 @@ public:
static Scalar createConstant(Scalar value) static Scalar createConstant(Scalar value)
{ return 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. * \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 * regard to x. For scalars (which do not consider derivatives), this method does
* nothing. * nothing.
*/ */
static Scalar createVariable(Scalar value, unsigned /*varIdx*/) static Scalar createVariable(Scalar value OPM_UNUSED, unsigned varIdx OPM_UNUSED)
{ return value; } { 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). * \brief Given a function evaluation, constrain it to its value (if necessary).
@ -249,6 +287,22 @@ template <class Evaluation, class Scalar>
Evaluation constant(const Scalar& value) Evaluation constant(const Scalar& value)
{ return Opm::MathToolbox<Evaluation>::createConstant(value); } { return Opm::MathToolbox<Evaluation>::createConstant(value); }
template <class Evaluation, class Scalar>
Evaluation constant(unsigned numDeriv, const Scalar& value)
{ return Opm::MathToolbox<Evaluation>::createConstant(numDeriv, value); }
template <class Evaluation, class Scalar>
Evaluation constant(const Evaluation& x, const Scalar& value)
{ return Opm::MathToolbox<Evaluation>::createConstant(x, value); }
template <class Evaluation, class Scalar>
Evaluation variable(unsigned numDeriv, const Scalar& value, unsigned idx)
{ return Opm::MathToolbox<Evaluation>::createVariable(numDeriv, value, idx); }
template <class Evaluation, class Scalar>
Evaluation variable(const Evaluation& x, const Scalar& value, unsigned idx)
{ return Opm::MathToolbox<Evaluation>::createVariable(x, value, idx); }
template <class Evaluation, class Scalar> template <class Evaluation, class Scalar>
Evaluation variable(const Scalar& value, unsigned idx) Evaluation variable(const Scalar& value, unsigned idx)
{ return Opm::MathToolbox<Evaluation>::createVariable(value, idx); } { return Opm::MathToolbox<Evaluation>::createVariable(value, idx); }

View File

@ -177,6 +177,13 @@ public:
{ return Evaluation(x.size(), 1.); } { return Evaluation(x.size(), 1.); }
// create a function evaluation for a "naked" depending variable (i.e., f(x) = x) // create a function evaluation for a "naked" depending variable (i.e., f(x) = x)
template <class RhsValueType>
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 <class RhsValueType> template <class RhsValueType>
static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos) static Evaluation createVariable(int nVars, const RhsValueType& value, int varPos)
{ {
@ -185,6 +192,14 @@ public:
return Evaluation(nVars, value, varPos); return Evaluation(nVars, value, varPos);
} }
template <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -194,6 +209,22 @@ public:
return Evaluation(nVars, value); 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 <class RhsValueType>
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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x, const RhsValueType& value)
{
return Evaluation(x.size(), value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -170,6 +170,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -179,6 +210,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -161,6 +161,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -170,6 +201,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -170,6 +170,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -179,6 +210,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -171,6 +171,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -180,6 +211,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -172,6 +172,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -181,6 +212,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -162,6 +162,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -171,6 +202,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -163,6 +163,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -172,6 +203,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -164,6 +164,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -173,6 +204,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -165,6 +165,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -174,6 +205,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -166,6 +166,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -175,6 +206,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -167,6 +167,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -176,6 +207,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -168,6 +168,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -177,6 +208,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -169,6 +169,37 @@ public:
return Evaluation(value, varPos); return Evaluation(value, varPos);
} }
template <class RhsValueType>
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 <class RhsValueType>
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 <class RhsValueType>
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 // "evaluate" a constant function (i.e. a function that does not depend on the set of
// relevant variables, f(x) = c). // relevant variables, f(x) = c).
@ -178,6 +209,14 @@ public:
return Evaluation(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 <class RhsValueType>
static Evaluation createConstant(const Evaluation& x OPM_UNUSED, const RhsValueType& value)
{
return Evaluation(value);
}
// print the value and the derivatives of the function evaluation // print the value and the derivatives of the function evaluation
void print(std::ostream& os = std::cout) const void print(std::ostream& os = std::cout) const
{ {

View File

@ -449,6 +449,12 @@ public:
static Evaluation createConstant(ValueType value) static Evaluation createConstant(ValueType value)
{ return Evaluation::createConstant(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) static Evaluation createVariable(ValueType value, int varIdx)
{ return Evaluation::createVariable(value, varIdx); } { return Evaluation::createVariable(value, varIdx); }