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

Add attach function with callback to GridTransfer

parent 7e46647e
......@@ -86,16 +86,21 @@ namespace AMDiS
REQUIRES(Concepts::UpdateData<Data>)>
void attach(Data& data)
{
auto it = updateCallbacks_.emplace(Key(&data), UpdateCallback{
[&data]() -> void { data.update(data.gridView()); }});
attach(data, [&data]() -> void { data.update(data.gridView()); });
}
/// Register callback to GridTransfer
template <class Data, class Callback>
void attach(Data const& data, Callback&& callback)
{
auto it = updateCallbacks_.emplace(Key(&data), UpdateCallback{FWD(callback)});
it.first->second.count++;
}
/// Unregister data from GridTransfer. Data is identified by its address.
template <class Data,
REQUIRES(Concepts::InterpolateData<Data>)>
void detach(Data& data)
void detach(Data const& data)
{
eraseCallback(interpolateCallbacks_, Key(&data));
}
......@@ -103,7 +108,7 @@ namespace AMDiS
/// Unregister data from GridTransfer. Data is identified by its address.
template <class Data,
REQUIRES(Concepts::UpdateData<Data>)>
void detach(Data& data)
void detach(Data const& data)
{
eraseCallback(updateCallbacks_, Key(&data));
}
......@@ -113,9 +118,14 @@ namespace AMDiS
bool preAdapt() override
{
assert(bound());
Dune::Timer t;
mightCoarsen_ = grid_->preAdapt();
Dune::MPIHelper::getCollectiveCommunication().max(&mightCoarsen_, 1);
for (auto&& data : interpolateCallbacks_)
data.second.preAdapt(mightCoarsen_);
info(2,"preAdapt needed {} seconds", t.elapsed());
return mightCoarsen_;
}
......@@ -124,7 +134,11 @@ namespace AMDiS
bool adapt() override
{
assert(bound());
Dune::Timer t;
refined_ = grid_->adapt();
Dune::MPIHelper::getCollectiveCommunication().max(&refined_, 1);
info(2,"adapt needed {} seconds", t.elapsed());
return refined_;
}
......@@ -133,6 +147,7 @@ namespace AMDiS
void postAdapt() override
{
assert(bound());
Dune::Timer t;
if (mightCoarsen_ || refined_) {
for (auto&& data : updateCallbacks_)
data.second.update();
......@@ -142,6 +157,7 @@ namespace AMDiS
grid_->postAdapt();
changeIndex_++;
info(2,"postAdapt needed {} seconds", t.elapsed());
}
/// Returns the grid change index, see \ref changeIndex.
......
......@@ -65,14 +65,19 @@ namespace AMDiS
get(grid)->attach(data);
}
template <class Grid, class Data, class Callback>
static void attach(Grid const& grid, Data const& data, Callback&& callback)
{
get(grid)->attach(data, FWD(callback));
}
template <class Grid, class Data>
static void detach(Grid const& grid, Data& data)
static void detach(Grid const& grid, Data const& data)
{
get(grid)->detach(data);
}
private:
/// \brief Returns the GridTransfer class, used for attaching and detaching Data
/**
* NOTE: The returned GridTransfer is not yet bound to a grid, since a
......
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