Canoe
Comprehensive Atmosphere N' Ocean Engine
total_flux.cpp
Go to the documentation of this file.
1 #include "../coordinates/coordinates.hpp"
2 #include "../globals.hpp"
3 #include "../thermodynamics/thermodynamics.hpp"
4 #include "diagnostics.hpp"
5 
6 HydroFlux::HydroFlux(MeshBlock *pmb) : Diagnostics(pmb, "hydroflux") {
7  type = "VECTORS";
8  grid = "--C";
9  varname = "v1rho,";
10  long_name = "horizontally averaged mass flux,";
11  units = "kg/(m^2.s),";
12 
13  for (int n = 1; n <= NVAPOR; ++n) {
14  varname += "v1q" + std::to_string(n) + ",";
15  units += "kg/(kg.m^2.s),";
16  long_name += "horizontally averaged vapor mass flux,";
17  }
18  for (int n = 0; n < 3; ++n) {
19  units += "m/s^2,";
20  varname += "v1v" + std::to_string(n + 1) + ",";
21  long_name += "horizontally averaged momentum flux,";
22  }
23  units += "m.K/s";
24  varname += "v1T";
25  long_name += "horizontally averaged heat flux";
26 
27  data.NewAthenaArray(NHYDRO, 1, 1, ncells1_);
28 }
29 
31  MeshBlock *pmb = pmy_block_;
32  Coordinates *pcoord = pmb->pcoord;
33  Thermodynamics *pthermo = pmb->pthermo;
34 
35  int is = pmb->is, js = pmb->js, ks = pmb->ks;
36  int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
37 
38  if (ncycle == 0) std::fill(data.data(), data.data() + data.GetSize(), 0.);
39 
40  // sum over horizontal grids weighted by volume
41  for (int k = ks; k <= ke; ++k)
42  for (int j = js; j <= je; ++j) {
43  pcoord->CellVolume(k, j, is, ie, vol_);
44  for (int i = is; i <= ie; ++i) {
45  data(0, i) += vol_(i) * w(IDN, k, j, i) * w(IVX, k, j, i);
46  for (int n = 1; n < IPR; ++n)
47  data(n, i) += vol_(i) * w(n, k, j, i) * w(IVX, k, j, i);
48  data(IPR, i) +=
49  vol_(i) * pthermo->GetTemp(w.at(k, j, i)) * w(IVX, k, j, i);
50  }
51  }
52 
53  ncycle++;
54 }
55 
57  MeshBlock *pmb = pmy_block_;
58 
60 
61  // take time and spatial average
62  if (ncycle > 0) {
63  for (int n = 0; n < NHYDRO; ++n)
64  for (int i = pmb->is; i <= pmb->ie; ++i)
65  data(n, i) /= ncycle * total_vol_(i);
66  }
67 
68  // clear cycle;
69  ncycle = 0;
70 }
void gatherAllData23_(AthenaArray< Real > &total_vol, AthenaArray< Real > &total_data)
std::string units
Definition: diagnostics.hpp:17
AthenaArray< Real > vol_
Definition: diagnostics.hpp:56
std::string long_name
Definition: diagnostics.hpp:17
std::string varname
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
AthenaArray< Real > total_vol_
Definition: diagnostics.hpp:57
std::string grid
Definition: diagnostics.hpp:16
void Progress(AthenaArray< Real > const &w)
Definition: total_flux.cpp:30
HydroFlux(MeshBlock *pmb)
Definition: total_flux.cpp:6
void Finalize(AthenaArray< Real > const &w)
Definition: total_flux.cpp:56
Real GetTemp(MeshBlock const *pmb, int k, int j, int i) const
Calculate temperature from primitive variable.