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