-
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
Fix Diagnostics of Diagnostics #452
Changes from all commits
75277e2
d6d1b62
1cf50a2
fd8ad70
59af186
597ba6a
c6c1fa6
0be6b0d
2d4798e
7695709
53234f2
3996356
e2817f9
0de497f
efb8c90
2132208
63f4342
053a9bc
ec1a2e5
14396ad
171fb16
0d90f99
9ce0ecf
725f1a9
c85cec0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1078,15 +1078,39 @@ def setup(self, domain, state_fields): | |
""" | ||
# Check if initial field already exists -- otherwise needs creating | ||
if not hasattr(state_fields, self.field_name2): | ||
field1 = state_fields(self.field_name1) | ||
field2 = state_fields(self.field_name2, space=field1.function_space(), | ||
pick_up=True, dump=False) | ||
# Attach state fields to self so that we can pick it up in compute | ||
self.state_fields = state_fields | ||
# The initial value for fields may not have already been set yet so we | ||
# postpone setting it until the compute method is called | ||
self.init_field_set = False | ||
else: | ||
field1 = state_fields(self.field_name1) | ||
field2 = state_fields(self.field_name2, space=field1.function_space(), | ||
pick_up=True, dump=False) | ||
# By default set this new field to the current value | ||
# This may be overwritten if picking up from a checkpoint | ||
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 think we still want these deleted comments in here... I suggest adding something like (you can use your own words!):
|
||
field2.assign(field1) | ||
self.state_fields = state_fields | ||
self.init_field_set = True | ||
|
||
super().setup(domain, state_fields) | ||
|
||
def compute(self): | ||
# The first time the compute method is called we set the initial field. | ||
# We do not want to do this if picking up from a checkpoint | ||
if not self.init_field_set: | ||
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. Add comment here along the lines of:
|
||
# Set initial field | ||
full_field = self.state_fields(self.field_name1) | ||
init_field = self.state_fields(self.field_name2) | ||
init_field.assign(full_field) | ||
|
||
self.init_field_set = True | ||
|
||
super().compute() | ||
|
||
@property | ||
def name(self): | ||
"""Gives the name of this diagnostic field.""" | ||
|
@@ -1248,7 +1272,10 @@ def setup(self, domain, state_fields): | |
state_fields (:class:`StateFields`): the model's field container. | ||
""" | ||
x = SpatialCoordinate(domain.mesh) | ||
self.expr = self.rho_averaged * (1 + self.r_t) * self.parameters.g * dot(x, domain.k) | ||
self._setup_thermodynamics(domain, state_fields) | ||
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. Thanks for fixing this! |
||
z = Function(self.rho_averaged.function_space()) | ||
z.interpolate(dot(x, domain.k)) | ||
self.expr = self.rho_averaged * (1 + self.r_t) * self.parameters.g * z | ||
super().setup(domain, state_fields, space=domain.spaces("DG")) | ||
|
||
|
||
|
@@ -1291,6 +1318,7 @@ def setup(self, domain, state_fields): | |
state_fields (:class:`StateFields`): the model's field container. | ||
""" | ||
u = state_fields('u') | ||
self._setup_thermodynamics(domain, state_fields) | ||
self.expr = 0.5 * self.rho_averaged * (1 + self.r_t) * dot(u, u) | ||
super().setup(domain, state_fields, space=domain.spaces("DG")) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -641,6 +641,11 @@ def pick_up_from_checkpoint(self, state_fields): | |
else: | ||
raise ValueError("Must set checkpoint True if picking up") | ||
|
||
# Prevent any steady-state diagnostics overwriting their original fields | ||
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. Very picky, but it would be good to have a blank line above this comment to help illustrate that the next segment of code is doing something separate from the above bits of code 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. So ive addressed the points regarding the example and some of the comments but was a bit uncertain on my explaining comments so they will be worth checking. I think including perturbation in this will be a good idea too so will start having a dig around in that now |
||
for diagnostic_field in self.diagnostic_fields: | ||
if hasattr(diagnostic_field, "init_field_set"): | ||
diagnostic_field.init_field_set = True | ||
|
||
return t, reference_profiles, step, initial_steps | ||
|
||
def dump(self, state_fields, t, step, initial_steps=None): | ||
|
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.
Did you mean to add all of these changes?