Пример #1
0
def get_opencg_cell(openmc_cell):
    """Return an OpenCG cell corresponding to an OpenMC cell.

    Parameters
    ----------
    openmc_cell : openmc.universe.Cell
        OpenMC cell

    Returns
    -------
    opencg_cell : opencg.Cell
        Equivalent OpenCG cell

    """

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

    global OPENCG_CELLS
    cell_id = openmc_cell._id

    # If this Cell was already created, use it
    if cell_id in OPENCG_CELLS:
        return OPENCG_CELLS[cell_id]

    # Create an OpenCG Cell to represent this OpenMC Cell
    name = openmc_cell._name
    opencg_cell = opencg.Cell(cell_id, name)

    fill = openmc_cell._fill

    if (openmc_cell._type == 'normal'):
        opencg_cell.setFill(get_opencg_material(fill))
    elif (openmc_cell._type == 'fill'):
        opencg_cell.setFill(get_opencg_universe(fill))
    else:
        opencg_cell.setFill(get_opencg_lattice(fill))

    if openmc_cell._rotation is not None:
        opencg_cell.setRotation(openmc_cell._rotation)

    if openmc_cell._translation is not None:
        opencg_cell.setTranslation(openmc_cell._translation)

    surfaces = openmc_cell._surfaces

    for surface_id in surfaces:
        surface = surfaces[surface_id][0]
        halfspace = surfaces[surface_id][1]
        opencg_cell.addSurface(get_opencg_surface(surface), halfspace)

    # Add the OpenMC Cell to the global collection of all OpenMC Cells
    OPENMC_CELLS[cell_id] = openmc_cell

    # Add the OpenCG Cell to the global collection of all OpenCG Cells
    OPENCG_CELLS[cell_id] = opencg_cell

    return opencg_cell
Пример #2
0
def get_opencg_cell(openmoc_cell):
    """Return an OpenCG cell corresponding to an OpenMOC cell.

    Parameters
    ----------
    openmoc_cell : openmoc.Cell
        OpenMOC cell

    Returns
    -------
    opencg_cell : opencg.Cell
        Equivalent OpenCG cell

    """

    cv.check_type('openmoc_cell', openmoc_cell, openmoc.Cell)

    global OPENCG_CELLS
    cell_id = openmoc_cell.getId()

    # If this Cell was already created, use it
    if cell_id in OPENCG_CELLS:
        return OPENCG_CELLS[cell_id]

    # Create an OpenCG Cell to represent this OpenMOC Cell
    name = openmoc_cell.getName()
    opencg_cell = opencg.Cell(cell_id, name)

    if (openmoc_cell.getType() == openmoc.MATERIAL):
        fill = openmoc_cell.getFillMaterial()
        opencg_cell.fill = get_opencg_material(fill)
    elif (openmoc_cell.getType() == openmoc.FILL):
        fill = openmoc_cell.getFillUniverse()
        if isinstance(fill, openmoc.Lattice):
            opencg_cell.fill = get_opencg_lattice(fill)
        else:
            opencg_cell.fill = get_opencg_universe(fill)

    if openmoc_cell.isRotated():
        rotation = openmoc_cell.getRotation(3)
        opencg_cell.rotation = rotation
    if openmoc_cell.isTranslated():
        translation = openmoc_cell.getTranslation(3)
        opencg_cell.translation = translation

    surfaces = openmoc_cell.getSurfaces()

    for surf_id, surface_halfspace in surfaces.items():
        halfspace = surface_halfspace._halfspace
        surface = surface_halfspace._surface
        opencg_cell.add_surface(get_opencg_surface(surface), halfspace)

    # Add the OpenMOC Cell to the global collection of all OpenMOC Cells
    OPENMOC_CELLS[cell_id] = openmoc_cell

    # Add the OpenCG Cell to the global collection of all OpenCG Cells
    OPENCG_CELLS[cell_id] = opencg_cell

    return opencg_cell
Пример #3
0
def get_opencg_cell(openmoc_cell):

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

  global OPENCG_CELLS
  cell_id = openmoc_cell.getId()

  # If this Cell was already created, use it
  if cell_id in OPENCG_CELLS:
    return OPENCG_CELLS[cell_id]

  # Create an OpenCG Cell to represent this OpenMOC Cell
  name = openmoc_cell.getName()
  opencg_cell = opencg.Cell(cell_id, name)

  if (openmoc_cell.getType() == openmoc.MATERIAL):
    fill = openmoc.castCellToCellBasic(openmoc_cell).getMaterial()
    opencg_cell.setFill(get_opencg_material(fill))
  elif (openmoc_cell.getType() == openmoc.FILL):
    fill = openmoc.castCellToCellFill(openmoc_cell).getFill()
    if isinstance(fill, openmoc.Lattice):
      opencg_cell.setFill(get_opencg_lattice(fill))
    else:
      opencg_cell.setFill(get_opencg_universe(fill))

  surfaces = openmoc_cell.getSurfaces()

  for surf_id, surface_halfspace in surfaces.items():
    halfspace = surface_halfspace._halfspace
    surface = surface_halfspace._surface
    opencg_cell.addSurface(get_opencg_surface(surface), halfspace)

  # Add the OpenMOC Cell to the global collection of all OpenMOC Cells
  OPENMOC_CELLS[cell_id] = openmoc_cell

  # Add the OpenCG Cell to the global collection of all OpenCG Cells
  OPENCG_CELLS[cell_id] = opencg_cell

  return opencg_cell
Пример #4
0
def get_opencg_cell(openmc_cell):
    """Return an OpenCG cell corresponding to an OpenMC cell.

    Parameters
    ----------
    openmc_cell : openmc.universe.Cell
        OpenMC cell

    Returns
    -------
    opencg_cell : opencg.Cell
        Equivalent OpenCG cell

    """

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

    global OPENCG_CELLS
    cell_id = openmc_cell.id

    # If this Cell was already created, use it
    if cell_id in OPENCG_CELLS:
        return OPENCG_CELLS[cell_id]

    # Create an OpenCG Cell to represent this OpenMC Cell
    name = openmc_cell.name
    opencg_cell = opencg.Cell(cell_id, name)

    fill = openmc_cell.fill

    if (openmc_cell.fill_type == 'material'):
        opencg_cell.fill = get_opencg_material(fill)
    elif (openmc_cell.fill_type == 'universe'):
        opencg_cell.fill = get_opencg_universe(fill)
    else:
        opencg_cell.fill = get_opencg_lattice(fill)

    if openmc_cell.rotation is not None:
        opencg_cell.rotation = openmc_cell.rotation

    if openmc_cell.translation is not None:
        opencg_cell.translation = openmc_cell.translation

    # Add surfaces to OpenCG 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, Halfspace):
            surface = region.surface
            halfspace = -1 if region.side == '-' else 1
            opencg_cell.add_surface(get_opencg_surface(surface), halfspace)
        elif isinstance(region, Intersection):
            for node in region.nodes:
                if not isinstance(node, Halfspace):
                    raise NotImplementedError("Complex cells not yet "
                                              "supported in OpenCG.")
                surface = node.surface
                halfspace = -1 if node.side == '-' else 1
                opencg_cell.add_surface(get_opencg_surface(surface), halfspace)
        else:
            raise NotImplementedError("Complex cells not yet supported "
                                      "in OpenCG.")

    # Add the OpenMC Cell to the global collection of all OpenMC Cells
    OPENMC_CELLS[cell_id] = openmc_cell

    # Add the OpenCG Cell to the global collection of all OpenCG Cells
    OPENCG_CELLS[cell_id] = opencg_cell

    return opencg_cell
Пример #5
0
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')
fuel_cell.fill = opencg_fuel
fuel_cell.add_surface(halfspace=+1, surface=min_x)
fuel_cell.add_surface(halfspace=-1, surface=left)
slab_universe.add_cell(fuel_cell)

# Create clad Cell
clad_cell = opencg.Cell(name='clad')
clad_cell.fill = opencg_clad
clad_cell.add_surface(halfspace=+1, surface=left)
clad_cell.add_surface(halfspace=-1, surface=right)
slab_universe.add_cell(clad_cell)

# Create water Cell
water_cell = opencg.Cell(name='water')
water_cell.fill = opencg_water