Commit eacb3756 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'issue/simple_grid_constructur' into 'master'

constructor of simple-grid changed to take lvalue or rvalue references, by using SmartRef

See merge request spraetor/dune-dec!12
parents 35bcdef4 a105469e
......@@ -14,14 +14,10 @@
#include <dune/dec/common/Output.hpp>
#include <dune/dec/common/Tags.hpp>
#include <dune/dec/ranges/IndexRange.hpp>
#include <dune/dec/utility/SmartReference.hpp>
namespace Dec
{
namespace tag
{
struct store_data {};
}
/** \brief An implementation of a simple grid wrapper, where the grid is
* described by two vectors: a connectivity vector for the elements and a
* vector of vertex coordinates.
......@@ -103,31 +99,26 @@ namespace Dec
public: // Member functions:
/// Constructor, takes a vector of element connectivity and a vector of vertex coordinates
SimpleGrid(Elements const& elements,
Coordinates const& coordinates)
: elements_(elements)
, coordinates_(coordinates)
, vertices_(coordinates.size())
, indexSet_(elements_, vertices_)
{
indexSet_.init(*this, Dim_<dim>);
}
SimpleGrid(Elements& elements,
Coordinates& coordinates,
tag::store_data)
: elements_(this->stored_elements_)
, coordinates_(this->stored_coordinates_)
, vertices_(coordinates.size())
, indexSet_(elements_, vertices_)
/// \brief Constructor, takes a vector of element connectivity and a vector of vertex coordinates.
/**
* An element-vector is a `vector<vector<unsigned int>>` of indices representing the connectivity of the grid
* The coordinate vector represents the coordinates of the vertices of the grid
* Optionally the tag `tag::store` can be provided, to create a copy of the passed vectors, otherwise
* the data is **refereced**, or moved if passed as rvalue.
*/
template <class Elements_, class Coordinates_, class... Tags>
SimpleGrid(Elements_&& elements,
Coordinates_&& coordinates,
Tags... tags)
: elements_(std::forward<Elements_>(elements), tags...)
, coordinates_(std::forward<Coordinates_>(coordinates), tags...)
, vertices_(coordinates_->size())
, indexSet_(*elements_, vertices_)
{
std::swap(stored_elements_, elements);
std::swap(stored_coordinates_, coordinates);
indexSet_.init(*this, Dim_<dim>);
}
/// Return the maximal refinementlevel of the grid. Since it can not be refined, this is always 0.
int maxLevel() const { return 0; }
/// Return the grids leaf index set
......@@ -180,10 +171,10 @@ namespace Dec
}
/// Return a vector of vertex coordinates
Coordinates const& vertices() const { return coordinates_; }
Coordinates const& vertices() const { return *coordinates_; }
/// Returns a vector of element connectivity
Elements const& elements() const { return elements_; }
Elements const& elements() const { return *elements_; }
/// Communicate data on this view
template <class DataHandleImp, class T>
......@@ -197,12 +188,12 @@ namespace Dec
private: // Implementation details:
// element iterators
ElementIterator begin_impl(Codim_t<0>, PriorityTag_t<1>) const { return {elements_.cbegin(), coordinates_}; }
ElementIterator end_impl (Codim_t<0>, PriorityTag_t<1>) const { return {elements_.cend(), coordinates_}; }
ElementIterator begin_impl(Codim_t<0>, PriorityTag_t<1>) const { return {elements_->cbegin(), *coordinates_}; }
ElementIterator end_impl (Codim_t<0>, PriorityTag_t<1>) const { return {elements_->cend(), *coordinates_}; }
// vertex iterators
VertexIterator begin_impl(Codim_t<dim>, PriorityTag_t<0>) const { return {vertices_.cbegin(), coordinates_}; }
VertexIterator end_impl (Codim_t<dim>, PriorityTag_t<0>) const { return {vertices_.cend(), coordinates_}; }
VertexIterator begin_impl(Codim_t<dim>, PriorityTag_t<0>) const { return {vertices_.cbegin(), *coordinates_}; }
VertexIterator end_impl (Codim_t<dim>, PriorityTag_t<0>) const { return {vertices_.cend(), *coordinates_}; }
template <int d>
int begin_impl(Codim_t<d>, PriorityTag_t<0>) const
......@@ -219,11 +210,8 @@ namespace Dec
private: // Member variables:
Elements stored_elements_;
Coordinates stored_coordinates_;
Elements const& elements_;
Coordinates const& coordinates_;
SmartRef<Elements const> elements_;
SmartRef<Coordinates const> coordinates_;
Vertices vertices_;
......
......@@ -53,8 +53,7 @@ namespace Dune
/// Finalize grid creation and hand over the grid.
virtual /*owner*/ Grid* createGrid() override
{
Grid* grid = new Grid(elements, coordinates, Dec::tag::store_data{});
return grid;
return new Grid(std::move(elements), std::move(coordinates));
}
private:
......
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