Skip to content

Commit 48d8f3c

Browse files
committed
Simplify photoionization eos implementation, change species masses
1 parent b1ce94d commit 48d8f3c

8 files changed

Lines changed: 26 additions & 87 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -88,65 +88,13 @@ function(setup_target_for_microphysics_compilation network_name output_dir)
8888
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/primordial_chem/actual_network_data.cpp
8989
${output_dir}/extern_parameters.cpp PARENT_SCOPE)
9090

91-
92-
#below for NAUX
93-
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 "H_ionization_TInd")
97-
#need these to write extern_parameters.H
98-
set(paramfile "${CMAKE_CURRENT_LIST_DIR}/_parameters")
99-
# TODO(#1)(james471): See how to do eosparamfile correctly
100-
set(EOSparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/photoionization/_parameters")
101-
set(networkpcparamfile "${CMAKE_SOURCE_DIR}/src/networks/H_ionization_TInd/_parameters")
102-
103-
#similarly, we want network_properties.H
104-
set(networkpropfile "${output_dir}/network_properties.H")
105-
# set(networkfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/primordial_chem/pynucastro.net")
106-
set(networkdir "${CMAKE_SOURCE_DIR}/src/networks/H_ionization_TInd/")
107-
set(networkheadertemplatefile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks/general_null/network_header.template")
108-
109-
#DO NOT change the order of the directories below!
110-
set (photoionization_dirs ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/gcem/include
111-
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration/VODE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration/utils
112-
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/integration ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces
113-
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/photoionization
114-
${CMAKE_SOURCE_DIR}/src/networks/H_ionization_TInd ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/networks
115-
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/constants
116-
PARENT_SCOPE)
117-
118-
#we need to have extern_parameters.cpp be available at configure time
119-
#the script write_probin.py writes this .cpp file so we call it here
120-
#note, execute_process only works on 'cmake' and not 'make'
121-
#so, if any of the _parameter files are changed, one needs to re-run 'cmake'
122-
#to generate updated header files
123-
124-
if(BUILD_UNIT_TEST_PC)
125-
message(STATUS "In BUILD_UNIT_TEST_PC")
126-
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/build_scripts/write_probin.py" --pa "${paramfile} ${EOSparamfile}
127-
${networkpcparamfile} ${networkparamfile} ${VODEparamfile} ${integrationparamfile} ${unittestparamfile}" --use_namespace WORKING_DIRECTORY ${output_dir}/)
128-
else()
129-
message(STATUS "Not in BUILD_UNIT_TEST_PC")
130-
#do not need paramfile and unittestparamfile
131-
execute_process(COMMAND python3 "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/util/build_scripts/write_probin.py" --pa "${EOSparamfile} ${networkpcparamfile}
132-
${networkparamfile} ${VODEparamfile} ${integrationparamfile} " --use_namespace WORKING_DIRECTORY ${output_dir}/)
133-
endif()
134-
135-
set(photoionization_sources ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/eos_data.cpp
136-
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/interfaces/network_initialization.cpp
137-
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/photoionization/actual_eos_data.cpp
138-
${CMAKE_SOURCE_DIR}/src/networks/H_ionization_TInd/actual_network_data.cpp
139-
${output_dir}/extern_parameters.cpp PARENT_SCOPE)
140-
141-
14291
#below for NAUX
14392
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}/)
14493
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}/)
14594

14695
elseif (${network_name} STREQUAL "photoionization")
14796
#need these to write extern_parameters.H
14897
set(paramfile "${CMAKE_CURRENT_LIST_DIR}/_parameters")
149-
# TODO(#1)(james471): See how to do eosparamfile correctly
15098
set(EOSparamfile "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/EOS/photoionization/_parameters")
15199
set(networkpcparamfile "${CMAKE_SOURCE_DIR}/src/networks/photoionization/_parameters")
152100

@@ -188,7 +136,6 @@ function(setup_target_for_microphysics_compilation network_name output_dir)
188136
${CMAKE_SOURCE_DIR}/src/networks/photoionization/actual_network_data.cpp
189137
${output_dir}/extern_parameters.cpp PARENT_SCOPE)
190138

191-
192139
#below for NAUX
193140
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}/)
194141
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}/)

EOS/photoionization/_parameters

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ eos_gamma_default real 1.4
55
# define the specie names, and their masses and gammas
66
species_1_name string "Electron"
77
species_1_gamma real 5./3.
8-
species_1_mass real 9.10938188e-28
8+
species_1_mass real 9.10938291e-28
99

1010
species_2_name string "Hydrogen"
1111
species_2_gamma real 5./3.
12-
species_2_mass real 1.67353251819e-24
12+
species_2_mass real 1.673532715291e-24
1313

1414
species_3_name string "Hydrogen_Ion"
1515
species_3_gamma real 5./3.
16-
species_3_mass real 1.67353251819e-24
16+
species_3_mass real 1.672621777e-24

EOS/photoionization/actual_eos.H

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77

88
#include "eos_type.H"
99
#include <AMReX.H>
10-
#include <iostream>
1110
#include <network.H>
1211
#include <fundamental_constants.H>
1312
#include <extern_parameters.H>
1413
#include <cmath>
1514
#include <actual_eos_data.H>
16-
#include <ostream>
1715

1816
const std::string eos_name = "multigamma";
1917

@@ -68,27 +66,20 @@ AMREX_GPU_HOST_DEVICE AMREX_INLINE
6866
void actual_eos (I input, T& state)
6967
{
7068
static_assert(std::is_same_v<I, eos_input_t>, "input must be either eos_input_rt or eos_input_re");
71-
const amrex::Real gasconstant = C::n_A * C::k_B;
72-
const amrex::Real protonmass = C::m_p;
73-
// Special gamma factors
69+
constexpr amrex::Real protonmass = C::m_p;
70+
7471
amrex::Real sum_Abarinv = 0.0_rt;
75-
amrex::Real sum_gammasinv = 0.0_rt;
72+
amrex::Real sum_ni_fi_over_2 = 0.0_rt;
7673
amrex::Real rhotot = 0.0_rt;
7774

7875
for (int n = 0; n < NumSpec; ++n) {
79-
rhotot += state.xn[n]*spmasses[n];
80-
// std::cout << "actual_eos()--> xn[" << n << "]: " << state.xn[n] << ", spmasses[" << n << "]: " << spmasses[n] << std::endl;
81-
}
82-
// std::cout << "Density in EOS: " << rhotot << std::endl;
83-
84-
for (int n = 0; n < NumSpec; ++n) {
76+
rhotot += state.xn[n] * spmasses[n];
77+
sum_ni_fi_over_2 += state.xn[n] / (gammas[n] - 1.0);
8578
sum_Abarinv += state.xn[n];
86-
sum_gammasinv += (state.xn[n]*protonmass/rhotot) * (1.0/(gammas[n]-1.0));
8779
}
88-
// std::cout << "actual_eos()--> rhotot: " << rhotot << ", state.xn[0]: " << state.xn[0] << ", state.xn[1]: " << state.xn[1] << ", state.xn[2]: " << state.xn[2] << std::endl;
80+
sum_ni_fi_over_2 /= sum_Abarinv;
8981
sum_Abarinv *= protonmass/rhotot;
9082
state.mu = 1.0 / sum_Abarinv;
91-
sum_gammasinv /= sum_Abarinv;
9283

9384
//-------------------------------------------------------------------------
9485
// For all EOS input modes EXCEPT eos_input_rt, first compute dens
@@ -98,7 +89,6 @@ void actual_eos (I input, T& state)
9889
amrex::Real temp = NAN;
9990
amrex::Real dens = NAN;
10091
amrex::Real eint = NAN;
101-
// std::cout << "Eos was called" << std::endl;
10292
switch (input) {
10393

10494
case eos_input_rt:
@@ -107,8 +97,7 @@ void actual_eos (I input, T& state)
10797
// We don't need to do anything here
10898
temp = state.T;
10999
dens = state.rho;
110-
eint = sum_gammasinv * sum_Abarinv * gasconstant * state.T;
111-
// std::cout << "actual_eos() --> eos_input_rt: temp: " << temp << ", dens: " << dens << ", eint: " << eint << ", sum_gammasinv: " << sum_gammasinv << ", sum_Abarinv: " << sum_Abarinv << std::endl;
100+
eint = sum_ni_fi_over_2 * C::k_B * temp / rhotot;
112101
break;
113102

114103
case eos_input_re:
@@ -121,9 +110,8 @@ void actual_eos (I input, T& state)
121110

122111
// stop the integration if the internal energy < 0
123112
AMREX_ASSERT(state.e > 0.);
124-
temp = state.e /( sum_gammasinv * gasconstant * sum_Abarinv);
113+
temp = state.e * rhotot / (sum_ni_fi_over_2 * C::k_B);
125114
eint = state.e;
126-
// std::cout << "actual_eos() --> eos_input_re: temp: " << temp << ", dens: " << dens << ", eint: " << eint << ", sum_gammasinv: " << sum_gammasinv << ", sum_Abarinv: " << sum_Abarinv << std::endl;
127115
}
128116

129117
break;
@@ -151,8 +139,8 @@ void actual_eos (I input, T& state)
151139

152140
// stop the integration if the pressure < 0
153141
AMREX_ASSERT(state.p > 0.);
154-
eint = state.p * sum_gammasinv / dens;
155-
temp = eint / (sum_gammasinv * gasconstant * sum_Abarinv);
142+
eint = state.p * sum_ni_fi_over_2 / dens;
143+
temp = eint * rhotot / (sum_ni_fi_over_2 * C::k_B);
156144
}
157145
break;
158146

