using new class
This commit is contained in:
parent
7b6003fb32
commit
cf374a04dc
|
@ -1,10 +1,12 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,math
|
import os
|
||||||
|
import sys
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy import ndimage
|
from scipy import ndimage
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
from io import StringIO
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
|
@ -63,35 +65,16 @@ options.trigger = np.array(options.trigger, dtype=int)
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
if name is None:
|
||||||
table = damask.ASCIItable(name = name,
|
virt_file = StringIO(''.join(sys.stdin.read()))
|
||||||
buffered = False, labeled = False)
|
geom = damask.Geom.from_file(virt_file)
|
||||||
|
else:
|
||||||
|
try: # really needed? Why not simply fail if file does not exists etc.
|
||||||
|
geom = damask.Geom.from_file(name)
|
||||||
except: continue
|
except: continue
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# --- interpret header ----------------------------------------------------------------------------
|
microstructure = geom.microstructure
|
||||||
|
|
||||||
table.head_read()
|
|
||||||
info,extra_header = table.head_getGeom()
|
|
||||||
damask.util.report_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
|
|
||||||
|
|
||||||
# --- read data ------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
microstructure = table.microstructure_read(info['grid']).reshape(info['grid'],order='F') # read microstructure
|
|
||||||
|
|
||||||
# --- do work ------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
newInfo = {
|
|
||||||
'microstructures': 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.offset == 0: options.offset = microstructure.max()
|
if options.offset == 0: options.offset = microstructure.max()
|
||||||
|
|
||||||
|
@ -102,33 +85,12 @@ for name in filenames:
|
||||||
extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}),
|
extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}),
|
||||||
microstructure + options.offset,microstructure)
|
microstructure + options.offset,microstructure)
|
||||||
|
|
||||||
newInfo['microstructures'] = len(np.unique(microstructure))
|
geom.microstructure = microstructure
|
||||||
|
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
# --- report ---------------------------------------------------------------------------------------
|
damask.util.croak('\n'.join(geom.info()))
|
||||||
|
|
||||||
if (newInfo['microstructures'] != info['microstructures']):
|
if name is None:
|
||||||
damask.util.croak('--> microstructures: %i'%newInfo['microstructures'])
|
sys.stdout.write(str(geom))
|
||||||
|
else:
|
||||||
# --- write header ---------------------------------------------------------------------------------
|
geom.to_file(name)
|
||||||
|
|
||||||
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=newInfo['microstructures']),
|
|
||||||
])
|
|
||||||
table.head_write()
|
|
||||||
|
|
||||||
# --- write microstructure information ------------------------------------------------------------
|
|
||||||
|
|
||||||
formatwidth = int(math.floor(math.log10(np.nanmax(microstructure))+1))
|
|
||||||
table.data = microstructure.reshape((info['grid'][0],info['grid'][1]*info['grid'][2]),order='F').transpose()
|
|
||||||
table.data_writeArray('%{}i'.format(formatwidth),delimiter = ' ')
|
|
||||||
|
|
||||||
# --- output finalization --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
table.close() # close ASCII table
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
import io
|
|
||||||
|
|
||||||
class Geom():
|
class Geom():
|
||||||
"""Geometry definition for grid solvers"""
|
"""Geometry definition for grid solvers"""
|
||||||
|
|
Loading…
Reference in New Issue