From 31956fba5755e9d016b5362ace6638c810a51442 Mon Sep 17 00:00:00 2001 From: atb1995 Date: Thu, 28 Nov 2024 10:32:35 +0000 Subject: [PATCH] Revert "Merge branch 'main' into mixed_fs_supg" This reverts commit ac03896ca3dde8a3ca8e381d28c964dfaa62e4d9, reversing changes made to 62d1d492a434790a20de54aab8a07074ebec4f3e. --- .../mountain_hydrostatic.py | 5 ++-- .../hydrostatic_initialisation.py | 24 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/examples/compressible_euler/mountain_hydrostatic.py b/examples/compressible_euler/mountain_hydrostatic.py index 1fc113a71..8d9b0f8a6 100644 --- a/examples/compressible_euler/mountain_hydrostatic.py +++ b/examples/compressible_euler/mountain_hydrostatic.py @@ -18,7 +18,7 @@ TrapeziumRule, SUPGOptions, ZComponent, Perturbation, CompressibleParameters, HydrostaticCompressibleEulerEquations, CompressibleSolver, compressible_hydrostatic_balance, HydrostaticImbalance, - SpongeLayerParameters, MinKernel, MaxKernel, logger + SpongeLayerParameters, MinKernel, MaxKernel, remove_initial_w, logger ) mountain_hydrostatic_defaults = { @@ -243,7 +243,8 @@ def mountain_hydrostatic( theta0.assign(theta_b) rho0.assign(rho_b) - u0.project(as_vector([initial_wind, 0.0]), bcs=eqns.bcs['u']) + u0.project(as_vector([initial_wind, 0.0])) + remove_initial_w(u0) stepper.set_reference_profiles([('rho', rho_b), ('theta', theta_b)]) diff --git a/gusto/initialisation/hydrostatic_initialisation.py b/gusto/initialisation/hydrostatic_initialisation.py index 53bf537e8..f4be78451 100644 --- a/gusto/initialisation/hydrostatic_initialisation.py +++ b/gusto/initialisation/hydrostatic_initialisation.py @@ -12,10 +12,9 @@ from gusto.recovery import Recoverer, BoundaryMethod -__all__ = [ - "boussinesq_hydrostatic_balance", "compressible_hydrostatic_balance", - "saturated_hydrostatic_balance", "unsaturated_hydrostatic_balance" -] +__all__ = ["boussinesq_hydrostatic_balance", + "compressible_hydrostatic_balance", "remove_initial_w", + "saturated_hydrostatic_balance", "unsaturated_hydrostatic_balance"] def boussinesq_hydrostatic_balance(equation, b0, p0, top=False, params=None): @@ -220,6 +219,23 @@ def compressible_hydrostatic_balance(equation, theta0, rho0, exner0=None, rho0.interpolate(thermodynamics.rho(parameters, theta0, exner)) +def remove_initial_w(u): + """ + Removes the vertical component of a velocity field. + + Args: + u (:class:`Function`): the velocity field to be altered. + """ + Vu = u.function_space() + Vv = FunctionSpace(Vu._ufl_domain, Vu.ufl_element()._elements[-1]) + bc = DirichletBC(Vu[0], 0.0, "bottom") + bc.apply(u) + uv = Function(Vv).project(u) + ustar = Function(u.function_space()).project(uv) + uin = Function(u.function_space()).assign(u - ustar) + u.assign(uin) + + def saturated_hydrostatic_balance(equation, state_fields, theta_e, mr_t, exner0=None, top=False, exner_boundary=Constant(1.0),