|
| 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, also including cosmic ray ionization |
| 37 | + run: | |
| 38 | + set -e |
| 39 | + cd unit_test/burn_cell_metal_chem |
| 40 | +
|
| 41 | + declare -A line_numbers_map=( |
| 42 | + ["Z=1"]="4450 4452 4454 4456 4457 4460 4461 4464 4470 4475" |
| 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"]="4463 4465 4467 4469 4470 4473 4474 4477 4483 4488" |
| 50 | + ["Z=1_cr"]="652 654 656 658 659 662 663 666 672 677" |
| 51 | + ["Z=1e-4_cr"]="652 654 656 658 659 662 663 666 672 677" |
| 52 | + ) |
| 53 | +
|
| 54 | + declare -A ref_map=( |
| 55 | + ["Z=1"]="reference_solution_1.out" |
| 56 | + ["Z=1_z10"]="reference_solution_1_z10.out" |
| 57 | + ["Z=1e-1"]="reference_solution_1e-1.out" |
| 58 | + ["Z=1e-2"]="reference_solution_1e-2.out" |
| 59 | + ["Z=1e-3"]="reference_solution_1e-3.out" |
| 60 | + ["Z=1e-4"]="reference_solution_1e-4.out" |
| 61 | + ["Z=1e-5"]="reference_solution_1e-5.out" |
| 62 | + ["Z=1e-6"]="reference_solution_1e-6.out" |
| 63 | + ["Z=1_cr"]="reference_solution_1_cr.out" |
| 64 | + ["Z=1e-4_cr"]="reference_solution_1e-4_cr.out" |
| 65 | + ) |
| 66 | +
|
| 67 | + ref_line_number_z10=(1 2 3 5 7 10 17 23 28) |
| 68 | +
|
| 69 | + # Original input file |
| 70 | + original_input_file="inputs_metal_chem_1" |
| 71 | + modified_input_file="inputs_metal_chem_modified" |
| 72 | +
|
| 73 | + 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" "Z=1_cr" "Z=1e-4_cr"; do |
| 74 | + cp $original_input_file $modified_input_file |
| 75 | + Z_val=${Z//Z=/} |
| 76 | +
|
| 77 | + if [[ "$Z" == "Z=1_z10" ]]; then |
| 78 | + # Modify the redshift line for Z=1_z10 |
| 79 | + sed -i 's/network.redshift = 0.0/network.redshift = 10.0/g' $modified_input_file |
| 80 | + elif [[ "$Z" != "Z=1_cr" && "$Z" != "Z=1e-4_cr" ]]; then |
| 81 | + # Replace the metallicity and dust2gas_ratio values for other Z values |
| 82 | + sed -i 's/network.metallicity = .*/network.metallicity = '"$Z_val"'/g' $modified_input_file |
| 83 | + sed -i 's/network.dust2gas_ratio = .*/network.dust2gas_ratio = '"$Z_val"'/g' $modified_input_file |
| 84 | + fi |
| 85 | +
|
| 86 | + if [[ "$Z" == "Z=1_cr" || "$Z" == "Z=1e-4_cr" ]]; then |
| 87 | + # Modify the number of steps, since CRs impact lowest densities |
| 88 | + sed -i 's/unit_test.nsteps = 100000/unit_test.nsteps = 600/g' $modified_input_file |
| 89 | + # Modify the crate line for Z=1_cr |
| 90 | + sed -i 's/network.crate = 0.0/network.crate = 3e-17/g' $modified_input_file |
| 91 | + if [[ "$Z" == "Z=1e-4_cr" ]]; then |
| 92 | + # Replace the metallicity and dust2gas_ratio values for other Z values |
| 93 | + sed -i 's/network.metallicity = 1/network.metallicity = 1e-4/g' $modified_input_file |
| 94 | + sed -i 's/network.dust2gas_ratio = 1/network.dust2gas_ratio = 1e-4/g' $modified_input_file |
| 95 | + fi |
| 96 | + fi |
| 97 | +
|
| 98 | + output_file="test_${Z_val}.out" |
| 99 | + ./main1d.gnu.DEBUG.ex $modified_input_file amrex.fpe_trap_{invalid,zero,overflow}=1 > $output_file |
| 100 | +
|
| 101 | + line_numbers="${line_numbers_map[$Z]}" |
| 102 | + ref_file="${ref_map[$Z]}" |
| 103 | +
|
| 104 | + error_found=false |
| 105 | + index=0 |
| 106 | + for line_number in $line_numbers; do |
| 107 | + 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) |
| 108 | +
|
| 109 | + # Adjust the line number for the reference file |
| 110 | + if [[ "$Z" == "Z=1" ]]; then |
| 111 | + reference_line_number=$((line_number - 4449)) |
| 112 | + elif [[ "$Z" == "Z=1_z10" ]]; then |
| 113 | + reference_line_number=${ref_line_number_z10[$index]} |
| 114 | + elif [[ "$Z" == "Z=1e-6" ]]; then |
| 115 | + reference_line_number=$((line_number - 4462)) |
| 116 | + elif [[ "$Z" == "Z=1_cr" || "$Z" == "Z=1e-4_cr" ]]; then |
| 117 | + reference_line_number=$((line_number - 651)) |
| 118 | + else |
| 119 | + reference_line_number=$((line_number - 4437)) |
| 120 | + fi |
| 121 | +
|
| 122 | + value2=$(awk 'NR=='"$reference_line_number"' {match($0, /[+-]?[0-9]+([.][0-9]+)?[eE]?[+-]?[0-9]+/); if (RSTART) print substr($0, RSTART, RLENGTH)}' $ref_file) |
| 123 | +
|
| 124 | + difference=$(awk -v val1="$value1" -v val2="$value2" 'BEGIN { printf "%.2f", (val1 - val2) / val2 }') |
| 125 | +
|
| 126 | + if (( $(echo "$difference > 0.01" | bc -l) )); then |
| 127 | + echo "Z: $Z" |
| 128 | + echo "Line number: $line_number" |
| 129 | + echo "Value in $output_file: $value1" |
| 130 | + echo "Value in $ref_file: $value2" |
| 131 | + echo "Difference between test and reference value is $difference, more than allowed threshold of 0.01" |
| 132 | + echo |
| 133 | + error_found=true |
| 134 | + fi |
| 135 | + index=$((index + 1)) |
| 136 | + done |
| 137 | +
|
| 138 | + if [[ $error_found == true ]]; then |
| 139 | + exit 1 |
| 140 | + fi |
| 141 | + done |
| 142 | +
|
| 143 | + - name: Print backtrace if any failure |
| 144 | + if: ${{ failure() && hashFiles('unit_test/burn_cell_metal_chem/Backtrace.0') != '' }} |
| 145 | + run: cat unit_test/burn_cell_metal_chem/Backtrace.0 |
| 146 | + |
0 commit comments