Skip to content

Commit

Permalink
PR #538: from firedrakeproject/compressible_coriolis_change
Browse files Browse the repository at this point in the history
Move omega from equations to parameters
  • Loading branch information
tommbendall authored Aug 16, 2024
2 parents e4cbef6 + 6042497 commit 7f446e2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
5 changes: 2 additions & 3 deletions examples/compressible/skamarock_klemp_hydrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
domain = Domain(mesh, dt, "RTCF", 1)

# Equation
parameters = CompressibleParameters()
Omega = as_vector((0., 0., 0.5e-4))
parameters = CompressibleParameters(Omega=0.5e-4)
balanced_pg = as_vector((0., -1.0e-4*20, 0.))
eqns = CompressibleEulerEquations(domain, parameters, Omega=Omega,
eqns = CompressibleEulerEquations(domain, parameters,
extra_terms=[("u", balanced_pg)])

# I/O
Expand Down
2 changes: 2 additions & 0 deletions gusto/core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class BoussinesqParameters(Configuration):
g = 9.810616
N = 0.01 # Brunt-Vaisala frequency (1/s)
cs = 340 # sound speed (for compressible case) (m/s)
Omega = None


class CompressibleParameters(Configuration):
Expand All @@ -136,6 +137,7 @@ class CompressibleParameters(Configuration):
w_sat2 = -17.27 # second const. in Teten's formula (no units)
w_sat3 = 35.86 # third const. in Teten's formula (K)
w_sat4 = 610.9 # fourth const. in Teten's formula (Pa)
Omega = None # Rotation rate


class ShallowWaterParameters(Configuration):
Expand Down
16 changes: 5 additions & 11 deletions gusto/equations/boussinesq_equations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Defines the Boussinesq equations."""

from firedrake import inner, dx, div, cross, split
from firedrake import inner, dx, div, cross, split, as_vector
from firedrake.fml import subject
from gusto.core.labels import (
time_derivative, transport, prognostic, linearisation,
Expand Down Expand Up @@ -40,7 +40,6 @@ class BoussinesqEquations(PrognosticEquationSet):

def __init__(self, domain, parameters,
compressible=True,
Omega=None,
space_names=None,
linearisation_map='default',
u_transport_option="vector_invariant_form",
Expand All @@ -54,8 +53,6 @@ def __init__(self, domain, parameters,
the model's physical parameters.
compressible (bool, optional): flag to indicate whether the
equations are compressible. Defaults to True
Omega (:class:`ufl.Expr`, optional): an expression for the planet's
rotation vector. Defaults to None.
space_names (dict, optional): a dictionary of strings for names of
the function spaces to use for the spatial discretisation. The
keys are the names of the prognostic variables. Defaults to None
Expand Down Expand Up @@ -191,11 +188,12 @@ def __init__(self, domain, parameters,
# -------------------------------------------------------------------- #
# Extra Terms (Coriolis)
# -------------------------------------------------------------------- #
if Omega is not None:
if self.parameters.Omega is not None:
# TODO: add linearisation
residual += coriolis(subject(prognostic(
Omega = as_vector((0, 0, self.parameters.Omega))
coriolis_form = coriolis(subject(prognostic(
inner(w, cross(2*Omega, u))*dx, 'u'), self.X))

residual += coriolis_form
# -------------------------------------------------------------------- #
# Linearise equations
# -------------------------------------------------------------------- #
Expand Down Expand Up @@ -227,7 +225,6 @@ class LinearBoussinesqEquations(BoussinesqEquations):

def __init__(self, domain, parameters,
compressible=True,
Omega=None,
space_names=None,
linearisation_map='default',
u_transport_option="vector_invariant_form",
Expand All @@ -241,8 +238,6 @@ def __init__(self, domain, parameters,
the model's physical parameters.
compressible (bool, optional): flag to indicate whether the
equations are compressible. Defaults to True
Omega (:class:`ufl.Expr`, optional): an expression for the planet's
rotation vector. Defaults to None.
space_names (dict, optional): a dictionary of strings for names of
the function spaces to use for the spatial discretisation. The
keys are the names of the prognostic variables. Defaults to None
Expand Down Expand Up @@ -278,7 +273,6 @@ def __init__(self, domain, parameters,
super().__init__(domain=domain,
parameters=parameters,
compressible=compressible,
Omega=Omega,
space_names=space_names,
linearisation_map=linearisation_map,
u_transport_option=u_transport_option,
Expand Down
20 changes: 9 additions & 11 deletions gusto/equations/compressible_euler_equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from firedrake import (
sin, pi, inner, dx, div, cross, FunctionSpace, FacetNormal, jump, avg, dS_v,
conditional, SpatialCoordinate, split, Constant
conditional, SpatialCoordinate, split, Constant, as_vector
)
from firedrake.fml import subject, replace_subject
from gusto.core.labels import (
Expand Down Expand Up @@ -34,7 +34,7 @@ class CompressibleEulerEquations(PrognosticEquationSet):
pressure.
"""

def __init__(self, domain, parameters, Omega=None, sponge_options=None,
def __init__(self, domain, parameters, sponge_options=None,
extra_terms=None, space_names=None,
linearisation_map='default',
u_transport_option="vector_invariant_form",
Expand All @@ -47,8 +47,6 @@ def __init__(self, domain, parameters, Omega=None, sponge_options=None,
mesh and the compatible function spaces.
parameters (:class:`Configuration`, optional): an object containing
the model's physical parameters.
Omega (:class:`ufl.Expr`, optional): an expression for the planet's
rotation vector. Defaults to None.
sponge_options (:class:`SpongeLayerParameters`, optional): any
parameters for applying a sponge layer to the upper boundary.
Defaults to None.
Expand Down Expand Up @@ -216,10 +214,12 @@ def __init__(self, domain, parameters, Omega=None, sponge_options=None,
# -------------------------------------------------------------------- #
# Extra Terms (Coriolis, Sponge, Diffusion and others)
# -------------------------------------------------------------------- #
if Omega is not None:
if parameters.Omega is not None:
# TODO: add linearisation
residual += coriolis(subject(prognostic(
inner(w, cross(2*Omega, u))*dx, "u"), self.X))
Omega = as_vector((0, 0, parameters.Omega))
coriolis_form = coriolis(subject(prognostic(
inner(w, cross(2*Omega, u))*dx, 'u'), self.X))
residual += coriolis_form

if sponge_options is not None:
W_DG = FunctionSpace(domain.mesh, "DG", 2)
Expand Down Expand Up @@ -279,7 +279,7 @@ class HydrostaticCompressibleEulerEquations(CompressibleEulerEquations):
equations.
"""

def __init__(self, domain, parameters, Omega=None, sponge=None,
def __init__(self, domain, parameters, sponge=None,
extra_terms=None, space_names=None, linearisation_map='default',
u_transport_option="vector_invariant_form",
diffusion_options=None,
Expand All @@ -291,8 +291,6 @@ def __init__(self, domain, parameters, Omega=None, sponge=None,
mesh and the compatible function spaces.
parameters (:class:`Configuration`, optional): an object containing
the model's physical parameters.
Omega (:class:`ufl.Expr`, optional): an expression for the planet's
rotation vector. Defaults to None.
sponge (:class:`ufl.Expr`, optional): an expression for a sponge
layer. Defaults to None.
extra_terms (:class:`ufl.Expr`, optional): any extra terms to be
Expand Down Expand Up @@ -325,7 +323,7 @@ def __init__(self, domain, parameters, Omega=None, sponge=None,
NotImplementedError: only mixing ratio tracers are implemented.
"""

super().__init__(domain, parameters, Omega=Omega, sponge=sponge,
super().__init__(domain, parameters, sponge=sponge,
extra_terms=extra_terms, space_names=space_names,
linearisation_map=linearisation_map,
u_transport_option=u_transport_option,
Expand Down

0 comments on commit 7f446e2

Please sign in to comment.