Commit 6fe3808b authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

using std::optional

parent ea95a2d0
......@@ -3,7 +3,8 @@
#ifndef DUNE_CURVED_SURFACE_GRID_ENTITY_HH
#define DUNE_CURVED_SURFACE_GRID_ENTITY_HH
#include <dune/common/std/optional.hh>
#include <optional>
#include <dune/geometry/referenceelements.hh>
#include <dune/grid/common/grid.hh>
......@@ -228,13 +229,13 @@ namespace Dune
Geometry geometry () const
{
if (!geo_) {
auto localFct = localFunction(Super::gridFunction());
if (hostElement_) {
auto localFct = localFunction(Super::gridFunction());
localFct.bind(*hostElement_);
auto refElem = referenceElement<ctype, Super::dimension>(hostElement_->type());
auto localGeometry = refElem.template geometry<codim>(subEntity_);
geo_ = std::make_shared<GeometryImpl>(Super::type(), localFct, localGeometry);
geo_ = std::make_shared<GeometryImpl>(Super::type(), std::move(localFct), localGeometry);
}
else {
DUNE_THROW(Dune::NotImplemented, "Geometry of entities of codim!=0 not implemented");
......@@ -245,7 +246,7 @@ namespace Dune
}
private:
Std::optional<HostElement> hostElement_;
std::optional<HostElement> hostElement_;
int subEntity_ = -1;
using GeometryImpl = typename Traits::template Codim<codim>::GeometryImpl;
......@@ -287,7 +288,7 @@ namespace Dune
auto localFct = localFunction(Super::gridFunction());
localFct.bind(Super::hostEntity());
auto fakeDefaultGeometry = Dune::DefaultLocalGeometry<typename Super::ctype, Super::mydimension, Super::mydimension>{};
geo_ = std::make_shared<GeometryImpl>(Super::type(), localFct, fakeDefaultGeometry);
geo_ = std::make_shared<GeometryImpl>(Super::type(), std::move(localFct), fakeDefaultGeometry);
}
return Geometry(*geo_);
......
......@@ -7,13 +7,13 @@
#include <functional>
#include <iterator>
#include <limits>
#include <optional>
#include <vector>
#include <dune/common/diagonalmatrix.hh>
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/std/optional.hh>
#include <dune/common/std/type_traits.hh>
#include <dune/curvedgeometry/curvedgeometry.hh>
......@@ -113,9 +113,9 @@ namespace Dune
* \param[in] args... argument to construct the local geometry
*
*/
template <class... Args>
Geometry (const ReferenceElement& refElement, const LocalFunction& localFunction, Args&&... args)
: Super(refElement, localFunction, LocalGeometry{std::forward<Args>(args)...})
template <class LF_, class... Args>
Geometry (const ReferenceElement& refElement, LF_&& localFunction, Args&&... args)
: Super(refElement, std::forward<LF_>(localFunction), LocalGeometry{std::forward<Args>(args)...})
{}
/// \brief constructor, forwarding to the other constructor that take a reference-element
......@@ -125,9 +125,9 @@ namespace Dune
* (stored by value)
* \param[in] args... argument to construct the local geometry
*/
template <class... Args>
Geometry (Dune::GeometryType gt, const LocalFunction& localFunction, Args&&... args)
: Super(gt, localFunction, LocalGeometry{std::forward<Args>(args)...})
template <class LF_, class... Args>
Geometry (Dune::GeometryType gt, LF_&& localFunction, Args&&... args)
: Super(gt, std::forward<LF_>(localFunction), LocalGeometry{std::forward<Args>(args)...})
{}
};
......@@ -178,7 +178,7 @@ namespace Dune
LocalGeometry(std::forward<Args>(args)...))
{}
Std::optional<LocalCoordinate> checkedLocal (const GlobalCoordinate& globalCoord) const
std::optional<LocalCoordinate> checkedLocal (const GlobalCoordinate& globalCoord) const
{
auto localCoord = Super::local(globalCoord);
if ((globalCoord - Super::global(localCoord)).two_norm2() > tolerance())
......
......@@ -4,6 +4,7 @@
#define DUNE_CURVED_SURFACE_GRID_DISCRETE_GRIDVIEWFUNCTION_HH
#include <array>
#include <optional>
#include <vector>
#if !HAVE_DUNE_FUNCTIONS
......@@ -223,7 +224,7 @@ namespace Dune
const VectorType& coords_;
std::vector<RangeType> localCoords_;
Std::optional<Geometry> geometry_;
std::optional<Geometry> geometry_;
mutable std::vector<typename LocalBasis::Traits::RangeType> shapeValues_;
mutable std::vector<typename LocalBasis::Traits::JacobianType> shapeGradients_;
mutable std::vector<DerivativeRange<0>> gradients_;
......
......@@ -3,11 +3,11 @@
#ifndef DUNE_CURVED_SURFACE_GRID_INTERSECTION_HH
#define DUNE_CURVED_SURFACE_GRID_INTERSECTION_HH
#include <optional>
#include <type_traits>
#include <utility>
#include <dune/common/fvector.hh>
#include <dune/common/std/optional.hh>
#include <dune/geometry/referenceelements.hh>
namespace Dune
......@@ -178,8 +178,8 @@ namespace Dune
const GridFunction* gridFunction_ = nullptr;
// geometry caches
mutable Std::optional<ElementGeometry> insideGeo_;
mutable Std::optional<GeometryImpl> geo_;
mutable std::optional<ElementGeometry> insideGeo_;
mutable std::optional<GeometryImpl> geo_;
};
} // namespace Curved
......
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