-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor bvals code #903
Labels
refactor
An improvement to existing code.
Comments
Some aspirational code for replacing std::unordered_map<LogicalLocation, NeighborBlock>
GetNeighborLocationMap(MeshBlockTree &tree, LogicalLocation center_loc) {
std::unordered_map<LogicalLocation, NeighborBlock> neighbor_map;
const ind ndim = 3;
for (int i = -(ndim > 0); i <= (ndim > 0); ++i) {
for (int j = -(ndim > 1); j <= (ndim > 1); ++j) {
for (int k = -(ndim > 2); k <= (ndim > 2); ++k) {
if (i==0 && j==0 && k==0) continue;
NeighborConnect nc;
int connect_indicator = std::abs(i) + std::abs(j) + std::abs(k);
if (connect_indicator == 1) {
nc = NeighborConnect::face;
} else if (connect_indicator == 2) {
nc = NeighborConnect::edge;
} else if (connect_indicator == 3) {
nc = NeighborConnect::corner;
}
const int bufid = -1; // I am not sure how these need to be set
const int tbid = -1; // I am not sure how these need to be set
auto pneighbor_tree = tree.FindNeighbor(center_loc, i, j, k);
if (pneighbor_tree == nullptr) {
// There is no neighbor in this direction
} else if (!pneighbor_tree->IsLeaf()) {
auto xidxs = (i == 0 ? std::vector<int>{0, 1} : std::vector<int>{i < 0});
auto yidxs = (j == 0 ? std::vector<int>{0, 1} : std::vector<int>{j < 0});
auto zidxs = (k == 0 ? std::vector<int>{0, 1} : std::vector<int>{k < 0});
if (ndim < 3) zidxs = {0};
if (ndim < 2) yidxs = {0};
if (ndim < 1) xidxs = {0};
for (auto nox1 : xidxs) {
for (auto nox2 : yidxs) {
for (auto nox3 : zidxs) {
auto pleaf = pneighbor_tree->GetLeaf(nox1, nox2, nox3);
auto nid = pleaf->GetGid();
int ifi[2]{0, 0};
int idx = 0;
if (xidxs.size() > 1) ifi[idx++] = nox1;
if (yidxs.size() > 1) ifi[idx++] = nox2;
if (zidxs.size() > 1) ifi[idx++] = nox3;
NeighborBlock nb;
nb.SetNeighbor(pleaf->GetLocation(), ranklist[nid],
pleaf->GetLocation().level, nid, i, j, k,
nc, nid - nslist[ranklist[nid]],
bufid, tbid, ifi[0], ifi[1]);
neighbor_map[pleaf->GetLocation()] = nb;
}
}
}
} else {
// Neighbor is at same or coarse level, so we can just grab it
auto nloc = pneighbor_tree->GetLocation();
if (neighbor_map.count(nloc) == 0) {
auto nid = pneighbor_tree->GetLocation();
NeighborBlock nb;
nb.SetNeighbor(nloc, ranklist[nid], nloc.level(),
nid, i, j, k,
nc, nid - nslist[ranklist[nid]],
bufid, tbid, 0, 0);
neighbor_map[nloc] = nb;
}
}
}
}
}
// Add some code here for determining neighbor ownership
return neighbor_map;
} |
Merged
8 tasks
Merged
6 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The old bvals code relies on a somewhat complex inheritance structure and much of it is unused after changes to the boundary communication routines. We should go through the old code, remove what is unnecessary, and clean things up/shorten code where possible.
The text was updated successfully, but these errors were encountered: