Skip to content

Commit

Permalink
this now works, TODO: the shared_edge_indices returns the indices in …
Browse files Browse the repository at this point in the history
…the _first_parameter_ if the second parameter is a subsban, the indices should be offset by the starting index. This is potentially dangerous and needs to be thought carefully.
  • Loading branch information
hamsteri15 committed Feb 2, 2024
1 parent 6c4fd59 commit 5d27c07
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 17 deletions.
39 changes: 39 additions & 0 deletions include/bits/geometry/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,51 @@ template <size_t N>
Box<N> shared_edge(const Box<N>& b1,
const Box<N>& b2,
const std::array<index_type, N> dir) {


std::array<index_type, N> beg{};
std::array<index_type, N> end{};



if (have_shared_edges(b1, b2, dir)){

for (size_t i = 0; i < N; ++i){

if (dir[i] == 1 && (b1.end[i] == b2.end[i])){
end[i] = b1.end[i];
beg[i] = end[i] - 1;
}
if (dir[i] == -1 && (b1.begin[i] == b2.begin[i])){
beg[i] = b1.begin[i];
end[i] = beg[i] + 1;
}

if (dir[i] == 0){
beg[i] = std::max(b1.begin[i], b2.begin[i]);
end[i] = std::min(b1.end[i], b2.end[i]);
}


}

}

return Box<N>(beg, end);


/*
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
Expand Down
66 changes: 49 additions & 17 deletions test/test_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,16 @@ TEST_CASE("Test box") {
CHECK(r1 == Box<2>({0,0}, {2,1}));
}

SECTION("Test 3"){

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

auto r1 = shared_edge(domain, sub, {0, 1});
CHECK(r1 == Box<2>({0,3}, {3, 4}));

}

}


Expand Down Expand Up @@ -429,37 +439,59 @@ TEST_CASE("Test box") {

}

/*
SECTION("Bug 1"){
const Box<2> domain({0,0}, {3,4});
const Box<2> sub({0, 2}, {3,4});
std::vector<int> data(flat_size(domain.get_extent()), 0);
auto span = make_span(data, domain.get_extent());
for (auto [j, i] : shared_edge_indices(domain, sub, {0, 1})){
span(j, i) = 1;
}
CHECK
(
data ==
std::vector<int> {0,0,0,1,
0,0,0,1,
0,0,0,1}
);
}



SECTION("boundary_loops"){

auto domain = Box<2>{{0,0}, {3, 4}};
auto topo = decompose(domain, 3, {false, false});
std::vector<int> data(flat_size(domain.get_extent()), 0);

auto bigspan = make_span(data, domain.get_extent());
SECTION("dir {0, 1}"){
std::vector<int> data(flat_size(domain.get_extent()), 0);

for (auto box : topo.get_boxes()){
auto bigspan = make_span(data, domain.get_extent());

auto subspan = make_subspan(bigspan, box.box.begin, box.box.end);
for (auto box : topo.get_boxes()){

auto indices = shared_edge_indices(domain, box.box, {0, 1});
auto subspan = make_subspan(bigspan, box.box.begin, box.box.end);

//auto indices = shared_edge_indices(domain, box.box, {0, 1});

for (auto [j,i] : shared_edge_indices(domain, box.box, {0, 1}))
{
bigspan(j,i) = 1;
}

for (auto [j,i] : indices){
subspan(j,i) = 1;
}

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

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

}
*/
}

}
Expand Down

0 comments on commit 5d27c07

Please sign in to comment.