Commit 6422d8a8 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[tpfa][scv, scvf] return position vectors by const ref

parent 26d58e67
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#define DUMUX_DISCRETIZATION_CC_SUBCONTROLVOLUME_HH #define DUMUX_DISCRETIZATION_CC_SUBCONTROLVOLUME_HH
#include <dumux/discretization/subcontrolvolumebase.hh> #include <dumux/discretization/subcontrolvolumebase.hh>
#include <dumux/common/optional.hh> #include <dune/common/std/optional.hh>
namespace Dumux namespace Dumux
{ {
...@@ -48,7 +48,11 @@ public: ...@@ -48,7 +48,11 @@ public:
// the contructor in the cc case // the contructor in the cc case
CCSubControlVolume(Geometry&& geometry, CCSubControlVolume(Geometry&& geometry,
GridIndexType elementIndex) GridIndexType elementIndex)
: ParentType(), geometry_(std::forward<Geometry>(geometry)), elementIndex_(elementIndex) {} : ParentType()
, geometry_(std::move(geometry))
, center_(geometry_.value().center())
, elementIndex_(elementIndex)
{}
//! The copy constrcutor //! The copy constrcutor
CCSubControlVolume(const CCSubControlVolume& other) = default; CCSubControlVolume(const CCSubControlVolume& other) = default;
...@@ -62,28 +66,30 @@ public: ...@@ -62,28 +66,30 @@ public:
// We want to use the default copy/move assignment. // We want to use the default copy/move assignment.
// But since geometry is not copy assignable :( we // But since geometry is not copy assignable :( we
// have to construct it again // have to construct it again
geometry_.release(); geometry_.reset();
geometry_.emplace(other.geometry_.value()); geometry_.emplace(other.geometry_.value());
center_ = other.center_;
elementIndex_ = other.elementIndex_; elementIndex_ = other.elementIndex_;
return *this; return *this;
} }
//! The move assignment operator //! The move assignment operator
CCSubControlVolume& operator=(CCSubControlVolume&& other) CCSubControlVolume& operator=(CCSubControlVolume&& other) noexcept
{ {
// We want to use the default copy/move assignment. // We want to use the default copy/move assignment.
// But since geometry is not copy assignable :( we // But since geometry is not copy assignable :( we
// have to construct it again // have to construct it again
geometry_.release(); geometry_.reset();
geometry_.emplace(other.geometry_.value()); geometry_.emplace(std::move(other.geometry_.value()));
center_ = std::move(other.center_);
elementIndex_ = std::move(other.elementIndex_); elementIndex_ = std::move(other.elementIndex_);
return *this; return *this;
} }
//! The center of the sub control volume //! The center of the sub control volume
GlobalPosition center() const const GlobalPosition& center() const
{ {
return geometry().center(); return center_;
} }
//! The volume of the sub control volume //! The volume of the sub control volume
...@@ -113,9 +119,9 @@ public: ...@@ -113,9 +119,9 @@ public:
} }
// The position of the dof this scv is embedded in // The position of the dof this scv is embedded in
GlobalPosition dofPosition() const const GlobalPosition& dofPosition() const
{ {
return geometry().center(); return center_;
} }
//! The global index of the element this scv is embedded in //! The global index of the element this scv is embedded in
...@@ -133,7 +139,8 @@ public: ...@@ -133,7 +139,8 @@ public:
private: private:
// Work around the fact that geometry is not default constructible // Work around the fact that geometry is not default constructible
Optional<Geometry> geometry_; Dune::Std::optional<Geometry> geometry_;
GlobalPosition center_;
GridIndexType elementIndex_; GridIndexType elementIndex_;
}; };
......
...@@ -81,13 +81,13 @@ public: ...@@ -81,13 +81,13 @@ public:
} }
//! The center of the sub control volume face //! The center of the sub control volume face
GlobalPosition center() const const GlobalPosition& center() const
{ {
return center_; return center_;
} }
//! The integration point for flux evaluations in global coordinates //! The integration point for flux evaluations in global coordinates
GlobalPosition ipGlobal() const const GlobalPosition& ipGlobal() const
{ {
// Return center for now // Return center for now
return center_; return center_;
...@@ -106,7 +106,7 @@ public: ...@@ -106,7 +106,7 @@ public:
} }
//! The unit outer normal of the sub control volume face //! The unit outer normal of the sub control volume face
GlobalPosition unitOuterNormal() const const GlobalPosition& unitOuterNormal() const
{ {
return unitOuterNormal_; return unitOuterNormal_;
} }
...@@ -136,10 +136,11 @@ public: ...@@ -136,10 +136,11 @@ public:
return scvfIndex_; return scvfIndex_;
} }
GlobalPosition corner(unsigned int localIdx) const //! return the i-th corner of this sub control volume face
const GlobalPosition& corner(int i) const
{ {
assert(localIdx < corners_.size() && "provided index exceeds the number of corners"); assert(i < corners_.size() && "provided index exceeds the number of corners");
return corners_[localIdx]; return corners_[i];
} }
//! The geometry of the sub control volume face //! The geometry of the sub control volume face
......
Supports Markdown
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