Skip to content

Commit f02444d

Browse files
authored
add 2d spherical plm support (#2997)
add 2d spherical plm support. Mainly adds the source terms.
1 parent 8b3196a commit f02444d

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

Source/hydro/trace_plm.cpp

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Castro::trace_plm(const Box& bx, const int idir,
3333
// vbx is the valid box (no ghost cells)
3434

3535
const auto dx = geom.CellSizeArray();
36+
const auto problo = geom.ProbLoArray();
37+
const int coord = geom.Coord();
3638

3739
const int* lo_bc = phys_bc.lo();
3840
const int* hi_bc = phys_bc.hi();
@@ -43,8 +45,6 @@ Castro::trace_plm(const Box& bx, const int idir,
4345
const auto domlo = geom.Domain().loVect3d();
4446
const auto domhi = geom.Domain().hiVect3d();
4547

46-
const Real dtdx = dt/dx[idir];
47-
4848
auto vlo = vbx.loVect3d();
4949
auto vhi = vbx.hiVect3d();
5050

@@ -100,6 +100,16 @@ Castro::trace_plm(const Box& bx, const int idir,
100100
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
101101
{
102102

103+
Real dtdL = dt / dx[idir];
104+
Real dL = dx[idir];
105+
106+
// Want dt/(rdtheta) instead of dt/dtheta for 2d Spherical
107+
if (coord == 2 && idir == 1) {
108+
Real r = problo[0] + static_cast<Real>(i + 0.5_rt) * dx[0];
109+
dL = r * dx[1];
110+
dtdL = dt / dL;
111+
}
112+
103113
bool lo_bc_test = lo_symm && ((idir == 0 && i == domlo[0]) ||
104114
(idir == 1 && j == domlo[1]) ||
105115
(idir == 2 && k == domlo[2]));
@@ -166,7 +176,7 @@ Castro::trace_plm(const Box& bx, const int idir,
166176
load_stencil(srcQ, idir, i, j, k, QUN, src);
167177

168178
Real dp = dq[IEIGN_P];
169-
pslope(trho, s, src, flat, lo_bc_test, hi_bc_test, dx[idir], dp);
179+
pslope(trho, s, src, flat, lo_bc_test, hi_bc_test, dL, dp);
170180
dq[IEIGN_P] = dp;
171181

172182
}
@@ -185,7 +195,7 @@ Castro::trace_plm(const Box& bx, const int idir,
185195

186196
// construct the right state on the i interface
187197

188-
Real ref_fac = 0.5_rt*(1.0_rt + dtdx*amrex::min(e[0], 0.0_rt));
198+
Real ref_fac = 0.5_rt*(1.0_rt + dtdL*amrex::min(e[0], 0.0_rt));
189199
Real rho_ref = rho - ref_fac*dq[IEIGN_RHO];
190200
Real un_ref = un - ref_fac*dq[IEIGN_UN];
191201
Real ut_ref = ut - ref_fac*dq[IEIGN_UT];
@@ -195,8 +205,8 @@ Castro::trace_plm(const Box& bx, const int idir,
195205

196206
// this is -(1/2) ( 1 + dt/dx lambda) (l . dq) r
197207
Real trace_fac0 = 0.0_rt; // FOURTH*dtdx*(e(1) - e(1))*(1.0_rt - sign(1.0_rt, e(1)))
198-
Real trace_fac1 = 0.25_rt*dtdx*(e[0] - e[1])*(1.0_rt - std::copysign(1.0_rt, e[1]));
199-
Real trace_fac2 = 0.25_rt*dtdx*(e[0] - e[2])*(1.0_rt - std::copysign(1.0_rt, e[2]));
208+
Real trace_fac1 = 0.25_rt*dtdL*(e[0] - e[1])*(1.0_rt - std::copysign(1.0_rt, e[1]));
209+
Real trace_fac2 = 0.25_rt*dtdL*(e[0] - e[2])*(1.0_rt - std::copysign(1.0_rt, e[2]));
200210

201211
Real apright = trace_fac2*alphap;
202212
Real amright = trace_fac0*alpham;
@@ -230,16 +240,16 @@ Castro::trace_plm(const Box& bx, const int idir,
230240

231241
// now construct the left state on the i+1 interface
232242

233-
ref_fac = 0.5_rt*(1.0_rt - dtdx*amrex::max(e[2], 0.0_rt));
243+
ref_fac = 0.5_rt*(1.0_rt - dtdL*amrex::max(e[2], 0.0_rt));
234244
rho_ref = rho + ref_fac*dq[IEIGN_RHO];
235245
un_ref = un + ref_fac*dq[IEIGN_UN];
236246
ut_ref = ut + ref_fac*dq[IEIGN_UT];
237247
utt_ref = utt + ref_fac*dq[IEIGN_UTT];
238248
p_ref = p + ref_fac*dq[IEIGN_P];
239249
rhoe_ref = rhoe + ref_fac*dq[IEIGN_RE];
240250

241-
trace_fac0 = 0.25_rt*dtdx*(e[2] - e[0])*(1.0_rt + std::copysign(1.0_rt, e[0]));
242-
trace_fac1 = 0.25_rt*dtdx*(e[2] - e[1])*(1.0_rt + std::copysign(1.0_rt, e[1]));
251+
trace_fac0 = 0.25_rt*dtdL*(e[2] - e[0])*(1.0_rt + std::copysign(1.0_rt, e[0]));
252+
trace_fac1 = 0.25_rt*dtdL*(e[2] - e[1])*(1.0_rt + std::copysign(1.0_rt, e[1]));
243253
trace_fac2 = 0.0_rt; // FOURTH*dtdx*(e(3) - e(3))*(1.0_rt + sign(1.0_rt, e(3)))
244254

245255
Real apleft = trace_fac2*alphap;
@@ -301,29 +311,42 @@ Castro::trace_plm(const Box& bx, const int idir,
301311
}
302312

303313
#if (AMREX_SPACEDIM < 3)
304-
// geometry source terms -- these only apply to the x-states
305-
if (idir == 0 && dloga(i,j,k) != 0.0_rt) {
306-
Real courn = dtdx*(cc + std::abs(un));
314+
// geometry source terms
315+
// these only apply to the x-states for cylindrical and spherical
316+
// or y-states for spherical
317+
318+
if (dloga(i,j,k) != 0.0_rt) {
319+
Real courn = dtdL*(cc + std::abs(un));
307320
Real eta = (1.0_rt-courn)/(cc*dt*std::abs(dloga(i,j,k)));
308321
Real dlogatmp = amrex::min(eta, 1.0_rt)*dloga(i,j,k);
309322
Real sourcr = -0.5_rt*dt*rho*dlogatmp*un;
310323
Real sourcp = sourcr*csq;
311324
Real source = sourcp*enth;
312325

313-
if (i <= vhi[0]) {
326+
if (idir == 0 && i <= vhi[0]) {
314327
qm(i+1,j,k,QRHO) += sourcr;
315328
qm(i+1,j,k,QRHO) = amrex::max(qm(i+1,j,k,QRHO), lsmall_dens);
316329
qm(i+1,j,k,QPRES) += sourcp;
317330
qm(i+1,j,k,QREINT) += source;
318331
}
319332

320-
if (i >= vlo[0]) {
333+
if (idir == 1 && j <= vhi[1]) {
334+
qm(i,j+1,k,QRHO) += sourcr;
335+
qm(i,j+1,k,QRHO) = amrex::max(qm(i,j+1,k,QRHO), lsmall_dens);
336+
qm(i,j+1,k,QPRES) += sourcp;
337+
qm(i,j+1,k,QREINT) += source;
338+
}
339+
340+
if ((idir == 0 && i >= vlo[0]) ||
341+
(idir == 1 && j >= vlo[1])) {
321342
qp(i,j,k,QRHO) += sourcr;
322343
qp(i,j,k,QRHO) = amrex::max(qp(i,j,k,QRHO), lsmall_dens);
323344
qp(i,j,k,QPRES) += sourcp;
324345
qp(i,j,k,QREINT) += source;
325346
}
347+
326348
}
349+
327350
#endif
328351

329352
for (int ipassive = 0; ipassive < npassive; ipassive++) {
@@ -340,12 +363,12 @@ Castro::trace_plm(const Box& bx, const int idir,
340363
(idir == 1 && j >= vlo[1]) ||
341364
(idir == 2 && k >= vlo[2])) {
342365

343-
Real spzero = un >= 0.0_rt ? -1.0_rt : un*dtdx;
366+
Real spzero = un >= 0.0_rt ? -1.0_rt : un*dtdL;
344367
qp(i,j,k,n) = s[i0] + 0.5_rt*(-1.0_rt - spzero)*dX;
345368
}
346369

347370
// Left state
348-
Real spzero = un >= 0.0_rt ? un*dtdx : 1.0_rt;
371+
Real spzero = un >= 0.0_rt ? un*dtdL : 1.0_rt;
349372
Real acmpleft = 0.5_rt*(1.0_rt - spzero )*dX;
350373

351374
if (idir == 0 && i <= vhi[0]) {

0 commit comments

Comments
 (0)