Skip to content

Commit

Permalink
Add some tests to do simple EoS queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jaharris87 committed Oct 18, 2023
1 parent 5a60c40 commit fff0e5a
Show file tree
Hide file tree
Showing 5 changed files with 457 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Distributions/UnitTests/EquationOfState/Executables/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
MACHINE = $(WEAKLIB_MACHINE)

OPT_LEVEL = DEBUG
OPT_LEVEL = OPTIMIZE
FLAGS = $(FLAGS_$(OPT_LEVEL))

USE_GPU ?= FALSE
USE_CUDA ?= FALSE
USE_HIP ?= FALSE
USE_OMP_OL ?= FALSE
USE_OACC ?= FALSE
USE_OMP ?= FALSE

include ../Makefile_EquationOfState
23 changes: 21 additions & 2 deletions Distributions/UnitTests/EquationOfState/Makefile_EquationOfState
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
include $(WEAKLIB_DIR)/External/Build/Makefile_Build
WEAKLIB_DIR ?= $(HOME)/weaklib
include $(WEAKLIB_DIR)/Distributions/Build/Makefile_Build
include $(WEAKLIB_DIR)/Distributions/Build/Makefile_WeakLib_ObjectFiles
include $(WEAKLIB_DIR)/Distributions/Build/Makefile_WeakLib_Dependencies

all: wlEosPerformanceTest wlReadEquationOfStateTest wlRewriteEquationOfStateTest
.DEFAULT_GOAL := all

all: wlEosQueryTest wlEosPerformanceTest wlReadEquationOfStateTest wlRewriteEquationOfStateTest

wlEosQueryTest: \
$(weaklib) wlEosQueryTest.o
$(FLINKER) $(FLAGS) -o wlEosQueryTest_$(MACHINE) \
$(weaklib) wlEosQueryTest.o \
$(LIBRARIES)

wlEosPerformanceTest: \
$(weaklib) wlEosPerformanceTest.o
Expand All @@ -26,6 +37,14 @@ clean:
clobber: clean
rm -f wlEosPerformanceTest_$(MACHINE)

wlEosQueryTest.o: \
wlKindModule.o \
wlEquationOfStateTableModule.o \
wlIOModuleHDF.o \
wlEOSIOModuleHDF.o \
wlInterpolationModule.o \
wlEosQueryTest.F90

wlEosPerformanceTest.o: \
wlKindModule.o \
wlEquationOfStateTableModule.o \
Expand Down
175 changes: 175 additions & 0 deletions Distributions/UnitTests/EquationOfState/wlEosQueryTest.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
PROGRAM wlEosQueryTest

USE wlKindModule, ONLY: &
dp
USE wlEquationOfStateTableModule, ONLY: &
EquationOfStateTableType
USE wlIOModuleHDF, ONLY: &
InitializeHDF, &
FinalizeHDF
USE wlEOSIOModuleHDF, ONLY: &
ReadEquationOfStateTableHDF
USE wlInterpolationModule, ONLY: &
LogInterpolateSingleVariable_3D_Custom, &
LogInterpolateSingleVariable_3D_Custom_Point

IMPLICIT NONE

REAL(dp), PARAMETER :: D_0 = 1660.55
REAL(dp), PARAMETER :: T_0 = 1.16046e9
REAL(dp), PARAMETER :: Y_0 = 0.5

INTEGER :: &
iP
INTEGER, PARAMETER :: &
nPoints = 2**16, &
iD = 1, iT = 2, iY = 3
REAL(dp) :: &
tBegin, &
tEnd, &
tCPU, &
tGPU
REAL(dp), DIMENSION(nPoints) :: &
D, T, Y, E, P, S, ET
TYPE(EquationOfStateTableType) :: &
EOS
REAL(DP), DIMENSION(:), ALLOCATABLE :: &
Ds_T, Ts_T, Ys_T
REAL(DP), DIMENSION(:,:,:), ALLOCATABLE :: &
Ps_T, Es_T, Ss_T, ETs_T
REAL(DP) :: &
OS_P, OS_E, OS_S, OS_ET
INTEGER :: &
iD_T, iT_T, iY_T, iP_T, iS_T, iE_T, iET_T

#if defined(WEAKLIB_OMP_OL)
#elif defined(WEAKLIB_OACC)
!$ACC INIT
#endif

CALL InitializeHDF( )
CALL ReadEquationOfStateTableHDF( EOS, "EquationOfStateTable.h5" )
CALL FinalizeHDF( )

iD_T = EOS % TS % Indices % iRho
iT_T = EOS % TS % Indices % iT
iY_T = EOS % TS % Indices % iYe

ALLOCATE( Ds_T(EOS % TS % nPoints(iD_T)) )
Ds_T = EOS % TS % States(iD_T) % Values

ALLOCATE( Ts_T(EOS % TS % nPoints(iT_T)) )
Ts_T = EOS % TS % States(iT_T) % Values

ALLOCATE( Ys_T(EOS % TS % nPoints(iY_T)) )
Ys_T = EOS % TS % States(iY_T) % Values

iP_T = EOS % DV % Indices % iPressure
iS_T = EOS % DV % Indices % iEntropyPerBaryon
iE_T = EOS % DV % Indices % iInternalEnergyDensity
iET_T = EOS % DV % Indices % iThermalEnergy

OS_P = EOS % DV % Offsets(iP_T)
OS_S = EOS % DV % Offsets(iS_T)
OS_E = EOS % DV % Offsets(iE_T)
OS_ET = EOS % DV % Offsets(iET_T)

ALLOCATE &
( Ps_T(1:EOS % DV % nPoints(1), &
1:EOS % DV % nPoints(2), &
1:EOS % DV % nPoints(3)) )
ALLOCATE &
( Ss_T(1:EOS % DV % nPoints(1), &
1:EOS % DV % nPoints(2), &
1:EOS % DV % nPoints(3)) )
ALLOCATE &
( Es_T(1:EOS % DV % nPoints(1), &
1:EOS % DV % nPoints(2), &
1:EOS % DV % nPoints(3)) )
ALLOCATE &
( ETs_T(1:EOS % DV % nPoints(1), &
1:EOS % DV % nPoints(2), &
1:EOS % DV % nPoints(3)) )

Ps_T = EOS % DV % Variables(iP_T ) % Values
Ss_T = EOS % DV % Variables(iS_T ) % Values
Es_T = EOS % DV % Variables(iE_T ) % Values
ETs_T = EOS % DV % Variables(iET_T ) % Values

#if defined(WEAKLIB_OMP_OL)
!$OMP TARGET ENTER DATA &
!$OMP MAP( to: Ds_T, Ts_T, Ys_T, Es_T, ETs_T, Ps_T, Ss_T, OS_E, OS_P, OS_S, OS_ET ) &
!$OMP MAP( alloc: D, T, Y, P, E, S, ET )
#elif defined (WEAKLIB_OACC)
!$ACC ENTER DATA &
!$ACC COPYIN( Ds_T, Ts_T, Ys_T, Es_T, ETs_T, Ps_T, Ss_T, OS_E, OS_P, OS_S, OS_ET ) &
!$ACC CREATE( D, T, Y, P, E, S, ET )
#endif

WRITE(*,*)
WRITE(*,'(A4,A10,I10.10)') '', 'nPoints = ', nPoints

! --- Initialize Density Points ---

D = D_0


! --- Initialize Temperature Points ---

T = T_0


! --- Initialize Electron Fraction Points ---

Y = Y_0

PRINT*, "Min/Max D = ", MINVAL( D ), MAXVAL( D )
PRINT*, "Min/Max T = ", MINVAL( T ), MAXVAL( T )
PRINT*, "Min/Max Y = ", MINVAL( Y ), MAXVAL( Y )

#if defined(WEAKLIB_OMP_OL)
!$OMP TARGET UPDATE TO( D, Y, T )
#elif defined (WEAKLIB_OACC)
!$ACC UPDATE DEVICE( D, Y, T )
#endif

! --- Compute Internal Energy, Pressure, and Entropy ---

DO iP = 1, nPoints

CALL LogInterpolateSingleVariable_3D_Custom_Point &
( D(iP), T(iP), Y(iP), Ds_T, Ts_T, Ys_T, OS_E, Es_T, E(iP) )

CALL LogInterpolateSingleVariable_3D_Custom_Point &
( D(iP), T(iP), Y(iP), Ds_T, Ts_T, Ys_T, OS_P, Ps_T, P(iP) )

CALL LogInterpolateSingleVariable_3D_Custom_Point &
( D(iP), T(iP), Y(iP), Ds_T, Ts_T, Ys_T, OS_S, Ss_T, S(iP) )

CALL LogInterpolateSingleVariable_3D_Custom_Point &
( D(iP), T(iP), Y(iP), Ds_T, Ts_T, Ys_T, OS_ET, ETs_T, ET(iP) )

END DO

WRITE(*,*)
WRITE(*,*) "Min/Max E = ", MINVAL( E ), MAXVAL( E )
WRITE(*,*) "Min/Max P = ", MINVAL( P ), MAXVAL( P )
WRITE(*,*) "Min/Max S = ", MINVAL( S ), MAXVAL( S )
WRITE(*,*) "Min/Max ET = ", MINVAL( ET ), MAXVAL( ET )

#if defined(WEAKLIB_OMP_OL)
!$OMP TARGET EXIT DATA &
!$OMP MAP( release: D, E, ET, P, S, Y, Ds_T, Ts_T, Ys_T, Es_T, ETs_T, Ps_T, Ss_T, OS_E, OS_P, OS_S, OS_ET )
#elif defined (WEAKLIB_OACC)
!$ACC EXIT DATA &
!$ACC DELETE( D, E, ET, P, S, Y, Ds_T, Ts_T, Ys_T, Es_T, ETs_T, Ps_T, Ss_T, OS_E, OS_P, OS_S, OS_ET )
#endif

DEALLOCATE( Ds_T, Ts_T, Ys_T, Ps_T, Ss_T, Es_T )

#if defined(WEAKLIB_OMP_OL)
#elif defined(WEAKLIB_OACC)
!$ACC SHUTDOWN
#endif

END PROGRAM wlEosQueryTest
17 changes: 16 additions & 1 deletion Distributions/UnitTests/Inversion/Makefile_Inversion
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ wlEosInversionTest: \
$(weaklib) wlEosInversionTest.o \
$(LIBRARIES)

wlEosInversionQuery: \
$(weaklib) wlEosInversionQuery.o
$(FLINKER) $(FLAGS) -o wlEosInversionQuery_$(MACHINE) \
$(weaklib) wlEosInversionQuery.o \
$(LIBRARIES)

clean:
rm -f *.o *.mod *.ld

Expand All @@ -26,4 +32,13 @@ wlEosInversionTest.o: \
wlEOSIOModuleHDF.o \
wlInterpolationModule.o \
wlEOSInversionModule.o \
wlEosInversionTest.F90
wlEosInversionTest.F90

wlEosInversionQuery.o: \
wlKindModule.o \
wlEquationOfStateTableModule.o \
wlIOModuleHDF.o \
wlEOSIOModuleHDF.o \
wlInterpolationModule.o \
wlEOSInversionModule.o \
wlEosInversionQuery.F90
Loading

0 comments on commit fff0e5a

Please sign in to comment.