Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python source class refactor #2524

Merged
merged 42 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8615975
Refactor of Python source classes and rename one class. Test outputs …
pshriwise May 13, 2023
393fa1b
Updating track output results
pshriwise May 13, 2023
22a9727
Updating ncrystal inputs
pshriwise May 13, 2023
7d7942b
Renaming SourceBase --> Source and Source --> IndependentSource
pshriwise May 14, 2023
f6a5626
Adding tests for deprecated parameters.
pshriwise May 15, 2023
60ef091
Removing MeshSource class and other small updates.
pshriwise May 15, 2023
1fcf9d9
Fixing indentation from name Source --> IndependentSource name change
pshriwise May 15, 2023
fc18fbf
updating source type
pshriwise May 15, 2023
6e2a1d9
Update type value to 'independent' for IndependentSource class
pshriwise May 16, 2023
460a412
Correcting class type in dlopen tests and adding a tally so the expec…
pshriwise May 16, 2023
5f5c8e8
Updating error type for file, library, parameter attributes and ensur…
pshriwise May 16, 2023
5fecafa
Resetting test binaries
pshriwise May 16, 2023
4ff3c1b
Updating libmesh regression test inputs
pshriwise May 16, 2023
1b7d68d
Filling out docstrings
pshriwise May 17, 2023
d207cdf
Updating the IO spec
pshriwise May 17, 2023
70ee07f
Correcting docs for IndependentSourse type attr value.
pshriwise May 18, 2023
e363c73
fix typo
pshriwise May 19, 2023
0e46280
Apply suggestions from @paulromano
pshriwise Jun 9, 2023
c11abe1
Renaming Source to SourceBase
pshriwise Jun 9, 2023
3027d8b
Make populate_xml_element an abstractmethod. Add ValueError for inval…
pshriwise Jun 9, 2023
979e803
Alternative method for protecting misuse of IndependentSource. Always…
pshriwise Jun 9, 2023
56dbe88
Removing old setters. Passing parameters
pshriwise Jun 9, 2023
2516bec
Adding deprecated Source class for bkw compatibility.
pshriwise Jun 9, 2023
798f351
Apply suggestions from @paulromano
pshriwise Jun 12, 2023
265b34d
Updating source energy and test results
pshriwise Jun 12, 2023
e40da02
Correcting default getattr behavior and adding a test check
pshriwise Jun 12, 2023
2b2e576
Removing additional IndependentSource parameter. Updating tests to re…
pshriwise Jun 12, 2023
9d2ba25
Updating regression tests expected inputs for explicit particle type …
pshriwise Jun 12, 2023
7b30736
Updating unstructured mesh test inputs
pshriwise Jun 12, 2023
b290125
Merge remote-tracking branch 'upstream/develop' into src-refactor
pshriwise Jun 12, 2023
0734546
Updating ncrystal test inputs
pshriwise Jun 12, 2023
fa01b54
CI trigger
pshriwise Jun 16, 2023
c1d4e91
Formatting dlopen source test code
pshriwise Jun 16, 2023
f09505e
Merge remote-tracking branch 'upstream/develop' into src-refactor
pshriwise Jun 20, 2023
19fd7a7
Putting setters back in their places
pshriwise Jun 20, 2023
67d9f0d
Reordering source properties and removing duplicates
pshriwise Jun 20, 2023
1f50bbf
FileSource.file to FileSource.path
pshriwise Jun 20, 2023
9e24f7a
Apply suggestion from @paulromano
pshriwise Jun 20, 2023
8648f3c
Updating docstring and some more tests.
pshriwise Jun 20, 2023
f5ebea2
Changing test attribute back
pshriwise Jun 20, 2023
a2e09c6
Apply suggestions from @paulromano
pshriwise Jun 20, 2023
fe23e7a
Removing duplicate code block and moving setters
pshriwise Jun 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions docs/source/io_formats/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -449,24 +449,29 @@ attributes/sub-elements:

*Default*: 1.0

:type:
Indicator of source type. One of ``independent_source``, ``file``, or ``compiled``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files below only have type='independent' - either this documentation or those files should change...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other classes use the unique component of the class name as their type, so we should do the same here. Updating that docstring now.


: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. Note, the number of source sites needs
to be the same as the number of particles simulated in a fission source
generation.
pshriwise marked this conversation as resolved.
Show resolved Hide resolved

*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 tha tparticles are instantiated from an externally
pshriwise marked this conversation as resolved.
Show resolved Hide resolved
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()``;
Expand All @@ -476,14 +481,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
Expand Down
2 changes: 1 addition & 1 deletion examples/assembly/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_source/build_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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()
Expand Down
2 changes: 1 addition & 1 deletion examples/parameterized_custom_source/build_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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
Expand Down
14 changes: 7 additions & 7 deletions include/openmc/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,26 @@ class FileSource : public Source {
//! 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
Expand Down
8 changes: 4 additions & 4 deletions openmc/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}

Expand Down
6 changes: 3 additions & 3 deletions openmc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import openmc.checkvalue as cv
from openmc.stats.multivariate import MeshSpatial

from . import RegularMesh, Source, VolumeCalculation, WeightWindows
from . import RegularMesh, Source, IndependentSource, VolumeCalculation, WeightWindows
from ._xml import clean_indentation, get_text, reorder_attributes
from openmc.checkvalue import PathLike
from .mesh import _read_meshes
Expand Down Expand Up @@ -149,7 +149,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.IndependentSource
Distribution of source sites in space, angle, and energy
sourcepoint : dict
Options for writing source points. Acceptable keys are:
Expand Down Expand Up @@ -992,7 +992,7 @@ def _create_max_order_subelement(self, root):
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())
Expand Down
Loading