mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Merge pull request #2168 from paulromano/time-filter-fix
Fix TimeFilter for very small time intervals with tracklength estimator
This commit is contained in:
commit
12ced92140
2 changed files with 43 additions and 4 deletions
|
|
@ -55,13 +55,16 @@ void TimeFilter::get_all_bins(
|
|||
// the current track and find where it overlaps with time bins and score
|
||||
// accordingly
|
||||
|
||||
// Skip if time interval is zero
|
||||
if (t_start == t_end)
|
||||
return;
|
||||
|
||||
// Determine first bin containing a portion of time interval
|
||||
auto i_bin = lower_bound_index(bins_.begin(), bins_.end(), t_start);
|
||||
|
||||
// If time interval is zero, add a match corresponding to the starting time
|
||||
if (t_end == t_start) {
|
||||
match.bins_.push_back(i_bin);
|
||||
match.weights_.push_back(1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Find matching bins
|
||||
double dt_total = t_end - t_start;
|
||||
for (; i_bin < bins_.size() - 1; ++i_bin) {
|
||||
|
|
|
|||
|
|
@ -149,3 +149,39 @@ def test_time_filter_surface(model_surf, run_in_tmpdir):
|
|||
|
||||
# After t0+ε, the current should be zero
|
||||
assert values[2] == 0.0
|
||||
|
||||
|
||||
def test_small_time_interval(run_in_tmpdir):
|
||||
# Create a model with a photon source at 1.0e8 seconds. Based on the speed
|
||||
# of the photon, the time intervals are on the order of 1e-9 seconds, which
|
||||
# are effectively 0 when compared to the starting time of the photon.
|
||||
mat = openmc.Material()
|
||||
mat.add_element('N', 1.0)
|
||||
mat.set_density('g/cm3', 0.001)
|
||||
sph = openmc.Sphere(r=5.0, boundary_type='vacuum')
|
||||
cell = openmc.Cell(fill=mat, region=-sph)
|
||||
model = openmc.Model()
|
||||
model.geometry = openmc.Geometry([cell])
|
||||
model.settings.particles = 100
|
||||
model.settings.batches = 10
|
||||
model.settings.run_mode = 'fixed source'
|
||||
model.settings.source = openmc.Source(
|
||||
time=openmc.stats.Discrete([1.0e8], [1.0]),
|
||||
particle='photon'
|
||||
)
|
||||
|
||||
# Add tallies with and without a time filter that should match all particles
|
||||
time_filter = openmc.TimeFilter([0.0, 1.0e100])
|
||||
tally_with_filter = openmc.Tally()
|
||||
tally_with_filter.filters = [time_filter]
|
||||
tally_with_filter.scores = ['flux']
|
||||
tally_without_filter = openmc.Tally()
|
||||
tally_without_filter.scores = ['flux']
|
||||
model.tallies.extend([tally_with_filter, tally_without_filter])
|
||||
|
||||
# Run the model and make sure the two tallies match
|
||||
sp_filename = model.run()
|
||||
with openmc.StatePoint(sp_filename) as sp:
|
||||
flux_with = sp.tallies[tally_with_filter.id].mean.ravel()[0]
|
||||
flux_without = sp.tallies[tally_without_filter.id].mean.ravel()[0]
|
||||
assert flux_with == pytest.approx(flux_without)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue