Esempio n. 1
0
 def testIntegrateRectangles3D(self): # Testing the integration fynction for y = 2*x at [0,1]. The area should be 1
     from proteus.WaveTools import reduceToIntervals,returnRectangles3D
     x = np.linspace(0,1,101)
     dx = 0.01
     z = np.linspace(0,1,201)
     dz = 0.005
     xim = reduceToIntervals(x,dx)
     zim = reduceToIntervals(z,dz)
     y1 = np.zeros((len(xim),len(zim)),)
             
     for j in range(len(zim)):
         for i in range(len(xim)):
             y1[i,j] = 2.*xim[i]*zim[j]
     
     A = sum(sum(returnRectangles3D(y1,xim,zim)))
     # Integrate function z*(2*x) over x[0,1], z[0,1] result == 0.5
     self.assertTrue(round(A,10)== 0.5)
Esempio n. 2
0
    def testIntegrateRectangles(self): # Testing the integration fynction for y = 2*x at [0,1]. The area should be 1

        from proteus.WaveTools import reduceToIntervals,returnRectangles 
        x = np.linspace(0,1,101)
        dx = 0.01
        xim = reduceToIntervals(x,dx)
        y = 2*xim 
        A = sum(returnRectangles(y,xim))
        self.assertTrue(round(A,10) == 1.0)
Esempio n. 3
0
 def testReduceToIntervals(self):
     from proteus.WaveTools import reduceToIntervals
     fi = np.linspace(0, 100, 101)
     df = 1
     fr = reduceToIntervals(fi,df)
     fi[:-1]+=0.5
     fi_te = np.zeros(len(fi)+1,)
     fi_te[1:] = fi[:]
     self.assertTrue((fr- fi_te == 0).all())
Esempio n. 4
0
    def testDirectional(self):
        from proteus.WaveTools import DirectionalWaves
        import random
        # Assinging a random value at a field and getting the expected output
        Tp = 1. 
        Hs = 0.15
        mwl = 4.5
        depth = 0.9
        g = np.array([0,0,-9.81])
        gAbs = 9.81
        # Setting the angle to the first quadrant otherwise the acos function further below is confused
        theta0 = 2*pi* random.random()
        dir1 = cos(theta0)
        dir2 = sin(theta0)

        waveDir = np.array([dir1,dir2, 0])
        N = 5
        M = 10
        phi =  2.0*pi*np.random.rand(2*M+1,N)
        gamma = 1.2
        TMA = True
        spectName = "JONSWAP"
        spectral_params =  {"gamma": gamma, "TMA": TMA,"depth": depth}
        bandFactor = 2.0
        spreadName = "mitsuyasu"
        spread_params = {"f0": 1./Tp, "smax": 15.}
        phiSymm = False

        aa= DirectionalWaves(
            M,
            Tp,
            Hs,
            mwl,#m significant wave height
            depth ,           #m depth
            waveDir,
            g,      #peak  frequency
            N,
            bandFactor,         #accelerationof gravity
            spectName,
            spreadName,
            spectral_params,
            spread_params,
            phi,
            phiSymm
            )
        x = random.random()*200. - 100.
        y = random.random()*200. - 100.
        z =  mwl - depth + random.random()*( depth)
        t =  random.random()*200. - 100.
        eta = aa.eta([x, y, z], t)
        ux, uy, uz = aa.u([x, y, z], t)

        # Testing with a specific phi array

        # setDirVector are tested above
        from proteus.WaveTools import setDirVector, dispersion, reduceToIntervals, returnRectangles3D, JONSWAP,mitsuyasu, normIntegral

        fmin = 1./(Tp * bandFactor) 
        fmax = bandFactor/(Tp)
        fi = np.linspace(fmin,fmax,N)
        thetas = np.linspace(theta0 - pi/2,theta0+pi/2,2*M+1)
        dth = pi/(2*M)
        df = (fmax-fmin)/(N - 1 )
        ki = dispersion(2*pi*fi,depth)
        waveDirs = np.zeros((2*M+1,3),)
        for jj in range(2*M+1):
            waveDirs[jj,:] = np.array([cos(thetas[jj]),sin(thetas[jj]),0])
        z0 = z - mwl
        fim = reduceToIntervals(fi,df)
        thetas-=theta0
        thetas_m = reduceToIntervals(thetas,dth)
        Si_Jm = JONSWAP(fim,1./Tp,Hs,gamma,TMA, depth)
        Si_dir = mitsuyasu(thetas_m,fim,1./Tp, 15.)
        for ii in range(0,N):            
            Si_dir[:,ii] = normIntegral(Si_dir[:,ii],thetas_m)
            Si_dir[:,ii]*= Si_Jm[ii] 
        ai = np.sqrt(2.*returnRectangles3D(Si_dir,thetas_m,fim))

        omega = 2*pi*fi
        etaRef = 0.
        uxRef = 0.
        uyRef = 0.
        uzRef = 0.

        for ii in range(N):
            for jj in range(2*M+1):
                normDir = waveDirs[jj,:]
                etaRef+=ai[jj,ii]*cos(ki[ii]*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-omega[ii]*t +phi[jj,ii])
                uxRef += normDir[0]*ai[jj,ii]*omega[ii] *cosh(ki[ii]*(z0+depth)) *cos(ki[ii]*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-omega[ii]*t +phi[jj,ii])/sinh(ki[ii]*depth)
                uyRef += normDir[1]*ai[jj,ii]*omega[ii] *cosh(ki[ii]*(z0+depth)) * cos(ki[ii]*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-omega[ii]*t +phi[jj,ii])/sinh(ki[ii]*depth)
                uzRef +=  ai[jj,ii]*omega[ii] *sinh(ki[ii]*(z0+depth)) * sin(ki[ii]*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-omega[ii]*t +phi[jj,ii])/sinh(ki[ii]*depth)
        self.assertTrue(round(eta,8) == round(etaRef,8) )
        self.assertTrue(round(ux,8) == round(uxRef,8))
        self.assertTrue(round(uy,8) == round(uyRef,8))
        self.assertTrue(round(uz,8) == round(uzRef,8))


        
        ab= DirectionalWaves(
            50,
            2.,
            0.1,
            mwl,
            1. ,
            np.array([1,1,0]),
            g,     
            51,
            1.1,         #accelerationof gravity
            "JONSWAP",
            "cos2s",
            spectral_params=None,
            spread_params={"s":15},
            phi=None,
            phiSymm=False
            )
