Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert breakout to C++ #270

Merged
merged 1 commit into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion EOS/breakout/Make.package
Original file line number Diff line number Diff line change
@@ -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
26 changes: 16 additions & 10 deletions EOS/breakout/actual_eos.F90
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
150 changes: 150 additions & 0 deletions EOS/breakout/actual_eos.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#ifndef _actual_eos_H_
#define _actual_eos_H_

#include <extern_parameters.H>
#include <fundamental_constants.H>
#include <network.H>
#include <actual_eos_data.H>

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
9 changes: 9 additions & 0 deletions EOS/breakout/actual_eos_data.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef _actual_eos_data_H_
#define _actual_eos_data_H_

#include <AMReX.H>
#include <AMReX_REAL.H>

extern AMREX_GPU_MANAGED amrex::Real gamma_const;

#endif
4 changes: 4 additions & 0 deletions EOS/breakout/actual_eos_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <actual_eos_data.H>

AMREX_GPU_MANAGED amrex::Real gamma_const;