Canoe
Comprehensive Atmosphere N' Ocean Engine
tendency.cpp
Go to the documentation of this file.
1 #include "../coordinates/coordinates.hpp"
2 #include "../globals.hpp"
3 #include "../particles/particles.hpp"
4 #include "diagnostics.hpp"
5 
6 Tendency::Tendency(MeshBlock *pmb) : Diagnostics(pmb, "tendency") {
7  type = "VECTORS";
8  grid = "--C";
9  varname = "rho_t,";
10  long_name = "horizontally averaged gas density tendency,";
11  units = "kg/(m^3.s),";
12 
13  wh_.NewAthenaArray(NHYDRO, ncells3_, ncells2_, ncells1_);
14  for (int n = 1; n <= NVAPOR; ++n) {
15  varname += "vapor" + std::to_string(n) + "_t,";
16  units += "kg/(kg.s),";
17  long_name += "horizontally averaged vapor mass mixing ratio tendency,";
18  }
19  for (int n = 0; n < 3; ++n) {
20  units += "m/s^2,";
21  varname += "vel" + std::to_string(n + 1) + "_t,";
22  long_name += "horizontally averaged velocity tendency,";
23  }
24  units += "pa/s";
25  varname += "press_t";
26  long_name += "horizontally averaged pressure tendency,";
27 
28  int npart = 0;
29  Particles *pp = pmb->ppart;
30  while (pp != nullptr) {
31  npart += pp->u.GetDim4();
32  for (int n = 0; n < pp->u.GetDim4(); ++n) {
33  units += ",kg/(m^3.s)";
34  varname += "," + pp->myname + std::to_string(n + 1) + "_t";
35  long_name +=
36  ",horizontally averaged " + pp->myname + " " + pp->CategoryName(n);
37  long_name += " density tendency";
38  }
39  pp = pp->next;
40  }
41  up_.NewAthenaArray(npart, ncells3_, ncells2_, ncells1_);
42  data.NewAthenaArray(NHYDRO + npart, 1, 1, ncells1_);
43  last_time_ = 0.;
44 }
45 
47  MeshBlock *pmb = pmy_block_;
48 
49  int is = pmb->is, js = pmb->js, ks = pmb->ks;
50  int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
51 
52  data.ZeroClear();
53  if (last_time_ == 0.) {
54  wh_ = w;
55  Particles *pp = pmb->ppart;
56  int m = 0;
57  while (pp != nullptr) {
58  for (int n = 0; n < pp->u.GetDim4(); ++n)
59  for (int k = ks; k <= ke; ++k)
60  for (int j = js; j <= je; ++j)
61  for (int i = is; i <= ie; ++i)
62  up_(m + n, k, j, i) = pp->u(n, k, j, i);
63  m += pp->u.GetDim4();
64  pp = pp->next;
65  }
66  last_time_ = pmb->pmy_mesh->time;
67  return;
68  }
69 
70  // hydro variables
71  for (int k = ks; k <= ke; ++k)
72  for (int j = js; j <= je; ++j) {
73  pmb->pcoord->CellVolume(k, j, is, ie, vol_);
74  for (int n = 0; n < NHYDRO; ++n)
75  for (int i = is; i <= ie; ++i)
76  data(n, i) += (w(n, k, j, i) - wh_(n, k, j, i)) * vol_(i);
77  }
78 
79  // particles
80  Particles *pp = pmb->ppart;
81  int m = 0;
82  while (pp != nullptr) {
83  for (int k = ks; k <= ke; ++k)
84  for (int j = js; j <= je; ++j) {
85  pmb->pcoord->CellVolume(k, j, is, ie, vol_);
86  for (int n = 0; n < pp->u.GetDim4(); ++n)
87  for (int i = is; i <= ie; ++i)
88  data(NHYDRO + m + n, i) +=
89  (pp->u(n, k, j, i) - up_(m + n, k, j, i)) * vol_(i);
90  }
91  m += pp->u.GetDim4();
92  pp = pp->next;
93  }
94 
96 
97  // std::cout << total_vol_(pmb->is) << std::endl;
98 
99  for (int n = 0; n < NHYDRO + m; ++n)
100  for (int i = is; i <= ie; ++i)
101  data(n, i) /= total_vol_(i) * (pmb->pmy_mesh->time - last_time_);
102 
103  last_time_ = pmb->pmy_mesh->time;
104 }
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
AthenaArray< Real > wh_
Real last_time_
void Finalize(AthenaArray< Real > const &w)
Definition: tendency.cpp:46
Tendency(MeshBlock *pmb)
Definition: tendency.cpp:6
AthenaArray< Real > up_