├── .circleci
└── config.yml
├── .github
└── CODE_OF_CONDUCT.md
├── .gitignore
├── .gitmodules
├── .pre-commit-config.yaml
├── .readthedocs.yml
├── CHANGELOG
├── CITATION.rst
├── CMakeLists.txt
├── CMakePresets.json
├── CONTRIBUTING.rst
├── LICENSE
├── README.md
├── VERSION
├── cmake
├── AddConditionalFortranFlags.cmake
├── GrackleConfig.cmake.in
├── InstallationHelperFuncs.cmake
├── TargetInfoProps.cmake
├── grackle.pc.in
└── installation_rules.cmake
├── config
└── tacc-frontera-intel.cmake
├── configure
├── dependencies.cmake
├── doc
├── Makefile
├── README
└── source
│ ├── Changelog.rst
│ ├── Citing.rst
│ ├── Conduct.rst
│ ├── Contributing.rst
│ ├── Help.rst
│ ├── Installation.rst
│ ├── Integration.rst
│ ├── Interaction.rst
│ ├── Parameters.rst
│ ├── Python.rst
│ ├── RateFunctions.rst
│ ├── Reference.rst
│ ├── Testing.rst
│ ├── Versioning.rst
│ ├── _images
│ ├── cooling_cell.png
│ ├── cooling_rate.png
│ ├── freefall.png
│ └── ramp.png
│ ├── conf.py
│ ├── index.rst
│ └── testing_snippets
│ └── generate.rst
├── input
├── pyproject.toml
├── scripts
├── configure_file.py
└── query_version.py
├── src
├── clib
│ ├── CMakeLists.txt
│ ├── Make.config.assemble
│ ├── Make.config.objects
│ ├── Make.config.settings
│ ├── Make.config.targets
│ ├── Make.mach.darwin
│ ├── Make.mach.fedora
│ ├── Make.mach.linux-gnu
│ ├── Make.mach.nasa-aitken-rome
│ ├── Make.mach.nasa-pleiades
│ ├── Make.mach.ncsa-bluewaters-cray
│ ├── Make.mach.ncsa-bluewaters-gnu
│ ├── Make.mach.summit
│ ├── Make.mach.tacc-stampede-gnu
│ ├── Make.mach.tacc-stampede-intel
│ ├── Make.mach.tigercpu
│ ├── Make.mach.uiuc-campus-gnu
│ ├── Make.mach.uiuc-campus-intel
│ ├── Make.mach.uiuc-campus-pgi
│ ├── Make.mach.unknown
│ ├── Make.mach.wheeler-intel
│ ├── Makefile
│ ├── README.md
│ ├── auto_general.c.in
│ ├── calc_tdust_1d_g.F
│ ├── calc_tdust_3d_g.F
│ ├── calc_temp1d_cloudy_g.F
│ ├── calc_temp_cloudy_g.F
│ ├── calculate_cooling_time.c
│ ├── calculate_dust_temperature.c
│ ├── calculate_gamma.c
│ ├── calculate_pressure.c
│ ├── calculate_temperature.c
│ ├── cie_thin_cooling_rate_tables.h
│ ├── cool1d_cloudy_g.F
│ ├── cool1d_cloudy_old_tables_g.F
│ ├── cool1d_multi_g.F
│ ├── cool_multi_time_g.F
│ ├── dynamic_api.c
│ ├── grackle_chemistry_data_fields.def
│ ├── grackle_field_data_fdatamembers.def
│ ├── grackle_macros.h
│ ├── grackle_units.c
│ ├── index_helper.c
│ ├── index_helper.h
│ ├── initialize_UVbackground_data.c
│ ├── initialize_chemistry_data.c
│ ├── initialize_cloudy_data.c
│ ├── initialize_rates.c
│ ├── interpolators_g.F
│ ├── phys_const.def
│ ├── phys_constants.h
│ ├── rate_functions.c
│ ├── set_default_chemistry_parameters.c
│ ├── solve_chemistry.c
│ ├── solve_rate_cool_g.F
│ ├── update_UVbackground_rates.c
│ ├── utils.c
│ └── utils.h
├── example
│ ├── CMakeLists.txt
│ ├── Make.config.targets
│ ├── Makefile
│ ├── c_example.c
│ ├── c_local_example.c
│ ├── cxx_example.C
│ ├── cxx_omp_example.C
│ └── fortran_example.F
├── include
│ ├── grackle.def
│ ├── grackle.h
│ ├── grackle_chemistry_data.h
│ ├── grackle_float.h.in
│ ├── grackle_fortran_interface.def
│ ├── grackle_fortran_types.def
│ ├── grackle_misc.h
│ ├── grackle_rate_functions.h
│ └── grackle_types.h
└── python
│ ├── CMakeLists.txt
│ ├── examples
│ ├── cooling_cell.py
│ ├── cooling_rate.py
│ ├── freefall.py
│ └── yt_grackle.py
│ ├── matplotlibrc
│ ├── pygrackle
│ ├── __config__.py.in
│ ├── __init__.py
│ ├── api.py
│ ├── fluid_container.py
│ ├── grackle_defs.pxd
│ ├── grackle_wrapper.pyx
│ ├── utilities
│ │ ├── __init__.py
│ │ ├── api.py
│ │ ├── convenience.py
│ │ ├── data_path.py
│ │ ├── evolve.py
│ │ ├── misc.py
│ │ ├── model_tests.py
│ │ ├── physical_constants.py
│ │ ├── primordial_equilibrium.py
│ │ ├── testing.py
│ │ └── units.py
│ └── yt_fields.py
│ ├── setup.cfg
│ └── tests
│ ├── conftest.py
│ ├── test_chemistry.py
│ ├── test_data
│ ├── test_dynamic_api.py
│ ├── test_get_grackle_version.py
│ ├── test_initialisation.py
│ ├── test_local_functions.py
│ ├── test_models.py
│ ├── test_primordial.py
│ ├── test_query_units.py
│ ├── test_specific_heating_rate.py
│ ├── test_volumetric_heating_rate.py
│ └── testing_common.py
└── tests
├── CMakeLists.txt
├── README.rst
├── scripts
├── c_example_ref.json
├── castxml_output_reader.py
├── castxml_wrapper.py
└── code_example_checker.py
└── unit
├── CMakeLists.txt
├── grtest_cmd.cpp
├── grtest_cmd.hpp
├── grtest_utils.cpp
├── grtest_utils.hpp
├── test_chemistry_struct_synced.cpp
├── test_ghost_zone.cpp
└── test_unit_interpolators_g.cpp
/.github/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | You can find the Grackle Community Code of Conduct [here](https://grackle.readthedocs.io/en/latest/Conduct.html).
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # use glob syntax.
2 | syntax: glob
3 |
4 | *.a
5 | *.la
6 | *.lai
7 | *.lo
8 | *.o
9 | *.lo
10 | *~
11 | *.pyc
12 | *.exe
13 | *.so
14 | *.dylib
15 |
16 | bin/freefall
17 | TAGS
18 | DEPEND
19 | DEPEND.bak
20 | out.compile
21 | out.make.DEPEND
22 | svn_version.def
23 | temp.show-*
24 | Make.config.machine
25 | Make.config.override
26 | *.mod
27 | CMakeUserPresets.json
28 |
29 | src/clib/autogen
30 | src/clib/libgrackle.so
31 | src/example/cxx_example
32 | src/example/cxx_table_example
33 | src/example/c_example
34 | src/example/c_table_example
35 | src/example/c_example_nostruct
36 | src/example/c_table_example_nostruct
37 | src/example/fortran_example
38 | src/example/fortran_table_example
39 | src/example/GRACKLE_INFO
40 | src/example/Table__OMP_Performance
41 | src/example/flake8.out
42 | src/example/*.png
43 | src/python/build/*
44 | src/python/*.png
45 | src/python/flake8.out
46 | src/python/.cache/*
47 | src/python/pygrackle.egg-info/*
48 | src/python/pygrackle/*.c
49 | src/python/tests/test_answers
50 |
51 | # build-directories for documentation
52 | doc/build
53 | # the following is created if you follow commands in .circleci/config.yml
54 | doc/source/_build/*
55 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "grackle_data_files"]
2 | path = grackle_data_files
3 | url = https://github.com/grackle-project/grackle_data_files
4 | branch = main
5 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | # This is a placeholder file. The plan is to introduce pre-commit and
2 | # pre-commit.ci into the newchem-cpp development branch. This file exists to
3 | # prevent the pre-commit.ci service from reporting errors on the main branch
4 | # (or for PRs into the main branch) because pre-commit.ci is unable to find
5 | # a .pre-commit-config.yaml file.
6 | #
7 | # Right now, this enables some extremely simplistic checks.
8 |
9 | ci:
10 | autofix_prs: false
11 | autoupdate_schedule: monthly
12 |
13 | repos:
14 |
15 | # there are some other useful hooks we could enable from here in the future
16 | - repo: https://github.com/pre-commit/pre-commit-hooks
17 | rev: v5.0.0
18 | hooks:
19 | - id: check-executables-have-shebangs
20 | - id: check-case-conflict # make sure no filenames would conflict on
21 | # case-insensitive filesystems
22 | # these hooks check that .json, .toml, .yaml files have valid syntax
23 | - id: check-json
24 | - id: check-toml
25 | - id: check-yaml
26 |
--------------------------------------------------------------------------------
/.readthedocs.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 |
3 | build:
4 | os: ubuntu-24.04
5 | tools:
6 | python: "3.11"
7 | jobs:
8 | install:
9 | - python -m pip install --upgrade pip
10 | - pip install --group 'docs'
11 |
12 | sphinx:
13 | # Path to your Sphinx configuration file.
14 | configuration: doc/source/conf.py
15 |
--------------------------------------------------------------------------------
/CITATION.rst:
--------------------------------------------------------------------------------
1 | Citing Grackle
2 | --------------
3 |
4 | The Grackle library was born out of the chemistry and cooling routines of the
5 | `Enzo `__ simulation code. As such, all of those who
6 | have contributed to Enzo development, and especially to the chemistry and
7 | cooling, have contributed to the Grackle.
8 |
9 | If you used the Grackle library in your work, please cite it as "the Grackle chemistry and cooling library (`Smith et al. 2017 `__)"
10 |
11 | Smith, B.D., Bryan, G.L., Glover, S.C.O., et al. 2017, MNRAS, 466, 2217
12 |
13 | Additionally, please add a footnote to: `https://grackle.readthedocs.io/ `_
14 |
15 | For LaTex and BibTex users, here is a copy of the bibitem entry
16 |
17 | .. code-block:: latex
18 |
19 | \bibitem[Smith et al.(2017)]{2017MNRAS.466.2217S} Smith, B.~D., Bryan, G.~L., Glover, S.~C.~O., et al.\ 2017, \mnras, 466, 2217
20 |
21 | and here is a copy of the Bibtext entry:
22 |
23 | .. code-block:: bibtex
24 |
25 | @ARTICLE{2017MNRAS.466.2217S,
26 | author = {{Smith}, B.~D. and {Bryan}, G.~L. and {Glover}, S.~C.~O. and
27 | {Goldbaum}, N.~J. and {Turk}, M.~J. and {Regan}, J. and {Wise}, J.~H. and
28 | {Schive}, H.-Y. and {Abel}, T. and {Emerick}, A. and {O'Shea}, B.~W. and
29 | {Anninos}, P. and {Hummels}, C.~B. and {Khochfar}, S.},
30 | title = "{GRACKLE: a chemistry and cooling library for astrophysics}",
31 | journal = {\mnras},
32 | archivePrefix = "arXiv",
33 | eprint = {1610.09591},
34 | keywords = {astrochemistry, methods: numerical, galaxies: formation},
35 | year = 2017,
36 | month = apr,
37 | volume = 466,
38 | pages = {2217-2234},
39 | doi = {10.1093/mnras/stw3291},
40 | adsurl = {http://adsabs.harvard.edu/abs/2017MNRAS.466.2217S},
41 | adsnote = {Provided by the SAO/NASA Astrophysics Data System}
42 | }
43 |
--------------------------------------------------------------------------------
/CMakePresets.json:
--------------------------------------------------------------------------------
1 | {
2 | "version" : 5,
3 | "cmakeMinimumRequired": {
4 | "major": 3,
5 | "minor": 24,
6 | "patch": 0
7 | },
8 | "configurePresets": [
9 | {
10 | "name": "ci-basic",
11 | "description": "Some basic configuration with Ninja generator. In case a user tries to use a preset, binaryDir was picked so they can run an example from ${binaryDir}/examples (the narrative docs explicitly tell people to do this).",
12 | "generator": "Ninja",
13 | "hidden": true,
14 | "binaryDir": "${sourceDir}/build_${presetName}"
15 | },
16 | {
17 | "name": "ci-common-config",
18 | "description": "Standard configuration of Grackle",
19 | "hidden": true,
20 | "inherits": "ci-basic",
21 | "cacheVariables": {
22 | "GRACKLE_USE_DOUBLE": "ON",
23 | "GRACKLE_USE_OPENMP": "OFF",
24 | "GRACKLE_BUILD_TESTS": "ON"
25 | }
26 | },
27 | {
28 | "name": "ci-omp-config",
29 | "description": "Standard configuration of Grackle with OpenMP. To a weird \"cross-reaction\" between gfortran, OpenMP, & the Ninja generator, we override the generator.",
30 | "generator": "Unix Makefiles",
31 | "hidden": true,
32 | "inherits": "ci-common-config",
33 | "cacheVariables": {
34 | "GRACKLE_USE_OPENMP": "ON"
35 | }
36 | },
37 | {
38 | "name": "ci-flags-warnings-gcc-clang",
39 | "description": "Flags common to gcc and clang for CI (theoretically we may want to maintain a separate set of flags for apple-clang)",
40 | "hidden": true,
41 | "cacheVariables" : {
42 | "CMAKE_COMPILE_WARNING_AS_ERROR": "ON",
43 | "CMAKE_C_FLAGS": "-Wall -Wpedantic -Wextra -Wno-error=unused-variable -Wno-error=maybe-uninitialized -Wno-unused-parameter",
44 | "CMAKE_CXX_FLAGS": "-Wall -Wpedantic -Wextra -Wno-unused-parameter"
45 | }
46 | },
47 | {
48 | "name": "ci-flags-warnings-appleClang",
49 | "description": "Flags from appleClang for CI",
50 | "hidden": true,
51 | "cacheVariables" : {
52 | "CMAKE_COMPILE_WARNING_AS_ERROR": "ON",
53 | "CMAKE_C_FLAGS": "-Wall -Wpedantic -Wextra -Wno-error=unused-variable -Wno-error=newline-eof -Wno-unused-parameter",
54 | "CMAKE_CXX_FLAGS": "-Wall -Wpedantic -Wno-c++17-attribute-extensions -Wno-unused-parameter"
55 | }
56 | },
57 | {
58 | "name": "ci-linux",
59 | "description": "the general configuration preset for linux",
60 | "inherits": ["ci-flags-warnings-gcc-clang", "ci-common-config"],
61 | "cacheVariables": { "CMAKE_BUILD_TYPE": "RELEASE" }
62 | },
63 | {
64 | "name": "ci-linux-omp",
65 | "description": "a preset for linux with OpenMP",
66 | "inherits": ["ci-flags-warnings-gcc-clang", "ci-omp-config"],
67 | "cacheVariables": { "CMAKE_BUILD_TYPE": "RELEASE" }
68 | },
69 | {
70 | "name": "ci-macos",
71 | "description": "the general configuration preset for macOS",
72 | "inherits": ["ci-flags-warnings-appleClang", "ci-common-config"],
73 | "cacheVariables": { "CMAKE_BUILD_TYPE": "RELEASE" }
74 | }
75 | ]
76 | }
77 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | ===========================
2 | The Grackle licensing terms
3 | ===========================
4 |
5 | The Grackle is licensed under the The Enzo Public License, which is
6 | BSD-like and is provided below.
7 |
8 | Copyright (c) 2013-, Enzo/Grackle development team.
9 |
10 | = Enzo Public License =
11 |
12 | ----------------
13 | === University of Illinois/NCSA Open Source License ===
14 |
15 | Copyright (c) 1993-2000 by Greg Bryan and the Laboratory for Computational
16 | Astrophysics and the Board of Trustees of the University of Illinois in
17 | Urbana-Champaign. All rights reserved.
18 |
19 | Developed by:
20 |
21 | * Laboratory for Computational Astrophysics
22 | * National Center for Supercomputing Applications
23 | * University of Illinois in Urbana-Champaign
24 |
25 | Permission is hereby granted, free of charge, to any person obtaining a copy
26 | of this software and associated documentation files (the "Software"), to deal
27 | with the Software without restriction, including without limitation the
28 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
29 | sell copies of the Software, and to permit persons to whom the Software is
30 | furnished to do so, subject to the following conditions:
31 |
32 | 1. Redistributions of source code must retain the above copyright notice,
33 | this list of conditions and the following disclaimers.
34 | 2. Redistributions in binary form must reproduce the above copyright notice,
35 | this list of conditions and the following disclaimers in the documentation
36 | and/or other materials provided with the distribution.
37 | 3. Neither the names of The Laboratory for Computational Astrophysics,
38 | The National Center for Supercomputing Applications, The University of
39 | Illinois in Urbana-Champaign, nor the names of its contributors may be used
40 | to endorse or promote products derived from this Software without specific
41 | prior written permission.
42 |
43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46 | CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
49 | THE SOFTWARE.
50 |
51 |
52 | ---------------
53 | === University of California/BSD License ===
54 |
55 | Copyright (c) 2000-2008 by Greg Bryan and the Laboratory for Computational
56 | Astrophysics and the Regents of the University of California.
57 |
58 | All rights reserved.
59 |
60 | Redistribution and use in source and binary forms, with or without
61 | modification, are permitted provided that the following conditions are met:
62 |
63 | 1. Redistributions of source code must retain the above copyright notice,
64 | this list of conditions and the following disclaimer.
65 | 2. Redistributions in binary form must reproduce the above copyright notice,
66 | this list of conditions and the following disclaimer in the documentation
67 | and/or other materials provided with the distribution.
68 | 3. Neither the name of the Laboratory for Computational Astrophysics, the
69 | University of California, nor the names of its contributors may be used to
70 | endorse or promote products derived from this software without specific prior
71 | written permission.
72 |
73 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
77 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
78 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
79 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
80 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
81 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
82 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
83 | THE POSSIBILITY OF SUCH DAMAGE.
84 |
85 | Grackle History and Development Team
86 | ------------------------------------
87 |
88 | The core Grackle functionality originated as the chemistry and cooling
89 | module of the Enzo simulation code. Enzo was originally written by
90 | Greg Bryan and is now developed by a large team of researchers comprising
91 | the Enzo development team. The chemistry and cooling modules were first
92 | extracted from Enzo to make the Grackle library by Britton Smith and is
93 | developed by members of the Enzo development team.
94 |
--------------------------------------------------------------------------------
/VERSION:
--------------------------------------------------------------------------------
1 | 3.4.1-dev
2 |
--------------------------------------------------------------------------------
/cmake/AddConditionalFortranFlags.cmake:
--------------------------------------------------------------------------------
1 | # this module primarily defines a function that "conditionally" applies fortran
2 | # flags to a given target (that are compiler-specific).
3 | # -> this is "conditional" in the sense that generator-expressions are used to
4 | # ensure that the flags are only applied to Fortran files
5 | #
6 | # the compiler will also provide some basic warnings about potential
7 | # compiler-specific issues
8 |
9 |
10 | # first, we define functions to print commonly-formatted compiler-specific
11 | # warning messages
12 |
13 | function(fc_warn_untested)
14 | # compared to a C compiler, it makes a lot of sense to warn about untested
15 | # fortran compilers because
16 | # - we adopt a fairly custom fortran dialect
17 | # - default name-mangling behavior of Fortran symbols can vary a lot between
18 | # different compilers
19 | message(WARNING
20 | "${CMAKE_Fortran_COMPILER_ID} Fortran compiler is NOT well tested")
21 | endfunction()
22 |
23 | function(fc_warn_ninja)
24 | # this creates a warning about using the current compiler with the ninja build
25 | # generator (only gets shown if configured with the ninja build generator)
26 |
27 | # optionally specify a description of the fortran compiler
28 | if (ARGC EQUAL 0)
29 | set(compiler_descr "the ${CMAKE_Fortran_COMPILER_ID} Fortran compiler")
30 | elseif (ARGC EQUAL 1)
31 | set(compiler_descr "${ARGV0}")
32 | else()
33 | message(FATAL_ERROR "Too many args were provided")
34 | endif()
35 |
36 | # gfortran usually appears to work fine... not sure what goes wrong with the
37 | # other compilers... (is it ninja related? Or does CMake infer more about how
38 | # to use gfortran?)
39 |
40 | if (CMAKE_GENERATOR MATCHES "Ninja")
41 | # We use MATCHES to catch extra Ninja generators like Ninja Multi-Config,
42 | # or (recently deprecated) IDE generators that wrap Ninja
43 |
44 | message(WARNING
45 | "Compilation issues have been encountered while using ${compiler_descr} "
46 | "with the Ninja build-generator. If you encounter problems, consider "
47 | "using the Makefile generator instead.")
48 | endif()
49 | endfunction()
50 |
51 |
52 | # down below, we implement the main function provided by this module
53 |
54 | function(add_conditional_fortran_flags target)
55 | # this function should ONLY introduce the minimal set of flags required to
56 | # succesfully compile the program
57 | # -> in other words, these flags only address formatting and name-mangling
58 | # -> it's considered an anti-pattern to hardcode other kinds of flags (it
59 | # creates challenges for the end-user to specify desired flags)
60 |
61 | # report to user what we are doing: we follow convention and repeat the
62 | # description of what we are doing alongside the result
63 | set(_grackle_fc_flag_msg "Identify compiler-specific Fortran flags")
64 | message(STATUS "${_grackle_fc_flag_msg}")
65 |
66 | # do some (non-exhaustive) handling of the fortran-specific flags!
67 | if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
68 | fc_warn_ninja() # issues encountered with ninja while using cmake 3.16.3
69 | set(GRACKLE_FC_FLAG "") # no flags needed!
70 |
71 | elseif (CMAKE_Fortran_COMPILER_ID MATCHES "^PGI|NVHPC$")
72 | # context: nvhpc is the new branding of pgi compilers
73 | # - the flags were inherited from old Machine-Makefile, but unclear whether
74 | # they will succesfully compile via cmake
75 | # - stuff does compile with nvfortran (but tests have not been run)
76 | fc_warn_untested()
77 | fc_warn_ninja() # issues encountered with nvhpc and ninja while using cmake
78 | # version 3.27.7
79 | set(GRACKLE_FC_FLAG "-Mnosecond_underscore;-Mextend")
80 |
81 | elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "XL") # IBM compiler
82 | fc_warn_untested() # things compile, but tests haven't been run
83 | fc_warn_ninja() # issues encountered with ninja with cmake version 3.27.7
84 |
85 | set(GRACKLE_FC_FLAG "-qfixed=132")
86 |
87 | elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
88 | set(GRACKLE_FC_FLAG "-fno-second-underscore;-ffixed-line-length-132")
89 |
90 | else()
91 | message(STATUS
92 | "No explicit logic for ${CMAKE_Fortran_COMPILER_ID} Fortran compiler, testing GNU flags"
93 | )
94 | fc_warn_ninja("certain Fortran compilers")
95 |
96 | set(GRACKLE_FC_FLAG "")
97 | include(CheckFortranCompilerFlag)
98 | check_fortran_compiler_flag(-fno-second-underscore no_second_underscore)
99 | check_fortran_compiler_flag(-ffixed-line-length-132 fixed_line_length_132)
100 | list(APPEND GRACKLE_FC_FLAG
101 | "$<$:-fno-second-underscore>"
102 | "$<$:-ffixed-line-length-132>"
103 | )
104 |
105 | endif()
106 |
107 | # report the results of this function
108 | if (GRACKLE_FC_FLAG STREQUAL "")
109 | message(STATUS "${_grackle_fc_flag_msg} - none needed")
110 | else()
111 | message(STATUS "${_grackle_fc_flag_msg} - ${GRACKLE_FC_FLAG}")
112 | target_compile_options(${target} PRIVATE
113 | "$<$:${GRACKLE_FC_FLAG}>"
114 | )
115 | endif()
116 | endfunction()
117 |
--------------------------------------------------------------------------------
/cmake/TargetInfoProps.cmake:
--------------------------------------------------------------------------------
1 | # to make our package easily consumable and provide a uniform interface whether
2 | # a downstream cmake process directly builds our product as a part of their
3 | # own build or they find an existing installation with a "CMake Package
4 | # Config" file.
5 | # -> a recommended practice to achieve that is to convey relevant information
6 | # through target properties. (The alternative is to use global variables,
7 | # but that is now discouraged)
8 | # -> but this means that we need to maintain 2 lists of target properties (one
9 | # where declare/build things AND the other where we compile things)
10 | # -> the idea is to provide a wrapper function around set_target_properties
11 | # that records this information, cache the list of properties, and provide
12 | # a second function to get the properties later (to use it to configure the
13 | # "CMake Package Config" file)
14 | # -> while we're at it, it probably makes sense to support reporting this
15 | # information in pkg-config files for non-cmake builds
16 | # -> in that case, we must provide it as global variables
17 | # -> if we're doing this, it makes sense to distinguish between BOOL and
18 | # STRING dtypes (since cmake has an expansive definition of a BOOL dtype)
19 |
20 |
21 |
22 | # this function is just like set_target_properties. It has the signature
23 | #
24 | # set_target_typed_info_properties( ...
25 | # (STRING_PROPERTIES|BOOL_PROPERTIES)
26 | #
27 | # [ ] ...)
28 | function(set_target_typed_info_properties)
29 | set(err_prefix "set_target_typed_info_properties called with")
30 |
31 | if(ARGC LESS_EQUAL 2)
32 | message(FATAL_ERROR "${err_prefix} incorect number of args")
33 | endif()
34 |
35 | math(EXPR loop_stop_inclusive "${ARGC} - 1")
36 | foreach(i RANGE 1 ${loop_stop_inclusive})
37 | if("${ARGV${i}}" MATCHES "^((BOOL)|(STRING))_PROPERTIES$")
38 | math(EXPR properties_start "${i} + 1")
39 | set(dtype "${CMAKE_MATCH_1}")
40 | break()
41 | endif()
42 | endforeach()
43 |
44 | if (NOT DEFINED properties_start)
45 | message(FATAL_ERROR "{err_prefix} no (STRING)|(BOOL)_PROPERTIES specifier")
46 | elseif(properties_start GREATER 2)
47 | message(FATAL_ERROR "set_target_properties only supports 1 target arg")
48 | endif()
49 |
50 | # confirm that remaing args can be organized into name-value pairs
51 | math(EXPR is_odd "((${loop_stop_inclusive}+1) - ${properties_start}) % 2")
52 | if (is_odd)
53 | message(FATAL_ERROR "${arg_num_err_msg} incorrect number of args")
54 | endif()
55 |
56 | set(target "${ARGV0}")
57 |
58 | # iterate over all name-value pairs
59 | foreach(i RANGE ${properties_start} ${loop_stop_inclusive} 2)
60 | math(EXPR ip1 "${i} + 1")
61 |
62 | if (${dtype} STREQUAL "STRING")
63 | set(val "${ARGV${ip1}}")
64 | elseif(${ARGV${ip1}})
65 | set(val 1) # sanitized TRUE boolean
66 | else()
67 | set(val 0) # sanitized FALSE boolean
68 | endif()
69 |
70 | set_target_properties(${target} PROPERTIES "${ARGV${i}}" ${val})
71 | list(APPEND property_list "${ARGV${i}}")
72 | endforeach()
73 |
74 | # now we save the list of information in a special (global) cache variable
75 | set(varName _TargetInfoProps__${target}__info_props)
76 | # build a combined list if the global variable already defined
77 | set(property_list ${${varName}} ${property_list})
78 | list(REMOVE_DUPLICATES property_list)
79 | set(${varName} ${property_list} CACHE INTERNAL "list of info props" FORCE)
80 | endfunction()
81 |
82 | # returns info properties in format that is embedded into output-config files.
83 | # valid export_format choices include:
84 | # - PKG_CONFIG (in this case the string declares module variables)
85 | # - CMAKE_CONFIG (in this case the string is put into set_target_properties)
86 | function(get_info_properties_export_str target export_format out_varname)
87 |
88 | set(varName _TargetInfoProps__${target}__info_props)
89 | if(NOT DEFINED CACHE{${varName}})
90 | message(FATAL_ERROR "No registered info properties for ${target}")
91 | elseif("${export_format}" STREQUAL "PKG_CONFIG")
92 | set(separator "=")
93 | elseif("${export_format}" STREQUAL "CMAKE_CONFIG")
94 | set(separator " ")
95 | else()
96 | message(FATAL_ERROR "export_format must be PKG_CONFIG or CMAKE_CONFIG")
97 | endif()
98 |
99 | set(output "")
100 | foreach(property_name IN LISTS "${varName}")
101 | get_target_property(val ${target} ${property_name})
102 | string(APPEND output "${property_name}${separator}${val}\n")
103 | endforeach()
104 | set(${out_varname} "${output}" PARENT_SCOPE)
105 |
106 | endfunction()
107 |
--------------------------------------------------------------------------------
/cmake/grackle.pc.in:
--------------------------------------------------------------------------------
1 | # DESCRIPTION
2 | # -----------
3 | #
4 | # This file can be used with pkg-config or pkgconf to help link against grackle
5 | #
6 | # There are essentially 2 versions of this file:
7 | # 1. The first version is intended for any installation that provides Grackle
8 | # as a shared library (including installations that provide it as both a
9 | # shared and a static library).
10 | # 2. The second version is intended for inclusion in an installation that
11 | # that ONLY provides Grackle as a static library.
12 | #
13 | # Most projects ONLY provide a version of the first kind.
14 | #
15 | # We provide both versions so that the build-system of a downstream
16 | # application can directly use
17 | # - the compiler flags returned by ``pkg-config --cflags grackle``
18 | # - the linker flags returned by ``pkg-config --libs grackle``
19 | # to consume Grackle without worrying about how exactly Grackle was installed
20 | # (the caller may need to specify PKG_CONFIG_PATH)
21 | #
22 | # When the first version of this file is consumed provided in an installation
23 | # that provides Grackle as both a shared and static library, you can access
24 | # static-library-specific by invoking pkg-config with the ``--static`` flag. As
25 | # discussed in the Grackle documentation, there are some challenges with
26 | # static-linking in that particular scenario.
27 |
28 |
29 | # The ${pcfiledir} variable is a feature of pkg-config & pkgconf that is
30 | # commonly used to make the build relocatable (there's not a ton of docs on it)
31 |
32 | prefix=${pcfiledir}/../..
33 | libdir=${prefix}/lib
34 | includedir=${prefix}/include
35 |
36 | # define Grackle-specific variables conveying extra information
37 | @_PC_INFO_PROPERTIES@
38 |
39 | Name: grackle
40 | Description: chemistry and radiative cooling library for astrophysical simulations and models
41 | Version: @Grackle_VERSION@
42 | URL: https://github.com/grackle-project/grackle
43 | Cflags: -I${includedir}
44 | Libs: -L${libdir} -lgrackle@_PC_EXTRA_LIBS@
45 | @_PC_LIBS_PRIVATE_ENTRY@
46 | @_PC_REQUIRES_ENTRY@
47 |
48 | # This file may be generated with or without Requires.private (it should be
49 | # configured so that it works properly in either case)
50 | # - unfortunately, when we use Requires.private, it ends up introducing extra
51 | # flags when compiling a shared library (and unnecessary Cflags when
52 | # compiling a static library)... It's probably ok, just ugly
53 |
54 | @_PC_REQUIRES_PRIVATE_ENTRY@
55 |
--------------------------------------------------------------------------------
/config/tacc-frontera-intel.cmake:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | # Provides host-file settings for frontera using the intel compilers
3 | #
4 | # About host-files:
5 | # - a host-file provides machine-specific configuration options to help compile
6 | # Grackle as a standalone library on common HPC platforms. They should not
7 | # generally be used when Grackle is embedded within the build of another
8 | # cmake project.
9 | #
10 | # - These mostly exist for convenience and parity with the machine-files used
11 | # by the classic build-system. They are most useful on HPC systems that
12 | # provide multiple compiler toolchains. (They usually aren't needed on local
13 | # systems)
14 | #
15 | # - In terms of modern, idiomatic CMake features, a host-file could be
16 | # replaced by a combination of a toolchain-file and a preset-file
17 | # -> toolchain files usually define compiler-toolchain related-options and
18 | # are commonly used for cross-compiling. Rule of thumb: you should be able
19 | # to recycle toolchain-files between unrelated projects (i.e. they don't
20 | # include project-specific variables).
21 | # -> a preset file (``CMakePresets.json`` and ``CMakeUserPresets.json``) are
22 | # intended to be used to specify common project-specific compilation
23 | # options. These can be read by IDEs.
24 | # -> after we update the minimum required CMake version for compiling Grackle
25 | # to at least 3.19, we may transition to using these features.
26 | #
27 | # All configuration options specified in this file should use CMake's ``set``
28 | # command with the ``CACHE`` option.
29 | #=======================================================================
30 |
31 |
32 | #-----------------------------------------------------------------------
33 | # Specify Compilers:
34 | #-----------------------------------------------------------------------
35 | set(CMAKE_CXX_COMPILER icpc CACHE STRING "")
36 | set(CMAKE_C_COMPILER icc CACHE STRING "")
37 | set(CMAKE_Fortran_COMPILER ifort CACHE STRING "")
38 |
39 |
40 | #-----------------------------------------------------------------------
41 | # Optimization Compiler Options:
42 | # -> these should really be machine-specific
43 | # -> these flags won't be used in debug-builds
44 | # -> See the installation documentation for more details on this topic
45 | # (including how to properly quote groups of variables)
46 | #-----------------------------------------------------------------------
47 | # The Frontera User Guide recommends the following flag for their Cascade Lake
48 | # (CLX) Compute Nodes
49 | set(GRACKLE_OPTIMIZATION_FLIST_INIT "-xCORE-AVX512" CACHE STRING "")
50 |
51 | #-----------------------------------------------------------------------
52 | # Other Options:
53 | # -> on certain platforms, if HDF5 is found in an extremely atypical spot, you
54 | # you might place that hint here
55 | # -> If you find that you NEED to configure other options in order to get
56 | # Grackle to successfully compile (e.g. a fortran flag to tell the compiler
57 | # how to handle Grackle's Fortran dialect), please open an issue on GitHub.
58 | # These sort of issues should be handled by logic executed in Grackle's
59 | # CMakeLists.txt files so that we don't duplicate this kind of logic across
60 | # host-files of different machines (and so that Grackle can be embedded
61 | # within other CMake projects)
62 | #-----------------------------------------------------------------------
63 |
64 | # the following frontera-specific snippet is only included for the sake of
65 | # example (it definitely isn't required)
66 | # Here we provide a hint about where to find hdf5 (cmake is usually smart
67 | # enough that it can find it without the hint). When you execute
68 | # module spider hdf5/1.x.y
69 | # The output informs us that loading that lmod-module will define the
70 | # TACC_HDF5_DIR environment variable, which specifies the location
71 | # of the module's hdf5 installation. Here, we're telling CMake that it MUST
72 | # use this particular installation
73 | set(HDF5_ROOT "$ENV{TACC_HDF5_DIR}" CACHE STRING
74 | "HDF5 install-location based on the loaded hdf5-module during configuration")
75 |
--------------------------------------------------------------------------------
/configure:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Create empty src/*/DEPEND files. These files are currently required
4 | # by make, but should not be stored in the subversion repository.
5 | # This is because the DEPEND files will change later, and the contents
6 | # will be machine-dependent.
7 |
8 | EXECS=(clib)
9 |
10 | for exec in ${EXECS[*]}
11 | do
12 |
13 | depend_file=src/$exec/DEPEND
14 |
15 | rm -f $depend_file
16 | touch $depend_file
17 |
18 | done
19 |
20 | # Create empty src/clib/Make.config.override file. This file is
21 | # required by make, but should not be stored in the subversion
22 | # repository. This is because the file will change later, and the
23 | # contents will be configuration-dependent.
24 |
25 | rm -f src/clib/Make.config.override
26 | touch src/clib/Make.config.override
27 |
28 | # Initialize the Make.config.machine file if it does not exist
29 | # Leave alone if it does exist
30 |
31 | if [ ! -e src/clib/Make.config.machine ]
32 | then
33 | echo "CONFIG_MACHINE = unknown" > src/clib/Make.config.machine
34 | fi
35 |
36 | echo "Configure complete."
37 |
--------------------------------------------------------------------------------
/dependencies.cmake:
--------------------------------------------------------------------------------
1 | # Handle external dependencies
2 | # -> locate all existing prebuilt dependencies
3 | # -> prepare other dependencies that must be built from source
4 |
5 | if (GRACKLE_BUILD_TESTS) # deal with testing dependencies
6 |
7 | # the only testing dependency is googletest. If we can't find a pre-installed
8 | # version of the library, we will fetch it and build from source
9 | find_package(GTest)
10 |
11 | if (NOT GTest_FOUND)
12 | message(STATUS
13 | "GTest not found. Fetching via FetchContent and configuring its build"
14 | )
15 |
16 | # NOTE: it is idiomatic to use FetchContent with a git hash rather than the
17 | # name of a tag or branch (since the latter 2 can freely change). If we use
18 | # the name of a tag/branch, then CMake will query GitHub on every
19 | # subsequent build to check whether the tag/branch is still the same
20 |
21 | include(FetchContent)
22 | FetchContent_Declare(
23 | googletest # the url contains the hash for v1.15.2
24 | URL https://github.com/google/googletest/archive/b514bdc898e2951020cbdca1304b75f5950d1f59.zip
25 | )
26 |
27 | # Tell GoogleTest's build-system not to define installation rules (since we
28 | # only use it to run tests from the build-directory)
29 | set(INSTALL_GTEST OFF)
30 | # For Windows: Prevent overriding the parent project's compiler/linker settings
31 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
32 | FetchContent_MakeAvailable(googletest)
33 |
34 | elseif("${CMAKE_VERSION}" VERSION_LESS "3.20")
35 | # CMake's built-in `FindGTest` module imported targets have different names
36 | # in earlier CMake versions
37 | add_library(GTest::gtest ALIAS GTest::GTest)
38 | add_library(GTest::gtest_main ALIAS GTest::Main)
39 | endif()
40 |
41 | if (NOT TARGET GTest::gtest_main)
42 | message("Target GTest:: stuff MISSING")
43 | endif()
44 | endif() # GRACKLE_BUILD_TESTS
45 |
46 | # find all of the other dependencies
47 | # -> we expect the caller of the build to make these available to us in one
48 | # form or another
49 |
50 | find_package(HDF5 REQUIRED COMPONENTS C)
51 | add_library(GRACKLE_HDF5_C INTERFACE IMPORTED)
52 | target_link_libraries(GRACKLE_HDF5_C INTERFACE ${HDF5_C_LIBRARIES})
53 | target_include_directories(GRACKLE_HDF5_C INTERFACE ${HDF5_C_INCLUDE_DIRS})
54 | target_compile_definitions(GRACKLE_HDF5_C INTERFACE ${HDF5_C_DEFINITIONS})
55 | if (HDF5_VERSION VERSION_LESS "1.6")
56 | message(FATAL_ERROR "HDF5 version 1.6 or newer is required")
57 | elseif(HDF5_VERSION VERSION_GREATER "1.6")
58 | target_compile_definitions(GRACKLE_HDF5_C INTERFACE -DH5_USE_16_API)
59 | endif()
60 |
61 | if (GRACKLE_USE_OPENMP)
62 | if (CMAKE_GENERATOR STREQUAL "Ninja")
63 | message(WARNING
64 | "using Ninja with GRACKLE_USE_OPENMP=ON may cause compilation problems."
65 | "The issues manifest as error with finding the \"omp_lib.h\" header "
66 | "that is conditionally included by some Fortran source files when using "
67 | "CMake. The quick fix is use Makefiles. See the docs for more info"
68 | )
69 | endif()
70 |
71 | if(GRACKLE_EXAMPLES)
72 | set(_GRACKLE_OMP_COMPONENTS C Fortran CXX)
73 | else()
74 | set(_GRACKLE_OMP_COMPONENTS C Fortran)
75 | endif()
76 | find_package(OpenMP REQUIRED COMPONENTS ${_GRACKLE_OMP_COMPONENTS})
77 | endif()
78 |
79 | # define target to link the math functions of the C standard library
80 | # (i.e. the -lm flag). This is commonly needed on unix-like platforms
81 | # -> For platforms that don't need libm, this target acts as a dummy
82 | # placeholder (that does nothing)
83 | # -> The -lm flag should NOT be used on MacOS (while CMake is smart enough to
84 | # not pass it to the linker, it will mess with exporting linker flags)
85 | #
86 | # NOTE: when we start using C++ in the core grackle library, we can remove
87 | # everything related to the toolchain::m variable (since the C++ runtime
88 | # library is ALWAYS linked to the math functions)
89 | add_library(toolchain::m INTERFACE IMPORTED)
90 | if (UNIX AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
91 | set_target_properties(toolchain::m PROPERTIES IMPORTED_LIBNAME "m")
92 | endif()
93 |
--------------------------------------------------------------------------------
/doc/README:
--------------------------------------------------------------------------------
1 | Grackle Documentation README
2 |
3 | This documentation is available online at: grackle.readthedocs.io
4 |
5 | In this directory and below are the Grackle documentation. They are written
6 | using the ReST [1] formatting, which is parsed into final formats using the
7 | Sphinx formatting engine [2].
8 |
9 | Here are some benefits of using ReST + Sphinx:
10 |
11 | - ReST is very readable in its raw form. It has minimal mark-up
12 | and is in plain text.
13 | - Now that the documents are included in the Grackle mecurial repository,
14 | wherever you are (Plane, Train, Automobile), all the documents are there
15 | without needing access to the internet.
16 | - Sphinx can parse the documents into many convenient formats, most notably HTML
17 | and a PDF.
18 |
19 | Building the documentation requires Sphinx. The easiest thing to do is to
20 | install the yt simulation analysis toolkit, available at yt-project.org.
21 | With that, simply type:
22 |
23 | pip install sphinx
24 |
25 | With Sphinx installed, build the documentation by typing the following in the
26 | doc directory:
27 |
28 | make html
29 |
30 | This will build html documentation in the build/html directory which is
31 | viewable with a web browser.
32 |
33 | [1] http://docutils.sourceforge.net/rst.html
34 | [2] http://sphinx.pocoo.org/
35 |
--------------------------------------------------------------------------------
/doc/source/Changelog.rst:
--------------------------------------------------------------------------------
1 | Changelog
2 | =========
3 |
4 | .. literalinclude:: ../../CHANGELOG
5 | :language: none
6 |
--------------------------------------------------------------------------------
/doc/source/Citing.rst:
--------------------------------------------------------------------------------
1 | .. _citing:
2 |
3 | .. include:: ../../CITATION.rst
4 |
--------------------------------------------------------------------------------
/doc/source/Conduct.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _conduct:
3 |
4 | Grackle Community Code of Conduct
5 | =================================
6 |
7 | The community of participants in open source scientific projects is
8 | made up of members from around the globe with a diverse set of skills,
9 | personalities, and experiences. It is through these differences that
10 | our community experiences success and continued growth. We expect
11 | everyone in our community to follow these guidelines when interacting
12 | with others both inside and outside of our community. Our goal is to
13 | keep ours a positive, inclusive, successful, and growing community.
14 |
15 | As members of the community,
16 |
17 | - We pledge to treat all people with respect and provide a harassment-
18 | and bullying-free environment, regardless of sex, sexual orientation
19 | and/or gender identity, disability, physical appearance, body size,
20 | race, nationality, ethnicity, and religion. In particular, sexual
21 | language and imagery, sexist, racist, or otherwise exclusionary jokes
22 | are not appropriate.
23 |
24 | - We pledge to respect the work of others by recognizing
25 | acknowledgment/citation requests of original authors. As authors, we
26 | pledge to be explicit about how we want our own work to be cited or
27 | acknowledged.
28 |
29 | - We pledge to welcome those interested in joining the community, and
30 | realize that including people with a variety of opinions and
31 | backgrounds will only serve to enrich our community. In particular,
32 | discussions relating to pros/cons of various technologies, programming
33 | languages, and so on are welcome, but these should be done with
34 | respect, taking proactive measure to ensure that all participants are
35 | heard and feel confident that they can freely express their opinions.
36 |
37 | - We pledge to welcome questions and answer them respectfully, paying
38 | particular attention to those new to the community. We pledge to
39 | provide respectful criticisms and feedback in forums, especially in
40 | discussion threads resulting from code contributions.
41 |
42 | - We pledge to be conscientious of the perceptions of the wider
43 | community and to respond to criticism respectfully. We will strive to
44 | model behaviors that encourage productive debate and disagreement,
45 | both within our community and where we are criticized. We will treat
46 | those outside our community with the same respect as people within our
47 | community.
48 |
49 | - We pledge to help the entire community follow the code of conduct,
50 | and to not remain silent when we see violations of the code of
51 | conduct. We will take action when members of our community violate
52 | this code such as contacting grackle.confidential@gmail.com (all emails
53 | sent to this address will be treated with the strictest confidence) or
54 | talking privately with the person.
55 |
56 | This code of conduct applies to all community situations online and
57 | offline, including mailing lists, forums, social media, conferences,
58 | meetings, associated social events, and one-to-one interactions.
59 |
60 | The Grackle Community Code of Conduct was adapted from the `Astropy
61 | Community Code of Conduct
62 | `_, which was
63 | partially inspired by the PSF code of conduct.
64 |
--------------------------------------------------------------------------------
/doc/source/Help.rst:
--------------------------------------------------------------------------------
1 | Help
2 | ----
3 |
4 | Mailing List
5 | ~~~~~~~~~~~~
6 |
7 | If you have any questions, please join the `Grackle Users Google Group
8 | `_. Feel
9 | free to post any questions or ideas for development.
10 |
11 | Slack Channel
12 | ~~~~~~~~~~~~~
13 |
14 | We also use `Slack `__ for lower latency discussions.
15 | If you'd like help in real time, this is the place.
16 | Click `here
17 | `__
18 | for an invitation to our Slack channel.
19 |
20 | GitHub Issues
21 | ~~~~~~~~~~~~~
22 |
23 | Alternatively you can describe issues or get help or post ideas for development by openning a `GitHub Issue `__
24 |
--------------------------------------------------------------------------------
/doc/source/_images/cooling_cell.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grackle-project/grackle/bfe0476d8171ce4707b87c5891b0a4ac09bb1d94/doc/source/_images/cooling_cell.png
--------------------------------------------------------------------------------
/doc/source/_images/cooling_rate.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grackle-project/grackle/bfe0476d8171ce4707b87c5891b0a4ac09bb1d94/doc/source/_images/cooling_rate.png
--------------------------------------------------------------------------------
/doc/source/_images/freefall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grackle-project/grackle/bfe0476d8171ce4707b87c5891b0a4ac09bb1d94/doc/source/_images/freefall.png
--------------------------------------------------------------------------------
/doc/source/_images/ramp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grackle-project/grackle/bfe0476d8171ce4707b87c5891b0a4ac09bb1d94/doc/source/_images/ramp.png
--------------------------------------------------------------------------------
/doc/source/testing_snippets/generate.rst:
--------------------------------------------------------------------------------
1 | .. code-block:: shell-session
2 |
3 | ~/grackle $ py.test --answer-dir=./my_test_answers --answer-store
4 |
5 | Each answer-test executed by this command reports that it has "passed" as long as it is able successfully store the result.
6 | The output will look like the following:
7 |
8 | .. code-block:: shell-session
9 |
10 | ============================= test session starts ==============================
11 | platform darwin -- Python 3.11.9, pytest-8.2.1, pluggy-1.5.0
12 | rootdir: /Users/britton/Documents/work/research/simulation/grackle/grackle-git/src/python
13 | configfile: pyproject.toml
14 | testpaths: src/python/tests
15 | plugins: cov-5.0.0
16 | collected 62 items
17 |
18 | src/python/tests/test_chemistry.py .... [ 6%]
19 | src/python/tests/test_chemistry_struct_synched.py . [ 8%]
20 | src/python/tests/test_dynamic_api.py ... [ 12%]
21 | src/python/tests/test_get_grackle_version.py . [ 14%]
22 | src/python/tests/test_initialisation.py . [ 16%]
23 | src/python/tests/test_local_functions.py . [ 17%]
24 | src/python/tests/test_models.py ....................................... [ 80%]
25 | src/python/tests/test_primordial.py . [ 82%]
26 | src/python/tests/test_query_units.py ... [ 87%]
27 | src/python/tests/test_specific_heating_rate.py .... [ 93%]
28 | src/python/tests/test_volumetric_heating_rate.py .... [100%]
29 |
30 | ======================== 62 passed in 95.46s (0:01:35) =========================
31 |
32 |
--------------------------------------------------------------------------------
/input:
--------------------------------------------------------------------------------
1 | grackle_data_files/input
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | # NOTE: scikit-build-core doesn't use the root-level CMakeLists.txt file,
2 | # instead we have it use src/python/CMakeLists.txt.
3 | #
4 | # There are 2 reasons for placing this at the root-level directory
5 | # (rather than in src/python):
6 | # 1. it ensures that the source-distribution of our source-directory and the
7 | # SDist we'll eventually distribute via PyPI will have the same structure
8 | # 2. it ensures that pygrackle can be installable by invoking
9 | # pip install pygrackle @ git+https://github.com/grackle-project/grackle
10 |
11 | [build-system]
12 | requires=[
13 | "cython",
14 | "cython-cmake>=0.2",
15 | # since tool.scikit-build.minimum-version is set to "build-system.requires",
16 | # the minimum build-requirement for scikit-build-core controls some default
17 | # behaviors when newer versions of scikit-build-core are installed
18 | # (we should keep an eye on this and keep increasing it over time)
19 | "scikit-build-core>=0.10"
20 | ]
21 | build-backend = "scikit_build_core.build"
22 |
23 | [project]
24 | name = "pygrackle"
25 | description = "A wrapper for the Grackle chemistry library"
26 | # A simpler project could infer used to infer the version number from git:
27 | # https://scikit-build-core.readthedocs.io/en/latest/configuration.html#dynamic-metadata
28 | # but pygrackle can't (currently) do this since it lives in a "monorepo"
29 | # https://github.com/pypa/setuptools_scm/issues/1056
30 | version = "1.1.1.dev0"
31 | classifiers=[
32 | "Development Status :: 5 - Production/Stable",
33 | "Environment :: Console",
34 | "Intended Audience :: Science/Research",
35 | "Topic :: Scientific/Engineering :: Astronomy",
36 | "License :: OSI Approved :: BSD License",
37 | "Operating System :: MacOS :: MacOS X",
38 | "Operating System :: POSIX :: Linux",
39 | "Operating System :: Unix",
40 | "Natural Language :: English",
41 | "Programming Language :: Python :: 3.8",
42 | "Programming Language :: Python :: 3.9",
43 | "Programming Language :: Python :: 3.10",
44 | "Programming Language :: Python :: 3.11",
45 | ]
46 | keywords=[
47 | "simulation", "chemistry", "cooling", "astronomy", "astrophysics"
48 | ]
49 | requires-python = ">=3.7"
50 | dependencies = [
51 | 'h5py',
52 | 'numpy',
53 | 'matplotlib',
54 | 'yt>=4.0.2'
55 | ]
56 |
57 | [project.license]
58 | text = "BSD 3-Clause"
59 |
60 | [project.urls]
61 | Homepage = 'https://github.com/grackle-project/grackle'
62 | Documentation = 'https://grackle.readthedocs.io/'
63 | Source = 'https://github.com/grackle-project/grackle'
64 | Tracker = 'https://github.com/grackle-project/grackle/issues'
65 |
66 | [project.optional-dependencies]
67 | # currently the next line duplicates the dependency-groups purely for
68 | # historical reasons. We should delete the following entry in the near-future
69 | # (since they are actually dependencies of the pygrackle-wheel).
70 | dev = ['flake8', 'packaging', 'pytest', 'sphinx', 'sphinx-tabs', 'furo']
71 |
72 | [dependency-groups]
73 | docs = ['sphinx', 'sphinx-tabs', 'furo']
74 | test = ['pytest', 'packaging']
75 | dev = ['flake8', {include-group = "docs"}, {include-group = 'test'}]
76 |
77 | [tool.pytest.ini_options]
78 | # settings inspired by: learn.scientific-python.org/development/guides/pytest/
79 | # -ra: The -r tells pytest to report extra test summary info on the events
80 | # corresponding to all characters following the r. Here, the "a"
81 | # corresponds to "all" events (other than passing tests)
82 | # --showlocals: directs pytest to show local variables in tracebacks
83 | # --strict-markers: ensures we don't try to use an unspecified fixture
84 | # --string-config: all configuration mistakes are reported as errors
85 | addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
86 | # by default, we treat any test marked xfail that doesn't fail as an error
87 | # (we can override this locally, if necessary)
88 | xfail_strict = true
89 | # limit the directories searched by pytests for the test files
90 | testpaths = [
91 | "src/python/tests",
92 | ]
93 |
94 |
95 | [tool.scikit-build]
96 | # redirect to the appropriate CMakeLists.txt file
97 | cmake.source-dir = "./src/python"
98 |
99 | # if the version of CMake (in {cmake.source-dir}/CMakeLists.txt) isn't found,
100 | # scikit-build-core will download and use a compatible CMake-verison
101 | cmake.version = "CMakeLists.txt"
102 |
103 | # The build type to use when building the project. Valid options are: "Debug",
104 | # "Release", "RelWithDebInfo", "MinSizeRel", "", etc.
105 | cmake.build-type = "Release"
106 |
107 | # since this is set, this provides a method for backward compatibility.
108 | minimum-version = "build-system.requires"
109 |
110 | # The following are all packaging-related and may require tweaking
111 |
112 | # Files to exclude from the SDist (even if they're included by default).
113 | # Supports gitignore syntax.
114 | sdist.exclude = [".circleci",".readthedocs.yml"]
115 |
116 | # A list of packages to auto-copy into the wheel.
117 | wheel.packages = ["./src/python/pygrackle"]
118 |
119 | # A set of patterns to exclude from the wheel. This is additive to the SDist
120 | # exclude patterns.
121 | wheel.exclude = [
122 | # Per the discussion in gh-220, we have decided not to package pyd files
123 | # (at least for right now)
124 | "**.pyd",
125 | # No need to package template files
126 | "**.py.in"
127 | ]
128 |
--------------------------------------------------------------------------------
/scripts/query_version.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import argparse
3 | import os
4 | import subprocess
5 |
6 |
7 | def get_last_line(path):
8 | last_line = None
9 | with open(path, "r") as f:
10 | for line in f:
11 | if len(line) > 0 and not line.isspace():
12 | last_line = line
13 | if last_line is None:
14 | raise ValueError("the {} file is empty".format(path))
15 | return last_line.rstrip()
16 |
17 |
18 | def query_version():
19 | return get_last_line(
20 | os.path.join(os.path.dirname(__file__), "..", "VERSION")
21 | )
22 |
23 |
24 | def _call(command, fallback_result=None, **kwargs):
25 | try:
26 | rslt = subprocess.check_output(command, shell=True, **kwargs)
27 | except (subprocess.CalledProcessError, OSError):
28 | return fallback_result
29 | return rslt.decode().rstrip() # return as str & remove any trailing '\n'
30 |
31 |
32 | def query_git(command):
33 | # historically, we queried whether git exists before executing a command.
34 | # However, on certain systems this doesn't seem to be adequate. Instead, we
35 | # just try to execute the command. If it fails, we fall back to "N/A"
36 | return _call(command, fallback_result="N/A")
37 |
38 |
39 | choices = {
40 | "show-version": query_version,
41 | "git-branch": lambda: query_git("git rev-parse --abbrev-ref HEAD"),
42 | "git-revision": lambda: query_git("git rev-parse HEAD"),
43 | }
44 |
45 | parser = argparse.ArgumentParser("query version information")
46 | parser.add_argument(
47 | "directive",
48 | choices=list(choices),
49 | help="specifies the information to check",
50 | )
51 |
52 | if __name__ == "__main__":
53 | args = parser.parse_args()
54 | result = choices[args.directive]()
55 | print(result)
56 |
--------------------------------------------------------------------------------
/src/clib/Make.config.objects:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.config.objects
4 | #
5 | # DESCRIPTION: Make include file defining OBJS_MAIN
6 | # (originally written by James Border for Enzo)
7 | #
8 | #=======================================================================
9 |
10 | #-----------------------------------------------------------------------
11 | # Default grackle object files
12 | #-----------------------------------------------------------------------
13 |
14 | OBJS_CONFIG_LIB = \
15 | $(AUTOGEN_DIR)/auto_general.lo \
16 | calculate_cooling_time.lo \
17 | calculate_dust_temperature.lo \
18 | calculate_gamma.lo \
19 | calculate_pressure.lo \
20 | calculate_temperature.lo \
21 | calc_temp1d_cloudy_g.lo \
22 | calc_temp_cloudy_g.lo \
23 | calc_tdust_1d_g.lo \
24 | calc_tdust_3d_g.lo \
25 | cool1d_cloudy_g.lo \
26 | cool1d_cloudy_old_tables_g.lo \
27 | cool1d_multi_g.lo \
28 | cool_multi_time_g.lo \
29 | dynamic_api.lo \
30 | grackle_units.lo \
31 | index_helper.lo \
32 | initialize_chemistry_data.lo \
33 | initialize_cloudy_data.lo \
34 | initialize_UVbackground_data.lo \
35 | interpolators_g.lo \
36 | set_default_chemistry_parameters.lo \
37 | solve_chemistry.lo \
38 | solve_rate_cool_g.lo \
39 | update_UVbackground_rates.lo \
40 | rate_functions.lo \
41 | initialize_rates.lo \
42 | utils.lo
--------------------------------------------------------------------------------
/src/clib/Make.config.settings:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.config.settings
4 | #
5 | # SUMMARY: This file contains all default compile-time configuration
6 | # settings and parameter values.
7 | # (originally written by James Border for Enzo)
8 | #
9 | # Configuration settings
10 | #
11 | # CONFIG_PRECISION
12 | # CONFIG_OPT
13 | #
14 | #=======================================================================
15 |
16 | #=======================================================================
17 | # CONFIG_PRECISION
18 | #=======================================================================
19 | # 32 use 32-bit precision for baryon field data
20 | # 64 use 64-bit precision for baryon field data
21 | #-----------------------------------------------------------------------
22 |
23 | CONFIG_PRECISION = 64
24 |
25 | #=======================================================================
26 | # CONFIG_OPT
27 | #=======================================================================
28 | # warn Write out verbose warnings when compiling
29 | # debug Compile for debugging
30 | # high Use conservative but high optimization
31 | # aggressive Use aggressive optimization
32 | #-----------------------------------------------------------------------
33 |
34 | CONFIG_OPT = high
35 |
36 | #=======================================================================
37 | # CONFIG_OMP
38 | #=======================================================================
39 | # on Enable OpenMP parallelization
40 | # off Disable OpenMP parallelization
41 | #-----------------------------------------------------------------------
42 |
43 | CONFIG_OMP = off
44 |
45 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.darwin:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.darwin
4 | #
5 | # DESCRIPTION: Makefile settings for macOS 11+
6 | # This was written to use:
7 | # HDF5 installed with Homebrew (https://brew.sh/)
8 | # gcc/g++/gfortran installed with Homebrew
9 | #
10 | # AUTHOR: Matthew Turk (mturk@slac.stanford.edu)
11 | # David Collins (dcollins4096@gmail.com)
12 | #
13 | # DATE: 2008-10-30
14 | #
15 | # Update: 2011-05-02
16 | # Default compilation in newer Xcode is now x86_64, rather than i386.
17 | # Updated fortran flags to reperesent change.
18 | # Changed suggested gfortran, hpc.sf.net version only build for i386.
19 | #
20 | # Update: 2021-04-08
21 | # (Ben Wibking) Use Homebrew instead of old versions of gfortran/gcc.
22 | #
23 | #=======================================================================
24 |
25 | MACH_TEXT = Darwin (macOS)
26 | MACH_VALID = 1
27 | MACH_FILE = Make.mach.darwin
28 |
29 | #-----------------------------------------------------------------------
30 | # Commands to run test executables
31 | #-----------------------------------------------------------------------
32 |
33 |
34 | #-----------------------------------------------------------------------
35 | # Install paths (local variables)
36 | #-----------------------------------------------------------------------
37 |
38 | LOCAL_PACKAGES = /usr/local
39 |
40 | LOCAL_FC_INSTALL = /usr/local/Cellar/gcc/10.2.0_4/lib/gcc/10
41 | LOCAL_HDF5_INSTALL = /usr/local/Cellar/hdf5/1.12.0_1
42 | LOCAL_SZIP_INSTALL = $(LOCAL_PACKAGES)
43 |
44 | #-----------------------------------------------------------------------
45 | # Compiler settings
46 | #-----------------------------------------------------------------------
47 |
48 | MACH_CPP = /usr/bin/cpp
49 |
50 | MACH_CC_NOMPI = gcc-10 # C compiler when not using MPI
51 | MACH_CXX_NOMPI = g++-10 # C++ compiler when not using MPI
52 | MACH_FC_NOMPI = gfortran # Fortran 77 compiler when not using MPI
53 | MACH_F90_NOMPI = gfortran # Fortran 90 compiler when not using MPI
54 | MACH_LD_NOMPI = gcc-10 # Linker when not using MPI
55 |
56 | MACH_LIBTOOL = glibtool
57 |
58 | #-----------------------------------------------------------------------
59 | # Machine-dependent defines
60 | #-----------------------------------------------------------------------
61 |
62 | # Note: When compiling against HDF5 version 1.8 or greater, you need to
63 | # compile HDF5 with --with-default-api-version=v16, or grackle with
64 | # -DH5_USE_16_API.
65 |
66 | MACH_DEFINES = -DLINUX -DH5_USE_16_API
67 |
68 | #-----------------------------------------------------------------------
69 | # Compiler flag settings
70 | #-----------------------------------------------------------------------
71 |
72 | MACH_OMPFLAGS = # OpenMP flags
73 | MACH_CPPFLAGS = -P -traditional
74 | MACH_CFLAGS =
75 | MACH_CXXFLAGS =
76 | MACH_FFLAGS = -fno-second-underscore -m64
77 | MACH_F90FLAGS = -fno-second-underscore -m64
78 | MACH_LDFLAGS =
79 |
80 | #-----------------------------------------------------------------------
81 | # Optimization flags
82 | #-----------------------------------------------------------------------
83 |
84 | MACH_OPT_WARN = -Wall -g
85 | MACH_OPT_DEBUG = -g
86 | MACH_OPT_HIGH = -O2
87 | MACH_OPT_AGGRESSIVE = -O3
88 |
89 | #-----------------------------------------------------------------------
90 | # Includes
91 | #-----------------------------------------------------------------------
92 |
93 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include
94 |
95 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
96 |
97 | #-----------------------------------------------------------------------
98 | # Libraries
99 | #-----------------------------------------------------------------------
100 |
101 | LOCAL_LIBS_MACH = -L$(LOCAL_FC_INSTALL) -lgfortran
102 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5
103 |
104 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
105 |
106 | #-----------------------------------------------------------------------
107 | # Installation
108 | #-----------------------------------------------------------------------
109 |
110 | MACH_INSTALL_PREFIX = $(HOME)/grackle_install
111 | MACH_INSTALL_LIB_DIR =
112 | MACH_INSTALL_INCLUDE_DIR =
--------------------------------------------------------------------------------
/src/clib/Make.mach.fedora:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.fedora
4 | #
5 | # DESCRIPTION: Makefile settings for a machine running Fedora
6 | #
7 | # AUTHOR: Shree Raj Shrestha (shree@actionproject.net)
8 | #
9 | # DATE: 2024-12-19
10 | #
11 | # This configuration assumes that build-essentials, gfortran
12 | # OpenMPI and HDF5 have been installed using dnf.
13 | #
14 | #=======================================================================
15 |
16 | MACH_TEXT = Use dnf to install hdf5-devel gfortran
17 | MACH_VALID = 1
18 | MACH_FILE = Make.mach.fedora
19 |
20 | #-----------------------------------------------------------------------
21 | # Install paths (local variables)
22 | #-----------------------------------------------------------------------
23 |
24 | #-----------------------------------------------------------------------
25 | # Compiler settings
26 | #-----------------------------------------------------------------------
27 |
28 | MACH_CC_NOMPI = gcc # C compiler
29 | MACH_CXX_NOMPI = g++ # C++ compiler
30 | MACH_FC_NOMPI = gfortran # Fortran 77
31 | MACH_F90_NOMPI = gfortran # Fortran 90
32 | MACH_LD_NOMPI = gcc # Linker
33 | MACH_LIBTOOL = libtool
34 |
35 | #-----------------------------------------------------------------------
36 | # Machine-dependent defines
37 | #-----------------------------------------------------------------------
38 |
39 | MACH_DEFINES = -DLINUX -DH5_USE_16_API -fPIC
40 |
41 | #-----------------------------------------------------------------------
42 | # Compiler flag settings
43 | #-----------------------------------------------------------------------
44 |
45 | MACH_OMPFLAGS = -fopenmp
46 | MACH_CPPFLAGS = -P -traditional
47 | MACH_CFLAGS =
48 | MACH_CXXFLAGS =
49 | MACH_FFLAGS = -fno-second-underscore -ffixed-line-length-132
50 | MACH_F90FLAGS = -fno-second-underscore
51 | MACH_LDFLAGS =
52 |
53 | #-----------------------------------------------------------------------
54 | # Optimization flags
55 | #-----------------------------------------------------------------------
56 |
57 | MACH_OPT_WARN = -Wall -g
58 | MACH_OPT_DEBUG = -g
59 | MACH_OPT_HIGH = -O2
60 | MACH_OPT_AGGRESSIVE = -O3 -g
61 |
62 | #-----------------------------------------------------------------------
63 | # Includes
64 | #-----------------------------------------------------------------------
65 |
66 | LOCAL_INCLUDES_HDF5 = -I/usr/include # HDF5 includes
67 |
68 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
69 |
70 | #-----------------------------------------------------------------------
71 | # Libraries
72 | #-----------------------------------------------------------------------
73 |
74 | LOCAL_LIBS_HDF5 = -L/usr/lib64/ -lz # HDF5 libraries
75 | LOCAL_LIBS_MACH = -lgfortran # Machine-dependent libraries
76 |
77 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
78 |
79 | #-----------------------------------------------------------------------
80 | # Installation
81 | #-----------------------------------------------------------------------
82 |
83 | MACH_INSTALL_PREFIX = $(HOME)/local
84 | MACH_INSTALL_LIB_DIR =
85 | MACH_INSTALL_INCLUDE_DIR =
86 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.linux-gnu:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.linux-gnu
4 | #
5 | # DESCRIPTION: Makefile settings for a machine running Ubuntu
6 | #
7 | # AUTHOR: Rick Wagner (rick@ucsd.edu)
8 | #
9 | # DATE: 2008-09-16
10 | #
11 | # This configuration assumes that build-essentials, gfortran, xutils-dev
12 | # OpenMPI and HDF5 have been installed using apt-get.
13 | #
14 | #=======================================================================
15 |
16 | MACH_TEXT = Use apt-get to install libhdf5-dev gfortran xutils-dev
17 | MACH_VALID = 1
18 | MACH_FILE = Make.mach.linux-gnu
19 |
20 | #-----------------------------------------------------------------------
21 | # Install paths (local variables)
22 | #-----------------------------------------------------------------------
23 |
24 | #-----------------------------------------------------------------------
25 | # Compiler settings
26 | #-----------------------------------------------------------------------
27 |
28 | MACH_CC_NOMPI = gcc # C compiler
29 | MACH_CXX_NOMPI = g++ # C++ compiler
30 | MACH_FC_NOMPI = gfortran # Fortran 77
31 | MACH_F90_NOMPI = gfortran # Fortran 90
32 | MACH_LD_NOMPI = gcc # Linker
33 | MACH_LIBTOOL = libtool
34 |
35 | #-----------------------------------------------------------------------
36 | # Machine-dependent defines
37 | #-----------------------------------------------------------------------
38 |
39 | MACH_DEFINES = -DLINUX -DH5_USE_16_API -fPIC
40 |
41 | #-----------------------------------------------------------------------
42 | # Compiler flag settings
43 | #-----------------------------------------------------------------------
44 |
45 | MACH_OMPFLAGS = -fopenmp
46 | MACH_CPPFLAGS = -P -traditional
47 | MACH_CFLAGS =
48 | MACH_CXXFLAGS =
49 | MACH_FFLAGS = -fno-second-underscore -ffixed-line-length-132
50 | MACH_F90FLAGS = -fno-second-underscore
51 | MACH_LDFLAGS =
52 |
53 | #-----------------------------------------------------------------------
54 | # Optimization flags
55 | #-----------------------------------------------------------------------
56 |
57 | MACH_OPT_WARN = -Wall -g
58 | MACH_OPT_DEBUG = -g
59 | MACH_OPT_HIGH = -O2
60 | MACH_OPT_AGGRESSIVE = -O3 -g
61 |
62 | #-----------------------------------------------------------------------
63 | # Includes
64 | #-----------------------------------------------------------------------
65 |
66 | LOCAL_INCLUDES_HDF5 = -I/usr/include/hdf5/serial # HDF5 includes
67 |
68 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
69 |
70 | #-----------------------------------------------------------------------
71 | # Libraries
72 | #-----------------------------------------------------------------------
73 |
74 | LOCAL_LIBS_HDF5 = -L/usr/lib/x86_64-linux-gnu/ -lhdf5_serial -lz # HDF5 libraries
75 | LOCAL_LIBS_MACH = -lgfortran # Machine-dependent libraries
76 |
77 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
78 |
79 | #-----------------------------------------------------------------------
80 | # Installation
81 | #-----------------------------------------------------------------------
82 |
83 | MACH_INSTALL_PREFIX = $(HOME)/local
84 | MACH_INSTALL_LIB_DIR =
85 | MACH_INSTALL_INCLUDE_DIR =
86 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.nasa-aitken-rome:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.nasa-aitken-rome
4 | #
5 | # DESCRIPTION: Makefile settings for NASA's Aikten Rome nodes
6 | #
7 | # modules: module use -a /nasa/modulefiles/testing
8 | # comp-intel/2020.4.304 and
9 | # hdf5/1.8.18_serial
10 | #
11 | #
12 | # AUTHOR: Molly Peeples
13 | # DATE: 2021-06-02
14 | #=======================================================================
15 |
16 | MACH_TEXT = NASA Aitken Rome
17 | MACH_VALID = 0
18 | MACH_FILE = Make.mach.nasa-aitken-rome
19 |
20 | MACHINE_NOTES = ""
21 |
22 | #-----------------------------------------------------------------------
23 | # Compiler settings
24 | #-----------------------------------------------------------------------
25 |
26 | MACH_CPP = icpc
27 | MACH_LIBTOOL = /usr/bin/libtool
28 |
29 | # Without MPI
30 |
31 | MACH_CC_NOMPI = icc
32 | MACH_CXX_NOMPI = icpc
33 | MACH_FC_NOMPI = ifort
34 | MACH_F90_NOMPI = ifort
35 | MACH_LD_NOMPI = icc
36 |
37 | #-----------------------------------------------------------------------
38 | # Install paths (local variables)
39 | #-----------------------------------------------------------------------
40 |
41 | LOCAL_HDF5_INSTALL = /nasa/modulefiles/sles15/hdf5/1.8.18_serial
42 | LOCAL_PYTHON_INSTALL = $(YT_DEST)
43 | LOCAL_COMPILER_DIR = /nasa/modulefiles/testing/comp-intel/2020.4.304
44 |
45 | #-----------------------------------------------------------------------
46 | # Machine-dependent defines
47 | #-----------------------------------------------------------------------
48 |
49 | MACH_DEFINES = -DLINUX -DH5_USE_16_API -fPIC
50 |
51 | #-----------------------------------------------------------------------
52 | # Compiler flag settings
53 | #-----------------------------------------------------------------------
54 |
55 | MACH_OMPFLAGS = # OpenMP flags
56 | MACH_CPPFLAGS = -P -traditional
57 | MACH_CFLAGS = -mp1 -prec_div -fp_port -align # C compiler flags
58 | MACH_CXXFLAGS = -mp1 -prec_div -fp_port -align # C++ compiler flags
59 | MACH_FFLAGS = # Fortran 77 compiler flags
60 | MACH_F90FLAGS = -mp1 -prec_div -fp_port -align -save -zero # Fortran 90 compiler flags
61 | MACH_LDFLAGS = -lifcore -lifport -lpthread -ldl # Linker flags
62 |
63 | #-----------------------------------------------------------------------
64 | # Optimization flags
65 | #-----------------------------------------------------------------------
66 |
67 | MACH_OPT_WARN =
68 | MACH_OPT_DEBUG = -g
69 | MACH_OPT_HIGH = -O2 -axAVX -xSSE4.1 -ip -ipo
70 | # use -xSSE4.2, if you're using Pleiades/Nehalem-EP cores
71 | MACH_OPT_AGGRESSIVE = -O3 -axAVX -ip -ipo
72 |
73 | #-----------------------------------------------------------------------
74 | # Includes
75 | #-----------------------------------------------------------------------
76 |
77 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include
78 |
79 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
80 |
81 | #-----------------------------------------------------------------------
82 | # Libraries
83 | #-----------------------------------------------------------------------
84 | #
85 |
86 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 -lz
87 | LOCAL_LIBS_FC = -L$(LOCAL_COMPILER_DIR)/lib/intel64
88 |
89 | LOCAL_LIBS_MACH = -L$(LOCAL_COMPILER_DIR)/lib/intel64 -lm -lifcore -lifport
90 |
91 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH) #$(LOCAL_LIBS_PYTHON)
92 |
93 | #-----------------------------------------------------------------------
94 | # Installation
95 | #-----------------------------------------------------------------------
96 |
97 | # if $(HOME)/local does not exist, mkdir before `make install`
98 |
99 | MACH_INSTALL_PREFIX = $(HOME)/local
100 | MACH_INSTALL_LIB_DIR =
101 | MACH_INSTALL_INCLUDE_DIR =
102 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.nasa-pleiades:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.nasa-pleiades
4 | #
5 | # DESCRIPTION: Makefile settings for NASA's pleiades
6 | #
7 | # modules: comp-intel/2020.4.304,
8 | # hdf5/1.8.18_serial
9 | #
10 | # AUTHOR: Nathan Goldbaum
11 | # DATE: 2014-04-24
12 | #
13 | #
14 | # MODIFIED: Molly Peeples
15 | # DATE: 2021-06-02
16 | #
17 | #=======================================================================
18 |
19 | MACH_TEXT = NASA Pleiades
20 | MACH_VALID = 0
21 | MACH_FILE = Make.mach.nasa-pleiades
22 |
23 | MACHINE_NOTES = "MACHINE_NOTES for Pleiades at NASA: \
24 | The following modules are needed to compile: \
25 | comp-intel/2020.4.304 and \
26 | hdf5/1.8.18_serial "
27 |
28 | #-----------------------------------------------------------------------
29 | # Compiler settings
30 | #-----------------------------------------------------------------------
31 |
32 | MACH_CPP = icpc
33 |
34 | # Without MPI
35 |
36 | MACH_CC_NOMPI = icc
37 | MACH_CXX_NOMPI = icpc
38 | MACH_FC_NOMPI = ifort
39 | MACH_F90_NOMPI = ifort
40 | MACH_LD_NOMPI = icc
41 |
42 | #-----------------------------------------------------------------------
43 | # Install paths (local variables)
44 | #-----------------------------------------------------------------------
45 |
46 | LOCAL_HDF5_INSTALL = /nasa/hdf5/1.8.18_serial
47 | LOCAL_PYTHON_INSTALL = $(YT_DEST)
48 | LOCAL_COMPILER_DIR = /nasa/intel/Compiler/2020.2.254/
49 |
50 | #-----------------------------------------------------------------------
51 | # Machine-dependent defines
52 | #-----------------------------------------------------------------------
53 |
54 | MACH_DEFINES = -DLINUX -DH5_USE_16_API -fPIC
55 |
56 | #-----------------------------------------------------------------------
57 | # Compiler flag settings
58 | #-----------------------------------------------------------------------
59 |
60 | MACH_LIBTOOL = /usr/bin/libtool
61 | MACH_OMPFLAGS = # OpenMP flags
62 | MACH_CPPFLAGS = -P -traditional
63 | MACH_CFLAGS = -mp1 -prec_div -fp_port -align # C compiler flags
64 | MACH_CXXFLAGS = -mp1 -prec_div -fp_port -align # C++ compiler flags
65 | MACH_FFLAGS = # Fortran 77 compiler flags
66 | MACH_F90FLAGS = -mp1 -prec_div -fp_port -align -save -zero # Fortran 90 compiler flags
67 | MACH_LDFLAGS = -lifcore -lifport -lpthread -ldl # Linker flags
68 |
69 | #-----------------------------------------------------------------------
70 | # Optimization flags
71 | #-----------------------------------------------------------------------
72 |
73 | MACH_OPT_WARN =
74 | MACH_OPT_DEBUG = -g
75 | MACH_OPT_HIGH = -O2 -axAVX -xSSE4.1 -ip -ipo
76 | # use -xSSE4.2, if you're using Pleiades/Nehalem-EP cores
77 | MACH_OPT_AGGRESSIVE = -O3 -axAVX -ip -ipo -xSSE4.1
78 |
79 | #-----------------------------------------------------------------------
80 | # Includes
81 | #-----------------------------------------------------------------------
82 |
83 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include
84 |
85 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
86 |
87 | #-----------------------------------------------------------------------
88 | # Libraries
89 | #-----------------------------------------------------------------------
90 | #
91 |
92 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 -lz
93 | LOCAL_LIBS_FC = -L$(LOCAL_COMPILER_DIR)/lib/intel64
94 |
95 | LOCAL_LIBS_MACH = -L$(LOCAL_COMPILER_DIR)/lib/intel64 -lm -lifcore -lifport
96 |
97 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH) #$(LOCAL_LIBS_PYTHON)
98 |
99 | #-----------------------------------------------------------------------
100 | # Installation
101 | #-----------------------------------------------------------------------
102 |
103 | # if $(HOME)/local does not exist, mkdir before `make install`
104 |
105 | MACH_INSTALL_PREFIX = $(HOME)/local
106 | MACH_INSTALL_LIB_DIR =
107 | MACH_INSTALL_INCLUDE_DIR =
108 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.ncsa-bluewaters-cray:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.ncsa-bluewaters-cray
4 | #
5 | # DESCRIPTION: Makefile settings for a machine running in BlueWater
6 | #
7 | # AUTHOR: Junwhan Choi
8 | #
9 | # DATE: 2014-07-26
10 | #
11 | # This uses gnu compilers and the cray-hdf5 module.
12 | # Note: requires module commands:
13 | # module load cray-hdf5
14 | #=======================================================================
15 |
16 | MACH_TEXT = Blue Waters with cray compilers. \
17 | Do this: module load cray-hdf5
18 | MACH_VALID = 1
19 | MACH_FILE = Make.mach.ncsa-bluewaters-cray
20 |
21 | #-----------------------------------------------------------------------
22 | # Install paths (local variables)
23 | #-----------------------------------------------------------------------
24 |
25 | LOCAL_HDF5_INSTALL = $(HDF5_ROOT)
26 |
27 | #-----------------------------------------------------------------------
28 | # Compiler settings
29 | #-----------------------------------------------------------------------
30 |
31 | MACH_CC_NOMPI = cc # C compiler
32 | MACH_CXX_NOMPI = CC # C++ compiler
33 | MACH_FC_NOMPI = ftn # Fortran 77
34 | MACH_F90_NOMPI = ftn # Fortran 90
35 | MACH_LD_NOMPI = cc # Linker
36 | MACH_LIBTOOL = libtool
37 |
38 | #-----------------------------------------------------------------------
39 | # Machine-dependent defines
40 | #-----------------------------------------------------------------------
41 |
42 | MACH_DEFINES = -DLINUX -DH5_USE_16_API -fPIC
43 |
44 | #-----------------------------------------------------------------------
45 | # Compiler flag settings
46 | #-----------------------------------------------------------------------
47 |
48 | MACH_OMPFLAGS = # OpenMP flags
49 | MACH_CPPFLAGS = -P -traditional
50 | MACH_CFLAGS =
51 | MACH_CXXFLAGS =
52 | MACH_FFLAGS =
53 | MACH_F90FLAGS =
54 | MACH_LDFLAGS =
55 |
56 | #-----------------------------------------------------------------------
57 | # Precision-related flags
58 | #-----------------------------------------------------------------------
59 |
60 | MACH_FFLAGS_INTEGER_32 =
61 | MACH_FFLAGS_INTEGER_64 = -s integer64
62 | MACH_FFLAGS_REAL_32 = -s real32 -s default64
63 | MACH_FFLAGS_REAL_64 = -s real64 -s default64
64 |
65 | #-----------------------------------------------------------------------
66 | # Optimization flags
67 | #-----------------------------------------------------------------------
68 |
69 | MACH_OPT_WARN = -Wall -g
70 | MACH_OPT_DEBUG = -g
71 | MACH_OPT_HIGH = -O2
72 | MACH_OPT_AGGRESSIVE = -O3 -g
73 |
74 | #-----------------------------------------------------------------------
75 | # Includes
76 | #-----------------------------------------------------------------------
77 |
78 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
79 |
80 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
81 |
82 | #-----------------------------------------------------------------------
83 | # Libraries
84 | #-----------------------------------------------------------------------
85 |
86 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 # HDF5 libraries
87 | LOCAL_LIBS_MACH =
88 |
89 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
90 |
91 | #-----------------------------------------------------------------------
92 | # Installation
93 | #-----------------------------------------------------------------------
94 |
95 | MACH_INSTALL_PREFIX = $(HOME)/local/cray
96 | MACH_INSTALL_LIB_DIR =
97 | MACH_INSTALL_INCLUDE_DIR =
98 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.ncsa-bluewaters-gnu:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.ncsa-bluewaters-gnu
4 | #
5 | # DESCRIPTION: Makefile settings for NCSA Blue Waters
6 | #
7 | # AUTHOR: Britton Smith
8 | #
9 | # DATE: 2016-04-16
10 | #
11 | # This uses gnu compilers and the cray-hdf5 module.
12 | # Note: requires module commands:
13 | # module swap PrgEnv-cray PrgEnv-gnu
14 | # module load cray-hdf5
15 | #=======================================================================
16 |
17 | MACH_TEXT = Blue Waters with gnu compilers. \
18 | Do this: module swap PrgEnv-cray PrgEnv-gnu ; module load cray-hdf5
19 | MACH_VALID = 1
20 | MACH_FILE = Make.mach.ncsa-bluewaters-gnu
21 |
22 | #-----------------------------------------------------------------------
23 | # Install paths (local variables)
24 | #-----------------------------------------------------------------------
25 |
26 | LOCAL_HDF5_INSTALL = $(HDF5_ROOT)
27 |
28 | #-----------------------------------------------------------------------
29 | # Compiler settings
30 | #-----------------------------------------------------------------------
31 |
32 | MACH_CC_NOMPI = cc # C compiler
33 | MACH_CXX_NOMPI = CC # C++ compiler
34 | MACH_FC_NOMPI = ftn # Fortran 77
35 | MACH_F90_NOMPI = ftn # Fortran 90
36 | MACH_LD_NOMPI = cc # Linker
37 | MACH_LIBTOOL = libtool
38 |
39 | #-----------------------------------------------------------------------
40 | # Machine-dependent defines
41 | #-----------------------------------------------------------------------
42 |
43 | MACH_DEFINES = -DLINUX -DH5_USE_16_API -fPIC
44 |
45 | #-----------------------------------------------------------------------
46 | # Compiler flag settings
47 | #-----------------------------------------------------------------------
48 |
49 | MACH_CPPFLAGS = -P -traditional
50 | MACH_CFLAGS =
51 | MACH_CXXFLAGS =
52 | MACH_FFLAGS =
53 | MACH_F90FLAGS =
54 | MACH_LDFLAGS =
55 |
56 | #-----------------------------------------------------------------------
57 | # Precision-related flags
58 | #-----------------------------------------------------------------------
59 |
60 | MACH_CPPFLAGS = -P -traditional
61 | MACH_CFLAGS =
62 | MACH_CXXFLAGS =
63 | MACH_FFLAGS = -fno-second-underscore -m64
64 | MACH_F90FLAGS = -fno-second-underscore -m64
65 | MACH_LDFLAGS =
66 |
67 | #-----------------------------------------------------------------------
68 | # Optimization flags
69 | #-----------------------------------------------------------------------
70 |
71 | MACH_OPT_WARN = -Wall -g
72 | MACH_OPT_DEBUG = -g
73 | MACH_OPT_HIGH = -O2
74 | MACH_OPT_AGGRESSIVE = -O3
75 |
76 | #-----------------------------------------------------------------------
77 | # Includes
78 | #-----------------------------------------------------------------------
79 |
80 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
81 |
82 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
83 |
84 | #-----------------------------------------------------------------------
85 | # Libraries
86 | #-----------------------------------------------------------------------
87 |
88 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 -lz # HDF5 libraries
89 | LOCAL_LIBS_MACH = -lgfortran
90 |
91 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
92 |
93 | #-----------------------------------------------------------------------
94 | # Installation
95 | #-----------------------------------------------------------------------
96 |
97 | MACH_INSTALL_PREFIX = $(HOME)/local
98 | MACH_INSTALL_LIB_DIR =
99 | MACH_INSTALL_INCLUDE_DIR =
100 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.summit:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.summit
4 | #
5 | # DESCRIPTION: Makefile settings for ORNL Summit
6 | #
7 | # AUTHOR: Bruno Villasenor (brvillas@ucsc.edu)
8 | #
9 | # DATE: 2019-03-15
10 | ##
11 | #=======================================================================
12 |
13 | MACH_TEXT = ORNL Summit
14 | MACH_VALID = 1
15 | MACH_FILE = Make.mach.linux-summit
16 |
17 | #-----------------------------------------------------------------------
18 | # Install paths (local variables)
19 | #-----------------------------------------------------------------------
20 |
21 | LOCAL_HDF5_INSTALL = $(OLCF_HDF5_ROOT)
22 |
23 | #-----------------------------------------------------------------------
24 | # Compiler settings
25 | #-----------------------------------------------------------------------
26 |
27 | MACH_CC_NOMPI = gcc # C compiler
28 | MACH_CXX_NOMPI = g++ # C++ compiler
29 | MACH_FC_NOMPI = gfortran # Fortran 77
30 | MACH_F90_NOMPI = gfortran # Fortran 90
31 | MACH_LD_NOMPI = gcc # Linker
32 | MACH_LIBTOOL = libtool
33 |
34 | #-----------------------------------------------------------------------
35 | # Machine-dependent defines
36 | #-----------------------------------------------------------------------
37 |
38 | MACH_DEFINES = -DLINUX -DH5_USE_16_API -fPIC
39 |
40 | #-----------------------------------------------------------------------
41 | # Compiler flag settings
42 | #-----------------------------------------------------------------------
43 |
44 | MACH_OMPFLAGS = -fopenmp
45 | MACH_CPPFLAGS = -P -traditional
46 | MACH_CFLAGS =
47 | MACH_CXXFLAGS =
48 | MACH_FFLAGS = -fno-second-underscore -ffixed-line-length-132
49 | MACH_F90FLAGS = -fno-second-underscore
50 | MACH_LDFLAGS =
51 |
52 | #-----------------------------------------------------------------------
53 | # Optimization flags
54 | #-----------------------------------------------------------------------
55 |
56 | MACH_OPT_WARN = -Wall -g
57 | MACH_OPT_DEBUG = -g
58 | MACH_OPT_HIGH = -O2
59 | MACH_OPT_AGGRESSIVE = -O3 -g
60 |
61 | #-----------------------------------------------------------------------
62 | # Includes
63 | #-----------------------------------------------------------------------
64 |
65 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
66 |
67 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
68 |
69 | #-----------------------------------------------------------------------
70 | # Libraries
71 | #-----------------------------------------------------------------------
72 |
73 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 -lz # HDF5 libraries
74 | LOCAL_LIBS_MACH = -lgfortran # Machine-dependent libraries
75 |
76 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
77 |
78 | #-----------------------------------------------------------------------
79 | # Installation
80 | #-----------------------------------------------------------------------
81 |
82 | MACH_INSTALL_PREFIX = $(HOME)/local
83 | MACH_INSTALL_LIB_DIR =
84 | MACH_INSTALL_INCLUDE_DIR =
--------------------------------------------------------------------------------
/src/clib/Make.mach.tacc-stampede-gnu:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.tacc-stampede-gnu
4 | #
5 | # DESCRIPTION: TACC Stampede Makefile
6 | # Written by Cameron Hummels, Jan 14
7 | # Edited by Gabriel Altay, Sept 14
8 | #
9 | # NOTES: Prepend the HDF5 lib directory to LD_LIBRARY_PATH for this to work
10 | # e.g. export LD_LIBRARY_PATH=$TACC_HDF5_DIR/lib:$LD_LIBRARY_PATH
11 | #=======================================================================
12 |
13 | MACH_TEXT = Stampede
14 | MACH_VALID = 0
15 | MACH_FILE = Make.mach.tacc-stampede-gnu
16 |
17 | #-----------------------------------------------------------------------
18 | # Compiler settings
19 | #-----------------------------------------------------------------------
20 |
21 | MACH_CPP = /usr/bin/cpp # C preprocessor command
22 |
23 | # Compilers
24 | MACH_CC_NOMPI = gcc # C compiler
25 | MACH_CXX_NOMPI = g++ # C++ compiler
26 | MACH_FC_NOMPI = gfortran # Fortran 77
27 | MACH_F90_NOMPI = gfortran # Fortran 90
28 | MACH_LD_NOMPI = gfortran # Linker
29 | MACH_LIBTOOL = libtool
30 |
31 | #-----------------------------------------------------------------------
32 | # Machine-dependent defines
33 | #-----------------------------------------------------------------------
34 |
35 | # Note: When compiling against HDF5 version 1.8 or greater, you need to
36 | # compile HDF5 with --with-default-api-version=v16, or specify with
37 | # -DH5_USE_16_API.
38 |
39 | MACH_DEFINES = -DLINUX -DH5_USE_16_API -fPIC # Defines for the architecture; e.g. -DSUN, -DLINUX, etc.
40 |
41 | #-----------------------------------------------------------------------
42 | # Compiler flag settings
43 | #-----------------------------------------------------------------------
44 |
45 | MACH_OMPFLAGS = # OpenMP flags
46 | MACH_CPPFLAGS = -P -traditional
47 | MACH_CFLAGS =
48 | MACH_CXXFLAGS =
49 | MACH_FFLAGS = -fno-second-underscore -ffixed-line-length-132
50 | MACH_F90FLAGS = -fno-second-underscore
51 | MACH_LDFLAGS = -lstdc++ -lc
52 |
53 | #-----------------------------------------------------------------------
54 | # Optimization flags
55 | #-----------------------------------------------------------------------
56 |
57 | MACH_OPT_WARN = -Wall -g
58 | MACH_OPT_DEBUG = -g
59 | MACH_OPT_HIGH = -O2
60 | MACH_OPT_AGGRESSIVE = -O3 -g
61 |
62 | #-----------------------------------------------------------------------
63 | # Includes
64 | #-----------------------------------------------------------------------
65 |
66 | LOCAL_HDF5_INSTALL = $(TACC_HDF5_DIR)
67 |
68 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
69 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
70 |
71 | #-----------------------------------------------------------------------
72 | # Libraries
73 | #-----------------------------------------------------------------------
74 |
75 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 # HDF5 libraries
76 | LOCAL_LIBS_MACH = -lm # Machine-dependent libraries
77 |
78 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
79 |
80 | #-----------------------------------------------------------------------
81 | # Installation
82 | #-----------------------------------------------------------------------
83 |
84 | # if $(HOME)/local does not exist, mkdir before `make install`
85 |
86 | MACH_INSTALL_PREFIX = $(HOME)/local
87 | MACH_INSTALL_LIB_DIR =
88 | MACH_INSTALL_INCLUDE_DIR =
89 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.tacc-stampede-intel:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.tacc-stampede-intel
4 | #
5 | # DESCRIPTION: TACC Stampede Makefile
6 | # Written by Cameron Hummels, Jan 14
7 | # Edited by Gabriel Altay, Sept 14
8 | #
9 | #=======================================================================
10 |
11 | MACH_TEXT = Stampede
12 | MACH_VALID = 0
13 | MACH_FILE = Make.mach.tacc-stampede-intel
14 |
15 | # Make sure to have the intel module loaded:
16 | # $ module load intel
17 |
18 | #-----------------------------------------------------------------------
19 | # Install paths (local variables)
20 | #-----------------------------------------------------------------------
21 |
22 | LOCAL_HDF5_INSTALL = $(TACC_HDF5_DIR)
23 | LOCAL_FC_INSTALL = $(TACC_INTEL_LIB)
24 |
25 | #-----------------------------------------------------------------------
26 | # Compiler settings
27 | #-----------------------------------------------------------------------
28 |
29 | MACH_CPP = /usr/bin/cpp # C preprocessor command
30 |
31 | # Compilers
32 | MACH_CC_NOMPI = icc # C compiler
33 | MACH_CXX_NOMPI = icpc # C++ compiler
34 | MACH_FC_NOMPI = ifort # Fortran 77
35 | MACH_F90_NOMPI = ifort # Fortran 90
36 | MACH_LD_NOMPI = icpc # Linker
37 | MACH_LIBTOOL = libtool
38 |
39 | #-----------------------------------------------------------------------
40 | # Machine-dependent defines
41 | #-----------------------------------------------------------------------
42 |
43 | # Note: When compiling against HDF5 version 1.8 or greater, you need to
44 | # compile HDF5 with --with-default-api-version=v16, or specify with
45 | # -DH5_USE_16_API.
46 |
47 | MACH_DEFINES = -DLINUX -DH5_USE_16_API
48 |
49 | #-----------------------------------------------------------------------
50 | # Compiler flag settings
51 | #-----------------------------------------------------------------------
52 |
53 | MACH_OMPFLAGS = # OpenMP flags
54 | MACH_CPPFLAGS = -P -traditional # C preprocessor flags
55 | MACH_CFLAGS = -mp1 -prec_div -fp_port -align # C compiler flags
56 | MACH_CXXFLAGS = -mp1 -prec_div -fp_port -align # C++ compiler flags
57 | MACH_FFLAGS = # Fortran 77 compiler flags
58 | MACH_F90FLAGS = -mp1 -prec_div -fp_port -align -save -zero # Fortran 90 compiler flags
59 | MACH_LDFLAGS = -lifcore -lifport -lpthread -ldl # Linker flags
60 |
61 | #-----------------------------------------------------------------------
62 | # Optimization flags
63 | #-----------------------------------------------------------------------
64 |
65 | MACH_OPT_WARN = # Flags for verbose compiler warnings
66 | MACH_OPT_DEBUG = -g -O0 # Flags for debugging
67 | MACH_OPT_HIGH = -O2 -xCORE-AVX2
68 | # use -xMIC-AVX512 (without -xCORE-AVX2) to build for KNL nodes
69 | # use -xCORE-AVX512 (without -xCORE-AVX2) to build for SKX nodes
70 | # use -xCORE-AVX2 -axCORE-AVX512,MIC-AVX512 to build a single binary for both
71 | # node types that dispatches optimal code path at execution
72 | MACH_OPT_AGGRESSIVE = -O3 -xCORE-AVX2 -Mfptrap -Mflushz -fastsse -Mdaz -Mnontemporal -Mnofprelaxed -Mvect=altcode,assoc,prefetch -Kieee # Flags for aggressive optimization
73 |
74 | #-----------------------------------------------------------------------
75 | # Includes
76 | #-----------------------------------------------------------------------
77 |
78 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
79 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
80 |
81 | #-----------------------------------------------------------------------
82 | # Libraries
83 | #-----------------------------------------------------------------------
84 |
85 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 # HDF5 libraries
86 | LOCAL_LIBS_MACH = -L$(LOCAL_FC_INSTALL) -lm -lifcore -lifport # Machine-dependent libraries
87 |
88 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
89 |
90 | #-----------------------------------------------------------------------
91 | # Installation
92 | #-----------------------------------------------------------------------
93 |
94 | # if $(HOME)/local does not exist, mkdir before `make install`
95 |
96 | MACH_INSTALL_PREFIX = $(HOME)/local
97 | MACH_INSTALL_LIB_DIR =
98 | MACH_INSTALL_INCLUDE_DIR =
99 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.tigercpu:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.tigercpu
4 | #
5 | # DESCRIPTION: Makefile settings for tigercpu at Princeton
6 | #
7 | # AUTHOR: He Jia (hejia@princeton.edu)
8 | #
9 | # DATE: 2020-08-31
10 | #
11 | #=======================================================================
12 |
13 | MACH_FILE = Make.mach.tigercpu
14 | MACH_TEXT = tigercpu
15 | MACH_VALID = 1
16 |
17 | # please load these modules:
18 | # module load intel/19.1/64/19.1.1.217 hdf5/intel-16.0/1.8.16
19 |
20 | #-----------------------------------------------------------------------
21 | # Install paths (local variables)
22 | #-----------------------------------------------------------------------
23 |
24 | LOCAL_HDF5_INSTALL = ${HDF5DIR}
25 |
26 | #-----------------------------------------------------------------------
27 | # Compiler settings
28 | #-----------------------------------------------------------------------
29 |
30 | MACH_CC_NOMPI = icc # C compiler when not using MPI
31 | MACH_CXX_NOMPI = icpc # C++ compiler when not using MPI
32 | MACH_FC_NOMPI = ifort # Fortran 77 compiler when not using MPI
33 | MACH_F90_NOMPI = ifort # Fortran 90 compiler when not using MPI
34 | MACH_LD_NOMPI = icpc # Linker when not using MPI
35 | MACH_LIBTOOL = libtool
36 |
37 | #-----------------------------------------------------------------------
38 | # Machine-dependent defines
39 | #-----------------------------------------------------------------------
40 |
41 | MACH_DEFINES = -DLINUX -DH5_USE_16_API
42 |
43 | #-----------------------------------------------------------------------
44 | # Compiler flag settings
45 | #-----------------------------------------------------------------------
46 |
47 | MACH_OMPFLAGS = -fopenmp
48 | MACH_CPPFLAGS = -P -traditional
49 | MACH_CFLAGS =
50 | MACH_CXXFLAGS =
51 | MACH_FFLAGS = -132
52 | MACH_F90FLAGS =
53 | MACH_LDFLAGS =
54 |
55 | #-----------------------------------------------------------------------
56 | # Optimization flags
57 | #-----------------------------------------------------------------------
58 |
59 | MACH_OPT_WARN = -Wall -g # Flags for verbose compiler warnings
60 | MACH_OPT_DEBUG = -O0 -g # Flags for debugging
61 | MACH_OPT_HIGH = -O2 -g -march=native # Flags for high conservative optimization
62 | MACH_OPT_AGGRESSIVE = -O3 -march=native # Flags for aggressive optimization
63 |
64 | #-----------------------------------------------------------------------
65 | # Includes
66 | #-----------------------------------------------------------------------
67 |
68 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
69 |
70 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
71 |
72 | #-----------------------------------------------------------------------
73 | # Libraries
74 | #-----------------------------------------------------------------------
75 |
76 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib64 -lhdf5 -lz # HDF5 libraries
77 | LOCAL_LIBS_MACH = -L$(LOCAL_COMPILER)/lib/intel64 -lcilkrts -lifcore -lifport # Machine-dependent libraries
78 |
79 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
80 |
81 | #-----------------------------------------------------------------------
82 | # Installation
83 | #-----------------------------------------------------------------------
84 |
85 | MACH_INSTALL_PREFIX = $(HOME)/grackle-build
86 | MACH_INSTALL_LIB_DIR =
87 | MACH_INSTALL_INCLUDE_DIR =
88 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.uiuc-campus-gnu:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.uiuc-campus-gnu
4 | #
5 | # DESCRIPTION: Makefile for the UIUC Campus cluster with GNU compiler
6 | # and OpenMP support
7 | #
8 | # AUTHOR: Hsi-Yu Schive
9 | #
10 | # DATE: April 1, 2016
11 | #=======================================================================
12 |
13 | MACH_TEXT = UIUC Campus GNU
14 | MACH_VALID = 0
15 | MACH_FILE = Make.mach.uiuc-campus-gnu
16 |
17 | #-----------------------------------------------------------------------
18 | # Install paths (local variables)
19 | #-----------------------------------------------------------------------
20 |
21 | LOCAL_HDF5_INSTALL = /projects/ncsa/grav/softwares/miniconda2
22 | LOCAL_FC_INSTALL = /usr/local/gcc-4.7.1/lib64
23 |
24 | #-----------------------------------------------------------------------
25 | # Compiler settings
26 | #-----------------------------------------------------------------------
27 |
28 | MACH_CPP = /usr/bin/cpp # C preprocessor command
29 |
30 | # Compilers
31 | MACH_CC_NOMPI = gcc # C compiler
32 | MACH_CXX_NOMPI = g++ # C++ compiler
33 | MACH_FC_NOMPI = gfortran # Fortran 77
34 | MACH_F90_NOMPI = gfortran # Fortran 90
35 | MACH_LD_NOMPI = gfortran # Linker
36 | MACH_LIBTOOL = libtool
37 |
38 | #-----------------------------------------------------------------------
39 | # Machine-dependent defines
40 | #-----------------------------------------------------------------------
41 |
42 | # Note: When compiling against HDF5 version 1.8 or greater, you need to
43 | # compile HDF5 with --with-default-api-version=v16, or specify with
44 | # -DH5_USE_16_API.
45 |
46 | MACH_DEFINES = -DLINUX -DH5_USE_16_API
47 |
48 | #-----------------------------------------------------------------------
49 | # Compiler flag settings
50 | #-----------------------------------------------------------------------
51 |
52 | MACH_OMPFLAGS = -fopenmp # OpenMP flags
53 | MACH_CPPFLAGS = -P -traditional # C preprocessor flags
54 | MACH_CFLAGS =
55 | MACH_CXXFLAGS =
56 | MACH_FFLAGS = -fno-second-underscore -ffixed-line-length-132
57 | MACH_F90FLAGS = -fno-second-underscore
58 | MACH_LDFLAGS = -lgfortran
59 |
60 |
61 | #-----------------------------------------------------------------------
62 | # Optimization flags
63 | #-----------------------------------------------------------------------
64 |
65 | MACH_OPT_WARN = # Flags for verbose compiler warnings
66 | MACH_OPT_DEBUG = -g -O0 # Flags for debugging
67 | MACH_OPT_HIGH = -O2 # Flags for high conservative optimization
68 | MACH_OPT_AGGRESSIVE = -O3 #-Mfptrap -Mflushz -fastsse -Mdaz -Mnontemporal -Mnofprelaxed -Mvect=altcode,assoc,prefetch -Kieee # Flags for aggressive optimization
69 |
70 | #-----------------------------------------------------------------------
71 | # Includes
72 | #-----------------------------------------------------------------------
73 |
74 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
75 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
76 |
77 | #-----------------------------------------------------------------------
78 | # Libraries
79 | #-----------------------------------------------------------------------
80 |
81 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 # HDF5 libraries
82 | LOCAL_LIBS_MACH = -L$(LOCAL_FC_INSTALL) -lm # Machine-dependent libraries
83 |
84 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
85 |
86 | #-----------------------------------------------------------------------
87 | # Installation
88 | #-----------------------------------------------------------------------
89 |
90 | # if $(HOME)/local does not exist, mkdir before `make install`
91 |
92 | MACH_INSTALL_PREFIX = $(HOME)/local
93 | MACH_INSTALL_LIB_DIR =
94 | MACH_INSTALL_INCLUDE_DIR =
95 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.uiuc-campus-intel:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.uiuc-campus-intel
4 | #
5 | # DESCRIPTION: Makefile for the UIUC Campus cluster with Intel compiler
6 | # and OpenMP support
7 | #
8 | # AUTHOR: Hsi-Yu Schive
9 | #
10 | # DATE: April 1, 2016
11 | #=======================================================================
12 |
13 | MACH_TEXT = UIUC Campus Intel
14 | MACH_VALID = 0
15 | MACH_FILE = Make.mach.uiuc-campus-intel
16 |
17 | #-----------------------------------------------------------------------
18 | # Install paths (local variables)
19 | #-----------------------------------------------------------------------
20 |
21 | LOCAL_HDF5_INSTALL = /projects/ncsa/grav/softwares/miniconda2
22 | LOCAL_FC_INSTALL = /usr/local/intel/intel-15.0/composerxe/lib/intel64
23 |
24 | #-----------------------------------------------------------------------
25 | # Compiler settings
26 | #-----------------------------------------------------------------------
27 |
28 | MACH_CPP = /usr/bin/cpp # C preprocessor command
29 |
30 | # Compilers
31 | MACH_CC_NOMPI = icc # C compiler
32 | MACH_CXX_NOMPI = icpc # C++ compiler
33 | MACH_FC_NOMPI = ifort # Fortran 77
34 | MACH_F90_NOMPI = ifort # Fortran 90
35 | MACH_LD_NOMPI = icpc # Linker
36 | MACH_LIBTOOL = libtool
37 |
38 | #-----------------------------------------------------------------------
39 | # Machine-dependent defines
40 | #-----------------------------------------------------------------------
41 |
42 | # Note: When compiling against HDF5 version 1.8 or greater, you need to
43 | # compile HDF5 with --with-default-api-version=v16, or specify with
44 | # -DH5_USE_16_API.
45 |
46 | MACH_DEFINES = -DLINUX -DH5_USE_16_API
47 |
48 | #-----------------------------------------------------------------------
49 | # Compiler flag settings
50 | #-----------------------------------------------------------------------
51 |
52 | MACH_OMPFLAGS = -fopenmp # OpenMP flags
53 | MACH_CPPFLAGS = -P -traditional # C preprocessor flags
54 | MACH_CFLAGS = -mp1 -prec_div -fp_port -align # C compiler flags
55 | MACH_CXXFLAGS = -mp1 -prec_div -fp_port -align # C++ compiler flags
56 | MACH_FFLAGS = # Fortran 77 compiler flags
57 | MACH_F90FLAGS = -mp1 -prec_div -fp_port -align #-save -zero # Fortran 90 compiler flags
58 | MACH_LDFLAGS = #-lifcore -lifport -lpthread -ldl # Linker flags
59 |
60 | #-----------------------------------------------------------------------
61 | # Optimization flags
62 | #-----------------------------------------------------------------------
63 |
64 | MACH_OPT_WARN = # Flags for verbose compiler warnings
65 | MACH_OPT_DEBUG = -g -O0 # Flags for debugging
66 | MACH_OPT_HIGH = -O2 # Flags for high conservative optimization
67 | MACH_OPT_AGGRESSIVE = -O3 #-Mfptrap -Mflushz -fastsse -Mdaz -Mnontemporal -Mnofprelaxed -Mvect=altcode,assoc,prefetch -Kieee # Flags for aggressive optimization
68 |
69 | #-----------------------------------------------------------------------
70 | # Includes
71 | #-----------------------------------------------------------------------
72 |
73 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
74 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
75 |
76 | #-----------------------------------------------------------------------
77 | # Libraries
78 | #-----------------------------------------------------------------------
79 |
80 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 # HDF5 libraries
81 | LOCAL_LIBS_MACH = -L$(LOCAL_FC_INSTALL) -lm -lifcore -lifport # Machine-dependent libraries
82 |
83 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
84 |
85 | #-----------------------------------------------------------------------
86 | # Installation
87 | #-----------------------------------------------------------------------
88 |
89 | # if $(HOME)/local does not exist, mkdir before `make install`
90 |
91 | MACH_INSTALL_PREFIX = $(HOME)/local
92 | MACH_INSTALL_LIB_DIR =
93 | MACH_INSTALL_INCLUDE_DIR =
94 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.uiuc-campus-pgi:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.uiuc-campus-pgi
4 | #
5 | # DESCRIPTION: Makefile for the UIUC Campus cluster with PGI compiler
6 | # and OpenMP support
7 | #
8 | # AUTHOR: Chester Cheng and Hsi-Yu Schive
9 | #
10 | # DATE: September 20, 2016
11 | #=======================================================================
12 |
13 | MACH_TEXT = UIUC Campus PGI
14 | MACH_VALID = 0
15 | MACH_FILE = Make.mach.uiuc-campus-pgi
16 |
17 | #-----------------------------------------------------------------------
18 | # Install paths (local variables)
19 | #-----------------------------------------------------------------------
20 |
21 | LOCAL_HDF5_INSTALL = /projects/ncsa/grav/softwares/miniconda2
22 | LOCAL_FC_INSTALL = /projects/ncsa/grav/hyschive/grackle_gpu/pgi/linux86-64/16.7/lib
23 |
24 | #-----------------------------------------------------------------------
25 | # Compiler settings
26 | #-----------------------------------------------------------------------
27 |
28 | MACH_CPP = /usr/bin/cpp # C preprocessor command
29 |
30 | # Compilers
31 | MACH_CC_NOMPI = pgcc # C compiler
32 | MACH_CXX_NOMPI = pgc++ # C++ compiler
33 | MACH_FC_NOMPI = pgf90 # Fortran 77
34 | MACH_F90_NOMPI = pgf90 # Fortran 90
35 | MACH_LD_NOMPI = pgc++ # Linker
36 | MACH_LIBTOOL = libtool
37 |
38 | #-----------------------------------------------------------------------
39 | # Machine-dependent defines
40 | #-----------------------------------------------------------------------
41 |
42 | # Note: When compiling against HDF5 version 1.8 or greater, you need to
43 | # compile HDF5 with --with-default-api-version=v16, or specify with
44 | # -DH5_USE_16_API.
45 |
46 | MACH_DEFINES = -DLINUX -DH5_USE_16_API
47 |
48 | #-----------------------------------------------------------------------
49 | # Compiler flag settings
50 | #-----------------------------------------------------------------------
51 |
52 | MACH_OMPFLAGS = -mp=bind # OpenMP flags
53 | MACH_CPPFLAGS = -P -traditional # C preprocessor flags
54 | MACH_CFLAGS =
55 | MACH_CXXFLAGS =
56 | MACH_FFLAGS = -Mnosecond_underscore -Mextend
57 | MACH_F90FLAGS = -Mnosecond_underscore
58 | MACH_LDFLAGS =
59 |
60 |
61 | #-----------------------------------------------------------------------
62 | # Optimization flags
63 | #-----------------------------------------------------------------------
64 |
65 | MACH_OPT_WARN = # Flags for verbose compiler warnings
66 | MACH_OPT_DEBUG = -g -O0 # Flags for debugging
67 | MACH_OPT_HIGH = -O2 # Flags for high conservative optimization
68 | MACH_OPT_AGGRESSIVE = -O3 #-Mfptrap -Mflushz -fastsse -Mdaz -Mnontemporal -Mnofprelaxed -Mvect=altcode,assoc,prefetch -Kieee # Flags for aggressive optimization
69 |
70 | #-----------------------------------------------------------------------
71 | # Includes
72 | #-----------------------------------------------------------------------
73 |
74 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
75 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
76 |
77 | #-----------------------------------------------------------------------
78 | # Libraries
79 | #-----------------------------------------------------------------------
80 |
81 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 # HDF5 libraries
82 | LOCAL_LIBS_MACH = -L$(LOCAL_FC_INSTALL) -lm -pgf90libs # Machine-dependent libraries
83 |
84 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
85 |
86 | #-----------------------------------------------------------------------
87 | # Installation
88 | #-----------------------------------------------------------------------
89 |
90 | # if $(HOME)/local does not exist, mkdir before `make install`
91 |
92 | MACH_INSTALL_PREFIX = $(HOME)/local
93 | MACH_INSTALL_LIB_DIR =
94 | MACH_INSTALL_INCLUDE_DIR =
95 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.unknown:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.unknown
4 | #
5 | # DESCRIPTION: Empty template for Makefile settings
6 | # (originally written by James Border for Enzo)
7 | #
8 | #=======================================================================
9 |
10 | MACH_TEXT = Unknown machine
11 | MACH_VALID = 0
12 | MACH_FILE = Make.mach.unknown
13 |
14 | #-----------------------------------------------------------------------
15 | # Compiler settings
16 | #-----------------------------------------------------------------------
17 |
18 | MACH_CPP = # C preprocessor command
19 |
20 | # Compilers
21 |
22 | MACH_CC_NOMPI = # C compiler
23 | MACH_CXX_NOMPI = # C++ compiler
24 | MACH_FC_NOMPI = # Fortran 77
25 | MACH_F90_NOMPI = # Fortran 90
26 | MACH_LD_NOMPI = # Linker
27 | MACH_LIBTOOL = libtool
28 |
29 | #-----------------------------------------------------------------------
30 | # Machine-dependent defines
31 | #-----------------------------------------------------------------------
32 |
33 | # Note: When compiling against HDF5 version 1.8 or greater, you need to
34 | # compile HDF5 with --with-default-api-version=v16, or specify with
35 | # -DH5_USE_16_API.
36 |
37 | MACH_DEFINES = -DH5_USE_16_API # Defines for the architecture; e.g. -DSUN, -DLINUX, etc.
38 |
39 | #-----------------------------------------------------------------------
40 | # Compiler flag settings
41 | #-----------------------------------------------------------------------
42 |
43 | MACH_OMPFLAGS = # OpenMP flags
44 | MACH_CPPFLAGS = # C preprocessor flags
45 | MACH_CFLAGS = # C compiler flags
46 | MACH_CXXFLAGS = # C++ compiler flags
47 | MACH_FFLAGS = # Fortran 77 compiler flags
48 | MACH_F90FLAGS = # Fortran 90 compiler flags
49 | MACH_LDFLAGS = # Linker flags
50 |
51 | #-----------------------------------------------------------------------
52 | # Optimization flags
53 | #-----------------------------------------------------------------------
54 |
55 | MACH_OPT_WARN = # Flags for verbose compiler warnings
56 | MACH_OPT_DEBUG = # Flags for debugging
57 | MACH_OPT_HIGH = # Flags for high conservative optimization
58 | MACH_OPT_AGGRESSIVE = # Flags for aggressive optimization
59 |
60 | #-----------------------------------------------------------------------
61 | # Includes
62 | #-----------------------------------------------------------------------
63 |
64 | LOCAL_INCLUDES_HDF5 = # HDF5 includes
65 |
66 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
67 |
68 | #-----------------------------------------------------------------------
69 | # Libraries
70 | #-----------------------------------------------------------------------
71 |
72 | LOCAL_LIBS_HDF5 = # HDF5 libraries
73 |
74 | LOCAL_LIBS_MACH = # Machine-dependent libraries
75 |
76 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
77 |
78 | #-----------------------------------------------------------------------
79 | # Installation
80 | #-----------------------------------------------------------------------
81 |
82 | MACH_INSTALL_PREFIX = $(HOME)/local
83 | MACH_INSTALL_LIB_DIR =
84 | MACH_INSTALL_INCLUDE_DIR =
85 |
--------------------------------------------------------------------------------
/src/clib/Make.mach.wheeler-intel:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Make.mach.tacc-wheeler-intel
4 | #
5 | # DESCRIPTION: Wheeler Makefile
6 | # Written by Christine Corbett Moran April 17
7 | #
8 | #=======================================================================
9 |
10 | MACH_TEXT = Wheeler
11 | MACH_VALID = 0
12 | MACH_FILE = Make.mach.wheeler-intel
13 |
14 | # Make sure to have the intel and HDF5 modules loaded:
15 | # $ module load intel/17.1 hdf5/1.8.17
16 |
17 | #-----------------------------------------------------------------------
18 | # Install paths (local variables)
19 | #-----------------------------------------------------------------------
20 |
21 | LOCAL_HDF5_INSTALL = $(HDF5_HOME)
22 | LOCAL_FC_INSTALL = /usr/local/Intel/2017.1/compilers_and_libraries/linux/lib/intel64
23 |
24 | #-----------------------------------------------------------------------
25 | # Compiler settings
26 | #-----------------------------------------------------------------------
27 |
28 | MACH_CPP = /usr/bin/cpp # C preprocessor command
29 |
30 | # Compilers
31 | MACH_CC_NOMPI = icc # C compiler
32 | MACH_CXX_NOMPI = icpc # C++ compiler
33 | MACH_FC_NOMPI = ifort # Fortran 77
34 | MACH_F90_NOMPI = ifort # Fortran 90
35 | MACH_LD_NOMPI = icpc # Linker
36 | MACH_LIBTOOL = libtool
37 |
38 | #-----------------------------------------------------------------------
39 | # Machine-dependent defines
40 | #-----------------------------------------------------------------------
41 |
42 | # Note: When compiling against HDF5 version 1.8 or greater, you need to
43 | # compile HDF5 with --with-default-api-version=v16, or specify with
44 | # -DH5_USE_16_API.
45 |
46 | MACH_DEFINES = -DLINUX -DH5_USE_16_API
47 |
48 | #-----------------------------------------------------------------------
49 | # Compiler flag settings
50 | #-----------------------------------------------------------------------
51 |
52 | MACH_OMPFLAGS = # OpenMP flags
53 | MACH_CPPFLAGS = -P -traditional # C preprocessor flags
54 | MACH_CFLAGS = -mp1 -prec_div -fp_port -align # C compiler flags
55 | MACH_CXXFLAGS = -mp1 -prec_div -fp_port -align # C++ compiler flags
56 | MACH_FFLAGS = # Fortran 77 compiler flags
57 | MACH_F90FLAGS = -mp1 -prec_div -fp_port -align -save -zero # Fortran 90 compiler flags
58 | MACH_LDFLAGS = -lifcore -lifport -lpthread -ldl # Linker flags
59 |
60 | #-----------------------------------------------------------------------
61 | # Optimization flags
62 | #-----------------------------------------------------------------------
63 |
64 | MACH_OPT_WARN = # Flags for verbose compiler warnings
65 | MACH_OPT_DEBUG = -g -O0 # Flags for debugging
66 | MACH_OPT_HIGH = -O2 # Flags for high conservative optimization
67 | MACH_OPT_AGGRESSIVE = -O3 -Mfptrap -Mflushz -fastsse -Mdaz -Mnontemporal -Mnofprelaxed -Mvect=altcode,assoc,prefetch -Kieee # Flags for aggressive optimization
68 |
69 | #-----------------------------------------------------------------------
70 | # Includes
71 | #-----------------------------------------------------------------------
72 |
73 | LOCAL_INCLUDES_HDF5 = -I$(LOCAL_HDF5_INSTALL)/include # HDF5 includes
74 | MACH_INCLUDES = $(LOCAL_INCLUDES_HDF5)
75 |
76 | #-----------------------------------------------------------------------
77 | # Libraries
78 | #-----------------------------------------------------------------------
79 |
80 | LOCAL_LIBS_HDF5 = -L$(LOCAL_HDF5_INSTALL)/lib -lhdf5 # HDF5 libraries
81 | LOCAL_LIBS_MACH = -L$(LOCAL_FC_INSTALL) -lm -lifcore -lifport # Machine-dependent libraries
82 |
83 | MACH_LIBS = $(LOCAL_LIBS_HDF5) $(LOCAL_LIBS_MACH)
84 |
85 | #-----------------------------------------------------------------------
86 | # Installation
87 | #-----------------------------------------------------------------------
88 |
89 | # if $(HOME)/local does not exist, mkdir before `make install`
90 |
91 | MACH_INSTALL_PREFIX = $(HOME)/local
92 | MACH_INSTALL_LIB_DIR =
93 | MACH_INSTALL_INCLUDE_DIR =
94 |
--------------------------------------------------------------------------------
/src/clib/README.md:
--------------------------------------------------------------------------------
1 | # Basic Code Organization
2 |
3 | This directory contains all of Grackle's C and Fortran source code files. It also contains all private header files.
4 |
5 | The directory located at `../include` (i.e. the `include` directory at `src/include`) contains Grackle's public header files.
6 |
7 | We review the differences between these headers further down this page.
8 |
9 | # Include-Directive Conventions
10 |
11 |
16 |
17 | When including a public header file inside one of the source files contained by this directory, please directly specify the name of the header file and **NOT** a relative path.
18 |
19 | Suppose we had a file called ``./my_source.c``. To include the ``grackle.h`` file:
20 | - you should write ``include "grackle.h"``
21 | - you should NOT write ``include "../include/grackle.h"``
22 |
23 | (we use the `-I` flag to tell the compiler where to search for the public headers)
24 |
25 | # More info and some conventions
26 |
27 | **What is the difference between public and private headers?**
28 |
29 | For the uninitiated:
30 |
31 | - public header files get installed with Grackle.
32 | - These are the header files that are made available to downstream applications.
33 | - Declarations for all of the functions and types that are part of our public API [described here](https://grackle.readthedocs.io/en/latest/Reference.html) must be stored in the so that files.
34 |
35 | - private header files are only used internal during the compilation process of Grackle. They include functions and types that are only used inside of Grackle. You should think of these as functions as private implementation details.
36 |
37 | *NOTE: just because a function/type is in the public header does not mean it is a part of the public API (the functions/types that are part of the public API are explicitly listed in the documentation at the above link). For example, we reserve the write to alter the contents of the * `chemistry_data_storage` * struct and it's contained structs*.
38 |
39 | Going forward, new private functions or types should generally be declared in the private headers.
40 |
41 | **How do we name files?**
42 | In general, all public header files should probably include ``grackle`` at the start of their names (to avoid name-conflicts during installation). There's no need for a private header file to do this (in fact, it's probably preferable if they don't do this to make it easier to distinguish whether its public or private. A public header must **NOT** share a name with a private header.
43 |
--------------------------------------------------------------------------------
/src/clib/auto_general.c.in:
--------------------------------------------------------------------------------
1 | #include
2 | #include "grackle.h"
3 |
4 | grackle_version get_grackle_version(void) {
5 | grackle_version out;
6 | out.version = "@VERSION_NUM@";
7 | out.branch = "@GIT_BRANCH@";
8 | out.revision = "@GIT_REVISION@";
9 | return out;
10 | }
11 |
12 | void auto_show_flags(FILE *fp) {
13 | fprintf (fp, "%s\n", "@SHOW_FLAGS_STR@");
14 | }
15 |
16 | void auto_show_config(FILE *fp) {
17 | fprintf (fp, "%s\n", "@SHOW_CONFIG_STR@");
18 | }
19 |
--------------------------------------------------------------------------------
/src/clib/calculate_gamma.c:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Calculate gamma (ratio of specific heats) field
4 | /
5 | /
6 | / Copyright (c) 2013, Enzo/Grackle Development Team.
7 | /
8 | / Distributed under the terms of the Enzo Public Licence.
9 | /
10 | / The full license is in the file LICENSE, distributed with this
11 | / software.
12 | ************************************************************************/
13 |
14 | #include
15 | #include
16 | #include
17 | #include "grackle_macros.h"
18 | #include "grackle_types.h"
19 | #include "grackle_chemistry_data.h"
20 | #include "phys_constants.h"
21 | #include "index_helper.h"
22 | #ifdef _OPENMP
23 | #include
24 | #endif
25 |
26 | extern chemistry_data *grackle_data;
27 | extern chemistry_data_storage grackle_rates;
28 |
29 | int local_calculate_temperature(chemistry_data *my_chemistry,
30 | chemistry_data_storage *my_rates,
31 | code_units *my_units,
32 | grackle_field_data *my_fields,
33 | gr_float *temperature);
34 |
35 | grackle_index_helper _build_index_helper(const grackle_field_data *my_fields);
36 |
37 | int local_calculate_gamma(chemistry_data *my_chemistry,
38 | chemistry_data_storage *my_rates,
39 | code_units *my_units,
40 | grackle_field_data *my_fields,
41 | gr_float *my_gamma)
42 | {
43 |
44 | if (!my_chemistry->use_grackle)
45 | return SUCCESS;
46 |
47 | const grackle_index_helper ind_helper = _build_index_helper(my_fields);
48 | int outer_ind, index;
49 |
50 | /* If molecular hydrogen is not being used, just use monotonic.
51 | (this should not really be called, but provide it just in case). */
52 |
53 | for (outer_ind = 0; outer_ind < ind_helper.outer_ind_size; outer_ind++){
54 |
55 | const grackle_index_range range = _inner_range(outer_ind, &ind_helper);
56 |
57 | for (index = range.start; index <= range.end; index++) {
58 | my_gamma[index] = my_chemistry->Gamma;
59 | }
60 | }
61 |
62 | if (my_chemistry->primordial_chemistry > 1) {
63 |
64 | /* Compute the temperature first. */
65 |
66 | if (local_calculate_temperature(my_chemistry, my_rates, my_units,
67 | my_fields, my_gamma) == FAIL) {
68 | fprintf(stderr, "Error in local_calculate_temperature.\n");
69 | return FAIL;
70 | }
71 |
72 | /* Compute Gamma with molecular Hydrogen formula from Omukau \& Nishi
73 | astro-ph/9811308. */
74 |
75 | double x, nH2, number_density, GammaH2Inverse,
76 | GammaInverse = 1 / (my_chemistry->Gamma - 1.0);
77 |
78 | /* parallelize the k and j loops with OpenMP
79 | * (these loops are flattened them for better parallelism) */
80 | # ifdef _OPENMP
81 | # pragma omp parallel for schedule( runtime ) \
82 | private( outer_ind, index, x, nH2, number_density, GammaH2Inverse )
83 | # endif
84 | for (outer_ind = 0; outer_ind < ind_helper.outer_ind_size; outer_ind++){
85 |
86 | const grackle_index_range range = _inner_range(outer_ind, &ind_helper);
87 |
88 | for (index = range.start; index <= range.end; index++) {
89 |
90 | /* Compute relative number abundence of molecular hydrogen. */
91 |
92 | number_density =
93 | 0.25 * (my_fields->HeI_density[index] +
94 | my_fields->HeII_density[index] +
95 | my_fields->HeIII_density[index]) +
96 | my_fields->HI_density[index] + my_fields->HII_density[index] +
97 | my_fields->HM_density[index] + my_fields->e_density[index];
98 |
99 | nH2 = 0.5 * (my_fields->H2I_density[index] +
100 | my_fields->H2II_density[index]);
101 |
102 | /* Only do full computation if there is a reasonable amount of H2.
103 | The second term in GammaH2Inverse accounts for the vibrational
104 | degrees of freedom. */
105 |
106 | GammaH2Inverse = 0.5*5.0;
107 | if (nH2 / number_density > 1e-3) {
108 | x = 6100.0 / my_gamma[index];
109 | if (x < 10.0)
110 | GammaH2Inverse = 0.5*(5 + 2.0 * x*x * exp(x)/POW(exp(x)-1.0,2));
111 | }
112 |
113 | /* Add in H2. */
114 |
115 | my_gamma[index] = 1.0 + (nH2 + number_density) /
116 | (nH2 * GammaH2Inverse + number_density * GammaInverse);
117 |
118 | } // end: loop over index
119 | } // end: loop over outer_ind
120 |
121 | } // end: if (my_chemistry->primordial_chemistry > 1)
122 |
123 | return SUCCESS;
124 | }
125 |
126 | int calculate_gamma(code_units *my_units,
127 | grackle_field_data *my_fields,
128 | gr_float *my_gamma)
129 | {
130 | if (local_calculate_gamma(grackle_data, &grackle_rates, my_units,
131 | my_fields, my_gamma) == FAIL) {
132 | fprintf(stderr, "Error in local_calculate_gamma.\n");
133 | return FAIL;
134 | }
135 | return SUCCESS;
136 | }
137 |
--------------------------------------------------------------------------------
/src/clib/calculate_pressure.c:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Calculate pressure field
4 | /
5 | /
6 | / Copyright (c) 2013, Enzo/Grackle Development Team.
7 | /
8 | / Distributed under the terms of the Enzo Public Licence.
9 | /
10 | / The full license is in the file LICENSE, distributed with this
11 | / software.
12 | ************************************************************************/
13 |
14 | #include
15 | #include
16 | #include
17 | #include "grackle_macros.h"
18 | #include "grackle_types.h"
19 | #include "grackle_chemistry_data.h"
20 | #include "phys_constants.h"
21 | #include "index_helper.h"
22 | #ifdef _OPENMP
23 | #include
24 | #endif
25 |
26 | extern chemistry_data *grackle_data;
27 | extern chemistry_data_storage grackle_rates;
28 |
29 | double get_temperature_units(code_units *my_units);
30 |
31 | int local_calculate_pressure(chemistry_data *my_chemistry,
32 | chemistry_data_storage *my_rates,
33 | code_units *my_units,
34 | grackle_field_data *my_fields,
35 | gr_float *pressure)
36 | {
37 |
38 | if (!my_chemistry->use_grackle)
39 | return SUCCESS;
40 |
41 | double tiny_number = 1.e-20;
42 | const grackle_index_helper ind_helper = _build_index_helper(my_fields);
43 | int outer_ind, index;
44 |
45 | /* parallelize the k and j loops with OpenMP
46 | * (these loops are flattened them for better parallelism) */
47 | # ifdef _OPENMP
48 | # pragma omp parallel for schedule( runtime ) private( outer_ind, index )
49 | # endif
50 | for (outer_ind = 0; outer_ind < ind_helper.outer_ind_size; outer_ind++){
51 |
52 | const grackle_index_range range = _inner_range(outer_ind, &ind_helper);
53 |
54 | for (index = range.start; index <= range.end; index++) {
55 |
56 | pressure[index] = ((my_chemistry->Gamma - 1.0) *
57 | my_fields->density[index] *
58 | my_fields->internal_energy[index]);
59 |
60 | if (pressure[index] < tiny_number)
61 | pressure[index] = tiny_number;
62 | } // end: loop over i
63 | } // end: loop over outer_ind
64 |
65 | /* Correct for Gamma from H2. */
66 |
67 | if (my_chemistry->primordial_chemistry > 1) {
68 |
69 | /* Calculate temperature units. */
70 |
71 | double temperature_units = get_temperature_units(my_units);
72 |
73 | double number_density, nH2, GammaH2Inverse,
74 | GammaInverse = 1.0/(my_chemistry->Gamma-1.0), x, Gamma1, temp;
75 |
76 | # ifdef _OPENMP
77 | # pragma omp parallel for schedule( runtime ) \
78 | private( outer_ind, index, \
79 | number_density, nH2, GammaH2Inverse, x, Gamma1, temp )
80 | # endif
81 | for (int outer_ind = 0; outer_ind < ind_helper.outer_ind_size; outer_ind++){
82 |
83 | const grackle_index_range range = _inner_range(outer_ind, &ind_helper);
84 |
85 | for (index = range.start; index <= range.end; index++) {
86 |
87 | number_density =
88 | 0.25 * (my_fields->HeI_density[index] +
89 | my_fields->HeII_density[index] +
90 | my_fields->HeIII_density[index]) +
91 | my_fields->HI_density[index] + my_fields->HII_density[index] +
92 | my_fields->HM_density[index] + my_fields->e_density[index];
93 |
94 | nH2 = 0.5 * (my_fields->H2I_density[index] +
95 | my_fields->H2II_density[index]);
96 |
97 | /* First, approximate temperature. */
98 |
99 | if (number_density == 0)
100 | number_density = tiny_number;
101 | temp = max(temperature_units * pressure[index] / (number_density + nH2),
102 | 1);
103 |
104 | /* Only do full computation if there is a reasonable amount of H2.
105 | The second term in GammaH2Inverse accounts for the vibrational
106 | degrees of freedom. */
107 |
108 | GammaH2Inverse = 0.5*5.0;
109 | if (nH2 / number_density > 1e-3) {
110 | x = 6100.0 / temp;
111 | if (x < 10.0)
112 | GammaH2Inverse = 0.5*(5 + 2.0 * x*x * exp(x)/POW(exp(x)-1.0,2));
113 | }
114 |
115 | Gamma1 = 1.0 + (nH2 + number_density) /
116 | (nH2 * GammaH2Inverse + number_density * GammaInverse);
117 |
118 | /* Correct pressure with improved Gamma. */
119 |
120 | pressure[index] *= (Gamma1 - 1.0) / (my_chemistry->Gamma - 1.0);
121 |
122 | } // end: loop over i
123 | } // end: loop over outer_ind
124 |
125 | } // end: if (my_chemistry->primordial_chemistry > 1)
126 |
127 | return SUCCESS;
128 | }
129 |
130 | int calculate_pressure(code_units *my_units,
131 | grackle_field_data *my_fields,
132 | gr_float *pressure)
133 | {
134 | if (local_calculate_pressure(grackle_data, &grackle_rates, my_units,
135 | my_fields, pressure) == FAIL) {
136 | fprintf(stderr, "Error in local_calculate_pressure.\n");
137 | return FAIL;
138 | }
139 | return SUCCESS;
140 | }
141 |
--------------------------------------------------------------------------------
/src/clib/grackle_field_data_fdatamembers.def:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / this file lists each member of the grackle_field_data struct that is
4 | / intended to hold field data. This list is intended to be used with
5 | / X-Macros in *.c files (to reduce the amount of code required to
6 | / interact with these fields)
7 | /
8 | / Currently, we just specify each field's name. In the future, we will
9 | / probably add other metadata (that may be used to help track when the
10 | / field is required or help with unit scaling/applying floors)
11 | /
12 | / Copyright (c) 2013, Enzo/Grackle Development Team.
13 | /
14 | / Distributed under the terms of the Enzo Public Licence.
15 | /
16 | / The full license is in the file LICENSE, distributed with this
17 | / software.
18 | ************************************************************************/
19 |
20 | ENTRY(density)
21 | ENTRY(HI_density)
22 | ENTRY(HII_density)
23 | ENTRY(HM_density)
24 | ENTRY(HeI_density)
25 | ENTRY(HeII_density)
26 | ENTRY(HeIII_density)
27 | ENTRY(H2I_density)
28 | ENTRY(H2II_density)
29 | ENTRY(DI_density)
30 | ENTRY(DII_density)
31 | ENTRY(HDI_density)
32 | ENTRY(e_density)
33 | ENTRY(metal_density)
34 | ENTRY(dust_density)
35 |
36 | ENTRY(internal_energy)
37 | ENTRY(x_velocity)
38 | ENTRY(y_velocity)
39 | ENTRY(z_velocity)
40 |
41 | ENTRY(volumetric_heating_rate)
42 | ENTRY(specific_heating_rate)
43 |
44 | ENTRY(temperature_floor)
45 |
46 | ENTRY(RT_heating_rate)
47 | ENTRY(RT_HI_ionization_rate)
48 | ENTRY(RT_HeI_ionization_rate)
49 | ENTRY(RT_HeII_ionization_rate)
50 | ENTRY(RT_H2_dissociation_rate)
51 |
52 | ENTRY(H2_self_shielding_length)
53 | ENTRY(H2_custom_shielding_factor)
54 |
55 | ENTRY(isrf_habing)
56 |
--------------------------------------------------------------------------------
/src/clib/grackle_macros.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Grackle definitions
4 | /
5 | /
6 | / Copyright (c) 2013, Enzo/Grackle Development Team.
7 | /
8 | / Distributed under the terms of the Enzo Public Licence.
9 | /
10 | / The full license is in the file LICENSE, distributed with this
11 | / software.
12 | ************************************************************************/
13 |
14 | #ifndef __GRACKLE_MACROS_H_
15 | #define __GRACKLE_MACROS_H_
16 | /***********************************************************************
17 | /
18 | / MACRO DEFINITIONS AND PARAMETERS
19 | /
20 | ************************************************************************/
21 |
22 | #define GRACKLE_FREE(p) \
23 | { \
24 | if (p != NULL) { \
25 | free(p); \
26 | p = NULL; \
27 | } \
28 | } \
29 |
30 | #ifdef CONFIG_THROW_ABORT
31 | #define GRACKLE_FAIL(A) raise(SIGABRT);
32 | #define GRACKLE_VFAIL(A, ...) raise(SIGABRT);
33 | #else
34 | #define GRACKLE_FAIL(A) throw(GrackleFatalException(A, __FILE__, __LINE__));
35 | #define GRACKLE_VFAIL(format, ...) {snprintf(current_error, 254, format, ##__VA_ARGS__); throw(GrackleFatalException(current_error, __FILE__, __LINE__));}
36 | #endif
37 |
38 | /* Fortran name generator (cpp blues) */
39 |
40 | #if defined(SUN_OLD)
41 | #define FORTRAN_NAME(NAME) NAME/**/_
42 | #endif
43 |
44 | #if defined(IRIS4) || defined(CONVEX) || defined(COMPAQ) || defined(SUN) || defined(LINUX) || defined(IA64) || defined(CRAYX1) || defined(XT3)
45 | #define FORTRAN_NAME(NAME) NAME##_
46 | #endif
47 |
48 | #if defined(SPP) || defined(SP2) || defined(BGL)
49 | #define FORTRAN_NAME(NAME) NAME
50 | #endif
51 |
52 | #ifdef CONFIG_PFLOAT_16
53 | #define PFORTRAN_NAME(NAME) NAME##_c
54 | #else
55 | #define PFORTRAN_NAME(NAME) FORTRAN_NAME(NAME)
56 | #endif
57 |
58 | /* HDF5 definitions */
59 |
60 | #define HDF5_FILE_I4 H5T_STD_I32BE
61 | #define HDF5_FILE_I8 H5T_STD_I64BE
62 | #define HDF5_FILE_R4 H5T_IEEE_F32BE
63 | #define HDF5_FILE_R8 H5T_IEEE_F64BE
64 | #define HDF5_FILE_B8 H5T_STD_B8BE
65 |
66 | #define HDF5_I4 H5T_NATIVE_INT
67 | #define HDF5_I8 H5T_NATIVE_LLONG
68 | #define HDF5_R4 H5T_NATIVE_FLOAT
69 | #define HDF5_R8 H5T_NATIVE_DOUBLE
70 | #define HDF5_R16 H5T_NATIVE_LDOUBLE
71 |
72 | /* Precision-dependent definitions */
73 |
74 | #ifdef GRACKLE_FLOAT_4
75 | #define FSYM "f"
76 | #define ESYM "e"
77 | #endif
78 |
79 | #ifdef GRACKLE_FLOAT_8
80 | #define FSYM "lf"
81 | #define ESYM "le"
82 | #endif
83 |
84 | #define GSYM "g"
85 |
86 | /* Standard definitions (well, fairly standard) */
87 |
88 | #ifndef NULL
89 | #define NULL 0
90 | #endif
91 |
92 | #ifdef FAIL
93 | #undef FAIL
94 | #endif
95 | #define FAIL 0
96 | #define SUCCESS 1
97 |
98 | #ifndef FALSE
99 | #define FALSE 0
100 | #define TRUE 1
101 | #endif
102 |
103 | #define FLOAT_UNDEFINED -99999.0
104 | #define INT_UNDEFINED -99999
105 | #define MAX_LINE_LENGTH 512
106 |
107 | #ifndef tiny
108 | #define tiny 1.0e-20
109 | #endif
110 |
111 | #ifndef huge
112 | #define huge 1.0e20
113 | #endif
114 |
115 | /* Macro definitions (things C should have) */
116 |
117 | #define max(A,B) ((A) > (B) ? (A) : (B))
118 | #define min(A,B) ((A) < (B) ? (A) : (B))
119 | #define sign(A) ((A) > 0 ? 1 : -1 )
120 | #define POW(X,Y) pow((double) (X), (double) (Y))
121 | #define COS(X) cos((double) (X))
122 | #define SIN(X) sin((double) (X))
123 |
124 | #endif
125 |
--------------------------------------------------------------------------------
/src/clib/index_helper.c:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Define routines useful for indexing
4 | /
5 | /
6 | / Copyright (c) Enzo/Grackle Development Team. All rights reserved.
7 | /
8 | / Distributed under the terms of the Enzo Public Licence.
9 | /
10 | / The full license is in the file LICENSE, distributed with this
11 | / software.
12 | ************************************************************************/
13 |
14 | #include "grackle_types.h"
15 | #include "index_helper.h"
16 |
17 | grackle_index_helper _build_index_helper(const grackle_field_data *my_fields)
18 | {
19 | grackle_index_helper out;
20 | const int rank = my_fields->grid_rank;
21 |
22 | /* handle i indices */
23 | out.i_dim = my_fields->grid_dimension[0];
24 | out.i_start = my_fields->grid_start[0];
25 | out.i_end = my_fields->grid_end[0];
26 |
27 | /* handle j indices (j_end isn't tracked by grackle_index_helper) */
28 | out.j_dim = (rank >= 2) ? my_fields->grid_dimension[1] : 1;
29 | out.j_start = (rank >= 2) ? my_fields->grid_start[1] : 0;
30 | int j_end = (rank >= 2) ? my_fields->grid_end[1] : 0;
31 | out.num_j_inds = (j_end - out.j_start) + 1;
32 |
33 | /* handle k indices (k_end & k_dim aren't tracked by grackle_index_helper) */
34 | out.k_start = (rank >= 3) ? my_fields->grid_start[2] : 0;
35 | int k_end = (rank >= 3) ? my_fields->grid_end[2] : 0;
36 | int num_k_inds = (k_end - out.k_start) + 1;
37 |
38 | out.outer_ind_size = num_k_inds * out.num_j_inds;
39 | return out;
40 | }
41 |
--------------------------------------------------------------------------------
/src/clib/index_helper.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Declare Grackle's index_helper type and associated functions. This is only
4 | / intended to be used internally.
5 | /
6 | /
7 | / Copyright (c) 2013, Enzo/Grackle Development Team.
8 | /
9 | / Distributed under the terms of the Enzo Public Licence.
10 | /
11 | / The full license is in the file LICENSE, distributed with this
12 | / software.
13 | ************************************************************************/
14 |
15 | #ifndef __GRACKLE_PRIVATE_H_
16 | #define __GRACKLE_PRIVATE_H_
17 |
18 | /***********************************************************************
19 | /
20 | / VARIABLE TYPES
21 | /
22 | ************************************************************************/
23 |
24 | typedef struct
25 | {
26 | int i_start;
27 | int i_end;
28 | int i_dim;
29 |
30 | int j_start;
31 | int j_dim;
32 | /* j_end isn't needed */
33 |
34 | int k_start;
35 | /* k_end & k_dim aren't needed */
36 |
37 | int num_j_inds;
38 | int outer_ind_size;
39 |
40 | } grackle_index_helper;
41 |
42 | typedef struct
43 | {
44 | int start;
45 | int end;
46 | } grackle_index_range;
47 |
48 | /***********************************************************************
49 | /
50 | / FUNCTION DECLARATIONS
51 | /
52 | ************************************************************************/
53 |
54 | // to help the compiler optimize the associated for-loops, this function:
55 | // - is implemented inline
56 | // - returns results as a struct rather than by modifying pointer arguments
57 | static inline grackle_index_range _inner_range(int outer_index,
58 | const grackle_index_helper* ind_helper)
59 | {
60 | int k = (outer_index / ind_helper->num_j_inds) + ind_helper->k_start;
61 | int j = (outer_index % ind_helper->num_j_inds) + ind_helper->j_start;
62 | int outer_offset = ind_helper->i_dim * (j + ind_helper->j_dim * k);
63 | grackle_index_range out = {ind_helper->i_start + outer_offset,
64 | ind_helper->i_end + outer_offset};
65 | return out;
66 | }
67 |
68 | grackle_index_helper _build_index_helper(const grackle_field_data *my_fields);
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/src/clib/phys_const.def:
--------------------------------------------------------------------------------
1 | #include "grackle_float.h"
2 |
3 | #ifdef GRACKLE_FLOAT_4
4 |
5 | #define kboltz 1.3806504e-16
6 | #define mass_h 1.67262171e-24
7 | #define mass_e 9.10938215e-28
8 | #define pi_val 3.14159265
9 | #define hplanck 6.6260693e-27
10 | #define ev2erg 1.60217653e-12
11 | #define c_light 2.99792458e10
12 | #define GravConst 6.67428e-8
13 | #define sigma_sb 5.670373e-5
14 | #define SolarMass 1.9891e33
15 | #define Mpc 3.0857e24
16 | #define kpc 3.0857e21
17 | #define pc 3.0857e18
18 |
19 | #endif
20 |
21 | #ifdef GRACKLE_FLOAT_8
22 |
23 | #define kboltz 1.3806504d-16
24 | #define mass_h 1.67262171d-24
25 | #define mass_e 9.10938215d-28
26 | #define pi_val 3.141592653589793d0
27 | #define hplanck 6.6260693d-27
28 | #define ev2erg 1.60217653d-12
29 | #define c_light 2.99792458d10
30 | #define GravConst 6.67428d-8
31 | #define sigma_sb 5.670373d-5
32 | #define SolarMass 1.9891d33
33 | #define Mpc 3.0857d24
34 | #define kpc 3.0857d21
35 | #define pc 3.0857d18
36 |
37 | #endif
38 |
39 |
--------------------------------------------------------------------------------
/src/clib/phys_constants.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Physical constants
4 | /
5 | /
6 | / Copyright (c) 2013, Enzo/Grackle Development Team.
7 | /
8 | / Distributed under the terms of the Enzo Public Licence.
9 | /
10 | / The full license is in the file LICENSE, distributed with this
11 | / software.
12 | ************************************************************************/
13 |
14 | #ifndef __g_phys_constants_h__
15 | #define __g_phys_constants_h__
16 | /***********************************************************************
17 | /
18 | / DEFINITION OF PHYSICAL CONSTANTS
19 | /
20 | / written by: Elizabeth Tasker (renamed by Daniel Reynolds)
21 | / date: May, 2005
22 | /
23 | / Note: CGS units
24 | /
25 | *********************************************************************/
26 |
27 | /* Physics constants */
28 |
29 | /************************************************/
30 |
31 | /* Boltzmann's constant [cm2gs-2K-1] or [ergK-1] */
32 |
33 | #define kboltz 1.3806504e-16
34 |
35 | /* Mass of hydrogen [g] */
36 |
37 | #define mh 1.67262171e-24
38 |
39 | /* Mass of an electron [g] */
40 |
41 | #define me 9.10938215e-28
42 |
43 | /* Pi */
44 |
45 | #define pi 3.14159265358979323846
46 |
47 |
48 | /************************************************/
49 |
50 | /* Astronomical constant */
51 |
52 | /************************************************/
53 |
54 | /* Speed of light [cms-1] */
55 |
56 | #define clight 2.99792458e10
57 |
58 | /* Gravitational constant [cm3g-1s-2]*/
59 |
60 | #define GravConst 6.67428e-8
61 |
62 | /* Solar mass [g] */
63 |
64 | #define SolarMass 1.9891e33
65 |
66 | /* Megaparsec [cm] */
67 |
68 | #define Mpc 3.0857e24
69 | #define kpc 3.0857e21
70 | #define pc 3.0857e18
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/src/clib/set_default_chemistry_parameters.c:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Set default parameter values
4 | /
5 | /
6 | / Copyright (c) 2013, Enzo/Grackle Development Team.
7 | /
8 | / Distributed under the terms of the Enzo Public Licence.
9 | /
10 | / The full license is in the file LICENSE, distributed with this
11 | / software.
12 | ************************************************************************/
13 |
14 | #include
15 | #include
16 | #include
17 |
18 | #include "grackle_macros.h"
19 | #include "grackle_types.h"
20 | #include "grackle_chemistry_data.h"
21 |
22 | int grackle_verbose = FALSE;
23 |
24 | chemistry_data *grackle_data = NULL;
25 | chemistry_data_storage grackle_rates;
26 |
27 | int local_initialize_chemistry_parameters(chemistry_data *my_chemistry)
28 | {
29 | if (my_chemistry == NULL){
30 | return FAIL;
31 | }
32 | // assign the default value to each field of my_chemistry
33 | #define ENTRY(FIELD, TYPE, DEFAULT_VAL) my_chemistry->FIELD = DEFAULT_VAL;
34 | #include "grackle_chemistry_data_fields.def"
35 | #undef ENTRY
36 | return SUCCESS;
37 | }
38 |
39 | int set_default_chemistry_parameters(chemistry_data *my_grackle)
40 | {
41 | grackle_data = my_grackle;
42 | return local_initialize_chemistry_parameters(my_grackle);
43 | }
44 |
45 | int gr_initialize_field_data(grackle_field_data *my_fields)
46 | {
47 | if (my_fields == NULL) {
48 | fprintf(stderr, "gr_initial_field_data was passed a NULL pointer\n");
49 | return FAIL;
50 | }
51 |
52 | my_fields->grid_rank = -1;
53 | my_fields->grid_dimension = NULL;
54 | my_fields->grid_start = NULL;
55 | my_fields->grid_end = NULL;
56 | my_fields->grid_dx = -1.0;
57 |
58 | // now, modify all members holding datafields to have values of NULL
59 | // (we use X-Macros to do this)
60 | #define ENTRY(MEMBER_NAME) my_fields->MEMBER_NAME = NULL;
61 | #include "grackle_field_data_fdatamembers.def"
62 | #undef ENTRY
63 |
64 | return SUCCESS;
65 | }
66 |
--------------------------------------------------------------------------------
/src/clib/utils.c:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Implement utility functions used internally by Grackle (across routines)
4 | /
5 | /
6 | / Copyright (c) 2013, Enzo/Grackle Development Team.
7 | /
8 | / Distributed under the terms of the Enzo Public Licence.
9 | /
10 | / The full license is in the file LICENSE, distributed with this
11 | / software.
12 | ************************************************************************/
13 |
14 | #include "utils.h"
15 | #include // fprintf, stderr
16 | #include "grackle_macros.h"
17 |
18 | int self_shielding_err_check(const chemistry_data *my_chemistry,
19 | const grackle_field_data *fields,
20 | const char* func_name) {
21 | if (my_chemistry->H2_self_shielding == 1) {
22 | if (fields->grid_rank != 3) {
23 | fprintf(stderr, "Error in %s: H2 self-shielding option 1 "
24 | "will only work for 3D Cartesian grids. Use option 2 "
25 | "to provide an array of shielding lengths with "
26 | "H2_self_shielding_length or option 3 to use the "
27 | "local Jeans length.",
28 | func_name);
29 | return FAIL;
30 | } else if (my_chemistry->primordial_chemistry >= 2 &&
31 | fields->grid_dx <= 0) {
32 | fprintf(stderr, "Error in %s: H2 self-shielding option 1 and primordial "
33 | "chemistry options of 2 or more require that grid_dx "
34 | "has a positive value.",
35 | func_name);
36 | return FAIL;
37 | }
38 | }
39 | return SUCCESS;
40 | }
41 |
--------------------------------------------------------------------------------
/src/clib/utils.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Declare utility functions used internally by Grackle (across routines)
4 | /
5 | /
6 | / Copyright (c) 2013, Enzo/Grackle Development Team.
7 | /
8 | / Distributed under the terms of the Enzo Public Licence.
9 | /
10 | / The full license is in the file LICENSE, distributed with this
11 | / software.
12 | ************************************************************************/
13 |
14 | #include "grackle_chemistry_data.h"
15 | #include "grackle_types.h"
16 |
17 | /// Perform an error check related to self-shielding. If the check fails, the
18 | /// function returns FAIL and prints an error message to stderr
19 | ///
20 | /// @param my_chemistry Holds configuration of chemistry solver
21 | /// @param fields Specify the field names
22 | /// @param func_name Name of the function that is calling the error check
23 | int self_shielding_err_check(const chemistry_data *my_chemistry,
24 | const grackle_field_data *fields,
25 | const char* func_name);
26 |
--------------------------------------------------------------------------------
/src/example/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | # overwrite the global variable that controls where the binaries compiled in
3 | # this directory are placed
4 | # -> because this file is only read by CMake via add_subdirectory and we are
5 | # are not making a CACHE variable, this won't affect anything outside of
6 | # this directory
7 | # -> for a build directory, , this places the binaries at
8 | # /examples
9 | # -> assuming that the build-directory is at the root level of the grackle
10 | # repository, then executing the examples from within the examples directory
11 | # should ensure that the paths to the datafiles are correct
12 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../../examples)
13 |
14 |
15 | add_executable(c_example c_example.c)
16 | target_link_libraries(c_example Grackle::Grackle)
17 |
18 | add_executable(c_local_example c_local_example.c)
19 | target_link_libraries(c_local_example Grackle::Grackle)
20 |
21 | set(CMAKE_CXX_STANDARD 11) # needed by apple-clang compiler for some examples
22 |
23 | add_executable(cxx_example cxx_example.C)
24 | target_link_libraries(cxx_example Grackle::Grackle)
25 |
26 | if (GRACKLE_USE_OPENMP)
27 | add_executable(cxx_omp_example cxx_omp_example.C)
28 | target_link_libraries(cxx_omp_example Grackle::Grackle OpenMP::OpenMP_CXX)
29 | endif()
30 |
31 | if (GRACKLE_USE_DOUBLE)
32 | # we don't really have a good reason for why this disabled. This should
33 | # really be fixed to work in single precision
34 |
35 | # the following target uses -O1 optimization because problems can arise with
36 | # higher levels of optimization. A comment in fortran_example.F provides more
37 | # details about the problems
38 | add_executable(fortran_example fortran_example.F)
39 | target_compile_options(fortran_example PRIVATE "-O1")
40 | target_link_libraries(fortran_example Grackle::Grackle)
41 | endif()
42 |
--------------------------------------------------------------------------------
/src/example/Makefile:
--------------------------------------------------------------------------------
1 | #=======================================================================
2 | #
3 | # FILE: Makefile
4 | #
5 | # SUMMARY: Configurable Makefile for grackle example executable
6 | # (originally written by James Border for Enzo)
7 | #
8 | # DESCRIPTION
9 | # See 'gmake help' for definitive description of targets
10 | #
11 | #=======================================================================
12 |
13 | # Use bash since sh does not recognize ">&" used in dep: target
14 |
15 | SHELL = /bin/bash
16 |
17 | TOP_DIR = ../../
18 |
19 | GRACKLE_DIR = $(TOP_DIR)/src/clib
20 | MODULES =
21 |
22 | #-----------------------------------------------------------------------
23 | # Make.config.settings is used for setting default values to all compile-time
24 | # configuration settings.
25 | #-----------------------------------------------------------------------
26 |
27 | include $(GRACKLE_DIR)/Make.config.settings
28 |
29 | #-----------------------------------------------------------------------
30 | # Make.config.machine is used for setting which Make.mach.* file to use
31 | #-----------------------------------------------------------------------
32 |
33 | MAKE_CONFIG_MACHINE = $(GRACKLE_DIR)/Make.config.machine
34 | include $(GRACKLE_DIR)/Make.config.machine
35 |
36 | #-----------------------------------------------------------------------
37 | # Make.config.override is used for overriding the default settings in
38 | # Make.config.settings. This was made separate from the default settings
39 | # to enable easily interfacing Grackle with a software testing environment
40 | # like lcatest.
41 | #-----------------------------------------------------------------------
42 |
43 | MAKE_CONFIG_OVERRIDE = $(GRACKLE_DIR)/Make.config.override
44 | include $(MAKE_CONFIG_OVERRIDE)
45 |
46 | CONFIG_USE_MPI = no
47 |
48 | #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
49 |
50 | #-----------------------------------------------------------------------
51 | # Make.config.assemble takes the settings in the Make.config.settings
52 | # and Make.config.override, and generates the appropriate make variables
53 | # required by this makefile. E.g. $(CXX), $(CXXFLAGS), etc.
54 | #-----------------------------------------------------------------------
55 |
56 | include $(GRACKLE_DIR)/Make.config.assemble
57 |
58 | #-----------------------------------------------------------------------
59 | # Make.mach. defines all machine-dependent settings.
60 | #-----------------------------------------------------------------------
61 |
62 | -include $(GRACKLE_DIR)/Make.mach.$(CONFIG_MACHINE)
63 | -include $(HOME)/.grackle/Make.mach.$(CONFIG_MACHINE)
64 |
65 | #-----------------------------------------------------------------------
66 | # add the OpenMP flag
67 | #-----------------------------------------------------------------------
68 |
69 | LDFLAGS += $(ASSEMBLE_OMP_FLAGS)
70 |
71 | #=======================================================================
72 | # OBJECT FILES
73 | #=======================================================================
74 |
75 | GRACKLE_INCLUDE = -I$(MACH_INSTALL_PREFIX)/include
76 | GRACKLE_LIB = -L$(MACH_INSTALL_PREFIX)/lib -lgrackle
77 |
78 | #-----------------------------------------------------------------------
79 | include ./Make.config.targets
80 |
81 | #-----------------------------------------------------------------------
82 | # HELP TARGET
83 | #-----------------------------------------------------------------------
84 |
85 | help:
86 | @echo
87 | @echo "========================================================================"
88 | @echo " Makefile Help for Grackle example"
89 | @echo "========================================================================"
90 | @echo
91 | @echo " gmake Compile and generate the executable 'grackle.exe'"
92 | @echo " gmake help Display this help information"
93 | @echo " gmake clean Remove object files, executable, etc."
94 | @echo
95 | @echo " gmake help-config Display detailed help on configuration make targets"
96 | @echo " gmake show-config Display the configuration settings"
97 | @echo " gmake show-flags Display specific compilation flags"
98 | @echo " gmake default Reset the configuration to the default values"
99 | @echo
100 |
101 |
102 | clean:
103 | -@rm -f *.o *.mod *.f *.f90 *~ *.exe $(OUTPUT) cxx_example cxx_omp_example c_example c_local_example fortran_example
104 |
105 | #-----------------------------------------------------------------------
106 | # Include configuration targets
107 | #-----------------------------------------------------------------------
108 |
109 | include $(GRACKLE_DIR)/Make.config.targets
110 |
--------------------------------------------------------------------------------
/src/include/grackle.def:
--------------------------------------------------------------------------------
1 | !=======================================================================
2 | !
3 | !
4 | ! Grackle fortran interface and data types
5 | !
6 | !
7 | ! Copyright (c) 2013, Enzo/Grackle Development Team.
8 | !
9 | ! Distributed under the terms of the Enzo Public Licence.
10 | !
11 | ! The full license is in the file LICENSE, distributed with this
12 | ! software.
13 | !=======================================================================
14 |
15 | #include "grackle_fortran_types.def"
16 | #include "grackle_fortran_interface.def"
17 |
--------------------------------------------------------------------------------
/src/include/grackle_float.h.in:
--------------------------------------------------------------------------------
1 | #if defined(__STDC__) || defined(__cplusplus)
2 | // this block is hidden from all Fortran compilers
3 | // -> the block will also be hidden from K&R C compilers (i.e. pre C89).
4 | // This is ok since this block just implements a warning. Frankly, I
5 | // suspect K&R C may be incompatible with Grackle.
6 | // -> the alternative to hiding this block from K&R C is defining a special
7 | // macro (maybe GRIMPL_FORTRAN_LANG) before this file is included in each
8 | // relevant `.def` file.
9 |
10 | // this logic should occur before the header guards
11 | #ifndef GRIMPL_PUBLIC_INCLUDE
12 | #include "grackle_misc.h"
13 | GRIMPL_COMPTIME_WARNING(
14 | "You are using a deprecated header file; include the public "
15 | "\"grackle.h\" header file instead! In a future Grackle version, "
16 | "\"grackle_float.h\" may cease to exist (or contents may change in an "
17 | "incompatible manner)."
18 | );
19 | #endif
20 | #endif
21 |
22 | #ifndef __GRACKLE_FLOAT_H__
23 | #define __GRACKLE_FLOAT_H__
24 | #define @GRACKLE_FLOAT_MACRO@
25 | #endif
26 |
--------------------------------------------------------------------------------
/src/include/grackle_fortran_types.def:
--------------------------------------------------------------------------------
1 | !=======================================================================
2 | !
3 | !
4 | ! Grackle fortran variable types
5 | !
6 | !
7 | ! Copyright (c) 2013, Enzo/Grackle Development Team.
8 | !
9 | ! Distributed under the terms of the Enzo Public Licence.
10 | !
11 | ! The full license is in the file LICENSE, distributed with this
12 | ! software.
13 | !=======================================================================
14 |
15 | #include "grackle_float.h"
16 |
17 | #ifdef GRACKLE_FLOAT_4
18 | #define tiny 1.e-20
19 | #define huge 1.e+20
20 | #define R_PREC real*4
21 | integer, parameter :: RKIND=4
22 | #endif
23 |
24 | #ifdef GRACKLE_FLOAT_8
25 | #define tiny 1.d-20
26 | #define huge 1.d+20
27 | #define R_PREC real*8
28 | integer, parameter :: RKIND=8
29 | #endif
30 |
31 | #define tiny8 1.d-40
32 | #define huge8 1.d+40
33 |
34 | integer, parameter :: DKIND=8
35 | integer, parameter :: DIKIND=8
36 |
--------------------------------------------------------------------------------
/src/include/grackle_misc.h:
--------------------------------------------------------------------------------
1 | // This existence of this header file is considered an implementation detail
2 | // - it's an error for external project to directly include this file. Any
3 | // external project directly include this file can/will start encountering
4 | // problems @ an arbitrary point in the future
5 | // - the only reason we don't currently abort with an error is so we can
6 | // gracefully warn about deprecated headers without introducing lots of
7 | // complex preprocessor logic
8 |
9 |
10 | #ifndef GRACKLE_MISC_H
11 | #define GRACKLE_MISC_H
12 |
13 | /// @def GRIMPL_COMPTIME_WARNING(MSG)
14 | /// @brief Internal macro used to produces a compile-time warning with the
15 | /// specified message (it should be a string literal). This exists because
16 | /// `#warning` is a non-standard extension (before C23 and C++23). On less
17 | /// popular compilers, this is a no-op
18 | ///
19 | /// @note
20 | /// The use of GRIMPL_DO_PRAGMA is based on gcc documentation
21 | /// https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html
22 |
23 | #define GRIMPL_DO_PRAGMA(x) _Pragma(#x)
24 | #ifdef __GNUC__
25 | // Modern versions of mainstream compilers that masquerade as gcc (like
26 | // clang or intel), understand the pragma used to implement this macro.
27 | // - Any compiler that don't understand it will treat it as a no-op (as
28 | // mandated by the C and C++ standards).
29 | #define GRIMPL_COMPTIME_WARNING(MSG) GRIMPL_DO_PRAGMA(GCC warning MSG)
30 | #else
31 | #define GRIMPL_COMPTIME_WARNING(MSG) /* no-op */
32 | #endif
33 |
34 | #endif /* GRACKLE_MISC_H */
35 |
--------------------------------------------------------------------------------
/src/include/grackle_types.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | /
3 | / Grackle variable types
4 | /
5 | /
6 | / Copyright (c) 2013, Enzo/Grackle Development Team.
7 | /
8 | / Distributed under the terms of the Enzo Public Licence.
9 | /
10 | / The full license is in the file LICENSE, distributed with this
11 | / software.
12 | ************************************************************************/
13 |
14 | // this should go before the header-guard
15 | #ifndef GRIMPL_PUBLIC_INCLUDE
16 | #include "grackle_misc.h"
17 | GRIMPL_COMPTIME_WARNING(
18 | "You are using a deprecated header file; include the public \"grackle.h\" "
19 | "header file instead! In a future Grackle version, \"grackle_types.h\" "
20 | "may cease to exist (or contents may change in an incompatible manner)."
21 | );
22 | #endif
23 |
24 |
25 | #ifndef __GRACKLE_TYPES_H__
26 | #define __GRACKLE_TYPES_H__
27 | /***********************************************************************
28 | /
29 | / VARIABLE TYPES
30 | /
31 | ************************************************************************/
32 |
33 | #include "grackle_float.h"
34 |
35 | // the following include-directive only exists because the definition of
36 | // the code_units type got moved and we don't want to break anybody's
37 | // code who expect that type to be defined in this file
38 | #include "grackle_chemistry_data.h"
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif /* __cplusplus */
43 |
44 | #ifdef GRACKLE_FLOAT_4
45 | #define gr_float float
46 | #endif
47 |
48 | #ifdef GRACKLE_FLOAT_8
49 | #define gr_float double
50 | #endif
51 |
52 | #if defined(GRACKLE_FLOAT_4) == defined(GRACKLE_FLOAT_8)
53 | #error "Both GRACKLE_FLOAT_4 and GRACKLE_FLOAT_8 are defined. Only one can be defined."
54 | #endif
55 |
56 | typedef struct
57 | {
58 |
59 | int grid_rank;
60 | int *grid_dimension;
61 | int *grid_start;
62 | int *grid_end;
63 |
64 | gr_float grid_dx;
65 |
66 | gr_float *density;
67 | gr_float *HI_density;
68 | gr_float *HII_density;
69 | gr_float *HM_density;
70 | gr_float *HeI_density;
71 | gr_float *HeII_density;
72 | gr_float *HeIII_density;
73 | gr_float *H2I_density;
74 | gr_float *H2II_density;
75 | gr_float *DI_density;
76 | gr_float *DII_density;
77 | gr_float *HDI_density;
78 | gr_float *e_density;
79 | gr_float *metal_density;
80 | gr_float *dust_density;
81 |
82 | gr_float *internal_energy;
83 | gr_float *x_velocity;
84 | gr_float *y_velocity;
85 | gr_float *z_velocity;
86 |
87 | gr_float *volumetric_heating_rate;
88 | gr_float *specific_heating_rate;
89 |
90 | gr_float *temperature_floor;
91 |
92 | gr_float *RT_heating_rate;
93 | gr_float *RT_HI_ionization_rate;
94 | gr_float *RT_HeI_ionization_rate;
95 | gr_float *RT_HeII_ionization_rate;
96 | gr_float *RT_H2_dissociation_rate;
97 |
98 | gr_float *H2_self_shielding_length;
99 | gr_float *H2_custom_shielding_factor;
100 |
101 | gr_float *isrf_habing;
102 |
103 | } grackle_field_data;
104 |
105 |
106 | typedef struct
107 | {
108 |
109 | const char* version;
110 | const char* branch;
111 | const char* revision;
112 |
113 | } grackle_version;
114 |
115 | #ifdef __cplusplus
116 | } /* extern "C" */
117 | #endif /* __cplusplus */
118 |
119 | #endif /* __GRACKLE_TYPES_H__ */
120 |
--------------------------------------------------------------------------------
/src/python/examples/cooling_cell.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Cooling cell example script
4 | #
5 | # This will initialize a single cell at a given temperature,
6 | # iterate the cooling solver for a fixed time, and output the
7 | # temperature vs. time.
8 | #
9 | #
10 | # Copyright (c) 2015-2016, Grackle Development Team.
11 | #
12 | # Distributed under the terms of the Enzo Public Licence.
13 | #
14 | # The full license is in the file LICENSE, distributed with this
15 | # software.
16 | ########################################################################
17 |
18 | from matplotlib import pyplot
19 | import os
20 | import sys
21 | import yt
22 |
23 | from pygrackle import \
24 | chemistry_data, \
25 | evolve_constant_density, \
26 | setup_fluid_container
27 | from pygrackle.utilities.physical_constants import \
28 | mass_hydrogen_cgs, \
29 | sec_per_Myr, \
30 | cm_per_mpc
31 | from pygrackle.utilities.data_path import grackle_data_dir
32 | from pygrackle.utilities.model_tests import \
33 | get_model_set, \
34 | model_test_format_version
35 |
36 | output_name = os.path.basename(__file__[:-3]) # strip off ".py"
37 |
38 | if __name__ == "__main__":
39 | # If we are running the script through the testing framework,
40 | # then we will pass in two integers corresponding to the sets
41 | # of parameters and inputs.
42 | if len(sys.argv) > 1:
43 | par_index = int(sys.argv[1])
44 | input_index = int(sys.argv[2])
45 | my_chemistry, input_set = get_model_set(
46 | output_name, par_index, input_index)
47 | for var, val in input_set.items():
48 | globals()[var] = val
49 | output_name = f"{output_name}_{par_index}_{input_index}"
50 | extra_attrs = {"format_version": model_test_format_version}
51 |
52 | # Just run the script as is.
53 | else:
54 | metallicity = 0.1 # Solar
55 | redshift = 0.
56 | # dictionary to store extra information in output dataset
57 | extra_attrs = {}
58 |
59 | my_chemistry = chemistry_data()
60 | my_chemistry.use_grackle = 1
61 | my_chemistry.with_radiative_cooling = 1
62 | my_chemistry.primordial_chemistry = 0
63 | my_chemistry.metal_cooling = 1
64 | my_chemistry.UVbackground = 1
65 | my_chemistry.grackle_data_file = \
66 | os.path.join(grackle_data_dir, "CloudyData_UVB=HM2012.h5")
67 |
68 | density = 0.1 * mass_hydrogen_cgs # g /cm^3
69 | temperature = 1e6 # K
70 | final_time = 100. # Myr
71 |
72 | # Set units
73 | my_chemistry.comoving_coordinates = 0
74 | my_chemistry.a_units = 1.0
75 | my_chemistry.a_value = 1. / (1. + redshift) / \
76 | my_chemistry.a_units
77 | my_chemistry.density_units = mass_hydrogen_cgs
78 | my_chemistry.length_units = cm_per_mpc
79 | my_chemistry.time_units = sec_per_Myr
80 | my_chemistry.set_velocity_units()
81 |
82 | metal_mass_fraction = metallicity * my_chemistry.SolarMetalFractionByMass
83 | fc = setup_fluid_container(
84 | my_chemistry,
85 | density=density,
86 | temperature=temperature,
87 | metal_mass_fraction=metal_mass_fraction,
88 | state="ionized",
89 | converge=True)
90 |
91 | # evolve gas at constant density
92 | data = evolve_constant_density(
93 | fc, final_time=final_time,
94 | safety_factor=0.01)
95 |
96 | p1, = pyplot.loglog(data["time"].to("Myr"),
97 | data["temperature"],
98 | color="black", label="T")
99 | pyplot.xlabel("Time [Myr]")
100 | pyplot.ylabel("T [K]")
101 | pyplot.twinx()
102 | p2, = pyplot.semilogx(data["time"].to("Myr"),
103 | data["mean_molecular_weight"],
104 | color="red", label="$\\mu$")
105 | pyplot.ylabel("$\\mu$")
106 | pyplot.legend([p1,p2],["T","$\\mu$"], fancybox=True,
107 | loc="center left")
108 | pyplot.tight_layout()
109 | pyplot.savefig(f"{output_name}.png")
110 |
111 | # save data arrays as a yt dataset
112 | yt.save_as_dataset({}, f"{output_name}.h5",
113 | data=data, extra_attrs=extra_attrs)
114 |
--------------------------------------------------------------------------------
/src/python/examples/cooling_rate.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Cooling rate example script
4 | #
5 | #
6 | # Copyright (c) 2013-2016, Grackle Development Team.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | from matplotlib import pyplot
15 | import numpy as np
16 | import os
17 | import sys
18 | import yt
19 |
20 | from pygrackle import \
21 | chemistry_data, \
22 | setup_fluid_container
23 | from pygrackle.utilities.data_path import grackle_data_dir
24 | from pygrackle.utilities.physical_constants import \
25 | mass_hydrogen_cgs, \
26 | sec_per_Myr, \
27 | cm_per_mpc
28 | from pygrackle.utilities.model_tests import \
29 | get_model_set, \
30 | model_test_format_version
31 |
32 | output_name = os.path.basename(__file__[:-3]) # strip off ".py"
33 |
34 | if __name__ == "__main__":
35 | # If we are running the script through the testing framework,
36 | # then we will pass in two integers corresponding to the sets
37 | # of parameters and inputs.
38 | if len(sys.argv) > 1:
39 | par_index = int(sys.argv[1])
40 | input_index = int(sys.argv[2])
41 | my_chemistry, input_set = get_model_set(
42 | output_name, par_index, input_index)
43 | for var, val in input_set.items():
44 | globals()[var] = val
45 | output_name = f"{output_name}_{par_index}_{input_index}"
46 | extra_attrs = {"format_version": model_test_format_version}
47 |
48 | # Just run the script as is.
49 | else:
50 | metallicity = 1. # Solar
51 | redshift = 0.
52 | specific_heating_rate = 0.
53 | volumetric_heating_rate = 0.
54 | # dictionary to store extra information in output dataset
55 | extra_attrs = {}
56 |
57 | # Set solver parameters
58 | my_chemistry = chemistry_data()
59 | my_chemistry.use_grackle = 1
60 | my_chemistry.with_radiative_cooling = 0
61 | my_chemistry.primordial_chemistry = 3
62 | my_chemistry.metal_cooling = 1
63 | my_chemistry.UVbackground = 1
64 | my_chemistry.self_shielding_method = 0
65 | my_chemistry.H2_self_shielding = 0
66 | my_chemistry.grackle_data_file = \
67 | os.path.join(grackle_data_dir, "CloudyData_UVB=HM2012.h5")
68 |
69 | my_chemistry.use_specific_heating_rate = 1
70 | my_chemistry.use_volumetric_heating_rate = 1
71 |
72 | # Set units
73 | my_chemistry.comoving_coordinates = 0 # proper units
74 | my_chemistry.a_units = 1.0
75 | my_chemistry.a_value = 1.0 / (1.0 + redshift) / \
76 | my_chemistry.a_units
77 | my_chemistry.density_units = mass_hydrogen_cgs # rho = 1.0 is 1.67e-24 g
78 | my_chemistry.length_units = cm_per_mpc # 1 Mpc in cm
79 | my_chemistry.time_units = sec_per_Myr # 1 Gyr in s
80 | my_chemistry.set_velocity_units()
81 |
82 | # Call convenience function for setting up a fluid container.
83 | # This container holds the solver parameters, units, and fields.
84 | metal_mass_fraction = metallicity * my_chemistry.SolarMetalFractionByMass
85 | temperature = np.logspace(1, 9, 200)
86 | fc = setup_fluid_container(
87 | my_chemistry,
88 | density=mass_hydrogen_cgs,
89 | temperature=temperature,
90 | metal_mass_fraction=metal_mass_fraction,
91 | converge=True)
92 |
93 | if my_chemistry.use_specific_heating_rate:
94 | fc["specific_heating_rate"][:] = specific_heating_rate
95 | if my_chemistry.use_volumetric_heating_rate:
96 | fc["volumetric_heating_rate"][:] = volumetric_heating_rate
97 |
98 | # get data arrays with symbolic units
99 | data = fc.finalize_data()
100 |
101 | pyplot.loglog(data["temperature"], np.abs(data["cooling_rate"]),
102 | color="black")
103 | pyplot.xlabel('T [K]')
104 | pyplot.ylabel('$\\Lambda$ [erg s$^{-1}$ cm$^{3}$]')
105 | pyplot.tight_layout()
106 | pyplot.savefig(f"{output_name}.png")
107 | yt.save_as_dataset({}, filename=f"{output_name}.h5",
108 | data=data, extra_attrs=extra_attrs)
109 |
--------------------------------------------------------------------------------
/src/python/examples/freefall.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Free-fall example script
4 | #
5 | #
6 | # Copyright (c) 2013-2016, Grackle Development Team.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | from matplotlib import pyplot
15 | import os
16 | import sys
17 | import yt
18 |
19 | from pygrackle import \
20 | chemistry_data, \
21 | evolve_constant_density, \
22 | evolve_freefall, \
23 | setup_fluid_container
24 | from pygrackle.utilities.physical_constants import \
25 | mass_hydrogen_cgs, \
26 | sec_per_Myr, \
27 | cm_per_mpc
28 | from pygrackle.utilities.data_path import grackle_data_dir
29 | from pygrackle.utilities.model_tests import \
30 | get_model_set, \
31 | model_test_format_version
32 |
33 | output_name = os.path.basename(__file__[:-3]) # strip off ".py"
34 |
35 | if __name__=="__main__":
36 | # If we are running the script through the testing framework,
37 | # then we will pass in two integers corresponding to the sets
38 | # of parameters and inputs.
39 | if len(sys.argv) > 1:
40 | par_index = int(sys.argv[1])
41 | input_index = int(sys.argv[2])
42 | my_chemistry, input_set = get_model_set(
43 | output_name, par_index, input_index)
44 | for var, val in input_set.items():
45 | globals()[var] = val
46 | output_name = f"{output_name}_{par_index}_{input_index}"
47 | extra_attrs = {"format_version": model_test_format_version}
48 |
49 | # Just run the script as is.
50 | else:
51 | metallicity = 0.
52 | # dictionary to store extra information in output dataset
53 | extra_attrs = {}
54 |
55 | # Set solver parameters
56 | my_chemistry = chemistry_data()
57 | my_chemistry.use_grackle = 1
58 | my_chemistry.with_radiative_cooling = 1
59 | my_chemistry.primordial_chemistry = 3
60 | my_chemistry.metal_cooling = 0
61 | my_chemistry.dust_chemistry = 0
62 | my_chemistry.photoelectric_heating = 0
63 | my_chemistry.self_shielding_method = 0
64 | my_chemistry.H2_self_shielding = 0
65 | my_chemistry.CaseBRecombination = 1
66 | my_chemistry.cie_cooling = 1
67 | my_chemistry.h2_optical_depth_approximation = 1
68 | my_chemistry.grackle_data_file = os.path.join(
69 | grackle_data_dir, "cloudy_metals_2008_3D.h5")
70 |
71 | redshift = 0.
72 |
73 | # Set units
74 | my_chemistry.comoving_coordinates = 0
75 | my_chemistry.a_units = 1.0
76 | my_chemistry.a_value = 1. / (1. + redshift) / \
77 | my_chemistry.a_units
78 | my_chemistry.density_units = mass_hydrogen_cgs
79 | my_chemistry.length_units = cm_per_mpc
80 | my_chemistry.time_units = sec_per_Myr
81 | my_chemistry.set_velocity_units()
82 |
83 | # set initial density and temperature
84 | initial_temperature = 50000.
85 | initial_density = 1e-1 * mass_hydrogen_cgs # g / cm^3
86 | final_density = 1e12 * mass_hydrogen_cgs
87 |
88 | metal_mass_fraction = metallicity * my_chemistry.SolarMetalFractionByMass
89 | dust_to_gas_ratio = metallicity * my_chemistry.local_dust_to_gas_ratio
90 | fc = setup_fluid_container(
91 | my_chemistry,
92 | density=initial_density,
93 | temperature=initial_temperature,
94 | metal_mass_fraction=metal_mass_fraction,
95 | dust_to_gas_ratio=dust_to_gas_ratio,
96 | state="ionized",
97 | converge=False)
98 |
99 | # let the gas cool at constant density from the starting temperature
100 | # down to a lower temperature to get the species fractions in a
101 | # reasonable state.
102 | cooling_temperature = 100.
103 | data0 = evolve_constant_density(
104 | fc, final_temperature=cooling_temperature,
105 | safety_factor=0.1)
106 |
107 | # evolve density and temperature according to free-fall collapse
108 | data = evolve_freefall(fc, final_density,
109 | safety_factor=0.01,
110 | include_pressure=True)
111 |
112 | plots = pyplot.loglog(data["density"], data["temperature"],
113 | color="black", label="T$_{gas}$")
114 | if fc.chemistry_data.dust_chemistry == 1:
115 | plots.extend(
116 | pyplot.loglog(data["density"], data["dust_temperature"],
117 | color="black", linestyle="--", label="T$_{dust}$"))
118 | pyplot.xlabel("$\\rho$ [g/cm$^{3}$]")
119 | pyplot.ylabel("T [K]")
120 |
121 | pyplot.twinx()
122 | plots.extend(
123 | pyplot.loglog(data["density"], data["H2I_density"] / data["density"],
124 | color="red", label="f$_{H2}$"))
125 | pyplot.ylabel("H$_{2}$ fraction")
126 | pyplot.legend(plots, [plot.get_label() for plot in plots],
127 | loc="lower right")
128 | pyplot.tight_layout()
129 | pyplot.savefig(f"{output_name}.png")
130 |
131 | # save data arrays as a yt dataset
132 | yt.save_as_dataset({}, f"{output_name}.h5",
133 | data=data, extra_attrs=extra_attrs)
134 |
--------------------------------------------------------------------------------
/src/python/examples/yt_grackle.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # yt fields for grackle functions
4 | #
5 | #
6 | # Copyright (c) Enzo/Grackle Development Team. All rights reserved.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | import os
15 | import sys
16 | import yt
17 |
18 | from pygrackle import add_grackle_fields
19 | from pygrackle.utilities.data_path import grackle_data_dir
20 | from pygrackle.utilities.model_tests import model_test_format_version
21 |
22 | output_name = os.path.basename(__file__[:-3]) # strip off ".py"
23 |
24 | DS_NAME = "IsolatedGalaxy/galaxy0030/galaxy0030"
25 | ds_path = os.path.join(os.environ.get('YT_DATA_DIR', default='.'), DS_NAME)
26 |
27 | if __name__ == "__main__":
28 | # If we are running the script through the testing framework,
29 | # then we will pass in two integers corresponding to the sets
30 | # of parameters and inputs.
31 | if len(sys.argv) > 1:
32 | par_index = int(sys.argv[1])
33 | input_index = int(sys.argv[2])
34 | output_name = f"{output_name}_{par_index}_{input_index}"
35 | extra_attrs = {"format_version": model_test_format_version}
36 |
37 | if 'YT_DATA_DIR' not in os.environ:
38 | raise RuntimeError(
39 | "YT_DATA_DIR env var must be defined when called by test suite"
40 | )
41 |
42 | # Just run the script as is.
43 | else:
44 | # dictionary to store extra information in output dataset
45 | extra_attrs = {}
46 |
47 | ds = yt.load(ds_path)
48 |
49 | grackle_data_file = os.path.join(grackle_data_dir, "CloudyData_UVB=HM2012.h5")
50 |
51 | grackle_pars = {'grackle_data_file': grackle_data_file,
52 | 'UVbackground': 1,
53 | 'h2_on_dust': 1}
54 |
55 | add_grackle_fields(ds, parameters=grackle_pars)
56 |
57 | sp = ds.sphere(ds.domain_center, (10, 'kpc'))
58 |
59 | fields = [
60 | ("gas", "grackle_cooling_time"),
61 | ("gas", "grackle_gamma"),
62 | ("gas", "grackle_mean_molecular_weight"),
63 | ("gas", "grackle_pressure"),
64 | ("gas", "grackle_temperature"),
65 | ("gas", "grackle_dust_temperature"),
66 | ]
67 | for field in fields:
68 | print (f"{field}: {sp[field]}")
69 |
70 | data = {field: sp[field] for field in fields}
71 | yt.save_as_dataset(ds, filename=f"{output_name}.h5",
72 | data=data, extra_attrs=extra_attrs)
73 |
--------------------------------------------------------------------------------
/src/python/matplotlibrc:
--------------------------------------------------------------------------------
1 | backend : Agg
--------------------------------------------------------------------------------
/src/python/pygrackle/__config__.py.in:
--------------------------------------------------------------------------------
1 | # Pygrackle's build system replaces __config__.py.in with __config__.py
2 | # -> This practice was inspired by numpy and scipy
3 | # -> everything other than __version__, is intended for internal purposes
4 |
5 | from enum import Enum
6 |
7 | __all__ = ["__version__"]
8 |
9 | def _report_error(variable_name, nominal_value, allowed_vals=None):
10 | """A function used to nicely describe any problems with file generation"""
11 |
12 | if allowed_vals is None:
13 | allowed_value_descr = ""
14 | else:
15 | allowed_value_descr = (
16 | f"\n\nKnown allowed values include {allowed_vals!r}. Either the "
17 | "list of allowed values must be updated OR something went wrong."
18 | )
19 |
20 | # we use unicode escape sequence, \u0040, that python automatically
21 | # converts to the "at sign" to avoid unintentional substitutions
22 | raise RuntimeError(
23 | "There appears to have been an issue when pygrackle's build system "
24 | f"generated `{__file__}` from the `{__file__}.in` template file. In "
25 | f"particular, \u0040{variable_name}\u0040 was replaced with an "
26 | f"invalid value of '{nominal_value}'.{allowed_value_descr}"
27 | ) from None
28 |
29 |
30 | # substitute in the version from pyproject.toml
31 | __version__ = "@SKBUILD_PROJECT_VERSION_FULL@"
32 | if (len(__version__) == 0) or __version__[0] == "@":
33 | _report_error("SKBUILD_PROJECT_VERSION_FULL", __version__)
34 |
35 |
36 | def _is_editable_installation():
37 | """Returns whether pygrackle was built as an editable install"""
38 | state = r"@SKBUILD_STATE@"
39 | # allowed values are given by
40 | # https://scikit-build-core.readthedocs.io/en/latest/cmakelists.html#accessing-information
41 | known = ("sdist", "wheel", "editable", "metadata_wheel", "metadata_editable")
42 | # I'm not entirely sure how the internals of scikit-build-core work, but
43 | # it seems to related to the specific hook that the frontend (e.g. pip/uv)
44 | # invoked. It seems unlikely that we'll see "metadata_..." in this file
45 | if state not in known:
46 | _report_error("SKBUILD_STATE", state, known)
47 | return 'editable' in state
48 |
49 |
50 | # specifies how we consumed the grackle library
51 | _GrackleBuild = Enum("_GrackleBuild", "ExternalClassic ExternalCMake Embedded")
52 | try:
53 | _grackle_build = _GrackleBuild[r"@_PYGRACKLE_CONSUME_MODE@"]
54 | except KeyError as err:
55 | _report_error("SKBUILD_STATE", err.args[0], list(_GrackleBuild.__members__))
56 |
--------------------------------------------------------------------------------
/src/python/pygrackle/__init__.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Pygrackle imports
4 | #
5 | #
6 | # Copyright (c) Grackle Development Team. All rights reserved.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | from .__config__ import \
15 | __version__
16 |
17 | from .fluid_container import \
18 | FluidContainer
19 |
20 | from .grackle_wrapper import \
21 | chemistry_data
22 |
23 | from .utilities.convenience import \
24 | setup_fluid_container
25 |
26 | from .utilities.evolve import \
27 | evolve_constant_density, \
28 | evolve_freefall
29 |
30 | from .utilities.units import \
31 | set_cosmology_units
32 |
33 | from .yt_fields import \
34 | add_grackle_fields
35 |
--------------------------------------------------------------------------------
/src/python/pygrackle/api.py:
--------------------------------------------------------------------------------
1 | import warnings
2 |
3 | warnings.warn("Importing from pygrackle.api is deprecated. Import from pygrackle directly.")
4 |
5 | from .fluid_container import FluidContainer, grid_to_grackle
6 | from .grackle_wrapper import \
7 | chemistry_data, solve_chemistry, calculate_cooling_time, \
8 | calculate_gamma, calculate_pressure, calculate_temperature
9 |
--------------------------------------------------------------------------------
/src/python/pygrackle/utilities/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/grackle-project/grackle/bfe0476d8171ce4707b87c5891b0a4ac09bb1d94/src/python/pygrackle/utilities/__init__.py
--------------------------------------------------------------------------------
/src/python/pygrackle/utilities/api.py:
--------------------------------------------------------------------------------
1 | import warnings
2 |
3 | warnings.warn("Importing from pygrackle.utilities.api is deprecated. Import from pygrackle directly.")
4 |
5 | from .convenience import \
6 | setup_fluid_container
7 |
8 | from .evolve import \
9 | evolve_constant_density, \
10 | evolve_freefall, \
11 | calculate_collapse_factor
12 |
13 | from .units import \
14 | set_cosmology_units
15 |
--------------------------------------------------------------------------------
/src/python/pygrackle/utilities/data_path.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Try to get a path to the Grackle input data.
4 | #
5 | #
6 | # Copyright (c) Grackle Development Team. All rights reserved.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | import os
15 |
16 | from pygrackle.__config__ import _is_editable_installation
17 | from pygrackle.utilities.misc import dirname
18 |
19 | if _is_editable_installation():
20 | # Note, this only works with an editable install of pygrackle.
21 | _install_dir = dirname(os.path.abspath(__file__), level=5)
22 | grackle_data_dir = os.path.join(_install_dir, "input")
23 | else:
24 | raise RuntimeError(
25 | "in non-editable pygrackle installations, like this one, "
26 | f"grackle_data_dir cannot be imported from {__file__}."
27 | )
28 |
--------------------------------------------------------------------------------
/src/python/pygrackle/utilities/misc.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # miscellaneous utilities
4 | #
5 | #
6 | # Copyright (c) Grackle Development Team. All rights reserved.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | try:
15 | from numpy import VisibleDeprecationWarning
16 | except ImportError:
17 | from numpy.exceptions import VisibleDeprecationWarning
18 |
19 | import os
20 | import warnings
21 |
22 | def dirname(path, level=1):
23 | """
24 | Multi-level version of os.path.dirname.
25 | """
26 | if not isinstance(level, int) or level < 1:
27 | raise ValueError(
28 | f"level must be a positive integer: {level}.")
29 | for i in range(level):
30 | path = os.path.dirname(path)
31 | return path
32 |
33 | def issue_deprecation_warning(msg, stacklevel=3):
34 | warnings.warn(msg, VisibleDeprecationWarning, stacklevel=stacklevel)
35 |
--------------------------------------------------------------------------------
/src/python/pygrackle/utilities/physical_constants.py:
--------------------------------------------------------------------------------
1 | #
2 | # Physical Constants and Units Conversion Factors
3 | #
4 | # Values for these constants, unless otherwise noted, are drawn from IAU,
5 | # IUPAC, and NIST data, whichever is newer.
6 | # http://maia.usno.navy.mil/NSFA/IAU2009_consts.html
7 | # http://goldbook.iupac.org/list_goldbook_phys_constants_defs.html
8 | # http://physics.nist.gov/cuu/Constants/index.html
9 |
10 | # Masses
11 | mass_electron_cgs = 9.109382e-28 # g
12 | amu_cgs = 1.660538921e-24 # g
13 | mass_hydrogen_cgs = 1.007947*amu_cgs # g
14 | mass_sun_cgs = 1.98841586e33 # g
15 | # Velocities
16 | speed_of_light_cgs = 2.99792458e10 # cm/s, exact
17 |
18 | # Cross Sections
19 | # 8*pi/3 (alpha*hbar*c/(2*pi))**2
20 | cross_section_thompson_cgs = 6.65245854533e-25 # cm^2
21 |
22 | # Charge
23 | charge_proton_cgs = 4.8032056e-10 # esu = 1.602176487e-19 Coulombs
24 |
25 | # Physical Constants
26 | boltzmann_constant_cgs = 1.3806488e-16 # erg K^-1
27 | gravitational_constant_cgs = 6.67384e-8 # cm^3 g^-1 s^-2
28 | planck_constant_cgs = 6.62606957e-27 # erg s
29 | stefan_boltzmann_constant_cgs = 5.670373e-5 # erg cm^-2 s^-1 K^-4
30 | # The following value was calcualted assuming H = 100 km/s/Mpc.
31 | # To get the correct value for your cosmological parameters,
32 | # you'll need to multiply through by h^2
33 | # [where h = H / (100 km/s/Mpc)]. See the Overdensity field in
34 | # yt.data_objects.universal_fields.
35 | rho_crit_now = 1.8788e-29 # g/cm^3 (cosmological critical density)
36 |
37 |
38 | # Misc. Approximations
39 | mass_mean_atomic_cosmology = 1.22
40 | mass_mean_atomic_galactic = 2.3
41 |
42 | # Conversion Factors: X au * mpc_per_au = Y mpc
43 | # length
44 | mpc_per_mpc = 1e0
45 | mpc_per_kpc = 1e-3
46 | mpc_per_pc = 1e-6
47 | mpc_per_au = 4.84813682e-12
48 | mpc_per_rsun = 2.253962e-14
49 | mpc_per_miles = 5.21552871e-20
50 | mpc_per_km = 3.24077929e-20
51 | mpc_per_cm = 3.24077929e-25
52 | kpc_per_cm = mpc_per_cm / mpc_per_kpc
53 | km_per_pc = 3.08567758e13
54 | km_per_m = 1e-3
55 | km_per_cm = 1e-5
56 | pc_per_cm = 3.24077929e-19
57 |
58 | m_per_fpc = 0.0324077929
59 |
60 | kpc_per_mpc = 1.0 / mpc_per_kpc
61 | pc_per_mpc = 1.0 / mpc_per_pc
62 | au_per_mpc = 1.0 / mpc_per_au
63 | rsun_per_mpc = 1.0 / mpc_per_rsun
64 | miles_per_mpc = 1.0 / mpc_per_miles
65 | km_per_mpc = 1.0 / mpc_per_km
66 | cm_per_mpc = 1.0 / mpc_per_cm
67 | cm_per_kpc = 1.0 / kpc_per_cm
68 | cm_per_km = 1.0 / km_per_cm
69 | pc_per_km = 1.0 / km_per_pc
70 | cm_per_pc = 1.0 / pc_per_cm
71 |
72 | # time
73 | # "IAU Style Manual" by G.A. Wilkins, Comm. 5, in IAU Transactions XXB (1989)
74 | sec_per_Gyr = 31.5576e15
75 | sec_per_Myr = 31.5576e12
76 | sec_per_kyr = 31.5576e9
77 | sec_per_year = 31.5576e6
78 | sec_per_day = 86400.0
79 | sec_per_hr = 3600.0
80 | day_per_year = 365.25
81 |
82 | # temperature / energy
83 | erg_per_eV = 1.602176562e-12
84 | erg_per_keV = erg_per_eV * 1.0e3
85 | K_per_keV = erg_per_keV / boltzmann_constant_cgs
86 | keV_per_K = 1.0 / K_per_keV
87 |
88 | #Short cuts
89 | G = gravitational_constant_cgs
90 | me = mass_electron_cgs
91 | mp = mass_hydrogen_cgs
92 | qp = charge_proton_cgs
93 | mh = mp
94 | clight = speed_of_light_cgs
95 | kboltz = boltzmann_constant_cgs
96 | hcgs = planck_constant_cgs
97 | sigma_thompson = cross_section_thompson_cgs
98 | Na = 1 / amu_cgs
99 |
--------------------------------------------------------------------------------
/src/python/pygrackle/utilities/testing.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Testing imports
4 | #
5 | #
6 | # Copyright (c) 2013, Enzo/Grackle Development Team.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | import importlib
15 | import numpy as np
16 | from numpy.testing import assert_array_equal, assert_almost_equal, \
17 | assert_approx_equal, assert_array_almost_equal, assert_equal, \
18 | assert_array_less, assert_string_equal, assert_array_almost_equal_nulp,\
19 | assert_allclose, assert_raises
20 | import os
21 | import shutil
22 | import subprocess
23 |
24 | def assert_rel_equal(a1, a2, decimals, err_msg='', verbose=True):
25 | if isinstance(a1, np.ndarray):
26 | assert(a1.size == a2.size)
27 | # Mask out NaNs
28 | a1[np.isnan(a1)] = 1.0
29 | a2[np.isnan(a2)] = 1.0
30 | elif np.any(np.isnan(a1)) and np.any(np.isnan(a2)):
31 | return True
32 | return assert_almost_equal(np.array(a1)/np.array(a2), 1.0,
33 | decimals, err_msg=err_msg,
34 | verbose=verbose)
35 |
36 | def random_logscale(log_min, log_max, size=1, random_state=None):
37 | if random_state is None:
38 | random_state = np.random.default_rng()
39 | log_val = (log_max - log_min) * random_state.random(size) + log_min
40 | return np.power(10, log_val)
41 |
42 | def requires_module(module):
43 | """
44 | Decorator that takes a module name as an argument and tries to import it.
45 | If the module imports without issue, the function is returned, but if not,
46 | a null function is returned. This is so tests that depend on certain modules
47 | being imported will not fail if the module is not installed on the testing
48 | platform.
49 | """
50 | def ffalse(func):
51 | return lambda: None
52 | def ftrue(func):
53 | return func
54 | try:
55 | importlib.import_module(module)
56 | except ImportError:
57 | return ffalse
58 | else:
59 | return ftrue
60 |
61 | def run_command(command, timeout=None, cwd=None):
62 | try:
63 | proc = subprocess.run(command, shell=True, timeout=timeout, cwd=cwd)
64 | if proc.returncode == 0:
65 | success = True
66 | else:
67 | success = False
68 | except subprocess.TimeoutExpired:
69 | print ("Process reached timeout of %d s. (%s)" % (timeout, command))
70 | success = False
71 | except KeyboardInterrupt:
72 | print ("Killed by keyboard interrupt!")
73 | success = False
74 | return success
75 |
--------------------------------------------------------------------------------
/src/python/pygrackle/utilities/units.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Units helper functions
4 | #
5 | #
6 | # Copyright (c) 2013, Enzo/Grackle Development Team.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | import numpy as np
15 |
16 | def set_cosmology_units(my_units, hubble_constant=0.704,
17 | omega_matter=0.268, omega_lambda=0.732,
18 | current_redshift=0.0, initial_redshift=0.0,
19 | comoving_box_size=1.0):
20 | r"""
21 | Set cosmological units like Enzo.
22 |
23 | Greg Bryan's note on cosmology units:
24 |
25 | time: utim = 1 / sqrt(4 * \pi * G * \rho_0 * (1+zri)^3)
26 | density: urho = \rho_0 * (1+z)^3
27 | length: uxyz = (1 Mpc) * box / h / (1+z)
28 | velocity: uvel = uaye * (uxyz / a) / utim (since u = a * dx/dt)
29 | (*) temperature: utem = m_H * \mu / k * uvel**2
30 | a(t): uaye = 1 / (1 + zri)
31 |
32 | where:
33 | box - size of simulation box in Mpc/h
34 | zri - initial redshift (start of simulation)
35 | \rho_0 = 3*\Omega_0*H_0^2/(8*\pi*G)
36 | Omega_0 - the fraction of non-relativistic matter at z=0
37 |
38 | Note that two definitions are dependent on redshift (urho
39 | and uxyz) so make sure to call this routine immediately
40 | before writing.
41 |
42 | * - the utem given below assumes that \mu = 1, so you must
43 | multiply the resulting temperature field by \mu.
44 | """
45 |
46 | my_units.comoving_coordinates = 1
47 | my_units.a_units = 1. / (1. + initial_redshift)
48 | my_units.a_value = 1.0 / (1.0 + current_redshift) / \
49 | my_units.a_units
50 | my_units.density_units = 1.8788e-29 * omega_matter * \
51 | np.power(hubble_constant, 2) * np.power(1 + current_redshift, 3)
52 | my_units.length_units = 3.085678e24 * comoving_box_size / \
53 | hubble_constant / (1. + current_redshift)
54 | my_units.time_units = 2.519445e17 / np.sqrt(omega_matter) / \
55 | hubble_constant / np.power(1 + initial_redshift, 1.5)
56 | my_units.velocity_units = 1.22475e7 * comoving_box_size * \
57 | np.sqrt(omega_matter) * np.sqrt(1 + initial_redshift)
58 |
--------------------------------------------------------------------------------
/src/python/setup.cfg:
--------------------------------------------------------------------------------
1 | [flake8]
2 | max-line-length = 999
3 | exclude = pygrackle/api.py,pygrackle/__init__.py,pygrackle/utilities/testing.py,pygrackle/utilities/api.py
4 | ignore = E111,E121,E122,E123,E124,E125,E127,E129,E131,E201,E202,E211,E221,E222,E227,E228,E241,E301,E203,E225,E226,E231,E251,E261,E262,E265,E266,E302,E303,E402,E502,E701,E731,W292,W293,W391,W503,W504
5 |
--------------------------------------------------------------------------------
/src/python/tests/conftest.py:
--------------------------------------------------------------------------------
1 | # this defines some basic utilities shared among all of the tests
2 | #
3 | # DO NOT import pygrackle into global scope in this file (or in any file
4 | # imported by this file). Some tests need to be runable without installing
5 | # pygrackle
6 |
7 | import os
8 | from typing import NamedTuple
9 |
10 | import pytest
11 |
12 |
13 | # this hook is used to add more command line flags to the pytest launcher
14 | def pytest_addoption(parser):
15 | parser.addoption(
16 | "--answer-dir",
17 | action="store",
18 | default=None,
19 | help=(
20 | "Path to directory used for storing answer-tests answers. All "
21 | "logic related to answer-tests is disabled unless this is "
22 | "specified. When specified alonside --answer-store, logic to "
23 | "generate the answers will be run (the answers are stored to this "
24 | "directory). When specified WITHOUT --answer-store, the results "
25 | "of each answer-test is compared against the answers that were "
26 | "previously stored in this directory."
27 | )
28 | )
29 |
30 | parser.addoption(
31 | "--answer-store",
32 | action="store_true",
33 | help=(
34 | "Indicates that we should store answer-test results. It is an "
35 | "error to specifiy this arg without --answer-dir."
36 | ),
37 | )
38 |
39 |
40 | class AnswerTestSpec(NamedTuple):
41 | generate_answers: bool
42 | answer_dir: str
43 |
44 |
45 | @pytest.fixture(scope="session")
46 | def answertestspec(request):
47 | """
48 | Return an object specifying all user-specified directives regarding
49 | answer tests (whether to run them and where to store/find results)
50 | """
51 |
52 | generate_answers = request.config.getoption("--answer-store")
53 |
54 | answer_dir = request.config.getoption("--answer-dir")
55 |
56 | if (answer_dir is None) and generate_answers:
57 | raise ValueError(
58 | "--answer-store option can't be specified without --answer-dir"
59 | )
60 | elif answer_dir is None:
61 | pytest.skip("no --answer-dir option found")
62 | elif (not os.path.isdir(answer_dir)) and (not generate_answers):
63 | pytest.skip(f"directory of test answers can't be found, {answer_dir}")
64 | else:
65 | os.makedirs(answer_dir, exist_ok=True)
66 |
67 | return AnswerTestSpec(generate_answers=generate_answers, answer_dir=answer_dir)
68 |
--------------------------------------------------------------------------------
/src/python/tests/test_data:
--------------------------------------------------------------------------------
1 | ../../../grackle_data_files/testing
--------------------------------------------------------------------------------
/src/python/tests/test_dynamic_api.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Test the API for dynamically accessing fields of chemistry_data
4 | #
5 | #
6 | # Copyright (c) 2013, Enzo/Grackle Development Team.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | from numpy.testing import assert_raises
15 |
16 | from pygrackle import chemistry_data
17 |
18 | from pygrackle.grackle_wrapper import _wrapped_c_chemistry_data
19 |
20 | def _test_dynamic_api(param_list, ok_vals, bad_vals, expected_output_type):
21 | # test that the chemistry_data() class supports access to an attribute
22 | # named for element in key_list.
23 | #
24 | # most other tests of chemistry_data() also implicitly test the dynamic_api
25 |
26 | def _check_expected_type(param, val):
27 | if not isinstance(val, expected_output_type):
28 | raise AssertionError(
29 | f"expected '{param}' to be an instance of "
30 | f"'{expected_output_type.__name__}', not an instance of "
31 | f"'{type(val).__name__}'"
32 | )
33 |
34 | obj = chemistry_data()
35 | for param in param_list:
36 | val = getattr(obj, param)
37 | _check_expected_type(param, val)
38 |
39 | for val_to_set in ok_vals:
40 | setattr(obj, param, val_to_set)
41 | val = getattr(obj, param)
42 | _check_expected_type(param, val)
43 |
44 | # check equality between val_to_set and val
45 | if isinstance(val_to_set, str) and (expected_output_type == bytes):
46 | assert val.decode('ascii') == val_to_set
47 | else:
48 | assert val == val_to_set
49 |
50 | # confirm that setting param to invalid values will raise TypeError
51 | for val_to_set in bad_vals:
52 | with assert_raises(TypeError):
53 | setattr(obj, param, val_to_set)
54 |
55 | def test_dynamic_api_int():
56 | _test_dynamic_api(_wrapped_c_chemistry_data.int_keys(),
57 | [342], [2.5, 'my string'], int)
58 |
59 | def test_dynamic_api_double():
60 | _test_dynamic_api(_wrapped_c_chemistry_data.double_keys(),
61 | [342, 2.0], ['my string'], float)
62 |
63 | def test_dynamic_api_string():
64 | _test_dynamic_api(_wrapped_c_chemistry_data.string_keys(),
65 | [b'dummy_bytes', 'dummy_str'], [1, 3.0], bytes)
66 |
--------------------------------------------------------------------------------
/src/python/tests/test_get_grackle_version.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Volumetric heating rate tests
4 | #
5 | #
6 | # Copyright (c) Grackle Development Team. All rights reserved.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 | from pygrackle.grackle_wrapper import get_grackle_version
15 | from packaging.version import Version, InvalidVersion
16 |
17 | import os
18 | import subprocess
19 |
20 | def query_grackle_version_props():
21 | # retrieve the current version information with git
22 |
23 | cur_dir = os.path.dirname(os.path.abspath(__file__))
24 |
25 | def _run(args):
26 | _rslt = subprocess.run(
27 | args, cwd=cur_dir, check=True, capture_output=True,
28 | )
29 | return _rslt.stdout.decode().rstrip()
30 |
31 | # get the name of the most recent tag preceeding this commit:
32 | most_recent_tag = _run(["git", "describe", "--abbrev=0", "--tags"])
33 | if most_recent_tag.startswith("grackle-"):
34 | latest_tagged_version = most_recent_tag[8:]
35 | elif most_recent_tag.startswith("gold-standard-v"):
36 | latest_tagged_version = most_recent_tag[15:]
37 | else:
38 | raise RuntimeError(
39 | "expected the most recent git-tag to start with "
40 | "'grackle-' or 'gold-standard-v'"
41 | )
42 |
43 | # get the actual revision when most_recent tag was introduced
44 | revision_of_tag = _run(["git", "rev-parse", "-n", "1", most_recent_tag])
45 |
46 | # get the branch name and current revision
47 | branch = _run(["git", "rev-parse", "--abbrev-ref", "HEAD"])
48 |
49 | revision = _run(["git", "rev-parse", "HEAD"])
50 |
51 | tagged_on_current_revision = revision == revision_of_tag
52 | return latest_tagged_version, branch, revision, tagged_on_current_revision
53 |
54 | def test_get_grackle_version():
55 | # this test assumes that Grackle was compiled with the currently checked
56 | # out version of the repository
57 |
58 | latest_tagged_version, branch, revision, tagged_on_current_revision \
59 | = query_grackle_version_props()
60 |
61 | # perform the easy checks
62 | results = get_grackle_version()
63 | if (len(results) != 3):
64 | raise RuntimeError(
65 | "get_grackle_version should return a dictionary with the 3 items"
66 | )
67 | elif results['branch'] != branch:
68 | raise RuntimeError(
69 | f"expected get_grackle_version()['branch'] to be '{branch}', not "
70 | f"'{results['branch']}'. Was a different branch of the repository "
71 | "checked out when the c library was compiled?"
72 | )
73 | elif results['revision'] != revision:
74 | raise RuntimeError(
75 | f"expected get_grackle_version()['revision'] to be '{revision}', "
76 | f"not '{results['revision']}'. Was a different revision of the "
77 | "repository checked out when the c library was compiled?"
78 | )
79 |
80 | # Check the formatting of the version strings (given by the tag of the most
81 | # recently tagged commit and given by get_grackle_version()['version'])
82 |
83 | description_string_pairs = [
84 | ("get_grackle_version()['version']", results['version']),
85 | ("the tag of the most recently tagged commit", latest_tagged_version)
86 | ]
87 |
88 | version_objects = []
89 | for description, str_val in description_string_pairs:
90 | try:
91 | # parse is fairly permissive about the file format
92 | version_objects.append(Version(str_val))
93 | except InvalidVersion:
94 | raise RuntimeError(
95 | f"The value given by {description}, {str_val!r}, doesn't have "
96 | "the expected formatting."
97 | )
98 | # Could add checks enforce other conventions here
99 |
100 | rslt_version_obj, latest_tagged_version_obj = version_objects
101 |
102 | # now check the consistency between the version numbers
103 | if tagged_on_current_revision:
104 | if results['version'] != latest_tagged_version:
105 | raise RuntimeError(
106 | "expected get_grackle_version()['version'] to be "
107 | f"{latest_tagged_version!r}, not {results['version']!r}.\n\n"
108 | "Did you tag a commit with a new version number & forget to "
109 | "update the version used by the Makefile?"
110 | )
111 | elif latest_tagged_version_obj >= rslt_version_obj:
112 | raise RuntimeError(
113 | "Something is wrong. The version number given by "
114 | f"get_grackle_version()['version'], {results['version']!r}, must "
115 | "exceed the version number encoded in the tag of the most recently "
116 | f"tagged git commit, {latest_tagged_version!r}.\n\n"
117 | "Did you update the version used by the Makefile & forget to "
118 | "update the commit's tag?"
119 | )
120 |
--------------------------------------------------------------------------------
/src/python/tests/test_models.py:
--------------------------------------------------------------------------------
1 | import os
2 | import pytest
3 | import sys
4 | import yt
5 |
6 | from numpy.testing import assert_allclose
7 |
8 | from pygrackle.__config__ import _is_editable_installation
9 | from pygrackle.utilities.model_tests import model_sets
10 | from pygrackle.utilities.testing import run_command
11 |
12 | from testing_common import grackle_python_dir
13 |
14 | pytestmark = pytest.mark.skipif(
15 | not _is_editable_installation(),
16 | reason="this module currently requires an editable installation"
17 | )
18 |
19 | python_example_dir = os.path.join(grackle_python_dir, "examples")
20 |
21 | # collect all of the python-examples and various model configurations into
22 | # a list of tuples
23 | all_sets = []
24 | for model_name, model in model_sets.items():
25 | for par_index in range(len(model["parameter_sets"])):
26 | for input_index in range(len(model["input_sets"])):
27 | all_sets.append((model_name, par_index, input_index))
28 |
29 | @pytest.mark.parametrize("model_name, par_index, input_index", all_sets)
30 | def test_model(answertestspec, tmp_path, model_name, par_index, input_index):
31 | """
32 | Each execution tests a python example with a set of inputs
33 |
34 | Each of the parameters down below is a fixture
35 |
36 | Parameters
37 | ----------
38 | answertestspec: AnswerTestSpec
39 | A fixture that provides info about the answer-testing configuration
40 | tmp_path: pathlib.Path
41 | A custom built-in fixture provided by pytest that specifies a pre-made
42 | temporary directory that is named for the current test
43 | """
44 |
45 | if (model_name == "yt_grackle") and ("YT_DATA_DIR" not in os.environ):
46 | pytest.skip("YT_DATA_DIR env variable isn't defined")
47 |
48 | script_path = os.path.join(python_example_dir, f"{model_name}.py")
49 | command = f"{sys.executable} {script_path} {par_index} {input_index}"
50 |
51 | if True:
52 | rval = run_command(command, timeout=60, cwd=tmp_path)
53 | assert rval, "example didn't complete succesfully"
54 |
55 | output_basename = f"{model_name}_{par_index}_{input_index}.h5"
56 | output_file = os.path.join(str(tmp_path), output_basename)
57 | answer_path = os.path.join(answertestspec.answer_dir, output_basename)
58 |
59 | if answertestspec.generate_answers:
60 | os.rename(output_file, answer_path)
61 | else:
62 | assert os.path.exists(answer_path)
63 |
64 | ds1 = yt.load(output_file)
65 | ds2 = yt.load(answer_path)
66 | ds1.parameters["format_version"] == ds2.parameters["format_version"]
67 | assert ds1.field_list == ds2.field_list
68 |
69 | for field in ds1.field_list:
70 | err_msg = f"Model mismatch: {model_name}, {par_index}, " + \
71 | f"{input_index}: {field}."
72 | assert_allclose(ds1.data[field], ds2.data[field],
73 | atol=0, rtol=1e-8, err_msg=err_msg)
74 |
--------------------------------------------------------------------------------
/src/python/tests/testing_common.py:
--------------------------------------------------------------------------------
1 | ########################################################################
2 | #
3 | # Common variables for testing.
4 | #
5 | #
6 | # Copyright (c), Grackle Development Team. All rights reserved.
7 | #
8 | # Distributed under the terms of the Enzo Public Licence.
9 | #
10 | # The full license is in the file LICENSE, distributed with this
11 | # software.
12 | ########################################################################
13 |
14 |
15 | import os
16 |
17 | from pygrackle.utilities.misc import dirname
18 |
19 | grackle_install_dir = dirname(os.path.abspath(__file__), level=4)
20 | grackle_data_dir = os.path.join(grackle_install_dir, "input")
21 | grackle_python_dir = os.path.join(grackle_install_dir, "src", "python")
22 |
--------------------------------------------------------------------------------
/tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory(unit)
2 |
3 | # down below, we add tests for various code-examples
4 |
5 | # determine the path to the script used to assist with tests of code examples
6 | set(checker_script ${CMAKE_CURRENT_LIST_DIR}/scripts/code_example_checker.py)
7 |
8 | # Dealing with hard-coded paths to data-files
9 | # -------------------------------------------
10 | # These tests are complicated by the fact that code-examples all hard-code
11 | # (relative) paths to data-files.
12 | #
13 | # Here we implement a 2-part stop-gap solution to gracefully handle these cases
14 | # (The rigorously correct solution will be possible once PRs #235, #237, and
15 | # #246 are merged into Grackle)
16 | #
17 | # Part 1) we launch all of the tests from the source-directory including the
18 | # source-code files
19 | # -> while we tried to configure the build system in such a way that the
20 | # code-example binaries can be executed from the directory where the
21 | # binaries are placed. But, this makes 2 assumptions:
22 | # (1) that Grackle is the top-level project
23 | # (2) the Grackle build directory's parent directory is the root-directory
24 | # of the Grackle repository
25 | # -> executing the code-examples from the src-directory during testing will be
26 | # more rigorous. It should work when Grackle is compiled as part of a larger
27 | # project
28 | set(example_exec_dir ${PROJECT_SOURCE_DIR}/src/example)
29 | #
30 | # Part 2) we perform a prerequisite test confirming that the assumed data file
31 | # actually exists (i.e. if Grackle's submodules got cloned).
32 | # -> we use ctest's fixture machinery to gracefully skip other tests if this
33 | # one fails
34 | # -> as a bonus, this confirms that the script used to run most of these tests
35 | # is working properly
36 |
37 | add_test(
38 | NAME GrExample.SatisfyPrereqs
39 | COMMAND ${checker_script} datacheck
40 | --exec-dir ${example_exec_dir}
41 | --assumed-data-path ../../input/CloudyData_UVB=HM2012.h5
42 | )
43 | set_tests_properties(GrExample.SatisfyPrereqs PROPERTIES
44 | FIXTURES_SETUP GREXAMPLE_PREREQS
45 | )
46 |
47 | # this case simply runs the example with 4 openmp threads
48 | if (GRACKLE_USE_OPENMP)
49 | add_test(NAME GrExample.cmp_omp
50 | COMMAND cxx_omp_example
51 | WORKING_DIRECTORY ${example_exec_dir}
52 | )
53 | set_tests_properties(GrExample.cmp_omp PROPERTIES
54 | ENVIRONMENT "OMP_NUM_THREADS=4"
55 | FIXTURES_REQUIRED GREXAMPLE_PREREQS
56 | DISABLED ${GRACKLE_USE_OPENMP}
57 | )
58 | endif()
59 |
60 | # the remaining tests are more rigorous:
61 | #
62 | # first, we check the results of c_example against the historical results
63 | # (which we previously recorded to a JSON file)
64 | # -> we may need to loosen up rtol so that this works across machines
65 | # -> if we ever need to regenerate the reference JSON file, we can run
66 | # `code_example_checker.py genjson --target --output `
67 | add_test(
68 | NAME GrExampleHistoricalCMP.c
69 | COMMAND ${checker_script} cmp
70 | --target $
71 | --ref ${CMAKE_CURRENT_LIST_DIR}/scripts/c_example_ref.json
72 | --rtol 6e-14
73 | --exec-timeout 10
74 | --exec-dir ${example_exec_dir}
75 | )
76 | set_tests_properties(GrExampleHistoricalCMP.c PROPERTIES
77 | FIXTURES_REQUIRED GREXAMPLE_PREREQS
78 | )
79 |
80 | # the remaining tests compare the results printed by various code examples
81 | # against each other. In general, there should be no differences in the
82 | # results
83 | add_test(
84 | NAME GrExampleCMP.c_local
85 | COMMAND ${checker_script} cmp
86 | --target $
87 | --ref $
88 | --exec-timeout 10
89 | --exec-dir ${example_exec_dir}
90 | )
91 | set_tests_properties(GrExampleCMP.c_local PROPERTIES
92 | FIXTURES_REQUIRED GREXAMPLE_PREREQS
93 | )
94 |
95 | add_test(
96 | NAME GrExampleCMP.cxx
97 | COMMAND ${checker_script} cmp
98 | --target $
99 | --ref $
100 | --exec-timeout 10
101 | --exec-dir ${example_exec_dir}
102 | )
103 | set_tests_properties(GrExampleCMP.cxx PROPERTIES
104 | FIXTURES_REQUIRED GREXAMPLE_PREREQS
105 | )
106 |
107 | if (TARGET fortran_example)
108 | # we allow for the Fortran to deviate from c_example to a small degree
109 | # -> to require an exact match, we probably need to rewrite all of the
110 | # examples so that they use hardcoded values
111 | add_test(
112 | NAME GrExampleCMP.fortran
113 | COMMAND ${checker_script} cmp
114 | --target $
115 | --ref $
116 | --rtol 6e-7
117 | --exec-timeout 10
118 | --exec-dir ${example_exec_dir}
119 | )
120 | set_tests_properties(GrExampleCMP.fortran PROPERTIES
121 | FIXTURES_REQUIRED GREXAMPLE_PREREQS
122 | )
123 | endif()
124 |
125 |
--------------------------------------------------------------------------------
/tests/README.rst:
--------------------------------------------------------------------------------
1 | Overview
2 | ========
3 |
4 | The contents of this directory are used to run the test suite associated with the core Grackle library.
5 | These tests are completely unrelated to the ``pytest`` testing suite.
6 |
--------------------------------------------------------------------------------
/tests/scripts/c_example_ref.json:
--------------------------------------------------------------------------------
1 | {
2 | "cooling_time": [
3 | -217289667699831.0,
4 | "s"
5 | ],
6 | "dust_temperature": [
7 | 40.83270717809425,
8 | "K"
9 | ],
10 | "gamma": [
11 | 1.666543353010762,
12 | "dimensionless"
13 | ],
14 | "pressure": [
15 | 3.285492067445912e-13,
16 | "dyne/cm^2"
17 | ],
18 | "temperature": [
19 | 2550.790222064882,
20 | "K"
21 | ]
22 | }
--------------------------------------------------------------------------------
/tests/scripts/castxml_wrapper.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | """
3 | This forwards the arguments on to castxml, if the castxml is installed. Otherwise
4 | it puts an empty output file at the specified location
5 | """
6 |
7 | import shutil
8 | import subprocess
9 | import sys
10 |
11 | _PROG = "castxml"
12 |
13 |
14 | def _get_output_location(args):
15 | for i, arg in enumerate(args):
16 | if arg == "-o" and i + 1 < len(args):
17 | return args[i + 1]
18 |
19 |
20 | if __name__ == "__main__":
21 | if shutil.which(_PROG) is None:
22 | output_location = _get_output_location(sys.argv)
23 | if output_location is None:
24 | sys.exit(1)
25 | f = open(output_location, "w") # <- truncates file if it exists
26 | f.close()
27 | sys.exit(0)
28 | else:
29 | code = subprocess.run([_PROG] + sys.argv[1:]).returncode
30 | sys.exit(code)
31 |
--------------------------------------------------------------------------------
/tests/unit/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # declare testdeps to bundle together dependencies used by all tests
2 | # ------------------------------------------------------------------
3 | add_library(testdeps INTERFACE)
4 | target_link_libraries(testdeps INTERFACE Grackle::Grackle GTest::gtest_main)
5 |
6 | # short-term hack to let tests invoke Fortran functions from C
7 | target_compile_definitions(testdeps INTERFACE "$<$:LINUX>")
8 | target_include_directories(testdeps INTERFACE ${PROJECT_SOURCE_DIR}/src/clib)
9 |
10 | # declare the grtest utility library
11 | # ----------------------------------
12 | # -> this is an internal library that defines reusable testing utilities
13 | # -> if we add more files to this library, we should consider relocating the
14 | # library to a different directory
15 |
16 | add_library(grtest_utils
17 | grtest_cmd.hpp grtest_cmd.cpp
18 | grtest_utils.hpp grtest_utils.cpp
19 | )
20 | # we are being a little lazy with our usage of testdeps right here
21 | target_link_libraries(grtest_utils PUBLIC testdeps)
22 | target_compile_features(grtest_utils PUBLIC cxx_std_17)
23 |
24 | # these compile-definitions act as short-term hacks
25 | target_compile_definitions(grtest_utils
26 | # this hack helps us get path input-file directory (we can remove it once we
27 | # introduce automatic file management in PR 235, PR 237, and PR 246)
28 | PRIVATE GR_DATADIR=${CMAKE_CURRENT_SOURCE_DIR}/../../grackle_data_files/input/
29 |
30 | # this hack lets us use Operating-system specific functionality (Once PR #237
31 | # is merged, we should make use of the machinery introduced by that PR for
32 | # enabling/disabling os-specific features)
33 | PRIVATE "$<$:PLATFORM_GENERIC_UNIX>"
34 | )
35 |
36 | # start declaring targets for tests
37 | # ---------------------------------
38 | add_executable(runInterpolationTests test_unit_interpolators_g.cpp)
39 | target_link_libraries(runInterpolationTests testdeps)
40 |
41 | gtest_discover_tests(runInterpolationTests)
42 |
43 | # one might argue that the following is more of an integration or end-to-end
44 | # test than a unit-test
45 | add_executable(runGhostZoneTests test_ghost_zone.cpp)
46 | target_link_libraries(runGhostZoneTests grtest_utils testdeps)
47 | gtest_discover_tests(runGhostZoneTests)
48 |
49 |
50 | # this target tests that the members of the chemistry_data struct can be
51 | # accessed through the "dynamic api." The test cases in this target are
52 | # "special" since they invoke shell commands, which involves the equivalent of
53 | # calling fork/exec or posix_spawn. There is a remote chance this could create
54 | # problems for "death-tests", so these test-cases should remain separate from
55 | # the rest of the gtest framework
56 | add_executable(runSyncedChemistryData test_chemistry_struct_synced.cpp)
57 | target_link_libraries(runSyncedChemistryData grtest_utils testdeps)
58 | target_compile_definitions(runSyncedChemistryData
59 | PRIVATE
60 | READER_PATH=${PROJECT_SOURCE_DIR}/tests/scripts/castxml_output_reader.py
61 | XML_PATH=${CMAKE_CURRENT_BINARY_DIR}/grackle.h.xml
62 | )
63 | # every (re)build runSyncedChemistryData triggers this custom command:
64 | # -> the castxml_wrapper.py script forwards all arguments to the castxml tool,
65 | # if the tool is installed. Otherwise, it injects an empty file at the output
66 | # location
67 | # -> the information in the XML-file is always produced from the same version of
68 | # the header file used to compile runSyncedChemistryData (even if the header
69 | # file is modified)
70 | add_custom_command(
71 | TARGET runSyncedChemistryData POST_BUILD
72 | COMMAND ${PROJECT_SOURCE_DIR}/tests/scripts/castxml_wrapper.py
73 | -c
74 | -I${GRACKLE_GENERATED_PUBLIC_HEADERS}
75 | -x c++
76 | --castxml-cc-gnu g++
77 | --castxml-output=1
78 | -o "grackle.h.xml"
79 | ${PROJECT_SOURCE_DIR}/src/include/grackle.h
80 | BYPRODUCTS "grackle.h.xml"
81 | VERBATIM
82 | )
83 |
84 | gtest_discover_tests(runSyncedChemistryData)
85 |
--------------------------------------------------------------------------------
/tests/unit/grtest_cmd.cpp:
--------------------------------------------------------------------------------
1 | #include "grtest_cmd.hpp"
2 |
3 | #include // FILE, fgets, fprintf, stderr, (popen/pclose on POSIX)
4 |
5 | #include // std::exit
6 | #include // std::stringstream
7 | #include
8 |
9 | // TODO: replace with Grackle's existing err machinery
10 | [[noreturn]] static void err_(std::string msg="") {
11 | const char* ptr = (msg.size() == 0) ? "" : msg.c_str();
12 | fprintf(stderr, "ERROR: %s\n", ptr);
13 | std::exit(1);
14 | }
15 |
16 | #ifdef PLATFORM_GENERIC_UNIX
17 |
18 | #define TEMP_BUF_SIZE 128
19 |
20 | grtest::ProcessStatusAndStdout grtest::capture_status_and_output(
21 | const std::string& command
22 | ) {
23 | // note: there are negligible portability benefits to using the `system`
24 | // function instead of `popen` since we would need the `WIFEXITED` &
25 | // `WEXITSTATUS` macros (provided by POSIX) to interpret the value returned
26 | // by `system`
27 | std::stringstream buf;
28 | char temp_buf[TEMP_BUF_SIZE];
29 |
30 | // fp represents a buffered pipe to the standard output of the command.
31 | FILE* fp = popen(command.data(), "r");
32 | if (fp == nullptr) { err_("there was a problem launching the command"); }
33 |
34 | // if our reads from the pipe outpace the rate at which the command writes to
35 | // the pipe, fgets won't return until more data becomes available. If the
36 | // processess ends, fgets encounters EOF (causing fgets to return)
37 | while (fgets(temp_buf, TEMP_BUF_SIZE, fp) != nullptr) { buf << temp_buf; }
38 | int status = pclose(fp);
39 | if (status == -1) { err_("there was a problem closing the command"); }
40 | return {status, buf.str()};
41 | }
42 |
43 | #else
44 |
45 | grtest::ProcessStatusAndStdout grtest::capture_status_and_output(
46 | const std::string& command
47 | ) {
48 | err_("not implemented on this platform");
49 | }
50 |
51 | #endif /* PLATFORM_GENERIC_UNIX */
52 |
--------------------------------------------------------------------------------
/tests/unit/grtest_cmd.hpp:
--------------------------------------------------------------------------------
1 | #ifndef GRTEST_CMD_H
2 | #define GRTEST_CMD_H
3 |
4 | #include
5 |
6 | namespace grtest {
7 |
8 | /// Encapsulates the result of launching a process
9 | struct ProcessStatusAndStdout {
10 | /// negative val indicates the process didn't terminate normally. Otherwise,
11 | /// it holds the process's exit-code
12 | int status;
13 | /// data captured from stdout
14 | std::string stdout_str;
15 | };
16 |
17 |
18 | /// Executes the specified command (it is passed to the Shell), waits for it to
19 | /// complete, & returns the captured status and stdout.
20 | ///
21 | /// @note
22 | /// The child process's stderr is inherited from the parent
23 | ProcessStatusAndStdout capture_status_and_output(const std::string& command);
24 |
25 | } // grtest
26 |
27 | #endif /* GRTEST_CMD_H */
28 |
--------------------------------------------------------------------------------
/tests/unit/grtest_utils.cpp:
--------------------------------------------------------------------------------
1 | #include "grtest_utils.hpp"
2 |
3 | #include
4 |
5 | // the goal here is to make it easy to initialize chemistry_data without
6 | // proliferating the GR_DATADIR macro throughout the test-code
7 | // -> the GR_DATADIR macro is specified as a compiler arg and it specifies the
8 | // path to the data-directory
9 |
10 | #define stringify(s) stringify_helper(s)
11 | #define stringify_helper(s) #s
12 |
13 | #define N_STANDARD_DATAFILES 7
14 |
15 | static const char* const standard_data_files[N_STANDARD_DATAFILES] = {
16 | stringify(GR_DATADIR) "/CloudyData_UVB=FG2011.h5",
17 | stringify(GR_DATADIR) "/CloudyData_UVB=FG2011_shielded.h5",
18 | stringify(GR_DATADIR) "/CloudyData_UVB=HM2012.h5",
19 | stringify(GR_DATADIR) "/CloudyData_UVB=HM2012_high_density.h5",
20 | stringify(GR_DATADIR) "/CloudyData_UVB=HM2012_shielded.h5",
21 | stringify(GR_DATADIR) "/CloudyData_noUVB.h5",
22 | stringify(GR_DATADIR) "/cloudy_metals_2008_3D.h5"
23 | };
24 |
25 | bool grtest::set_standard_datafile(
26 | chemistry_data& my_chemistry, const char* datafile
27 | ) {
28 |
29 | if (datafile==NULL) {
30 | return false; // we should probably abort the program with an error
31 | }
32 |
33 | // we get the number of characters in the prefix-path
34 | // -> strlen does not include the null character
35 | // -> we add 1 because we always insert a '/' between the prefix and the
36 | // file's basename
37 | std::size_t prefix_len = 1 + std::strlen(stringify(GR_DATADIR));
38 |
39 | for (int i = 0; i < N_STANDARD_DATAFILES; i++){
40 | if (std::strcmp(datafile, standard_data_files[i]+prefix_len) == 0) {
41 | my_chemistry.grackle_data_file = standard_data_files[i];
42 | return true;
43 | }
44 | }
45 | return false;
46 | }
47 |
--------------------------------------------------------------------------------
/tests/unit/grtest_utils.hpp:
--------------------------------------------------------------------------------
1 | // This defines a series of utilities to aid with testing grackle
2 |
3 | #ifndef GRTEST_UTILS_HPP
4 | #define GRTEST_UTILS_HPP
5 |
6 | #include
7 | #include
8 |
9 | namespace grtest {
10 |
11 | /// this function records the desired standard datafile within the
12 | /// chemistry_data struct. It deals with the minutia of making sure that
13 | /// grackle can find the standardized data-file
14 | ///
15 | /// @returns true if successful or false if unsuccessful
16 | ///
17 | /// @note
18 | /// For the sake of forward compatability (we will probably change the
19 | /// implementation if we merge PRs 235, 237, and 246) you should:
20 | /// - only pass string literals (or the addresses of string-literals) as the
21 | /// this function's datafile arg
22 | /// - AND never deallocate my_chemistry.datafile after calling this function
23 | /// (there won't be a memory leak)
24 | bool set_standard_datafile(chemistry_data& my_chemistry, const char* datafile);
25 |
26 | }
27 |
28 | /// In this namespace, we define tools to help with drawing random numbers
29 | /// in a reproducible manner (for a given seed) across platforms
30 | ///
31 | /// In this regard, there issues with common built-in choices:
32 | /// -> functions like drand48 apparently aren't particularly portable
33 | /// (https://charm.readthedocs.io/en/latest/faq/manual.html#how-much-does-getting-a-random-number-generator-right-matter)
34 | /// -> machinery in the C++ standard library for sampling distributions (e.g.
35 | /// std::normal_distribution or std::uniform_real_distribution) are allowed
36 | /// to produce differente sequences of output values (for a given generator
37 | /// and seed) in different implementations of the standard library
38 | /// -> https://stackoverflow.com/a/24554535
39 | ///
40 | /// The solution:
41 | /// -> the pseudo-random number generators themselves are very portable in the
42 | /// C++ standard library
43 | /// -> consequently, this namespace provides functions sample distributions
44 | /// from a given generator so we can be sure that the mapping is portable
45 | namespace grtest::random {
46 |
47 | /// return randomly drawn double-precision value drawn from the uniform
48 | /// distribution over the interval [0.0, 1.0).
49 | inline double uniform_dist_transform(std::minstd_rand &generator) {
50 |
51 | // this static_assert breaks things on macOS's apple-clang compiler
52 | //static_assert((generator.max() <= UINT32_MAX) && (generator.min() == 1),
53 | // "Unexpected PRNG Property"); // sanity-check!
54 |
55 | // cast to double since they can perfectly represent all values of uint32_t
56 | double raw = static_cast(generator()) - 1.0;
57 | double range = static_cast(generator.max());
58 | return raw / range;
59 | }
60 |
61 | } // namespace grtest::random
62 |
63 | #endif /* GRTEST_UTILS_HPP */
64 |
--------------------------------------------------------------------------------