removed code doubling
This commit is contained in:
parent
6d74cbf374
commit
61090c955d
|
@ -227,15 +227,8 @@ class Test():
|
||||||
|
|
||||||
def execute_inCurrentDir(self,cmd,streamIn=None):
|
def execute_inCurrentDir(self,cmd,streamIn=None):
|
||||||
|
|
||||||
initialPath=os.getcwd()
|
|
||||||
os.chdir(self.dirCurrent())
|
|
||||||
logging.info(cmd)
|
logging.info(cmd)
|
||||||
process = subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr = subprocess.PIPE,stdin=subprocess.PIPE)
|
out,error = damask.util.execute(cmd,streamIn,self.dirCurrent())
|
||||||
if streamIn != None:
|
|
||||||
out,error = process.communicate(streamIn.read())
|
|
||||||
else:
|
|
||||||
out,error = process.communicate()
|
|
||||||
os.chdir(initialPath)
|
|
||||||
|
|
||||||
logging.info(error)
|
logging.info(error)
|
||||||
logging.debug(out)
|
logging.debug(out)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
# damask utility functions
|
# damask utility functions
|
||||||
import sys,time,random,threading
|
import sys,time,random,threading,os,subprocess,shlex
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser, Option
|
from optparse import Option
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
def croak(what,
|
def croak(what,
|
||||||
|
@ -398,3 +398,20 @@ def curve_fit_bound(f, xdata, ydata, p0=None, sigma=None, bounds=None, **kw):
|
||||||
return popt, pcov, infodict, errmsg, ier
|
return popt, pcov, infodict, errmsg, ier
|
||||||
else:
|
else:
|
||||||
return popt, pcov
|
return popt, pcov
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import damask
|
||||||
from damask.util import leastsqBound
|
from damask.util import leastsqBound
|
||||||
|
|
||||||
scriptID = string.replace('$Id$','\n','\\n')
|
scriptID = string.replace('$Id$','\n','\\n')
|
||||||
scriptName = scriptID.split()[1][:-3]
|
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
||||||
|
|
||||||
def runFit(exponent, eqStress, dimension, criterion):
|
def runFit(exponent, eqStress, dimension, criterion):
|
||||||
global s, threads, myFit
|
global s, threads, myFit
|
||||||
|
@ -48,21 +48,6 @@ def runFit(exponent, eqStress, dimension, criterion):
|
||||||
threads[i].join()
|
threads[i].join()
|
||||||
print fitResidual
|
print fitResidual
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def principalStresses(sigmas):
|
def principalStresses(sigmas):
|
||||||
'''
|
'''
|
||||||
computes principal stresses (i.e. eigenvalues) for a set of Cauchy stresses.
|
computes principal stresses (i.e. eigenvalues) for a set of Cauchy stresses.
|
||||||
|
@ -163,16 +148,6 @@ def sym6to33(sigma6):
|
||||||
sigma33[2,0] = sigma6[5]; sigma33[0,2] = sigma6[5]
|
sigma33[2,0] = sigma6[5]; sigma33[0,2] = sigma6[5]
|
||||||
return sigma33
|
return sigma33
|
||||||
|
|
||||||
def array2tuple(array):
|
|
||||||
'''transform numpy.array into tuple'''
|
|
||||||
try:
|
|
||||||
return tuple(array2tuple(i) for i in array)
|
|
||||||
except TypeError:
|
|
||||||
return array
|
|
||||||
def get_weight(ndim):
|
|
||||||
#more to do
|
|
||||||
return np.ones(ndim)
|
|
||||||
|
|
||||||
|
|
||||||
class Criteria(object):
|
class Criteria(object):
|
||||||
'''
|
'''
|
||||||
|
@ -1243,7 +1218,7 @@ def doSim(delay,thread):
|
||||||
if not os.path.isfile('%s_%i.spectralOut'%(options.geometry,loadNo)):
|
if not os.path.isfile('%s_%i.spectralOut'%(options.geometry,loadNo)):
|
||||||
print('starting simulation %s from %s'%(loadNo,thread))
|
print('starting simulation %s from %s'%(loadNo,thread))
|
||||||
s.release()
|
s.release()
|
||||||
execute('DAMASK_spectral -g %s -l %i'%(options.geometry,loadNo))
|
damask.util.execute('DAMASK_spectral -g %s -l %i'%(options.geometry,loadNo))
|
||||||
else: s.release()
|
else: s.release()
|
||||||
|
|
||||||
s.acquire()
|
s.acquire()
|
||||||
|
@ -1251,12 +1226,12 @@ def doSim(delay,thread):
|
||||||
print('starting post processing for sim %i from %s'%(loadNo,thread))
|
print('starting post processing for sim %i from %s'%(loadNo,thread))
|
||||||
s.release()
|
s.release()
|
||||||
try:
|
try:
|
||||||
execute('postResults --cr f,p --co totalshear %s_%i.spectralOut'%(options.geometry,loadNo))
|
damask.util.execute('postResults --cr f,p --co totalshear %s_%i.spectralOut'%(options.geometry,loadNo))
|
||||||
except:
|
except:
|
||||||
execute('postResults --cr f,p %s_%i.spectralOut'%(options.geometry,loadNo))
|
damask.util.execute('postResults --cr f,p %s_%i.spectralOut'%(options.geometry,loadNo))
|
||||||
execute('addCauchy ./postProc/%s_%i.txt'%(options.geometry,loadNo))
|
damask.util.execute('addCauchy ./postProc/%s_%i.txt'%(options.geometry,loadNo))
|
||||||
execute('addStrainTensors -l -v ./postProc/%s_%i.txt'%(options.geometry,loadNo))
|
damask.util.execute('addStrainTensors -l -v ./postProc/%s_%i.txt'%(options.geometry,loadNo))
|
||||||
execute('addMises -s Cauchy -e ln(V) ./postProc/%s_%i.txt'%(options.geometry,loadNo))
|
damask.util.execute('addMises -s Cauchy -e ln(V) ./postProc/%s_%i.txt'%(options.geometry,loadNo))
|
||||||
else: s.release()
|
else: s.release()
|
||||||
|
|
||||||
s.acquire()
|
s.acquire()
|
||||||
|
@ -1264,7 +1239,7 @@ def doSim(delay,thread):
|
||||||
print('reading values for sim %i from %s'%(loadNo,thread))
|
print('reading values for sim %i from %s'%(loadNo,thread))
|
||||||
s.release()
|
s.release()
|
||||||
|
|
||||||
refFile = open('./postProc/%s_%i.txt'%(options.geometry,loadNo))
|
refFile = './postProc/%s_%i.txt'%(options.geometry,loadNo)
|
||||||
table = damask.ASCIItable(refFile)
|
table = damask.ASCIItable(refFile)
|
||||||
table.head_read()
|
table.head_read()
|
||||||
if options.fitting =='equivalentStrain':
|
if options.fitting =='equivalentStrain':
|
||||||
|
|
|
@ -14,21 +14,6 @@ scriptName = os.path.splitext(scriptID.split()[1])[0]
|
||||||
mismatch = None
|
mismatch = None
|
||||||
currentSeedsName = None
|
currentSeedsName = None
|
||||||
|
|
||||||
def execute(cmd,streamIn=None,dir='./'):
|
|
||||||
'''
|
|
||||||
executes a command in given directory and returns stdout and stderr for optional stdin
|
|
||||||
'''
|
|
||||||
initialPath=os.getcwd()
|
|
||||||
os.chdir(dir)
|
|
||||||
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):
|
||||||
#---------------------------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------------------------
|
||||||
|
@ -113,7 +98,7 @@ class myThread (threading.Thread):
|
||||||
perturbedGeomVFile.close()
|
perturbedGeomVFile.close()
|
||||||
perturbedGeomVFile = StringIO()
|
perturbedGeomVFile = StringIO()
|
||||||
perturbedSeedsVFile.reset()
|
perturbedSeedsVFile.reset()
|
||||||
perturbedGeomVFile.write(execute('geom_fromVoronoiTessellation '+
|
perturbedGeomVFile.write(damask.util.execute('geom_fromVoronoiTessellation '+
|
||||||
' -g '+' '.join(map(str, options.grid)),streamIn=perturbedSeedsVFile)[0])
|
' -g '+' '.join(map(str, options.grid)),streamIn=perturbedSeedsVFile)[0])
|
||||||
perturbedGeomVFile.reset()
|
perturbedGeomVFile.reset()
|
||||||
|
|
||||||
|
@ -257,7 +242,7 @@ if os.path.isfile(os.path.splitext(options.seedFile)[0]+'.seeds'):
|
||||||
with open(os.path.splitext(options.seedFile)[0]+'.seeds') as initialSeedFile:
|
with open(os.path.splitext(options.seedFile)[0]+'.seeds') as initialSeedFile:
|
||||||
for line in initialSeedFile: bestSeedsVFile.write(line)
|
for line in initialSeedFile: bestSeedsVFile.write(line)
|
||||||
else:
|
else:
|
||||||
bestSeedsVFile.write(execute('seeds_fromRandom'+\
|
bestSeedsVFile.write(damask.util.execute('seeds_fromRandom'+\
|
||||||
' -g '+' '.join(map(str, options.grid))+\
|
' -g '+' '.join(map(str, options.grid))+\
|
||||||
' -r %i'%options.randomSeed+\
|
' -r %i'%options.randomSeed+\
|
||||||
' -N '+str(nMicrostructures))[0])
|
' -N '+str(nMicrostructures))[0])
|
||||||
|
@ -266,7 +251,7 @@ bestSeedsUpdate = time.time()
|
||||||
# ----------- tessellate initial seed file to get and evaluate geom file
|
# ----------- tessellate initial seed file to get and evaluate geom file
|
||||||
bestSeedsVFile.reset()
|
bestSeedsVFile.reset()
|
||||||
initialGeomVFile = StringIO()
|
initialGeomVFile = StringIO()
|
||||||
initialGeomVFile.write(execute('geom_fromVoronoiTessellation '+
|
initialGeomVFile.write(damask.util.execute('geom_fromVoronoiTessellation '+
|
||||||
' -g '+' '.join(map(str, options.grid)),bestSeedsVFile)[0])
|
' -g '+' '.join(map(str, options.grid)),bestSeedsVFile)[0])
|
||||||
initialGeomVFile.reset()
|
initialGeomVFile.reset()
|
||||||
initialGeomTable = damask.ASCIItable(initialGeomVFile,None,labeled=False,readonly=True)
|
initialGeomTable = damask.ASCIItable(initialGeomVFile,None,labeled=False,readonly=True)
|
||||||
|
|
Loading…
Reference in New Issue