-
Notifications
You must be signed in to change notification settings - Fork 13
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
Terminator toy #457
Merged
Merged
Terminator toy #457
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e6dabe9
started TerminatorToy physics class
ta440 fb42334
added the evaluate property to the TerminatorToy scheme
ta440 b3fa487
Merge branch 'main' of github.com:firedrakeproject/gusto into termina…
ta440 6688c1e
Merge branch 'tracer_density' into terminator_toy
ta440 4157642
made changes to terminator coupled equations
ta440 e422188
cleaned up equation formulation for Terminator Toy
ta440 fc2aa7f
changes
ta440 8bf7d04
Merge branch 'main' into terminator_toy
ta440 315fffe
io logging of tracer amounts for debugging
ta440 55a8259
Merge remote-tracking branch 'origin/main' into terminator_toy
ta440 1f1aa3c
updated to work with gusto changes
ta440 36a3ffd
added the SplitPrescribedTransport timestepper
ta440 fbc3e0a
merged main into terminator
ta440 0d1e5be
beginning the analytical formulation
ta440 fa6cc8f
add implicit_formulation of Terminator Toy
ta440 532c617
more implicit working
ta440 c73f6b5
making the physics scheme compatible with backwards euler
ta440 1322d1d
more changes
ta440 33e70ff
tidy up terminator toy
ta440 3608f70
linting
ta440 c4345b0
more linting
ta440 b931032
Merge branch 'main' into terminator_toy
ta440 1c89b49
more linting
ta440 c01aa56
compatible with fml purge
ta440 4005ea4
make the code more efficient
ta440 03816ec
better docstring and use ValueError
ta440 0cac4dc
Merge branch 'main' into terminator_toy
tommbendall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ | |
from gusto.transport_methods import TransportMethod | ||
import ufl | ||
|
||
__all__ = ["Timestepper", "SplitPhysicsTimestepper", "SemiImplicitQuasiNewton", | ||
"PrescribedTransport"] | ||
__all__ = ["Timestepper", "SplitPhysicsTimestepper", "SplitPrescribedTransport", | ||
"SemiImplicitQuasiNewton", "PrescribedTransport"] | ||
|
||
|
||
class BaseTimestepper(object, metaclass=ABCMeta): | ||
|
@@ -124,7 +124,6 @@ def setup_transporting_velocity(self, scheme): | |
transport term should be replaced with the transport term of | ||
this discretisation. | ||
""" | ||
|
||
if self.transporting_velocity == "prognostic" and "u" in self.fields._field_names: | ||
# Use the prognostic wind variable as the transporting velocity | ||
u_idx = self.equation.field_names.index('u') | ||
|
@@ -378,6 +377,91 @@ def timestep(self): | |
scheme.apply(self.x.np1(scheme.field_name), self.x.np1(scheme.field_name)) | ||
|
||
|
||
class SplitPrescribedTransport(Timestepper): | ||
""" | ||
Implements a timeloop where the physics terms are solved separately from | ||
the dynamics, like with SplitPhysicsTimestepper, but here we define | ||
a prescribed transporting velocity, as opposed to having the | ||
velocity as a prognostic variable. | ||
""" | ||
|
||
def __init__(self, equation, scheme, io, spatial_methods=None, | ||
physics_schemes=None, | ||
prescribed_transporting_velocity=None): | ||
""" | ||
Args: | ||
equation (:class:`PrognosticEquation`): the prognostic equation | ||
scheme (:class:`TimeDiscretisation`): the scheme to use to timestep | ||
the prognostic equation | ||
io (:class:`IO`): the model's object for controlling input/output. | ||
spatial_methods (iter,optional): a list of objects describing the | ||
methods to use for discretising transport or diffusion terms | ||
for each transported/diffused variable. Defaults to None, | ||
in which case the terms follow the original discretisation in | ||
the equation. | ||
physics_schemes: (list, optional): a list of tuples of the form | ||
(:class:`PhysicsParametrisation`, :class:`TimeDiscretisation`), | ||
pairing physics parametrisations and timestepping schemes to use | ||
for each. Timestepping schemes for physics can be explicit | ||
or implicit. Defaults to None. | ||
prescribed_transporting_velocity: (field, optional): A known | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a bit more description to this to explain that it can be a python function, taking time as an argument? I see that the docstrings are wrong for the |
||
velocity field that is used for the transport of tracers. | ||
This can be made time-varying by defining a python function | ||
that uses time as an argument. | ||
Defaults to None. | ||
""" | ||
|
||
# As we handle physics differently to the Timestepper, these are not | ||
# passed to the super __init__ | ||
super().__init__(equation, scheme, io, spatial_methods=spatial_methods) | ||
|
||
if physics_schemes is not None: | ||
self.physics_schemes = physics_schemes | ||
else: | ||
self.physics_schemes = [] | ||
|
||
for parametrisation, phys_scheme in self.physics_schemes: | ||
# check that the supplied schemes for physics are valid | ||
if hasattr(parametrisation, "explicit_only") and parametrisation.explicit_only: | ||
assert isinstance(phys_scheme, ExplicitTimeDiscretisation), \ | ||
("Only explicit time discretisations can be used with " | ||
+ f"physics scheme {parametrisation.label.label}") | ||
apply_bcs = False | ||
phys_scheme.setup(equation, apply_bcs, parametrisation.label) | ||
|
||
if prescribed_transporting_velocity is not None: | ||
self.velocity_projection = Projector( | ||
prescribed_transporting_velocity(self.t), | ||
self.fields('u')) | ||
else: | ||
self.velocity_projection = None | ||
|
||
@property | ||
def transporting_velocity(self): | ||
return self.fields('u') | ||
|
||
def setup_scheme(self): | ||
self.setup_equation(self.equation) | ||
# Go through and label all non-physics terms with a "dynamics" label | ||
dynamics = Label('dynamics') | ||
self.equation.label_terms(lambda t: not any(t.has_label(time_derivative, physics_label)), dynamics) | ||
apply_bcs = True | ||
self.scheme.setup(self.equation, apply_bcs, dynamics) | ||
self.setup_transporting_velocity(self.scheme) | ||
self.scheme.courant_max = self.io.courant_max | ||
|
||
def timestep(self): | ||
|
||
if self.velocity_projection is not None: | ||
self.velocity_projection.project() | ||
|
||
super().timestep() | ||
|
||
with timed_stage("Physics"): | ||
for _, scheme in self.physics_schemes: | ||
scheme.apply(self.x.np1(scheme.field_name), self.x.np1(scheme.field_name)) | ||
|
||
|
||
class SemiImplicitQuasiNewton(BaseTimestepper): | ||
""" | ||
Implements a semi-implicit quasi-Newton discretisation, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a
pass
underneath this to make it obvious that this evaluate method does nothing