Skip to content
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

Closed
lroberts36 opened this issue Jul 7, 2023 · 1 comment · Fixed by #1009
Closed

Refactor bvals code #903

lroberts36 opened this issue Jul 7, 2023 · 1 comment · Fixed by #1009
Assignees
Labels
refactor An improvement to existing code.

Comments

@lroberts36
Copy link
Collaborator

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.

@lroberts36
Copy link
Collaborator Author

lroberts36 commented Jul 7, 2023

Some aspirational code for replacing BoundaryBase::SearchAndSetNeighbors (I mostly created this issue so I would have somewhere to stash this):

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;  
}

@lroberts36 lroberts36 added the refactor An improvement to existing code. label Jul 7, 2023
@lroberts36 lroberts36 linked a pull request Jul 24, 2023 that will close this issue
8 tasks
@lroberts36 lroberts36 removed a link to a pull request Sep 28, 2023
8 tasks
@lroberts36 lroberts36 linked a pull request Mar 7, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor An improvement to existing code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants