Canoe
Comprehensive Atmosphere N' Ocean Engine
roe_shallow_yz.cpp
Go to the documentation of this file.
1 // \brief Roe's linearized Riemann solver for shallow water model
3 
4 // C/C++ headers
5 #include <algorithm> // min()
6 #include <cmath> // sqrt()
7 #include <iostream>
8 
9 // Athena++ headers
10 #include <athena/athena.hpp>
11 #include <athena/coordinates/coordinates.hpp>
12 #include <athena/hydro/hydro.hpp>
13 #include <athena/mesh/mesh.hpp>
14 
15 // canoe
16 #include <configure.hpp>
17 
18 void Hydro::RiemannSolver(int const k, int const j, int const il, int const iu,
19  int const ivx, AthenaArray<Real> &wl,
21  AthenaArray<Real> const &dxw) {
22  int ivy = ivx == IVY ? IVZ : IVY;
23 
24  Real wli[NHYDRO], wri[NHYDRO], wave[3][3], speed[3];
25 
26  Real ubar, vbar, cbar, delh, delu, delv, hbar, a1, a2, a3;
27 
28  AthenaArray<Real> empty{}; // placeholder for unused electric/magnetic fields
29 #ifdef AFFINE // need of projection
30  {
31  switch (ivx) {
32  case IVY:
33  pmy_block->pcoord->PrimToLocal2(k, j, il, iu, empty, wl, wr, empty);
34  break;
35  case IVZ:
36  pmy_block->pcoord->PrimToLocal3(k, j, il, iu, empty, wl, wr, empty);
37  break;
38  }
39  }
40 #endif // AFFINE
41 
42  for (int i = il; i <= iu; ++i) {
43  for (int n = 0; n < NHYDRO; ++n) {
44  wli[n] = wl(n, i);
45  wri[n] = wr(n, i);
46  }
47 
48  ubar = (wli[ivx] * sqrt(wli[IDN]) + wri[ivx] * sqrt(wri[IDN])) /
49  (sqrt(wli[IDN]) + sqrt(wri[IDN]));
50  vbar = (wli[ivy] * sqrt(wli[IDN]) + wri[ivy] * sqrt(wri[IDN])) /
51  (sqrt(wli[IDN]) + sqrt(wri[IDN]));
52  cbar = sqrt(0.5 * (wli[IDN] + wri[IDN]));
53 
54  delh = wri[IDN] - wli[IDN];
55  delu = wri[ivx] - wli[ivx];
56  delv = wri[ivy] - wli[ivy];
57  hbar = sqrt(wli[IDN] * wri[IDN]);
58 
59  a1 = 0.5 * (cbar * delh - hbar * delu) / cbar;
60  a2 = hbar * delv;
61  a3 = 0.5 * (cbar * delh + hbar * delu) / cbar;
62 
63  wave[0][0] = a1;
64  wave[0][1] = a1 * (ubar - cbar);
65  wave[0][2] = a1 * vbar;
66  wave[1][0] = 0.;
67  wave[1][1] = 0.;
68  wave[1][2] = a2;
69  wave[2][0] = a3;
70  wave[2][1] = a3 * (ubar + cbar);
71  wave[2][2] = a3 * vbar;
72 
73  speed[0] = fabs(ubar - cbar);
74  speed[1] = fabs(ubar);
75  speed[2] = fabs(ubar + cbar);
76 
77  flx(IDN, k, j, i) = 0.5 * (wli[IDN] * wli[ivx] + wri[IDN] * wri[ivx]);
78  flx(ivx, k, j, i) =
79  0.5 * (wli[IDN] * wli[ivx] * wli[ivx] + 0.5 * wli[IDN] * wli[IDN] +
80  wri[IDN] * wri[ivx] * wri[ivx] + 0.5 * wri[IDN] * wri[IDN]);
81  flx(ivy, k, j, i) =
82  0.5 * (wli[IDN] * wli[ivx] * wli[ivy] + wri[IDN] * wri[ivx] * wri[ivy]);
83  flx(IVX, k, j, i) = 0.;
84 
85  for (int r = 0; r < 3; ++r) {
86  flx(IDN, k, j, i) -= 0.5 * speed[r] * wave[r][0];
87  flx(ivx, k, j, i) -= 0.5 * speed[r] * wave[r][1];
88  flx(ivy, k, j, i) -= 0.5 * speed[r] * wave[r][2];
89  }
90  }
91 
92 #ifdef AFFINE // need of deprojection
93  {
94  // check if this is correct
95  switch (ivx) {
96  case IVY:
97  pmy_block->pcoord->FluxToGlobal2(k, j, il, iu, empty, empty, flx, empty,
98  empty);
99  break;
100  case IVZ:
101  pmy_block->pcoord->FluxToGlobal3(k, j, il, iu, empty, empty, flx, empty,
102  empty);
103  break;
104  }
105  }
106 #endif // AFFINE
107 }