示例#1
0
def copy_expression(expr):
    if hasattr(expr, 'cppcode'):
        # old fenics versions
        new_expr = dla.Expression(expr.cppcode, **expr.user_parameters,
                                  degree=expr.ufl_element().degree())
    else:
        # fenics 2019
        new_expr = dla.Expression(expr._cppcode, **expr._user_parameters,
                                  degree=expr.ufl_element().degree())
    return new_expr
示例#2
0
def get_halfar_shallow_ice_exact_solution(Gamma, mesh, degree, ndim):
    import sympy as sp
    H, x, y, t = get_halfar_shallow_ice_exact_solution_sympy(Gamma, ndim)
    exact_sol = dla.Expression(
        sp.printing.ccode(H), cell=mesh.ufl_cell(),
        domain=mesh, t=0, degree=degree)
    return exact_sol
示例#3
0
def assemble_fenics(u, kappa0, kappa1):

    f = fa.Expression(
        "10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)", degree=2)

    inner, grad, dx = ufl.inner, ufl.grad, ufl.dx
    J_form = 0.5 * inner(kappa0 * grad(u), grad(u)) * dx - kappa1 * f * u * dx
    J = fa.assemble(J_form)
    return J
示例#4
0
def solve_fenics(kappa0, kappa1):

    f = fa.Expression(
        "10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)", degree=2)

    u = fa.Function(V)
    bcs = [fa.DirichletBC(V, fa.Constant(0.0), "on_boundary")]

    inner, grad, dx = ufl.inner, ufl.grad, ufl.dx
    JJ = 0.5 * inner(kappa0 * grad(u), grad(u)) * dx - kappa1 * f * u * dx
    v = fenics.TestFunction(V)
    F = fenics.derivative(JJ, u, v)
    fa.solve(F == 0, u, bcs=bcs)
    return u