unified style and other minor improvements
This commit is contained in:
parent
e72ae63873
commit
ebf20f2ebc
|
@ -1285,7 +1285,7 @@ def doSim(thread):
|
|||
s.acquire()
|
||||
damask.util.croak('Reading values from simulation %i (%s)'%(loadNo,thread))
|
||||
refFile = './postProc/%s_%i.txt'%(options.geometry,loadNo)
|
||||
table = damask.ASCIItable(refFile)
|
||||
table = damask.ASCIItable(refFile,readonly=True)
|
||||
table.head_read()
|
||||
|
||||
if options.fitting =='equivalentStrain':
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
import os,sys,vtk
|
||||
import numpy as np
|
||||
from optparse import OptionParser
|
||||
import damask
|
||||
from optparse import OptionParser
|
||||
|
||||
|
||||
scriptID = '$Id$'
|
||||
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# MAIN
|
||||
# --------------------------------------------------------------------
|
||||
|
@ -23,16 +23,16 @@ parser.add_option('-m', '--mode',
|
|||
dest = 'mode',
|
||||
type = 'choice', choices = ['cell','point'],
|
||||
help = 'cell-centered or point-centered coordinates ')
|
||||
parser.add_option('-p', '--positions',
|
||||
parser.add_option('-c', '--coordinates',
|
||||
dest = 'position',
|
||||
type = 'string', metavar = 'string',
|
||||
help = 'coordinate label [%default]')
|
||||
parser.set_defaults(position = 'pos',
|
||||
parser.set_defaults(position ='ipinitialcoord',
|
||||
mode ='cell'
|
||||
)
|
||||
|
||||
(options, filenames) = parser.parse_args()
|
||||
|
||||
if not options.mode: parser.error("No coordinate type specified.")
|
||||
# --- loop over input files -------------------------------------------------------------------------
|
||||
|
||||
if filenames == []: filenames = [None]
|
||||
|
@ -42,23 +42,19 @@ for name in filenames:
|
|||
table = damask.ASCIItable(name = name,
|
||||
buffered = False, readonly = True)
|
||||
except: continue
|
||||
damask.util.croak(damask.util.emph(scriptName)+(': '+name if name else ''))
|
||||
damask.util.report(scriptName,name)
|
||||
|
||||
# --- interpret header ----------------------------------------------------------------------------
|
||||
|
||||
table.head_read()
|
||||
|
||||
# ------------------------------------------ sanity checks ----------------------------------------
|
||||
errors = []
|
||||
if table.label_dimension(options.position) != 3:
|
||||
errors.append('coordinates {} are not a vector.'.format(options.position))
|
||||
|
||||
errors = []
|
||||
remarks = []
|
||||
|
||||
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 != []:
|
||||
damask.util.croak(errors)
|
||||
table.close(dismiss = True)
|
||||
table.close(dismiss=True)
|
||||
continue
|
||||
|
||||
# --------------- figure out size and grid ---------------------------------------------------------
|
||||
|
@ -96,30 +92,24 @@ for name in filenames:
|
|||
rGrid.SetYCoordinates(coordArray[1])
|
||||
rGrid.SetZCoordinates(coordArray[2])
|
||||
|
||||
damask.util.croak('{} points and {} cells...'.format(rGrid.GetNumberOfPoints(),rGrid.GetNumberOfCells(),))
|
||||
|
||||
# ------------------------------------------ output result ---------------------------------------
|
||||
|
||||
if name:
|
||||
(dir,filename) = os.path.split(name)
|
||||
writer = vtk.vtkXMLRectilinearGridWriter()
|
||||
(directory,filename) = os.path.split(name)
|
||||
writer.SetDataModeToBinary()
|
||||
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()))
|
||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(rGrid)
|
||||
else: writer.SetInputData(rGrid)
|
||||
writer.Write()
|
||||
|
||||
else:
|
||||
writer = vtk.vtkRectilinearGridWriter()
|
||||
writer = vtk.vtkDataSetWriter()
|
||||
writer.WriteToOutputStringOn()
|
||||
writer.SetFileTypeToASCII()
|
||||
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 = []
|
||||
|
||||
# --------------- read data -----------------------------------------------------------------------
|
||||
errors = []
|
||||
while table.data_read():
|
||||
words = table.data
|
||||
if words[0] == '#': # process initial comments/header block
|
||||
if len(words) > 2:
|
||||
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
|
||||
else:
|
||||
currPos = words[3:5]
|
||||
|
@ -99,6 +100,10 @@ for name in filenames:
|
|||
eulerangles.append(map(math.degrees,map(float,words[:3])))
|
||||
phase.append(options.phase[int(float(words[options.column-1]) > options.threshold)])
|
||||
|
||||
if errors != []:
|
||||
damask.util.croak(errors)
|
||||
continue
|
||||
|
||||
# --------------- determine size and grid ---------------------------------------------------------
|
||||
info['grid'] = np.array(map(len,coords),'i')
|
||||
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]
|
||||
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 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]))
|
||||
if errors != []:
|
||||
damask.util.croak(errors)
|
||||
continue
|
||||
|
||||
eulerangles=np.around(eulerangles,int(options.precision)) # round to desired precision
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue