예제 #1
0
    def testFenton(self):
        from proteus.WaveTools import MonochromaticWaves
        period = 1. 
        waveHeight = 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])
        phi0 = random.random()*2.*pi 
        wl = 10.
        YC =  np.array([5.,4.,3.,2.,1.])
        BC =  np.array([1.,2.,3.,4.,5.]) 
        mv =  np.array([6.,7.,8.])
# Set-up of Y and B coeffs does not correspond to physical properties
        a = MonochromaticWaves(period,waveHeight,mwl,depth,g,waveDir,wavelength=wl,waveType="Fenton",Ycoeff = YC, Bcoeff = BC, meanVelocity = mv,phi0 = phi0) 
        x = random.random()*200. - 100.
        y = random.random()*200. - 100.
        z =  mwl - depth + random.random()*( depth)
        t =  random.random()*200. - 100.
        eta = a.eta([x, y, z], t)
        ux, uy, uz = a.u([x, y, z], t)
        omega = 2.*pi/period
# setDirVector are tested above
        from proteus.WaveTools import setDirVector
        kw = 2*pi/wl
        z0 = z - mwl
        normDir = setDirVector(waveDir)       
        amp = 0.5 * waveHeight
        etaRef = 0.
        uxRef = 0.
        uyRef = 0.
        uzRef = 0.
        jj = 0
        uxRef= mv[0]
        uyRef= mv[1]
        uzRef= mv[2]

        for ii in range(len(YC)):
            jj+=1
            etaRef+=YC[ii]*cos(jj*kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-jj*omega*t + jj*phi0)/kw
            uxRef += normDir[0]* np.sqrt(gAbs/kw)*jj*BC[ii]*cosh(jj*kw*(z0+depth)) *cos(jj*kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-jj*omega*t +jj*phi0)/cosh(jj*kw*depth)
            uyRef += normDir[1]* np.sqrt(gAbs/kw)*jj*BC[ii]*cosh(jj*kw*(z0+depth)) *cos(jj*kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-jj*omega*t +jj*phi0)/cosh(jj*kw*depth)
            uzRef +=  np.sqrt(gAbs/kw)*jj*BC[ii]*sinh(jj*kw*(z0+depth)) *sin(jj*kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z)-jj*omega*t +jj*phi0)/cosh(jj*kw*depth)
            
#            uxRef+=  normDir[0]*amp*omega*cosh(kw*(z0+depth))*cos(kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z) - omega * t +phi0)/sinh(kw*depth)
#*jj*BC[ii]*normDir[0]*cosh(jj*kw*(z0+depth))*cos(jj*kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z) - jj*omega * t +phi0)*tanh(jj*kw*depth)/sinh(jj*kw*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))
예제 #2
0
    def testLinear(self):
        from proteus.WaveTools import MonochromaticWaves
        import random
# Wave direction, random in x,y plane
        period = 1 
        waveHeight = 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])
        phi0 = random.random()*2.*pi        
        a = MonochromaticWaves(period,waveHeight,mwl,depth,g,waveDir,wavelength=None,waveType="Linear",Ycoeff = None, Bcoeff =None, meanVelocity = np.array([0.,0,0.]),phi0 = phi0)
        x = random.random()*200. - 100.
        y = random.random()*200. - 100.
        z = mwl - depth + random.random()*( depth)
        t =  random.random()*200. - 100.
        eta = a.eta([x, y, z], t)
        ux, uy, uz = a.u([x, y, z], t)

        omega = 2.*pi/period
# dispersion and setDirVector are tested above
        from proteus.WaveTools import dispersion,setDirVector
        kw = dispersion(omega,depth,gAbs)
        normDir = setDirVector(waveDir)
        amp = 0.5 * waveHeight
# Flow equation from Wikipedia, Airy wave theory https://en.wikipedia.org/wiki/Airy_wave_theoryhttps://en.wikipedia.org/wiki/Airy_wave_theory
        etaRef = amp*cos(kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z) - omega * t +phi0)
        z0 = z - mwl
        uxRef = normDir[0]*amp*omega*cosh(kw*(z0+depth))*cos(kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z) - omega * t +phi0)/sinh(kw*depth)
        uyRef = normDir[1]*amp*omega*cosh(kw*(z0+depth))*cos(kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z) - omega * t +phi0)/sinh(kw*depth)
        uzRef = amp*omega*sinh(kw*(z0+depth))*sin(kw*(normDir[0]*x+normDir[1]*y+normDir[2]*z) - omega * t +phi0)/sinh(kw*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) )
예제 #3
0
 def test_unsteady_two_phase_velocity_inlet(self):
     from proteus.WaveTools import MonochromaticWaves
     b_or = np.array([[0., -1., 0.]])
     b_i = 0
     BC = create_BC(folder='mprans', b_or=b_or, b_i=b_i)
     # creating a wave
     period = 0.8
     height = 0.029
     mwl = depth = 0.9
     direction = np.array([1., 0., 0.])
     g = np.array([0., -9.81, 0.])
     waves = MonochromaticWaves(period, height, mwl, depth, g, direction)
     # need to set epsFact and he with context as they are called in BC...
     ct = get_context()
     from proteus.ctransportCoefficients import smoothedHeaviside
     #-----
     # set BC
     wind_speed=np.array([1., 2., 3.4])
     smoothing = 0.
     BC.setUnsteadyTwoPhaseVelocityInlet(waves, smoothing, vert_axis=1,
                                         wind_speed=wind_speed)
     BC.getContext(ct)
     BC.u_dirichlet.uOfXT = BC.u_dirichlet.init_cython()
     BC.v_dirichlet.uOfXT = BC.v_dirichlet.init_cython()
     BC.w_dirichlet.uOfXT = BC.w_dirichlet.init_cython()
     BC.vof_dirichlet.uOfXT = BC.vof_dirichlet.init_cython()
     BC.p_advective.uOfXT = BC.p_advective.init_cython()
     u_dir, v_dir, w_dir, vof_dir, p_adv = [], [], [], [], []
     u_calc, vof_calc, p_calc = [], [], []
     t_list = get_time_array()
     for t in t_list:
         x = np.array(get_random_x())
         u_dir += [BC.u_dirichlet.uOfXT(x, t)]
         v_dir += [BC.v_dirichlet.uOfXT(x, t)]
         w_dir += [BC.w_dirichlet.uOfXT(x, t)]
         vof_dir += [BC.vof_dirichlet.uOfXT(x, t)]
         p_adv += [BC.p_advective.uOfXT(x, t)]
         # calculations
         waveHeight = waves.mwl+waves.eta(x, t)
         wavePhi = x[1]-waveHeight
         if wavePhi <= 0:
             H = 0.
             wave_u = waves.u(x, t)
         elif smoothing > 0 and 0 < wavePhi <= smoothing:
             H = smoothedHeaviside(0.5*smoothing, wavePhi-0.5*smoothing)
             x_max = list(x)
             x_max[1] = waveHeight
             wave_u = waves.u(x_max, t)
         else:
             H = 1.
             wave_u = np.array([0., 0., 0.])
         U = H*wind_speed + (1-H)*wave_u
         u_calc += [U]
         p_calc += [np.sum(U*b_or[b_i])]
         if wavePhi >= smoothing/2.:
             Hvof = 1.
         elif smoothing > 0 and -smoothing/2. < wavePhi < smoothing/2.:
             Hvof = smoothedHeaviside(smoothing, wavePhi)
         elif wavePhi <= -smoothing/2.:
             Hvof = 0.
         vof_calc += [Hvof]
     u_calc = np.array(u_calc)
     vof_calc = np.array(vof_calc)
     npt.assert_equal(BC.p_dirichlet.uOfXT, None)
     npt.assert_equal(u_dir, u_calc[:, 0])
     npt.assert_equal(v_dir, u_calc[:, 1])
     npt.assert_equal(w_dir, u_calc[:, 2])
     npt.assert_equal(vof_dir, vof_calc)
     npt.assert_equal(BC.k_dirichlet.uOfXT, None)
     npt.assert_equal(BC.dissipation_dirichlet.uOfXT, None)
     npt.assert_equal(p_adv, p_calc)
     npt.assert_equal(BC.u_advective.uOfXT, None)
     npt.assert_equal(BC.v_advective.uOfXT, None)
     npt.assert_equal(BC.w_advective.uOfXT, None)
     npt.assert_equal(BC.vof_advective.uOfXT, None)
     npt.assert_equal(BC.k_advective.uOfXT, None)
     npt.assert_equal(BC.dissipation_advective.uOfXT, None)
     npt.assert_equal(BC.u_diffusive.uOfXT, None)
     npt.assert_equal(BC.v_diffusive.uOfXT, None)
     npt.assert_equal(BC.w_diffusive.uOfXT, None)
     npt.assert_equal(BC.k_diffusive.uOfXT, None)
     npt.assert_equal(BC.dissipation_diffusive.uOfXT, None)
예제 #4
0
 def test_unsteady_two_phase_velocity_inlet(self):
     from proteus.WaveTools import MonochromaticWaves
     b_or = [[0., -1., 0.]]
     b_i = 0
     BC = create_BC(folder='mprans', b_or=b_or, b_i=b_i)
     # creating a wave
     period = 0.8
     height = 0.029
     mwl = depth = 0.9
     direction = np.array([1., 0., 0.])
     g = np.array([0., -9.81, 0.])
     waves = MonochromaticWaves(period, height, mwl, depth, g, direction)
     # need to set epsFact and he with context as they are called in BC...
     from proteus import Context
     case = sys.modules[__name__]
     Context.setFromModule(case)
     ct = Context.get()
     ecH = ct.epsFact_consrv_heaviside
     he = ct.domain.MeshOptions.he
     from proteus.ctransportCoefficients import smoothedHeaviside
     #-----
     # set BC
     windSpeed = np.array([1., 2., 3.4])
     BC.setUnsteadyTwoPhaseVelocityInlet(waves,
                                         vert_axis=1,
                                         windSpeed=windSpeed)
     u_dir, v_dir, w_dir, vof_dir, p_adv = [], [], [], [], []
     u_calc, vof_calc, p_calc = [], [], []
     t_list = get_time_array()
     for t in t_list:
         x = np.array(get_random_x())
         u_dir += [BC.u_dirichlet(x, t)]
         v_dir += [BC.v_dirichlet(x, t)]
         w_dir += [BC.w_dirichlet(x, t)]
         vof_dir += [BC.vof_dirichlet(x, t)]
         p_adv += [BC.p_advective(x, t)]
         # calculations
         waveHeight = waves.mwl + waves.eta(x, t)
         wavePhi = x[1] - waveHeight
         if wavePhi <= 0:
             wave_u = waves.u(x, t)
         else:
             x_max = list(x)
             x_max[1] = waveHeight
             wave_u = waves.u(x_max, t)
         Hu = smoothedHeaviside(0.5 * ecH * he, wavePhi - 0.5 * ecH * he)
         U = Hu * windSpeed + (1 - Hu) * wave_u
         u_calc += [U]
         p_calc += [np.sum(U * b_or[b_i])]
         Hvof = smoothedHeaviside(ecH * he, wavePhi)
         vof_calc += [Hvof]
     u_calc = np.array(u_calc)
     vof_calc = np.array(vof_calc)
     npt.assert_equal(BC.p_dirichlet, None)
     npt.assert_equal(u_dir, u_calc[:, 0])
     npt.assert_equal(v_dir, u_calc[:, 1])
     npt.assert_equal(w_dir, u_calc[:, 2])
     npt.assert_equal(vof_dir, vof_calc)
     npt.assert_equal(BC.k_dirichlet, None)
     npt.assert_equal(BC.dissipation_dirichlet, None)
     npt.assert_equal(p_adv, p_calc)
     npt.assert_equal(BC.u_advective, None)
     npt.assert_equal(BC.v_advective, None)
     npt.assert_equal(BC.w_advective, None)
     npt.assert_equal(BC.vof_advective, None)
     npt.assert_equal(BC.k_advective, None)
     npt.assert_equal(BC.dissipation_advective, None)
     npt.assert_equal(BC.u_diffusive, None)
     npt.assert_equal(BC.v_diffusive, None)
     npt.assert_equal(BC.w_diffusive, None)
     npt.assert_equal(BC.k_diffusive, None)
     npt.assert_equal(BC.dissipation_diffusive, None)
예제 #5
0
 def test_unsteady_two_phase_velocity_inlet(self):
     from proteus.WaveTools import MonochromaticWaves
     b_or = [[0., -1., 0.]]
     b_i = 0
     BC = create_BC(folder='mprans', b_or=b_or, b_i=b_i)
     # creating a wave
     period = 0.8
     height = 0.029
     mwl = depth = 0.9
     direction = np.array([1., 0., 0.])
     g = np.array([0., -9.81, 0.])
     waves = MonochromaticWaves(period, height, mwl, depth, g, direction)
     # need to set epsFact and he with context as they are called in BC...
     ct = get_context()
     from proteus.ctransportCoefficients import smoothedHeaviside
     #-----
     # set BC
     wind_speed=np.array([1., 2., 3.4])
     BC.setUnsteadyTwoPhaseVelocityInlet(waves, vert_axis=1,
                                         wind_speed=wind_speed)
     BC.getContext(ct)
     BC.u_dirichlet.uOfXT = BC.u_dirichlet.init_cython()
     BC.v_dirichlet.uOfXT = BC.v_dirichlet.init_cython()
     BC.w_dirichlet.uOfXT = BC.w_dirichlet.init_cython()
     BC.vof_dirichlet.uOfXT = BC.vof_dirichlet.init_cython()
     BC.p_advective.uOfXT = BC.p_advective.init_cython()
     u_dir, v_dir, w_dir, vof_dir, p_adv = [], [], [], [], []
     u_calc, vof_calc, p_calc = [], [], []
     t_list = get_time_array()
     for t in t_list:
         x = np.array(get_random_x())
         u_dir += [BC.u_dirichlet.uOfXT(x, t)]
         v_dir += [BC.v_dirichlet.uOfXT(x, t)]
         w_dir += [BC.w_dirichlet.uOfXT(x, t)]
         vof_dir += [BC.vof_dirichlet.uOfXT(x, t)]
         p_adv += [BC.p_advective.uOfXT(x, t)]
         # calculations
         waveHeight = waves.mwl+waves.eta(x, t)
         wavePhi = x[1]-waveHeight
         if wavePhi <= 0:
             wave_u = waves.u(x, t)
         elif wavePhi > 0 and wavePhi < 0.5*ct.ecH*ct.he:
             x_max = list(x)
             x_max[1] = waveHeight
             wave_u = waves.u(x_max, t)
         else:
             wave_u = np.array([0., 0., 0.])
         Hu = smoothedHeaviside(0.5*ct.ecH*ct.he, wavePhi-0.5*ct.ecH*ct.he)
         U = Hu*wind_speed + (1-Hu)*wave_u
         u_calc += [U]
         p_calc += [np.sum(U*b_or[b_i])]
         Hvof = smoothedHeaviside(ct.ecH*ct.he, wavePhi)
         vof_calc += [Hvof]
     u_calc = np.array(u_calc)
     vof_calc = np.array(vof_calc)
     npt.assert_equal(BC.p_dirichlet.uOfXT, None)
     npt.assert_equal(u_dir, u_calc[:, 0])
     npt.assert_equal(v_dir, u_calc[:, 1])
     npt.assert_equal(w_dir, u_calc[:, 2])
     npt.assert_equal(vof_dir, vof_calc)
     npt.assert_equal(BC.k_dirichlet.uOfXT, None)
     npt.assert_equal(BC.dissipation_dirichlet.uOfXT, None)
     npt.assert_equal(p_adv, p_calc)
     npt.assert_equal(BC.u_advective.uOfXT, None)
     npt.assert_equal(BC.v_advective.uOfXT, None)
     npt.assert_equal(BC.w_advective.uOfXT, None)
     npt.assert_equal(BC.vof_advective.uOfXT, None)
     npt.assert_equal(BC.k_advective.uOfXT, None)
     npt.assert_equal(BC.dissipation_advective.uOfXT, None)
     npt.assert_equal(BC.u_diffusive.uOfXT, None)
     npt.assert_equal(BC.v_diffusive.uOfXT, None)
     npt.assert_equal(BC.w_diffusive.uOfXT, None)
     npt.assert_equal(BC.k_diffusive.uOfXT, None)
     npt.assert_equal(BC.dissipation_diffusive.uOfXT, None)