Exemplo n.º 1
0
 def uOfXT(self,x,t):
     if useShock:
         return smoothedHeaviside(epsFact_consrv_heaviside*he,shockSignedDistance(x))
     else:
         surfaceNormal = [-sin(self.slopeAngle),cos(self.slopeAngle)]
         signedDistance = (x[0] - 0.5)*surfaceNormal[0]+(x[2] - self.waterLevel)*surfaceNormal[1]
         return smoothedHeaviside(epsFact_consrv_heaviside*he,signedDistance)
Exemplo n.º 2
0
def getDBC_vof(x,flag):
    if altBC:
        if flag in [domain.boundaryTags['downstream'],domain.boundaryTags['upstream'],domain.boundaryTags['top']]:
            return lambda x,t: smoothedHeaviside(epsFact_consrv_heaviside*he,x[2]-waterLevel)
    else:
        if flag in [domain.boundaryTags['upstream']]:
            return lambda x,t: smoothedHeaviside(epsFact_consrv_heaviside*he,x[2]-waterLevel)
        if flag in [domain.boundaryTags['downstream']]:
            return lambda x,t: smoothedHeaviside(epsFact_consrv_heaviside*he,x[2]-waterLevel)
Exemplo n.º 3
0
 def inlet_vof_dirichlet(x, t):
     from proteus import Context
     ct = Context.get()
     level = wave.mwl + wave.eta(x,t)
     mesh = ct.domain.MeshOptions
     he, ecH = ct.domain.MeshOptions.he, ct.epsFact_consrv_heaviside
     H = smoothedHeaviside(ecH*he,x[vert_axis]-level)
     return H
Exemplo n.º 4
0
 def uOfXT(self,x,t):
     import numpy as np
     beta = epsCoupez*he
     r = math.sqrt((x[0]-self.xc)**2 + (x[1]-self.yc)**2)
     if ct.STABILIZATION_TYPE_ncls==0 or ct.level_set_function==0: #use dist function
         return self.radius - r
     else: #use saturated distance function
         return beta*(2*smoothedHeaviside(beta, self.radius - r)-1)    
Exemplo n.º 5
0
 def __cpp_calculate_smoothing_H(self, phi):
     if phi >= self.smoothing:
         H = 1.
     elif self.smoothing > 0 and -self.smoothing < phi < self.smoothing:
         H = smoothedHeaviside(self.smoothing, phi)
     elif phi <= -self.smoothing:
         H = 0.
     return H
def getDBC_vof(x,flag):
    if setWavesAtInflow:
        return freeSurfaceVOF_bc
    if flag in [domain.boundaryTags['top']]:
        return lambda x,t: 1.0
    #enforce air on right outflow boundary?
    if flag in [domain.boundaryTags['right']]:
        return lambda x,t: 1.0
    #
    if flag in [domain.boundaryTags['left']]:
        return lambda x,t: smoothedHeaviside(epsFact*dy,x[1]-waterLevelBase)
Exemplo n.º 7
0
 def twp_flowVelocity(x, t):
     from proteus import Context
     ct = Context.get()
     vert_axis = self.Shape.Domain.nd-1
     waveHeight = self.waves.mwl+self.waves.eta(x, t)
     wavePhi = x[vert_axis]-waveHeight
     if wavePhi <= 0:
         waterSpeed = self.waves.u(x, t)
     else:
         x_max = np.copy(x)
         x_max[vert_axis] = waveHeight
         waterSpeed = self.waves.u(x_max, t)
     he, ech = ct.domain.MeshOptions.he, ct.epsFact_consrv_heaviside
     H = smoothedHeaviside(0.5*ech*he, wavePhi-0.5*ech*he)
     return H*self.windSpeed[i] + (1-H)*waterSpeed[i]
Exemplo n.º 8
0
 def ux_dirichlet(x, t):
     from proteus import Context
     ct = Context.get()
     waveHeight = wave.mwl+wave.eta(x, t)
     wavePhi = x[vert_axis]-waveHeight
     if wavePhi <= 0:
         waterSpeed = wave.u(x, t)
     else:
         x_max = list(x)
         x_max[vert_axis] = waveHeight
         waterSpeed = wave.u(x_max, t)
     he, ecH = ct.domain.MeshOptions.he, ct.epsFact_consrv_heaviside
     # smoothing only above wave, only on half the VOF smoothing length
     H = smoothedHeaviside(0.5*ecH*he, wavePhi-0.5*ecH*he)
     ux = H*windSpeed + (1-H)*waterSpeed
     return ux[i]
Exemplo n.º 9
0
 def inlet_p_advective(x, t):
     from proteus import Context
     ct = Context.get()
     # This is the normal velocity, based on the outwards boundary
     # orientation b_or
     # needs to be equal to -ux_dirichlet
     b_or = self._b_or[self._b_i]
     nd = len(b_or)
     waterSpeed = np.array(wave.u(x, t))
     waveHeight = wave.mwl+wave.eta(x, t)
     wavePhi = x[vert_axis]-waveHeight
     he = ct.domain.MeshOptions.he
     if wavePhi <= 0:
         waterSpeed = wave.u(x, t)
     else:
         x_max = list(x)
         x_max[vert_axis] = waveHeight
         waterSpeed = wave.u(x_max, t)
     he, ecH = ct.domain.MeshOptions.he, ct.epsFact_consrv_heaviside
     # smoothing only above wave, only on half the VOF smoothing length
     H = smoothedHeaviside(0.5*ecH*he, wavePhi-0.5*ecH*he)
     U = H*windSpeed + (1-H)*waterSpeed
     u_p = np.sum(U[:nd]*b_or)
     return u_p
Exemplo n.º 10
0
def waveVF(x, t):
    return smoothedHeaviside(epsFact_consrv_heaviside * he, wavePhi(x, t))
Exemplo n.º 11
0
 def uOfXT(self,x,t):
     return smoothedHeaviside(epsFact_consrv_heaviside*he,x[2] - inflowHeight(t))
Exemplo n.º 12
0
def twpflowVelocity_u(x, t):
    waterspeed = waveVelocity_u(x, t)
    H = smoothedHeaviside(epsFact_consrv_heaviside * he,
                          wavePhi(x, t) - epsFact_consrv_heaviside * he)
    u = H * windVelocity[0] + (1.0 - H) * waterspeed
    return u
Exemplo n.º 13
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)
Exemplo n.º 14
0
 def uOfXT(self, x, t):
     return smoothedHeaviside(ecH * he, signedDistance(x, 0.))
Exemplo n.º 15
0
def outflowVF(x,t):
    return smoothedHeaviside(epsFact_consrv_heaviside*he,x[1] - outflowHeight)
Exemplo n.º 16
0
 def uOfXT(self,x,t):
     H=smoothedHeaviside(epsFact_consrv_heaviside*0,x[2]-waterLevel)
     return H
Exemplo n.º 17
0
def inflowVelocity_u(x, t):
    waterspeed = inflowVelocityMean[0] + omega * amplitude * sin(
        omega * t) / (k * inflowHeightMean)
    H = smoothedHeaviside(epsFact_consrv_heaviside * he,
                          inflowPhi(x, t) - epsFact_consrv_heaviside * he)
    return H * windspeed_u + (1.0 - H) * waterspeed
Exemplo n.º 18
0
 def uOfXT(self, x, t):
     r = math.sqrt((x[0] - self.xc)**2 + (x[1] - self.yc)**2)
     return smoothedHeaviside(epsFactHeaviside * he, self.radius - r)
Exemplo n.º 19
0
 def test_hydrostatic_pressure_outlet_with_depth(self):
     from proteus.ctransportCoefficients import smoothedHeaviside, smoothedHeaviside_integral
     # input 
     ct = get_context()
     b_or = np.array([[0., -1., 0.]])
     b_i = 0
     seaLevel = 0.5 # m
     rhoUp = 1.004e-6 # kg/m3
     rhoDown = 1.500e-5 # kg/m3
     g = np.array([0., -9.81, 0.]) # m/s2
     refLevel = seaLevel
     smoothing = 3.*0.01 # m
     nd = 2
     vert_axis = nd - 1
     air = 1.
     water = 0.
     pRef = 0. # Pa
     BC = create_BC(folder='mprans', b_or=b_or, b_i=b_i)
     # setting variables
     uDir, vDir, wDir, vofDir, pDir, uDiff, kDiff, dissDiff = [],[],[],[],[],[],[],[]
     vofCalc, pCalc = [],[]
     t_list = get_time_array()
     BC.setHydrostaticPressureOutletWithDepth(seaLevel, rhoUp, rhoDown, g, refLevel, smoothing)
     # time step iterations
     for t in t_list:
         x = np.array(get_random_x())
         vofDir += [BC.vof_dirichlet.uOfXT(x, t)]
         pDir += [BC.p_dirichlet.uOfXT(x, t)]
         # Relative system of coordinates based on the point chosen as reference with pressure=pRef
         phiCalc = x[vert_axis] - seaLevel
         phi_top = refLevel - seaLevel
         phi_ref = phi_top - phiCalc
         rho_diff = rhoUp - rhoDown
         phi_diff = smoothedHeaviside_integral(smoothing, phi_top) - smoothedHeaviside_integral(smoothing, phiCalc)
         pTot = pRef - (g[vert_axis]*rhoDown*phi_ref) - (g[vert_axis]*rho_diff*phi_diff)
         pCalc += [pTot]
         # smoothing for vof activated along either the water-phase and air phase side
         if phiCalc <= -smoothing: 
             Heav = 0.
         elif -smoothing < phiCalc < smoothing: 
             Heav = smoothedHeaviside(smoothing, phiCalc)
         else: 
             Heav = 1.
         vofCalc += [Heav*air + (1.-Heav)*water]
         # Velocity and turbulence variables
         uDir += [BC.u_dirichlet.uOfXT(x, t)]
         vDir += [BC.v_dirichlet.uOfXT(x, t)]
         wDir += [BC.w_dirichlet.uOfXT(x, t)]
         uDiff += [BC.u_diffusive.uOfXT(x, t)]
         kDiff += [BC.k_diffusive.uOfXT(x, t)]
         dissDiff += [BC.dissipation_diffusive.uOfXT(x, t)]
     nt = len(t_list)
     uCalc, vCalc, wCalc, uDiffCalc, kCalc, dissCalc = np.zeros(nt), np.zeros(nt), np.zeros(nt), np.zeros(nt), np.zeros(nt), np.zeros(nt)
     npt.assert_equal(uDir, uCalc)
     npt.assert_equal(vDir, vCalc)
     npt.assert_equal(wDir, wCalc)
     npt.assert_allclose(pDir, pCalc, atol=1e-10)
     npt.assert_equal(vofDir, vofCalc)
     npt.assert_equal(uDiff, uDiffCalc)
     npt.assert_equal(kDiff, kCalc)
     npt.assert_equal(dissDiff, dissCalc)
Exemplo n.º 20
0
def outflowVel(x, t):
    waterspeed = outflowVelocityMean[0]
    H = smoothedHeaviside(epsFact_consrv_heaviside * he,
                          outflowPhi(x, t) - epsFact_consrv_heaviside * he)
    u = (1.0 - H) * waterspeed
    return u
Exemplo n.º 21
0
def outflowVF(x, t):
    return smoothedHeaviside(epsFact_consrv_heaviside * he, outflowPhi(x, t))
Exemplo n.º 22
0
 def uOfXT(self, x, t):
     from proteus.ctransportCoefficients import smoothedHeaviside
     return smoothedHeaviside(1.5 * opts.he, self.phi.uOfXT(x, 0.0))
Exemplo n.º 23
0
    tank.BC['airvent'].vof_dirichlet.uOfXT = lambda x, t: 1.0
    tank.BC['airvent'].u_diffusive.uOfXT = lambda x, t: 0.0
    tank.BC['airvent'].v_diffusive.uOfXT = lambda x, t: 0.0
    

#--- Initial Conditions

def wavePhi(x,t):
    return x[1] - opts.waterLine_z

def outflowPhi(x,t):
    return x[1] - outflow_level

def twpflowVelocity_u(x,t):
    waterspeed = opts.u[0]
    H = smoothedHeaviside(ecH*he,wavePhi(x,t)-ecH*he)
    u = H*windVelocity[0] + (1.0-H)*waterspeed
    return u

def twpflowVelocity_u_D(x, t):
    waterspeed = opts.outflow_velocity
    H = smoothedHeaviside(ecH * he, outflowPhi(x, t) - ecH * he)
    u = H * windVelocity[0] + (1.0 - H) * waterspeed
    return u

def signedDistance(x):
    phi_x = x[0] - opts.waterLine_x
    phi_z = x[1] - opts.waterLine_z
    phi_z_outflow = x[1] - outflow_level
    if phi_x <= 0.0:
        if phi_z < 0.0:
Exemplo n.º 24
0
class VF_IC:
    def uOfXT(self, x, t):
        return smoothedHeaviside(smoothing,opts.outlet_level-x[vert_axis]) 
Exemplo n.º 25
0
def twpflowVelocity_u(x,t):
    waterspeed = waveVelocity_u(x,t)
    H = smoothedHeaviside(epsFact_consrv_heaviside*he,wavePhi(x,t)-epsFact_consrv_heaviside*he)
    u = H*windspeed_u + (1.0-H)*waterspeed#
    print x[2],u
    return u
Exemplo n.º 26
0
def inflowVelocity_v(x, t):
    waterspeed = 0.0
    H = smoothedHeaviside(epsFact_consrv_heaviside * he,
                          inflowPhi(x, t) - epsFact_consrv_heaviside * he)
    return H * windspeed_v + (1.0 - H) * waterspeed
Exemplo n.º 27
0
def waveVF(x,t):
    return smoothedHeaviside(epsFact_consrv_heaviside*he,wavePhi(x,t))
Exemplo n.º 28
0
def inflowVOF(x, t):
    return smoothedHeaviside(epsFact_consrv_heaviside * he, inflowPhi(x, t))
Exemplo n.º 29
0
def inflowVF(x, t):
    return smoothedHeaviside(epsFact_consrv_heaviside * he, inflowPhi(x, t))
 def uOfXT(self,x,t):
     return smoothedHeaviside(self.eps,x[2] - waterLevelBase)
Exemplo n.º 31
0
 def test_hydrostatic_pressure_outlet_with_depth(self):
     from proteus.ctransportCoefficients import smoothedHeaviside, smoothedHeaviside_integral
     # input
     ct = get_context()
     b_or = np.array([[0., -1., 0.]])
     b_i = 0
     seaLevel = 0.5  # m
     rhoUp = 1.004e-6  # kg/m3
     rhoDown = 1.500e-5  # kg/m3
     g = np.array([0., -9.81, 0.])  # m/s2
     refLevel = seaLevel
     smoothing = 3. * 0.01  # m
     nd = 2
     vert_axis = nd - 1
     air = 1.
     water = 0.
     pRef = 0.  # Pa
     BC = create_BC(folder='mprans', b_or=b_or, b_i=b_i)
     # setting variables
     uDir, vDir, wDir, vofDir, pDir, vDiff, kDiff, dissDiff = [],[],[],[],[],[],[],[]
     pInc_dir, pInit_dir = [], []
     vofCalc, pCalc = [], []
     t_list = get_time_array()
     BC.setHydrostaticPressureOutletWithDepth(seaLevel, rhoUp, rhoDown, g,
                                              refLevel, smoothing)
     # time step iterations
     for t in t_list:
         x = np.array(get_random_x())
         vofDir += [BC.vof_dirichlet.uOfXT(x, t)]
         pDir += [BC.p_dirichlet.uOfXT(x, t)]
         # Relative system of coordinates based on the point chosen as reference with pressure=pRef
         phiCalc = x[vert_axis] - seaLevel
         phi_top = refLevel - seaLevel
         phi_ref = phi_top - phiCalc
         rho_diff = rhoUp - rhoDown
         phi_diff = smoothedHeaviside_integral(
             smoothing, phi_top) - smoothedHeaviside_integral(
                 smoothing, phiCalc)
         pTot = pRef - (g[vert_axis] * rhoDown *
                        phi_ref) - (g[vert_axis] * rho_diff * phi_diff)
         pCalc += [pTot]
         # smoothing for vof activated along either the water-phase and air phase side
         if phiCalc <= -smoothing:
             Heav = 0.
         elif -smoothing < phiCalc < smoothing:
             Heav = smoothedHeaviside(smoothing, phiCalc)
         else:
             Heav = 1.
         vofCalc += [Heav * air + (1. - Heav) * water]
         # Velocity and turbulence variables
         uDir += [BC.u_dirichlet.uOfXT(x, t)]
         vDir += [BC.v_dirichlet.uOfXT]
         wDir += [BC.w_dirichlet.uOfXT(x, t)]
         vDiff += [BC.v_diffusive.uOfXT(x, t)]
         kDiff += [BC.k_diffusive.uOfXT(x, t)]
         dissDiff += [BC.dissipation_diffusive.uOfXT(x, t)]
     nt = len(t_list)
     uCalc, vCalc, wCalc, vDiffCalc, kCalc, dissCalc = np.zeros(
         nt), np.zeros(nt), np.zeros(nt), np.zeros(nt), np.zeros(
             nt), np.zeros(nt)
     npt.assert_equal(uDir, uCalc)
     npt.assert_equal(BC.v_dirichlet.uOfXT, None)
     npt.assert_equal(wDir, wCalc)
     npt.assert_allclose(pDir, pCalc, atol=1e-10)
     npt.assert_equal(vofDir, vofCalc)
     npt.assert_equal(vDiff, vDiffCalc)
     npt.assert_equal(kDiff, kCalc)
     npt.assert_equal(dissDiff, dissCalc)
Exemplo n.º 32
0
def outflowVF(x, t):
    return smoothedHeaviside(epsFact_consrv_heaviside * he,
                             x[2] - outflowHeight)
Exemplo n.º 33
0
 def uOfXT(self, x, t):
     return smoothedHeaviside(ct.ecH * ct.he, ct.signedDistance(x))
Exemplo n.º 34
0
def outflowVF(x, t):
    return smoothedHeaviside(epsFact_consrv_heaviside * he, x[2] - inflowHeightMean)
Exemplo n.º 35
0
 def uOfXT(self, x, t):
     return smoothedHeaviside(epsFact_consrv_heaviside * he,
                              signedDistance(x))
Exemplo n.º 36
0
 def uOfXT(self,x,t):
     return smoothedHeaviside(ecH*he,signedDistance(x))
Exemplo n.º 37
0
 def uOfXT(self, x, t):
     return smoothedHeaviside(ct.epsFact_consrv_heaviside * mesh.he,
                              x[nd - 1] - ct.waterLevel)
Exemplo n.º 38
0
    def PUMI_transferFields(self):
        p0 = self.pList[0].ct
        n0 = self.nList[0].ct

        if self.TwoPhaseFlow:
            domain = p0.myTpFlowProblem.domain
            rho_0 = p0.myTpFlowProblem.physical_parameters['densityA']
            nu_0 = p0.myTpFlowProblem.physical_parameters[
                'kinematicViscosityA']
            rho_1 = p0.myTpFlowProblem.physical_parameters['densityB']
            nu_1 = p0.myTpFlowProblem.physical_parameters[
                'kinematicViscosityB']
            g = p0.myTpFlowProblem.physical_parameters['gravity']
            epsFact_density = p0.myTpFlowProblem.clsvof_parameters[
                'epsFactHeaviside']
        else:
            domain = p0.domain
            rho_0 = p0.rho_0
            nu_0 = p0.nu_0
            rho_1 = p0.rho_1
            nu_1 = p0.nu_1
            g = p0.g
            epsFact_density = p0.epsFact_density
        logEvent("Copying coordinates to PUMI")
        domain.PUMIMesh.transferFieldToPUMI(
            b"coordinates", self.modelList[0].levelModelList[0].mesh.nodeArray)

        #I want to compute the density and viscosity arrays here
        #arrays are length = number of elements and will correspond to density at center of element
        rho_transfer = numpy.zeros(
            (self.modelList[0].levelModelList[0].mesh.nElements_owned), 'd')
        nu_transfer = numpy.zeros(
            (self.modelList[0].levelModelList[0].mesh.nElements_owned), 'd')
        #get quadrature points at element centroid and evaluate at shape functions
        from proteus import Quadrature
        transferQpt = Quadrature.SimplexGaussQuadrature(p0.domain.nd, 1)
        qpt_centroid = numpy.asarray([transferQpt.points[0]])
        materialSpace = self.nList[0].femSpaces[0](
            self.modelList[0].levelModelList[0].mesh.subdomainMesh,
            p0.domain.nd)
        materialSpace.getBasisValuesRef(qpt_centroid)

        #obtain the level-set or vof value at each element centroid
        #pass through heaviside function to get material property
        from proteus.ctransportCoefficients import smoothedHeaviside

        IEN = self.modelList[2].levelModelList[0].u[0].femSpace.dofMap.l2g
        for (eID, dofs) in enumerate(IEN):
            phi_val = 0.0
            for idx in range(len(dofs)):
                phi_val += materialSpace.psi[0][idx] * self.modelList[
                    2].levelModelList[0].u[0].dof[dofs[idx]]
            #rho_transfer[eID] = phi_val

            #heaviside
            h_phi = 0.0
            for idx in range(len(dofs)):
                h_phi += (materialSpace.psi[0][idx]) * (self.modelList[
                    2].levelModelList[0].mesh.nodeDiametersArray[dofs[idx]])
            eps_rho = p0.epsFact_density * h_phi
            smoothed_phi_val = smoothedHeaviside(eps_rho, phi_val)

            rho_transfer[eID] = (1.0 - smoothed_phi_val) * self.pList[
                0].ct.rho_0 + smoothed_phi_val * self.pList[0].ct.rho_1
            nu_transfer[eID] = (1.0 - smoothed_phi_val) * self.pList[
                0].ct.nu_0 + smoothed_phi_val * self.pList[0].ct.nu_1

        self.modelList[0].levelModelList[0].mesh.elementMaterial = numpy.zeros(
            (self.modelList[0].levelModelList[0].mesh.nElements_owned), 'd')
        self.modelList[0].levelModelList[
            0].mesh.elementMaterial[:] = rho_transfer[:]

        #put the solution field as uList
        #VOF and LS needs to reset the u.dof array for proper transfer
        #but needs to be returned to the original form if not actually adapting....be careful with the following statements, unsure if this doesn't break something else
        import copy
        for m in self.modelList:
            for lm in m.levelModelList:
                lm.u_store = lm.u.copy()
                for ci in range(0, lm.coefficients.nc):
                    lm.u_store[ci] = lm.u[ci].copy()

        self.modelList[1].levelModelList[0].setUnknowns(
            self.modelList[1].uList[0])
        self.modelList[2].levelModelList[0].setUnknowns(
            self.modelList[2].uList[0])

        logEvent("Copying DOF and parameters to PUMI")
        for m in self.modelList:
            for lm in m.levelModelList:
                coef = lm.coefficients
                if coef.vectorComponents is not None:
                    vector = numpy.zeros((lm.mesh.nNodes_global, 3), 'd')
                    for vci in range(len(coef.vectorComponents)):
                        vector[:,
                               vci] = lm.u[coef.vectorComponents[vci]].dof[:]

                    domain.PUMIMesh.transferFieldToPUMI(
                        coef.vectorName.encode('utf-8'), vector)
                    #Transfer dof_last
                    for vci in range(len(coef.vectorComponents)):
                        vector[:, vci] = lm.u[
                            coef.vectorComponents[vci]].dof_last[:]
                    domain.PUMIMesh.transferFieldToPUMI(
                        coef.vectorName.encode('utf-8') + b"_old", vector)
                    #Transfer dof_last_last
                    for vci in range(len(coef.vectorComponents)):
                        vector[:, vci] = lm.u[
                            coef.vectorComponents[vci]].dof_last_last[:]
                    p0.domain.PUMIMesh.transferFieldToPUMI(
                        coef.vectorName.encode('utf-8') + b"_old_old", vector)

                    del vector
                for ci in range(coef.nc):
                    if coef.vectorComponents is None or \
                       ci not in coef.vectorComponents:
                        scalar = numpy.zeros((lm.mesh.nNodes_global, 1), 'd')
                        scalar[:, 0] = lm.u[ci].dof[:]
                        domain.PUMIMesh.transferFieldToPUMI(
                            coef.variableNames[ci].encode('utf-8'), scalar)

                        #Transfer dof_last
                        scalar[:, 0] = lm.u[ci].dof_last[:]
                        domain.PUMIMesh.transferFieldToPUMI(
                            coef.variableNames[ci].encode('utf-8') + b"_old",
                            scalar)
                        #Transfer dof_last_last
                        scalar[:, 0] = lm.u[ci].dof_last_last[:]
                        p0.domain.PUMIMesh.transferFieldToPUMI(
                            coef.variableNames[ci].encode('utf-8') +
                            b"_old_old", scalar)

                        del scalar

        scalar = numpy.zeros((lm.mesh.nNodes_global, 1), 'd')

        del scalar
        #Get Physical Parameters
        #Can we do this in a problem-independent  way?

        rho = numpy.array([rho_0, rho_1])
        nu = numpy.array([nu_0, nu_1])
        g = numpy.asarray(g)

        #This condition is to account for adapting before the simulation started
        if (hasattr(self, "tn")):
            #deltaT = self.tn-self.tn_last
            #is actually the time step for next step, self.tn and self.tn_last refer to entries in tnList
            #deltaT = self.systemStepController.dt_system
            deltaT = self.modelList[0].levelModelList[0].timeIntegration.dtLast
            T_current = self.systemStepController.t_system_last
            deltaT_next = self.systemStepController.dt_system
        else:
            deltaT = 0
            deltaT_next = 0.0
            T_current = 0.0

        epsFact = epsFact_density
        #domain.PUMIMesh.transferPropertiesToPUMI(rho,nu,g,deltaT,epsFact)
        domain.PUMIMesh.transferPropertiesToPUMI(rho_transfer, nu_transfer, g,
                                                 deltaT, deltaT_next,
                                                 T_current, epsFact)

        del rho, nu, g, epsFact
Exemplo n.º 39
0
def twpflowVelocity_w(x, t):
    waterspeed = waveVelocity_w(x, t)
    H = smoothedHeaviside(epsFact_consrv_heaviside * he,
                          wavePhi(x, t) - epsFact_consrv_heaviside * he)
    return H * windspeed_w + (1.0 - H) * waterspeed
Exemplo n.º 40
0
def twpflowVelocity_u_D(x, t):
    waterspeed = outflow_velocity
    H = smoothedHeaviside(ecH * he, outflowPhi(x, t) - ecH * he)
    u = H * windVelocity[0] + (1.0 - H) * waterspeed
    return u
Exemplo n.º 41
0
 def uOfX(self,X):
     dx = X[0]-self.center[0]; dy = X[1]-self.center[1];
     dBubble = self.radius - sqrt(dx**2 + dy**2)
     return smoothedHeaviside(epsFactHeaviside*he,dBubble)#Heaviside(dBubble)
Exemplo n.º 42
0
 def uOfXT(self, x, t):
     return smoothedHeaviside(1.5 * opts.he, signedDistance(x))
Exemplo n.º 43
0
def v_current(x, t):
    waterspeed = inflowVelocityMean[1]
    H = smoothedHeaviside(epsFact_consrv_heaviside * he, x[2] - inflowHeightMean - epsFact_consrv_heaviside * he)
    v = H * windVelocity[0] + (1.0 - H) * waterspeed
    return v
Exemplo n.º 44
0
def twpflowVelocity_v(x, t):
    waterspeed = 0.0
    H = smoothedHeaviside(epsFact_consrv_heaviside * he,
                          wavePhi(x, t) - epsFact_consrv_heaviside * he)
    return H * windVelocity[1] + (1.0 - H) * waterspeed
Exemplo n.º 45
0
 def uOfXT(self, x, t):
     return smoothedHeaviside(smoothing,x[nd-1]-water_level)
Exemplo n.º 46
0
 def uOfXT(self, x, t):
     return smoothedHeaviside(opts.ecH * he, signedDistance(x))
 def uOfXT(self,x,t):
     return smoothedHeaviside(self.eps,x[1] - waterLevelBase)
Exemplo n.º 48
0
 def uOfXT(self,X,T):
     return smoothedHeaviside(epsFactHeaviside*he,self.phiSol.uOfXT(X,T))#Heaviside(dBubble)
Exemplo n.º 49
0
def outflowVel(x,t):
    waterspeed = netcurrentVelocity
    H = smoothedHeaviside(epsFact_consrv_heaviside*he,outflowPhi(x,t)-epsFact_consrv_heaviside*he)
    u = (1.0-H)*waterspeed
    return u
Exemplo n.º 50
0
def twpflowVelocity_u(x,t):
    waterspeed = inflowVelocityMean[0]
    H = smoothedHeaviside(epsFact_consrv_heaviside*he,wavePhi(x,t)-epsFact_consrv_heaviside*he)
    u = H*windVelocity[0] + (1.0-H)*waterspeed
    return u
Exemplo n.º 51
0
def twpflowVelocity_w(x,t):
    waterspeed = waveVelocity_w(x,t)
    H = smoothedHeaviside(epsFact_consrv_heaviside*he,wavePhi(x,t)-epsFact_consrv_heaviside*he)
    w = H*windspeed_w+(1.0-H)*waterspeed
    print x[2],w
    return w
Exemplo n.º 52
0
 def uOfX(self,X):
     dx = X[0]-self.center[0]; dy = X[1]-self.center[1];
     dBubble = self.radius - sqrt(dx**2 + dy**2)
     return smoothedHeaviside(epsFactHeaviside*he,dBubble)#Heaviside(dBubble)
Exemplo n.º 53
0
 def H(x,t):
     return smoothedHeaviside(epsFact_consrv_heaviside*0,x[2]-waterLevel)
Exemplo n.º 54
0
 def uOfXT(self, x, t):
     H = smoothedHeaviside(epsFact_consrv_heaviside * 0, x[2] - waterLevel)
     return H
Exemplo n.º 55
0
def twpflowVelocity_v(x,t):
    waterspeed = waveVelocity_v(x,t)
    H = smoothedHeaviside(epsFact_consrv_heaviside*he,wavePhi(x,t)-epsFact_consrv_heaviside*he)
    return H*windVelocity[1]+(1.0-H)*waterspeed
Exemplo n.º 56
0
 def H(x, t):
     return smoothedHeaviside(epsFact_consrv_heaviside * 0,
                              x[2] - waterLevel)
Exemplo n.º 57
0
 def uOfXT(self,x,t):
     return smoothedHeaviside(epsFact_consrv_heaviside*he,signedDistance(x))
Exemplo n.º 58
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()
     BC.pInit_advective.uOfXT = BC.pInit_advective.init_cython()
     u_dir, v_dir, w_dir, vof_dir, p_adv = [], [], [], [], []
     pInc_adv, pInit_adv, us_dir, vs_dir,ws_dir, vof_dir, vos_dir = [], [], [], [], [],[],[]
     u_calc, vof_calc, p_calc = [], [], []
     k_dir, d_dir, k_dif, d_dif = [], [], [], []
     t_list = get_time_array()
     zeros = np.zeros(len(t_list))
     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)]
         k_dir += [BC.k_dirichlet.uOfXT(x, t)]
         d_dir += [BC.dissipation_dirichlet.uOfXT(x, t)]
         k_dif += [BC.k_diffusive.uOfXT(x, t)]
         d_dif += [BC.dissipation_diffusive.uOfXT(x, t)]
         us_dir += [BC.us_dirichlet.uOfXT(x, t)]
         vs_dir += [BC.vs_dirichlet.uOfXT(x, t)]
         ws_dir += [BC.ws_dirichlet.uOfXT(x, t)]
         vof_dir += [BC.vof_dirichlet.uOfXT(x, t)]
         vos_dir += [BC.vos_dirichlet.uOfXT(x, t)]
         p_adv += [BC.p_advective.uOfXT(x, t)]
         pInc_adv += [BC.pInc_advective.uOfXT(x, t)]
         pInit_adv += [BC.pInit_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(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 >= old_div(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)
     kInf = 1e-30 + zeros
     dInf = 1e-10 + zeros
     npt.assert_equal(BC.p_dirichlet.uOfXT, None)
     npt.assert_equal(BC.pInc_dirichlet.uOfXT, None)
     npt.assert_equal(BC.pInit_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(us_dir, zeros)
     npt.assert_equal(vs_dir, zeros)
     npt.assert_equal(ws_dir, zeros)
     npt.assert_equal(vof_dir, vof_calc)
     npt.assert_equal(vos_dir, zeros)
     npt.assert_equal(k_dir, kInf)
     npt.assert_equal(d_dir, dInf)
     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.us_advective.uOfXT, None)
     npt.assert_equal(BC.vs_advective.uOfXT, None)
     npt.assert_equal(BC.ws_advective.uOfXT, None)
     npt.assert_equal(BC.vof_advective.uOfXT, None)
     npt.assert_equal(BC.vos_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.us_diffusive.uOfXT, None)
     npt.assert_equal(BC.vs_diffusive.uOfXT, None)
     npt.assert_equal(BC.ws_diffusive.uOfXT, None)
     npt.assert_equal(k_dif, zeros)
     npt.assert_equal(d_dif, zeros)
Exemplo n.º 59
0
def outflowVF(x, t):
    return smoothedHeaviside(epsFact_density * he, x[1] - outflowHeight)
Exemplo n.º 60
0
 def test_two_phase_velocity_inlet(self):
     from proteus.ctransportCoefficients import smoothedHeaviside
     # input
     ct = get_context()
     b_or = np.array([[0., -1., 0.]])
     b_i = 0
     U0 = [0.1, 0.2, 0.3]  # m/s
     waterDepth = 0.5  # m
     smoothing = 3. * 0.01  # m
     Uwind = [0.01, 0.02, 0.03]  # m/s
     vert_axis = 1  # by default alligned with the gravity
     air = 1.
     water = 0.
     kInflow = 0.00005
     dissipationInflow = 0.00001
     kInflowAir = old_div(kInflow, 10.)
     dissipationInflowAir = old_div(dissipationInflow, 10.)
     BC = create_BC(folder='mprans', b_or=b_or, b_i=b_i)
     # setting variables
     uDir, vDir, wDir, vofDir, pAdv, kDir, dissipationDir = [],[],[],[],[],[],[]
     uCalc, vCalc, wCalc, vofCalc, pCalc, kCalc, dissipationCalc = [],[],[],[],[],[],[]
     t_list = get_time_array()
     BC.setTwoPhaseVelocityInlet(U0, waterDepth, smoothing, Uwind,
                                 vert_axis, air, water, kInflow,
                                 dissipationInflow, kInflowAir,
                                 dissipationInflowAir)
     # time step iterations
     for t in t_list:
         x = np.array(get_random_x())
         uDir += [BC.u_dirichlet.uOfXT(x, t)]
         vDir += [BC.v_dirichlet.uOfXT(x, t)]
         wDir += [BC.w_dirichlet.uOfXT(x, t)]
         vofDir += [BC.vof_dirichlet.uOfXT(x, t)]
         pAdv += [BC.p_advective.uOfXT(x, t)]
         kDir += [BC.k_dirichlet.uOfXT(x, t)]
         dissipationDir += [BC.dissipation_dirichlet.uOfXT(x, t)]
         phiCalc = x[vert_axis] - waterDepth
         # smoothing for velocity, kappa, dissipation field activated only along the 'air phase' side
         if phiCalc <= 0.:
             Heav = 0.
         elif 0. < phiCalc <= smoothing:
             Heav = smoothedHeaviside(smoothing, phiCalc - smoothing / 2.)
         else:
             Heav = 1.
         u, v, w = Heav * np.array(Uwind) + (1. - Heav) * np.array(U0)
         uCalc += [u]
         vCalc += [v]
         wCalc += [w]
         up = np.sqrt((u**2) * abs(b_or[0][0]) + (v**2) * abs(b_or[0][1]) +
                      (w**2) * abs(b_or[0][2]))
         pCalc += [-up]
         kCalc += [Heav * kInflowAir + (1. - Heav) * kInflow]
         dissipationCalc += [
             Heav * dissipationInflowAir + (1. - Heav) * dissipationInflow
         ]
         # smoothing for vof activated along either the water-phase and air phase side
         if phiCalc <= -smoothing:
             Heav = 0.
         elif -smoothing < phiCalc < smoothing:
             Heav = smoothedHeaviside(smoothing, phiCalc)
         else:
             Heav = 1.
         vofCalc += [Heav * air + (1. - Heav) * water]
     npt.assert_equal(uDir, uCalc)
     npt.assert_equal(vDir, vCalc)
     npt.assert_equal(wDir, wCalc)
     npt.assert_equal(vofDir, vofCalc)
     npt.assert_equal(BC.p_dirichlet.uOfXT, None)
     npt.assert_equal(kDir, kCalc)
     npt.assert_equal(dissipationDir, dissipationCalc)
     npt.assert_equal(pAdv, pCalc)