<commit_before>from firedrake import (inner, outer, grad, avg, dx, dS_h, dS_v,
                       FacetNormal)
from gusto.form_manipulation_labelling import subject, diffusion


__all__ = ["interior_penalty_diffusion_form"]


def interior_penalty_diffusion_form(state, test, q, parameters):
    """
    Interior penalty diffusion form

    :arg state: :class:`.State` object.
    :arg V: Function space of diffused field
    :arg direction: list containing directions in which function space
    :arg: mu: the penalty weighting function, which is
    :recommended to be proportional to 1/dx
    :arg: kappa: strength of diffusion

    """
    kappa = parameters.kappa
    mu = parameters.mu

    n = FacetNormal(state.mesh)

    form = inner(grad(test), grad(q)*kappa)*dx

    def get_flux_form(dS, M):

        fluxes = (
            -inner(2*avg(outer(q, n)), avg(grad(test)*M))
            - inner(avg(grad(q)*M), 2*avg(outer(test, n)))
            + mu*inner(2*avg(outer(q, n)), 2*avg(outer(test, n)*kappa))
        )*dS
        return fluxes

    form += get_flux_form(dS_v, kappa)
    form += get_flux_form(dS_h, kappa)

    form = subject(form, q)

    return diffusion(form)<commit_msg>do not label diffusion form subject twice<commit_after>from firedrake import (inner, outer, grad, avg, dx, dS_h, dS_v,
                       FacetNormal)
from gusto.form_manipulation_labelling import subject, diffusion


__all__ = ["interior_penalty_diffusion_form"]


def interior_penalty_diffusion_form(state, test, q, parameters):
    """
    Interior penalty diffusion form

    :arg state: :class:`.State` object.
    :arg V: Function space of diffused field
    :arg direction: list containing directions in which function space
    :arg: mu: the penalty weighting function, which is
    :recommended to be proportional to 1/dx
    :arg: kappa: strength of diffusion

    """
    kappa = parameters.kappa
    mu = parameters.mu

    n = FacetNormal(state.mesh)

    form = inner(grad(test), grad(q)*kappa)*dx

    def get_flux_form(dS, M):

        fluxes = (
            -inner(2*avg(outer(q, n)), avg(grad(test)*M))
            - inner(avg(grad(q)*M), 2*avg(outer(test, n)))
            + mu*inner(2*avg(outer(q, n)), 2*avg(outer(test, n)*kappa))
        )*dS
        return fluxes

    form += get_flux_form(dS_v, kappa)
    form += get_flux_form(dS_h, kappa)

    return diffusion(form)
{'fraction_non_alphanumeric': 0.11691022964509394, 'fraction_numerical': 0.0041753653444676405, 'mean_word_length': 3.1027397260273974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '66724', 'n_tokens_mistral': 820, 'n_tokens_neox': 767, 'n_words': 208}