Canoe
Comprehensive Atmosphere N' Ocean Engine
coriolis_acc.cpp
Go to the documentation of this file.
1 
3 // c++ header
4 #include <sstream>
5 #include <stdexcept>
6 
7 // climath header
8 extern "C" {
9 #include <core.h>
10 }
11 
12 // debugger
13 #include <debugger.hpp>
14 
15 // Athena++ headers
16 #include <athena.hpp>
17 #include <coordinates/coordinates.hpp>
18 #include <hydro/hydro.hpp>
19 #include <hydro/srcterms/hydro_srcterms.hpp>
20 #include <mesh/mesh.hpp>
21 
23 // axial direction to conserved variables
24 void Forcing::Coriolis123(const Real dt, const AthenaArray<Real> *flx,
25  const AthenaArray<Real> &prim,
26  AthenaArray<Real> &cons) {
27  MeshBlock *pmb = pmy_hydro_->pmy_block;
28  pdebug->Enter("HydroSourceTerms::Coriolis123");
29 
30  if (omega1_ != 0.0 || omega2_ != 0.0 || omega3_ != 0.0) {
31  for (int k = pmb->ks; k <= pmb->ke; ++k) {
32 #pragma omp parallel for schedule(static)
33  for (int j = pmb->js; j <= pmb->je; ++j) {
34  for (int i = pmb->is; i <= pmb->ie; ++i) {
35  Real m1 = prim(IDN, k, j, i) * prim(IM1, k, j, i),
36  m2 = prim(IDN, k, j, i) * prim(IM2, k, j, i),
37  m3 = prim(IDN, k, j, i) * prim(IM3, k, j, i);
38  cons(IM1, k, j, i) += 2. * dt * (omega3_ * m2 - omega2_ * m3);
39  cons(IM2, k, j, i) += 2. * dt * (omega1_ * m3 - omega3_ * m1);
40  if (pmb->ke > pmb->ks) // 3d
41  cons(IM3, k, j, i) += 2. * dt * (omega2_ * m1 - omega1_ * m2);
42  }
43  }
44  }
45  }
46 
47  pdebug->Leave();
48  return;
49 }
50 
52 // cartesian coordinate to conserved variables
53 void Forcing::CoriolisXYZ(const Real dt, const AthenaArray<Real> *flx,
54  const AthenaArray<Real> &prim,
55  AthenaArray<Real> &cons) {
56  MeshBlock *pmb = pmy_hydro_->pmy_block;
57  pdebug->Enter("HydroSourceTerms::CoriolisXYZ");
58 
59  Real omega1, omega2, omega3, theta, phi;
60 
61  if (omegax_ != 0.0 || omegay_ != 0.0 || omegaz_ != 0.0) {
62  for (int k = pmb->ks; k <= pmb->ke; ++k) {
63 #pragma omp parallel for schedule(static)
64  for (int j = pmb->js; j <= pmb->je; ++j)
65  for (int i = pmb->is; i <= pmb->ie; ++i) {
66  if (strcmp(COORDINATE_SYSTEM, "cartesian") == 0) {
67  omega1 = omegaz_;
68  omega2 = omegax_;
69  omega3 = omegay_;
70  } else if (strcmp(COORDINATE_SYSTEM, "cylindrical") == 0) {
71  theta = pmb->pcoord->x2v(j);
72 
73  omega1 = cos(theta) * omegax_ + sin(theta) * omegay_;
74  omega2 = -sin(theta) * omegax_ + cos(theta) * omegay_;
75  omega3 = omegaz_;
76  } else if (strcmp(COORDINATE_SYSTEM, "spherical_polar") == 0) {
77  theta = pmb->pcoord->x2v(j);
78  phi = pmb->pcoord->x3v(k);
79 
80  omega1 = sin(theta) * cos(phi) * omegax_ +
81  sin(theta) * sin(phi) * omegay_ + cos(theta) * omegaz_;
82  omega2 = cos(theta) * cos(phi) * omegax_ +
83  cos(theta) * sin(phi) * omegay_ - sin(theta) * omegaz_;
84  omega3 = -sin(phi) * omegax_ + cos(phi) * omegay_;
85  } else {
86  std::stringstream msg;
87  msg << "### FATAL ERROR in HydroSourceTerms::CoriolisXYZ"
88  << std::endl
89  << "Unrecognized coordinate system" << std::endl;
90  ATHENA_ERROR(msg);
91  }
92 
93  Real m1 = prim(IDN, k, j, i) * prim(IM1, k, j, i),
94  m2 = prim(IDN, k, j, i) * prim(IM2, k, j, i),
95  m3 = prim(IDN, k, j, i) * prim(IM3, k, j, i);
96  cons(IM1, k, j, i) += 2. * dt * (omega3 * m2 - omega2 * m3);
97  cons(IM2, k, j, i) += 2. * dt * (omega1 * m3 - omega3 * m1);
98  cons(IM3, k, j, i) += 2. * dt * (omega2 * m1 - omega1 * m2);
99  }
100  }
101  }
102  pdebug->Leave();
103 
104  return;
105 }