-
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
Improve tracer density #492
Changes from 7 commits
f9cad21
7a7a099
a411171
baa1b66
c320322
d0a12bc
e1a5028
3a66b4e
1cb388f
0aebae3
3a9c38d
5dad4ca
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 |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
LinearVariationalProblem, LinearVariationalSolver, FacetNormal, \ | ||
ds_b, ds_v, ds_t, dS_h, dS_v, ds, dS, div, avg, jump, pi, \ | ||
TensorFunctionSpace, SpatialCoordinate, as_vector, \ | ||
Projector, Interpolator, FunctionSpace | ||
Projector, Interpolator, FunctionSpace, FiniteElement, \ | ||
TensorProductElement | ||
from firedrake.assign import Assigner | ||
|
||
from abc import ABCMeta, abstractmethod, abstractproperty | ||
|
@@ -1691,7 +1692,10 @@ class TracerDensity(DiagnosticField): | |
"""Diagnostic for computing the density of a tracer. This is | ||
computed as the product of a mixing ratio and dry density""" | ||
|
||
name = "TracerDensity" | ||
@property | ||
def name(self): | ||
"""Gives the name of this diagnostic field.""" | ||
return "TracerDensity_"+self.mixing_ratio_name+'_'+self.density_name | ||
|
||
def __init__(self, mixing_ratio_name, density_name, space=None, method='interpolate'): | ||
""" | ||
|
@@ -1705,7 +1709,9 @@ def __init__(self, mixing_ratio_name, density_name, space=None, method='interpol | |
for this diagnostic. Valid options are 'interpolate', 'project' and | ||
'assign'. Defaults to 'interpolate'. | ||
""" | ||
|
||
super().__init__(method=method, required_fields=(mixing_ratio_name, density_name)) | ||
|
||
self.mixing_ratio_name = mixing_ratio_name | ||
self.density_name = density_name | ||
|
||
|
@@ -1717,7 +1723,36 @@ def setup(self, domain, state_fields): | |
domain (:class:`Domain`): the model's domain object. | ||
state_fields (:class:`StateFields`): the model's field container. | ||
""" | ||
|
||
m_X = state_fields(self.mixing_ratio_name) | ||
rho_d = state_fields(self.density_name) | ||
|
||
m_X_space = m_X.function_space() | ||
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 want all of this code to be protected behind an 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. Cool, I've changed it to enable this, although I've used |
||
rho_d_space = rho_d.function_space() | ||
|
||
if domain.spaces.extruded_mesh: | ||
m_X_horiz = m_X_space.ufl_element().sub_elements[0] | ||
m_X_vert = m_X_space.ufl_element().sub_elements[1] | ||
rho_d_horiz = rho_d_space.ufl_element().sub_elements[0] | ||
rho_d_vert = rho_d_space.ufl_element().sub_elements[1] | ||
|
||
horiz_degree = m_X_horiz.degree() + rho_d_horiz.degree() | ||
vert_degree = m_X_vert.degree() + rho_d_vert.degree() | ||
|
||
cell = domain.mesh._base_mesh.ufl_cell().cellname() | ||
horiz_elt = FiniteElement('DG', cell, horiz_degree) | ||
vert_elt = FiniteElement('DG', cell, vert_degree) | ||
elt = TensorProductElement(horiz_elt, vert_elt) | ||
|
||
else: | ||
m_X_degree = m_X_space.ufl_element().degree() | ||
rho_d_degree = rho_d_space.ufl_element().degree() | ||
degree = m_X_degree + rho_d_degree | ||
|
||
cell = domain.mesh.ufl_cell().cellname() | ||
elt = FiniteElement('DG', cell, degree) | ||
|
||
tracer_density_space = FunctionSpace(domain.mesh, elt, name='tracer_density_space') | ||
|
||
self.expr = m_X*rho_d | ||
super().setup(domain, state_fields) | ||
super().setup(domain, state_fields, space=tracer_density_space) |
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.
should the
density_name
argument come after thetransport_eqn
argument for consistency?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.
Oops, good spot, thanks!