Example #1
0
def get_aspect_ratios2d(mesh, python=False):
    """
    Computes the aspect ratio of each cell in a 2D triangular mesh

    :arg mesh: the input mesh to do computations on
    :kwarg python: compute the measure using Python?

    :rtype: firedrake.function.Function aspect_ratios with
        aspect ratio data
    """
    P0 = firedrake.FunctionSpace(mesh, "DG", 0)
    if python:
        P0_ten = firedrake.TensorFunctionSpace(mesh, "DG", 0)
        J = firedrake.interpolate(ufl.Jacobian(mesh), P0_ten)
        edge1 = ufl.as_vector([J[0, 0], J[1, 0]])
        edge2 = ufl.as_vector([J[0, 1], J[1, 1]])
        edge3 = edge1 - edge2
        a = ufl.sqrt(ufl.dot(edge1, edge1))
        b = ufl.sqrt(ufl.dot(edge2, edge2))
        c = ufl.sqrt(ufl.dot(edge3, edge3))
        aspect_ratios = firedrake.interpolate(
            a * b * c / ((a + b - c) * (b + c - a) * (c + a - b)), P0
        )
    else:
        coords = mesh.coordinates
        aspect_ratios = firedrake.Function(P0)
        op2.par_loop(
            get_pyop2_kernel("get_aspect_ratio", 2),
            mesh.cell_set,
            aspect_ratios.dat(op2.WRITE, aspect_ratios.cell_node_map()),
            coords.dat(op2.READ, coords.cell_node_map()),
        )
    return aspect_ratios
Example #2
0
def meshMetric(mesh):
    """
    Extract mesh size tensor from a given ``mesh``.
    This returns the physical element metric tensor, ``G`` as a 
    UFL object.
    """
    dx_dxiHat = 0.5 * ufl.Jacobian(mesh)
    dxiHat_dx = inv(dx_dxiHat)
    G = dxiHat_dx.T * dxiHat_dx
    return G
Example #3
0
def get_scaled_jacobians2d(mesh, python=False):
    """
    Computes the scaled Jacobian of each cell in a 2D triangular mesh

    :arg mesh: the input mesh to do computations on
    :kwarg python: compute the measure using Python?

    :rtype: firedrake.function.Function scaled_jacobians with scaled
        jacobian data.
    """
    P0 = firedrake.FunctionSpace(mesh, "DG", 0)
    if python:
        P0_ten = firedrake.TensorFunctionSpace(mesh, "DG", 0)
        J = firedrake.interpolate(ufl.Jacobian(mesh), P0_ten)
        edge1 = ufl.as_vector([J[0, 0], J[1, 0]])
        edge2 = ufl.as_vector([J[0, 1], J[1, 1]])
        edge3 = edge1 - edge2
        a = ufl.sqrt(ufl.dot(edge1, edge1))
        b = ufl.sqrt(ufl.dot(edge2, edge2))
        c = ufl.sqrt(ufl.dot(edge3, edge3))
        detJ = ufl.JacobianDeterminant(mesh)
        jacobian_sign = ufl.sign(detJ)
        max_product = ufl.Max(
            ufl.Max(ufl.Max(a * b, a * c), ufl.Max(b * c, b * a)), ufl.Max(c * a, c * b)
        )
        scaled_jacobians = firedrake.interpolate(detJ / max_product * jacobian_sign, P0)
    else:
        coords = mesh.coordinates
        scaled_jacobians = firedrake.Function(P0)
        op2.par_loop(
            get_pyop2_kernel("get_scaled_jacobian", 2),
            mesh.cell_set,
            scaled_jacobians.dat(op2.WRITE, scaled_jacobians.cell_node_map()),
            coords.dat(op2.READ, coords.cell_node_map()),
        )
    return scaled_jacobians
uddot_exact = diff(udot_exact, t)
f = resLHS_strong(uddot_exact, u_exact)

# Galerkin weak residual:
w = TestFunction(spline.V)
res_weak = (inner(rho * uddot_alpha, w) + inner(P(u_alpha), spline.grad(w)) -
            inner(f, w)) * spline.dx


# DC term:
def norm2(u, eps=0.0):
    return sqrt(inner(u, u) + eps**2)


c_s = sqrt((K + 4.0 * mu / 3.0) / rho)
dxi_dxiHat = 0.5 * ufl.Jacobian(spline.mesh)
dx_dxi = spline.parametricGrad(spline.F + u_alpha)
dx_dxiHat = dx_dxi * dxi_dxiHat
dxiHat_dx = inv(dx_dxiHat)
G = dxiHat_dx.T * dxiHat_dx
h_K2 = tr(inv(G))
h = sqrt(h_K2)
nu_DC_res = h*C_DC*norm2(resLHS_strong(uddot_alpha,u_alpha)-f)\
            /norm2(gradx(u_alpha,udot_alpha),eps=Constant(DOLFIN_EPS))
nu_DC_max = 0.5 * rho / J(u_alpha) * C_max * c_s * h
nu_DC = ufl.Min(nu_DC_res, nu_DC_max)


def D_op(u, udot):
    return sym(gradx(u, udot))
res_DC = nu_DC*inner(D_op(u_alpha,udot_alpha),D_op(u_alpha,w))\
Example #5
0
if (GALERKIN):
    DYN_SUBSCALES = False

##########################

# Quadrature degree to use in all integrals:
QUAD_DEG = 6

# Use fixed quadrature rule.  (Automatic degree estimation skyrockets
# due to the residual-based stabilization terms.)
dx = dx(metadata={"quadrature_degree": QUAD_DEG})

# Mesh and derivation of mesh-size metric:
mesh = BoxMesh(Point(0.0, 0.0, 0.0), Point(math.pi, math.pi, math.pi), Nel,
               Nel, Nel)
dx_dxiHat = 0.5 * ufl.Jacobian(mesh)
G = inv(dx_dxiHat.T * dx_dxiHat)

# Definition of the Taylor--Hood element, augmented with the fine-scale
# pressure:
cell = mesh.ufl_cell()
u_el = VectorElement("Lagrange", cell, 2, quad_scheme="default")
p_el = FiniteElement("Lagrange", cell, 1, quad_scheme="default")
pPrime_el = p_el

# Unfortunately, a mixed element including the quadrature representation of
# uPrime does not work, as requesting derivatives of any of the other
# components leads to the form compiler attempting to differentiate all
# components, including the quadrature space for which derivatives are
# ill-defined.
X_el = MixedElement([u_el, p_el, pPrime_el])