コード例 #1
0
def get_compatible_opencg_surfaces(opencg_surface):

    if not isinstance(opencg_surface, opencg.Surface):
        msg = 'Unable to create an OpenMOC Surface from {0} which ' \
              'is not an OpenCG Surface'.format(opencg_surface)
        raise ValueError(msg)

    global OPENMOC_SURFACES
    surface_id = opencg_surface._id

    # If this Surface was already created, use it
    if surface_id in OPENMOC_SURFACES:
        return OPENMOC_SURFACES[surface_id]

    # Create an OpenMOC Surface to represent this OpenCG Surface
    name = opencg_surface._name

    # Correct for OpenMOC's syntax for Surfaces dividing Cells
    boundary = opencg_surface._boundary_type

    if opencg_surface._type == 'z-squareprism':
        x0 = opencg_surface._coeffs['x0']
        y0 = opencg_surface._coeffs['y0']
        R = opencg_surface._coeffs['R']

        # Create a list of the four planes we need
        left = opencg.XPlane(x0=x0 - R, name=name)
        right = opencg.XPlane(x0=x0 + R, name=name)
        bottom = opencg.YPlane(y0=y0 - R, name=name)
        top = opencg.YPlane(y0=y0 + R, name=name)

        # Set the boundary conditions for each Surface
        left.setBoundaryType(boundary)
        right.setBoundaryType(boundary)
        bottom.setBoundaryType(boundary)
        top.setBoundaryType(boundary)

        surfaces = [left, right, bottom, top]

    elif opencg_surface._type in [
            'x-cylinder', 'y-cylinder', 'x-squareprism', 'y-squareprism'
    ]:
        msg = 'Unable to create a compatible OpenMOC Surface from an OpenCG ' \
              'Surface of type {0} since it is not compatible with OpenMOCs 2D ' \
              'geometry formulation on the xy-plane'.format(opencg_surface._type)
        raise ValueError(msg)

    else:
        msg = 'Unable to create a compatible OpenMOC Surface from an OpenCG ' \
              'Surface of type {0} since it already a compatible ' \
              'Surface type in OpenMOC'.format(opencg_surface._type)
        raise ValueError(msg)

    # Add the OpenMOC Surface(s) to the global collection of all OpenMOC Surfaces
    OPENMOC_SURFACES[surface_id] = surfaces

    # Add the OpenCG Surface to the global collection of all OpenCG Surfaces
    OPENCG_SURFACES[surface_id] = opencg_surface

    return surfaces
コード例 #2
0
def get_compatible_opencg_surfaces(opencg_surface):
    """Generate OpenCG surfaces that are compatible with OpenMC equivalent to an
    OpenCG surface that is not compatible. For example, this method may be used
    to convert a ZSquarePrism OpenCG surface into a collection of equivalent
    XPlane and YPlane OpenCG surfaces.

    Parameters
    ----------
    opencg_surface : opencg.Surface
        OpenCG surface that is incompatible with OpenMC

    Returns
    -------
    surfaces : list of opencg.Surface
        Collection of surfaces equivalent to the original one but compatible
        with OpenMC

    """

    if not isinstance(opencg_surface, opencg.Surface):
        msg = 'Unable to create an OpenMC Surface from "{0}" which ' \
              'is not an OpenCG Surface'.format(opencg_surface)
        raise ValueError(msg)

    global OPENMC_SURFACES
    surface_id = opencg_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 OpenCG Surface
    name = opencg_surface._name
    boundary = opencg_surface._boundary_type

    if opencg_surface._type == 'x-squareprism':
        y0 = opencg_surface._coeffs['y0']
        z0 = opencg_surface._coeffs['z0']
        R = opencg_surface._coeffs['R']

        # Create a list of the four planes we need
        left = opencg.YPlane(name=name, boundary=boundary, y0=y0 - R)
        right = opencg.YPlane(name=name, boundary=boundary, y0=y0 + R)
        bottom = opencg.ZPlane(name=name, boundary=boundary, z0=z0 - R)
        top = opencg.ZPlane(name=name, boundary=boundary, z0=z0 + R)
        surfaces = [left, right, bottom, top]

    elif opencg_surface._type == 'y-squareprism':
        x0 = opencg_surface._coeffs['x0']
        z0 = opencg_surface._coeffs['z0']
        R = opencg_surface._coeffs['R']

        # Create a list of the four planes we need
        left = opencg.XPlane(name=name, boundary=boundary, x0=x0 - R)
        right = opencg.XPlane(name=name, boundary=boundary, x0=x0 + R)
        bottom = opencg.ZPlane(name=name, boundary=boundary, z0=z0 - R)
        top = opencg.ZPlane(name=name, boundary=boundary, z0=z0 + R)
        surfaces = [left, right, bottom, top]

    elif opencg_surface._type == 'z-squareprism':
        x0 = opencg_surface._coeffs['x0']
        y0 = opencg_surface._coeffs['y0']
        R = opencg_surface._coeffs['R']

        # Create a list of the four planes we need
        left = opencg.XPlane(name=name, boundary=boundary, x0=x0 - R)
        right = opencg.XPlane(name=name, boundary=boundary, x0=x0 + R)
        bottom = opencg.YPlane(name=name, boundary=boundary, y0=y0 - R)
        top = opencg.YPlane(name=name, boundary=boundary, y0=y0 + R)
        surfaces = [left, right, bottom, top]

    else:
        msg = 'Unable to create a compatible OpenMC Surface an OpenCG ' \
              'Surface of type "{0}" since it already a compatible ' \
              'Surface type in OpenMC'.format(opencg_surface._type)
        raise ValueError(msg)

    # Add the OpenMC Surface(s) to the global collection of all OpenMC Surfaces
    OPENMC_SURFACES[surface_id] = surfaces

    # Add the OpenCG Surface to the global collection of all OpenCG Surfaces
    OPENCG_SURFACES[surface_id] = opencg_surface

    return surfaces
コード例 #3
0
def get_opencg_surface(openmc_surface):
    """Return an OpenCG surface corresponding to an OpenMC surface.

    Parameters
    ----------
    openmc_surface : openmc.surface.Surface
        OpenMC surface

    Returns
    -------
    opencg_surface : opencg.Surface
        Equivalent OpenCG surface

    """

    if not isinstance(openmc_surface, openmc.Surface):
        msg = 'Unable to create an OpenCG Surface from "{0}" ' \
              'which is not an OpenMC Surface'.format(openmc_surface)
        raise ValueError(msg)

    global OPENCG_SURFACES
    surface_id = openmc_surface._id

    # If this Material was already created, use it
    if surface_id in OPENCG_SURFACES:
        return OPENCG_SURFACES[surface_id]

    # Create an OpenCG Surface to represent this OpenMC Surface
    name = openmc_surface._name

    # Correct for OpenMC's syntax for Surfaces dividing Cells
    boundary = openmc_surface._boundary_type
    if boundary == 'transmission':
        boundary = 'interface'

    opencg_surface = None

    if openmc_surface._type == 'plane':
        A = openmc_surface._coeffs['A']
        B = openmc_surface._coeffs['B']
        C = openmc_surface._coeffs['C']
        D = openmc_surface._coeffs['D']
        opencg_surface = opencg.Plane(surface_id, name, boundary, A, B, C, D)

    elif openmc_surface._type == 'x-plane':
        x0 = openmc_surface._coeffs['x0']
        opencg_surface = opencg.XPlane(surface_id, name, boundary, x0)

    elif openmc_surface._type == 'y-plane':
        y0 = openmc_surface._coeffs['y0']
        opencg_surface = opencg.YPlane(surface_id, name, boundary, y0)

    elif openmc_surface._type == 'z-plane':
        z0 = openmc_surface._coeffs['z0']
        opencg_surface = opencg.ZPlane(surface_id, name, boundary, z0)

    elif openmc_surface._type == 'x-cylinder':
        y0 = openmc_surface._coeffs['y0']
        z0 = openmc_surface._coeffs['z0']
        R = openmc_surface._coeffs['R']
        opencg_surface = opencg.XCylinder(surface_id, name, boundary, y0, z0,
                                          R)

    elif openmc_surface._type == 'y-cylinder':
        x0 = openmc_surface._coeffs['x0']
        z0 = openmc_surface._coeffs['z0']
        R = openmc_surface._coeffs['R']
        opencg_surface = opencg.YCylinder(surface_id, name, boundary, x0, z0,
                                          R)

    elif openmc_surface._type == 'z-cylinder':
        x0 = openmc_surface._coeffs['x0']
        y0 = openmc_surface._coeffs['y0']
        R = openmc_surface._coeffs['R']
        opencg_surface = opencg.ZCylinder(surface_id, name, boundary, x0, y0,
                                          R)

    # Add the OpenMC Surface to the global collection of all OpenMC Surfaces
    OPENMC_SURFACES[surface_id] = openmc_surface

    # Add the OpenCG Surface to the global collection of all OpenCG Surfaces
    OPENCG_SURFACES[surface_id] = opencg_surface

    return opencg_surface
コード例 #4
0
def get_compatible_opencg_surfaces(opencg_surface):
    """Generate OpenCG surfaces that are compatible with OpenMOC equivalent to
    an OpenCG surface that is not compatible. For example, this method may be
    used to convert a ZSquarePrism OpenCG surface into a collection of
    equivalent XPlane and YPlane OpenCG surfaces.

    Parameters
    ----------
    opencg_surface : opencg.Surface
        OpenCG surface that is incompatible with OpenMOC

    Returns
    -------
    surfaces : list of opencg.Surface
        Collection of surfaces equivalent to the original one but compatible
        with OpenMOC

    """

    cv.check_type('opencg_surface', opencg_surface, opencg.Surface)

    global OPENMOC_SURFACES
    surface_id = opencg_surface.id

    # If this Surface was already created, use it
    if surface_id in OPENMOC_SURFACES:
        return OPENMOC_SURFACES[surface_id]

    # Create an OpenMOC Surface to represent this OpenCG Surface
    name = str(opencg_surface.name)

    # Correct for OpenMOC's syntax for Surfaces dividing Cells
    boundary = opencg_surface.boundary_type

    if opencg_surface.type == 'x-squareprism':
        y0 = opencg_surface.y0
        z0 = opencg_surface.z0
        R = opencg_surface.r

        # Create a list of the four planes we need
        min_y = opencg.YPlane(y0=y0 - R, name=name)
        max_y = opencg.YPlane(y0=y0 + R, name=name)
        min_z = opencg.ZPlane(z0=z0 - R, name=name)
        max_z = opencg.ZPlane(z0=z0 + R, name=name)

        # Set the boundary conditions for each Surface
        min_y.boundary_type = boundary
        max_y.boundary_type = boundary
        min_z.boundary_type = boundary
        max_z.boundary_type = boundary

        surfaces = [min_y, max_y, min_z, max_z]

    elif opencg_surface.type == 'y-squareprism':
        x0 = opencg_surface.x0
        z0 = opencg_surface.z0
        R = opencg_surface.r

        # Create a list of the four planes we need
        min_x = opencg.XPlane(name=name, boundary=boundary, x0=x0 - R)
        max_x = opencg.XPlane(name=name, boundary=boundary, x0=x0 + R)
        min_z = opencg.ZPlane(name=name, boundary=boundary, z0=z0 - R)
        max_z = opencg.ZPlane(name=name, boundary=boundary, z0=z0 + R)

        # Set the boundary conditions for each Surface
        min_x.boundary_type = boundary
        max_x.boundary_type = boundary
        min_z.boundary_type = boundary
        max_z.boundary_type = boundary

        surfaces = [min_x, max_x, min_z, max_z]

    elif opencg_surface.type == 'z-squareprism':
        x0 = opencg_surface.x0
        y0 = opencg_surface.y0
        R = opencg_surface.r

        # Create a list of the four planes we need
        min_x = opencg.XPlane(name=name, boundary=boundary, x0=x0 - R)
        max_x = opencg.XPlane(name=name, boundary=boundary, x0=x0 + R)
        min_y = opencg.YPlane(name=name, boundary=boundary, y0=y0 - R)
        max_y = opencg.YPlane(name=name, boundary=boundary, y0=y0 + R)

        # Set the boundary conditions for each Surface
        min_x.boundary_type = boundary
        max_x.boundary_type = boundary
        min_y.boundary_type = boundary
        max_y.boundary_type = boundary

        surfaces = [min_x, max_x, min_y, max_y]

    else:
        msg = 'Unable to create a compatible OpenMOC Surface an OpenCG ' \
              'Surface of type "{0}" since it already a compatible ' \
              'Surface type in OpenMOC'.format(opencg_surface.type)
        raise ValueError(msg)

    # Add the OpenMOC Surface(s) to global collection of all OpenMOC Surfaces
    OPENMOC_SURFACES[surface_id] = surfaces

    # Add the OpenCG Surface to the global collection of all OpenCG Surfaces
    OPENCG_SURFACES[surface_id] = opencg_surface

    return surfaces
コード例 #5
0
def get_opencg_surface(openmoc_surface):
    """Return an OpenCG surface corresponding to an OpenMOC surface.

    Parameters
    ----------
    openmc_surface : openmoc.Surface
        OpenMOC surface

    Returns
    -------
    opencg_surface : opencg.Surface
        Equivalent OpenCG surface

    """

    cv.check_type('openmoc_surface', openmoc_surface, openmoc.Surface)

    global OPENCG_SURFACES
    surface_id = openmoc_surface.getId()

    # If this Surface was already created, use it
    if surface_id in OPENCG_SURFACES:
        return OPENCG_SURFACES[surface_id]

    # Create an OpenCG Surface to represent this OpenMOC Surface
    name = openmoc_surface.getName()

    # Correct for OpenMOC'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.BOUNDARY_NONE:
        boundary = 'interface'

    opencg_surface = None
    surface_type = openmoc_surface.getSurfaceType()

    if surface_type == openmoc.PLANE:
        openmoc_surface = openmoc.castSurfaceToPlane(openmoc_surface)
        A = openmoc_surface.getA()
        B = openmoc_surface.getB()
        C = openmoc_surface.getC()
        D = openmoc_surface.getD()
        opencg_surface = opencg.Plane(surface_id, name, boundary, A, B, C, D)

    elif surface_type == openmoc.XPLANE:
        openmoc_surface = openmoc.castSurfaceToXPlane(openmoc_surface)
        x0 = openmoc_surface.getX()
        opencg_surface = opencg.XPlane(surface_id, name, boundary, x0)

    elif surface_type == openmoc.YPLANE:
        openmoc_surface = openmoc.castSurfaceToYPlane(openmoc_surface)
        y0 = openmoc_surface.getY()
        opencg_surface = opencg.YPlane(surface_id, name, boundary, y0)

    elif surface_type == openmoc.ZPLANE:
        openmoc_surface = openmoc.castSurfaceToZPlane(openmoc_surface)
        z0 = openmoc_surface.getZ()
        opencg_surface = opencg.ZPlane(surface_id, name, boundary, z0)

    elif surface_type == openmoc.ZCYLINDER:
        openmoc_surface = openmoc.castSurfaceToZCylinder(openmoc_surface)
        x0 = openmoc_surface.getX0()
        y0 = openmoc_surface.getY0()
        R = openmoc_surface.getRadius()
        opencg_surface = opencg.ZCylinder(surface_id, name, boundary, x0, y0,
                                          R)

    # Add the OpenMOC Surface to the global collection of all OpenMOC Surfaces
    OPENMOC_SURFACES[surface_id] = openmoc_surface

    # Add the OpenCG Surface to the global collection of all OpenCG Surfaces
    OPENCG_SURFACES[surface_id] = opencg_surface

    return opencg_surface
