Esempio n. 1
0
import openmoc
import _openmoc_intel_double
from openmoc_intel_double import *
import signal

# Tell Python to recognize CTRL+C and stop the C++ extension module
# when this is passed in from the keyboard
signal.signal(signal.SIGINT, signal.SIG_DFL)

set_log_level(str(openmoc.get_log_level()))
set_output_directory(openmoc.get_output_directory())
set_log_filename(openmoc.get_log_filename())

Timer = openmoc.Timer
Esempio n. 2
0
import signal, sys

import _openmoc_intel_double

# For Python 2.X.X
if (sys.version_info[0] == 2):
  import openmoc
  from openmoc_intel_double import *
# For Python 3.X.X
else:
  import openmoc.openmoc as openmoc
  from openmoc.intel.double.openmoc_intel_double import *

# Tell Python to recognize CTRL+C and stop the C++ extension module
# when this is passed in from the keyboard
signal.signal(signal.SIGINT, signal.SIG_DFL)

set_log_level(str(openmoc.get_log_level()))
set_output_directory(openmoc.get_output_directory())
set_log_filename(openmoc.get_log_filename())

Timer = openmoc.Timer
Esempio n. 3
0
def compute_fission_rates(solver, use_hdf5=False):
    """Computes the fission rate in each FSR.

    This method combines the rates based on their hierarchical universe/lattice
    structure. The fission rates are then exported to a binary HDF5 or Python
    pickle file.

    This routine is intended to be called by the user in Python to compute
    fission rates. Typically, the fission rates will represent pin powers. The
    routine either exports fission rates to an HDF5 binary file or pickle file
    with each fission rate being indexed by a string representing the
    universe/lattice hierarchy.

    Parameters
    ----------
    solver : openmoc.Solver
        The solver used to compute the flux
    use_hdf5 : bool
        Whether or not to export fission rates to an HDF5 file

    Examples
    --------
    This routine may be called from a Python script as follows:

        >>> compute_fission_rates(solver, use_hdf5=True)

    """

    global solver_types
    cv.check_type('solver', solver, solver_types)
    cv.check_type('use_hdf5', use_hdf5, bool)

    # Make directory if it does not exist
    directory = openmoc.get_output_directory() + '/fission-rates/'
    filename = 'fission-rates'
    if not os.path.exists(directory):
        os.makedirs(directory)

    # Get geometry
    geometry = solver.getGeometry()

    # Compute the volume-weighted fission rates for each FSR
    fsr_fission_rates = solver.computeFSRFissionRates(geometry.getNumFSRs())

    # Initialize fission rates dictionary
    fission_rates_sum = {}

    # Loop over FSRs and populate fission rates dictionary
    for fsr in range(geometry.getNumFSRs()):

        if geometry.findFSRMaterial(fsr).isFissionable():

            # Get the linked list of LocalCoords
            point = geometry.getFSRPoint(fsr)
            coords = openmoc.LocalCoords(point.getX(), point.getY(),
                                         point.getZ())
            coords.setUniverse(geometry.getRootUniverse())
            geometry.findCellContainingCoords(coords)
            coords = coords.getHighestLevel().getNext()

            # initialize dictionary key
            key = 'UNIV = 0 : '

            # Parse through the linked list and create fsr key.
            # If lowest level sub dictionary already exists, then increment
            # fission rate; otherwise, set the fission rate.
            while True:
                if coords.getType() is openmoc.LAT:
                    key += 'LAT = ' + str(coords.getLattice().getId()) + ' (' + \
                           str(coords.getLatticeX()) + ', ' + \
                           str(coords.getLatticeY()) + ', ' + \
                           str(coords.getLatticeZ()) + ') : '
                else:
                    key += 'UNIV = ' + str(
                        coords.getUniverse().getId()) + ' : '

                # Remove trailing ' : ' on end of key if at last univ/lat
                if coords.getNext() is None:
                    key = key[:-3]
                    break
                else:
                    coords = coords.getNext()

            # Increment or set fission rate
            if key in fission_rates_sum:
                fission_rates_sum[key] += fsr_fission_rates[fsr]
            else:
                fission_rates_sum[key] = fsr_fission_rates[fsr]

    # Write the fission rates to the HDF5 file
    if use_hdf5:
        f = h5py.File(directory + filename + '.h5', 'w')
        fission_rates_group = f.create_group('fission-rates')
        for key, value in fission_rates_sum.items():
            fission_rates_group.attrs[key] = value
        f.close()

    # Pickle the fission rates to a file
    else:
        pickle.dump(fission_rates_sum, open(directory + filename + '.pkl',
                                            'wb'))
Esempio n. 4
0
def compute_fission_rates(solver, use_hdf5=False):
    """Computes the fission rate in each FSR.

    This method combines the rates based on their hierarchical universe/lattice
    structure. The fission rates are then exported to a binary HDF5 or Python
    pickle file.

    This routine is intended to be called by the user in Python to compute
    fission rates. Typically, the fission rates will represent pin powers. The
    routine either exports fission rates to an HDF5 binary file or pickle file
    with each fission rate being indexed by a string representing the
    universe/lattice hierarchy.

    Parameters
    ----------
    solver : openmoc.Solver
        The solver used to compute the flux
    use_hdf5 : bool
        Whether or not to export fission rates to an HDF5 file

    Examples
    --------
    This routine may be called from a Python script as follows:

        >>> compute_fission_rates(solver, use_hdf5=True)

    """

    cv.check_type('solver', solver, openmoc.Solver)
    cv.check_type('use_hdf5', use_hdf5, bool)

    # Make directory if it does not exist
    directory = openmoc.get_output_directory() + '/fission-rates/'
    filename = 'fission-rates'
    if not os.path.exists(directory):
        os.makedirs(directory)

    # Get geometry
    geometry = solver.getGeometry()

    # Compute the volume-weighted fission rates for each FSR
    fsr_fission_rates = solver.computeFSRFissionRates(geometry.getNumFSRs())

    # Initialize fission rates dictionary
    fission_rates_sum = {}

    # Loop over FSRs and populate fission rates dictionary
    for fsr in range(geometry.getNumFSRs()):

        if geometry.findFSRMaterial(fsr).isFissionable():

            # Get the linked list of LocalCoords
            point = geometry.getFSRPoint(fsr)
            coords = openmoc.LocalCoords(point.getX(), point.getY(), point.getZ())
            coords.setUniverse(geometry.getRootUniverse())
            geometry.findCellContainingCoords(coords)
            coords = coords.getHighestLevel().getNext()

            # initialize dictionary key
            key = 'UNIV = 0 : '

            # Parse through the linked list and create fsr key.
            # If lowest level sub dictionary already exists, then increment
            # fission rate; otherwise, set the fission rate.
            while True:
                if coords.getType() is openmoc.LAT:
                    key += 'LAT = ' + str(coords.getLattice().getId()) + ' (' + \
                           str(coords.getLatticeX()) + ', ' + \
                           str(coords.getLatticeY()) + ', ' + \
                           str(coords.getLatticeZ()) + ') : '
                else:
                    key += 'UNIV = ' + str(coords.getUniverse().getId()) + ' : '

                # Remove trailing ' : ' on end of key if at last univ/lat
                if coords.getNext() is None:
                    key = key[:-3]
                    break
                else:
                    coords = coords.getNext()

            # Increment or set fission rate
            if key in fission_rates_sum:
                fission_rates_sum[key] += fsr_fission_rates[fsr]
            else:
                fission_rates_sum[key] = fsr_fission_rates[fsr]

    # Write the fission rates to the HDF5 file
    if use_hdf5:
        f = h5py.File(directory + filename + '.h5', 'w')
        fission_rates_group = f.create_group('fission-rates')
        for key, value in fission_rates_sum.items():
            fission_rates_group.attrs[key] = value
        f.close()

    # Pickle the fission rates to a file
    else:
        pickle.dump(fission_rates_sum, open(directory + filename + '.pkl', 'wb'))