Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
4aacf7e
calc_tdust_3d_g: remove misc unused variables 1/4
mabruzzo Jan 5, 2025
43fa8ae
calc_tdust_3d_g: remove misc unused variables 2/4
mabruzzo Jan 5, 2025
3e03795
calc_tdust_3d_g: remove misc unused variables 3/4
mabruzzo Jan 5, 2025
99dad7a
calc_tdust_3d_g: remove misc unused variables 4/4
mabruzzo Jan 5, 2025
22ec78f
calc_tdust_3d_g: cleanup 1st parallel clause
mabruzzo Jan 5, 2025
d3a0ae7
calc_tdust_3d_g: cleanup 3rd parallel clause
mabruzzo Jan 5, 2025
8ebfc1c
calc_tdust_3d_g: remove dust-chem metal species
mabruzzo Jan 5, 2025
36caa98
calc_tdust_3d_g: remove metal-chem metal species
mabruzzo Jan 5, 2025
78cf9aa
calc_tdust_3d_g: adopt more consistent type declarations with other p…
mabruzzo Jan 5, 2025
33f398a
cool1d_multi_g: tweak dust-related calcs
mabruzzo Jan 5, 2025
6c3ddf5
factor out calc_all_tdust_gasgr_1d_g
mabruzzo Jan 5, 2025
25e32d4
calc_all_tdust_gasgr_1d_g: remove some arguments
mabruzzo Jan 5, 2025
98a291f
remove slightly more arguments.
mabruzzo Jan 5, 2025
c220239
remove even more args.
mabruzzo Jan 5, 2025
8fff8df
even more tweaks.
mabruzzo Jan 5, 2025
b0f75ab
calc_all_tdust_gasgr_1d_g: rename mynh -> nh
mabruzzo Jan 5, 2025
6a7ee60
add declaration of calc_all_tdust_gasgr_1d_g to fortran_func_decls.h
mabruzzo Jan 5, 2025
6751401
calc_tdust_3d_g: start using calc_grain_size_increment_1d
mabruzzo Jan 5, 2025
581c9b9
solve_chemistry.c: include the "grackle.h" header and remove now unne…
mabruzzo Jan 10, 2025
5719483
initial port of the solve_rate_cool-g function from Fortran to C++
mabruzzo Jan 10, 2025
c03fe6a
solve_rate_cool_g: move docstrings and remove some now unnecessary co…
mabruzzo Jan 10, 2025
ae2c2eb
solve_rate_cool_g: some minor formatting improvements
mabruzzo Jan 10, 2025
d5426e2
solve_rate_cool_g-cpp: refactor to remove goto
mabruzzo Jan 10, 2025
5bf7fae
solve_rate_cool: directly return an exit code (rather than modify a p…
mabruzzo Jan 10, 2025
7593c00
solve_rate_cool_g: translate remaining error-msgs
mabruzzo Jan 10, 2025
4e490f0
solve_rate_cool_g: accept imetal, dt args by value
mabruzzo Jan 10, 2025
2b7b7c9
solve_rate_cool_g: accept utem, uxyz, urho args by value
mabruzzo Jan 10, 2025
ef11003
remove FORTRAN_NAME(solve_rate_cool_g) solve_chemistry.c
mabruzzo Jan 10, 2025
0510057
step_rate_newton_raphson: make `ierror` local var
mabruzzo Jan 10, 2025
4b0062e
step_rate_newton_raphson: make `itr` local var
mabruzzo Jan 10, 2025
5c4a7b0
solve_rate_cool: start replacing individual local variables with prev…
mabruzzo Jan 10, 2025
b78447b
solve_rate_cool: replace more local variables with previously defined…
mabruzzo Jan 10, 2025
43560af
replace local variables with the last previously defined struct.
mabruzzo Jan 10, 2025
141d11d
solve_rate_cool_g: move some variable declarations to location where …
mabruzzo Jan 13, 2025
b916a10
solve_rate_cool_g: move some more variable declarations to scope wher…
mabruzzo Jan 13, 2025
b9f535b
solve_rate_cool_g: extract some logic into a helper function called `…
mabruzzo Jan 13, 2025
7816dcd
introduce SpLUT lookup table
mabruzzo Jan 15, 2025
59e8db5
solve_rate_cool: replace ~50 temporary variables with `species_tmpdens`
mabruzzo Jan 15, 2025
924c060
introduce col_rec_rxn_rate_members.def file from the gen2024-rate_acc…
mabruzzo Jan 15, 2025
2f36308
solve_rate_cool: replace ~90 temporary variables with `kcr_buf`
mabruzzo Jan 15, 2025
57245ef
extract chem-heating-rates into a separate struct.
mabruzzo Jan 15, 2025
6a80250
solve_rate_cool_g: aggregate ~20 more local vars into structs.
mabruzzo Jan 15, 2025
0cb37e2
Introduce `InternalGrUnits` type
mabruzzo Jan 17, 2025
0cf325b
solve_rate_cool_g-cpp: integrate InternalGrUnits
mabruzzo Jan 17, 2025
0f51ed4
InternalGrUnits: docstring tweak
mabruzzo Jan 17, 2025
8a226da
solve_rate_cool_g: replace most uses of with
mabruzzo Jan 17, 2025
f1462bc
internal_units.h: a few small tweaks to work with C files.
mabruzzo Jan 17, 2025
387b388
solve_rate_cool_g: replaced multiple args with InternalGrUnits
mabruzzo Jan 17, 2025
e7f53f6
introduce a C++ wrapper for the scale_fields_g Fortran subroutine
mabruzzo Jan 17, 2025
106f2ca
introduce C++ wrapper for `ceiling_species_g_` subroutine
mabruzzo Jan 17, 2025
08c6ae3
introduce C++ wrapper for `make_consistent_g_` Fortran subroutine
mabruzzo Jan 17, 2025
62c70f5
introduce C++ wrapper for `lookup_cool_rates1d_g` subroutine
mabruzzo Jan 19, 2025
41e874b
introduce C++ wrapper for `lookup_cool_rates1d_g` subroutine.
mabruzzo Jan 19, 2025
c64b865
introduce C++ wrapper for `step_rate_g` subroutine
mabruzzo Jan 19, 2025
f8784d3
introduce C++ wrapper for `step_rate_newton_raphson` subroutine
mabruzzo Jan 19, 2025
11fc93c
introduce C++ wrapper for `cool1d_multi_g` subroutine.
mabruzzo Jan 19, 2025
9bf2f13
Add utem to InternalGrUnits struct
mabruzzo Jan 20, 2025
55bae14
Tweak `index_helper.h` for C++ compatability
mabruzzo Jan 21, 2025
83253ce
introduce the IndexRange
mabruzzo Jan 21, 2025
1aaa064
first step towards integrating IndexRange into solve_rate_cool_g
mabruzzo Jan 21, 2025
c251745
start integrating IndexRange into wrapped fortran subroutines
mabruzzo Jan 21, 2025
2a0f229
where available, prefer `IndexRange` to pass i_start and i_end (rathe…
mabruzzo Jan 21, 2025
ddd2a8e
solve_rate_cool_g: shift error & warning messages to print 0-based in…
mabruzzo Jan 21, 2025
37dede7
solve_rate_cool_g: all occurences of `j` and `k` now refer to the 0-b…
mabruzzo Jan 21, 2025
72b3a2d
solve_rate_cool_g: move declaration of `i` to within the init-stateme…
mabruzzo Jan 21, 2025
1073a2d
solve_rate_cool_g: modified the first 6 for-loops (of 13) that iterat…
mabruzzo Jan 21, 2025
6a6cae2
solve_rate_cool_g: modified the first 7th and 8th for-loops (of 13) t…
mabruzzo Jan 21, 2025
f1bad9c
solve_rate_cool_g: modified the 9th for-loop (of 13) that iterate ove…
mabruzzo Jan 21, 2025
769df11
solve_rate_cool_g: modified the 10th for-loop (of 13) that iterates o…
mabruzzo Jan 21, 2025
f25e1c1
solve_rate_cool_g: modified the final 3 for-loops (of 13) that iterat…
mabruzzo Jan 21, 2025
93b8020
solve_rate_cool_g: refactored the helper function, `calc_Heq_div_dHeq…
mabruzzo Jan 21, 2025
1b2d6fa
solve_rate_cool_g: for loops over i now use idx_range.i_(start|stop) …
mabruzzo Jan 21, 2025
d4be5e0
made some quantities computed outside the loop into constants.
mabruzzo Jan 21, 2025
6bc2d48
solve_rate_cool_g: move declarations of some other scalar quantities …
mabruzzo Jan 21, 2025
2e81fcd
solve_rate_cool_g: tweaked appearance of coupled-radiative-transfer l…
mabruzzo Jan 22, 2025
e315fc1
factor itmask modification logic out into its own function
mabruzzo Jan 22, 2025
c1e33da
solve_rate_cool_g: making some if-statements legible
mabruzzo Jan 22, 2025
6559471
solve_rate_cool_g: relocate declarations for 2 more local variables i…
mabruzzo Jan 22, 2025
89ac828
solve_rate_cool_g: remove comp[12] local variables
mabruzzo Jan 22, 2025
f550baa
solve_rate_cool_g: make `any_dust` a `const` variable
mabruzzo Jan 22, 2025
e895f56
solve_rate_cool_g: remove 2 constants (these became unnecessary back …
mabruzzo Jan 22, 2025
5ba7217
solve_rate_cool_g: extracted the logic for finding the timestep that …
mabruzzo Jan 22, 2025
82c9f16
solve_rate_cool_g: apply some superficial tweaks to `set_subcycle_dt_…
mabruzzo Jan 22, 2025
fbf76b2
solve_rate_cool_g: extract logic that computes the max timestep for c…
mabruzzo Jan 22, 2025
6200872
correct the description of p2d in the docstring of calc_Heq_div_dHeqdt
mabruzzo Jan 22, 2025
1055473
correct the description of p2d in the docstring of set_subcycle_dt_fr…
mabruzzo Jan 22, 2025
7b39db9
solve_rate_cool_g: adjust formatting of logic that computes the max t…
mabruzzo Jan 22, 2025
9f033fe
solve_rate_cool_g-cpp: adjust a comment
mabruzzo Jan 22, 2025
f59fef6
solve_rate_cool_g: extract the logic for picking a chemistry-network …
mabruzzo Jan 22, 2025
36f828e
solve_rate_cool_g: large step toward aggregating all local variables …
mabruzzo Jan 23, 2025
4e53df8
solve_rate_cool_g: finished aggregating local variables just used for…
mabruzzo Jan 24, 2025
0897411
solve_rate_cool_g: describe potential refactoring
mabruzzo Jan 24, 2025
a39801e
solve_rate_cool_g: moved View creation of radiation field into the he…
mabruzzo Jan 24, 2025
5c71925
solve_rate_cool_g: finish most reloactions -- this function should no…
mabruzzo Jan 24, 2025
e38de31
address some namespace topics.
mabruzzo Jan 25, 2025
a2fb3e1
convert SpLUT to a struct (from a namespace)
mabruzzo Jan 25, 2025
03df051
Convert ColRecRxnLUT from namespace to struct
mabruzzo Jan 25, 2025
d8df5ca
add a note near the top of LUT.hpp about moving contents into a names…
mabruzzo Jan 26, 2025
9e109dc
Merge branch 'gen2024' into gen2024-transcribe
mabruzzo Jan 26, 2025
ba12c47
Merge branch 'gen2024-transcribe_cool_multi_time_g' into gen2024trans…
mabruzzo May 8, 2025
278a1fb
Merge branch 'gen2024-transcribe_cool_multi_time_g' into gen2024trans…
mabruzzo May 17, 2025
d3350bd
add a missing include-directive
mabruzzo May 17, 2025
f1bb2ab
Merge branch 'gen2024-transcribe_cool_multi_time_g' into gen2024trans…
mabruzzo Jun 9, 2025
cee8f0a
Merge branch 'newchem-cpp' into gen2024transcribe/solve_rate_cool_g
mabruzzo Jun 12, 2025
91290b6
pull in the most recent change from gen2024-rate_access_API
mabruzzo Jun 12, 2025
12c0136
Replace ColRecRxn with CollisionalRxn
mabruzzo Jun 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/clib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ add_library(Grackle_Grackle
# C++ Source (and Private Header Files)
cool_multi_time_g-cpp.C cool_multi_time_g-cpp.h
internal_types.C internal_types.hpp
solve_rate_cool_g-cpp.C solve_rate_cool_g-cpp.h
utils-cpp.C utils-cpp.hpp
fortran_func_wrappers.hpp

# Fortran Source Files
calc_all_tdust_gasgr_1d_g.F
Expand Down
168 changes: 168 additions & 0 deletions src/clib/LUT.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
// See LICENSE file for license and copyright information

/// @file LUT.hpp
/// @brief Declares some lookup-tables (LUTs) used internally by Grackle

#ifndef LUT_HPP
#define LUT_HPP

#ifndef __cplusplus
#error "This file can only be read by a c++ compiler"
#endif

// once we have transcribed more code, we should really put this header's
// contents inside of the grackle::impl namespace
// - if a lookup-table is called {name}, then its fully qualified name will be
// `grackle::impl::{name}`.
// - when using the LUT in a function, we can shorten its name, within the
// function to just {name} by inserting `using grackle::impl::{name};` near
// the start of the function
// - we should hold off on doing this until more code is transcribed (since it
// will be hard for the transcription tools to automatically handle the
// shortenning of the fully qualified name)



/// This is collection of enumerators (localized to the `SpLUT::` scope), with
/// an enumerator named for EVERY species (primordial-species, metal-species,
/// grain-species, etc). The enumerator values are intended to be used in a
/// compile-time lookup table (LUT), that incur no overhead at runtime.
///
/// To understand this entity's purpose, imagine that we want to temporarily
/// track data for all N species known to Grackle (the data for each species is
/// stored in a buffer of common size determined at runtime). Consider the
/// following 3 ways we could accomplish this:
/// 1. define a separate variable holding a pointer for every single species
/// - this is what the fortran routines historically did
/// - this won't scale well with N (e.g. a function that requires all of
/// this info needs to take N arguments)
/// 2. define a single struct with a separate data member holding a pointer
/// for every single species.
/// - still doesn't scale well if for applying a common operation to the
/// data of each species (e.g. allocating/deallocating/zeroing-out)
/// 3. track each data-member in a statically sized array that holds pointers
/// for each species
/// - the array length is `SpLUT::NUM_ENTRIES` (known at compile time)
/// - it is now trivial to apply a common operation to each pointer
/// - we use the enumerator values in this LUT to lookup the value
/// corresponding to a given species (for example, we could use
/// `SpLUT::HI` to look up values related to HI)
///
/// > [!important]
/// > This is a private implementation detail. We should never unintentionally
/// > expose this information directly in the public API (i.e. we want to
/// > maintain our flexibility). With that said, there are hypothetical
/// > scenarios where we might deliberately expose it (for performance purposes)
/// > -- but we should think long and hard about it before we do
///
/// Implementation
/// --------------
/// We implement choose to implement this entity by defining the enumerators
/// within a "stateless struct" (i.e. has a size of 0) that won't be
/// instantiated. The enclosing struct acts exactly like a pseudo-namespace
/// - doing this lets us use short/simple names for each enumerator without
/// fear of collision
/// - there are 2 advantages of using a struct over a namespace:
/// 1. it forces us to localize the definition in 1 location (in comparison,
/// C++ lets us add identifiers to a namespace in other files)
/// 2. it provides the flexibility to experiment with passing the LUT as a
/// template parameter
/// - a function that take accepts a specialized LUT (e.g. picked based
/// on primordial_chemistry) could reduce branching within loops and
/// and plausibly produce faster code.
/// - **WE DON'T CURRENTLY HAVE PLANS TO PURSUE THIS.** There are
/// much more immediately useful things to pursue first
///
/// Other Thoughts
/// --------------
/// - maybe we should store the dust species in a separate lookup table?
/// - adopting data-structures that leverage this LUT, is probably an important
/// stepping stone to implementing a system where reaction rates are
/// dynamically specified. After adopting such a system, we may not even need
/// a lookup table any more (this all assumes, of course, that such a system
/// is adequately performant)
struct SpLUT {

// in the future, we may want to reimplement the following in terms of the
// XMacros provided in grackle_field_data_fdatamembers.def (or we may need to
// slightly revise the system?)
enum {
e,
HI,
HII,
HeI,
HeII,
HeIII,

HM,
H2I,
H2II,

DI,
DII,
HDI,

DM,
HDII,
HeHII,

CI,
CII,
CO,
CO2,
OI,
OH,
H2O,
O2,
SiI,
SiOI,
SiO2I,
CH,
CH2,
COII,
OII,
OHII,
H2OII,
H3OII,
O2II,

Mg,
Al,
S,
Fe,

SiM,
FeM,
Mg2SiO4,
MgSiO3,
Fe3O4,
AC,
SiO2D,
MgO,
FeS,
Al2O3,
reforg,
volorg,
H2Oice,

NUM_ENTRIES // <- always last (so it specifies the number of species)
}; // enum

}; // SpLUT struct


/// Defines the LUT for Standard Collisional reaction rates
struct CollisionalRxnLUT {

enum {
#define ENTRY(NAME) NAME,
#include "collisional_rxn_rate_members.def"
#undef ENTRY

NUM_ENTRIES // <- always last (so it specifies the number of species)
}; // enum

}; // CollisionalRxnLUT struct


#endif /* LUT_HPP */
1 change: 1 addition & 0 deletions src/clib/Make.config.objects
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ OBJS_CONFIG_LIB = \
set_default_chemistry_parameters.lo \
solve_chemistry.lo \
solve_rate_cool_g.lo \
solve_rate_cool_g-cpp.lo \
status_reporting.lo \
update_UVbackground_rates.lo \
lookup_cool_rates0d.lo \
Expand Down
132 changes: 132 additions & 0 deletions src/clib/collisional_rxn_rate_members.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/***********************************************************************
/
/ this file lists each member of the collisional species reaction rates
/ that we interpolate in 1d as a function of temperature. This list is
/ intended to be used with X-Macros (to reduce the amount of code
/ required to interact with these data-members)
/
/ Currently, we just specify each rate name. In the future, we will
/ probably add other metadata to track the initializer function.
/
/ Copyright (c) 2013, Enzo/Grackle Development Team.
/
/ Distributed under the terms of the Enzo Public Licence.
/
/ The full license is in the file LICENSE, distributed with this
/ software.
************************************************************************/


/**********************************
* primordial chemistry rate data *
**********************************/

/* 6 species rates */
ENTRY(k1)
ENTRY(k2)
ENTRY(k3)
ENTRY(k4)
ENTRY(k5)
ENTRY(k6)

/* 9 species rates (including H2) */
ENTRY(k7)
ENTRY(k8)
ENTRY(k9)
ENTRY(k10)
ENTRY(k11)
ENTRY(k12)
ENTRY(k13)
ENTRY(k14)
ENTRY(k15)
ENTRY(k16)
ENTRY(k17)
ENTRY(k18)
ENTRY(k19)
ENTRY(k20) /* currently not used */
ENTRY(k21) /* currently not used */
ENTRY(k22) /* 3-body H2 formation */
ENTRY(k23) /* H2-H2 dissociation */

// k13dd is currently omitted from this list. It holds the density dependent
// version of k13 (collisional H2 dissociation)

// radiative rates for 6-species (k24, k25, k26) are omitted
// radiative rates for 9-species (k27, k28, k29, k30, k31) are omitted

// 12 species rates (with Deuterium)
ENTRY(k50)
ENTRY(k51)
ENTRY(k52)
ENTRY(k53)
ENTRY(k54)
ENTRY(k55)
ENTRY(k56)

// New H-ionizing reactions, used for 6, 9 & 12 species chemistry
ENTRY(k57)
ENTRY(k58)

// 15 species rates (with DM, HDII, HeHII)
ENTRY(k125)
ENTRY(k129)
ENTRY(k130)
ENTRY(k131)
ENTRY(k132)
ENTRY(k133)
ENTRY(k134)
ENTRY(k135)
ENTRY(k136)
ENTRY(k137)
ENTRY(k148)
ENTRY(k149)
ENTRY(k150)
ENTRY(k151)
ENTRY(k152)
ENTRY(k153)

// Metal species chemistry rate data
// ---------------------------------

ENTRY(kz15)
ENTRY(kz16)
ENTRY(kz17)
ENTRY(kz18)
ENTRY(kz19)
ENTRY(kz20)
ENTRY(kz21)
ENTRY(kz22)
ENTRY(kz23)
ENTRY(kz24)
ENTRY(kz25)
ENTRY(kz26)
ENTRY(kz27)
ENTRY(kz28)
ENTRY(kz29)
ENTRY(kz30)
ENTRY(kz31)
ENTRY(kz32)
ENTRY(kz33)
ENTRY(kz34)
ENTRY(kz35)
ENTRY(kz36)
ENTRY(kz37)
ENTRY(kz38)
ENTRY(kz39)
ENTRY(kz40)
ENTRY(kz41)
ENTRY(kz42)
ENTRY(kz43)
ENTRY(kz44)
ENTRY(kz45)
ENTRY(kz46)
ENTRY(kz47)
ENTRY(kz48)
ENTRY(kz49)
ENTRY(kz50)
ENTRY(kz51)
ENTRY(kz52)
ENTRY(kz53)
ENTRY(kz54)


Loading