コード例 #6
0
def get_opencg_surface(openmc_surface):
    """Return an OpenCG surface corresponding to an OpenMC surface.

    Parameters
    ----------
    openmc_surface : openmc.surface.Surface
        OpenMC surface

    Returns
    -------
    opencg_surface : opencg.Surface
        Equivalent OpenCG 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 OPENCG_SURFACES:
        return OPENCG_SURFACES[surface_id]

    # Create an OpenCG Surface to represent this OpenMC Surface
    name = openmc_surface.name

    # Correct for OpenMC's syntax for Surfaces dividing Cells
    boundary = openmc_surface.boundary_type
    if boundary == 'transmission':
        boundary = 'interface'

    opencg_surface = None

    if openmc_surface.type == 'plane':
        A = openmc_surface.a
        B = openmc_surface.b
        C = openmc_surface.c
        D = openmc_surface.d
        opencg_surface = opencg.Plane(surface_id, name, boundary, A, B, C, D)

    elif openmc_surface.type == 'x-plane':
        x0 = openmc_surface.x0
        opencg_surface = opencg.XPlane(surface_id, name, boundary, x0)

    elif openmc_surface.type == 'y-plane':
        y0 = openmc_surface.y0
        opencg_surface = opencg.YPlane(surface_id, name, boundary, y0)

    elif openmc_surface.type == 'z-plane':
        z0 = openmc_surface.z0
        opencg_surface = opencg.ZPlane(surface_id, name, boundary, z0)

    elif openmc_surface.type == 'x-cylinder':
        y0 = openmc_surface.y0
        z0 = openmc_surface.z0
        R = openmc_surface.r
        opencg_surface = opencg.XCylinder(surface_id, name, boundary, y0, z0,
                                          R)

    elif openmc_surface.type == 'y-cylinder':
        x0 = openmc_surface.x0
        z0 = openmc_surface.z0
        R = openmc_surface.r
        opencg_surface = opencg.YCylinder(surface_id, name, boundary, x0, z0,
                                          R)

    elif openmc_surface.type == 'z-cylinder':
        x0 = openmc_surface.x0
        y0 = openmc_surface.y0
        R = openmc_surface.r
        opencg_surface = opencg.ZCylinder(surface_id, name, boundary, x0, y0,
                                          R)

    # Add the OpenMC Surface to the global collection of all OpenMC Surfaces
    OPENMC_SURFACES[surface_id] = openmc_surface

    # Add the OpenCG Surface to the global collection of all OpenCG Surfaces
    OPENCG_SURFACES[surface_id] = opencg_surface

    return opencg_surface
コード例 #7
0
def get_opencg_surface(openmoc_surface):

    if not isinstance(openmoc_surface, openmoc.Surface):
        msg = 'Unable to create an OpenCG Surface from {0} ' \
              'which is not an OpenMOC Surface'.format(openmoc_surface)
        raise ValueError(msg)

    global OPENCG_SURFACES
    surface_id = openmoc_surface.getId()

    # If this Surface was already created, use it
    if surface_id in OPENCG_SURFACES:
        return OPENCG_SURFACES[surface_id]

    # Create an OpenCG Surface to represent this OpenMOC Surface
    name = openmoc_surface.getName()

    # Correct for OpenMOC'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.BOUNDARY_NONE:
        boundary = 'interface'

    opencg_surface = None

    surface_type = openmoc_surface.getSurfaceType()

    if surface_type == openmoc.PLANE:
        openmoc_surface = openmoc.castSurfaceToPlane(openmoc_surface)
        A = openmoc_surface.getA()
        B = openmoc_surface.getB()
        C = openmoc_surface.getC()
        opencg_surface = opencg.Plane(surface_id, name, boundary, A, B, 0, C)

    elif surface_type == openmoc.XPLANE:
        openmoc_surface = openmoc.castSurfaceToXPlane(openmoc_surface)
        x0 = openmoc_surface.getX()
        opencg_surface = opencg.XPlane(surface_id, name, boundary, x0)

    elif surface_type == openmoc.YPLANE:
        openmoc_surface = openmoc.castSurfaceToYPlane(openmoc_surface)
        y0 = openmoc_surface.getY()
        opencg_surface = opencg.YPlane(surface_id, name, boundary, y0)

    elif surface_type == openmoc.ZPLANE:
        openmoc_surface = openmoc.castSurfaceToZPlane(openmoc_surface)
        z0 = openmoc_surface.getZ()
        opencg_surface = opencg.ZPlane(surface_id, name, boundary, z0)

    elif surface_type == openmoc.ZYCLINDER:
        openmoc_surface = openmoc.castSurfaceToZCylinder(openmoc_surface)
        x0 = openmoc_surface.getX0()
        y0 = openmoc_surface.getY0()
        R = openmoc_surface.getRadius()
        opencg_surface = opencg.ZCylinder(surface_id, name, boundary, x0, y0,
                                          R)

    # Add the OpenMOC Surface to the global collection of all OpenMOC Surfaces
    OPENMOC_SURFACES[surface_id] = openmoc_surface

    # Add the OpenCG Surface to the global collection of all OpenCG Surfaces
    OPENCG_SURFACES[surface_id] = opencg_surface

    return opencg_surface
コード例 #8
0
materials_file.default_xs = '71c'

# Export to "materials.xml"
materials_file.export_to_xml()

# Get OpenCG versions of each OpenMC material to fill OpenCG Cells below
opencg_fuel = openmc.opencg_compatible.get_opencg_material(fuel)
opencg_clad = openmc.opencg_compatible.get_opencg_material(clad)
opencg_water = openmc.opencg_compatible.get_opencg_material(water)

###############################################################################
#                 Exporting to OpenMC geometry.xml File
###############################################################################

# Create bounding surfaces
min_x = opencg.XPlane(boundary='reflective', x0=0.0)
max_x = opencg.XPlane(boundary='reflective', x0=5.0)
min_y = opencg.YPlane(boundary='reflective', y0=0.0)
max_y = opencg.YPlane(boundary='reflective', y0=10.0)
min_z = opencg.ZPlane(boundary='reflective', z0=0.0)
max_z = opencg.ZPlane(boundary='reflective', z0=10.0)

# Create material interfacial surfaces
left = opencg.XPlane(surface_id=1, boundary='interface', x0=2.0)
right = opencg.XPlane(surface_id=2, boundary='interface', x0=2.4)

# Create a Universe to encapsulate the 1D slab
slab_universe = opencg.Universe(name='1D slab')

# Create fuel Cell
fuel_cell = opencg.Cell(name='fuel')