Skip to content

Commit

Permalink
put same MeshData utilities in their own namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
lroberts36 committed Nov 25, 2024
1 parent 6d1a882 commit 2478da4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 7 additions & 4 deletions example/poisson_gmg/poisson_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ TaskCollection PoissonDriver::MakeTaskCollection(BlockList_t &blocks) {
auto &md_rhs = pmesh->mesh_data.Add("rhs", md, {u::name()});

// Move the rhs variable into the rhs stage for stage based solver
auto copy_rhs = tl.AddTask(none, TF(solvers::utils::CopyDataBetweenFields<rhs, u>), md);
auto copy_rhs =
tl.AddTask(none, TF(solvers::utils::between_fields::CopyData<rhs, u>), md);
copy_rhs = tl.AddTask(copy_rhs, TF(solvers::utils::CopyData<parthenon::TypeList<u>>),
md, md_rhs);

// Possibly set rhs <- A.u_exact for a given u_exact so that the exact solution is
// known when we solve A.u = rhs
if (use_exact_rhs) {
auto copy_exact = tl.AddTask(copy_rhs, TF(solvers::utils::CopyDataBetweenFields<exact, u>), md);
auto copy_exact = tl.AddTask(
copy_rhs, TF(solvers::utils::between_fields::CopyData<exact, u>), md);
copy_exact = tl.AddTask(
copy_exact, TF(solvers::utils::CopyData<parthenon::TypeList<u>>), md, md_u);
auto comm = AddBoundaryExchangeTasks<BoundaryType::any>(copy_exact, tl, md_u, true);
Expand All @@ -103,8 +105,9 @@ TaskCollection PoissonDriver::MakeTaskCollection(BlockList_t &blocks) {
auto copy_back = tl.AddTask(
solve, TF(solvers::utils::CopyData<parthenon::TypeList<u>>), md_u, md);
auto diff = tl.AddTask(
copy_back, TF(solvers::utils::AddFieldsAndStore<exact, u, u>), md, 1.0, -1.0);
auto get_err = solvers::utils::DotProduct<u, u>(diff, tl, &err, md);
copy_back, TF(solvers::utils::between_fields::AddFieldsAndStore<exact, u, u>),
md, 1.0, -1.0);
auto get_err = solvers::utils::between_fields::DotProduct<u, u>(diff, tl, &err, md);
tl.AddTask(
get_err,
[](PoissonDriver *driver, int partition) {
Expand Down
14 changes: 13 additions & 1 deletion src/solvers/solver_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ struct Stencil {
};

namespace utils {

namespace between_fields {
template <class in_t, class out_t, bool only_fine_on_composite = true>
TaskStatus CopyDataBetweenFields(const std::shared_ptr<MeshData<Real>> &md) {
TaskStatus CopyData(const std::shared_ptr<MeshData<Real>> &md) {
using TE = parthenon::TopologicalElement;
TE te = TE::CC;
IndexRange ib = md->GetBoundsI(IndexDomain::entire, te);
Expand Down Expand Up @@ -177,6 +179,7 @@ TaskStatus CopyDataBetweenFields(const std::shared_ptr<MeshData<Real>> &md) {
});
return TaskStatus::complete;
}
} // namespace between_fields

template <class TL, bool only_fine_on_composite = true>
TaskStatus CopyData(const std::shared_ptr<MeshData<Real>> &md_in,
Expand Down Expand Up @@ -245,6 +248,10 @@ TaskStatus SetToZero(const std::shared_ptr<MeshData<Real>> &md) {
return TaskStatus::complete;
}

// Utilities functions in the between_fields namespace work on separate fields specified
// by types. Other utility functions work on the same list of fields across separate
// MeshData containers.
namespace between_fields {
template <class a_t, class b_t, class out_t, bool only_fine_on_composite = true>
TaskStatus AddFieldsAndStoreInteriorSelect(const std::shared_ptr<MeshData<Real>> &md,
Real wa = 1.0, Real wb = 1.0,
Expand Down Expand Up @@ -292,6 +299,7 @@ TaskStatus AddFieldsAndStore(const std::shared_ptr<MeshData<Real>> &md, Real wa
return AddFieldsAndStoreInteriorSelect<a_t, b_t, out, only_fine_on_composite>(
md, wa, wb, false);
}
} // namespace between_fields

template <class TL, bool only_fine_on_composite = true>
TaskStatus AddFieldsAndStoreInteriorSelect(const std::shared_ptr<MeshData<Real>> &md_a,
Expand Down Expand Up @@ -347,6 +355,7 @@ TaskStatus AddFieldsAndStore(const std::shared_ptr<MeshData<Real>> &md_a,
wa, wb, false);
}

namespace between_fields {
template <class a_t, class b_t, class out_t>
TaskStatus ADividedByB(const std::shared_ptr<MeshData<Real>> &md) {
IndexRange ib = md->GetBoundsI(IndexDomain::interior);
Expand All @@ -367,6 +376,7 @@ TaskStatus ADividedByB(const std::shared_ptr<MeshData<Real>> &md) {
});
return TaskStatus::complete;
}
} // namespace between_fields

template <class TL>
TaskStatus ADividedByB(const std::shared_ptr<MeshData<Real>> &md_a,
Expand All @@ -391,6 +401,7 @@ TaskStatus ADividedByB(const std::shared_ptr<MeshData<Real>> &md_a,
return TaskStatus::complete;
}

namespace between_fields {
template <class a_t, class b_t>
TaskStatus DotProductLocal(const std::shared_ptr<MeshData<Real>> &md,
AllReduce<Real> *adotb) {
Expand Down Expand Up @@ -439,6 +450,7 @@ TaskID DotProduct(TaskID dependency_in, TaskList &tl, AllReduce<Real> *adotb,
start_global_adotb, &AllReduce<Real>::CheckReduce, adotb);
return finish_global_adotb;
}
} // namespace between_fields

template <class a_t>
TaskStatus GlobalMinLocal(const std::shared_ptr<MeshData<Real>> &md,
Expand Down

0 comments on commit 2478da4

Please sign in to comment.