From 42ac7902f730235905db91fc8ea742116ef78efb Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 20 Sep 2015 21:03:10 +0000 Subject: [PATCH] indents wrong in fortran, seeds_fromDistribution bugfix and using ASCII table facilities --- code/DAMASK_spectral_solverAL.f90 | 7 +++--- code/DAMASK_spectral_solverBasicPETSc.f90 | 2 +- processing/pre/seeds_fromDistribution.py | 26 +++++++++++------------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/code/DAMASK_spectral_solverAL.f90 b/code/DAMASK_spectral_solverAL.f90 index ea25fc3aa..b52f3963e 100644 --- a/code/DAMASK_spectral_solverAL.f90 +++ b/code/DAMASK_spectral_solverAL.f90 @@ -417,8 +417,8 @@ subroutine AL_formResidual(in,x_scal,f_scal,dummy,ierr) if (iand(debug_level(debug_spectral),debug_spectralRotation) /= 0) & write(6,'(/,a,/,3(3(f12.7,1x)/))',advance='no') ' deformation gradient aim (lab) =', & math_transpose33(math_rotate_backward33(F_aim,params%rotation_BC)) - write(6,'(/,a,/,3(3(f12.7,1x)/))',advance='no') ' deformation gradient aim =', & - math_transpose33(F_aim) + write(6,'(/,a,/,3(3(f12.7,1x)/))',advance='no') ' deformation gradient aim =', & + math_transpose33(F_aim) flush(6) endif endif newIteration @@ -669,8 +669,7 @@ subroutine AL_forward(guess,timeinc,timeinc_old,loadCaseTime,F_BC,P_BC,rotation_ Fdot = Utilities_calculateRate(math_rotate_backward33(f_aimDot,rotation_BC), & timeinc_old,guess,F_lastInc,reshape(F,[3,3,grid(1),grid(2),grid3])) F_lambdaDot = Utilities_calculateRate(math_rotate_backward33(f_aimDot,rotation_BC), & - timeinc_old,guess,F_lambda_lastInc,reshape(F_lambda,[3,3,grid(1), & - grid(2),grid3])) + timeinc_old,guess,F_lambda_lastInc,reshape(F_lambda,[3,3,grid(1),grid(2),grid3])) F_lastInc = reshape(F, [3,3,grid(1),grid(2),grid3]) F_lambda_lastInc = reshape(F_lambda,[3,3,grid(1),grid(2),grid3]) endif diff --git a/code/DAMASK_spectral_solverBasicPETSc.f90 b/code/DAMASK_spectral_solverBasicPETSc.f90 index 8ecc508ce..f9b867e5d 100644 --- a/code/DAMASK_spectral_solverBasicPETSc.f90 +++ b/code/DAMASK_spectral_solverBasicPETSc.f90 @@ -355,7 +355,7 @@ subroutine BasicPETSC_formResidual(in,x_scal,f_scal,dummy,ierr) math_transpose33(math_rotate_backward33(F_aim,params%rotation_BC)) write(6,'(/,a,/,3(3(f12.7,1x)/))',advance='no') ' deformation gradient aim =', & math_transpose33(F_aim) - flush(6) + flush(6) endif endif newIteration diff --git a/processing/pre/seeds_fromDistribution.py b/processing/pre/seeds_fromDistribution.py index 460a80621..94201e97a 100755 --- a/processing/pre/seeds_fromDistribution.py +++ b/processing/pre/seeds_fromDistribution.py @@ -76,6 +76,7 @@ class myThread (threading.Thread): s.release() if randReset: # new direction because current one led to worse fit + randReset = False NmoveGrains = random.randrange(1,maxSeeds) @@ -97,16 +98,17 @@ class myThread (threading.Thread): perturbedSeedsTable.head_write() outputAlive=True ms = 1 + i = 0 while outputAlive and perturbedSeedsTable.data_read(): # perturbe selected microstructure if ms in selectedMs: - direction+=direction newCoords=np.array(tuple(map(float,perturbedSeedsTable.data[0:3]))+direction[i]) newCoords=np.where(newCoords>=1.0,newCoords-1.0,newCoords) # ensure that the seeds remain in the box (move one side out, other side in) newCoords=np.where(newCoords <0.0,newCoords+1.0,newCoords) perturbedSeedsTable.data[0:3]=[format(f, '8.6f') for f in newCoords] + direction[i]*=2. + i+= 1 ms+=1 perturbedSeedsTable.data_write() - #--- do tesselation with perturbed seed file ---------------------------------------------------------- perturbedGeomVFile.close() perturbedGeomVFile = StringIO() @@ -114,8 +116,9 @@ class myThread (threading.Thread): perturbedGeomVFile.write(execute('geom_fromVoronoiTessellation '+ ' -g '+' '.join(map(str, options.grid)),streamIn=perturbedSeedsVFile)[0]) perturbedGeomVFile.reset() + #--- evaluate current seeds file ---------------------------------------------------------------------- - perturbedGeomTable = damask.ASCIItable(perturbedGeomVFile,labeled=False,readonly=True) + perturbedGeomTable = damask.ASCIItable(perturbedGeomVFile,None,labeled=False,readonly=True) perturbedGeomTable.head_read() for i in perturbedGeomTable.info: if i.startswith('microstructures'): myNmicrostructures = int(i.split('\t')[1]) @@ -233,16 +236,12 @@ points = float(reduce(mul,options.grid)) # ----------- calculate target distribution and bin edges targetGeomFile = os.path.splitext(os.path.basename(options.target))[0]+'.geom' -targetGeomTable = damask.ASCIItable(targetGeomFile,labeled=False,readonly=True) +targetGeomTable = damask.ASCIItable(targetGeomFile,None,labeled=False,readonly=True) targetGeomTable.head_read() - -for i in targetGeomTable.info: - if i.startswith('microstructures'): nMicrostructures = int(i.split()[1]) - if i.startswith('grid'): targetPoints = int(np.array(map(float,i.split()[2:7:2])).prod()) - -targetGeomTable.data_readArray() - -targetVolFrac = np.bincount(targetGeomTable.data.astype(int).ravel())[1:nMicrostructures+1]/targetPoints +info,devNull = targetGeomTable.head_getGeom() +nMicrostructures = info['microstructures'] +targetVolFrac = np.bincount(targetGeomTable.microstructure_read(info['grid']))[1:nMicrostructures+1]/\ + float(info['grid'].prod()) target=[] for i in xrange(1,nMicrostructures+1): targetHist,targetBins = np.histogram(targetVolFrac,bins=i) #bin boundaries @@ -266,7 +265,7 @@ initialGeomVFile = StringIO() initialGeomVFile.write(execute('geom_fromVoronoiTessellation '+ ' -g '+' '.join(map(str, options.grid)),bestSeedsVFile)[0]) initialGeomVFile.reset() -initialGeomTable = damask.ASCIItable(initialGeomVFile,labeled=False,readonly=True) +initialGeomTable = damask.ASCIItable(initialGeomVFile,None,labeled=False,readonly=True) initialGeomTable.head_read() info,devNull = initialGeomTable.head_getGeom() @@ -296,7 +295,6 @@ if match >0: print 'Stage %i cleared'%match sys.stdout.flush() initialGeomVFile.close() - # start mulithreaded monte carlo simulation threads=[] s=threading.Semaphore(1)