Canoe
Comprehensive Atmosphere N' Ocean Engine
sponge_layer.cpp
Go to the documentation of this file.
1 // Athena++ headers
2 #include "../communicator/communicator.hpp"
3 #include "../coordinates/coordinates.hpp"
4 #include "../debugger/debugger.hpp"
5 #include "../globals.hpp"
6 #include "../math/core.h" // sqr
7 #include "../mesh/mesh.hpp"
8 #include "physics.hpp"
9 
11  AthenaArray<Real> const &w, Real time,
12  Real dt) {
13  MeshBlock *pmb = pmy_block;
14  NeighborBlock const *ptop = pmb->pcomm->findTopNeighbor();
15  if (ptop != nullptr) return TaskStatus::success;
16 
17  pmb->pdebug->Call("Physics::TopSpongerLayer");
18  Coordinates *pcoord = pmb->pcoord;
19  Real x1max = pmb->block_size.x1max;
20 
21  for (int k = pmb->ks; k <= pmb->ke; ++k)
22  for (int j = pmb->js; j <= pmb->je; ++j)
23  for (int i = pmb->ie; i >= pmb->is; --i) {
24  Real eta = (width_top_ - (x1max - pcoord->x1f(i + 1))) / width_top_;
25  if (eta < 0) break;
26 
27  Real scale = sqr(sin(M_PI / 2. * eta));
28  du(IVX, k, j, i) -=
29  w(IDN, k, j, i) * w(IVX, k, j, i) / tau_top_ * scale * dt;
30  du(IVY, k, j, i) -=
31  w(IDN, k, j, i) * w(IVY, k, j, i) / tau_top_ * scale * dt;
32  du(IVZ, k, j, i) -=
33  w(IDN, k, j, i) * w(IVZ, k, j, i) / tau_top_ * scale * dt;
34  }
35 
36 #if DEBUG_LEVEL > 2
37  pmb->pdebug->CheckConservation("du", du, pmb->is, pmb->ie, pmb->js, pmb->je,
38  pmb->ks, pmb->ke);
39 #endif
40  pmb->pdebug->Leave();
41  return TaskStatus::success;
42 }
43 
45  AthenaArray<Real> const &w, Real time,
46  Real dt) {
47  MeshBlock *pmb = pmy_block;
48  NeighborBlock const *pbot = pmb->pcomm->findBotNeighbor();
49  if (pbot != nullptr) return TaskStatus::success;
50 
51  pmb->pdebug->Call("Physics::BotSpongeLayer");
52  Coordinates *pcoord = pmb->pcoord;
53  Real x1min = pmb->block_size.x1min;
54 
55  for (int k = pmb->ks; k <= pmb->ke; ++k)
56  for (int j = pmb->js; j <= pmb->je; ++j)
57  for (int i = pmb->is; i <= pmb->ie; ++i) {
58  Real eta = (width_bot_ - (pcoord->x1f(i) - x1min)) / width_bot_;
59  if (eta < 0) break;
60 
61  Real scale = sqr(sin(M_PI / 2. * eta));
62  du(IVX, k, j, i) -=
63  w(IDN, k, j, i) * w(IVX, k, j, i) / tau_bot_ * scale * dt;
64  du(IVY, k, j, i) -=
65  w(IDN, k, j, i) * w(IVY, k, j, i) / tau_bot_ * scale * dt;
66  du(IVZ, k, j, i) -=
67  w(IDN, k, j, i) * w(IVZ, k, j, i) / tau_bot_ * scale * dt;
68  }
69 
70 #if (DEBUG_LEVEL > 1)
71  pmb->pdebug->CheckConservation("du", du, pmb->is, pmb->ie, pmb->js, pmb->je,
72  pmb->ks, pmb->ke);
73 #endif
74  pmb->pdebug->Leave();
75  return TaskStatus::success;
76 }
77 
79  AthenaArray<Real> const &w, Real time,
80  Real dt) {
81  MeshBlock *pmb = pmy_block;
82  NeighborBlock const *pleft = pmb->pcomm->findLeftNeighbor();
83  if (pleft != nullptr) return TaskStatus::success;
84 
85  pmb->pdebug->Call("Physics::LeftSpongerLayer");
86  Coordinates *pcoord = pmb->pcoord;
87  Real x2min = pmb->block_size.x2min;
88 
89  for (int k = pmb->ks; k <= pmb->ke; ++k)
90  for (int j = pmb->js; j <= pmb->je; ++j) {
91  Real eta = (width_left_ - (pcoord->x2f(j) - x2min)) / width_left_;
92  if (eta < 0) break;
93  for (int i = pmb->is; i <= pmb->ie; ++i) {
94  Real scale = sqr(sin(M_PI / 2. * eta));
95  du(IVX, k, j, i) -=
96  w(IDN, k, j, i) * w(IVX, k, j, i) / tau_left_ * scale * dt;
97  du(IVY, k, j, i) -=
98  w(IDN, k, j, i) * w(IVY, k, j, i) / tau_left_ * scale * dt;
99  du(IVZ, k, j, i) -=
100  w(IDN, k, j, i) * w(IVZ, k, j, i) / tau_left_ * scale * dt;
101  }
102  }
103 
104 #if DEBUG_LEVEL > 2
105  pmb->pdebug->CheckConservation("du", du, pmb->is, pmb->ie, pmb->js, pmb->je,
106  pmb->ks, pmb->ke);
107 #endif
108  pmb->pdebug->Leave();
109  return TaskStatus::success;
110 }
111 
113  AthenaArray<Real> const &w, Real time,
114  Real dt) {
115  MeshBlock *pmb = pmy_block;
116  NeighborBlock const *pright = pmb->pcomm->findRightNeighbor();
117  if (pright != nullptr) return TaskStatus::success;
118 
119  pmb->pdebug->Call("Physics::RightSpongeLayer");
120  Coordinates *pcoord = pmb->pcoord;
121  Real x2max = pmb->block_size.x2max;
122 
123  for (int k = pmb->ks; k <= pmb->ke; ++k)
124  for (int j = pmb->je; j <= pmb->js; --j) {
125  Real eta = (width_right_ - (x2max - pcoord->x2f(j + 1))) / width_right_;
126  if (eta < 0) break;
127  for (int i = pmb->is; i <= pmb->ie; ++i) {
128  Real scale = sqr(sin(M_PI / 2. * eta));
129  du(IVX, k, j, i) -=
130  w(IDN, k, j, i) * w(IVX, k, j, i) / tau_right_ * scale * dt;
131  du(IVY, k, j, i) -=
132  w(IDN, k, j, i) * w(IVY, k, j, i) / tau_right_ * scale * dt;
133  du(IVZ, k, j, i) -=
134  w(IDN, k, j, i) * w(IVZ, k, j, i) / tau_right_ * scale * dt;
135  }
136  }
137 
138 #if (DEBUG_LEVEL > 1)
139  pmb->pdebug->CheckConservation("du", du, pmb->is, pmb->ie, pmb->js, pmb->je,
140  pmb->ks, pmb->ke);
141 #endif
142  pmb->pdebug->Leave();
143  return TaskStatus::success;
144 }
Real width_bot_
Definition: physics.hpp:78
TaskStatus BotSpongeLayer(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
Real tau_right_
Definition: physics.hpp:83
TaskStatus RightSpongeLayer(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
Real tau_left_
Definition: physics.hpp:80
MeshBlock * pmy_block
Definition: physics.hpp:24
Real tau_bot_
Definition: physics.hpp:77
Real width_right_
Definition: physics.hpp:84
Real width_left_
Definition: physics.hpp:81
TaskStatus TopSpongeLayer(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
Real width_top_
Definition: physics.hpp:75
Real tau_top_
Definition: physics.hpp:74
TaskStatus LeftSpongeLayer(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
double sqr(double x)
Definition: core.h:14