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

Split timestepper #537

Merged
merged 17 commits into from
Sep 4, 2024
Merged

Split timestepper #537

merged 17 commits into from
Sep 4, 2024

Conversation

ta440
Copy link
Collaborator

@ta440 ta440 commented Aug 14, 2024

Adds a general SplitTimestepper class that allows different terms to be timestepped separately using a defined time discretisation. A 'term_splitting' list specifies the order that the terms are solved, e.g ['transport', 'physics', 'diffusion']. A timestepping scheme for each non-physics term is specified in the 'dynamics_schemes' dictionary.
Furthermore, substepping can be used for a term by defining weights. For example, we can Strang-split the transport between diffusion with term_splitting=['transport','diffusion','transport'], weights=[0.5,1,0.5].

A test is added to integration_tests/model/test_split_timestepper.py. This tests three different splittings of the advection-diffusion equation with source physics.

@tommbendall tommbendall added the enhancement Pull requests or issues relating to adding a new capability label Aug 15, 2024
@ta440 ta440 marked this pull request as ready for review August 29, 2024 11:34
Copy link
Contributor

@tommbendall tommbendall left a comment

Choose a reason for hiding this comment

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

Looks good Tim. My comments are mainly about overflowing lines

@@ -130,4 +130,4 @@ def test_boussinesq(tmpdir, compressible):

# Slack values chosen to be robust to different platforms
assert error < 1e-10, f'Values for {variable} in ' + \
'Incompressible test do not match KGO values'
'{compressible} test do not match KGO values'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'{compressible} test do not match KGO values'
f'{compressible} test do not match KGO values'

# If we have physics schemes, extract these.
if 'physics' in term_splitting:
if physics_schemes is None:
raise ValueError('Physics schemes need to be specified when applying a physics splitting in the SplitTimestepper')
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be split over multiple lines?

if term == 'physics':
count += weights[idx]
if count != 1:
raise ValueError('Incorrect weights are specified for the physics schemes in the split timestepper.')
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto!


# Multilevel schemes are currently not supported for the dynamics terms.
for label, scheme in self.dynamics_schemes.items():
assert scheme.nlevels == 1, "Multilevel schemes are not currently implemented in the split timestepper"
Copy link
Contributor

Choose a reason for hiding this comment

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

And here, maybe by doing:

Suggested change
assert scheme.nlevels == 1, "Multilevel schemes are not currently implemented in the split timestepper"
assert scheme.nlevels == 1, \
"Multilevel schemes are not currently implemented in the split timestepper"

# dynamics scheme
for term in self.term_splitting:
if term != 'physics':
assert term in self.dynamics_schemes, f"The {term} terms do not have a specified scheme in the split timestepper"
Copy link
Contributor

Choose a reason for hiding this comment

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

and here ... e.g.

Suggested change
assert term in self.dynamics_schemes, f"The {term} terms do not have a specified scheme in the split timestepper"
assert term in self.dynamics_schemes, \
f"The {term} terms do not have a specified scheme in the split timestepper"

dynamics_schemes = {'transport': ImplicitMidpoint(domain),
'diffusion': ForwardEuler(domain)}
term_splitting = ['transport', 'diffusion', 'physics']
stepper = SplitTimestepper(equation, term_splitting, dynamics_schemes, io, spatial_methods=spatial_methods, physics_schemes=physics_schemes)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we also split this line?

'diffusion': ForwardEuler(domain)}
term_splitting = ['diffusion', 'transport', 'physics', 'transport']
weights = [1., 0.6, 1., 0.4]
stepper = SplitTimestepper(equation, term_splitting, dynamics_schemes, io, weights=weights, spatial_methods=spatial_methods, physics_schemes=physics_schemes)
Copy link
Contributor

Choose a reason for hiding this comment

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

and this one!

dynamics_schemes = {'transport': SSPRK3(domain),
'diffusion': SSPRK3(domain)}
term_splitting = ['physics', 'transport', 'diffusion', 'physics']
weights = [1./3., 1, 1, 2./3.]
Copy link
Contributor

Choose a reason for hiding this comment

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

this is cool

'diffusion': SSPRK3(domain)}
term_splitting = ['physics', 'transport', 'diffusion', 'physics']
weights = [1./3., 1, 1, 2./3.]
stepper = SplitTimestepper(equation, term_splitting, dynamics_schemes, io, weights=weights, spatial_methods=spatial_methods, physics_schemes=physics_schemes)
Copy link
Contributor

Choose a reason for hiding this comment

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

and split this line!

term_splitting (list): a list of labels specifying the terms that should
be solved separately and the order to do so.
dynamics_schemes: (:class:`TimeDiscretisation`) A list of time
discretisations for the dynamics schemes. A scheme must be
Copy link
Contributor

Choose a reason for hiding this comment

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

these continuation comments need indenting -- the pattern should be:

Args:
    variable_name (variable_type): description ....
        ... continued description ...
        ... more continued description ...
    next_variable (next_type): etc ...

Copy link
Contributor

@tommbendall tommbendall left a comment

Choose a reason for hiding this comment

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

Great, thanks Tim!

@tommbendall tommbendall merged commit 3a5367e into main Sep 4, 2024
4 checks passed
@tommbendall tommbendall deleted the split_timestepper branch September 4, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Pull requests or issues relating to adding a new capability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants