Canoe
Comprehensive Atmosphere N' Ocean Engine
buoyancy.cpp
Go to the documentation of this file.
1 #include "../coordinates/coordinates.hpp"
2 #include "../hydro/hydro.hpp"
3 #include "../hydro/srcterms/hydro_srcterms.hpp"
4 #include "../reconstruct/interpolation.hpp"
5 #include "diagnostics.hpp"
6 
7 Buoyancy::Buoyancy(MeshBlock* pmb) : Diagnostics(pmb, "b") {
8  type = "SCALARS";
9  long_name = "buoyancy";
10  units = "m/s^2";
11  data.NewAthenaArray(ncells3_, ncells2_, ncells1_);
12  pf_.NewAthenaArray(ncells3_, ncells2_, ncells1_ + 1);
13  grav_ = pmb->phydro->hsrc.GetG1();
14 }
15 
17  MeshBlock* pmb = pmy_block_;
18  int is = pmb->is, js = pmb->js, ks = pmb->ks;
19  int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
20 
21  for (int k = ks; k <= ke; ++k)
22  for (int j = js; j <= je; ++j)
23  for (int i = is; i <= ie + 1; ++i) {
24  // pf_(k,j,i) =
25  // interp_cp4(w(IPR,k,j,i-2),w(IPR,k,j,i-1),w(IPR,k,j,i),w(IPR,k,j,i+1));
26  pf_(k, j, i) = sqrt(w(IPR, k, j, i - 1) * w(IPR, k, j, i));
27  }
28 
29  // buoyancy
30  for (int k = ks; k <= ke; ++k)
31  for (int j = js; j <= je; ++j)
32  for (int i = is; i <= ie; ++i) {
33  Real dx = pmb->pcoord->dx1f(i);
34  data(k, j, i) =
35  (pf_(k, j, i) - pf_(k, j, i + 1)) / (dx * w(IDN, k, j, i)) + grav_;
36  }
37 
38  // fix boundary condition
39  bool has_top_neighbor = false;
40  bool has_bot_neighbor = false;
41  for (int n = 0; n < pmb->pbval->nneighbor; ++n) {
42  NeighborBlock& nb = pmb->pbval->neighbor[n];
43  if ((nb.ni.ox1 == -1) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == 0))
44  has_bot_neighbor = true;
45  if ((nb.ni.ox1 == 1) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == 0))
46  has_top_neighbor = true;
47  }
48 
49  if (!has_bot_neighbor) {
50  for (int k = ks; k <= ke; ++k)
51  for (int j = js; j <= je; ++j) data(k, j, is) = data(k, j, is + 1);
52  }
53 
54  if (!has_top_neighbor) {
55  for (int k = ks; k <= ke; ++k)
56  for (int j = js; j <= je; ++j) data(k, j, ie) = data(k, j, ie - 1);
57  }
58 }
Buoyancy(MeshBlock *pmb)
Definition: buoyancy.cpp:7
AthenaArray< Real > pf_
void Finalize(AthenaArray< Real > const &w)
Definition: buoyancy.cpp:16
std::string units
Definition: diagnostics.hpp:17
std::string long_name
Definition: diagnostics.hpp:17
std::string type
Definition: diagnostics.hpp:16
AthenaArray< Real > data
Definition: diagnostics.hpp:19
MeshBlock * pmy_block_
Definition: diagnostics.hpp:44