-
Notifications
You must be signed in to change notification settings - Fork 12
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
Wrapper of options #471
Merged
Merged
Wrapper of options #471
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
573ad52
started MixedOptions and an integration test for this
ta440 e04c73a
MixedOptions dictionary added
ta440 4a13df3
improvements to MixedOptions
ta440 6165057
more mixed options changes
ta440 775d3b2
more changes to mixed options
ta440 793768e
working on new test functions with mixed options
ta440 5f05367
more changes to test functions for multiple wrappers
ta440 5c13db1
more changes to mixed options with replacing test functions
ta440 806a49e
mixed options works for embedded dg and recovery
ta440 2be1354
moved DG1-DG1 equispaced test from test_limiters to test_mixed_fs_opt…
ta440 6d2fc9b
finalising mixed options test script
ta440 25ed243
lint
ta440 f410d2c
lint
ta440 d166a22
lint
ta440 aa3d7c0
lint
ta440 f1e958a
lint
ta440 51f6f7b
remove dubugging statements
ta440 55e0856
separate MixedFSOptions and MixedFSWrapper to align with exising code
ta440 164041c
lint
ta440 edcc929
lint
ta440 b317f39
lint
ta440 0700381
set up original spaces for MixedFSWrapper within the subwrappers
ta440 2f517e1
make original_space a base wrapper property
ta440 5c2980d
make original_space a required argument for wrapper.setup()
ta440 222c396
lint
ta440 66ce750
Merge branch 'main' into wrapper_of_options
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
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 |
---|---|---|
|
@@ -7,15 +7,15 @@ | |
from abc import ABCMeta, abstractmethod | ||
from firedrake import ( | ||
FunctionSpace, Function, BrokenElement, Projector, Interpolator, | ||
VectorElement, Constant, as_ufl, dot, grad, TestFunction | ||
VectorElement, Constant, as_ufl, dot, grad, TestFunction, MixedFunctionSpace | ||
) | ||
from firedrake.fml import Term | ||
from gusto.configuration import EmbeddedDGOptions, RecoveryOptions, SUPGOptions | ||
from gusto.recovery import Recoverer, ReversibleRecoverer | ||
from gusto.labels import transporting_velocity | ||
import ufl | ||
|
||
__all__ = ["EmbeddedDGWrapper", "RecoveryWrapper", "SUPGWrapper"] | ||
__all__ = ["EmbeddedDGWrapper", "RecoveryWrapper", "SUPGWrapper", "MixedFSWrapper"] | ||
|
||
|
||
class Wrapper(object, metaclass=ABCMeta): | ||
|
@@ -33,14 +33,23 @@ def __init__(self, time_discretisation, wrapper_options): | |
self.time_discretisation = time_discretisation | ||
self.options = wrapper_options | ||
self.solver_parameters = None | ||
self.original_space = None | ||
|
||
@abstractmethod | ||
def setup(self): | ||
def setup(self, original_space): | ||
""" | ||
Performs standard set up routines, and is to be called by the setup | ||
method of the underlying time discretisation. | ||
Store the original function space of the prognostic variable. | ||
|
||
Within each child wrapper, setup performs standard set up routines, | ||
and is to be called by the setup method of the underlying | ||
time discretisation. | ||
|
||
Args: | ||
original_space (:class:`FunctionSpace`): the space that the | ||
prognostic variable is defined on. This is a subset space of | ||
a mixed function space when using a MixedFSWrapper. | ||
""" | ||
pass | ||
self.original_space = original_space | ||
|
||
@abstractmethod | ||
def pre_apply(self): | ||
|
@@ -76,13 +85,14 @@ class EmbeddedDGWrapper(Wrapper): | |
the original space. | ||
""" | ||
|
||
def setup(self): | ||
def setup(self, original_space): | ||
"""Sets up function spaces and fields needed for this wrapper.""" | ||
|
||
assert isinstance(self.options, EmbeddedDGOptions), \ | ||
'Embedded DG wrapper can only be used with Embedded DG Options' | ||
|
||
original_space = self.time_discretisation.fs | ||
super().setup(original_space) | ||
|
||
domain = self.time_discretisation.domain | ||
equation = self.time_discretisation.equation | ||
|
||
|
@@ -91,7 +101,7 @@ def setup(self): | |
# -------------------------------------------------------------------- # | ||
|
||
if self.options.embedding_space is None: | ||
V_elt = BrokenElement(original_space.ufl_element()) | ||
V_elt = BrokenElement(self.original_space.ufl_element()) | ||
self.function_space = FunctionSpace(domain.mesh, V_elt) | ||
else: | ||
self.function_space = self.options.embedding_space | ||
|
@@ -104,8 +114,9 @@ def setup(self): | |
|
||
self.x_in = Function(self.function_space) | ||
self.x_out = Function(self.function_space) | ||
|
||
if self.time_discretisation.idx is None: | ||
self.x_projected = Function(equation.function_space) | ||
self.x_projected = Function(self.original_space) | ||
else: | ||
self.x_projected = Function(equation.spaces[self.time_discretisation.idx]) | ||
|
||
|
@@ -158,13 +169,14 @@ class RecoveryWrapper(Wrapper): | |
field is then returned to the original space. | ||
""" | ||
|
||
def setup(self): | ||
def setup(self, original_space): | ||
"""Sets up function spaces and fields needed for this wrapper.""" | ||
|
||
assert isinstance(self.options, RecoveryOptions), \ | ||
'Embedded DG wrapper can only be used with Recovery Options' | ||
'Recovery wrapper can only be used with Recovery Options' | ||
|
||
super().setup(original_space) | ||
|
||
original_space = self.time_discretisation.fs | ||
domain = self.time_discretisation.domain | ||
equation = self.time_discretisation.equation | ||
|
||
|
@@ -173,7 +185,7 @@ def setup(self): | |
# -------------------------------------------------------------------- # | ||
|
||
if self.options.embedding_space is None: | ||
V_elt = BrokenElement(original_space.ufl_element()) | ||
V_elt = BrokenElement(self.original_space.ufl_element()) | ||
self.function_space = FunctionSpace(domain.mesh, V_elt) | ||
else: | ||
self.function_space = self.options.embedding_space | ||
|
@@ -184,11 +196,12 @@ def setup(self): | |
# Internal variables to be used | ||
# -------------------------------------------------------------------- # | ||
|
||
self.x_in_tmp = Function(self.time_discretisation.fs) | ||
self.x_in_tmp = Function(self.original_space) | ||
self.x_in = Function(self.function_space) | ||
self.x_out = Function(self.function_space) | ||
|
||
if self.time_discretisation.idx is None: | ||
self.x_projected = Function(equation.function_space) | ||
self.x_projected = Function(self.original_space) | ||
else: | ||
self.x_projected = Function(equation.spaces[self.time_discretisation.idx]) | ||
|
||
|
@@ -361,3 +374,61 @@ def label_terms(self, residual): | |
new_residual = transporting_velocity.update_value(new_residual, self.transporting_velocity) | ||
|
||
return new_residual | ||
|
||
|
||
class MixedFSWrapper(object): | ||
""" | ||
An object to hold a subwrapper dictionary with different wrappers for | ||
different tracers. This means that different tracers can be solved | ||
simultaneously using a CoupledTransportEquation, whilst being in | ||
different spaces and needing different implementation options. | ||
""" | ||
|
||
def __init__(self): | ||
|
||
self.wrapper_spaces = None | ||
self.field_names = None | ||
self.subwrappers = {} | ||
|
||
def setup(self): | ||
""" Compute the new mixed function space from the subwrappers """ | ||
|
||
self.function_space = MixedFunctionSpace(self.wrapper_spaces) | ||
self.x_in = Function(self.function_space) | ||
self.x_out = Function(self.function_space) | ||
|
||
def pre_apply(self, x_in): | ||
""" | ||
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. This method looks exactly right to me |
||
Perform the pre-applications for all fields | ||
with an associated subwrapper. | ||
""" | ||
|
||
for field_name in self.field_names: | ||
field_idx = self.field_names.index(field_name) | ||
field = x_in.subfunctions[field_idx] | ||
x_in_sub = self.x_in.subfunctions[field_idx] | ||
|
||
if field_name in self.subwrappers: | ||
subwrapper = self.subwrappers[field_name] | ||
subwrapper.pre_apply(field) | ||
x_in_sub.assign(subwrapper.x_in) | ||
else: | ||
x_in_sub.assign(field) | ||
|
||
def post_apply(self, x_out): | ||
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. This method looks exactly right to me |
||
""" | ||
Perform the post-applications for all fields | ||
with an associated subwrapper. | ||
""" | ||
|
||
for field_name in self.field_names: | ||
field_idx = self.field_names.index(field_name) | ||
field = self.x_out.subfunctions[field_idx] | ||
x_out_sub = x_out.subfunctions[field_idx] | ||
|
||
if field_name in self.subwrappers: | ||
subwrapper = self.subwrappers[field_name] | ||
subwrapper.x_out.assign(field) | ||
subwrapper.post_apply(x_out_sub) | ||
else: | ||
x_out_sub.assign(field) |
Oops, something went wrong.
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.
Thanks for correcting this!