Canoe
Comprehensive Atmosphere N' Ocean Engine
exchanger.cpp
Go to the documentation of this file.
1 // athena
2 #include <athena/bvals/bvals.hpp>
3 #include <athena/mesh/mesh.hpp>
4 
5 // canoe
6 #include <common.hpp>
7 
8 namespace ExchangerHelper {
9 
10 NeighborBlock const *find_bot_neighbor(MeshBlock const *pmb) {
11  NeighborBlock *pbot = nullptr;
12 
13  for (int n = 0; n < pmb->pbval->nneighbor; ++n) {
14  NeighborBlock *nb = pmb->pbval->neighbor + n;
15  if ((nb->ni.ox1 == -1) && (nb->ni.ox2 == 0) && (nb->ni.ox3 == 0)) pbot = nb;
16  }
17 
18  return pbot;
19 }
20 
21 NeighborBlock const *find_top_neighbor(MeshBlock const *pmb) {
22  NeighborBlock *ptop = nullptr;
23 
24  for (int n = 0; n < pmb->pbval->nneighbor; ++n) {
25  NeighborBlock *nb = pmb->pbval->neighbor + n;
26  if ((nb->ni.ox1 == 1) && (nb->ni.ox2 == 0) && (nb->ni.ox3 == 0)) ptop = nb;
27  }
28 
29  return ptop;
30 }
31 
32 NeighborBlock const *find_left_neighbor(MeshBlock const *pmb) {
33  NeighborBlock *pleft = nullptr;
34 
35  for (int n = 0; n < pmb->pbval->nneighbor; ++n) {
36  NeighborBlock *nb = pmb->pbval->neighbor + n;
37  if ((nb->ni.ox1 == 0) && (nb->ni.ox2 == -1) && (nb->ni.ox3 == 0))
38  pleft = nb;
39  }
40 
41  return pleft;
42 }
43 
44 NeighborBlock const *find_right_neighbor(MeshBlock const *pmb) {
45  NeighborBlock *pright = nullptr;
46 
47  for (int n = 0; n < pmb->pbval->nneighbor; ++n) {
48  NeighborBlock *nb = pmb->pbval->neighbor + n;
49  if ((nb->ni.ox1 == 1) && (nb->ni.ox2 == 1) && (nb->ni.ox3 == 0))
50  pright = nb;
51  }
52 
53  return pright;
54 }
55 
56 NeighborBlock const *find_back_neighbor(MeshBlock const *pmb) {
57  NeighborBlock *pback = nullptr;
58 
59  for (int n = 0; n < pmb->pbval->nneighbor; ++n) {
60  NeighborBlock *nb = pmb->pbval->neighbor + n;
61  if ((nb->ni.ox1 == 0) && (nb->ni.ox2 == 0) && (nb->ni.ox3 == -1))
62  pback = nb;
63  }
64 
65  return pback;
66 }
67 
68 NeighborBlock const *find_front_neighbor(MeshBlock const *pmb) {
69  NeighborBlock *pfront = nullptr;
70 
71  for (int n = 0; n < pmb->pbval->nneighbor; ++n) {
72  NeighborBlock *nb = pmb->pbval->neighbor + n;
73  if ((nb->ni.ox1 == 1) && (nb->ni.ox2 == 1) && (nb->ni.ox3 == 1))
74  pfront = nb;
75  }
76 
77  return pfront;
78 }
79 
80 void find_neighbors(MeshBlock const *pmb, CoordinateDirection dir,
81  NeighborBlock *bblock, NeighborBlock *tblock) {
82  // set void bblock
83  bblock->snb.gid = -1;
84  bblock->snb.rank = -1;
85 
86  // set void tblock
87  tblock->snb.gid = -1;
88  tblock->snb.rank = -1;
89 
90  for (int n = 0; n < pmb->pbval->nneighbor; ++n) {
91  NeighborBlock &nb = pmb->pbval->neighbor[n];
92  if (dir == X1DIR) {
93  if ((nb.ni.ox1 == -1) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == 0))
94  *bblock = nb;
95  if ((nb.ni.ox1 == 1) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == 0))
96  *tblock = nb;
97  } else if (dir == X2DIR) {
98  if ((nb.ni.ox1 == 0) && (nb.ni.ox2 == -1) && (nb.ni.ox3 == 0))
99  *bblock = nb;
100  if ((nb.ni.ox1 == 0) && (nb.ni.ox2 == 1) && (nb.ni.ox3 == 0))
101  *tblock = nb;
102  } else { // X3DIR
103  if ((nb.ni.ox1 == 0) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == -1))
104  *bblock = nb;
105  if ((nb.ni.ox1 == 0) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == 1))
106  *tblock = nb;
107  }
108  }
109 }
110 
111 } // namespace ExchangerHelper
NeighborBlock const * find_back_neighbor(MeshBlock const *pmb)
find back neighbor block
Definition: exchanger.cpp:56
NeighborBlock const * find_left_neighbor(MeshBlock const *pmb)
find left neighbor block
Definition: exchanger.cpp:32
NeighborBlock const * find_front_neighbor(MeshBlock const *pmb)
find front neighbor block
Definition: exchanger.cpp:68
NeighborBlock const * find_bot_neighbor(MeshBlock const *pmb)
find bottom neighbor block
Definition: exchanger.cpp:10
NeighborBlock const * find_top_neighbor(MeshBlock const *pmb)
find top neighbor block
Definition: exchanger.cpp:21
NeighborBlock const * find_right_neighbor(MeshBlock const *pmb)
find right neighbor block
Definition: exchanger.cpp:44
void find_neighbors(MeshBlock const *pmb, CoordinateDirection dir, NeighborBlock *bblock, NeighborBlock *tblock)
find neighbors in one coordinate direction
Definition: exchanger.cpp:80