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

Merge branch 'feature/gridtransfer_attach' into 'master'

Add attach function with callback to GridTransfer

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