mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
added padding arg to bounding_region (#2701)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
fd9172927c
commit
eb3eec8e71
3 changed files with 60 additions and 8 deletions
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import annotations
|
||||
from typing import Iterable
|
||||
|
||||
import numpy as np
|
||||
|
|
@ -87,3 +88,30 @@ class BoundingBox(tuple):
|
|||
@property
|
||||
def width(self):
|
||||
return self.upper_right - self.lower_left
|
||||
|
||||
def extend(self, padding_distance: float) -> BoundingBox:
|
||||
"""Returns an extended bounding box
|
||||
|
||||
Parameters
|
||||
----------
|
||||
padding_distance : float
|
||||
The distance to enlarge the bounding box by
|
||||
|
||||
Returns
|
||||
-------
|
||||
An enlarged bounding box
|
||||
|
||||
"""
|
||||
return BoundingBox(np.array(
|
||||
[
|
||||
self[0][0] - padding_distance,
|
||||
self[0][1] - padding_distance,
|
||||
self[0][2] - padding_distance
|
||||
]
|
||||
), np.array(
|
||||
[
|
||||
self[1][0] + padding_distance,
|
||||
self[1][1] + padding_distance,
|
||||
self[1][2] + padding_distance
|
||||
]
|
||||
))
|
||||
|
|
|
|||
|
|
@ -837,7 +837,7 @@ class DAGMCUniverse(UniverseBase):
|
|||
coords = dagmc_file['tstt']['nodes']['coordinates'][()]
|
||||
lower_left_corner = coords.min(axis=0)
|
||||
upper_right_corner = coords.max(axis=0)
|
||||
return (lower_left_corner, upper_right_corner)
|
||||
return openmc.BoundingBox(lower_left_corner, upper_right_corner)
|
||||
|
||||
@property
|
||||
def filename(self):
|
||||
|
|
@ -950,7 +950,13 @@ class DAGMCUniverse(UniverseBase):
|
|||
dagmc_element.set('filename', str(self.filename))
|
||||
xml_element.append(dagmc_element)
|
||||
|
||||
def bounding_region(self, bounded_type='box', boundary_type='vacuum', starting_id=10000):
|
||||
def bounding_region(
|
||||
self,
|
||||
bounded_type: str = 'box',
|
||||
boundary_type: str = 'vacuum',
|
||||
starting_id: int = 10000,
|
||||
padding_distance: float = 0.
|
||||
):
|
||||
"""Creates a either a spherical or box shaped bounding region around
|
||||
the DAGMC geometry.
|
||||
|
||||
|
|
@ -970,6 +976,10 @@ class DAGMCUniverse(UniverseBase):
|
|||
Starting ID of the surface(s) used in the region. For bounded_type
|
||||
'box', the next 5 IDs will also be used. Defaults to 10000 to reduce
|
||||
the chance of an overlap of surface IDs with the DAGMC geometry.
|
||||
padding_distance : float
|
||||
Distance between the bounding region surfaces and the minimal
|
||||
bounding box. Allows for the region to be larger than the DAGMC
|
||||
geometry.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -983,16 +993,15 @@ class DAGMCUniverse(UniverseBase):
|
|||
check_type('bounded type', bounded_type, str)
|
||||
check_value('bounded type', bounded_type, ('box', 'sphere'))
|
||||
|
||||
bbox = self.bounding_box
|
||||
bbox = self.bounding_box.extend(padding_distance)
|
||||
|
||||
if bounded_type == 'sphere':
|
||||
bbox_center = (bbox[0] + bbox[1])/2
|
||||
radius = np.linalg.norm(np.asarray(bbox))
|
||||
radius = np.linalg.norm(bbox.upper_right - bbox.center)
|
||||
bounding_surface = openmc.Sphere(
|
||||
surface_id=starting_id,
|
||||
x0=bbox_center[0],
|
||||
y0=bbox_center[1],
|
||||
z0=bbox_center[2],
|
||||
x0=bbox.center[0],
|
||||
y0=bbox.center[1],
|
||||
z0=bbox.center[2],
|
||||
boundary_type=boundary_type,
|
||||
r=radius,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,23 +23,38 @@ def test_bounding_region(request):
|
|||
assert isinstance(region, openmc.Region)
|
||||
assert len(region) == 6
|
||||
assert region[0].surface.type == "x-plane"
|
||||
assert region[0].surface.x0 == -25.
|
||||
assert region[1].surface.type == "x-plane"
|
||||
assert region[1].surface.x0 == 25.
|
||||
assert region[2].surface.type == "y-plane"
|
||||
assert region[2].surface.y0 == -25.
|
||||
assert region[3].surface.type == "y-plane"
|
||||
assert region[3].surface.y0 == 25.
|
||||
assert region[4].surface.type == "z-plane"
|
||||
assert region[4].surface.z0 == -25.
|
||||
assert region[5].surface.type == "z-plane"
|
||||
assert region[5].surface.z0 == 25.
|
||||
assert region[0].surface.boundary_type == "vacuum"
|
||||
assert region[1].surface.boundary_type == "vacuum"
|
||||
assert region[2].surface.boundary_type == "vacuum"
|
||||
assert region[3].surface.boundary_type == "vacuum"
|
||||
assert region[4].surface.boundary_type == "vacuum"
|
||||
assert region[5].surface.boundary_type == "vacuum"
|
||||
region = u.bounding_region(padding_distance=5)
|
||||
assert region[0].surface.x0 == -30.
|
||||
assert region[1].surface.x0 == 30.
|
||||
assert region[2].surface.y0 == -30.
|
||||
assert region[3].surface.y0 == 30.
|
||||
assert region[4].surface.z0 == -30.
|
||||
assert region[5].surface.z0 == 30.
|
||||
|
||||
region = u.bounding_region(bounded_type="sphere", boundary_type="reflective")
|
||||
assert isinstance(region, openmc.Region)
|
||||
assert isinstance(region, openmc.Halfspace)
|
||||
assert region.surface.type == "sphere"
|
||||
assert region.surface.boundary_type == "reflective"
|
||||
larger_region = u.bounding_region(bounded_type="sphere", padding_distance=10)
|
||||
assert larger_region.surface.r > region.surface.r
|
||||
|
||||
|
||||
def test_bounded_universe(request):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue