Skip to content

Commit

Permalink
Merge branch 'main' into timestepping_physics
Browse files Browse the repository at this point in the history
  • Loading branch information
tommbendall authored Jul 27, 2023
2 parents 866e46a + c173934 commit b1aa590
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/compressible/dcmip_3_1_meanflow_quads.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
io = IO(domain, output, diagnostic_fields=diagnostic_fields)

# Transport schemes
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho", subcycles=2),
SSPRK3(domain, "theta", options=SUPGOptions(), subcycles=2)]
transport_methods = [DGUpwind(eqns, field) for field in ["u", "rho", "theta"]]
Expand Down
2 changes: 1 addition & 1 deletion examples/compressible/moist_bryan_fritsch.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
SSPRK3(domain, "theta", options=EmbeddedDGOptions()),
SSPRK3(domain, "water_vapour", options=EmbeddedDGOptions()),
SSPRK3(domain, "cloud_water", options=EmbeddedDGOptions()),
ImplicitMidpoint(domain, "u")]
TrapeziumRule(domain, "u")]

transport_methods = [DGUpwind(eqns, field) for field in ["u", "rho", "theta", "water_vapour", "cloud_water"]]

Expand Down
2 changes: 1 addition & 1 deletion examples/compressible/mountain_hydrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

# Transport schemes
theta_opts = SUPGOptions()
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho"),
SSPRK3(domain, "theta", options=theta_opts)]
transport_methods = [DGUpwind(eqns, "u"),
Expand Down
2 changes: 1 addition & 1 deletion examples/compressible/mountain_nonhydrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

# Transport schemes
theta_opts = SUPGOptions()
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho"),
SSPRK3(domain, "theta", options=theta_opts)]
transport_methods = [DGUpwind(eqns, "u"),
Expand Down
2 changes: 1 addition & 1 deletion examples/compressible/robert_bubble.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# Transport schemes
theta_opts = EmbeddedDGOptions()
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho"),
SSPRK3(domain, "theta", options=theta_opts)]

Expand Down
2 changes: 1 addition & 1 deletion examples/compressible/skamarock_klemp_hydrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

# Transport schemes
theta_opts = SUPGOptions()
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho"),
SSPRK3(domain, "theta", options=theta_opts)]

Expand Down
2 changes: 1 addition & 1 deletion examples/compressible/skamarock_klemp_nonlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

# Transport schemes
theta_opts = SUPGOptions()
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho"),
SSPRK3(domain, "theta", options=theta_opts)]
transport_methods = [DGUpwind(eqns, "u"),
Expand Down
2 changes: 1 addition & 1 deletion examples/compressible/straka_bubble.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

# Transport schemes
theta_opts = SUPGOptions()
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho"),
SSPRK3(domain, "theta", options=theta_opts)]
transport_methods = [DGUpwind(eqns, "u"),
Expand Down
2 changes: 1 addition & 1 deletion examples/incompressible/skamarock_klemp_incompressible.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

# Transport schemes
b_opts = SUPGOptions()
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "b", options=b_opts)]
transport_methods = [DGUpwind(eqns, "u"), DGUpwind(eqns, "b", ibp=b_opts.ibp)]

Expand Down
2 changes: 1 addition & 1 deletion examples/shallow_water/williamson_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
io = IO(domain, output, diagnostic_fields=diagnostic_fields)

# Transport schemes
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "D", subcycles=2)]
transport_methods = [DGUpwind(eqns, "u"), DGUpwind(eqns, "D")]

Expand Down
2 changes: 1 addition & 1 deletion examples/shallow_water/williamson_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
io = IO(domain, output, diagnostic_fields=diagnostic_fields)

# Transport schemes
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "D")]
transport_methods = [DGUpwind(eqns, "u"), DGUpwind(eqns, "D")]

Expand Down
24 changes: 12 additions & 12 deletions gusto/time_discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


__all__ = ["ForwardEuler", "BackwardEuler", "SSPRK3", "RK4", "Heun",
"ThetaMethod", "ImplicitMidpoint", "BDF2", "TR_BDF2", "Leapfrog", "AdamsMoulton", "AdamsBashforth"]
"ThetaMethod", "TrapeziumRule", "BDF2", "TR_BDF2", "Leapfrog", "AdamsMoulton", "AdamsBashforth"]


def wrapper_apply(original_apply):
Expand Down Expand Up @@ -646,23 +646,24 @@ def apply(self, x_out, x_in):

class ThetaMethod(TimeDiscretisation):
"""
Implements the theta implicit-explicit timestepping method.
Implements the theta implicit-explicit timestepping method, which can
be thought as a generalised trapezium rule.
The theta implicit-explicit timestepping method for operator F is written as
y^(n+1) = y^n + dt*(1-theta)*F[y^n] + dt*theta*F[y^(n+1)]
for off-centring parameter theta.
"""

def __init__(self, domain, field_name=None, theta=None,
def __init__(self, domain, theta, field_name=None,
solver_parameters=None, options=None):
"""
Args:
domain (:class:`Domain`): the model's domain object, containing the
mesh and the compatible function spaces.
theta (float): the off-centring parameter. theta = 1
corresponds to a backward Euler method. Defaults to None.
field_name (str, optional): name of the field to be evolved.
Defaults to None.
theta (float, optional): the off-centring parameter. theta = 1
corresponds to a backward Euler method. Defaults to None.
solver_parameters (dict, optional): dictionary of parameters to
pass to the underlying solver. Defaults to None.
options (:class:`AdvectionOptions`, optional): an object containing
Expand All @@ -673,9 +674,7 @@ def __init__(self, domain, field_name=None, theta=None,
Raises:
ValueError: if theta is not provided.
"""
# TODO: would this be better as a non-optional argument? Or should the
# check be on the provided value?
if theta is None:
if (theta < 0 or theta > 1):
raise ValueError("please provide a value for theta between 0 and 1")
if isinstance(options, (EmbeddedDGOptions, RecoveryOptions)):
raise NotImplementedError("Only SUPG advection options have been implemented for this time discretisation")
Expand Down Expand Up @@ -727,11 +726,12 @@ def apply(self, x_out, x_in):
x_out.assign(self.x_out)


class ImplicitMidpoint(ThetaMethod):
class TrapeziumRule(ThetaMethod):
"""
Implements the implicit midpoint timestepping method.
Implements the trapezium rule timestepping method, also commonly known as
Crank Nicholson.
The implicit midpoint timestepping method for operator F is written as
The trapezium rule timestepping method for operator F is written as
y^(n+1) = y^n + dt/2*F[y^n] + dt/2*F[y^(n+1)].
It is equivalent to the "theta" method with theta = 1/2.
"""
Expand All @@ -751,7 +751,7 @@ def __init__(self, domain, field_name=None, solver_parameters=None,
to control the "wrapper" methods, such as Embedded DG or a
recovery method. Defaults to None.
"""
super().__init__(domain, field_name, theta=0.5,
super().__init__(domain, 0.5, field_name,
solver_parameters=solver_parameters,
options=options)

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/balance/test_compressible_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def setup_balance(dirname):
io = IO(domain, output)

# Set up transport schemes
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho"),
SSPRK3(domain, "theta", options=EmbeddedDGOptions())]
transport_methods = [DGUpwind(eqns, 'u'),
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/balance/test_saturated_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def setup_saturated(dirname, recovered):
if recovered:
transported_fields.append(SSPRK3(domain, 'u', options=u_opts))
else:
transported_fields.append(ImplicitMidpoint(domain, 'u'))
transported_fields.append(TrapeziumRule(domain, 'u'))

transport_methods = [DGUpwind(eqns, 'u'),
DGUpwind(eqns, 'rho'),
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/balance/test_unsaturated_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def setup_unsaturated(dirname, recovered):
if recovered:
transported_fields.append(SSPRK3(domain, "u", options=u_opts))
else:
transported_fields.append(ImplicitMidpoint(domain, "u"))
transported_fields.append(TrapeziumRule(domain, "u"))

transport_methods = [DGUpwind(eqns, 'u'),
DGUpwind(eqns, 'rho'),
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/equations/test_dry_compressible.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run_dry_compressible(tmpdir):
io = IO(domain, output)

# Transport schemes
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho"),
SSPRK3(domain, "theta")]
transport_methods = [DGUpwind(eqn, 'u'),
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/equations/test_incompressible.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run_incompressible(tmpdir):

# Transport Schemes
b_opts = SUPGOptions()
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "b", options=b_opts)]
transport_methods = [DGUpwind(eqn, "u"),
DGUpwind(eqn, "b", ibp=b_opts.ibp)]
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/equations/test_moist_compressible.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run_moist_compressible(tmpdir):
io = IO(domain, output)

# Transport schemes
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "rho"),
SSPRK3(domain, "theta")]
transport_methods = [DGUpwind(eqn, "u"),
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/equations/test_sw_fplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run_sw_fplane(tmpdir):
io = IO(domain, output, diagnostic_fields=[CourantNumber()])

# Transport schemes
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "D")]
transport_methods = [DGUpwind(eqns, "u"),
DGUpwind(eqns, "D")]
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/equations/test_sw_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_sw_setup(tmpdir, u_transport_option):
domain, eqns, io = setup_sw(dirname, dt, u_transport_option)

# Transport schemes
transported_fields = [ImplicitMidpoint(domain, "u"),
transported_fields = [TrapeziumRule(domain, "u"),
SSPRK3(domain, "D")]

transport_methods = [DGUpwind(eqns, 'u'),
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/model/test_time_discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_time_discretisation(tmpdir, scheme, tracer_setup):
if scheme == "ssprk":
transport_scheme = SSPRK3(domain)
elif scheme == "implicit_midpoint":
transport_scheme = ImplicitMidpoint(domain)
transport_scheme = TrapeziumRule(domain)
elif scheme == "RK4":
transport_scheme = RK4(domain)
elif scheme == "Heun":
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/transport/test_supg_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_supg_transport_scalar(tmpdir, equation_form, scheme, space,
if scheme == "ssprk":
transport_scheme = SSPRK3(domain, options=opts)
elif scheme == "implicit_midpoint":
transport_scheme = ImplicitMidpoint(domain, options=opts)
transport_scheme = TrapeziumRule(domain, options=opts)

transport_method = DGUpwind(eqn, "f", ibp=ibp)
timestepper = PrescribedTransport(eqn, transport_scheme, setup.io, transport_method)
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_supg_transport_vector(tmpdir, equation_form, scheme, space,
if scheme == "ssprk":
transport_scheme = SSPRK3(domain, options=opts)
elif scheme == "implicit_midpoint":
transport_scheme = ImplicitMidpoint(domain, options=opts)
transport_scheme = TrapeziumRule(domain, options=opts)

transport_method = DGUpwind(eqn, "f", ibp=ibp)
timestepper = PrescribedTransport(eqn, transport_scheme, setup.io, transport_method)
Expand Down

0 comments on commit b1aa590

Please sign in to comment.