Skip to content

Commit

Permalink
I think this fixes the tests but might break mesh movement - check si…
Browse files Browse the repository at this point in the history
…gn of ke term!!
  • Loading branch information
jshipton committed Aug 25, 2023
1 parent 5f5b6a1 commit 2c36527
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
6 changes: 5 additions & 1 deletion gusto/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class Domain(object):
the same then this can be specified through the "degree" argument.
"""
def __init__(self, mesh, dt, family, degree=None,
horizontal_degree=None, vertical_degree=None):
horizontal_degree=None, vertical_degree=None,
move_mesh=False):
"""
Args:
mesh (:class:`Mesh`): the model's mesh.
Expand Down Expand Up @@ -59,6 +60,9 @@ def __init__(self, mesh, dt, family, degree=None,
else:
raise TypeError(f'dt must be a Constant, float or int, not {type(dt)}')

# store whether we are moving the mesh
self.move_mesh = move_mesh

# -------------------------------------------------------------------- #
# Build compatible function spaces
# -------------------------------------------------------------------- #
Expand Down
25 changes: 17 additions & 8 deletions gusto/equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,20 +669,29 @@ def __init__(self, domain, parameters, fexpr=None, bexpr=None,
# -------------------------------------------------------------------- #
# Transport Terms
# -------------------------------------------------------------------- #


# Mesh movement requires the circulation form, and an

Check failure on line 674 in gusto/equations.py

View workflow job for this annotation

GitHub Actions / Run linter

E303

gusto/equations.py:674:9: E303 too many blank lines (2)
# additional modification
if domain.move_mesh:
assert u_transport_option == "circulation_form"

# Velocity transport term -- depends on formulation
if u_transport_option == "vector_invariant_form":
u_adv = prognostic(vector_invariant_form(domain, w, u, u), 'u')
elif u_transport_option == "vector_advection_form":
u_adv = prognostic(advection_form(w, u, u), 'u')
elif u_transport_option == "circulation_form":
ke_form = prognostic(kinetic_energy_form(domain, w, u), "u")
ke_form = transport.remove(ke_form)
ke_form = ke_form.label_map(
lambda t: t.has_label(transporting_velocity),
lambda t: Term(ufl.replace(
t.form, {t.get(transporting_velocity): u}), t.labels))
ke_form = transporting_velocity.remove(ke_form)
u_adv = prognostic(advection_equation_circulation_form(domain, w, u), "u") - ke_form
ke_form = prognostic(kinetic_energy_form(w, u, u), "u")
if domain.move_mesh:
ke_form = transport.remove(ke_form)
ke_form = ke_form.label_map(
lambda t: t.has_label(transporting_velocity),

Check failure on line 689 in gusto/equations.py

View workflow job for this annotation

GitHub Actions / Run linter

F821

gusto/equations.py:689:43: F821 undefined name 'transporting_velocity'
lambda t: Term(ufl.replace(
t.form, {t.get(transporting_velocity): u}), t.labels))

Check failure on line 691 in gusto/equations.py

View workflow job for this annotation

GitHub Actions / Run linter

F821

gusto/equations.py:691:40: F821 undefined name 'transporting_velocity'
ke_form = transporting_velocity.remove(ke_form)

Check failure on line 692 in gusto/equations.py

View workflow job for this annotation

GitHub Actions / Run linter

F821

gusto/equations.py:692:27: F821 undefined name 'transporting_velocity'
ke_form *= -1
u_adv = prognostic(advection_equation_circulation_form(domain, w, u, u), "u") + ke_form
else:
raise ValueError("Invalid u_transport_option: %s" % u_transport_option)

Expand Down
7 changes: 7 additions & 0 deletions gusto/timeloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ def __init__(self, equation_set, io, transport_schemes,
Vu = equation_set.domain.spaces("HDiv")
self.uadv = Function(Vu)

assert isinstance(equation_set, ShallowWaterEquations), \
'Mesh movement only works with the shallow water equation set'

super().__init__(equation_set=equation_set,
io=io,
transport_schemes=transport_schemes,
Expand Down Expand Up @@ -708,6 +711,10 @@ def __init__(self, equation_set, io, transport_schemes,
self.v1 = Function(mesh.coordinates.function_space())
self.v1_V1 = Function(Vu)

# Set up diagnostics - also called in the run method, is it ok
# to do this twice (I suspect not)
self.io.setup_diagnostics(self.fields)

mesh_generator.monitor.setup(self.fields)
mesh_generator.setup()

Expand Down

0 comments on commit 2c36527

Please sign in to comment.