Skip to content

Commit

Permalink
Setting surf_source_ attribute for DAGMC surfaces. (openmc-dev#2857)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
pshriwise and paulromano authored Jan 30, 2024
1 parent 09eb33a commit cb7ef00
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/dagmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ void DAGUniverse::init_geometry()
s->id_ = adjust_geometry_ids_ ? next_surf_id++
: dagmc_instance_->id_by_index(2, i + 1);

// set surface source attribute if needed
if (contains(settings::source_write_surf_id, s->id_))
s->surf_source_ = true;

// set BCs
std::string bc_value =
dmd_ptr->get_surface_property("boundary", surf_handle);
Expand Down
36 changes: 33 additions & 3 deletions tests/regression_tests/dagmc/legacy/test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from pathlib import Path

import openmc
import openmc.lib

from pathlib import Path
import h5py
import numpy as np
import pytest
from tests.testing_harness import PyAPITestHarness

from tests.testing_harness import PyAPITestHarness, config

pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
Expand All @@ -13,7 +17,7 @@
def model():
openmc.reset_auto_ids()

model = openmc.model.Model()
model = openmc.Model()

# settings
model.settings.batches = 5
Expand Down Expand Up @@ -73,6 +77,32 @@ def test_missing_material_name(model):
assert exp_error_msg in str(exec_info.value)


def test_surf_source(model):
# create a surface source read on this model to ensure
# particles are being generated correctly
n = 100
model.settings.surf_source_write = {'surface_ids': [1], 'max_particles': n}

# If running in MPI mode, setup proper keyword arguments for run()
kwargs = {'openmc_exec': config['exe']}
if config['mpi']:
kwargs['mpi_args'] = [config['mpiexec'], '-n', config['mpi_np']]
model.run(**kwargs)

with h5py.File('surface_source.h5') as fh:
assert fh.attrs['filetype'] == b'source'
arr = fh['source_bank'][...]
expected_size = n * int(config['mpi_np']) if config['mpi'] else n
assert arr.size == expected_size

# check that all particles are on surface 1 (radius = 7)
xs = arr[:]['r']['x']
ys = arr[:]['r']['y']
rad = np.sqrt(xs**2 + ys**2)
assert np.allclose(rad, 7.0)


def test_dagmc(model):
harness = PyAPITestHarness('statepoint.5.h5', model)
harness.main()

0 comments on commit cb7ef00

Please sign in to comment.