Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions .kessel/workflows/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Build(BuildEnvironment):
spack_env = environment("singularity_eos_default")
project_spec = environment("singularity-eos+tests")

xcap_spackages_checkout = environment(Path.cwd() / "extern" / "xcap_spackages", variable="XCAP_SPACKAGES_CHECKOUT")
xcap_spackages_checkout = environment(
Path.cwd() / "extern" / "xcap_spackages", variable="XCAP_SPACKAGES_CHECKOUT")

def ci_message(self, args):
pre_alloc_init = ""
Expand Down Expand Up @@ -43,7 +44,8 @@ def env(self, args):
super().prepare_env(args)

if "KESSEL_DEPLOYMENT" not in self.environ:
self.exec(f"spack repo add {self.xcap_spackages_checkout}/v2/spack_repo/xcap || true")
self.exec(
f"spack repo add {self.xcap_spackages_checkout}/v2/spack_repo/xcap || true")

# Handle spiner and ports-of-call submodule dependencies
spiner_path = self.source_dir / "utils" / "spiner"
Expand All @@ -52,7 +54,8 @@ def env(self, args):

ports_of_call_path = self.source_dir / "utils" / "ports-of-call"
if (ports_of_call_path / ".git").exists():
self.exec(f"spack develop --no-clone -p {ports_of_call_path} ports-of-call@main")
self.exec(
f"spack develop --no-clone -p {ports_of_call_path} ports-of-call@main")

super().install_env(args)

Expand All @@ -62,7 +65,7 @@ def test(self, args):
pushd {self.build_dir}
if [[ -f sesame2spiner/sesame2spiner ]]; then
echo "/usr/projects/data/eos/eos-developmental/Sn2162/v01/sn2162-v01.bin" > sesameFilesDir.txt
sesame2spiner/sesame2spiner -s materials.sp5 ../sesame2spiner/examples/unit_tests/*.dat
sesame2spiner/sesame2spiner -s materials.sp5 ../sesame2spiner/examples/unit_tests/mats.dat
sesame2spiner/sesame2spiner -s duplicates.sp5 ../sesame2spiner/examples/duplicate-test/*.dat
fi
popd""")
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Current develop

### Added (new features/APIs/variables/...)
- [[PR618]](https://github.com/lanl/singularity-eos/pull/618) Add PTDerivativesFromPreferred for computing derivatives of a mixture in a cell
- [[PR623]](https://github.com/lanl/singularity-eos/pull/623) Expanded the sesame2spiner syntax to support multiple material definitions in one input file.
- [[PR618]](https://github.com/lanl/singularity-eos/pull/618) Add PTDerivativesFromPreferred for computing derivatives of a mixture in a cell

### Fixed (Repair bugs, etc)

Expand Down
47 changes: 47 additions & 0 deletions sesame2spiner/examples/all_in_one.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ======================================================================
# © 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.
# ======================================================================

# First material doesn't need <name>
matid = 5030
name = air
# These set the number of grid points per decade
# for each variable. The default is 50 points
# per decade.
numrho/decade = 40
numT/decade = 40
numSie/decade = 40

<aluminum>
matid=3720
name=aluminum # define it again to test
rhomin = 1e-5
Tmin = 1

<helium>
matid = 5762

<steel>
matid = 4272
rhomin = 1e-5
Tmin = 1


<titanium>
matid = 2961
# These set the number of grid points per decade
# for each variable. The default is 50 points
# per decade.
numrho/decade = 30
numT/decade = 25
numSie/decade = 15
51 changes: 51 additions & 0 deletions sesame2spiner/examples/unit_tests/mats.dat
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.
# ======================================================================

# First material doesn't need <name>
matid = 5030
name = air

<Aluminum>
matid=3720
name=Aluminum # can override name

<copper>
matid=3337
piecewiseRho = false
numrho/decade = 50

<deuterium>
matid = 5267

<Foam>
matid=7592
numrho/decade = 200
numT/decade = 200

<gold>
matid = 2700

<neon>
matid = 5000

<steel>
matid=4272
ionization = true

<tin>
matid=2162

<titanium>
matid = 2961

10 changes: 1 addition & 9 deletions sesame2spiner/generate_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,7 @@ herr_t saveAllMaterials(const std::string &savename,
herr_t status = H5_SUCCESS;

for (auto const &filename : filenames) {
Params p(filename);
if (!p.Contains("matid")) {
std::cerr << "Material file " << filename << "is missing matid.\n"
<< "Example input files:\n"
<< EXAMPLESTRING << std::endl;
std::exit(1);
}
matids.push_back(p.Get<int>("matid"));
params.push_back(p);
AddMaterials(params, matids, filename);
}

std::cout << "Saving to file " << savename << std::endl;
Expand Down
85 changes: 85 additions & 0 deletions sesame2spiner/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>

#include "parse_cli.hpp"
#include "parser.hpp"

Params::Params(const std::string &input_file) {
Expand All @@ -39,10 +41,22 @@ void Params::Parse(std::istream &s) {
auto delimiter_pos = line.find("=");
auto name = line.substr(0, delimiter_pos);
auto value = line.substr(delimiter_pos + 1);
// make sure there's no trailing comment
auto comment_pos = value.find("#");
if (comment_pos != std::string::npos) {
value.erase(comment_pos);
}
Comment on lines +44 to +48
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

params_[name] = value;
}
}

void Params::Print(std::ostream &s) const {
s << "\nParams for " << params_.at("name") << "\n";
for (const auto &pair : params_) {
s << pair.first << " = " << pair.second << "\n";
}
}

template <>
std::string Params::Get(const std::string &key) const {
return params_.at(key);
Expand Down Expand Up @@ -74,3 +88,74 @@ bool Params::Get(const std::string &key) const {
throw std::runtime_error("The value of " + key + " is not a boolean.\n");
}
}

void add_param(const Params &p, std::vector<Params> &params, std::vector<int> &matids,
const std::string &filename) {

if (!p.Contains("matid")) {
if (p.Contains("name")) {
const auto &name = p.Get<std::string>("name");
std::cerr << "Material " << name << " in file " << filename << "is missing matid.\n"
<< "Example input files:\n"
<< EXAMPLESTRING << std::endl;
std::exit(1);
} else {
std::cerr << "A Material in file " << filename << "has no name.\n"
<< "Example input files:\n"
<< EXAMPLESTRING << std::endl;
std::exit(1);
}
}
matids.push_back(p.Get<int>("matid"));
params.push_back(p);
}

void parse_file(std::vector<Params> &params, std::vector<int> &matids, std::istream &s,
const std::string &filename) {
std::string line;
Params p;
size_t line_num = 1;
while (getline(s, line)) {
line.erase(std::remove_if(line.begin(), line.end(), isspace), line.end());
if (line[0] == '#' || line.empty()) {
line_num++;
continue;
}
if (line[0] == '<') {
auto term = line.find('>');
if (term == std::string::npos) {
std::cerr << "Missing closing > on line " << line_num << " of file " << filename
<< "\n";
std::exit(1);
}

auto name = line.substr(1, term - 1);
if (!p.Empty()) add_param(p, params, matids, filename);

p.Clear();
p.Set("name", name);
} else {
auto delimiter_pos = line.find("=");
auto name = line.substr(0, delimiter_pos);
auto value = line.substr(delimiter_pos + 1);
// make sure there's no trailing comment
auto comment_pos = value.find("#");
if (comment_pos != std::string::npos) {
value.erase(comment_pos);
}
p.Set(name, value);
}
line_num++;
}
if (!p.Empty()) add_param(p, params, matids, filename);
}

void AddMaterials(std::vector<Params> &params, std::vector<int> &matids,
const std::string &input_file) {
std::ifstream config_file(input_file);
if (config_file.is_open()) {
parse_file(params, matids, config_file, input_file);
} else {
throw std::runtime_error("Couldn't open config file " + input_file + "\n");
}
}
9 changes: 9 additions & 0 deletions sesame2spiner/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

// Parse a simple parameter file with
// "#" denoting comments.
class Params {
public:
Params() = default;
Params(const std::string &input_file);
Params(std::stringstream &input) { Parse(input); }

Expand All @@ -34,10 +36,17 @@ class Params {
T Get(const std::string &key, T default_value) const {
return Contains(key) ? Get<T>(key) : default_value;
}
void Print(std::ostream &s) const;
void Clear() { params_.clear(); }
bool Empty() const { return params_.size() == 0; }
void Set(const std::string &key, const std::string &val) { params_[key] = val; }

private:
void Parse(std::istream &s);
std::unordered_map<std::string, std::string> params_;
};

void AddMaterials(std::vector<Params> &params, std::vector<int> &matids,
const std::string &input_file);

#endif // SESAME2SPINER_PARSER_HPP_
Loading