diff --git a/.clang-format-ignore b/.clang-format-ignore index 0da982561..b0f939de8 100644 --- a/.clang-format-ignore +++ b/.clang-format-ignore @@ -51,8 +51,6 @@ src/clib/time_deriv_0d.hpp src/clib/update_UVbackground_rates.cpp src/clib/utils-cpp.cpp src/clib/utils-cpp.hpp -src/clib/utils.c -src/clib/utils.h src/example/c_example.c src/example/c_local_example.c src/example/cxx_example.C diff --git a/src/clib/CMakeLists.txt b/src/clib/CMakeLists.txt index 06512f604..b5b0b6655 100644 --- a/src/clib/CMakeLists.txt +++ b/src/clib/CMakeLists.txt @@ -89,7 +89,6 @@ add_library(Grackle_Grackle initialize_UVbackground_data.c initialize_UVbackground_data.h rate_functions.c status_reporting.c status_reporting.h - utils.c # auto-generated C source files ${CMAKE_CURRENT_BINARY_DIR}/auto_general.c @@ -122,6 +121,7 @@ add_library(Grackle_Grackle rate_utils.cpp solve_chemistry.cpp scale_fields.cpp scale_fields.hpp + self_shielding_err_check.hpp set_default_chemistry_parameters.cpp solve_rate_cool_g-cpp.cpp solve_rate_cool_g-cpp.h step_rate_gauss_seidel.hpp @@ -178,7 +178,6 @@ add_library(Grackle_Grackle interp_table_utils.h phys_constants.h collisional_rxn_rate_members.def # <-- acts as a C header - utils.h dust_const.def # Fortran public headers diff --git a/src/clib/Make.config.objects b/src/clib/Make.config.objects index 7a4bb87af..100678d37 100644 --- a/src/clib/Make.config.objects +++ b/src/clib/Make.config.objects @@ -51,6 +51,5 @@ OBJS_CONFIG_LIB = \ rate_functions.lo \ rate_utils.lo \ gaussj_g.lo \ - utils.lo \ utils-cpp.lo \ internal_types.lo diff --git a/src/clib/calculate_cooling_time.cpp b/src/clib/calculate_cooling_time.cpp index 1576d621e..671f58651 100644 --- a/src/clib/calculate_cooling_time.cpp +++ b/src/clib/calculate_cooling_time.cpp @@ -15,8 +15,8 @@ #include "grackle.h" #include "cool_multi_time_g.h" #include "internal_units.h" +#include "self_shielding_err_check.hpp" #include "update_UVbackground_rates.hpp" -#include "utils.h" extern "C" int local_calculate_cooling_time(chemistry_data *my_chemistry, chemistry_data_storage *my_rates, @@ -72,8 +72,9 @@ extern "C" int local_calculate_cooling_time(chemistry_data *my_chemistry, InternalGrUnits internalu = new_internalu_(my_units); /* Error checking for H2 shielding approximation */ - if (self_shielding_err_check(my_chemistry, my_fields, - "local_calculate_temperature") != GR_SUCCESS) { + if (grackle::impl::self_shielding_err_check(my_chemistry, my_fields, + "local_calculate_temperature") + != GR_SUCCESS) { return GR_FAIL; } diff --git a/src/clib/self_shielding_err_check.hpp b/src/clib/self_shielding_err_check.hpp new file mode 100644 index 000000000..64c1ffac0 --- /dev/null +++ b/src/clib/self_shielding_err_check.hpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// See the LICENSE file for license and copyright information +// SPDX-License-Identifier: NCSA AND BSD-3-Clause +// +//===----------------------------------------------------------------------===// +/// +/// @file +/// Defines self_shielding_err_check +/// +//===----------------------------------------------------------------------===// + +#ifndef SELF_SHIELDING_ERR_CHECK_HPP +#define SELF_SHIELDING_ERR_CHECK_HPP + +#include // std::fprintf, stderr +#include "grackle.h" + +namespace grackle::impl { + +/// Perform an error check related to self-shielding. If the check fails, the +/// function returns FAIL and prints an error message to stderr +/// +/// @param my_chemistry Holds configuration of chemistry solver +/// @param fields Specify the field names +/// @param func_name Name of the function that is calling the error check +inline int self_shielding_err_check(const chemistry_data* my_chemistry, + const grackle_field_data* fields, + const char* func_name) { + if (my_chemistry->H2_self_shielding == 1) { + if (fields->grid_rank != 3) { + std::fprintf(stderr, + "Error in %s: H2 self-shielding option 1 " + "will only work for 3D Cartesian grids. Use option 2 " + "to provide an array of shielding lengths with " + "H2_self_shielding_length or option 3 to use the " + "local Jeans length.", + func_name); + return GR_FAIL; + } else if (my_chemistry->primordial_chemistry >= 2 && + fields->grid_dx <= 0) { + std::fprintf(stderr, + "Error in %s: H2 self-shielding option 1 and primordial " + "chemistry options of 2 or more require that grid_dx " + "has a positive value.", + func_name); + return GR_FAIL; + } + } + return GR_SUCCESS; +} + +} // namespace grackle::impl + +#endif // SELF_SHIELDING_ERR_CHECK_HPP diff --git a/src/clib/solve_chemistry.cpp b/src/clib/solve_chemistry.cpp index bd7699852..02755181d 100644 --- a/src/clib/solve_chemistry.cpp +++ b/src/clib/solve_chemistry.cpp @@ -15,8 +15,8 @@ #include "grackle.h" #include "internal_units.h" #include "solve_rate_cool_g-cpp.h" +#include "self_shielding_err_check.hpp" #include "update_UVbackground_rates.hpp" -#include "utils.h" extern "C" int local_solve_chemistry(chemistry_data *my_chemistry, chemistry_data_storage *my_rates, @@ -75,9 +75,10 @@ extern "C" int local_solve_chemistry(chemistry_data *my_chemistry, InternalGrUnits internalu = new_internalu_(my_units); /* Error checking for H2 shielding approximation */ - if (self_shielding_err_check(my_chemistry, my_fields, - "local_solve_chemistry") != GR_SUCCESS) { - return GR_SUCCESS; + if (grackle::impl::self_shielding_err_check(my_chemistry, my_fields, + "local_solve_chemistry") + != GR_SUCCESS) { + return GR_FAIL; } /* Call the routine to solve cooling equations. */ diff --git a/src/clib/utils.c b/src/clib/utils.c deleted file mode 100644 index 8a6d9086d..000000000 --- a/src/clib/utils.c +++ /dev/null @@ -1,40 +0,0 @@ -/*********************************************************************** -/ -/ Implement utility functions used internally by Grackle (across routines) -/ -/ -/ 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. -************************************************************************/ - -#include "utils.h" -#include // fprintf, stderr -#include "grackle_macros.h" - -int self_shielding_err_check(const chemistry_data *my_chemistry, - const grackle_field_data *fields, - const char* func_name) { - if (my_chemistry->H2_self_shielding == 1) { - if (fields->grid_rank != 3) { - fprintf(stderr, "Error in %s: H2 self-shielding option 1 " - "will only work for 3D Cartesian grids. Use option 2 " - "to provide an array of shielding lengths with " - "H2_self_shielding_length or option 3 to use the " - "local Jeans length.", - func_name); - return FAIL; - } else if (my_chemistry->primordial_chemistry >= 2 && - fields->grid_dx <= 0) { - fprintf(stderr, "Error in %s: H2 self-shielding option 1 and primordial " - "chemistry options of 2 or more require that grid_dx " - "has a positive value.", - func_name); - return FAIL; - } - } - return SUCCESS; -} diff --git a/src/clib/utils.h b/src/clib/utils.h deleted file mode 100644 index dc74e372e..000000000 --- a/src/clib/utils.h +++ /dev/null @@ -1,39 +0,0 @@ -/*********************************************************************** -/ -/ Declare utility functions used internally by Grackle (across routines) -/ -/ -/ 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. -************************************************************************/ - -#ifndef UTILS_H -#define UTILS_H - -#include "grackle_chemistry_data.h" -#include "grackle_types.h" - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/// Perform an error check related to self-shielding. If the check fails, the -/// function returns FAIL and prints an error message to stderr -/// -/// @param my_chemistry Holds configuration of chemistry solver -/// @param fields Specify the field names -/// @param func_name Name of the function that is calling the error check -int self_shielding_err_check(const chemistry_data *my_chemistry, - const grackle_field_data *fields, - const char* func_name); - - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus - -#endif // UTILS_H