Beispiel #1
0
def set_linear_dirichlet_constant(mesh,
                                  dt,
                                  var_name='Temperature',
                                  bc_temperature=1300.,
                                  temperature=300.,
                                  source_value=0.,
                                  axis=1,
                                  right=True,
                                  tol=1e-4,
                                  conductivity=1.,
                                  density=1.,
                                  specific_heat=1.):
    '''
    Heat equation problem where an edge/surface is set at a given temperature
    and everything else at another.

    Parameters
    ----------
    axis : int
        Controls boundary to which Dirichlet bc is applied.
    right : bool
        Dirichlet bc is applied to the planar and perpendicular face found in
        the max (True) or min (False) coordinate.
    '''

    # function space
    V = FunctionSpace(mesh, 'Lagrange', 1)

    # boundary conditions
    bcs = [
        set_dirichlet_bc_lim(V,
                             value=bc_temperature,
                             axis=axis,
                             right=right,
                             tol=tol)
    ]

    # initial condition
    u_initial = Constant(temperature)
    u_n = Function(V, name=var_name)
    u_n.interpolate(u_initial)

    # problem formulation
    f = Constant(source_value)
    u_n, a, L = get_formulation_constant_props(V,
                                               u_initial,
                                               f,
                                               dt,
                                               conductivity,
                                               density,
                                               specific_heat,
                                               var_name=var_name)

    u = Function(V, name=var_name)

    return u_n, a, L, u, bcs
Beispiel #2
0
def get_formulation(V, u_initial, f, dt, var_name='Temperature'):

    # interpolate initial condition
    u_n = Function(V, name=var_name)
    u_n.interpolate(u_initial)

    # function spaces
    u_h = TrialFunction(V)
    v = TestFunction(V)

    # formulation
    a = u_h * v * dx + dt * dot(grad(u_h), grad(v)) * dx
    L = (u_n + dt * f) * v * dx

    return u_n, a, L
Beispiel #3
0
def get_formulation_constant_props(V, u_initial, f, dt, conductivity, density,
                                   specific_heat, var_name='Temperature'):

    # medium properties
    k = Constant(conductivity)
    rho = Constant(density)
    c_p = Constant(specific_heat)

    # interpolate initial condition
    u_n = Function(V, name=var_name)
    u_n.interpolate(u_initial)

    # function spaces
    u_h = TrialFunction(V)
    v = TestFunction(V)

    # formulation
    param1 = rho * c_p
    param2 = k / param1
    a = u_h * v * dx + param2 * dt * dot(grad(u_h), grad(v)) * dx
    L = (u_n + param1 * dt * f) * v * dx

    return u_n, a, L
Beispiel #4
0
def interpolate(v, V):
    """Return interpolation of a given function into a given finite
    element space.

    *Arguments*
        v
            a :py:class:`Function <dolfin.functions.function.Function>` or
            an :py:class:`Expression <dolfin.functions.expression.Expression>`
        V
            a :py:class:`FunctionSpace (standard, mixed, etc.)
            <dolfin.functions.functionspace.FunctionSpace>`

    *Example of usage*

        .. code-block:: python

            v = Expression("sin(pi*x[0])")
            V = FunctionSpace(mesh, "Lagrange", 1)
            Iv = interpolate(v, V)

    """

    # Check arguments
    # if not isinstance(V, cpp.functionFunctionSpace):
    #     cpp.dolfin_error("interpolation.py",
    #                      "compute interpolation",
    #                      "Illegal function space for interpolation, not a FunctionSpace (%s)" % str(v))

    # Compute interpolation
    Pv = Function(V)

    if hasattr(v, "_cpp_object"):
        Pv.interpolate(v._cpp_object)
    else:
        Pv.interpolate(v)

    return Pv