From a1999348be7b57a895bf9d4e31490d26ece5eea0 Mon Sep 17 00:00:00 2001 From: Witt-D Date: Fri, 16 Aug 2024 14:08:37 +0100 Subject: [PATCH 1/9] quick change for how the coriolis is defined --- gusto/core/configuration.py | 4 ++-- gusto/equations/boussinesq_equations.py | 7 ++++--- gusto/equations/compressible_euler_equations.py | 10 ++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/gusto/core/configuration.py b/gusto/core/configuration.py index 5aebf5a33..ca90a3e19 100644 --- a/gusto/core/configuration.py +++ b/gusto/core/configuration.py @@ -114,7 +114,7 @@ class BoussinesqParameters(Configuration): g = 9.810616 N = 0.01 # Brunt-Vaisala frequency (1/s) cs = 340 # sound speed (for compressible case) (m/s) - + Omega = None class CompressibleParameters(Configuration): """Physical parameters for the Compressible Euler equations.""" @@ -136,7 +136,7 @@ class CompressibleParameters(Configuration): w_sat2 = -17.27 # second const. in Teten's formula (no units) w_sat3 = 35.86 # third const. in Teten's formula (K) w_sat4 = 610.9 # fourth const. in Teten's formula (Pa) - + Omega = None # Rotation rate class ShallowWaterParameters(Configuration): """Physical parameters for the shallow-water equations.""" diff --git a/gusto/equations/boussinesq_equations.py b/gusto/equations/boussinesq_equations.py index eae09369e..dfb744dc4 100644 --- a/gusto/equations/boussinesq_equations.py +++ b/gusto/equations/boussinesq_equations.py @@ -191,11 +191,12 @@ def __init__(self, domain, parameters, # -------------------------------------------------------------------- # # Extra Terms (Coriolis) # -------------------------------------------------------------------- # - if Omega is not None: + if self.parameters.Omega is not None: # TODO: add linearisation - residual += coriolis(subject(prognostic( + Omega = as_vector((0, 0, self.parameters.Omega)) + coriolis_form = coriolis(subject(prognostic( inner(w, cross(2*Omega, u))*dx, 'u'), self.X)) - + residual += coriolis_form # -------------------------------------------------------------------- # # Linearise equations # -------------------------------------------------------------------- # diff --git a/gusto/equations/compressible_euler_equations.py b/gusto/equations/compressible_euler_equations.py index b6b89cd8c..b11b8a7bd 100644 --- a/gusto/equations/compressible_euler_equations.py +++ b/gusto/equations/compressible_euler_equations.py @@ -216,10 +216,12 @@ def __init__(self, domain, parameters, Omega=None, sponge_options=None, # -------------------------------------------------------------------- # # Extra Terms (Coriolis, Sponge, Diffusion and others) # -------------------------------------------------------------------- # - if Omega is not None: - # TODO: add linearisation - residual += coriolis(subject(prognostic( - inner(w, cross(2*Omega, u))*dx, "u"), self.X)) + if parameters.Omega is not None: + # TODO: add linearis0ation + Omega = as_vector((0, 0, parameters.Omega)) + coriolis_form = coriolis(subject(prognostic( + inner(w, cross(2*Omega, u))*dx, 'u'), self.X)) + residual += coriolis_form if sponge_options is not None: W_DG = FunctionSpace(domain.mesh, "DG", 2) From 62361a9bcf0c06ee53f36100c2f39e14c2a3757e Mon Sep 17 00:00:00 2001 From: Witt-D Date: Fri, 16 Aug 2024 14:10:10 +0100 Subject: [PATCH 2/9] removed excess omega --- gusto/equations/boussinesq_equations.py | 1 - gusto/equations/compressible_euler_equations.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/gusto/equations/boussinesq_equations.py b/gusto/equations/boussinesq_equations.py index dfb744dc4..a842be4ff 100644 --- a/gusto/equations/boussinesq_equations.py +++ b/gusto/equations/boussinesq_equations.py @@ -40,7 +40,6 @@ class BoussinesqEquations(PrognosticEquationSet): def __init__(self, domain, parameters, compressible=True, - Omega=None, space_names=None, linearisation_map='default', u_transport_option="vector_invariant_form", diff --git a/gusto/equations/compressible_euler_equations.py b/gusto/equations/compressible_euler_equations.py index b11b8a7bd..9ecc9905f 100644 --- a/gusto/equations/compressible_euler_equations.py +++ b/gusto/equations/compressible_euler_equations.py @@ -34,7 +34,7 @@ class CompressibleEulerEquations(PrognosticEquationSet): pressure. """ - def __init__(self, domain, parameters, Omega=None, sponge_options=None, + def __init__(self, domain, parameters, sponge_options=None, extra_terms=None, space_names=None, linearisation_map='default', u_transport_option="vector_invariant_form", From e31912307bc8cc28dca34ee1cd2d647e9a7fd73e Mon Sep 17 00:00:00 2001 From: Witt-D Date: Fri, 16 Aug 2024 14:15:22 +0100 Subject: [PATCH 3/9] flake8 fixes --- gusto/equations/boussinesq_equations.py | 2 +- gusto/equations/compressible_euler_equations.py | 2 +- gusto/equations/shallow_water_equations.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gusto/equations/boussinesq_equations.py b/gusto/equations/boussinesq_equations.py index a842be4ff..50c6adecd 100644 --- a/gusto/equations/boussinesq_equations.py +++ b/gusto/equations/boussinesq_equations.py @@ -1,6 +1,6 @@ """Defines the Boussinesq equations.""" -from firedrake import inner, dx, div, cross, split +from firedrake import inner, dx, div, cross, split, as_vector from firedrake.fml import subject from gusto.core.labels import ( time_derivative, transport, prognostic, linearisation, diff --git a/gusto/equations/compressible_euler_equations.py b/gusto/equations/compressible_euler_equations.py index 9ecc9905f..b5d6f84a3 100644 --- a/gusto/equations/compressible_euler_equations.py +++ b/gusto/equations/compressible_euler_equations.py @@ -2,7 +2,7 @@ from firedrake import ( sin, pi, inner, dx, div, cross, FunctionSpace, FacetNormal, jump, avg, dS_v, - conditional, SpatialCoordinate, split, Constant + conditional, SpatialCoordinate, split, Constant, as_vector ) from firedrake.fml import subject, replace_subject from gusto.core.labels import ( diff --git a/gusto/equations/shallow_water_equations.py b/gusto/equations/shallow_water_equations.py index 7e7453656..2b9f58d38 100644 --- a/gusto/equations/shallow_water_equations.py +++ b/gusto/equations/shallow_water_equations.py @@ -165,13 +165,13 @@ def __init__(self, domain, parameters, fexpr=None, bexpr=None, if fexpr is not None: V = FunctionSpace(domain.mesh, 'CG', 1) - f = self.prescribed_fields('coriolis', V).interpolate(fexpr) + self.f = self.prescribed_fields('coriolis', V).interpolate(fexpr) coriolis_form = coriolis(subject( - prognostic(f*inner(domain.perp(u), w)*dx, "u"), self.X)) + prognostic(self.f*inner(domain.perp(u), w)*dx, "u"), self.X)) # Add linearisation if self.linearisation_map(coriolis_form.terms[0]): linear_coriolis = coriolis( - subject(prognostic(f*inner(domain.perp(u_trial), w)*dx, 'u'), self.X)) + subject(prognostic(self.f*inner(domain.perp(u_trial), w)*dx, 'u'), self.X)) coriolis_form = linearisation(coriolis_form, linear_coriolis) residual += coriolis_form From 99f30af82c2281c747324c317dd432c548b582c1 Mon Sep 17 00:00:00 2001 From: Witt-D Date: Fri, 16 Aug 2024 14:18:22 +0100 Subject: [PATCH 4/9] flake8 again --- gusto/core/configuration.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gusto/core/configuration.py b/gusto/core/configuration.py index ca90a3e19..252f25187 100644 --- a/gusto/core/configuration.py +++ b/gusto/core/configuration.py @@ -116,6 +116,7 @@ class BoussinesqParameters(Configuration): cs = 340 # sound speed (for compressible case) (m/s) Omega = None + class CompressibleParameters(Configuration): """Physical parameters for the Compressible Euler equations.""" @@ -138,6 +139,7 @@ class CompressibleParameters(Configuration): w_sat4 = 610.9 # fourth const. in Teten's formula (Pa) Omega = None # Rotation rate + class ShallowWaterParameters(Configuration): """Physical parameters for the shallow-water equations.""" From 965cd4f37f712b8ee6c118049bf1a915199907fd Mon Sep 17 00:00:00 2001 From: Witt-D Date: Fri, 16 Aug 2024 14:29:16 +0100 Subject: [PATCH 5/9] changed one example file for new configuration --- examples/compressible/skamarock_klemp_hydrostatic.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/compressible/skamarock_klemp_hydrostatic.py b/examples/compressible/skamarock_klemp_hydrostatic.py index 36b500540..9988a6d72 100644 --- a/examples/compressible/skamarock_klemp_hydrostatic.py +++ b/examples/compressible/skamarock_klemp_hydrostatic.py @@ -39,10 +39,9 @@ domain = Domain(mesh, dt, "RTCF", 1) # Equation -parameters = CompressibleParameters() -Omega = as_vector((0., 0., 0.5e-4)) +parameters = CompressibleParameters(Omega=0.5e-4) balanced_pg = as_vector((0., -1.0e-4*20, 0.)) -eqns = CompressibleEulerEquations(domain, parameters, Omega=Omega, +eqns = CompressibleEulerEquations(domain, parameters, extra_terms=[("u", balanced_pg)]) # I/O From 92ea426f7b818fda28b6a97bbaa051db7a57b8fa Mon Sep 17 00:00:00 2001 From: Witt-D Date: Fri, 16 Aug 2024 14:39:33 +0100 Subject: [PATCH 6/9] removeds self.f comment --- gusto/equations/shallow_water_equations.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gusto/equations/shallow_water_equations.py b/gusto/equations/shallow_water_equations.py index 2b9f58d38..7e7453656 100644 --- a/gusto/equations/shallow_water_equations.py +++ b/gusto/equations/shallow_water_equations.py @@ -165,13 +165,13 @@ def __init__(self, domain, parameters, fexpr=None, bexpr=None, if fexpr is not None: V = FunctionSpace(domain.mesh, 'CG', 1) - self.f = self.prescribed_fields('coriolis', V).interpolate(fexpr) + f = self.prescribed_fields('coriolis', V).interpolate(fexpr) coriolis_form = coriolis(subject( - prognostic(self.f*inner(domain.perp(u), w)*dx, "u"), self.X)) + prognostic(f*inner(domain.perp(u), w)*dx, "u"), self.X)) # Add linearisation if self.linearisation_map(coriolis_form.terms[0]): linear_coriolis = coriolis( - subject(prognostic(self.f*inner(domain.perp(u_trial), w)*dx, 'u'), self.X)) + subject(prognostic(f*inner(domain.perp(u_trial), w)*dx, 'u'), self.X)) coriolis_form = linearisation(coriolis_form, linear_coriolis) residual += coriolis_form From 102b8634f2499f249475c28015eafbcf64d496e2 Mon Sep 17 00:00:00 2001 From: Witt-D Date: Fri, 16 Aug 2024 14:40:31 +0100 Subject: [PATCH 7/9] fixed spelling --- gusto/equations/compressible_euler_equations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gusto/equations/compressible_euler_equations.py b/gusto/equations/compressible_euler_equations.py index b5d6f84a3..9721b664e 100644 --- a/gusto/equations/compressible_euler_equations.py +++ b/gusto/equations/compressible_euler_equations.py @@ -217,7 +217,7 @@ def __init__(self, domain, parameters, sponge_options=None, # Extra Terms (Coriolis, Sponge, Diffusion and others) # -------------------------------------------------------------------- # if parameters.Omega is not None: - # TODO: add linearis0ation + # TODO: add linearisation Omega = as_vector((0, 0, parameters.Omega)) coriolis_form = coriolis(subject(prognostic( inner(w, cross(2*Omega, u))*dx, 'u'), self.X)) From 576580ae6fa63a39580d27e6f50a8877feee8750 Mon Sep 17 00:00:00 2001 From: Witt-D Date: Fri, 16 Aug 2024 14:41:44 +0100 Subject: [PATCH 8/9] fixed docstrings --- gusto/equations/boussinesq_equations.py | 2 -- gusto/equations/compressible_euler_equations.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/gusto/equations/boussinesq_equations.py b/gusto/equations/boussinesq_equations.py index 50c6adecd..dc6977bc6 100644 --- a/gusto/equations/boussinesq_equations.py +++ b/gusto/equations/boussinesq_equations.py @@ -53,8 +53,6 @@ def __init__(self, domain, parameters, the model's physical parameters. compressible (bool, optional): flag to indicate whether the equations are compressible. Defaults to True - Omega (:class:`ufl.Expr`, optional): an expression for the planet's - rotation vector. Defaults to None. space_names (dict, optional): a dictionary of strings for names of the function spaces to use for the spatial discretisation. The keys are the names of the prognostic variables. Defaults to None diff --git a/gusto/equations/compressible_euler_equations.py b/gusto/equations/compressible_euler_equations.py index 9721b664e..5ba2874ba 100644 --- a/gusto/equations/compressible_euler_equations.py +++ b/gusto/equations/compressible_euler_equations.py @@ -47,8 +47,6 @@ def __init__(self, domain, parameters, sponge_options=None, mesh and the compatible function spaces. parameters (:class:`Configuration`, optional): an object containing the model's physical parameters. - Omega (:class:`ufl.Expr`, optional): an expression for the planet's - rotation vector. Defaults to None. sponge_options (:class:`SpongeLayerParameters`, optional): any parameters for applying a sponge layer to the upper boundary. Defaults to None. From 60424971ef6cf6ad463eff546c38dad0b7f7a883 Mon Sep 17 00:00:00 2001 From: Witt-D Date: Fri, 16 Aug 2024 14:44:36 +0100 Subject: [PATCH 9/9] more removal of Omegas --- gusto/equations/boussinesq_equations.py | 4 ---- gusto/equations/compressible_euler_equations.py | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/gusto/equations/boussinesq_equations.py b/gusto/equations/boussinesq_equations.py index dc6977bc6..0711259e1 100644 --- a/gusto/equations/boussinesq_equations.py +++ b/gusto/equations/boussinesq_equations.py @@ -225,7 +225,6 @@ class LinearBoussinesqEquations(BoussinesqEquations): def __init__(self, domain, parameters, compressible=True, - Omega=None, space_names=None, linearisation_map='default', u_transport_option="vector_invariant_form", @@ -239,8 +238,6 @@ def __init__(self, domain, parameters, the model's physical parameters. compressible (bool, optional): flag to indicate whether the equations are compressible. Defaults to True - Omega (:class:`ufl.Expr`, optional): an expression for the planet's - rotation vector. Defaults to None. space_names (dict, optional): a dictionary of strings for names of the function spaces to use for the spatial discretisation. The keys are the names of the prognostic variables. Defaults to None @@ -276,7 +273,6 @@ def __init__(self, domain, parameters, super().__init__(domain=domain, parameters=parameters, compressible=compressible, - Omega=Omega, space_names=space_names, linearisation_map=linearisation_map, u_transport_option=u_transport_option, diff --git a/gusto/equations/compressible_euler_equations.py b/gusto/equations/compressible_euler_equations.py index 5ba2874ba..73b80b7d6 100644 --- a/gusto/equations/compressible_euler_equations.py +++ b/gusto/equations/compressible_euler_equations.py @@ -279,7 +279,7 @@ class HydrostaticCompressibleEulerEquations(CompressibleEulerEquations): equations. """ - def __init__(self, domain, parameters, Omega=None, sponge=None, + def __init__(self, domain, parameters, sponge=None, extra_terms=None, space_names=None, linearisation_map='default', u_transport_option="vector_invariant_form", diffusion_options=None, @@ -291,8 +291,6 @@ def __init__(self, domain, parameters, Omega=None, sponge=None, mesh and the compatible function spaces. parameters (:class:`Configuration`, optional): an object containing the model's physical parameters. - Omega (:class:`ufl.Expr`, optional): an expression for the planet's - rotation vector. Defaults to None. sponge (:class:`ufl.Expr`, optional): an expression for a sponge layer. Defaults to None. extra_terms (:class:`ufl.Expr`, optional): any extra terms to be @@ -325,7 +323,7 @@ def __init__(self, domain, parameters, Omega=None, sponge=None, NotImplementedError: only mixing ratio tracers are implemented. """ - super().__init__(domain, parameters, Omega=Omega, sponge=sponge, + super().__init__(domain, parameters, sponge=sponge, extra_terms=extra_terms, space_names=space_names, linearisation_map=linearisation_map, u_transport_option=u_transport_option,