Canoe
Comprehensive Atmosphere N' Ocean Engine
microphysical_schemes.hpp
Go to the documentation of this file.
1 #ifndef SRC_MICROPHYSICS_MICROPHYSICAL_SCHEMES_HPP_
2 #define SRC_MICROPHYSICS_MICROPHYSICAL_SCHEMES_HPP_
3 
4 // C/C++
5 #include <map>
6 #include <memory>
7 #include <string>
8 #include <vector>
9 
10 // external
11 #include <yaml-cpp/yaml.h>
12 
13 #include <Eigen/Core>
14 #include <Eigen/Dense>
15 
16 // athena
17 #include <athena/athena.hpp>
18 #include <athena/mesh/mesh.hpp>
19 
20 // canoe
21 #include <air_parcel.hpp>
22 #include <virtual_groups.hpp>
23 
24 // microphysics
25 #include "chemistry_solver.hpp"
26 
27 class MeshBlock;
28 class ParameterInput;
29 
32  public:
33  MicrophysicalSchemeBase(std::string name) : NamedGroup(name) {}
35 
36  public:
41  virtual void AssembleReactionMatrix(AirParcel const &air, Real time) = 0;
42 
48  virtual void EvolveOneStep(AirParcel *air, Real time, Real dt) = 0;
49 
50  public:
56  Hydro const *phydro, int kl, int ku, int jl,
57  int ju, int il, int iu) = 0;
58 };
59 
60 using MicrophysicalSchemePtr = std::shared_ptr<MicrophysicalSchemeBase>;
61 using AllMicrophysicalSchemes = std::vector<MicrophysicalSchemePtr>;
62 
65  public:
66  static AllMicrophysicalSchemes Create(MeshBlock *pmb, ParameterInput *pin);
67 };
68 
70 template <int D>
72  public ParameterGroup,
73  public SpeciesIndexGroup {
74  public:
75  // needed for Eigen small matrix
76  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
77 
78  enum { Size = D };
79  using RealVector = Eigen::Matrix<Real, D, 1>;
80  using RealMatrix = Eigen::Matrix<Real, D, D>;
81 
82  public:
83  MicrophysicalScheme(std::string name, YAML::Node const &node)
84  : MicrophysicalSchemeBase(name) {
85  if (node["parameters"]) SetRealsFrom(node["parameters"]);
86 
87  if (node["dependent-species"]) {
88  auto species = node["dependent-species"].as<std::vector<std::string>>();
89  SetSpeciesIndex(species);
90  }
91  }
92 
93  virtual ~MicrophysicalScheme() {}
94 
95  public:
96  Real const *GetRatePtr() const { return rate_.data(); }
97  Real const *GetJacobianPtr() const { return jacb_.data(); }
98 
99  public:
100  void SetVsedFromConserved(AthenaArray<Real> vsed[3], Hydro const *phydro,
101  int kl, int ku, int jl, int ju, int il,
102  int iu) override {
103  for (auto n : GetCloudIndexArray())
104  for (int k = kl; k <= ku; ++k)
105  for (int j = jl; j <= ju; ++j)
106  for (int i = il; i <= iu; ++i) {
107  vsed[0](n, k, j, i) = 0.0;
108  vsed[1](n, k, j, i) = 0.0;
109  vsed[2](n, k, j, i) = 0.0;
110  }
111  }
112 
113  protected:
115  Eigen::Matrix<Real, D, 1> rate_;
116  Eigen::Matrix<Real, D, D> jacb_;
117 };
118 
120 class Kessler94 : public MicrophysicalScheme<3> {
121  public:
123  enum { Size = Base::Size };
124 
125  public:
126  Kessler94(std::string name, YAML::Node const &node);
127  ~Kessler94();
128 
129  public:
130  void AssembleReactionMatrix(AirParcel const &air, Real time) override;
131  void EvolveOneStep(AirParcel *air, Real time, Real dt) override;
132 
134  void SetVsedFromConserved(AthenaArray<Real> vsed[3], Hydro const *phydro,
135  int kl, int ku, int jl, int ju, int il,
136  int iu) override;
137 
138  protected:
141 };
142 
143 #endif // SRC_MICROPHYSICS_MICROPHYSICAL_SCHEMES_HPP_
Kessler (1994) microphysical scheme.
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
virtual base class for all microphysical schemes
virtual void AssembleReactionMatrix(AirParcel const &air, Real time)=0
Assemble the reaction matrix.
MicrophysicalSchemeBase(std::string name)
constructor and destructor
virtual void EvolveOneStep(AirParcel *air, Real time, Real dt)=0
Evolve the air parcel one time step.
virtual void SetVsedFromConserved(AthenaArray< Real > vsed[3], Hydro const *phydro, int kl, int ku, int jl, int ju, int il, int iu)=0
Set the sedimentation velocity from the conserved variables.
base class for all microphysical schemes
Real const * GetJacobianPtr() const
Eigen::Matrix< Real, D, 1 > rate_
rate and jacobian
MicrophysicalScheme(std::string name, YAML::Node const &node)
constructor and destructor
Eigen::Matrix< Real, D, D > RealMatrix
Real const * GetRatePtr() const
member functions
Eigen::Matrix< Real, D, D > jacb_
Eigen::Matrix< Real, D, 1 > RealVector
void SetVsedFromConserved(AthenaArray< Real > vsed[3], Hydro const *phydro, int kl, int ku, int jl, int ju, int il, int iu) override
inbound functions
factory class for contructing microphysical schemes
static AllMicrophysicalSchemes Create(MeshBlock *pmb, ParameterInput *pin)
void SetRealsFrom(YAML::Node const &node)
void SetSpeciesIndex(std::vector< std::string > const &species_names)
Set species index based on species names.
std::vector< int > const & GetCloudIndexArray() const
std::vector< MicrophysicalSchemePtr > AllMicrophysicalSchemes
std::shared_ptr< MicrophysicalSchemeBase > MicrophysicalSchemePtr