Skip to content

Commit

Permalink
Mini refactoring of ComputeUpdatedPrimVarFunctor2D_MHD (and 3D).
Browse files Browse the repository at this point in the history
  • Loading branch information
pkestene committed Aug 3, 2024
1 parent b101dba commit 7e82cc1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
23 changes: 13 additions & 10 deletions src/muscl/MHDRunFunctors2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -924,12 +924,16 @@ class ComputeUpdatedPrimVarFunctor2D_MHD : public MHDBaseFunctor2D
ComputeUpdatedPrimVarFunctor2D_MHD(HydroParams params,
DataArray2d Udata,
DataArray2d Qdata,
DataArray2d Slopes_x,
DataArray2d Slopes_y,
DataArray2d Qdata2,
real_t dtdx,
real_t dtdy)
: MHDBaseFunctor2D(params)
, Udata(Udata)
, Qdata(Qdata)
, Slopes_x(Slopes_x)
, Slopes_y(Slopes_y)
, Qdata2(Qdata2)
, dtdx(dtdx)
, dtdy(dtdy){};
Expand All @@ -939,11 +943,14 @@ class ComputeUpdatedPrimVarFunctor2D_MHD : public MHDBaseFunctor2D
apply(HydroParams params,
DataArray2d Udata,
DataArray2d Qdata,
DataArray2d Slopes_x,
DataArray2d Slopes_y,
DataArray2d Qdata2,
real_t dtdx,
real_t dtdy)
{
ComputeUpdatedPrimVarFunctor2D_MHD functor(params, Udata, Qdata, Qdata2, dtdx, dtdy);
ComputeUpdatedPrimVarFunctor2D_MHD functor(
params, Udata, Qdata, Slopes_x, Slopes_y, Qdata2, dtdx, dtdy);
Kokkos::parallel_for(
"ComputeUpdatedPrimVarFunctor2D_MHD",
Kokkos::MDRangePolicy<Kokkos::Rank<2>>({ 0, 0 }, { params.isize, params.jsize }),
Expand All @@ -969,17 +976,12 @@ class ComputeUpdatedPrimVarFunctor2D_MHD : public MHDBaseFunctor2D
get_state(Qdata, i, j, q);

MHDState dq[2];
MHDState qm, qp;

// compute hydro slopes along X
get_state(Qdata, i + 1, j, qp);
get_state(Qdata, i - 1, j, qm);
slope_unsplit_hydro_2d(q, qp, qm, dq[IX]);
// retrieve hydro slopes along X
get_state(Slopes_x, i, j, dq[IX]);

// compute hydro slopes along Y
get_state(Qdata, i, j + 1, qp);
get_state(Qdata, i, j - 1, qm);
slope_unsplit_hydro_2d(q, qp, qm, dq[IY]);
// retrieve hydro slopes along Y
get_state(Slopes_y, i, j, dq[IY]);

// Cell centered values
real_t r = q[ID];
Expand Down Expand Up @@ -1042,6 +1044,7 @@ class ComputeUpdatedPrimVarFunctor2D_MHD : public MHDBaseFunctor2D
} // operator ()

DataArray2d Udata, Qdata; // input
DataArray2d Slopes_x, Slopes_y; // input
DataArray2d Qdata2; // output
real_t dtdx, dtdy;

Expand Down
32 changes: 18 additions & 14 deletions src/muscl/MHDRunFunctors3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,13 +869,19 @@ class ComputeUpdatedPrimVarFunctor3D_MHD : public MHDBaseFunctor3D
ComputeUpdatedPrimVarFunctor3D_MHD(HydroParams params,
DataArray3d Udata,
DataArray3d Qdata,
DataArray3d Slopes_x,
DataArray3d Slopes_y,
DataArray3d Slopes_z,
DataArray3d Qdata2,
real_t dtdx,
real_t dtdy,
real_t dtdz)
: MHDBaseFunctor3D(params)
, Udata(Udata)
, Qdata(Qdata)
, Slopes_x(Slopes_x)
, Slopes_y(Slopes_y)
, Slopes_z(Slopes_z)
, Qdata2(Qdata2)
, dtdx(dtdx)
, dtdy(dtdy)
Expand All @@ -886,12 +892,16 @@ class ComputeUpdatedPrimVarFunctor3D_MHD : public MHDBaseFunctor3D
apply(HydroParams params,
DataArray3d Udata,
DataArray3d Qdata,
DataArray3d Slopes_x,
DataArray3d Slopes_y,
DataArray3d Slopes_z,
DataArray3d Qdata2,
real_t dtdx,
real_t dtdy,
real_t dtdz)
{
ComputeUpdatedPrimVarFunctor3D_MHD functor(params, Udata, Qdata, Qdata2, dtdx, dtdy, dtdz);
ComputeUpdatedPrimVarFunctor3D_MHD functor(
params, Udata, Qdata, Slopes_x, Slopes_y, Slopes_z, Qdata2, dtdx, dtdy, dtdz);
Kokkos::parallel_for("ComputeUpdatedPrimVarFunctor3D_MHD",
Kokkos::MDRangePolicy<Kokkos::Rank<3>>(
{ 0, 0, 0 }, { params.isize, params.jsize, params.ksize }),
Expand Down Expand Up @@ -919,22 +929,15 @@ class ComputeUpdatedPrimVarFunctor3D_MHD : public MHDBaseFunctor3D
get_state(Qdata, i, j, k, q);

MHDState dq[3];
MHDState qm, qp;

// compute hydro slopes along X
get_state(Qdata, i + 1, j, k, qp);
get_state(Qdata, i - 1, j, k, qm);
slope_unsplit_hydro_3d(q, qp, qm, dq[IX]);
// retrieve hydro slopes along X
get_state(Slopes_x, i, j, k, dq[IX]);

// compute hydro slopes along Y
get_state(Qdata, i, j + 1, k, qp);
get_state(Qdata, i, j - 1, k, qm);
slope_unsplit_hydro_3d(q, qp, qm, dq[IY]);
// retrieve hydro slopes along Y
get_state(Slopes_y, i, j, k, dq[IY]);

// compute hydro slopes along Z
get_state(Qdata, i, j, k + 1, qp);
get_state(Qdata, i, j, k - 1, qm);
slope_unsplit_hydro_3d(q, qp, qm, dq[IZ]);
// retrieve hydro slopes along Z
get_state(Slopes_y, i, j, k, dq[IZ]);

// Cell centered values
real_t r = q[ID];
Expand Down Expand Up @@ -1012,6 +1015,7 @@ class ComputeUpdatedPrimVarFunctor3D_MHD : public MHDBaseFunctor3D
} // operator ()

DataArray3d Udata, Qdata; // input
DataArray3d Slopes_x, Slopes_y, Slopes_z; // input
DataArray3d Qdata2; // output
real_t dtdx, dtdy, dtdz;

Expand Down
6 changes: 4 additions & 2 deletions src/muscl/SolverMHDMuscl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ SolverMHDMuscl<2>::godunov_unsplit_impl(DataArray data_in, DataArray data_out, r
ComputeSlopesFunctor2D_MHD::apply(params, data_in, Q, Slopes_x, Slopes_y);

// update (cell-centered) primitive variables, perform 1/2 time step
ComputeUpdatedPrimVarFunctor2D_MHD::apply(params, data_in, Q, Q2, dtdx, dtdy);
ComputeUpdatedPrimVarFunctor2D_MHD::apply(
params, data_in, Q, Slopes_x, Slopes_y, Q2, dtdx, dtdy);

// compute electric field (v wedge B)
ComputeElecFieldFunctor2D::apply(params, data_in, Q, ElecField);
Expand Down Expand Up @@ -526,7 +527,8 @@ SolverMHDMuscl<3>::godunov_unsplit_impl(DataArray data_in, DataArray data_out, r
ComputeSlopesFunctor3D_MHD::apply(params, data_in, Q, Slopes_x, Slopes_y, Slopes_z);

// update (cell-centered) primitive variables, perform 1/2 time step
ComputeUpdatedPrimVarFunctor3D_MHD::apply(params, data_in, Q, Q2, dtdx, dtdy, dtdz);
ComputeUpdatedPrimVarFunctor3D_MHD::apply(
params, data_in, Q, Slopes_x, Slopes_y, Slopes_z, Q2, dtdx, dtdy, dtdz);

// compute electric field (v wedge B)
ComputeElecFieldFunctor3D::apply(params, data_in, Q, ElecField);
Expand Down

0 comments on commit 7e82cc1

Please sign in to comment.