-
Notifications
You must be signed in to change notification settings - Fork 11
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
Log the Courant number #424
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from netCDF4 import Dataset | ||
import sys | ||
import time | ||
from gusto.diagnostics import Diagnostics | ||
from gusto.diagnostics import Diagnostics, CourantNumber | ||
from gusto.meshes import get_flat_latlon_mesh | ||
from firedrake import (Function, functionspaceimpl, File, | ||
DumbCheckpoint, FILE_CREATE, FILE_READ, CheckpointFile) | ||
|
@@ -238,6 +238,60 @@ def log_parameters(self, equation): | |
logger.info("Physical parameters that take non-default values:") | ||
logger.info(", ".join("%s: %s" % (k, float(v)) for (k, v) in vars(equation.parameters).items())) | ||
|
||
def setup_log_courant(self, state_fields, name='u', expression=None): | ||
""" | ||
Sets up Courant number diagnostics to be logged. | ||
|
||
Args: | ||
state_fields (:class:`StateFields`): the model's field container. | ||
name (str, optional): the name of the field to log the Courant | ||
number of. Defaults to 'u'. | ||
expression (:class:`ufl.Expr`, optional): expression of velocity | ||
field to take Courant number of. Defaults to None, in which case | ||
|
||
""" | ||
|
||
if self.output.log_courant: | ||
diagnostic_names = [diagnostic.name for diagnostic in self.diagnostic_fields] | ||
courant_name = None if name == 'u' else name | ||
|
||
# Set up diagnostic if it hasn't already been | ||
if courant_name not in diagnostic_names and 'u' in state_fields._field_names: | ||
if expression is None: | ||
diagnostic = CourantNumber(to_dump=False) | ||
elif expression is not None: | ||
diagnostic = CourantNumber(velocity=expression, name=courant_name, to_dump=False) | ||
|
||
self.diagnostic_fields.append(diagnostic) | ||
diagnostic.setup(self.domain, state_fields) | ||
self.diagnostics.register(diagnostic.name) | ||
|
||
def log_courant(self, state_fields, name='u', message=None): | ||
""" | ||
Logs the maximum Courant number value. | ||
|
||
Args: | ||
state_fields (:class:`StateFields`): the model's field container. | ||
name (str, optional): the name of the field to log the Courant | ||
number of. Defaults to 'u'. | ||
message (str, optional): an extra message to be logged. Defaults to | ||
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. I like the option to add a message! |
||
None. | ||
""" | ||
|
||
if self.output.log_courant and 'u' in state_fields._field_names: | ||
diagnostic_names = [diagnostic.name for diagnostic in self.diagnostic_fields] | ||
courant_name = 'CourantNumber' if name == 'u' else 'CourantNumber_'+name | ||
courant_idx = diagnostic_names.index(courant_name) | ||
courant_diagnostic = self.diagnostic_fields[courant_idx] | ||
courant_diagnostic.compute() | ||
courant_field = state_fields(courant_name) | ||
courant_max = self.diagnostics.max(courant_field) | ||
|
||
if message is None: | ||
logger.info(f'Max Courant: {courant_max:.2e}') | ||
else: | ||
logger.info(f'Max Courant {message}: {courant_max:.2e}') | ||
|
||
def setup_diagnostics(self, state_fields): | ||
""" | ||
Prepares the I/O for computing the model's global diagnostics and | ||
|
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
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.
unfinished comment...