@@ -203,18 +191,18 @@ void actual_eos (I input, T& state)
203191
}
204192

205193
if constexpr (has_pressure<T>::value) {
206-
amrex::Real pressure = state.rho * eint / sum_gammasinv;
194+
amrex::Real pressure = state.rho * eint / sum_ni_fi_over_2;
207195
state.p = pressure;
208196

209197
state.dpdT = pressure / temp;
210198
state.dpdr = pressure / dens;
211-
state.cs = std::sqrt((1.0 + 1.0/sum_gammasinv) * state.p /state.rho);
199+
state.cs = std::sqrt((1.0 + 1.0/sum_ni_fi_over_2) * state.p /state.rho);
212200
if constexpr (has_G<T>::value) {
213-
state.G = 0.5 * (1.0 + (1.0 + 1.0/sum_gammasinv));
201+
state.G = 0.5 * (1.0 + (1.0 + 1.0/sum_ni_fi_over_2));
214202
}
215203
}
216204

217-
amrex::Real dedT = sum_gammasinv * sum_Abarinv * gasconstant;
205+
amrex::Real dedT = sum_ni_fi_over_2 * C::k_B / rhotot;
218206
amrex::Real dedr = 0.0_rt;
219207
if constexpr (has_energy<T>::value) {
220208
state.dedT = dedT;

integration/VODE/vode_dvhin.H

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ void dvhin (BurnT& state, DvodeT& vstate, amrex::Real& H0, int& NITER, int& IER)
4545
amrex::Real HUB = PT1 * TDIST;
4646

4747
for (int i = 1; i <= int_neqs; ++i) {
48-
// TODO(#3)(james471): This can probably be optimized to reduce branching
4948
amrex::Real atol{};
5049
#if defined (PHOTOCHEMISTRY)
5150
if (i <= NumSpec) {

integration/VODE/vode_dvstep.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,14 @@ int dvstep (BurnT& state, DvodeT& vstate)
350350
break;
351351
}
352352
#endif
353-
#endif
354353

355354
#ifdef SDC
356355
// Abort the program. This is unimplemented
357356
amrex::Abort("SDC does not yet support radiation updates");
358357
#endif
359358

360359
}
360+
#endif
361361

362362
// The corrector has converged (NFLAG = 0). The local error test is
363363
// made and control passes to statement 500 if it fails.

integration/utils/numerical_jacobian.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/// difference in terms of X and T and then convert the Jacobian
3030
/// elements to be in terms of X and e
3131

32-
// TODO(#2)(james471): This needs fixes for radiation
32+
// TODO(james471): This needs fixes for radiation
3333

3434
struct jac_info_t {
3535
amrex::Real h;

interfaces/burn_type.H

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ struct burn_t
170170

171171
};
172172

173-
// TODO(james471): Add radiation variables to the printout
174173
inline
175174
std::ostream& operator<< (std::ostream& o, burn_t const& burn_state)
176175
{
@@ -181,6 +180,12 @@ std::ostream& operator<< (std::ostream& o, burn_t const& burn_state)
181180
for (double X : burn_state.xn) {
182181
o << X << " ";
183182
}
183+
#ifdef PHOTOCHEMISTRY
184+
o << "rn = ";
185+
for (double Rn : burn_state.rn) {
186+
o << Rn << " ";
187+
}
188+
#endif
184189
o << std::endl;
185190
o << "(i, j, k) = " << burn_state.i << " " << burn_state.j << " " << burn_state.k << std::endl;
186191
#if NAUX_NET > 0

networks/rhs.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <integrator_data.H>
2121
#include <microphysics_autodiff.H>
2222

23-
// TODO(#2)(james471): Check if this requires changes for radiation variables
23+
// TODO(james471): Check if this requires changes for radiation variables
2424

2525
#ifdef NEW_NETWORK_IMPLEMENTATION
2626

0 commit comments

Comments
 (0)