Skip to content

Commit

Permalink
add default values for various parameters; consistency changes in cod…
Browse files Browse the repository at this point in the history
…e and tests
  • Loading branch information
yardasol committed Dec 8, 2022
1 parent 434ac51 commit 9192e57
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 52 deletions.
4 changes: 4 additions & 0 deletions saltproc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ def read_main_input(main_inp_file):
output_path = (input_path / output_path)
j['output_path'] = output_path.resolve()

# Create output directoy if it doesn't exist
if not Path(j['output_path']).exists():
Path(j['output_path']).mkdir(parents=True)

# Class settings
depcode_input = j['depcode']
simulation_input = j['simulation']
Expand Down
3 changes: 2 additions & 1 deletion saltproc/input_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"description": "Path output data storing folder",
"type": "string",
"pattern": "^(.\\/)*(.*)$",
"default": "saltproc_results"
"default": "saltproc_runtime"
},
"n_depletion_steps": {
"description": "Number of steps for constant power and depletion interval case",
Expand Down Expand Up @@ -259,6 +259,7 @@
"db_name": {
"description": "Output HDF5 database file name",
"type": "string",
"default": "saltproc_results.h5",
"pattern": "^(.*)\\.h5$"},
"restart_flag": {
"description": "Restart simulation from the step when it stopped?",
Expand Down
71 changes: 42 additions & 29 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import pytest

from saltproc.app import read_main_input, _create_depcode_object, _create_reactor_object
from saltproc.app import read_main_input, _create_depcode_object, _create_simulation_object, _create_reactor_object
from saltproc import Simulation


Expand All @@ -23,54 +23,67 @@ def path_test_file(cwd):


@pytest.fixture(scope='session')
def serpent_depcode(cwd):
"""SerpentDepcode object for unit tests"""
def serpent_runtime(cwd, tmpdir_factory):
"""SaltProc objects for Serpent unit tests"""
saltproc_input = str(cwd / 'serpent_data' / 'tap_input.json')
_, _, _, object_input = read_main_input(saltproc_input)
depcode = _create_depcode_object(object_input[0])
depcode.runtime_inputfile = str(cwd / 'serpent_data' / 'tap_reference')
output_dir = str(depcode.output_path).split('/')[-1]
depcode.output_path = tmpdir_factory.mktemp(f'serpent_{output_dir}')

return depcode
simulation = _create_simulation_object(object_input[1], depcode, 1, 1)
#db_path=str(
# cwd /
# 'serpent_data' /
# 'tap_reference_db.h5'))

reactor = _create_reactor_object(object_input[2])

return depcode, simulation, reactor


@pytest.fixture(scope='session')
def serpent_reactor(cwd):
saltproc_input = str(cwd / 'serpent_data' / 'tap_input.json')
_, _, _, object_input = read_main_input(saltproc_input)
reactor = _create_reactor_object(object_input[2])
def serpent_depcode(serpent_runtime):
"""SerpentDepcode object for unit tests"""
depcode, _, _ = serpent_runtime
return depcode


@pytest.fixture(scope='session')
def serpent_reactor(serpent_runtime):
_, _, reactor = serpent_runtime
return reactor


@pytest.fixture(scope='session')
def openmc_depcode(cwd):
"""OpenMCDepcode object for unit tests"""
def simulation(serpent_runtime):
"""Simulation object for unit tests"""
_, simulation, _ = serpent_runtime
return simulation


@pytest.fixture(scope='session')
def openmc_runtime(cwd, tmpdir_factory):
"""SaltProc objects for OpenMC unit tests"""
saltproc_input = str(cwd / 'openmc_data' / 'tap_input.json')
_, _, _, object_input = read_main_input(saltproc_input)
depcode = _create_depcode_object(object_input[0])
output_dir = str(depcode.output_path).split('/')[-1]
depcode.output_path = tmpdir_factory.mktemp(f'openmc_{output_dir}')
reactor = _create_reactor_object(object_input[2])

return depcode
return depcode, reactor


@pytest.fixture(scope='session')
def openmc_reactor(cwd):
openmc_input = str(cwd / 'openmc_data' / 'tap_input.json')
_, _, _, object_input = read_main_input(openmc_input)
reactor = _create_reactor_object(object_input[2])

return reactor
def openmc_depcode(openmc_runtime):
"""OpenMCDepcode objects for unit tests"""
depcode, _ = openmc_runtime
return depcode


@pytest.fixture(scope='session')
def simulation(cwd, serpent_depcode):
"""Simulation object for unit tests"""
simulation = Simulation(
sim_name='test_simulation',
sim_depcode=serpent_depcode,
core_number=1,
node_number=1,
db_path=str(
cwd /
'serpent_data' /
'tap_reference_db.h5'))
return simulation
def openmc_reactor(openmc_runtime):
_, reactor = openmc_runtime
return reactor
2 changes: 1 addition & 1 deletion tests/integration_tests/file_interface_openmc/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_write_depletion_settings(openmc_depcode, msr):
with open(openmc_depcode.output_path / 'depletion_settings.json') as f:
j = json.load(f)
assert Path(j['directory']).resolve() == Path(
openmc_depcode.runtime_inputfile['settings']).parents[0]
openmc_depcode.output_path)
assert j['timesteps'][0] == msr.depletion_timesteps[0]
assert j['operator_kwargs']['chain_file'] == \
openmc_depcode.chain_file_path
Expand Down
5 changes: 4 additions & 1 deletion tests/integration_tests/run_constant_reprocessing/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Run SaltProc with reprocessing"""
from pathlib import Path
import shutil

import numpy as np
import pytest
Expand All @@ -11,7 +12,7 @@
@pytest.fixture
def setup(scope='module'):
cwd = str(Path(__file__).parents[0].resolve())
test_db = cwd + '/test_db.h5'
test_db = cwd + '/saltproc_runtime/saltproc_results.h5'
ref_db = cwd + '/tap_reference_db.h5'
tol = 1e-9

Expand All @@ -28,6 +29,8 @@ def test_integration_2step_constant_ideal_removal_heavy(setup):
np.testing.assert_equal(read_keff(test_db), read_keff(ref_db))
assert_db_almost_equal(test_db, ref_db, tol)

shutil.rmtree(cwd + '/saltproc_runtime')

def read_keff(file):
db = tb.open_file(file, mode='r')
sim_param = db.root.simulation_parameters
Expand Down
29 changes: 10 additions & 19 deletions tests/integration_tests/run_no_reprocessing/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Run SaltProc without reprocessing"""
import os
import glob
from pathlib import Path
import shutil

import numpy as np
import pytest
Expand All @@ -14,31 +13,28 @@
@pytest.fixture
def setup():
cwd = str(Path(__file__).parents[0].resolve())
main_input = cwd + '/test_input.json'
saltproc_input = cwd + '/test_input.json'

input_path, process_input_file, path_input_file, object_input = \
app.read_main_input(main_input)
app.read_main_input(saltproc_input)

depcode = app._create_depcode_object(object_input[0])
sss_file = cwd + '/_test'
depcode.runtime_inputfile = sss_file
depcode.runtime_matfile = cwd + '/_test_mat'

simulation = app._create_simulation_object(object_input[1], depcode, 1, 1)

reactor = app._create_reactor_object(object_input[2], object_input[0]['codename'])
reactor = app._create_reactor_object(object_input[2])

return cwd, simulation, reactor, sss_file
return cwd, simulation, reactor


@pytest.mark.slow
def test_integration_2step_saltproc_no_reproc_heavy(setup):
cwd, simulation, reactor, sss_file = setup
cwd, simulation, reactor = setup
runsim_no_reproc(simulation, reactor, 2)
saltproc_out = sss_file + '_dep.m'

output_path = str(simulation.sim_depcode.output_path)
ref_result = serpent.parse_dep(cwd + '/reference_dep.m', make_mats=False)
test_result = serpent.parse_dep(saltproc_out, make_mats=False)
test_result = serpent.parse_dep(f'{output_path}/runtime_input.serpent_dep.m', make_mats=False)

ref_mdens_error = np.loadtxt(cwd + '/reference_error')

Expand All @@ -47,13 +43,8 @@ def test_integration_2step_saltproc_no_reproc_heavy(setup):

test_mdens_error = np.array(ref_fuel_mdens - test_fuel_mdens)
np.testing.assert_array_almost_equal(test_mdens_error, ref_mdens_error)
# Cleaning after testing
out_file_list = glob.glob(cwd + '/_test*')
for file in out_file_list:
try:
os.remove(file)
except OSError:
print("Error while deleting file : ", file)

shutil.rmtree(cwd + '/saltproc_runtime')


def runsim_no_reproc(simulation, reactor, nsteps):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_read_main_input(cwd, codename, ext):
str((input_path / 'tap_template.ini').resolve())

assert simulation_input['db_name'] == \
str((data_path / '../temp_data/db_saltproc.h5').resolve())
str((data_path / f'../{codename}_data/saltproc_runtime/saltproc_results.h5').resolve())
assert simulation_input['restart_flag'] is False

np.testing.assert_equal(
Expand Down

0 comments on commit 9192e57

Please sign in to comment.