6 #include <athena/coordinates/coordinates.hpp>
7 #include <athena/hydro/hydro.hpp>
8 #include <athena/stride_iterator.hpp>
18 #include "../thermodynamics/thermodynamics.hpp"
23 Real grav,
int kl,
int ku,
int jl,
int ju,
25 for (
int k = kl; k <= ku; ++k)
26 for (
int j = jl;
j <= ju; ++
j)
27 for (
int i = iu; i >= il; --i)
28 psf(k,
j, i) = psf(k,
j, i + 1) + grav * w(IDN, k,
j, i) * pco->dx1f(i);
34 auto pco = pmb->pcoord;
37 Real grav = -pmb->phydro->hsrc.GetG1();
39 int is = pmb->is, ie = pmb->ie;
41 if (grav == 0.)
return;
43 std::stringstream msg;
45 msg <<
"### FATAL ERROR in function [Hydro::DecomposePressure]" << std::endl
46 <<
"number of ghost cells (NGHOST) must be at least 3" << std::endl;
56 for (
int k = kl; k <= ku; ++k)
57 for (
int j = jl;
j <= ju; ++
j) {
58 Real dz = pco->dx1f(ie);
62 pthermo->Extrapolate(&var, dz / 2.,
65 psf_(k,
j, ie + 1) = var.w[IPR];
73 for (
int k = kl; k <= ku; ++k)
74 for (
int j = jl;
j <= ju; ++
j) {
76 for (
int i = is - NGHOST; i <= ie + NGHOST; ++i) {
77 pres_(k,
j, i) = w(IPR, k,
j, i);
78 dens_(k,
j, i) = w(IDN, k,
j, i);
81 for (
int i = is; i <= ie; ++i) {
84 if (fabs(
psf_(k,
j, i) -
psf_(k,
j, i + 1)) < 1.E-6)
85 psv = (
psf_(k,
j, i) +
psf_(k,
j, i + 1)) / 2.;
89 w(IPR, k,
j, i) -= psv;
92 (pco->x1v(i + 1) - pco->x1v(i - 1)) -
97 if (pmb->pbval->block_bcs[inner_x1] != BoundaryFlag::block)
99 (pco->x1v(is + 1) - pco->x1v(is)) -
102 if (pmb->pbval->block_bcs[outer_x1] != BoundaryFlag::block)
104 (pco->x1v(ie) - pco->x1v(ie - 1)) -
151 auto pco = pmb->pcoord;
154 Real grav = -pmb->phydro->hsrc.GetG1();
155 int is = pmb->is, ie = pmb->ie;
156 if (grav == 0.)
return;
158 for (
int i = is - NGHOST; i <= ie + NGHOST; ++i) {
159 w(IPR, k,
j, i) =
pres_(k,
j, i);
160 w(IDN, k,
j, i) =
dens_(k,
j, i);
164 for (
int i = il; i <= iu; ++i) {
165 wr(IPR, i) +=
psf_(k,
j, i);
166 if (wr(IPR, i) < 0.) wr(IPR, i) =
psf_(k,
j, i);
168 wl(IPR, i + 1) +=
psf_(k,
j, i + 1);
169 if (wl(IPR, i + 1) < 0.) wl(IPR, i + 1) =
psf_(k,
j, i + 1);
171 mdpdz = (w(IPR, k,
j, i - 1) - w(IPR, k,
j, i)) /
172 (pco->x1v(i) - pco->x1v(i - 1));
173 wr(IDN, i) = (mdpdz - wr(IDN, i)) / grav;
174 if (wr(IDN, i) < 0.) wr(IDN, i) = mdpdz / grav;
176 wl(IDN, i + 1) = (mdpdz - wl(IDN, i + 1)) / grav;
177 if (wl(IDN, i + 1) < 0.) wl(IDN, i + 1) = mdpdz / grav;
181 Real dz = pco->dx1f(is);
184 air1.ToMoleFraction();
188 mdpdz = (air1.w[IPR] - air0.w[IPR]) / dz;
189 if (pmb->pbval->block_bcs[inner_x1] == BoundaryFlag::reflect) {
190 for (
int i = il + 1; i < is; ++i) {
191 wl(IDN, i) = wl(IDN, 2 * is - i);
192 wr(IDN, i) = wr(IDN, 2 * is - i);
194 wl(IDN, is) = (mdpdz - wl(IDN, is)) / grav;
195 wr(IDN, is) = (mdpdz - wr(IDN, is)) / grav;
196 }
else if (pmb->pbval->block_bcs[inner_x1] == BoundaryFlag::outflow) {
197 for (
int i = il + 1; i < is; ++i)
198 wl(IDN, i) = wr(IDN, i) = sqrt(w(IDN, k,
j, i) * w(IDN, k,
j, i - 1));
199 wl(IDN, is) = (mdpdz - wl(IDN, is)) / grav;
200 wr(IDN, is) = (mdpdz - wr(IDN, is)) / grav;
206 air1.ToMoleFraction();
210 mdpdz = (air0.w[IPR] - air1.w[IPR]) / dz;
211 if (pmb->pbval->block_bcs[outer_x1] == BoundaryFlag::reflect) {
212 for (
int i = ie + 2; i <= iu + 1; ++i) {
213 wl(IDN, i) = wl(IDN, 2 * ie - i + 2);
214 wr(IDN, i) = wr(IDN, 2 * ie - i + 2);
216 wl(IDN, ie + 1) = (mdpdz - wl(IDN, ie + 1)) / grav;
217 wr(IDN, ie + 1) = (mdpdz - wr(IDN, ie + 1)) / grav;
218 }
else if (pmb->pbval->block_bcs[outer_x1] == BoundaryFlag::outflow) {
219 for (
int i = ie + 2; i <= iu + 1; ++i)
220 wl(IDN, i) = wr(IDN, i) = sqrt(w(IDN, k,
j, i) * w(IDN, k,
j, i - 1));
221 wl(IDN, ie + 1) = (mdpdz - wl(IDN, ie + 1)) / grav;
222 wr(IDN, ie + 1) = (mdpdz - wr(IDN, ie + 1)) / grav;
void IntegrateDownwards(AthenaArray< Real > &psf, AthenaArray< Real > const &w, Coordinates *pco, Real grav, int kl, int ku, int jl, int ju, int il, int iu)
AthenaArray< Real > pres_
AthenaArray< Real > dens_
void WaitToFinishSync(AthenaArray< Real > &w, int kl, int ku, int jl, int ju)
void ApplyHydroBoundary(AthenaArray< Real > &w, AthenaArray< Real > &psf, int kl, int ku, int jl, int ju)
void RecvFromTop(AthenaArray< Real > &psf, int kl, int ku, int jl, int ju)
void SyncNewVariables(AthenaArray< Real > const &w, int kl, int ku, int jl, int ju)
void RestoreFromBuoyancy(AthenaArray< Real > &w, AthenaArray< Real > &wl, AthenaArray< Real > &wr, int k, int j, int il, int iu)
void ChangeToBuoyancy(AthenaArray< Real > &w, int kl, int ku, int jl, int ju)
void SendToBottom(AthenaArray< Real > const &psf, int kl, int ku, int jl, int ju)
static Thermodynamics const * GetInstance()
Return a pointer to the one and only instance of Thermodynamics.
AirParcel gather_from_primitive(MeshBlock const *pmb, int k, int j, int i)