Esempio n. 5
0
    def testRandom(self):
        from proteus.WaveTools import RandomWaves
        import random
        # Assinging a random value at a field and getting the expected output
        Tp = 1. 
        Hs = 0.15
        mwl = 4.5
        depth = 0.9
        g = np.array([0,0,-9.81])
        gAbs = 9.81
        dir1 = 2*random.random() - 1 
        dir2 = 2*random.random() - 1 
        waveDir = np.array([dir1,dir2, 0])
        N = 100
        phi = np.random.rand(N)
        gamma = 1.2
        TMA = True
        spectName = "JONSWAP"
        bandFactor = 2.0

        a= RandomWaves(Tp,
                     Hs,
                     mwl,#m significant wave height
                     depth ,           #m depth
                     waveDir,
                     g,      #peak  frequency
                     N,
                     bandFactor,         #accelerationof gravity
                     spectName# random words will result in error and return the available spectra 
                   )
        x = random.random()*200. - 100.
        y = random.random()*200. - 100.
        z =  mwl - depth + random.random()*( depth)
        t =  random.random()*200. - 100.
        # Just loading functions
        eta = a.eta([x, y, z], t)
        ux, uy, uz = a.u([x, y, z], t)

        # Testing with a specific phi array
        a= RandomWaves(
            Tp,
            Hs,
            mwl,#m significant wave height
            depth ,           #m depth
            waveDir,
            g,      #peak  frequency
            N,
            bandFactor,         #accelerationof gravity
            spectName, 
            spectral_params =  {"gamma": gamma, "TMA": TMA,"depth": depth}, 
            phi = phi# random words will result in error and return the available spectra 
    )
        eta = a.eta([x, y, z], t)
        ux, uy, uz = a.u([x, y, z], t)


        # setDirVector are tested above
        from proteus.WaveTools import setDirVector, dispersion, reduceToIntervals, returnRectangles, JONSWAP
        fmin = 1./(Tp * bandFactor) 
        fmax = bandFactor/(Tp)
        fi = np.linspace(fmin,fmax,N)
        df = (fmax-fmin)/(N -1 )
        ki = dispersion(2*pi*fi,depth)
        z0 = z - mwl
        normDir = setDirVector(waveDir) 
        fim = reduceToIntervals(fi,df)
        Si_Jm = JONSWAP(fim,1./Tp,Hs,gamma,TMA, depth)
        ai = np.sqrt(2.*returnRectangles(Si_Jm,fim))
        omega = 2*pi*fi
        etaRef = 0.
        uxRef = 0.
        uyRef = 0.
        uzRef = 0.

        for ii in range(N):
            etaRef+=ai[ii]*cos(ki[ii]*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-omega[ii]*t +phi[ii])
            uxRef += normDir[0]*ai[ii]*omega[ii] *cosh(ki[ii]*(z0+depth)) *cos(ki[ii]*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-omega[ii]*t +phi[ii])/sinh(ki[ii]*depth)
            uyRef += normDir[1]*ai[ii]*omega[ii] *cosh(ki[ii]*(z0+depth)) * cos(ki[ii]*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-omega[ii]*t +phi[ii])/sinh(ki[ii]*depth)
            uzRef +=  ai[ii]*omega[ii] *sinh(ki[ii]*(z0+depth)) * sin(ki[ii]*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-omega[ii]*t +phi[ii])/sinh(ki[ii]*depth)
        

        self.assertTrue(round(eta,8) == round(etaRef,8) )
        self.assertTrue(round(ux,8) == round(uxRef,8))
        self.assertTrue(round(uy,8) == round(uyRef,8))
        self.assertTrue(round(uz,8) == round(uzRef,8))




        aa= RandomWaves(2,
                     0.1,
                     0.,#m significant wave height
                     1. ,           #m depth
                     np.array([0.,1,0]),
                     g,      #peak  frequency
                     N,
                     bandFactor,         #accelerationof gravity
                     spectName# random words will result in error and return the available spectra 
                   )