def minfuncVecField_V3_10r(params, U, V, x, y):
    import numpy as np
    import PIVutils
    from scipy.integrate import simps

    assert U.shape[0] == U.shape[1], 'Data must be a square matrix.'
    assert U.shape == V.shape, 'U and V fields must be the same size'

    [U2, V2] = PIVutils.genHairpinField_V3(int((U.shape[0] - 1) / 2),
                                           *params,
                                           x=x,
                                           y=y)

    BoxSize = int((U.shape[0] - 1) / 2)
    W = np.zeros([2 * BoxSize + 1, 2 * BoxSize + 1])
    X, Y = np.meshgrid(x, y)
    R = np.hypot(X - params[2], Y - params[2])
    W[R <= params[1]] = 1
    W[R >= params[1]] = params[1] / R[R >= params[1]]

    #a = W*((U-U2)**2 + (V-V2)**2)
    #print(a.shape)

    #Determine integral of weighting function
    Area = simps(simps(W, y), x)
    #Area = 1
    obj = W * ((U - U2)**2 + (V - V2)**2)

    #Area_lite = np.mean(W)*(x[-1]-x[0])*(y[-1]-y[0])
    #return np.sum(obj)/np.mean(W) #okay but not acceptable
    #return np.sum(obj)/np.mean(obj) #doesn't converge at all
    return np.sum(obj) / Area
def minfuncVecField_V3_og(params, U, V, x, y):
    import numpy as np
    import PIVutils
    from scipy.integrate import simps

    assert U.shape[0] == U.shape[1], 'Data must be a square matrix.'
    assert U.shape == V.shape, 'U and V fields must be the same size'

    [U2, V2] = PIVutils.genHairpinField_V3(int((U.shape[0] - 1) / 2),
                                           *params,
                                           x=x,
                                           y=y)

    BoxSize = int((U.shape[0] - 1) / 2)
    W = np.zeros([2 * BoxSize + 1, 2 * BoxSize + 1])
    X, Y = np.meshgrid(x, y)
    R = np.hypot(X - params[2], Y - params[2])
    W[R <= params[1]] = 1
    W[R >= params[1]] = params[1] / R[R >= params[1]]

    #a = W*((U-U2)**2 + (V-V2)**2)
    #print(a.shape)

    #Determine integral of weighting function
    Area = simps(simps(W, y), x)
    #Area = 1
    return np.sum(W * ((U - U2)**2 + (V - V2)**2)) / Area
def minfuncVecField_V2(params, U, V, x, y):
    import numpy as np
    import PIVutils

    assert U.shape[0] == U.shape[1], 'Data must be a square matrix.'
    assert U.shape == V.shape, 'U and V fields must be the same size'

    [U2, V2] = PIVutils.genHairpinField_V2(int((U.shape[0] - 1) / 2),
                                           *params,
                                           x=x,
                                           y=y)

    return np.sum(((U - U2)**2 + (V - V2)**2))
def minfuncVecField_V5(params, U, V, x, y):

    #weighting function
    # w (R<r) = 1
    # w (R>r) = abr/(x^2 + a^2)
    #serpentine with a radius a = (R)

    import numpy as np
    import PIVutils
    from scipy.integrate import simps
    import math

    assert U.shape[0] == U.shape[1], 'Data must be a square matrix.'
    assert U.shape == V.shape, 'U and V fields must be the same size'

    [U2, V2] = PIVutils.genHairpinField_V3(int((U.shape[0] - 1) / 2),
                                           *params,
                                           x=x,
                                           y=y)

    BoxSize = int((U.shape[0] - 1) / 2)
    W = np.zeros([2 * BoxSize + 1, 2 * BoxSize + 1])
    X, Y = np.meshgrid(x, y)
    R = np.hypot(X - params[2], Y - params[2])

    k = 1
    r = k * params[1]

    R = np.array(R)
    W[R <= r] = 1
    W[R >= r] = np.sqrt(R[R >= r]**2 +
                        r**2) + r * R[R >= r] / (R[R >= r]**2 + r**2)
    #serpentine + circle

    #a = W*((U-U2)**2 + (V-V2)**2)
    #print(a.shape)

    #Determine integral of weighting function
    Area = simps(simps(W, y), x)

    return np.sum(W * ((U - U2)**2 + (V - V2)**2)) / Area
