Пример #1
0
def nu_PWC_arit(phi, cc):
    A = df.conditional(df.gt(phi, 0.975), 1.0, 0.0)
    B = df.conditional(df.lt(phi, 0.025), 1.0, 0.0)
    nu = A * cc[r"\nu_1"]\
       + B * cc[r"\nu_2"]\
       + (1.0 - A - B) * 0.5 * (cc[r"\nu_1"] + cc[r"\nu_2"])
    return nu
Пример #2
0
def nu_PWC_harm(phi, cc):
    A = df.conditional(df.gt(phi, 0.975), 1.0, 0.0)
    B = df.conditional(df.lt(phi, 0.025), 1.0, 0.0)
    nu = A * cc[r"\nu_1"]\
       + B * cc[r"\nu_2"]\
       + (1.0 - A - B) * 2.0 / (1.0 / cc[r"\nu_1"] + 1.0 / cc[r"\nu_2"])
    return nu
Пример #3
0
def navier_stokes_stabilization_penalties(
    simulation,
    nu,
    velocity_continuity_factor_D12=0,
    pressure_continuity_factor=0,
    no_coeff=False,
):
    """
    Calculate the stabilization parameters needed in the DG scheme
    """
    ndim = simulation.ndim
    mpm = simulation.multi_phase_model
    mesh = simulation.data['mesh']
    use_const = simulation.input.get_value(
        'solver/spatially_constant_penalty', False, 'bool'
    )

    if no_coeff:
        mu_min = mu_max = 1.0
    else:
        mu_min, mu_max = mpm.get_laminar_dynamic_viscosity_range()

    P = simulation.data['Vu'].ufl_element().degree()
    if use_const:
        simulation.log.info('    Using spatially constant elliptic penalty')
        penalty_dS = define_penalty(
            mesh, P, mu_min, mu_max, boost_factor=3, exponent=1.0
        )
        penalty_ds = penalty_dS * 2
        simulation.log.info(
            '    DG SIP penalty:  dS %.1f  ds %.1f' % (penalty_dS, penalty_ds)
        )
        penalty_dS = Constant(penalty_dS)
        penalty_ds = Constant(penalty_ds)

    else:
        simulation.log.info('    Using spatially varying elliptic penalties')
        penalty_dS = define_spatially_varying_penalty(
            simulation, P, mu_min, mu_max, boost_factor=3, exponent=1.0
        )
        penalty_ds = penalty_dS * 2
        penalty_dS = dolfin.conditional(
            dolfin.lt(penalty_dS('+'), penalty_dS('-')),
            penalty_dS('-'),
            penalty_dS('+'),
        )

    if velocity_continuity_factor_D12:
        D12 = Constant([velocity_continuity_factor_D12] * ndim)
    else:
        D12 = Constant([0] * ndim)

    if pressure_continuity_factor:
        h = simulation.data['h']
        h = Constant(1.0)
        D11 = avg(h / nu) * Constant(pressure_continuity_factor)
    else:
        D11 = None

    return penalty_dS, penalty_ds, D11, D12
Пример #4
0
    def setUp(self):
        self.mesh = mesh = dolfin.UnitSquareMesh(20, 2, "left")
        self.DG0_element = DG0e = dolfin.FiniteElement("DG", mesh.ufl_cell(),
                                                       0)
        self.DG0v_element = DG0ve = dolfin.VectorElement(
            "DG", mesh.ufl_cell(), 0)
        self.DG0 = DG0 = dolfin.FunctionSpace(mesh, DG0e)
        self.DG0v = DG0v = dolfin.FunctionSpace(mesh, DG0ve)

        self.fsr = fsr = FunctionSubspaceRegistry()
        fsr.register(DG0)
        fsr.register(DG0v)

        self.cellmid = cm = CellMidpointExpression(mesh, element=DG0ve)
        self.n = n = dolfin.FacetNormal(mesh)

        self.u = u = dolfin.Function(DG0)
        self.v = v = dolfin.TestFunction(DG0)

        u_bc = dolfin.Expression('x[0]', degree=2)

        x = dolfin.SpatialCoordinate(mesh)
        self.rho = rho = dolfin.conditional(
            dolfin.lt((x[0] - 0.5)**2 + (x[1] - 0.5)**2, 0.2**2), 0.0, 0.0)

        dot = dolfin.dot
        cellsize = dolfin.CellSize(mesh)
        self.h = h = cm('+') - cm('-')
        self.h_boundary = h_boundary = 2 * n * dot(x - cm, n)
        self.E = E = h / dot(h, h) * (u('-') - u('+'))
        self.E_boundary = E_boundary = h_boundary / dot(
            h_boundary, h_boundary) * (u - u_bc)
        dS = dolfin.dS

        eps = 1e-8

        class BL(dolfin.SubDomain):
            def inside(self, x, on_boundary):
                return abs(x[0]) < eps

        class BR(dolfin.SubDomain):
            def inside(self, x, on_boundary):
                return abs(x[0] - 1) < eps

        ff = dolfin.FacetFunction('size_t', mesh, 0)
        BL().mark(ff, 1)
        BR().mark(ff, 1)

        ds = dolfin.Measure('ds', domain=mesh, subdomain_data=ff)

        self.F = (dot(E, n('+')) * v('+') * dS + dot(E, n('-')) * v('-') * dS -
                  v * rho * dolfin.dx + dot(E_boundary, n) * v * ds(1))
Пример #5
0
def test_scalar_conditions(R):
    c = Function(R)
    c.vector()[:] = 1.5

    # Float conversion does not interfere with boolean ufl expressions
    assert isinstance(lt(c, 3), ufl.classes.LT)
    assert not isinstance(lt(c, 3), bool)

    # Float conversion is not implicit in boolean Python expressions
    assert isinstance(c < 3, ufl.classes.LT)
    assert not isinstance(c < 3, bool)

    # == is used in ufl to compare equivalent representations,
    # <,> result in LT/GT expressions, bool conversion is illegal

    # Note that 1.5 < 0 == False == 1.5 < 1, but that is not what we
    # compare here:
    assert not (c < 0) == (c < 1)
    # This protects from "if c < 0: ..." misuse:
    with pytest.raises(ufl.UFLException):
        bool(c < 0)
    with pytest.raises(ufl.UFLException):
        not c < 0
Пример #6
0
 def _tree(base, length):
     if base >= N:
         return 0.0
     if length == 1:
         return mapping[base][1]
     elif length > 1:
         l2 = length // 2
         if base + l2 >= N:  # no right side
             return _tree(base, l2)
         cut = (mapping[base + l2][0] + mapping[base + l2 - 1][0]) / 2
         return dolfin.conditional(dolfin.lt(expr, cut), _tree(base, l2),
                                   _tree(base + l2, l2))
     else:
         raise AssertionError()
Пример #7
0
    a = dot(omega, grad(I))
    w = v * omega
    n = facet_normal

    a_bc = S - beta * I

    return (dot(w, n) * a_bc,
            -a * div(w) + dot(w, grad(beta * I)) - dot(w, grad(S)))


if really_squished_mesh:
    lower_boundary_value = dolfin.Constant(1.0)
else:
    lower_boundary_value = dolfin.conditional(
        dolfin.lt((x[0] - 0.5)**2, 0.35**2), 1.0, 0.0)

bcs = [dolfin.DirichletBC(space, lower_boundary_value, lower_boundary)]

if not no_side_bc:

    def _side_bc(subdomain):
        bcs.append(dolfin.DirichletBC(space, dolfin.Constant(0.0), subdomain))

    if theta < np.pi / 2:
        _side_bc(left_boundary)
    else:
        _side_bc(right_boundary)

# alpha = dolfin.Constant(1.0)
alpha = dolfin.conditional(
Пример #8
0
 def Phi_pddproj_clipped(self):
     Phi = self.Phi_pddproj
     return dolfin.conditional(dolfin.lt(Phi.m, 0.0), 0.0, Phi.m) * Phi.u
Пример #9
0
def omega(k):
    k0 = Mat.ft / Mat.E
    beta = Mat.ft / Mat.Gf
    exponent = beta * (k0 - k)
    omega = 1.0 - k0 / k * (1.0 - Mat.alpha + Mat.alpha * df.exp(exponent))
    return df.conditional(df.lt(k, k0), 0, omega)