Пример #1
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()
Пример #2
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()
Пример #3
0
def main():

    print "Loading statepoint..."
    sp = statepoint.StatePoint('statepoint.300.binary')

    print "Parsing statepoint..."
    sp.read_results()

    print "\nAvailable Tallies:"
    for tally in sp.tallies:
        print "\tTally {}".format(tally.id)
        print "\t\tscores: {}".format(" ".join(tally.scores))
        print "\t\tfilters: {}".format(" ".join(tally.filters.keys()))
    

    ## Loop through the mesh for tally 1 and create plots
    print "Extracting Mesh Values from Tally 1..."

    tallyid = 0     # tally 1
    score = 0       # flux is zero see (order of tally.filters.keys())

    # get mesh dimensions
    meshid = sp.tallies[tallyid].filters['mesh'].bins[0]
    for i,m in enumerate(sp.meshes):
        if m.id == meshid:
          mesh = m
    nx,ny,nz = mesh.dimension

    # loop through mesh and extract values
    thermal = {}
    fast = {}
    for x in range(1,nx+1):
        for y in range(1,ny+1):
            for z in range(1,nz+1):
                val,err = sp.get_value(tallyid,
                                       [('mesh',(x,y,z)),('energyin',0)],
                                       score)
                thermal[(x,y,z)] = val
                val,err = sp.get_value(tallyid,
                                       [('mesh',(x,y,z)),('energyin',1)],
                                       score)
                fast[(x,y,z)] = val

    # write gnuplot datafile with axially-integrated values
    print "Making gnuplots ..."
    with open('meshdata.dat','w') as fh:
        for x in range(1,nx+1):
            for y in range(1,ny+1):
                thermalval = 0.
                fastval = 0.
                for z in range(1,nz+1):
                  thermalval += thermal[(x,y,z)]
                  fastval += fast[(x,y,z)]
                fh.write("{} {} {} {}\n".format(x,y,thermalval,fastval))
                
    # write gnuplot file and make plots
    with open('tmp.gnuplot','w') as fh:
      fh.write(r"""set terminal png size 800,400
set output 'fluxplot.png'
set nokey
set autoscale fix
set multiplot layout 1,2 title "Pin Mesh Axially-Integrated Flux Tally"
set title "Thermal"
plot 'meshdata.dat' using 1:2:3 with image
set title "Fast"
plot 'meshdata.dat' using 1:2:4 with image
""")
    os.system("gnuplot < tmp.gnuplot")
  
    # make 3d silo file
    print "Making 3D SILO File ..."
    sm.init_silo("fluxtally.silo")
    sm.init_mesh('tally_mesh',nx,ny,nz,
                          -85.8774, -85.8774, -81.662, # lower left of mesh
                          1.63576,1.63576,8.1662)      # width of mesh cells
    sm.init_var('flux_tally_thermal')
    for x in range(1,nx+1):
      for y in range(1,ny+1):
          for z in range(1,nz+1):
            sm.set_value(float(thermal[(x,y,z)]),x,y,z)
    sm.finalize_var()
    sm.init_var('flux_tally_fast')
    for x in range(1,nx+1):
      for y in range(1,ny+1):
          for z in range(1,nz+1):
              sm.set_value(float(fast[(x,y,z)]),x,y,z)
    sm.finalize_var()
    sm.finalize_mesh()
    sm.finalize_silo()
Пример #4
0
#!/usr/bin/env python

import silomesh as sm

silo_filename = 'test.silo'
xdim,ydim,zdim = (50, 50, 50)             # dimension of mesh in each direction
lowx,lowy,lowz = (0.0, 0.0, 0.0)          # lower left point of mesh
highx,highy,highz = (50.0, 100.0, 300.0)  # upper right point of mesh

sm.init_silo(silo_filename)
sm.init_mesh('meshname1',xdim,ydim,zdim,lowx,lowy,lowz,highx,highy,highz)

sm.init_var('x')
for x in range(xdim):
  for y in range(ydim):
    for z in range(zdim):
      sm.set_value(float(x+1),x+1,y+1,z+1)
sm.finalize_var()

sm.init_var('y')
for x in range(xdim):
  for y in range(ydim):
    for z in range(zdim):
      sm.set_value(float(y+1),x+1,y+1,z+1)
sm.finalize_var()

sm.init_var('z')
for x in range(xdim):
  for y in range(ydim):
    for z in range(zdim):
      sm.set_value(float(z+1),x+1,y+1,z+1)
Пример #5
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()
Пример #6
0
def main():

    print "Loading statepoint..."
    sp = statepoint.StatePoint('statepoint.300.binary')

    print "Parsing statepoint..."
    sp.read_results()

    print "\nAvailable Tallies:"
    for tally in sp.tallies:
        print "\tTally {}".format(tally.id)
        print "\t\tscores: {}".format(" ".join(tally.scores))
        print "\t\tfilters: {}".format(" ".join(tally.filters.keys()))

    ## Loop through the mesh for tally 1 and create plots
    print "Extracting Mesh Values from Tally 1..."

    tallyid = 0  # tally 1
    score = 0  # flux is zero see (order of tally.filters.keys())

    # get mesh dimensions
    meshid = sp.tallies[tallyid].filters['mesh'].bins[0]
    for i, m in enumerate(sp.meshes):
        if m.id == meshid:
            mesh = m
    nx, ny, nz = mesh.dimension

    # loop through mesh and extract values
    thermal = {}
    fast = {}
    for x in range(1, nx + 1):
        for y in range(1, ny + 1):
            for z in range(1, nz + 1):
                val, err = sp.get_value(tallyid, [('mesh', (x, y, z)),
                                                  ('energyin', 0)], score)
                thermal[(x, y, z)] = val
                val, err = sp.get_value(tallyid, [('mesh', (x, y, z)),
                                                  ('energyin', 1)], score)
                fast[(x, y, z)] = val

    # write gnuplot datafile with axially-integrated values
    print "Making gnuplots ..."
    with open('meshdata.dat', 'w') as fh:
        for x in range(1, nx + 1):
            for y in range(1, ny + 1):
                thermalval = 0.
                fastval = 0.
                for z in range(1, nz + 1):
                    thermalval += thermal[(x, y, z)]
                    fastval += fast[(x, y, z)]
                fh.write("{} {} {} {}\n".format(x, y, thermalval, fastval))

    # write gnuplot file and make plots
    with open('tmp.gnuplot', 'w') as fh:
        fh.write(r"""set terminal png size 800,400
set output 'fluxplot.png'
set nokey
set autoscale fix
set multiplot layout 1,2 title "Pin Mesh Axially-Integrated Flux Tally"
set title "Thermal"
plot 'meshdata.dat' using 1:2:3 with image
set title "Fast"
plot 'meshdata.dat' using 1:2:4 with image
""")
    os.system("gnuplot < tmp.gnuplot")

    # make 3d silo file
    print "Making 3D SILO File ..."
    sm.init_silo("fluxtally.silo")
    sm.init_mesh(
        'tally_mesh',
        nx,
        ny,
        nz,
        -85.8774,
        -85.8774,
        -81.662,  # lower left of mesh
        1.63576,
        1.63576,
        8.1662)  # width of mesh cells
    sm.init_var('flux_tally_thermal')
    for x in range(1, nx + 1):
        for y in range(1, ny + 1):
            for z in range(1, nz + 1):
                sm.set_value(float(thermal[(x, y, z)]), x, y, z)
    sm.finalize_var()
    sm.init_var('flux_tally_fast')
    for x in range(1, nx + 1):
        for y in range(1, ny + 1):
            for z in range(1, nz + 1):
                sm.set_value(float(fast[(x, y, z)]), x, y, z)
    sm.finalize_var()
    sm.finalize_mesh()
    sm.finalize_silo()
Пример #7
0
def main(file_, o):

  print(file_)
  fh = open(file_,'rb')
  header = get_header(fh)
  meshparms = header['dimension'] + header['lower_left'] + header['upper_right']
  nx,ny,nz = meshparms[0], meshparms[1], meshparms[2]
  ll = header['lower_left']

  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

    origin = [(l+w*n/2.) for n,l,w in zip((nx,ny,nz),ll,header['width'])]

    grid = vtk.vtkImageData()
    grid.SetDimensions(nx+1,ny+1,nz+1)
    grid.SetOrigin(*ll)
    grid.SetSpacing(*header['width'])

    data = vtk.vtkDoubleArray()
    data.SetName("id")
    data.SetNumberOfTuples(nx*ny*nz)
    for x in range(nx):
      sys.stdout.write(" {0}%\r".format(int(x/nx*100)))
      sys.stdout.flush()
      for y in range(ny):
        for z in range(nz):
          i = z*nx*ny + y*nx + x
          id_ = get_int(fh)[0]
          data.SetValue(i, id_)
    grid.GetCellData().AddArray(data)

    writer = vtk.vtkXMLImageDataWriter()
    writer.SetInput(grid)
    if not o.output[-4:] == ".vti": o.output += ".vti"
    writer.SetFileName(o.output)
    writer.Write()

  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 not o.output[-5:] == ".silo": o.output += ".silo"
    silomesh.init_silo(o.output)
    silomesh.init_mesh('plot', *meshparms)
    silomesh.init_var("id")
    for x in range(1,nx+1):
      sys.stdout.write(" {0}%\r".format(int(x/nx*100)))
      sys.stdout.flush()
      for y in range(1,ny+1):
        for z in range(1,nz+1):
          id_ = get_int(fh)[0]
          silomesh.set_value(float(id_), x, y, z)
    print()
    silomesh.finalize_var()
    silomesh.finalize_mesh()
    silomesh.finalize_silo()
Пример #8
0
def main(file_, o):

  print file_
  fh = open(file_,'rb')
  header = get_header(fh)
  meshparms = header['dimension'] + header['lower_left'] + header['upper_right']
  nx,ny,nz = meshparms[0], meshparms[1], meshparms[2]
  ll = header['lower_left']

  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
    
    origin = [(l+w*n/2.) for n,l,w in zip((nx,ny,nz),ll,header['width'])]
    
    grid = vtk.vtkImageData()
    grid.SetDimensions(nx+1,ny+1,nz+1)
    grid.SetOrigin(*ll)
    grid.SetSpacing(*header['width'])
    
    data = vtk.vtkDoubleArray()
    data.SetName("id")
    data.SetNumberOfTuples(nx*ny*nz)
    for x in range(nx):
      sys.stdout.write(" {0}%\r".format(int(x/nx*100)))
      sys.stdout.flush()
      for y in range(ny):
        for z in range(nz):
          i = z*nx*ny + y*nx + x
          id_ = get_int(fh)[0]
          data.SetValue(i, id_)
    grid.GetCellData().AddArray(data)
    
    writer = vtk.vtkXMLImageDataWriter()
    writer.SetInput(grid)
    if not o.output[-4:] == ".vti": o.output += ".vti"
    writer.SetFileName(o.output)
    writer.Write()

  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 not o.output[-5:] == ".silo": o.output += ".silo"
    silomesh.init_silo(o.output)
    silomesh.init_mesh('plot', *meshparms)
    silomesh.init_var("id")
    for x in range(1,nx+1):
      sys.stdout.write(" {0}%\r".format(int(x/nx*100)))
      sys.stdout.flush()
      for y in range(1,ny+1):
        for z in range(1,nz+1):
          id_ = get_int(fh)[0]
          silomesh.set_value(float(id_), x, y, z)
    print
    silomesh.finalize_var()
    silomesh.finalize_mesh()
    silomesh.finalize_silo()