From bcea290e55fdb4075f93fe4844eab4c5d53d2154 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Mon, 8 Apr 2024 14:02:15 +0100 Subject: [PATCH 1/3] added seed --- src/openmc_plasma_source/tokamak_source.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/openmc_plasma_source/tokamak_source.py b/src/openmc_plasma_source/tokamak_source.py index a594e95..9eca470 100644 --- a/src/openmc_plasma_source/tokamak_source.py +++ b/src/openmc_plasma_source/tokamak_source.py @@ -44,8 +44,10 @@ class TokamakSource: (cm) angles (iterable of floats): the start and stop angles of the ring in radians - sample_size (int, optional): number of neutron sources. Defaults - to 1000. + sample_size int: number of neutron sources. Defaults to 1000. + sample_seed int: the seed passed to numpy.random when sampling source + location. Numpy recommend a large int value. Defaults to + 122807528840384100672342137672332424406 """ def __init__( @@ -68,6 +70,7 @@ def __init__( shafranov_factor: float, angles: Tuple[float, float] = (0, 2 * np.pi), sample_size: int = 1000, + sample_seed: int = 1, ) -> None: # Assign attributes self.major_radius = major_radius @@ -88,6 +91,7 @@ def __init__( self.shafranov_factor = shafranov_factor self.angles = angles self.sample_size = sample_size + self.sample_seed = sample_seed # Perform sanity checks for inputs not caught by properties if self.minor_radius >= self.major_radius: @@ -341,8 +345,9 @@ def sample_sources(self): (neutron source density) and .RZ (coordinates) """ # create a sample of (a, alpha) coordinates - a = np.random.random(self.sample_size) * self.minor_radius - alpha = np.random.random(self.sample_size) * 2 * np.pi + rng = np.random.default_rng(self.sample_seed) + a = rng.random(self.sample_size) * self.minor_radius + alpha = rng.random(self.sample_size) * 2 * np.pi # compute densities, temperatures, neutron source densities and # convert coordinates From a18afe0e081728807c60b7641888685eeee8b53f Mon Sep 17 00:00:00 2001 From: shimwell Date: Mon, 8 Apr 2024 13:02:39 +0000 Subject: [PATCH 2/3] [skip ci] Apply formatting changes --- src/openmc_plasma_source/tokamak_source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openmc_plasma_source/tokamak_source.py b/src/openmc_plasma_source/tokamak_source.py index 9eca470..09c526c 100644 --- a/src/openmc_plasma_source/tokamak_source.py +++ b/src/openmc_plasma_source/tokamak_source.py @@ -345,7 +345,7 @@ def sample_sources(self): (neutron source density) and .RZ (coordinates) """ # create a sample of (a, alpha) coordinates - rng = np.random.default_rng(self.sample_seed) + rng = np.random.default_rng(self.sample_seed) a = rng.random(self.sample_size) * self.minor_radius alpha = rng.random(self.sample_size) * 2 * np.pi From c5494446ef712ec700e12c63e239338493d33922 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Mon, 8 Apr 2024 14:05:32 +0100 Subject: [PATCH 3/3] changed default seed value --- src/openmc_plasma_source/tokamak_source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openmc_plasma_source/tokamak_source.py b/src/openmc_plasma_source/tokamak_source.py index 09c526c..904d5c0 100644 --- a/src/openmc_plasma_source/tokamak_source.py +++ b/src/openmc_plasma_source/tokamak_source.py @@ -70,7 +70,7 @@ def __init__( shafranov_factor: float, angles: Tuple[float, float] = (0, 2 * np.pi), sample_size: int = 1000, - sample_seed: int = 1, + sample_seed: int = 122807528840384100672342137672332424406, ) -> None: # Assign attributes self.major_radius = major_radius