Canoe
Comprehensive Atmosphere N' Ocean Engine
curl.cpp
Go to the documentation of this file.
1 #include "../coordinates/coordinates.hpp"
2 #include "../reconstruct/interpolation.hpp"
3 #include "diagnostics.hpp"
4 
5 Curl::Curl(MeshBlock *pmb) : Diagnostics(pmb, "curl") {
6  long_name = "curl";
7  units = "1/s";
8  if (pmb->block_size.nx3 > 1) {
9  type = "VECTORS";
10  data.NewAthenaArray(3, ncells3_, ncells2_, ncells1_);
11  v3f2_.NewAthenaArray(ncells3_ + 1, ncells2_ + 1, ncells1_ + 1);
12  v2f3_.NewAthenaArray(ncells3_ + 1, ncells2_ + 1, ncells1_ + 1);
13  v1f3_.NewAthenaArray(ncells3_ + 1, ncells2_ + 1, ncells1_ + 1);
14  v3f1_.NewAthenaArray(ncells3_ + 1, ncells2_ + 1, ncells1_ + 1);
15  v2f1_.NewAthenaArray(ncells3_ + 1, ncells2_ + 1, ncells1_ + 1);
16  v1f2_.NewAthenaArray(ncells3_ + 1, ncells2_ + 1, ncells1_ + 1);
17  } else if (pmb->block_size.nx2 > 1) {
18  type = "SCALARS";
19  data.NewAthenaArray(ncells3_, ncells2_, ncells1_);
20  v2f1_.NewAthenaArray(ncells3_, ncells2_ + 1, ncells1_ + 1);
21  v1f2_.NewAthenaArray(ncells3_, ncells2_ + 1, ncells1_ + 1);
22  }
23 }
24 
26  MeshBlock *pmb = pmy_block_;
27  Coordinates *pcoord = pmb->pcoord;
28  int is = pmb->is, js = pmb->js, ks = pmb->ks;
29  int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
30 
31  // interpolate velocities to cell faces
32  if (pmb->block_size.nx3 > 1) {
33  for (int k = ks; k <= ke + 1; ++k)
34  for (int j = js; j <= je + 1; ++j)
35  for (int i = is; i <= ie + 1; ++i) {
36  v3f2_(k, j, i) = interp_cp4(w(IVZ, k, j - 2, i), w(IVZ, k, j - 1, i),
37  w(IVZ, k, j, i), w(IVZ, k, j + 1, i));
38  v2f3_(k, j, i) = interp_cp4(w(IVY, k - 2, j, i), w(IVY, k - 1, j, i),
39  w(IVY, k, j, i), w(IVY, k + 1, j, i));
40  v1f3_(k, j, i) = interp_cp4(w(IVX, k - 2, j, i), w(IVX, k - 1, j, i),
41  w(IVX, k, j, i), w(IVX, k + 1, j, i));
42  v3f1_(k, j, i) = interp_cp4(w(IVZ, k, j, i - 2), w(IVZ, k, j, i - 1),
43  w(IVZ, k, j, i), w(IVZ, k, j, i + 1));
44  v2f1_(k, j, i) = interp_cp4(w(IVY, k, j, i - 2), w(IVY, k, j, i - 1),
45  w(IVY, k, j, i), w(IVY, k, j, i + 1));
46  v1f2_(k, j, i) = interp_cp4(w(IVX, k, j - 2, i), w(IVX, k, j - 1, i),
47  w(IVX, k, j, i), w(IVX, k, j + 1, i));
48  }
49  } else if (pmb->block_size.nx2 > 1) {
50  for (int j = js; j <= je + 1; ++j)
51  for (int i = is; i <= ie + 1; ++i) {
52  v2f1_(ks, j, i) = interp_cp4(w(IVY, ks, j, i - 2), w(IVY, ks, j, i - 1),
53  w(IVY, ks, j, i), w(IVY, ks, j, i + 1));
54  v1f2_(ks, j, i) = interp_cp4(w(IVX, ks, j - 2, i), w(IVX, ks, j - 1, i),
55  w(IVX, ks, j, i), w(IVX, ks, j + 1, i));
56  }
57  }
58 
59  // curl, FIXME, check whether this works for other coordinates
60  for (int k = ks; k <= ke; ++k)
61  for (int j = js; j <= je; ++j) {
62  if (pmb->block_size.nx3 > 1) {
63  pcoord->Edge2Length(k, j, is, ie, x2edge_);
64  pcoord->Edge2Length(k + 1, j, is, ie, x2edge_p1_);
65  pcoord->Edge3Length(k, j, is, ie, x3edge_);
66  pcoord->Edge3Length(k, j + 1, is, ie, x3edge_p1_);
67  pcoord->VolCenterFace1Area(k, j, is, ie, x1area_);
68 
69  for (int i = is; i <= ie; ++i) {
70  data(0, k, j, i) = -(x3edge_p1_(i) * v3f2_(k, j + 1, i) -
71  x3edge_(i) * v3f2_(k, j, i) -
72  x2edge_p1_(i) * v2f3_(k + 1, j, i) +
73  x2edge_(i) * v2f3_(k, j, i)) /
74  x1area_(i);
75  }
76  }
77 
78  // curl
79  if (pmb->block_size.nx3 > 1) {
80  pcoord->Edge3Length(k, j, is, ie + 1, x3edge_);
81  pcoord->Edge1Length(k, j, is, ie, x1edge_);
82  pcoord->Edge1Length(k + 1, j, is, ie, x1edge_p1_);
83  pcoord->VolCenterFace2Area(k, j, is, ie, x2area_);
84  for (int i = is; i <= ie; ++i)
85  data(1, k, j, i) = -(x1edge_p1_(i) * v1f3_(k + 1, j, i) -
86  x1edge_(i) * v1f3_(k, j, i) -
87  x3edge_(i + 1) * v3f1_(k, j, i + 1) +
88  x3edge_(i) * v3f1_(k, j, i)) /
89  x2area_(i);
90  }
91 
92  // curl
93  if (pmb->block_size.nx2 > 1) {
94  pcoord->Edge1Length(k, j, is, ie, x1edge_);
95  pcoord->Edge1Length(k, j + 1, is, ie, x1edge_p1_);
96  pcoord->Edge2Length(k, j, is, ie + 1, x2edge_);
97  pcoord->VolCenterFace3Area(k, j, is, ie, x3area_);
98  if (pmb->block_size.nx3 > 1) { // curl is a vector
99  for (int i = is; i <= ie; ++i)
100  data(2, k, j, i) = -(x2edge_(i + 1) * v2f1_(k, j, i + 1) -
101  x2edge_(i) * v2f1_(k, j, i) -
102  x1edge_p1_(i) * v1f2_(k, j + 1, i) +
103  x1edge_(i) * v1f2_(k, j, i)) /
104  x3area_(i);
105  } else { // curl is a scalar
106  for (int i = is; i <= ie; ++i)
107  data(k, j, i) = -(x2edge_(i + 1) * v2f1_(k, j, i + 1) -
108  x2edge_(i) * v2f1_(k, j, i) -
109  x1edge_p1_(i) * v1f2_(k, j + 1, i) +
110  x1edge_(i) * v1f2_(k, j, i)) /
111  x3area_(i);
112  }
113  }
114  }
115 }
Curl(MeshBlock *pmb)
Definition: curl.cpp:5
AthenaArray< Real > v2f3_
Definition: diagnostics.hpp:86
AthenaArray< Real > v3f2_
Definition: diagnostics.hpp:86
AthenaArray< Real > v1f2_
Definition: diagnostics.hpp:86
void Finalize(AthenaArray< Real > const &w)
Definition: curl.cpp:25
AthenaArray< Real > v3f1_
Definition: diagnostics.hpp:86
AthenaArray< Real > v1f3_
Definition: diagnostics.hpp:86
AthenaArray< Real > v2f1_
Definition: diagnostics.hpp:86
std::string units
Definition: diagnostics.hpp:17
AthenaArray< Real > x3edge_p1_
Definition: diagnostics.hpp:59
AthenaArray< Real > x2edge_p1_
Definition: diagnostics.hpp:58
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
AthenaArray< Real > x1edge_
Definition: diagnostics.hpp:58
std::string type
Definition: diagnostics.hpp:16
AthenaArray< Real > data
Definition: diagnostics.hpp:19
AthenaArray< Real > x2edge_
Definition: diagnostics.hpp:58
AthenaArray< Real > x3edge_
Definition: diagnostics.hpp:58
AthenaArray< Real > x1edge_p1_
Definition: diagnostics.hpp:58
AthenaArray< Real > x2area_
Definition: diagnostics.hpp:56
MeshBlock * pmy_block_
Definition: diagnostics.hpp:44