Skip to content

Commit 6405ec8

Browse files
authored
Merge branch 'development' into vode_maxord
2 parents 9175c98 + fb8b008 commit 6405ec8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+16738
-578
lines changed
+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: burn_cell_metal_chem
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
burn_cell_metal_chem:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
14+
- name: Get AMReX
15+
run: |
16+
mkdir external
17+
cd external
18+
git clone https://github.com/AMReX-Codes/amrex.git
19+
cd amrex
20+
git checkout development
21+
echo 'AMREX_HOME=$(GITHUB_WORKSPACE)/external/amrex' >> $GITHUB_ENV
22+
echo $AMREX_HOME
23+
if [[ -n "${AMREX_HOME}" ]]; then exit 1; fi
24+
cd ../..
25+
26+
- name: Install dependencies
27+
run: |
28+
sudo apt-get update -y -qq
29+
sudo apt-get -qq -y install curl cmake jq clang g++>=9.3.0
30+
31+
- name: Compile
32+
run: |
33+
cd unit_test/burn_cell_metal_chem
34+
make -j 2
35+
36+
- name: Run and compare outputs for different Z values
37+
run: |
38+
set -e
39+
cd unit_test/burn_cell_metal_chem
40+
41+
declare -A line_numbers_map=(
42+
["Z=1"]="4461 4463 4465 4467 4468 4471 4472 4475 4481 4486"
43+
["Z=1_z10"]="1613 1615 4456 4458 4460 4463 4470 4476 4481"
44+
["Z=1e-1"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
45+
["Z=1e-2"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
46+
["Z=1e-3"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
47+
["Z=1e-4"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
48+
["Z=1e-5"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
49+
["Z=1e-6"]="4438 4440 4442 4444 4445 4448 4449 4452 4458 4463"
50+
)
51+
52+
declare -A ref_map=(
53+
["Z=1"]="reference_solution_1.out"
54+
["Z=1_z10"]="reference_solution_1_z10.out"
55+
["Z=1e-1"]="reference_solution_1e-1.out"
56+
["Z=1e-2"]="reference_solution_1e-2.out"
57+
["Z=1e-3"]="reference_solution_1e-3.out"
58+
["Z=1e-4"]="reference_solution_1e-4.out"
59+
["Z=1e-5"]="reference_solution_1e-5.out"
60+
["Z=1e-6"]="reference_solution_1e-6.out"
61+
)
62+
63+
ref_line_number_z10=(1 2 3 5 7 10 17 23 28)
64+
65+
# Original input file
66+
original_input_file="inputs_metal_chem_1"
67+
modified_input_file="inputs_metal_chem_modified"
68+
69+
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
70+
cp $original_input_file $modified_input_file
71+
Z_val=${Z//Z=/}
72+
73+
if [[ "$Z" == "Z=1_z10" ]]; then
74+
# Modify the redshift line for Z=1_z10
75+
sed -i 's/network.redshift = 0.0/network.redshift = 10.0/g' $modified_input_file
76+
else
77+
# Replace the metallicity and dust2gas_ratio values for other Z values
78+
sed -i 's/network.metallicity = .*/network.metallicity = '"$Z_val"'/g' $modified_input_file
79+
sed -i 's/network.dust2gas_ratio = .*/network.dust2gas_ratio = '"$Z_val"'/g' $modified_input_file
80+
fi
81+
82+
output_file="test_${Z_val}.out"
83+
./main1d.gnu.DEBUG.ex $modified_input_file amrex.fpe_trap_{invalid,zero,overflow}=1 > $output_file
84+
85+
line_numbers="${line_numbers_map[$Z]}"
86+
ref_file="${ref_map[$Z]}"
87+
88+
error_found=false
89+
index=0
90+
for line_number in $line_numbers; do
91+
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)
92+
93+
# Adjust the line number for the reference file
94+
if [[ "$Z" == "Z=1" ]]; then
95+
reference_line_number=$((line_number - 4460))
96+
elif [[ "$Z" == "Z=1_z10" ]]; then
97+
reference_line_number=${ref_line_number_z10[$index]}
98+
else
99+
reference_line_number=$((line_number - 4437))
100+
fi
101+
102+
value2=$(awk 'NR=='"$reference_line_number"' {match($0, /[+-]?[0-9]+([.][0-9]+)?[eE]?[+-]?[0-9]+/); if (RSTART) print substr($0, RSTART, RLENGTH)}' $ref_file)
103+
104+
difference=$(awk -v val1="$value1" -v val2="$value2" 'BEGIN { printf "%.2f", (val1 - val2) / val2 }')
105+
106+
if (( $(echo "$difference > 0.01" | bc -l) )); then
107+
echo "Z: $Z"
108+
echo "Line number: $line_number"
109+
echo "Value in $output_file: $value1"
110+
echo "Value in $ref_file: $value2"
111+
echo "Difference between test and reference value is $difference, more than allowed threshold of 0.01"
112+
echo
113+
error_found=true
114+
fi
115+
index=$((index + 1))
116+
done
117+
118+
if [[ $error_found == true ]]; then
119+
exit 1
120+
fi
121+
done
122+
123+
- name: Print backtrace if any failure
124+
if: ${{ failure() && hashFiles('unit_test/burn_cell_metal_chem/Backtrace.0') != '' }}
125+
run: cat unit_test/burn_cell_metal_chem/Backtrace.0
126+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: macos_burn_cell_metal_chem
2+
3+
on: [pull_request]
4+
jobs:
5+
burn_cell:
6+
runs-on: macos-13
7+
steps:
8+
- uses: actions/checkout@v4
9+
with:
10+
fetch-depth: 0
11+
12+
- name: Install dependencies
13+
run: |
14+
brew install cmake openmpi python3 || true
15+
brew link --overwrite [email protected]
16+
17+
- name: Compile and run
18+
run: |
19+
mkdir build && cd build
20+
cmake .. -DBUILD_UNIT_TEST_MC=true -DBUILD_AMReX=true
21+
make -j2
22+
ctest --output-on-failure

.github/workflows/macos_build_cell_primordial_chem.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
- name: Compile and run
1818
run: |
1919
mkdir build && cd build
20-
cmake .. -DBUILD_UNIT_TEST=true -DBUILD_AMReX=true
20+
cmake .. -DBUILD_UNIT_TEST_PC=true -DBUILD_AMReX=true
2121
make -j2
2222
ctest --output-on-failure

CMakeLists.txt

+74-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)
22

33
project(Microphysics
44
VERSION 1.0.0
5-
DESCRIPTION "building primordial_chemistry network in Microphysics with CMake"
5+
DESCRIPTION "building primordial_chemistry or metal_chemistry networks in Microphysics with CMake"
66
LANGUAGES CXX C)
77

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

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

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

30+
set(networkpropfile "${output_dir}/network_properties.H")
3131
set(networkfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/gammalaw.net")
3232
set(networkdir "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/")
3333
set(networkheadertemplatefile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/network_header.template")
@@ -44,6 +44,7 @@ function(setup_target_for_microphysics_compilation network_name output_dir)
4444
set(gamma_law_sources ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/eos_data.cpp
4545
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/network_initialization.cpp
4646
${output_dir}/extern_parameters.cpp PARENT_SCOPE)
47+
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}/)
4748

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

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

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

8891

8992
#below for NAUX
9093
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}/)
94+
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}/)
95+
96+
elseif (${network_name} STREQUAL "metal_chem")
97+
#need these to write extern_parameters.H
98+
set(paramfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/unit_test/burn_cell_metal_chem/_parameters")
99+
set(EOSparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/metal_chem/_parameters")
100+
set(networkmcparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem/_parameters")
101+
102+
#similarly, we want network_properties.H
103+
set(networkpropfile "${output_dir}/network_properties.H")
104+
set(networkfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem/pynucastro.net")
105+
set(networkdir "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem/")
106+
set(networkheadertemplatefile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/network_header.template")
107+
108+
#DO NOT change the order of the directories below!
109+
set (metal_chem_dirs ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/gcem/include
110+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration/VODE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration/utils
111+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces
112+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/metal_chem
113+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks
114+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/constants
115+
PARENT_SCOPE)
116+
117+
#we need to have extern_parameters.cpp be available at configure time
118+
#the script write_probin.py writes this .cpp file so we call it here
119+
#note, execute_process only works on 'cmake' and not 'make'
120+
#so, if any of the _parameter files are changed, one needs to re-run 'cmake'
121+
#to generate updated header files
122+
123+
if(BUILD_UNIT_TEST_MC)
124+
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/build_scripts/write_probin.py" --pa "${paramfile} ${EOSparamfile}
125+
${networkmcparamfile} ${networkparamfile} ${VODEparamfile} ${integrationparamfile} ${unittestparamfile}" --use_namespace WORKING_DIRECTORY ${output_dir}/)
126+
else()
127+
#do not need paramfile and unittestparamfile
128+
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/build_scripts/write_probin.py" --pa "${EOSparamfile} ${networkmcparamfile}
129+
${networkparamfile} ${VODEparamfile} ${integrationparamfile} " --use_namespace WORKING_DIRECTORY ${output_dir}/)
130+
endif()
131+
132+
#unlike primordial chem, we also include actual_network_data.cpp here because it is in there that we read in the Semenov opacity table
133+
set(metal_chem_sources ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/eos_data.cpp
134+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/network_initialization.cpp
135+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/metal_chem/actual_eos_data.cpp
136+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/metal_chem/actual_network_data.cpp
137+
${output_dir}/extern_parameters.cpp PARENT_SCOPE)
138+
139+
140+
#below for NAUX
141+
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}/)
142+
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}/)
91143

92144
else()
93-
message(FATAL_ERROR "Given network_name " ${network_name} " currently not supported. Use either 'gamma_law' or 'primordial_chem' ")
145+
message(FATAL_ERROR "Given network_name " ${network_name} " currently not supported. Use either 'gamma_law' or 'primordial_chem' or 'metal_chem' ")
94146

95147
endif()
96148

97-
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}/)
98149

