Ejemplo n.º 1
0
    def _parse_statepoint(self, statepoint, tally_id=1):
        """Parses a statepoint file and reads in the relevant fluxes, assigns them
        to the DataSources or the XSCache, and returns k, phi_g, and E_g.

        Parameters
        ----------
        statepoint : xsgen.statepoint.StatePoint
            An OpenMC StatePoint.
        tally_id : int
            The tally id we wish to read group flux from.

        Returns
        -------
        k : float
            Neutron multiplication factor.
        phi_g : list of floats
            Group flux.
        e_g : list of floats
            Group structure.
        """
        sp = StatePoint(statepoint)
        sp.read_results()
        # compute group fluxes for data sources
        for tally, ds in zip(sp.tallies[1:3], (self.eafds, self.omcds)):
            ds.src_phi_g = tally.results[::-1, :, 0].flatten()
            ds.src_phi_g /= ds.src_phi_g.sum()
        # compute return values
        k, kerr = sp.k_combined
        tally = sp.tallies[tally_id - 1]
        phi_g = tally.results[::-1, :, 0].flatten()
        phi_g /= phi_g.sum()
        e_g = tally.filters["energyin"].bins

        return k, phi_g, e_g
Ejemplo n.º 2
0
 def _parse_statepoint(self, statepoint):
     """Parses a statepoint file and reads in the relevant fluxes, assigns them 
     to the DataSources or the XSCache, and returns k and phi_g.
     """
     sp = StatePoint(statepoint)
     sp.read_results()
     # compute group fluxes for data sources
     for tally, ds in zip(sp.tallies[1:4], (self.cinderds, self.eafds, self.omcds)):
         ds.src_phi_g = tally.results[::-1, :, 0].flatten()
         ds.src_phi_g /= ds.src_phi_g.sum()
     # compute return values
     k, kerr = sp.k_combined
     t_flux = sp.tallies[0]
     phi_g = t_flux.results[::-1, :, 0].flatten()
     phi_g /= phi_g.sum()
     return k, phi_g
Ejemplo n.º 3
0
import numpy as np
import scipy.stats
import matplotlib.pyplot as plt

from statepoint import StatePoint

# Get filename
filename = argv[1]

# Determine axial level
axial_level = int(argv[2]) if len(argv) > 2 else 1
score = int(argv[3]) if len(argv) > 3 else 1

# Create StatePoint object
sp = StatePoint(filename)

# Read number of realizations for global tallies
sp.n_realizations = sp._get_int()[0]

# Read global tallies
n_global_tallies = sp._get_int()[0]
sp.global_tallies = np.array(sp._get_double(2 * n_global_tallies))
sp.global_tallies.shape = (n_global_tallies, 2)

# Flag indicating if tallies are present
tallies_present = sp._get_int()[0]

# Check if tallies are present
if not tallies_present:
    raise Exception("No tally data in state point!")
Ejemplo n.º 4
0
import numpy as np
import scipy.stats
import matplotlib.pyplot as plt

from statepoint import StatePoint

# Get filename
filename = argv[1]

# Determine axial level
axial_level = int(argv[2]) if len(argv) > 2 else 1
score = int(argv[3]) if len(argv) > 3 else 1

# Create StatePoint object
sp = StatePoint(filename)

# Read number of realizations for global tallies
sp.n_realizations = sp._get_int()[0]

# Read global tallies
n_global_tallies = sp._get_int()[0]
sp.global_tallies = np.array(sp._get_double(2*n_global_tallies))
sp.global_tallies.shape = (n_global_tallies, 2)

# Flag indicating if tallies are present
tallies_present = sp._get_int()[0]

# Check if tallies are present
if not tallies_present:
    raise Exception("No tally data in state point!")
Ejemplo n.º 5
0
assemblies = ['Fuel-1.6wo-CRD', \
              'Fuel-2.4wo-16BA-grid-56', \
              'Fuel-3.1wo-instr-16BA-grid-17']

# Loop over assemblies
for assembly in assemblies:

    print 'Exporting ' + assembly

    # Create an HDF5 group for this assembly in our 'targets.h5' file
    assembly_group = f.create_group(assembly)
    high_energy = assembly_group.create_group('High Energy')
    low_energy = assembly_group.create_group('Low Energy')

    # Import the OpenMC results for this assembly
    sp = StatePoint('../openmc-input/'+assembly+'/pinwise/statepoint.1250.h5')
    sp.read_results()

    # Extract 2D numpy arrays of the batch means for each type of tally
    flux = sp.extract_results(1, 'flux')['mean']
    tot_rxn_rate = sp.extract_results(1, 'total')['mean']
    abs_rxn_rate = sp.extract_results(1, 'absorption')['mean']
    fiss_rxn_rate = sp.extract_results(1, 'fission')['mean']
    nufiss_rxn_rate = sp.extract_results(1, 'nu-fission')['mean']

    # Reshape to grid with energy group as third index
    flux = np.reshape(flux, (x, y, groups))
    tot_rxn_rate = np.reshape(tot_rxn_rate, (x, y, groups))
    abs_rxn_rate = np.reshape(abs_rxn_rate, (x, y, groups))
    fiss_rxn_rate = np.reshape(fiss_rxn_rate, (x, y, groups))
    nufiss_rxn_rate = np.reshape(nufiss_rxn_rate, (x, y, groups))
Ejemplo n.º 6
0
def main(file_, o):
  """Main program"""

  sp = StatePoint(file_)
  sp.read_results()

  validate_options(sp, o)

  if o.list:
    print_available(sp)
    return

  if o.vtk:
    if not o.output[-4:] == ".vtm": o.output += ".vtm"
  else:
    if not o.output[-5:] == ".silo": o.output += ".silo"

  if o.vtk:
    try:
      import vtk
    except:
      print('The vtk python bindings do not appear to be installed properly.\n'
            'On Ubuntu: sudo apt-get install python-vtk\n'
            'See: http://www.vtk.org/')
      return
  else:
    try:
      import silomesh
    except:
      print('The silomesh package does not appear to be installed properly.\n'
            'See: https://github.com/nhorelik/silomesh/')
      return

  if o.vtk:
    blocks = vtk.vtkMultiBlockDataSet()
    blocks.SetNumberOfBlocks(5)
    block_idx = 0
  else:
    silomesh.init_silo(o.output)

  # Tally loop #################################################################
  for tally in sp.tallies:

    # skip non-mesh tallies or non-user-specified tallies
    if o.tallies and not tally.id in o.tallies: continue
    if not 'mesh' in tally.filters: continue

    print("Processing Tally {}...".format(tally.id))

    # extract filter options and mesh parameters for this tally
    filtercombos = get_filter_combos(tally)
    meshparms = get_mesh_parms(sp, tally)
    nx,ny,nz = meshparms[:3]
    ll = meshparms[3:6]
    ur = meshparms[6:9]

    if o.vtk:
      ww = [(u-l)/n for u,l,n in zip(ur,ll,(nx,ny,nz))]
      grid = grid = vtk.vtkImageData()
      grid.SetDimensions(nx+1,ny+1,nz+1)
      grid.SetOrigin(*ll)
      grid.SetSpacing(*ww)
    else:
      silomesh.init_mesh('Tally_{}'.format(tally.id), *meshparms)

    # Score loop ###############################################################
    for sid,score in enumerate(tally.scores):

      # skip non-user-specified scrores for this tally
      if o.scores and tally.id in o.scores and not sid in o.scores[tally.id]:
        continue

      # Filter loop ############################################################
      for filterspec in filtercombos:

        # skip non-user-specified filter bins
        skip = False
        if o.filters and tally.id in o.filters:
          for filter_,bin in filterspec[1:]:
            if filter_ in o.filters[tally.id] and \
               not bin in o.filters[tally.id][filter_]:
              skip = True
              break
        if skip: continue

        # find and sanitize the variable name for this score
        varname = get_sanitized_filterspec_name(tally, score, filterspec)
        if o.vtk:
          vtkdata = vtk.vtkDoubleArray()
          vtkdata.SetName(varname)
          dataforvtk = {}
        else:
          silomesh.init_var(varname)

        lbl = "\t Score {}.{} {}:\t\t{}".format(tally.id, sid+1, score, varname)

        # Mesh fill loop #######################################################
        for x in range(1,nx+1):
          sys.stdout.write(lbl+" {0}%\r".format(int(x/nx*100)))
          sys.stdout.flush()
          for y in range(1,ny+1):
            for z in range(1,nz+1):
              filterspec[0][1] = (x,y,z)
              val = sp.get_value(tally.id-1, filterspec, sid)[o.valerr]
              if o.vtk:
                # vtk cells go z, y, x, so we store it now and enter it later
                i = (z-1)*nx*ny + (y-1)*nx + x-1
                dataforvtk[i] = float(val)
              else:
                silomesh.set_value(float(val), x, y, z)

        # end mesh fill loop
        print()
        if o.vtk:
          for i in range(nx*ny*nz):
            vtkdata.InsertNextValue(dataforvtk[i])
          grid.GetCellData().AddArray(vtkdata)
          del vtkdata

        else:
          silomesh.finalize_var()

      # end filter loop

    # end score loop
    if o.vtk:
      blocks.SetBlock(block_idx, grid)
      block_idx += 1
    else:
      silomesh.finalize_mesh()

  # end tally loop
  if o.vtk:
    writer = vtk.vtkXMLMultiBlockDataWriter()
    writer.SetFileName(o.output)
    writer.SetInput(blocks)
    writer.Write()
  else:
    silomesh.finalize_silo()
Ejemplo n.º 7
0
#!/usr/bin/env python

from sys import argv
from math import sqrt

import numpy as np
import scipy.stats
import matplotlib
import matplotlib.pyplot as plt

from statepoint import StatePoint

# Create StatePoint object
sp1 = StatePoint('without-ufs.state')
sp2 = StatePoint('with-ufs.state')

sp1._get_int()
sp2._get_int()

# Calculate t-value for 95% two-sided CI
n = sp1.current_batch - sp1.n_inactive
t_value = scipy.stats.t.ppf(0.975, n - 1)

################################ WITHOUT UFS ###################################
for t in sp1.tallies:
    n_bins = t.n_score_bins * t.n_filter_bins
    i_mesh = [f.type for f in t.filters].index('mesh')

    # Get Mesh object
    m = sp1.meshes[t.filters[i_mesh].bins[0] - 1]
    nx, ny, nz = m.dimension
Ejemplo n.º 8
0
#!/usr/bin/env python

from sys import argv
from math import sqrt

import scipy.stats
import matplotlib.pyplot as plt
import numpy as np

from statepoint import StatePoint

# Create StatePoint object
sp1 = StatePoint('without-ufs.state')
sp2 = StatePoint('with-ufs.state')

# Calculate t-value for 95% two-sided CI
n = sp1.current_batch - sp1.n_inactive
t_value = scipy.stats.t.ppf(0.975, n - 1)

# Get uncertainties for without UFS
sp1.read_values()
unc1 = []
for s, s2 in sp1.tallies[0].values[:,0,:]:
    s /= n
    if s != 0.0:
        relative_error = t_value*sqrt((s2/n - s*s)/(n-1))/s
        unc1.append(relative_error)

