refactor(reaction): refactored to an abstract reaction class in prep for weak reactions
This commit is contained in:
69
utils/WRL/format.py
Normal file
69
utils/WRL/format.py
Normal file
@@ -0,0 +1,69 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from tqdm import tqdm
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def write_cpp_header(df, output_path):
|
||||
"""Writes the DataFrame to a C++ header as a constexpr array of structs."""
|
||||
|
||||
with open(output_path, 'w') as f:
|
||||
f.write(f"""// This is an auto generated file, do not edit this file directly
|
||||
// This file was created using the format.py script in GridFire/utils/WRL
|
||||
// This file was created on {datetime.now()}
|
||||
// Rates from this file have been retrived from A. Ravlic, S. Giraud, N. Paar, and R.G.T. Zegers, https://doi.org/10.48550/arXiv.2412.00650
|
||||
// Rates have been culled to cover T9 < 10 & log electron density < 11 for all species up to and including Z=40 (Zirconium)
|
||||
// In order to save space in the binary all data has been stored as either single prescision floating point numbers, uint8_t, or uint16_t\n""")
|
||||
f.write("#pragma once\n\n")
|
||||
f.write("#include <array>\n\n")
|
||||
f.write("#include <cstdint>\n\n")
|
||||
f.write("namespace gridfire::rates::weak {\n\n")
|
||||
|
||||
f.write(" // Represents a single row from the unified weak rate table\n")
|
||||
f.write(" struct RateDataRow {\n")
|
||||
f.write(" uint16_t A;\n")
|
||||
f.write(" uint8_t Z;\n")
|
||||
f.write(" float t9;\n")
|
||||
f.write(" float log_rhoye;\n")
|
||||
f.write(" float mu_e;\n")
|
||||
f.write(" float log_beta_plus;\n")
|
||||
f.write(" float log_electron_capture;\n")
|
||||
f.write(" float log_neutrino_loss_ec;\n")
|
||||
f.write(" float log_beta_minus;\n")
|
||||
f.write(" float log_positron_capture;\n")
|
||||
f.write(" float log_antineutrino_loss_bd;\n")
|
||||
f.write(" };\n\n")
|
||||
|
||||
f.write(" // The complete, pre-processed weak rate table data\n")
|
||||
f.write(f" static constexpr std::array<RateDataRow, {len(df)}> UNIFIED_WEAK_DATA = {{\n")
|
||||
|
||||
for row in tqdm(df.itertuples(), total=len(df)):
|
||||
f.write(" RateDataRow(")
|
||||
f.write(f"{row.A}, {row.Z}, {row.t9}, {row.lrhoYe}, {row.mu_e}, ")
|
||||
f.write(f"{row._6}, {row._7}, {row.nue}, {row._9}, {row._10}, {row.nubar}")
|
||||
f.write("),\n")
|
||||
|
||||
f.write(" };\n\n")
|
||||
f.write("} // namespace gridfire::rates::weak\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(description="Format unified weak rate library into c++ header")
|
||||
parser.add_argument("path", help="path to WRL file", type=str)
|
||||
parser.add_argument("-o", "--output", help="path to save c++ header to", default="weak_rate_library.h", type=str)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
print(f"Reading weak rate data from: {args.path}")
|
||||
df = pd.read_csv(args.path, sep=r'\s+', comment='#')
|
||||
df.columns = [
|
||||
"A", "Z", "t9", "lrhoYe", "mu_e", "beta+", "e-",
|
||||
"nue", "beta-", "e+", "nubar", "ID"
|
||||
]
|
||||
|
||||
df = df[(df.t9 < 10) & (df.lrhoYe < 11) & (df.Z <= 40)]
|
||||
print(df)
|
||||
print(f"Found {len(df)} total data rows.")
|
||||
print(f"Generating C++ header file: {args.output}")
|
||||
write_cpp_header(df, args.output)
|
||||
print("Done.")
|
||||
954241
utils/WRL/rate_table_Ravlic_others.txt
Normal file
954241
utils/WRL/rate_table_Ravlic_others.txt
Normal file
File diff suppressed because it is too large
Load Diff
13
utils/WRL/readme.md
Normal file
13
utils/WRL/readme.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Unified Weak Rate Library
|
||||
This library was retrived on August 13th, 2025 from the following URL
|
||||
|
||||
```bash
|
||||
wget https://groups.frib.msu.edu/charge_exchange/weakrate_tables/rate_table_Ravlic_others.txt
|
||||
```
|
||||
|
||||
# Citations
|
||||
- A. Ravlic, S. Giraud, N. Paar, and R.G.T. Zegers, https://doi.org/10.48550/arXiv.2412.00650
|
||||
|
||||
This is version 1.3 of the weak rate library. See
|
||||
[https://www.remcozegers.com/weak-rate-library](https://www.remcozegers.com/weak-rate-library)
|
||||
for details on versions 1.3, 1.2, and 1.1
|
||||
BIN
utils/WRL/test
Executable file
BIN
utils/WRL/test
Executable file
Binary file not shown.
9
utils/WRL/test.cpp
Normal file
9
utils/WRL/test.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "weak_rate_library.h"
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
|
||||
int main() {
|
||||
std::size_t totalBytes = sizeof(gridfire::rates::weak::UNIFIED_WEAK_DATA);
|
||||
std::cout << "Total size in bytes of packed weak reaction data is : " << totalBytes/1.0e6 << " MB" << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user