Skip to content
Snippets Groups Projects
Commit 92ac5951 authored by Tobias Leibner's avatar Tobias Leibner
Browse files

[spaces.fv.defaultproduct] move make_identical_tuple to dune-stuff

parent 431b7aa2
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <tuple> #include <tuple>
#include <dune/stuff/common/tuple.hh>
#include <dune/gdt/playground/mapper/productdgpdelab.hh> #include <dune/gdt/playground/mapper/productdgpdelab.hh>
#include <dune/gdt/spaces/interface.hh> #include <dune/gdt/spaces/interface.hh>
...@@ -32,42 +34,6 @@ class PdelabBasedProduct ...@@ -32,42 +34,6 @@ class PdelabBasedProduct
namespace internal { namespace internal {
// from
// https://stackoverflow.com/questions/16853552/how-to-create-a-type-list-for-variadic-templates-that-contains-n-times-the-sam
// in the end, we would like to have something like indices< 1, 2, 3 > for N = 3
template <std::size_t...>
struct indices
{
};
// we want to call this with empty Indices, i.e. create_indices< N >::type == indices< 1, 2, 3 > for N = 3
template <std::size_t N, std::size_t... Indices>
struct create_indices : create_indices<N - 1, N - 1, Indices...>
{
};
// terminating template
template <std::size_t... Indices>
struct create_indices<0, Indices...>
{
typedef indices<Indices...> type;
};
// T_aliased< T, Index > is always the type T, no matter what Index is
template <typename T, std::size_t index>
using T_aliased = T;
// make_identical_tuple< T, N >::type is a std::tuple< T, ... , T > with a length of N
template <typename T, std::size_t N, typename I = typename create_indices<N>::type>
struct make_identical_tuple;
template <typename T, std::size_t N, std::size_t... Indices>
struct make_identical_tuple<T, N, indices<Indices...>>
{
using type = std::tuple<T_aliased<T, Indices>...>;
};
template <class GridViewImp, int polynomialOrder, class RangeFieldImp, size_t rangeDim, size_t rangeDimCols> template <class GridViewImp, int polynomialOrder, class RangeFieldImp, size_t rangeDim, size_t rangeDimCols>
class PdelabBasedProductTraits class PdelabBasedProductTraits
...@@ -91,7 +57,7 @@ public: ...@@ -91,7 +57,7 @@ public:
typedef typename Dune::GDT::Spaces::DG::PdelabBased<GridViewType, polOrder, RangeFieldType, 1, dimRangeCols> typedef typename Dune::GDT::Spaces::DG::PdelabBased<GridViewType, polOrder, RangeFieldType, 1, dimRangeCols>
FactorSpaceType; FactorSpaceType;
typedef typename make_identical_tuple<FactorSpaceType, dimRange>::type SpaceTupleType; typedef typename DSC::make_identical_tuple<FactorSpaceType, dimRange>::type SpaceTupleType;
}; };
......
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
#ifndef DUNE_GDT_SPACES_FV_DEFAULTPRODUCT_HH #ifndef DUNE_GDT_SPACES_FV_DEFAULTPRODUCT_HH
#define DUNE_GDT_SPACES_FV_DEFAULTPRODUCT_HH #define DUNE_GDT_SPACES_FV_DEFAULTPRODUCT_HH
#include <tuple> #include <dune/stuff/common/tuple.hh>
#include <dune/gdt/mapper/default/productfv.hh>
#include "default.hh" #include "default.hh"
#include "interface.hh" #include "interface.hh"
...@@ -31,42 +29,6 @@ class DefaultProduct ...@@ -31,42 +29,6 @@ class DefaultProduct
namespace internal { namespace internal {
// from
// https://stackoverflow.com/questions/16853552/how-to-create-a-type-list-for-variadic-templates-that-contains-n-times-the-sam
// in the end, we would like to have something like indices< 0, 1, 2 > for N = 3
template <std::size_t...>
struct indices
{
};
// we want to call this with empty Indices, i.e. create_indices< N >::type == indices< 0, 1, 2 > for N = 3
template <std::size_t N, std::size_t... Indices>
struct create_indices : create_indices<N - 1, N - 1, Indices...>
{
};
// terminating template
template <std::size_t... Indices>
struct create_indices<0, Indices...>
{
typedef indices<Indices...> type;
};
// T_aliased< T, Index > is always the type T, no matter what Index is
template <typename T, std::size_t index>
using T_aliased = T;
// make_identical_tuple< T, N >::type is a std::tuple< T, ... , T > with a length of N
template <typename T, std::size_t N, typename I = typename create_indices<N>::type>
struct make_identical_tuple;
template <typename T, std::size_t N, std::size_t... Indices>
struct make_identical_tuple<T, N, indices<Indices...>>
{
using type = std::tuple<T_aliased<T, Indices>...>;
};
template <class GridViewImp, class RangeFieldImp, size_t rangeDim, size_t rangeDimCols> template <class GridViewImp, class RangeFieldImp, size_t rangeDim, size_t rangeDimCols>
class DefaultProductTraits : public DefaultTraits<GridViewImp, RangeFieldImp, rangeDim, rangeDimCols> class DefaultProductTraits : public DefaultTraits<GridViewImp, RangeFieldImp, rangeDim, rangeDimCols>
...@@ -81,14 +43,14 @@ public: ...@@ -81,14 +43,14 @@ public:
static const size_t dimRangeCols = rangeDimCols; static const size_t dimRangeCols = rangeDimCols;
using typename BaseType::RangeFieldType; using typename BaseType::RangeFieldType;
typedef typename Dune::GDT::Spaces::FV::Default<GridViewType, RangeFieldType, 1, dimRangeCols> FactorSpaceType; typedef typename Dune::GDT::Spaces::FV::Default<GridViewType, RangeFieldType, 1, dimRangeCols> FactorSpaceType;
typedef typename make_identical_tuple<FactorSpaceType, dimRange>::type SpaceTupleType; typedef typename DSC::make_identical_tuple<FactorSpaceType, dimRange>::type SpaceTupleType;
typedef typename Dune::GDT::Mapper::ProductFiniteVolume<GridViewType, dimRange, 1> MapperType; typedef typename Dune::GDT::Mapper::ProductFiniteVolume<GridViewType, dimRange, 1> MapperType;
}; // class DefaultProductTraits }; // class DefaultProductTraits
} // namespace internal } // namespace internal
/** TODO: delete copy constructor again and uncomment move constructor? */
template <class GridViewImp, class RangeFieldImp, size_t rangeDim> template <class GridViewImp, class RangeFieldImp, size_t rangeDim>
class DefaultProduct<GridViewImp, RangeFieldImp, rangeDim, 1> class DefaultProduct<GridViewImp, RangeFieldImp, rangeDim, 1>
: public Dune::GDT::Spaces::ProductFVInterface<internal::DefaultProductTraits<GridViewImp, RangeFieldImp, rangeDim, : public Dune::GDT::Spaces::ProductFVInterface<internal::DefaultProductTraits<GridViewImp, RangeFieldImp, rangeDim,
...@@ -117,11 +79,11 @@ public: ...@@ -117,11 +79,11 @@ public:
{ {
} }
// DefaultProduct(ThisType&& source) = default; DefaultProduct(ThisType&& source) = default;
// ThisType& operator=(const ThisType& other) = delete; ThisType& operator=(const ThisType& other) = delete;
// ThisType& operator=(ThisType&& source) = delete; ThisType& operator=(ThisType&& source) = delete;
// These methods are required by ProductSpaceInterface // These methods are required by ProductSpaceInterface
template <size_t ii> template <size_t ii>
......
...@@ -214,9 +214,8 @@ public: ...@@ -214,9 +214,8 @@ public:
++current_solution_it) { ++current_solution_it) {
const auto time = current_solution_it->first; const auto time = current_solution_it->first;
const auto time_on_level = current_solution_on_level_it->first; const auto time_on_level = current_solution_on_level_it->first;
const auto inserted_it = time_prolongated_current_solution_on_level.insert( const auto inserted_it = time_prolongated_current_solution_on_level.emplace_hint(
time_prolongated_current_solution_on_level_it_end, time_prolongated_current_solution_on_level_it_end, time, current_solution_on_level_it->second);
std::make_pair(time, current_solution_on_level_it->second));
if (time_on_level < time && current_solution_on_level_it != current_solution_on_level_it_last) { if (time_on_level < time && current_solution_on_level_it != current_solution_on_level_it_last) {
// compute weighted average of the two values of current_solution_on_level_ // compute weighted average of the two values of current_solution_on_level_
inserted_it->second.vector() = (current_solution_on_level_it->second.vector() * (time_on_level - last_time) inserted_it->second.vector() = (current_solution_on_level_it->second.vector() * (time_on_level - last_time)
...@@ -319,11 +318,8 @@ protected: ...@@ -319,11 +318,8 @@ protected:
++reference_solution_it) { ++reference_solution_it) {
const double time = reference_solution_it->first; const double time = reference_solution_it->first;
const auto discrete_exact_solution_at_time = exact_solution->evaluate_at_time(time); const auto discrete_exact_solution_at_time = exact_solution->evaluate_at_time(time);
const auto inserted_it = discrete_exact_solution_->insert( const auto inserted_it = discrete_exact_solution_->emplace_hint(
discrete_exact_solution_->end(), discrete_exact_solution_->end(), time, reference_solution_it->second);
std::make_pair(time,
DiscreteFunctionType(reference_discretization_->fv_space(),
"exact solution at time " + DSC::to_string(time))));
project(*discrete_exact_solution_at_time, inserted_it->second); project(*discrete_exact_solution_at_time, inserted_it->second);
} }
if (!visualize_prefix_.empty()) { if (!visualize_prefix_.empty()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment