Commit 9686a7fc authored by Bernd Flemisch's avatar Bernd Flemisch
Browse files

[cc][scv] make SubControlVolume constructor more flexible

See the comment added in `subcontrolvolume.hh`.
parent a5f8e795
......@@ -65,6 +65,20 @@ class CCSubControlVolume
using LocalIndexType = typename T::LocalIndexType;
using Scalar = typename T::Scalar;
// In the following, the correct parameter type for the geometry passed to
// the constructor below is determined. It depends upon whether the
// `geometry()` method of the `Element` returns a copy or a const reference.
// In the first case, the correct type is `Geometry&&`, while it is
// `Geometry` for the second case. Although returning by copy is prescribed
// by the Dune interface, the grid implementation CpGrid uses a const
// reference as of Opm 2018.04. Once this is fixed, the parameter type can
// be hardcoded to `Geometry&&`.
using Element = typename GV::template Codim<0>::Entity;
using GeometryRT = typename std::result_of<decltype(&Element::geometry)(Element)>::type;
using GeometryRTWithoutRef = typename std::remove_reference<GeometryRT>::type;
static constexpr bool grtIsReference = !std::is_same<GeometryRT, GeometryRTWithoutRef>::value;
static constexpr bool grtIsConst = std::is_const<GeometryRTWithoutRef>::value;
using GeometryParamType = std::conditional_t<grtIsReference && grtIsConst, Geometry, Geometry&&>;
public:
//! export the type used for global coordinates
using GlobalPosition = typename T::GlobalPosition;
......@@ -73,8 +87,8 @@ public:
CCSubControlVolume() = default;
// the contructor in the cc case
CCSubControlVolume(Geometry&& geometry,
// See the explanation above for deriving `GeometryParamType`.
CCSubControlVolume(GeometryParamType geometry,
GridIndexType elementIndex)
: ParentType()
, geometry_(std::move(geometry))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment