mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 13:15:39 -04:00
Merge branch 'develop' into new-scatt-mat
This commit is contained in:
commit
98e0c362b3
16 changed files with 931 additions and 1221 deletions
|
|
@ -25,7 +25,7 @@ except ImportError:
|
|||
|
||||
|
||||
MOCK_MODULES = ['numpy', 'numpy.polynomial', 'numpy.polynomial.polynomial',
|
||||
'h5py', 'pandas', 'uncertainties', 'opencg']
|
||||
'h5py', 'pandas', 'uncertainties', 'openmoc']
|
||||
sys.modules.update((mod_name, MagicMock()) for mod_name in MOCK_MODULES)
|
||||
|
||||
import numpy as np
|
||||
|
|
|
|||
|
|
@ -49,10 +49,6 @@
|
|||
"\n",
|
||||
"import openmc\n",
|
||||
"import openmc.mgxs\n",
|
||||
"import openmoc\n",
|
||||
"import openmoc.process\n",
|
||||
"from openmoc.opencg_compatible import get_openmoc_geometry\n",
|
||||
"from openmoc.materialize import load_openmc_mgxs_lib\n",
|
||||
"\n",
|
||||
"%matplotlib inline"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -524,9 +524,9 @@
|
|||
" Copyright | 2011-2017 Massachusetts Institute of Technology\n",
|
||||
" License | http://openmc.readthedocs.io/en/latest/license.html\n",
|
||||
" Version | 0.8.0\n",
|
||||
" Git SHA1 | 60a1f157dae88b62e1865a5fe3efd7ef0773a068\n",
|
||||
" Date/Time | 2017-02-25 14:26:54\n",
|
||||
" OpenMP Threads | 8\n",
|
||||
" Git SHA1 | 43b141e9ba542da8b28c078cf2df8a6777cfb2ad\n",
|
||||
" Date/Time | 2017-02-28 11:52:00\n",
|
||||
" OpenMP Threads | 4\n",
|
||||
"\n",
|
||||
" ===========================================================================\n",
|
||||
" ========================> INITIALIZATION <=========================\n",
|
||||
|
|
@ -536,11 +536,16 @@
|
|||
" Reading geometry XML file...\n",
|
||||
" Reading materials XML file...\n",
|
||||
" Reading cross sections XML file...\n",
|
||||
" Reading H1 from /opt/xsdata/nndc/H1.h5\n",
|
||||
" Reading O16 from /opt/xsdata/nndc/O16.h5\n",
|
||||
" Reading U235 from /opt/xsdata/nndc/U235.h5\n",
|
||||
" Reading U238 from /opt/xsdata/nndc/U238.h5\n",
|
||||
" Reading Zr90 from /opt/xsdata/nndc/Zr90.h5\n",
|
||||
" Reading H1 from\n",
|
||||
" /home/wbinventor/Documents/NSE-CRPG-Codes/openmc/data/nndc_hdf5/H1.h5\n",
|
||||
" Reading O16 from\n",
|
||||
" /home/wbinventor/Documents/NSE-CRPG-Codes/openmc/data/nndc_hdf5/O16.h5\n",
|
||||
" Reading U235 from\n",
|
||||
" /home/wbinventor/Documents/NSE-CRPG-Codes/openmc/data/nndc_hdf5/U235.h5\n",
|
||||
" Reading U238 from\n",
|
||||
" /home/wbinventor/Documents/NSE-CRPG-Codes/openmc/data/nndc_hdf5/U238.h5\n",
|
||||
" Reading Zr90 from\n",
|
||||
" /home/wbinventor/Documents/NSE-CRPG-Codes/openmc/data/nndc_hdf5/Zr90.h5\n",
|
||||
" Maximum neutron transport energy: 2.00000E+07 eV for H1\n",
|
||||
" Reading tallies XML file...\n",
|
||||
" Building neighboring cells lists for each surface...\n",
|
||||
|
|
@ -611,20 +616,20 @@
|
|||
"\n",
|
||||
" =======================> TIMING STATISTICS <=======================\n",
|
||||
"\n",
|
||||
" Total time for initialization = 3.5070E-01 seconds\n",
|
||||
" Reading cross sections = 2.4151E-01 seconds\n",
|
||||
" Total time in simulation = 2.3276E+00 seconds\n",
|
||||
" Time in transport only = 2.2350E+00 seconds\n",
|
||||
" Time in inactive batches = 2.5677E-01 seconds\n",
|
||||
" Time in active batches = 2.0708E+00 seconds\n",
|
||||
" Time synchronizing fission bank = 2.7683E-03 seconds\n",
|
||||
" Sampling source sites = 2.0233E-03 seconds\n",
|
||||
" SEND/RECV source sites = 7.1007E-04 seconds\n",
|
||||
" Time accumulating tallies = 5.0753E-05 seconds\n",
|
||||
" Total time for finalization = 3.8695E-04 seconds\n",
|
||||
" Total time elapsed = 2.6857E+00 seconds\n",
|
||||
" Calculation Rate (inactive) = 97364.6 neutrons/second\n",
|
||||
" Calculation Rate (active) = 48290.8 neutrons/second\n",
|
||||
" Total time for initialization = 3.0114E-01 seconds\n",
|
||||
" Reading cross sections = 1.8743E-01 seconds\n",
|
||||
" Total time in simulation = 9.7641E+00 seconds\n",
|
||||
" Time in transport only = 9.5168E+00 seconds\n",
|
||||
" Time in inactive batches = 1.2602E+00 seconds\n",
|
||||
" Time in active batches = 8.5039E+00 seconds\n",
|
||||
" Time synchronizing fission bank = 5.4293E-03 seconds\n",
|
||||
" Sampling source sites = 4.3508E-03 seconds\n",
|
||||
" SEND/RECV source sites = 9.9399E-04 seconds\n",
|
||||
" Time accumulating tallies = 1.2758E-04 seconds\n",
|
||||
" Total time for finalization = 3.6982E-04 seconds\n",
|
||||
" Total time elapsed = 1.0075E+01 seconds\n",
|
||||
" Calculation Rate (inactive) = 19838.7 neutrons/second\n",
|
||||
" Calculation Rate (active) = 11759.3 neutrons/second\n",
|
||||
"\n",
|
||||
" ============================> RESULTS <============================\n",
|
||||
"\n",
|
||||
|
|
@ -905,7 +910,7 @@
|
|||
" <td>6.250000e-01</td>\n",
|
||||
" <td>total</td>\n",
|
||||
" <td>(((total / flux) - (absorption / flux)) - (sca...</td>\n",
|
||||
" <td>-5.551115e-15</td>\n",
|
||||
" <td>-1.110223e-15</td>\n",
|
||||
" <td>0.011292</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
|
|
@ -915,7 +920,7 @@
|
|||
" <td>2.000000e+07</td>\n",
|
||||
" <td>total</td>\n",
|
||||
" <td>(((total / flux) - (absorption / flux)) - (sca...</td>\n",
|
||||
" <td>-1.110223e-16</td>\n",
|
||||
" <td>1.776357e-15</td>\n",
|
||||
" <td>0.002570</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
|
|
@ -928,8 +933,8 @@
|
|||
"1 1 6.25e-01 2.00e+07 total \n",
|
||||
"\n",
|
||||
" score mean std. dev. \n",
|
||||
"0 (((total / flux) - (absorption / flux)) - (sca... -5.55e-15 1.13e-02 \n",
|
||||
"1 (((total / flux) - (absorption / flux)) - (sca... -1.11e-16 2.57e-03 "
|
||||
"0 (((total / flux) - (absorption / flux)) - (sca... -1.11e-15 1.13e-02 \n",
|
||||
"1 (((total / flux) - (absorption / flux)) - (sca... 1.78e-15 2.57e-03 "
|
||||
]
|
||||
},
|
||||
"execution_count": 22,
|
||||
|
|
@ -1192,7 +1197,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.0"
|
||||
"version": "3.5.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,8 +0,0 @@
|
|||
.. _pythonapi_opencg_compatible:
|
||||
|
||||
====================
|
||||
OpenCG Compatibility
|
||||
====================
|
||||
|
||||
.. automodule:: openmc.opencg_compatible
|
||||
:members:
|
||||
8
docs/source/pythonapi/openmoc_compatible.rst
Normal file
8
docs/source/pythonapi/openmoc_compatible.rst
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.. _pythonapi_openmoc_compatible:
|
||||
|
||||
=====================
|
||||
OpenMOC Compatibility
|
||||
=====================
|
||||
|
||||
.. automodule:: openmc.openmoc_compatible
|
||||
:members:
|
||||
|
|
@ -28,6 +28,6 @@ from openmc.mixin import *
|
|||
from openmc.plotter import *
|
||||
|
||||
try:
|
||||
from openmc.opencg_compatible import *
|
||||
from openmc.openmoc_compatible import *
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -399,7 +399,6 @@ class CrossFilter(object):
|
|||
distribcell tally filters (default is None). The geometric
|
||||
information in the Summary object is embedded into a Multi-index
|
||||
column with a geometric "path" to each distribcell instance.
|
||||
NOTE: This option requires the OpenCG Python package.
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
|
|||
|
|
@ -1301,8 +1301,7 @@ class DistribcellFilter(Filter):
|
|||
filter_bins = np.tile(filter_bins, tile_factor)
|
||||
df = pd.DataFrame({self.short_name.lower() : filter_bins})
|
||||
|
||||
# If OpenCG level info DataFrame was created, concatenate
|
||||
# with DataFrame of distribcell instance IDs
|
||||
# Concatenate with DataFrame of distribcell instance IDs
|
||||
if level_df is not None:
|
||||
level_df = level_df.dropna(axis=1, how='all')
|
||||
level_df = level_df.astype(np.int)
|
||||
|
|
|
|||
|
|
@ -610,7 +610,7 @@ class Material(object):
|
|||
def make_isotropic_in_lab(self):
|
||||
for nuclide, percent, percent_type in self._nuclides:
|
||||
nuclide.scattering = 'iso-in-lab'
|
||||
for element, percent, percent_type in self._elements:
|
||||
for element, percent, percent_type, enrichment in self._elements:
|
||||
element.scattering = 'iso-in-lab'
|
||||
|
||||
def get_nuclides(self):
|
||||
|
|
|
|||
|
|
@ -586,7 +586,7 @@ class Library(object):
|
|||
self._geometry = statepoint.summary.geometry
|
||||
self._nuclides = statepoint.summary.nuclides
|
||||
|
||||
if statepoint.run_mode == 'k-eigenvalue':
|
||||
if statepoint.run_mode == 'eigenvalue':
|
||||
self._keff = statepoint.k_combined[0]
|
||||
|
||||
# Load tallies for each MGXS for each domain and mgxs type
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
738
openmc/openmoc_compatible.py
Normal file
738
openmc/openmoc_compatible.py
Normal file
|
|
@ -0,0 +1,738 @@
|
|||
import copy
|
||||
import operator
|
||||
|
||||
import numpy as np
|
||||
|
||||
import openmoc
|
||||
import openmc
|
||||
import openmc.checkvalue as cv
|
||||
|
||||
|
||||
# A dictionary of all OpenMC Materials created
|
||||
# Keys - Material IDs
|
||||
# Values - Materials
|
||||
OPENMC_MATERIALS = {}
|
||||
|
||||
# A dictionary of all OpenMOC Materials created
|
||||
# Keys - Material IDs
|
||||
# Values - Materials
|
||||
OPENMOC_MATERIALS = {}
|
||||
|
||||
# A dictionary of all OpenMC Surfaces created
|
||||
# Keys - Surface IDs
|
||||
# Values - Surfaces
|
||||
OPENMC_SURFACES = {}
|
||||
|
||||
# A dictionary of all OpenMOC Surfaces created
|
||||
# Keys - Surface IDs
|
||||
# Values - Surfaces
|
||||
OPENMOC_SURFACES = {}
|
||||
|
||||
# A dictionary of all OpenMC Cells created
|
||||
# Keys - Cell IDs
|
||||
# Values - Cells
|
||||
OPENMC_CELLS = {}
|
||||
|
||||
# A dictionary of all OpenMOC Cells created
|
||||
# Keys - Cell IDs
|
||||
# Values - Cells
|
||||
OPENMOC_CELLS = {}
|
||||
|
||||
# A dictionary of all OpenMC Universes created
|
||||
# Keys - Universes IDs
|
||||
# Values - Universes
|
||||
OPENMC_UNIVERSES = {}
|
||||
|
||||
# A dictionary of all OpenMOC Universes created
|
||||
# Keys - Universes IDs
|
||||
# Values - Universes
|
||||
OPENMOC_UNIVERSES = {}
|
||||
|
||||
# A dictionary of all OpenMC Lattices created
|
||||
# Keys - Lattice IDs
|
||||
# Values - Lattices
|
||||
OPENMC_LATTICES = {}
|
||||
|
||||
# A dictionary of all OpenMOC Lattices created
|
||||
# Keys - Lattice IDs
|
||||
# Values - Lattices
|
||||
OPENMOC_LATTICES = {}
|
||||
|
||||
|
||||
def get_openmoc_material(openmc_material):
|
||||
"""Return an OpenMOC material corresponding to an OpenMC material.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmc_material : openmc.Material
|
||||
OpenMC material
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmoc_material : openmoc.Material
|
||||
Equivalent OpenMOC material
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmc_material', openmc_material, openmc.Material)
|
||||
|
||||
material_id = openmc_material.id
|
||||
|
||||
# If this Material was already created, use it
|
||||
if material_id in OPENMOC_MATERIALS:
|
||||
return OPENMOC_MATERIALS[material_id]
|
||||
|
||||
# Create an OpenMOC Material to represent this OpenMC Material
|
||||
name = str(openmc_material.name)
|
||||
openmoc_material = openmoc.Material(id=material_id, name=name)
|
||||
|
||||
# Add the OpenMC Material to the global collection of all OpenMC Materials
|
||||
OPENMC_MATERIALS[material_id] = openmc_material
|
||||
|
||||
# Add the OpenMOC Material to the global collection of all OpenMOC Materials
|
||||
OPENMOC_MATERIALS[material_id] = openmoc_material
|
||||
|
||||
return openmoc_material
|
||||
|
||||
|
||||
def get_openmc_material(openmoc_material):
|
||||
"""Return an OpenMC material corresponding to an OpenMOC material.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmoc_material : openmoc.Material
|
||||
OpenMOC material
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc_material : openmc.Material
|
||||
Equivalent OpenMC material
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmoc_material', openmoc_material, openmoc.Material)
|
||||
|
||||
material_id = openmoc_material.getId()
|
||||
|
||||
# If this Material was already created, use it
|
||||
if material_id in OPENMC_MATERIALS:
|
||||
return OPENMC_MATERIALS[material_id]
|
||||
|
||||
# Create an OpenMC Material to represent this OpenMOC Material
|
||||
name = openmoc_material.getName()
|
||||
openmc_material = openmc.Material(material_id=material_id, name=name)
|
||||
|
||||
# Add the OpenMOC Material to the global collection of all OpenMOC Materials
|
||||
OPENMOC_MATERIALS[material_id] = openmoc_material
|
||||
|
||||
# Add the OpenMC Material to the global collection of all OpenMC Materials
|
||||
OPENMC_MATERIALS[material_id] = openmc_material
|
||||
|
||||
return openmc_material
|
||||
|
||||
|
||||
def get_openmoc_surface(openmc_surface):
|
||||
"""Return an OpenMOC surface corresponding to an OpenMC surface.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmc_surface : openmc.Surface
|
||||
OpenMC surface
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmoc_surface : openmoc.Surface
|
||||
Equivalent OpenMOC surface
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmc_surface', openmc_surface, openmc.Surface)
|
||||
|
||||
surface_id = openmc_surface.id
|
||||
|
||||
# If this Material was already created, use it
|
||||
if surface_id in OPENMOC_SURFACES:
|
||||
return OPENMOC_SURFACES[surface_id]
|
||||
|
||||
# Create an OpenMOC Surface to represent this OpenMC Surface
|
||||
name = openmc_surface.name
|
||||
|
||||
# Determine the type of boundary conditions applied to the Surface
|
||||
if openmc_surface.boundary_type == 'vacuum':
|
||||
boundary = openmoc.VACUUM
|
||||
elif openmc_surface.boundary_type == 'reflective':
|
||||
boundary = openmoc.REFLECTIVE
|
||||
elif openmc_surface.boundary_type == 'periodic':
|
||||
boundary = openmoc.PERIODIC
|
||||
else:
|
||||
boundary = openmoc.BOUNDARY_NONE
|
||||
|
||||
if openmc_surface.type == 'plane':
|
||||
A = openmc_surface.a
|
||||
B = openmc_surface.b
|
||||
C = openmc_surface.c
|
||||
D = openmc_surface.d
|
||||
openmoc_surface = openmoc.Plane(A, B, C, D, surface_id, name)
|
||||
|
||||
elif openmc_surface.type == 'x-plane':
|
||||
x0 = openmc_surface.x0
|
||||
openmoc_surface = openmoc.XPlane(x0, surface_id, name)
|
||||
|
||||
elif openmc_surface.type == 'y-plane':
|
||||
y0 = openmc_surface.y0
|
||||
openmoc_surface = openmoc.YPlane(y0, surface_id, name)
|
||||
|
||||
elif openmc_surface.type == 'z-plane':
|
||||
z0 = openmc_surface.z0
|
||||
openmoc_surface = openmoc.ZPlane(z0, surface_id, name)
|
||||
|
||||
elif openmc_surface.type == 'z-cylinder':
|
||||
x0 = openmc_surface.x0
|
||||
y0 = openmc_surface.y0
|
||||
R = openmc_surface.r
|
||||
openmoc_surface = openmoc.ZCylinder(x0, y0, R, surface_id, name)
|
||||
|
||||
else:
|
||||
msg = 'Unable to create an OpenMOC Surface from an OpenMC ' \
|
||||
'Surface of type "{}" since it is not a compatible ' \
|
||||
'Surface type in OpenMOC'.format(type(openmc_surface))
|
||||
raise ValueError(msg)
|
||||
|
||||
# Set the boundary condition for this Surface
|
||||
openmoc_surface.setBoundaryType(boundary)
|
||||
|
||||
# Add the OpenMC Surface to the global collection of all OpenMC Surfaces
|
||||
OPENMC_SURFACES[surface_id] = openmc_surface
|
||||
|
||||
# Add the OpenMOC Surface to the global collection of all OpenMOC Surfaces
|
||||
OPENMOC_SURFACES[surface_id] = openmoc_surface
|
||||
|
||||
return openmoc_surface
|
||||
|
||||
|
||||
def get_openmc_surface(openmoc_surface):
|
||||
"""Return an OpenMC surface corresponding to an OpenMOC surface.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmoc_surface : openmoc.Surface
|
||||
OpenMOC surface
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc_surface : openmc.Surface
|
||||
Equivalent OpenMC surface
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmoc_surface', openmoc_surface, openmoc.Surface)
|
||||
|
||||
surface_id = openmoc_surface.id
|
||||
|
||||
# If this Surface was already created, use it
|
||||
if surface_id in OPENMC_SURFACES:
|
||||
return OPENMC_SURFACES[surface_id]
|
||||
|
||||
# Create an OpenMC Surface to represent this OpenMOC Surface
|
||||
name = openmoc_surface.name
|
||||
|
||||
# Correct for OpenMC's syntax for Surfaces dividing Cells
|
||||
boundary = openmoc_surface.getBoundaryType()
|
||||
if boundary == openmoc.VACUUM:
|
||||
boundary = 'vacuum'
|
||||
elif boundary == openmoc.REFLECTIVE:
|
||||
boundary = 'reflective'
|
||||
elif boundary == openmoc.PERIODIC:
|
||||
boundary = 'periodic'
|
||||
else:
|
||||
boundary = 'transmission'
|
||||
|
||||
if openmoc_surface.getSurfaceType() == openmoc.PLANE:
|
||||
A = openmoc_surface.getA()
|
||||
B = openmoc_surface.getB()
|
||||
C = openmoc_surface.getC()
|
||||
D = openmoc_surface.getD()
|
||||
openmc_surface = openmc.Plane(surface_id, boundary, A, B, C, D, name)
|
||||
|
||||
elif openmoc_surface.getSurfaceType() == openmoc.XPLANE:
|
||||
x0 = openmoc_surface.getX()
|
||||
openmc_surface = openmc.XPlane(surface_id, boundary, x0, name)
|
||||
|
||||
elif openmoc_surface.getSurfaceType() == openmoc.YPLANE:
|
||||
y0 = openmoc_surface.getY()
|
||||
openmc_surface = openmc.YPlane(surface_id, boundary, y0, name)
|
||||
|
||||
elif openmoc_surface.getSurfaceType() == openmoc.ZPLANE:
|
||||
z0 = openmoc_surface.getZ()
|
||||
openmc_surface = openmc.ZPlane(surface_id, boundary, z0, name)
|
||||
|
||||
elif openmoc_surface.getSurfaceType() == openmoc.ZCYLINDER:
|
||||
x0 = openmoc_surface.getX0()
|
||||
y0 = openmoc_surface.getY0()
|
||||
R = openmoc_surface.getR()
|
||||
openmc_surface = openmc.ZCylinder(surface_id, boundary, x0, y0, R, name)
|
||||
|
||||
# Add the OpenMC Surface to the global collection of all OpenMC Surfaces
|
||||
OPENMC_SURFACES[surface_id] = openmc_surface
|
||||
|
||||
# Add the OpenMOC Surface to the global collection of all OpenMOC Surfaces
|
||||
OPENMOC_SURFACES[surface_id] = openmoc_surface
|
||||
|
||||
return openmc_surface
|
||||
|
||||
|
||||
def get_openmoc_cell(openmc_cell):
|
||||
"""Return an OpenMOC cell corresponding to an OpenMC cell.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmc_cell : openmc.Cell
|
||||
OpenMC cell
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmoc_cell : openmoc.Cell
|
||||
Equivalent OpenMOC cell
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmc_cell', openmc_cell, openmc.Cell)
|
||||
|
||||
cell_id = openmc_cell.id
|
||||
|
||||
# If this Cell was already created, use it
|
||||
if cell_id in OPENMOC_CELLS:
|
||||
return OPENMOC_CELLS[cell_id]
|
||||
|
||||
# Create an OpenMOC Cell to represent this OpenMC Cell
|
||||
name = openmc_cell.name
|
||||
openmoc_cell = openmoc.Cell(cell_id, name)
|
||||
|
||||
fill = openmc_cell.fill
|
||||
|
||||
if openmc_cell.fill_type == 'material':
|
||||
openmoc_cell.setFill(get_openmoc_material(fill))
|
||||
elif openmc_cell.fill_type == 'universe':
|
||||
openmoc_cell.setFill(get_openmoc_universe(fill))
|
||||
else:
|
||||
openmoc_cell.setFill(get_openmoc_lattice(fill))
|
||||
|
||||
if openmc_cell.rotation is not None:
|
||||
rotation = np.asarray(openmc_cell.rotation, dtype=np.float64)
|
||||
openmoc_cell.setRotation(rotation)
|
||||
if openmc_cell.translation is not None:
|
||||
translation = np.asarray(openmc_cell.translation, dtype=np.float64)
|
||||
openmoc_cell.setTranslation(translation)
|
||||
|
||||
# Add surfaces to OpenMOC cell from OpenMC cell region. Right now this only
|
||||
# works if the region is a single half-space or an intersection of
|
||||
# half-spaces, i.e., no complex cells.
|
||||
region = openmc_cell.region
|
||||
if region is not None:
|
||||
if isinstance(region, openmc.Halfspace):
|
||||
surface = region.surface
|
||||
halfspace = -1 if region.side == '-' else 1
|
||||
openmoc_cell.addSurface(halfspace, get_openmoc_surface(surface))
|
||||
elif isinstance(region, openmc.Intersection):
|
||||
for node in region.nodes:
|
||||
if not isinstance(node, openmc.Halfspace):
|
||||
raise NotImplementedError("Complex cells not yet "
|
||||
"supported in OpenMOC.")
|
||||
surface = node.surface
|
||||
halfspace = -1 if node.side == '-' else 1
|
||||
openmoc_cell.addSurface(halfspace, get_openmoc_surface(surface))
|
||||
else:
|
||||
raise NotImplementedError("Complex cells not yet supported "
|
||||
"in OpenMOC.")
|
||||
|
||||
# Add the OpenMC Cell to the global collection of all OpenMC Cells
|
||||
OPENMC_CELLS[cell_id] = openmc_cell
|
||||
|
||||
# Add the OpenMOC Cell to the global collection of all OpenMOC Cells
|
||||
OPENMOC_CELLS[cell_id] = openmoc_cell
|
||||
|
||||
return openmoc_cell
|
||||
|
||||
|
||||
def get_openmc_cell(openmoc_cell):
|
||||
"""Return an OpenMC cell corresponding to an OpenMOC cell.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmoc_cell : openmoc.Cell
|
||||
OpenMOC cell
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc_cell : openmc.Cell
|
||||
Equivalent OpenMC cell
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmoc_cell', openmoc_cell, openmoc.Cell)
|
||||
|
||||
cell_id = openmoc_cell.getId()
|
||||
|
||||
# If this Cell was already created, use it
|
||||
if cell_id in OPENMC_CELLS:
|
||||
return OPENMC_CELLS[cell_id]
|
||||
|
||||
# Create an OpenMOC Cell to represent this OpenMC Cell
|
||||
name = openmoc_cell.getName()
|
||||
openmc_cell = openmc.Cell(cell_id, name)
|
||||
|
||||
if (openmoc_cell.getType() == openmoc.MATERIAL):
|
||||
fill = openmoc_cell.getFillMaterial()
|
||||
openmc_cell.fill = get_openmc_material(fill)
|
||||
elif (openmoc_cell.getType() == openmoc.FILL):
|
||||
fill = openmoc_cell.getFillUniverse()
|
||||
if isinstance(fill, openmoc.Lattice):
|
||||
openmc_cell.fill = get_openmc_lattice(fill)
|
||||
else:
|
||||
openmc_cell.fill = get_openmc_universe(fill)
|
||||
|
||||
if openmoc_cell.isRotated():
|
||||
rotation = openmoc_cell.getRotation(3)
|
||||
openmc_cell.rotation = rotation
|
||||
if openmoc_cell.isTranslated():
|
||||
translation = openmoc_cell.getTranslation(3)
|
||||
openmc_cell.translation = translation
|
||||
|
||||
regions = []
|
||||
for surf_id, surf_halfspace in openmoc_cell.getSurfaces().values():
|
||||
halfspace = surf_halfspace._halfspace
|
||||
surface = get_openmc_surface(surf_halfspace._surface)
|
||||
regions.append(-surface if halfspace == -1 else +surface)
|
||||
openmc_cell.region = openmc.Intersection(*regions)
|
||||
|
||||
# Add the OpenMC Cell to the global collection of all OpenMC Cells
|
||||
OPENMC_CELLS[cell_id] = openmc_cell
|
||||
|
||||
# Add the OpenMOC Cell to the global collection of all OpenMOC Cells
|
||||
OPENMOC_CELLS[cell_id] = openmoc_cell
|
||||
|
||||
return openmc_cell
|
||||
|
||||
|
||||
def get_openmoc_universe(openmc_universe):
|
||||
"""Return an OpenMOC universe corresponding to an OpenMC universe.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmc_universe : openmc.Universe
|
||||
OpenMC universe
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmoc_universe : openmoc.Universe
|
||||
Equivalent OpenMOC universe
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmc_universe', openmc_universe, openmc.Universe)
|
||||
|
||||
universe_id = openmc_universe.id
|
||||
|
||||
# If this Universe was already created, use it
|
||||
if universe_id in OPENMOC_UNIVERSES:
|
||||
return OPENMOC_UNIVERSES[universe_id]
|
||||
|
||||
# Create an OpenMOC Universe to represent this OpenMC Universe
|
||||
name = openmc_universe.name
|
||||
openmoc_universe = openmoc.Universe(universe_id, name)
|
||||
|
||||
# Convert all OpenMC Cells in this Universe to OpenMOC Cells
|
||||
openmc_cells = openmc_universe.cells
|
||||
|
||||
for openmc_cell in openmc_cells.values():
|
||||
openmoc_cell = get_openmoc_cell(openmc_cell)
|
||||
openmoc_universe.addCell(openmoc_cell)
|
||||
|
||||
# Add the OpenMC Universe to the global collection of all OpenMC Universes
|
||||
OPENMC_UNIVERSES[universe_id] = openmc_universe
|
||||
|
||||
# Add the OpenMOC Universe to the global collection of all OpenMOC Universes
|
||||
OPENMOC_UNIVERSES[universe_id] = openmoc_universe
|
||||
|
||||
return openmoc_universe
|
||||
|
||||
|
||||
def get_openmc_universe(openmoc_universe):
|
||||
"""Return an OpenMC universe corresponding to an OpenMOC universe.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmoc_universe : openmoc.Universe
|
||||
OpenMOC universe
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc_universe : openmc.Universe
|
||||
Equivalent OpenMC universe
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmoc_universe', openmoc_universe, openmoc.Universe)
|
||||
|
||||
universe_id = openmoc_universe.getId()
|
||||
|
||||
# If this Universe was already created, use it
|
||||
if universe_id in OPENMC_UNIVERSES:
|
||||
return OPENMC_UNIVERSES[universe_id]
|
||||
|
||||
# Create an OpenMC Universe to represent this OpenMOC Universe
|
||||
name = openmoc_universe.getName()
|
||||
openmc_universe = openmc.Universe(universe_id, name)
|
||||
|
||||
# Convert all OpenMOC Cells in this Universe to OpenMC Cells
|
||||
for openmoc_cell in openmoc_universe.getCells():
|
||||
openmc_cell = get_openmc_cell(openmoc_cell)
|
||||
openmc_universe.add_cell(openmc_cell)
|
||||
|
||||
# Add the OpenMC Universe to the global collection of all OpenMC Universes
|
||||
OPENMC_UNIVERSES[universe_id] = openmc_universe
|
||||
|
||||
# Add the OpenMOC Universe to the global collection of all OpenMOC Universes
|
||||
OPENMOC_UNIVERSES[universe_id] = openmoc_universe
|
||||
|
||||
return openmc_universe
|
||||
|
||||
|
||||
def get_openmoc_lattice(openmc_lattice):
|
||||
"""Return an OpenMOC lattice corresponding to an OpenMOC lattice.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmc_lattice : openmc.RectLattice
|
||||
OpenMC lattice
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmoc_lattice : openmoc.Lattice
|
||||
Equivalent OpenMOC lattice
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmc_lattice', openmc_lattice, openmc.RectLattice)
|
||||
|
||||
lattice_id = openmc_lattice.id
|
||||
|
||||
# If this Lattice was already created, use it
|
||||
if lattice_id in OPENMOC_LATTICES:
|
||||
return OPENMOC_LATTICES[lattice_id]
|
||||
|
||||
# Create an OpenMOC Lattice to represent this OpenMC Lattice
|
||||
name = openmc_lattice.name
|
||||
dimension = openmc_lattice.shape
|
||||
pitch = openmc_lattice.pitch
|
||||
lower_left = openmc_lattice.lower_left
|
||||
universes = openmc_lattice.universes
|
||||
|
||||
# Convert 2D dimension to 3D for OpenMOC
|
||||
if len(dimension) == 2:
|
||||
new_dimension = np.ones(3, dtype=int)
|
||||
new_dimension[:2] = dimension
|
||||
dimension = new_dimension
|
||||
|
||||
# Convert 2D pitch to 3D for OpenMOC
|
||||
if len(pitch) == 2:
|
||||
new_pitch = np.ones(3, dtype=np.float64) * np.finfo(np.float64).max
|
||||
new_pitch[:2] = pitch
|
||||
pitch = new_pitch
|
||||
|
||||
# Convert 2D lower left to 3D for OpenMOC
|
||||
if len(lower_left) == 2:
|
||||
new_lower_left = np.ones(3, dtype=np.float64) * np.finfo(np.float64).min
|
||||
new_lower_left[:2] = lower_left
|
||||
lower_left = new_lower_left
|
||||
|
||||
# Convert 2D universes array to 3D for OpenMOC
|
||||
if len(universes.shape) == 2:
|
||||
new_universes = universes.copy()
|
||||
new_universes.shape = (1,) + universes.shape
|
||||
universes = new_universes
|
||||
|
||||
# Initialize an empty array for the OpenMOC nested Universes in this Lattice
|
||||
universe_array = np.ndarray(tuple(dimension[::-1]), dtype=openmoc.Universe)
|
||||
|
||||
# Create OpenMOC Universes for each unique nested Universe in this Lattice
|
||||
unique_universes = openmc_lattice.get_unique_universes()
|
||||
|
||||
for universe_id, universe in unique_universes.items():
|
||||
unique_universes[universe_id] = get_openmoc_universe(universe)
|
||||
|
||||
# Build the nested Universe array
|
||||
for z in range(dimension[2]):
|
||||
for y in range(dimension[1]):
|
||||
for x in range(dimension[0]):
|
||||
universe_id = universes[z][y][x].id
|
||||
universe_array[z][dimension[1]-y-1][x] = unique_universes[universe_id]
|
||||
|
||||
openmoc_lattice = openmoc.Lattice(lattice_id, name)
|
||||
openmoc_lattice.setWidth(pitch[0], pitch[1], pitch[2])
|
||||
openmoc_lattice.setUniverses(universe_array.tolist())
|
||||
|
||||
offset = np.array(lower_left, dtype=np.float64) - \
|
||||
((np.array(pitch, dtype=np.float64) *
|
||||
np.array(dimension, dtype=np.float64))) / -2.0
|
||||
openmoc_lattice.setOffset(offset[0], offset[1], offset[2])
|
||||
|
||||
# Add the OpenMC Lattice to the global collection of all OpenMC Lattices
|
||||
OPENMC_LATTICES[lattice_id] = openmc_lattice
|
||||
|
||||
# Add the OpenMOC Lattice to the global collection of all OpenMOC Lattices
|
||||
OPENMOC_LATTICES[lattice_id] = openmoc_lattice
|
||||
|
||||
return openmoc_lattice
|
||||
|
||||
|
||||
def get_openmc_lattice(openmoc_lattice):
|
||||
"""Return an OpenMC lattice corresponding to an OpenMOC lattice.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmoc_lattice : openmoc.Lattice
|
||||
OpenMOC lattice
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc_lattice : openmc.RectLattice
|
||||
Equivalent OpenMC lattice
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmoc_lattice', openmoc_lattice, openmoc.Lattice)
|
||||
|
||||
lattice_id = openmoc_lattice.getId()
|
||||
|
||||
# If this Lattice was already created, use it
|
||||
if lattice_id in OPENMC_LATTICES:
|
||||
return OPENMC_LATTICES[lattice_id]
|
||||
|
||||
name = openmoc_lattice.getName()
|
||||
dimension = [1, openmoc_lattice.getNumY(), openmoc_lattice.getNumX()]
|
||||
width = [1, openmoc_lattice.getWidthY(), openmoc_lattice.getWidthX()]
|
||||
offset = openmoc_lattice.getOffset()
|
||||
lower_left = np.array(offset, dtype=np.float64) + \
|
||||
((np.array(width, dtype=np.float64) *
|
||||
np.array(dimension, dtype=np.float64))) / -2.0
|
||||
|
||||
# Initialize an empty array for the OpenMOC nested Universes in this Lattice
|
||||
universe_array = np.ndarray(tuple(np.array(dimension)[::-1]),
|
||||
dtype=openmoc.Universe)
|
||||
|
||||
# Create OpenMOC Universes for each unique nested Universe in this Lattice
|
||||
unique_universes = openmoc_lattice.getUniqueUniverses()
|
||||
|
||||
for universe_id, universe in unique_universes.items():
|
||||
unique_universes[universe_id] = get_openmc_universe(universe)
|
||||
|
||||
# Build the nested Universe array
|
||||
for z in range(dimension[2]):
|
||||
for y in range(dimension[1]):
|
||||
for x in range(dimension[0]):
|
||||
universe = openmoc_lattice.getUniverse(x, y)
|
||||
universe_id = universe.getId()
|
||||
universe_array[z][dimension[1]-y-1][x] = unique_universes[universe_id]
|
||||
|
||||
openmc_lattice = openmc.RectLattice(lattice_id=lattice_id, name=name)
|
||||
openmc_lattice.pitch = width
|
||||
openmc_lattice.lower_left = lower_left
|
||||
openmc_lattice.universes = universe_array
|
||||
|
||||
# Add the OpenMC Lattice to the global collection of all OpenMC Lattices
|
||||
OPENMC_LATTICES[lattice_id] = openmc_lattice
|
||||
|
||||
# Add the OpenMOC Lattice to the global collection of all OpenMOC Lattices
|
||||
OPENMOC_LATTICES[lattice_id] = openmoc_lattice
|
||||
|
||||
return openmc_lattice
|
||||
|
||||
|
||||
def get_openmoc_geometry(openmc_geometry):
|
||||
"""Return an OpenMC geometry corresponding to an OpenMOC geometry.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmc_geometry : openmc.Geometry
|
||||
OpenMC geometry
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmoc_geometry : openmoc.Geometry
|
||||
Equivalent OpenMOC geometry
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmc_geometry', openmc_geometry, openmc.Geometry)
|
||||
|
||||
# Clear dictionaries and auto-generated IDs
|
||||
OPENMC_SURFACES.clear()
|
||||
OPENMOC_SURFACES.clear()
|
||||
OPENMC_CELLS.clear()
|
||||
OPENMOC_CELLS.clear()
|
||||
OPENMC_UNIVERSES.clear()
|
||||
OPENMOC_UNIVERSES.clear()
|
||||
OPENMC_LATTICES.clear()
|
||||
OPENMOC_LATTICES.clear()
|
||||
|
||||
openmc_root_universe = openmc_geometry.root_universe
|
||||
openmoc_root_universe = get_openmoc_universe(openmc_root_universe)
|
||||
|
||||
openmoc_geometry = openmoc.Geometry()
|
||||
openmoc_geometry.setRootUniverse(openmoc_root_universe)
|
||||
|
||||
# Update OpenMOC's auto-generated object IDs (e.g., Surface, Material)
|
||||
# with the maximum of those created from the OpenMC objects
|
||||
all_materials = openmoc_geometry.getAllMaterials()
|
||||
all_surfaces = openmoc_geometry.getAllSurfaces()
|
||||
all_cells = openmoc_geometry.getAllCells()
|
||||
all_universes = openmoc_geometry.getAllUniverses()
|
||||
|
||||
max_material_id = max(all_materials.keys())
|
||||
max_surface_id = max(all_surfaces.keys())
|
||||
max_cell_id = max(all_cells.keys())
|
||||
max_universe_id = max(all_universes.keys())
|
||||
|
||||
openmoc.maximize_material_id(max_material_id+1)
|
||||
openmoc.maximize_surface_id(max_surface_id+1)
|
||||
openmoc.maximize_cell_id(max_cell_id+1)
|
||||
openmoc.maximize_universe_id(max_universe_id+1)
|
||||
|
||||
return openmoc_geometry
|
||||
|
||||
|
||||
def get_openmc_geometry(openmoc_geometry):
|
||||
"""Return an OpenMC geometry corresponding to an OpenMOC geometry.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
openmoc_geometry : openmoc.Geometry
|
||||
OpenMOC geometry
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc_geometry : openmc.Geometry
|
||||
Equivalent OpenMC geometry
|
||||
|
||||
"""
|
||||
|
||||
cv.check_type('openmoc_geometry', openmoc_geometry, openmoc.Geometry)
|
||||
|
||||
# Clear dictionaries and auto-generated ID
|
||||
OPENMC_SURFACES.clear()
|
||||
OPENMOC_SURFACES.clear()
|
||||
OPENMC_CELLS.clear()
|
||||
OPENMOC_CELLS.clear()
|
||||
OPENMC_UNIVERSES.clear()
|
||||
OPENMOC_UNIVERSES.clear()
|
||||
OPENMC_LATTICES.clear()
|
||||
OPENMOC_LATTICES.clear()
|
||||
|
||||
openmoc_root_universe = \
|
||||
openmoc_geometry.getRootUniverse(openmoc_root_universe)
|
||||
|
||||
openmc_geometry = openmc.Geometry()
|
||||
openmc_geometry.root_universe = openmc_root_universe
|
||||
|
||||
return openmc_geometry
|
||||
|
|
@ -179,13 +179,15 @@ contains
|
|||
integer :: bank_types(5) ! Datatypes
|
||||
#endif
|
||||
integer(MPI_ADDRESS_KIND) :: bank_disp(5) ! Displacements
|
||||
type(Bank) :: b
|
||||
logical :: init_called
|
||||
type(Bank) :: b
|
||||
|
||||
! Indicate that MPI is turned on
|
||||
mpi_enabled = .true.
|
||||
|
||||
! Initialize MPI
|
||||
call MPI_INIT(mpi_err)
|
||||
call MPI_INITIALIZED(init_called, mpi_err)
|
||||
if (.not. init_called) call MPI_INIT(mpi_err)
|
||||
|
||||
! Determine number of processors and rank of each processor
|
||||
mpi_intracomm = intracomm
|
||||
|
|
|
|||
|
|
@ -262,6 +262,9 @@ contains
|
|||
! A track can span multiple mesh bins so we need to handle a lot of
|
||||
! intersection logic for tracklength tallies.
|
||||
|
||||
! ========================================================================
|
||||
! Determine if the track intersects the tally mesh.
|
||||
|
||||
! Copy the starting and ending coordinates of the particle. Offset these
|
||||
! just a bit for the purposes of determining if there was an intersection
|
||||
! in case the mesh surfaces coincide with lattice/geometric surfaces which
|
||||
|
|
@ -296,6 +299,9 @@ contains
|
|||
end if
|
||||
end if
|
||||
|
||||
! ========================================================================
|
||||
! Figure out which mesh cell to tally.
|
||||
|
||||
! Copy the un-modified coordinates the particle direction.
|
||||
xyz0 = p % last_xyz
|
||||
xyz1 = p % coord(1) % xyz
|
||||
|
|
@ -304,11 +310,20 @@ contains
|
|||
! Compute the length of the entire track.
|
||||
total_distance = sqrt(sum((xyz1 - xyz0)**2))
|
||||
|
||||
! If we're looking for the first valid bin, check to see if the particle
|
||||
! starts inside the mesh.
|
||||
if (current_bin == NO_BIN_FOUND) then
|
||||
! We are looking for the first valid mesh bin. Check to see if the
|
||||
! particle starts inside the mesh.
|
||||
if (any(ijk0(:m % n_dimension) < 1) &
|
||||
.or. any(ijk0(:m % n_dimension) > m % dimension)) then
|
||||
! The particle does not start in the mesh. Note that we nudged the
|
||||
! start and end coordinates by a TINY_BIT each so we will have
|
||||
! difficulty resolving tracks that are less than 2*TINY_BIT in length.
|
||||
! If the track is that short, it is also insignificant so we can
|
||||
! safely ignore it in the tallies.
|
||||
if (total_distance < 2*TINY_BIT) then
|
||||
next_bin = NO_BIN_FOUND
|
||||
return
|
||||
end if
|
||||
|
||||
! The particle does not start in the mesh so keep iterating the ijk0
|
||||
! indices to cross the nearest mesh surface until we've found a valid
|
||||
|
|
@ -347,14 +362,12 @@ contains
|
|||
xyz0 = xyz0 + distance * uvw
|
||||
|
||||
end if
|
||||
end if
|
||||
|
||||
! ========================================================================
|
||||
! If we've already scored some mesh bins, figure out which mesh cell is
|
||||
! next and where the particle enters that cell.
|
||||
else
|
||||
! We have already scored some mesh bins for this track. Pick up where
|
||||
! we left off and find the next mesh cell that the particle enters.
|
||||
|
||||
if (current_bin /= NO_BIN_FOUND) then
|
||||
! Get the indices to the last bin.
|
||||
! Get the indices to the last bin we scored.
|
||||
call bin_to_mesh_indices(m, current_bin, ijk0(:m % n_dimension))
|
||||
|
||||
! If the particle track ends in that bin, then we are done.
|
||||
|
|
@ -401,7 +414,10 @@ contains
|
|||
end if
|
||||
end if
|
||||
|
||||
! Compute the length of the track segment in this mesh cell.
|
||||
! ========================================================================
|
||||
! Compute the length of the track segment in the appropiate mesh cell and
|
||||
! return.
|
||||
|
||||
if (all(ijk0(:m % n_dimension) == ijk1(:m % n_dimension))) then
|
||||
! The track ends in this cell. Use the particle end location rather
|
||||
! than the mesh surface.
|
||||
|
|
@ -422,7 +438,7 @@ contains
|
|||
distance = minval(d(:m % n_dimension))
|
||||
end if
|
||||
|
||||
! Assign the next tally bin and the score
|
||||
! Assign the next tally bin and the score.
|
||||
next_bin = mesh_indices_to_bin(m, ijk0(:m % n_dimension))
|
||||
weight = distance / total_distance
|
||||
endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue