Skip to content

Commit

Permalink
Merge branch 'development' into vode_maxord
Browse files Browse the repository at this point in the history
  • Loading branch information
psharda authored Aug 29, 2024
2 parents 9175c98 + fb8b008 commit 6405ec8
Show file tree
Hide file tree
Showing 44 changed files with 16,738 additions and 578 deletions.
126 changes: 126 additions & 0 deletions .github/workflows/burn_cell_metal_chem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: burn_cell_metal_chem

on: [pull_request]

jobs:
burn_cell_metal_chem:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get AMReX
run: |
mkdir external
cd external
git clone https://github.com/AMReX-Codes/amrex.git
cd amrex
git checkout development
echo 'AMREX_HOME=$(GITHUB_WORKSPACE)/external/amrex' >> $GITHUB_ENV
echo $AMREX_HOME
if [[ -n "${AMREX_HOME}" ]]; then exit 1; fi
cd ../..
- name: Install dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get -qq -y install curl cmake jq clang g++>=9.3.0
- name: Compile
run: |
cd unit_test/burn_cell_metal_chem
make -j 2
- name: Run and compare outputs for different Z values
run: |
set -e
cd unit_test/burn_cell_metal_chem
declare -A line_numbers_map=(
["Z=1"]="4461 4463 4465 4467 4468 4471 4472 4475 4481 4486"
["Z=1_z10"]="1613 1615 4456 4458 4460 4463 4470 4476 4481"
["Z=1e-1"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
["Z=1e-2"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
["Z=1e-3"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
["Z=1e-4"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
["Z=1e-5"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
["Z=1e-6"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
)
declare -A ref_map=(
["Z=1"]="reference_solution_1.out"
["Z=1_z10"]="reference_solution_1_z10.out"
["Z=1e-1"]="reference_solution_1e-1.out"
["Z=1e-2"]="reference_solution_1e-2.out"
["Z=1e-3"]="reference_solution_1e-3.out"
["Z=1e-4"]="reference_solution_1e-4.out"
["Z=1e-5"]="reference_solution_1e-5.out"
["Z=1e-6"]="reference_solution_1e-6.out"
)
ref_line_number_z10=(1 2 3 5 7 10 17 23 28)
# Original input file
original_input_file="inputs_metal_chem_1"
modified_input_file="inputs_metal_chem_modified"
for Z in "Z=1" "Z=1_z10" "Z=1e-1" "Z=1e-2" "Z=1e-3" "Z=1e-4" "Z=1e-5" "Z=1e-6"; do
cp $original_input_file $modified_input_file
Z_val=${Z//Z=/}
if [[ "$Z" == "Z=1_z10" ]]; then
# Modify the redshift line for Z=1_z10
sed -i 's/network.redshift = 0.0/network.redshift = 10.0/g' $modified_input_file
else
# Replace the metallicity and dust2gas_ratio values for other Z values
sed -i 's/network.metallicity = .*/network.metallicity = '"$Z_val"'/g' $modified_input_file
sed -i 's/network.dust2gas_ratio = .*/network.dust2gas_ratio = '"$Z_val"'/g' $modified_input_file
fi
output_file="test_${Z_val}.out"
./main1d.gnu.DEBUG.ex $modified_input_file amrex.fpe_trap_{invalid,zero,overflow}=1 > $output_file
line_numbers="${line_numbers_map[$Z]}"
ref_file="${ref_map[$Z]}"
error_found=false
index=0
for line_number in $line_numbers; do
value1=$(awk 'NR=='"$line_number"' {match($0, /[+-]?[0-9]+([.][0-9]+)?[eE]?[+-]?[0-9]+/); if (RSTART) print substr($0, RSTART, RLENGTH); else print 0}' $output_file)
# Adjust the line number for the reference file
if [[ "$Z" == "Z=1" ]]; then
reference_line_number=$((line_number - 4460))
elif [[ "$Z" == "Z=1_z10" ]]; then
reference_line_number=${ref_line_number_z10[$index]}
else
reference_line_number=$((line_number - 4437))
fi
value2=$(awk 'NR=='"$reference_line_number"' {match($0, /[+-]?[0-9]+([.][0-9]+)?[eE]?[+-]?[0-9]+/); if (RSTART) print substr($0, RSTART, RLENGTH)}' $ref_file)
difference=$(awk -v val1="$value1" -v val2="$value2" 'BEGIN { printf "%.2f", (val1 - val2) / val2 }')
if (( $(echo "$difference > 0.01" | bc -l) )); then
echo "Z: $Z"
echo "Line number: $line_number"
echo "Value in $output_file: $value1"
echo "Value in $ref_file: $value2"
echo "Difference between test and reference value is $difference, more than allowed threshold of 0.01"
echo
error_found=true
fi
index=$((index + 1))
done
if [[ $error_found == true ]]; then
exit 1
fi
done
- name: Print backtrace if any failure
if: ${{ failure() && hashFiles('unit_test/burn_cell_metal_chem/Backtrace.0') != '' }}
run: cat unit_test/burn_cell_metal_chem/Backtrace.0

22 changes: 22 additions & 0 deletions .github/workflows/macos_build_cell_metal_chem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: macos_burn_cell_metal_chem

on: [pull_request]
jobs:
burn_cell:
runs-on: macos-13
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install dependencies
run: |
brew install cmake openmpi python3 || true
brew link --overwrite [email protected]
- name: Compile and run
run: |
mkdir build && cd build
cmake .. -DBUILD_UNIT_TEST_MC=true -DBUILD_AMReX=true
make -j2
ctest --output-on-failure
2 changes: 1 addition & 1 deletion .github/workflows/macos_build_cell_primordial_chem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
- name: Compile and run
run: |
mkdir build && cd build
cmake .. -DBUILD_UNIT_TEST=true -DBUILD_AMReX=true
cmake .. -DBUILD_UNIT_TEST_PC=true -DBUILD_AMReX=true
make -j2
ctest --output-on-failure
87 changes: 74 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)

project(Microphysics
VERSION 1.0.0
DESCRIPTION "building primordial_chemistry network in Microphysics with CMake"
DESCRIPTION "building primordial_chemistry or metal_chemistry networks in Microphysics with CMake"
LANGUAGES CXX C)

#----------------------------------------------------------------------------------------------------------------------
Expand All @@ -23,11 +23,11 @@ function(setup_target_for_microphysics_compilation network_name output_dir)
set(integrationparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration/_parameters")
set(unittestparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/unit_test/_parameters")

set(networkpropfile "${output_dir}/network_properties.H")

if (${network_name} STREQUAL "gamma_law")
set(EOSparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/gamma_law/_parameters")

set(networkpropfile "${output_dir}/network_properties.H")
set(networkfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/gammalaw.net")
set(networkdir "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/")
set(networkheadertemplatefile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/network_header.template")
Expand All @@ -44,6 +44,7 @@ function(setup_target_for_microphysics_compilation network_name output_dir)
set(gamma_law_sources ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/eos_data.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/network_initialization.cpp
${output_dir}/extern_parameters.cpp PARENT_SCOPE)
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/write_network.py" --header_template "${networkheadertemplatefile}" --header_output "${networkpropfile}" -s "${networkfile}" WORKING_DIRECTORY ${output_dir}/)

elseif (${network_name} STREQUAL "primordial_chem")
#need these to write extern_parameters.H
Expand All @@ -52,6 +53,7 @@ function(setup_target_for_microphysics_compilation network_name output_dir)
set(networkpcparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/primordial_chem/_parameters")

#similarly, we want network_properties.H
set(networkpropfile "${output_dir}/network_properties.H")
set(networkfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/primordial_chem/pynucastro.net")
set(networkdir "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/primordial_chem/")
set(networkheadertemplatefile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/network_header.template")
Expand All @@ -71,7 +73,7 @@ function(setup_target_for_microphysics_compilation network_name output_dir)
#so, if any of the _parameter files are changed, one needs to re-run 'cmake'
#to generate updated header files

if(BUILD_UNIT_TEST)
if(BUILD_UNIT_TEST_PC)
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/build_scripts/write_probin.py" --pa "${paramfile} ${EOSparamfile}
${networkpcparamfile} ${networkparamfile} ${VODEparamfile} ${integrationparamfile} ${unittestparamfile}" --use_namespace WORKING_DIRECTORY ${output_dir}/)
else()
Expand All @@ -83,18 +85,67 @@ function(setup_target_for_microphysics_compilation network_name output_dir)
set(primordial_chem_sources ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/eos_data.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/network_initialization.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/primordial_chem/actual_eos_data.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/primordial_chem/actual_network_data.cpp
${output_dir}/extern_parameters.cpp PARENT_SCOPE)


#below for NAUX
execute_process(COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${PYTHONPATH}:${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null" python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/get_naux.py" --net "${networkdir}" --microphysics_path "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/" WORKING_DIRECTORY ${output_dir}/)
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/write_network.py" --header_template "${networkheadertemplatefile}" --header_output "${networkpropfile}" -s "${networkfile}" WORKING_DIRECTORY ${output_dir}/)

elseif (${network_name} STREQUAL "metal_chem")
#need these to write extern_parameters.H
set(paramfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/unit_test/burn_cell_metal_chem/_parameters")
set(EOSparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/metal_chem/_parameters")
set(networkmcparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem/_parameters")

#similarly, we want network_properties.H
set(networkpropfile "${output_dir}/network_properties.H")
set(networkfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem/pynucastro.net")
set(networkdir "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem/")
set(networkheadertemplatefile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/network_header.template")

#DO NOT change the order of the directories below!
set (metal_chem_dirs ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/gcem/include
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration/VODE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration/utils
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/metal_chem
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/constants
PARENT_SCOPE)

#we need to have extern_parameters.cpp be available at configure time
#the script write_probin.py writes this .cpp file so we call it here
#note, execute_process only works on 'cmake' and not 'make'
#so, if any of the _parameter files are changed, one needs to re-run 'cmake'
#to generate updated header files

if(BUILD_UNIT_TEST_MC)
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/build_scripts/write_probin.py" --pa "${paramfile} ${EOSparamfile}
${networkmcparamfile} ${networkparamfile} ${VODEparamfile} ${integrationparamfile} ${unittestparamfile}" --use_namespace WORKING_DIRECTORY ${output_dir}/)
else()
#do not need paramfile and unittestparamfile
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/build_scripts/write_probin.py" --pa "${EOSparamfile} ${networkmcparamfile}
${networkparamfile} ${VODEparamfile} ${integrationparamfile} " --use_namespace WORKING_DIRECTORY ${output_dir}/)
endif()

#unlike primordial chem, we also include actual_network_data.cpp here because it is in there that we read in the Semenov opacity table
set(metal_chem_sources ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/eos_data.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/network_initialization.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/metal_chem/actual_eos_data.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem/actual_network_data.cpp
${output_dir}/extern_parameters.cpp PARENT_SCOPE)


#below for NAUX
execute_process(COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${PYTHONPATH}:${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null" python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/get_naux.py" --net "${networkdir}" --microphysics_path "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/" WORKING_DIRECTORY ${output_dir}/)
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/write_network.py" --header_template "${networkheadertemplatefile}" --header_output "${networkpropfile}" -s "${networkfile}" WORKING_DIRECTORY ${output_dir}/)

else()
message(FATAL_ERROR "Given network_name " ${network_name} " currently not supported. Use either 'gamma_law' or 'primordial_chem' ")
message(FATAL_ERROR "Given network_name " ${network_name} " currently not supported. Use either 'gamma_law' or 'primordial_chem' or 'metal_chem' ")

endif()

execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/write_network.py" --header_template "${networkheadertemplatefile}" --header_output "${networkpropfile}" -s "${networkfile}" WORKING_DIRECTORY ${output_dir}/)

endfunction()

Expand Down Expand Up @@ -126,8 +177,9 @@ endif()

#set a cache variable that controls whether
#we want to build the unit test or not
set(BUILD_UNIT_TEST false CACHE BOOL "Do you want to build the unit test? (true/false)")
message("Building unit test -- ${BUILD_UNIT_TEST}")
set(BUILD_UNIT_TEST_PC false CACHE BOOL "Do you want to build the primordial chem unit test? (true/false)")

set(BUILD_UNIT_TEST_MC false CACHE BOOL "Do you want to build the metal chem unit test? (true/false)")

add_compile_options(-Werror -Wall -Wextra)

Expand All @@ -140,19 +192,28 @@ add_compile_options(-Werror -Wall -Wextra)
#this will generate a warning but it will build successfully
#do not need unit_test paramfiles when unit_test is not built

if(BUILD_UNIT_TEST)
setup_target_for_microphysics_compilation("primordial_chem" ${CMAKE_BINARY_DIR})
if(BUILD_UNIT_TEST_PC AND BUILD_UNIT_TEST_MC)
message(FATAL_ERROR "Cannot build both primordial chem and metal chem tests at the same time!")
endif()

if(BUILD_UNIT_TEST_PC)
#Build primordial chem unit test
setup_target_for_microphysics_compilation("primordial_chem" ${CMAKE_BINARY_DIR})
include_directories(${primordial_chem_dirs})

#adding unit_test as subdirectories
#adding unit_tests as subdirectories
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unit_test)
message("Building primordial chem unit test")

else()
elseif(BUILD_UNIT_TEST_MC)
#Build metal chem unit test
setup_target_for_microphysics_compilation("metal_chem" ${CMAKE_BINARY_DIR})
include_directories(${metal_chem_dirs})

#adding unit_tests as subdirectories
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unit_test)

message("Not building primordial chem unit test")
endif()


#Sample command: cmake .. -DBUILD_UNIT_TEST_MC=True -DBUILD_AMReX=True -DAMReX_SPACEDIM=1

3 changes: 3 additions & 0 deletions EOS/metal_chem/Make.package
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CEXE_headers += actual_eos.H
CEXE_headers += actual_eos_data.H
CEXE_sources += actual_eos_data.cpp
Loading

0 comments on commit 6405ec8

Please sign in to comment.