From 8ef6f7bfc2f399bf4e93e7246d42c5792da6a161 Mon Sep 17 00:00:00 2001 From: Andreas Lauser Date: Wed, 2 Sep 2015 13:11:29 +0200 Subject: [PATCH] make the Evaluation template class work better as field type for Dune::FieldMatrix/Dune::FieldVector IMO this doges the edges of the c++ specifcation quite a bit too hard, but at least with Dune >= 2.4 it should now work unconditionally (and for older dune versions, the #error has been demoted to a #warning) --- opm/material/localad/Evaluation.hpp | 43 +++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/opm/material/localad/Evaluation.hpp b/opm/material/localad/Evaluation.hpp index f86651207..73cc143f0 100644 --- a/opm/material/localad/Evaluation.hpp +++ b/opm/material/localad/Evaluation.hpp @@ -32,6 +32,8 @@ #include #include +#include + namespace Opm { namespace LocalAd { /*! @@ -419,9 +421,9 @@ std::ostream& operator<<(std::ostream& os, const Evaluation +const Opm::LocalAd::Evaluation abs(const Opm::LocalAd::Evaluation& x) +{ return Opm::LocalAd::abs(x); } + +} // namespace std + +#if defined DUNE_DENSEMATRIX_HH +#warning \ + "Due to some C++ peculiarity regarding function overloads, the 'Evaluation.hpp'" \ + "header file must be included before Dune's 'densematrix.hh' for Dune < 2.4. " \ + "(If Evaluations are to be used in conjunction with a dense matrix.)" #endif +#endif + +// this makes the Dune matrix/vector classes happy... #include namespace Dune { @@ -454,16 +472,11 @@ struct FieldTraits > { public: typedef Opm::LocalAd::Evaluation field_type; - typedef Scalar real_type; + // setting real_type to field_type here potentially leads to slightly worse + // performance, but at least it makes things compile. + typedef field_type real_type; }; -namespace fvmeta { -template -inline Scalar absreal(const Opm::LocalAd::Evaluation& k) -{ - return std::abs(k.value); -} - -}} // namespace fvmeta, Dune +} // namespace Dune #endif