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

Merge branch 'issue/data_transfer_cleanup' into 'master'

cleanup of DataTransfer, created generator for treeContainer is node-data template is used

See merge request !66
parents 818b7a19 79f58977
#pragma once
#include <map>
#include <memory>
#include <dune/grid/common/mcmgmapper.hh>
#include <amdis/Output.hpp>
#include <amdis/typetree/TreeContainer.hpp>
namespace AMDiS
{
......@@ -51,8 +55,64 @@ namespace AMDiS
};
template <class Node, class Container, class Basis>
class NodeDataTransfer;
/** Data Transfer implementation for a single grid using interpolation
* Handles computations related to the geometric information of the grid and passes that to the
* underlying NodeDataTransfer classes
*/
template <class Container, class Basis>
class DataTransfer;
class DataTransfer
: public DataTransferInterface<Container>
{
using LocalView = typename Basis::LocalView;
using Tree = typename LocalView::Tree;
using GridView = typename Basis::GridView;
using Grid = typename GridView::Grid;
using Element = typename GridView::template Codim<0>::Entity;
using Geometry = typename Element::Geometry;
using LocalCoordinate = typename Geometry::LocalCoordinate;
using IdType = typename Grid::LocalIdSet::IdType;
template <class Node>
using NodeElementData = typename NodeDataTransfer<Node, Container, Basis>::NodeElementData;
using ElementData = TYPEOF(makeTreeContainer<NodeElementData>(std::declval<const Tree&>()));
public:
DataTransfer(std::shared_ptr<Basis> basis);
/** Saves data contained in coeff in the PersistentContainer
* To be called after grid.preAdapt() and before grid.adapt()
*/
void preAdapt(Container const& coeff, bool mightCoarsen) override;
/** Unpacks data from the PersistentContainer
* To be called after grid.adapt() and before grid.postAdapt()
*/
void postAdapt(Container& coeff, bool refined) override;
private:
/// The global basis
std::shared_ptr<Basis const> basis_;
/// Container with data that persists during grid adaptation
using PersistentContainer = std::map<IdType, ElementData>;
PersistentContainer persistentContainer_;
/// Map leaf entities to unique index
using Mapper = Dune::LeafMultipleCodimMultipleGeomTypeMapper<Grid>;
Mapper mapper_;
/// Data transfer on a single basis node
template <class Node>
using NDT = NodeDataTransfer<Node, Container, Basis>;
using NodeDataTransferContainer = TYPEOF(makeTreeContainer<NDT>(std::declval<const Tree&>()));
NodeDataTransferContainer nodeDataTransfer_;
};
/// Factory to create DataTransfer objects based on the \ref DataTransferOperation
template <class Container>
......@@ -62,14 +122,14 @@ namespace AMDiS
public:
template <class Basis>
static std::unique_ptr<Interface> create(DataTransferOperation op, Basis const& basis)
static std::unique_ptr<Interface> create(DataTransferOperation op, std::shared_ptr<Basis> basis)
{
switch (op)
{
case DataTransferOperation::NO_OPERATION:
return std::make_unique<NoDataTransfer<Container>>();
case DataTransferOperation::INTERPOLATE:
return std::make_unique<DataTransfer<Container, Basis>>(basis);
return std::make_unique<DataTransfer<Container, Basis>>(std::move(basis));
default:
error_exit("Invalid data transfer\n");
return nullptr; // avoid warnings
......
This diff is collapsed.
......@@ -84,8 +84,8 @@ namespace AMDiS
public:
/// Constructor. Stores the shared_ptr of the basis and creates a new DataTransfer.
DOFVectorBase(std::shared_ptr<GlobalBasis> basis, DataTransferOperation op)
: basis_(basis)
, dataTransfer_(DataTransferFactory::create(op, *basis_))
: basis_(std::move(basis))
, dataTransfer_(DataTransferFactory::create(op, basis_))
{
compress();
attachToGridTransfer();
......
......@@ -202,6 +202,13 @@ namespace AMDiS
return makeTreeContainer(tree, [](const auto&) {return Value{};});
}
template<template<class> class NodeData, class Tree>
auto makeTreeContainer(const Tree& tree)
{
return makeTreeContainer(tree, [](const auto& node) {return NodeData<TYPEOF(node)>{};});
}
/**
* \brief Alias to container type generated by makeTreeContainer for given value and tree type
*/
......
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