From 08f74ce79d305cdd9684c81f61db870de5289b52 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 27 Feb 2020 20:45:10 -0800 Subject: [PATCH] Convert breakout to C++ --- EOS/breakout/Make.package | 4 +- EOS/breakout/actual_eos.F90 | 26 +++--- EOS/breakout/actual_eos.H | 150 +++++++++++++++++++++++++++++++ EOS/breakout/actual_eos_data.H | 9 ++ EOS/breakout/actual_eos_data.cpp | 4 + 5 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 EOS/breakout/actual_eos.H create mode 100644 EOS/breakout/actual_eos_data.H create mode 100644 EOS/breakout/actual_eos_data.cpp diff --git a/EOS/breakout/Make.package b/EOS/breakout/Make.package index 1f6dd71491..04e037f28f 100644 --- a/EOS/breakout/Make.package +++ b/EOS/breakout/Make.package @@ -1,3 +1,5 @@ F90EXE_sources += actual_eos.F90 - +CEXE_headers += actual_eos_data.H +CEXE_sources += actual_eos_data.cpp +CEXE_headers += actual_eos.H diff --git a/EOS/breakout/actual_eos.F90 b/EOS/breakout/actual_eos.F90 index 99edf5b5f2..c4bb053df6 100644 --- a/EOS/breakout/actual_eos.F90 +++ b/EOS/breakout/actual_eos.F90 @@ -1,7 +1,3 @@ -! This is a constant gamma equation of state, using an ideal gas. -! -! This a simplified version of the more general eos_gamma_general. -! module actual_eos_module @@ -10,11 +6,12 @@ module actual_eos_module use eos_type_module use amrex_fort_module, only : rt => amrex_real + implicit none - character (len=64), public :: eos_name = "gamma_law" + character (len=64), public :: eos_name = "breakout" - real(rt) , allocatable, save :: gamma_const + real(rt), allocatable, save :: gamma_const #ifdef AMREX_USE_CUDA attributes(managed) :: gamma_const @@ -75,15 +72,17 @@ subroutine actual_eos(input, state) case (eos_input_rh) ! dens, enthalpy, and xmass are inputs -#if !(defined(ACC) || defined(CUDA)) +#ifndef AMREX_USE_GPU call amrex_error('EOS: eos_input_rh is not supported in this EOS.') #endif + case (eos_input_tp) ! temp, pres, and xmass are inputs #if !(defined(ACC) || defined(CUDA)) call amrex_error('EOS: eos_input_tp is not supported in this EOS.') #endif + case (eos_input_rp) ! dens, pres, and xmass are inputs @@ -117,26 +116,32 @@ subroutine actual_eos(input, state) ! pressure entropy, and xmass are inputs +#ifndef AMREX_USE_GPU call amrex_error('EOS: eos_input_ps is not supported in this EOS.') +#endif case (eos_input_ph) ! pressure, enthalpy and xmass are inputs -#if !(defined(ACC) || defined(CUDA)) +#ifndef AMREX_USE_GPU call amrex_error('EOS: eos_input_ph is not supported in this EOS.') #endif + case (eos_input_th) ! temperature, enthalpy and xmass are inputs ! This system is underconstrained. -#if !(defined(ACC) || defined(CUDA)) +#ifndef AMREX_USE_GPU call amrex_error('EOS: eos_input_th is not a valid input for the gamma law EOS.') #endif + case default -#if !(defined(ACC) || defined(CUDA)) + +#ifndef AMREX_USE_GPU call amrex_error('EOS: invalid input.') #endif + end select end subroutine actual_eos @@ -148,6 +153,7 @@ subroutine actual_eos_finalize if (allocated(gamma_const)) then deallocate(gamma_const) endif + end subroutine actual_eos_finalize end module actual_eos_module diff --git a/EOS/breakout/actual_eos.H b/EOS/breakout/actual_eos.H new file mode 100644 index 0000000000..b4112f9bb2 --- /dev/null +++ b/EOS/breakout/actual_eos.H @@ -0,0 +1,150 @@ +#ifndef _actual_eos_H_ +#define _actual_eos_H_ + +#include +#include +#include +#include + +const std::string eos_name = "breakout"; + +inline +void actual_eos_init () +{ + + // constant ratio of specific heats + if (eos_gamma > 0.e0_rt) { + gamma_const = eos_gamma; + } else { + gamma_const = 5.0_rt / 3.0_rt; + } + +} + + + +AMREX_GPU_HOST_DEVICE inline +void actual_eos (eos_input_t input, eos_t& state) +{ + + const Real R = k_B * n_A; + + Real poverrho; + + // Calculate mu. This is the only difference between + // this EOS and gamma_law. + state.mu = 1.0_rt / state.aux[1]; + + switch (input) { + + case eos_input_rt: + + // dens, temp and xmass are inputs + state.cv = R / (state.mu * (gamma_const - 1.0_rt)) ; + state.e = state.cv * state.T; + state.p = (gamma_const - 1.0_rt) * state.rho * state.e; + state.gam1 = gamma_const; + + break; + + case eos_input_rh: + + // dens, enthalpy, and xmass are inputs +#ifndef AMREX_USE_GPU + amrex::Error("EOS: eos_input_rh is not supported in this EOS."); +#endif + + break; + + case eos_input_tp: + + // temp, pres, and xmass are inputs +#ifndef AMREX_USE_GPU + amrex::Error("EOS: eos_input_tp is not supported in this EOS."); +#endif + + break; + + case eos_input_rp: + + // dens, pres, and xmass are inputs + + poverrho = state.p / state.rho; + state.T = poverrho * state.mu * (1.0_rt / R); + state.e = poverrho * (1.0_rt / (gamma_const - 1.0_rt)); + state.gam1 = gamma_const; + + break; + + case eos_input_re: + + // dens, energy, and xmass are inputs + + poverrho = (gamma_const - 1.0_rt) * state.e; + + state.p = poverrho * state.rho; + state.T = poverrho * state.mu * (1.0_rt / R); + state.gam1 = gamma_const; + + // sound speed + state.cs = sqrt(gamma_const * poverrho); + + state.dpdr_e = poverrho; + state.dpde = (gamma_const - 1.0_rt) * state.rho; + + // Try to avoid the expensive log function. Since we don't need entropy + // in hydro solver, set it to an invalid but "nice" value for the plotfile. + state.s = 1.0_rt; + + break; + + case eos_input_ps: + + // pressure entropy, and xmass are inputs + +#ifndef AMREX_USE_GPU + amrex::Error("EOS: eos_input_ps is not supported in this EOS."); +#endif + + break; + + case eos_input_ph: + + // pressure, enthalpy and xmass are inputs +#ifndef AMREX_USE_GPU + amrex::Error("EOS: eos_input_ph is not supported in this EOS."); +#endif + + break; + + case eos_input_th: + + // temperature, enthalpy and xmass are inputs + + // This system is underconstrained. +#ifndef AMREX_USE_GPU + amrex::Error("EOS: eos_input_th is not a valid input for the gamma law EOS."); +#endif + + break; + + default: + +#ifndef AMREX_USE_GPU + amrex::Error("EOS: invalid input."); +#endif + + break; + + } + +} + + + +inline +void actual_eos_finalize () +{ +} + +#endif diff --git a/EOS/breakout/actual_eos_data.H b/EOS/breakout/actual_eos_data.H new file mode 100644 index 0000000000..99a8dbf476 --- /dev/null +++ b/EOS/breakout/actual_eos_data.H @@ -0,0 +1,9 @@ +#ifndef _actual_eos_data_H_ +#define _actual_eos_data_H_ + +#include +#include + +extern AMREX_GPU_MANAGED amrex::Real gamma_const; + +#endif diff --git a/EOS/breakout/actual_eos_data.cpp b/EOS/breakout/actual_eos_data.cpp new file mode 100644 index 0000000000..716dd54b83 --- /dev/null +++ b/EOS/breakout/actual_eos_data.cpp @@ -0,0 +1,4 @@ +#include + +AMREX_GPU_MANAGED amrex::Real gamma_const; +