-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement filter for cosine of angle of surface crossing (#2768)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
- Loading branch information
1 parent
1a520c9
commit c285a2c
Showing
14 changed files
with
254 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef OPENMC_TALLIES_FILTER_MU_SURFACE_H | ||
#define OPENMC_TALLIES_FILTER_MU_SURFACE_H | ||
|
||
#include <gsl/gsl-lite.hpp> | ||
|
||
#include "openmc/tallies/filter_mu.h" | ||
#include "openmc/vector.h" | ||
|
||
namespace openmc { | ||
|
||
//============================================================================== | ||
//! Bins the incoming-outgoing direction cosine. This is only used for surface | ||
//! crossings. | ||
//============================================================================== | ||
|
||
class MuSurfaceFilter : public MuFilter { | ||
public: | ||
//---------------------------------------------------------------------------- | ||
// Constructors, destructors | ||
|
||
~MuSurfaceFilter() = default; | ||
|
||
//---------------------------------------------------------------------------- | ||
// Methods | ||
|
||
std::string type_str() const override { return "musurface"; } | ||
FilterType type() const override { return FilterType::MUSURFACE; } | ||
|
||
void get_all_bins(const Particle& p, TallyEstimator estimator, | ||
FilterMatch& match) const override; | ||
}; | ||
|
||
} // namespace openmc | ||
#endif // OPENMC_TALLIES_FILTER_MU_SURFACE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "openmc/tallies/filter_musurface.h" | ||
|
||
#include <cmath> // for abs, copysign | ||
|
||
#include "openmc/search.h" | ||
#include "openmc/surface.h" | ||
#include "openmc/tallies/tally_scoring.h" | ||
|
||
namespace openmc { | ||
|
||
void MuSurfaceFilter::get_all_bins( | ||
const Particle& p, TallyEstimator estimator, FilterMatch& match) const | ||
{ | ||
// Get surface normal (and make sure it is a unit vector) | ||
const auto surf {model::surfaces[std::abs(p.surface()) - 1].get()}; | ||
auto n = surf->normal(p.r()); | ||
n /= n.norm(); | ||
|
||
// Determine whether normal should be pointing in or out | ||
if (p.surface() < 0) | ||
n *= -1; | ||
|
||
// Determine cosine of angle between normal and particle direction | ||
double mu = p.u().dot(n); | ||
if (std::abs(mu) > 1.0) | ||
mu = std::copysign(1.0, mu); | ||
|
||
// Find matching bin | ||
if (mu >= bins_.front() && mu <= bins_.back()) { | ||
auto bin = lower_bound_index(bins_.begin(), bins_.end(), mu); | ||
match.bins_.push_back(bin); | ||
match.weights_.push_back(1.0); | ||
} | ||
} | ||
|
||
} // namespace openmc |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<model> | ||
<materials> | ||
<material depletable="true" id="1"> | ||
<density units="g/cm3" value="10.0"/> | ||
<nuclide ao="1.0" name="U235"/> | ||
</material> | ||
<material id="2"> | ||
<density units="g/cm3" value="1.0"/> | ||
<nuclide ao="1.0" name="Zr90"/> | ||
</material> | ||
</materials> | ||
<geometry> | ||
<cell id="1" material="1" region="-1" universe="1"/> | ||
<cell id="2" material="2" region="1 -2" universe="1"/> | ||
<surface coeffs="0.0 0.0 1.0" id="1" type="z-cylinder"/> | ||
<surface boundary="vacuum" coeffs="0.0 0.0 3.0" id="2" type="z-cylinder"/> | ||
</geometry> | ||
<settings> | ||
<run_mode>eigenvalue</run_mode> | ||
<particles>1000</particles> | ||
<batches>5</batches> | ||
<inactive>0</inactive> | ||
</settings> | ||
<tallies> | ||
<filter id="1" type="surface"> | ||
<bins>1</bins> | ||
</filter> | ||
<filter id="2" type="musurface"> | ||
<bins>-1.0 -0.5 0.0 0.5 1.0</bins> | ||
</filter> | ||
<tally id="1"> | ||
<filters>1 2</filters> | ||
<scores>current</scores> | ||
</tally> | ||
</tallies> | ||
</model> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
k-combined: | ||
1.157005E-01 7.587090E-03 | ||
tally 1: | ||
0.000000E+00 | ||
0.000000E+00 | ||
0.000000E+00 | ||
0.000000E+00 | ||
8.770000E-01 | ||
1.608710E-01 | ||
3.909000E+00 | ||
3.063035E+00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import numpy as np | ||
from math import pi | ||
|
||
import openmc | ||
import pytest | ||
|
||
from tests.testing_harness import PyAPITestHarness | ||
|
||
|
||
@pytest.fixture | ||
def model(): | ||
model = openmc.Model() | ||
fuel = openmc.Material() | ||
fuel.set_density('g/cm3', 10.0) | ||
fuel.add_nuclide('U235', 1.0) | ||
zr = openmc.Material() | ||
zr.set_density('g/cm3', 1.0) | ||
zr.add_nuclide('Zr90', 1.0) | ||
|
||
cyl1 = openmc.ZCylinder(r=1.0) | ||
cyl2 = openmc.ZCylinder(r=3.0, boundary_type='vacuum') | ||
cell1 = openmc.Cell(fill=fuel, region=-cyl1) | ||
cell2 = openmc.Cell(fill=zr, region=+cyl1 & -cyl2) | ||
model.geometry = openmc.Geometry([cell1, cell2]) | ||
|
||
model.settings.batches = 5 | ||
model.settings.inactive = 0 | ||
model.settings.particles = 1000 | ||
|
||
# Create a tally for current through the first surface binned by mu | ||
surf_filter = openmc.SurfaceFilter([cyl1]) | ||
mu_filter = openmc.MuSurfaceFilter([-1.0, -0.5, 0.0, 0.5, 1.0]) | ||
tally = openmc.Tally() | ||
tally.filters = [surf_filter, mu_filter] | ||
tally.scores = ['current'] | ||
model.tallies.append(tally) | ||
|
||
return model | ||
|
||
|
||
def test_filter_musurface(model): | ||
harness = PyAPITestHarness('statepoint.5.h5', model) | ||
harness.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import openmc | ||
|
||
|
||
def test_musurface(run_in_tmpdir): | ||
sphere = openmc.Sphere(r=1.0, boundary_type='vacuum') | ||
cell = openmc.Cell(region=-sphere) | ||
model = openmc.Model() | ||
model.geometry = openmc.Geometry([cell]) | ||
model.settings.particles = 1000 | ||
model.settings.batches = 10 | ||
E = 1.0 | ||
model.settings.source = openmc.IndependentSource( | ||
space=openmc.stats.Point(), | ||
angle=openmc.stats.Isotropic(), | ||
energy=openmc.stats.delta_function(E), | ||
) | ||
model.settings.run_mode = "fixed source" | ||
|
||
filter1 = openmc.MuSurfaceFilter(200) | ||
filter2 = openmc.SurfaceFilter(sphere) | ||
tally = openmc.Tally() | ||
tally.filters = [filter1, filter2] | ||
tally.scores = ['current'] | ||
model.tallies = openmc.Tallies([tally]) | ||
|
||
# Run OpenMC | ||
sp_filename = model.run() | ||
|
||
# Get current binned by mu | ||
with openmc.StatePoint(sp_filename) as sp: | ||
current_mu = sp.tallies[tally.id].mean.ravel() | ||
|
||
# All contributions should show up in last bin | ||
assert current_mu[-1] == 1.0 | ||
for element in current_mu[:-1]: | ||
assert element == 0.0 | ||
|
||
|