def minfuncVecField10r_rect(params, U, V, x, y):
    import numpy as np
    import PIVutils
    from scipy.integrate import simps

    big_ = max(U.shape)
    a, b = U.shape

    if len(x) > len(y): x1 = y1 = x
    else: x1 = y1 = y

    [U2_, V2_] = PIVutils.genHairpinField_V3(int((big_ - 1) / 2),
                                             *params,
                                             x=x1,
                                             y=y1)

    [U2, V2] = Reshaped(U2_, V2_, U.shape)

    W = np.zeros(U.shape)
    X, Y = np.meshgrid(x, y)
    R = np.hypot(X - params[2], Y - params[2])

    #print(R.shape, W.shape, 'RW')
    #print(x.shape, y.shape, 'xy')

    W[R <= params[1]] = 1
    W[R >= params[1]] = params[1] / R[R >= params[1]]

    #Determine integral of weighting function
    #Area = simps(simps(W, y), x)
    Area = simps(simps(W, x), y)

    #Area = 1
    obj = W * ((U - U2)**2 + (V - V2)**2)

    return np.sum(obj) / Area
Exemple #6
0
def psf(G):
    import PIVutils
    PIVutils.plotScalarField(G)
    return 
Exemple #7
0
def init_data(mat_path = "C:/Users/Kommalapati sahil/Desktop/owen"):
    """
    used to load initial data to begin the simulations. 
    returns X, Y, U, V, Swirl, Cond,Prof 
    """
    import matplotlib.pyplot as plt
    import numpy as np
    import h5py
    from importlib import reload
    from scipy import interpolate
    import PIVutils
    import PODutils

    import os
    import sys 
    
    noEdge = True
    interpVecs = True

    print("current path :", sys.executable)


    
    X, Y, U, V, Swirl, Cond, Prof = PIVutils.loadDataset(mat_path + "/RNV45-RI2.mat",\
                                                         ['X','Y','U','V','Swirl'],['Cond','Prof'],matlabData = True)
    
    #print("Uinf", Cond["Uinf"][0][0])

    X = X/Cond["delta"]
    Y = Y/Cond["delta"]

    NanLocs = np.isnan(Swirl)
    uSize = Swirl.shape
    scale = (X[1,-1]-X[1,1])/(uSize[1]-1)

    #interpolate
    missVecs = np.zeros(U.shape)
    missVecs[np.isnan(U)] = 1
    PercentMissing = np.zeros(U.shape[2])
    for i in range(U.shape[2]):
        PercentMissing[i] = missVecs[:,:,i].sum()/(U.shape[0]*U.shape[1])*100

    if interpVecs:
        for i in range(uSize[2]):
            #print(i)
            f = interpolate.interp2d(X[0,:], Y[:,0], U[:,:,i], kind='linear')
            U[:,:,i] = f(X[0,:],Y[:,0])
            f = interpolate.interp2d(X[0,:], Y[:,0], V[:,:,i], kind='linear')
            V[:,:,i] = f(X[0,:],Y[:,0])   
            f = interpolate.interp2d(X[0,:], Y[:,0], Swirl[:,:,i], kind='linear')
            Swirl[:,:,i] = f(X[0,:],Y[:,0]) 

    #remove background noise
    Noise = np.std(Swirl,axis=(2,1))
    Noise = np.std(Noise[-5:])
    print(Noise)

    SwirlFilt = Swirl.copy()    #think this should completely copy the list, allowing me to try things

    NoiseFilt = 20      # Filter at 20 times rms of freestream swirl 

    #Swirl must be above a certain background value or it is zeroed
    SwirlFilt[np.absolute(Swirl)<NoiseFilt*Noise] = 0

    #noramlize with std
    SwirlStd = np.std(Swirl,axis=(2,1))
    #print(SwirlStd)

    #Normalize field by the std of Swirl
    SwirlFilt = SwirlFilt/SwirlStd.reshape(uSize[0],1,1) #match the SwirlStd length (123) with the correct index in Swirl (also 123)

    SwirlFiltBackup = SwirlFilt.copy()

    # Create thresholded field
    SwirlFilt = SwirlFiltBackup.copy()    #think this should completely copy the list, allowing me to try things

    #Then only keep those locations where swirls is greater than Thresh*SwirlStd

    #Unified V 5 major change! *here*
    ThreshSTD = 0.6
    SwirlFilt[np.absolute(SwirlFilt)<ThreshSTD] = 0
    SwirlFiltPro = SwirlFilt.copy()
    SwirlFiltPro[SwirlFiltPro>0] = 0
    SwirlFiltRet = SwirlFilt.copy()
    SwirlFiltRet[SwirlFiltRet<0] = 0
    
    return X, Y, U, V,Swirl, Cond,Prof, SwirlFiltPro, SwirlFiltRet, SwirlFilt