Python source class refactor (#2524)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Patrick Shriwise 2023-06-20 21:27:55 -05:00 committed by GitHub
parent ee7b95245a
commit eda39ad9ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
146 changed files with 648 additions and 4310 deletions

View file

@ -449,24 +449,27 @@ attributes/sub-elements:
*Default*: 1.0
:type:
Indicator of source type. One of ``independent``, ``file``, or ``compiled``.
:particle:
The source particle type, either ``neutron`` or ``photon``.
*Default*: neutron
:file:
If this attribute is given, it indicates that the source is to be read from
a binary source file whose path is given by the value of this element. Note,
the number of source sites needs to be the same as the number of particles
simulated in a fission source generation.
If this attribute is given, it indicates that the source type is ``file``,
meaning particles are to be read from a binary source file whose path is
given by the value of this element.
*Default*: None
:library:
If this attribute is given, it indicates that the source is to be
instantiated from an externally compiled source function. This source can be
as complex as is required to define the source for your problem. The library
has a few basic requirements:
If this attribute is given, it indicates that the source type is
``compiled``, meaning that particles are instantiated from an externally
compiled source function. This source can be completely customized as needed
to define the source for your problem. The library has a few basic
requirements:
* It must contain a class that inherits from ``openmc::Source``;
* The class must implement a function called ``sample()``;
@ -476,14 +479,12 @@ attributes/sub-elements:
More documentation on how to build sources can be found in :ref:`custom_source`.
*Default*: None
:parameters:
If this attribute is given, it provides the parameters to pass through to the
class generated using the ``library`` parameter . More documentation on how to
build parametrized sources can be found in :ref:`parameterized_custom_source`.
*Default*: None
If this attribute is given, it indicated that the source type is
``compiled``. Its value provides the parameters to pass through to the class
generated using the ``library`` parameter. More documentation on how to
build parametrized sources can be found in
:ref:`parameterized_custom_source`.
:space:
An element specifying the spatial distribution of source sites. This element

View file

@ -112,7 +112,7 @@ def assembly_model():
model.settings.batches = 150
model.settings.inactive = 50
model.settings.particles = 1000
model.settings.source = openmc.Source(space=openmc.stats.Box(
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
(-pitch/2, -pitch/2, -1),
(pitch/2, pitch/2, 1),
only_fissionable=True

View file

@ -18,7 +18,7 @@ settings = openmc.Settings()
settings.run_mode = 'fixed source'
settings.batches = 10
settings.particles = 1000
source = openmc.Source()
source = openmc.IndependentSource()
source.library = 'build/libsource.so'
settings.source = source
settings.export_to_xml()

View file

@ -18,7 +18,7 @@ settings = openmc.Settings()
settings.run_mode = 'fixed source'
settings.batches = 10
settings.particles = 1000
source = openmc.Source()
source = openmc.IndependentSource()
source.library = 'build/libparameterized_source.so'
source.parameters = 'radius=3.0, energy=14.08e6'
settings.source = source

View file

@ -115,26 +115,26 @@ private:
//! Wrapper for custom sources that manages opening/closing shared library
//==============================================================================
class CustomSourceWrapper : public Source {
class CompiledSourceWrapper : public Source {
public:
// Constructors, destructors
CustomSourceWrapper(std::string path, std::string parameters);
~CustomSourceWrapper();
CompiledSourceWrapper(std::string path, std::string parameters);
~CompiledSourceWrapper();
// Defer implementation to custom source library
SourceSite sample(uint64_t* seed) const override
{
return custom_source_->sample(seed);
return compiled_source_->sample(seed);
}
double strength() const override { return custom_source_->strength(); }
double strength() const override { return compiled_source_->strength(); }
private:
void* shared_library_; //!< library from dlopen
unique_ptr<Source> custom_source_;
unique_ptr<Source> compiled_source_;
};
typedef unique_ptr<Source> create_custom_source_t(std::string parameters);
typedef unique_ptr<Source> create_compiled_source_t(std::string parameters);
//==============================================================================
// Functions

View file

@ -76,7 +76,7 @@ def pwr_pin_cell():
model.settings.batches = 10
model.settings.inactive = 5
model.settings.particles = 100
model.settings.source = openmc.Source(space=openmc.stats.Box(
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
[-pitch/2, -pitch/2, -1], [pitch/2, pitch/2, 1], only_fissionable=True))
plot = openmc.Plot.from_geometry(model.geometry)
@ -415,7 +415,7 @@ def pwr_core():
model.settings.batches = 10
model.settings.inactive = 5
model.settings.particles = 100
model.settings.source = openmc.Source(space=openmc.stats.Box(
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
[-160, -160, -183], [160, 160, 183]))
plot = openmc.Plot()
@ -527,7 +527,7 @@ def pwr_assembly():
model.settings.batches = 10
model.settings.inactive = 5
model.settings.particles = 100
model.settings.source = openmc.Source(space=openmc.stats.Box(
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
[-pitch/2, -pitch/2, -1], [pitch/2, pitch/2, 1], only_fissionable=True))
plot = openmc.Plot()
@ -629,7 +629,7 @@ def slab_mg(num_regions=1, mat_names=None, mgxslib_name='2g.h5'):
INF = 1000.
bounds = [0., -INF, -INF, rads[0], INF, INF]
uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:])
settings_file.source = openmc.source.Source(space=uniform_dist)
settings_file.source = openmc.IndependentSource(space=uniform_dist)
settings_file.output = {'summary': False}

View file

@ -13,8 +13,8 @@ import lxml.etree as ET
import openmc.checkvalue as cv
from openmc.stats.multivariate import MeshSpatial
from . import (RegularMesh, Source, VolumeCalculation, WeightWindows,
WeightWindowGenerator)
from . import (RegularMesh, SourceBase, IndependentSource,
VolumeCalculation, WeightWindows, WeightWindowGenerator)
from ._xml import clean_indentation, get_text, reorder_attributes
from openmc.checkvalue import PathLike
from .mesh import _read_meshes
@ -150,7 +150,7 @@ class Settings:
The type of calculation to perform (default is 'eigenvalue')
seed : int
Seed for the linear congruential pseudorandom number generator
source : Iterable of openmc.Source
source : Iterable of openmc.SourceBase
Distribution of source sites in space, angle, and energy
sourcepoint : dict
Options for writing source points. Acceptable keys are:
@ -265,7 +265,7 @@ class Settings:
self._max_order = None
# Source subelement
self._source = cv.CheckedList(Source, 'source distributions')
self._source = cv.CheckedList(SourceBase, 'source distributions')
self._confidence_intervals = None
self._electron_treatment = None
@ -459,14 +459,14 @@ class Settings:
self._max_order = max_order
@property
def source(self) -> typing.List[Source]:
def source(self) -> typing.List[SourceBase]:
return self._source
@source.setter
def source(self, source: typing.Union[Source, typing.Iterable[Source]]):
def source(self, source: typing.Union[SourceBase, typing.Iterable[SourceBase]]):
if not isinstance(source, MutableSequence):
source = [source]
self._source = cv.CheckedList(Source, 'source distributions', source)
self._source = cv.CheckedList(SourceBase, 'source distributions', source)
@property
def confidence_intervals(self) -> bool:
@ -969,7 +969,7 @@ class Settings:
if not isinstance(wwgs, MutableSequence):
wwgs = [wwgs]
self._weight_window_generators = cv.CheckedList(WeightWindowGenerator, 'weight window generators', wwgs)
def _create_run_mode_subelement(self, root):
elem = ET.SubElement(root, "run_mode")
elem.text = self._run_mode.value
@ -1024,7 +1024,7 @@ class Settings:
def _create_source_subelement(self, root):
for source in self.source:
root.append(source.to_xml_element())
if isinstance(source.space, MeshSpatial):
if isinstance(source, IndependentSource) and isinstance(source.space, MeshSpatial):
path = f"./mesh[@id='{source.space.mesh.id}']"
if root.find(path) is None:
root.append(source.space.mesh.to_xml_element())
@ -1402,7 +1402,7 @@ class Settings:
def _source_from_xml_element(self, root, meshes=None):
for elem in root.findall('source'):
src = Source.from_xml_element(elem, meshes)
src = SourceBase.from_xml_element(elem, meshes)
# add newly constructed source object to the list
self.source.append(src)

View file

@ -1,3 +1,5 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from collections.abc import Iterable
from enum import IntEnum
from numbers import Real
@ -16,9 +18,107 @@ from openmc.checkvalue import PathLike
from openmc.stats.multivariate import UnitSphere, Spatial
from openmc.stats.univariate import Univariate
from ._xml import get_text
from .mesh import MeshBase
class Source:
class SourceBase(ABC):
"""Base class for external sources
Parameters
----------
strength : float
Strength of the source
Attributes
----------
type : {'independent', 'file', 'compiled'}
Indicator of source type.
strength : float
Strength of the source
"""
def __init__(self, strength=1.0):
self.strength = strength
@property
def strength(self):
return self._strength
@strength.setter
def strength(self, strength):
cv.check_type('source strength', strength, Real)
cv.check_greater_than('source strength', strength, 0.0, True)
self._strength = strength
@abstractmethod
def populate_xml_element(self, element):
"""Add necessary source information to an XML element
Returns
-------
element : lxml.etree._Element
XML element containing source data
"""
pass
def to_xml_element(self) -> ET.Element:
"""Return XML representation of the source
Returns
-------
element : xml.etree.ElementTree.Element
XML element containing source data
"""
element = ET.Element("source")
element.set("type", self.type)
element.set("strength", str(self.strength))
self.populate_xml_element(element)
return element
@classmethod
def from_xml_element(cls, elem: ET.Element, meshes=None) -> openmc.SourceBase:
"""Generate source from an XML element
Parameters
----------
elem : lxml.etree._Element
XML element
meshes : dict
Dictionary with mesh IDs as keys and openmc.MeshBase instances as
values
Returns
-------
openmc.SourceBase
Source generated from XML element
"""
source_type = get_text(elem, 'type')
if source_type is None:
# attempt to determine source type based on attributes
# for backward compatibility
if get_text(elem, 'file') is not None:
return FileSource.from_xml_element(elem)
elif get_text(elem, 'library') is not None:
return CompiledSource.from_xml_element(elem)
else:
return IndependentSource.from_xml_element(elem)
else:
if source_type == 'independent':
return IndependentSource.from_xml_element(elem, meshes)
elif source_type == 'compiled':
return CompiledSource.from_xml_element(elem)
elif source_type == 'file':
return FileSource.from_xml_element(elem)
else:
raise ValueError(f'Source type {source_type} is not recognized')
class IndependentSource(SourceBase):
"""Distribution of phase space coordinates for source sites.
Parameters
@ -31,14 +131,6 @@ class Source:
Energy distribution of source sites
time : openmc.stats.Univariate
time distribution of source sites
filename : str
Source file from which sites should be sampled
library : str
Path to a custom source library
parameters : str
Parameters to be provided to the custom source library
.. versionadded:: 0.12
strength : float
Strength of the source
particle : {'neutron', 'photon'}
@ -57,14 +149,13 @@ class Source:
Energy distribution of source sites
time : openmc.stats.Univariate or None
time distribution of source sites
file : str or None
Source file from which sites should be sampled
library : str or None
Path to a custom source library
parameters : str
Parameters to be provided to the custom source library
strength : float
Strength of the source
type : str
Indicator of source type: 'independent'
.. versionadded:: 0.13.4
particle : {'neutron', 'photon'}
Source particle type
ids : Iterable of int
@ -80,20 +171,16 @@ class Source:
angle: Optional[openmc.stats.UnitSphere] = None,
energy: Optional[openmc.stats.Univariate] = None,
time: Optional[openmc.stats.Univariate] = None,
filename: Optional[str] = None,
library: Optional[str] = None,
parameters: Optional[str] = None,
strength: float = 1.0,
particle: str = 'neutron',
domains: Optional[Sequence[typing.Union[openmc.Cell, openmc.Material, openmc.Universe]]] = None
):
super().__init__(strength)
self._space = None
self._angle = None
self._energy = None
self._time = None
self._file = None
self._library = None
self._parameters = None
if space is not None:
self.space = space
@ -103,12 +190,6 @@ class Source:
self.energy = energy
if time is not None:
self.time = time
if filename is not None:
self.file = filename
if library is not None:
self.library = library
if parameters is not None:
self.parameters = parameters
self.strength = strength
self.particle = particle
@ -124,31 +205,25 @@ class Source:
self.domain_ids = [d.id for d in domains]
@property
def file(self):
return self._file
def type(self) -> str:
return 'independent'
@file.setter
def file(self, filename):
cv.check_type('source file', filename, str)
self._file = filename
def __getattr__(self, name):
cls_names = {'file': 'FileSource', 'library': 'CompiledSource',
'parameters': 'CompiledSource'}
if name in cls_names:
raise AttributeError(
f'The "{name}" attribute has been deprecated on the '
f'IndependentSource class. Please use the {cls_names[name]} class.')
else:
super().__getattribute__(name)
@property
def library(self):
return self._library
@library.setter
def library(self, library_name):
cv.check_type('library', library_name, str)
self._library = library_name
@property
def parameters(self):
return self._parameters
@parameters.setter
def parameters(self, parameters_path):
cv.check_type('parameters', parameters_path, str)
self._parameters = parameters_path
def __setattr__(self, name, value):
if name in ('file', 'library', 'parameters'):
# Ensure proper AttributeError is thrown
getattr(self, name)
else:
super().__setattr__(name, value)
@property
def space(self):
@ -186,16 +261,6 @@ class Source:
cv.check_type('time distribution', time, Univariate)
self._time = time
@property
def strength(self):
return self._strength
@strength.setter
def strength(self, strength):
cv.check_type('source strength', strength, Real)
cv.check_greater_than('source strength', strength, 0.0, True)
self._strength = strength
@property
def particle(self):
return self._particle
@ -223,25 +288,16 @@ class Source:
cv.check_value('domain type', domain_type, ('cell', 'material', 'universe'))
self._domain_type = domain_type
def to_xml_element(self) -> ET.Element:
"""Return XML representation of the source
def populate_xml_element(self, element):
"""Add necessary source information to an XML element
Returns
-------
element : lxml.etree._Element
XML element containing source data
"""
element = ET.Element("source")
element.set("strength", str(self.strength))
if self.particle != 'neutron':
element.set("particle", self.particle)
if self.file is not None:
element.set("file", self.file)
if self.library is not None:
element.set("library", self.library)
if self.parameters is not None:
element.set("parameters", self.parameters)
super().populate_xml_element(element)
element.set("particle", self.particle)
if self.space is not None:
element.append(self.space.to_xml_element())
if self.angle is not None:
@ -255,10 +311,9 @@ class Source:
dt_elem.text = self.domain_type
id_elem = ET.SubElement(element, "domain_ids")
id_elem.text = ' '.join(str(uid) for uid in self.domain_ids)
return element
@classmethod
def from_xml_element(cls, elem: ET.Element, meshes=None) -> 'openmc.Source':
def from_xml_element(cls, elem: ET.Element, meshes=None) -> 'openmc.SourceBase':
"""Generate source from an XML element
Parameters
@ -306,14 +361,6 @@ class Source:
if filename is not None:
source.file = filename
library = get_text(elem, 'library')
if library is not None:
source.library = library
parameters = get_text(elem, 'parameters')
if parameters is not None:
source.parameters = parameters
space = elem.find('space')
if space is not None:
source.space = Spatial.from_xml_element(space, meshes)
@ -333,6 +380,210 @@ class Source:
return source
def Source(*args, **kwargs):
"""
A function for backward compatibility of sources. Will be removed in the
future. Please update to IndependentSource.
"""
warnings.warn("This class is deprecated in favor of 'IndependentSource'", FutureWarning)
return openmc.IndependentSource(*args, **kwargs)
class CompiledSource(SourceBase):
"""A source based on a compiled shared library
.. versionadded:: 0.13.4
Parameters
----------
library : str or None
Path to a compiled shared library
parameters : str
Parameters to be provided to the compiled shared library function
strength : float
Strength of the source
Attributes
----------
library : str or None
Path to a compiled shared library
parameters : str
Parameters to be provided to the compiled shared library function
strength : float
Strength of the source
type : str
Indicator of source type: 'compiled'
"""
def __init__(self, library: Optional[str] = None, parameters: Optional[str] = None, strength=1.0) -> None:
super().__init__(strength=strength)
self._library = None
if library is not None:
self.library = library
self._parameters = None
if parameters is not None:
self.parameters = parameters
@property
def type(self) -> str:
return "compiled"
@property
def library(self) -> str:
return self._library
@library.setter
def library(self, library_name):
cv.check_type('library', library_name, str)
self._library = library_name
@property
def parameters(self) -> str:
return self._parameters
@parameters.setter
def parameters(self, parameters_path):
cv.check_type('parameters', parameters_path, str)
self._parameters = parameters_path
def populate_xml_element(self, element):
"""Add necessary compiled source information to an XML element
Returns
-------
element : lxml.etree._Element
XML element containing source data
"""
super().populate_xml_element(element)
element.set("library", self.library)
if self.parameters is not None:
element.set("parameters", self.parameters)
@classmethod
def from_xml_element(cls, elem: ET.Element, meshes=None) -> openmc.CompiledSource:
"""Generate a compiled source from an XML element
Parameters
----------
elem : lxml.etree._Element
XML element
meshes : dict
Dictionary with mesh IDs as keys and openmc.MeshBase instances as
values
Returns
-------
openmc.CompiledSource
Source generated from XML element
"""
library = get_text(elem, 'library')
source = cls(library)
strength = get_text(elem, 'strength')
if strength is not None:
source.strength = float(strength)
parameters = get_text(elem, 'parameters')
if parameters is not None:
source.parameters = parameters
return source
class FileSource(SourceBase):
"""A source based on particles stored in a file
.. versionadded:: 0.13.4
Parameters
----------
path : str or pathlib.Path
Path to the source file from which sites should be sampled
strength : float
Strength of the source (default is 1.0)
Attributes
----------
path : Pathlike
Source file from which sites should be sampled
strength : float
Strength of the source
type : str
Indicator of source type: 'file'
"""
def __init__(self, path: Optional[PathLike] = None, strength=1.0) -> None:
super().__init__(strength=strength)
self._path = None
if path is not None:
self.path = path
@property
def type(self) -> str:
return "file"
@property
def path(self) -> PathLike:
return self._path
@path.setter
def path(self, p: PathLike):
cv.check_type('source file', p, str)
self._path = p
def populate_xml_element(self, element):
"""Add necessary file source information to an XML element
Returns
-------
element : lxml.etree._Element
XML element containing source data
"""
super().populate_xml_element(element)
if self.path is not None:
element.set("file", self.path)
@classmethod
def from_xml_element(cls, elem: ET.Element) -> openmc.FileSource:
"""Generate file source from an XML element
Parameters
----------
elem : lxml.etree._Element
XML element
meshes : dict
Dictionary with mesh IDs as keys and openmc.MeshBase instances as
values
Returns
-------
openmc.FileSource
Source generated from XML element
"""
filename = get_text(elem, 'file')
source = cls(filename)
strength = get_text(elem, 'strength')
if strength is not None:
source.strength = float(strength)
return source
class ParticleType(IntEnum):
"""
IntEnum class representing a particle type. Type

View file

@ -458,7 +458,7 @@ void read_settings_xml(pugi::xml_node root)
// Create custom source
model::external_sources.push_back(
make_unique<CustomSourceWrapper>(path, parameters));
make_unique<CompiledSourceWrapper>(path, parameters));
} else {
model::external_sources.push_back(make_unique<IndependentSource>(node));
}

View file

@ -326,10 +326,10 @@ SourceSite FileSource::sample(uint64_t* seed) const
}
//==============================================================================
// CustomSourceWrapper implementation
// CompiledSourceWrapper implementation
//==============================================================================
CustomSourceWrapper::CustomSourceWrapper(
CompiledSourceWrapper::CompiledSourceWrapper(
std::string path, std::string parameters)
{
#ifdef HAS_DYNAMIC_LINKING
@ -343,7 +343,7 @@ CustomSourceWrapper::CustomSourceWrapper(
dlerror();
// get the function to create the custom source from the library
auto create_custom_source = reinterpret_cast<create_custom_source_t*>(
auto create_compiled_source = reinterpret_cast<create_compiled_source_t*>(
dlsym(shared_library_, "openmc_create_source"));
// check for any dlsym errors
@ -356,7 +356,7 @@ CustomSourceWrapper::CustomSourceWrapper(
}
// create a pointer to an instance of the custom source
custom_source_ = create_custom_source(parameters);
compiled_source_ = create_compiled_source(parameters);
#else
fatal_error("Custom source libraries have not yet been implemented for "
@ -364,11 +364,11 @@ CustomSourceWrapper::CustomSourceWrapper(
#endif
}
CustomSourceWrapper::~CustomSourceWrapper()
CompiledSourceWrapper::~CompiledSourceWrapper()
{
// Make sure custom source is cleared before closing shared library
if (custom_source_.get())
custom_source_.reset();
if (compiled_source_.get())
compiled_source_.reset();
#ifdef HAS_DYNAMIC_LINKING
dlclose(shared_library_);

View file

@ -29,7 +29,7 @@
<particles>10000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-4.0 -4.0 -4.0 4.0 4.0 4.0</parameters>
</space>

View file

@ -40,7 +40,7 @@ def model():
model.settings.inactive = 5
model.settings.batches = 10
source_box = openmc.stats.Box((-4., -4., -4.), (4., 4., 4.))
model.settings.source = openmc.Source(space=source_box)
model.settings.source = openmc.IndependentSource(space=source_box)
return model

View file

@ -208,7 +208,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-32 -32 0 32 32 32</parameters>
</space>

View file

@ -54,7 +54,7 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness):
self._model.tallies.append(tally)
# Specify summary output and correct source sampling box
self._model.settings.source = openmc.Source(space=openmc.stats.Box(
self._model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
[-32, -32, 0], [32, 32, 32], only_fissionable = True))
def _get_results(self, hash_output=True):

View file

@ -20,7 +20,7 @@
<run_mode>fixed source</run_mode>
<particles>100</particles>
<batches>10</batches>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-1 -1 -1 1 1 1</parameters>
</space>

View file

@ -38,8 +38,8 @@ class CreateFissionNeutronsTestHarness(PyAPITestHarness):
bounds = [-1, -1, -1, 1, 1, 1]
uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:])
watt_dist = openmc.stats.Watt()
settings_file.source = openmc.source.Source(space=uniform_dist,
energy=watt_dist)
settings_file.source = openmc.IndependentSource(space=uniform_dist,
energy=watt_dist)
self._model.settings = settings_file
# Create tallies

View file

@ -20,7 +20,7 @@
<particles>100</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-4 -4 -4 4 4 4</parameters>
</space>

View file

@ -65,7 +65,7 @@ def model():
model.settings.particles = 100
source_box = openmc.stats.Box([-4, -4, -4],
[ 4, 4, 4])
source = openmc.Source(space=source_box)
source = openmc.IndependentSource(space=source_box)
model.settings.source = source
model.settings.temperature['default'] = 293

View file

@ -20,7 +20,7 @@
<particles>100</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-4 -4 -4 4 4 4</parameters>
</space>

View file

@ -22,7 +22,7 @@ def model():
source_box = openmc.stats.Box([-4, -4, -4],
[ 4, 4, 4])
source = openmc.Source(space=source_box)
source = openmc.IndependentSource(space=source_box)
model.settings.source = source

View file

@ -10,7 +10,7 @@
<particles>100</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-4 -4 -4 4 4 4</parameters>
</space>

View file

@ -18,8 +18,8 @@ class UWUWTest(PyAPITestHarness):
self._model.settings.inactive = 0
self._model.settings.particles = 100
source = openmc.Source(space=Box([-4, -4, -4],
[ 4, 4, 4]))
source = openmc.IndependentSource(space=Box([-4, -4, -4],
[ 4, 4, 4]))
self._model.settings.source = source
# geometry

View file

@ -10,7 +10,7 @@
<particles>100</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-4 -4 -4 4 4 4</parameters>
</space>

View file

@ -18,8 +18,8 @@ class UWUWTest(PyAPITestHarness):
self._model.settings.inactive = 0
self._model.settings.particles = 100
source = openmc.Source(space=Box([-4, -4, -4],
[ 4, 4, 4]))
source = openmc.IndependentSource(space=Box([-4, -4, -4],
[ 4, 4, 4]))
self._model.settings.source = source
# geometry

View file

@ -46,7 +46,7 @@ def test_full(run_in_tmpdir, problem, multiproc):
settings.batches = 10
settings.inactive = 0
space = openmc.stats.Box(lower_left, upper_right)
settings.source = openmc.Source(space=space)
settings.source = openmc.IndependentSource(space=space)
settings.seed = 1
settings.verbosity = 1

View file

@ -300,7 +300,7 @@
<particles>100</particles>
<batches>3</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-160 -160 -183 160 160 183</parameters>
</space>

View file

@ -16,7 +16,7 @@ class DiffTallyTestHarness(PyAPITestHarness):
self._model.settings.batches = 3
self._model.settings.inactive = 0
self._model.settings.particles = 100
self._model.settings.source = openmc.Source(space=openmc.stats.Box(
self._model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
[-160, -160, -183], [160, 160, 183]))
self._model.settings.temperature['multipole'] = True

View file

@ -40,7 +40,7 @@
<particles>1000</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-1 -1 -1 1 1 1</parameters>
</space>

View file

@ -65,7 +65,7 @@ class DistribmatTestHarness(PyAPITestHarness):
sets_file.batches = 5
sets_file.inactive = 0
sets_file.particles = 1000
sets_file.source = openmc.Source(space=openmc.stats.Box(
sets_file.source = openmc.IndependentSource(space=openmc.stats.Box(
[-1, -1, -1], [1, 1, 1]))
self._model.settings = sets_file

View file

@ -16,7 +16,7 @@
<batches>7</batches>
<inactive>3</inactive>
<generations_per_batch>3</generations_per_batch>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-4.0 -4.0 -4.0 4.0 4.0 4.0</parameters>
</space>

View file

@ -22,7 +22,7 @@ def model():
model.settings.batches = 7
model.settings.generations_per_batch = 3
space = openmc.stats.Box((-4.0, -4.0, -4.0), (4.0, 4.0, 4.))
model.settings.source = openmc.Source(space=space)
model.settings.source = openmc.IndependentSource(space=space)
t = openmc.Tally()
t.scores = ['flux']

View file

@ -19,7 +19,7 @@
<run_mode>fixed source</run_mode>
<particles>100</particles>
<batches>10</batches>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-1 -1 -1 1 1 1</parameters>
</space>

View file

@ -40,8 +40,8 @@ class EnergyCutoffTestHarness(PyAPITestHarness):
bounds = [-1, -1, -1, 1, 1, 1]
uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:])
watt_dist = openmc.stats.Watt()
settings_file.source = openmc.source.Source(space=uniform_dist,
energy=watt_dist)
settings_file.source = openmc.IndependentSource(space=uniform_dist,
energy=watt_dist)
self._model.settings = settings_file
# Tally flux under energy cutoff

View file

@ -46,7 +46,7 @@
<run_mode>fixed source</run_mode>
<particles>100</particles>
<batches>10</batches>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="point">
<parameters>0.0 0.0 0.0</parameters>
</space>

View file

@ -258,7 +258,7 @@ def test_external_mesh(cpp_driver):
space = openmc.stats.Point()
angle = openmc.stats.Monodirectional((-1.0, 0.0, 0.0))
energy = openmc.stats.Discrete(x=[15.e+06], p=[1.0])
source = openmc.Source(space=space, energy=energy, angle=angle)
source = openmc.IndependentSource(space=space, energy=energy, angle=angle)
settings.source = source
model = openmc.model.Model(geometry=geometry,

View file

@ -39,7 +39,7 @@
<particles>1000</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="point">
<parameters>0.0 0.0 0.0</parameters>
</space>

View file

@ -69,7 +69,7 @@ def model():
model.settings.batches = 5
model.settings.inactive = 0
model.settings.particles = 1000
model.settings.source = openmc.Source(space=openmc.stats.Point())
model.settings.source = openmc.IndependentSource(space=openmc.stats.Point())
instances = ([(c4, i) for i in range(c4.num_instances)] +
[(c2, i) for i in range(c2.num_instances)] +

View file

@ -15,7 +15,7 @@
<run_mode>fixed source</run_mode>
<particles>100</particles>
<batches>10</batches>
<source strength="10.0">
<source particle="neutron" strength="10.0" type="independent">
<space type="point">
<parameters>0.0 0.0 0.0</parameters>
</space>

View file

@ -48,8 +48,8 @@ def test_fixed_source():
model.settings.batches = 10
model.settings.particles = 100
model.settings.temperature = {'default': 294}
model.settings.source = openmc.Source(space=openmc.stats.Point(),
strength=10.0)
model.settings.source = openmc.IndependentSource(space=openmc.stats.Point(),
strength=10.0)
tally = openmc.Tally()
tally.scores = ['flux']

View file

@ -312,7 +312,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-160 -160 -183 160 160 183</parameters>
</space>

View file

@ -68,7 +68,7 @@
<particles>1000</particles>
<batches>5</batches>
<inactive>2</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-0.9899494936611666 -0.9899494936611666 0.0 0.9899494936611666 0.9899494936611666 10.0</parameters>
</space>

View file

@ -132,7 +132,7 @@ class HexLatticeCoincidentTestHarness(PyAPITestHarness):
settings = openmc.Settings()
settings.run_mode = 'eigenvalue'
source = openmc.Source()
source = openmc.IndependentSource()
corner_dist = sqrt(2) * pin_rad
ll = [-corner_dist, -corner_dist, 0.0]
ur = [corner_dist, corner_dist, 10.0]

View file

@ -113,7 +113,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-13.62546635287517 -13.62546635287517 0.0 13.62546635287517 13.62546635287517 10.0</parameters>
</space>

View file

@ -187,7 +187,7 @@ class HexLatticeOXTestHarness(PyAPITestHarness):
settings = openmc.Settings()
settings.run_mode = 'eigenvalue'
source = openmc.Source()
source = openmc.IndependentSource()
ll = [-edge_length, -edge_length, 0.0]
ur = [edge_length, edge_length, 10.0]
source.space = openmc.stats.Box(ll, ur)

View file

@ -62,7 +62,7 @@
<particles>1000</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="point">
<parameters>0.0 0.0 0.0</parameters>
</space>

View file

@ -73,7 +73,7 @@ def rotated_lattice_model():
model.settings.batches = 5
model.settings.inactive = 0
model.settings.particles = 1000
model.settings.source = openmc.Source(space=openmc.stats.Point())
model.settings.source = openmc.IndependentSource(space=openmc.stats.Point())
model.settings.export_to_xml()
return model

View file

@ -48,7 +48,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>0.0 -1000.0 -1000.0 154.90833333333333 1000.0 1000.0</parameters>
</space>

View file

@ -47,7 +47,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>0.0 -1000.0 -1000.0 154.90833333333333 1000.0 1000.0</parameters>
</space>

View file

@ -19,7 +19,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-5 -5 -5 5 5 5</parameters>
</space>

View file

@ -114,7 +114,7 @@ class MGXSTestHarness(PyAPITestHarness):
# Create an initial uniform spatial source distribution
bounds = [-5, -5, -5, 5, 5, 5]
uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:])
settings_file.source = openmc.source.Source(space=uniform_dist)
settings_file.source = openmc.IndependentSource(space=uniform_dist)
self._model.settings = settings_file

View file

@ -17,7 +17,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>0.0 -1000.0 -1000.0 929.45 1000.0 1000.0</parameters>
</space>

View file

@ -17,7 +17,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>0.0 -1000.0 -1000.0 929.45 1000.0 1000.0</parameters>
</space>

View file

@ -17,7 +17,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>0.0 -1000.0 -1000.0 929.45 1000.0 1000.0</parameters>
</space>

View file

@ -17,7 +17,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>0.0 -1000.0 -1000.0 929.45 1000.0 1000.0</parameters>
</space>

View file

@ -291,6 +291,6 @@ def build_inf_model(xsnames, xslibname, temperature, tempmethod='nearest'):
bounds = [-INF, -INF, -INF, INF, INF, INF]
uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True)
settings_file.temperature = {'method': tempmethod}
settings_file.source = openmc.Source(space=uniform_dist)
settings_file.source = openmc.IndependentSource(space=uniform_dist)
model.settings = settings_file
model.export_to_model_xml()

View file

@ -41,7 +41,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>

View file

@ -41,7 +41,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>

View file

@ -41,7 +41,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>

View file

@ -41,7 +41,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>

View file

@ -68,7 +68,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-10.71 -10.71 -1 10.71 10.71 1</parameters>
</space>

View file

@ -41,7 +41,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>

View file

@ -41,7 +41,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>

View file

@ -41,7 +41,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>

View file

@ -41,7 +41,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>

View file

@ -41,7 +41,7 @@
<particles>100</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.63 -0.63 -1 0.63 0.63 1</parameters>
</space>

View file

@ -29,7 +29,7 @@
<particles>10000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-4.0 -4.0 -4.0 4.0 4.0 4.0</parameters>
</space>

View file

@ -19,7 +19,7 @@
<run_mode>fixed source</run_mode>
<particles>10000</particles>
<batches>1</batches>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="point">
<parameters>0 0 0</parameters>
</space>

View file

@ -37,7 +37,7 @@
<particles>1000</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-1 -1 -1 1 1 1</parameters>
</space>

View file

@ -53,7 +53,7 @@ def make_model():
model.settings.batches = 5
model.settings.inactive = 0
model.settings.particles = 1000
model.settings.source = openmc.Source(space=openmc.stats.Box(
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
[-1, -1, -1], [1, 1, 1]))
model.settings.temperature = {'tolerance': 1000, 'multipole': True}

View file

@ -16,7 +16,7 @@
<run_mode>fixed source</run_mode>
<particles>100000</particles>
<batches>10</batches>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="point">
<parameters>0 0 -20</parameters>
</space>

View file

@ -33,7 +33,7 @@ def pencil_beam_model(cfg, E0, N):
# Source definition
source = openmc.Source()
source = openmc.IndependentSource()
source.space = openmc.stats.Point((0, 0, -20))
source.angle = openmc.stats.Monodirectional(reference_uvw=(0, 0, 1))
source.energy = openmc.stats.Discrete([E0], [1.0])

View file

@ -28,7 +28,7 @@
<particles>1000</particles>
<batches>4</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>0 0 0 5 5 0</parameters>
</space>

View file

@ -42,7 +42,7 @@ def box_model():
model.settings.particles = 1000
model.settings.batches = 4
model.settings.inactive = 0
model.settings.source = openmc.Source(space=openmc.stats.Box(
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
(0, 0, 0), (5, 5, 0))
)
return model

View file

@ -25,7 +25,7 @@
<particles>1000</particles>
<batches>4</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>0 0 0 5 5 0</parameters>
</space>

View file

@ -46,7 +46,7 @@ def model():
model.settings.particles = 1000
model.settings.batches = 4
model.settings.inactive = 0
model.settings.source = openmc.Source(space=openmc.stats.Box(
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
(0, 0, 0), (5, 5, 0))
)
return model

View file

@ -19,7 +19,7 @@
<run_mode>fixed source</run_mode>
<particles>10000</particles>
<batches>1</batches>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="point">
<parameters>0 0 0</parameters>
</space>

View file

@ -27,7 +27,7 @@ def model():
inner_cyl_right.fill = mat
model.geometry = openmc.Geometry([inner_cyl_left, inner_cyl_right, outer_cyl])
source = openmc.Source()
source = openmc.IndependentSource()
source.space = openmc.stats.Point((0, 0, 0))
source.angle = openmc.stats.Monodirectional()
source.energy = openmc.stats.Discrete([14.0e6], [1.0])

View file

@ -15,7 +15,7 @@
<particles>1000</particles>
<batches>5</batches>
<inactive>2</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="point">
<parameters>0 0 0</parameters>
</space>

View file

@ -20,7 +20,7 @@ def model():
model.settings.batches = 5
model.settings.inactive = 2
model.settings.photon_transport = True
model.settings.source = openmc.Source(space=openmc.stats.Point((0, 0, 0)))
model.settings.source = openmc.IndependentSource(space=openmc.stats.Point((0, 0, 0)))
particle_filter = openmc.ParticleFilter(['neutron', 'photon'])
tally_tracklength = openmc.Tally()

View file

@ -17,7 +17,7 @@
<run_mode>fixed source</run_mode>
<particles>10000</particles>
<batches>1</batches>
<source particle="photon" strength="1.0">
<source particle="photon" strength="1.0" type="independent">
<space type="point">
<parameters>0 0 0</parameters>
</space>

View file

@ -21,7 +21,7 @@ class SourceTestHarness(PyAPITestHarness):
inside_sphere.fill = mat
self._model.geometry = openmc.Geometry([inside_sphere])
source = openmc.Source()
source = openmc.IndependentSource()
source.space = openmc.stats.Point((0, 0, 0))
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([10.0e6], [1.0])

View file

@ -18,7 +18,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-4 -4 -4 4 4 4</parameters>
</space>

View file

@ -35,7 +35,7 @@ class ResonanceScatteringTestHarness(PyAPITestHarness):
settings.batches = 10
settings.inactive = 5
settings.particles = 1000
settings.source = openmc.source.Source(
settings.source = openmc.IndependentSource(
space=openmc.stats.Box([-4, -4, -4], [4, 4, 4]))
settings.resonance_scattering = res_scat_settings
self._model.settings = settings

View file

@ -51,7 +51,7 @@
<particles>400</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-4 -4 -4 4 4 4</parameters>
</space>

View file

@ -67,7 +67,7 @@ def make_model():
model.settings.batches = 5
model.settings.inactive = 0
model.settings.particles = 400
model.settings.source = openmc.Source(space=openmc.stats.Box(
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
[-4, -4, -4], [4, 4, 4]))
return model

View file

@ -15,7 +15,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>5</inactive>
<source strength="0.3">
<source particle="neutron" strength="0.3" type="independent">
<space type="cartesian">
<x parameters="-3.0 3.0" type="uniform"/>
<y type="discrete">
@ -33,14 +33,14 @@
</angle>
<energy parameters="1289500.0" type="maxwell"/>
</source>
<source strength="0.1">
<source particle="neutron" strength="0.1" type="independent">
<space type="box">
<parameters>-4.0 -4.0 -4.0 4.0 4.0 4.0</parameters>
</space>
<angle reference_uvw="0.0 1.0 0.0" type="monodirectional"/>
<energy parameters="988000.0 2.249e-06" type="watt"/>
</source>
<source strength="0.1">
<source particle="neutron" strength="0.1" type="independent">
<space type="point">
<parameters>1.2 -2.3 0.781</parameters>
</space>
@ -49,7 +49,7 @@
<parameters>1.0 1.3894954943731377 1.93069772888325 2.6826957952797255 3.72759372031494 5.17947467923121 7.196856730011519 10.0 13.894954943731374 19.306977288832496 26.826957952797247 37.2759372031494 51.7947467923121 71.96856730011518 100.0 138.94954943731375 193.06977288832496 268.26957952797244 372.7593720314938 517.9474679231207 719.6856730011514 1000.0 1389.4954943731375 1930.6977288832495 2682.6957952797247 3727.593720314938 5179.474679231207 7196.856730011514 10000.0 13894.95494373136 19306.977288832495 26826.95795279722 37275.93720314938 51794.74679231213 71968.56730011514 100000.0 138949.5494373136 193069.77288832495 268269.5795279722 372759.3720314938 517947.4679231202 719685.6730011514 1000000.0 1389495.494373136 1930697.7288832497 2682695.7952797217 3727593.720314938 5179474.679231202 7196856.730011513 10000000.0 0.0 2.9086439299358713e-08 5.80533561806147e-08 8.67817193689187e-08 1.1515347785771536e-07 1.4305204600565115e-07 1.7036278261198208e-07 1.9697346200185813e-07 2.227747351856934e-07 2.4766057919761985e-07 2.715287327665956e-07 2.9428111652990295e-07 3.1582423606228735e-07 3.360695660646056e-07 3.549339141332686e-07 3.723397626156721e-07 3.882155871468592e-07 4.024961505584776e-07 4.151227709522976e-07 4.260435628367196e-07 4.3521365033538783e-07 4.4259535159179273e-07 4.4815833361210174e-07 4.5187973690993757e-07 4.5374426944091084e-07 4.5374426944091084e-07 4.5187973690993757e-07 4.4815833361210174e-07 4.4259535159179273e-07 4.352136503353879e-07 4.2604356283671966e-07 4.1512277095229767e-07 4.0249615055847764e-07 3.8821558714685926e-07 3.723397626156722e-07 3.5493391413326864e-07 3.360695660646057e-07 3.158242360622874e-07 2.942811165299031e-07 2.715287327665957e-07 2.4766057919762e-07 2.2277473518569352e-07 1.9697346200185819e-07 1.7036278261198226e-07 1.4305204600565126e-07 1.1515347785771556e-07 8.678171936891881e-08 5.805335618061493e-08 2.9086439299358858e-08 5.559621115282002e-23</parameters>
</energy>
</source>
<source strength="0.1">
<source particle="neutron" strength="0.1" type="independent">
<space origin="1.0 1.0 0.0" type="spherical">
<r parameters="2.0 3.0" type="uniform"/>
<cos_theta type="discrete">
@ -62,7 +62,7 @@
<parameters>1.0 1.3894954943731377 1.93069772888325 2.6826957952797255 3.72759372031494 5.17947467923121 7.196856730011519 10.0 13.894954943731374 19.306977288832496 26.826957952797247 37.2759372031494 51.7947467923121 71.96856730011518 100.0 138.94954943731375 193.06977288832496 268.26957952797244 372.7593720314938 517.9474679231207 719.6856730011514 1000.0 1389.4954943731375 1930.6977288832495 2682.6957952797247 3727.593720314938 5179.474679231207 7196.856730011514 10000.0 13894.95494373136 19306.977288832495 26826.95795279722 37275.93720314938 51794.74679231213 71968.56730011514 100000.0 138949.5494373136 193069.77288832495 268269.5795279722 372759.3720314938 517947.4679231202 719685.6730011514 1000000.0 1389495.494373136 1930697.7288832497 2682695.7952797217 3727593.720314938 5179474.679231202 7196856.730011513 10000000.0 0.0 2.9086439299358713e-08 5.80533561806147e-08 8.67817193689187e-08 1.1515347785771536e-07 1.4305204600565115e-07 1.7036278261198208e-07 1.9697346200185813e-07 2.227747351856934e-07 2.4766057919761985e-07 2.715287327665956e-07 2.9428111652990295e-07 3.1582423606228735e-07 3.360695660646056e-07 3.549339141332686e-07 3.723397626156721e-07 3.882155871468592e-07 4.024961505584776e-07 4.151227709522976e-07 4.260435628367196e-07 4.3521365033538783e-07 4.4259535159179273e-07 4.4815833361210174e-07 4.5187973690993757e-07 4.5374426944091084e-07 4.5374426944091084e-07 4.5187973690993757e-07 4.4815833361210174e-07 4.4259535159179273e-07 4.352136503353879e-07 4.2604356283671966e-07 4.1512277095229767e-07 4.0249615055847764e-07 3.8821558714685926e-07 3.723397626156722e-07 3.5493391413326864e-07 3.360695660646057e-07 3.158242360622874e-07 2.942811165299031e-07 2.715287327665957e-07 2.4766057919762e-07 2.2277473518569352e-07 1.9697346200185819e-07 1.7036278261198226e-07 1.4305204600565126e-07 1.1515347785771556e-07 8.678171936891881e-08 5.805335618061493e-08 2.9086439299358858e-08 5.559621115282002e-23</parameters>
</energy>
</source>
<source strength="0.1">
<source particle="neutron" strength="0.1" type="independent">
<space origin="1.0 1.0 0.0" type="cylindrical">
<r parameters="2.0 3.0" type="uniform"/>
<phi parameters="0.0 6.283185307179586" type="uniform"/>
@ -75,7 +75,7 @@
<parameters>1.0 1.3894954943731377 1.93069772888325 2.6826957952797255 3.72759372031494 5.17947467923121 7.196856730011519 10.0 13.894954943731374 19.306977288832496 26.826957952797247 37.2759372031494 51.7947467923121 71.96856730011518 100.0 138.94954943731375 193.06977288832496 268.26957952797244 372.7593720314938 517.9474679231207 719.6856730011514 1000.0 1389.4954943731375 1930.6977288832495 2682.6957952797247 3727.593720314938 5179.474679231207 7196.856730011514 10000.0 13894.95494373136 19306.977288832495 26826.95795279722 37275.93720314938 51794.74679231213 71968.56730011514 100000.0 138949.5494373136 193069.77288832495 268269.5795279722 372759.3720314938 517947.4679231202 719685.6730011514 1000000.0 1389495.494373136 1930697.7288832497 2682695.7952797217 3727593.720314938 5179474.679231202 7196856.730011513 10000000.0 0.0 2.9086439299358713e-08 5.80533561806147e-08 8.67817193689187e-08 1.1515347785771536e-07 1.4305204600565115e-07 1.7036278261198208e-07 1.9697346200185813e-07 2.227747351856934e-07 2.4766057919761985e-07 2.715287327665956e-07 2.9428111652990295e-07 3.1582423606228735e-07 3.360695660646056e-07 3.549339141332686e-07 3.723397626156721e-07 3.882155871468592e-07 4.024961505584776e-07 4.151227709522976e-07 4.260435628367196e-07 4.3521365033538783e-07 4.4259535159179273e-07 4.4815833361210174e-07 4.5187973690993757e-07 4.5374426944091084e-07 4.5374426944091084e-07 4.5187973690993757e-07 4.4815833361210174e-07 4.4259535159179273e-07 4.352136503353879e-07 4.2604356283671966e-07 4.1512277095229767e-07 4.0249615055847764e-07 3.8821558714685926e-07 3.723397626156722e-07 3.5493391413326864e-07 3.360695660646057e-07 3.158242360622874e-07 2.942811165299031e-07 2.715287327665957e-07 2.4766057919762e-07 2.2277473518569352e-07 1.9697346200185819e-07 1.7036278261198226e-07 1.4305204600565126e-07 1.1515347785771556e-07 8.678171936891881e-08 5.805335618061493e-08 2.9086439299358858e-08 5.559621115282002e-23</parameters>
</energy>
</source>
<source strength="0.1">
<source particle="neutron" strength="0.1" type="independent">
<space origin="1.0 1.0 0.0" type="cylindrical">
<r parameters="2.0 3.0" type="uniform"/>
<phi parameters="0.0 6.283185307179586" type="uniform"/>
@ -98,7 +98,7 @@
</pair>
</energy>
</source>
<source strength="0.1">
<source particle="neutron" strength="0.1" type="independent">
<space origin="1.0 1.0 0.0" type="spherical">
<r parameters="2.0 3.0 2.0" type="powerlaw"/>
<cos_theta type="discrete">
@ -122,7 +122,7 @@
</energy>
<time parameters="2 5" type="uniform"/>
</source>
<source strength="0.1">
<source particle="neutron" strength="0.1" type="independent">
<space origin="1.0 1.0 0.0" type="cylindrical">
<r parameters="2.0 3.0 1.0" type="powerlaw"/>
<phi parameters="0.0 6.283185307179586" type="uniform"/>

View file

@ -68,14 +68,14 @@ class SourceTestHarness(PyAPITestHarness):
time1 = openmc.stats.Uniform(2, 5)
source1 = openmc.Source(spatial1, angle1, energy1, strength=0.3)
source2 = openmc.Source(spatial2, angle2, energy2, strength=0.1)
source3 = openmc.Source(spatial3, angle3, energy3, strength=0.1)
source4 = openmc.Source(spatial4, angle3, energy3, strength=0.1)
source5 = openmc.Source(spatial5, angle3, energy3, strength=0.1)
source6 = openmc.Source(spatial5, angle3, energy4, strength=0.1)
source7 = openmc.Source(spatial6, angle3, energy4, time1, strength=0.1)
source8 = openmc.Source(spatial7, angle3, energy4, time1, strength=0.1)
source1 = openmc.IndependentSource(spatial1, angle1, energy1, strength=0.3)
source2 = openmc.IndependentSource(spatial2, angle2, energy2, strength=0.1)
source3 = openmc.IndependentSource(spatial3, angle3, energy3, strength=0.1)
source4 = openmc.IndependentSource(spatial4, angle3, energy3, strength=0.1)
source5 = openmc.IndependentSource(spatial5, angle3, energy3, strength=0.1)
source6 = openmc.IndependentSource(spatial5, angle3, energy4, strength=0.1)
source7 = openmc.IndependentSource(spatial6, angle3, energy4, time1, strength=0.1)
source8 = openmc.IndependentSource(spatial7, angle3, energy4, time1, strength=0.1)
settings = openmc.Settings()
settings.batches = 10

View file

@ -18,6 +18,18 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>0</inactive>
<source library="build/libsource.so" strength="1.0"/>
<source library="build/libsource.so" strength="1.0" type="compiled"/>
</settings>
</model>
<tallies>
<filter id="1" type="material">
<bins>1</bins>
</filter>
<filter id="2" type="energy">
<bins>0.0 2000.0 1000000.0</bins>
</filter>
<tally id="1">
<filters>1 2</filters>
<scores>flux</scores>
</tally>
</tallies>
</model>

View file

@ -0,0 +1,5 @@
tally 1:
1.445856E+04
2.090732E+07
0.000000E+00
0.000000E+00

View file

@ -5,8 +5,7 @@
#include "openmc/random_lcg.h"
#include "openmc/source.h"
class CustomSource : public openmc::Source
{
class CustomSource : public openmc::Source {
openmc::SourceSite sample(uint64_t* seed) const
{
openmc::SourceSite particle;
@ -20,16 +19,17 @@ class CustomSource : public openmc::Source
particle.r.z = 0.;
// angle
particle.u = {1.0, 0.0, 0.0};
particle.E = 14.08e6;
particle.E = 1.00e3;
particle.delayed_group = 0;
return particle;
}
};
// A function to create a unique pointer to an instance of this class when generated
// via a plugin call using dlopen/dlsym.
// You must have external C linkage here otherwise dlopen will not find the file
extern "C" std::unique_ptr<CustomSource> openmc_create_source(std::string parameters)
// A function to create a unique pointer to an instance of this class when
// generated via a plugin call using dlopen/dlsym. You must have external C
// linkage here otherwise dlopen will not find the file
extern "C" std::unique_ptr<CustomSource> openmc_create_source(
std::string parameters)
{
return std::make_unique<CustomSource>();
}

View file

@ -61,8 +61,18 @@ def model():
model.settings.particles = 1000
model.settings.run_mode = 'fixed source'
tally = openmc.Tally()
mat_filter = openmc.MaterialFilter([natural_lead])
# energy filter with two bins 0 eV - 1 keV and 1 keV - 1 MeV the second bin
# of the energy filter (last two entries in the tally results) should be
# zero
energy_filter = openmc.EnergyFilter([0.0, 2e3, 1e6])
tally.filters = [mat_filter, energy_filter]
tally.scores = ['flux']
model.tallies = openmc.Tallies([tally])
# custom source from shared library
source = openmc.Source()
source = openmc.CompiledSource()
source.library = 'build/libsource.so'
model.settings.source = source

View file

@ -18,6 +18,18 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>0</inactive>
<source library="build/libsource.so" parameters="1e3" strength="1.0"/>
<source library="build/libsource.so" parameters="1e3" strength="1.0" type="compiled"/>
</settings>
</model>
<tallies>
<filter id="1" type="material">
<bins>1</bins>
</filter>
<filter id="2" type="energy">
<bins>0.0 2000.0 1000000.0</bins>
</filter>
<tally id="1">
<filters>1 2</filters>
<scores>flux</scores>
</tally>
</tallies>
</model>

View file

@ -0,0 +1,5 @@
tally 1:
1.445856E+04
2.090732E+07
0.000000E+00
0.000000E+00

View file

@ -61,8 +61,17 @@ def model():
model.settings.particles = 1000
model.settings.run_mode = 'fixed source'
tally = openmc.Tally()
mat_filter = openmc.MaterialFilter([natural_lead])
# energy filter with two bins 0 eV - 1 keV and 1 keV - 1 MeV
# the second bin shouldn't have any results
energy_filter = openmc.EnergyFilter([0.0, 2e3, 1e6])
tally.filters = [mat_filter, energy_filter]
tally.scores = ['flux']
model.tallies = openmc.Tallies([tally])
# custom source from shared library
source = openmc.Source()
source = openmc.CompiledSource()
source.library = 'build/libsource.so'
source.parameters = '1e3'
model.settings.source = source

View file

@ -16,7 +16,7 @@
<run_mode>fixed source</run_mode>
<particles>1000</particles>
<batches>10</batches>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="point">
<parameters>0 0 0</parameters>
</space>

View file

@ -44,7 +44,7 @@ def model(request):
if surf_source_op == 'write':
point = openmc.stats.Point((0, 0, 0))
pt_src = openmc.Source(space=point)
pt_src = openmc.IndependentSource(space=point)
openmc_model.settings.source = pt_src
openmc_model.settings.surf_source_write = {'surface_ids': [1],

View file

@ -29,7 +29,7 @@
<particles>1000</particles>
<batches>10</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="fission">
<parameters>-0.62992 -0.62992 -1 0.62992 0.62992 1</parameters>
</space>

View file

@ -74,7 +74,7 @@ class SurfaceTallyTestHarness(PyAPITestHarness):
bounds = [-0.62992, -0.62992, -1, 0.62992, 0.62992, 1]
uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:],\
only_fissionable=True)
settings_file.source = openmc.source.Source(space=uniform_dist)
settings_file.source = openmc.IndependentSource(space=uniform_dist)
self._model.settings = settings_file
# Tallies file

View file

@ -300,7 +300,7 @@
<particles>400</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<source particle="neutron" strength="1.0" type="independent">
<space type="box">
<parameters>-160 -160 -183 160 160 183</parameters>
</space>

View file

@ -13,7 +13,7 @@ def test_tallies():
model.settings.batches = 5
model.settings.inactive = 0
model.settings.particles = 400
model.settings.source = openmc.Source(space=openmc.stats.Box(
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
[-160, -160, -183], [160, 160, 183]))
azimuthal_bins = (-3.14159, -1.8850, -0.6283, 0.6283, 1.8850, 3.14159)

Some files were not shown because too many files have changed in this diff Show more