From a73c96fba9f3ced9e1b4036c7601c01bfa5191a1 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Wed, 20 May 2020 15:02:49 -0400 Subject: [PATCH 01/23] port primtocons and prim_half to C++ --- Source/driver/timestep.cpp | 2 +- Source/mhd/Castro_mhd.H | 18 ++++ Source/mhd/Castro_mhd.cpp | 38 ++------ Source/mhd/Castro_mhd_F.H | 12 --- Source/mhd/Make.package | 1 + Source/mhd/ct_upwind.f90 | 168 ----------------------------------- Source/mhd/mhd_sound_speed.H | 25 ------ Source/mhd/mhd_util.H | 76 ++++++++++++++++ Source/mhd/mhd_util.cpp | 94 +++++++++++++++++++- 9 files changed, 197 insertions(+), 237 deletions(-) delete mode 100644 Source/mhd/mhd_sound_speed.H create mode 100644 Source/mhd/mhd_util.H diff --git a/Source/driver/timestep.cpp b/Source/driver/timestep.cpp index 51d7ae9e19..9251c1d776 100644 --- a/Source/driver/timestep.cpp +++ b/Source/driver/timestep.cpp @@ -6,7 +6,7 @@ #endif #ifdef MHD -#include "mhd_sound_speed.H" +#include "mhd_util.H" #endif using namespace amrex; diff --git a/Source/mhd/Castro_mhd.H b/Source/mhd/Castro_mhd.H index 215db3b804..ce0c2c95ab 100644 --- a/Source/mhd/Castro_mhd.H +++ b/Source/mhd/Castro_mhd.H @@ -12,3 +12,21 @@ amrex::Array4 const& flux1, amrex::Array4 const& flux2); + void + PrimToCons(const amrex::Box& bx, + amrex::Array4 const& q_arr, + amrex::Array4 const& u_arr); + + void + prim_half(const amrex::Box& bx, + amrex::Array4 const& q2D, + amrex::Array4 const& q_arr, + amrex::Array4 const& flxx, + amrex::Array4 const& flxy, + amrex::Array4 const& flxz, + const amrex::Real dt); + + + void + AMREX_GPU_DEVICE AMREX_FORCE_INLINE + qflux(amrex::Real* qflx, amrex::Real* flx, amrex::Real* q_zone); diff --git a/Source/mhd/Castro_mhd.cpp b/Source/mhd/Castro_mhd.cpp index fdc2908da6..4299e78dc6 100644 --- a/Source/mhd/Castro_mhd.cpp +++ b/Source/mhd/Castro_mhd.cpp @@ -338,13 +338,8 @@ Castro::just_the_mhd(Real time, Real dt) auto ux_right_arr = ux_right.array(); auto elix_ux_right = ux_right.elixir(); - PrimToCons(gbx.loVect(), gbx.hiVect(), - BL_TO_FORTRAN_ANYD(qx_left), - BL_TO_FORTRAN_ANYD(ux_left)); - - PrimToCons(gbx.loVect(), gbx.hiVect(), - BL_TO_FORTRAN_ANYD(qx_right), - BL_TO_FORTRAN_ANYD(ux_right)); + PrimToCons(gbx, qx_left_arr, ux_left_arr); + PrimToCons(gbx, qx_right_arr, ux_right_arr); uy_left.resize(gbx, NUM_STATE+3); auto uy_left_arr = uy_left.array(); @@ -354,13 +349,8 @@ Castro::just_the_mhd(Real time, Real dt) auto uy_right_arr = uy_right.array(); auto elix_uy_right = uy_right.elixir(); - PrimToCons(gbx.loVect(), gbx.hiVect(), - BL_TO_FORTRAN_ANYD(qy_left), - BL_TO_FORTRAN_ANYD(uy_left)); - - PrimToCons(gbx.loVect(), gbx.hiVect(), - BL_TO_FORTRAN_ANYD(qy_right), - BL_TO_FORTRAN_ANYD(uy_right)); + PrimToCons(gbx, qy_left_arr, uy_left_arr); + PrimToCons(gbx, qy_right_arr, uy_right_arr); uz_left.resize(gbx, NUM_STATE+3); auto uz_left_arr = uz_left.array(); @@ -370,14 +360,8 @@ Castro::just_the_mhd(Real time, Real dt) auto uz_right_arr = uz_right.array(); auto elix_uz_right = uz_right.elixir(); - PrimToCons(gbx.loVect(), gbx.hiVect(), - BL_TO_FORTRAN_ANYD(qz_left), - BL_TO_FORTRAN_ANYD(uz_left)); - - PrimToCons(gbx.loVect(), gbx.hiVect(), - BL_TO_FORTRAN_ANYD(qz_right), - BL_TO_FORTRAN_ANYD(uz_right)); - + PrimToCons(gbx, qz_left_arr, uz_left_arr); + PrimToCons(gbx, qz_right_arr, uz_right_arr); // MM CTU Step 2 // Use "1D" fluxes To interpolate Temporary Edge Centered Electric Fields, eq.36 @@ -708,14 +692,8 @@ Castro::just_the_mhd(Real time, Real dt) auto q2D_arr = q2D.array(); auto elix_q2D = q2D.elixir(); - prim_half(obx.loVect(), obx.hiVect(), - BL_TO_FORTRAN_ANYD(q2D), - BL_TO_FORTRAN_ANYD(q), - BL_TO_FORTRAN_ANYD(flxx1D), - BL_TO_FORTRAN_ANYD(flxy1D), - BL_TO_FORTRAN_ANYD(flxz1D), - dx[0], dx[1], dx[2], dt); - + prim_half(obx, q2D_arr, q_arr, + flxx1D_arr, flxy1D_arr, flxz1D_arr, dt); // Final Electric Field Update eq.48 diff --git a/Source/mhd/Castro_mhd_F.H b/Source/mhd/Castro_mhd_F.H index f4e93b4a65..e0484d706e 100644 --- a/Source/mhd/Castro_mhd_F.H +++ b/Source/mhd/Castro_mhd_F.H @@ -46,10 +46,6 @@ extern "C" BL_FORT_FAB_ARG_3D(flxx), BL_FORT_FAB_ARG_3D(flxy)); - void PrimToCons(const int lo[], const int hi[], - const BL_FORT_FAB_ARG_3D(q), - BL_FORT_FAB_ARG_3D(u)); - void corner_couple(const int lo[], const int hi[], BL_FORT_FAB_ARG_3D(qr_out), BL_FORT_FAB_ARG_3D(ql_out), @@ -74,14 +70,6 @@ extern "C" const int d, const int d1, const int d2, const Real dx, const Real dt); - void prim_half(const int lo[], const int hi[], - BL_FORT_FAB_ARG_3D(q2D), - const BL_FORT_FAB_ARG_3D(q), - const BL_FORT_FAB_ARG_3D(flxx), - const BL_FORT_FAB_ARG_3D(flxy), - const BL_FORT_FAB_ARG_3D(flxz), - const Real dx, const Real dy, const Real dz, const Real dt); - void hlld(const int lo[], const int hi[], const BL_FORT_FAB_ARG_3D(qleft), const BL_FORT_FAB_ARG_3D(qright), diff --git a/Source/mhd/Make.package b/Source/mhd/Make.package index 593856f1ef..a12e79fbd8 100644 --- a/Source/mhd/Make.package +++ b/Source/mhd/Make.package @@ -5,6 +5,7 @@ FEXE_headers += Castro_mhd_F.H CEXE_sources += Castro_mhd.cpp CEXE_sources += mhd_util.cpp +CEXE_headers += mhd_util.H ca_F90EXE_sources += flatten_mhd.F90 ca_f90EXE_sources += ct_upwind.f90 diff --git a/Source/mhd/ct_upwind.f90 b/Source/mhd/ct_upwind.f90 index c1774ee532..1acedc3460 100644 --- a/Source/mhd/ct_upwind.f90 +++ b/Source/mhd/ct_upwind.f90 @@ -7,8 +7,6 @@ module ct_upwind implicit none - private primtocons - ! note: in this module, we use left and right to mean with respect ! to the interface. So qleft, uleft, ul, ... are the left state on ! an interface and qright, uright, ur, ... are the right state on an @@ -20,62 +18,6 @@ module ct_upwind contains - subroutine PrimToCons(lo, hi, q, q_lo, q_hi, u, u_lo, u_hi) bind(C, name="PrimToCons") - - ! calculate the conserved variables from the primitive - - use amrex_fort_module, only : rt => amrex_real - use meth_params_module - use eos_type_module, only : eos_t, eos_input_rp - use eos_module, only: eos - use network, only: nspec - - implicit none - - integer, intent(in) :: lo(3), hi(3) - integer, intent(in) :: q_lo(3), q_hi(3) - integer, intent(in) :: u_lo(3), u_hi(3) - - real(rt), intent(in) :: q(q_lo(1):q_hi(1), q_lo(2):q_hi(2), q_lo(3):q_hi(3), NQ) - real(rt), intent(out) :: u(u_lo(1):u_hi(1), u_lo(2):u_hi(2), u_lo(3):u_hi(3), NVAR+3) - - integer :: i ,j ,k - - type(eos_t) :: eos_state - - do k = lo(3), hi(3) - do j = lo(2), hi(2) - do i = lo(1), hi(1) - - u(i,j,k,URHO) = q(i,j,k,QRHO) - u(i,j,k,UMX) = q(i,j,k,QRHO)*q(i,j,k,QU) - u(i,j,k,UMY) = q(i,j,k,QRHO)*q(i,j,k,QV) - u(i,j,k,UMZ) = q(i,j,k,QRHO)*q(i,j,k,QW) - - eos_state % rho = q(i, j, k, QRHO) - eos_state % p = q(i, j, k, QPRES) - eos_state % T = 100.d0 !dummy initial g. - eos_state % xn = q(i, j, k, QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - - u(i,j,k,UEDEN) = eos_state % rho * eos_state % e & - + 0.5d0*q(i,j,k,QRHO)*dot_product(q(i,j,k,QU:QW),q(i,j,k,QU:QW)) & - + 0.5d0*(dot_product(q(i,j,k,QMAGX:QMAGZ),q(i,j,k,QMAGX:QMAGZ))) - - u(i,j,k,UEINT) = eos_state % rho * eos_state % e - u(i,j,k,UTEMP) = eos_state % T - - u(i,j,k,UMAGX:UMAGZ) = q(i,j,k,QMAGX:QMAGZ) - - ! species - u(i,j,k,UFS:UFS-1+nspec) = q(i,j,k,QRHO) * q(i,j,k,QFS:QFS-1+nspec) - - enddo - enddo - enddo - end subroutine PrimToCons - subroutine ConsToPrim(q, u) @@ -587,114 +529,4 @@ subroutine half_step(w_lo, w_hi, & end subroutine - - subroutine prim_half(w_lo, w_hi, & - q2D, q2_lo, q2_hi, & - q, q_lo, q_hi, & - flxx, flxx_lo, flxx_hi, & - flxy, flxy_lo, flxy_hi, & - flxz, flxz_lo, flxz_hi, & - dx, dy, dz, dt) bind(C, name="prim_half") - - ! Find the 2D corrected primitive variables - - use amrex_fort_module, only : rt => amrex_real - use meth_params_module, only : NVAR - - implicit none - - integer, intent(in) :: w_lo(3), w_hi(3) - integer, intent(in) :: q_lo(3), q_hi(3) - integer, intent(in) :: q2_lo(3), q2_hi(3) - integer, intent(in) :: flxx_lo(3), flxx_hi(3) - integer, intent(in) :: flxy_lo(3), flxy_hi(3) - integer, intent(in) :: flxz_lo(3), flxz_hi(3) - - real(rt), intent(in) :: q(q_lo(1):q_hi(1),q_lo(2):q_hi(2),q_lo(3):q_hi(3),NQ) - real(rt), intent(in) :: flxx(flxx_lo(1):flxx_hi(1),flxx_lo(2):flxx_hi(2),flxx_lo(3):flxx_hi(3),NVAR+3) - real(rt), intent(in) :: flxy(flxy_lo(1):flxy_hi(1),flxy_lo(2):flxy_hi(2),flxy_lo(3):flxy_hi(3),NVAR+3) - real(rt), intent(in) :: flxz(flxz_lo(1):flxz_hi(1),flxz_lo(2):flxz_hi(2),flxz_lo(3):flxz_hi(3),NVAR+3) - - real(rt), intent(out) :: q2D(q2_lo(1):q2_hi(1),q2_lo(2):q2_hi(2),q2_lo(3):q2_hi(3),NQ) - - real(rt) :: divF(NVAR+3) - real(rt) :: divF_q(NQ) - real(rt), value :: dx, dy, dz, dt - - integer :: i, j, k - - do k = w_lo(3),w_hi(3) - do j = w_lo(2),w_hi(2) - do i = w_lo(1),w_hi(1) - - divF(:) = (flxx(i+1,j,k,:) - flxx(i,j,k,:)) / dx + & - (flxy(i,j+1,k,:) - flxy(i,j,k,:)) / dy + & - (flxz(i,j,k+1,:) - flxz(i,j,k,:)) / dz - - ! that is a flux of conserved variables -- transform it to primitive - call qflux(divF_q, divF, q(i,j,k,:)) - - ! Right below eq. 48 - q2D(i,j,k,:) = q(i,j,k,:) - 0.5d0*dt * divF_q - - enddo - enddo - enddo - end subroutine prim_half - - - subroutine qflux(qflx,flx,q) - - ! Calculate the C to P Jacobian applied to the fluxes - - use amrex_fort_module, only : rt => amrex_real - use meth_params_module !,only : QRHO, QU, QV, QW, QPRES, QMAGX, QMAGY, QMAGZ, QVAR, NVAR - use eos_module, only : eos - use eos_type_module, only: eos_t, eos_input_rp - use network, only : nspec - - implicit none - - ! this is step 10 in the paper, just after Eq. 48 - - ! this implements dW/dU . qflux, where dW/dU is the Jacobian of - ! the primitive quantities (W) with respect to conserved quantities (U) - - real(rt), intent(in) :: flx(NVAR+3), q(NQ) - real(rt), intent(out) :: qflx(NQ) - real(rt) :: dedp, dedrho, totalE - - type (eos_t) :: eos_state - - qflx = 0.d0 - qflx(QRHO) = flx(URHO) - qflx(QU) = ( flx(UMX) - flx(URHO) * q(QU) )/q(QRHO) - qflx(QV) = ( flx(UMY) - flx(URHO) * q(QV) )/q(QRHO) - qflx(QW) = ( flx(UMZ) - flx(URHO) * q(QW) )/q(QRHO) - - qflx(QFS:QFS+nspec-1) = ( flx(UFS:UFS+nspec-1) - flx(URHO) * q(QFS:QFS+nspec-1) )/q(QRHO) - - eos_state % rho = q(QRHO) - eos_state % p = q(QPRES) - eos_state % T = 100.d0 !dummy initial guess - eos_state % xn = q(QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - - dedrho = eos_state % dedr - eos_state % dedT * eos_state % dPdr * 1.0d0/eos_state % dPdT - dedp = eos_state % dedT * 1.0d0/eos_state % dPdT - - qflx(QPRES) = ( -q(QMAGX)*flx(UMAGX) - q(QMAGY)*flx(UMAGY) - q(QMAGZ)*flx(UMAGZ) + & - flx(UEDEN) - flx(UMX)*q(QU) - flx(UMY)*q(QV) - & - flx(UMZ)*q(QW) + flx(URHO)*(0.5*(q(QU)**2+q(QV)**2+q(QW)**2) - & - eos_state % e -q(QRHO)*dedrho) ) / ( dedp * q(QRHO)) - - qflx(QMAGX) = flx(UMAGX) - qflx(QMAGY) = flx(UMAGY) - qflx(QMAGZ) = flx(UMAGZ) - - qflx(QTEMP) = 0.0_rt - - end subroutine qflux - end module ct_upwind diff --git a/Source/mhd/mhd_sound_speed.H b/Source/mhd/mhd_sound_speed.H deleted file mode 100644 index aeeb52fc0f..0000000000 --- a/Source/mhd/mhd_sound_speed.H +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef CASTRO_MHD_SOUND_SPEED_H -#define CASTRO_MHD_SOUND_SPEED_H - -#include "Castro_util.H" - -using namespace amrex; - - -// sound speed calc for ideal MHD -void -AMREX_GPU_DEVICE AMREX_FORCE_INLINE -eos_soundspeed_mhd(Real& c, Real as, Real ca, Real bd) { - - // inputs: - // as = P_g * gam1/rho - // ca = B^2/rho - // bd = B_direction^2/rho - - // Fast Magneto-Sonic Wave - c = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*bd)); - c = std::sqrt(c); -} - - -#endif diff --git a/Source/mhd/mhd_util.H b/Source/mhd/mhd_util.H new file mode 100644 index 0000000000..b8f03c8e3c --- /dev/null +++ b/Source/mhd/mhd_util.H @@ -0,0 +1,76 @@ +#ifndef CASTRO_MHD_SOUND_SPEED_H +#define CASTRO_MHD_SOUND_SPEED_H + +#include "Castro_util.H" + +using namespace amrex; + +constexpr int UMAGX = NUM_STATE; +constexpr int UMAGY = NUM_STATE+1; +constexpr int UMAGZ = NUM_STATE+2; + +// sound speed calc for ideal MHD +void +AMREX_GPU_DEVICE AMREX_FORCE_INLINE +eos_soundspeed_mhd(Real& c, Real as, Real ca, Real bd) { + + // inputs: + // as = P_g * gam1/rho + // ca = B^2/rho + // bd = B_direction^2/rho + + // Fast Magneto-Sonic Wave + c = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*bd)); + c = std::sqrt(c); +} + +void +AMREX_GPU_DEVICE AMREX_FORCE_INLINE +Castro::qflux(Real* qflx, Real* flx, Real* q_zone) { + + // Calculate the C to P Jacobian applied to the fluxes + + // this is step 10 in the paper, just after Eq. 48 + + // this implements dW/dU . qflux, where dW/dU is the Jacobian of + // the primitive quantities (W) with respect to conserved quantities (U) + + qflx[QRHO] = flx[URHO]; + qflx[QU] = (flx[UMX] - flx[URHO] * q_zone[QU]) / q_zone[QRHO]; + qflx[QV] = (flx[UMY] - flx[URHO] * q_zone[QV]) / q_zone[QRHO]; + qflx[QW] = (flx[UMZ] - flx[URHO] * q_zone[QW]) / q_zone[QRHO]; + + for (int n = 0; n < NumSpec; n++) { + qflx[QFS+n] = (flx[UFS+n] - flx[URHO] * q_zone[QFS+n]) / q_zone[QRHO]; + } + + eos_t eos_state; + eos_state.rho = q_zone[QRHO]; + eos_state.p = q_zone[QPRES]; + eos_state.T = 100.0_rt; // dummy initial guess + for (int n = 0; n < NumSpec; n++) { + eos_state.xn[n] = q_zone[QFS+n]; + } + + eos(eos_input_rp, eos_state); + + Real dedrho = eos_state.dedr - eos_state.dedT * eos_state.dpdr * 1.0_rt / eos_state.dpdT; + Real dedp = eos_state.dedT * 1.0_rt / eos_state.dpdT; + + qflx[QPRES] = (-q_zone[QMAGX] * flx[UMAGX] - q_zone[QMAGY] * flx[UMAGY] - + q_zone[QMAGZ] * flx[UMAGZ] + flx[UEDEN] - + flx[UMX] * q_zone[QU] - flx[UMY] * q_zone[QV] - flx[UMZ] * q_zone[QW] + + flx[URHO] * (0.5_rt * (q_zone[QU] * q_zone[QU] + + q_zone[QV] * q_zone[QV] + + q_zone[QW] * q_zone[QW]) - + eos_state.e - q_zone[QRHO] * dedrho)) / + (dedp * q_zone[QRHO]); + + qflx[QMAGX] = flx[UMAGX]; + qflx[QMAGY] = flx[UMAGY]; + qflx[QMAGZ] = flx[UMAGZ]; + + qflx[QTEMP] = 0.0_rt; +} +#endif + diff --git a/Source/mhd/mhd_util.cpp b/Source/mhd/mhd_util.cpp index d4f24f2978..18c2db8ea4 100644 --- a/Source/mhd/mhd_util.cpp +++ b/Source/mhd/mhd_util.cpp @@ -3,7 +3,7 @@ #include "Castro_util.H" #include "Castro_hydro_F.H" -#include "mhd_sound_speed.H" +#include "mhd_util.H" using namespace amrex; @@ -147,3 +147,95 @@ Castro::consup_mhd(const Box& bx, }); } + + +void +Castro::PrimToCons(const Box& bx, + Array4 const& q_arr, + Array4 const& u_arr) { + + // calculate the conserved variables from the primitive + + amrex::ParallelFor(bx, + [=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) noexcept + { + + u_arr(i,j,k,URHO) = q_arr(i,j,k,QRHO); + u_arr(i,j,k,UMX) = q_arr(i,j,k,QRHO)*q_arr(i,j,k,QU); + u_arr(i,j,k,UMY) = q_arr(i,j,k,QRHO)*q_arr(i,j,k,QV); + u_arr(i,j,k,UMZ) = q_arr(i,j,k,QRHO)*q_arr(i,j,k,QW); + + eos_t eos_state; + eos_state.rho = q_arr(i,j,k,QRHO); + eos_state.p = q_arr(i,j,k,QPRES); + eos_state.T = 100.0_rt; // dummy initial T. + for (int n = 0; n < NumSpec; n++) { + eos_state.xn[n] = q_arr(i,j,k,QFS+n); + } + + eos(eos_input_rp, eos_state); + + u_arr(i,j,k,UEDEN) = eos_state.rho * eos_state.e + + + 0.5_rt * q_arr(i,j,k,QRHO) * (q_arr(i,j,k,QU) * q_arr(i,j,k,QU) + + q_arr(i,j,k,QV) * q_arr(i,j,k,QV) + + q_arr(i,j,k,QW) * q_arr(i,j,k,QW)) + + + 0.5_rt * (q_arr(i,j,k,QMAGX) * q_arr(i,j,k,QMAGX) + + q_arr(i,j,k,QMAGY) * q_arr(i,j,k,QMAGY) + + q_arr(i,j,k,QMAGZ) * q_arr(i,j,k,QMAGZ)); + + u_arr(i,j,k,UEINT) = eos_state.rho * eos_state.e; + u_arr(i,j,k,UTEMP) = eos_state.T; + + u_arr(i,j,k,UMAGX) = q_arr(i,j,k,QMAGX); + u_arr(i,j,k,UMAGY) = q_arr(i,j,k,QMAGY); + u_arr(i,j,k,UMAGZ) = q_arr(i,j,k,QMAGZ); + + // species + for (int n = 0; n < NumSpec; n++) { + u_arr(i,j,k,UFS+n) = q_arr(i,j,k,QRHO) * q_arr(i,j,k,QFS+n); + } + + }); +} + + +void +Castro::prim_half(const Box& bx, + Array4 const& q2D, + Array4 const& q_arr, + Array4 const& flxx, + Array4 const& flxy, + Array4 const& flxz, + const Real dt) { + + // Find the 2D corrected primitive variables and n+1/2 + + auto dx = geom.CellSizeArray(); + + amrex::ParallelFor(bx, + [=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) noexcept + { + + Real divF[NUM_STATE+3]; + Real divF_q[NQ]; + Real q_zone[NQ]; + + for (int n = 0; n < NUM_STATE+3; n++) { + divF[n] = (flxx(i+1,j,k,n) - flxx(i,j,k,n)) / dx[0] + + (flxy(i,j+1,k,n) - flxy(i,j,k,n)) / dx[1] + + (flxz(i,j,k+1,n) - flxz(i,j,k,n)) / dx[2]; + } + + // that is a flux of conserved variables -- transform it to primitive + for (int n = 0; n < NQ; n++) { + q_zone[n] = q_arr(i,j,k,n); + } + + qflux(divF_q, divF, q_zone); + + // Right below eq. 48 + for (int n = 0; n < NQ; n++) { + q2D(i,j,k,n) = q_arr(i,j,k,n) - 0.5_rt * dt * divF_q[n]; + } + }); +} From a63553fc2e6f12cc2b8288e1b5d5c88f1855f1ec Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Thu, 21 May 2020 19:21:35 -0400 Subject: [PATCH 02/23] we don't need NHYP in Fortran, so just define NUM_GROW in C++ --- Source/driver/Castro_F.H | 2 -- Source/driver/Castro_nd.F90 | 21 --------------------- Source/driver/Castro_setup.cpp | 8 ++++++-- Source/driver/meth_params.template | 6 ------ 4 files changed, 6 insertions(+), 31 deletions(-) diff --git a/Source/driver/Castro_F.H b/Source/driver/Castro_F.H index a81ae864b4..e2804425a0 100644 --- a/Source/driver/Castro_F.H +++ b/Source/driver/Castro_F.H @@ -33,8 +33,6 @@ extern "C" void ca_set_amr_info(const int& level, const int& iteration, const int& ncycle, const amrex::Real& time, const amrex::Real& dt); - void ca_get_method_params(int* HYP_GROW); - void runtime_pretty_print(int* jobinfo_file_name, const int* jobinfo_file_length); #ifdef PROB_PARAMS void prob_params_pretty_print(int* jobinfo_file_name, const int* jobinfo_file_length); diff --git a/Source/driver/Castro_nd.F90 b/Source/driver/Castro_nd.F90 index 3382f15afd..4ac9eced6b 100644 --- a/Source/driver/Castro_nd.F90 +++ b/Source/driver/Castro_nd.F90 @@ -212,27 +212,6 @@ subroutine ca_set_amr_info(level_in, iteration_in, ncycle_in, time_in, dt_in) & end subroutine ca_set_amr_info -! ::: -! ::: ---------------------------------------------------------------- -! ::: - - - -subroutine ca_get_method_params(nGrowHyp) bind(C, name="ca_get_method_params") - ! Passing data from f90 back to C++ - ! - ! Binds to C function `ca_get_method_params` - - use meth_params_module, only: NHYP - use amrex_fort_module, only: rt => amrex_real - - implicit none - - integer, intent(out) :: ngrowHyp - - nGrowHyp = NHYP - -end subroutine ca_get_method_params ! ::: ! ::: ---------------------------------------------------------------- diff --git a/Source/driver/Castro_setup.cpp b/Source/driver/Castro_setup.cpp index 186447db88..a031c35084 100644 --- a/Source/driver/Castro_setup.cpp +++ b/Source/driver/Castro_setup.cpp @@ -280,8 +280,12 @@ Castro::variableSetUp () const int dm = BL_SPACEDIM; - // Define NUM_GROW from the f90 module. - ca_get_method_params(&NUM_GROW); + // NUM_GROW is the number of ghost cells needed for the hyperbolic portions +#ifdef MHD + NUM_GROW = 6; +#else + NUM_GROW = 4; +#endif const Real run_strt = ParallelDescriptor::second() ; diff --git a/Source/driver/meth_params.template b/Source/driver/meth_params.template index 3a785b71a6..15d9113523 100644 --- a/Source/driver/meth_params.template +++ b/Source/driver/meth_params.template @@ -15,12 +15,6 @@ module meth_params_module implicit none - ! number of ghost cells for the hyperbolic solver - integer, parameter :: NHYP = 4 -#ifdef MHD - integer, parameter :: NMAG = 3 -#endif - #ifdef RADIATION integer, allocatable, save :: fspace_type logical, allocatable, save :: do_inelastic_scattering From ae57a16524b48c91e0bc626a8793bcd9271f9d6b Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 09:11:22 -0400 Subject: [PATCH 03/23] we need 6 ghost cells for MHD + flattening --- Source/mhd/Castro_mhd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/mhd/Castro_mhd.cpp b/Source/mhd/Castro_mhd.cpp index 45c1147b5d..e76338792c 100644 --- a/Source/mhd/Castro_mhd.cpp +++ b/Source/mhd/Castro_mhd.cpp @@ -34,7 +34,7 @@ Castro::just_the_mhd(Real time, Real dt) //} - BL_ASSERT(NUM_GROW == 4); + BL_ASSERT(NUM_GROW == 6); #ifdef _OPENMP From 1b40ecb6d1a53040b6d7a31d3fb5e4ba7bff5781 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 09:23:32 -0400 Subject: [PATCH 04/23] add comment --- Source/mhd/Castro_mhd.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/mhd/Castro_mhd.cpp b/Source/mhd/Castro_mhd.cpp index e76338792c..6cd224c1b0 100644 --- a/Source/mhd/Castro_mhd.cpp +++ b/Source/mhd/Castro_mhd.cpp @@ -202,6 +202,9 @@ Castro::just_the_mhd(Real time, Real dt) auto flatn_arr = flatn.array(); auto elix_flatn = flatn.elixir(); + // we need to compute the flattening coefficient for every zone + // center where we do reconstruction + amrex::ParallelFor(obx, [=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) noexcept { From ff1477672872ae0819514f6db6b453a9d3035461 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 10:12:23 -0400 Subject: [PATCH 05/23] add the computation of qptot for MHD --- Source/hydro/advection_util.cpp | 8 +++++++- Source/mhd/Castro_mhd.cpp | 36 ++++++++++++++++----------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Source/hydro/advection_util.cpp b/Source/hydro/advection_util.cpp index b63d78c9e1..dbaf946eb4 100644 --- a/Source/hydro/advection_util.cpp +++ b/Source/hydro/advection_util.cpp @@ -61,7 +61,6 @@ Castro::ctoprim(const Box& bx, [=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) noexcept { - #ifndef AMREX_USE_CUDA if (uin(i,j,k,URHO) <= 0.0_rt) { std::cout << std::endl; @@ -162,6 +161,13 @@ Castro::ctoprim(const Box& bx, q_arr(i,j,k,QGC) = eos_state.gam1; #endif +#ifdef MHD + q_arr(i,j,k,QPTOT) = q_arr(i,j,k,QPRES) + + 0.5_rt * (q_arr(i,j,k,QMAGX) * q_arr(i,j,k,QMAGX) + + q_arr(i,j,k,QMAGY) * q_arr(i,j,k,QMAGY) + + q_arr(i,j,k,QMAGZ) * q_arr(i,j,k,QMAGZ)); +#endif + #ifdef RADIATION qaux_arr(i,j,k,QGAMCG) = eos_state.gam1; qaux_arr(i,j,k,QCG) = eos_state.cs; diff --git a/Source/mhd/Castro_mhd.cpp b/Source/mhd/Castro_mhd.cpp index f4f1c3ab4b..c818c4a45f 100644 --- a/Source/mhd/Castro_mhd.cpp +++ b/Source/mhd/Castro_mhd.cpp @@ -198,18 +198,18 @@ Castro::just_the_mhd(Real time, Real dt) // we need to compute the flattening coefficient for every zone // center where we do reconstruction - const Box& nbi = amrex::grow(bx, IntVect(3, 3, 3)); + const Box& bxi = amrex::grow(bx, IntVect(3, 3, 3)); - flatn.resize(nbi, 1); + flatn.resize(bxi, 1); auto flatn_arr = flatn.array(); auto elix_flatn = flatn.elixir(); - flatg.resize(nbi, 1); + flatg.resize(bxi, 1); auto flatg_arr = flatg.array(); auto elix_flatg = flatg.elixir(); if (use_flattening == 0) { - amrex::ParallelFor(nbi, + amrex::ParallelFor(bxi, [=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) noexcept { flatn_arr(i,j,k) = 0.0; @@ -230,35 +230,35 @@ Castro::just_the_mhd(Real time, Real dt) // Interpolate Cell centered values to faces qleft[0].resize(bx_gc, NQ); - auto qx_left_arr = qx_left.array(); - auto elix_qx_left = qx_left.elixir(); + auto qx_left_arr = qleft[0].array(); + auto elix_qx_left = qleft[0].elixir(); - qxright[0].resize(bx_gc, NQ); - auto qx_right_arr = qx_right.array(); - auto elix_qx_right = qx_right.elixir(); + qright[0].resize(bx_gc, NQ); + auto qx_right_arr = qright[0].array(); + auto elix_qx_right = qright[0].elixir(); qleft[1].resize(bx_gc, NQ); - auto qy_left_arr = qy_left.array(); - auto elix_qy_left = qy_left.elixir(); + auto qy_left_arr = qleft[1].array(); + auto elix_qy_left = qleft[1].elixir(); qright[1].resize(bx_gc, NQ); - auto qy_right_arr = qy_right.array(); - auto elix_qy_right = qy_right.elixir(); + auto qy_right_arr = qright[1].array(); + auto elix_qy_right = qright[1].elixir(); qleft[2].resize(bx_gc, NQ); - auto qz_left_arr = qz_left.array(); - auto elix_qz_left = qz_left.elixir(); + auto qz_left_arr = qleft[2].array(); + auto elix_qz_left = qleft[2].elixir(); qright[2].resize(bx_gc, NQ); - auto qz_right_arr = qz_right.array(); - auto elix_qz_right = qz_right.elixir(); + auto qz_right_arr = qright[2].array(); + auto elix_qz_right = qright[2].elixir(); for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { const int idir_f = idir + 1; - plm(nbi.loVect(), nbi.hiVect(), idir_f, + plm(bxi.loVect(), bxi.hiVect(), idir_f, BL_TO_FORTRAN_ANYD(q), BL_TO_FORTRAN_ANYD(qaux), BL_TO_FORTRAN_ANYD(flatn), From 57671d9994a50b298dfb02844b01376a70d80ffa Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 11:07:37 -0400 Subject: [PATCH 06/23] don't let any coarse grid have < NUM_GROW cells --- Exec/mhd_tests/Alfven/inputs-sod-x | 4 ++-- Exec/mhd_tests/BrioWu/inputs-briowu-x | 6 +++--- Exec/mhd_tests/BrioWu/inputs-briowu-y | 6 +++--- Exec/mhd_tests/BrioWu/inputs-briowu-z | 6 +++--- Exec/mhd_tests/BrioWu/inputs-sod-x | 4 ++-- Exec/mhd_tests/BrioWu/inputs-sod-x-inv | 4 ++-- Exec/mhd_tests/BrioWu/inputs-sod-y | 4 ++-- Exec/mhd_tests/BrioWu/inputs-sod-z | 4 ++-- Exec/mhd_tests/BrioWu/inputs.briowu.test | 8 ++++---- Exec/mhd_tests/DaiWoodward/inputs | 6 +++--- Exec/mhd_tests/FastRarefaction/inputs | 6 +++--- Exec/mhd_tests/OrszagTang/inputs | 4 ++-- Exec/mhd_tests/OrszagTang/inputs.test | 4 ++-- Exec/mhd_tests/RT/inputs_3d | 6 +++--- Source/mhd/Castro_mhd.cpp | 11 ++++++++++- 15 files changed, 46 insertions(+), 37 deletions(-) diff --git a/Exec/mhd_tests/Alfven/inputs-sod-x b/Exec/mhd_tests/Alfven/inputs-sod-x index 4f7f5e38cf..372556dd84 100644 --- a/Exec/mhd_tests/Alfven/inputs-sod-x +++ b/Exec/mhd_tests/Alfven/inputs-sod-x @@ -6,8 +6,8 @@ stop_time = 0.1 geometry.is_periodic = 1 1 1 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical geometry.prob_lo = 0 0 0 -geometry.prob_hi = 1 0.0625 0.0625 #0.015625 0.015625 -amr.n_cell = 64 4 4 +geometry.prob_hi = 1 0.125 0.125 #0.015625 0.015625 +amr.n_cell = 64 8 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/BrioWu/inputs-briowu-x b/Exec/mhd_tests/BrioWu/inputs-briowu-x index fd40b5c314..de11cb083c 100644 --- a/Exec/mhd_tests/BrioWu/inputs-briowu-x +++ b/Exec/mhd_tests/BrioWu/inputs-briowu-x @@ -5,9 +5,9 @@ stop_time = 0.1 # PROBLEM SIZE & GEOMETRY geometry.is_periodic = 0 1 1 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical -geometry.prob_lo = 0 0 0 -geometry.prob_hi = 1 0.015625 0.015625 -amr.n_cell = 256 4 4 +geometry.prob_lo = 0 0 0 +geometry.prob_hi = 1 0.03125 0.03125 +amr.n_cell = 256 8 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/BrioWu/inputs-briowu-y b/Exec/mhd_tests/BrioWu/inputs-briowu-y index c296822fd1..98b1e2ad9d 100644 --- a/Exec/mhd_tests/BrioWu/inputs-briowu-y +++ b/Exec/mhd_tests/BrioWu/inputs-briowu-y @@ -5,9 +5,9 @@ stop_time = 0.1 # PROBLEM SIZE & GEOMETRY geometry.is_periodic = 1 0 1 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical -geometry.prob_lo = 0 0 0 -geometry.prob_hi = 0.015625 1 0.015625 -amr.n_cell = 4 256 4 +geometry.prob_lo = 0 0 0 +geometry.prob_hi = 0.03125 1 0.03125 +amr.n_cell = 8 256 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/BrioWu/inputs-briowu-z b/Exec/mhd_tests/BrioWu/inputs-briowu-z index 8a85654b92..1eef619887 100644 --- a/Exec/mhd_tests/BrioWu/inputs-briowu-z +++ b/Exec/mhd_tests/BrioWu/inputs-briowu-z @@ -5,9 +5,9 @@ stop_time = 0.1 # PROBLEM SIZE & GEOMETRY geometry.is_periodic = 1 1 0 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical -geometry.prob_lo = 0 0 0 -geometry.prob_hi = 0.015625 0.015625 1. -amr.n_cell = 4 4 256 +geometry.prob_lo = 0 0 0 +geometry.prob_hi = 0.03125 0.03125 1. +amr.n_cell = 8 8 256 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/BrioWu/inputs-sod-x b/Exec/mhd_tests/BrioWu/inputs-sod-x index 5dd365f4ec..ef74238e59 100644 --- a/Exec/mhd_tests/BrioWu/inputs-sod-x +++ b/Exec/mhd_tests/BrioWu/inputs-sod-x @@ -6,8 +6,8 @@ stop_time = 0.2 geometry.is_periodic = 0 0 0 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical geometry.prob_lo = 0 0 0 -geometry.prob_hi = 1 0.125 0.125 -amr.n_cell = 32 4 4 +geometry.prob_hi = 1 0.25 0.25 +amr.n_cell = 32 8 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/BrioWu/inputs-sod-x-inv b/Exec/mhd_tests/BrioWu/inputs-sod-x-inv index 69e25460b4..bbe683ee50 100644 --- a/Exec/mhd_tests/BrioWu/inputs-sod-x-inv +++ b/Exec/mhd_tests/BrioWu/inputs-sod-x-inv @@ -6,8 +6,8 @@ stop_time = 0.2 geometry.is_periodic = 0 0 0 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical geometry.prob_lo = 0 0 0 -geometry.prob_hi = 1 0.125 0.125 -amr.n_cell = 32 4 4 +geometry.prob_hi = 1 0.25 0.25 +amr.n_cell = 32 8 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/BrioWu/inputs-sod-y b/Exec/mhd_tests/BrioWu/inputs-sod-y index 94082ff764..976c21655f 100644 --- a/Exec/mhd_tests/BrioWu/inputs-sod-y +++ b/Exec/mhd_tests/BrioWu/inputs-sod-y @@ -6,8 +6,8 @@ stop_time = 0.2 geometry.is_periodic = 0 0 0 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical geometry.prob_lo = 0 0 0 -geometry.prob_hi = 0.125 1 0.125 -amr.n_cell = 4 32 4 +geometry.prob_hi = 0.25 1 0.25 +amr.n_cell = 8 32 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/BrioWu/inputs-sod-z b/Exec/mhd_tests/BrioWu/inputs-sod-z index 04d33f754d..d912dd9219 100644 --- a/Exec/mhd_tests/BrioWu/inputs-sod-z +++ b/Exec/mhd_tests/BrioWu/inputs-sod-z @@ -6,8 +6,8 @@ stop_time = 0.2 geometry.is_periodic = 0 0 0 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical geometry.prob_lo = 0 0 0 -geometry.prob_hi = 0.125 0.125 1. -amr.n_cell = 4 4 32 +geometry.prob_hi = 0.25 0.25 1. +amr.n_cell = 8 8 32 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/BrioWu/inputs.briowu.test b/Exec/mhd_tests/BrioWu/inputs.briowu.test index 58ab13e0d6..19d81eb6ba 100644 --- a/Exec/mhd_tests/BrioWu/inputs.briowu.test +++ b/Exec/mhd_tests/BrioWu/inputs.briowu.test @@ -5,9 +5,9 @@ stop_time = 0.1 # PROBLEM SIZE & GEOMETRY geometry.is_periodic = 0 1 1 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical -geometry.prob_lo = 0 0 0 -geometry.prob_hi = 1 0.015625 0.015625 -amr.n_cell = 256 4 4 +geometry.prob_lo = 0 0 0 +geometry.prob_hi = 1 0.03125 0.03125 +amr.n_cell = 256 8 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry @@ -44,7 +44,7 @@ amr.v = 1 # verbosity in Amr.cpp amr.max_level = 0 # maximum level number allowed amr.ref_ratio = 2 2 2 2 # refinement ratio amr.regrid_int = 2 2 2 2 # how often to regrid -amr.blocking_factor = 4 # block factor in grid generation +amr.blocking_factor = 8 # block factor in grid generation amr.max_grid_size = 64 amr.n_error_buf = 2 2 2 2 # number of buffer cells in error est diff --git a/Exec/mhd_tests/DaiWoodward/inputs b/Exec/mhd_tests/DaiWoodward/inputs index 40040d4730..320da8fcea 100644 --- a/Exec/mhd_tests/DaiWoodward/inputs +++ b/Exec/mhd_tests/DaiWoodward/inputs @@ -5,9 +5,9 @@ stop_time = 0.2 # PROBLEM SIZE & GEOMETRY geometry.is_periodic = 0 1 1 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical -geometry.prob_lo = 0 0 0 -geometry.prob_hi = 1 0.015625 0.015625 -amr.n_cell = 256 4 4 +geometry.prob_lo = 0 0 0 +geometry.prob_hi = 1 0.03125 0.03125 +amr.n_cell = 256 8 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/FastRarefaction/inputs b/Exec/mhd_tests/FastRarefaction/inputs index 9ed5a0a36c..d5ed556f5c 100644 --- a/Exec/mhd_tests/FastRarefaction/inputs +++ b/Exec/mhd_tests/FastRarefaction/inputs @@ -5,9 +5,9 @@ stop_time = 0.1 # PROBLEM SIZE & GEOMETRY geometry.is_periodic = 0 1 1 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical -geometry.prob_lo = 0 0 0 -geometry.prob_hi = 1 0.015625 0.015625 -amr.n_cell = 256 4 4 +geometry.prob_lo = 0 0 0 +geometry.prob_hi = 1 0.03125 0.03125 +amr.n_cell = 256 8 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/OrszagTang/inputs b/Exec/mhd_tests/OrszagTang/inputs index 92b1dc75d7..419d138273 100644 --- a/Exec/mhd_tests/OrszagTang/inputs +++ b/Exec/mhd_tests/OrszagTang/inputs @@ -6,8 +6,8 @@ stop_time = 0.5 geometry.is_periodic = 1 1 1 geometry.coord_sys = 0 # 0 => cart geometry.prob_lo = 0 0 0 -geometry.prob_hi = 1 1 0.02 -amr.n_cell = 200 200 4 +geometry.prob_hi = 1 1 0.04 +amr.n_cell = 200 200 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/OrszagTang/inputs.test b/Exec/mhd_tests/OrszagTang/inputs.test index a1a2223fe2..50c83283f8 100644 --- a/Exec/mhd_tests/OrszagTang/inputs.test +++ b/Exec/mhd_tests/OrszagTang/inputs.test @@ -6,8 +6,8 @@ stop_time = 0.5 geometry.is_periodic = 1 1 1 geometry.coord_sys = 0 # 0 => cart geometry.prob_lo = 0 0 0 -geometry.prob_hi = 1 1 0.02 -amr.n_cell = 200 200 4 +geometry.prob_hi = 1 1 0.04 +amr.n_cell = 200 200 8 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Exec/mhd_tests/RT/inputs_3d b/Exec/mhd_tests/RT/inputs_3d index 256bf32931..831db78e19 100644 --- a/Exec/mhd_tests/RT/inputs_3d +++ b/Exec/mhd_tests/RT/inputs_3d @@ -5,12 +5,12 @@ stop_time = 2.5 # PROBLEM SIZE & GEOMETRY geometry.is_periodic = 1 1 0 geometry.coord_sys = 0 # 0 => cart, 1 => RZ 2=>spherical -geometry.prob_lo = 0 0 0 -geometry.prob_hi = 0.5 0.015625 1.0 +geometry.prob_lo = 0 0 0 +geometry.prob_hi = 0.5 0.03125 1.0 # use with single level #amr.n_cell = 256 256 512 # use with 1 level of refinement -amr.n_cell = 128 4 256 +amr.n_cell = 128 8 256 # >>>>>>>>>>>>> BC FLAGS <<<<<<<<<<<<<<<< # 0 = Interior 3 = Symmetry diff --git a/Source/mhd/Castro_mhd.cpp b/Source/mhd/Castro_mhd.cpp index e76338792c..f375251328 100644 --- a/Source/mhd/Castro_mhd.cpp +++ b/Source/mhd/Castro_mhd.cpp @@ -1,6 +1,6 @@ #include "Castro.H" #include "Castro_F.H" - +#include using namespace amrex; void @@ -185,6 +185,14 @@ Castro::just_the_mhd(Real time, Real dt) const int* hi_gc = bx_gc.hiVect(); + std::cout << "working on ctoprim" << std::endl; + std::cout << "u_arr: " << Sborder.nGrow() << std::endl; + std::cout << "NUM_GROW = " << NUM_GROW << std::endl; + //std::cout << "q = " << q.nGrow() << std::endl; + std::cout << "bx_gc = " << bx_gc << std::endl; + + //std::cout << "q_arr ng = " << q.ngrow << std::endl; + ctoprim(bx_gc, time, u_arr, Bx_arr, By_arr, Bz_arr, @@ -705,3 +713,4 @@ Castro::just_the_mhd(Real time, Real dt) } } + From e5ec8f46b11798d64a86bc471ac61316e98fdda8 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 11:40:16 -0400 Subject: [PATCH 07/23] remove debugging prints --- Source/mhd/Castro_mhd.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Source/mhd/Castro_mhd.cpp b/Source/mhd/Castro_mhd.cpp index f375251328..7520e9b063 100644 --- a/Source/mhd/Castro_mhd.cpp +++ b/Source/mhd/Castro_mhd.cpp @@ -184,15 +184,6 @@ Castro::just_the_mhd(Real time, Real dt) const int* lo_gc = bx_gc.loVect(); const int* hi_gc = bx_gc.hiVect(); - - std::cout << "working on ctoprim" << std::endl; - std::cout << "u_arr: " << Sborder.nGrow() << std::endl; - std::cout << "NUM_GROW = " << NUM_GROW << std::endl; - //std::cout << "q = " << q.nGrow() << std::endl; - std::cout << "bx_gc = " << bx_gc << std::endl; - - //std::cout << "q_arr ng = " << q.ngrow << std::endl; - ctoprim(bx_gc, time, u_arr, Bx_arr, By_arr, Bz_arr, From 6e9b1cfeac4800f1435faa37e3d75236e1c3e75f Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 12:01:53 -0400 Subject: [PATCH 08/23] remove old headers --- Source/mhd/Castro_mhd_F.H | 47 --------------------------------------- 1 file changed, 47 deletions(-) diff --git a/Source/mhd/Castro_mhd_F.H b/Source/mhd/Castro_mhd_F.H index e0484d706e..e781a29616 100644 --- a/Source/mhd/Castro_mhd_F.H +++ b/Source/mhd/Castro_mhd_F.H @@ -9,11 +9,6 @@ extern "C" { #endif - void mhd_flatten - (const int lo[], const int hi[], - const BL_FORT_FAB_ARG_3D(q), - BL_FORT_FAB_ARG_3D(flatn)); - void plm (const int lo[], const int hi[], const int idir, @@ -28,48 +23,6 @@ extern "C" const BL_FORT_FAB_ARG_3D(srcq), const amrex::Real dx[], const amrex::Real dt); - void electric_edge_x(const int lo[], const int hi[], - const BL_FORT_FAB_ARG_3D(q), - BL_FORT_FAB_ARG_3D(E), - BL_FORT_FAB_ARG_3D(flxy), - BL_FORT_FAB_ARG_3D(flxz)); - - void electric_edge_y(const int lo[], const int hi[], - const BL_FORT_FAB_ARG_3D(q), - BL_FORT_FAB_ARG_3D(E), - BL_FORT_FAB_ARG_3D(flxx), - BL_FORT_FAB_ARG_3D(flxz)); - - void electric_edge_z(const int lo[], const int hi[], - const BL_FORT_FAB_ARG_3D(q), - BL_FORT_FAB_ARG_3D(E), - BL_FORT_FAB_ARG_3D(flxx), - BL_FORT_FAB_ARG_3D(flxy)); - - void corner_couple(const int lo[], const int hi[], - BL_FORT_FAB_ARG_3D(qr_out), - BL_FORT_FAB_ARG_3D(ql_out), - const BL_FORT_FAB_ARG_3D(ur), - const BL_FORT_FAB_ARG_3D(ul), - const BL_FORT_FAB_ARG_3D(flxd2), - const BL_FORT_FAB_ARG_3D(Ed1), - const BL_FORT_FAB_ARG_3D(Ed3), - const int d1, const int d2, const int d3, - const Real dx, const Real dt); - - void half_step(const int lo[], const int hi[], - BL_FORT_FAB_ARG_3D(qr_out), - BL_FORT_FAB_ARG_3D(ql_out), - const BL_FORT_FAB_ARG_3D(ur), - const BL_FORT_FAB_ARG_3D(ul), - const BL_FORT_FAB_ARG_3D(flxd1), - const BL_FORT_FAB_ARG_3D(flxd2), - const BL_FORT_FAB_ARG_3D(Ed), - const BL_FORT_FAB_ARG_3D(Ed1), - const BL_FORT_FAB_ARG_3D(Ed2), - const int d, const int d1, const int d2, - const Real dx, const Real dt); - void hlld(const int lo[], const int hi[], const BL_FORT_FAB_ARG_3D(qleft), const BL_FORT_FAB_ARG_3D(qright), From 41a769bc3fe1f67c98fea0220331509cb30db95e Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 12:50:19 -0400 Subject: [PATCH 09/23] start working on the PLM conversion --- Source/mhd/Make.package | 3 +- Source/mhd/mhd_plm.cpp | 741 ++++++++++++++++++++++++++++++++++++++++ Source/mhd/mhd_util.H | 12 + 3 files changed, 755 insertions(+), 1 deletion(-) create mode 100644 Source/mhd/mhd_plm.cpp diff --git a/Source/mhd/Make.package b/Source/mhd/Make.package index ad5121736f..3fa85e970b 100644 --- a/Source/mhd/Make.package +++ b/Source/mhd/Make.package @@ -9,6 +9,7 @@ CEXE_headers += mhd_util.H CEXE_sources += ct_upwind.cpp CEXE_sources += electric.cpp +CEXE_sources += mhd_plm.cpp + ca_f90EXE_sources += hlld.f90 -ca_f90EXE_sources += mhd_plm_3d.f90 ca_F90EXE_sources += mhd_state.F90 diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp new file mode 100644 index 0000000000..f875af528d --- /dev/null +++ b/Source/mhd/mhd_plm.cpp @@ -0,0 +1,741 @@ + +void +Castro::plm(const Box& bx, + const int idir, + Array4 const& s, + Array4 const& qaux, + Array4 const& flatn, + Array4 const& bx, + Array4 const& by, + Array4 const& bz, + Array4 const& qleft, + Array4 const& qright, + Array4 const& srcQ, + const Real dt) { + + // these loops are over cell-centers and for each cell-center, we find the left and + // right interface states + + const auto dx = geom.CellSizeArray(); + + Real dtdx = dt/dx[idir]; + + amrex::ParallelFor(bx, + [=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) noexcept + { + + // compute the 1-sided differences used for the slopes + + Real dQL[NEIGN]; + Real dQR[NEIGN]; + + // we use a reduced eigensystem, the normal B field component is + // omitted + + if (idir == 0) { + + // component (Bx) is omitted + + dQL[IEIGN_RHO] = s(i,j,k,QRHO) - s(i-1,j,k,QRHO); + dQL[IEIGN_U] = s(i,j,k,QU) - s(i-1,j,k,QU); + dQL[IEIGN_V] = s(i,j,k,QV) - s(i-1,j,k,QV); + dQL[IEIGN_W] = s(i,j,k,QW) - s(i-1,j,k,QW); + dQL[IEIGN_P] = s(i,j,k,QPRES) - s(i-1,j,k,QPRES); + dQL[IEIGN_BT] = s(i,j,k,QMAGY) - s(i-1,j,k,QMAGY); + dQL[IEIGN_BTT] = s(i,j,k,QMAGZ) - s(i-1,j,k,QMAGZ); + + dQR[IEIGN_RHO] = s(i+1,j,k,QRHO) - s(i,j,k,QRHO); + dQR[IEIGN_U] = s(i+1,j,k,QU) - s(i,j,k,QU); + dQR[IEIGN_V] = s(i+1,j,k,QV) - s(i,j,k,QV); + dQR[IEIGN_W] = s(i+1,j,k,QW) - s(i,j,k,QW); + dQR[IEIGN_P] = s(i+1,j,k,QPRES) - s(i,j,k,QPRES); + dQR[IEIGN_BT] = s(i+1,j,k,QMAGY) - s(i,j,k,QMAGY); + dQR[IEIGN_BTT] = s(i+1,j,k,QMAGZ) - s(i,j,k,QMAGZ); + + } else if (idir == 1) { + + // component (By) is omitted + + dQL[IEIGN_RHO] = s(i,j,k,QRHO) - s(i,j-1,k,QRHO); + dQL[IEIGN_U] = s(i,j,k,QU) - s(i,j-1,k,QU); + dQL[IEIGN_V] = s(i,j,k,QV) - s(i,j-1,k,QV); + dQL[IEIGN_W] = s(i,j,k,QW) - s(i,j-1,k,QW); + dQL[IEIGN_P] = s(i,j,k,QPRES) - s(i,j-1,k,QPRES); + dQL[IEIGN_BT] = s(i,j,k,QMAGX) - s(i,j-1,k,QMAGX); + dQL[IEIGN_BTT] = s(i,j,k,QMAGZ) - s(i,j-1,k,QMAGZ); + + dQR[IEIGN_RHO] = s(i,j+1,k,QRHO) - s(i,j,k,QRHO); + dQR[IEIGN_U] = s(i,j+1,k,QU) - s(i,j,k,QU); + dQR[IEIGN_V] = s(i,j+1,k,QV) - s(i,j,k,QV); + dQR[IEIGN_W] = s(i,j+1,k,QW) - s(i,j,k,QW); + dQR[IEIGN_P] = s(i,j+1,k,QPRES) - s(i,j,k,QPRES); + dQR[IEIGN_BT] = s(i,j+1,k,QMAGX) - s(i,j,k,QMAGX); + dQR[IEIGN_BTT] = s(i,j+1,k,QMAGZ) - s(i,j,k,QMAGZ); + + } else { + + // component (Bz) is omitted + + dQL[IEIGN_RHO] = s(i,j,k,QRHO) - s(i,j,k-1,QRHO); + dQL[IEIGN_U] = s(i,j,k,QU) - s(i,j,k-1,QU); + dQL[IEIGN_V] = s(i,j,k,QV) - s(i,j,k-1,QV); + dQL[IEIGN_W] = s(i,j,k,QW) - s(i,j,k-1,QW); + dQL[IEIGN_P] = s(i,j,k,QPRES) - s(i,j,k-1,QPRES); + dQL[IEIGN_BT] = s(i,j,k,QMAGX) - s(i,j,k-1,QMAGX); + dQL[IEIGN_BTT] = s(i,j,k,QMAGY) - s(i,j,k-1,QMAGY); + + dQR[IEIGN_RHO] = s(i,j,k+1,QRHO) - s(i,j,k,QRHO); + dQR[IEIGN_U] = s(i,j,k+1,QU) - s(i,j,k,QU); + dQR[IEIGN_V] = s(i,j,k+1,QV) - s(i,j,k,QV); + dQR[IEIGN_W] = s(i,j,k+1,QW) - s(i,j,k,QW); + dQR[IEIGN_P] = s(i,j,k+1,QPRES) - s(i,j,k,QPRES); + dQR[IEIGN_BT] = s(i,j,k+1,QMAGX) - s(i,j,k,QMAGX); + dQR[IEIGN_BTT] = s(i,j,k+1,QMAGY) - s(i,j,k,QMAGY); + + } + + // compute the eigenvectors and eigenvalues for this coordinate direction + + Real q_zone[NQ]; + for (int n = 0; n < NQ; n++) { + q_zone[n] = s(i,j,k,n); + } + + Real as = qaux(i,j,k,QC); + + Real lam[NEIGN]; + Real leig[NEIGN]; + Real reig[NEIGN]; + + evals(lam, as, q_zone, idir); + + if (idir == 0) { + evecx(leig, reig, as, q_zone); + + } else if (idir == 1) { + evecy(leig, reig, as, q_zone); + + } else { + evecz(leig, reig, as, q_zone); + } + + // MHD Source Terms -- from the Miniati paper, Eq. 32 and 33 + Real smhd[NEIGN]; + + smhd[IEIGN_RHO] = 0.0_rt; + smhd[IEIGN_U] = q_zone[QMAGX] / q_zone[QRHO]; + smhd[IEIGN_V] = q_zone[QMAGY] / q_zone[QRHO]; + smhd[IEIGN_W] = q_zone[QMAGZ] / q_zone[QRHO]; + smhd[IEIGN_P] = q_zone[QMAGX] * q_zone[QU] + + q_zone[QMAGY] * q_zone[QV] + + q_zone[QMAGZ] * q_zone[QW]; + + if (idir == 0) { + smhd[IEIGN_BT] = q_zone[QV]; + smhd[IEIGN_BTT] = q_zone[QW]; + + // cross-talk of normal magnetic field direction + for (int n = 0; n < NEIGN; n++) { + smhd[n] = smhd[n] * (bx(i+1,j,k) - bx(i,j,k)) / dx[idir]; + } + + } else if (idir == 1) { + smhd[IEIGN_BT] = q_zone[QU]; + smhd[IEIGN_BTT] = q_zone[QW]; + + // cross-talk of normal magnetic field direction + for (int n = 0; n < NEIGN; n++) { + smhd[n] = smhd[n] * (by(i,j+1,k) - by(i,j,k)) / dx[idir]; + } + + } else { + smhd[IEIGN_BT] = q_zone[QU]; + smhd[IEIGN_BTT] = q_zone[QV]; + + // cross-talk of normal magnetic field direction + for (int n = 0; n < NEIGN; n++) { + smhd[n] = smhd[n] * (bz(i,j,k+1) - bz(i,j,k)) / dx[idir]; + } + } + + // Perform the characteristic projection. Since we are using + // Using HLLD, we sum over all eigenvalues -- see the discussion after Eq. 31 + Real summ_p[NEIGN] = {0.0_rt}; + Real summ_m[NEIGN] = {0.0_rt}; + + for (int ii = 0; ii < NEIGN; ii++) { + Real dL[NEIGN] = {0.0_rt}; + Real dR[NEIGN] = {0.0_rt}; + + for (int n = 0; n < NEIGN; n++) { + dL[n] = leig(ii,n) * dQL[n]; + dR[n] = leig(ii,n) * dQR[n]; + } + + Real dW; + slope(dW, dL, dR, flatn(i,j,k)); + + for (int n = 0; n < NEIGN; n++) { + summ_p[n] += (1.0_rt - dtdx * lam[ii]) * dW * reig(n,ii); + summ_m[n] -= (1.0_rt + dtdx * lam[ii]) * dW * reig(n,ii); + } + } + + // left state at i+1/2 + + if (idir == 0) { + qleft(i+1,j,k,QRHO) = amrex::max(small_dens, + q_zone[QRHO] + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qleft(i+1,j,k,QU) = q_zone[QU] + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qleft(i+1,j,k,QV) = q_zone[QV] + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qleft(i+1,j,k,QW) = q_zone[QW] + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + qleft(i+1,j,k,QPRES) = amrex::max(small_pres, + q_zone[QPRES] + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + + qleft(i+1,j,k,QMAGX) = bx(i+1,j,k); // Bx stuff + qleft(i+1,j,k,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qleft(i+1,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + + } else if (idir == 1) { + qleft(i,j+1,k,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5_rt*summ_p(IEIGN_RHO) + 0.5_rt*dt*smhd(IEIGN_RHO)) + qleft(i,j+1,k,QU) = s(i,j,k,QU) + 0.5_rt*summ_p(IEIGN_U) + 0.5_rt*dt*smhd(IEIGN_U) + qleft(i,j+1,k,QV) = s(i,j,k,QV) + 0.5_rt*summ_p(IEIGN_V) + 0.5_rt*dt*smhd(IEIGN_V) + qleft(i,j+1,k,QW) = s(i,j,k,QW) + 0.5_rt*summ_p(IEIGN_W) + 0.5_rt*dt*smhd(IEIGN_W) + qleft(i,j+1,k,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5_rt*summ_p(IEIGN_P) + 0.5_rt*dt*smhd(IEIGN_P)) + + qleft(i,j+1,k,QMAGX) = s(i,j,k,QMAGX) + 0.5_rt*summ_p(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) + qleft(i,j+1,k,QMAGY) = by(i,j+1,k) !! By stuff + qleft(i,j+1,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5_rt*summ_p(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) + + else + qleft(i,j,k+1,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5_rt*summ_p(IEIGN_RHO) + 0.5_rt*dt*smhd(IEIGN_RHO)) + qleft(i,j,k+1,QU) = s(i,j,k,QU) + 0.5_rt*summ_p(IEIGN_U) + 0.5_rt*dt*smhd(IEIGN_U) + qleft(i,j,k+1,QV) = s(i,j,k,QV) + 0.5_rt*summ_p(IEIGN_V) + 0.5_rt*dt*smhd(IEIGN_V) + qleft(i,j,k+1,QW) = s(i,j,k,QW) + 0.5_rt*summ_p(IEIGN_W) + 0.5_rt*dt*smhd(IEIGN_W) + qleft(i,j,k+1,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5_rt*summ_p(IEIGN_P) + 0.5_rt*dt*smhd(IEIGN_P)) + + qleft(i,j,k+1,QMAGX) = s(i,j,k,QMAGX) + 0.5_rt*summ_p(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) + qleft(i,j,k+1,QMAGY) = s(i,j,k,QMAGY) + 0.5_rt*summ_p(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) + qleft(i,j,k+1,QMAGZ) = bz(i,j,k+1) !! Bz stuff + end if + + ! right state at i-1/2 + qright(i,j,k,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5_rt*summ_m(IEIGN_RHO) + 0.5_rt*dt*smhd(IEIGN_RHO)) + qright(i,j,k,QU) = s(i,j,k,QU) + 0.5_rt*summ_m(IEIGN_U) + 0.5_rt*dt*smhd(IEIGN_U) + qright(i,j,k,QV) = s(i,j,k,QV) + 0.5_rt*summ_m(IEIGN_V) + 0.5_rt*dt*smhd(IEIGN_V) + qright(i,j,k,QW) = s(i,j,k,QW) + 0.5_rt*summ_m(IEIGN_W) + 0.5_rt*dt*smhd(IEIGN_W) + qright(i,j,k,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5_rt*summ_m(IEIGN_P) + 0.5_rt*dt*smhd(IEIGN_P)) + + if (idir == 1) then + qright(i,j,k,QMAGX) = bx(i,j,k) !! Bx stuff + qright(i,j,k,QMAGY) = s(i,j,k,QMAGY) + 0.5_rt*summ_m(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) + qright(i,j,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5_rt*summ_m(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) + + else if (idir == 2) then + qright(i,j,k,QMAGX) = s(i,j,k,QMAGX) + 0.5_rt*summ_m(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) + qright(i,j,k,QMAGY) = by(i,j,k) !! By stuff + qright(i,j,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5_rt*summ_m(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) + + else + qright(i,j,k,QMAGX) = s(i,j,k,QMAGX) + 0.5_rt*summ_m(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) + qright(i,j,k,QMAGY) = s(i,j,k,QMAGY) + 0.5_rt*summ_m(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) + qright(i,j,k,QMAGZ) = bz(i,j,k) !! Bz stuff + endif + + ! species + do ii = QFS, QFS+nspec-1 + if (idir == 1) then + dL = s(i,j,k,ii) - s(i-1,j,k,ii) + dR = s(i+1,j,k,ii) - s(i,j,k,ii) + un = s(i,j,k,QU) + + else if (idir == 2) then + dL = s(i,j,k,ii) - s(i,j-1,k,ii) + dR = s(i,j+1,k,ii) - s(i,j,k,ii) + un = s(i,j,k,QV) + + else + dL = s(i,j,k,ii) - s(i,j,k-1,ii) + dR = s(i,j,k+1,ii) - s(i,j,k,ii) + un = s(i,j,k,QW) + end if + + call slope(dW, dL, dR, flatn(i,j,k)) + + if (idir == 1) then + qleft(i+1,j,k,ii) = s(i,j,k,ii) + 0.5_rt*(1.0d0 - dtdx*un) * dW + else if (idir == 2) then + qleft(i,j+1,k,ii) = s(i,j,k,ii) + 0.5_rt*(1.0d0 - dtdx*un) * dW + else + qleft(i,j,k+1,ii) = s(i,j,k,ii) + 0.5_rt*(1.0d0 - dtdx*un) * dW + endif + qright(i,j,k,ii) = s(i,j,k,ii) - 0.5_rt*(1.0d0 + dtdx*un) * dW + enddo + + ! rho e + if (idir == 1) then + eos_state % rho = qleft(i+1,j,k,QRHO) + eos_state % p = qleft(i+1,j,k,QPRES) + eos_state % T = s(i,j,k,QTEMP) !some initial guess? + eos_state % xn = qleft(i+1,j,k,QFS:QFS+nspec-1) + + call eos(eos_input_rp, eos_state) + qleft(i+1,j,k,QREINT) = eos_state % e * eos_state % rho + + else if (idir == 2) then + eos_state % rho = qleft(i,j+1,k,QRHO) + eos_state % p = qleft(i,j+1,k,QPRES) + eos_state % T = s(i,j,k,QTEMP) !some initial guess? + eos_state % xn = qleft(i,j+1,k,QFS:QFS+nspec-1) + + call eos(eos_input_rp, eos_state) + qleft(i,j+1,k,QREINT) = eos_state % e * eos_state % rho + + else + eos_state % rho = qleft(i,j,k+1,QRHO) + eos_state % p = qleft(i,j,k+1,QPRES) + eos_state % T = s(i,j,k,QTEMP) !some initial guess? + eos_state % xn = qleft(i,j,k+1,QFS:QFS+nspec-1) + + call eos(eos_input_rp, eos_state) + qleft(i,j,k+1,QREINT) = eos_state % e * eos_state % rho + + end if + + eos_state % rho = qright(i,j,k,QRHO) + eos_state % p = qright(i,j,k,QPRES) + eos_state % xn = qright(i,j,k,QFS:QFS+nspec-1) + + call eos(eos_input_rp, eos_state) + qright(i,j,k,QREINT) = eos_state % e * eos_state % rho + + ! add source terms + if (idir == 1) then + qleft(i+1,j,k,QRHO) = max(small_dens, qleft(i+1,j,k,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)) + qleft(i+1,j,k,QU) = qleft(i+1,j,k,QU) + 0.5_rt*dt*srcQ(i,j,k,QU) + qleft(i+1,j,k,QV) = qleft(i+1,j,k,QV) + 0.5_rt*dt*srcQ(i,j,k,QV) + qleft(i+1,j,k,QW) = qleft(i+1,j,k,QW) + 0.5_rt*dt*srcQ(i,j,k,QW) + qleft(i+1,j,k,QPRES) = qleft(i+1,j,k,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES) + qleft(i+1,j,k,QREINT) = qleft(i+1,j,k,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT) + + else if (idir == 2) then + qleft(i,j+1,k,QRHO) = max(small_dens, qleft(i,j+1,k,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)) + qleft(i,j+1,k,QU) = qleft(i,j+1,k,QU) + 0.5_rt*dt*srcQ(i,j,k,QU) + qleft(i,j+1,k,QV) = qleft(i,j+1,k,QV) + 0.5_rt*dt*srcQ(i,j,k,QV) + qleft(i,j+1,k,QW) = qleft(i,j+1,k,QW) + 0.5_rt*dt*srcQ(i,j,k,QW) + qleft(i,j+1,k,QPRES) = qleft(i,j+1,k,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES) + qleft(i,j+1,k,QREINT) = qleft(i,j+1,k,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT) + + else + qleft(i,j,k+1,QRHO) = max(small_dens, qleft(i,j,k+1,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)) + qleft(i,j,k+1,QU) = qleft(i,j,k+1,QU) + 0.5_rt*dt*srcQ(i,j,k,QU) + qleft(i,j,k+1,QV) = qleft(i,j,k+1,QV) + 0.5_rt*dt*srcQ(i,j,k,QV) + qleft(i,j,k+1,QW) = qleft(i,j,k+1,QW) + 0.5_rt*dt*srcQ(i,j,k,QW) + qleft(i,j,k+1,QPRES) = qleft(i,j,k+1,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES) + qleft(i,j,k+1,QREINT) = qleft(i,j,k+1,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT) + end if + + qright(i,j,k,QRHO) = max(small_dens, qright(i,j,k,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)) + qright(i,j,k,QU) = qright(i,j,k,QU) + 0.5_rt*dt*srcQ(i,j,k,QU) + qright(i,j,k,QV) = qright(i,j,k,QV) + 0.5_rt*dt*srcQ(i,j,k,QV) + qright(i,j,k,QW) = qright(i,j,k,QW) + 0.5_rt*dt*srcQ(i,j,k,QW) + qright(i,j,k,QPRES) = qright(i,j,k,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES) + qright(i,j,k,QREINT) = qright(i,j,k,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT) + + enddo + enddo + enddo + + end subroutine plm + + !======================================== Minmod TVD slope limiter ========================================= + subroutine minmod(dW, WR, WL) + + use amrex_fort_module, only : rt => amrex_real + + implicit none + + real(rt), intent(in) :: WR, WL + real(rt), intent(out) :: dW + dW = 0.d0 + + if (abs(WR) < abs(WL) .and. WR*WL > 0.d0) then + dW = WR + else if (abs(WL) < abs(WR) .and. WR*WL > 0.d0) then + dW = WL + endif + + end subroutine minmod + + + !========================================= VanLeer TVD slope limiter ======================================= + subroutine vanleer(dW, WR, WL) + + use amrex_fort_module, only : rt => amrex_real + + implicit none + + real(rt), intent(in ) :: WR, WL + real(rt), intent(out) :: dW + dW = 0.0d0 + + if( WR*WL .gt. 0.0d0 ) then + dW = 2.0d0*WR*WL/(WR + WL) + endif + + end subroutine vanleer + + !========================================== centered difference =========================================== + subroutine centerdif(dW, WR, WL) + + use amrex_fort_module, only : rt => amrex_real + + implicit none + + real(rt), intent(in ) :: WR, WL + real(rt), intent(out) :: dW + + dW = (WR+WL)/2.0d0 + + end subroutine centerdif + + !================================== second order MC ============================== + subroutine secondMC(dW, WR, WL) + + use amrex_fort_module, only : rt => amrex_real + use amrex_constants_module, only : ZERO, HALF, ONE, TWO + + implicit none + + real(rt), intent(in ) :: WR, WL + real(rt), intent(out ) :: dW + + real(rt) :: dlim + + if (WR * WL .ge. ZERO) then + dlim = TWO * min(abs(WR), abs(WL)) + else + dlim = ZERO + endif + + dW = min(HALF * abs(WR + WL), dlim ) * sign(ONE, WR + WL) + + + end subroutine secondMC + + + + !================================================================ + subroutine slope(dW, WR, WL, flat) + use amrex_fort_module, only : rt => amrex_real + + implicit none + real(rt), intent(in ) :: flat + real(rt), intent(in ) :: WR, WL + real(rt), intent(out) :: dW + + if (mhd_plm_slope == 0) then + dW = 0.0 + elseif (mhd_plm_slope == 1) then + call vanleer(dW,WR,WL) + elseif (mhd_plm_slope == 2) then + call centerdif(dW,WR,WL) + elseif (mhd_plm_slope == 3) then + call secondMC(dW,WR,WL) + endif + + if (use_flattening == 1) then + dW = flat * dW + endif + + end subroutine slope + + !=========================================== Evals ========================================================= + + subroutine evals(lam, qaux, Q, dir) + + use amrex_fort_module, only : rt => amrex_real + use network, only: nspec + implicit none + + real(rt), intent(in) :: Q(NQ), qaux(NQAUX) + real(rt), intent(out) :: lam(NEIGN) !7 waves + integer, intent(in) :: dir !Choose direction, 1 for x, 2 for y, 3 for z + + !The characteristic speeds of the system + real(rt) :: cfx, cfy, cfz, cax, cay, caz, csx, csy, csz, ca, as + + ! speeds + as = qaux(QC) * qaux(QC) + + ! Alfven + ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) + cax = (Q(QMAGX)**2)/Q(QRHO) + cay = (Q(QMAGY)**2)/Q(QRHO) + caz = (Q(QMAGZ)**2)/Q(QRHO) + + ! Slow + csx = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cax)) + csy = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cay)) + csz = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*caz)) + + ! Fast + cfx = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cax)) + cfy = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cay)) + cfz = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*caz)) + + if(dir.eq.1) then + + !Ax eigenvalues + lam(1) = Q(QU) - sqrt(cfx) + lam(2) = Q(QU) - sqrt(cax) + lam(3) = Q(QU) - sqrt(csx) + lam(4) = Q(QU) + lam(5) = Q(QU) + sqrt(csx) + lam(6) = Q(QU) + sqrt(cax) + lam(7) = Q(QU) + sqrt(cfx) + + elseif(dir.eq.2) then + + !Ay eigenvalues + lam(1) = Q(QV) - sqrt(cfy) + lam(2) = Q(QV) - sqrt(cay) + lam(3) = Q(QV) - sqrt(csy) + lam(4) = Q(QV) + lam(5) = Q(QV) + sqrt(csy) + lam(6) = Q(QV) + sqrt(cay) + lam(7) = Q(QV) + sqrt(cfy) + + else + + !Az eigenvalues + lam(1) = Q(QW) - sqrt(cfz) + lam(2) = Q(QW) - sqrt(caz) + lam(3) = Q(QW) - sqrt(csz) + lam(4) = Q(QW) + lam(5) = Q(QW) + sqrt(csz) + lam(6) = Q(QW) + sqrt(caz) + lam(7) = Q(QW) + sqrt(cfz) + endif + + end subroutine evals + + !====================================== Left Eigenvectors =============================================== + + !x direction + subroutine evecx(leig, reig, qaux, Q) + use amrex_fort_module, only : rt => amrex_real + use network, only : nspec + + implicit none + + !returnes Leig, where the rows are the left eigenvectors of the characteristic matrix Ax + real(rt), intent(in) ::Q(NQ), qaux(NQAUX) + real(rt), intent(out) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN) + + !The characteristic speeds of the system + real(rt) :: cfx, cax, csx, ca, as, S, N + real(rt) :: cff, css, Qf, Qs, AAf, AAs, alf, als, bety, betz + + ! Speeds + + as = qaux(QC) * qaux(QC) + + ! Alfven + ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) + cax = (Q(QMAGX)**2)/Q(QRHO) + + ! Slow + csx = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cax)) + + ! Fast + cfx = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cax)) + + !useful constants + alf = sqrt((as - csx)/(cfx - csx)) + als = sqrt((cfx - as)/(cfx - csx)) + if(cfx - as .lt. 0.d0) als = 0.d0 + if(as - csx .lt. 0.d0) alf = 0.d0 + + if(abs(Q(QMAGY)).le. 1.d-14 .and.abs(Q(QMAGZ)).le. 1.d-14) then + bety = 1.d0/sqrt(2.d0) + betz = bety + else + bety = Q(QMAGY)/(sqrt(Q(QMAGY)**2 + Q(QMAGZ)**2)) + betz = Q(QMAGZ)/(sqrt(Q(QMAGY)**2 + Q(QMAGZ)**2)) + endif + + cff = sqrt(cfx)*alf + css = sqrt(csx)*als + S = sign(1.0d0, Q(QMAGX)) + Qf = sqrt(cfx)*alf*S + Qs = sqrt(csx)*als*S + N = 0.5_rt/as + AAf = sqrt(as)*alf*sqrt(Q(QRHO)) + AAs = sqrt(as)*als*sqrt(Q(QRHO)) + + + leig(1,:) = (/0.d0, -N*Cff, N*Qs*bety, N*Qs*betz, N*alf/Q(QRHO), N*AAs*bety/Q(QRHO), N*AAs*betz/Q(QRHO)/) !u - cf + leig(2,:) = (/0.d0, 0.d0, -0.5_rt*betz, 0.5_rt*bety, 0.d0, -0.5_rt*S*betz/(sqrt(Q(QRHO))), 0.5_rt*bety*S/(sqrt(Q(QRHO)))/) !u - cAx + leig(3,:) = (/0.d0, -N*Css, -N*Qf*bety, -N*Qf*betz, N*als/Q(QRHO), -N*AAf*bety/Q(QRHO), -N*AAf*betz/Q(QRHO)/) !u - cs + leig(4,:) = (/1.d0, 0.d0, 0.d0, 0.d0, -1.d0/as, 0.d0, 0.d0/) !u + leig(5,:) = (/0.d0, N*Css, N*Qf*bety, N*Qf*betz, N*als/Q(QRHO), -N*AAf*bety/Q(QRHO), -N*AAf*betz/Q(QRHO)/) !u + cs + leig(6,:) = (/0.d0, 0.d0, 0.5_rt*betz, -0.5_rt*bety, 0.d0, -0.5_rt*betz*S/(sqrt(Q(QRHO))), 0.5_rt*bety*S/(sqrt(Q(QRHO)))/) !u + cAx + leig(7,:) = (/0.d0, N*Cff, -N*Qs*bety, -N*Qs*betz, N*alf/Q(QRHO), N*AAs*bety/Q(QRHO), N*AAs*betz/Q(QRHO)/) !u + cf + + ! u - cf u - Cax u - cs u u + cs u + Cax u + cf + reig(IEIGN_RHO,:) = (/Q(QRHO)*alf, 0.d0, Q(QRHO)*als, 1.d0, Q(QRHO)*als, 0.d0, Q(QRHO)*alf/) + reig(IEIGN_U,:) = (/-cff , 0.d0, -css, 0.d0, css, 0.d0, cff/) + reig(IEIGN_V,:) = (/Qs*bety, -betz, -Qf*bety, 0.d0, Qf*bety, betz, -Qs*bety/) + reig(IEIGN_W,:) = (/Qs*betz, bety, -Qf*betz, 0.d0, Qf*betz, -bety, -Qs*betz/) + reig(IEIGN_P,:) = (/Q(QRHO)*as*alf, 0.d0, Q(QRHO)*as*als, 0.d0 , Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*alf/) + reig(IEIGN_BT,:) = (/AAs*bety, -betz*S*sqrt(Q(QRHO)), -AAf*bety, 0.d0 , -AAf*bety, -betz*S*sqrt(Q(QRHO)), AAs*bety/) + reig(IEIGN_BTT,:) = (/AAs*betz, bety*S*sqrt(Q(QRHO)), -AAf*betz, 0.d0, -AAf*betz, bety*S*sqrt(Q(QRHO)), AAs*betz/) + + + end subroutine evecx + + !y direction + subroutine evecy(leig, reig, qaux, Q) + use amrex_fort_module, only : rt => amrex_real + use network, only : nspec + + implicit none + + !returnes Leig, where the rows are the left eigenvectors of the characteristic matrix Ay + real(rt), intent(in) :: Q(NQ), qaux(NQAUX) + real(rt), intent(out) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN) + + !The characteristic speeds of the system + real(rt) :: cfy, cay, csy, ca, as, S, N + real(rt) :: cff, css, Qf, Qs, AAf, AAs, alf, als, betx, betz + + + ! Speeds + as = qaux(QC) * qaux(QC) + + ! Alfven + ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) + cay = (Q(QMAGY)**2)/Q(QRHO) + + ! Slow + csy = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cay)) + + ! Fast + cfy = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cay)) + + !useful constants + alf = sqrt((as - csy)/(cfy - csy)) + als = sqrt((cfy - as)/(cfy - csy)) + if(as - csy .lt. 0.d0) alf = 0.d0 + if(cfy - as .lt. 0.d0) als = 0.d0 + + if(abs(Q(QMAGX)).le. 1.d-14 .and.abs(Q(QMAGZ)).le. 1.d-14) then + betx = 1.d0/sqrt(2.d0) + betz = betx + else + betx = Q(QMAGX)/(sqrt(Q(QMAGX)**2 + Q(QMAGZ)**2)) + betz = Q(QMAGZ)/(sqrt(Q(QMAGX)**2 + Q(QMAGZ)**2)) + endif + + cff = sqrt(cfy)*alf + css = sqrt(csy)*als + S = sign(1.0d0, Q(QMAGY)) + Qf = sqrt(cfy)*alf*S + Qs = sqrt(csy)*als*S + AAf = sqrt(as)*alf*sqrt(Q(QRHO)) + AAs = sqrt(as)*als*sqrt(Q(QRHO)) + N = 0.5_rt/as + + !Need to double check the rows + leig(1,:) = (/0.d0, N*Qs*betx, -N*Cff , N*Qs*betz, N*alf/Q(QRHO), N*AAs*betx/Q(QRHO), N*AAs*betz/Q(QRHO)/) ! v - cf + leig(2,:) = (/0.d0, -0.5_rt*betz, 0.d0, 0.5_rt*betx, 0.d0, -0.5_rt*betz*S/(sqrt(Q(QRHO))), 0.5_rt*betx*S/(sqrt(Q(QRHO)))/) ! v - cAy + leig(3,:) = (/0.d0, -N*Qf*betx, -N*Css, -N*Qf*betz, N*als/Q(QRHO), -N*AAf*betx/Q(QRHO), -N*AAf*betz/Q(QRHO)/) ! v - cs + leig(4,:) = (/1.d0, 0.d0, 0.d0, 0.d0, -1.d0/as, 0.d0, 0.d0/) ! v + leig(5,:) = (/0.d0, N*Qf*betx, N*Css, N*Qf*betz, N*als/Q(QRHO), -N*AAf*betx/Q(QRHO), -N*AAf*betz/Q(QRHO)/) ! v + cs + leig(6,:) = (/0.d0, 0.5_rt*betz, 0.d0, -0.5_rt*betx, 0.d0, -0.5_rt*betz*S/(sqrt(Q(QRHO))), 0.5_rt*betx*S/(sqrt(Q(QRHO)))/) ! v + cAy + leig(7,:) = (/0.d0, -N*Qs*betx, N*Cff, -N*Qs*betz, N*alf/Q(QRHO), N*AAs*betx/Q(QRHO), N*AAs*betz/Q(QRHO)/) ! v + cf + + ! v - cf v - Cay v - cs v v + cs v + Cay v + cf + reig(IEIGN_RHO,:) = (/Q(QRHO)*alf, 0.d0, Q(QRHO)*als, 1.d0, Q(QRHO)*als, 0.d0, Q(QRHO)*alf/) + reig(IEIGN_V,:) = (/-cff, 0.d0, -css, 0.d0 , css, 0.d0, cff/) + reig(IEIGN_U,:) = (/Qs*betx, -betz, -Qf*betx, 0.d0 , Qf*betx, betz, -Qs*betx/) + reig(IEIGN_W,:) = (/Qs*betz, betx, -Qf*betz, 0.d0 , Qf*betz, -betx , -Qs*betz/) + reig(IEIGN_P,:) = (/Q(QRHO)*as*alf, 0.d0, Q(QRHO)*as*als, 0.d0 , Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*alf/) + reig(IEIGN_BT,:) = (/AAs*betx, -betz*S*sqrt(Q(QRHO)), -AAf*betx, 0.d0 , -AAf*betx, -betz*S*sqrt(Q(QRHO)) , AAs*betx/) + reig(IEIGN_BTT,:) = (/AAs*betz, betx*S*sqrt(Q(QRHO)), -AAf*betz, 0.d0, -AAf*betz, betx*S*sqrt(Q(QRHO)), AAs*betz/) + + end subroutine evecy + + !z direction + subroutine evecz(leig, reig, qaux, Q) + use amrex_fort_module, only : rt => amrex_real + use network, only : nspec + + implicit none + + !returnes Leig, where the rows are the left eigenvectors of the characteristic matrix Az + real(rt), intent(in) :: Q(NQ), qaux(NQAUX) + real(rt), intent(out) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN) + + !The characteristic speeds of the system + real(rt) :: cfz, caz, csz, ca, as, S, N + real(rt) :: cff, css, Qf, Qs, AAf, AAs, alf, als, betx, bety + + ! Speeds + as = qaux(QC) * qaux(QC) + + ! Alfven + ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) + caz = (Q(QMAGZ)**2)/Q(QRHO) + + ! Slow + csz = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*caz)) + + ! Fast + cfz = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*caz)) + + !useful constants + alf = sqrt((as - csz)/(cfz - csz)) + als = sqrt((cfz - as)/(cfz - csz)) + + if(cfz - as .lt. 0.d0) als = 0.d0 + + if(abs(Q(QMAGX)).le. 1.d-14 .and.abs(Q(QMAGY)).le. 1.d-14) then + betx = 1.d0/sqrt(2.d0) + bety = betx + else + betx = Q(QMAGX)/(sqrt(Q(QMAGX)**2 + Q(QMAGY)**2)) + bety = Q(QMAGY)/(sqrt(Q(QMAGX)**2 + Q(QMAGY)**2)) + endif + + cff = sqrt(cfz)*alf + css = sqrt(csz)*als + S = sign(1.0d0, Q(QMAGZ)) + Qf = sqrt(cfz)*alf*S + Qs = sqrt(csz)*als*S + AAf = sqrt(as)*alf*sqrt(Q(QRHO)) + AAs = sqrt(as)*als*sqrt(Q(QRHO)) + N = 0.5_rt/as + + !Need to double check the order + leig(1,:) = (/0.d0, N*Qs*betx, N*Qs*bety, -N*Cff, N*alf/Q(QRHO) , N*AAs*betx/Q(QRHO), N*AAs*bety/Q(QRHO)/) !w - cf + leig(2,:) = (/0.d0, -0.5_rt*bety, 0.5_rt*betx, 0.d0, 0.d0, -0.5_rt*S*bety/(sqrt(Q(QRHO))) , 0.5_rt*betx*S/(sqrt(Q(QRHO)))/) !w - cAz + leig(3,:) = (/0.d0, -N*Qf*betx, -N*Qf*bety, -N*Css, N*als/Q(QRHO) , -N*AAf*betx/Q(QRHO), -N*AAf*bety/Q(QRHO)/) !w - cs + leig(4,:) = (/1.d0, 0.d0 , 0.d0, 0.d0, -1.d0/as, 0.d0, 0.d0/) !w + leig(5,:) = (/0.d0, N*Qf*betx, N*Qf*bety, N*Css, N*als/Q(QRHO) , -N*AAf*betx/Q(QRHO), -N*AAf*bety/Q(QRHO)/) !w + cs + leig(6,:) = (/0.d0, 0.5_rt*bety , -0.5_rt*betx, 0.0d0, 0.d0 , -0.5_rt*bety*S/(sqrt(Q(QRHO))) , 0.5_rt*betx*S/(sqrt(Q(QRHO))) /) !w + cAz + leig(7,:) = (/0.d0, -N*Qs*betx, -N*Qs*bety, N*Cff , N*alf/Q(QRHO) , N*AAs*betx/Q(QRHO) , N*AAs*bety/Q(QRHO) /) !w + cf + + ! w - cf w - Caz w - cs w w + cs w + Caz w + cf + reig(IEIGN_RHO,:) = (/Q(QRHO)*alf, 0.d0, Q(QRHO)*als, 1.d0, Q(QRHO)*als, 0.d0, Q(QRHO)*alf/) + reig(IEIGN_W,:) = (/-cff , 0.d0, -css, 0.d0, css, 0.d0 , cff/) + reig(IEIGN_U,:) = (/Qs*betx, -bety, -Qf*betx, 0.d0, Qf*betx, bety, -Qs*betx/) + reig(IEIGN_V,:) = (/Qs*bety, betx, -Qf*bety, 0.d0, Qf*bety, -betx , -Qs*bety/) + reig(IEIGN_P,:) = (/Q(QRHO)*as*alf, 0.d0, Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*alf/) + reig(IEIGN_BT,:) = (/AAs*betx, -bety*S*sqrt(Q(QRHO)), -AAf*betx, 0.d0, -AAf*betx, -bety*S*sqrt(Q(QRHO)), AAs*betx/) + reig(IEIGN_BTT,:) = (/AAs*bety, betx*S*sqrt(Q(QRHO)), -AAf*bety, 0.d0, -AAf*bety, betx*S*sqrt(Q(QRHO)), AAs*bety/) + + end subroutine evecz + +end module mhd_plm_module diff --git a/Source/mhd/mhd_util.H b/Source/mhd/mhd_util.H index f7f94c1a93..daee0378ba 100644 --- a/Source/mhd/mhd_util.H +++ b/Source/mhd/mhd_util.H @@ -9,6 +9,18 @@ constexpr int UMAGX = NUM_STATE; constexpr int UMAGY = NUM_STATE+1; constexpr int UMAGZ = NUM_STATE+2; +constexpr int NEIGN = 7; + +constexpr int IEIGN_RHO = 1; +constexpr int IEIGN_U = 2; +constexpr int IEIGN_V = 3; +constexpr int IEIGN_W = 4; +constexpr int IEIGN_P = 5; + +// perpendicular magnetic field components +constexpr int IEIGN_BT = 6; +constexpr int IEIGN_BTT = 7; + // sound speed calc for ideal MHD void AMREX_GPU_DEVICE AMREX_FORCE_INLINE From 145271f6d2f1067eac335bb14013e1ea1299641c Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 18:22:25 -0400 Subject: [PATCH 10/23] more work on the eigensystem --- Source/mhd/mhd_plm.cpp | 606 ++++++++++++----------------------------- Source/mhd/mhd_util.H | 14 +- 2 files changed, 174 insertions(+), 446 deletions(-) diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp index f875af528d..3752025ef0 100644 --- a/Source/mhd/mhd_plm.cpp +++ b/Source/mhd/mhd_plm.cpp @@ -197,156 +197,173 @@ Castro::plm(const Box& bx, qleft(i+1,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else if (idir == 1) { - qleft(i,j+1,k,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5_rt*summ_p(IEIGN_RHO) + 0.5_rt*dt*smhd(IEIGN_RHO)) - qleft(i,j+1,k,QU) = s(i,j,k,QU) + 0.5_rt*summ_p(IEIGN_U) + 0.5_rt*dt*smhd(IEIGN_U) - qleft(i,j+1,k,QV) = s(i,j,k,QV) + 0.5_rt*summ_p(IEIGN_V) + 0.5_rt*dt*smhd(IEIGN_V) - qleft(i,j+1,k,QW) = s(i,j,k,QW) + 0.5_rt*summ_p(IEIGN_W) + 0.5_rt*dt*smhd(IEIGN_W) - qleft(i,j+1,k,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5_rt*summ_p(IEIGN_P) + 0.5_rt*dt*smhd(IEIGN_P)) - - qleft(i,j+1,k,QMAGX) = s(i,j,k,QMAGX) + 0.5_rt*summ_p(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) - qleft(i,j+1,k,QMAGY) = by(i,j+1,k) !! By stuff - qleft(i,j+1,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5_rt*summ_p(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) - - else - qleft(i,j,k+1,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5_rt*summ_p(IEIGN_RHO) + 0.5_rt*dt*smhd(IEIGN_RHO)) - qleft(i,j,k+1,QU) = s(i,j,k,QU) + 0.5_rt*summ_p(IEIGN_U) + 0.5_rt*dt*smhd(IEIGN_U) - qleft(i,j,k+1,QV) = s(i,j,k,QV) + 0.5_rt*summ_p(IEIGN_V) + 0.5_rt*dt*smhd(IEIGN_V) - qleft(i,j,k+1,QW) = s(i,j,k,QW) + 0.5_rt*summ_p(IEIGN_W) + 0.5_rt*dt*smhd(IEIGN_W) - qleft(i,j,k+1,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5_rt*summ_p(IEIGN_P) + 0.5_rt*dt*smhd(IEIGN_P)) - - qleft(i,j,k+1,QMAGX) = s(i,j,k,QMAGX) + 0.5_rt*summ_p(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) - qleft(i,j,k+1,QMAGY) = s(i,j,k,QMAGY) + 0.5_rt*summ_p(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) - qleft(i,j,k+1,QMAGZ) = bz(i,j,k+1) !! Bz stuff - end if - - ! right state at i-1/2 - qright(i,j,k,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5_rt*summ_m(IEIGN_RHO) + 0.5_rt*dt*smhd(IEIGN_RHO)) - qright(i,j,k,QU) = s(i,j,k,QU) + 0.5_rt*summ_m(IEIGN_U) + 0.5_rt*dt*smhd(IEIGN_U) - qright(i,j,k,QV) = s(i,j,k,QV) + 0.5_rt*summ_m(IEIGN_V) + 0.5_rt*dt*smhd(IEIGN_V) - qright(i,j,k,QW) = s(i,j,k,QW) + 0.5_rt*summ_m(IEIGN_W) + 0.5_rt*dt*smhd(IEIGN_W) - qright(i,j,k,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5_rt*summ_m(IEIGN_P) + 0.5_rt*dt*smhd(IEIGN_P)) - - if (idir == 1) then - qright(i,j,k,QMAGX) = bx(i,j,k) !! Bx stuff - qright(i,j,k,QMAGY) = s(i,j,k,QMAGY) + 0.5_rt*summ_m(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) - qright(i,j,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5_rt*summ_m(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) - - else if (idir == 2) then - qright(i,j,k,QMAGX) = s(i,j,k,QMAGX) + 0.5_rt*summ_m(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) - qright(i,j,k,QMAGY) = by(i,j,k) !! By stuff - qright(i,j,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5_rt*summ_m(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) - - else - qright(i,j,k,QMAGX) = s(i,j,k,QMAGX) + 0.5_rt*summ_m(IEIGN_BT) + 0.5_rt*dt*smhd(IEIGN_BT) - qright(i,j,k,QMAGY) = s(i,j,k,QMAGY) + 0.5_rt*summ_m(IEIGN_BTT) + 0.5_rt*dt*smhd(IEIGN_BTT) - qright(i,j,k,QMAGZ) = bz(i,j,k) !! Bz stuff - endif - - ! species - do ii = QFS, QFS+nspec-1 - if (idir == 1) then - dL = s(i,j,k,ii) - s(i-1,j,k,ii) - dR = s(i+1,j,k,ii) - s(i,j,k,ii) - un = s(i,j,k,QU) - - else if (idir == 2) then - dL = s(i,j,k,ii) - s(i,j-1,k,ii) - dR = s(i,j+1,k,ii) - s(i,j,k,ii) - un = s(i,j,k,QV) - - else - dL = s(i,j,k,ii) - s(i,j,k-1,ii) - dR = s(i,j,k+1,ii) - s(i,j,k,ii) - un = s(i,j,k,QW) - end if - - call slope(dW, dL, dR, flatn(i,j,k)) - - if (idir == 1) then - qleft(i+1,j,k,ii) = s(i,j,k,ii) + 0.5_rt*(1.0d0 - dtdx*un) * dW - else if (idir == 2) then - qleft(i,j+1,k,ii) = s(i,j,k,ii) + 0.5_rt*(1.0d0 - dtdx*un) * dW - else - qleft(i,j,k+1,ii) = s(i,j,k,ii) + 0.5_rt*(1.0d0 - dtdx*un) * dW - endif - qright(i,j,k,ii) = s(i,j,k,ii) - 0.5_rt*(1.0d0 + dtdx*un) * dW - enddo - - ! rho e - if (idir == 1) then - eos_state % rho = qleft(i+1,j,k,QRHO) - eos_state % p = qleft(i+1,j,k,QPRES) - eos_state % T = s(i,j,k,QTEMP) !some initial guess? - eos_state % xn = qleft(i+1,j,k,QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - qleft(i+1,j,k,QREINT) = eos_state % e * eos_state % rho - - else if (idir == 2) then - eos_state % rho = qleft(i,j+1,k,QRHO) - eos_state % p = qleft(i,j+1,k,QPRES) - eos_state % T = s(i,j,k,QTEMP) !some initial guess? - eos_state % xn = qleft(i,j+1,k,QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - qleft(i,j+1,k,QREINT) = eos_state % e * eos_state % rho - - else - eos_state % rho = qleft(i,j,k+1,QRHO) - eos_state % p = qleft(i,j,k+1,QPRES) - eos_state % T = s(i,j,k,QTEMP) !some initial guess? - eos_state % xn = qleft(i,j,k+1,QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - qleft(i,j,k+1,QREINT) = eos_state % e * eos_state % rho - - end if - - eos_state % rho = qright(i,j,k,QRHO) - eos_state % p = qright(i,j,k,QPRES) - eos_state % xn = qright(i,j,k,QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - qright(i,j,k,QREINT) = eos_state % e * eos_state % rho - - ! add source terms - if (idir == 1) then - qleft(i+1,j,k,QRHO) = max(small_dens, qleft(i+1,j,k,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)) - qleft(i+1,j,k,QU) = qleft(i+1,j,k,QU) + 0.5_rt*dt*srcQ(i,j,k,QU) - qleft(i+1,j,k,QV) = qleft(i+1,j,k,QV) + 0.5_rt*dt*srcQ(i,j,k,QV) - qleft(i+1,j,k,QW) = qleft(i+1,j,k,QW) + 0.5_rt*dt*srcQ(i,j,k,QW) - qleft(i+1,j,k,QPRES) = qleft(i+1,j,k,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES) - qleft(i+1,j,k,QREINT) = qleft(i+1,j,k,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT) - - else if (idir == 2) then - qleft(i,j+1,k,QRHO) = max(small_dens, qleft(i,j+1,k,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)) - qleft(i,j+1,k,QU) = qleft(i,j+1,k,QU) + 0.5_rt*dt*srcQ(i,j,k,QU) - qleft(i,j+1,k,QV) = qleft(i,j+1,k,QV) + 0.5_rt*dt*srcQ(i,j,k,QV) - qleft(i,j+1,k,QW) = qleft(i,j+1,k,QW) + 0.5_rt*dt*srcQ(i,j,k,QW) - qleft(i,j+1,k,QPRES) = qleft(i,j+1,k,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES) - qleft(i,j+1,k,QREINT) = qleft(i,j+1,k,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT) - - else - qleft(i,j,k+1,QRHO) = max(small_dens, qleft(i,j,k+1,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)) - qleft(i,j,k+1,QU) = qleft(i,j,k+1,QU) + 0.5_rt*dt*srcQ(i,j,k,QU) - qleft(i,j,k+1,QV) = qleft(i,j,k+1,QV) + 0.5_rt*dt*srcQ(i,j,k,QV) - qleft(i,j,k+1,QW) = qleft(i,j,k+1,QW) + 0.5_rt*dt*srcQ(i,j,k,QW) - qleft(i,j,k+1,QPRES) = qleft(i,j,k+1,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES) - qleft(i,j,k+1,QREINT) = qleft(i,j,k+1,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT) - end if - - qright(i,j,k,QRHO) = max(small_dens, qright(i,j,k,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)) - qright(i,j,k,QU) = qright(i,j,k,QU) + 0.5_rt*dt*srcQ(i,j,k,QU) - qright(i,j,k,QV) = qright(i,j,k,QV) + 0.5_rt*dt*srcQ(i,j,k,QV) - qright(i,j,k,QW) = qright(i,j,k,QW) + 0.5_rt*dt*srcQ(i,j,k,QW) - qright(i,j,k,QPRES) = qright(i,j,k,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES) - qright(i,j,k,QREINT) = qright(i,j,k,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT) - - enddo - enddo - enddo - - end subroutine plm + qleft(i,j+1,k,QRHO) = amrex::max(small_dens, + q_zone[QRHO] + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qleft(i,j+1,k,QU) = q_zone[QU] + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qleft(i,j+1,k,QV) = q_zone[QV] + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qleft(i,j+1,k,QW) = q_zone[QW] + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + qleft(i,j+1,k,QPRES) = amrex::max(small_pres, + q_zone[QPRES] + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + + qleft(i,j+1,k,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qleft(i,j+1,k,QMAGY) = by(i,j+1,k); // By stuff + qleft(i,j+1,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + + } else { + qleft(i,j,k+1,QRHO) = amrex::max(small_dens, + q_zone[QRHO] + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qleft(i,j,k+1,QU) = q_zone[QU] + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qleft(i,j,k+1,QV) = q_zone[QV] + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qleft(i,j,k+1,QW) = q_zone[QW] + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + qleft(i,j,k+1,QPRES) = amrex::max(small_pres, + q_zone[QPRES] + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + + qleft(i,j,k+1,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qleft(i,j,k+1,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qleft(i,j,k+1,QMAGZ) = bz(i,j,k+1); // Bz stuff + } + + // right state at i-1/2 + qright(i,j,k,QRHO) = amrex::max(small_dens, + q_zone[QRHO] + 0.5_rt*summ_m[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qright(i,j,k,QU) = q_zone[QU] + 0.5_rt*summ_m[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qright(i,j,k,QV) = q_zone[QV] + 0.5_rt*summ_m[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qright(i,j,k,QW) = q_zone[QW] + 0.5_rt*summ_m[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + qright(i,j,k,QPRES) = amrex::max(small_pres, + q_zone[QPRES] + 0.5_rt*summ_m[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + + if (idir == 0) { + qright(i,j,k,QMAGX) = bx(i,j,k); // Bx stuff + qright(i,j,k,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qright(i,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + + } else if (idir == 1) { + qright(i,j,k,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qright(i,j,k,QMAGY) = by(i,j,k); // By stuff + qright(i,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + + } else { + qright(i,j,k,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qright(i,j,k,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qright(i,j,k,QMAGZ) = bz(i,j,k); // Bz stuff + } + + // species + for (int n = 0; n < NumSpec; n++) { + Real dL; + Real dR; + Real un; + Real dW; + + if (idir == 0) { + dL = s(i,j,k,QFS+n) - s(i-1,j,k,QFS+n); + dR = s(i+1,j,k,QFS+n) - s(i,j,k,QFS+n); + un = s(i,j,k,QU); + + } else if (idir == 1) { + dL = s(i,j,k,QFS+n) - s(i,j-1,k,QFS+n); + dR = s(i,j+1,k,QFS+n) - s(i,j,k,QFS+n); + un = s(i,j,k,QV); + + } else { + dL = s(i,j,k,QFS+n) - s(i,j,k-1,QFS+n); + dR = s(i,j,k+1,QFS+n) - s(i,j,k,QFS+n); + un = s(i,j,k,QW); + } + + slope(dW, dL, dR, flatn(i,j,k)); + + if (idir == 0) { + qleft(i+1,j,k,QFS+n) = q_zone[QFS+n] + 0.5_rt*(1.0_rt - dtdx*un) * dW; + } else if (idir == 1) { + qleft(i,j+1,k,QFS+n) = q_zone[QFS+n] + 0.5_rt*(1.0_rt - dtdx*un) * dW; + } else { + qleft(i,j,k+1,QFS+n) = q_zone[QFS+n] + 0.5_rt*(1.0_rt - dtdx*un) * dW; + } + qright(i,j,k,QFS) = q_zone[QFS+n] - 0.5_rt*(1.0_rt + dtdx*un) * dW; + } + + // rho e + eos_t eos_state; + + if (idir == 0) { + eos_state.rho = qleft(i+1,j,k,QRHO); + eos_state.p = qleft(i+1,j,k,QPRES); + eos_state.T = s(i,j,k,QTEMP); // some initial guess? + for (int n = 0; n < NQ; n++) { + eos_state.xn[n] = qleft(i+1,j,k,QFS+n); + } + eos(eos_input_rp, eos_state); + qleft(i+1,j,k,QREINT) = eos_state.e * eos_state.rho; + + } else if (idir == 1) { + eos_state.rho = qleft(i,j+1,k,QRHO); + eos_state.p = qleft(i,j+1,k,QPRES); + eos_state.T = s(i,j,k,QTEMP); // some initial guess? + for (int n = 0; n < NQ; n++) { + eos_state.xn[n] = qleft(i,j+1,k,QFS+n); + } + eos(eos_input_rp, eos_state); + qleft(i,j+1,k,QREINT) = eos_state.e * eos_state.rho; + + } else { + eos_state.rho = qleft(i,j,k+1,QRHO); + eos_state.p = qleft(i,j,k+1,QPRES); + eos_state.T = s(i,j,k,QTEMP); // some initial guess? + for (int n = 0; n < NQ; n++) { + eos_state.xn[n] = qleft(i,j,k+1,QFS+n); + } + eos(eos_input_rp, eos_state); + qleft(i,j,k+1,QREINT) = eos_state. e * eos_state.rho; + } + + eos_state.rho = qright(i,j,k,QRHO); + eos_state.p = qright(i,j,k,QPRES); + for (int n = 0; n < NQ; n++) { + eos_state.xn[n] = qright(i,j,k,QFS+n); + } + + eos(eos_input_rp, eos_state); + qright(i,j,k,QREINT) = eos_state.e * eos_state.rho; + + // add source terms + if (idir == 0) { + qleft(i+1,j,k,QRHO) = amrex::max(small_dens, + qleft(i+1,j,k,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)); + qleft(i+1,j,k,QU) = qleft(i+1,j,k,QU) + 0.5_rt*dt*srcQ(i,j,k,QU); + qleft(i+1,j,k,QV) = qleft(i+1,j,k,QV) + 0.5_rt*dt*srcQ(i,j,k,QV); + qleft(i+1,j,k,QW) = qleft(i+1,j,k,QW) + 0.5_rt*dt*srcQ(i,j,k,QW); + qleft(i+1,j,k,QPRES) = qleft(i+1,j,k,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES); + qleft(i+1,j,k,QREINT) = qleft(i+1,j,k,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT); + + } else if (idir == 1) { + qleft(i,j+1,k,QRHO) = amrex::max(small_dens, + qleft(i,j+1,k,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)); + qleft(i,j+1,k,QU) = qleft(i,j+1,k,QU) + 0.5_rt*dt*srcQ(i,j,k,QU); + qleft(i,j+1,k,QV) = qleft(i,j+1,k,QV) + 0.5_rt*dt*srcQ(i,j,k,QV); + qleft(i,j+1,k,QW) = qleft(i,j+1,k,QW) + 0.5_rt*dt*srcQ(i,j,k,QW); + qleft(i,j+1,k,QPRES) = qleft(i,j+1,k,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES); + qleft(i,j+1,k,QREINT) = qleft(i,j+1,k,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT); + + } else { + qleft(i,j,k+1,QRHO) = max(small_dens, qleft(i,j,k+1,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)); + qleft(i,j,k+1,QU) = qleft(i,j,k+1,QU) + 0.5_rt*dt*srcQ(i,j,k,QU); + qleft(i,j,k+1,QV) = qleft(i,j,k+1,QV) + 0.5_rt*dt*srcQ(i,j,k,QV); + qleft(i,j,k+1,QW) = qleft(i,j,k+1,QW) + 0.5_rt*dt*srcQ(i,j,k,QW); + qleft(i,j,k+1,QPRES) = qleft(i,j,k+1,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES); + qleft(i,j,k+1,QREINT) = qleft(i,j,k+1,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT); + } + + qright(i,j,k,QRHO) = max(small_dens, qright(i,j,k,QRHO) + 0.5_rt*dt*srcQ(i,j,k,QRHO)); + qright(i,j,k,QU) = qright(i,j,k,QU) + 0.5_rt*dt*srcQ(i,j,k,QU); + qright(i,j,k,QV) = qright(i,j,k,QV) + 0.5_rt*dt*srcQ(i,j,k,QV); + qright(i,j,k,QW) = qright(i,j,k,QW) + 0.5_rt*dt*srcQ(i,j,k,QW); + qright(i,j,k,QPRES) = qright(i,j,k,QPRES) + 0.5_rt*dt*srcQ(i,j,k,QPRES); + qright(i,j,k,QREINT) = qright(i,j,k,QREINT) + 0.5_rt*dt*srcQ(i,j,k,QREINT); + + }); +} + !======================================== Minmod TVD slope limiter ========================================= subroutine minmod(dW, WR, WL) @@ -449,293 +466,4 @@ Castro::plm(const Box& bx, endif end subroutine slope - - !=========================================== Evals ========================================================= - - subroutine evals(lam, qaux, Q, dir) - - use amrex_fort_module, only : rt => amrex_real - use network, only: nspec - implicit none - - real(rt), intent(in) :: Q(NQ), qaux(NQAUX) - real(rt), intent(out) :: lam(NEIGN) !7 waves - integer, intent(in) :: dir !Choose direction, 1 for x, 2 for y, 3 for z - - !The characteristic speeds of the system - real(rt) :: cfx, cfy, cfz, cax, cay, caz, csx, csy, csz, ca, as - - ! speeds - as = qaux(QC) * qaux(QC) - - ! Alfven - ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) - cax = (Q(QMAGX)**2)/Q(QRHO) - cay = (Q(QMAGY)**2)/Q(QRHO) - caz = (Q(QMAGZ)**2)/Q(QRHO) - - ! Slow - csx = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cax)) - csy = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cay)) - csz = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*caz)) - - ! Fast - cfx = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cax)) - cfy = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cay)) - cfz = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*caz)) - - if(dir.eq.1) then - - !Ax eigenvalues - lam(1) = Q(QU) - sqrt(cfx) - lam(2) = Q(QU) - sqrt(cax) - lam(3) = Q(QU) - sqrt(csx) - lam(4) = Q(QU) - lam(5) = Q(QU) + sqrt(csx) - lam(6) = Q(QU) + sqrt(cax) - lam(7) = Q(QU) + sqrt(cfx) - - elseif(dir.eq.2) then - - !Ay eigenvalues - lam(1) = Q(QV) - sqrt(cfy) - lam(2) = Q(QV) - sqrt(cay) - lam(3) = Q(QV) - sqrt(csy) - lam(4) = Q(QV) - lam(5) = Q(QV) + sqrt(csy) - lam(6) = Q(QV) + sqrt(cay) - lam(7) = Q(QV) + sqrt(cfy) - - else - - !Az eigenvalues - lam(1) = Q(QW) - sqrt(cfz) - lam(2) = Q(QW) - sqrt(caz) - lam(3) = Q(QW) - sqrt(csz) - lam(4) = Q(QW) - lam(5) = Q(QW) + sqrt(csz) - lam(6) = Q(QW) + sqrt(caz) - lam(7) = Q(QW) + sqrt(cfz) - endif - - end subroutine evals - - !====================================== Left Eigenvectors =============================================== - - !x direction - subroutine evecx(leig, reig, qaux, Q) - use amrex_fort_module, only : rt => amrex_real - use network, only : nspec - - implicit none - - !returnes Leig, where the rows are the left eigenvectors of the characteristic matrix Ax - real(rt), intent(in) ::Q(NQ), qaux(NQAUX) - real(rt), intent(out) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN) - - !The characteristic speeds of the system - real(rt) :: cfx, cax, csx, ca, as, S, N - real(rt) :: cff, css, Qf, Qs, AAf, AAs, alf, als, bety, betz - - ! Speeds - - as = qaux(QC) * qaux(QC) - - ! Alfven - ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) - cax = (Q(QMAGX)**2)/Q(QRHO) - - ! Slow - csx = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cax)) - - ! Fast - cfx = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cax)) - - !useful constants - alf = sqrt((as - csx)/(cfx - csx)) - als = sqrt((cfx - as)/(cfx - csx)) - if(cfx - as .lt. 0.d0) als = 0.d0 - if(as - csx .lt. 0.d0) alf = 0.d0 - - if(abs(Q(QMAGY)).le. 1.d-14 .and.abs(Q(QMAGZ)).le. 1.d-14) then - bety = 1.d0/sqrt(2.d0) - betz = bety - else - bety = Q(QMAGY)/(sqrt(Q(QMAGY)**2 + Q(QMAGZ)**2)) - betz = Q(QMAGZ)/(sqrt(Q(QMAGY)**2 + Q(QMAGZ)**2)) - endif - - cff = sqrt(cfx)*alf - css = sqrt(csx)*als - S = sign(1.0d0, Q(QMAGX)) - Qf = sqrt(cfx)*alf*S - Qs = sqrt(csx)*als*S - N = 0.5_rt/as - AAf = sqrt(as)*alf*sqrt(Q(QRHO)) - AAs = sqrt(as)*als*sqrt(Q(QRHO)) - - - leig(1,:) = (/0.d0, -N*Cff, N*Qs*bety, N*Qs*betz, N*alf/Q(QRHO), N*AAs*bety/Q(QRHO), N*AAs*betz/Q(QRHO)/) !u - cf - leig(2,:) = (/0.d0, 0.d0, -0.5_rt*betz, 0.5_rt*bety, 0.d0, -0.5_rt*S*betz/(sqrt(Q(QRHO))), 0.5_rt*bety*S/(sqrt(Q(QRHO)))/) !u - cAx - leig(3,:) = (/0.d0, -N*Css, -N*Qf*bety, -N*Qf*betz, N*als/Q(QRHO), -N*AAf*bety/Q(QRHO), -N*AAf*betz/Q(QRHO)/) !u - cs - leig(4,:) = (/1.d0, 0.d0, 0.d0, 0.d0, -1.d0/as, 0.d0, 0.d0/) !u - leig(5,:) = (/0.d0, N*Css, N*Qf*bety, N*Qf*betz, N*als/Q(QRHO), -N*AAf*bety/Q(QRHO), -N*AAf*betz/Q(QRHO)/) !u + cs - leig(6,:) = (/0.d0, 0.d0, 0.5_rt*betz, -0.5_rt*bety, 0.d0, -0.5_rt*betz*S/(sqrt(Q(QRHO))), 0.5_rt*bety*S/(sqrt(Q(QRHO)))/) !u + cAx - leig(7,:) = (/0.d0, N*Cff, -N*Qs*bety, -N*Qs*betz, N*alf/Q(QRHO), N*AAs*bety/Q(QRHO), N*AAs*betz/Q(QRHO)/) !u + cf - - ! u - cf u - Cax u - cs u u + cs u + Cax u + cf - reig(IEIGN_RHO,:) = (/Q(QRHO)*alf, 0.d0, Q(QRHO)*als, 1.d0, Q(QRHO)*als, 0.d0, Q(QRHO)*alf/) - reig(IEIGN_U,:) = (/-cff , 0.d0, -css, 0.d0, css, 0.d0, cff/) - reig(IEIGN_V,:) = (/Qs*bety, -betz, -Qf*bety, 0.d0, Qf*bety, betz, -Qs*bety/) - reig(IEIGN_W,:) = (/Qs*betz, bety, -Qf*betz, 0.d0, Qf*betz, -bety, -Qs*betz/) - reig(IEIGN_P,:) = (/Q(QRHO)*as*alf, 0.d0, Q(QRHO)*as*als, 0.d0 , Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*alf/) - reig(IEIGN_BT,:) = (/AAs*bety, -betz*S*sqrt(Q(QRHO)), -AAf*bety, 0.d0 , -AAf*bety, -betz*S*sqrt(Q(QRHO)), AAs*bety/) - reig(IEIGN_BTT,:) = (/AAs*betz, bety*S*sqrt(Q(QRHO)), -AAf*betz, 0.d0, -AAf*betz, bety*S*sqrt(Q(QRHO)), AAs*betz/) - - - end subroutine evecx - - !y direction - subroutine evecy(leig, reig, qaux, Q) - use amrex_fort_module, only : rt => amrex_real - use network, only : nspec - - implicit none - - !returnes Leig, where the rows are the left eigenvectors of the characteristic matrix Ay - real(rt), intent(in) :: Q(NQ), qaux(NQAUX) - real(rt), intent(out) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN) - - !The characteristic speeds of the system - real(rt) :: cfy, cay, csy, ca, as, S, N - real(rt) :: cff, css, Qf, Qs, AAf, AAs, alf, als, betx, betz - - - ! Speeds - as = qaux(QC) * qaux(QC) - - ! Alfven - ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) - cay = (Q(QMAGY)**2)/Q(QRHO) - - ! Slow - csy = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cay)) - - ! Fast - cfy = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cay)) - - !useful constants - alf = sqrt((as - csy)/(cfy - csy)) - als = sqrt((cfy - as)/(cfy - csy)) - if(as - csy .lt. 0.d0) alf = 0.d0 - if(cfy - as .lt. 0.d0) als = 0.d0 - - if(abs(Q(QMAGX)).le. 1.d-14 .and.abs(Q(QMAGZ)).le. 1.d-14) then - betx = 1.d0/sqrt(2.d0) - betz = betx - else - betx = Q(QMAGX)/(sqrt(Q(QMAGX)**2 + Q(QMAGZ)**2)) - betz = Q(QMAGZ)/(sqrt(Q(QMAGX)**2 + Q(QMAGZ)**2)) - endif - - cff = sqrt(cfy)*alf - css = sqrt(csy)*als - S = sign(1.0d0, Q(QMAGY)) - Qf = sqrt(cfy)*alf*S - Qs = sqrt(csy)*als*S - AAf = sqrt(as)*alf*sqrt(Q(QRHO)) - AAs = sqrt(as)*als*sqrt(Q(QRHO)) - N = 0.5_rt/as - - !Need to double check the rows - leig(1,:) = (/0.d0, N*Qs*betx, -N*Cff , N*Qs*betz, N*alf/Q(QRHO), N*AAs*betx/Q(QRHO), N*AAs*betz/Q(QRHO)/) ! v - cf - leig(2,:) = (/0.d0, -0.5_rt*betz, 0.d0, 0.5_rt*betx, 0.d0, -0.5_rt*betz*S/(sqrt(Q(QRHO))), 0.5_rt*betx*S/(sqrt(Q(QRHO)))/) ! v - cAy - leig(3,:) = (/0.d0, -N*Qf*betx, -N*Css, -N*Qf*betz, N*als/Q(QRHO), -N*AAf*betx/Q(QRHO), -N*AAf*betz/Q(QRHO)/) ! v - cs - leig(4,:) = (/1.d0, 0.d0, 0.d0, 0.d0, -1.d0/as, 0.d0, 0.d0/) ! v - leig(5,:) = (/0.d0, N*Qf*betx, N*Css, N*Qf*betz, N*als/Q(QRHO), -N*AAf*betx/Q(QRHO), -N*AAf*betz/Q(QRHO)/) ! v + cs - leig(6,:) = (/0.d0, 0.5_rt*betz, 0.d0, -0.5_rt*betx, 0.d0, -0.5_rt*betz*S/(sqrt(Q(QRHO))), 0.5_rt*betx*S/(sqrt(Q(QRHO)))/) ! v + cAy - leig(7,:) = (/0.d0, -N*Qs*betx, N*Cff, -N*Qs*betz, N*alf/Q(QRHO), N*AAs*betx/Q(QRHO), N*AAs*betz/Q(QRHO)/) ! v + cf - - ! v - cf v - Cay v - cs v v + cs v + Cay v + cf - reig(IEIGN_RHO,:) = (/Q(QRHO)*alf, 0.d0, Q(QRHO)*als, 1.d0, Q(QRHO)*als, 0.d0, Q(QRHO)*alf/) - reig(IEIGN_V,:) = (/-cff, 0.d0, -css, 0.d0 , css, 0.d0, cff/) - reig(IEIGN_U,:) = (/Qs*betx, -betz, -Qf*betx, 0.d0 , Qf*betx, betz, -Qs*betx/) - reig(IEIGN_W,:) = (/Qs*betz, betx, -Qf*betz, 0.d0 , Qf*betz, -betx , -Qs*betz/) - reig(IEIGN_P,:) = (/Q(QRHO)*as*alf, 0.d0, Q(QRHO)*as*als, 0.d0 , Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*alf/) - reig(IEIGN_BT,:) = (/AAs*betx, -betz*S*sqrt(Q(QRHO)), -AAf*betx, 0.d0 , -AAf*betx, -betz*S*sqrt(Q(QRHO)) , AAs*betx/) - reig(IEIGN_BTT,:) = (/AAs*betz, betx*S*sqrt(Q(QRHO)), -AAf*betz, 0.d0, -AAf*betz, betx*S*sqrt(Q(QRHO)), AAs*betz/) - - end subroutine evecy - - !z direction - subroutine evecz(leig, reig, qaux, Q) - use amrex_fort_module, only : rt => amrex_real - use network, only : nspec - - implicit none - - !returnes Leig, where the rows are the left eigenvectors of the characteristic matrix Az - real(rt), intent(in) :: Q(NQ), qaux(NQAUX) - real(rt), intent(out) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN) - - !The characteristic speeds of the system - real(rt) :: cfz, caz, csz, ca, as, S, N - real(rt) :: cff, css, Qf, Qs, AAf, AAs, alf, als, betx, bety - - ! Speeds - as = qaux(QC) * qaux(QC) - - ! Alfven - ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) - caz = (Q(QMAGZ)**2)/Q(QRHO) - - ! Slow - csz = 0.5_rt*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*caz)) - - ! Fast - cfz = 0.5_rt*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*caz)) - - !useful constants - alf = sqrt((as - csz)/(cfz - csz)) - als = sqrt((cfz - as)/(cfz - csz)) - - if(cfz - as .lt. 0.d0) als = 0.d0 - - if(abs(Q(QMAGX)).le. 1.d-14 .and.abs(Q(QMAGY)).le. 1.d-14) then - betx = 1.d0/sqrt(2.d0) - bety = betx - else - betx = Q(QMAGX)/(sqrt(Q(QMAGX)**2 + Q(QMAGY)**2)) - bety = Q(QMAGY)/(sqrt(Q(QMAGX)**2 + Q(QMAGY)**2)) - endif - - cff = sqrt(cfz)*alf - css = sqrt(csz)*als - S = sign(1.0d0, Q(QMAGZ)) - Qf = sqrt(cfz)*alf*S - Qs = sqrt(csz)*als*S - AAf = sqrt(as)*alf*sqrt(Q(QRHO)) - AAs = sqrt(as)*als*sqrt(Q(QRHO)) - N = 0.5_rt/as - - !Need to double check the order - leig(1,:) = (/0.d0, N*Qs*betx, N*Qs*bety, -N*Cff, N*alf/Q(QRHO) , N*AAs*betx/Q(QRHO), N*AAs*bety/Q(QRHO)/) !w - cf - leig(2,:) = (/0.d0, -0.5_rt*bety, 0.5_rt*betx, 0.d0, 0.d0, -0.5_rt*S*bety/(sqrt(Q(QRHO))) , 0.5_rt*betx*S/(sqrt(Q(QRHO)))/) !w - cAz - leig(3,:) = (/0.d0, -N*Qf*betx, -N*Qf*bety, -N*Css, N*als/Q(QRHO) , -N*AAf*betx/Q(QRHO), -N*AAf*bety/Q(QRHO)/) !w - cs - leig(4,:) = (/1.d0, 0.d0 , 0.d0, 0.d0, -1.d0/as, 0.d0, 0.d0/) !w - leig(5,:) = (/0.d0, N*Qf*betx, N*Qf*bety, N*Css, N*als/Q(QRHO) , -N*AAf*betx/Q(QRHO), -N*AAf*bety/Q(QRHO)/) !w + cs - leig(6,:) = (/0.d0, 0.5_rt*bety , -0.5_rt*betx, 0.0d0, 0.d0 , -0.5_rt*bety*S/(sqrt(Q(QRHO))) , 0.5_rt*betx*S/(sqrt(Q(QRHO))) /) !w + cAz - leig(7,:) = (/0.d0, -N*Qs*betx, -N*Qs*bety, N*Cff , N*alf/Q(QRHO) , N*AAs*betx/Q(QRHO) , N*AAs*bety/Q(QRHO) /) !w + cf - - ! w - cf w - Caz w - cs w w + cs w + Caz w + cf - reig(IEIGN_RHO,:) = (/Q(QRHO)*alf, 0.d0, Q(QRHO)*als, 1.d0, Q(QRHO)*als, 0.d0, Q(QRHO)*alf/) - reig(IEIGN_W,:) = (/-cff , 0.d0, -css, 0.d0, css, 0.d0 , cff/) - reig(IEIGN_U,:) = (/Qs*betx, -bety, -Qf*betx, 0.d0, Qf*betx, bety, -Qs*betx/) - reig(IEIGN_V,:) = (/Qs*bety, betx, -Qf*bety, 0.d0, Qf*bety, -betx , -Qs*bety/) - reig(IEIGN_P,:) = (/Q(QRHO)*as*alf, 0.d0, Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*alf/) - reig(IEIGN_BT,:) = (/AAs*betx, -bety*S*sqrt(Q(QRHO)), -AAf*betx, 0.d0, -AAf*betx, -bety*S*sqrt(Q(QRHO)), AAs*betx/) - reig(IEIGN_BTT,:) = (/AAs*bety, betx*S*sqrt(Q(QRHO)), -AAf*bety, 0.d0, -AAf*bety, betx*S*sqrt(Q(QRHO)), AAs*bety/) - - end subroutine evecz - end module mhd_plm_module diff --git a/Source/mhd/mhd_util.H b/Source/mhd/mhd_util.H index daee0378ba..6c9d6f64fb 100644 --- a/Source/mhd/mhd_util.H +++ b/Source/mhd/mhd_util.H @@ -11,15 +11,15 @@ constexpr int UMAGZ = NUM_STATE+2; constexpr int NEIGN = 7; -constexpr int IEIGN_RHO = 1; -constexpr int IEIGN_U = 2; -constexpr int IEIGN_V = 3; -constexpr int IEIGN_W = 4; -constexpr int IEIGN_P = 5; +constexpr int IEIGN_RHO = 0; +constexpr int IEIGN_U = 1; +constexpr int IEIGN_V = 2; +constexpr int IEIGN_W = 3; +constexpr int IEIGN_P = 4; // perpendicular magnetic field components -constexpr int IEIGN_BT = 6; -constexpr int IEIGN_BTT = 7; +constexpr int IEIGN_BT = 5; +constexpr int IEIGN_BTT = 6; // sound speed calc for ideal MHD void From 8011c33a6c45c68dd26bfa54ebe9a686b9e65a37 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 19:20:40 -0400 Subject: [PATCH 11/23] port the eigenstuff to C++ --- Source/mhd/mhd_eigen.H | 620 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 620 insertions(+) create mode 100644 Source/mhd/mhd_eigen.H diff --git a/Source/mhd/mhd_eigen.H b/Source/mhd/mhd_eigen.H new file mode 100644 index 0000000000..41c6a7363c --- /dev/null +++ b/Source/mhd/mhd_eigen.H @@ -0,0 +1,620 @@ +#ifndef CASTRO_MHD_EIGEN_H +#define CASTRO_MHD_EIGEN_H + +void +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +Castro::evals(Real* lam, const Real as_in, Real* Q, const int dir) { + + // The characteristic speeds of the system + + // Alfven + + Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; + + int QUN; + Real cad; // acoustic + Real cs; // slow + Real cf; // fast + + Real as = as_in * as_in; + + if (dir == 0) { + QUN = QU; + cad = (Q[QMAGX]*Q[QMAGX]) / Q[QRHO]; + cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cax)); + cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cax)); + + } else if (dir == 1) { + QUN = QV; + cad = (Q[QMAGY]*Q[QMAGY]) / Q[QRHO]; + cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cay)); + cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cay)); + + } else { + QUN = QW; + cad = (Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; + cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*caz)); + cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*caz)); + + } + + // eigenvalues + lam[0] = Q[QUN] - std::sqrt(cf); + lam[1] = Q[QUN] - std::sqrt(cad); + lam[2] = Q[QUN] - std::sqrt(cs); + lam[3] = Q[QUN]; + lam[4] = Q[QUN] + std::sqrt(cs); + lam[5] = Q[QUN] + std::sqrt(cad); + lam[6] = Q[QUN] + std::sqrt(cf); + +} + + +void +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +Castro::evecx(Array2d const& leig, + Array2d const& reig, + const Real as_in, + Real* Q) { + + // returns Leig, where the rows are the left eigenvectors of the characteristic matrix Ax + + // The characteristic speeds of the system + + Real as = as_in * as_in; + + // Alfven + + Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; + Real cax = (Q[QMAGX]*Q[QMAGX]) / Q[QRHO]; + + // Slow + + Real csx = 0.5_rt*((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cax)); + + // Fast + + Real cfx = 0.5_rt*((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cax)); + + // useful constants + + Real alf = std::sqrt((as - csx)/(cfx - csx)); + Real als = std::sqrt((cfx - as)/(cfx - csx)); + + if (cfx - as < 0.d0) { + als = 0.0_rt; + } + + if (as - csx < 0.d0) { + alf = 0.0_rt; + } + + Real bety; + Real betz; + + if (std::abs(Q[QMAGY]) <= 1.e-14_rt && std::abs(Q[QMAGZ]) <= 1.e-14_rt) { + bety = 1.0_rt / std::sqrt(2.0_rt); + betz = bety; + + } else { + bety = Q[QMAGY] / (std::sqrt(Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ])); + betz = Q[QMAGZ] / (std::sqrt(Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ])); + } + + Real cff = std::sqrt(cfx) * alf; + Real css = std::sqrt(csx) * als; + + Real S = std::copysign(1.0_rt, Q[QMAGX]); + + Real Qf = std::sqrt(cfx) * alf * S; + Real Qs = std::sqrt(csx) * als * S; + + Real N = 0.5_rt / as; + + Real AAf = std::sqrt(as) * alf * std::sqrt(Q[QRHO]); + Real AAs = std::sqrt(as) * als * std::sqrt(Q[QRHO]); + + + // u - cf wave + leig(0, IEIGN_RHO) = 0.0; + leig(0, IEIGN_U) = -N*Cff; + leig(0, IEIGN_V) = N*Qs*bety; + leig(0, IEIGN_W) = N*Qs*betz; + leig(0, IEIGN_P) = N*alf/Q(QRHO); + leig(0, IEIGN_BT) = N*AAs*bety/Q(QRHO); + leig(0, IEIGN_BTT) = N*AAs*betz/Q(QRHO); + + // u - cax + leig(1, IEIGN_RHO) = 0.0; + leig(1, IEIGN_U) = 0.0; + leig(1, IEIGN_V) = -0.5_rt*betz; + leig(1, IEIGN_W) = 0.5_rt*bety; + leig(1, IEIGN_P) = 0.d0; + leig(1, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q[QRHO]); + leig(1, IEIGN_BTT) = 0.5_rt*bety*S/std::sqrt(Q[QRHO]); + + // u - cs + leig(2, IEIGN_RHO) = 0.0; + leig(2, IEIGN_U) = -N*Css; + leig(2, IEIGN_V) = -N*Qf*bety; + leig(2, IEIGN_W) = -N*Qf*betz; + leig(2, IEIGN_P) = N*als/Q[QRHO]; + leig(2, IEIGN_BT) = -N*AAf*bety/Q[QRHO]; + leig(2, IEIGN_BTT) = -N*AAf*betz/Q[QRHO]; + + // u + leig(3, IEIGN_RHO) = 1.0; + leig(3, IEIGN_U) = 0.0; + leig(3, IEIGN_V) = 0.0; + leig(3, IEIGN_W) = 0.0; + leig(3, IEIGN_P) = -1.0_rt/as; + leig(3, IEIGN_BT) = 0.0; + leig(3, IEIGN_BTT) = 0.0; + + // u + cs + leig(4, IEIGN_RHO) = 0.0; + leig(4, IEIGN_U) = N*Css; + leig(4, IEIGN_V) = N*Qf*bety; + leig(4, IEIGN_W) = N*Qf*betz; + leig(4, IEIGN_P) = N*als/Q[QRHO]; + leig(4, IEIGN_BT) = -N*AAf*bety/Q[QRHO]; + leig(4, IEIGN_BTT) = -N*AAf*betz/Q[QRHO]; + + // u + cax + leig(5, IEIGN_RHO) = 0.0; + leig(5, IEIGN_U) = 0.0; + leig(5, IEIGN_V) = 0.5_rt*betz; + leig(5, IEIGN_W) = -0.5_rt*bety; + leig(5, IEIGN_P) = 0.0; + leig(5, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q[QRHO]); + leig(5, IEIGN_BTT) = 0.5_rt*bety*S/std::sqrt(Q[QRHO]); + + // u + cf + leig(6, IEIGN_RHO) = 0.0; + leig(6, IEIGN_U) = N*Cff; + leig(6, IEIGN_V) = -N*Qs*bety; + leig(6, IEIGN_W) = -N*Qs*betz; + leig(6, IEIGN_P) = N*alf/Q[QRHO]; + leig(6, IEIGN_BT) = N*AAs*bety/Q[QRHO]; + leig(7, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; + + // u - cf ; u - Cax ; u - cs ; u ; u + cs ; u + Cax ; u + cf + + reig(IEIGN_RHO, 0) = Q[QRHO]*alf; + reig(IEIGN_RHO, 1) = 0.0; + reig(IEIGN_RHO, 2) = Q[QRHO]*als; + reig(IEIGN_RHO, 3) = 1.0_rt; + reig(IEIGN_RHO, 4) = Q[QRHO]*als; + reig(IEIGN_RHO, 5) = 0.0; + reig(IEIGN_RHO, 6) = Q[QRHO]*alf; + + reig(IEIGN_U, 0) = -cff; + reig(IEIGN_U, 1) = 0.0; + reig(IEIGN_U, 2) = -css; + reig(IEIGN_U, 3) = 0.0; + reig(IEIGN_U, 4) = css; + reig(IEIGN_U, 5) = 0.0; + reig(IEIGN_U, 6) = cff; + + reig(IEIGN_V, 0) = Qs*bety; + reig(IEIGN_V, 1) = -betz; + reig(IEIGN_V, 2) = -Qf*bety; + reig(IEIGN_V, 3) = 0.0; + reig(IEIGN_V, 4) = Qf*bety; + reig(IEIGN_V, 5) = betz; + reig(IEIGN_V, 6) = -Qs*bety; + + reig(IEIGN_W, 0) = Qs*betz; + reig(IEIGN_W, 1) = bety; + reig(IEIGN_W, 2) = -Qf*betz; + reig(IEIGN_W, 3) = 0.0; + reig(IEIGN_W, 4) = Qf*betz; + reig(IEIGN_W, 5) = -bety; + reig(IEIGN_W, 6) = -Qs*betz; + + reig(IEIGN_P, 0) = Q[QRHO]*as*alf; + reig(IEIGN_P, 1) = 0.0; + reig(IEIGN_P, 2) = Q[QRHO]*as*als; + reig(IEIGN_P, 3) = 0.0; + reig(IEIGN_P, 4) = Q[QRHO]*as*als; + reig(IEIGN_P, 5) = 0.0; + reig(IEIGN_P, 6) = Q[QRHO]*as*alf; + + reig(IEIGN_BT, 0) = AAs*bety; + reig(IEIGN_BT, 1) = -betz*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 2) = -AAf*bety; + reig(IEIGN_BT, 3) = 0.0; + reig(IEIGN_BT, 4) = -AAf*bety; + reig(IEIGN_BT, 5) = -betz*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 6) = AAs*bety; + + reig(IEIGN_BTT, 0) = AAs*betz; + reig(IEIGN_BTT, 1) = bety*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 2) = -AAf*betz; + reig(IEIGN_BTT, 3) = 0.0; + reig(IEIGN_BTT, 4) = -AAf*betz; + reig(IEIGN_BTT, 5) = bety*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 6) = AAs*betz; + +} + + +void +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +Castro::evecy(Array2d const& leig, + Array2d const& reig, + const Real as_in, + Real* Q) { + + + // returns Leig, where the rows are the left eigenvectors of the characteristic matrix Ay + + // The characteristic speeds of the system + + Real as = as_in * as_in; + + // Alfven + + Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; + Real cay = (Q[QMAGY]*Q[QMAGY]) / Q[QRHO]; + + // Slow + + Real csy = 0.5_rt*((as + ca) - std::sqrt((as + ca)**2 - 4.0_rt*as*cay)); + + // Fast + + Real cfy = 0.5_rt*((as + ca) + std::sqrt((as + ca)**2 - 4.0_rt*as*cay)); + + // useful constants + + Real alf = std::sqrt((as - csy)/(cfy - csy)); + Real als = std::sqrt((cfy - as)/(cfy - csy)); + + if (as - csy < 0.0) { + alf = 0.0_rt; + } + + if (cfy - as < 0.0) { + als = 0.0_rt; + } + + Real betx; + Real betz; + + if(std::abs(Q[QMAGX]) <= 1.e-14_rt && std::abs(Q[QMAGZ]) <= 1.e-14_rt) { + betx = 1.0_rt / std::sqrt(2.0_rt); + betz = betx; + + } else { + betx = Q[QMAGX] / std::sqrt(Q[QMAGX]*Q[QMAGX] + Q[QMAGZ]*Q[QMAGZ]); + betz = Q[QMAGZ] / std::sqrt(Q[QMAGX]*Q[QMAGX] + Q[QMAGZ]*Q[QMAGZ]); + } + + Real cff = std::sqrt(cfy) * alf; + Real css = std::sqrt(csy) * als; + + Real S = std::copysign(1.0_rt, Q[QMAGY]); + + Real Qf = std::sqrt(cfy) * alf * S; + Real Qs = std::sqrt(csy) * als * S; + + Real N = 0.5_rt / as; + + Real AAf = std::sqrt(as) * alf * std::sqrt(Q[QRHO]); + Real AAs = std::sqrt(as) * als * std::sqrt(Q[QRHO]); + + + // v - cf + leig(0, IEIGN_RHO) = 0.0; + leig(0, IEIGN_U) = N*Qs*betx; + leig(0, IEIGN_V) = -N*Cff; + leig(0, IEIGN_W) = N*Qs*betz; + leig(0, IEIGN_P) = N*alf/Q[QRHO]; + leig(0, IEIGN_BT) = N*AAs*betx/Q[QRHO]; + leig(0, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; + + // v - cay + leig(1, IEIGN_RHO) = 0.0; + leig(1, IEIGN_U) = -0.5_rt*betz; + leig(1, IEIGN_V) = 0.0; + leig(1, IEIGN_W) = 0.5_rt*betx; + leig(1, IEIGN_P) = 0.0; + leig(1, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q[QRHO]); + leig(1, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q[QRHO]); + + // v - cs + leig(2, IEIGN_RHO) = 0.0; + leig(2, IEIGN_U) = -N*Qf*betx; + leig(2, IEIGN_V) = -N*Css; + leig(2, IEIGN_W) = -N*Qf*betz; + leig(2, IEIGN_P) = N*als/Q[QRHO]; + leig(2, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; + leig(2, IEIGN_BTT) = -N*AAf*betz/Q[QRHO]; + + // v + leig(3, IEIGN_RHO) = 1.0_rt; + leig(3, IEIGN_U) = 0.0; + leig(3, IEIGN_V) = 0.0; + leig(3, IEIGN_W) = 0.0; + leig(3, IEIGN_P) = -1.0_rt/as; + leig(3, IEIGN_BT) = 0.0; + leig(3, IEIGN_BTT) = 0.0; + + // v + cs + leig(4, IEIGN_RHO) = 0.0; + leig(4, IEIGN_U) = N*Qf*betx; + leig(4, IEIGN_V) = N*Css; + leig(4, IEIGN_W) = N*Qf*betz; + leig(4, IEIGN_P) = N*als/Q[QRHO]; + leig(4, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; + leig(4, IEIGN_BTT) = -N*AAf*betz/Q[QRHO]; + + // v + cay + leig(5, IEIGN_RHO) = 0.0; + leig(5, IEIGN_U) = 0.5_rt*betz; + leig(5, IEIGN_V) = 0.0; + leig(5, IEIGN_W) = -0.5_rt*betx; + leig(5, IEIGN_P) = 0.0; + leig(5, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q[QRHO]); + leig(5, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q[QRHO]); + + // v + cf + leig(6, IEIGN_RHO) = 0.0; + leig(6, IEIGN_U) = -N*Qs*betx; + leig(6, IEIGN_V) = N*Cff; + leig(6, IEIGN_W) = -N*Qs*betz; + leig(6, IEIGN_P) = N*alf/Q[QRHO]; + leig(6, IEIGN_BT) = N*AAs*betx/Q[QRHO]; + leig(6, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; + + // v - cf ; v - Cay ; v - cs ; v ; v + cs ; v + Cay ; v + cf + + reig(IEIGN_RHO, 0) = Q[QRHO]*alf; + reig(IEIGN_RHO, 1) = 0.0; + reig(IEIGN_RHO, 2) = Q[QRHO]*als; + reig(IEIGN_RHO, 3) = 1.0_rt; + reig(IEIGN_RHO, 4) = Q[QRHO]*als; + reig(IEIGN_RHO, 5) = 0.0; + reig(IEIGN_RHO, 6) = Q[QRHO]*alf; + + reig(IEIGN_V, 0) = -cff; + reig(IEIGN_V, 1) = 0.0; + reig(IEIGN_V, 2) = -css; + reig(IEIGN_V, 3) = 0.0; + reig(IEIGN_V, 4) = css; + reig(IEIGN_V, 5) = 0.0; + reig(IEIGN_V, 6) = cff; + + reig(IEIGN_U, 0) = Qs*betx; + reig(IEIGN_U, 1) = -betz; + reig(IEIGN_U, 2) = -Qf*betx; + reig(IEIGN_U, 3) = 0.0; + reig(IEIGN_U, 4) = Qf*betx; + reig(IEIGN_U, 5) = betz; + reig(IEIGN_U, 6) = -Qs*betx; + + reig(IEIGN_W, 0) = Qs*betz; + reig(IEIGN_W, 1) = betx; + reig(IEIGN_W, 2) = -Qf*betz; + reig(IEIGN_W, 3) = 0.0; + reig(IEIGN_W, 4) = Qf*betz; + reig(IEIGN_W, 5) = -betx; + reig(IEIGN_W, 6) = -Qs*betz; + + reig(IEIGN_P, 0) = Q[QRHO]*as*alf; + reig(IEIGN_P, 1) = 0.0; + reig(IEIGN_P, 2) = Q[QRHO]*as*als; + reig(IEIGN_P, 3) = 0.0; + reig(IEIGN_P, 4) = Q[QRHO]*as*als; + reig(IEIGN_P, 5) = 0.0; + reig(IEIGN_P, 6) = Q[QRHO]*as*alf; + + reig(IEIGN_BT, 0) = AAs*betx; + reig(IEIGN_BT, 1) = -betz*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 2) = -AAf*betx; + reig(IEIGN_BT, 3) = 0.0; + reig(IEIGN_BT, 4) = -AAf*betx; + reig(IEIGN_BT, 5) = -betz*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 6) = AAs*betx; + + reig(IEIGN_BTT, 0) = AAs*betz; + reig(IEIGN_BTT, 1) = betx*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 2) = -AAf*betz; + reig(IEIGN_BTT, 3) = 0.0; + reig(IEIGN_BTT, 4) = -AAf*betz; + reig(IEIGN_BTT, 5) = betx*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 6) = AAs*betz; + +} + + +void +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +Castro::evecz(Array2d const& leig, + Array2d const& reig, + const Real as_in, + Real* Q) { + + // returns Leig, where the rows are the left eigenvectors of the characteristic matrix Az + + // The characteristic speeds of the system + + Real as = as_in * as_in; + + // Alfven + + Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q{QMAGZ]) / Q[QRHO]; + Real caz = (Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; + + // Slow + + Real csz = 0.5_rt*((as + ca) - std::sqrt((as + ca)**2 - 4.0_rt*as*caz)); + + // Fast + + Real cfz = 0.5_rt*((as + ca) + std::sqrt((as + ca)**2 - 4.0_rt*as*caz)); + + // useful constants + + Real alf = std::sqrt((as - csz)/(cfz - csz)); + Real als = std::sqrt((cfz - as)/(cfz - csz)); + + if (cfz - as < 0.0) { + als = 0.0_rt; + } + + if (as - csz < 0.d0) { + alf = 0.0_rt; + } + + Real betx; + Real bety; + + if (std::abs(Q[QMAGX]) <= 1.e-14_rt && std::abs(Q[QMAGY]) <= 1.e-14_rt) { + betx = 1.0_rt/std::sqrt(2.0_rt); + bety = betx; + + } else { + betx = Q[QMAGX] / std::sqrt(Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY]); + bety = Q[QMAGY] / std::sqrt(Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY]); + } + + Real cff = std::sqrt(cfz) * alf; + Real css = std::sqrt(csz) * als; + + Real S = std::copysign(1.0_rt, Q[QMAGZ]); + + Real Qf = std::sqrt(cfz) * alf * S; + Real Qs = std::sqrt(csz) * als * S; + + Real N = 0.5_rt / as; + + Real AAf = std::sqrt(as) * alf * std::sqrt(Q[QRHO]); + Real AAs = std::sqrt(as) * als * std::sqrt(Q[QRHO]); + + + // w - cf + leig(0, IEIGN_RHO) = 0.0; + leig(0, IEIGN_U) = N*Qs*betx; + leig(0, IEIGN_V) = N*Qs*bety; + leig(0, IEIGN_W) = -N*Cff; + leig(0, IEIGN_P) = N*alf/Q[QRHO]; + leig(0, IEIGN_BT) = N*AAs*betx/Q[QRHO]; + leig(0, IEIGN_BTT) = N*AAs*bety/Q[QRHO]; + + // w - caz + leig(1, IEIGN_RHO) = 0.0; + leig(1, IEIGN_U) = -0.5_rt*bety; + leig(1, IEIGN_V) = 0.5_rt*betx; + leig(1, IEIGN_W) = 0.0; + leig(1, IEIGN_P) = 0.0; + leig(1, IEIGN_BT) = -0.5_rt*bety*S/std::sqrt(Q[QRHO]); + leig(1, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q[QRHO]); + + // w - cs + leig(2, IEIGN_RHO) = 0.0; + leig(2, IEIGN_U) = -N*Qf*betx; + leig(2, IEIGN_V) = -N*Qf*bety; + leig(2, IEIGN_W) = -N*Css; + leig(2, IEIGN_P) = N*als/Q[QRHO]; + leig(2, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; + leig(2, IEIGN_BTT) = -N*AAf*bety/Q[QRHO]; + + // w + leig(3, IEIGN_RHO) = 1.0_rt; + leig(3, IEIGN_U) = 0.0; + leig(3, IEIGN_V) = 0.0; + leig(3, IEIGN_W) = 0.0; + leig(3, IEIGN_P) = -1.0_rt/as; + leig(3, IEIGN_BT) = 0.0; + leig(3, IEIGN_BTT) = 0.0; + + // w + cs + leig(4, IEIGN_RHO) = 0.0; + leig(4, IEIGN_U) = N*Qf*betx; + leig(4, IEIGN_V) = N*Qf*bety; + leig(4, IEIGN_W) = N*Css; + leig(4, IEIGN_P) = N*als/Q[QRHO]; + leig(4, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; + leig(4, IEIGN_BTT) = -N*AAf*bety/Q[QRHO]; + + // w + caz + leig(5, IEIGN_RHO) = 0.0; + leig(5, IEIGN_U) = 0.5_rt*bety; + leig(5, IEIGN_V) = -0.5_rt*betx; + leig(5, IEIGN_W) = 0.0; + leig(5, IEIGN_P) = 0.0; + leig(5, IEIGN_BT) = -0.5_rt*bety*S/std::sqrt(Q[QRHO]); + leig(5, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q[QRHO]); + + // w + cf + leig(6, IEIGN_RHO) = 0.0; + leig(6, IEIGN_U) = -N*Qs*betx; + leig(6, IEIGN_V) = -N*Qs*bety; + leig(6, IEIGN_W) = N*Cff; + leig(6, IEIGN_P) = N*alf/Q[QRHO]; + leig(6, IEIGN_BT) = N*AAs*betx/Q[QRHO]; + leig(6, IEIGN_BTT) = N*AAs*bety/Q[QRHO]; + + // w - cf ; w - Caz ; w - cs ; w ; w + cs ; w + Caz ; w + cf + + reig(IEIGN_RHO, 0) = Q[QRHO]*alf; + reig(IEIGN_RHO, 1) = 0.0; + reig(IEIGN_RHO, 2) = Q[QRHO]*als; + reig(IEIGN_RHO, 3) = 1.0_rt; + reig(IEIGN_RHO, 4) = Q[QRHO]*als; + reig(IEIGN_RHO, 5) = 0.0; + reig(IEIGN_RHO, 6) = Q[QRHO]*alf; + + reig(IEIGN_W, 0) = -cff; + reig(IEIGN_W, 1) = 0.0; + reig(IEIGN_W, 2) = -css; + reig(IEIGN_W, 3) = 0.0; + reig(IEIGN_W, 4) = css; + reig(IEIGN_W, 5) = 0.0; + reig(IEIGN_W, 6) = cff; + + reig(IEIGN_U, 0) = Qs*betx; + reig(IEIGN_U, 1) = -bety; + reig(IEIGN_U, 2) = -Qf*betx; + reig(IEIGN_U, 3) = 0.0; + reig(IEIGN_U, 4) = Qf*betx; + reig(IEIGN_U, 5) = bety; + reig(IEIGN_U, 6) = -Qs*betx; + + reig(IEIGN_V, 0) = Qs*bety; + reig(IEIGN_V, 1) = betx; + reig(IEIGN_V, 2) = -Qf*bety; + reig(IEIGN_V, 3) = 0.0; + reig(IEIGN_V, 4) = Qf*bety; + reig(IEIGN_V, 5) = -betx; + reig(IEIGN_V, 6) = -Qs*bety; + + reig(IEIGN_P, 0) = Q[QRHO]*as*alf; + reig(IEIGN_P, 1) = 0.0; + reig(IEIGN_P, 2) = Q[QRHO]*as*als; + reig(IEIGN_P, 3) = 0.0; + reig(IEIGN_P, 4) = Q[QRHO]*as*als; + reig(IEIGN_P, 5) = 0.0; + reig(IEIGN_P, 6) = Q[QRHO]*as*alf; + + reig(IEIGN_BT, 0) = AAs*betx; + reig(IEIGN_BT, 1) = -bety*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 2) = -AAf*betx; + reig(IEIGN_BT, 3) = 0.0; + reig(IEIGN_BT, 4) = -AAf*betx; + reig(IEIGN_BT, 5) = -bety*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 6) = AAs*betx; + + reig(IEIGN_BTT, 0) = AAs*bety; + reig(IEIGN_BTT, 1) = betx*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 2) = -AAf*bety; + reig(IEIGN_BTT, 3) = 0.0; + reig(IEIGN_BTT, 4) = -AAf*bety; + reig(IEIGN_BTT, 5) = betx*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 6) = AAs*bety; + +} + +#endif From ea27c20063557b34655ab8d60acb00843dd4c73f Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 20:49:28 -0400 Subject: [PATCH 12/23] remove more headers --- Source/mhd/Castro_mhd_F.H | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Source/mhd/Castro_mhd_F.H b/Source/mhd/Castro_mhd_F.H index e781a29616..dacdcd7e9e 100644 --- a/Source/mhd/Castro_mhd_F.H +++ b/Source/mhd/Castro_mhd_F.H @@ -9,20 +9,6 @@ extern "C" { #endif - void plm - (const int lo[], const int hi[], - const int idir, - const BL_FORT_FAB_ARG_3D(s), - const BL_FORT_FAB_ARG_3D(qaux), - const BL_FORT_FAB_ARG_3D(flatn), - const BL_FORT_FAB_ARG_3D(bx), - const BL_FORT_FAB_ARG_3D(by), - const BL_FORT_FAB_ARG_3D(bz), - BL_FORT_FAB_ARG_3D(Ip), - BL_FORT_FAB_ARG_3D(Im), - const BL_FORT_FAB_ARG_3D(srcq), - const amrex::Real dx[], const amrex::Real dt); - void hlld(const int lo[], const int hi[], const BL_FORT_FAB_ARG_3D(qleft), const BL_FORT_FAB_ARG_3D(qright), From d280f6b7ff64d148fe8c24c583d14cea453e95d3 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 21:15:40 -0400 Subject: [PATCH 13/23] finish first pass --- Source/mhd/Castro_mhd.H | 39 ++++++++++++ Source/mhd/Castro_mhd.cpp | 2 +- Source/mhd/Make.package | 2 + Source/mhd/mhd_eigen.H | 2 + Source/mhd/mhd_plm.cpp | 121 +++++--------------------------------- Source/mhd/mhd_slope.H | 78 ++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 108 deletions(-) create mode 100644 Source/mhd/mhd_slope.H diff --git a/Source/mhd/Castro_mhd.H b/Source/mhd/Castro_mhd.H index 8fe6238d0f..19d02dde79 100644 --- a/Source/mhd/Castro_mhd.H +++ b/Source/mhd/Castro_mhd.H @@ -5,6 +5,45 @@ amrex::Array4 const& q_arr, amrex::Array4 const& qaux_arr); + void + plm(const amrex::Box& bx, + const int idir, + amrex::Array4 const& s, + amrex::Array4 const& qaux, + amrex::Array4 const& flatn, + amrex::Array4 const& bx, + amrex::Array4 const& by, + amrex::Array4 const& bz, + amrex::Array4 const& qleft, + amrex::Array4 const& qright, + amrex::Array4 const& srcQ, + const amrex::Real dt); + + void + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + evals(amrex::Real* lam, const amrex::Real as_in, amrex::Real* Q, const int dir); + + void + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + evecx(amrex::Array2d const& leig, + amrex::Array2d const& reig, + const amrex::Real as_in, + amrex::Real* Q); + + void + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + evecy(amrex::Array2d const& leig, + amrex::Array2d const& reig, + const amrex::Real as_in, + amrex::Real* Q); + + void + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + evecz(amrex::Array2d const& leig, + amrex::Array2d const& reig, + const amrex::Real as_in, + amrex::Real* Q); + void consup_mhd(const amrex::Box& bx, amrex::Array4 const& update, diff --git a/Source/mhd/Castro_mhd.cpp b/Source/mhd/Castro_mhd.cpp index c457c70ff1..ea5364aaa4 100644 --- a/Source/mhd/Castro_mhd.cpp +++ b/Source/mhd/Castro_mhd.cpp @@ -1,6 +1,6 @@ #include "Castro.H" #include "Castro_F.H" -#include + using namespace amrex; void diff --git a/Source/mhd/Make.package b/Source/mhd/Make.package index 3fa85e970b..937e45186d 100644 --- a/Source/mhd/Make.package +++ b/Source/mhd/Make.package @@ -6,6 +6,8 @@ FEXE_headers += Castro_mhd_F.H CEXE_sources += Castro_mhd.cpp CEXE_sources += mhd_util.cpp CEXE_headers += mhd_util.H +CEXE_headers += mhd_eigen.H +CEXE_headers += mhd_slope.H CEXE_sources += ct_upwind.cpp CEXE_sources += electric.cpp diff --git a/Source/mhd/mhd_eigen.H b/Source/mhd/mhd_eigen.H index 41c6a7363c..7c9265044e 100644 --- a/Source/mhd/mhd_eigen.H +++ b/Source/mhd/mhd_eigen.H @@ -1,6 +1,8 @@ #ifndef CASTRO_MHD_EIGEN_H #define CASTRO_MHD_EIGEN_H +#include "mhd_util.H" + void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Castro::evals(Real* lam, const Real as_in, Real* Q, const int dir) { diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp index 3752025ef0..c04619161f 100644 --- a/Source/mhd/mhd_plm.cpp +++ b/Source/mhd/mhd_plm.cpp @@ -1,3 +1,10 @@ +#include "Castro.H" +#include "Castro_F.H" + +using namespace amrex; + +#include "mhd_eigen.H" +#include "mhd_slope.H" void Castro::plm(const Box& bx, @@ -109,6 +116,9 @@ Castro::plm(const Box& bx, evals(lam, as, q_zone, idir); + Array2d leig; + Array2d reig; + if (idir == 0) { evecx(leig, reig, as, q_zone); @@ -164,12 +174,12 @@ Castro::plm(const Box& bx, Real summ_m[NEIGN] = {0.0_rt}; for (int ii = 0; ii < NEIGN; ii++) { - Real dL[NEIGN] = {0.0_rt}; - Real dR[NEIGN] = {0.0_rt}; + Real dL = 0.0; + Real dR = 0.0; for (int n = 0; n < NEIGN; n++) { - dL[n] = leig(ii,n) * dQL[n]; - dR[n] = leig(ii,n) * dQR[n]; + dL += leig(ii,n) * dQL[n]; + dR += leig(ii,n) * dQR[n]; } Real dW; @@ -364,106 +374,3 @@ Castro::plm(const Box& bx, }); } - - !======================================== Minmod TVD slope limiter ========================================= - subroutine minmod(dW, WR, WL) - - use amrex_fort_module, only : rt => amrex_real - - implicit none - - real(rt), intent(in) :: WR, WL - real(rt), intent(out) :: dW - dW = 0.d0 - - if (abs(WR) < abs(WL) .and. WR*WL > 0.d0) then - dW = WR - else if (abs(WL) < abs(WR) .and. WR*WL > 0.d0) then - dW = WL - endif - - end subroutine minmod - - - !========================================= VanLeer TVD slope limiter ======================================= - subroutine vanleer(dW, WR, WL) - - use amrex_fort_module, only : rt => amrex_real - - implicit none - - real(rt), intent(in ) :: WR, WL - real(rt), intent(out) :: dW - dW = 0.0d0 - - if( WR*WL .gt. 0.0d0 ) then - dW = 2.0d0*WR*WL/(WR + WL) - endif - - end subroutine vanleer - - !========================================== centered difference =========================================== - subroutine centerdif(dW, WR, WL) - - use amrex_fort_module, only : rt => amrex_real - - implicit none - - real(rt), intent(in ) :: WR, WL - real(rt), intent(out) :: dW - - dW = (WR+WL)/2.0d0 - - end subroutine centerdif - - !================================== second order MC ============================== - subroutine secondMC(dW, WR, WL) - - use amrex_fort_module, only : rt => amrex_real - use amrex_constants_module, only : ZERO, HALF, ONE, TWO - - implicit none - - real(rt), intent(in ) :: WR, WL - real(rt), intent(out ) :: dW - - real(rt) :: dlim - - if (WR * WL .ge. ZERO) then - dlim = TWO * min(abs(WR), abs(WL)) - else - dlim = ZERO - endif - - dW = min(HALF * abs(WR + WL), dlim ) * sign(ONE, WR + WL) - - - end subroutine secondMC - - - - !================================================================ - subroutine slope(dW, WR, WL, flat) - use amrex_fort_module, only : rt => amrex_real - - implicit none - real(rt), intent(in ) :: flat - real(rt), intent(in ) :: WR, WL - real(rt), intent(out) :: dW - - if (mhd_plm_slope == 0) then - dW = 0.0 - elseif (mhd_plm_slope == 1) then - call vanleer(dW,WR,WL) - elseif (mhd_plm_slope == 2) then - call centerdif(dW,WR,WL) - elseif (mhd_plm_slope == 3) then - call secondMC(dW,WR,WL) - endif - - if (use_flattening == 1) then - dW = flat * dW - endif - - end subroutine slope -end module mhd_plm_module diff --git a/Source/mhd/mhd_slope.H b/Source/mhd/mhd_slope.H new file mode 100644 index 0000000000..d57e7fd82a --- /dev/null +++ b/Source/mhd/mhd_slope.H @@ -0,0 +1,78 @@ +#ifndef CASTRO_MHD_SLOPE_H +#define CASTRO_MHD_SLOPE_H + +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void +minmod(Real& dW, const Real WR, const Real WL) { + + dW = 0.0; + + if (WL*WR > 0.0) { + if (std::abs(WR) < std::abs(WL)) { + dW = WR; + } else { + dW = WL; + } + } +} + + +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void +vanleer(Real& dW, const Real WR, const Real WL) { + + dW = 0.0; + + if (WR*WL > 0.0) { + dW = 2.0_rt * WR * WL / (WR + WL); + } +} + + +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void +centerdif(Real& dW, const Real WR, const Real WL) { + dW = (WR + WL) / 2.0_rt; +} + + +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void +secondMC(Real& dW, const Real WR, const Real WL) { + + Real dlim = 0.0; + + if (WR * WL >= 0.0_rt) { + dlim = 2.0_rt * amrex::min(std::abs(WR), std::abs(WL)); + } + + dW = amrex::min(0.5_rt * std::abs(WR + WL), dlim) * + std::copysign(1.0_rt, WR + WL); + +} + + +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void +slope(Real& dW, const Real WR, const Real WL, const Real flat) { + + if (mhd_plm_slope == 0) { + dW = 0.0; + + } else if (mhd_plm_slope == 1) { + vanleer(dW, WR, WL); + + } else if (mhd_plm_slope == 2) { + centerdif(dW, WR, WL); + + } else if (mhd_plm_slope == 3) { + secondMC(dW, WR, WL); + + } + + if (use_flattening == 1) { + dW = flat * dW; + } +} + +#endif From 1c2718ae6dda7b21c7f52e3a84961b41ca17e41b Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 21:55:03 -0400 Subject: [PATCH 14/23] this compiles now --- Source/driver/Castro.H | 4 +++ Source/mhd/Castro_mhd.H | 19 +++++----- Source/mhd/Castro_mhd.cpp | 18 +++------- Source/mhd/Make.package | 1 + Source/mhd/mhd_eigen.H | 74 +++++++++++++++++++-------------------- Source/mhd/mhd_plm.cpp | 38 ++++++++++---------- Source/mhd/mhd_util.H | 17 +-------- 7 files changed, 76 insertions(+), 95 deletions(-) diff --git a/Source/driver/Castro.H b/Source/driver/Castro.H index 58f7d581ba..d6f917f6fe 100644 --- a/Source/driver/Castro.H +++ b/Source/driver/Castro.H @@ -3,6 +3,10 @@ #include +#ifdef MHD +#include +#endif + // runtime parameters #include using namespace castro; diff --git a/Source/mhd/Castro_mhd.H b/Source/mhd/Castro_mhd.H index 19d02dde79..cf0a1645d6 100644 --- a/Source/mhd/Castro_mhd.H +++ b/Source/mhd/Castro_mhd.H @@ -1,3 +1,4 @@ + void just_the_mhd(amrex::Real time, amrex::Real dt); void @@ -11,9 +12,9 @@ amrex::Array4 const& s, amrex::Array4 const& qaux, amrex::Array4 const& flatn, - amrex::Array4 const& bx, - amrex::Array4 const& by, - amrex::Array4 const& bz, + amrex::Array4 const& Bx, + amrex::Array4 const& By, + amrex::Array4 const& Bz, amrex::Array4 const& qleft, amrex::Array4 const& qright, amrex::Array4 const& srcQ, @@ -25,22 +26,22 @@ void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - evecx(amrex::Array2d const& leig, - amrex::Array2d const& reig, + evecx(amrex::Array2D& leig, + amrex::Array2D& reig, const amrex::Real as_in, amrex::Real* Q); void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - evecy(amrex::Array2d const& leig, - amrex::Array2d const& reig, + evecy(amrex::Array2D& leig, + amrex::Array2D& reig, const amrex::Real as_in, amrex::Real* Q); void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - evecz(amrex::Array2d const& leig, - amrex::Array2d const& reig, + evecz(amrex::Array2D& leig, + amrex::Array2D& reig, const amrex::Real as_in, amrex::Real* Q); diff --git a/Source/mhd/Castro_mhd.cpp b/Source/mhd/Castro_mhd.cpp index ea5364aaa4..4473370f4e 100644 --- a/Source/mhd/Castro_mhd.cpp +++ b/Source/mhd/Castro_mhd.cpp @@ -255,19 +255,11 @@ Castro::just_the_mhd(Real time, Real dt) for (int idir = 0; idir < AMREX_SPACEDIM; idir++) { - const int idir_f = idir + 1; - - plm(bxi.loVect(), bxi.hiVect(), idir_f, - BL_TO_FORTRAN_ANYD(q), - BL_TO_FORTRAN_ANYD(qaux), - BL_TO_FORTRAN_ANYD(flatn), - BL_TO_FORTRAN_ANYD(Bx), - BL_TO_FORTRAN_ANYD(By), - BL_TO_FORTRAN_ANYD(Bz), - BL_TO_FORTRAN_ANYD(qleft[idir]), - BL_TO_FORTRAN_ANYD(qright[idir]), - BL_TO_FORTRAN_ANYD(srcQ), - dx_f, dt); + plm(bxi, idir, + q_arr, qaux_arr, flatn_arr, + Bx_arr, By_arr, Bz_arr, + qleft[idir].array(), qright[idir].array(), + src_q_arr, dt); } diff --git a/Source/mhd/Make.package b/Source/mhd/Make.package index 937e45186d..4ac07708e6 100644 --- a/Source/mhd/Make.package +++ b/Source/mhd/Make.package @@ -8,6 +8,7 @@ CEXE_sources += mhd_util.cpp CEXE_headers += mhd_util.H CEXE_headers += mhd_eigen.H CEXE_headers += mhd_slope.H +CEXE_headers += mhd_sizes.H CEXE_sources += ct_upwind.cpp CEXE_sources += electric.cpp diff --git a/Source/mhd/mhd_eigen.H b/Source/mhd/mhd_eigen.H index 7c9265044e..10af6bd396 100644 --- a/Source/mhd/mhd_eigen.H +++ b/Source/mhd/mhd_eigen.H @@ -14,7 +14,7 @@ Castro::evals(Real* lam, const Real as_in, Real* Q, const int dir) { Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; int QUN; - Real cad; // acoustic + Real cad; // Alfven Real cs; // slow Real cf; // fast @@ -23,20 +23,20 @@ Castro::evals(Real* lam, const Real as_in, Real* Q, const int dir) { if (dir == 0) { QUN = QU; cad = (Q[QMAGX]*Q[QMAGX]) / Q[QRHO]; - cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cax)); - cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cax)); + cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); + cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); } else if (dir == 1) { QUN = QV; cad = (Q[QMAGY]*Q[QMAGY]) / Q[QRHO]; - cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cay)); - cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cay)); + cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); + cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); } else { QUN = QW; cad = (Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; - cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*caz)); - cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*caz)); + cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); + cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); } @@ -54,8 +54,8 @@ Castro::evals(Real* lam, const Real as_in, Real* Q, const int dir) { void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -Castro::evecx(Array2d const& leig, - Array2d const& reig, +Castro::evecx(Array2D& leig, + Array2D& reig, const Real as_in, Real* Q) { @@ -83,11 +83,11 @@ Castro::evecx(Array2d const& leig, Real alf = std::sqrt((as - csx)/(cfx - csx)); Real als = std::sqrt((cfx - as)/(cfx - csx)); - if (cfx - as < 0.d0) { + if (cfx - as < 0.0) { als = 0.0_rt; } - if (as - csx < 0.d0) { + if (as - csx < 0.0) { alf = 0.0_rt; } @@ -119,25 +119,25 @@ Castro::evecx(Array2d const& leig, // u - cf wave leig(0, IEIGN_RHO) = 0.0; - leig(0, IEIGN_U) = -N*Cff; + leig(0, IEIGN_U) = -N*cff; leig(0, IEIGN_V) = N*Qs*bety; leig(0, IEIGN_W) = N*Qs*betz; - leig(0, IEIGN_P) = N*alf/Q(QRHO); - leig(0, IEIGN_BT) = N*AAs*bety/Q(QRHO); - leig(0, IEIGN_BTT) = N*AAs*betz/Q(QRHO); + leig(0, IEIGN_P) = N*alf/Q[QRHO]; + leig(0, IEIGN_BT) = N*AAs*bety/Q[QRHO]; + leig(0, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; // u - cax leig(1, IEIGN_RHO) = 0.0; leig(1, IEIGN_U) = 0.0; leig(1, IEIGN_V) = -0.5_rt*betz; leig(1, IEIGN_W) = 0.5_rt*bety; - leig(1, IEIGN_P) = 0.d0; + leig(1, IEIGN_P) = 0.0; leig(1, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q[QRHO]); leig(1, IEIGN_BTT) = 0.5_rt*bety*S/std::sqrt(Q[QRHO]); // u - cs leig(2, IEIGN_RHO) = 0.0; - leig(2, IEIGN_U) = -N*Css; + leig(2, IEIGN_U) = -N*css; leig(2, IEIGN_V) = -N*Qf*bety; leig(2, IEIGN_W) = -N*Qf*betz; leig(2, IEIGN_P) = N*als/Q[QRHO]; @@ -155,7 +155,7 @@ Castro::evecx(Array2d const& leig, // u + cs leig(4, IEIGN_RHO) = 0.0; - leig(4, IEIGN_U) = N*Css; + leig(4, IEIGN_U) = N*css; leig(4, IEIGN_V) = N*Qf*bety; leig(4, IEIGN_W) = N*Qf*betz; leig(4, IEIGN_P) = N*als/Q[QRHO]; @@ -173,7 +173,7 @@ Castro::evecx(Array2d const& leig, // u + cf leig(6, IEIGN_RHO) = 0.0; - leig(6, IEIGN_U) = N*Cff; + leig(6, IEIGN_U) = N*cff; leig(6, IEIGN_V) = -N*Qs*bety; leig(6, IEIGN_W) = -N*Qs*betz; leig(6, IEIGN_P) = N*alf/Q[QRHO]; @@ -243,8 +243,8 @@ Castro::evecx(Array2d const& leig, void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -Castro::evecy(Array2d const& leig, - Array2d const& reig, +Castro::evecy(Array2D& leig, + Array2D& reig, const Real as_in, Real* Q) { @@ -262,11 +262,11 @@ Castro::evecy(Array2d const& leig, // Slow - Real csy = 0.5_rt*((as + ca) - std::sqrt((as + ca)**2 - 4.0_rt*as*cay)); + Real csy = 0.5_rt*((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cay)); // Fast - Real cfy = 0.5_rt*((as + ca) + std::sqrt((as + ca)**2 - 4.0_rt*as*cay)); + Real cfy = 0.5_rt*((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cay)); // useful constants @@ -310,7 +310,7 @@ Castro::evecy(Array2d const& leig, // v - cf leig(0, IEIGN_RHO) = 0.0; leig(0, IEIGN_U) = N*Qs*betx; - leig(0, IEIGN_V) = -N*Cff; + leig(0, IEIGN_V) = -N*cff; leig(0, IEIGN_W) = N*Qs*betz; leig(0, IEIGN_P) = N*alf/Q[QRHO]; leig(0, IEIGN_BT) = N*AAs*betx/Q[QRHO]; @@ -328,7 +328,7 @@ Castro::evecy(Array2d const& leig, // v - cs leig(2, IEIGN_RHO) = 0.0; leig(2, IEIGN_U) = -N*Qf*betx; - leig(2, IEIGN_V) = -N*Css; + leig(2, IEIGN_V) = -N*css; leig(2, IEIGN_W) = -N*Qf*betz; leig(2, IEIGN_P) = N*als/Q[QRHO]; leig(2, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; @@ -346,7 +346,7 @@ Castro::evecy(Array2d const& leig, // v + cs leig(4, IEIGN_RHO) = 0.0; leig(4, IEIGN_U) = N*Qf*betx; - leig(4, IEIGN_V) = N*Css; + leig(4, IEIGN_V) = N*css; leig(4, IEIGN_W) = N*Qf*betz; leig(4, IEIGN_P) = N*als/Q[QRHO]; leig(4, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; @@ -364,7 +364,7 @@ Castro::evecy(Array2d const& leig, // v + cf leig(6, IEIGN_RHO) = 0.0; leig(6, IEIGN_U) = -N*Qs*betx; - leig(6, IEIGN_V) = N*Cff; + leig(6, IEIGN_V) = N*cff; leig(6, IEIGN_W) = -N*Qs*betz; leig(6, IEIGN_P) = N*alf/Q[QRHO]; leig(6, IEIGN_BT) = N*AAs*betx/Q[QRHO]; @@ -433,8 +433,8 @@ Castro::evecy(Array2d const& leig, void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -Castro::evecz(Array2d const& leig, - Array2d const& reig, +Castro::evecz(Array2D& leig, + Array2D& reig, const Real as_in, Real* Q) { @@ -446,16 +446,16 @@ Castro::evecz(Array2d const& leig, // Alfven - Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q{QMAGZ]) / Q[QRHO]; + Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; Real caz = (Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; // Slow - Real csz = 0.5_rt*((as + ca) - std::sqrt((as + ca)**2 - 4.0_rt*as*caz)); + Real csz = 0.5_rt*((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*caz)); // Fast - Real cfz = 0.5_rt*((as + ca) + std::sqrt((as + ca)**2 - 4.0_rt*as*caz)); + Real cfz = 0.5_rt*((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*caz)); // useful constants @@ -466,7 +466,7 @@ Castro::evecz(Array2d const& leig, als = 0.0_rt; } - if (as - csz < 0.d0) { + if (as - csz < 0.0) { alf = 0.0_rt; } @@ -500,7 +500,7 @@ Castro::evecz(Array2d const& leig, leig(0, IEIGN_RHO) = 0.0; leig(0, IEIGN_U) = N*Qs*betx; leig(0, IEIGN_V) = N*Qs*bety; - leig(0, IEIGN_W) = -N*Cff; + leig(0, IEIGN_W) = -N*cff; leig(0, IEIGN_P) = N*alf/Q[QRHO]; leig(0, IEIGN_BT) = N*AAs*betx/Q[QRHO]; leig(0, IEIGN_BTT) = N*AAs*bety/Q[QRHO]; @@ -518,7 +518,7 @@ Castro::evecz(Array2d const& leig, leig(2, IEIGN_RHO) = 0.0; leig(2, IEIGN_U) = -N*Qf*betx; leig(2, IEIGN_V) = -N*Qf*bety; - leig(2, IEIGN_W) = -N*Css; + leig(2, IEIGN_W) = -N*css; leig(2, IEIGN_P) = N*als/Q[QRHO]; leig(2, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; leig(2, IEIGN_BTT) = -N*AAf*bety/Q[QRHO]; @@ -536,7 +536,7 @@ Castro::evecz(Array2d const& leig, leig(4, IEIGN_RHO) = 0.0; leig(4, IEIGN_U) = N*Qf*betx; leig(4, IEIGN_V) = N*Qf*bety; - leig(4, IEIGN_W) = N*Css; + leig(4, IEIGN_W) = N*css; leig(4, IEIGN_P) = N*als/Q[QRHO]; leig(4, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; leig(4, IEIGN_BTT) = -N*AAf*bety/Q[QRHO]; @@ -554,7 +554,7 @@ Castro::evecz(Array2d const& leig, leig(6, IEIGN_RHO) = 0.0; leig(6, IEIGN_U) = -N*Qs*betx; leig(6, IEIGN_V) = -N*Qs*bety; - leig(6, IEIGN_W) = N*Cff; + leig(6, IEIGN_W) = N*cff; leig(6, IEIGN_P) = N*alf/Q[QRHO]; leig(6, IEIGN_BT) = N*AAs*betx/Q[QRHO]; leig(6, IEIGN_BTT) = N*AAs*bety/Q[QRHO]; diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp index c04619161f..14ca169539 100644 --- a/Source/mhd/mhd_plm.cpp +++ b/Source/mhd/mhd_plm.cpp @@ -12,9 +12,9 @@ Castro::plm(const Box& bx, Array4 const& s, Array4 const& qaux, Array4 const& flatn, - Array4 const& bx, - Array4 const& by, - Array4 const& bz, + Array4 const& Bx, + Array4 const& By, + Array4 const& Bz, Array4 const& qleft, Array4 const& qright, Array4 const& srcQ, @@ -111,13 +111,11 @@ Castro::plm(const Box& bx, Real as = qaux(i,j,k,QC); Real lam[NEIGN]; - Real leig[NEIGN]; - Real reig[NEIGN]; evals(lam, as, q_zone, idir); - Array2d leig; - Array2d reig; + Array2D leig; + Array2D reig; if (idir == 0) { evecx(leig, reig, as, q_zone); @@ -146,7 +144,7 @@ Castro::plm(const Box& bx, // cross-talk of normal magnetic field direction for (int n = 0; n < NEIGN; n++) { - smhd[n] = smhd[n] * (bx(i+1,j,k) - bx(i,j,k)) / dx[idir]; + smhd[n] = smhd[n] * (Bx(i+1,j,k) - Bx(i,j,k)) / dx[idir]; } } else if (idir == 1) { @@ -155,7 +153,7 @@ Castro::plm(const Box& bx, // cross-talk of normal magnetic field direction for (int n = 0; n < NEIGN; n++) { - smhd[n] = smhd[n] * (by(i,j+1,k) - by(i,j,k)) / dx[idir]; + smhd[n] = smhd[n] * (By(i,j+1,k) - By(i,j,k)) / dx[idir]; } } else { @@ -164,7 +162,7 @@ Castro::plm(const Box& bx, // cross-talk of normal magnetic field direction for (int n = 0; n < NEIGN; n++) { - smhd[n] = smhd[n] * (bz(i,j,k+1) - bz(i,j,k)) / dx[idir]; + smhd[n] = smhd[n] * (Bz(i,j,k+1) - Bz(i,j,k)) / dx[idir]; } } @@ -202,7 +200,7 @@ Castro::plm(const Box& bx, qleft(i+1,j,k,QPRES) = amrex::max(small_pres, q_zone[QPRES] + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); - qleft(i+1,j,k,QMAGX) = bx(i+1,j,k); // Bx stuff + qleft(i+1,j,k,QMAGX) = Bx(i+1,j,k); // Bx stuff qleft(i+1,j,k,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; qleft(i+1,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; @@ -216,7 +214,7 @@ Castro::plm(const Box& bx, q_zone[QPRES] + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); qleft(i,j+1,k,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qleft(i,j+1,k,QMAGY) = by(i,j+1,k); // By stuff + qleft(i,j+1,k,QMAGY) = By(i,j+1,k); // By stuff qleft(i,j+1,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else { @@ -230,7 +228,7 @@ Castro::plm(const Box& bx, qleft(i,j,k+1,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; qleft(i,j,k+1,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; - qleft(i,j,k+1,QMAGZ) = bz(i,j,k+1); // Bz stuff + qleft(i,j,k+1,QMAGZ) = Bz(i,j,k+1); // Bz stuff } // right state at i-1/2 @@ -243,19 +241,19 @@ Castro::plm(const Box& bx, q_zone[QPRES] + 0.5_rt*summ_m[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); if (idir == 0) { - qright(i,j,k,QMAGX) = bx(i,j,k); // Bx stuff + qright(i,j,k,QMAGX) = Bx(i,j,k); // Bx stuff qright(i,j,k,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; qright(i,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else if (idir == 1) { qright(i,j,k,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qright(i,j,k,QMAGY) = by(i,j,k); // By stuff + qright(i,j,k,QMAGY) = By(i,j,k); // By stuff qright(i,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else { qright(i,j,k,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; qright(i,j,k,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; - qright(i,j,k,QMAGZ) = bz(i,j,k); // Bz stuff + qright(i,j,k,QMAGZ) = Bz(i,j,k); // Bz stuff } // species @@ -300,7 +298,7 @@ Castro::plm(const Box& bx, eos_state.rho = qleft(i+1,j,k,QRHO); eos_state.p = qleft(i+1,j,k,QPRES); eos_state.T = s(i,j,k,QTEMP); // some initial guess? - for (int n = 0; n < NQ; n++) { + for (int n = 0; n < NumSpec; n++) { eos_state.xn[n] = qleft(i+1,j,k,QFS+n); } eos(eos_input_rp, eos_state); @@ -310,7 +308,7 @@ Castro::plm(const Box& bx, eos_state.rho = qleft(i,j+1,k,QRHO); eos_state.p = qleft(i,j+1,k,QPRES); eos_state.T = s(i,j,k,QTEMP); // some initial guess? - for (int n = 0; n < NQ; n++) { + for (int n = 0; n < NumSpec; n++) { eos_state.xn[n] = qleft(i,j+1,k,QFS+n); } eos(eos_input_rp, eos_state); @@ -320,7 +318,7 @@ Castro::plm(const Box& bx, eos_state.rho = qleft(i,j,k+1,QRHO); eos_state.p = qleft(i,j,k+1,QPRES); eos_state.T = s(i,j,k,QTEMP); // some initial guess? - for (int n = 0; n < NQ; n++) { + for (int n = 0; n < NumSpec; n++) { eos_state.xn[n] = qleft(i,j,k+1,QFS+n); } eos(eos_input_rp, eos_state); @@ -329,7 +327,7 @@ Castro::plm(const Box& bx, eos_state.rho = qright(i,j,k,QRHO); eos_state.p = qright(i,j,k,QPRES); - for (int n = 0; n < NQ; n++) { + for (int n = 0; n < NumSpec; n++) { eos_state.xn[n] = qright(i,j,k,QFS+n); } diff --git a/Source/mhd/mhd_util.H b/Source/mhd/mhd_util.H index 6c9d6f64fb..e22943f6b0 100644 --- a/Source/mhd/mhd_util.H +++ b/Source/mhd/mhd_util.H @@ -2,25 +2,10 @@ #define CASTRO_MHD_SOUND_SPEED_H #include "Castro_util.H" +#include "mhd_sizes.H" using namespace amrex; -constexpr int UMAGX = NUM_STATE; -constexpr int UMAGY = NUM_STATE+1; -constexpr int UMAGZ = NUM_STATE+2; - -constexpr int NEIGN = 7; - -constexpr int IEIGN_RHO = 0; -constexpr int IEIGN_U = 1; -constexpr int IEIGN_V = 2; -constexpr int IEIGN_W = 3; -constexpr int IEIGN_P = 4; - -// perpendicular magnetic field components -constexpr int IEIGN_BT = 5; -constexpr int IEIGN_BTT = 6; - // sound speed calc for ideal MHD void AMREX_GPU_DEVICE AMREX_FORCE_INLINE From 5c0edb55c44a9ba7db3798ed54ecd71fff6ea649 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 21:55:39 -0400 Subject: [PATCH 15/23] add missing file --- Source/mhd/mhd_sizes.H | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Source/mhd/mhd_sizes.H diff --git a/Source/mhd/mhd_sizes.H b/Source/mhd/mhd_sizes.H new file mode 100644 index 0000000000..121587ef33 --- /dev/null +++ b/Source/mhd/mhd_sizes.H @@ -0,0 +1,20 @@ +#ifndef CASTRO_MHD_SIZES_H +#define CASTRO_MHD_SIZES_H + +constexpr int UMAGX = NUM_STATE; +constexpr int UMAGY = NUM_STATE+1; +constexpr int UMAGZ = NUM_STATE+2; + +constexpr int NEIGN = 7; + +constexpr int IEIGN_RHO = 0; +constexpr int IEIGN_U = 1; +constexpr int IEIGN_V = 2; +constexpr int IEIGN_W = 3; +constexpr int IEIGN_P = 4; + +// perpendicular magnetic field components +constexpr int IEIGN_BT = 5; +constexpr int IEIGN_BTT = 6; + +#endif From a247579592d8de052b1e11a38907057d23e9735a Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 22:03:42 -0400 Subject: [PATCH 16/23] fix index bug --- Source/mhd/mhd_plm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp index 14ca169539..b377d0bbfc 100644 --- a/Source/mhd/mhd_plm.cpp +++ b/Source/mhd/mhd_plm.cpp @@ -288,7 +288,7 @@ Castro::plm(const Box& bx, } else { qleft(i,j,k+1,QFS+n) = q_zone[QFS+n] + 0.5_rt*(1.0_rt - dtdx*un) * dW; } - qright(i,j,k,QFS) = q_zone[QFS+n] - 0.5_rt*(1.0_rt + dtdx*un) * dW; + qright(i,j,k,QFS+n) = q_zone[QFS+n] - 0.5_rt*(1.0_rt + dtdx*un) * dW; } // rho e From 3f0c5d22fc34f2d00a5775b2808bdacd28f14095 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 May 2020 22:04:24 -0400 Subject: [PATCH 17/23] remove unneeded Fortran --- Source/mhd/mhd_plm_3d.f90 | 777 -------------------------------------- 1 file changed, 777 deletions(-) delete mode 100644 Source/mhd/mhd_plm_3d.f90 diff --git a/Source/mhd/mhd_plm_3d.f90 b/Source/mhd/mhd_plm_3d.f90 deleted file mode 100644 index 92dcb0cddf..0000000000 --- a/Source/mhd/mhd_plm_3d.f90 +++ /dev/null @@ -1,777 +0,0 @@ -module mhd_plm_module - - ! Module that gives a piecewise linear interpolation for the primitive variables - ! They are projected onto the characteristic variables for tracing. - - use amrex_fort_module, only : rt => amrex_real - use meth_params_module - implicit none - - private centerdif, vanleer, evecx, evecy, evecz, evals, slope - - public plm - - integer, parameter :: NEIGN = 7 - - integer, parameter :: IEIGN_RHO = 1 - integer, parameter :: IEIGN_U = 2 - integer, parameter :: IEIGN_V = 3 - integer, parameter :: IEIGN_W = 4 - integer, parameter :: IEIGN_P = 5 - - ! perpendicular magnetic field components - integer, parameter :: IEIGN_BT = 6 - integer, parameter :: IEIGN_BTT = 7 - -contains - - subroutine plm(lo, hi, & - idir, & - s, s_lo, s_hi, & - qaux, qa_lo, qa_hi, & - flatn, f_lo, f_hi, & - bx, bxlo, bxhi, & - by, bylo, byhi, & - bz, bzlo, bzhi, & - qleft, ql_lo, ql_hi, & - qright, qr_lo, qr_hi, & - srcQ, srcq_lo, srcq_hi, & - dx, dt) bind(C, name="plm") - - use network, only: nspec - use eos_module - use eos_type_module, only: eos_t, eos_input_rp - use meth_params_module, only: small_dens, small_pres - - implicit none - - integer, intent(in) :: lo(3), hi(3) - integer, intent(in), value :: idir - integer, intent(in) :: s_lo(3), s_hi(3) - integer, intent(in) :: qa_lo(3), qa_hi(3) - integer, intent(in) :: f_lo(3), f_hi(3) - integer, intent(in) :: bxlo(3), bxhi(3) - integer, intent(in) :: bylo(3), byhi(3) - integer, intent(in) :: bzlo(3), bzhi(3) - integer, intent(in) :: ql_lo(3), ql_hi(3) - integer, intent(in) :: qr_lo(3), qr_hi(3) - integer, intent(in) :: srcq_lo(3), srcq_hi(3) - - real(rt), intent(in) :: s(s_lo(1):s_hi(1), s_lo(2):s_hi(2), s_lo(3):s_hi(3), NQ) - real(rt), intent(in) :: qaux(qa_lo(1):qa_hi(1), qa_lo(2):qa_hi(2), qa_lo(3):qa_hi(3), NQAUX) - - ! face-centered magnetic fields - real(rt), intent(in ) :: bx(bxlo(1):bxhi(1), bxlo(2):bxhi(2), bxlo(3):bxhi(3)) - real(rt), intent(in ) :: by(bylo(1):byhi(1), bylo(2):byhi(2), bylo(3):byhi(3)) - real(rt), intent(in ) :: bz(bzlo(1):bzhi(1), bzlo(2):bzhi(2), bzlo(3):bzhi(3)) - - real(rt), intent(in) :: srcQ(srcq_lo(1):srcq_hi(1), srcq_lo(2):srcq_hi(2), srcq_lo(3):srcq_hi(3), NQSRC) - real(rt), intent(in) :: flatn(f_lo(1):f_hi(1),f_lo(2):f_hi(2),f_lo(3):f_hi(3)) - - real(rt), intent(out) :: qleft(ql_lo(1):ql_hi(1), ql_lo(2):ql_hi(2), ql_lo(3):ql_hi(3), NQ) - real(rt), intent(out) :: qright(qr_lo(1):qr_hi(1), qr_lo(2):qr_hi(2), qr_lo(3):qr_hi(3), NQ) - - real(rt), intent(in ) :: dx(3) - real(rt), intent(in), value :: dt - - real(rt) :: dQL(NEIGN), dQR(NEIGN), dW, dL, dR - real(rt) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN), lam(NEIGN), summ_p(NEIGN), summ_m(NEIGN) - real(rt) :: smhd(NEIGN) - - integer :: ii, i , j, k, n - real(rt) :: un, dtdx - - type(eos_t) :: eos_state - - ! these loops are over cell-centers and for each cell-center, we find the left and - ! right interface states - - dtdx = dt/dx(idir) - - !=========================== PLM ========================================= - do k = lo(3), hi(3) - do j = lo(2), hi(2) - do i = lo(1), hi(1) - - ! compute the 1-sided differences used for the slopes - - if (idir == 1) then - ! we use a reduced eigensystem, the normal B field - ! component (Bx) is omitted - - dQL(IEIGN_RHO) = s(i,j,k,QRHO) - s(i-1,j,k,QRHO) - dQL(IEIGN_U) = s(i,j,k,QU) - s(i-1,j,k,QU) - dQL(IEIGN_V) = s(i,j,k,QV) - s(i-1,j,k,QV) - dQL(IEIGN_W) = s(i,j,k,QW) - s(i-1,j,k,QW) - dQL(IEIGN_P) = s(i,j,k,QPRES) - s(i-1,j,k,QPRES) - dQL(IEIGN_BT) = s(i,j,k,QMAGY) - s(i-1,j,k,QMAGY) - dQL(IEIGN_BTT) = s(i,j,k,QMAGZ) - s(i-1,j,k,QMAGZ) - - dQR(IEIGN_RHO) = s(i+1,j,k,QRHO) - s(i,j,k,QRHO) - dQR(IEIGN_U) = s(i+1,j,k,QU) - s(i,j,k,QU) - dQR(IEIGN_V) = s(i+1,j,k,QV) - s(i,j,k,QV) - dQR(IEIGN_W) = s(i+1,j,k,QW) - s(i,j,k,QW) - dQR(IEIGN_P) = s(i+1,j,k,QPRES) - s(i,j,k,QPRES) - dQR(IEIGN_BT) = s(i+1,j,k,QMAGY) - s(i,j,k,QMAGY) - dQR(IEIGN_BTT) = s(i+1,j,k,QMAGZ) - s(i,j,k,QMAGZ) - - else if (idir == 2) then - ! we use a reduced eigensystem, the normal B field - ! component (By) is omitted - - dQL(IEIGN_RHO) = s(i,j,k,QRHO) - s(i,j-1,k,QRHO) - dQL(IEIGN_U) = s(i,j,k,QU) - s(i,j-1,k,QU) - dQL(IEIGN_V) = s(i,j,k,QV) - s(i,j-1,k,QV) - dQL(IEIGN_W) = s(i,j,k,QW) - s(i,j-1,k,QW) - dQL(IEIGN_P) = s(i,j,k,QPRES) - s(i,j-1,k,QPRES) - dQL(IEIGN_BT) = s(i,j,k,QMAGX) - s(i,j-1,k,QMAGX) - dQL(IEIGN_BTT) = s(i,j,k,QMAGZ) - s(i,j-1,k,QMAGZ) - - dQR(IEIGN_RHO) = s(i,j+1,k,QRHO) - s(i,j,k,QRHO) - dQR(IEIGN_U) = s(i,j+1,k,QU) - s(i,j,k,QU) - dQR(IEIGN_V) = s(i,j+1,k,QV) - s(i,j,k,QV) - dQR(IEIGN_W) = s(i,j+1,k,QW) - s(i,j,k,QW) - dQR(IEIGN_P) = s(i,j+1,k,QPRES) - s(i,j,k,QPRES) - dQR(IEIGN_BT) = s(i,j+1,k,QMAGX) - s(i,j,k,QMAGX) - dQR(IEIGN_BTT) = s(i,j+1,k,QMAGZ) - s(i,j,k,QMAGZ) - - else - ! we use a reduced eigensystem, the normal B field - ! component (Bz) is omitted - - dQL(IEIGN_RHO) = s(i,j,k,QRHO) - s(i,j,k-1,QRHO) - dQL(IEIGN_U) = s(i,j,k,QU) - s(i,j,k-1,QU) - dQL(IEIGN_V) = s(i,j,k,QV) - s(i,j,k-1,QV) - dQL(IEIGN_W) = s(i,j,k,QW) - s(i,j,k-1,QW) - dQL(IEIGN_P) = s(i,j,k,QPRES) - s(i,j,k-1,QPRES) - dQL(IEIGN_BT) = s(i,j,k,QMAGX) - s(i,j,k-1,QMAGX) - dQL(IEIGN_BTT) = s(i,j,k,QMAGY) - s(i,j,k-1,QMAGY) - - dQR(IEIGN_RHO) = s(i,j,k+1,QRHO) - s(i,j,k,QRHO) - dQR(IEIGN_U) = s(i,j,k+1,QU) - s(i,j,k,QU) - dQR(IEIGN_V) = s(i,j,k+1,QV) - s(i,j,k,QV) - dQR(IEIGN_W) = s(i,j,k+1,QW) - s(i,j,k,QW) - dQR(IEIGN_P) = s(i,j,k+1,QPRES) - s(i,j,k,QPRES) - dQR(IEIGN_BT) = s(i,j,k+1,QMAGX) - s(i,j,k,QMAGX) - dQR(IEIGN_BTT) = s(i,j,k+1,QMAGY) - s(i,j,k,QMAGY) - - end if - - ! compute the eigenvectors and eigenvalues for this coordinate direction - - call evals(lam, qaux(i,j,k,:), s(i,j,k,:), idir) - - if (idir == 1) then - call evecx(leig, reig, qaux(i,j,k,:), s(i,j,k,:)) - - else if (idir == 2) then - call evecy(leig, reig, qaux(i,j,k,:), s(i,j,k,:)) - - else - call evecz(leig, reig, qaux(i,j,k,:), s(i,j,k,:)) - end if - - ! MHD Source Terms -- from the Miniati paper, Eq. 32 and 33 - smhd(IEIGN_RHO) = 0.0d0 - smhd(IEIGN_U) = s(i,j,k,QMAGX)/s(i,j,k,QRHO) - smhd(IEIGN_V) = s(i,j,k,QMAGY)/s(i,j,k,QRHO) - smhd(IEIGN_W) = s(i,j,k,QMAGZ)/s(i,j,k,QRHO) - smhd(IEIGN_P) = s(i,j,k,QMAGX)*s(i,j,k,QU) + & - s(i,j,k,QMAGY)*s(i,j,k,QV) + & - s(i,j,k,QMAGZ)*s(i,j,k,QW) - - if (idir == 1) then - smhd(IEIGN_BT) = s(i,j,k,QV) - smhd(IEIGN_BTT) = s(i,j,k,QW) - - ! cross-talk of normal magnetic field direction - smhd(:) = smhd(:)*(bx(i+1,j,k) - bx(i,j,k))/dx(idir) - - else if (idir == 2) then - smhd(IEIGN_BT) = s(i,j,k,QU) - smhd(IEIGN_BTT) = s(i,j,k,QW) - - ! cross-talk of normal magnetic field direction - smhd(:) = smhd(:)*(by(i,j+1,k) - by(i,j,k))/dx(idir) - - else - smhd(IEIGN_BT) = s(i,j,k,QU) - smhd(IEIGN_BTT) = s(i,j,k,QV) - - ! cross-talk of normal magnetic field direction - smhd(:) = smhd(:)*(bz(i,j,k+1) - bz(i,j,k))/dx(idir) - - end if - - - ! Perform the characteristic projection. Since we are using - ! Using HLLD, we sum over all eigenvalues -- see the discussion after Eq. 31 - summ_p = 0.d0 - summ_m = 0.d0 - - do ii = 1, NEIGN - dL = dot_product(leig(ii,:), dQL) - dR = dot_product(leig(ii,:), dQR) - call slope(dW, dL, dR, flatn(i,j,k)) - - summ_p(:) = summ_p(:) + (1.0d0 - dtdx*lam(ii)) * dW * reig(:,ii) - summ_m(:) = summ_m(:) - (1.0d0 + dtdx*lam(ii)) * dW * reig(:,ii) - enddo - - ! left state at i+1/2 - - - if (idir == 1) then - qleft(i+1,j,k,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5d0*summ_p(IEIGN_RHO) + 0.5d0*dt*smhd(IEIGN_RHO)) - qleft(i+1,j,k,QU) = s(i,j,k,QU) + 0.5d0*summ_p(IEIGN_U) + 0.5d0*dt*smhd(IEIGN_U) - qleft(i+1,j,k,QV) = s(i,j,k,QV) + 0.5d0*summ_p(IEIGN_V) + 0.5d0*dt*smhd(IEIGN_V) - qleft(i+1,j,k,QW) = s(i,j,k,QW) + 0.5d0*summ_p(IEIGN_W) + 0.5d0*dt*smhd(IEIGN_W) - qleft(i+1,j,k,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5d0*summ_p(IEIGN_P) + 0.5d0*dt*smhd(IEIGN_P)) - - qleft(i+1,j,k,QMAGX) = bx(i+1,j,k) !! Bx stuff - qleft(i+1,j,k,QMAGY) = s(i,j,k,QMAGY) + 0.5d0*summ_p(IEIGN_BT) + 0.5d0*dt*smhd(IEIGN_BT) - qleft(i+1,j,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5d0*summ_p(IEIGN_BTT) + 0.5d0*dt*smhd(IEIGN_BTT) - - else if (idir == 2) then - qleft(i,j+1,k,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5d0*summ_p(IEIGN_RHO) + 0.5d0*dt*smhd(IEIGN_RHO)) - qleft(i,j+1,k,QU) = s(i,j,k,QU) + 0.5d0*summ_p(IEIGN_U) + 0.5d0*dt*smhd(IEIGN_U) - qleft(i,j+1,k,QV) = s(i,j,k,QV) + 0.5d0*summ_p(IEIGN_V) + 0.5d0*dt*smhd(IEIGN_V) - qleft(i,j+1,k,QW) = s(i,j,k,QW) + 0.5d0*summ_p(IEIGN_W) + 0.5d0*dt*smhd(IEIGN_W) - qleft(i,j+1,k,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5d0*summ_p(IEIGN_P) + 0.5d0*dt*smhd(IEIGN_P)) - - qleft(i,j+1,k,QMAGX) = s(i,j,k,QMAGX) + 0.5d0*summ_p(IEIGN_BT) + 0.5d0*dt*smhd(IEIGN_BT) - qleft(i,j+1,k,QMAGY) = by(i,j+1,k) !! By stuff - qleft(i,j+1,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5d0*summ_p(IEIGN_BTT) + 0.5d0*dt*smhd(IEIGN_BTT) - - else - qleft(i,j,k+1,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5d0*summ_p(IEIGN_RHO) + 0.5d0*dt*smhd(IEIGN_RHO)) - qleft(i,j,k+1,QU) = s(i,j,k,QU) + 0.5d0*summ_p(IEIGN_U) + 0.5d0*dt*smhd(IEIGN_U) - qleft(i,j,k+1,QV) = s(i,j,k,QV) + 0.5d0*summ_p(IEIGN_V) + 0.5d0*dt*smhd(IEIGN_V) - qleft(i,j,k+1,QW) = s(i,j,k,QW) + 0.5d0*summ_p(IEIGN_W) + 0.5d0*dt*smhd(IEIGN_W) - qleft(i,j,k+1,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5d0*summ_p(IEIGN_P) + 0.5d0*dt*smhd(IEIGN_P)) - - qleft(i,j,k+1,QMAGX) = s(i,j,k,QMAGX) + 0.5d0*summ_p(IEIGN_BT) + 0.5d0*dt*smhd(IEIGN_BT) - qleft(i,j,k+1,QMAGY) = s(i,j,k,QMAGY) + 0.5d0*summ_p(IEIGN_BTT) + 0.5d0*dt*smhd(IEIGN_BTT) - qleft(i,j,k+1,QMAGZ) = bz(i,j,k+1) !! Bz stuff - end if - - ! right state at i-1/2 - qright(i,j,k,QRHO) = max(small_dens, s(i,j,k,QRHO) + 0.5d0*summ_m(IEIGN_RHO) + 0.5d0*dt*smhd(IEIGN_RHO)) - qright(i,j,k,QU) = s(i,j,k,QU) + 0.5d0*summ_m(IEIGN_U) + 0.5d0*dt*smhd(IEIGN_U) - qright(i,j,k,QV) = s(i,j,k,QV) + 0.5d0*summ_m(IEIGN_V) + 0.5d0*dt*smhd(IEIGN_V) - qright(i,j,k,QW) = s(i,j,k,QW) + 0.5d0*summ_m(IEIGN_W) + 0.5d0*dt*smhd(IEIGN_W) - qright(i,j,k,QPRES) = max(small_pres, s(i,j,k,QPRES) + 0.5d0*summ_m(IEIGN_P) + 0.5d0*dt*smhd(IEIGN_P)) - - if (idir == 1) then - qright(i,j,k,QMAGX) = bx(i,j,k) !! Bx stuff - qright(i,j,k,QMAGY) = s(i,j,k,QMAGY) + 0.5d0*summ_m(IEIGN_BT) + 0.5d0*dt*smhd(IEIGN_BT) - qright(i,j,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5d0*summ_m(IEIGN_BTT) + 0.5d0*dt*smhd(IEIGN_BTT) - - else if (idir == 2) then - qright(i,j,k,QMAGX) = s(i,j,k,QMAGX) + 0.5d0*summ_m(IEIGN_BT) + 0.5d0*dt*smhd(IEIGN_BT) - qright(i,j,k,QMAGY) = by(i,j,k) !! By stuff - qright(i,j,k,QMAGZ) = s(i,j,k,QMAGZ) + 0.5d0*summ_m(IEIGN_BTT) + 0.5d0*dt*smhd(IEIGN_BTT) - - else - qright(i,j,k,QMAGX) = s(i,j,k,QMAGX) + 0.5d0*summ_m(IEIGN_BT) + 0.5d0*dt*smhd(IEIGN_BT) - qright(i,j,k,QMAGY) = s(i,j,k,QMAGY) + 0.5d0*summ_m(IEIGN_BTT) + 0.5d0*dt*smhd(IEIGN_BTT) - qright(i,j,k,QMAGZ) = bz(i,j,k) !! Bz stuff - endif - - ! species - do ii = QFS, QFS+nspec-1 - if (idir == 1) then - dL = s(i,j,k,ii) - s(i-1,j,k,ii) - dR = s(i+1,j,k,ii) - s(i,j,k,ii) - un = s(i,j,k,QU) - - else if (idir == 2) then - dL = s(i,j,k,ii) - s(i,j-1,k,ii) - dR = s(i,j+1,k,ii) - s(i,j,k,ii) - un = s(i,j,k,QV) - - else - dL = s(i,j,k,ii) - s(i,j,k-1,ii) - dR = s(i,j,k+1,ii) - s(i,j,k,ii) - un = s(i,j,k,QW) - end if - - call slope(dW, dL, dR, flatn(i,j,k)) - - if (idir == 1) then - qleft(i+1,j,k,ii) = s(i,j,k,ii) + 0.5d0*(1.0d0 - dtdx*un) * dW - else if (idir == 2) then - qleft(i,j+1,k,ii) = s(i,j,k,ii) + 0.5d0*(1.0d0 - dtdx*un) * dW - else - qleft(i,j,k+1,ii) = s(i,j,k,ii) + 0.5d0*(1.0d0 - dtdx*un) * dW - endif - qright(i,j,k,ii) = s(i,j,k,ii) - 0.5d0*(1.0d0 + dtdx*un) * dW - enddo - - ! rho e - if (idir == 1) then - eos_state % rho = qleft(i+1,j,k,QRHO) - eos_state % p = qleft(i+1,j,k,QPRES) - eos_state % T = s(i,j,k,QTEMP) !some initial guess? - eos_state % xn = qleft(i+1,j,k,QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - qleft(i+1,j,k,QREINT) = eos_state % e * eos_state % rho - - else if (idir == 2) then - eos_state % rho = qleft(i,j+1,k,QRHO) - eos_state % p = qleft(i,j+1,k,QPRES) - eos_state % T = s(i,j,k,QTEMP) !some initial guess? - eos_state % xn = qleft(i,j+1,k,QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - qleft(i,j+1,k,QREINT) = eos_state % e * eos_state % rho - - else - eos_state % rho = qleft(i,j,k+1,QRHO) - eos_state % p = qleft(i,j,k+1,QPRES) - eos_state % T = s(i,j,k,QTEMP) !some initial guess? - eos_state % xn = qleft(i,j,k+1,QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - qleft(i,j,k+1,QREINT) = eos_state % e * eos_state % rho - - end if - - eos_state % rho = qright(i,j,k,QRHO) - eos_state % p = qright(i,j,k,QPRES) - eos_state % xn = qright(i,j,k,QFS:QFS+nspec-1) - - call eos(eos_input_rp, eos_state) - qright(i,j,k,QREINT) = eos_state % e * eos_state % rho - - ! add source terms - if (idir == 1) then - qleft(i+1,j,k,QRHO) = max(small_dens, qleft(i+1,j,k,QRHO) + 0.5d0*dt*srcQ(i,j,k,QRHO)) - qleft(i+1,j,k,QU) = qleft(i+1,j,k,QU) + 0.5d0*dt*srcQ(i,j,k,QU) - qleft(i+1,j,k,QV) = qleft(i+1,j,k,QV) + 0.5d0*dt*srcQ(i,j,k,QV) - qleft(i+1,j,k,QW) = qleft(i+1,j,k,QW) + 0.5d0*dt*srcQ(i,j,k,QW) - qleft(i+1,j,k,QPRES) = qleft(i+1,j,k,QPRES) + 0.5d0*dt*srcQ(i,j,k,QPRES) - qleft(i+1,j,k,QREINT) = qleft(i+1,j,k,QREINT) + 0.5d0*dt*srcQ(i,j,k,QREINT) - - else if (idir == 2) then - qleft(i,j+1,k,QRHO) = max(small_dens, qleft(i,j+1,k,QRHO) + 0.5d0*dt*srcQ(i,j,k,QRHO)) - qleft(i,j+1,k,QU) = qleft(i,j+1,k,QU) + 0.5d0*dt*srcQ(i,j,k,QU) - qleft(i,j+1,k,QV) = qleft(i,j+1,k,QV) + 0.5d0*dt*srcQ(i,j,k,QV) - qleft(i,j+1,k,QW) = qleft(i,j+1,k,QW) + 0.5d0*dt*srcQ(i,j,k,QW) - qleft(i,j+1,k,QPRES) = qleft(i,j+1,k,QPRES) + 0.5d0*dt*srcQ(i,j,k,QPRES) - qleft(i,j+1,k,QREINT) = qleft(i,j+1,k,QREINT) + 0.5d0*dt*srcQ(i,j,k,QREINT) - - else - qleft(i,j,k+1,QRHO) = max(small_dens, qleft(i,j,k+1,QRHO) + 0.5d0*dt*srcQ(i,j,k,QRHO)) - qleft(i,j,k+1,QU) = qleft(i,j,k+1,QU) + 0.5d0*dt*srcQ(i,j,k,QU) - qleft(i,j,k+1,QV) = qleft(i,j,k+1,QV) + 0.5d0*dt*srcQ(i,j,k,QV) - qleft(i,j,k+1,QW) = qleft(i,j,k+1,QW) + 0.5d0*dt*srcQ(i,j,k,QW) - qleft(i,j,k+1,QPRES) = qleft(i,j,k+1,QPRES) + 0.5d0*dt*srcQ(i,j,k,QPRES) - qleft(i,j,k+1,QREINT) = qleft(i,j,k+1,QREINT) + 0.5d0*dt*srcQ(i,j,k,QREINT) - end if - - qright(i,j,k,QRHO) = max(small_dens, qright(i,j,k,QRHO) + 0.5d0*dt*srcQ(i,j,k,QRHO)) - qright(i,j,k,QU) = qright(i,j,k,QU) + 0.5d0*dt*srcQ(i,j,k,QU) - qright(i,j,k,QV) = qright(i,j,k,QV) + 0.5d0*dt*srcQ(i,j,k,QV) - qright(i,j,k,QW) = qright(i,j,k,QW) + 0.5d0*dt*srcQ(i,j,k,QW) - qright(i,j,k,QPRES) = qright(i,j,k,QPRES) + 0.5d0*dt*srcQ(i,j,k,QPRES) - qright(i,j,k,QREINT) = qright(i,j,k,QREINT) + 0.5d0*dt*srcQ(i,j,k,QREINT) - - enddo - enddo - enddo - - end subroutine plm - - !======================================== Minmod TVD slope limiter ========================================= - subroutine minmod(dW, WR, WL) - - use amrex_fort_module, only : rt => amrex_real - - implicit none - - real(rt), intent(in) :: WR, WL - real(rt), intent(out) :: dW - dW = 0.d0 - - if (abs(WR) < abs(WL) .and. WR*WL > 0.d0) then - dW = WR - else if (abs(WL) < abs(WR) .and. WR*WL > 0.d0) then - dW = WL - endif - - end subroutine minmod - - - !========================================= VanLeer TVD slope limiter ======================================= - subroutine vanleer(dW, WR, WL) - - use amrex_fort_module, only : rt => amrex_real - - implicit none - - real(rt), intent(in ) :: WR, WL - real(rt), intent(out) :: dW - dW = 0.0d0 - - if( WR*WL .gt. 0.0d0 ) then - dW = 2.0d0*WR*WL/(WR + WL) - endif - - end subroutine vanleer - - !========================================== centered difference =========================================== - subroutine centerdif(dW, WR, WL) - - use amrex_fort_module, only : rt => amrex_real - - implicit none - - real(rt), intent(in ) :: WR, WL - real(rt), intent(out) :: dW - - dW = (WR+WL)/2.0d0 - - end subroutine centerdif - - !================================== second order MC ============================== - subroutine secondMC(dW, WR, WL) - - use amrex_fort_module, only : rt => amrex_real - use amrex_constants_module, only : ZERO, HALF, ONE, TWO - - implicit none - - real(rt), intent(in ) :: WR, WL - real(rt), intent(out ) :: dW - - real(rt) :: dlim - - if (WR * WL .ge. ZERO) then - dlim = TWO * min(abs(WR), abs(WL)) - else - dlim = ZERO - endif - - dW = min(HALF * abs(WR + WL), dlim ) * sign(ONE, WR + WL) - - - end subroutine secondMC - - - - !================================================================ - subroutine slope(dW, WR, WL, flat) - use amrex_fort_module, only : rt => amrex_real - - implicit none - real(rt), intent(in ) :: flat - real(rt), intent(in ) :: WR, WL - real(rt), intent(out) :: dW - - if (mhd_plm_slope == 0) then - dW = 0.0 - elseif (mhd_plm_slope == 1) then - call vanleer(dW,WR,WL) - elseif (mhd_plm_slope == 2) then - call centerdif(dW,WR,WL) - elseif (mhd_plm_slope == 3) then - call secondMC(dW,WR,WL) - endif - - if (use_flattening == 1) then - dW = flat * dW - endif - - end subroutine slope - - !=========================================== Evals ========================================================= - - subroutine evals(lam, qaux, Q, dir) - - use amrex_fort_module, only : rt => amrex_real - use network, only: nspec - implicit none - - real(rt), intent(in) :: Q(NQ), qaux(NQAUX) - real(rt), intent(out) :: lam(NEIGN) !7 waves - integer, intent(in) :: dir !Choose direction, 1 for x, 2 for y, 3 for z - - !The characteristic speeds of the system - real(rt) :: cfx, cfy, cfz, cax, cay, caz, csx, csy, csz, ca, as - - ! speeds - as = qaux(QC) * qaux(QC) - - ! Alfven - ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) - cax = (Q(QMAGX)**2)/Q(QRHO) - cay = (Q(QMAGY)**2)/Q(QRHO) - caz = (Q(QMAGZ)**2)/Q(QRHO) - - ! Slow - csx = 0.5d0*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cax)) - csy = 0.5d0*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cay)) - csz = 0.5d0*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*caz)) - - ! Fast - cfx = 0.5d0*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cax)) - cfy = 0.5d0*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cay)) - cfz = 0.5d0*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*caz)) - - if(dir.eq.1) then - - !Ax eigenvalues - lam(1) = Q(QU) - sqrt(cfx) - lam(2) = Q(QU) - sqrt(cax) - lam(3) = Q(QU) - sqrt(csx) - lam(4) = Q(QU) - lam(5) = Q(QU) + sqrt(csx) - lam(6) = Q(QU) + sqrt(cax) - lam(7) = Q(QU) + sqrt(cfx) - - elseif(dir.eq.2) then - - !Ay eigenvalues - lam(1) = Q(QV) - sqrt(cfy) - lam(2) = Q(QV) - sqrt(cay) - lam(3) = Q(QV) - sqrt(csy) - lam(4) = Q(QV) - lam(5) = Q(QV) + sqrt(csy) - lam(6) = Q(QV) + sqrt(cay) - lam(7) = Q(QV) + sqrt(cfy) - - else - - !Az eigenvalues - lam(1) = Q(QW) - sqrt(cfz) - lam(2) = Q(QW) - sqrt(caz) - lam(3) = Q(QW) - sqrt(csz) - lam(4) = Q(QW) - lam(5) = Q(QW) + sqrt(csz) - lam(6) = Q(QW) + sqrt(caz) - lam(7) = Q(QW) + sqrt(cfz) - endif - - end subroutine evals - - !====================================== Left Eigenvectors =============================================== - - !x direction - subroutine evecx(leig, reig, qaux, Q) - use amrex_fort_module, only : rt => amrex_real - use network, only : nspec - - implicit none - - !returnes Leig, where the rows are the left eigenvectors of the characteristic matrix Ax - real(rt), intent(in) ::Q(NQ), qaux(NQAUX) - real(rt), intent(out) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN) - - !The characteristic speeds of the system - real(rt) :: cfx, cax, csx, ca, as, S, N - real(rt) :: cff, css, Qf, Qs, AAf, AAs, alf, als, bety, betz - - ! Speeds - - as = qaux(QC) * qaux(QC) - - ! Alfven - ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) - cax = (Q(QMAGX)**2)/Q(QRHO) - - ! Slow - csx = 0.5d0*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cax)) - - ! Fast - cfx = 0.5d0*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cax)) - - !useful constants - alf = sqrt((as - csx)/(cfx - csx)) - als = sqrt((cfx - as)/(cfx - csx)) - if(cfx - as .lt. 0.d0) als = 0.d0 - if(as - csx .lt. 0.d0) alf = 0.d0 - - if(abs(Q(QMAGY)).le. 1.d-14 .and.abs(Q(QMAGZ)).le. 1.d-14) then - bety = 1.d0/sqrt(2.d0) - betz = bety - else - bety = Q(QMAGY)/(sqrt(Q(QMAGY)**2 + Q(QMAGZ)**2)) - betz = Q(QMAGZ)/(sqrt(Q(QMAGY)**2 + Q(QMAGZ)**2)) - endif - - cff = sqrt(cfx)*alf - css = sqrt(csx)*als - S = sign(1.0d0, Q(QMAGX)) - Qf = sqrt(cfx)*alf*S - Qs = sqrt(csx)*als*S - N = 0.5d0/as - AAf = sqrt(as)*alf*sqrt(Q(QRHO)) - AAs = sqrt(as)*als*sqrt(Q(QRHO)) - - - leig(1,:) = (/0.d0, -N*Cff, N*Qs*bety, N*Qs*betz, N*alf/Q(QRHO), N*AAs*bety/Q(QRHO), N*AAs*betz/Q(QRHO)/) !u - cf - leig(2,:) = (/0.d0, 0.d0, -0.5d0*betz, 0.5d0*bety, 0.d0, -0.5d0*S*betz/(sqrt(Q(QRHO))), 0.5d0*bety*S/(sqrt(Q(QRHO)))/) !u - cAx - leig(3,:) = (/0.d0, -N*Css, -N*Qf*bety, -N*Qf*betz, N*als/Q(QRHO), -N*AAf*bety/Q(QRHO), -N*AAf*betz/Q(QRHO)/) !u - cs - leig(4,:) = (/1.d0, 0.d0, 0.d0, 0.d0, -1.d0/as, 0.d0, 0.d0/) !u - leig(5,:) = (/0.d0, N*Css, N*Qf*bety, N*Qf*betz, N*als/Q(QRHO), -N*AAf*bety/Q(QRHO), -N*AAf*betz/Q(QRHO)/) !u + cs - leig(6,:) = (/0.d0, 0.d0, 0.5d0*betz, -0.5d0*bety, 0.d0, -0.5d0*betz*S/(sqrt(Q(QRHO))), 0.5d0*bety*S/(sqrt(Q(QRHO)))/) !u + cAx - leig(7,:) = (/0.d0, N*Cff, -N*Qs*bety, -N*Qs*betz, N*alf/Q(QRHO), N*AAs*bety/Q(QRHO), N*AAs*betz/Q(QRHO)/) !u + cf - - ! u - cf u - Cax u - cs u u + cs u + Cax u + cf - reig(IEIGN_RHO,:) = (/Q(QRHO)*alf, 0.d0, Q(QRHO)*als, 1.d0, Q(QRHO)*als, 0.d0, Q(QRHO)*alf/) - reig(IEIGN_U,:) = (/-cff , 0.d0, -css, 0.d0, css, 0.d0, cff/) - reig(IEIGN_V,:) = (/Qs*bety, -betz, -Qf*bety, 0.d0, Qf*bety, betz, -Qs*bety/) - reig(IEIGN_W,:) = (/Qs*betz, bety, -Qf*betz, 0.d0, Qf*betz, -bety, -Qs*betz/) - reig(IEIGN_P,:) = (/Q(QRHO)*as*alf, 0.d0, Q(QRHO)*as*als, 0.d0 , Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*alf/) - reig(IEIGN_BT,:) = (/AAs*bety, -betz*S*sqrt(Q(QRHO)), -AAf*bety, 0.d0 , -AAf*bety, -betz*S*sqrt(Q(QRHO)), AAs*bety/) - reig(IEIGN_BTT,:) = (/AAs*betz, bety*S*sqrt(Q(QRHO)), -AAf*betz, 0.d0, -AAf*betz, bety*S*sqrt(Q(QRHO)), AAs*betz/) - - - end subroutine evecx - - !y direction - subroutine evecy(leig, reig, qaux, Q) - use amrex_fort_module, only : rt => amrex_real - use network, only : nspec - - implicit none - - !returnes Leig, where the rows are the left eigenvectors of the characteristic matrix Ay - real(rt), intent(in) :: Q(NQ), qaux(NQAUX) - real(rt), intent(out) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN) - - !The characteristic speeds of the system - real(rt) :: cfy, cay, csy, ca, as, S, N - real(rt) :: cff, css, Qf, Qs, AAf, AAs, alf, als, betx, betz - - - ! Speeds - as = qaux(QC) * qaux(QC) - - ! Alfven - ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) - cay = (Q(QMAGY)**2)/Q(QRHO) - - ! Slow - csy = 0.5d0*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*cay)) - - ! Fast - cfy = 0.5d0*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*cay)) - - !useful constants - alf = sqrt((as - csy)/(cfy - csy)) - als = sqrt((cfy - as)/(cfy - csy)) - if(as - csy .lt. 0.d0) alf = 0.d0 - if(cfy - as .lt. 0.d0) als = 0.d0 - - if(abs(Q(QMAGX)).le. 1.d-14 .and.abs(Q(QMAGZ)).le. 1.d-14) then - betx = 1.d0/sqrt(2.d0) - betz = betx - else - betx = Q(QMAGX)/(sqrt(Q(QMAGX)**2 + Q(QMAGZ)**2)) - betz = Q(QMAGZ)/(sqrt(Q(QMAGX)**2 + Q(QMAGZ)**2)) - endif - - cff = sqrt(cfy)*alf - css = sqrt(csy)*als - S = sign(1.0d0, Q(QMAGY)) - Qf = sqrt(cfy)*alf*S - Qs = sqrt(csy)*als*S - AAf = sqrt(as)*alf*sqrt(Q(QRHO)) - AAs = sqrt(as)*als*sqrt(Q(QRHO)) - N = 0.5d0/as - - !Need to double check the rows - leig(1,:) = (/0.d0, N*Qs*betx, -N*Cff , N*Qs*betz, N*alf/Q(QRHO), N*AAs*betx/Q(QRHO), N*AAs*betz/Q(QRHO)/) ! v - cf - leig(2,:) = (/0.d0, -0.5d0*betz, 0.d0, 0.5d0*betx, 0.d0, -0.5d0*betz*S/(sqrt(Q(QRHO))), 0.5d0*betx*S/(sqrt(Q(QRHO)))/) ! v - cAy - leig(3,:) = (/0.d0, -N*Qf*betx, -N*Css, -N*Qf*betz, N*als/Q(QRHO), -N*AAf*betx/Q(QRHO), -N*AAf*betz/Q(QRHO)/) ! v - cs - leig(4,:) = (/1.d0, 0.d0, 0.d0, 0.d0, -1.d0/as, 0.d0, 0.d0/) ! v - leig(5,:) = (/0.d0, N*Qf*betx, N*Css, N*Qf*betz, N*als/Q(QRHO), -N*AAf*betx/Q(QRHO), -N*AAf*betz/Q(QRHO)/) ! v + cs - leig(6,:) = (/0.d0, 0.5d0*betz, 0.d0, -0.5d0*betx, 0.d0, -0.5d0*betz*S/(sqrt(Q(QRHO))), 0.5d0*betx*S/(sqrt(Q(QRHO)))/) ! v + cAy - leig(7,:) = (/0.d0, -N*Qs*betx, N*Cff, -N*Qs*betz, N*alf/Q(QRHO), N*AAs*betx/Q(QRHO), N*AAs*betz/Q(QRHO)/) ! v + cf - - ! v - cf v - Cay v - cs v v + cs v + Cay v + cf - reig(IEIGN_RHO,:) = (/Q(QRHO)*alf, 0.d0, Q(QRHO)*als, 1.d0, Q(QRHO)*als, 0.d0, Q(QRHO)*alf/) - reig(IEIGN_V,:) = (/-cff, 0.d0, -css, 0.d0 , css, 0.d0, cff/) - reig(IEIGN_U,:) = (/Qs*betx, -betz, -Qf*betx, 0.d0 , Qf*betx, betz, -Qs*betx/) - reig(IEIGN_W,:) = (/Qs*betz, betx, -Qf*betz, 0.d0 , Qf*betz, -betx , -Qs*betz/) - reig(IEIGN_P,:) = (/Q(QRHO)*as*alf, 0.d0, Q(QRHO)*as*als, 0.d0 , Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*alf/) - reig(IEIGN_BT,:) = (/AAs*betx, -betz*S*sqrt(Q(QRHO)), -AAf*betx, 0.d0 , -AAf*betx, -betz*S*sqrt(Q(QRHO)) , AAs*betx/) - reig(IEIGN_BTT,:) = (/AAs*betz, betx*S*sqrt(Q(QRHO)), -AAf*betz, 0.d0, -AAf*betz, betx*S*sqrt(Q(QRHO)), AAs*betz/) - - end subroutine evecy - - !z direction - subroutine evecz(leig, reig, qaux, Q) - use amrex_fort_module, only : rt => amrex_real - use network, only : nspec - - implicit none - - !returnes Leig, where the rows are the left eigenvectors of the characteristic matrix Az - real(rt), intent(in) :: Q(NQ), qaux(NQAUX) - real(rt), intent(out) :: leig(NEIGN,NEIGN), reig(NEIGN,NEIGN) - - !The characteristic speeds of the system - real(rt) :: cfz, caz, csz, ca, as, S, N - real(rt) :: cff, css, Qf, Qs, AAf, AAs, alf, als, betx, bety - - ! Speeds - as = qaux(QC) * qaux(QC) - - ! Alfven - ca = (Q(QMAGX)**2 + Q(QMAGY)**2 + Q(QMAGZ)**2)/Q(QRHO) - caz = (Q(QMAGZ)**2)/Q(QRHO) - - ! Slow - csz = 0.5d0*((as + ca) - sqrt((as + ca)**2 - 4.0d0*as*caz)) - - ! Fast - cfz = 0.5d0*((as + ca) + sqrt((as + ca)**2 - 4.0d0*as*caz)) - - !useful constants - alf = sqrt((as - csz)/(cfz - csz)) - als = sqrt((cfz - as)/(cfz - csz)) - - if(cfz - as .lt. 0.d0) als = 0.d0 - - if(abs(Q(QMAGX)).le. 1.d-14 .and.abs(Q(QMAGY)).le. 1.d-14) then - betx = 1.d0/sqrt(2.d0) - bety = betx - else - betx = Q(QMAGX)/(sqrt(Q(QMAGX)**2 + Q(QMAGY)**2)) - bety = Q(QMAGY)/(sqrt(Q(QMAGX)**2 + Q(QMAGY)**2)) - endif - - cff = sqrt(cfz)*alf - css = sqrt(csz)*als - S = sign(1.0d0, Q(QMAGZ)) - Qf = sqrt(cfz)*alf*S - Qs = sqrt(csz)*als*S - AAf = sqrt(as)*alf*sqrt(Q(QRHO)) - AAs = sqrt(as)*als*sqrt(Q(QRHO)) - N = 0.5d0/as - - !Need to double check the order - leig(1,:) = (/0.d0, N*Qs*betx, N*Qs*bety, -N*Cff, N*alf/Q(QRHO) , N*AAs*betx/Q(QRHO), N*AAs*bety/Q(QRHO)/) !w - cf - leig(2,:) = (/0.d0, -0.5d0*bety, 0.5d0*betx, 0.d0, 0.d0, -0.5d0*S*bety/(sqrt(Q(QRHO))) , 0.5d0*betx*S/(sqrt(Q(QRHO)))/) !w - cAz - leig(3,:) = (/0.d0, -N*Qf*betx, -N*Qf*bety, -N*Css, N*als/Q(QRHO) , -N*AAf*betx/Q(QRHO), -N*AAf*bety/Q(QRHO)/) !w - cs - leig(4,:) = (/1.d0, 0.d0 , 0.d0, 0.d0, -1.d0/as, 0.d0, 0.d0/) !w - leig(5,:) = (/0.d0, N*Qf*betx, N*Qf*bety, N*Css, N*als/Q(QRHO) , -N*AAf*betx/Q(QRHO), -N*AAf*bety/Q(QRHO)/) !w + cs - leig(6,:) = (/0.d0, 0.5d0*bety , -0.5d0*betx, 0.0d0, 0.d0 , -0.5d0*bety*S/(sqrt(Q(QRHO))) , 0.5d0*betx*S/(sqrt(Q(QRHO))) /) !w + cAz - leig(7,:) = (/0.d0, -N*Qs*betx, -N*Qs*bety, N*Cff , N*alf/Q(QRHO) , N*AAs*betx/Q(QRHO) , N*AAs*bety/Q(QRHO) /) !w + cf - - ! w - cf w - Caz w - cs w w + cs w + Caz w + cf - reig(IEIGN_RHO,:) = (/Q(QRHO)*alf, 0.d0, Q(QRHO)*als, 1.d0, Q(QRHO)*als, 0.d0, Q(QRHO)*alf/) - reig(IEIGN_W,:) = (/-cff , 0.d0, -css, 0.d0, css, 0.d0 , cff/) - reig(IEIGN_U,:) = (/Qs*betx, -bety, -Qf*betx, 0.d0, Qf*betx, bety, -Qs*betx/) - reig(IEIGN_V,:) = (/Qs*bety, betx, -Qf*bety, 0.d0, Qf*bety, -betx , -Qs*bety/) - reig(IEIGN_P,:) = (/Q(QRHO)*as*alf, 0.d0, Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*als, 0.d0, Q(QRHO)*as*alf/) - reig(IEIGN_BT,:) = (/AAs*betx, -bety*S*sqrt(Q(QRHO)), -AAf*betx, 0.d0, -AAf*betx, -bety*S*sqrt(Q(QRHO)), AAs*betx/) - reig(IEIGN_BTT,:) = (/AAs*bety, betx*S*sqrt(Q(QRHO)), -AAf*bety, 0.d0, -AAf*bety, betx*S*sqrt(Q(QRHO)), AAs*bety/) - - end subroutine evecz - -end module mhd_plm_module From d0833fbcb46fdcd0876b8bf44bd3fe2082d913dc Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sat, 23 May 2020 11:50:47 -0400 Subject: [PATCH 18/23] fix some compiler warnings --- Source/mhd/Castro_mhd.cpp | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Source/mhd/Castro_mhd.cpp b/Source/mhd/Castro_mhd.cpp index 4473370f4e..a1e8d2686a 100644 --- a/Source/mhd/Castro_mhd.cpp +++ b/Source/mhd/Castro_mhd.cpp @@ -11,14 +11,7 @@ Castro::just_the_mhd(Real time, Real dt) hydro_source.setVal(0.0); - const int finest_level = parent->finestLevel(); - const auto dx = geom.CellSizeArray(); - const Real* dx_f = geom.CellSize(); - - const int* domain_lo = geom.Domain().loVect(); - const int* domain_hi = geom.Domain().hiVect(); - MultiFab& S_new = get_new_data(State_Type); MultiFab& Bx_new= get_new_data(Mag_Type_x); @@ -89,14 +82,9 @@ Castro::just_the_mhd(Real time, Real dt) // box with NUM_GROW ghost cells for PPM stuff const Box& bx_gc = amrex::grow(bx, NUM_GROW); - const int* lo = bx.loVect(); - const int* hi = bx.hiVect(); - FArrayBox &statein = Sborder[mfi]; auto u_arr = statein.array(); - FArrayBox &stateout = S_new[mfi]; - FArrayBox &source_in = sources_for_hydro[mfi]; auto src_arr = source_in.array(); @@ -178,18 +166,11 @@ Castro::just_the_mhd(Real time, Real dt) auto src_q_arr = srcQ.array(); auto elix_src_q = srcQ.elixir(); - const int* lo_gc = bx_gc.loVect(); - const int* hi_gc = bx_gc.hiVect(); - ctoprim(bx_gc, time, u_arr, Bx_arr, By_arr, Bz_arr, q_arr, qaux_arr); - const int* lo1 = obx.loVect(); - const int* hi1 = obx.hiVect(); - - src_to_prim(bx_gc, q_arr, src_arr, src_q_arr); check_for_mhd_cfl_violation(bx, dt, q_arr, qaux_arr); From 0c7917de41d58c1d4beaf118893ae8c4da9b3f5a Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sat, 23 May 2020 12:53:16 -0400 Subject: [PATCH 19/23] fix an index --- Source/mhd/mhd_eigen.H | 2 +- Source/mhd/mhd_plm.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/mhd/mhd_eigen.H b/Source/mhd/mhd_eigen.H index 10af6bd396..cf4e0e1daf 100644 --- a/Source/mhd/mhd_eigen.H +++ b/Source/mhd/mhd_eigen.H @@ -178,7 +178,7 @@ Castro::evecx(Array2D& leig, leig(6, IEIGN_W) = -N*Qs*betz; leig(6, IEIGN_P) = N*alf/Q[QRHO]; leig(6, IEIGN_BT) = N*AAs*bety/Q[QRHO]; - leig(7, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; + leig(6, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; // u - cf ; u - Cax ; u - cs ; u ; u + cs ; u + Cax ; u + cf diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp index b377d0bbfc..ed9f61a916 100644 --- a/Source/mhd/mhd_plm.cpp +++ b/Source/mhd/mhd_plm.cpp @@ -180,7 +180,7 @@ Castro::plm(const Box& bx, dR += leig(ii,n) * dQR[n]; } - Real dW; + Real dW = 0.0; slope(dW, dL, dR, flatn(i,j,k)); for (int n = 0; n < NEIGN; n++) { @@ -261,7 +261,7 @@ Castro::plm(const Box& bx, Real dL; Real dR; Real un; - Real dW; + Real dW = 0.0; if (idir == 0) { dL = s(i,j,k,QFS+n) - s(i-1,j,k,QFS+n); From 3be7a18a97a36cee125504664121733d5b4bab65 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sat, 23 May 2020 13:45:58 -0400 Subject: [PATCH 20/23] fix location of qualifiers --- Source/mhd/Castro_mhd.H | 14 +++++++------- Source/mhd/mhd_eigen.H | 8 ++++---- Source/mhd/mhd_util.H | 10 +++++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/mhd/Castro_mhd.H b/Source/mhd/Castro_mhd.H index cf0a1645d6..f12303dfb4 100644 --- a/Source/mhd/Castro_mhd.H +++ b/Source/mhd/Castro_mhd.H @@ -20,26 +20,26 @@ amrex::Array4 const& srcQ, const amrex::Real dt); - void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + void evals(amrex::Real* lam, const amrex::Real as_in, amrex::Real* Q, const int dir); - void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + void evecx(amrex::Array2D& leig, amrex::Array2D& reig, const amrex::Real as_in, amrex::Real* Q); - void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + void evecy(amrex::Array2D& leig, amrex::Array2D& reig, const amrex::Real as_in, amrex::Real* Q); - void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + void evecz(amrex::Array2D& leig, amrex::Array2D& reig, const amrex::Real as_in, @@ -67,8 +67,8 @@ const amrex::Real dt); - void AMREX_GPU_DEVICE AMREX_FORCE_INLINE + void qflux(amrex::Real* qflx, amrex::Real* flx, amrex::Real* q_zone); void @@ -92,8 +92,8 @@ amrex::Array4 const& flxx, amrex::Array4 const& flxy); - void AMREX_GPU_DEVICE AMREX_FORCE_INLINE + void electric(amrex::Real* q_zone, amrex::Real& E_zone, const int comp); @@ -122,8 +122,8 @@ amrex::Array4 const& Ed2, const int d, const int d1, const int d2, const amrex::Real dt); - void AMREX_GPU_DEVICE AMREX_FORCE_INLINE + void ConsToPrim(amrex::Real* q_zone, amrex::Real* U_zone); diff --git a/Source/mhd/mhd_eigen.H b/Source/mhd/mhd_eigen.H index cf4e0e1daf..5a6e7c510b 100644 --- a/Source/mhd/mhd_eigen.H +++ b/Source/mhd/mhd_eigen.H @@ -3,8 +3,8 @@ #include "mhd_util.H" -void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void Castro::evals(Real* lam, const Real as_in, Real* Q, const int dir) { // The characteristic speeds of the system @@ -52,8 +52,8 @@ Castro::evals(Real* lam, const Real as_in, Real* Q, const int dir) { } -void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void Castro::evecx(Array2D& leig, Array2D& reig, const Real as_in, @@ -241,8 +241,8 @@ Castro::evecx(Array2D& leig, } -void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void Castro::evecy(Array2D& leig, Array2D& reig, const Real as_in, @@ -431,8 +431,8 @@ Castro::evecy(Array2D& leig, } -void AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void Castro::evecz(Array2D& leig, Array2D& reig, const Real as_in, diff --git a/Source/mhd/mhd_util.H b/Source/mhd/mhd_util.H index e22943f6b0..4dd96f8182 100644 --- a/Source/mhd/mhd_util.H +++ b/Source/mhd/mhd_util.H @@ -7,8 +7,8 @@ using namespace amrex; // sound speed calc for ideal MHD -void AMREX_GPU_DEVICE AMREX_FORCE_INLINE +void eos_soundspeed_mhd(Real& c, Real as, Real ca, Real bd) { // inputs: @@ -21,8 +21,8 @@ eos_soundspeed_mhd(Real& c, Real as, Real ca, Real bd) { c = std::sqrt(c); } -void AMREX_GPU_DEVICE AMREX_FORCE_INLINE +void Castro::qflux(Real* qflx, Real* flx, Real* q_zone) { // Calculate the C to P Jacobian applied to the fluxes @@ -71,8 +71,8 @@ Castro::qflux(Real* qflx, Real* flx, Real* q_zone) { } -void AMREX_GPU_DEVICE AMREX_FORCE_INLINE +void Castro::electric(Real* q_zone, Real& E_zone, const int comp) { // this takes the cell-center primitive state, q_zone, and computes the cell-center @@ -92,8 +92,8 @@ Castro::electric(Real* q_zone, Real& E_zone, const int comp) { } -void AMREX_GPU_DEVICE AMREX_FORCE_INLINE +void Castro::ConsToPrim(Real* q_zone, Real* U_zone) { // calculate the primitive variables from the conserved @@ -141,8 +141,8 @@ Castro::ConsToPrim(Real* q_zone, Real* U_zone) { -int AMREX_GPU_DEVICE AMREX_FORCE_INLINE +int epsilon_ijk(const int i, const int j, const int k) { int val; From 60d54eed0bcf41a3cc4078d933d01812fa5773f6 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sat, 23 May 2020 14:05:47 -0400 Subject: [PATCH 21/23] convert some arrays to Array1D --- Source/mhd/Castro_mhd.H | 10 +- Source/mhd/mhd_eigen.H | 249 ++++++++++++++++++++-------------------- Source/mhd/mhd_plm.cpp | 106 ++++++++--------- 3 files changed, 185 insertions(+), 180 deletions(-) diff --git a/Source/mhd/Castro_mhd.H b/Source/mhd/Castro_mhd.H index f12303dfb4..a93cc4bfef 100644 --- a/Source/mhd/Castro_mhd.H +++ b/Source/mhd/Castro_mhd.H @@ -22,28 +22,30 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void - evals(amrex::Real* lam, const amrex::Real as_in, amrex::Real* Q, const int dir); + evals(amrex::Array1D& lam, + const amrex::Real as_in, + amrex::Array1D& Q, const int dir); AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void evecx(amrex::Array2D& leig, amrex::Array2D& reig, const amrex::Real as_in, - amrex::Real* Q); + amrex::Array1D& Q); AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void evecy(amrex::Array2D& leig, amrex::Array2D& reig, const amrex::Real as_in, - amrex::Real* Q); + amrex::Array1D& Q); AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void evecz(amrex::Array2D& leig, amrex::Array2D& reig, const amrex::Real as_in, - amrex::Real* Q); + amrex::Array1D& Q); void consup_mhd(const amrex::Box& bx, diff --git a/Source/mhd/mhd_eigen.H b/Source/mhd/mhd_eigen.H index 5a6e7c510b..25b83745aa 100644 --- a/Source/mhd/mhd_eigen.H +++ b/Source/mhd/mhd_eigen.H @@ -5,13 +5,16 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void -Castro::evals(Real* lam, const Real as_in, Real* Q, const int dir) { +Castro::evals(Array1D& lam, + const Real as_in, + Array1D& Q, + const int dir) { // The characteristic speeds of the system // Alfven - Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; + Real ca = (Q(QMAGX)*Q(QMAGX) + Q(QMAGY)*Q(QMAGY) + Q(QMAGZ)*Q(QMAGZ)) / Q(QRHO); int QUN; Real cad; // Alfven @@ -22,32 +25,32 @@ Castro::evals(Real* lam, const Real as_in, Real* Q, const int dir) { if (dir == 0) { QUN = QU; - cad = (Q[QMAGX]*Q[QMAGX]) / Q[QRHO]; + cad = (Q(QMAGX)*Q(QMAGX)) / Q(QRHO); cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); } else if (dir == 1) { QUN = QV; - cad = (Q[QMAGY]*Q[QMAGY]) / Q[QRHO]; + cad = (Q(QMAGY)*Q(QMAGY)) / Q(QRHO); cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); } else { QUN = QW; - cad = (Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; + cad = (Q(QMAGZ)*Q(QMAGZ)) / Q(QRHO); cs = 0.5_rt * ((as + ca) - std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); cf = 0.5_rt * ((as + ca) + std::sqrt((as + ca)*(as + ca) - 4.0_rt*as*cad)); } // eigenvalues - lam[0] = Q[QUN] - std::sqrt(cf); - lam[1] = Q[QUN] - std::sqrt(cad); - lam[2] = Q[QUN] - std::sqrt(cs); - lam[3] = Q[QUN]; - lam[4] = Q[QUN] + std::sqrt(cs); - lam[5] = Q[QUN] + std::sqrt(cad); - lam[6] = Q[QUN] + std::sqrt(cf); + lam(0) = Q(QUN) - std::sqrt(cf); + lam(1) = Q(QUN) - std::sqrt(cad); + lam(2) = Q(QUN) - std::sqrt(cs); + lam(3) = Q(QUN); + lam(4) = Q(QUN) + std::sqrt(cs); + lam(5) = Q(QUN) + std::sqrt(cad); + lam(6) = Q(QUN) + std::sqrt(cf); } @@ -57,7 +60,7 @@ void Castro::evecx(Array2D& leig, Array2D& reig, const Real as_in, - Real* Q) { + Array1D& Q) { // returns Leig, where the rows are the left eigenvectors of the characteristic matrix Ax @@ -67,8 +70,8 @@ Castro::evecx(Array2D& leig, // Alfven - Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; - Real cax = (Q[QMAGX]*Q[QMAGX]) / Q[QRHO]; + Real ca = (Q(QMAGX)*Q(QMAGX) + Q(QMAGY)*Q(QMAGY) + Q(QMAGZ)*Q(QMAGZ)) / Q(QRHO); + Real cax = (Q(QMAGX)*Q(QMAGX)) / Q(QRHO); // Slow @@ -94,27 +97,27 @@ Castro::evecx(Array2D& leig, Real bety; Real betz; - if (std::abs(Q[QMAGY]) <= 1.e-14_rt && std::abs(Q[QMAGZ]) <= 1.e-14_rt) { + if (std::abs(Q(QMAGY)) <= 1.e-14_rt && std::abs(Q(QMAGZ)) <= 1.e-14_rt) { bety = 1.0_rt / std::sqrt(2.0_rt); betz = bety; } else { - bety = Q[QMAGY] / (std::sqrt(Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ])); - betz = Q[QMAGZ] / (std::sqrt(Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ])); + bety = Q(QMAGY) / (std::sqrt(Q(QMAGY)*Q(QMAGY) + Q(QMAGZ)*Q(QMAGZ))); + betz = Q(QMAGZ) / (std::sqrt(Q(QMAGY)*Q(QMAGY) + Q(QMAGZ)*Q(QMAGZ))); } Real cff = std::sqrt(cfx) * alf; Real css = std::sqrt(csx) * als; - Real S = std::copysign(1.0_rt, Q[QMAGX]); + Real S = std::copysign(1.0_rt, Q(QMAGX)); Real Qf = std::sqrt(cfx) * alf * S; Real Qs = std::sqrt(csx) * als * S; Real N = 0.5_rt / as; - Real AAf = std::sqrt(as) * alf * std::sqrt(Q[QRHO]); - Real AAs = std::sqrt(as) * als * std::sqrt(Q[QRHO]); + Real AAf = std::sqrt(as) * alf * std::sqrt(Q(QRHO)); + Real AAs = std::sqrt(as) * als * std::sqrt(Q(QRHO)); // u - cf wave @@ -122,9 +125,9 @@ Castro::evecx(Array2D& leig, leig(0, IEIGN_U) = -N*cff; leig(0, IEIGN_V) = N*Qs*bety; leig(0, IEIGN_W) = N*Qs*betz; - leig(0, IEIGN_P) = N*alf/Q[QRHO]; - leig(0, IEIGN_BT) = N*AAs*bety/Q[QRHO]; - leig(0, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; + leig(0, IEIGN_P) = N*alf/Q(QRHO); + leig(0, IEIGN_BT) = N*AAs*bety/Q(QRHO); + leig(0, IEIGN_BTT) = N*AAs*betz/Q(QRHO); // u - cax leig(1, IEIGN_RHO) = 0.0; @@ -132,17 +135,17 @@ Castro::evecx(Array2D& leig, leig(1, IEIGN_V) = -0.5_rt*betz; leig(1, IEIGN_W) = 0.5_rt*bety; leig(1, IEIGN_P) = 0.0; - leig(1, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q[QRHO]); - leig(1, IEIGN_BTT) = 0.5_rt*bety*S/std::sqrt(Q[QRHO]); + leig(1, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q(QRHO)); + leig(1, IEIGN_BTT) = 0.5_rt*bety*S/std::sqrt(Q(QRHO)); // u - cs leig(2, IEIGN_RHO) = 0.0; leig(2, IEIGN_U) = -N*css; leig(2, IEIGN_V) = -N*Qf*bety; leig(2, IEIGN_W) = -N*Qf*betz; - leig(2, IEIGN_P) = N*als/Q[QRHO]; - leig(2, IEIGN_BT) = -N*AAf*bety/Q[QRHO]; - leig(2, IEIGN_BTT) = -N*AAf*betz/Q[QRHO]; + leig(2, IEIGN_P) = N*als/Q(QRHO); + leig(2, IEIGN_BT) = -N*AAf*bety/Q(QRHO); + leig(2, IEIGN_BTT) = -N*AAf*betz/Q(QRHO); // u leig(3, IEIGN_RHO) = 1.0; @@ -158,9 +161,9 @@ Castro::evecx(Array2D& leig, leig(4, IEIGN_U) = N*css; leig(4, IEIGN_V) = N*Qf*bety; leig(4, IEIGN_W) = N*Qf*betz; - leig(4, IEIGN_P) = N*als/Q[QRHO]; - leig(4, IEIGN_BT) = -N*AAf*bety/Q[QRHO]; - leig(4, IEIGN_BTT) = -N*AAf*betz/Q[QRHO]; + leig(4, IEIGN_P) = N*als/Q(QRHO); + leig(4, IEIGN_BT) = -N*AAf*bety/Q(QRHO); + leig(4, IEIGN_BTT) = -N*AAf*betz/Q(QRHO); // u + cax leig(5, IEIGN_RHO) = 0.0; @@ -168,27 +171,27 @@ Castro::evecx(Array2D& leig, leig(5, IEIGN_V) = 0.5_rt*betz; leig(5, IEIGN_W) = -0.5_rt*bety; leig(5, IEIGN_P) = 0.0; - leig(5, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q[QRHO]); - leig(5, IEIGN_BTT) = 0.5_rt*bety*S/std::sqrt(Q[QRHO]); + leig(5, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q(QRHO)); + leig(5, IEIGN_BTT) = 0.5_rt*bety*S/std::sqrt(Q(QRHO)); // u + cf leig(6, IEIGN_RHO) = 0.0; leig(6, IEIGN_U) = N*cff; leig(6, IEIGN_V) = -N*Qs*bety; leig(6, IEIGN_W) = -N*Qs*betz; - leig(6, IEIGN_P) = N*alf/Q[QRHO]; - leig(6, IEIGN_BT) = N*AAs*bety/Q[QRHO]; - leig(6, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; + leig(6, IEIGN_P) = N*alf/Q(QRHO); + leig(6, IEIGN_BT) = N*AAs*bety/Q(QRHO); + leig(6, IEIGN_BTT) = N*AAs*betz/Q(QRHO); // u - cf ; u - Cax ; u - cs ; u ; u + cs ; u + Cax ; u + cf - reig(IEIGN_RHO, 0) = Q[QRHO]*alf; + reig(IEIGN_RHO, 0) = Q(QRHO)*alf; reig(IEIGN_RHO, 1) = 0.0; - reig(IEIGN_RHO, 2) = Q[QRHO]*als; + reig(IEIGN_RHO, 2) = Q(QRHO)*als; reig(IEIGN_RHO, 3) = 1.0_rt; - reig(IEIGN_RHO, 4) = Q[QRHO]*als; + reig(IEIGN_RHO, 4) = Q(QRHO)*als; reig(IEIGN_RHO, 5) = 0.0; - reig(IEIGN_RHO, 6) = Q[QRHO]*alf; + reig(IEIGN_RHO, 6) = Q(QRHO)*alf; reig(IEIGN_U, 0) = -cff; reig(IEIGN_U, 1) = 0.0; @@ -214,28 +217,28 @@ Castro::evecx(Array2D& leig, reig(IEIGN_W, 5) = -bety; reig(IEIGN_W, 6) = -Qs*betz; - reig(IEIGN_P, 0) = Q[QRHO]*as*alf; + reig(IEIGN_P, 0) = Q(QRHO)*as*alf; reig(IEIGN_P, 1) = 0.0; - reig(IEIGN_P, 2) = Q[QRHO]*as*als; + reig(IEIGN_P, 2) = Q(QRHO)*as*als; reig(IEIGN_P, 3) = 0.0; - reig(IEIGN_P, 4) = Q[QRHO]*as*als; + reig(IEIGN_P, 4) = Q(QRHO)*as*als; reig(IEIGN_P, 5) = 0.0; - reig(IEIGN_P, 6) = Q[QRHO]*as*alf; + reig(IEIGN_P, 6) = Q(QRHO)*as*alf; reig(IEIGN_BT, 0) = AAs*bety; - reig(IEIGN_BT, 1) = -betz*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 1) = -betz*S*std::sqrt(Q(QRHO)); reig(IEIGN_BT, 2) = -AAf*bety; reig(IEIGN_BT, 3) = 0.0; reig(IEIGN_BT, 4) = -AAf*bety; - reig(IEIGN_BT, 5) = -betz*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 5) = -betz*S*std::sqrt(Q(QRHO)); reig(IEIGN_BT, 6) = AAs*bety; reig(IEIGN_BTT, 0) = AAs*betz; - reig(IEIGN_BTT, 1) = bety*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 1) = bety*S*std::sqrt(Q(QRHO)); reig(IEIGN_BTT, 2) = -AAf*betz; reig(IEIGN_BTT, 3) = 0.0; reig(IEIGN_BTT, 4) = -AAf*betz; - reig(IEIGN_BTT, 5) = bety*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 5) = bety*S*std::sqrt(Q(QRHO)); reig(IEIGN_BTT, 6) = AAs*betz; } @@ -246,7 +249,7 @@ void Castro::evecy(Array2D& leig, Array2D& reig, const Real as_in, - Real* Q) { + Array1D& Q) { // returns Leig, where the rows are the left eigenvectors of the characteristic matrix Ay @@ -257,8 +260,8 @@ Castro::evecy(Array2D& leig, // Alfven - Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; - Real cay = (Q[QMAGY]*Q[QMAGY]) / Q[QRHO]; + Real ca = (Q(QMAGX)*Q(QMAGX) + Q(QMAGY)*Q(QMAGY) + Q(QMAGZ)*Q(QMAGZ)) / Q(QRHO); + Real cay = (Q(QMAGY)*Q(QMAGY)) / Q(QRHO); // Slow @@ -284,27 +287,27 @@ Castro::evecy(Array2D& leig, Real betx; Real betz; - if(std::abs(Q[QMAGX]) <= 1.e-14_rt && std::abs(Q[QMAGZ]) <= 1.e-14_rt) { + if(std::abs(Q(QMAGX)) <= 1.e-14_rt && std::abs(Q(QMAGZ)) <= 1.e-14_rt) { betx = 1.0_rt / std::sqrt(2.0_rt); betz = betx; } else { - betx = Q[QMAGX] / std::sqrt(Q[QMAGX]*Q[QMAGX] + Q[QMAGZ]*Q[QMAGZ]); - betz = Q[QMAGZ] / std::sqrt(Q[QMAGX]*Q[QMAGX] + Q[QMAGZ]*Q[QMAGZ]); + betx = Q(QMAGX) / std::sqrt(Q(QMAGX)*Q(QMAGX) + Q(QMAGZ)*Q(QMAGZ)); + betz = Q(QMAGZ) / std::sqrt(Q(QMAGX)*Q(QMAGX) + Q(QMAGZ)*Q(QMAGZ)); } Real cff = std::sqrt(cfy) * alf; Real css = std::sqrt(csy) * als; - Real S = std::copysign(1.0_rt, Q[QMAGY]); + Real S = std::copysign(1.0_rt, Q(QMAGY)); Real Qf = std::sqrt(cfy) * alf * S; Real Qs = std::sqrt(csy) * als * S; Real N = 0.5_rt / as; - Real AAf = std::sqrt(as) * alf * std::sqrt(Q[QRHO]); - Real AAs = std::sqrt(as) * als * std::sqrt(Q[QRHO]); + Real AAf = std::sqrt(as) * alf * std::sqrt(Q(QRHO)); + Real AAs = std::sqrt(as) * als * std::sqrt(Q(QRHO)); // v - cf @@ -312,9 +315,9 @@ Castro::evecy(Array2D& leig, leig(0, IEIGN_U) = N*Qs*betx; leig(0, IEIGN_V) = -N*cff; leig(0, IEIGN_W) = N*Qs*betz; - leig(0, IEIGN_P) = N*alf/Q[QRHO]; - leig(0, IEIGN_BT) = N*AAs*betx/Q[QRHO]; - leig(0, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; + leig(0, IEIGN_P) = N*alf/Q(QRHO); + leig(0, IEIGN_BT) = N*AAs*betx/Q(QRHO); + leig(0, IEIGN_BTT) = N*AAs*betz/Q(QRHO); // v - cay leig(1, IEIGN_RHO) = 0.0; @@ -322,17 +325,17 @@ Castro::evecy(Array2D& leig, leig(1, IEIGN_V) = 0.0; leig(1, IEIGN_W) = 0.5_rt*betx; leig(1, IEIGN_P) = 0.0; - leig(1, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q[QRHO]); - leig(1, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q[QRHO]); + leig(1, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q(QRHO)); + leig(1, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q(QRHO)); // v - cs leig(2, IEIGN_RHO) = 0.0; leig(2, IEIGN_U) = -N*Qf*betx; leig(2, IEIGN_V) = -N*css; leig(2, IEIGN_W) = -N*Qf*betz; - leig(2, IEIGN_P) = N*als/Q[QRHO]; - leig(2, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; - leig(2, IEIGN_BTT) = -N*AAf*betz/Q[QRHO]; + leig(2, IEIGN_P) = N*als/Q(QRHO); + leig(2, IEIGN_BT) = -N*AAf*betx/Q(QRHO); + leig(2, IEIGN_BTT) = -N*AAf*betz/Q(QRHO); // v leig(3, IEIGN_RHO) = 1.0_rt; @@ -348,9 +351,9 @@ Castro::evecy(Array2D& leig, leig(4, IEIGN_U) = N*Qf*betx; leig(4, IEIGN_V) = N*css; leig(4, IEIGN_W) = N*Qf*betz; - leig(4, IEIGN_P) = N*als/Q[QRHO]; - leig(4, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; - leig(4, IEIGN_BTT) = -N*AAf*betz/Q[QRHO]; + leig(4, IEIGN_P) = N*als/Q(QRHO); + leig(4, IEIGN_BT) = -N*AAf*betx/Q(QRHO); + leig(4, IEIGN_BTT) = -N*AAf*betz/Q(QRHO); // v + cay leig(5, IEIGN_RHO) = 0.0; @@ -358,27 +361,27 @@ Castro::evecy(Array2D& leig, leig(5, IEIGN_V) = 0.0; leig(5, IEIGN_W) = -0.5_rt*betx; leig(5, IEIGN_P) = 0.0; - leig(5, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q[QRHO]); - leig(5, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q[QRHO]); + leig(5, IEIGN_BT) = -0.5_rt*betz*S/std::sqrt(Q(QRHO)); + leig(5, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q(QRHO)); // v + cf leig(6, IEIGN_RHO) = 0.0; leig(6, IEIGN_U) = -N*Qs*betx; leig(6, IEIGN_V) = N*cff; leig(6, IEIGN_W) = -N*Qs*betz; - leig(6, IEIGN_P) = N*alf/Q[QRHO]; - leig(6, IEIGN_BT) = N*AAs*betx/Q[QRHO]; - leig(6, IEIGN_BTT) = N*AAs*betz/Q[QRHO]; + leig(6, IEIGN_P) = N*alf/Q(QRHO); + leig(6, IEIGN_BT) = N*AAs*betx/Q(QRHO); + leig(6, IEIGN_BTT) = N*AAs*betz/Q(QRHO); // v - cf ; v - Cay ; v - cs ; v ; v + cs ; v + Cay ; v + cf - reig(IEIGN_RHO, 0) = Q[QRHO]*alf; + reig(IEIGN_RHO, 0) = Q(QRHO)*alf; reig(IEIGN_RHO, 1) = 0.0; - reig(IEIGN_RHO, 2) = Q[QRHO]*als; + reig(IEIGN_RHO, 2) = Q(QRHO)*als; reig(IEIGN_RHO, 3) = 1.0_rt; - reig(IEIGN_RHO, 4) = Q[QRHO]*als; + reig(IEIGN_RHO, 4) = Q(QRHO)*als; reig(IEIGN_RHO, 5) = 0.0; - reig(IEIGN_RHO, 6) = Q[QRHO]*alf; + reig(IEIGN_RHO, 6) = Q(QRHO)*alf; reig(IEIGN_V, 0) = -cff; reig(IEIGN_V, 1) = 0.0; @@ -404,28 +407,28 @@ Castro::evecy(Array2D& leig, reig(IEIGN_W, 5) = -betx; reig(IEIGN_W, 6) = -Qs*betz; - reig(IEIGN_P, 0) = Q[QRHO]*as*alf; + reig(IEIGN_P, 0) = Q(QRHO)*as*alf; reig(IEIGN_P, 1) = 0.0; - reig(IEIGN_P, 2) = Q[QRHO]*as*als; + reig(IEIGN_P, 2) = Q(QRHO)*as*als; reig(IEIGN_P, 3) = 0.0; - reig(IEIGN_P, 4) = Q[QRHO]*as*als; + reig(IEIGN_P, 4) = Q(QRHO)*as*als; reig(IEIGN_P, 5) = 0.0; - reig(IEIGN_P, 6) = Q[QRHO]*as*alf; + reig(IEIGN_P, 6) = Q(QRHO)*as*alf; reig(IEIGN_BT, 0) = AAs*betx; - reig(IEIGN_BT, 1) = -betz*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 1) = -betz*S*std::sqrt(Q(QRHO)); reig(IEIGN_BT, 2) = -AAf*betx; reig(IEIGN_BT, 3) = 0.0; reig(IEIGN_BT, 4) = -AAf*betx; - reig(IEIGN_BT, 5) = -betz*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 5) = -betz*S*std::sqrt(Q(QRHO)); reig(IEIGN_BT, 6) = AAs*betx; reig(IEIGN_BTT, 0) = AAs*betz; - reig(IEIGN_BTT, 1) = betx*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 1) = betx*S*std::sqrt(Q(QRHO)); reig(IEIGN_BTT, 2) = -AAf*betz; reig(IEIGN_BTT, 3) = 0.0; reig(IEIGN_BTT, 4) = -AAf*betz; - reig(IEIGN_BTT, 5) = betx*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 5) = betx*S*std::sqrt(Q(QRHO)); reig(IEIGN_BTT, 6) = AAs*betz; } @@ -436,7 +439,7 @@ void Castro::evecz(Array2D& leig, Array2D& reig, const Real as_in, - Real* Q) { + Array1D& Q) { // returns Leig, where the rows are the left eigenvectors of the characteristic matrix Az @@ -446,8 +449,8 @@ Castro::evecz(Array2D& leig, // Alfven - Real ca = (Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY] + Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; - Real caz = (Q[QMAGZ]*Q[QMAGZ]) / Q[QRHO]; + Real ca = (Q(QMAGX)*Q(QMAGX) + Q(QMAGY)*Q(QMAGY) + Q(QMAGZ)*Q(QMAGZ)) / Q(QRHO); + Real caz = (Q(QMAGZ)*Q(QMAGZ)) / Q(QRHO); // Slow @@ -473,27 +476,27 @@ Castro::evecz(Array2D& leig, Real betx; Real bety; - if (std::abs(Q[QMAGX]) <= 1.e-14_rt && std::abs(Q[QMAGY]) <= 1.e-14_rt) { + if (std::abs(Q(QMAGX)) <= 1.e-14_rt && std::abs(Q(QMAGY)) <= 1.e-14_rt) { betx = 1.0_rt/std::sqrt(2.0_rt); bety = betx; } else { - betx = Q[QMAGX] / std::sqrt(Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY]); - bety = Q[QMAGY] / std::sqrt(Q[QMAGX]*Q[QMAGX] + Q[QMAGY]*Q[QMAGY]); + betx = Q(QMAGX) / std::sqrt(Q(QMAGX)*Q(QMAGX) + Q(QMAGY)*Q(QMAGY)); + bety = Q(QMAGY) / std::sqrt(Q(QMAGX)*Q(QMAGX) + Q(QMAGY)*Q(QMAGY)); } Real cff = std::sqrt(cfz) * alf; Real css = std::sqrt(csz) * als; - Real S = std::copysign(1.0_rt, Q[QMAGZ]); + Real S = std::copysign(1.0_rt, Q(QMAGZ)); Real Qf = std::sqrt(cfz) * alf * S; Real Qs = std::sqrt(csz) * als * S; Real N = 0.5_rt / as; - Real AAf = std::sqrt(as) * alf * std::sqrt(Q[QRHO]); - Real AAs = std::sqrt(as) * als * std::sqrt(Q[QRHO]); + Real AAf = std::sqrt(as) * alf * std::sqrt(Q(QRHO)); + Real AAs = std::sqrt(as) * als * std::sqrt(Q(QRHO)); // w - cf @@ -501,9 +504,9 @@ Castro::evecz(Array2D& leig, leig(0, IEIGN_U) = N*Qs*betx; leig(0, IEIGN_V) = N*Qs*bety; leig(0, IEIGN_W) = -N*cff; - leig(0, IEIGN_P) = N*alf/Q[QRHO]; - leig(0, IEIGN_BT) = N*AAs*betx/Q[QRHO]; - leig(0, IEIGN_BTT) = N*AAs*bety/Q[QRHO]; + leig(0, IEIGN_P) = N*alf/Q(QRHO); + leig(0, IEIGN_BT) = N*AAs*betx/Q(QRHO); + leig(0, IEIGN_BTT) = N*AAs*bety/Q(QRHO); // w - caz leig(1, IEIGN_RHO) = 0.0; @@ -511,17 +514,17 @@ Castro::evecz(Array2D& leig, leig(1, IEIGN_V) = 0.5_rt*betx; leig(1, IEIGN_W) = 0.0; leig(1, IEIGN_P) = 0.0; - leig(1, IEIGN_BT) = -0.5_rt*bety*S/std::sqrt(Q[QRHO]); - leig(1, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q[QRHO]); + leig(1, IEIGN_BT) = -0.5_rt*bety*S/std::sqrt(Q(QRHO)); + leig(1, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q(QRHO)); // w - cs leig(2, IEIGN_RHO) = 0.0; leig(2, IEIGN_U) = -N*Qf*betx; leig(2, IEIGN_V) = -N*Qf*bety; leig(2, IEIGN_W) = -N*css; - leig(2, IEIGN_P) = N*als/Q[QRHO]; - leig(2, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; - leig(2, IEIGN_BTT) = -N*AAf*bety/Q[QRHO]; + leig(2, IEIGN_P) = N*als/Q(QRHO); + leig(2, IEIGN_BT) = -N*AAf*betx/Q(QRHO); + leig(2, IEIGN_BTT) = -N*AAf*bety/Q(QRHO); // w leig(3, IEIGN_RHO) = 1.0_rt; @@ -537,9 +540,9 @@ Castro::evecz(Array2D& leig, leig(4, IEIGN_U) = N*Qf*betx; leig(4, IEIGN_V) = N*Qf*bety; leig(4, IEIGN_W) = N*css; - leig(4, IEIGN_P) = N*als/Q[QRHO]; - leig(4, IEIGN_BT) = -N*AAf*betx/Q[QRHO]; - leig(4, IEIGN_BTT) = -N*AAf*bety/Q[QRHO]; + leig(4, IEIGN_P) = N*als/Q(QRHO); + leig(4, IEIGN_BT) = -N*AAf*betx/Q(QRHO); + leig(4, IEIGN_BTT) = -N*AAf*bety/Q(QRHO); // w + caz leig(5, IEIGN_RHO) = 0.0; @@ -547,27 +550,27 @@ Castro::evecz(Array2D& leig, leig(5, IEIGN_V) = -0.5_rt*betx; leig(5, IEIGN_W) = 0.0; leig(5, IEIGN_P) = 0.0; - leig(5, IEIGN_BT) = -0.5_rt*bety*S/std::sqrt(Q[QRHO]); - leig(5, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q[QRHO]); + leig(5, IEIGN_BT) = -0.5_rt*bety*S/std::sqrt(Q(QRHO)); + leig(5, IEIGN_BTT) = 0.5_rt*betx*S/std::sqrt(Q(QRHO)); // w + cf leig(6, IEIGN_RHO) = 0.0; leig(6, IEIGN_U) = -N*Qs*betx; leig(6, IEIGN_V) = -N*Qs*bety; leig(6, IEIGN_W) = N*cff; - leig(6, IEIGN_P) = N*alf/Q[QRHO]; - leig(6, IEIGN_BT) = N*AAs*betx/Q[QRHO]; - leig(6, IEIGN_BTT) = N*AAs*bety/Q[QRHO]; + leig(6, IEIGN_P) = N*alf/Q(QRHO); + leig(6, IEIGN_BT) = N*AAs*betx/Q(QRHO); + leig(6, IEIGN_BTT) = N*AAs*bety/Q(QRHO); // w - cf ; w - Caz ; w - cs ; w ; w + cs ; w + Caz ; w + cf - reig(IEIGN_RHO, 0) = Q[QRHO]*alf; + reig(IEIGN_RHO, 0) = Q(QRHO)*alf; reig(IEIGN_RHO, 1) = 0.0; - reig(IEIGN_RHO, 2) = Q[QRHO]*als; + reig(IEIGN_RHO, 2) = Q(QRHO)*als; reig(IEIGN_RHO, 3) = 1.0_rt; - reig(IEIGN_RHO, 4) = Q[QRHO]*als; + reig(IEIGN_RHO, 4) = Q(QRHO)*als; reig(IEIGN_RHO, 5) = 0.0; - reig(IEIGN_RHO, 6) = Q[QRHO]*alf; + reig(IEIGN_RHO, 6) = Q(QRHO)*alf; reig(IEIGN_W, 0) = -cff; reig(IEIGN_W, 1) = 0.0; @@ -593,28 +596,28 @@ Castro::evecz(Array2D& leig, reig(IEIGN_V, 5) = -betx; reig(IEIGN_V, 6) = -Qs*bety; - reig(IEIGN_P, 0) = Q[QRHO]*as*alf; + reig(IEIGN_P, 0) = Q(QRHO)*as*alf; reig(IEIGN_P, 1) = 0.0; - reig(IEIGN_P, 2) = Q[QRHO]*as*als; + reig(IEIGN_P, 2) = Q(QRHO)*as*als; reig(IEIGN_P, 3) = 0.0; - reig(IEIGN_P, 4) = Q[QRHO]*as*als; + reig(IEIGN_P, 4) = Q(QRHO)*as*als; reig(IEIGN_P, 5) = 0.0; - reig(IEIGN_P, 6) = Q[QRHO]*as*alf; + reig(IEIGN_P, 6) = Q(QRHO)*as*alf; reig(IEIGN_BT, 0) = AAs*betx; - reig(IEIGN_BT, 1) = -bety*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 1) = -bety*S*std::sqrt(Q(QRHO)); reig(IEIGN_BT, 2) = -AAf*betx; reig(IEIGN_BT, 3) = 0.0; reig(IEIGN_BT, 4) = -AAf*betx; - reig(IEIGN_BT, 5) = -bety*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BT, 5) = -bety*S*std::sqrt(Q(QRHO)); reig(IEIGN_BT, 6) = AAs*betx; reig(IEIGN_BTT, 0) = AAs*bety; - reig(IEIGN_BTT, 1) = betx*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 1) = betx*S*std::sqrt(Q(QRHO)); reig(IEIGN_BTT, 2) = -AAf*bety; reig(IEIGN_BTT, 3) = 0.0; reig(IEIGN_BTT, 4) = -AAf*bety; - reig(IEIGN_BTT, 5) = betx*S*std::sqrt(Q[QRHO]); + reig(IEIGN_BTT, 5) = betx*S*std::sqrt(Q(QRHO)); reig(IEIGN_BTT, 6) = AAs*bety; } diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp index ed9f61a916..fd5e10e3c9 100644 --- a/Source/mhd/mhd_plm.cpp +++ b/Source/mhd/mhd_plm.cpp @@ -103,14 +103,14 @@ Castro::plm(const Box& bx, // compute the eigenvectors and eigenvalues for this coordinate direction - Real q_zone[NQ]; + Array1D q_zone; for (int n = 0; n < NQ; n++) { - q_zone[n] = s(i,j,k,n); + q_zone(n) = s(i,j,k,n); } Real as = qaux(i,j,k,QC); - Real lam[NEIGN]; + Array1D lam; evals(lam, as, q_zone, idir); @@ -131,16 +131,16 @@ Castro::plm(const Box& bx, Real smhd[NEIGN]; smhd[IEIGN_RHO] = 0.0_rt; - smhd[IEIGN_U] = q_zone[QMAGX] / q_zone[QRHO]; - smhd[IEIGN_V] = q_zone[QMAGY] / q_zone[QRHO]; - smhd[IEIGN_W] = q_zone[QMAGZ] / q_zone[QRHO]; - smhd[IEIGN_P] = q_zone[QMAGX] * q_zone[QU] + - q_zone[QMAGY] * q_zone[QV] + - q_zone[QMAGZ] * q_zone[QW]; + smhd[IEIGN_U] = q_zone(QMAGX) / q_zone(QRHO); + smhd[IEIGN_V] = q_zone(QMAGY) / q_zone(QRHO); + smhd[IEIGN_W] = q_zone(QMAGZ) / q_zone(QRHO); + smhd[IEIGN_P] = q_zone(QMAGX) * q_zone(QU) + + q_zone(QMAGY) * q_zone(QV) + + q_zone(QMAGZ) * q_zone(QW); if (idir == 0) { - smhd[IEIGN_BT] = q_zone[QV]; - smhd[IEIGN_BTT] = q_zone[QW]; + smhd[IEIGN_BT] = q_zone(QV); + smhd[IEIGN_BTT] = q_zone(QW); // cross-talk of normal magnetic field direction for (int n = 0; n < NEIGN; n++) { @@ -148,8 +148,8 @@ Castro::plm(const Box& bx, } } else if (idir == 1) { - smhd[IEIGN_BT] = q_zone[QU]; - smhd[IEIGN_BTT] = q_zone[QW]; + smhd[IEIGN_BT] = q_zone(QU); + smhd[IEIGN_BTT] = q_zone(QW); // cross-talk of normal magnetic field direction for (int n = 0; n < NEIGN; n++) { @@ -157,8 +157,8 @@ Castro::plm(const Box& bx, } } else { - smhd[IEIGN_BT] = q_zone[QU]; - smhd[IEIGN_BTT] = q_zone[QV]; + smhd[IEIGN_BT] = q_zone(QU); + smhd[IEIGN_BTT] = q_zone(QV); // cross-talk of normal magnetic field direction for (int n = 0; n < NEIGN; n++) { @@ -184,8 +184,8 @@ Castro::plm(const Box& bx, slope(dW, dL, dR, flatn(i,j,k)); for (int n = 0; n < NEIGN; n++) { - summ_p[n] += (1.0_rt - dtdx * lam[ii]) * dW * reig(n,ii); - summ_m[n] -= (1.0_rt + dtdx * lam[ii]) * dW * reig(n,ii); + summ_p[n] += (1.0_rt - dtdx * lam(ii)) * dW * reig(n,ii); + summ_m[n] -= (1.0_rt + dtdx * lam(ii)) * dW * reig(n,ii); } } @@ -193,66 +193,66 @@ Castro::plm(const Box& bx, if (idir == 0) { qleft(i+1,j,k,QRHO) = amrex::max(small_dens, - q_zone[QRHO] + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); - qleft(i+1,j,k,QU) = q_zone[QU] + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; - qleft(i+1,j,k,QV) = q_zone[QV] + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; - qleft(i+1,j,k,QW) = q_zone[QW] + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + q_zone(QRHO) + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qleft(i+1,j,k,QU) = q_zone(QU) + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qleft(i+1,j,k,QV) = q_zone(QV) + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qleft(i+1,j,k,QW) = q_zone(QW) + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; qleft(i+1,j,k,QPRES) = amrex::max(small_pres, - q_zone[QPRES] + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + q_zone(QPRES) + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); qleft(i+1,j,k,QMAGX) = Bx(i+1,j,k); // Bx stuff - qleft(i+1,j,k,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qleft(i+1,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qleft(i+1,j,k,QMAGY) = q_zone(QMAGY) + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qleft(i+1,j,k,QMAGZ) = q_zone(QMAGZ) + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else if (idir == 1) { qleft(i,j+1,k,QRHO) = amrex::max(small_dens, - q_zone[QRHO] + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); - qleft(i,j+1,k,QU) = q_zone[QU] + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; - qleft(i,j+1,k,QV) = q_zone[QV] + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; - qleft(i,j+1,k,QW) = q_zone[QW] + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + q_zone(QRHO) + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qleft(i,j+1,k,QU) = q_zone(QU) + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qleft(i,j+1,k,QV) = q_zone(QV) + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qleft(i,j+1,k,QW) = q_zone(QW) + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; qleft(i,j+1,k,QPRES) = amrex::max(small_pres, - q_zone[QPRES] + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + q_zone(QPRES) + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); - qleft(i,j+1,k,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qleft(i,j+1,k,QMAGX) = q_zone(QMAGX) + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; qleft(i,j+1,k,QMAGY) = By(i,j+1,k); // By stuff - qleft(i,j+1,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qleft(i,j+1,k,QMAGZ) = q_zone(QMAGZ) + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else { qleft(i,j,k+1,QRHO) = amrex::max(small_dens, - q_zone[QRHO] + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); - qleft(i,j,k+1,QU) = q_zone[QU] + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; - qleft(i,j,k+1,QV) = q_zone[QV] + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; - qleft(i,j,k+1,QW) = q_zone[QW] + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + q_zone(QRHO) + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qleft(i,j,k+1,QU) = q_zone(QU) + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qleft(i,j,k+1,QV) = q_zone(QV) + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qleft(i,j,k+1,QW) = q_zone(QW) + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; qleft(i,j,k+1,QPRES) = amrex::max(small_pres, - q_zone[QPRES] + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + q_zone(QPRES) + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); - qleft(i,j,k+1,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qleft(i,j,k+1,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qleft(i,j,k+1,QMAGX) = q_zone(QMAGX) + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qleft(i,j,k+1,QMAGY) = q_zone(QMAGY) + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; qleft(i,j,k+1,QMAGZ) = Bz(i,j,k+1); // Bz stuff } // right state at i-1/2 qright(i,j,k,QRHO) = amrex::max(small_dens, - q_zone[QRHO] + 0.5_rt*summ_m[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); - qright(i,j,k,QU) = q_zone[QU] + 0.5_rt*summ_m[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; - qright(i,j,k,QV) = q_zone[QV] + 0.5_rt*summ_m[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; - qright(i,j,k,QW) = q_zone[QW] + 0.5_rt*summ_m[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + q_zone(QRHO) + 0.5_rt*summ_m[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qright(i,j,k,QU) = q_zone(QU) + 0.5_rt*summ_m[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qright(i,j,k,QV) = q_zone(QV) + 0.5_rt*summ_m[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qright(i,j,k,QW) = q_zone(QW) + 0.5_rt*summ_m[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; qright(i,j,k,QPRES) = amrex::max(small_pres, - q_zone[QPRES] + 0.5_rt*summ_m[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + q_zone(QPRES) + 0.5_rt*summ_m[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); if (idir == 0) { qright(i,j,k,QMAGX) = Bx(i,j,k); // Bx stuff - qright(i,j,k,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qright(i,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qright(i,j,k,QMAGY) = q_zone(QMAGY) + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qright(i,j,k,QMAGZ) = q_zone(QMAGZ) + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else if (idir == 1) { - qright(i,j,k,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qright(i,j,k,QMAGX) = q_zone(QMAGX) + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; qright(i,j,k,QMAGY) = By(i,j,k); // By stuff - qright(i,j,k,QMAGZ) = q_zone[QMAGZ] + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qright(i,j,k,QMAGZ) = q_zone(QMAGZ) + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else { - qright(i,j,k,QMAGX) = q_zone[QMAGX] + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qright(i,j,k,QMAGY) = q_zone[QMAGY] + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qright(i,j,k,QMAGX) = q_zone(QMAGX) + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qright(i,j,k,QMAGY) = q_zone(QMAGY) + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; qright(i,j,k,QMAGZ) = Bz(i,j,k); // Bz stuff } @@ -282,13 +282,13 @@ Castro::plm(const Box& bx, slope(dW, dL, dR, flatn(i,j,k)); if (idir == 0) { - qleft(i+1,j,k,QFS+n) = q_zone[QFS+n] + 0.5_rt*(1.0_rt - dtdx*un) * dW; + qleft(i+1,j,k,QFS+n) = q_zone(QFS+n) + 0.5_rt*(1.0_rt - dtdx*un) * dW; } else if (idir == 1) { - qleft(i,j+1,k,QFS+n) = q_zone[QFS+n] + 0.5_rt*(1.0_rt - dtdx*un) * dW; + qleft(i,j+1,k,QFS+n) = q_zone(QFS+n) + 0.5_rt*(1.0_rt - dtdx*un) * dW; } else { - qleft(i,j,k+1,QFS+n) = q_zone[QFS+n] + 0.5_rt*(1.0_rt - dtdx*un) * dW; + qleft(i,j,k+1,QFS+n) = q_zone(QFS+n) + 0.5_rt*(1.0_rt - dtdx*un) * dW; } - qright(i,j,k,QFS+n) = q_zone[QFS+n] - 0.5_rt*(1.0_rt + dtdx*un) * dW; + qright(i,j,k,QFS+n) = q_zone(QFS+n) - 0.5_rt*(1.0_rt + dtdx*un) * dW; } // rho e From d8a3301c714c96a198540c1ec5c34fd791a68d67 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sat, 6 Jun 2020 20:29:46 -0400 Subject: [PATCH 22/23] this implements a reference state in MHD PLM basically does what is in Colella 1990 / Stone et al. 2008 --- Source/mhd/mhd_plm.cpp | 141 ++++++++++++++++++++++++++++++----------- 1 file changed, 105 insertions(+), 36 deletions(-) diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp index 145b600b06..58cd1206cc 100644 --- a/Source/mhd/mhd_plm.cpp +++ b/Source/mhd/mhd_plm.cpp @@ -168,9 +168,16 @@ Castro::plm(const Box& bx, // Perform the characteristic projection. Since we are using // Using HLLD, we sum over all eigenvalues -- see the discussion after Eq. 31 - Real summ_p[NEIGN] = {0.0_rt}; - Real summ_m[NEIGN] = {0.0_rt}; + // We'll follow the method from Colella 1990 (as also written in Stone 2008) + // where we first compute a reference state using the fastest moving eigenvalue + // toward the interface and the project the difference of the waves from that + + // compute the limited primitive variable slopes where we limit on + // the characteristic variables. Note, we need this final result + // ahead of time to compute the reference states + + Real dq_lim[NEIGN] = {}; for (int ii = 0; ii < NEIGN; ii++) { Real dL = 0.0; Real dR = 0.0; @@ -184,8 +191,70 @@ Castro::plm(const Box& bx, slope(dW, dL, dR, flatn(i,j,k)); for (int n = 0; n < NEIGN; n++) { - summ_p[n] += (1.0_rt - dtdx * lam(ii)) * dW * reig(n,ii); - summ_m[n] -= (1.0_rt + dtdx * lam(ii)) * dW * reig(n,ii); + dq_lim[n] += dW * reig(n,ii); + } + } + + + Real q_ref_left[NEIGN]; + Real ref_term = 0.5_rt * (1.0_rt - amrex::max(lam(NEIGN-1), 0.0_rt) * dtdx); + + q_ref_left[IEIGN_RHO] = q_zone(QRHO) + ref_term * dq_lim[QRHO]; + q_ref_left[IEIGN_U] = q_zone(QU) + ref_term * dq_lim[QRHO]; + q_ref_left[IEIGN_V] = q_zone(QV) + ref_term * dq_lim[QRHO]; + q_ref_left[IEIGN_W] = q_zone(QW) + ref_term * dq_lim[QRHO]; + q_ref_left[IEIGN_P] = q_zone(QPRES) + ref_term * dq_lim[QRHO]; + if (idir == 0) { + q_ref_left[IEIGN_BT] = q_zone(QMAGY) + ref_term * dq_lim[IEIGN_BT]; + q_ref_left[IEIGN_BTT] = q_zone(QMAGZ) + ref_term * dq_lim[IEIGN_BTT]; + + } else if (idir == 1) { + q_ref_left[IEIGN_BT] = q_zone(QMAGX) + ref_term * dq_lim[IEIGN_BT]; + q_ref_left[IEIGN_BTT] = q_zone(QMAGZ) + ref_term * dq_lim[IEIGN_BTT]; + + } else if (idir == 2) { + q_ref_left[IEIGN_BT] = q_zone(QMAGX) + ref_term * dq_lim[IEIGN_BT]; + q_ref_left[IEIGN_BTT] = q_zone(QMAGY) + ref_term * dq_lim[IEIGN_BTT]; + + } + + Real q_ref_right[NEIGN]; + // note: Stone et al. 2008 Eq. 41 has a sign error, compare to + // Colella 1990 Eq. 2.11 + ref_term = 0.5_rt * (1.0_rt + amrex::min(lam(0), 0.0_rt) * dtdx); + + q_ref_right[IEIGN_RHO] = q_zone(QRHO) - ref_term * dq_lim[QRHO]; + q_ref_right[IEIGN_U] = q_zone(QU) - ref_term * dq_lim[QRHO]; + q_ref_right[IEIGN_V] = q_zone(QV) - ref_term * dq_lim[QRHO]; + q_ref_right[IEIGN_W] = q_zone(QW) - ref_term * dq_lim[QRHO]; + q_ref_right[IEIGN_P] = q_zone(QPRES) - ref_term * dq_lim[QRHO]; + if (idir == 0) { + q_ref_right[IEIGN_BT] = q_zone(QMAGY) - ref_term * dq_lim[IEIGN_BT]; + q_ref_right[IEIGN_BTT] = q_zone(QMAGZ) - ref_term * dq_lim[IEIGN_BTT]; + + } else if (idir == 1) { + q_ref_right[IEIGN_BT] = q_zone(QMAGX) - ref_term * dq_lim[IEIGN_BT]; + q_ref_right[IEIGN_BTT] = q_zone(QMAGZ) - ref_term * dq_lim[IEIGN_BTT]; + + } else if (idir == 2) { + q_ref_right[IEIGN_BT] = q_zone(QMAGX) - ref_term * dq_lim[IEIGN_BT]; + q_ref_right[IEIGN_BTT] = q_zone(QMAGY) - ref_term * dq_lim[IEIGN_BTT]; + + } + + Real summ_p[NEIGN] = {0.0_rt}; + Real summ_m[NEIGN] = {0.0_rt}; + + for (int ii = 0; ii < NEIGN; ii++) { + Real Ldq = 0.0; + + for (int n = 0; n < NEIGN; n++) { + Ldq += leig(ii,n) * dq_lim[n]; + } + + for (int n = 0; n < NEIGN; n++) { + summ_p[n] += 0.5_rt * dtdx * (lam(NEIGN-1) - lam(ii)) * Ldq * reig(n,ii); + summ_m[n] += 0.5_rt * dtdx * (lam(0) - lam(ii)) * Ldq * reig(n,ii); } } @@ -193,66 +262,66 @@ Castro::plm(const Box& bx, if (idir == 0) { qleft(i+1,j,k,QRHO) = amrex::max(small_dens, - q_zone(QRHO) + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); - qleft(i+1,j,k,QU) = q_zone(QU) + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; - qleft(i+1,j,k,QV) = q_zone(QV) + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; - qleft(i+1,j,k,QW) = q_zone(QW) + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + q_ref_left[IEIGN_RHO] + summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qleft(i+1,j,k,QU) = q_ref_left[IEIGN_U] + summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qleft(i+1,j,k,QV) = q_ref_left[IEIGN_V] + summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qleft(i+1,j,k,QW) = q_ref_left[IEIGN_W] + summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; qleft(i+1,j,k,QPRES) = amrex::max(small_pres, - q_zone(QPRES) + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + q_ref_left[IEIGN_P] + summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); qleft(i+1,j,k,QMAGX) = Bx(i+1,j,k); // Bx stuff - qleft(i+1,j,k,QMAGY) = q_zone(QMAGY) + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qleft(i+1,j,k,QMAGZ) = q_zone(QMAGZ) + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qleft(i+1,j,k,QMAGY) = q_ref_left[IEIGN_BT] + summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qleft(i+1,j,k,QMAGZ) = q_ref_left[IEIGN_BTT] + summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else if (idir == 1) { qleft(i,j+1,k,QRHO) = amrex::max(small_dens, - q_zone(QRHO) + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); - qleft(i,j+1,k,QU) = q_zone(QU) + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; - qleft(i,j+1,k,QV) = q_zone(QV) + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; - qleft(i,j+1,k,QW) = q_zone(QW) + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + q_ref_left[IEIGN_RHO] + summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qleft(i,j+1,k,QU) = q_ref_left[IEIGN_U] + summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qleft(i,j+1,k,QV) = q_ref_left[IEIGN_V] + summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qleft(i,j+1,k,QW) = q_ref_left[IEIGN_W] + summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; qleft(i,j+1,k,QPRES) = amrex::max(small_pres, - q_zone(QPRES) + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + q_ref_left[IEIGN_P] + summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); - qleft(i,j+1,k,QMAGX) = q_zone(QMAGX) + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qleft(i,j+1,k,QMAGX) = q_ref_left[IEIGN_BT] + summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; qleft(i,j+1,k,QMAGY) = By(i,j+1,k); // By stuff - qleft(i,j+1,k,QMAGZ) = q_zone(QMAGZ) + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qleft(i,j+1,k,QMAGZ) = q_ref_left[IEIGN_BTT] + summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else { qleft(i,j,k+1,QRHO) = amrex::max(small_dens, - q_zone(QRHO) + 0.5_rt*summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); - qleft(i,j,k+1,QU) = q_zone(QU) + 0.5_rt*summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; - qleft(i,j,k+1,QV) = q_zone(QV) + 0.5_rt*summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; - qleft(i,j,k+1,QW) = q_zone(QW) + 0.5_rt*summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + q_ref_left[IEIGN_RHO] + summ_p[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qleft(i,j,k+1,QU) = q_ref_left[IEIGN_U] + summ_p[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qleft(i,j,k+1,QV) = q_ref_left[IEIGN_V] + summ_p[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qleft(i,j,k+1,QW) = q_ref_left[IEIGN_W] + summ_p[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; qleft(i,j,k+1,QPRES) = amrex::max(small_pres, - q_zone(QPRES) + 0.5_rt*summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + q_ref_left[IEIGN_P] + summ_p[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); - qleft(i,j,k+1,QMAGX) = q_zone(QMAGX) + 0.5_rt*summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qleft(i,j,k+1,QMAGY) = q_zone(QMAGY) + 0.5_rt*summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qleft(i,j,k+1,QMAGX) = q_ref_left[IEIGN_BT] + summ_p[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qleft(i,j,k+1,QMAGY) = q_ref_left[IEIGN_BTT] + summ_p[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; qleft(i,j,k+1,QMAGZ) = Bz(i,j,k+1); // Bz stuff } // right state at i-1/2 qright(i,j,k,QRHO) = amrex::max(small_dens, - q_zone(QRHO) + 0.5_rt*summ_m[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); - qright(i,j,k,QU) = q_zone(QU) + 0.5_rt*summ_m[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; - qright(i,j,k,QV) = q_zone(QV) + 0.5_rt*summ_m[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; - qright(i,j,k,QW) = q_zone(QW) + 0.5_rt*summ_m[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; + q_ref_right[IEIGN_RHO] + summ_m[IEIGN_RHO] + 0.5_rt*dt*smhd[IEIGN_RHO]); + qright(i,j,k,QU) = q_ref_right[IEIGN_U] + summ_m[IEIGN_U] + 0.5_rt*dt*smhd[IEIGN_U]; + qright(i,j,k,QV) = q_ref_right[IEIGN_V] + summ_m[IEIGN_V] + 0.5_rt*dt*smhd[IEIGN_V]; + qright(i,j,k,QW) = q_ref_right[IEIGN_W] + summ_m[IEIGN_W] + 0.5_rt*dt*smhd[IEIGN_W]; qright(i,j,k,QPRES) = amrex::max(small_pres, - q_zone(QPRES) + 0.5_rt*summ_m[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); + q_ref_right[IEIGN_P] + summ_m[IEIGN_P] + 0.5_rt*dt*smhd[IEIGN_P]); if (idir == 0) { qright(i,j,k,QMAGX) = Bx(i,j,k); // Bx stuff - qright(i,j,k,QMAGY) = q_zone(QMAGY) + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qright(i,j,k,QMAGZ) = q_zone(QMAGZ) + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qright(i,j,k,QMAGY) = q_ref_right[IEIGN_BT] + summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qright(i,j,k,QMAGZ) = q_ref_right[IEIGN_BTT] + summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else if (idir == 1) { - qright(i,j,k,QMAGX) = q_zone(QMAGX) + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qright(i,j,k,QMAGX) = q_ref_right[IEIGN_BT] + summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; qright(i,j,k,QMAGY) = By(i,j,k); // By stuff - qright(i,j,k,QMAGZ) = q_zone(QMAGZ) + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qright(i,j,k,QMAGZ) = q_ref_right[IEIGN_BTT] + summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; } else { - qright(i,j,k,QMAGX) = q_zone(QMAGX) + 0.5_rt*summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; - qright(i,j,k,QMAGY) = q_zone(QMAGY) + 0.5_rt*summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; + qright(i,j,k,QMAGX) = q_ref_right[IEIGN_BT] + summ_m[IEIGN_BT] + 0.5_rt*dt*smhd[IEIGN_BT]; + qright(i,j,k,QMAGY) = q_ref_right[IEIGN_BTT] + summ_m[IEIGN_BTT] + 0.5_rt*dt*smhd[IEIGN_BTT]; qright(i,j,k,QMAGZ) = Bz(i,j,k); // Bz stuff } From 0ed284309fcd02b3a9bc64f8b53b830b9878da4c Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sat, 6 Jun 2020 20:36:39 -0400 Subject: [PATCH 23/23] fix indexing --- Source/mhd/mhd_plm.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp index 58cd1206cc..3aea8967ca 100644 --- a/Source/mhd/mhd_plm.cpp +++ b/Source/mhd/mhd_plm.cpp @@ -200,10 +200,10 @@ Castro::plm(const Box& bx, Real ref_term = 0.5_rt * (1.0_rt - amrex::max(lam(NEIGN-1), 0.0_rt) * dtdx); q_ref_left[IEIGN_RHO] = q_zone(QRHO) + ref_term * dq_lim[QRHO]; - q_ref_left[IEIGN_U] = q_zone(QU) + ref_term * dq_lim[QRHO]; - q_ref_left[IEIGN_V] = q_zone(QV) + ref_term * dq_lim[QRHO]; - q_ref_left[IEIGN_W] = q_zone(QW) + ref_term * dq_lim[QRHO]; - q_ref_left[IEIGN_P] = q_zone(QPRES) + ref_term * dq_lim[QRHO]; + q_ref_left[IEIGN_U] = q_zone(QU) + ref_term * dq_lim[QU]; + q_ref_left[IEIGN_V] = q_zone(QV) + ref_term * dq_lim[QV]; + q_ref_left[IEIGN_W] = q_zone(QW) + ref_term * dq_lim[QW]; + q_ref_left[IEIGN_P] = q_zone(QPRES) + ref_term * dq_lim[QPRES]; if (idir == 0) { q_ref_left[IEIGN_BT] = q_zone(QMAGY) + ref_term * dq_lim[IEIGN_BT]; q_ref_left[IEIGN_BTT] = q_zone(QMAGZ) + ref_term * dq_lim[IEIGN_BTT]; @@ -224,10 +224,10 @@ Castro::plm(const Box& bx, ref_term = 0.5_rt * (1.0_rt + amrex::min(lam(0), 0.0_rt) * dtdx); q_ref_right[IEIGN_RHO] = q_zone(QRHO) - ref_term * dq_lim[QRHO]; - q_ref_right[IEIGN_U] = q_zone(QU) - ref_term * dq_lim[QRHO]; - q_ref_right[IEIGN_V] = q_zone(QV) - ref_term * dq_lim[QRHO]; - q_ref_right[IEIGN_W] = q_zone(QW) - ref_term * dq_lim[QRHO]; - q_ref_right[IEIGN_P] = q_zone(QPRES) - ref_term * dq_lim[QRHO]; + q_ref_right[IEIGN_U] = q_zone(QU) - ref_term * dq_lim[QU]; + q_ref_right[IEIGN_V] = q_zone(QV) - ref_term * dq_lim[QV]; + q_ref_right[IEIGN_W] = q_zone(QW) - ref_term * dq_lim[QW]; + q_ref_right[IEIGN_P] = q_zone(QPRES) - ref_term * dq_lim[QPRES]; if (idir == 0) { q_ref_right[IEIGN_BT] = q_zone(QMAGY) - ref_term * dq_lim[IEIGN_BT]; q_ref_right[IEIGN_BTT] = q_zone(QMAGZ) - ref_term * dq_lim[IEIGN_BTT];