99150
endfunction()
100151

@@ -126,8 +177,9 @@ endif()
126177

127178
#set a cache variable that controls whether
128179
#we want to build the unit test or not
129-
set(BUILD_UNIT_TEST false CACHE BOOL "Do you want to build the unit test? (true/false)")
130-
message("Building unit test -- ${BUILD_UNIT_TEST}")
180+
set(BUILD_UNIT_TEST_PC false CACHE BOOL "Do you want to build the primordial chem unit test? (true/false)")
181+
182+
set(BUILD_UNIT_TEST_MC false CACHE BOOL "Do you want to build the metal chem unit test? (true/false)")
131183

132184
add_compile_options(-Werror -Wall -Wextra)
133185

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

143-
if(BUILD_UNIT_TEST)
144-
setup_target_for_microphysics_compilation("primordial_chem" ${CMAKE_BINARY_DIR})
195+
if(BUILD_UNIT_TEST_PC AND BUILD_UNIT_TEST_MC)
196+
message(FATAL_ERROR "Cannot build both primordial chem and metal chem tests at the same time!")
197+
endif()
145198

199+
if(BUILD_UNIT_TEST_PC)
200+
#Build primordial chem unit test
201+
setup_target_for_microphysics_compilation("primordial_chem" ${CMAKE_BINARY_DIR})
146202
include_directories(${primordial_chem_dirs})
147203

148-
#adding unit_test as subdirectories
204+
#adding unit_tests as subdirectories
149205
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unit_test)
150-
message("Building primordial chem unit test")
151206

152-
else()
207+
elseif(BUILD_UNIT_TEST_MC)
208+
#Build metal chem unit test
209+
setup_target_for_microphysics_compilation("metal_chem" ${CMAKE_BINARY_DIR})
210+
include_directories(${metal_chem_dirs})
211+
212+
#adding unit_tests as subdirectories
213+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unit_test)
153214

154215
message("Not building primordial chem unit test")
155216
endif()
156217

157-
218+
#Sample command: cmake .. -DBUILD_UNIT_TEST_MC=True -DBUILD_AMReX=True -DAMReX_SPACEDIM=1
158219

EOS/metal_chem/Make.package

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CEXE_headers += actual_eos.H
2+
CEXE_headers += actual_eos_data.H
3+
CEXE_sources += actual_eos_data.cpp

0 commit comments

Comments
 (0)