Beispiel #1
0
phi2 = np.float64(var_set[phi1_lt_pi, 2])
Y = np.float64(var_set[phi1_lt_pi, 3])

f.close

n_tot = phi1.shape[0]

euler = np.zeros((n_tot, 3), dtype='float64')
euler[:, 0] = phi1
euler[:, 1] = phi
euler[:, 2] = phi2
""" Calculate X """

coeff = np.zeros(N_L, dtype='complex128')

indxvec = gsh.gsh_basis_info()

fzsz = 3. / (2. * np.pi**2)
bsz = phi1max * phimax * phi2max / n_tot
print "esz: %s" % bsz
print "n_tot: %s" % n_tot
print "Y size: %s" % Y.size

for ii in xrange(N_L):
    if np.mod(ii, 10) == 0:
        print ii

    l = indxvec[ii, 0]
    X_ = gsh.gsh_eval(euler, [ii])[:, 0]
    tmp = (1. / (2. * l + 1.)) * np.sum(
        Y * X_.conj() * np.sin(euler[:, 1])) * bsz * fzsz
def eval_func(theta, X, et_norm):
    """
    Summary: performs evaluation of calibrated function
    Inputs:
        theta ([el**3], float): vector of deformation modes for each SVE
        X ([el**3, 3], float): array of euler angles for each SVE
        et_norm ([el**3], float): vector of norm(et_dev) for each SVE
    Outputs:
        Y ([el**3], float): vector of values calculated by function
    """

    thr = 0.00001  # threshold on coefs w/rt maximum magnitude coef
    # thr = 0.0  # threshold on coefs w/rt maximum magnitude coef

    LL_p = 16  # LL_p: gsh truncation level

    a = 0.00485  # start for en range
    b = 0.00905  # end for en range

    # N_p: number of GSH bases to evaluate
    indxvec = gsh.gsh_basis_info()
    N_p = np.sum(indxvec[:, 0] <= LL_p)
    # N_p = 500

    N_q = 40  # number of cosine bases to evaluate for theta
    N_r = 14  # number of cosine bases to evaluate for en

    L_th = np.pi/3.
    L_en = b-a

    # filename = 'log_final_results9261.txt'

    f = h5py.File('coef_sortbymag.hdf5', 'r')
    coeff = f.get('coef')[...]
    f.close()

    N_pts = theta.size

    """Select the desired set of coefficients"""

    cmax = N_p*N_q*N_r  # total number of permutations of basis functions

    # fn.WP(str(cmax), filename)

    cmat = np.unravel_index(np.arange(cmax), [N_p, N_q, N_r])
    cmat = np.array(cmat).T

    cuttoff = thr*np.abs(coeff).max()
    indxvec = np.arange(cmax)[np.abs(coeff) > cuttoff]

    # N_coef = indxvec.size
    # pct_coef = 100.*N_coef/cmax
    # fn.WP("number of coefficients retained: %s" % N_coef, filename)
    # fn.WP("percentage of coefficients retained %s%%"
    #       % np.round(pct_coef, 4), filename)

    """Evaluate the parts of the basis function individually"""

    p_U = np.unique(cmat[indxvec, 0])
    q_U = np.unique(cmat[indxvec, 1])
    r_U = np.unique(cmat[indxvec, 2])

    # fn.WP("number of p basis functions used: %s" % p_U.size, filename)
    # fn.WP("number of q basis functions used: %s" % q_U.size, filename)
    # fn.WP("number of r basis functions used: %s" % r_U.size, filename)

    all_basis_p = np.zeros([N_pts, N_p], dtype='complex128')
    for p in p_U:
        all_basis_p[:, p] = np.squeeze(gsh.gsh_eval(X, [p]))

    all_basis_q = np.zeros([N_pts, N_q], dtype='complex128')
    for q in q_U:
        all_basis_q[:, q] = np.cos(q*np.pi*theta/L_th)

    all_basis_r = np.zeros([N_pts, N_r], dtype='complex128')
    for r in r_U:
        all_basis_r[:, r] = np.cos(r*np.pi*(et_norm-a)/L_en)

    """Perform the prediction"""

    Y_ = np.zeros(theta.size, dtype='complex128')

    for ii in indxvec:

        p, q, r = cmat[ii, :]
        basis_p = all_basis_p[:, p]
        basis_q = all_basis_q[:, q]
        basis_r = all_basis_r[:, r]

        ep_set = basis_p*basis_q*basis_r

        Y_ += coeff[ii]*ep_set

    return Y_
    euler = np.zeros([n_tot, 3], dtype='float64')
    euler[:, 0] = phi1.reshape(phi1.size)
    euler[:, 1] = phi.reshape(phi.size)
    euler[:, 2] = phi2.reshape(phi2.size)

    return euler, n_tot

"""Initialize the important constants"""

phi1max = 360.  # max phi1 angle (deg) for integration domain
phimax = 90.  # max phi angle (deg) for integration domain
phi2max = 60.  # max phi2 angle (deg) for integration domain
inc = 3.  # degree increment for euler angle generation
L_trunc = 16  # truncation level in the l index for the GSH

indxvec_new = gsh_old.gsh_basis_info()
N_L_new = np.sum(indxvec_new[:, 0] <= L_trunc)
indxvec_new = indxvec_new[:N_L_new, :]

indxvec_new = gsh_new.gsh_basis_info()
N_L_new = np.sum(indxvec_new[:, 0] <= L_trunc)
indxvec_new = indxvec_new[:N_L_new, :]

print "N_L_new = %s" % N_L_new

euler, n_tot = euler_grid_center(inc, phi1max, phimax, phi2max)

""" Generate Y """

indxlist = np.arange(N_L_new)
bvec = [0]
def euler_rand(n_tot, phi1max, phimax, phi2max):

    phi1 = np.random.rand(n_tot) * phi1max * (np.pi / 180.)
    phi = np.random.rand(n_tot) * phimax * (np.pi / 180.)
    phi2 = np.random.rand(n_tot) * phi2max * (np.pi / 180.)

    euler = np.zeros((n_tot, 3))
    euler[:, 0] = phi1
    euler[:, 1] = phi
    euler[:, 2] = phi2

    return euler


indxvec_complex = gsh_old.gsh_basis_info()
N_L_complex = np.sum(indxvec_complex[:, 0] <= 6)
indxvec_complex = indxvec_complex[:N_L_complex, :]

indxvec_real = gsh_new.gsh_basis_info()
N_L_real = np.sum(indxvec_real[:, 0] <= 6)
indxvec_real = indxvec_complex[:N_L_real, :]

print "N_L_complex = %s" % N_L_complex

phi1max = 360.
phimax = 90.
phi2max = 60.

inc = 3.
euler, n_tot = euler_grid_center(inc, phi1max, phimax, phi2max)