mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
PEP8 fixes for openmc-voxel-to-silovtk
This commit is contained in:
parent
0f6c324c94
commit
6a862d82af
1 changed files with 26 additions and 21 deletions
|
|
@ -24,25 +24,27 @@ def parse_options():
|
|||
|
||||
def main(file_, o):
|
||||
print(file_)
|
||||
fh = open(file_,'rb')
|
||||
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]
|
||||
meshparms = (header['dimension'] + header['lower_left'] +
|
||||
header['upper_right'])
|
||||
nx, ny, nz = meshparms[:3]
|
||||
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'
|
||||
print('The vtk python bindings do not appear to be installed '
|
||||
'properly.\nOn 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'])]
|
||||
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.SetDimensions(nx+1, ny+1, nz+1)
|
||||
grid.SetOrigin(*ll)
|
||||
grid.SetSpacing(*header['width'])
|
||||
|
||||
|
|
@ -61,7 +63,8 @@ def main(file_, o):
|
|||
|
||||
writer = vtk.vtkXMLImageDataWriter()
|
||||
writer.SetInputData(grid)
|
||||
if not o.output[-4:] == ".vti": o.output += ".vti"
|
||||
if not o.output.endswith(".vti"):
|
||||
o.output += ".vti"
|
||||
writer.SetFileName(o.output)
|
||||
writer.Write()
|
||||
|
||||
|
|
@ -69,18 +72,19 @@ def main(file_, o):
|
|||
try:
|
||||
import silomesh
|
||||
except:
|
||||
print('The silomesh package does not appear to be installed properly.\n'
|
||||
'See: https://github.com/nhorelik/silomesh/')
|
||||
print('The silomesh package does not appear to be installed '
|
||||
'properly.\nSee: https://github.com/nhorelik/silomesh/')
|
||||
return
|
||||
if not o.output[-5:] == ".silo": o.output += ".silo"
|
||||
if not o.output.endswith(".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):
|
||||
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):
|
||||
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()
|
||||
|
|
@ -90,16 +94,17 @@ def main(file_, o):
|
|||
|
||||
|
||||
def get_header(file_):
|
||||
nx,ny,nz = get_int(file_, 3)
|
||||
wx,wy,wz = get_double(file_, 3)
|
||||
lx,ly,lz = get_double(file_, 3)
|
||||
header = {'dimension':[nx,ny,nz], 'width':[wx,wy,wz], 'lower_left':[lx,ly,lz],
|
||||
'upper_right': [lx+wx*nx,ly+wy*ny,lz+wz*nz]}
|
||||
nx, ny, nz = get_int(file_, 3)
|
||||
wx, wy, wz = get_double(file_, 3)
|
||||
lx, ly, lz = get_double(file_, 3)
|
||||
header = {'dimension': [nx, ny, nz], 'width': [wx, wy, wz],
|
||||
'lower_left': [lx, ly, lz],
|
||||
'upper_right': [lx+wx*nx, ly+wy*ny, lz+wz*nz]}
|
||||
return header
|
||||
|
||||
|
||||
def get_data(file_, n, typeCode, size):
|
||||
return list(struct.unpack('={0}{1}'.format(n,typeCode),
|
||||
return list(struct.unpack('={0}{1}'.format(n, typeCode),
|
||||
file_.read(n*size)))
|
||||
|
||||
|
||||
|
|
@ -114,4 +119,4 @@ def get_double(file_, n=1, path=None):
|
|||
if __name__ == '__main__':
|
||||
(options, args) = parse_options()
|
||||
if args:
|
||||
main(args[0],options)
|
||||
main(args[0], options)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue