Skip to content

Commit

Permalink
shared edge_indices appears to work
Browse files Browse the repository at this point in the history
  • Loading branch information
hamsteri15 committed Jan 29, 2024
1 parent c10b6bb commit 1505b75
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 15 deletions.
32 changes: 31 additions & 1 deletion include/bits/communication/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ static constexpr auto edge_indices(const Box<N>& box,
return md_indices(begin, end);
}

/// @brief Given a box and a direction (normal) vector. Returns a box of the
/// indices at the boundary edge of the box desbribed by the normal.
/// @param box The box the query the edge for.
/// @param dir A normal vector to determine which edge to query the bounds for,
/// a negative value points towards beginning and a positive value towards end.
/// @return A box beginning at the begin of the edge and ending one pass the end
/// of the edge.
template <size_t N>
Box<N> get_edge(const Box<N>& b, std::array<index_type, N> dir) {

Expand All @@ -314,13 +321,36 @@ Box<N> get_edge(const Box<N>& b, std::array<index_type, N> dir) {
return Box<N>(beg, end);
}

/// @brief Given two boxes and a direction vector, determines the shared edge of
/// the two boxes described by the direction vector. If no shared edge exists,
/// an empty box is returned.
/// @param b1 First box to test.
/// @param b2 Second box to test.
/// @param dir A normal vector to determine which edge to query the bounds for,
/// a negative value points towards beginning and a positive value towards end.
/// @return A box beginning at the begin of the shared edge and ending one pass
/// the end of the shared edge. If no shared edge exists, an empty box is
/// returned.
template <size_t N>
Box<N> shared_edge(const Box<N>& b1,
const Box<N>& b2,
const std::array<index_type, N> dir) {
return intersection(get_edge(b1, dir), get_edge(b2, dir));
if (have_shared_edges(b1, b2, dir)) {
return intersection(get_edge(b1, dir), get_edge(b2, dir));
}
std::array<index_type, N> beg{};
std::array<index_type, N> end{};
return Box<N>(beg, end);
}

/// @brief Given two boxes and a direction vector, determines the shared edge
/// indices of the two boxes described by the direction vector. If no shared
/// edge exists, an empty set of indices is returned.
/// @param b1 First box to test.
/// @param b2 Second box to test.
/// @param dir A normal vector to determine which edge to query the indices for,
/// a negative value points towards beginning and a positive value towards end.
/// @return A set of indices at the shared edge of the two boxes.
template <size_t N>
static constexpr auto shared_edge_indices(
const Box<N>& b1, const Box<N>& b2, const std::array<index_type, N>& dir) {
Expand Down
61 changes: 47 additions & 14 deletions test/test_communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ TEST_CASE("Test box") {

CHECK(intersection(b1, b2) == Box<3>({0, 0, 0}, {0, 0, 0}));
}


}

SECTION("Contains") {
Expand Down Expand Up @@ -231,6 +233,8 @@ TEST_CASE("Test box") {
}




SECTION("edge_indices"){


Expand Down Expand Up @@ -317,9 +321,11 @@ TEST_CASE("Test box") {
);

}

}




SECTION("shared_edge"){

SECTION("Test 1"){
Expand All @@ -329,6 +335,7 @@ TEST_CASE("Test box") {
auto r1 = shared_edge(domain, sub, {0, 1});

CHECK(r1 == Box<2>({0,0}, {0,0}));

}

SECTION("Test 2"){
Expand All @@ -340,18 +347,15 @@ TEST_CASE("Test box") {
CHECK(r1 == Box<2>({0,0}, {2,1}));
}




}

/*

SECTION("shared_edge_indices"){


SECTION("Test 1"){

const Box<2> domain({0,0}, {3,3});
const Box<2> domain({0,0}, {3,4});
const Box<2> sub({0, 0}, {2,2});

std::vector<int> data(flat_size(domain.get_extent()), 0);
Expand All @@ -368,9 +372,9 @@ TEST_CASE("Test box") {
CHECK
(
data ==
std::vector<int> {0,0,0,
0,0,0,
0,0,0}
std::vector<int> {0,0,0,0,
0,0,0,0,
0,0,0,0}
);
}

Expand All @@ -380,15 +384,44 @@ TEST_CASE("Test box") {
std::fill(data.begin(), data.end(), 0);
for (auto [j, i] : shared_edge_indices(domain, sub, {0,-1})){
span(j, i) = 1;
std::cout << j << " " << i << std::endl;
}

CHECK
(
data ==
std::vector<int> {1,0,0,
1,0,0,
0,0,0}
std::vector<int> {1,0,0,0,
1,0,0,0,
0,0,0,0}
);
}

SECTION("dir {-1, -1}"){
std::fill(data.begin(), data.end(), 0);
for (auto [j, i] : shared_edge_indices(domain, sub, {-1,-1})){
span(j, i) = 1;
}

CHECK
(
data ==
std::vector<int> {1,0,0,0,
0,0,0,0,
0,0,0,0}
);
}

SECTION("dir {1, 1}"){
std::fill(data.begin(), data.end(), 0);
for (auto [j, i] : shared_edge_indices(domain, sub, {1, 1})){
span(j, i) = 1;
}

CHECK
(
data ==
std::vector<int> {0,0,0,0,
0,0,0,0,
0,0,0,0}
);
}

Expand All @@ -398,7 +431,7 @@ TEST_CASE("Test box") {


}
*/




Expand Down

0 comments on commit 1505b75

Please sign in to comment.