Skip to content

Commit

Permalink
Pass amr::Info instead of the amr::Flags when making AMR decisions
Browse files Browse the repository at this point in the history
This change allows Elements to figure out the new Mesh of their neighbors
when adjusting the Domain after the final AMR decisions are determined.
  • Loading branch information
kidder committed Oct 11, 2023
1 parent 0858d4d commit c66a6a6
Show file tree
Hide file tree
Showing 39 changed files with 1,053 additions and 680 deletions.
7 changes: 4 additions & 3 deletions src/Domain/Amr/Flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// See LICENSE.txt for details.

#include "Domain/Amr/Flag.hpp"

#include <ostream>
#include <vector>

#include "Options/Options.hpp"
#include "Options/ParseOptions.hpp"
#include "Utilities/ErrorHandling/Error.hpp"
#include "Utilities/GetOutput.hpp"
#include "Utilities/StdHelpers.hpp"

#include <ostream>
#include <vector>

namespace {
std::vector<amr::Flag> known_amr_flags() {
return std::vector{amr::Flag::Undefined, amr::Flag::Join,
Expand Down
12 changes: 6 additions & 6 deletions src/Domain/Amr/NeighborsOfChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "Domain/Amr/Flag.hpp"
#include "Domain/Amr/Helpers.hpp"
#include "Domain/Amr/Info.hpp"
#include "Domain/Amr/NewNeighborIds.hpp"
#include "Domain/Structure/Direction.hpp"
#include "Domain/Structure/DirectionMap.hpp"
Expand All @@ -26,8 +27,8 @@ template <size_t VolumeDim>
DirectionMap<VolumeDim, Neighbors<VolumeDim>> neighbors_of_child(
const Element<VolumeDim>& parent,
const std::array<Flag, VolumeDim>& parent_flags,
const std::unordered_map<ElementId<VolumeDim>, std::array<Flag, VolumeDim>>&
parent_neighbor_flags,
const std::unordered_map<ElementId<VolumeDim>, Info<VolumeDim>>&
parent_neighbor_info,
const ElementId<VolumeDim>& child_id) {
DirectionMap<VolumeDim, Neighbors<VolumeDim>> result;

Expand All @@ -48,7 +49,7 @@ DirectionMap<VolumeDim, Neighbors<VolumeDim>> neighbors_of_child(
result.emplace(direction,
Neighbors<VolumeDim>{
new_neighbor_ids(child_id, direction, old_neighbors,
parent_neighbor_flags),
parent_neighbor_info),
old_neighbors.orientation()});
}
}
Expand All @@ -70,9 +71,8 @@ DirectionMap<VolumeDim, Neighbors<VolumeDim>> neighbors_of_child(
template DirectionMap<DIM(data), Neighbors<DIM(data)>> neighbors_of_child( \
const Element<DIM(data)>& parent, \
const std::array<Flag, DIM(data)>& parent_flags, \
const std::unordered_map<ElementId<DIM(data)>, \
std::array<Flag, DIM(data)>>& \
parent_neighbor_flags, \
const std::unordered_map<ElementId<DIM(data)>, Info<DIM(data)>>& \
parent_neighbor_info, \
const ElementId<DIM(data)>& child_id);

GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3))
Expand Down
10 changes: 7 additions & 3 deletions src/Domain/Amr/NeighborsOfChild.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "Domain/Amr/Flag.hpp"

/// \cond
namespace amr {
template <size_t VolumeDim>
struct Info;
} // namespace amr
template <size_t VolumeDim, typename T>
class DirectionMap;
template <size_t VolumeDim>
Expand All @@ -24,12 +28,12 @@ namespace amr {
/// \ingroup AmrGroup
/// \brief returns the neighbors of the Element with ElementId `child_id`,
/// whose parent Element is `parent` which has refinement flags `parent_flags`
/// and neighbor flags `parent_neighbor_flags`
/// and neighbor Info `parent_neighbor_info`
template <size_t VolumeDim>
DirectionMap<VolumeDim, Neighbors<VolumeDim>> neighbors_of_child(
const Element<VolumeDim>& parent,
const std::array<Flag, VolumeDim>& parent_flags,
const std::unordered_map<ElementId<VolumeDim>, std::array<Flag, VolumeDim>>&
parent_neighbor_flags,
const std::unordered_map<ElementId<VolumeDim>, Info<VolumeDim>>&
parent_neighbor_info,
const ElementId<VolumeDim>& child_id);
} // namespace amr
37 changes: 18 additions & 19 deletions src/Domain/Amr/NeighborsOfParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "Domain/Amr/Flag.hpp"
#include "Domain/Amr/Helpers.hpp"
#include "Domain/Amr/Info.hpp"
#include "Domain/Amr/NewNeighborIds.hpp"
#include "Domain/Structure/Direction.hpp"
#include "Domain/Structure/DirectionMap.hpp"
Expand All @@ -27,25 +28,24 @@ namespace amr {
template <size_t VolumeDim>
DirectionMap<VolumeDim, Neighbors<VolumeDim>> neighbors_of_parent(
const ElementId<VolumeDim>& parent_id,
const std::vector<
std::tuple<const Element<VolumeDim>&,
const std::unordered_map<ElementId<VolumeDim>,
std::array<Flag, VolumeDim>>&>>&
children_elements_and_neighbor_flags) {
const std::vector<std::tuple<
const Element<VolumeDim>&,
const std::unordered_map<ElementId<VolumeDim>, Info<VolumeDim>>&>>&
children_elements_and_neighbor_info) {
DirectionMap<VolumeDim, Neighbors<VolumeDim>> result;

std::vector<ElementId<VolumeDim>> children_ids;
children_ids.reserve(children_elements_and_neighbor_flags.size());
children_ids.reserve(children_elements_and_neighbor_info.size());
alg::transform(
children_elements_and_neighbor_flags, std::back_inserter(children_ids),
children_elements_and_neighbor_info, std::back_inserter(children_ids),
[](const auto& child_items) { return std::get<0>(child_items).id(); });

const auto is_child = [&children_ids](const ElementId<VolumeDim>& id) {
return alg::find(children_ids, id) != children_ids.end();
};

for (const auto& [child, child_neighbor_flags] :
children_elements_and_neighbor_flags) {
for (const auto& [child, child_neighbor_info] :
children_elements_and_neighbor_info) {
for (const auto& [direction, child_neighbors] : child.neighbors()) {
if (has_potential_sibling(child.id(), direction) and
is_child(*(child_neighbors.ids().begin()))) {
Expand All @@ -55,11 +55,11 @@ DirectionMap<VolumeDim, Neighbors<VolumeDim>> neighbors_of_parent(
result.emplace(direction, Neighbors<VolumeDim>{
amr::new_neighbor_ids(
parent_id, direction, child_neighbors,
child_neighbor_flags),
child_neighbor_info),
child_neighbors.orientation()});
} else {
result.at(direction).add_ids(amr::new_neighbor_ids(
parent_id, direction, child_neighbors, child_neighbor_flags));
parent_id, direction, child_neighbors, child_neighbor_info));
}
}
}
Expand All @@ -68,14 +68,13 @@ DirectionMap<VolumeDim, Neighbors<VolumeDim>> neighbors_of_parent(

#define DIM(data) BOOST_PP_TUPLE_ELEM(0, data)

#define INSTANTIATE(_, data) \
template DirectionMap<DIM(data), Neighbors<DIM(data)>> neighbors_of_parent( \
const ElementId<DIM(data)>& parent_id, \
const std::vector< \
std::tuple<const Element<DIM(data)>&, \
const std::unordered_map<ElementId<DIM(data)>, \
std::array<Flag, DIM(data)>>&>>& \
children_elements_and_neighbor_flags);
#define INSTANTIATE(_, data) \
template DirectionMap<DIM(data), Neighbors<DIM(data)>> neighbors_of_parent( \
const ElementId<DIM(data)>& parent_id, \
const std::vector<std::tuple< \
const Element<DIM(data)>&, \
const std::unordered_map<ElementId<DIM(data)>, Info<DIM(data)>>&>>& \
children_elements_and_neighbor_info);

GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3))

Expand Down
17 changes: 9 additions & 8 deletions src/Domain/Amr/NeighborsOfParent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#include <unordered_map>
#include <vector>

#include "Domain/Amr/Flag.hpp"

/// \cond
namespace amr {
template <size_t VolumeDim>
struct Info;
} // namespace amr
template <size_t VolumeDim, typename T>
class DirectionMap;
template <size_t VolumeDim>
Expand All @@ -25,13 +27,12 @@ class Neighbors;
namespace amr {
/// \ingroup AmrGroup
/// \brief returns the neighbors of the Element with ElementId `parent_id`,
/// that is created from its `children_elements_and_neighbor_flags`
/// that is created from its `children_elements_and_neighbor_info`
template <size_t VolumeDim>
DirectionMap<VolumeDim, Neighbors<VolumeDim>> neighbors_of_parent(
const ElementId<VolumeDim>& parent_id,
const std::vector<
std::tuple<const Element<VolumeDim>&,
const std::unordered_map<ElementId<VolumeDim>,
std::array<Flag, VolumeDim>>&>>&
children_elements_and_neighbor_flags);
const std::vector<std::tuple<
const Element<VolumeDim>&,
const std::unordered_map<ElementId<VolumeDim>, Info<VolumeDim>>&>>&
children_elements_and_neighbor_info);
} // namespace amr
26 changes: 13 additions & 13 deletions src/Domain/Amr/NewNeighborIds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#include "DataStructures/Index.hpp"
#include "DataStructures/IndexIterator.hpp"
#include "Domain/Amr/Flag.hpp"
#include "Domain/Amr/Helpers.hpp"
#include "Domain/Amr/Info.hpp"
#include "Domain/Structure/Direction.hpp"
#include "Domain/Structure/ElementId.hpp"
#include "Domain/Structure/Neighbors.hpp"
Expand Down Expand Up @@ -40,9 +42,8 @@ template <size_t VolumeDim>
std::unordered_set<ElementId<VolumeDim>> new_neighbor_ids(
const ElementId<VolumeDim>& my_id, const Direction<VolumeDim>& direction,
const Neighbors<VolumeDim>& previous_neighbors_in_direction,
const std::unordered_map<ElementId<VolumeDim>,
std::array<amr::Flag, VolumeDim>>&
previous_neighbors_amr_flags) {
const std::unordered_map<ElementId<VolumeDim>, Info<VolumeDim>>&
previous_neighbors_amr_info) {
std::unordered_set<ElementId<VolumeDim>> new_neighbors_in_direction;

const OrientationMap<VolumeDim>& orientation_map_from_me_to_neighbors =
Expand All @@ -55,7 +56,7 @@ std::unordered_set<ElementId<VolumeDim>> new_neighbor_ids(
const ElementId<1>& previous_neighbor_id =
*(previous_neighbors_in_direction.ids().begin());
const amr::Flag neighbor_flag =
previous_neighbors_amr_flags.at(previous_neighbor_id)[0];
previous_neighbors_amr_info.at(previous_neighbor_id).flags[0];
SegmentId previous_segment_id = previous_neighbor_id.segment_ids()[0];
SegmentId new_segment_id =
(amr::Flag::Join == neighbor_flag
Expand Down Expand Up @@ -88,7 +89,7 @@ std::unordered_set<ElementId<VolumeDim>> new_neighbor_ids(
const auto neighbor_segment_ids = previous_neighbor_id.segment_ids();
for (size_t d = 0; d < VolumeDim; ++d) {
const amr::Flag neighbor_flag =
previous_neighbors_amr_flags.at(previous_neighbor_id)[d];
previous_neighbors_amr_info.at(previous_neighbor_id).flags.at(d);
const SegmentId neighbor_segment_id = gsl::at(neighbor_segment_ids, d);
if (dim_of_direction_to_me_in_neighbor_frame == d) {
// This is the normal direction. I know my previous neighbor touched
Expand Down Expand Up @@ -176,14 +177,13 @@ std::unordered_set<ElementId<VolumeDim>> new_neighbor_ids(

#define DIM(data) BOOST_PP_TUPLE_ELEM(0, data)

#define INSTANTIATE(_, data) \
template std::unordered_set<ElementId<DIM(data)>> new_neighbor_ids( \
const ElementId<DIM(data)>& my_id, \
const Direction<DIM(data)>& direction, \
const Neighbors<DIM(data)>& previous_neighbors_in_direction, \
const std::unordered_map<ElementId<DIM(data)>, \
std::array<amr::Flag, DIM(data)>>& \
previous_neighbors_amr_flags);
#define INSTANTIATE(_, data) \
template std::unordered_set<ElementId<DIM(data)>> new_neighbor_ids( \
const ElementId<DIM(data)>& my_id, \
const Direction<DIM(data)>& direction, \
const Neighbors<DIM(data)>& previous_neighbors_in_direction, \
const std::unordered_map<ElementId<DIM(data)>, Info<DIM(data)>>& \
previous_neighbors_amr_info);

GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3))

Expand Down
13 changes: 7 additions & 6 deletions src/Domain/Amr/NewNeighborIds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#include <unordered_map>
#include <unordered_set>

#include "Domain/Amr/Flag.hpp"

/// \cond
namespace amr {
template <size_t VolumeDim>
struct Info;
} // namespace amr
template <size_t VolumeDim>
class Direction;
template <size_t VolumeDim>
Expand All @@ -29,13 +31,12 @@ namespace amr {
/// child) of the Element with `my_id` if `my_id` corresponds to a newly created
/// child (or parent) Element.
///
/// \note `previous_neighbors_amr_flags` may contain flags from neighbors in
/// \note `previous_neighbors_amr_info` may contain info from neighbors in
/// directions other than `direction`
template <size_t VolumeDim>
std::unordered_set<ElementId<VolumeDim>> new_neighbor_ids(
const ElementId<VolumeDim>& my_id, const Direction<VolumeDim>& direction,
const Neighbors<VolumeDim>& previous_neighbors_in_direction,
const std::unordered_map<ElementId<VolumeDim>,
std::array<amr::Flag, VolumeDim>>&
previous_neighbors_amr_flags);
const std::unordered_map<ElementId<VolumeDim>, Info<VolumeDim>>&
previous_neighbors_amr_info);
} // namespace amr
15 changes: 10 additions & 5 deletions src/Domain/Amr/Tags/Flags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@

#pragma once

#include <array>
#include <cstddef>

#include "DataStructures/DataBox/Tag.hpp"
#include "Domain/Amr/Flag.hpp"

/// \cond
namespace amr {
template <size_t VolumeDim>
struct Info;
} // namespace amr
/// \endcond

namespace amr::Tags {
/// amr::Flag%s for an Element.
/// amr::Info for an Element.
template <size_t VolumeDim>
struct Flags : db::SimpleTag {
using type = std::array<amr::Flag, VolumeDim>;
struct Info : db::SimpleTag {
using type = amr::Info<VolumeDim>;
};

} // namespace amr::Tags
13 changes: 7 additions & 6 deletions src/Domain/Amr/Tags/NeighborFlags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@

#pragma once

#include <array>
#include <cstddef>
#include <unordered_map>

#include "DataStructures/DataBox/Tag.hpp"
#include "Domain/Amr/Flag.hpp"

/// \cond
namespace amr {
template <size_t VolumeDim>
struct Info;
} // namespace amr
template <size_t VolumeDim>
class ElementId;
/// \endcond

namespace amr::Tags {
/// amr::Flag%s for the neighbors of an Element.
/// amr::Info for the neighbors of an Element.
template <size_t VolumeDim>
struct NeighborFlags : db::SimpleTag {
using type = std::unordered_map<ElementId<VolumeDim>,
std::array<amr::Flag, VolumeDim>>;
struct NeighborInfo : db::SimpleTag {
using type = std::unordered_map<ElementId<VolumeDim>, amr::Info<VolumeDim>>;
};

} // namespace amr::Tags
1 change: 1 addition & 0 deletions src/Domain/Amr/UpdateAmrDecision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Domain/Amr/UpdateAmrDecision.hpp"

#include "Domain/Amr/Flag.hpp"
#include "Domain/Amr/Helpers.hpp"
#include "Domain/Structure/Direction.hpp"
#include "Domain/Structure/Element.hpp" // IWYU pragma: keep
Expand Down
5 changes: 3 additions & 2 deletions src/Domain/Amr/UpdateAmrDecision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include <array>
#include <cstddef>

#include "Domain/Amr/Flag.hpp"

/// \cond
namespace amr {
enum class Flag;
} // namespace amr
namespace gsl {
template <typename T>
class not_null;
Expand Down
4 changes: 3 additions & 1 deletion src/Evolution/Initialization/Evolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "DataStructures/DataBox/Prefixes.hpp"
#include "Domain/Amr/Flag.hpp"
#include "Domain/Amr/Helpers.hpp"
#include "Domain/Amr/Info.hpp"
#include "Domain/Amr/Tags/Flags.hpp"
#include "Domain/Structure/ElementId.hpp"
#include "Domain/Tags.hpp"
Expand Down Expand Up @@ -204,7 +205,8 @@ struct ProjectTimeStepping : tt::ConformsTo<amr::protocols::Projector> {
// step quantities to belong to the first child
const auto& parent_diagnostics =
get<::Tags::AdaptiveSteppingDiagnostics>(parent_items);
const auto& parent_amr_flags = get<amr::Tags::Flags<Dim>>(parent_items);
const auto& parent_amr_flags =
get<amr::Tags::Info<Dim>>(parent_items).flags;
const auto& parent_id =
get<Parallel::Tags::ArrayIndexImpl<ElementId<Dim>>>(parent_items);
auto children_ids = amr::ids_of_children(parent_id, parent_amr_flags);
Expand Down
Loading

0 comments on commit c66a6a6

Please sign in to comment.