Canoe
Comprehensive Atmosphere N' Ocean Engine
microphysics.cpp
Go to the documentation of this file.
1 
4 // C/C++
5 #include <fstream>
6 
7 // athena
8 #include <athena/athena.hpp>
9 #include <athena/mesh/mesh.hpp>
10 #include <athena/parameter_input.hpp>
11 #include <athena/reconstruct/interpolation.hpp>
12 #include <athena/scalars/scalars.hpp>
13 
14 // application
15 #include <application/application.hpp>
16 #include <application/exceptions.hpp>
17 
18 // canoe
19 #include <air_parcel.hpp>
20 #include <configure.hpp>
21 #include <impl.hpp>
22 
23 // microphysics
25 #include "microphysics.hpp"
26 
27 const std::string Microphysics::input_key = "microphysics_config";
28 
29 Microphysics::Microphysics(MeshBlock *pmb, ParameterInput *pin)
30  : pmy_block_(pmb) {
31  if (NCLOUD == 0) return;
32 
33  Application::Logger app("microphysics");
34  app->Log("Initialize Microphysics");
35 
36  w.InitWithShallowSlice(pmb->pscalars->r, 4, 0, NCLOUD);
37  u.InitWithShallowSlice(pmb->pscalars->s, 4, 0, NCLOUD);
38 
39  int ncells1 = pmb->ncells1;
40  int ncells2 = pmb->ncells2;
41  int ncells3 = pmb->ncells3;
42 
43  // storage for sedimentation velocity at cell boundary
44  vsedf[0].NewAthenaArray(NCLOUD, ncells3, ncells2, ncells1 + 1);
45  vsedf[1].NewAthenaArray(NCLOUD, ncells3, ncells2 + 1, ncells1);
46  vsedf[2].NewAthenaArray(NCLOUD, ncells3 + 1, ncells2, ncells1);
47 
48  // storage for cloud mass flux at cell boundary
49  mass_flux[0].NewAthenaArray(NCLOUD, ncells3, ncells2, ncells1 + 1);
50  mass_flux[1].NewAthenaArray(NCLOUD, ncells3, ncells2 + 1, ncells1);
51  mass_flux[2].NewAthenaArray(NCLOUD, ncells3 + 1, ncells2, ncells1);
52 
53  // internal storage for sedimentation velocity at cell center
54  vsed_[0].NewAthenaArray(NCLOUD, ncells3, ncells2, ncells1);
55  vsed_[0].ZeroClear();
56  vsed_[1].NewAthenaArray(NCLOUD, ncells3, ncells2, ncells1);
57  vsed_[1].ZeroClear();
58  vsed_[2].NewAthenaArray(NCLOUD, ncells3, ncells2, ncells1);
59  vsed_[2].ZeroClear();
60 
61  // hydro_.NewAthenaArray(NCLOUD_HYDRO, NCLOUD, ncells3, ncells2, ncells1);
62  // hydro_.ZeroClear();
63 
65 }
66 
68  if (NCLOUD == 0) return;
69 
70  Application::Logger app("microphysics");
71  app->Log("Destroy Microphysics");
72 }
73 
74 // void Microphysics::AddFrictionalHeating(
75 // std::vector<AirParcel> &air_column) const {}
76 
77 void Microphysics::EvolveSystems(AirColumn &ac, Real time, Real dt) {
78  for (auto &system : systems_)
79  for (auto &air : ac) {
80  system->AssembleReactionMatrix(air, time);
81  system->EvolveOneStep(&air, time, dt);
82  }
83 }
84 
85 void Microphysics::SetVsedFromConserved(Hydro const *phydro) {
86  auto pmb = pmy_block_;
87 
88  int ks = pmb->ks, js = pmb->js, is = pmb->is;
89  int ke = pmb->ke, je = pmb->je, ie = pmb->ie;
90 
91  for (auto &system : systems_) {
92  system->SetVsedFromConserved(vsed_, phydro, ks, ke, js, je, is, ie);
93  }
94 
95  // interpolation to cell interface
96  for (int n = 0; n < NCLOUD; ++n)
97  for (int k = ks; k <= ke + 1; ++k)
98  for (int j = js; j <= je + 1; ++j)
99  for (int i = is; i <= ie + 1; ++i) {
100  vsedf[X1DIR](n, k, j, i) = interp_cp4(
101  vsed_[X1DIR](n, k, j, i - 2), vsed_[X1DIR](n, k, j, i - 1),
102  vsed_[X1DIR](n, k, j, i), vsed_[X1DIR](n, k, j, i + 1));
103 
104  vsedf[X2DIR](n, k, j, i) = interp_cp4(
105  vsed_[X2DIR](n, k, j - 2, i), vsed_[X2DIR](n, k, j - 1, i),
106  vsed_[X2DIR](n, k, j, i), vsed_[X2DIR](n, k, j + 1, i));
107 
108  vsedf[X3DIR](n, k, j, i) = interp_cp4(
109  vsed_[X3DIR](n, k - 2, j, i), vsed_[X3DIR](n, k - 1, j, i),
110  vsed_[X3DIR](n, k, j, i), vsed_[X3DIR](n, k + 1, j, i));
111  }
112 
113  // fix boundary condition (TODO)
114  for (int n = 0; n < NCLOUD; ++n)
115  for (int k = ks; k <= ke; ++k)
116  for (int j = js; j <= je; ++j) {
117  // no sedimentation velocity at the boundary
118  vsedf[X1DIR](n, k, j, is) = 0.;
119  vsedf[X1DIR](n, k, j, ie + 1) = 0.;
120  }
121 }
122 
123 namespace AllTasks {
124 
125 // hydro tasks should be move into hydro in the future
126 bool hydro_implicit_correction(MeshBlock *pmb, IntegrationStage stage) {
127  return true;
128 }
129 bool hydro_calculate_flux(MeshBlock *pmb, IntegrationStage stage) {
130  return true;
131 }
132 
134  IntegrationStage stage) {
135  auto scheduler = pmb->pimpl->scheduler;
136  if (!scheduler->CheckDone({hydro_implicit_correction})) return false;
137  return true;
138 }
139 
140 bool microphysics_set_mass_flux(MeshBlock *pmb, IntegrationStage stage) {
141  auto scheduler = pmb->pimpl->scheduler;
142  if (!scheduler->CheckDone({hydro_calculate_flux})) return false;
143  // Riemann Solver in hydro sets the cloud mass flux
144  // No need to do anything there
145  return true;
146 }
147 
148 bool microphysics_evolve_system(MeshBlock *pmb, IntegrationStage stage) {
149  auto scheduler = pmb->pimpl->scheduler;
150  if (!scheduler->CheckDone({hydro_implicit_correction})) return false;
151  return true;
152 }
153 
154 bool scalar_claculate_flux(MeshBlock *pmb, IntegrationStage stage) {
155  auto scheduler = pmb->pimpl->scheduler;
156  if (!scheduler->CheckDone({microphysics_set_mass_flux})) return false;
157  return true;
158 }
159 
160 } // namespace AllTasks
std::vector< AirParcel > AirColumn
Definition: air_parcel.hpp:121
static AllMicrophysicalSchemes Create(MeshBlock *pmb, ParameterInput *pin)
AthenaArray< Real > w
primitive variables: mass fraction [kg/kg]
void SetVsedFromConserved(Hydro const *phydro)
inbound functions
Microphysics(MeshBlock *pmb, ParameterInput *pin)
constructor and destructor
std::vector< std::shared_ptr< MicrophysicalSchemeBase > > systems_
pointers of microphysical systems
AthenaArray< Real > u
conserved variables: mass concentration [kg/m^3]
static const std::string input_key
microphysics input key in the input file [microphysics_config]
MeshBlock const * pmy_block_
meshblock pointer
AthenaArray< Real > vsed_[3]
sedimentation velocity at cell center [m/s]
void EvolveSystems(AirColumn &ac, Real time, Real dt)
Evolve all microphysical systems.
AthenaArray< Real > mass_flux[3]
mass flux of the dry fluid [kg/m^2/s]
AthenaArray< Real > vsedf[3]
sedimentation velocity at cell interface [m/s]
bool microphysics_set_mass_flux(MeshBlock *pmb, IntegrationStage stage)
bool hydro_calculate_flux(MeshBlock *pmb, IntegrationStage stage)
bool microphysics_evolve_system(MeshBlock *pmb, IntegrationStage stage)
bool hydro_implicit_correction(MeshBlock *pmb, IntegrationStage stage)
bool microphysics_set_sedimentaton_velocity(MeshBlock *pmb, IntegrationStage stage)
bool scalar_claculate_flux(MeshBlock *pmb, IntegrationStage stage)
std::pair< int, int > IntegrationStage
Definition: schedulers.hpp:12