# Get uncertainties for with UFS
sp2.read_values()
unc2 = []
Ejemplo n.º 9
0
def main(file_, o):
    """Main program"""

    sp = StatePoint(file_)
    sp.read_results()

    validate_options(sp, o)

    if o.list:
        print_available(sp)
        return

    silomesh.init_silo(o.output)

    # Tally loop #################################################################
    for tally in sp.tallies:

        # skip non-mesh tallies or non-user-specified tallies
        if o.tallies and not tally.id in o.tallies: continue
        if not 'mesh' in tally.filters: continue

        print "Processing Tally {}...".format(tally.id)

        # extract filter options and mesh parameters for this tally
        filtercombos = get_filter_combos(tally)
        meshparms = get_mesh_parms(sp, tally)
        nx, ny, nz = meshparms[0], meshparms[1], meshparms[2]
        silomesh.init_mesh('Tally_{}'.format(tally.id), *meshparms)

        # Score loop ###############################################################
        for sid, score in enumerate(tally.scores):

            # skip non-user-specified scrores for this tally
            if o.scores and tally.id in o.scores and not sid in o.scores[
                    tally.id]:
                continue

            # Filter loop ############################################################
            for filterspec in filtercombos:

                # skip non-user-specified filter bins
                skip = False
                if o.filters and tally.id in o.filters:
                    for filter_, bin in filterspec[1:]:
                        if filter_ in o.filters[tally.id] and \
                           not bin in o.filters[tally.id][filter_]:
                            skip = True
                            break
                if skip: continue

                # find and sanitize the variable name for this score
                varname = get_sanitized_filterspec_name(
                    tally, score, filterspec)
                silomesh.init_var(varname)

                print "\t Score {}.{} {}:\t\t{}".format(
                    tally.id, sid + 1, score, varname)

                # Mesh fill loop #######################################################
                for x in range(1, nx + 1):
                    for y in range(1, ny + 1):
                        for z in range(1, nz + 1):
                            filterspec[0][1] = (x, y, z)
                            val = sp.get_value(tally.id - 1, filterspec,
                                               sid)[o.valerr]
                            silomesh.set_value(float(val), x, y, z)

                # end mesh fill loop
                silomesh.finalize_var()

            # end filter loop

        # end score loop
        silomesh.finalize_mesh()

    # end tally loop
    silomesh.finalize_silo()
Ejemplo n.º 10
0
#!/usr/bin/env python

from sys import argv
from math import sqrt

import numpy as np
import scipy.stats
import matplotlib
import matplotlib.pyplot as plt

from statepoint import StatePoint

# Create StatePoint object
sp1 = StatePoint('without-ufs.state')
sp2 = StatePoint('with-ufs.state')

sp1._get_int()
sp2._get_int()

# Calculate t-value for 95% two-sided CI
n = sp1.current_batch - sp1.n_inactive
t_value = scipy.stats.t.ppf(0.975, n - 1)

################################ WITHOUT UFS ###################################
for t in sp1.tallies:
    n_bins = t.n_score_bins * t.n_filter_bins
    i_mesh = [f.type for f in t.filters].index('mesh')

    # Get Mesh object
    m = sp1.meshes[t.filters[i_mesh].bins[0] - 1]
    nx, ny, nz = m.dimension
Ejemplo n.º 11
0
#!/usr/bin/env python

import sys

from numpy.testing import assert_allclose, assert_equal

from statepoint import StatePoint

if len(sys.argv) > 2:
    path1 = sys.argv[1]
    path2 = sys.argv[2]
else:
    raise

# Create StatePoint objects
sp1 = StatePoint(path1)
sp2 = StatePoint(path2)

# Read tally results
sp1.read_results()
sp2.read_results()

# Compare header information
assert sp1.revision == sp2.revision
assert sp1.version == sp2.version
assert sp1.seed == sp2.seed
assert sp1.run_mode == sp2.run_mode
assert sp1.n_particles == sp2.n_particles
assert sp1.n_batches == sp2.n_batches

if sp1.run_mode == 2:
Ejemplo n.º 12
0
def main(file_, o):
  """Main program"""
  
  sp = StatePoint(file_)
  sp.read_results()

  validate_options(sp, o)
  
  if o.list:
    print_available(sp)
    return

  silomesh.init_silo(o.output)

  # Tally loop #################################################################
  for tally in sp.tallies:
  
    # skip non-mesh tallies or non-user-specified tallies
    if o.tallies and not tally.id in o.tallies: continue
    if not 'mesh' in tally.filters: continue
    
    print "Processing Tally {}...".format(tally.id)
    
    # extract filter options and mesh parameters for this tally
    filtercombos = get_filter_combos(tally)
    meshparms = get_mesh_parms(sp, tally)
    nx,ny,nz = meshparms[0], meshparms[1], meshparms[2]
    silomesh.init_mesh('Tally_{}'.format(tally.id), *meshparms)
    
    # Score loop ###############################################################
    for sid,score in enumerate(tally.scores):
    
      # skip non-user-specified scrores for this tally
      if o.scores and tally.id in o.scores and not sid in o.scores[tally.id]:
        continue
      
      # Filter loop ############################################################
      for filterspec in filtercombos:
        
        # skip non-user-specified filter bins
        skip = False
        if o.filters and tally.id in o.filters:
          for filter_,bin in filterspec[1:]:
            if filter_ in o.filters[tally.id] and \
               not bin in o.filters[tally.id][filter_]:
              skip = True
              break
        if skip: continue
        
        # find and sanitize the variable name for this score
        varname = get_sanitized_filterspec_name(tally, score, filterspec)
        silomesh.init_var(varname)
        
        print "\t Score {}.{} {}:\t\t{}".format(tally.id, sid+1, score, varname)
        
        # Mesh fill loop #######################################################
        for x in range(1,nx+1):
          for y in range(1,ny+1):
            for z in range(1,nz+1):
              filterspec[0][1] = (x,y,z)
              val = sp.get_value(tally.id-1, filterspec, sid)[o.valerr]
              silomesh.set_value(float(val), x, y, z)
              
        # end mesh fill loop
        silomesh.finalize_var()
        
      # end filter loop
      
    # end score loop
    silomesh.finalize_mesh()
    
  # end tally loop
  silomesh.finalize_silo()
Ejemplo n.º 13
0
# energy options are 1 or 2
energy = 2         
num_groups = 2

# Mesh is 17x17 or 51x51
mesh_x_dim = 17
mesh_y_dim = 17


################################################################################
# Create plot of initial data to start animation
################################################################################

# Instantiate statepoint for the first batch of tally data
print directory + 'statepoint.' + str(batch_start) + '.h5'
sp = StatePoint(directory + 'statepoint.' + str(batch_start) + '.h5')
sp.read_results()
tallyid = 1
tally1_data = sp.extract_results(tallyid, score1)
tally2_data = sp.extract_results(tallyid, score2)

tally1_means = tally1_data['mean']
tally1_std_dev = np.nan_to_num(tally1_data['CI95'])
tally2_means = tally2_data['mean']
tally2_std_dev = np.nan_to_num(tally2_data['CI95'])

# Reshape to grid with energy as third index
tally1_means = np.reshape(tally1_means,(mesh_x_dim, mesh_y_dim, num_groups))
tally1_std_dev = np.reshape(tally1_std_dev,(mesh_x_dim, mesh_y_dim, num_groups))
tally2_means = np.reshape(tally2_means,(mesh_x_dim, mesh_y_dim, num_groups))
tally2_std_dev = np.reshape(tally2_std_dev,(mesh_x_dim, mesh_y_dim, num_groups))
Ejemplo n.º 14
0
#!/usr/bin/env python

from sys import argv
from math import sqrt

import scipy.stats
import matplotlib.pyplot as plt
import numpy as np

from statepoint import StatePoint

# Create StatePoint object
sp1 = StatePoint('without-ufs.state')
sp2 = StatePoint('with-ufs.state')

# Calculate t-value for 95% two-sided CI
n = sp1.current_batch - sp1.n_inactive
t_value = scipy.stats.t.ppf(0.975, n - 1)

# Get uncertainties for without UFS
sp1.read_values()
unc1 = []
for s, s2 in sp1.tallies[0].values[:, 0, :]:
    s /= n
    if s != 0.0:
        relative_error = t_value * sqrt((s2 / n - s * s) / (n - 1)) / s
        unc1.append(relative_error)

# Get uncertainties for with UFS
sp2.read_values()
unc2 = []