<commit_before>from __future__ import absolute_import
from abc import ABCMeta, abstractmethod
from firedrake import Function, LinearVariationalProblem, LinearVariationalSolver


def embedded_dg(original_apply):
    """
    Decorator to add interpolation and projection steps for embedded
    DG advection.
    """
    def get_apply(self, x_in, x_out):
        if hasattr(self, "Projector"):
            def new_apply(self, x_in, x_out):
                self.xdg_in.interpolate(x_in)
                original_apply(self, self.xdg_in, self.xdg_out)
                self.Projector.project()
                x_out.assign(self.x_projected)
            return new_apply(self, x_in, x_out)

        else:
            return original_apply(self, x_in, x_out)
    return get_apply


class Advection(object):
    """
    Base class for advection schemes.

    :arg state: :class:`.State` object.
    :arg field: field to be advected
    :arg equation: :class:`.Equation` object, specifying the equation
    that field satisfies
    :arg solver_params: solver_parameters
    """
    __metaclass__ = ABCMeta

    def __init__(self, state, field, equation=None, solver_params=None):

        self.state = state
        self.field = field

        if solver_params is None:
            self.solver_parameters = {'ksp_type':'preonly',
                                      'pc_type':'bjacobi',
                                      'sub_pc_type': 'ilu'}
        else:
            self.solver_parameters = solver_params
        self.dt = self.state.timestepping.dt

        # check to see if we are using an embedded DG method - is we are then
        # the projector and output function will have been set up in the
        # equation class and we can get the correct function space from
        # the output function.
        if hasattr(equation, "Projector"):
            fs = equation.xdg_out.function_space()
            self.Projector = equation.Projector
            self.xdg_out = equation.xdg_out
            self.xdg_in = Function(fs)
            self.x_projected = equation.x_projected
        else:
            fs = field.function_space()

        # setup required functions
        self.dq = Function(fs)
        self.q1 = Function(fs)

        # get ubar from the equation class if provided
        self.equation = equation
        if equation is not None:
            self.ubar = self.equation.ubar

    def update_solver(self):
        # setup solver using lhs and rhs defined in derived class

        problem = LinearVariationalProblem(self.lhs, self.rhs, self.dq)<commit_msg>reinstate default solvers for linear advection problems<commit_after>from __future__ import absolute_import
from abc import ABCMeta, abstractmethod
from firedrake import Function, LinearVariationalProblem, LinearVariationalSolver
from gusto.transport_equation import LinearAdvection


def embedded_dg(original_apply):
    """
    Decorator to add interpolation and projection steps for embedded
    DG advection.
    """
    def get_apply(self, x_in, x_out):
        if hasattr(self, "Projector"):
            def new_apply(self, x_in, x_out):
                self.xdg_in.interpolate(x_in)
                original_apply(self, self.xdg_in, self.xdg_out)
                self.Projector.project()
                x_out.assign(self.x_projected)
            return new_apply(self, x_in, x_out)

        else:
            return original_apply(self, x_in, x_out)
    return get_apply


class Advection(object):
    """
    Base class for advection schemes.

    :arg state: :class:`.State` object.
    :arg field: field to be advected
    :arg equation: :class:`.Equation` object, specifying the equation
    that field satisfies
    :arg solver_params: solver_parameters
    """
    __metaclass__ = ABCMeta

    def __init__(self, state, field, equation=None, solver_params=None):

        self.state = state
        self.field = field

        if solver_params is None:
            if isinstance(equation, LinearAdvection):
                self.solver_parameters = {'ksp_type':'cg',
                                          'pc_type':'bjacobi',
                                          'sub_pc_type': 'ilu'}
            else:
                self.solver_parameters = {'ksp_type':'preonly',
                                          'pc_type':'bjacobi',
                                          'sub_pc_type': 'ilu'}
        else:
            self.solver_parameters = solver_params
        self.dt = self.state.timestepping.dt

        # check to see if we are using an embedded DG method - is we are then
        # the projector and output function will have been set up in the
        # equation class and we can get the correct function space from
        # the output function.
        if hasattr(equation, "Projector"):
            fs = equation.xdg_out.function_space()
            self.Projector = equation.Projector
            self.xdg_out = equation.xdg_out
            self.xdg_in = Function(fs)
            self.x_projected = equation.x_projected
        else:
            fs = field.function_space()

        # setup required functions
        self.dq = Function(fs)
        self.q1 = Function(fs)

        # get ubar from the equation class if provided
        self.equation = equation
        if equation is not None:
            self.ubar = self.equation.ubar

    def update_solver(self):
        # setup solver using lhs and rhs defined in derived class

        problem = LinearVariationalProblem(self.lhs, self.rhs, self.dq)
{'fraction_non_alphanumeric': 0.07625430175692809, 'fraction_numerical': 0.0003622532149972831, 'mean_word_length': 2.093557422969188, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1258765', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1499, 'n_words': 436}