Canoe
Comprehensive Atmosphere N' Ocean Engine
eddy_kinetic_energy.cpp
Go to the documentation of this file.
1 
9 // Athena++ headers
10 #include "../coordinates/coordinates.hpp"
11 #include "../globals.hpp"
12 #include "../utils/utils.hpp"
13 #include "diagnostics.hpp"
14 
15 // MPI headers
16 #ifdef MPI_PARALLEL
17 #include <mpi.h>
18 #endif
19 
20 EddyKineticEnergy::EddyKineticEnergy(MeshBlock *pmb) : Diagnostics(pmb, "eke") {
21  type = "VECTORS";
22  grid = "--C";
23  long_name = "eddy kinetic energy,mean kinetic energy";
24  units = "J/m^3,J/m^3";
25  data.NewAthenaArray(2, 1, 1, ncells1_);
26 }
27 
29  MeshBlock *pmb = pmy_block_;
30 
31  int is = pmb->is, js = pmb->js, ks = pmb->ks;
32  int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
33 
34  Real *data_sum = new Real[4 * ncells1_];
35  Real **dir_sum;
36  NewCArray(dir_sum, 3, 4 * ncells1_);
37 
38  std::fill(data_sum, data_sum + 4 * ncells1_, 0.);
39  // calculate horizontal mean
40  for (int k = ks; k <= ke; ++k)
41  for (int j = js; j <= je; ++j) {
42  pmb->pcoord->CellVolume(k, j, is, ie, vol_);
43  for (int i = is; i <= ie; ++i) {
44  data_sum[0 * ncells1_ + i] += vol_(i) * w(IVX, k, j, i);
45  data_sum[1 * ncells1_ + i] += vol_(i) * w(IVY, k, j, i);
46  data_sum[2 * ncells1_ + i] += vol_(i) * w(IVZ, k, j, i);
47  data_sum[3 * ncells1_ + i] += vol_(i);
48  }
49  }
50 
51  /*#ifdef MPI_PARALLEL
52  MPI_Comm comm;
53 
54  for (int d = 0; d < 3; ++d) {
55  if ((d == 1) && (!pmb->pmy_mesh->f2)) break;
56  if ((d == 2) && (!pmb->pmy_mesh->f3)) break;
57  SetColor(static_cast<CoordinateDirection>(d));
58  if (Globals::my_rank == 0) {
59  for (int i = 0; i < Globals::nranks; ++i)
60  std::cout << color_[i] << " ";
61  std::cout << std::endl;
62  }
63  MPI_Comm_split(MPI_COMM_WORLD, color_[Globals::my_rank],
64  Globals::my_rank, &comm); MPI_Allreduce(data_sum, dir_sum[d], 4*ncells1_,
65  MPI_ATHENA_REAL, MPI_SUM, comm); MPI_Comm_free(&comm);
66  }
67  #endif*/
68 
69  // calculate eddy and mean
70  data.ZeroClear();
71  for (int n = 0; n < 3; ++n) {
72  if ((n == 1) && (!pmb->pmy_mesh->f2)) break;
73  if ((n == 2) && (!pmb->pmy_mesh->f3)) break;
74  for (int k = ks; k <= ke; ++k)
75  for (int j = js; j <= je; ++j)
76  for (int i = is; i <= ie; ++i) {
77  Real mean =
78  dir_sum[n][n * ncells1_ + i] / dir_sum[n][3 * ncells1_ + i];
79  Real eddy = w(IVX + n, k, j, i) - mean;
80  data(0, i) += 0.5 * w(IDN, k, j, i) * eddy * eddy;
81  data(1, i) += 0.5 * w(IDN, k, j, i) * mean * mean;
82  }
83  }
84 
85  delete[] data_sum;
86  FreeCArray(dir_sum);
87 }
std::string units
Definition: diagnostics.hpp:17
AthenaArray< Real > vol_
Definition: diagnostics.hpp:56
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
std::string grid
Definition: diagnostics.hpp:16
EddyKineticEnergy(MeshBlock *pmb)
void Finalize(AthenaArray< Real > const &w)
void FreeCArray(T **a)
Definition: ndarrays.hpp:13
void NewCArray(T **&a, int n1, int n2)
Definition: ndarrays.hpp:5