-
Notifications
You must be signed in to change notification settings - Fork 28
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
Adding 2-D tracer transport in thetis #122
Conversation
* don't do `if logical_variable==True:` * overshoot and conservation tests weren't actually run
New TracerMassConservation2DCallback wasn't actually used.
So it actually fails if we accidentily use the 3d conservation callback.
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.
This looks great! Only minor comments
@@ -212,6 +216,8 @@ def create_function_spaces(self): | |||
raise Exception('Unsupported finite element family {:}'.format(self.options.element_family)) | |||
self.function_spaces.V_2d = MixedFunctionSpace([self.function_spaces.U_2d, self.function_spaces.H_2d]) | |||
|
|||
self.function_spaces.Q_2d = FunctionSpace(self.mesh2d, 'DG', 1, name='Q_2d') |
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.
The tracer space is called H in the 3D model, we could use the same symbol 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.
Yeah, the reason I suggested a different symbol is that I interpreted H
as the pressure/elevation space - which in 3D has to be same as the tracer space. For depth averaged tracers, I think we don't get strict conservation anyway, so perhaps we could be more flexible. Also strictly speaking I think the requirement is for the tracer space to be a subspace of the pressure space, so in the case of P1DG-P2 you could use P1 tracers.
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.
I see, yes we already use H_2d
for the elevation space.
thetis/solver2d.py
Outdated
self.fields.tracer_2d = Function(self.function_spaces.Q_2d, name='tracer_2d') | ||
self.eq_tracer = tracer_eq_2d.TracerEquation2D(self.function_spaces.Q_2d, bathymetry=self.fields.bathymetry_2d, | ||
use_lax_friedrichs=self.options.use_lax_friedrichs_tracer) | ||
self.eq_tracer.bnd_functions = self.bnd_functions['tracer'] |
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.
Assigning the bnd functions to the equation here. Is this being used? We also set the bnd functions in the coupled time integrator class.
""" | ||
Testing 2D horizontal diffusion of tracers against analytical solution. | ||
|
||
Tuomas Karna 2015-12-14, Athanasios Angeloudis 16/01/2018 |
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 we keep these author tags in the source code? To me it's unclear if they're useful. Currently there are some from 2015 that mention me, but no others...
options.horizontal_viscosity_scale = Constant(horizontal_diffusivity) | ||
options.update(model_options) | ||
if hasattr(options.timestepper_options, 'use_automatic_timestep'): | ||
options.timestepper_options.use_automatic_timestep = True |
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.
Related to setting the horizontal_viscosity_scale
: it seems that solver2d.set_time_step
does not take viscosity scale into account when computing the time step, therefore use_automatic_timestep
is not really meaninful, especially here where we are testing diffusion only. See #79 . Doesn't have to be implemented in this PR.
|
||
# project analytical solultion on high order mesh | ||
t_const.assign(t) | ||
tracer_ana_ho.project(tracer_expr) |
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.
Same comment on high order projection.
|
||
# project analytical solultion on high order mesh | ||
t_const.assign(t) | ||
tracer_ana_ho.project(ana_tracer_expr) |
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.
I think projection to high-order function space is no longer necessary if tracer_expr
is pure UFL expression; errornorm
should just work. This is a remnant of times when it didn't.
thetis/field_defs.py
Outdated
@@ -64,6 +64,12 @@ | |||
'unit': 'm s-1', | |||
'filename': 'Velocity2d', | |||
} | |||
field_metadata['tracer_2d'] = { | |||
'name': 'Tracer', |
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.
Depth averaged?
thetis/coupled_timeintegrator_2d.py
Outdated
|
||
def _create_tracer_integrator(self): | ||
""" | ||
Create time integrator for salinity equation |
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.
tracer equation?
thetis/tracer_eq_2d.py
Outdated
|
||
class TracerEquation2D(Equation): | ||
""" | ||
3D tracer advection-diffusion equation :eq:`tracer_eq` in conservative form |
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.
2D
thetis/tracer_eq_2d.py
Outdated
""" | ||
:arg function_space: :class:`FunctionSpace` where the solution belongs | ||
:kwarg bathymetry: bathymetry of the domain | ||
:type bathymetry: 3D :class:`Function` or :class:`Constant` |
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.
rm 3D
One missing bit is the documentation. At least 2D model formulation should be updated. Would also be nice to have a 2D demo with tracers. Can be in another PR. |
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.
I think the high order spaces could be removed altogether from the tests. Also remove thetis/.solver2d.py.swp
file.
next_export_t += solverobj.options.simulation_export_time | ||
iexport += 1 | ||
|
||
# project analytical solultion on high order mesh |
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.
typo: solution
next_export_t += solverobj.options.simulation_export_time | ||
iexport += 1 | ||
|
||
# project analytical solultion on high order mesh |
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.
typo
|
||
p1dg_ho = FunctionSpace(solverobj.mesh2d, 'DG', options.polynomial_degree + 2, | ||
vfamily='DG', vdegree=options.polynomial_degree + 2) | ||
tracer_ana_ho = Function(p1dg_ho, name='tracer analytical') |
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.
I guess my point on the high order projection was that p1dg_ho
and tracer_ana_ho
are no longer needed. You can just compute the error as errornorm(tracer_ana_ufl_expr, tracer_sol)
. I think /test/pressure_grad
has some examples (degree_rise
option is also obsolete).
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.
Oh now I see, yes I just realised that these do not make a difference! Updating it now
Thanks for the updates, looks good to me! |
adding the option to solve advection diffusion equation in 2D