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