Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMEX Multistage #453

Merged
merged 26 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1a56e1b
add unit test
alexbrown1995 Sep 7, 2023
fae09a9
Needs tidying, but IMEX_Euler3 is a seemingly working version of IMEX…
alexbrown1995 Sep 14, 2023
97ff98f
Tidy and adding new schemes
alexbrown1995 Sep 18, 2023
1a1fdc0
Merge branch 'main' into IMEX_multistage
alexbrown1995 Sep 18, 2023
aa2d599
Add back in courant logging, tidy time disc
alexbrown1995 Sep 19, 2023
b1b4cf5
change to split advective and div term in SWE
alexbrown1995 Sep 29, 2023
00f9966
SSP3 correction
alexbrown1995 Oct 5, 2023
a6b28a1
Tidy of code, lint corrections
alexbrown1995 Oct 19, 2023
9fef4b2
Merge branch 'main' into IMEX_multistage
alexbrown1995 Oct 19, 2023
c8207bc
revert explicitmultistage changes
alexbrown1995 Oct 19, 2023
78f5557
revert test changes
alexbrown1995 Oct 19, 2023
177c308
adressed most review comments
alexbrown1995 Oct 25, 2023
3a34def
Warning for explicit implicit splitting added
alexbrown1995 Oct 25, 2023
564cafb
Comments added and equations refactor moved into time_discretisation.…
alexbrown1995 Oct 26, 2023
31ddf80
Splitting on conservative term added. Need to make it work in case of…
alexbrown1995 Oct 27, 2023
0c6fba4
Merge to main
alexbrown1995 Oct 27, 2023
85e57a7
Lint fix
alexbrown1995 Oct 27, 2023
10ed951
Labelling of implicit and explicit terms moved outside of time_disc, …
alexbrown1995 Nov 1, 2023
e866193
change error message
alexbrown1995 Nov 1, 2023
cccc433
Merge to main
alexbrown1995 Nov 1, 2023
5878f23
lint fix + firedrake fml move
alexbrown1995 Nov 1, 2023
958e002
Error switched to Runtime
alexbrown1995 Nov 1, 2023
6daae50
linearisation terms added
alexbrown1995 Nov 1, 2023
9191901
bug fix to test func / q
alexbrown1995 Nov 1, 2023
d29d137
Update gusto/common_forms.py
atb1995 Nov 7, 2023
7a14129
Change in description
alexbrown1995 Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 71 additions & 3 deletions gusto/common_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
Provides some basic forms for discretising various common terms in equations for
geophysical fluid dynamics."""

from firedrake import dx, dot, grad, div, inner, outer, cross, curl
from firedrake import (dx, dot, grad, div, inner, outer, cross, curl, split,
TestFunction, TestFunctions, TrialFunction)
from firedrake.fml import subject, drop
from gusto.configuration import TransportEquationType
from gusto.labels import transport, transporting_velocity, diffusion
from gusto.labels import (transport, transporting_velocity, diffusion,
prognostic, linearisation)

__all__ = ["advection_form", "continuity_form", "vector_invariant_form",
"kinetic_energy_form", "advection_equation_circulation_form",
"diffusion_form", "linear_advection_form", "linear_continuity_form"]
"diffusion_form", "linear_advection_form", "linear_continuity_form",
"split_continuity_form"]


def advection_form(test, q, ubar):
Expand Down Expand Up @@ -194,3 +198,67 @@ def diffusion_form(test, q, kappa):
form = -inner(test, div(kappa*grad(q)))*dx

return diffusion(form)


def split_continuity_form(equation):
u"""
Loops through terms in a given equation, and splits continuity terms into
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you mention that this will split up all conservative terms in the equation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks Tom

advective and divergence terms.

This describes splitting ∇.(u*q) into u.∇q and q(∇.u),
for transporting velocity u and transported q.

Args:
equation (:class:`PrognosticEquation`): the model's equation.

Returns:
equation (:class:`PrognosticEquation`): the model's equation.
atb1995 marked this conversation as resolved.
Show resolved Hide resolved
"""

for t in equation.residual:
if (t.get(transport) == TransportEquationType.conservative):
# Get fields and test functions
subj = t.get(subject)
prognostic_field_name = t.get(prognostic)
if hasattr(equation, "field_names"):
idx = equation.field_names.index(prognostic_field_name)
W = equation.function_space
test = TestFunctions(W)[idx]
q = split(subj)[idx]
else:
W = equation.function_space
test = TestFunction(W)
q = subj
# u is either a prognostic or prescribed field
if (hasattr(equation, "field_names")
and 'u' in equation.field_names):
u_idx = equation.field_names.index('u')
uadv = split(equation.X)[u_idx]
elif 'u' in equation.prescribed_fields._field_names:
uadv = equation.prescribed_fields('u')
else:
raise ValueError('Cannot get velocity field')

# Create new advective and divergence terms
adv_term = prognostic(advection_form(test, q, uadv), prognostic_field_name)
div_term = prognostic(test*q*div(uadv)*dx, prognostic_field_name)

# Add linearisations of new terms if required
if (t.has_label(linearisation)):
u_trial = TrialFunction(W)[u_idx]
qbar = split(equation.X_ref)[idx]
# Add linearisation to adv_term
linear_adv_term = linear_advection_form(test, qbar, u_trial)
adv_term = linearisation(adv_term, linear_adv_term)
# Add linearisation to div_term
linear_div_term = transporting_velocity(qbar*test*div(u_trial)*dx, u_trial)
div_term = linearisation(div_term, linear_div_term)

# Add new terms onto residual
equation.residual += subject(adv_term + div_term, subj)
# Drop old term
equation.residual = equation.residual.label_map(
lambda t: t.get(transport) == TransportEquationType.conservative,
map_if_true=drop)

return equation
1 change: 1 addition & 0 deletions gusto/equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ def __init__(self, domain, parameters, fexpr=None, bexpr=None,

# Depth transport term
D_adv = prognostic(continuity_form(phi, D, u), 'D')

# Transport term needs special linearisation
if self.linearisation_map(D_adv.terms[0]):
linear_D_adv = linear_continuity_form(phi, H, u_trial)
Expand Down
2 changes: 2 additions & 0 deletions gusto/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def __call__(self, target, value=None):
# ---------------------------------------------------------------------------- #

time_derivative = Label("time_derivative")
implicit = Label("implicit")
Copy link
Contributor

@tommbendall tommbendall Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see these labels added!

explicit = Label("explicit")
transport = Label("transport", validator=lambda value: type(value) == TransportEquationType)
diffusion = Label("diffusion")
transporting_velocity = Label("transporting_velocity", validator=lambda value: type(value) in [Function, ufl.tensors.ListTensor])
Expand Down
Loading
Loading