Canoe
Comprehensive Atmosphere N' Ocean Engine
horizontal_divergence.cpp
Go to the documentation of this file.
1 #include "../coordinates/coordinates.hpp"
2 #include "../reconstruct/interpolation.hpp"
3 #include "diagnostics.hpp"
4 
6  : Diagnostics(pmb, "div_h") {
7  type = "SCALARS";
8  data.NewAthenaArray(ncells3_, ncells2_, ncells1_);
9  if (pmb->block_size.nx2 > 1)
10  v2f2_.NewAthenaArray(ncells3_, ncells2_ + 1, ncells1_);
11  if (pmb->block_size.nx3 > 1)
12  v3f3_.NewAthenaArray(ncells3_ + 1, ncells2_, ncells1_);
13 }
14 
16  data.DeleteAthenaArray();
17  if (pmy_block_->block_size.nx2 > 1) v2f2_.DeleteAthenaArray();
18  if (pmy_block_->block_size.nx3 > 1) v3f3_.DeleteAthenaArray();
19 }
20 
22  MeshBlock *pmb = pmy_block_;
23  Coordinates *pcoord = pmb->pcoord;
24  int is = pmb->is, js = pmb->js, ks = pmb->ks;
25  int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
26 
27  // interpolate velocities to cell faces
28  if (pmb->block_size.nx2 > 1)
29  for (int k = ks; k <= ke; ++k)
30  for (int j = js; j <= je + 1; ++j)
31  for (int i = is; i <= ie; ++i) {
32  v2f2_(k, j, i) = interp_cp4(w(IVY, k, j - 2, i), w(IVY, k, j - 1, i),
33  w(IVY, k, j, i), w(IVY, k, j + 1, i));
34  }
35  if (pmb->block_size.nx3 > 1)
36  for (int k = ks; k <= ke + 1; ++k)
37  for (int j = js; j <= je; ++j)
38  for (int i = is; i <= ie; ++i) {
39  v3f3_(k, j, i) = interp_cp4(w(IVZ, k - 2, j, i), w(IVZ, k - 1, j, i),
40  w(IVZ, k, j, i), w(IVZ, k + 1, j, i));
41  }
42 
43  // divergence
44  for (int k = ks; k <= ke; ++k)
45  for (int j = js; j <= je; ++j) {
46  pcoord->CellVolume(k, j, is, ie, vol_);
47  for (int i = is; i <= ie; ++i) {
48  if (pmb->block_size.nx2 > 1) {
49  pcoord->Face2Area(k, j, is, ie, x2area_);
50  pcoord->Face2Area(k, j + 1, is, ie, x2area_p1_);
51  data(k, j, i) =
52  x2area_p1_(i) * v2f2_(k, j + 1, i) - x2area_(i) * v2f2_(k, j, i);
53  }
54 
55  if (pmb->block_size.nx3 > 1) {
56  pcoord->Face3Area(k, j, is, ie, x3area_);
57  pcoord->Face3Area(k + 1, j, is, ie, x3area_p1_);
58  data(k, j, i) +=
59  x3area_p1_(i) * v3f3_(k + 1, j, i) - x3area_(i) * v3f3_(k, j, i);
60  }
61 
62  data(k, j, i) /= vol_(i);
63  }
64  }
65 }
AthenaArray< Real > x2area_p1_
Definition: diagnostics.hpp:56
AthenaArray< Real > vol_
Definition: diagnostics.hpp:56
AthenaArray< Real > x3area_
Definition: diagnostics.hpp:56
std::string type
Definition: diagnostics.hpp:16
AthenaArray< Real > data
Definition: diagnostics.hpp:19
AthenaArray< Real > x2area_
Definition: diagnostics.hpp:56
AthenaArray< Real > x3area_p1_
Definition: diagnostics.hpp:56
MeshBlock * pmy_block_
Definition: diagnostics.hpp:44
AthenaArray< Real > v2f2_
AthenaArray< Real > v3f3_
HorizontalDivergence(MeshBlock *pmb)
void Finalize(AthenaArray< Real > const &w)