Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PopIII Simulation #368

Merged
merged 212 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
aaceae8
added PopIII setup
Aug 29, 2023
ddfa289
added rotation
Aug 30, 2023
bbbbe83
added minimum density below which chemistry should not be performed
Sep 1, 2023
3299e73
final touches
Sep 1, 2023
61ef7e5
Merge remote-tracking branch 'origin/development' into popiii
psharda Sep 1, 2023
1726bb6
update with popiii
Sep 1, 2023
9155cf2
updated
Sep 1, 2023
6b98642
bug fix
psharda Sep 1, 2023
3c9ed56
decrease timesteps
psharda Sep 1, 2023
b8774e6
use numdens
Sep 1, 2023
b1ef513
verbose
Sep 1, 2023
44272c2
fix bug
psharda Sep 1, 2023
96a0f04
Merge branch 'popiii' of github.com:psharda/quokka into popiii
psharda Sep 1, 2023
65ece50
define proper values
psharda Sep 1, 2023
6e22e8b
fix bug
psharda Sep 1, 2023
a41c1a4
try
Sep 1, 2023
25cc027
fixed bug
psharda Sep 1, 2023
6814273
try2
psharda Sep 2, 2023
4fc5ffa
reset density floor
psharda Sep 2, 2023
f17b271
define temp outside parallelFor
psharda Sep 8, 2023
448611f
Merge branch 'quokka-astro:development' into popiii
psharda Sep 8, 2023
60fba77
use BL_Profile
psharda Sep 8, 2023
5dbb67c
inputs for perturbations.py direcrly read from the .in file
psharda Sep 8, 2023
2bf5287
Merge branch 'quokka-astro:development' into popiii
psharda Sep 8, 2023
0e90457
updated cmakelists
psharda Sep 8, 2023
a57d9c8
correct includes order
psharda Sep 8, 2023
206b7f1
add {} to variable declaration
psharda Sep 8, 2023
b4246fb
added author name
psharda Sep 8, 2023
3b42508
remove duplicate include
psharda Sep 8, 2023
c8835a8
include NSCBC
psharda Sep 8, 2023
31e4032
added comments
psharda Sep 8, 2023
d4646a0
set reconstruct_eint to true
psharda Sep 8, 2023
0a7c107
move perturbations to src/
psharda Sep 8, 2023
7a814af
moved perturbatinos to src/
psharda Sep 8, 2023
9427d61
move perturb to src
psharda Sep 8, 2023
b912d38
moved perturb to src
psharda Sep 8, 2023
5669ea7
fix bug
psharda Sep 8, 2023
dcae899
re-add enabled
psharda Sep 8, 2023
2b87ce8
updated params to match PopIII expectations
psharda Sep 8, 2023
c564972
remove turbdatareader
psharda Sep 8, 2023
9307705
remove turbdatareader
psharda Sep 8, 2023
d0fa85d
move turbdatareader to src
psharda Sep 8, 2023
57b9827
dont refine outside core
psharda Sep 9, 2023
d16ad34
Merge remote-tracking branch 'origin/development' into popiii
psharda Sep 9, 2023
9abec00
remove is chem enabled
psharda Sep 9, 2023
7e9116e
Merge branch 'development' into popiii
psharda Sep 9, 2023
3a4cc58
define redshift
psharda Sep 9, 2023
6fc07b1
reset params
psharda Sep 9, 2023
43593d6
Merge branch 'development' into popiii
psharda Sep 11, 2023
36ef67c
Merge branch 'quokka-astro:development' into popiii
psharda Sep 12, 2023
ef99de2
Merge branch 'quokka-astro:development' into popiii
psharda Sep 13, 2023
b9decda
modify
psharda Sep 13, 2023
e9b52c9
increase density floor
Sep 13, 2023
db3d1d2
return invalid state if mass scalars have negative partial densities
Sep 13, 2023
1c7b6f2
enforce limits on mass scalars
Sep 13, 2023
e78afac
add LLF fallback solver
BenWibking Sep 13, 2023
9150f3a
use if constexpr
Sep 13, 2023
31f294e
Merge remote-tracking branch 'origin/specie-limits' into popiii
Sep 13, 2023
400dfb7
Merge remote-tracking branch 'ben/BenWibking/llf-fallback' into popiii
Sep 13, 2023
308ddf6
fix typo
BenWibking Sep 13, 2023
0a067a4
Merge remote-tracking branch 'ben/BenWibking/llf-fallback' into popiii
Sep 13, 2023
7bd6f54
Merge remote-tracking branch 'origin/development' into popiii
Sep 14, 2023
a1c6385
set temp floor based on redshift
Sep 14, 2023
c25dafa
Merge branch 'quokka-astro:development' into specie-limits
psharda Sep 14, 2023
0a4683d
print cell coords
Sep 14, 2023
191c43b
print cell coords
Sep 14, 2023
d361292
check for dimensions
Sep 14, 2023
08b1921
amrex spelling
Sep 14, 2023
0c41f67
new function for printing coords
Sep 15, 2023
c170480
fix error
Sep 15, 2023
5c06a3c
declare const
Sep 15, 2023
ae85251
fix bug
Sep 15, 2023
685bfb3
Merge remote-tracking branch 'origin/specie-limits' into popiii
Sep 15, 2023
d9ce090
remove clangtidy suggestion
Sep 15, 2023
b4906b5
drive turb in entire box
Sep 15, 2023
4b34db0
Merge remote-tracking branch 'origin/specie-limits' into popiii
Sep 15, 2023
e966d79
use minmod limiting for PLM
BenWibking Sep 15, 2023
d8b7da9
write multifab to disk if hydro update fails
BenWibking Sep 15, 2023
8e70cca
call MPI_Abort
BenWibking Sep 15, 2023
a9d8611
Merge remote-tracking branch 'ben/BenWibking/use-minmod' into popiii
Sep 15, 2023
2bbf595
Merge remote-tracking branch 'ben/BenWibking/output-multifab-on-crash…
Sep 15, 2023
a797259
debuggin
Sep 18, 2023
c0e3cd0
debugging
Sep 18, 2023
f5be142
Merge branch 'development' into popiii
psharda Sep 19, 2023
9e18b88
dont do chem if dt < 0
Sep 19, 2023
bb7f592
use speed ceiling
Sep 19, 2023
0668d1a
ensure pressure eqbm in ICs
Sep 20, 2023
d15dc33
checks
Sep 20, 2023
d85d399
Merge branch 'popiii' of github.com:psharda/quokka into popiii
Sep 20, 2023
4898868
add velx and pressure as derived vars
Sep 20, 2023
78bdc4c
add exmaple of refinement restricted to certain cell positions to av…
Sep 20, 2023
04aea4f
abort if rho = 0;
Sep 20, 2023
6691333
check hydro state in more locations
Sep 20, 2023
73eecb5
fix tab
Sep 20, 2023
0d4f673
reduce validstates boolean
Sep 20, 2023
d8f405d
add function call name keyword
Sep 20, 2023
5eae125
enforceLimits returns a bool
Sep 21, 2023
19c5486
enforceLimits returns a bool
Sep 21, 2023
57386d8
write pltfile when rho = 0 encountered and abort
Sep 21, 2023
62db47e
indent
Sep 21, 2023
f1e2c29
added dummy test
Sep 21, 2023
c805e1f
fix bug
Sep 21, 2023
2158523
updated
Sep 21, 2023
f5024ae
reset refinement
Sep 21, 2023
4bce756
added sound speed
Sep 21, 2023
6af6e2e
added sound speed
Sep 21, 2023
7817e1c
do not abort
psharda Sep 22, 2023
f44ad77
refine on 64 cells
psharda Sep 23, 2023
9b65963
update amrex
psharda Sep 24, 2023
f136ccf
Merge branch 'development' into popiii
psharda Sep 24, 2023
79c50f9
delete copiii
psharda Sep 24, 2023
1317371
remove debugs
psharda Sep 24, 2023
cd9657f
remove debugs
psharda Sep 24, 2023
9a12f0a
remove debugs
psharda Sep 24, 2023
7854b37
updated
psharda Sep 24, 2023
604d95b
remove speed ceiling
psharda Sep 25, 2023
2907834
renormalize species post flooring
Sep 25, 2023
177e05b
renormalize mass scalars in enforce limits
psharda Sep 25, 2023
322731c
resolve spell check
psharda Sep 25, 2023
3fb1693
Merge branch 'development' into popiii
psharda Sep 26, 2023
f9aeffc
dont need velocity large anymore in states valid
psharda Sep 26, 2023
f264f93
undo some stuff
psharda Sep 26, 2023
ee2a5c9
remove debug printf
psharda Sep 26, 2023
6371065
remove debug printf
psharda Sep 26, 2023
ea32e06
remove debug printf
psharda Sep 26, 2023
8652fd3
remove debug printf
psharda Sep 26, 2023
76e9770
revert enforceLimits as boolean
psharda Sep 27, 2023
7c3df93
revert enforceLimits boolean
psharda Sep 27, 2023
c04e3c4
fix spaces
psharda Sep 27, 2023
7bf9c79
sample input file for main repo
psharda Sep 27, 2023
83d9735
renormalize mass scalars post enforcing limit
Sep 27, 2023
ea24e55
only normalize if sum > 0
Oct 6, 2023
6e7edab
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2023
96868de
updated
psharda Oct 6, 2023
bf916aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2023
589638d
update
psharda Oct 6, 2023
b6c976c
merged spsum
psharda Oct 6, 2023
2b59f0e
Merge branch 'development' into popiii
psharda Oct 6, 2023
03535f3
cosmetic
psharda Oct 6, 2023
d074ff6
remove actual_eos_data.H
psharda Oct 7, 2023
0c34263
resolve clang tidy comments
psharda Oct 7, 2023
50825cb
updated microp
Oct 9, 2023
d8075b0
Merge branch 'quokka-astro:development' into popiii
psharda Oct 14, 2023
786f532
Merge branch 'development' into popiii
psharda Oct 15, 2023
4657676
Merge branch 'development' into popiii
psharda Nov 3, 2023
901d02d
Merge branch 'development' into popiii
psharda Nov 4, 2023
96a0a4b
fix bug
psharda Nov 4, 2023
9514585
Merge branch 'quokka-astro:development' into popiii
psharda Nov 9, 2023
8800336
Merge branch 'development' into popiii
psharda Nov 28, 2023
d606f44
Merge branch 'development' into popiii
psharda Dec 20, 2023
0c2f6ca
updated microp
psharda Dec 20, 2023
7e84b50
Merge branch 'development' into popiii
psharda Dec 20, 2023
357e2a5
Merge branch 'development' into popiii
psharda Dec 26, 2023
785c3a8
Merge branch 'development' into popiii
psharda Jan 11, 2024
c77b759
Merge branch 'development' into popiii
psharda Jan 12, 2024
a00b3bb
Merge branch 'development' into popiii
psharda Jan 15, 2024
8d48705
Merge branch 'development' into popiii
psharda Jan 20, 2024
aadaa1d
updated
psharda Jan 25, 2024
069444b
fix bug
psharda Jan 25, 2024
7af9e1a
fix bug
psharda Jan 25, 2024
32a63ea
Merge branch 'development' into popiii
psharda Feb 3, 2024
70424b3
dummy commit
Feb 3, 2024
ede20a5
Merge remote-tracking branch 'origin/test' into popiii
Feb 3, 2024
b87ae84
debug 1
Feb 3, 2024
24394a7
debug 1
Feb 3, 2024
1536cd7
include other headers present in primordial chem
Feb 3, 2024
e2e9aea
include openPMRsources as in primordial chem
Feb 3, 2024
c4c0def
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 3, 2024
bb45cf2
test radhydrosim
Feb 3, 2024
e49e378
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 3, 2024
998694b
debug chemistry
Feb 3, 2024
021c7a2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 3, 2024
1cac4d4
const tiny profiler
Feb 3, 2024
a8a490c
moved turb files to src
Feb 3, 2024
83dc726
updated cmakelists
Feb 3, 2024
ebb4c3d
comment print statement
Feb 3, 2024
b7c64c7
codeQL suggestion
Feb 3, 2024
421546b
moved turbdatareader
Feb 4, 2024
e6aa3f4
clang-tidy warnings
Feb 4, 2024
e28998d
Merge branch 'development' into test
psharda Feb 4, 2024
0f46098
resolve conflict
Feb 4, 2024
69616f8
revert
Feb 4, 2024
702faa4
reorder includes
Feb 4, 2024
d953142
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 4, 2024
03eb8d9
debug
Feb 4, 2024
b78f563
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 4, 2024
7575060
turn off pre-commit
Feb 4, 2024
da515d6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 4, 2024
dfe52d1
remove precommit
Feb 4, 2024
c2f33ca
Merge branch 'popiii' of https://github.com/psharda/quokka into popiii
Feb 4, 2024
87c4fb4
debug
Feb 4, 2024
dfa1c90
dont build primordial chem
Feb 4, 2024
e8618c9
Merge branch 'development' into popiii
psharda Feb 4, 2024
e0d9926
revert
Feb 4, 2024
c2ccaea
cmake in 3D
Feb 4, 2024
38963af
fix clang-tidy warnings
Feb 4, 2024
d2f1377
readded precommit
Feb 4, 2024
0dd17b3
trying to fix table3d error
Feb 4, 2024
91e112a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 4, 2024
eb14f58
revert
Feb 4, 2024
a403431
arrange tests alphabetically
Feb 5, 2024
a7557c7
reduce grid size to 128
Feb 5, 2024
5959fa1
comment for h5py
Feb 5, 2024
b2cd1af
make initial rms vel a runtime param
Feb 5, 2024
4c7a7fc
let the code calculate pressure
Feb 5, 2024
47315f8
make jeans refinement params runtime params
Feb 5, 2024
e313ba7
move dt < 0 outside of the inner loop
Feb 5, 2024
37f1ba1
declaring an initial value of vars
Feb 5, 2024
414e0e5
make density floor runtime param
Feb 5, 2024
a1d31e7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 5, 2024
d0fc050
use a different variable for parmparse
Feb 5, 2024
55d18ff
dont need to define density_floor, its defined in simulation.hpp
Feb 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ set (QuokkaObjSources "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" "${CMAKE_CURRENT_SO
#endif()
#link_libraries(QuokkaObj)

add_subdirectory(PopIII)


add_subdirectory(StarCluster)
add_subdirectory(PrimordialChem)

Expand Down Expand Up @@ -154,4 +157,3 @@ add_subdirectory(ShockCloud)
add_subdirectory(PassiveScalar)
add_subdirectory(FCQuantities)
add_subdirectory(SphericalCollapse)
add_subdirectory(NSCBC)
psharda marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 7 additions & 1 deletion src/Chemistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ namespace quokka::chemistry

AMREX_GPU_DEVICE void chemburner(burn_t &chemstate, const Real dt);

template <typename problem_t> void computeChemistry(amrex::MultiFab &mf, const Real dt, const Real max_density_allowed)
template <typename problem_t> void computeChemistry(amrex::MultiFab &mf, const Real dt, const Real max_density_allowed, const Real min_density_allowed)
{

BL_PROFILE("Chemistry::computeChemistry()");
psharda marked this conversation as resolved.
Show resolved Hide resolved
psharda marked this conversation as resolved.
Show resolved Hide resolved
psharda marked this conversation as resolved.
Show resolved Hide resolved
for (amrex::MFIter iter(mf); iter.isValid(); ++iter) {
const amrex::Box &indexRange = iter.validbox();
auto const &state = mf.array(iter);
Expand Down Expand Up @@ -64,6 +65,11 @@ template <typename problem_t> void computeChemistry(amrex::MultiFab &mf, const R
chemstate.xn[nn] = inmfracs[nn];
}

// dont do chemistry in cells with densities below the minimum density specified
if (rho < min_density_allowed) {
return;
}

// stop the test if we have reached very high densities
if (rho > max_density_allowed) {
amrex::Abort("Density exceeded max_density_allowed!");
Expand Down
77 changes: 77 additions & 0 deletions src/PopIII/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
if (AMReX_SPACEDIM EQUAL 3)
# Define a custom target that runs the Python script to produce the input perturbations file


set(microphysics_network_name "primordial_chem") #this will override network_name to primordial_chem for this directory only
setup_target_for_microphysics_compilation(${microphysics_network_name} "${CMAKE_CURRENT_BINARY_DIR}/")

#use the BEFORE keyword so that these files get priority in compilation for targets in this directory
#this is critical to ensure the correct Microphysics files are linked to primordial chem target
include_directories(BEFORE ${primordial_chem_dirs} "${CMAKE_CURRENT_BINARY_DIR}/" "includes/extern_parameters.H" "includes/network_properties.H")

add_executable(popiii popiii.cpp TurbDataReader.cpp ../main.cpp ../GrackleDataReader.cpp ../CloudyCooling.cpp ../Chemistry.cpp ${primordial_chem_sources})
target_compile_definitions(popiii PUBLIC PRIMORDIAL_CHEM) #this will add #define PRIMORDIAL_CHEM

if(AMReX_GPU_BACKEND MATCHES "CUDA")
setup_target_for_cuda_compilation(popiii)
endif()

#need h5py to run perturbations.py file below
psharda marked this conversation as resolved.
Show resolved Hide resolved
execute_process(
COMMAND Python3::Interpreter -c "h5py"
RESULT_VARIABLE EXIT_CODE
OUTPUT_QUIET
)

#re-run cmake if this file is changed
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/tests/PopIII.in)

# Read the 'PopIII.in' file line by line
file(READ ${CMAKE_SOURCE_DIR}/tests/PopIII.in pop_in_contents)

# Split the file contents into lines
string(REPLACE "\n" ";" pop_in_lines "${pop_in_contents}")

# Iterate through the lines and look for lines starting with 'amr.n_cell'
foreach(line IN LISTS pop_in_lines)
if (line MATCHES "^amr\\.n_cell.*")
set(match_line "${line}")
break()
endif()
endforeach()

if (match_line)
message(STATUS "picked line is ${match_line}")
# Use a regular expression to find consecutive digit
string(REGEX MATCHALL "[0-9]+" digits_list "${match_line}")
# Iterate through the matched digits and extract the first one
list(GET digits_list 0 first_digits)
# Check if matched digits were found
if (first_digits)
#first_digits give the box size, but you also want box size / 2 as kmax in the script below
math(EXPR int_first_digits "${first_digits}")
# Check if the conversion was successful
if (int_first_digits)
# Divide the integer by two
math(EXPR result "${int_first_digits} / 2")
else()
message(FATAL_ERROR "Conversion to integer failed, so cannot find kmax!")
endif()
message(STATUS "Will create initial perturbations of box size ${first_digits} and kmax ${result}")

else()
message(FATAL_ERROR "No box size found to create initial perturbations for!")
endif()
else()
message(FATAL_ERROR "No matching line found in ${CMAKE_SOURCE_DIR}/tests/PopIII.in!")
endif()


add_test(NAME ComputePerturbations COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/perturbation.py --kmin=2 --kmax=${result} --size=${first_digits} --alpha=2 --f_solenoidal=1.0 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests)
add_test(NAME PopIII COMMAND popiii PopIII.in WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests)
set_tests_properties(ComputePerturbations PROPERTIES FIXTURES_SETUP PopIII_fixture)
set_tests_properties(PopIII PROPERTIES FIXTURES_REQUIRED PopIII_fixture)

# AMR test only works on Setonix because Gadi and avatar do not have enough memory per GPU
# add_test(NAME PopIIIAMR COMMAND popiii popiii_AMR.in WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests)
endif()
119 changes: 119 additions & 0 deletions src/PopIII/TurbDataReader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//==============================================================================
psharda marked this conversation as resolved.
Show resolved Hide resolved
// TwoMomentRad - a radiation transport library for patch-based AMR codes
// Copyright 2020 Benjamin Wibking.
// Released under the MIT license. See LICENSE file included in the GitHub repo.
//==============================================================================
/// \file TurbDataReader.cpp
/// \brief Reads turbulent driving fields generated as cubic HDF5 arrays.
///

#include "TurbDataReader.hpp"
#include "AMReX_Arena.H"
#include "AMReX_BLassert.H"
#include "AMReX_Print.H"
#include "AMReX_TableData.H"
#include <string>

auto read_dataset(hid_t &file_id, char const *dataset_name) -> amrex::Table3D<double>
{
// open dataset
hid_t dset_id = 0;
dset_id = H5Dopen2(file_id, dataset_name, H5P_DEFAULT);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(dset_id != -1, "Can't open table!");

// get dimensions
hid_t const dspace = H5Dget_space(dset_id);
const int ndims = H5Sget_simple_extent_ndims(dspace);
std::vector<hsize_t> dims(ndims);
H5Sget_simple_extent_dims(dspace, dims.data(), nullptr);

uint64_t data_size = 1;
for (int idim = 0; idim < ndims; ++idim) {
data_size *= dims[idim];
}

// allocate array for dataset storage
auto *temp_data = new double[data_size];
psharda marked this conversation as resolved.
Show resolved Hide resolved

// read dataset
herr_t status = H5Dread(dset_id, HDF5_R8, H5S_ALL, H5S_ALL, H5P_DEFAULT, temp_data);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(status != -1, "Failed to read dataset!");

// close dataset
status = H5Dclose(dset_id);

// WARNING: Table3D uses column-major (Fortran-order) indexing, but HDF5
// tables use row-major (C-order) indexing!
amrex::GpuArray<int, 3> const lo{0, 0, 0};
amrex::GpuArray<int, 3> const hi{static_cast<int>(dims[0]), static_cast<int>(dims[1]), static_cast<int>(dims[2])};
auto table = amrex::Table3D<double>(temp_data, lo, hi);
return table;
}

void initialize_turbdata(turb_data &data, std::string &data_file)
{
amrex::Print() << "Initializing turbulence data...\n";
amrex::Print() << fmt::format("data_file: {}.\n", data_file);

herr_t status = 0;
herr_t const h5_error = -1;

// open file
hid_t file_id = 0;
file_id = H5Fopen(data_file.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(file_id != h5_error, "Failed to open data file!");

data.dvx = read_dataset(file_id, "pertx");
data.dvy = read_dataset(file_id, "perty");
data.dvz = read_dataset(file_id, "pertz");

// close file
status = H5Fclose(file_id);
}

auto get_tabledata(amrex::Table3D<double> &in_t) -> amrex::TableData<double, 3>
{
amrex::Array<int, 3> tlo{in_t.begin[0], in_t.begin[1], in_t.begin[2]};
amrex::Array<int, 3> thi{in_t.end[0] - 1, in_t.end[1] - 1, in_t.end[2] - 1};
amrex::TableData<double, 3> tableData(tlo, thi, amrex::The_Pinned_Arena());
auto h_table = tableData.table();

amrex::Print() << "Copying tableData on indices " << tlo << " to " << thi << ".\n";

// fill tableData
for (int i = tlo[0]; i <= thi[0]; ++i) {
for (int j = tlo[1]; j <= thi[1]; ++j) {
for (int k = tlo[2]; k <= thi[2]; ++k) {
h_table(i, j, k) = in_t(i, j, k);
}
}
}

return tableData;
}

auto computeRms(amrex::TableData<amrex::Real, 3> &dvx, amrex::TableData<amrex::Real, 3> &dvy, amrex::TableData<amrex::Real, 3> &dvz) -> amrex::Real
{
amrex::Array<int, 3> tlo = dvx.lo();
amrex::Array<int, 3> thi = dvx.hi();
auto const &dvx_table = dvx.const_table();
auto const &dvy_table = dvy.const_table();
auto const &dvz_table = dvz.const_table();

// compute rms power
amrex::Real rms_sq = 0;
amrex::Long N = 0;
for (int i = tlo[0]; i <= thi[0]; ++i) {
for (int j = tlo[1]; j <= thi[1]; ++j) {
for (int k = tlo[2]; k <= thi[2]; ++k) {
amrex::Real const vx = dvx_table(i, j, k);
amrex::Real const vy = dvy_table(i, j, k);
amrex::Real const vz = dvz_table(i, j, k);
rms_sq += vx * vx + vy * vy + vz * vz;
++N;
}
}
}
rms_sq /= static_cast<amrex::Real>(N);
return std::sqrt(rms_sq);
}
59 changes: 59 additions & 0 deletions src/PopIII/TurbDataReader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef TURBDATAREADER_HPP_ // NOLINT
#define TURBDATAREADER_HPP_
//==============================================================================
// TwoMomentRad - a radiation transport library for patch-based AMR codes
// Copyright 2020 Benjamin Wibking.
// Released under the MIT license. See LICENSE file included in the GitHub repo.
//==============================================================================
/// \file TurbDataReader.hpp
/// \brief Reads turbulent driving fields generated as cubic HDF5 arrays.
///

#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <string>

#include "fmt/core.h"
#include <H5Dpublic.h>
#include <H5Ppublic.h>
#include <hdf5.h>

#include "AMReX.H"
#include "AMReX_Array.H"
#include "AMReX_BLassert.H"
#include "AMReX_TableData.H"

/* HDF5 definitions */

#define HDF5_FILE_I4 H5T_STD_I32BE
#define HDF5_FILE_I8 H5T_STD_I64BE
#define HDF5_FILE_R4 H5T_IEEE_F32BE
#define HDF5_FILE_R8 H5T_IEEE_F64BE
#define HDF5_FILE_B8 H5T_STD_B8BE

#define HDF5_I4 H5T_NATIVE_INT
#define HDF5_I8 H5T_NATIVE_LLONG
#define HDF5_R4 H5T_NATIVE_FLOAT
#define HDF5_R8 H5T_NATIVE_DOUBLE
#define HDF5_R16 H5T_NATIVE_LDOUBLE

// Cooling table storage

using turb_data = struct turb_data {
// values
amrex::Table3D<double> dvx;
amrex::Table3D<double> dvy;
amrex::Table3D<double> dvz;
};

void initialize_turbdata(turb_data &data, std::string &data_file);

auto read_dataset(hid_t &file_id, char const *dataset_name) -> amrex::Table3D<double>;

auto get_tabledata(amrex::Table3D<double> &in_t) -> amrex::TableData<double, 3>;

auto computeRms(amrex::TableData<amrex::Real, 3> &dvx, amrex::TableData<amrex::Real, 3> &dvy, amrex::TableData<amrex::Real, 3> &dvz) -> amrex::Real;

#endif // TURBDATAREADER_HPP_
30 changes: 30 additions & 0 deletions src/PopIII/ascent_actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-
action: "add_pipelines"
pipelines:
pl1:
f2:
type: "slice"
params:
point:
x: 0.
y: 0.
z: 0.
normal:
x: 0.0
y: 0.0
z: 1.0
-
action: "add_scenes"
scenes:
s1:
plots:
p1:
type: "pseudocolor"
field: "log_density"
pipeline: "pl1"
renders:
r1:
image_prefix: "dens%05d"
annotations: "true"
camera:
zoom: 1.5
Loading
Loading