Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e4df3f9
address compiler warning in chemistry_solver_funcs.hppp
mabruzzo Dec 19, 2025
e2ea0d9
address warning about uninitialized variables in solve_rate_cool_g-cp…
mabruzzo Dec 19, 2025
9ff4b3a
mv testing utility library from tests/unit to tests/grtestutils
mabruzzo Dec 18, 2025
b5b7e65
slightly alter we define targets that support testing
mabruzzo Dec 18, 2025
8cae777
address a todo item (to reduce code duplication)
mabruzzo Dec 18, 2025
5cf43bc
Add gmock to the list of libraries linked via testdeps
mabruzzo Dec 19, 2025
deb6c84
mv GrackleCtxPack out of test_ghost_zone and refactor
mabruzzo Dec 16, 2025
c4495e7
transfer grtest_api_fixture out of test_ghost_zone
mabruzzo Dec 16, 2025
268b9b4
introduce some basic tests of ratequery
mabruzzo Dec 17, 2025
cd7deac
add more ratequery tests
mabruzzo Dec 17, 2025
2425701
tweak the name of the test_ghost_zone tests
mabruzzo Dec 17, 2025
37fad17
factor out machinery for creating adaptor
mabruzzo Dec 18, 2025
39e1c0c
fix a broken header include
mabruzzo Dec 19, 2025
804efcf
some light refactoring of the rate utlities
mabruzzo Dec 12, 2025
ff9eca6
rename rateprop -> ratequery::Descr (as in a rate description)
mabruzzo Dec 12, 2025
9a32a9e
slightly more refactoring
mabruzzo Dec 12, 2025
d13591e
tweak signatures of grunstable_(ratequery_id|ith_rate)
mabruzzo Dec 12, 2025
1fff13c
rename rate_utils to ratequery
mabruzzo Dec 12, 2025
3659a3a
rename Descr->Entry
mabruzzo Dec 12, 2025
11ddf78
introduce ratequery.hpp
mabruzzo Dec 12, 2025
fb030ff
Store the `Entry` Registry within chemistry_data_storage
mabruzzo Dec 12, 2025
e42e0dd
lay the foundation for querying properties
mabruzzo Dec 12, 2025
97d3ce6
gracklepy: start directly querying shapes
mabruzzo Dec 12, 2025
ab816b4
gracklepy: use new shape query logic
mabruzzo Dec 12, 2025
080a097
Tweak grackle wrapper
mabruzzo Dec 13, 2025
3a95ef0
remove unimplemented rate properties
mabruzzo Dec 13, 2025
5df10fc
address a gcc compiler warning
mabruzzo Dec 19, 2025
fe1aba6
introduce grunstable_ratequery_nrates
mabruzzo Dec 19, 2025
93c4c74
add some tests that query rates
mabruzzo Dec 19, 2025
08841f7
introduced a setter and getter function
mabruzzo Dec 20, 2025
c75aacf
gracklepy: implement wrappers that use getter/setter
mabruzzo Dec 20, 2025
0881873
gracklepy: purge uses of grunstable_ratequery_get_ptr
mabruzzo Dec 20, 2025
144db1f
remove remaining references to grunstable_ratequery_get_ptr
mabruzzo Dec 20, 2025
5d6fb08
Rename `RecipeEntrySet` -> `EntrySet` and track `id_offset` separately
mabruzzo Dec 13, 2025
5b7ed15
initial implementation of RegBuilder
mabruzzo Dec 20, 2025
7baec78
use RegistryBuilder within RegistryConstructor
mabruzzo Dec 20, 2025
c5a7231
Remove new_Registry
mabruzzo Dec 20, 2025
de89e2b
relocate and simplify get_CollisionalRxn_Entry
mabruzzo Dec 21, 2025
ef5b1be
assorted cleanup
mabruzzo Dec 21, 2025
a2665b2
address a typo in a docstring
mabruzzo Dec 28, 2025
25da6ba
introduce PtrUnion
mabruzzo Dec 13, 2025
3f8ef14
recombine RecipeInfo and EntrySet and flesh out the role of EntrySet
mabruzzo Dec 16, 2025
7da7b81
fix an issue with the canonical invalid rateid
mabruzzo Dec 21, 2025
f9df7b8
flesh out additional support for querying strings
mabruzzo Dec 21, 2025
587a134
first stab at update gracklepy
mabruzzo Dec 22, 2025
de1c5ef
improve the gracklepy bindings
mabruzzo Dec 23, 2025
5c36e45
elaborate on a few more items that need addressing before stabilizing…
mabruzzo Dec 23, 2025
f69092c
fix some issues in test_api_ratequery
mabruzzo Dec 23, 2025
0de69ae
fix a bug in writable check
mabruzzo Dec 23, 2025
862a86d
Shifted the entire definition of EntrySet into ratequery.cpp
mabruzzo Dec 23, 2025
ac69a55
introduce SimpleVec
mabruzzo Dec 23, 2025
651db0e
refactor RegBuilder to use SimpleVec
mabruzzo Dec 26, 2025
9a99f75
prepare RegBuilder to handle owned Entries
mabruzzo Dec 26, 2025
a2e31db
implement logic for RegBuilder to create owned Entry instances
mabruzzo Dec 28, 2025
5b45e62
tweak a test
mabruzzo Dec 28, 2025
419d3e2
minor bugfix
mabruzzo Dec 31, 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
14 changes: 7 additions & 7 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ src/include/grackle_float.h.in
src/include/grackle_misc.h
src/include/grackle_rate_functions.h
src/include/grackle_types.h
tests/unit/grtest_cmd.cpp
tests/unit/grtest_cmd.hpp
tests/unit/grtest_os.cpp
tests/unit/grtest_os.hpp
tests/unit/grtest_utils.cpp
tests/unit/grtest_utils.hpp
tests/grtestutils/cmd.cpp
tests/grtestutils/cmd.hpp
tests/grtestutils/os.cpp
tests/grtestutils/os.hpp
tests/grtestutils/utils.cpp
tests/grtestutils/utils.hpp
tests/grtestutils/googletest/check_allclose.hpp
tests/unit/test_chemistry_struct_synced.cpp
tests/unit/test_ghost_zone.cpp
tests/unit/test_interpolators_comparisons.cpp
tests/unit/test_linalg.cpp
tests/unit/test_status_reporting.cpp
tests/unit/test_unit_interpolators_g.cpp
tests/unit/utest_helpers.hpp

3 changes: 2 additions & 1 deletion src/clib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ add_library(Grackle_Grackle
lookup_cool_rates1d.hpp
make_consistent.cpp make_consistent.hpp
opaque_storage.hpp
rate_utils.cpp
ratequery.cpp ratequery.hpp
solve_chemistry.cpp
scale_fields.cpp scale_fields.hpp
solve_rate_cool_g-cpp.cpp solve_rate_cool_g-cpp.h
support/SimpleVec.hpp
step_rate_gauss_seidel.hpp
step_rate_newton_raphson.hpp
time_deriv_0d.hpp
Expand Down
2 changes: 1 addition & 1 deletion src/clib/Make.config.objects
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ OBJS_CONFIG_LIB = \
calc_tdust_3d.lo \
calc_grain_size_increment_1d.lo \
rate_functions.lo \
rate_utils.lo \
ratequery.lo \
gaussj_g.lo \
utils.lo \
utils-cpp.lo \
Expand Down
21 changes: 16 additions & 5 deletions src/clib/chemistry_solver_funcs.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// See LICENSE file for license and copyright information

/// @file chemistry_solver_funcs.hpp
//===----------------------------------------------------------------------===//
//
// See the LICENSE file for license and copyright information
// SPDX-License-Identifier: NCSA AND BSD-3-Clause
//
//===----------------------------------------------------------------------===//
///
/// @file
/// @brief Defines chemistry reaction related functions invoked by the
/// grackle solver in order to integrate the species densities over time.
///
Expand All @@ -14,6 +19,8 @@
/// be decoupled from the derivative calculation for primoridial species
/// - it may also make sense to further divide logic by the kinds of species
/// that are affected (e.g. primordial vs grains)
///
//===----------------------------------------------------------------------===//

#ifndef CHEMISTRY_SOLVER_FUNCS_HPP
#define CHEMISTRY_SOLVER_FUNCS_HPP
Expand Down Expand Up @@ -579,7 +586,9 @@ inline void species_density_updates_gauss_seidel(

if ( (my_chemistry->metal_chemistry == 1) &&
(itmask_metal[i] != MASK_FALSE) ) {
scoef = scoef;
// we comment out the following line that assigns scoef to itself since
// it has no practical impact and produces a compiler warning
// scoef = scoef;
acoef = acoef
+ kcol_buf.data[CollisionalRxnLUT::kz44][i] * CII(i,j,k) / 12.
+ kcol_buf.data[CollisionalRxnLUT::kz45][i] * OII(i,j,k) / 16.
Expand Down Expand Up @@ -1932,7 +1941,9 @@ inline void species_density_derivatives_0d(

if ((my_chemistry->metal_chemistry == 1) &&
(itmask_metal[0] != MASK_FALSE)) {
scoef = scoef;
// we comment out the following line that assigns scoef to itself since
// it has no practical impact and produces a compiler warning
// scoef = scoef;
acoef = acoef
+ kcr_buf.data[CollisionalRxnLUT::kz44][0] * CII / 12.
+ kcr_buf.data[CollisionalRxnLUT::kz45][0] * OII / 16.
Expand Down
51 changes: 47 additions & 4 deletions src/clib/initialize_chemistry_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "internal_types.hpp" // drop_CollisionalRxnRateCollection
#include "opaque_storage.hpp" // gr_opaque_storage
#include "phys_constants.h"
#include "ratequery.hpp"
#include "status_reporting.h"

#ifdef _OPENMP
#include <omp.h>
Expand Down Expand Up @@ -229,9 +231,15 @@ static void initialize_empty_chemistry_data_storage_struct(chemistry_data_storag
my_rates->opaque_storage = NULL;
}

extern "C" int local_initialize_chemistry_data(chemistry_data *my_chemistry,
chemistry_data_storage *my_rates,
code_units *my_units)
/// core logic of local_initialize_chemistry_data_
///
/// @note
/// This has been separated from local_initialize_chemistry_data to ensure that
/// any memory allocations tracked by reg_builder can be appropriately freed
/// (this is somewhat unavoidable in C++ without destructors)
static int local_initialize_chemistry_data_(
chemistry_data *my_chemistry, chemistry_data_storage *my_rates,
code_units *my_units, grackle::impl::ratequery::RegBuilder* reg_builder)
{

/* Better safe than sorry: Initialize everything to NULL/0 */
Expand Down Expand Up @@ -403,6 +411,7 @@ extern "C" int local_initialize_chemistry_data(chemistry_data *my_chemistry,
init_empty_interp_grid_props_(
&my_rates->opaque_storage->h2dust_grain_interp_props);
my_rates->opaque_storage->grain_species_info = nullptr;
my_rates->opaque_storage->registry = nullptr;

double co_length_units, co_density_units;
if (my_units->comoving_coordinates == TRUE) {
Expand All @@ -418,7 +427,8 @@ extern "C" int local_initialize_chemistry_data(chemistry_data *my_chemistry,

// Compute rate tables.
if (grackle::impl::initialize_rates(my_chemistry, my_rates, my_units,
co_length_units, co_density_units)
co_length_units, co_density_units,
reg_builder)
!= GR_SUCCESS) {
fprintf(stderr, "Error in initialize_rates.\n");
return GR_FAIL;
Expand Down Expand Up @@ -456,6 +466,16 @@ extern "C" int local_initialize_chemistry_data(chemistry_data *my_chemistry,
/* store a copy of the initial units */
my_rates->initial_units = *my_units;

// initialize the registry
if (grackle::impl::ratequery::RegBuilder_misc_recipies(reg_builder,
my_chemistry)
!= GR_SUCCESS){
return GrPrintAndReturnErr("error in RegBuilder_misc_recipies");
}
my_rates->opaque_storage->registry = new grackle::impl::ratequery::Registry(
grackle::impl::ratequery::RegBuilder_consume_and_build(reg_builder)
);

if (grackle_verbose) {
time_t timer;
char tstr[80];
Expand Down Expand Up @@ -503,6 +523,20 @@ extern "C" int local_initialize_chemistry_data(chemistry_data *my_chemistry,
return GR_SUCCESS;
}


extern "C" int local_initialize_chemistry_data(chemistry_data *my_chemistry,
chemistry_data_storage *my_rates,
code_units *my_units)
{
namespace rate_q = grackle::impl::ratequery;
rate_q::RegBuilder reg_builder = rate_q::new_RegBuilder();

int out = local_initialize_chemistry_data_(my_chemistry, my_rates, my_units,
&reg_builder);
rate_q::drop_RegBuilder(&reg_builder);
return out;
}

extern "C" int initialize_chemistry_data(code_units *my_units)
{
if (local_initialize_chemistry_data(grackle_data, &grackle_rates,
Expand Down Expand Up @@ -659,6 +693,15 @@ extern "C" int local_free_chemistry_data(chemistry_data *my_chemistry,
delete my_rates->opaque_storage->grain_species_info;
}

if (my_rates->opaque_storage->registry != nullptr) {
// delete contents of registry
grackle::impl::ratequery::drop_Registry(
my_rates->opaque_storage->registry
);
// delete registry, itself
delete my_rates->opaque_storage->registry;
}

delete my_rates->opaque_storage;
my_rates->opaque_storage = nullptr;

Expand Down
86 changes: 85 additions & 1 deletion src/clib/initialize_rates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,79 @@ int init_kcol_rate_tables(
return GR_SUCCESS;
}


/// a function that encodes the algorithm for looking up the `i`th pointer
/// collisional reaction rate from an instance of `chemistry_data_storage`.
///
/// This is intended to be registered with RegBuilder in order to provide
/// access to the various collisional reaction rates.
///
/// @param my_rates The object from which the rate Entry is loaded
/// @param i the index of the queried rate
grackle::impl::ratequery::Entry get_CollisionalRxn_Entry
(chemistry_data_storage* my_rates, int i) {
// sanity check! (this shouldn't actually happen)
if ((my_rates == nullptr) || (my_rates->opaque_storage == nullptr) ||
(my_rates->opaque_storage->kcol_rate_tables == nullptr)) {
return grackle::impl::ratequery::mk_invalid_Entry();
}

// import new_Entry into the current scope (so we don't need the full name)
using ::grackle::impl::ratequery::new_Entry;

double** data = my_rates->opaque_storage->kcol_rate_tables->data;

// this implementation leverages the following properties of the
// CollisionalRxnLUT enum:
// - each entry of collisional_rxn_rate_members.def has a corresponding
// enumeration-constant
// - the very first enumeration constant has a value of 0 (since a value
// wasn't explicitly specified)
// - the value of each other enumeration constants is 1 larger than the value
// of the previous value (if a value isn't explicitly specified)
// - CollisionalRxnLUT::NUM_ENTRIES specifies the number of other enumeration
// constants (excluding CollisionalRxnLUT::NUM_ENTRIES) in the enum
switch (i) {
#define TO_STR(s) #s
#define ENTRY(NAME) \
case CollisionalRxnLUT::NAME: { return new_Entry(data[i], TO_STR(NAME)); }
#include "collisional_rxn_rate_members.def"

#undef ENTRY
#undef TO_STR
default: {
return grackle::impl::ratequery::mk_invalid_Entry();
}
}
}


/// a function that encodes the algorithm for looking up the k13dd
/// collisional reaction rate from an instance of `chemistry_data_storage`.
///
/// This is intended to be registered with RegBuilder in order to provide
/// access to the various collisional reaction rates.
///
/// @param my_rates The object from which the rate Entry is loaded
/// @param i the index of the queried rate
grackle::impl::ratequery::Entry get_k13dd_Entry(
chemistry_data_storage* my_rates, int i) {
if (i == 0) {
double* ptr = (my_rates == nullptr) ? nullptr : my_rates->k13dd;
return grackle::impl::ratequery::new_Entry(ptr, "k13dd");
} else {
return grackle::impl::ratequery::mk_invalid_Entry();
}
}


} // anonymous namespace

//Definition of the initialise_rates function.
int grackle::impl::initialize_rates(
chemistry_data *my_chemistry, chemistry_data_storage *my_rates,
code_units *my_units, double co_length_unit, double co_density_unit)
code_units *my_units, double co_length_unit, double co_density_unit,
ratequery::RegBuilder* reg_builder)
{
// TODO: we REALLY need to do an error check that
// my_chemistry->NumberOfTemperatureBins >= 2
Expand Down Expand Up @@ -493,6 +560,15 @@ int grackle::impl::initialize_rates(
return GR_FAIL;
}

// register the recipe for looking up the "standard" collisional rates
if (grackle::impl::ratequery::RegBuilder_recipe_1d(
reg_builder, CollisionalRxnLUT::NUM_ENTRIES,
&get_CollisionalRxn_Entry, my_chemistry->NumberOfTemperatureBins
) != GR_SUCCESS) {
return GrPrintAndReturnErr("error registering standard collisional "
"reaction rates");
}

//--------Calculate coefficients for density-dependent collisional H2 dissociation rate--------
//
// idt = 0 calculates coefficients for direct collisional dissociation idt = 1
Expand All @@ -508,6 +584,14 @@ int grackle::impl::initialize_rates(
// coeff7(idt=0, TbinFinal), coeff1(idt=1, Tbin1), ..., coeff7(idt=1, TbinFinal)}
add_k13dd_reaction_rate(&my_rates->k13dd, kUnit, my_chemistry);

// maybe k13dd should be considered multi-dimensional?
if (grackle::impl::ratequery::RegBuilder_recipe_1d(
reg_builder, 1, &get_k13dd_Entry,
my_chemistry->NumberOfTemperatureBins * 14) != GR_SUCCESS) {
return GrPrintAndReturnErr("error registering k13dd rate");
}


//H2 formation on dust grains requires loop over the dust temperature.
add_h2dust_reaction_rate(&my_rates->h2dust, kUnit, my_chemistry);

Expand Down
4 changes: 3 additions & 1 deletion src/clib/initialize_rates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
#define INITIALIZE_RATES_HPP

#include "grackle.h"
#include "ratequery.hpp"

namespace grackle::impl {

int initialize_rates(chemistry_data* my_chemistry,
chemistry_data_storage* my_rates, code_units* my_units,
double co_length_unit, double co_density_unit);
double co_length_unit, double co_density_unit,
ratequery::RegBuilder* reg_builder);

} // namespace grackle::impl

Expand Down
4 changes: 4 additions & 0 deletions src/clib/opaque_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "grackle.h"
#include "dust/grain_species_info.hpp"
#include "internal_types.hpp"
#include "ratequery.hpp"

/// a struct that used to wrap some private storage details
///
Expand Down Expand Up @@ -95,6 +96,9 @@ struct gr_opaque_storage {
/// > calculations). An alternative would be to briefly initialize an
/// > instance during setup and then repack the data.
grackle::impl::GrainSpeciesInfo* grain_species_info;

/// used to implement the experimental ratequery machinery
grackle::impl::ratequery::Registry* registry;
};

#endif /* OPAQUE_STORAGE_HPP */
Loading