2 #include <athena/athena.hpp>
3 #include <athena/coordinates/coordinates.hpp>
4 #include <athena/field/field.hpp>
5 #include <athena/hydro/hydro.hpp>
6 #include <athena/mesh/mesh.hpp>
7 #include <athena/parameter_input.hpp>
8 #include <athena/scalars/scalars.hpp>
11 #include <application/exceptions.hpp>
32 int find_task(Task
const *task_list,
int ntasks, TaskID
const &
id) {
33 for (
int i = 0; i < ntasks; ++i) {
34 if (task_list[i].task_id ==
id)
return i;
36 throw NotFoundError(
"find_task",
"Task Function");
45 itask =
find_task(task_list_, ntasks, INT_HYD);
46 task_list_[itask].TaskFunc =
50 itask =
find_task(task_list_, ntasks, SRC_TERM);
51 task_list_[itask].TaskFunc =
70 if (ORBITAL_ADVECTION) {
71 itask =
find_task(task_list_, ntasks, SEND_HYDORB);
74 itask =
find_task(task_list_, ntasks, SEND_HYD);
77 itask =
find_task(task_list_, ntasks, SETB_HYD);
81 if (pm->multilevel || SHEAR_PERIODIC) {
82 itask =
find_task(task_list_, ntasks, SEND_HYDFLX);
85 itask =
find_task(task_list_, ntasks, RECV_HYDFLX);
88 itask =
find_task(task_list_, ntasks, INT_HYD);
93 if (!ORBITAL_ADVECTION) {
94 itask =
find_task(task_list_, ntasks, SEND_SCLR);
97 itask =
find_task(task_list_, ntasks, SETB_SCLR);
104 task_list_[ntasks].task_id = id;
105 task_list_[ntasks].dependency = dep;
110 task_list_[ntasks].TaskFunc =
112 task_list_[ntasks].lb_time =
true;
114 task_list_[ntasks].TaskFunc =
116 task_list_[ntasks].lb_time =
true;
118 task_list_[ntasks].TaskFunc =
120 task_list_[ntasks].lb_time =
true;
122 throw NotFoundError(
"AddTask",
"Task ID");
129 auto ph = pmb->phydro;
130 auto pf = pmb->pfield;
131 auto phevi = pmb->pimpl->phevi;
133 if (pmb->pmy_mesh->fluid_setup != FluidFormulation::evolve)
134 return TaskStatus::next;
136 if (stage <= nstages) {
137 if (stage_wghts[stage - 1].main_stage) {
142 ave_wghts[1] = stage_wghts[stage - 1].delta;
146 pmb->WeightedAve(ph->u1, ph->u, ph->u2, ph->u0, ph->fl_div, ave_wghts);
148 ave_wghts[0] = stage_wghts[stage - 1].gamma_1;
149 ave_wghts[1] = stage_wghts[stage - 1].gamma_2;
150 ave_wghts[2] = stage_wghts[stage - 1].gamma_3;
151 if (ave_wghts[0] == 0.0 && ave_wghts[1] == 1.0 && ave_wghts[2] == 0.0)
152 ph->u.SwapAthenaArray(ph->u1);
154 pmb->WeightedAve(ph->u, ph->u1, ph->u2, ph->u0, ph->fl_div, ave_wghts);
156 const Real wght = stage_wghts[stage - 1].beta * pmb->pmy_mesh->dt;
157 pmb->pimpl->du.ZeroClear();
158 ph->AddFluxDivergence(wght, pmb->pimpl->du);
160 pmb->pcoord->AddCoordTermsDivergence(wght, ph->flux, ph->w, pf->bcc,
166 if (stage == 4 && integrator ==
"ssprk5_4") {
171 const Real beta = 0.063692468666290;
172 const Real wght_ssp = beta * pmb->pmy_mesh->dt;
174 pmb->WeightedAve(ph->u2, ph->u1, ph->u2, ph->u0, ph->fl_div, ave_wghts);
175 ph->AddFluxDivergence(wght_ssp, ph->u2);
177 pmb->pcoord->AddCoordTermsDivergence(wght_ssp, ph->flux, ph->w, pf->bcc,
181 return TaskStatus::next;
183 return TaskStatus::fail;
187 Hydro *ph = pmb->phydro;
188 Field *pf = pmb->pfield;
189 PassiveScalars *ps = pmb->pscalars;
192 if (!(ph->hsrc.hydro_sourceterms_defined) ||
193 pmb->pmy_mesh->fluid_setup != FluidFormulation::evolve)
194 return TaskStatus::next;
196 if (stage <= nstages) {
197 if (stage_wghts[stage - 1].main_stage) {
199 Real t_start_stage = pmb->pmy_mesh->time +
200 stage_wghts[(stage - 1)].sbeta * pmb->pmy_mesh->dt;
202 Real dt = (stage_wghts[(stage - 1)].beta) * (pmb->pmy_mesh->dt);
204 ph->hsrc.AddSourceTerms(t_start_stage, dt, ph->flux, ph->w, ps->r,
205 pf->bcc, pmb->pimpl->du, ps->s);
209 return TaskStatus::next;
211 return TaskStatus::fail;
215 int is = pmb->is, js = pmb->js, ks = pmb->ks;
216 int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
218 auto prad = pmb->pimpl->prad;
220 if (stage <= nstages) {
221 if (stage_wghts[stage - 1].main_stage) {
222 for (
int k = ks; k <= ke; ++k)
223 for (
int j = js;
j <= je; ++
j) {
224 prad->AddRadiativeFlux(pmb->phydro, k,
j, is, ie + 1);
227 if (stage == nstages) {
228 if (prad->GetCounter() > 0.) {
229 prad->DecrementCounter(pmb->pmy_mesh->dt);
231 prad->ResetCounter();
232 for (
int k = ks; k <= ke; ++k)
233 for (
int j = js;
j <= je; ++
j)
234 prad->CalRadiativeFlux(pmb, k,
j, is, ie + 1);
238 return TaskStatus::next;
240 return TaskStatus::fail;
244 Hydro *ph = pmb->phydro;
245 auto phevi = pmb->pimpl->phevi;
246 Real dt = pmb->pmy_mesh->dt;
248 if (stage <= nstages) {
249 if (stage_wghts[stage - 1].main_stage) {
252 if ((phevi->implicit_flag & (1 << 2)) && (pmb->ncells3 > 1)) {
253 phevi->SetDirection(X3DIR);
254 if (phevi->implicit_flag & (1 << 3))
255 phevi->FullCorrection(pmb->pimpl->du, ph->w,
256 stage_wghts[stage - 1].beta * dt);
258 phevi->PartialCorrection(pmb->pimpl->du, ph->w,
259 stage_wghts[stage - 1].beta * dt);
263 if ((phevi->implicit_flag & (1 << 1)) && (pmb->ncells2 > 1)) {
264 phevi->SetDirection(X2DIR);
265 if (phevi->implicit_flag & (1 << 3))
266 phevi->FullCorrection(pmb->pimpl->du, ph->w,
267 stage_wghts[stage - 1].beta * dt);
269 phevi->PartialCorrection(pmb->pimpl->du, ph->w,
270 stage_wghts[stage - 1].beta * dt);
274 if (phevi->implicit_flag & 1) {
275 phevi->SetDirection(X1DIR);
276 if (phevi->implicit_flag & (1 << 3))
277 phevi->FullCorrection(pmb->pimpl->du, ph->w,
278 stage_wghts[stage - 1].beta * dt);
280 phevi->PartialCorrection(pmb->pimpl->du, ph->w,
281 stage_wghts[stage - 1].beta * dt);
290 pmb->WeightedAve(ph->u, pmb->pimpl->du, ph->u2, ph->u2, ph->u2, wghts);
292 return TaskStatus::next;
294 return TaskStatus::fail;
298 if (stage <= nstages) {
299 pmb->pimpl->pmicro->SetVsedFromConserved(pmb->phydro);
301 return TaskStatus::fail;
305 if (stage != nstages)
return TaskStatus::next;
307 int is = pmb->is, js = pmb->js, ks = pmb->ks;
308 int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
312 auto pmicro = pmb->pimpl->pmicro;
314 for (
int k = ks; k <= ke; k++)
315 for (
int j = js;
j <= je;
j++) {
320 pmicro->EvolveSystems(ac, pmb->pmy_mesh->time, pmb->pmy_mesh->dt);
322 pthermo->SaturationAdjustment(ac);
327 return TaskStatus::success;
TaskStatus AddFluxToConserved(MeshBlock *pmb, int stage)
TaskStatus IntegrateHydro(MeshBlock *pmb, int stage)
TaskStatus ImplicitCorrection(MeshBlock *pmb, int stage)
ImplicitHydroTasks(ParameterInput *pin, Mesh *pm)
TaskStatus UpdateAllConserved(MeshBlock *pmb, int stage)
TaskStatus AddSourceTerms(MeshBlock *pmb, int stage)
void AddTask(TaskID const &id, TaskID const &dep) override
static Thermodynamics const * GetInstance()
Return a pointer to the one and only instance of Thermodynamics.
int find_task(Task const *task_list, int ntasks, TaskID const &id)
TaskStatus(TaskList::*)(MeshBlock *, int) TaskFunction
void distribute_to_conserved(MeshBlock *pmb, int k, int j, int i, AirParcel const &air_in)
AirParcel gather_from_conserved(MeshBlock const *pmb, int k, int j, int i)
This should track the largest task ID in the athena/task_list/task_list.hpp.
const TaskID IMPLICIT_CORR(80)
const TaskID UPDATE_ALLCONS(82)
const TaskID ADD_FLX_CONS(81)