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

make grid functions default constructible

parent 847c3e5d
...@@ -48,12 +48,14 @@ namespace Dune ...@@ -48,12 +48,14 @@ namespace Dune
using Signature = Range(Domain); using Signature = Range(Domain);
public: public:
PointDataLocalFunction (Factory const& factory, std::vector<Field> const& values, unsigned int comp) PointDataLocalFunction (Factory const* factory, std::vector<Field> const* values, unsigned int comp)
: factory_(factory) : factory_(factory)
, values_(values) , values_(values)
, comp_(comp) , comp_(comp)
{} {}
PointDataLocalFunction () = default;
void bind (LocalContext const& element) void bind (LocalContext const& element)
{ {
lfe_ = &cache_.get(element.type()); lfe_ = &cache_.get(element.type());
...@@ -62,11 +64,11 @@ namespace Dune ...@@ -62,11 +64,11 @@ namespace Dune
// NOTE: assumes, that Lagrange nodes are ordered like element vertices // NOTE: assumes, that Lagrange nodes are ordered like element vertices
localValues_.resize(element.subEntities(Grid::dimension)); localValues_.resize(element.subEntities(Grid::dimension));
for (unsigned int i = 0; i < element.subEntities(Grid::dimension); ++i) { for (unsigned int i = 0; i < element.subEntities(Grid::dimension); ++i) {
unsigned int idx = factory_.insertionIndex(element.template subEntity<Grid::dimension>(i)); unsigned int idx = factory_->insertionIndex(element.template subEntity<Grid::dimension>(i));
DynamicVector<Field>& v = localValues_[i]; DynamicVector<Field>& v = localValues_[i];
v.resize(comp_); v.resize(comp_);
for (unsigned int j = 0; j < comp_; ++j) for (unsigned int j = 0; j < comp_; ++j)
v[j] = values_[comp_*idx + j]; v[j] = (*values_)[comp_*idx + j];
} }
} }
...@@ -90,8 +92,8 @@ namespace Dune ...@@ -90,8 +92,8 @@ namespace Dune
} }
private: private:
Factory const& factory_; Factory const* factory_ = nullptr;
std::vector<Field> const& values_; std::vector<Field> const* values_ = nullptr;
unsigned int comp_; unsigned int comp_;
// Local Finite-Element // Local Finite-Element
...@@ -113,22 +115,24 @@ namespace Dune ...@@ -113,22 +115,24 @@ namespace Dune
using Signature = Range(Domain); using Signature = Range(Domain);
public: public:
CellDataLocalFunction (Factory const& factory, std::vector<Field> const& values, unsigned int comp) CellDataLocalFunction (Factory const* factory, std::vector<Field> const* values, unsigned int comp)
: factory_(factory) : factory_(factory)
, values_(values) , values_(values)
, comp_(comp) , comp_(comp)
{} {}
CellDataLocalFunction () = default;
void bind (LocalContext const& element) void bind (LocalContext const& element)
{ {
unsigned int idx = factory_.insertionIndex(element); unsigned int idx = factory_->insertionIndex(element);
// collect values on cells // collect values on cells
DynamicVector<Field>& v = localValue_; DynamicVector<Field>& v = localValue_;
v.resize(comp_); v.resize(comp_);
for (unsigned int j = 0; j < comp_; ++j) for (unsigned int j = 0; j < comp_; ++j)
v[j] = values_[comp_*idx + j]; v[j] = (*values_)[comp_*idx + j];
} }
void unbind () void unbind ()
...@@ -140,8 +144,8 @@ namespace Dune ...@@ -140,8 +144,8 @@ namespace Dune
} }
private: private:
Factory const& factory_; Factory const* factory_ = nullptr;
std::vector<Field> const& values_; std::vector<Field> const* values_ = nullptr;
unsigned int comp_; unsigned int comp_;
// cache of local values // cache of local values
...@@ -159,11 +163,13 @@ namespace Dune ...@@ -159,11 +163,13 @@ namespace Dune
std::vector<std::uint8_t> const& /*types*/, std::vector<std::uint8_t> const& /*types*/,
std::vector<std::int64_t> const& /*offsets*/, std::vector<std::int64_t> const& /*offsets*/,
std::vector<std::int64_t> const& /*connectivity*/) std::vector<std::int64_t> const& /*connectivity*/)
: factory_(creator.factory()) : factory_(&creator.factory())
, values_(values) , values_(&values)
, comp_(comp) , comp_(comp)
{} {}
ContinuousGridFunction () = default;
Range operator() (Domain const& global) const Range operator() (Domain const& global) const
{ {
DUNE_THROW(Dune::NotImplemented, "Evaluation in global coordinates not implemented."); DUNE_THROW(Dune::NotImplemented, "Evaluation in global coordinates not implemented.");
...@@ -181,9 +187,9 @@ namespace Dune ...@@ -181,9 +187,9 @@ namespace Dune
} }
private: private:
Factory const& factory_; Factory const* factory_;
std::vector<Field> const& values_; std::vector<Field> const* values_ = nullptr;
unsigned int comp_; unsigned int comp_ = 0;
EntitySet entitySet_; EntitySet entitySet_;
}; };
......
...@@ -56,10 +56,10 @@ namespace Dune ...@@ -56,10 +56,10 @@ namespace Dune
public: public:
/// Constructor. Stores references to the passed data. /// Constructor. Stores references to the passed data.
PointDataLocalFunction (GridCreator const& creator, std::vector<Field> const& values, unsigned int comp, PointDataLocalFunction (GridCreator const* creator, std::vector<Field> const* values, unsigned int comp,
std::vector<std::uint8_t> const& types, std::vector<std::uint8_t> const* types,
std::vector<std::int64_t> const& offsets, std::vector<std::int64_t> const* offsets,
std::vector<std::int64_t> const& connectivity) std::vector<std::int64_t> const* connectivity)
: creator_(creator) : creator_(creator)
, values_(values) , values_(values)
, comp_(comp) , comp_(comp)
...@@ -68,6 +68,8 @@ namespace Dune ...@@ -68,6 +68,8 @@ namespace Dune
, connectivity_(connectivity) , connectivity_(connectivity)
{} {}
PointDataLocalFunction () = default;
/// Binding the local-function to an element. /// Binding the local-function to an element.
/** /**
* Constructs a new local finite-element with a polynomial order given * Constructs a new local finite-element with a polynomial order given
...@@ -77,29 +79,29 @@ namespace Dune ...@@ -77,29 +79,29 @@ namespace Dune
**/ **/
void bind (LocalContext const& element) void bind (LocalContext const& element)
{ {
unsigned int insertionIndex = creator_.factory().insertionIndex(element); unsigned int insertionIndex = creator_->factory().insertionIndex(element);
std::int64_t shift = (insertionIndex == 0 ? 0 : offsets_[insertionIndex-1]); std::int64_t shift = (insertionIndex == 0 ? 0 : (*offsets_)[insertionIndex-1]);
std::int64_t numNodes = offsets_[insertionIndex] - shift; std::int64_t numNodes = (*offsets_)[insertionIndex] - shift;
[[maybe_unused]] std::int64_t maxNumNodes = numLagrangePoints(element.type().id(), element.type().dim(), 20); [[maybe_unused]] std::int64_t maxNumNodes = numLagrangePoints(element.type().id(), element.type().dim(), 20);
VTK_ASSERT(numNodes > 0 && numNodes < maxNumNodes); VTK_ASSERT(numNodes > 0 && numNodes < maxNumNodes);
int order = creator_.order(element.type(), numNodes); int order = creator_->order(element.type(), numNodes);
VTK_ASSERT(order > 0 && order < 20); VTK_ASSERT(order > 0 && order < 20);
// construct a local finite-element with the corresponding order and Lagrange points // construct a local finite-element with the corresponding order and Lagrange points
// as stored in the file // as stored in the file
lfe_.emplace(LFE{element.type(), (unsigned int)(order)}); lfe_.emplace(LFE{element.type(), (unsigned int)(order)});
lgeo_.emplace(creator_.localGeometry(element)); lgeo_.emplace(creator_->localGeometry(element));
// collect values on lagrange nodes // collect values on lagrange nodes
localValues_.resize(numNodes); localValues_.resize(numNodes);
for (std::int64_t i = shift, i0 = 0; i < offsets_[insertionIndex]; ++i, ++i0) { for (std::int64_t i = shift, i0 = 0; i < (*offsets_)[insertionIndex]; ++i, ++i0) {
std::int64_t idx = connectivity_[i]; std::int64_t idx = (*connectivity_)[i];
DynamicVector<Field>& v = localValues_[i0]; DynamicVector<Field>& v = localValues_[i0];
v.resize(comp_); v.resize(comp_);
for (unsigned int j = 0; j < comp_; ++j) for (unsigned int j = 0; j < comp_; ++j)
v[j] = values_[comp_*idx + j]; v[j] = (*values_)[comp_*idx + j];
} }
} }
...@@ -128,12 +130,12 @@ namespace Dune ...@@ -128,12 +130,12 @@ namespace Dune
} }
private: private:
GridCreator const& creator_; GridCreator const* creator_ = nullptr;
std::vector<Field> const& values_; std::vector<Field> const* values_ = nullptr;
unsigned int comp_; unsigned int comp_;
std::vector<std::uint8_t> const& types_; std::vector<std::uint8_t> const* types_ = nullptr;
std::vector<std::int64_t> const& offsets_; std::vector<std::int64_t> const* offsets_ = nullptr;
std::vector<std::int64_t> const& connectivity_; std::vector<std::int64_t> const* connectivity_ = nullptr;
// Local Finite-Element // Local Finite-Element
std::optional<LFE> lfe_ = std::nullopt; std::optional<LFE> lfe_ = std::nullopt;
...@@ -156,27 +158,29 @@ namespace Dune ...@@ -156,27 +158,29 @@ namespace Dune
public: public:
/// Constructor. Stores references to the passed data. /// Constructor. Stores references to the passed data.
CellDataLocalFunction (GridCreator const& creator, std::vector<Field> const& values, unsigned int comp, CellDataLocalFunction (GridCreator const* creator, std::vector<Field> const* values, unsigned int comp,
std::vector<std::uint8_t> const& /*types*/, std::vector<std::uint8_t> const* /*types*/,
std::vector<std::int64_t> const& /*offsets*/, std::vector<std::int64_t> const* /*offsets*/,
std::vector<std::int64_t> const& /*connectivity*/) std::vector<std::int64_t> const* /*connectivity*/)
: factory_(creator.factory()) : creator_(creator)
, values_(values) , values_(values)
, comp_(comp) , comp_(comp)
{} {}
CellDataLocalFunction () = default;
/// Binding the local-function to an element extract the cell-value from the vector /// Binding the local-function to an element extract the cell-value from the vector
/// of data. /// of data.
void bind (LocalContext const& element) void bind (LocalContext const& element)
{ {
unsigned int idx = factory_.insertionIndex(element); unsigned int idx = creator_->factory().insertionIndex(element);
// collect values on cells // collect values on cells
DynamicVector<Field>& v = localValue_; DynamicVector<Field>& v = localValue_;
v.resize(comp_); v.resize(comp_);
for (unsigned int j = 0; j < comp_; ++j) for (unsigned int j = 0; j < comp_; ++j)
v[j] = values_[comp_*idx + j]; v[j] = (*values_)[comp_*idx + j];
} }
/// Unbinds from the bound element. Does nothing /// Unbinds from the bound element. Does nothing
...@@ -191,8 +195,8 @@ namespace Dune ...@@ -191,8 +195,8 @@ namespace Dune
} }
private: private:
Factory const& factory_; GridCreator const* creator_ = nullptr;
std::vector<Field> const& values_; std::vector<Field> const* values_ = nullptr;
unsigned int comp_; unsigned int comp_;
// cache of local values // cache of local values
...@@ -212,14 +216,16 @@ namespace Dune ...@@ -212,14 +216,16 @@ namespace Dune
std::vector<std::uint8_t> const& types, std::vector<std::uint8_t> const& types,
std::vector<std::int64_t> const& offsets, std::vector<std::int64_t> const& offsets,
std::vector<std::int64_t> const& connectivity) std::vector<std::int64_t> const& connectivity)
: creator_(creator) : creator_(&creator)
, values_(values) , values_(&values)
, comp_(comp) , comp_(comp)
, types_(types) , types_(&types)
, offsets_(offsets) , offsets_(&offsets)
, connectivity_(connectivity) , connectivity_(&connectivity)
{} {}
LagrangeGridFunction () = default;
/// Global evaluation. Not supported! /// Global evaluation. Not supported!
Range operator() (Domain const& global) const Range operator() (Domain const& global) const
{ {
...@@ -241,12 +247,12 @@ namespace Dune ...@@ -241,12 +247,12 @@ namespace Dune
} }
private: private:
GridCreator const& creator_; GridCreator const* creator_ = nullptr;
std::vector<Field> const& values_; std::vector<Field> const* values_ = nullptr;
unsigned int comp_; unsigned int comp_ = 0;
std::vector<std::uint8_t> const& types_; std::vector<std::uint8_t> const* types_ = nullptr;
std::vector<std::int64_t> const& offsets_; std::vector<std::int64_t> const* offsets_ = nullptr;
std::vector<std::int64_t> const& connectivity_; std::vector<std::int64_t> const* connectivity_ = nullptr;
EntitySet entitySet_; EntitySet entitySet_;
}; };
......
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