DAMASK_EICMD/processing/pre/geom_fromMinimalSurface.py

96 lines
3.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: UTF-8 no BOM -*-
2019-05-25 02:01:34 +05:30
import os
import sys
import math
2014-10-09 22:33:06 +05:30
import numpy as np
from optparse import OptionParser
import damask
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
2014-10-09 22:33:06 +05:30
# --------------------------------------------------------------------
# MAIN
2014-10-09 22:33:06 +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
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [option(s)] [geomfile]', description = """
Generate a geometry file of a bicontinuous structure of given type.
2014-10-09 22:33:06 +05:30
""", version = scriptID)
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 -------------------------------------------------------------------------
if filenames == []: filenames = [None]
for name in filenames:
2019-05-25 02:01:34 +05:30
damask.util.report(scriptName,name)
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]
2019-05-25 02:01:34 +05:30
microstructure = np.empty(options.grid,dtype='int')
2016-10-25 00:46:29 +05:30
for z in range(options.grid[2]):
for y in range(options.grid[1]):
for x in range(options.grid[0]):
2019-05-25 02:01:34 +05:30
microstructure[x,y,z]=options.microstructure[options.threshold < surface[options.type](X[x],Y[y],Z[z])]
geom=damask.Geom(options.size,microstructure,options.homogenization,
comments=[scriptID + ' ' + ' '.join(sys.argv[1:])])
2019-05-25 13:44:53 +05:30
damask.util.croak(geom)
2019-05-25 02:01:34 +05:30
if name is None:
2019-05-25 13:44:53 +05:30
sys.stdout.write(str(geom.show()))
2019-05-25 02:01:34 +05:30
else:
geom.to_file(name)