From 6828f2ecc645e5560cf39f4a53d5014386241380 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sun, 15 Oct 2023 15:03:19 -0400 Subject: [PATCH] Move dlognugroup to C++ --- Source/hydro/Castro_ctu_rad.cpp | 15 +-- Source/radiation/RadMultiGroup.cpp | 21 +--- Source/radiation/Rad_nd.F90 | 190 ----------------------------- Source/radiation/Radiation.H | 2 +- Source/radiation/rad_params.F90 | 23 ---- 5 files changed, 8 insertions(+), 243 deletions(-) delete mode 100644 Source/radiation/Rad_nd.F90 delete mode 100644 Source/radiation/rad_params.F90 diff --git a/Source/hydro/Castro_ctu_rad.cpp b/Source/hydro/Castro_ctu_rad.cpp index 0c22df74b8..53273c0e65 100644 --- a/Source/hydro/Castro_ctu_rad.cpp +++ b/Source/hydro/Castro_ctu_rad.cpp @@ -37,23 +37,14 @@ Castro::ctu_rad_consup(const Box& bx, GpuArray Erscale = {0.0}; - GpuArray dlognu = {0.0}; - - GpuArray nugroup = {0.0}; - - - if (NGROUPS > 1) { - ca_get_nugroup(nugroup.begin()); - ca_get_dlognu(dlognu.begin()); - if (radiation::fspace_advection_type == 1) { for (int g = 0; g < NGROUPS; g++) { - Erscale[g] = dlognu[g]; + Erscale[g] = radiation->dlognugroup[g]; } } else { for (int g = 0; g < NGROUPS; g++) { - Erscale[g] = nugroup[g] * dlognu[g]; + Erscale[g] = radiation->nugroup[g] * radiation->dlognugroup[g]; } } } @@ -308,7 +299,7 @@ Castro::ctu_rad_consup(const Box& bx, ustar[g] = Erout(i,j,k,g) / Erscale[g]; } - update_one_species(NGROUPS, ustar, af, dlognu.begin(), dt, nstep_fsp_tmp); + update_one_species(NGROUPS, ustar, af, radiation->dlognugroup.dataPtr(), dt, nstep_fsp_tmp); for (int g = 0; g < NGROUPS; g++) { Erout(i,j,k,g) = ustar[g] * Erscale[g]; diff --git a/Source/radiation/RadMultiGroup.cpp b/Source/radiation/RadMultiGroup.cpp index fd2a1342ea..6d10bced88 100644 --- a/Source/radiation/RadMultiGroup.cpp +++ b/Source/radiation/RadMultiGroup.cpp @@ -21,11 +21,10 @@ void Radiation::get_groups(int verbose) group_print_factor = 1.0; group_units = " (units are Hz)"; - Vector dlognugroup; - xnu.resize(nGroups+1, 0.0); // Bounds of the frequency group nugroup.resize(nGroups, 1.0); // Geometric center of the frequency group dnugroup.resize(nGroups, 0.0); // Width of the frequency group + lognugroup.resize(nGroups, 0.0); // Log of the center of the frequency group dlognugroup.resize(nGroups, 0.0); // Log of the width of the frequency group ParmParse pp("radiation"); @@ -79,22 +78,10 @@ void Radiation::get_groups(int verbose) dlognugroup[i] = log(xnu[i+1]) - log(xnu[i]); } } - } - - int nG0 = 0, nG1 = 0; - if (SolverType == MGFLDSolver) { - BL_FORT_PROC_CALL(CA_INITGROUPS3,ca_initgroups3) - (nugroup.dataPtr(), dnugroup.dataPtr(), dlognugroup.dataPtr(), xnu.dataPtr(), - nGroups, nG0, nG1); - } - else if (xnu.size() > 0) { - BL_FORT_PROC_CALL(CA_INITGROUPS2,ca_initgroups2) - (nugroup.dataPtr(), dnugroup.dataPtr(), xnu.dataPtr(), nGroups); - } - else { - BL_FORT_PROC_CALL(CA_INITGROUPS,ca_initgroups) - (nugroup.dataPtr(), dnugroup.dataPtr(), nGroups, nG0, nG1); + for (int i = 0; i < nGroups; ++i) { + lognugroup[i] = std::log(nugroup[i]); + } } if (ParallelDescriptor::IOProcessor()) { diff --git a/Source/radiation/Rad_nd.F90 b/Source/radiation/Rad_nd.F90 deleted file mode 100644 index 2583066a99..0000000000 --- a/Source/radiation/Rad_nd.F90 +++ /dev/null @@ -1,190 +0,0 @@ -subroutine ca_init_fort_constants(hplanck_in, avogadro_in) bind(C, name="ca_init_fort_constants") - - use rad_params_module, only: hplanck, avogadro - use amrex_fort_module, only: rt => amrex_real - - implicit none - - real(rt), intent(in), value :: hplanck_in, avogadro_in - - hplanck = hplanck_in - avogadro = avogadro_in - -end subroutine ca_init_fort_constants - - - -! For single group, let set ngroups to 1. -subroutine ca_initsinglegroup(ngr) bind(C, name="ca_initsinglegroup") - - use rad_params_module, only: ngroups, nugroup, dnugroup, ng0, ng1 - use amrex_fort_module, only: rt => amrex_real - - implicit none - - integer :: ngr - - ! Local variables - integer :: i - - ng0 = 0 - ng1 = 0 - - allocate(nugroup( 0:ngroups-1)) - allocate(dnugroup(0:ngroups-1)) - - do i = 0, ngroups-1 - nugroup(i) = 1.e0_rt ! dummy - dnugroup(i) = 1.e0_rt - enddo - -end subroutine ca_initsinglegroup - -!! ----------------------------------------------------------- -!> @brief This routine is called at problem setup time and is used -!! to initialize the arrays nugroup and dnugroup in -!! probdata with the neutrino group energies and widths. -!! -!! The widths are used to derive neutrino spectrum for plot files -!! ----------------------------------------------------------- -subroutine ca_initgroups(nugr, dnugr, ngr, ngr0, ngr1) - - use rad_params_module, only: ngroups, ng0, ng1, nugroup, dnugroup, & - current_group - use amrex_fort_module, only: rt => amrex_real - - implicit none - - real(rt) :: nugr(0:ngr-1), dnugr(0:ngr-1) - integer :: ngr, ngr0, ngr1 - - ! Local variables - integer :: i - - allocate(current_group, ng0, ng1) - - ng0 = ngr0 - ng1 = ngr1 - - allocate(nugroup( 0:ngroups-1)) - allocate(dnugroup(0:ngroups-1)) - - do i = 0, ngroups-1 - nugroup(i) = nugr(i) - dnugroup(i) = dnugr(i) - enddo - -end subroutine ca_initgroups - -subroutine ca_initgroups2(nugr, dnugr, xnugr, ngr) - - use rad_params_module, only: ngroups, nugroup, dnugroup, xnu, dlognu, lognugroup, & - current_group, ng0, ng1 - use amrex_fort_module, only: rt => amrex_real - - implicit none - - real(rt), intent(in) :: nugr(0:ngr-1), dnugr(0:ngr-1), xnugr(0:ngr) - integer :: ngr - - ! Local variables - integer :: i - - allocate(current_group, ng0, ng1) - - allocate(nugroup( 0:ngroups-1)) - allocate(dnugroup(0:ngroups-1)) - allocate(xnu(0:ngroups)) - allocate(dlognu(0:ngroups-1)) - allocate(lognugroup(0:ngroups-1)) - - nugroup(:) = nugr(:) - dnugroup(:) = dnugr(:) - xnu(:) = xnugr(:) - lognugroup(:) = log(nugroup) - - dlognu(0:ngroups-1) = log(xnu(1:ngroups)) - log(xnu(0:ngroups-1)) - -end subroutine ca_initgroups2 - -subroutine ca_initgroups3(nugr, dnugr, dlognugr, xnugr, ngr, ngr0, ngr1) - ! used by MGFLDSolver - - use rad_params_module, only: ngroups, ng0, ng1, nugroup, dnugroup, & - xnu, dlognu, lognugroup, erg2rhoYe, avogadro, hplanck, & - current_group - use amrex_fort_module, only: rt => amrex_real - - implicit none - - real(rt), intent(in) :: nugr(0:ngr-1), dnugr(0:ngr-1), dlognugr(0:ngr-1), xnugr(0:ngr) - integer :: ngr, ngr0, ngr1 - - ! Local variables - integer :: i - - allocate(current_group, ng0, ng1) - - ng0 = ngr0 - ng1 = ngr1 - - allocate(nugroup( 0:ngroups-1)) - allocate(dnugroup(0:ngroups-1)) - allocate(xnu(0:ngroups)) - allocate(dlognu(0:ngroups-1)) - allocate(erg2rhoYe(0:ngroups-1)) - allocate(lognugroup( 0:ngroups-1)) - - nugroup(:) = nugr(:) - dnugroup(:) = dnugr(:) - xnu(:) = xnugr(:) - dlognu(:) = dlognugr(:) - lognugroup(:) = log(nugroup) - - erg2rhoYe = 0.e0_rt - if (ng0 > 0) then - erg2rhoYe(0:ng0-1) = 1.e0_rt / (avogadro*hplanck*nugroup(0:ng0-1)) - if (ng1 > 0) then - erg2rhoYe(ng0:ng0+ng1-1) = -1.e0_rt / (avogadro*hplanck*nugroup(ng0:ng0+ng1-1)) - end if - end if - -end subroutine ca_initgroups3 - -subroutine ca_get_dlognu(dlognu_out) bind(C, name="ca_get_dlognu") - - use amrex_fort_module, only: rt => amrex_real - use rad_params_module, only: ngroups, dlognu - implicit none - - real(rt), intent(out) :: dlognu_out(0:ngroups-1) - - dlognu_out(:) = dlognu(:) - -end subroutine ca_get_dlognu - -subroutine ca_get_nugroup(nugroup_out) bind(C, name="ca_get_nugroup") - - use amrex_fort_module, only: rt => amrex_real - use rad_params_module, only: ngroups, nugroup - implicit none - - real(rt), intent(out) :: nugroup_out(0:ngroups-1) - - nugroup_out(:) = nugroup(:) - -end subroutine ca_get_nugroup - -subroutine ca_get_dnugroup(dnugroup_out) bind(C, name="ca_get_dnugroup") - - use amrex_fort_module, only: rt => amrex_real - use rad_params_module, only: ngroups, dnugroup - implicit none - - real(rt), intent(out) :: dnugroup_out(0:ngroups-1) - - dnugroup_out(:) = dnugroup(:) - -end subroutine ca_get_dnugroup - - diff --git a/Source/radiation/Radiation.H b/Source/radiation/Radiation.H index 35b4f58f69..58be11061a 100644 --- a/Source/radiation/Radiation.H +++ b/Source/radiation/Radiation.H @@ -885,7 +885,7 @@ public: const amrex::Array& lambda, const amrex::MultiFab& Er, const amrex::MultiFab& F, int iflx); - amrex::Vector xnu, nugroup, dnugroup; + amrex::Vector xnu, nugroup, dnugroup, lognugroup, dlognugroup; protected: diff --git a/Source/radiation/rad_params.F90 b/Source/radiation/rad_params.F90 deleted file mode 100644 index 53fd9cca2b..0000000000 --- a/Source/radiation/rad_params.F90 +++ /dev/null @@ -1,23 +0,0 @@ - -! This module stores physical constants and radiation group information -! used for multigroup photon and neutrino radiation diffusion. -! These parameters are initialized in ca_initgroups? to match the -! values used in the C++ radiation code. - -module rad_params_module - - ! radiation energy group information - - use amrex_fort_module, only: rt => amrex_real - - implicit none - - integer, parameter :: ngroups = NGROUPS - - real :: hplanck, avogadro - - integer, allocatable, save :: current_group, ng0, ng1 - real(rt), save, allocatable :: nugroup(:), dnugroup(:), xnu(:), dlognu(:), & - erg2rhoYe(:), lognugroup(:) - -end module rad_params_module