making use of new class

@philip: 1D arrangement needed?
This commit is contained in:
Martin Diehl 2019-05-25 08:36:00 +02:00
parent 6c7f7c77da
commit 4788fc6046
2 changed files with 17 additions and 44 deletions

View File

@ -1,7 +1,9 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 no BOM -*-
import os,sys,math
import os
import sys
import math
import numpy as np
from optparse import OptionParser
import damask
@ -33,48 +35,19 @@ parser.set_defaults(oneD = False,
if filenames == []: filenames = [None]
for name in filenames:
try:
table = damask.ASCIItable(name = name,
buffered = False, labeled = False)
except: continue
if name is None:
virt_file = StringIO(''.join(sys.stdin.read()))
geom = damask.Geom.from_file(virt_file)
else:
geom = damask.Geom.from_file(name)
damask.util.report(scriptName,name)
# --- interpret header ----------------------------------------------------------------------------
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
table.head_read()
info,extra_header = table.head_getGeom()
damask.util.report_geom(info)
damask.util.croak('\n'.join(geom.info()))
errors = []
if np.any(info['grid'] < 1): errors.append('invalid grid a b c.')
if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.')
if errors != []:
damask.util.croak(errors)
table.close(dismiss = True)
continue
# --- write header ---------------------------------------------------------------------------------
table.labels_clear()
table.info_clear()
table.info_append(extra_header+[
scriptID + ' ' + ' '.join(sys.argv[1:]),
"grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']),
"size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']),
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']),
"homogenization\t{homog}".format(homog=info['homogenization']),
"microstructures\t{microstructures}".format(microstructures=info['microstructures']),
])
table.head_write()
# --- write microstructure information ------------------------------------------------------------
microstructure = table.microstructure_read(info['grid']) # read microstructure
formatwidth = int(math.floor(math.log10(microstructure.max())+1)) # efficient number printing format
table.data = microstructure if options.oneD else \
microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose()
table.data_writeArray('%%%ii'%(formatwidth),delimiter = ' ')
#--- output finalization --------------------------------------------------------------------------
table.close() # close ASCII table
if name is None:
sys.stdout.write(str(geom))
else:
geom.to_file(name)

View File

@ -86,7 +86,7 @@ class Geom():
items = line.split()
if len(items) == 3:
if items[1].lower() == 'of':
items = np.ones(float(items[0]))*int(items[2])
items = np.ones(int(items[0]))*float(items[2])
elif items[1].lower() == 'to':
items = np.linspace(int(items[0]),int(items[2]),
abs(int(items[2])-int(items[0]))+1,dtype=float)