unified style and other minor improvements
This commit is contained in:
parent
e72ae63873
commit
ebf20f2ebc
|
@ -1285,7 +1285,7 @@ def doSim(thread):
|
||||||
s.acquire()
|
s.acquire()
|
||||||
damask.util.croak('Reading values from simulation %i (%s)'%(loadNo,thread))
|
damask.util.croak('Reading values from simulation %i (%s)'%(loadNo,thread))
|
||||||
refFile = './postProc/%s_%i.txt'%(options.geometry,loadNo)
|
refFile = './postProc/%s_%i.txt'%(options.geometry,loadNo)
|
||||||
table = damask.ASCIItable(refFile)
|
table = damask.ASCIItable(refFile,readonly=True)
|
||||||
table.head_read()
|
table.head_read()
|
||||||
|
|
||||||
if options.fitting =='equivalentStrain':
|
if options.fitting =='equivalentStrain':
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
|
|
||||||
import os,sys,vtk
|
import os,sys,vtk
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
|
||||||
import damask
|
import damask
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
|
||||||
scriptID = '$Id$'
|
scriptID = '$Id$'
|
||||||
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# MAIN
|
# MAIN
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
@ -23,16 +23,16 @@ parser.add_option('-m', '--mode',
|
||||||
dest = 'mode',
|
dest = 'mode',
|
||||||
type = 'choice', choices = ['cell','point'],
|
type = 'choice', choices = ['cell','point'],
|
||||||
help = 'cell-centered or point-centered coordinates ')
|
help = 'cell-centered or point-centered coordinates ')
|
||||||
parser.add_option('-p', '--positions',
|
parser.add_option('-c', '--coordinates',
|
||||||
dest = 'position',
|
dest = 'position',
|
||||||
type = 'string', metavar = 'string',
|
type = 'string', metavar = 'string',
|
||||||
help = 'coordinate label [%default]')
|
help = 'coordinate label [%default]')
|
||||||
parser.set_defaults(position = 'pos',
|
parser.set_defaults(position ='ipinitialcoord',
|
||||||
|
mode ='cell'
|
||||||
)
|
)
|
||||||
|
|
||||||
(options, filenames) = parser.parse_args()
|
(options, filenames) = parser.parse_args()
|
||||||
|
|
||||||
if not options.mode: parser.error("No coordinate type specified.")
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
# --- loop over input files -------------------------------------------------------------------------
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
@ -42,23 +42,19 @@ for name in filenames:
|
||||||
table = damask.ASCIItable(name = name,
|
table = damask.ASCIItable(name = name,
|
||||||
buffered = False, readonly = True)
|
buffered = False, readonly = True)
|
||||||
except: continue
|
except: continue
|
||||||
damask.util.croak(damask.util.emph(scriptName)+(': '+name if name else ''))
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# --- interpret header ----------------------------------------------------------------------------
|
# --- interpret header ----------------------------------------------------------------------------
|
||||||
|
|
||||||
table.head_read()
|
table.head_read()
|
||||||
|
|
||||||
# ------------------------------------------ sanity checks ----------------------------------------
|
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
remarks = []
|
if table.label_dimension(options.position) != 3:
|
||||||
|
errors.append('coordinates {} are not a vector.'.format(options.position))
|
||||||
if table.label_dimension(options.position) != 3: errors.append('coordinates {} are not a vector.'.format(options.position))
|
|
||||||
|
|
||||||
if remarks != []: damask.util.croak(remarks)
|
|
||||||
if errors != []:
|
if errors != []:
|
||||||
damask.util.croak(errors)
|
damask.util.croak(errors)
|
||||||
table.close(dismiss = True)
|
table.close(dismiss=True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# --------------- figure out size and grid ---------------------------------------------------------
|
# --------------- figure out size and grid ---------------------------------------------------------
|
||||||
|
@ -96,30 +92,24 @@ for name in filenames:
|
||||||
rGrid.SetYCoordinates(coordArray[1])
|
rGrid.SetYCoordinates(coordArray[1])
|
||||||
rGrid.SetZCoordinates(coordArray[2])
|
rGrid.SetZCoordinates(coordArray[2])
|
||||||
|
|
||||||
damask.util.croak('{} points and {} cells...'.format(rGrid.GetNumberOfPoints(),rGrid.GetNumberOfCells(),))
|
|
||||||
|
|
||||||
# ------------------------------------------ output result ---------------------------------------
|
# ------------------------------------------ output result ---------------------------------------
|
||||||
|
|
||||||
if name:
|
if name:
|
||||||
(dir,filename) = os.path.split(name)
|
|
||||||
writer = vtk.vtkXMLRectilinearGridWriter()
|
writer = vtk.vtkXMLRectilinearGridWriter()
|
||||||
|
(directory,filename) = os.path.split(name)
|
||||||
writer.SetDataModeToBinary()
|
writer.SetDataModeToBinary()
|
||||||
writer.SetCompressorTypeToZLib()
|
writer.SetCompressorTypeToZLib()
|
||||||
writer.SetFileName(os.path.join(dir,os.path.splitext(filename)[0]+'_{}'.format(options.position) \
|
writer.SetFileName(os.path.join(directory,os.path.splitext(filename)[0]+'_{}'.format(options.mode) \
|
||||||
+'.'+writer.GetDefaultFileExtension()))
|
+'.'+writer.GetDefaultFileExtension()))
|
||||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(rGrid)
|
|
||||||
else: writer.SetInputData(rGrid)
|
|
||||||
writer.Write()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
writer = vtk.vtkRectilinearGridWriter()
|
writer = vtk.vtkDataSetWriter()
|
||||||
writer.WriteToOutputStringOn()
|
writer.WriteToOutputStringOn()
|
||||||
writer.SetFileTypeToASCII()
|
|
||||||
writer.SetHeader('# powered by '+scriptID)
|
writer.SetHeader('# powered by '+scriptID)
|
||||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(rGrid)
|
|
||||||
else: writer.SetInputData(rGrid)
|
|
||||||
writer.Write()
|
|
||||||
sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
|
||||||
|
|
||||||
table.close() # close input ASCII table
|
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(rGrid)
|
||||||
|
else: writer.SetInputData(rGrid)
|
||||||
|
writer.Write()
|
||||||
|
if name == None: sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
||||||
|
|
||||||
|
table.close()
|
||||||
|
|
|
@ -81,12 +81,13 @@ for name in filenames:
|
||||||
eulerangles = []
|
eulerangles = []
|
||||||
|
|
||||||
# --------------- read data -----------------------------------------------------------------------
|
# --------------- read data -----------------------------------------------------------------------
|
||||||
|
errors = []
|
||||||
while table.data_read():
|
while table.data_read():
|
||||||
words = table.data
|
words = table.data
|
||||||
if words[0] == '#': # process initial comments/header block
|
if words[0] == '#': # process initial comments/header block
|
||||||
if len(words) > 2:
|
if len(words) > 2:
|
||||||
if words[2].lower() == 'hexgrid':
|
if words[2].lower() == 'hexgrid':
|
||||||
damask.util.croak('The file has HexGrid format. Please first convert to SquareGrid...\n')
|
errors.append('The file has HexGrid format. Please first convert to SquareGrid...')
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
currPos = words[3:5]
|
currPos = words[3:5]
|
||||||
|
@ -98,7 +99,11 @@ for name in filenames:
|
||||||
pos['max'][i] = max(pos['max'][i],currPos[i])
|
pos['max'][i] = max(pos['max'][i],currPos[i])
|
||||||
eulerangles.append(map(math.degrees,map(float,words[:3])))
|
eulerangles.append(map(math.degrees,map(float,words[:3])))
|
||||||
phase.append(options.phase[int(float(words[options.column-1]) > options.threshold)])
|
phase.append(options.phase[int(float(words[options.column-1]) > options.threshold)])
|
||||||
|
|
||||||
|
if errors != []:
|
||||||
|
damask.util.croak(errors)
|
||||||
|
continue
|
||||||
|
|
||||||
# --------------- determine size and grid ---------------------------------------------------------
|
# --------------- determine size and grid ---------------------------------------------------------
|
||||||
info['grid'] = np.array(map(len,coords),'i')
|
info['grid'] = np.array(map(len,coords),'i')
|
||||||
info['size'][0:2] = info['grid'][0:2]/(info['grid'][0:2]-1.0)* \
|
info['size'][0:2] = info['grid'][0:2]/(info['grid'][0:2]-1.0)* \
|
||||||
|
@ -110,12 +115,15 @@ for name in filenames:
|
||||||
|
|
||||||
limits = [360,180,360]
|
limits = [360,180,360]
|
||||||
if any([np.any(eulerangles[:,i]>=limits[i]) for i in [0,1,2]]):
|
if any([np.any(eulerangles[:,i]>=limits[i]) for i in [0,1,2]]):
|
||||||
damask.util.croak('Error: euler angles out of bound. Ang file might contain unidexed poins.\n')
|
errors.append('Error: euler angles out of bound. Ang file might contain unidexed poins.')
|
||||||
for i,angle in enumerate(['phi1','PHI','phi2']):
|
for i,angle in enumerate(['phi1','PHI','phi2']):
|
||||||
for n in np.nditer(np.where(eulerangles[:,i]>=limits[i]),['zerosize_ok']):
|
for n in np.nditer(np.where(eulerangles[:,i]>=limits[i]),['zerosize_ok']):
|
||||||
damask.util.croak('%s in line %i (%4.2f %4.2f %4.2f)\n'
|
errors.append('%s in line %i (%4.2f %4.2f %4.2f)\n'
|
||||||
%(angle,n,eulerangles[n,0],eulerangles[n,1],eulerangles[n,2]))
|
%(angle,n,eulerangles[n,0],eulerangles[n,1],eulerangles[n,2]))
|
||||||
|
if errors != []:
|
||||||
|
damask.util.croak(errors)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
eulerangles=np.around(eulerangles,int(options.precision)) # round to desired precision
|
eulerangles=np.around(eulerangles,int(options.precision)) # round to desired precision
|
||||||
for i,angle in enumerate(['phi1','PHI','phi2']):
|
for i,angle in enumerate(['phi1','PHI','phi2']):
|
||||||
eulerangles[:,i]%=limits[i] # ensure, that rounded euler angles are not out of bounds (modulo by limits)
|
eulerangles[:,i]%=limits[i] # ensure, that rounded euler angles are not out of bounds (modulo by limits)
|
||||||
|
|
Loading…
Reference in New Issue