Skip to content

Commit

Permalink
corrected OpenMC Lib
Browse files Browse the repository at this point in the history
  • Loading branch information
dodu94 committed Feb 17, 2025
1 parent 9d6abd8 commit b210153
Show file tree
Hide file tree
Showing 8 changed files with 704 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/source/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ scipy
python-docx
aspose-words
requests
f4enix >= 0.8.1
f4enix >= 0.12.0
seaborn
# DOC reqs
sphinx
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"python-docx",
"aspose-words",
"requests",
"f4enix >= 0.8.1",
"f4enix >= 0.12.0",
# openmc @ git+https://github.com/openmc-dev/[email protected]#egg=openmc
"pyyaml",
"ttkthemes",
Expand Down
19 changes: 11 additions & 8 deletions src/jade/config/run_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import xml.etree.ElementTree as ET
from abc import ABC, abstractmethod
from collections.abc import Sequence
from dataclasses import dataclass
Expand Down Expand Up @@ -256,14 +257,16 @@ def __post_init__(self):
# table to get the correct zaid name. This could be expensive.
lm = LibManager(defaultlib="00c") # Just for name conversions
self._available_zaids = []
for filename in os.listdir(self.path):
if filename.endswith(".h5"):
zaid = filename.split(".")[0]
try:
zaidnum = lm.get_zaidnum(zaid)
except ValueError:
continue # ignore the files that we cannot understand for the moment
self._available_zaids.append(zaidnum)
root = ET.parse(self.path).getroot()
for type_tag in root.findall("library"):
zaidname = type_tag.get("materials")
try:
zaidnum = lm.get_zaidnum(str(zaidname))
except ValueError:
continue # ignore the files that we cannot understand for the moment
except KeyError:
continue # ignore the files that we cannot understand for the moment
self._available_zaids.append(zaidnum)

def get_lib_zaids(self) -> list[str]:
return self._available_zaids
Expand Down
685 changes: 685 additions & 0 deletions tests/config/resources/cross_sections.xml

Large diffs are not rendered by default.

Empty file.
Empty file.
Empty file.
13 changes: 6 additions & 7 deletions tests/config/test_run_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from importlib.resources import files
from importlib.resources import as_file, files

import pytest

Expand All @@ -19,7 +19,7 @@
from tests.config import resources as conf_res

ROOT_DEFAULT_CFG = files(res).joinpath("default_cfg")
OPENMC_LIBS = files(conf_res).joinpath("openmclib")
CONF_RES = files(conf_res)


class TestEnvironmentVariables:
Expand Down Expand Up @@ -122,9 +122,8 @@ def test_from_yamls(self, tmpdir):

class TestLibraryOpenMC:
def test_post(self):
with OPENMC_LIBS as path:
lib = LibraryOpenMC("dummy", path)
with as_file(CONF_RES.joinpath("cross_sections.xml")) as file:
lib = LibraryOpenMC("dummy", file)

for name in lib.get_lib_zaids():
assert name in ["1001", "2004"]
assert len(lib.get_lib_zaids()) == 2
assert "1001" in lib.get_lib_zaids()
assert "1000" in lib.get_lib_zaids()

0 comments on commit b210153

Please sign in to comment.