Polishing
- keep microstructure as integer - avoid constant reshape - IMPORTANT: random order has changed!
This commit is contained in:
parent
0556827f29
commit
064dabe34b
2
PRIVATE
2
PRIVATE
|
@ -1 +1 @@
|
|||
Subproject commit 05ac971ce58fc399dd99be9151b7d61d049aec42
|
||||
Subproject commit 1b08e028a6177d03a0d4202e5feed2ec29f91c19
|
|
@ -128,7 +128,6 @@ random.seed(options.randomSeed)
|
|||
for name in filenames:
|
||||
damask.util.report(scriptName,name)
|
||||
|
||||
# --- sanity checks -------------------------------------------------------------------------
|
||||
remarks = []
|
||||
errors = []
|
||||
if any(grid==0):
|
||||
|
@ -144,29 +143,27 @@ for name in filenames:
|
|||
damask.util.croak(errors)
|
||||
sys.exit()
|
||||
|
||||
# --- do work ------------------------------------------------------------------------------------
|
||||
grainEuler = np.random.rand(3,options.N) # create random Euler triplets
|
||||
grainEuler[0,:] *= 360.0 # phi_1 is uniformly distributed
|
||||
grainEuler[1,:] = np.degrees(np.arccos(2*grainEuler[1,:]-1)) # cos(Phi) is uniformly distributed
|
||||
grainEuler[2,:] *= 360.0 # phi_2 is uniformly distributed
|
||||
eulers = np.random.rand(options.N,3) # create random Euler triplets
|
||||
eulers[:,0] *= 360.0 # phi_1 is uniformly distributed
|
||||
eulers[:,1] = np.degrees(np.arccos(2*eulers[:,1]-1)) # cos(Phi) is uniformly distributed
|
||||
eulers[:,2] *= 360.0 # phi_2 is uniformly distributed
|
||||
|
||||
if not options.selective:
|
||||
n = np.maximum(np.ones(3),np.array(grid*fraction),
|
||||
dtype=int,casting='unsafe') # find max grid indices within fraction
|
||||
n = np.maximum(np.ones(3),np.array(grid*fraction),dtype=int,casting='unsafe') # find max grid indices within fraction
|
||||
meshgrid = np.meshgrid(*map(np.arange,n),indexing='ij') # create a meshgrid within fraction
|
||||
coords = np.vstack((meshgrid[0],meshgrid[1],meshgrid[2])).reshape(3,n.prod()).T # assemble list of 3D coordinates
|
||||
seeds = ((random.sample(list(coords),options.N)+np.random.random(options.N*3).reshape(options.N,3))\
|
||||
coords = np.vstack((meshgrid[0],meshgrid[1],meshgrid[2])).reshape(n.prod(),3) # assemble list of 3D coordinates
|
||||
seeds = (random.sample(coords.tolist(),options.N)+np.random.rand(options.N,3))\
|
||||
/ \
|
||||
(n/fraction)).T # pick options.N of those, rattle position,
|
||||
(n/fraction) # pick options.N of those, rattle position,
|
||||
# and rescale to fall within fraction
|
||||
else:
|
||||
seeds = np.zeros((options.N,3),dtype=float) # seed positions array
|
||||
seeds = np.zeros((options.N,3)) # seed positions array
|
||||
seeds[0] = np.random.random(3)*grid/max(grid)
|
||||
i = 1 # start out with one given point
|
||||
if i%(options.N/100.) < 1: damask.util.croak('.',False)
|
||||
|
||||
while i < options.N:
|
||||
candidates = np.random.random(options.numCandidates*3).reshape(options.numCandidates,3)
|
||||
candidates = np.random.rand(options.numCandidates,3)
|
||||
distances = kdtree_search(seeds[:i],candidates)
|
||||
best = distances.argmax()
|
||||
if distances[best] > options.distance: # require minimum separation
|
||||
|
@ -175,26 +172,19 @@ for name in filenames:
|
|||
if i%(options.N/100.) < 1: damask.util.croak('.',False)
|
||||
|
||||
damask.util.croak('')
|
||||
seeds = seeds.T # prepare shape for stacking
|
||||
|
||||
if options.weights:
|
||||
weights = [np.random.uniform(low = 0, high = options.max, size = options.N)] if options.max > 0.0 \
|
||||
else [np.random.normal(loc = options.mean, scale = options.sigma, size = options.N)]
|
||||
|
||||
|
||||
data = np.transpose(np.vstack(tuple([seeds,
|
||||
grainEuler,
|
||||
np.arange(options.microstructure,options.microstructure + options.N),
|
||||
] + (weights if options.weights else [])
|
||||
)))
|
||||
|
||||
comments = [scriptID + ' ' + ' '.join(sys.argv[1:]),
|
||||
'grid\ta {}\tb {}\tc {}'.format(*grid),
|
||||
'randomSeed\t{}'.format(options.randomSeed),
|
||||
]
|
||||
|
||||
shapes = {'pos':(3,),'euler':(3,),'microstructure':(1,)}
|
||||
if options.weights: shapes['weight'] = (1,)
|
||||
table = damask.Table(np.hstack((seeds,eulers)),{'pos':(3,),'euler':(3,)},comments)
|
||||
table.add('microstructure',np.arange(options.microstructure,options.microstructure + options.N,dtype=int))
|
||||
|
||||
if options.weights:
|
||||
weights = np.random.uniform(low = 0, high = options.max, size = options.N) if options.max > 0.0 \
|
||||
else np.random.normal(loc = options.mean, scale = options.sigma, size = options.N)
|
||||
table.add('weight',weights)
|
||||
|
||||
table = damask.Table(data,shapes,comments)
|
||||
table.to_ASCII(sys.stdout if name is None else name)
|
||||
|
|
Loading…
Reference in New Issue