some more syntax improvements
This commit is contained in:
parent
043f2faeb3
commit
974b8cde41
|
@ -1,16 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
'''
|
import sys,os,re
|
||||||
Writes meaningful labels to the Abaqus input file (*.inp)
|
|
||||||
based on the files
|
|
||||||
<modelname_jobname>.output<Homogenization/Crystallite/Constitutive>
|
|
||||||
that are written during the first run of the model.
|
|
||||||
See Abaqus Keyword Reference Manual (AKRM) *DEPVAR for details.
|
|
||||||
Original script: marc_addUserOutput.py modified by Benjamin Bode
|
|
||||||
'''
|
|
||||||
|
|
||||||
import sys,os,re,string
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
|
@ -19,7 +10,6 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
def ParseOutputFormat(filename,what,me):
|
def ParseOutputFormat(filename,what,me):
|
||||||
# -----------------------------
|
|
||||||
format = {'outputs':{},'specials':{'brothers':[]}}
|
format = {'outputs':{},'specials':{'brothers':[]}}
|
||||||
|
|
||||||
outputmetafile = filename+'.output'+what
|
outputmetafile = filename+'.output'+what
|
||||||
|
@ -120,7 +110,7 @@ for file in files:
|
||||||
|
|
||||||
for what in me:
|
for what in me:
|
||||||
outputFormat[what] = ParseOutputFormat(formatFile,what,me[what])
|
outputFormat[what] = ParseOutputFormat(formatFile,what,me[what])
|
||||||
if not '_id' in outputFormat[what]['specials']:
|
if '_id' not in outputFormat[what]['specials']:
|
||||||
print "'%s' not found in <%s>"%(me[what],what)
|
print "'%s' not found in <%s>"%(me[what],what)
|
||||||
print '\n'.join(map(lambda x:' '+x,outputFormat[what]['specials']['brothers']))
|
print '\n'.join(map(lambda x:' '+x,outputFormat[what]['specials']['brothers']))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -164,19 +154,14 @@ for file in files:
|
||||||
if m:
|
if m:
|
||||||
lastSection = thisSection
|
lastSection = thisSection
|
||||||
thisSection = m.group(1)
|
thisSection = m.group(1)
|
||||||
#Abaqus keyword can be upper or lower case
|
if (lastSection.upper() == '*DEPVAR' and thisSection.upper() == '*USER'): #Abaqus keyword can be upper or lower case
|
||||||
if (lastSection.upper() == '*DEPVAR' and thisSection.upper() == '*USER'):
|
|
||||||
#Abaqus SDVs are named SDV1...SDVn if no specific name is given
|
|
||||||
#Abaqus needs total number of SDVs in the line after *Depvar keyword
|
|
||||||
if options.number > 0:
|
if options.number > 0:
|
||||||
#number of SDVs
|
output.write('%i\n'%options.number) #Abaqus needs total number of SDVs in the line after *Depvar keyword
|
||||||
output.write('%i\n'%options.number)
|
|
||||||
else:
|
else:
|
||||||
#number of SDVs
|
|
||||||
output.write('%i\n'%len(UserVars))
|
output.write('%i\n'%len(UserVars))
|
||||||
#index,output variable key,output variable description
|
|
||||||
for i in range(len(UserVars)):
|
for i in range(len(UserVars)):
|
||||||
output.write('%i,"%i%s","%i%s"\n'%(i+1,0,UserVars[i],0,UserVars[i]))
|
output.write('%i,"%i%s","%i%s"\n'%(i+1,0,UserVars[i],0,UserVars[i])) #index,output variable key,output variable description
|
||||||
if (thisSection.upper() != '*DEPVAR' or not re.match('\s*\d',line)):
|
if (thisSection.upper() != '*DEPVAR' or not re.match('\s*\d',line)):
|
||||||
output.write(line)
|
output.write(line)
|
||||||
output.close()
|
output.close()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,math,string
|
import os,sys,math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import damask
|
import damask
|
||||||
|
@ -114,7 +114,7 @@ for name in filenames:
|
||||||
|
|
||||||
microstructure = microstructure.reshape(info['grid'],order='F')
|
microstructure = microstructure.reshape(info['grid'],order='F')
|
||||||
|
|
||||||
if options.dimension != None:
|
if options.dimension is not None:
|
||||||
mask = (np.array(options.dimension) < 0).astype(float) # zero where positive dimension, otherwise one
|
mask = (np.array(options.dimension) < 0).astype(float) # zero where positive dimension, otherwise one
|
||||||
dim = abs(np.array(options.dimension)) # dimensions of primitive body
|
dim = abs(np.array(options.dimension)) # dimensions of primitive body
|
||||||
pos = np.zeros(3,dtype='float')
|
pos = np.zeros(3,dtype='float')
|
||||||
|
@ -134,10 +134,9 @@ for name in filenames:
|
||||||
|
|
||||||
|
|
||||||
# --- report ---------------------------------------------------------------------------------------
|
# --- report ---------------------------------------------------------------------------------------
|
||||||
|
if ( newInfo['microstructures'] != info['microstructures']):
|
||||||
|
damask.util.croak('--> microstructures: %i'%newInfo['microstructures'])
|
||||||
|
|
||||||
remarks = []
|
|
||||||
if ( newInfo['microstructures'] != info['microstructures']): remarks.append('--> microstructures: %i'%newInfo['microstructures'])
|
|
||||||
if remarks != []: damask.util.croak(remarks)
|
|
||||||
|
|
||||||
#--- write header ---------------------------------------------------------------------------------
|
#--- write header ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,math,string
|
import os,sys,math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import damask
|
import damask
|
||||||
|
@ -81,7 +81,8 @@ for name in filenames:
|
||||||
'microstructures': 0,
|
'microstructures': 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
newInfo['grid'] = np.array([int(o*float(n.translate(None,'xX'))) if n[-1].lower() == 'x' else int(n) for o,n in zip(info['grid'],options.grid)],'i')
|
newInfo['grid'] = np.array([int(o*float(n.translate(None,'xX'))) if n[-1].lower() == 'x'\
|
||||||
|
else int(n) for o,n in zip(info['grid'],options.grid)],'i')
|
||||||
newInfo['grid'] = np.where(newInfo['grid'] > 0, newInfo['grid'],info['grid'])
|
newInfo['grid'] = np.where(newInfo['grid'] > 0, newInfo['grid'],info['grid'])
|
||||||
|
|
||||||
microstructure_cropped = np.zeros(newInfo['grid'],'i')
|
microstructure_cropped = np.zeros(newInfo['grid'],'i')
|
||||||
|
@ -143,7 +144,7 @@ for name in filenames:
|
||||||
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=newInfo['origin']),
|
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=newInfo['origin']),
|
||||||
"homogenization\t{homog}".format(homog=info['homogenization']),
|
"homogenization\t{homog}".format(homog=info['homogenization']),
|
||||||
"microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']),
|
"microstructures\t{microstructures}".format(microstructures=newInfo['microstructures']),
|
||||||
extra_header
|
extra_header
|
||||||
])
|
])
|
||||||
table.labels_clear()
|
table.labels_clear()
|
||||||
table.head_write()
|
table.head_write()
|
||||||
|
|
|
@ -1,7 +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,sys,vtk
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import damask
|
import damask
|
||||||
|
@ -91,8 +91,7 @@ for name in filenames:
|
||||||
(directory,filename) = os.path.split(name)
|
(directory,filename) = os.path.split(name)
|
||||||
writer.SetDataModeToBinary()
|
writer.SetDataModeToBinary()
|
||||||
writer.SetCompressorTypeToZLib()
|
writer.SetCompressorTypeToZLib()
|
||||||
writer.SetFileName(os.path.join(directory,os.path.splitext(filename)[0]
|
writer.SetFileName(os.path.join(directory,os.path.splitext(filename)[0]+'.'+writer.GetDefaultFileExtension()))
|
||||||
+'.'+writer.GetDefaultFileExtension()))
|
|
||||||
else:
|
else:
|
||||||
writer = vtk.vtkDataSetWriter()
|
writer = vtk.vtkDataSetWriter()
|
||||||
writer.WriteToOutputStringOn()
|
writer.WriteToOutputStringOn()
|
||||||
|
@ -101,6 +100,6 @@ for name in filenames:
|
||||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
||||||
else: writer.SetInputData(grid)
|
else: writer.SetInputData(grid)
|
||||||
writer.Write()
|
writer.Write()
|
||||||
if name == None: sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
if name is None: sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
||||||
|
|
||||||
table.close()
|
table.close()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,string,math
|
import os,sys,math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import damask
|
import damask
|
||||||
from scipy import ndimage
|
from scipy import ndimage
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,string,math,itertools
|
import os,sys,math,itertools
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy import ndimage
|
from scipy import ndimage
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,math,string
|
import os,sys,math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from PIL import Image,ImageOps
|
from PIL import Image
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
|
@ -51,7 +51,7 @@ for name in filenames:
|
||||||
try:
|
try:
|
||||||
img.seek(slice) # advance to slice
|
img.seek(slice) # advance to slice
|
||||||
layer = np.expand_dims(1+np.array(img,dtype = 'uint16'),axis = 0) # read image layer
|
layer = np.expand_dims(1+np.array(img,dtype = 'uint16'),axis = 0) # read image layer
|
||||||
microstructure = layer if slice == 0 else np.vstack((microstructure,layer)) # add to microstructure data
|
microstructure = layer if slice == 0 else np.vstack((microstructure,layer)) # noqa
|
||||||
slice += 1 # advance to next slice
|
slice += 1 # advance to next slice
|
||||||
except EOFError:
|
except EOFError:
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,string,math
|
import os,sys,math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import damask
|
import damask
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,string,math
|
import os,sys,math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import damask
|
import damask
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,string
|
import os,sys
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import damask
|
import damask
|
||||||
|
|
Loading…
Reference in New Issue