Canoe
Comprehensive Atmosphere N' Ocean Engine
robert.cpp
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------------------
2  * SNAP Example Program
3  *
4  * Contributer:
5  * Cheng Li, University of Michigan
6  *
7  * Year: 2021
8  * Contact: chengcli@umich.edu
9  * Reference: Robert et al., 1992
10  * -------------------------------------------------------------------------------------
11  */
12 
13 // @sect3{Include files}
14 
15 // These input files are just like those in the @ref straka, so additional
16 // comments are not required.
17 #include <athena/athena.hpp>
18 #include <athena/athena_arrays.hpp>
19 #include <athena/coordinates/coordinates.hpp>
20 #include <athena/eos/eos.hpp>
21 #include <athena/field/field.hpp>
22 #include <athena/hydro/hydro.hpp>
23 #include <athena/mesh/mesh.hpp>
24 #include <athena/parameter_input.hpp>
25 #include <athena/stride_iterator.hpp>
26 
27 // canoe
28 #include <impl.hpp>
29 
30 // snap
32 
33 // @sect3{Preamble}
34 
35 // We only need one global variables here, the surface pressure
36 Real p0;
37 
38 // Same as that in @ref straka, make outputs of temperature and potential
39 // temperature.
40 void MeshBlock::InitUserMeshBlockData(ParameterInput *pin) {
41  AllocateUserOutputVariables(2);
42  SetUserOutputVariableName(0, "temp");
43  SetUserOutputVariableName(1, "theta");
44 }
45 
46 // Set temperature and potential temperature.
47 void MeshBlock::UserWorkBeforeOutput(ParameterInput *pin) {
48  auto pthermo = Thermodynamics::GetInstance();
49 
50  Real gamma = peos->GetGamma();
51  for (int k = ks; k <= ke; ++k)
52  for (int j = js; j <= je; ++j)
53  for (int i = is; i <= ie; ++i) {
54  user_out_var(0, k, j, i) = pthermo->GetTemp(this, k, j, i);
55  user_out_var(1, k, j, i) = pthermo->PotentialTemp(this, p0, k, j, i);
56  }
57 }
58 
59 // Initialize surface pressure from input file.
60 void Mesh::InitUserMeshData(ParameterInput *pin) {
61  p0 = pin->GetReal("problem", "p0");
62 }
63 
64 // @sect3{Initial condition}
65 
66 // We do not need forcings other than gravity in this problem,
67 // so we go directly to the initial condition.
68 void MeshBlock::ProblemGenerator(ParameterInput *pin) {
69  // Similar to @ref straka, read variables in the input file
70  Real gamma = pin->GetReal("hydro", "gamma");
71  Real grav = -phydro->hsrc.GetG1();
72  Real Ts = pin->GetReal("problem", "Ts");
73  Real Rd = pin->GetReal("thermodynamics", "Rd");
74  Real cp = gamma / (gamma - 1.) * Rd;
75 
76  Real xc = pin->GetReal("problem", "xc");
77  Real yc = pin->GetReal("problem", "yc");
78  Real zc = pin->GetReal("problem", "zc");
79  Real s = pin->GetReal("problem", "s");
80  Real a = pin->GetReal("problem", "a");
81  Real dT = pin->GetReal("problem", "dT");
82 
83  // Whether to do a uniform bubble or not.
84  bool uniform_bubble =
85  pin->GetOrAddBoolean("problem", "uniform_bubble", false);
86 
87  // Loop over the grids and set initial condition
88  for (int k = ks; k <= ke; ++k)
89  for (int j = js; j <= je; ++j)
90  for (int i = is; i <= ie; ++i) {
91  Real x1 = pcoord->x1v(i);
92  Real x2 = pcoord->x2v(j);
93  Real x3 = pcoord->x3v(k);
94  Real r = sqrt((x3 - yc) * (x3 - yc) + (x2 - xc) * (x2 - xc) +
95  (x1 - zc) * (x1 - zc));
96  Real temp = Ts - grav * x1 / cp;
97  phydro->w(IPR, k, j, i) = p0 * pow(temp / Ts, cp / Rd);
98  if (r <= a)
99  temp += dT * pow(phydro->w(IPR, k, j, i) / p0, Rd / cp);
100  else if (!uniform_bubble)
101  temp += dT * exp(-(r - a) * (r - a) / (s * s)) *
102  pow(phydro->w(IPR, k, j, i) / p0, Rd / cp);
103  phydro->w(IDN, k, j, i) = phydro->w(IPR, k, j, i) / (Rd * temp);
104  phydro->w(IVX, k, j, i) = phydro->w(IVY, k, j, i) = 0.;
105  }
106 
107  // Change primitive variables to conserved variables
108  peos->PrimitiveToConserved(phydro->w, pfield->bcc, phydro->u, pcoord, is, ie,
109  js, je, ks, ke);
110 }
static Thermodynamics const * GetInstance()
Return a pointer to the one and only instance of Thermodynamics.
float temp
Definition: fit_ammonia.py:6
Real p0
Definition: robert.cpp:36
Real Rd
Definition: straka.cpp:66
Real cp
Definition: straka.cpp:66