Canoe
Comprehensive Atmosphere N' Ocean Engine
register_package.cpp
Go to the documentation of this file.
1 // Athena++ headers
2 #include "../athena.hpp"
3 #include "../debugger/debugger.hpp"
4 #include "../mesh/mesh.hpp"
5 #include "../parameter_input.hpp"
6 #include "../task_list/task_manager.hpp"
7 #include "../thermodynamics/thermodynamics.hpp"
8 #include "physics.hpp"
9 
10 using namespace PhysicsPackageNames;
11 
12 Physics::Physics(MeshBlock *pmb, ParameterInput *pin) : pmy_block(pmb) {
13  pmb->pdebug->Enter("Physics");
14  std::stringstream &msg = pmb->pdebug->msg;
15  char package_names[1024], *p;
16  std::string str = pin->GetOrAddString("physics", "packages", "");
17  std::strcpy(package_names, str.c_str());
18  p = std::strtok(package_names, " ,");
19 
20  ptm = new TaskManager<Physics>(this);
21 
22  PhysicsPackage pkg;
23  while (p != NULL) {
24  if (std::strcmp(p, "fix_bot_temperature") == 0) {
25  msg << "- use physcis fix_bot_temperature" << std::endl;
26  pkg.id = FIX_BOT_TEMPERATURE;
27  pkg.dep = 0LL;
28  pkg.conflict = 0LL;
30  ptm->AddPackage(pkg, "fix_bot_temperature");
31 
32  tau_Tbot_ = pin->GetReal("physics", "fix_bot_temperature.tau");
33  // -1 means to use the initial condition
34  Tbot_ = pin->GetOrAddReal("physics", "bot_temperature", -1);
35  if (!hydro_bot_.IsAllocated())
36  hydro_bot_.NewAthenaArray(NHYDRO, pmb->ncells3, pmb->ncells2);
37  msg << "- tau = " << tau_Tbot_ << " s" << std::endl;
38  tem_bot_.InitWithShallowSlice(hydro_bot_, 3, IDN, 1);
39  } else if (std::strcmp(p, "fix_bot_velocity") == 0) {
40  msg << "- use physcis fix_bot_velocity" << std::endl;
41  pkg.id = FIX_BOT_VELOCITY;
42  pkg.dep = 0LL;
43  pkg.conflict = 0LL;
44  // pkg.Function = &Physics::RelaxBotVelocity;
45  ptm->AddPackage(pkg, "fix_bot_velocity");
46 
47  tau_Ubot_ = pin->GetReal("physics", "fix_bot_velocity.tau");
48  if (!hydro_bot_.IsAllocated())
49  hydro_bot_.NewAthenaArray(NHYDRO, pmb->ncells3, pmb->ncells2);
50  vel_bot_.InitWithShallowSlice(hydro_bot_, 3, IVX, 3);
51  } else if (std::strcmp(p, "fix_bot_composition") == 0) {
52  msg << "- use physcis fix_bot_composition" << std::endl;
53  pkg.id = FIX_BOT_COMPOSITION;
54  pkg.dep = 0LL;
55  pkg.conflict = 0LL;
56  // pkg.Function = &Physics::RelaxBotComposition;
57  ptm->AddPackage(pkg, "fix_bot_composition");
58 
59  tau_Ubot_ = pin->GetReal("physics", "fix_bot_composition.tau");
60  if (!hydro_bot_.IsAllocated())
61  hydro_bot_.NewAthenaArray(NHYDRO, pmb->ncells3, pmb->ncells2);
62  com_bot_.InitWithShallowSlice(hydro_bot_, 3, IDN, 1 + NVAPOR);
63  } else if (std::strcmp(p, "top_sponge") == 0) {
64  msg << "- use physcis top_sponge" << std::endl;
65  pkg.id = TOP_SPONGE_LAYER;
66  pkg.dep = 0LL;
67  pkg.conflict = 0LL;
69  ptm->AddPackage(pkg, "top_sponge");
70 
71  tau_top_ = pin->GetReal("physics", "top_sponge.tau");
72  width_top_ = pin->GetReal("physics", "top_sponge.width");
73  } else if (std::strcmp(p, "bot_sponge") == 0) {
74  msg << "- use physcis bot_sponge" << std::endl;
75  pkg.id = BOT_SPONGE_LAYER;
76  pkg.dep = 0LL;
77  pkg.conflict = 0LL;
79  ptm->AddPackage(pkg, "bot_sponge");
80 
81  tau_bot_ = pin->GetReal("physics", "bot_sponge.tau");
82  width_bot_ = pin->GetReal("physics", "bot_sponge.width");
83  } else if (std::strcmp(p, "left_sponge") == 0) {
84  msg << "- use physcis left_sponge" << std::endl;
85  pkg.id = LFT_SPONGE_LAYER;
86  pkg.dep = 0LL;
87  pkg.conflict = 0LL;
89  ptm->AddPackage(pkg, "left_sponge");
90 
91  tau_left_ = pin->GetReal("physics", "left_sponge.tau");
92  width_left_ = pin->GetReal("physics", "left_sponge.width");
93  } else if (std::strcmp(p, "right_sponge") == 0) {
94  msg << "- use physcis right_sponge" << std::endl;
95  pkg.id = RHT_SPONGE_LAYER;
96  pkg.dep = 0LL;
97  pkg.conflict = 0LL;
99  ptm->AddPackage(pkg, "right_sponge");
100 
101  tau_right_ = pin->GetReal("physics", "right_sponge.tau");
102  width_right_ = pin->GetReal("physics", "right_sponge.width");
103  } else if (std::strcmp(p, "top_cooling") == 0) {
104  msg << "- use physcis top_cooling" << std::endl;
105  pkg.id = TOP_COOLING;
106  pkg.dep = 0LL;
107  pkg.conflict = 0LL;
109  ptm->AddPackage(pkg, "top_cooling");
110 
111  // dTdt_ = pin->GetReal("physics", "top_cooling.rate")/86400.; // K/day to
112  // K/s
113  flux_top_ = pin->GetReal("physics", "top_cooling.flux");
114  } else if (std::strcmp(p, "bot_heating") == 0) {
115  msg << "- use physcis bot_heating" << std::endl;
116  pkg.id = BOT_HEATING;
117  pkg.dep = 0LL;
118  pkg.conflict = 0LL;
120  ptm->AddPackage(pkg, "bot_heating");
121 
122  flux_bot_ = pin->GetReal("physics", "bot_heating.flux");
123  } else {
124  msg << "### FATAL ERROR in function Physics::Physics" << std::endl
125  << "Package '" << p << "' "
126  << "unrecognized." << std::endl;
127  ATHENA_ERROR(msg);
128  }
129  packages_.push_back(pkg);
130  p = std::strtok(NULL, " ,");
131  }
132  pmb->pdebug->Leave();
133 }
134 
136  MeshBlock *pmb = pmy_block;
137 
138  /* find top and bot neighbor
139  NeighborBlock ntop, nbot;
140  bool has_top_neighbor = false;
141  bool has_bot_neighbor = false;
142  for (int n = 0; n < pmb->pbval->nneighbor; ++n) {
143  NeighborBlock& nb = pmb->pbval->neighbor[n];
144  if ((nb.ni.ox1 == -1) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == 0)) {
145  nbot = nb;
146  has_bot_neighbor = true;
147  } if ((nb.ni.ox1 == 1) && (nb.ni.ox2 == 0) && (nb.ni.ox3 == 0)) {
148  ntop = nb;
149  has_top_neighbor = true;
150  }
151  }
152 
153  if (has_bot_neighbor)
154  ptm->RemoveTask(FIX_BOT_TEMPERATURE | FIX_BOT_VELOCITY | FIX_BOT_COMPOSITION
155  | BOT_HEATING);
156 
157  if (has_top_neighbor)
158  ptm->RemoveTask(TOP_COOLING);*/
159 
160  for (int k = pmb->ks; k <= pmb->ke; ++k)
161  for (int j = pmb->js; j <= pmb->je; ++j) {
162  if (ptm->HasTask(FIX_BOT_TEMPERATURE))
163  tem_bot_(k, j) = pmb->pthermo->GetTemp(w.at(k, j, pmb->is));
164  if (ptm->HasTask(FIX_BOT_VELOCITY)) {
165  vel_bot_(0, k, j) = w(IVX, k, j, pmb->is);
166  vel_bot_(1, k, j) = w(IVY, k, j, pmb->is);
167  vel_bot_(2, k, j) = w(IVZ, k, j, pmb->is);
168  }
169  if (ptm->HasTask(FIX_BOT_COMPOSITION))
170  for (int n = 1; n <= NVAPOR; ++n)
171  com_bot_(n, k, j) = w(n, k, j, pmb->is);
172  }
173 }
Real width_bot_
Definition: physics.hpp:78
AthenaArray< Real > com_bot_
Definition: physics.hpp:68
TaskStatus BotSpongeLayer(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
Real tau_right_
Definition: physics.hpp:83
TaskStatus RelaxBotTemperature(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
TaskStatus RightSpongeLayer(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
Real tau_left_
Definition: physics.hpp:80
MeshBlock * pmy_block
Definition: physics.hpp:24
Real tau_bot_
Definition: physics.hpp:77
TaskStatus TopCooling(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
Real width_right_
Definition: physics.hpp:84
void Initialize(AthenaArray< Real > const &w)
Real tau_Ubot_
Definition: physics.hpp:71
Real Tbot_
Definition: physics.hpp:71
Real tau_Tbot_
Definition: physics.hpp:71
AthenaArray< Real > vel_bot_
Definition: physics.hpp:68
std::vector< PhysicsPackage > packages_
Definition: physics.hpp:64
Real width_left_
Definition: physics.hpp:81
TaskStatus TopSpongeLayer(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
Real width_top_
Definition: physics.hpp:75
Real tau_top_
Definition: physics.hpp:74
Real flux_bot_
Definition: physics.hpp:89
AthenaArray< Real > tem_bot_
Definition: physics.hpp:68
TaskStatus LeftSpongeLayer(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
AthenaArray< Real > hydro_bot_
Definition: physics.hpp:67
TaskStatus BotHeating(AthenaArray< Real > &du, AthenaArray< Real > const &w, Real time, Real dt)
TaskManager< Physics > * ptm
Definition: physics.hpp:25
Real flux_top_
Definition: physics.hpp:88
Physics(MeshBlock *pmb, ParameterInput *pin)
const uint64_t RHT_SPONGE_LAYER
Definition: physics.hpp:116
const uint64_t LFT_SPONGE_LAYER
Definition: physics.hpp:115
const uint64_t BOT_HEATING
Definition: physics.hpp:118
const uint64_t FIX_BOT_TEMPERATURE
Definition: physics.hpp:110
const uint64_t BOT_SPONGE_LAYER
Definition: physics.hpp:114
const uint64_t TOP_SPONGE_LAYER
Definition: physics.hpp:113
const uint64_t FIX_BOT_COMPOSITION
Definition: physics.hpp:112
const uint64_t TOP_COOLING
Definition: physics.hpp:117
const uint64_t FIX_BOT_VELOCITY
Definition: physics.hpp:111
task to do on a meshblock
Definition: physics.hpp:96
TaskStatus(Physics::* Function)(AthenaArray< Real > &, AthenaArray< Real > const &, Real, Real)
Definition: physics.hpp:104
uint64_t conflict
encodes conflict tasks
Definition: physics.hpp:99
uint64_t dep
encodes dependencies to other tasks
Definition: physics.hpp:98
uint64_t id
encodes task using bit positions
Definition: physics.hpp:97