-
Notifications
You must be signed in to change notification settings - Fork 8
Add utility to convert IPCRESS files to Spiner via Gandolf #76
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
Changes from all commits
df01078
aa28f6d
cba114f
ce63b03
2a5ff4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #------------------------------------------------------------------------------# | ||
| # © 2026. Triad National Security, LLC. All rights reserved. This | ||
| # program was produced under U.S. Government contract 89233218CNA000001 | ||
| # for Los Alamos National Laboratory (LANL), which is operated by Triad | ||
| # National Security, LLC for the U.S. Department of Energy/National | ||
| # Nuclear Security Administration. All rights in the program are | ||
| # reserved by Triad National Security, LLC, and the U.S. Department of | ||
| # Energy/National Nuclear Security Administration. The Government is | ||
| # granted for itself and others acting on its behalf a nonexclusive, | ||
| # paid-up, irrevocable worldwide license in this material to reproduce, | ||
| # prepare derivative works, distribute copies to the public, perform | ||
| # publicly and display publicly, and to permit others to do so. | ||
| #------------------------------------------------------------------------------# | ||
|
|
||
| # ARL NOTE: Based off FindEOSPAC.cmake from singularity-eos | ||
|
|
||
| # Find the native GANDOLF headers and libraries. | ||
| # | ||
| # GANDOLF_INCLUDE_DIRECTORY - Where to find gandolf.h, etc. | ||
| # GANDOLF_LIBRARY - Gandolf library | ||
| # GANDOLF_FOUND - True if gandolf found. | ||
| # | ||
| # Current modules set GANDOLF_INC_DIR and GANDOLF_LIB_DIR and prepend the top | ||
| # level of the Gandolf build to CMAKE_PREFIX_PATH | ||
|
|
||
|
|
||
| # if environment variables are set, use them as hints to FIND calls | ||
| set(GANDOLF_INC_DIR_HINTS "") | ||
| if(DEFINED ENV{GANDOLF_INC_DIR}) | ||
| list(APPEND GANDOLF_INC_DIR_HINTS "$ENV{GANDOLF_INC_DIR}") | ||
| endif() | ||
|
|
||
| set(GANDOLF_LIB_DIR_HINTS "") | ||
| if(DEFINED ENV{GANDOLF_LIB_DIR}) | ||
| list(APPEND GANDOLF_LIB_DIR_HINTS "$ENV{GANDOLF_LIB_DIR}") | ||
| endif() | ||
|
|
||
|
|
||
| # Look for the header file. | ||
| FIND_PATH(GANDOLF_INC_DIR NAMES gandolf.h HINTS ${GANDOLF_INC_DIR_HINTS}) | ||
|
|
||
| # Look for the library. | ||
| FIND_LIBRARY(GANDOLF_LIB_DIR NAMES libgandolf.a HINTS ${GANDOLF_LIB_DIR_HINTS}) | ||
|
|
||
| # handle the QUIETLY and REQUIRED arguments and set GANDOLF_FOUND to TRUE if | ||
| # all listed variables are TRUE | ||
| INCLUDE(FindPackageHandleStandardArgs) | ||
| FIND_PACKAGE_HANDLE_STANDARD_ARGS(gandolf DEFAULT_MSG GANDOLF_LIB_DIR GANDOLF_INC_DIR) | ||
|
|
||
| # Copy the results to the output variables. | ||
| SET(GANDOLF_LIBRARY ${GANDOLF_LIB_DIR}) | ||
| SET(GANDOLF_INCLUDE_DIRECTORY ${GANDOLF_INC_DIR}) | ||
|
|
||
| MARK_AS_ADVANCED(GANDOLF_INCLUDE_DIRECTORY GANDOLF_LIBRARY) | ||
|
|
||
| if(GANDOLF_INCLUDE_DIRECTORY AND GANDOLF_LIBRARY) | ||
| add_library(gandolf::gandolf STATIC IMPORTED) | ||
| set_target_properties(gandolf::gandolf PROPERTIES | ||
| IMPORTED_LOCATION "${GANDOLF_LIBRARY}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${GANDOLF_INCLUDE_DIRECTORY}") | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #------------------------------------------------------------------------------ | ||
| # © 2026. Triad National Security, LLC. All rights reserved. This | ||
| # program was produced under U.S. Government contract 89233218CNA000001 | ||
| # for Los Alamos National Laboratory (LANL), which is operated by Triad | ||
| # National Security, LLC for the U.S. Department of Energy/National | ||
| # Nuclear Security Administration. All rights in the program are | ||
| # reserved by Triad National Security, LLC, and the U.S. Department of | ||
| # Energy/National Nuclear Security Administration. The Government is | ||
| # granted for itself and others acting on its behalf a nonexclusive, | ||
| # paid-up, irrevocable worldwide license in this material to reproduce, | ||
| # prepare derivative works, distribute copies to the public, perform | ||
| # publicly and display publicly, and to permit others to do so. | ||
| #------------------------------------------------------------------------------ | ||
| project(ipcress2spiner VERSION 0.8.0.0 LANGUAGES CXX Fortran) | ||
|
|
||
| find_package(gandolf) | ||
|
|
||
| if(GANDOLF_FOUND) | ||
| add_executable(ipcress2spiner | ||
| parse_cli.cpp | ||
| parse_cli.hpp | ||
| make_spiner_databox.hpp | ||
| interpolate_opacity.hpp | ||
| main.cpp | ||
| ) | ||
|
|
||
|
|
||
| target_include_directories(ipcress2spiner | ||
| PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> | ||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_BINDIR}> | ||
| ${GANDOLF_INCLUDE_DIRECTORY} | ||
| ) | ||
|
|
||
|
|
||
| target_link_libraries(ipcress2spiner | ||
| PRIVATE | ||
| singularity-opac::singularity-opac | ||
| ${GANDOLF_LIBRARY} | ||
| PortsofCall::PortsofCall | ||
| ) | ||
|
|
||
| set_property(TARGET ipcress2spiner PROPERTY LINKER_LANGUAGE Fortran) | ||
| # Define the full version as a string macro | ||
| target_compile_definitions(ipcress2spiner PRIVATE | ||
| IPCRESS2SPINER_VERSION=\"${PROJECT_VERSION}\" | ||
| ) | ||
| install(TARGETS ipcress2spiner DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
| else() | ||
| message("GANDOLF was not found, not building ipcress2spiner") | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //====================================================================== | ||
| // generate_files function that write spiner file | ||
| // Author: Alex R. Long (along@lanl.gov) | ||
| // © 2026. Triad National Security, LLC. All rights reserved. This | ||
| // program was produced under U.S. Government contract 89233218CNA000001 | ||
| // for Los Alamos National Laboratory (LANL), which is operated by Triad | ||
| // National Security, LLC for the U.S. Department of Energy/National | ||
| // Nuclear Security Administration. All rights in the program are | ||
| // reserved by Triad National Security, LLC, and the U.S. Department of | ||
| // Energy/National Nuclear Security Administration. The Government is | ||
| // granted for itself and others acting on its behalf a nonexclusive, | ||
| // paid-up, irrevocable worldwide license in this material to reproduce, | ||
| // prepare derivative works, distribute copies to the public, perform | ||
| // publicly and display publicly, and to permit others to do so. | ||
| //====================================================================== | ||
|
|
||
| #ifndef _IPCRESS2SPINER_GENERATE_FILES_HPP_ | ||
| #define _IPCRESS2SPINER_GENERATE_FILES_HPP_ | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
| #include <utils/spiner/spiner/sp5.hpp> | ||
| #include <utils/spiner/spiner/databox.hpp> | ||
| #include <utils/spiner/spiner/interpolation.hpp> | ||
| #include <utils/spiner/spiner/singularity_opac_sp5.hpp> | ||
|
|
||
| herr_t saveMaterial(hid_t loc, hid_t matGroup, const int matid, | ||
| const std::string &sMatid, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my own gandolf ignorance here. Do materials have a matid the same way the sesame database does?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They have material IDs that don't match the sesame IDs. I'll try to provide a map in the next update and write the common name out as part of the metadata. |
||
| const std::string &sp5_field_name, | ||
| const std::vector<double> &group_bounds, | ||
| Spiner::DataBox<double> &opacity) { | ||
|
|
||
|
|
||
| double zero_offset =0.0; | ||
| herr_t status = 0; | ||
| // Dependent variables metadata | ||
| status += H5LTset_attribute_string(loc, sMatid.c_str(), SP5::Offsets::messageName, | ||
| SP5::Offsets::message); | ||
| status += H5LTset_attribute_double(loc, sMatid.c_str(), SP5::Offsets::rho, | ||
| &zero_offset, 1); | ||
| status += H5LTset_attribute_double(loc, sMatid.c_str(), SP5::Offsets::T, &zero_offset, 1); | ||
|
|
||
| status += opacity.saveHDF(matGroup, sp5_field_name); | ||
|
|
||
| return status; | ||
| } | ||
|
|
||
| #endif // _IPCRESS2SPINER_GENERATE_FILES_HPP_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| //====================================================================== | ||
| // ipcress2spiner tool for converting ipcress to spiner | ||
| // Author: Alex R. Long (along@lanl.gov) | ||
| // © 2026. Triad National Security, LLC. All rights reserved. This | ||
| // program was produced under U.S. Government contract 89233218CNA000001 | ||
| // for Los Alamos National Laboratory (LANL), which is operated by Triad | ||
| // National Security, LLC for the U.S. Department of Energy/National | ||
| // Nuclear Security Administration. All rights in the program are | ||
| // reserved by Triad National Security, LLC, and the U.S. Department of | ||
| // Energy/National Nuclear Security Administration. The Government is | ||
| // granted for itself and others acting on its behalf a nonexclusive, | ||
| // paid-up, irrevocable worldwide license in this material to reproduce, | ||
| // prepare derivative works, distribute copies to the public, perform | ||
| // publicly and display publicly, and to permit others to do so. | ||
| //====================================================================== | ||
|
|
||
| #ifndef _IPCRESS2SPINER_INTERPOLATE_HPP_ | ||
| #define _IPCRESS2SPINER_INTERPOLATE_HPP_ | ||
|
|
||
| inline double interpolate_mg_opacity_data(const std::vector<double> &T_grid, const std::vector<double> &rho_grid, const std::vector<double> &group_bounds, const std::vector<double> &op_data, | ||
|
alexrlongne marked this conversation as resolved.
|
||
| double target_T, double target_rho, double target_hnu, const double log_interpolation) { | ||
|
|
||
| size_t n_T = T_grid.size(); | ||
| size_t n_rho = rho_grid.size(); | ||
| size_t n_groups = group_bounds.size()-1; | ||
|
|
||
| auto T_L = std::distance(T_grid.begin(), std::lower_bound(T_grid.begin(), T_grid.end(), target_T)); | ||
| T_L = (target_T < T_grid[T_L]) ? T_L-1 : T_L; | ||
| T_L = (T_L == (T_grid.size()-1)) ? T_L-1: T_L; | ||
| auto T_R = T_L + 1; | ||
| // fraction of T_2 to use | ||
| double T_frac = -1.0; // defaulted to invalid value | ||
| if (log_interpolation) { | ||
| auto log_T_L = log(T_grid[T_L]); | ||
| auto log_T_R = log(T_grid[T_R]); | ||
| auto log_T_target = log(target_T); | ||
| T_frac = (log_T_target - log_T_L) / (log_T_R - log_T_L); | ||
| } | ||
| else { | ||
| T_frac = (target_T - T_grid[T_L]) / (T_grid[T_R] - T_grid[T_L]); | ||
| } | ||
|
|
||
| auto rho_L = std::distance(rho_grid.begin(), std::lower_bound(rho_grid.begin(), rho_grid.end(), target_rho)); | ||
| rho_L = (target_rho < rho_grid[rho_L]) ? rho_L-1 : rho_L; | ||
| rho_L = (rho_L == (rho_grid.size()-1)) ? rho_L-1: rho_L; | ||
| auto rho_R = rho_L + 1; | ||
| // fraction of rho_2 to use | ||
| double rho_frac = -1.0; // defaulted to invalid value | ||
| if (log_interpolation) { | ||
| auto log_rho_L = log(rho_grid[rho_L]); | ||
| auto log_rho_R = log(rho_grid[rho_R]); | ||
| auto log_rho_target = log(target_rho); | ||
| rho_frac = (log_rho_target - log_rho_L) / (log_rho_R - log_rho_L); | ||
| } | ||
| else { | ||
| rho_frac = (target_rho - rho_grid[rho_L]) / (rho_grid[rho_R] - rho_grid[rho_L]); | ||
| } | ||
|
|
||
| auto group = std::distance(group_bounds.begin(), std::lower_bound(group_bounds.begin(), group_bounds.end(), target_hnu)); | ||
| group = (target_hnu < group_bounds[group]) ? group-1 : group; | ||
| group = (group == (group_bounds.size()-1)) ? group-1 : group; | ||
|
|
||
| // get the adjacent rows of the opacity index, looks like op_[T]_[rho]_[hnu] with L indicating | ||
| // left or index n and "R" indicating right index (n+1) | ||
| auto op_L_L = op_data[ T_L * (n_rho*n_groups) + rho_L*(n_groups) + group]; | ||
| auto op_L_R = op_data[ T_L * (n_rho*n_groups) + rho_R*(n_groups) + group]; | ||
| auto op_R_L = op_data[ T_R * (n_rho*n_groups) + rho_L*(n_groups) + group]; | ||
| auto op_R_R = op_data[ T_R * (n_rho*n_groups) + rho_R*(n_groups) + group]; | ||
|
|
||
| // reduce in temperature dimension | ||
| auto op_L =(1.0-T_frac) * op_L_L + T_frac*op_R_L; | ||
| auto op_R =(1.0-T_frac) * op_L_R + T_frac*op_R_R; | ||
|
|
||
| // reduce in density dimension and return | ||
| double interp_opac = (1.0-rho_frac) * op_L + rho_frac*op_R; | ||
| if (false) { | ||
|
alexrlongne marked this conversation as resolved.
|
||
| std::cout<<"Targets--T: "<<target_T<<" rho: "<<target_rho<<" hnu: "<<target_hnu<<" T frac:" <<T_frac<<" rho frac: "<<rho_frac<<std::endl; | ||
| std::cout<<"Interpolation box: "<<std::endl; | ||
| std::cout<<op_L_R<<"--------"<<op_R_R<<" |"<<std::endl; | ||
| std::cout<<"| |"<<std::endl; | ||
| std::cout<<"| |"<<std::endl; | ||
| std::cout<<"| "<<interp_opac<<" |"<<std::endl; | ||
| std::cout<<"| |"<<std::endl; | ||
| std::cout<<"| |"<<std::endl; | ||
| std::cout<<op_L_L<<"--------"<<op_R_L<<std::endl; | ||
| } | ||
| return interp_opac; | ||
| } | ||
|
|
||
| #endif // _IPCRESS2SPINER_INTERPOLATE_HPP_ | ||
Uh oh!
There was an error while loading. Please reload this page.