standardized and cleaned
-write to file if given -type casting is done in the geom class
This commit is contained in:
parent
07276d511c
commit
931fa9d36a
|
@ -1,37 +1,36 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
from optparse import OptionParser
|
|
||||||
|
|
||||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
scriptID = ' '.join([scriptName,damask.version])
|
scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# MAIN
|
# MAIN
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [geomfile(s)]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
|
||||||
Generate homogeneous geometry.
|
Generate homogeneous geometry.
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option('-g',
|
parser.add_option('-g','--grid',
|
||||||
'--grid',
|
|
||||||
dest = 'grid',
|
dest = 'grid',
|
||||||
type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
|
type = 'int', nargs = 3, metavar = ' '.join(['int']*3),
|
||||||
help = 'a,b,c grid of hexahedral box %default')
|
help = 'a,b,c grid of hexahedral box %default')
|
||||||
parser.add_option('-s',
|
parser.add_option('-s', '--size',
|
||||||
'--size',
|
|
||||||
dest = 'size',
|
dest = 'size',
|
||||||
type = 'float', nargs = 3, metavar = ' '.join(['float']*3),
|
type = 'float', nargs = 3, metavar = ' '.join(['float']*3),
|
||||||
help = 'x,y,z of geometry size %default')
|
help = 'x,y,z of geometry size %default')
|
||||||
parser.add_option('-o',
|
parser.add_option('-o','--origin',
|
||||||
'--origin',
|
|
||||||
dest = 'origin',
|
dest = 'origin',
|
||||||
type = 'float', nargs = 3, metavar = ' '.join(['float']*3),
|
type = 'float', nargs = 3, metavar = ' '.join(['float']*3),
|
||||||
help = 'x,y,z of geometry origin %default')
|
help = 'x,y,z of geometry origin %default')
|
||||||
|
@ -39,36 +38,33 @@ parser.add_option('--homogenization',
|
||||||
dest = 'homogenization',
|
dest = 'homogenization',
|
||||||
type = 'int', metavar = 'int',
|
type = 'int', metavar = 'int',
|
||||||
help = 'homogenization index [%default]')
|
help = 'homogenization index [%default]')
|
||||||
parser.add_option('-f',
|
parser.add_option('-f','--fill',
|
||||||
'--fill',
|
|
||||||
dest = 'fill',
|
dest = 'fill',
|
||||||
type = 'float', metavar = 'float',
|
type = 'float', metavar = 'int',
|
||||||
help = 'microstructure index [%default]')
|
help = 'microstructure index [%default]')
|
||||||
|
|
||||||
parser.set_defaults(grid = [16,16,16],
|
parser.set_defaults(grid = (16,16,16),
|
||||||
size = [1.,1.,1.],
|
size = (1.,1.,1.),
|
||||||
origin = [0.,0.,0.],
|
origin = (0.,0.,0.),
|
||||||
homogenization = 1,
|
homogenization = 1,
|
||||||
fill = 1,
|
fill = 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
(options, filenames) = parser.parse_args()
|
(options, filename) = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
name = None if filename == [] else filename[0]
|
||||||
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
dtype = float if np.isnan(options.fill) or int(options.fill) != options.fill else int
|
dtype = float if np.isnan(options.fill) or int(options.fill) != options.fill else int
|
||||||
grid = list(map( int,options.grid))
|
geom = damask.Geom(microstructure=np.full(options.grid,options.fill,dtype=dtype),
|
||||||
size = list(map(float,options.size))
|
size=options.size,
|
||||||
origin = list(map(float,options.origin))
|
origin=options.origin,
|
||||||
homogenization = int(options.homogenization)
|
homogenization=options.homogenization,
|
||||||
fill = float(options.fill)
|
|
||||||
|
|
||||||
damask.util.report(scriptName,'')
|
|
||||||
|
|
||||||
geom = damask.Geom(microstructure=(fill * np.ones(grid)).astype(dtype),
|
|
||||||
size=size,
|
|
||||||
origin=origin,
|
|
||||||
homogenization=homogenization,
|
|
||||||
comments=scriptID + ' ' + ' '.join(sys.argv[1:]))
|
comments=scriptID + ' ' + ' '.join(sys.argv[1:]))
|
||||||
|
|
||||||
damask.util.croak(geom)
|
damask.util.croak(geom)
|
||||||
|
|
||||||
|
if name is None:
|
||||||
sys.stdout.write(str(geom.show()))
|
sys.stdout.write(str(geom.show()))
|
||||||
|
else:
|
||||||
|
geom.to_file(name)
|
||||||
|
|
|
@ -192,7 +192,7 @@ class Geom():
|
||||||
"""Writes to file"""
|
"""Writes to file"""
|
||||||
header = self.get_header()
|
header = self.get_header()
|
||||||
grid = self.get_grid()
|
grid = self.get_grid()
|
||||||
format_string = '%{}i'.format(1+int(np.floor(np.log10(np.nanmax(self.microstructure)-1)))) if self.microstructure.dtype == int \
|
format_string = '%{}i'.format(1+int(np.floor(np.log10(np.nanmax(self.microstructure))))) if self.microstructure.dtype == int \
|
||||||
else '%g'
|
else '%g'
|
||||||
np.savetxt(fname,
|
np.savetxt(fname,
|
||||||
self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T,
|
self.microstructure.reshape([grid[0],np.prod(grid[1:])],order='F').T,
|
||||||
|
|
Loading…
Reference in New Issue