2012-11-07 22:22:10 +05:30
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2014-11-18 13:30:45 +05:30
|
|
|
import os,sys,string,math
|
2014-10-09 22:33:06 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-10-09 22:33:06 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
2013-05-13 18:40:31 +05:30
|
|
|
# MAIN
|
2014-10-09 22:33:06 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2012-11-07 22:22:10 +05:30
|
|
|
minimal_surfaces = ['primitive','gyroid','diamond',]
|
|
|
|
|
|
|
|
surface = {
|
|
|
|
'primitive': lambda x,y,z: math.cos(x)+math.cos(y)+math.cos(z),
|
|
|
|
'gyroid': lambda x,y,z: math.sin(x)*math.cos(y)+math.sin(y)*math.cos(z)+math.cos(x)*math.sin(z),
|
|
|
|
'diamond': lambda x,y,z: math.cos(x-y)*math.cos(z)+math.sin(x+y)*math.sin(z),
|
|
|
|
}
|
2013-07-18 19:01:40 +05:30
|
|
|
|
2014-10-09 22:33:06 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog', description = """
|
2012-11-07 22:22:10 +05:30
|
|
|
Generate a geometry file of a bicontinuous structure of given type.
|
2014-10-09 22:33:06 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2012-11-07 22:22:10 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-t','--type',
|
|
|
|
dest = 'type',
|
|
|
|
choices = minimal_surfaces, metavar = 'string',
|
|
|
|
help = 'type of minimal surface [primitive] {%s}' %(','.join(minimal_surfaces)))
|
|
|
|
parser.add_option('-f','--threshold',
|
|
|
|
dest = 'threshold',
|
|
|
|
type = 'float', metavar = 'float',
|
|
|
|
help = 'threshold value defining minimal surface [%default]')
|
|
|
|
parser.add_option('-g', '--grid',
|
|
|
|
dest = 'grid',
|
|
|
|
type = 'int', nargs = 3, metavar = 'int int int',
|
|
|
|
help = 'a,b,c grid of hexahedral box [%default]')
|
|
|
|
parser.add_option('-s', '--size',
|
|
|
|
dest = 'size',
|
|
|
|
type = 'float', nargs = 3, metavar = 'float float float',
|
|
|
|
help = 'x,y,z size of hexahedral box [%default]')
|
|
|
|
parser.add_option('-p', '--periods',
|
|
|
|
dest = 'periods',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
help = 'number of repetitions of unit cell [%default]')
|
|
|
|
parser.add_option('--homogenization',
|
|
|
|
dest = 'homogenization',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
help = 'homogenization index to be used [%default]')
|
|
|
|
parser.add_option('--m',
|
|
|
|
dest = 'microstructure',
|
|
|
|
type = 'int', nargs = 2, metavar = 'int int',
|
|
|
|
help = 'two microstructure indices to be used [%default]')
|
|
|
|
parser.set_defaults(type = minimal_surfaces[0],
|
|
|
|
threshold = 0.0,
|
|
|
|
periods = 1,
|
|
|
|
grid = (16,16,16),
|
|
|
|
size = (1.0,1.0,1.0),
|
|
|
|
homogenization = 1,
|
|
|
|
microstructure = (1,2),
|
|
|
|
)
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
|
2015-08-12 23:13:49 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2015-08-12 23:13:49 +05:30
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(outname = name,
|
|
|
|
buffered = False, labeled = False)
|
2015-08-21 01:12:05 +05:30
|
|
|
except: continue
|
2015-09-24 21:04:27 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------ make grid -------------------------------------
|
|
|
|
|
|
|
|
info = {
|
|
|
|
'grid': np.array(options.grid),
|
|
|
|
'size': np.array(options.size),
|
|
|
|
'origin': np.zeros(3,'d'),
|
|
|
|
'microstructures': max(options.microstructure),
|
|
|
|
'homogenization': options.homogenization
|
|
|
|
}
|
2013-05-13 18:40:31 +05:30
|
|
|
|
|
|
|
#--- report ---------------------------------------------------------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-09-24 21:04:27 +05:30
|
|
|
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
2015-08-08 00:33:26 +05:30
|
|
|
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
|
|
|
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
|
|
|
'homogenization: %i'%info['homogenization'],
|
|
|
|
'microstructures: %i'%info['microstructures'],
|
|
|
|
])
|
|
|
|
|
|
|
|
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 != []:
|
2015-09-24 21:04:27 +05:30
|
|
|
damask.util.croak(errors)
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close(dismiss = True)
|
|
|
|
continue
|
2013-05-15 02:39:37 +05:30
|
|
|
|
2013-05-13 18:40:31 +05:30
|
|
|
#--- write header ---------------------------------------------------------------------------------
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.labels_clear()
|
|
|
|
table.info_clear()
|
|
|
|
table.info_append([
|
|
|
|
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()
|
|
|
|
|
2013-05-13 18:40:31 +05:30
|
|
|
#--- write data -----------------------------------------------------------------------------------
|
2015-08-21 01:12:05 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
X = options.periods*2.0*math.pi*(np.arange(options.grid[0])+0.5)/options.grid[0]
|
|
|
|
Y = options.periods*2.0*math.pi*(np.arange(options.grid[1])+0.5)/options.grid[1]
|
|
|
|
Z = options.periods*2.0*math.pi*(np.arange(options.grid[2])+0.5)/options.grid[2]
|
|
|
|
|
|
|
|
for z in xrange(options.grid[2]):
|
|
|
|
for y in xrange(options.grid[1]):
|
|
|
|
table.data_clear()
|
|
|
|
for x in xrange(options.grid[0]):
|
|
|
|
table.data_append(options.microstructure[options.threshold < surface[options.type](X[x],Y[y],Z[z])])
|
|
|
|
table.data_write()
|
|
|
|
|
|
|
|
table.close()
|