Canoe
Comprehensive Atmosphere N' Ocean Engine
kessler94.cpp
Go to the documentation of this file.
1 // external
2 #include <application/application.hpp>
3 
4 // canoe
5 #include <configure.hpp>
6 
7 // snap
9 
10 // microphysics
12 
13 Kessler94::Kessler94(std::string name, YAML::Node const &node)
14  : MicrophysicalScheme<3>(name, node) {
15  Application::Logger app("microphysics");
16  app->Log("Initialize Kessler94 Scheme for " + name);
17 }
18 
20  Application::Logger app("microphysics");
21  app->Log("Destroy Kessler94 Scheme for " + GetName());
22 }
23 
25  auto pthermo = Thermodynamics::GetInstance();
26 
27  // get indices
28  int iv = GetSpeciesIndex(0);
29  int ic = GetSpeciesIndex(1);
30  int ip = GetSpeciesIndex(2);
31 
32  // get parameters
33  Real k1 = GetPar<Real>("autoconversion");
34  Real k2 = GetPar<Real>("accretion");
35  Real k3 = GetPar<Real>("evaporation");
36 
37  // calculate saturation deficit (negative means sub-saturation)
38  auto rates = pthermo->TryEquilibriumTP_VaporCloud(air, iv, 0., true);
39  Real dqv = -rates[0];
40 
41  // assemble matrix
42  rate_.setZero();
43  jacb_.setZero();
44 
45  if (dqv < 0.) { // evaporation
46  rate_(0) += -k3 * air.w[ip] * dqv;
47  rate_(2) += k3 * air.w[ip] * dqv;
48  jacb_(0, 0) += -k3 * air.w[ip];
49  jacb_(0, 2) += -k3 * dqv;
50  jacb_(2, 0) += k3 * air.w[ip];
51  jacb_(2, 2) += k3 * dqv;
52  }
53 
54  // autoconversion
55  rate_(1) += -k1 * air.w[ic];
56  rate_(2) += k1 * air.w[ic];
57  jacb_(1, 1) += -k1;
58  jacb_(2, 1) += k1;
59 
60  // accretion
61  rate_(1) += -k2 * air.w[ic] * air.w[ip];
62  rate_(2) += k2 * air.w[ic] * air.w[ip];
63  jacb_(1, 1) += -k2 * air.w[ip];
64  jacb_(1, 2) += -k2 * air.w[ic];
65  jacb_(2, 1) += k2 * air.w[ip];
66  jacb_(2, 2) += k2 * air.w[ic];
67 }
68 
69 void Kessler94::EvolveOneStep(AirParcel *air, Real time, Real dt) {
70  auto pthermo = Thermodynamics::GetInstance();
71 
72  // auto sol = solver_.solveBDF1<Base::RealVector>(rate_, jacb_, dt);
73  // auto sol = solver_.solveTRBDF2<Base::RealVector>(rate_, jacb_, dt);
75  rate_, jacb_, dt, air->w, GetSpeciesIndexArray().data());
76 
78  // 0 is a special buffer place for cloud in equilibrium with vapor at the same
79  // temperature
80  int jbuf = pthermo->GetCloudIndex(GetSpeciesIndex(0), 0);
81 
82  air->c[jbuf] += sol(0);
83  for (int n = 1; n < Size; ++n) air->w[GetSpeciesIndex(n)] += sol(n);
84 }
85 
87  Hydro const *phydro, int kl, int ku,
88  int jl, int ju, int il, int iu) {
89  int ip = GetCloudIndex(2);
90  Real vel = GetPar<Real>("sedimentation");
91 
92  for (int k = kl; k <= ku; ++k)
93  for (int j = jl; j <= ju; ++j)
94  for (int i = il; i <= iu; ++i) {
95  vsed[0](ip, k, j, i) = vel;
96  }
97 }
Real *const w
Definition: air_parcel.hpp:36
Real *const c
cloud data
Definition: air_parcel.hpp:39
T1 solveTRBDF2Blend(T2 const &Rate, T3 const &Jac, Real dt, Real const c[], int const indx[])
void AssembleReactionMatrix(AirParcel const &air, Real time) override
functions
Definition: kessler94.cpp:24
Kessler94(std::string name, YAML::Node const &node)
constructor and destructor
Definition: kessler94.cpp:13
void EvolveOneStep(AirParcel *air, Real time, Real dt) override
Evolve the air parcel one time step.
Definition: kessler94.cpp:69
void SetVsedFromConserved(AthenaArray< Real > vsed[3], Hydro const *phydro, int kl, int ku, int jl, int ju, int il, int iu) override
inbound functions
Definition: kessler94.cpp:86
ChemistrySolver< Size > solver_
chemistry solver
base class for all microphysical schemes
Eigen::Matrix< Real, D, 1 > rate_
rate and jacobian
Eigen::Matrix< Real, D, D > jacb_
Eigen::Matrix< Real, D, 1 > RealVector
std::string GetName() const
int GetSpeciesIndex(int n) const
int GetCloudIndex(int n) const
std::vector< int > const & GetSpeciesIndexArray() const
static Thermodynamics const * GetInstance()
Return a pointer to the one and only instance of Thermodynamics.