polishing, unifying,simplifying
This commit is contained in:
parent
563e74c832
commit
2acd737859
|
@ -4,7 +4,6 @@
|
||||||
import os,sys,string,math,numpy
|
import os,sys,string,math,numpy
|
||||||
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
||||||
|
|
||||||
|
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
class extendedOption(Option):
|
class extendedOption(Option):
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
@ -84,8 +83,8 @@ if numpy.any(options.size < 0.0):
|
||||||
file['croak'].write('invalid size...\n')
|
file['croak'].write('invalid size...\n')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
info = {
|
info = {
|
||||||
'grid': options.grid,
|
'grid': numpy.array(options.grid),
|
||||||
'size': options.size,
|
'size': numpy.array(options.size),
|
||||||
'origin': numpy.zeros(3,'d'),
|
'origin': numpy.zeros(3,'d'),
|
||||||
'microstructures': max(options.microstructure),
|
'microstructures': max(options.microstructure),
|
||||||
'homogenization': options.homogenization
|
'homogenization': options.homogenization
|
||||||
|
@ -105,7 +104,7 @@ header.append("size\tx %f\ty %f\tz %f\n"%(info['size'][0],info['size'][1],info['
|
||||||
header.append("origin\tx %f\ty %f\tz %f\n"%(info['origin'][0],info['origin'][1],info['origin'][2],))
|
header.append("origin\tx %f\ty %f\tz %f\n"%(info['origin'][0],info['origin'][1],info['origin'][2],))
|
||||||
header.append("microstructures\t%i\n"%info['microstructures'])
|
header.append("microstructures\t%i\n"%info['microstructures'])
|
||||||
header.append("homogenization\t%i\n"%info['homogenization'])
|
header.append("homogenization\t%i\n"%info['homogenization'])
|
||||||
file['output'].write('%i\theader\n'%(len(new_header))+''.join(new_header))
|
file['output'].write('%i\theader\n'%(len(header))+''.join(header))
|
||||||
|
|
||||||
#--- write data -----------------------------------------------------------------------------------
|
#--- write data -----------------------------------------------------------------------------------
|
||||||
for z in xrange(options.grid[2]):
|
for z in xrange(options.grid[2]):
|
||||||
|
|
|
@ -39,7 +39,6 @@ mappings = {
|
||||||
'microstructures': lambda x: int(x),
|
'microstructures': lambda x: int(x),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
|
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
|
||||||
Scales a geometry description independently in x, y, and z direction in terms of grid and/or size.
|
Scales a geometry description independently in x, y, and z direction in terms of grid and/or size.
|
||||||
""" + string.replace('$Id$','\n','\\n')
|
""" + string.replace('$Id$','\n','\\n')
|
||||||
|
@ -91,15 +90,14 @@ for file in files:
|
||||||
content = file['input'].readlines()
|
content = file['input'].readlines()
|
||||||
file['input'].close()
|
file['input'].close()
|
||||||
|
|
||||||
#--- interpretate header --------------------------------------------------------------------------
|
#--- interprete header ----------------------------------------------------------------------------
|
||||||
info = {
|
info = {
|
||||||
'grid': numpy.array(options.grid),
|
'grid': numpy.zeros(3,'i'),
|
||||||
'size': numpy.array(options.size),
|
'size': numpy.zeros(3,'d'),
|
||||||
'origin': numpy.zeros(3,'d'),
|
'origin': numpy.zeros(3,'d'),
|
||||||
'microstructures': 0,
|
'microstructures': 0,
|
||||||
'homogenization': 0
|
'homogenization': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
newInfo = {
|
newInfo = {
|
||||||
'grid': numpy.array(options.grid),
|
'grid': numpy.array(options.grid),
|
||||||
'size': numpy.array(options.size),
|
'size': numpy.array(options.size),
|
||||||
|
@ -134,11 +132,12 @@ for file in files:
|
||||||
'homogenization: %i\n'%info['homogenization'] + \
|
'homogenization: %i\n'%info['homogenization'] + \
|
||||||
'microstructures: %i\n\n'%info['microstructures'])
|
'microstructures: %i\n\n'%info['microstructures'])
|
||||||
|
|
||||||
if options.grid == [0,0,0]:
|
if numpy.all(info['grid'] == 0):
|
||||||
newInfo['grid'] = info['grid']
|
newInfo['grid'] = info['grid']
|
||||||
if options.size == [0.0,0.0,0.0]:
|
if numpy.all(info['size'] == 0.0)::
|
||||||
newInfo['size'] = info['size']
|
newInfo['size'] = info['size']
|
||||||
|
|
||||||
|
#--- read data ------------------------------------------------------------------------------------
|
||||||
microstructure = numpy.zeros(info['grid'],'i')
|
microstructure = numpy.zeros(info['grid'],'i')
|
||||||
i = 0
|
i = 0
|
||||||
for line in content:
|
for line in content:
|
||||||
|
@ -157,20 +156,17 @@ for file in files:
|
||||||
if (newInfo['microstructures'] != info['microstructures']):
|
if (newInfo['microstructures'] != info['microstructures']):
|
||||||
file['croak'].write('--> microstructures: %i\n'%newInfo['microstructures'])
|
file['croak'].write('--> microstructures: %i\n'%newInfo['microstructures'])
|
||||||
|
|
||||||
|
#--- assemble header ------------------------------------------------------------------------------
|
||||||
new_header.append('$Id$\n')
|
new_header.append('$Id$\n')
|
||||||
new_header.append("grid\ta %i\tb %i\tc %i\n"%(newInfo['grid'][0],newInfo['grid'][1],newInfo['grid'][2]))
|
new_header.append("grid\ta %i\tb %i\tc %i\n"%(newInfo['grid'][0],newInfo['grid'][1],newInfo['grid'][2]))
|
||||||
new_header.append("size\tx %f\ty %f\tz %f\n"%(newInfo['size'][0],newInfo['size'][1],newInfo['size'][2]))
|
new_header.append("size\tx %f\ty %f\tz %f\n"%(newInfo['size'][0],newInfo['size'][1],newInfo['size'][2]))
|
||||||
new_header.append("origin\tx %f\ty %f\tz %f\n"%(info['origin'][0],info['origin'][1],info['origin'][2]))
|
new_header.append("origin\tx %f\ty %f\tz %f\n"%(info['origin'][0],info['origin'][1],info['origin'][2]))
|
||||||
new_header.append("microstructures\t%i\n"%newInfo['microstructures'])
|
new_header.append("microstructures\t%i\n"%newInfo['microstructures'])
|
||||||
new_header.append("homogenization\t%i\n"%info['homogenization'])
|
new_header.append("homogenization\t%i\n"%info['homogenization'])
|
||||||
|
|
||||||
# ------------------------------------------ assemble header ---------------------------------------
|
|
||||||
|
|
||||||
output = '%i\theader\n'%(len(new_header))
|
output = '%i\theader\n'%(len(new_header))
|
||||||
output += ''.join(new_header)
|
output += ''.join(new_header)
|
||||||
|
|
||||||
# ------------------------------------- regenerate texture information ----------------------------------
|
#--- scale microstructure -------------------------------------------------------------------------
|
||||||
|
|
||||||
for c in xrange(options.grid[2]):
|
for c in xrange(options.grid[2]):
|
||||||
z = int(info['grid'][2]*(c+0.5)/options.grid[2])%info['grid'][2]
|
z = int(info['grid'][2]*(c+0.5)/options.grid[2])%info['grid'][2]
|
||||||
for b in xrange(options.grid[1]):
|
for b in xrange(options.grid[1]):
|
||||||
|
@ -179,13 +175,10 @@ for file in files:
|
||||||
x = int(info['grid'][0]*(a+0.5)/options.grid[0])%info['grid'][0]
|
x = int(info['grid'][0]*(a+0.5)/options.grid[0])%info['grid'][0]
|
||||||
output += str(microstructure[x,y,z]).rjust(formatwidth) + {True:' ',False:'\n'}[options.twoD]
|
output += str(microstructure[x,y,z]).rjust(formatwidth) + {True:' ',False:'\n'}[options.twoD]
|
||||||
output += {True:'\n',False:''}[options.twoD]
|
output += {True:'\n',False:''}[options.twoD]
|
||||||
|
|
||||||
# ------------------------------------------ output result ---------------------------------------
|
|
||||||
|
|
||||||
file['output'].write(output)
|
file['output'].write(output)
|
||||||
|
|
||||||
|
#--- output finalization --------------------------------------------------------------------------
|
||||||
if file['name'] != 'STDIN':
|
if file['name'] != 'STDIN':
|
||||||
file['input'].close()
|
|
||||||
file['output'].close()
|
file['output'].close()
|
||||||
os.rename(file['name']+'_tmp',file['name'])
|
os.rename(file['name']+'_tmp',file['name'])
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ mappings = {
|
||||||
'homogenization': lambda x: int(x),
|
'homogenization': lambda x: int(x),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
|
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
|
||||||
translate microstructure indices (shift or substitute) and/or geometry origin.
|
translate microstructure indices (shift or substitute) and/or geometry origin.
|
||||||
""" + string.replace('$Id$','\n','\\n')
|
""" + string.replace('$Id$','\n','\\n')
|
||||||
|
@ -96,15 +95,14 @@ for file in files:
|
||||||
content = file['input'].readlines()
|
content = file['input'].readlines()
|
||||||
file['input'].close()
|
file['input'].close()
|
||||||
|
|
||||||
#--- interpretate header --------------------------------------------------------------------------
|
#--- interprete header ----------------------------------------------------------------------------
|
||||||
info = {
|
info = {
|
||||||
'grid': numpy.array([0,0,0]),
|
'grid': numpy.zeros(3,'i'),
|
||||||
'size': numpy.array([0.0,0.0,0.0]),
|
'size': numpy.zeros(3,'d'),
|
||||||
'origin': numpy.zeros(3,'d'),
|
'origin': numpy.zeros(3,'d'),
|
||||||
'microstructures': 0,
|
'microstructures': 0,
|
||||||
'homogenization': 0
|
'homogenization': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
newInfo = {
|
newInfo = {
|
||||||
'origin': numpy.zeros(3,'d'),
|
'origin': numpy.zeros(3,'d'),
|
||||||
'microstructures': 0,
|
'microstructures': 0,
|
||||||
|
|
|
@ -246,7 +246,7 @@ parser.add_option("-s", "--spectral", action="store_const", const="spectral",\
|
||||||
|
|
||||||
parser.add_option("--homogenization", type="int",\
|
parser.add_option("--homogenization", type="int",\
|
||||||
dest="homogenization",\
|
dest="homogenization",\
|
||||||
help="homogenization index from material.config (only required for spectral file type)")
|
help="homogenization index from material.config (only required for geom file type)")
|
||||||
|
|
||||||
|
|
||||||
parser.set_defaults(filetype = 'geom')
|
parser.set_defaults(filetype = 'geom')
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
import os,sys,string,re,math,numpy,random
|
import os,sys,string,re,math,numpy,random
|
||||||
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------------------------
|
||||||
# -----------------------------
|
|
||||||
class extendedOption(Option):
|
class extendedOption(Option):
|
||||||
# -----------------------------
|
#------------------------------------------------------------------------------------------------
|
||||||
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
||||||
# taken from online tutorial http://docs.python.org/library/optparse.html
|
# taken from online tutorial http://docs.python.org/library/optparse.html
|
||||||
|
|
||||||
|
@ -24,8 +23,9 @@ class extendedOption(Option):
|
||||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
Option.take_action(self, action, dest, opt, value, values, parser)
|
||||||
|
|
||||||
|
|
||||||
# ----------------------- MAIN -------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
# MAIN
|
||||||
|
#--------------------------------------------------------------------------------------------------
|
||||||
identifiers = {
|
identifiers = {
|
||||||
'grid': ['a','b','c'],
|
'grid': ['a','b','c'],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue