Пример #1
0
def read_meas(el, ns, set_id, step, comp, tensor_id, newdir, wrt_file):

    start = time.time()

    #    nwd = os.getcwd() + '\\' + newdir
    nwd = os.getcwd() + '/' + newdir  # for unix
    os.chdir(nwd)

    compd = {'11': 0, '22': 4, '33': 8, '12': 1, '23': 5, '13': 6}
    compp = compd[comp]

    r_real = np.zeros([ns, el, el, el])

    sn = 0

    if set_id == "cal":
        for filename in os.listdir(nwd):
            if filename.endswith('%s.vtk' % step):
                r_temp = rr.read_vtk_tensor(filename=filename,
                                            tensor_id=tensor_id,
                                            comp=compp)
                r_real[sn, ...] = r_temp.reshape([el, el, el])
                sn += 1
    else:
        for filename in os.listdir(nwd):
            if filename.endswith('.vtk'):
                r_temp = rr.read_vtk_tensor(filename=filename,
                                            tensor_id=tensor_id,
                                            comp=compp)
                r_real[sn, ...] = r_temp.reshape([el, el, el])
                sn += 1

    # return to the original directory
    os.chdir('..')

    typ = ['sigma', 'epsilon', 'epsilonp']

    np.save('%s%s_fem_%s%s_s%s' % (typ[tensor_id], comp, ns, set_id, step),
            r_real)

    # fftn of response fields
    r_fft = np.fft.fftn(r_real, axes=[1, 2, 3])
    del r_real
    np.save('%s%s_fft_fem_%s%s_s%s' % (typ[tensor_id], comp, ns, set_id, step),
            r_fft)

    end = time.time()
    timeE = np.round((end - start), 3)

    msg = 'The measure of interest has been read from .vtk file for %s, component %s: %s seconds' % (
        set_id, comp, timeE)
    rr.WP(msg, wrt_file)
Пример #2
0
def read_meas(el, ns, set_id, step, comp, tensor_id, newdir, wrt_file):

    start = time.time()

    typ = ['sigma', 'epsilon_t', 'epsilon_p']

    #    nwd = os.getcwd() + '\\' + newdir
    nwd = os.getcwd() + '/' + newdir  # for unix
    os.chdir(nwd)

    compd = {'11': 0, '22': 4, '33': 8, '12': 1, '13': 6, '23': 5}
    compp = compd[comp]

    r_fem = np.zeros([ns, el, el, el])

    sn = 0
    for filename in os.listdir(nwd):
        if filename.endswith('%s.vtk' % step):
            r_temp = rr.read_vtk_tensor(filename=filename,
                                        tensor_id=tensor_id,
                                        comp=compp)
            r_fem[sn, ...] = r_temp.reshape([el, el, el])
            sn += 1

    # return to the original directory
    os.chdir('..')

    # open HDF5 file
    base = tb.open_file("ref_%s%s_s%s.h5" % (ns, set_id, step), mode="a")
    # create a group one level below root called r[comp]
    group = base.create_group('/%s' % typ[tensor_id], 'r%s' % comp,
                              'comp %s response fields' % comp)
    # initialize array for the euler angles
    base.create_array(group, 'r_fem', r_fem, 'FEM generated response fields')
    # close the HDF5 file
    base.close()

    # FFT OF RESPONSE FIELD

    # open HDF5 file
    base = tb.open_file("D_%s%s_s%s.h5" % (ns, set_id, step), mode="a")
    # create a group one level below root called r[comp]
    group = base.create_group('/%s' % typ[tensor_id], 'r%s' % comp,
                              'FFTs of comp %s response fields' % comp)
    # initialize array for the euler angles
    base.create_array(group, 'r_fft', np.fft.fftn(r_fem, axes=[1, 2, 3]),
                      'FFT of FEM generated response fields')
    # close the HDF5 file
    base.close()

    end = time.time()
    timeE = np.round((end - start), 3)

    msg = 'The measure of interest has been read from .vtk file' \
          ' for %s, set %s: %s seconds' % (set_id, comp, timeE)
    rr.WP(msg, wrt_file)
Пример #3
0
def read_meas(ns, set_id, step, comp, vtk_filename, tensor_id, newdir, wrt_file):

    start = time.time() 

    ## el is the # of elements per side of the cube 
    el = 21 
    
    r_real = np.zeros([el,el,el,ns])
    
    ## change to directory with the .vtk files
#    cwd = os.getcwd()
##    os.chdir(cwd + '\\' + newdir)    
#    os.chdir(cwd + '/' + newdir) #for unix    
#
#    compd = {'11':0,'22':4,'33':8,'12':1,'23':5,'31':6}    
#    compp = compd[comp]    
#    print compp    
#
#    for sn in xrange(ns):
#        l_sn = str(sn+1).zfill(5)  
#        r_temp = rr.read_vtk_tensor(filename = vtk_filename %l_sn, tensor_id = tensor_id, comp = compp)
#        r_real[:,:,:,sn] = np.swapaxes(np.reshape(np.flipud(r_temp), [el,el,el]),1,2)
    
    
    nwd = os.getcwd() + '\\' + newdir
#    nwd = os.getcwd() + '/' + newdir #for unix 
    os.chdir(nwd)

    compd = {'11':0,'22':4,'33':8,'12':1,'23':5,'31':6}    
    compp = compd[comp]    

    sn = 0    
    for filename in os.listdir(nwd):
        if filename.endswith('%s.vtk' %step):  
            r_temp = rr.read_vtk_tensor(filename = filename, tensor_id = tensor_id, comp = compp)
            r_real[:,:,:,sn] = np.swapaxes(np.reshape(np.flipud(r_temp), [el,el,el]),1,2)
            sn += 1             
            
    ## return to the original directory    
    os.chdir('..')    
    
    np.save('r%s_%s%s_s%s' %(comp,ns,set_id,step), r_real)

    ## fftn of response fields    
    r_fft = np.fft.fftn(r_real, axes = [0,1,2]) 
    del r_real
    np.save('r%s_fft_%s%s_s%s' %(comp,ns,set_id,step),r_fft)  
    

    end = time.time()
    timeE = np.round((end - start),3)
    
    msg = 'The measure of interest has been read from .vtk file for %s, set %s: %s seconds' %(set_id,comp,timeE)
    rr.WP(msg,wrt_file)
Пример #4
0
def read_meas(el, ns, set_id, step, comp, tensor_id, newdir, wrt_file):

    start = time.time()

    # nwd = os.getcwd() + '\\' + newdir
    nwd = os.getcwd() + '/' + newdir  # for unix
    os.chdir(nwd)

    compd = {'11': 0, '22': 4, '33': 8, '23': 5, '12': 1, '13': 6}
    compp = compd[comp]

    r_real = np.zeros([ns, el, el, el])

    sn = 0

    # for filename in os.listdir(nwd):
    #     if filename.endswith('%s.vtk' % step):
    #         r_temp = rr.read_vtk_tensor(filename=filename,
    #                                     tensor_id=tensor_id,
    #                                     comp=compp)
    #         r_real[sn, ...] = r_temp.reshape([el, el, el])
    #         sn += 1

    for sn in xrange(ns):
        filename = "Ti64_Dream3D_v01_Output_%s.vtk" % str(sn + 1)
        r_temp = rr.read_vtk_tensor(filename=filename,
                                    tensor_id=tensor_id,
                                    comp=compp)
        r_real[sn, ...] = r_temp.reshape([el, el, el])

    # return to the original directory
    os.chdir('..')

    typ = ['sigma', 'epsilon', 'epsilonp']

    f = h5py.File("data.hdf5", 'a')
    dset_name = '%s%s_fem_%s%s_s%s' % (typ[tensor_id], comp, ns, set_id, step)
    f.create_dataset(dset_name, data=r_real)

    # fftn of response fields
    r_fft = np.fft.fftn(r_real, axes=[1, 2, 3])
    del r_real
    dset_name = '%s%s_fft_fem_%s%s_s%s' % (typ[tensor_id], comp, ns, set_id,
                                           step)
    f.create_dataset(dset_name, data=r_fft)

    f.close()

    end = time.time()
    timeE = np.round((end - start), 3)

    msg = 'The measure of interest has been read from .vtk file for %s, component %s: %s seconds' % (
        set_id, comp, timeE)
    rr.WP(msg, wrt_file)
Пример #5
0
def read_meas(ns, set_id, comp, tensor_id, newdir):

    start = time.time()

    C = const()

    typ = ['sigma', 'epsilon_t', 'epsilon_p']

    # nwd = os.getcwd() + '\\' + newdir
    nwd = os.getcwd() + '/' + newdir  # for unix
    os.chdir(nwd)

    compd = {'11': 0, '22': 4, '33': 8, '12': 1, '13': 6, '23': 5}
    compp = compd[comp]

    r_fem = np.zeros([ns, C['el'], C['el'], C['el']])

    sn = 0
    for filename in os.listdir(nwd):
        if filename.endswith('%s.vtk' % C['step']):
            r_temp = rr.read_vtk_tensor(filename=filename,
                                        tensor_id=tensor_id,
                                        comp=compp)
            r_fem[sn, ...] = r_temp.reshape([C['el'], C['el'], C['el']])
            sn += 1
    """return to the original directory"""
    os.chdir('..')

    f = h5py.File("responses.hdf5", 'a')
    f.create_dataset('%s_%s' % (typ[tensor_id], set_id), data=r_fem)
    f.close()

    # """FFT OF RESPONSE FIELD"""

    # f = h5py.File("D_%s%s_s%s.hdf5" % (ns, set_id, step), 'a')
    # tmp = np.fft.fftn(r_fem, axes=[1, 2, 3])

    # print tmp.shape

    # f.create_dataset('rfft%s_%s' % (comp, typ[tensor_id]), data=tmp)
    # f.close()

    end = time.time()
    timeE = np.round((end - start), 3)

    msg = 'The measure of interest has been read from .vtk file' \
          ' for %s, component %s, type %s: %s seconds' % (set_id, comp,
                                                          typ[tensor_id],
                                                          timeE)
    rr.WP(msg, C['wrt_file'])
Пример #6
0
def read_meas(el, ns, set_id, step, typ, comp, tensor_id, newdir):

#    nwd = os.getcwd() + '\\' + newdir
    nwd = os.getcwd() + '/' + newdir  # for unix
    os.chdir(nwd)

    compd = {'11': 0, '22': 4, '33': 8, '12': 1, '23': 5, '31': 6}
    compp = compd[comp]

    r_real = np.zeros([ns, el, el, el])

    sn = 0
    for filename in os.listdir(nwd):
        if filename.endswith('.vtk'):
            r_temp = rr.read_vtk_tensor(filename=filename, tensor_id=tensor_id,
                                        comp=compp)
            r_real[sn, ...] = r_temp.reshape([el, el, el])
            sn += 1

    # return to the original directory
    os.chdir('..')

    np.save('%s%s_%s%s_s%s' % (typ, comp, ns, set_id, step), r_real)
Пример #7
0
@author: nhpnp3
"""

import functions as rr
import numpy as np

el = 21

filename = 'Results_Ti64_Dream3D_XdirLoad_210microns_9261el_AbqInp_PowerLaw_LCF_021_data_v2_05.vtk'
r_fem = np.zeros([6, el**3])

compl = ['11', '22', '33', '12', '13', '23']
compd = {'11': 0, '22': 4, '33': 8, '12': 1, '13': 6, '23': 5}

for comp in xrange(6):

    compp = compd[compl[comp]]

    print comp
    print compl[comp]
    print compd[compl[comp]]

    r_temp = rr.read_vtk_tensor(filename=filename, tensor_id=1, comp=compp)

    r_fem[comp, ...] = r_temp

r_norm = np.sqrt(r_fem[0,...]**2 + r_fem[1,...]**2 + r_fem[2,...]**2 + \
                 2*(r_fem[3,...]**2) + 2*(r_fem[4,...]**2) + 2*(r_fem[5,...]**2))

print np.min(r_norm)
print np.max(r_norm)