示例#1
0
 def test_relationship_reference(self, update, reference_dir, model,
                                 lattice):
     reference = os.path.join(reference_dir,
                              '{}_{}.txt'.format(lattice, model))
     ori = Orientation(Rotation(), lattice)
     eu = np.array([
         o.rotation.as_Eulers(degrees=True)
         for o in ori.relatedOrientations(model)
     ])
     if update:
         coords = np.array([(1, i + 1) for i, x in enumerate(eu)])
         table = damask.Table(eu, {'Eulers': (3, )})
         table.add('pos', coords)
         table.to_ASCII(reference)
     assert np.allclose(eu,
                        damask.Table.from_ASCII(reference).get('Eulers'))
示例#2
0
(options,filenames) = parser.parse_args()
if filenames == []: filenames = [None]

options.whitelist = [int(i) for i in options.whitelist]
options.blacklist = [int(i) for i in options.blacklist]

for name in filenames:
    damask.util.report(scriptName,name)

    geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
    microstructure = geom.get_microstructure().reshape((-1,1),order='F')

    mask = np.logical_and(np.in1d(microstructure,options.whitelist,invert=False) if options.whitelist else \
                          np.full(geom.grid.prod(),True,dtype=bool),
                          np.in1d(microstructure,options.blacklist,invert=True)  if options.blacklist else \
                          np.full(geom.grid.prod(),True,dtype=bool))

    seeds = damask.grid_filters.cell_coord0(geom.grid,geom.size).reshape(-1,3,order='F')

    comments = geom.comments \
             + [scriptID + ' ' + ' '.join(sys.argv[1:]),
                'grid\ta {}\tb {}\tc {}'.format(*geom.grid),
                'size\tx {}\ty {}\tz {}'.format(*geom.size),
                'origin\tx {}\ty {}\tz {}'.format(*geom.origin),
                'homogenization\t{}'.format(geom.homogenization)]

    table = damask.Table(seeds[mask],{'pos':(3,)},comments)
    table.add('microstructure',microstructure[mask])
    table.to_ASCII(sys.stdout if name is None else \
                   os.path.splitext(name)[0]+'.seeds')
示例#3
0
文件: blowUp.py 项目: hrh741/DAMASK
options.packing = np.array(options.packing)
prefix = 'blowUp{}x{}x{}_'.format(*options.packing)

for name in filenames:
    damask.util.report(scriptName, name)

    table = damask.Table.from_ASCII(
        StringIO(''.join(sys.stdin.read())) if name is None else name)
    grid, size, origin = damask.grid_filters.cell_coord0_gridSizeOrigin(
        table.get(options.pos))

    packing = np.array(options.packing, 'i')
    outSize = grid * packing

    data = table.data.values.reshape(tuple(grid) + (-1, ), order='F')
    blownUp = ndimage.interpolation.zoom(data,
                                         tuple(packing) + (1, ),
                                         order=0,
                                         mode='nearest').reshape(
                                             outSize.prod(), -1, order='F')

    table = damask.Table(blownUp, table.shapes, table.comments)

    coords = damask.grid_filters.cell_coord0(outSize, size, origin)
    table.set(options.pos, coords.reshape(-1, 3, order='F'))
    table.set('elem', np.arange(1, outSize.prod() + 1))

    outname = os.path.join(os.path.dirname(name),
                           prefix + os.path.basename(name))
    table.to_ASCII(sys.stdout if name is None else outname)
示例#4
0
                    pos = 'pos',
                   )

(options,filenames) = parser.parse_args()

for name in filenames:
    damask.util.report(scriptName,name)

    table = damask.Table.load(StringIO(''.join(sys.stdin.read())) if name is None else name)
    grid,size,origin = damask.grid_filters.cellsSizeOrigin_coordinates0_point(table.get(options.pos))

    F = table.get(options.f).reshape(tuple(grid)+(-1,),order='F').reshape(tuple(grid)+(3,3))
    if options.nodal:
        damask.Table(damask.grid_filters.coordinates0_node(grid,size).reshape(-1,3,order='F'),
                     {'pos':(3,)})\
              .add('avg({}).{}'.format(options.f,options.pos),
                   damask.grid_filters.displacement_avg_node(size,F).reshape(-1,3,order='F'),
                   scriptID+' '+' '.join(sys.argv[1:]))\
              .add('fluct({}).{}'.format(options.f,options.pos),
                   damask.grid_filters.displacement_fluct_node(size,F).reshape(-1,3,order='F'),
                    scriptID+' '+' '.join(sys.argv[1:]))\
               .save((sys.stdout if name is None else os.path.splitext(name)[0]+'_nodal.txt'))
    else:
        table.add('avg({}).{}'.format(options.f,options.pos),
                  damask.grid_filters.displacement_avg_point(size,F).reshape(-1,3,order='F'),
                  scriptID+' '+' '.join(sys.argv[1:]))\
             .add('fluct({}).{}'.format(options.f,options.pos),
                  damask.grid_filters.displacement_fluct_point(size,F).reshape(-1,3,order='F'),
                  scriptID+' '+' '.join(sys.argv[1:]))\
             .save((sys.stdout if name is None else name))
示例#5
0
    for i in range(Nx):
        for j in range(Ny):
            g[0] = round((i + 0.5) * box[0] * geom.grid[0] / Nx -
                         0.5) + offset[0]
            g[1] = round((j + 0.5) * box[1] * geom.grid[1] / Ny -
                         0.5) + offset[1]
            for k in range(Nz):
                g[2] = k + offset[2]
                g %= geom.grid
                seeds[n,
                      0:3] = (g +
                              0.5) / geom.grid  # normalize coordinates to box
                seeds[n, 3] = geom.material[g[0], g[1], g[2]]
                if options.x: g[0] += 1
                if options.y: g[1] += 1
                n += 1


    comments = geom.comments \
             + [scriptID + ' ' + ' '.join(sys.argv[1:]),
                'poking\ta {}\tb {}\tc {}'.format(Nx,Ny,Nz),
                'grid\ta {}\tb {}\tc {}'.format(*geom.grid),
                'size\tx {}\ty {}\tz {}'.format(*geom.size),
                'origin\tx {}\ty {}\tz {}'.format(*geom.origin),
               ]

    table = damask.Table(seeds, {'pos': (3, ), 'material': (1, )}, comments)
    table.set('material',table.get('material').astype(np.int))\
         .save(sys.stdout if name is None else \
                     os.path.splitext(name)[0]+f'_poked_{options.N}.seeds',legacy=True)
示例#6
0
  if (minmax[2] == 0.0).all():                                                                       # no data in grid?
    damask.util.croak('no data found on grid...')
    minmax[2,:] = np.array([0.0,1.0])                                                                # making up arbitrary z minmax
  if options.type[2].lower() == 'log':
    grid = np.log(grid)
    minmax[2] = np.log(minmax[2])

  delta[2] = minmax[2,1]-minmax[2,0]

  for x in range(options.bins[0]):
    for y in range(options.bins[1]):
      result[x,y,:] = [minmax[0,0]+delta[0]/options.bins[0]*(x+0.5),
                       minmax[1,0]+delta[1]/options.bins[1]*(y+0.5),
                       np.clip((grid[x,y]-minmax[2,0])/delta[2],0.0,1.0)]

  for c in (0,1):
    if options.type[c].lower() == 'log': result[:,:,c] = np.exp(result[:,:,c])

  if options.invert: result[:,:,2] = 1.0 - result[:,:,2]

  comments = scriptID + '\t' + ' '.join(sys.argv[1:])
  shapes = {'bin_%s'%options.data[0]:(1,),'bin_%s'%options.data[1]:(1,),'z':(1,)}
  table  = damask.Table(result.reshape(options.bins[0]*options.bins[1],3),shapes,[comments])
  if name:
    outname = os.path.join(os.path.dirname(name),'binned-{}-{}_'.format(*options.data) +
                                                ('weighted-{}_'.format(options.weight) if options.weight else '') +
                                                 os.path.basename(name))
    table.to_ASCII(outname)
  else:
    table.to_ASCII(sys.stdout)
示例#7
0
        seeds[0] = np.random.random(3) * size

        i = 1
        progress = damask.util._ProgressBar(options.N,'',50)
        while i < options.N:
            candidates = np.random.rand(options.numCandidates,3)*np.broadcast_to(size,(options.numCandidates,3))
            tree = spatial.cKDTree(seeds[:i])
            distances, dev_null = tree.query(candidates)
            best = distances.argmax()
            if distances[best] > options.distance:                                                  # require minimum separation
                seeds[i] = candidates[best]                                                         # maximum separation to existing point cloud
                i += 1
                progress.update(i)


    comments = [scriptID + ' ' + ' '.join(sys.argv[1:]),
                'grid\ta {}\tb {}\tc {}'.format(*grid),
                'size\tx {}\ty {}\tz {}'.format(*size),
                'randomSeed\t{}'.format(options.randomSeed),
               ]

    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.to_ASCII(sys.stdout if name is None else name)
示例#8
0
        grid = np.array(options.grid, 'i')
        size = np.array(options.size, 'd')

    packing = np.where(grid == 1, 1,
                       packing)  # reset packing to 1 where grid==1
    shift = np.where(grid == 1, 0, shift)  # reset   shift to 0 where grid==1
    packedGrid = np.maximum(np.ones(3, 'i'), grid // packing)

    data = table.data.values.reshape(tuple(grid) + (-1, ), order='F')
    averagedDown = scipy.ndimage.filters.uniform_filter( \
                    np.roll(
                    np.roll(
                    np.roll(data,
                            -shift[0],axis = 0),
                            -shift[1],axis = 1),
                            -shift[2],axis = 2),
                    size = list(packing) + [1],
                    mode = 'wrap',
                    origin = list(-(packing//2)) + [0])\
                    [::packing[0],::packing[1],::packing[2],:].reshape((packedGrid.prod(),-1),order = 'F')

    table = damask.Table(averagedDown, table.shapes, table.comments)

    coords = damask.grid_filters.cell_coord0(
        packedGrid, size, shift / packedGrid * size + origin)
    table.set(options.pos, coords.reshape(-1, 3, order='F'))

    outname = os.path.join(os.path.dirname(name),
                           prefix + os.path.basename(name))
    table.to_ASCII(sys.stdout if name is None else outname)
示例#9
0
    seeds = np.zeros((Nx*Ny*Nz,4))
    g     = np.zeros(3,dtype=np.int)

    n = 0
    for i in range(Nx):
        for j in range(Ny):
            g[0] = round((i+0.5)*box[0]*geom.grid[0]/Nx-0.5)+offset[0]
            g[1] = round((j+0.5)*box[1]*geom.grid[1]/Ny-0.5)+offset[1]
            for k in range(Nz):
                g[2] = k + offset[2]
                g %= geom.grid
                seeds[n,0:3] = (g+0.5)/geom.grid                                                    # normalize coordinates to box
                seeds[n,  3] = geom.microstructure[g[0],g[1],g[2]]
                if options.x: g[0] += 1
                if options.y: g[1] += 1
                n += 1


    comments = geom.comments \
             + [scriptID + ' ' + ' '.join(sys.argv[1:]),
                'poking\ta {}\tb {}\tc {}'.format(Nx,Ny,Nz),
                'grid\ta {}\tb {}\tc {}'.format(*geom.grid),
                'size\tx {}\ty {}\tz {}'.format(*geom.size),
                'origin\tx {}\ty {}\tz {}'.format(*geom.origin),
                'homogenization\t{}'.format(geom.homogenization)]

    table = damask.Table(seeds,{'pos':(3,),'microstructure':(1,)},comments)
    table.set('microstructure',table.get('microstructure').astype(np.int))
    table.to_ASCII(sys.stdout if name is None else \
                   os.path.splitext(name)[0]+'_poked_{}.seeds'.format(options.N))
示例#10
0
options = parser.parse_args()

if options.mat is None: options.mat=[]
if options.con is None: options.con=[]

for filename in options.filenames:
    results = damask.Result(filename)

    if not results.structured: continue
    coords = damask.grid_filters.cell_coord0(results.grid,results.size,results.origin).reshape(-1,3,order='F')

    N_digits = int(np.floor(np.log10(int(results.increments[-1][3:]))))+1
    N_digits = 5 # hack to keep test intact
    for inc in damask.util.show_progress(results.iterate('increments'),len(results.increments)):
        table = damask.Table(np.ones(np.product(results.grid),dtype=int)*int(inc[3:]),{'inc':(1,)})\
                      .add('pos',coords.reshape(-1,3))

        results.pick('materialpoints',False)
        results.pick('constituents',  True)
        for label in options.con:
            x = results.get_dataset_location(label)
            if len(x) != 0:
                table = table.add(label,results.read_dataset(x,0,plain=True).reshape(results.grid.prod(),-1))

        results.pick('constituents',  False)
        results.pick('materialpoints',True)
        for label in options.mat:
            x = results.get_dataset_location(label)
            if len(x) != 0:
                table = table.add(label,results.read_dataset(x,0,plain=True).reshape(results.grid.prod(),-1))
示例#11
0
(options, filenames) = parser.parse_args()

for name in filenames:
    damask.util.report(scriptName, name)

    table = damask.Table.from_ASCII(
        StringIO(''.join(sys.stdin.read())) if name is None else name)
    grid, size, origin = damask.grid_filters.cell_coord0_gridSizeOrigin(
        table.get(options.pos))

    F = table.get(options.f).reshape(tuple(grid) + (-1, ),
                                     order='F').reshape(tuple(grid) + (3, 3))
    if options.nodal:
        table = damask.Table(
            damask.grid_filters.node_coord0(grid, size).reshape(-1,
                                                                3,
                                                                order='F'),
            {'pos': (3, )})
        table.add(
            'avg({}).{}'.format(options.f, options.pos),
            damask.grid_filters.node_displacement_avg(size,
                                                      F).reshape(-1,
                                                                 3,
                                                                 order='F'),
            scriptID + ' ' + ' '.join(sys.argv[1:]))
        table.add(
            'fluct({}).{}'.format(options.f, options.pos),
            damask.grid_filters.node_displacement_fluct(size,
                                                        F).reshape(-1,
                                                                   3,
                                                                   order='F'),