cleaning
This commit is contained in:
parent
76a0a93c42
commit
a51f2a29f6
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 no BOM -*-
|
||||
|
||||
import os,sys,string,vtk
|
||||
import numpy as np
|
||||
import os
|
||||
from optparse import OptionParser
|
||||
import damask
|
||||
|
||||
|
@ -48,7 +47,7 @@ for name in filenames:
|
|||
table.labels_append(['1_Euler','2_Euler','3_Euler',
|
||||
'1_pos','2_pos',
|
||||
'IQ','CI','PhaseID','Intensity','Fit',
|
||||
], # labels according to OIM Analysis 7.2 Manual, p 403 (of 517)
|
||||
], # OIM Analysis 7.2 Manual, p 403 (of 517)
|
||||
reset = True)
|
||||
|
||||
# ------------------------------------------ assemble header ---------------------------------------
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 no BOM -*-
|
||||
|
||||
import threading,time,os,subprocess,shlex,string
|
||||
import threading,os,string
|
||||
import numpy as np
|
||||
from optparse import OptionParser, OptionGroup
|
||||
from optparse import OptionParser
|
||||
from shutil import copy2
|
||||
from re import split
|
||||
import damask
|
||||
|
@ -14,26 +14,10 @@ scriptID = ' '.join([scriptName,damask.version])
|
|||
def list_split(option, opt, value, parser):
|
||||
setattr(parser.values, option.dest, value.split(','))
|
||||
|
||||
def execute(cmd,streamIn=None,wd='./'):
|
||||
'''
|
||||
executes a command in given directory and returns stdout and stderr for optional stdin
|
||||
'''
|
||||
initialPath=os.getcwd()
|
||||
os.chdir(wd)
|
||||
process = subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr = subprocess.PIPE,stdin=subprocess.PIPE)
|
||||
if streamIn != None:
|
||||
out,error = process.communicate(streamIn.read())
|
||||
else:
|
||||
out,error = process.communicate()
|
||||
os.chdir(initialPath)
|
||||
return out,error
|
||||
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
class myThread (threading.Thread):
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
'''
|
||||
Runner class
|
||||
'''
|
||||
"""Runner"""
|
||||
|
||||
def __init__(self, threadID):
|
||||
threading.Thread.__init__(self)
|
||||
self.threadID = threadID
|
||||
|
@ -48,8 +32,6 @@ class myThread (threading.Thread):
|
|||
s.release()
|
||||
|
||||
def doSim(delay,thread):
|
||||
# s.acquire() and s.release() are couple
|
||||
#
|
||||
global dirCurrent
|
||||
s.acquire()
|
||||
delta_angle = offsetPhi()
|
||||
|
@ -63,22 +45,22 @@ def doSim(delay,thread):
|
|||
os.mkdir(dire,0755)
|
||||
for file in [options.geometry+'.geom',options.load+'.load','numerics.config']:
|
||||
copy2(dirCurrent+'/'+file, dire)
|
||||
newMatConfig = newMaterialConfig(dirCurrent,delta_angle)
|
||||
newMaterialConfig(dirCurrent,delta_angle)
|
||||
|
||||
os.chdir(dire)
|
||||
if not os.path.isfile('%s_%s.spectralOut'%(options.geometry,options.load)):
|
||||
print('starting uniaxial tension in direction of angle %s from %s'%(file_angle,thread))
|
||||
s.release()
|
||||
execute('DAMASK_spectral -g %s -l %s'%(options.geometry,options.load))
|
||||
damask.util.execute('DAMASK_spectral -g %s -l %s'%(options.geometry,options.load))
|
||||
else: s.release()
|
||||
|
||||
s.acquire()
|
||||
if not os.path.isfile('./%s/%s_%s.txt'%('Rvalues',options.geometry,options.load)):
|
||||
print('starting post processing for angle %s from %s'%(file_angle,thread))
|
||||
s.release()
|
||||
execute('postResults --cr f,p -d %s %s_%s.spectralOut'%('Rvalues',options.geometry,options.load))
|
||||
execute('addCauchy ./%s/%s_%s.txt'%('Rvalues',options.geometry,options.load))
|
||||
execute('addStrainTensors -l -v ./%s/%s_%s.txt'%('Rvalues',options.geometry,options.load))
|
||||
damask.util.execute('postResults --cr f,p -d %s %s_%s.spectralOut'%('Rvalues',options.geometry,options.load))
|
||||
damask.util.execute('addCauchy ./%s/%s_%s.txt'%('Rvalues',options.geometry,options.load))
|
||||
damask.util.execute('addStrainTensors -l -v ./%s/%s_%s.txt'%('Rvalues',options.geometry,options.load))
|
||||
print('post processing for angle %s from %s is finished'%(file_angle,thread))
|
||||
|
||||
else:
|
||||
|
@ -122,7 +104,6 @@ def newMaterialConfig(dire,angle):
|
|||
line2 = line
|
||||
f.write(line2)
|
||||
f.close()
|
||||
return True
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# MAIN
|
||||
|
@ -135,15 +116,20 @@ strength anisotropic coefficients (normalized yield stress)
|
|||
""", version=string.replace(scriptID,'\n','\\n')
|
||||
)
|
||||
|
||||
parser.add_option('-l','--load' , dest='load', type='string',
|
||||
parser.add_option('-l','--load' ,
|
||||
dest='load', type='string',
|
||||
help='name of the load file [%default]', metavar='string')
|
||||
parser.add_option('-g','--geometry', dest='geometry', type='string',
|
||||
parser.add_option('-g','--geometry',
|
||||
dest='geometry', type='string',
|
||||
help='name of the geometry file [%default]', metavar='string')
|
||||
parser.add_option('-s', '--strain', dest='strain', type='string', action='callback', callback=list_split,
|
||||
help='the threshold strains, using comma to seperate multiple strains [%default]', metavar='string')
|
||||
parser.add_option('-t','--threads', dest='threads', type='int',
|
||||
parser.add_option('-s', '--strain',
|
||||
dest='strain', type='string', action='callback', callback=list_split,
|
||||
help='threshold strains, using comma to seperate multiple strains [%default]', metavar='string')
|
||||
parser.add_option('-t','--threads',
|
||||
dest='threads', type='int',
|
||||
help='number of parallel executions [%default]', metavar='int')
|
||||
parser.add_option('-n','--number', dest='number', type='int',
|
||||
parser.add_option('-n','--number',
|
||||
dest='number', type='int',
|
||||
help='Number of uni-axial tensile tests [%default]', metavar='int')
|
||||
|
||||
parser.set_defaults(geometry = '20grains16x16x16')
|
||||
|
|
|
@ -1,33 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 no BOM -*-
|
||||
|
||||
import os,sys,string,re,numpy,scipy.ndimage,scipy.signal,vtk
|
||||
import os,string,scipy
|
||||
import numpy as np
|
||||
import damask
|
||||
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
||||
from optparse import OptionParser
|
||||
|
||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||
scriptID = ' '.join([scriptName,damask.version])
|
||||
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
class extendedOption(Option):
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
# 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
|
||||
|
||||
ACTIONS = Option.ACTIONS + ("extend",)
|
||||
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
||||
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
||||
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
||||
|
||||
def take_action(self, action, dest, opt, value, values, parser):
|
||||
if action == "extend":
|
||||
lvalue = value.split(",")
|
||||
values.ensure_value(dest, []).extend(lvalue)
|
||||
else:
|
||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
||||
|
||||
|
||||
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
|
||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||
Apply filter(s) to Gwyddion data.
|
||||
""" + string.replace(scriptID,'\n','\\n')
|
||||
)
|
||||
|
@ -59,7 +41,7 @@ for file in filenames:
|
|||
if pieces[1] == 'Height:': height = float(pieces[2])
|
||||
header.append(line.lstrip('#').strip())
|
||||
|
||||
elevation = numpy.loadtxt(file)#*1e6
|
||||
elevation = np.loadtxt(file)#*1e6
|
||||
|
||||
if options.opening > 0:
|
||||
elevation = scipy.ndimage.morphology.grey_opening(elevation,options.opening)
|
||||
|
@ -80,5 +62,5 @@ for file in filenames:
|
|||
elevation = scipy.ndimage.filters.median_filter(elevation,options.median)
|
||||
filters += '_median%i'%options.median
|
||||
|
||||
numpy.savetxt(os.path.splitext(file)[0]+filters+os.path.splitext(file)[1],elevation,header='\n'.join(header))
|
||||
np.savetxt(os.path.splitext(file)[0]+filters+os.path.splitext(file)[1],elevation,header='\n'.join(header))
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 no BOM -*-
|
||||
|
||||
import os,sys,string,re,numpy,scipy.ndimage,scipy.signal,vtk
|
||||
import os,string,vtk
|
||||
import numpy as np
|
||||
import damask
|
||||
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
||||
from optparse import OptionParser
|
||||
|
||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||
scriptID = ' '.join([scriptName,damask.version])
|
||||
|
@ -26,26 +27,7 @@ scalingFactor = { \
|
|||
},
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
class extendedOption(Option):
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
# 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
|
||||
|
||||
ACTIONS = Option.ACTIONS + ("extend",)
|
||||
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
||||
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
||||
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
||||
|
||||
def take_action(self, action, dest, opt, value, values, parser):
|
||||
if action == "extend":
|
||||
lvalue = value.split(",")
|
||||
values.ensure_value(dest, []).extend(lvalue)
|
||||
else:
|
||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
||||
|
||||
|
||||
parser = OptionParser(option_class=extendedOption, usage='%prog options [file[s]]', description = """
|
||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||
Produce VTK rectilinear grid from Gwyddion dataset exported as text.
|
||||
""" + string.replace(scriptID,'\n','\\n')
|
||||
)
|
||||
|
@ -78,16 +60,16 @@ for file in filenames:
|
|||
if options.scaling == 0.0:
|
||||
options.scaling = scalingFactor[lateralunit][elevationunit]
|
||||
|
||||
elevation = numpy.loadtxt(file)*options.scaling
|
||||
elevation = np.loadtxt(file)*options.scaling
|
||||
|
||||
grid = vtk.vtkRectilinearGrid()
|
||||
grid.SetDimensions(elevation.shape[1],elevation.shape[0],1)
|
||||
|
||||
xCoords = vtk.vtkDoubleArray()
|
||||
for x in numpy.arange(0.0,width,width/elevation.shape[1],'d'):
|
||||
for x in np.arange(0.0,width,width/elevation.shape[1],'d'):
|
||||
xCoords.InsertNextValue(x)
|
||||
yCoords = vtk.vtkDoubleArray()
|
||||
for y in numpy.arange(0.0,height,height/elevation.shape[0],'d'):
|
||||
for y in np.arange(0.0,height,height/elevation.shape[0],'d'):
|
||||
yCoords.InsertNextValue(y)
|
||||
zCoords = vtk.vtkDoubleArray()
|
||||
zCoords.InsertNextValue(0.0)
|
||||
|
@ -99,8 +81,8 @@ for file in filenames:
|
|||
vector = vtk.vtkFloatArray()
|
||||
vector.SetName("elevation");
|
||||
vector.SetNumberOfComponents(3);
|
||||
vector.SetNumberOfTuples(numpy.prod(elevation.shape));
|
||||
for i,z in enumerate(numpy.ravel(elevation)):
|
||||
vector.SetNumberOfTuples(np.prod(elevation.shape));
|
||||
for i,z in enumerate(np.ravel(elevation)):
|
||||
vector.SetTuple3(i,0,0,z)
|
||||
|
||||
grid.GetPointData().AddArray(vector)
|
||||
|
|
Loading…
Reference in New Issue