Skip to content

Commit

Permalink
move is_cg to core.function_spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
JHopeCollins committed Dec 18, 2024
1 parent f4dd05d commit 32602c5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
26 changes: 23 additions & 3 deletions gusto/core/function_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"""

from gusto.core.logging import logger
from firedrake import (HCurl, HDiv, FunctionSpace, FiniteElement,
TensorProductElement, interval)
from firedrake import (HCurl, HDiv, FunctionSpace, FiniteElement, VectorElement,
TensorProductElement, BrokenElement, interval)

__all__ = ["Spaces", "check_degree_args"]

Expand Down Expand Up @@ -116,7 +116,6 @@ def add_space(self, name, space, overwrite_space=False, continuity=None):

# set the continuity of the space - for extruded meshes specify both directions
if continuity is None:
from gusto.time_discretisation.wrappers import is_cg
continuity = is_cg(space)
if self.extruded_mesh:
self.continuity[name] = {
Expand Down Expand Up @@ -548,3 +547,24 @@ def check_degree_args(name, mesh, degree, horizontal_degree, vertical_degree):
raise ValueError(f'Cannot pass both "degree" and "vertical_degree" to {name}')
if not extruded_mesh and vertical_degree is not None:
raise ValueError(f'Cannot pass "vertical_degree" to {name} if mesh is not extruded')


def is_cg(V):
"""
Checks if a :class:`FunctionSpace` is continuous.
Function to check if a given space, V, is CG. Broken elements are always
discontinuous; for vector elements we check the names of the Sobolev spaces
of the subelements and for all other elements we just check the Sobolev
space name.
Args:
V (:class:`FunctionSpace`): the space to check.
"""
ele = V.ufl_element()
if isinstance(ele, BrokenElement):
return False
elif type(ele) == VectorElement:
return all([e.sobolev_space.name == "H1" for e in ele._sub_elements])
else:
return V.ufl_element().sobolev_space.name == "H1"
2 changes: 1 addition & 1 deletion gusto/solvers/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This module provides some parameters sets that are good defaults
for particular kinds of system.
"""
from gusto.time_discretisation.wrappers import is_cg
from gusto.core.function_spaces import is_cg

__all__ = ['mass_parameters']

Expand Down
24 changes: 2 additions & 22 deletions gusto/time_discretisation/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
from abc import ABCMeta, abstractmethod
from firedrake import (
FunctionSpace, Function, BrokenElement, Projector, Interpolator,
VectorElement, Constant, as_ufl, dot, grad, TestFunction, MixedFunctionSpace
Constant, as_ufl, dot, grad, TestFunction, MixedFunctionSpace
)
from firedrake.fml import Term
from gusto.core.configuration import EmbeddedDGOptions, RecoveryOptions, SUPGOptions
from gusto.recovery import Recoverer, ReversibleRecoverer, ConservativeRecoverer
from gusto.core.labels import transporting_velocity
from gusto.core.conservative_projection import ConservativeProjector
from gusto.core.function_spaces import is_cg
import ufl

__all__ = ["EmbeddedDGWrapper", "RecoveryWrapper", "SUPGWrapper", "MixedFSWrapper"]
Expand Down Expand Up @@ -307,27 +308,6 @@ def post_apply(self, x_out):
x_out.assign(self.x_projected)


def is_cg(V):
"""
Checks if a :class:`FunctionSpace` is continuous.
Function to check if a given space, V, is CG. Broken elements are always
discontinuous; for vector elements we check the names of the Sobolev spaces
of the subelements and for all other elements we just check the Sobolev
space name.
Args:
V (:class:`FunctionSpace`): the space to check.
"""
ele = V.ufl_element()
if isinstance(ele, BrokenElement):
return False
elif type(ele) == VectorElement:
return all([e.sobolev_space.name == "H1" for e in ele._sub_elements])
else:
return V.ufl_element().sobolev_space.name == "H1"


class SUPGWrapper(Wrapper):
"""
Wrapper for computing a time discretisation with SUPG, which adjusts the
Expand Down

0 comments on commit 32602c5

Please sign in to comment.