Skip to content
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

Firedrake warnings fix #396

Merged
merged 5 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gusto/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def add_field(self, name, space, subfield_names=None):

if len(space) > 1:
assert len(space) == len(subfield_names)
for field_name, field in zip(subfield_names, value.split()):
for field_name, field in zip(subfield_names, value.subfunctions):
setattr(self, field_name, field)
field.rename(field_name)
self.fields.append(field)
Expand Down
8 changes: 4 additions & 4 deletions gusto/initialisation_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def incompressible_hydrostatic_balance(equation, b0, p0, top=False, params=None)

solve(a == L, w1, bcs=bcs, solver_parameters=params)

v, pprime = w1.split()
v, pprime = w1.subfunctions
p0.project(pprime)


Expand Down Expand Up @@ -235,13 +235,13 @@ def compressible_hydrostatic_balance(equation, theta0, rho0, exner0=None,
options_prefix="exner_solver")

exner_solver.solve()
v, exner = w.split()
v, exner = w.subfunctions
if exner0 is not None:
exner0.assign(exner)

if solve_for_rho:
w1 = Function(W)
v, rho = w1.split()
v, rho = w1.subfunctions
rho.interpolate(thermodynamics.rho(parameters, theta0, exner))
v, rho = split(w1)
dv, dexner = TestFunctions(W)
Expand All @@ -256,7 +256,7 @@ def compressible_hydrostatic_balance(equation, theta0, rho0, exner0=None,
rhosolver = NonlinearVariationalSolver(rhoproblem, solver_parameters=params,
options_prefix="rhosolver")
rhosolver.solve()
v, rho_ = w1.split()
v, rho_ = w1.subfunctions
rho0.assign(rho_)
else:
rho0.interpolate(thermodynamics.rho(parameters, theta0, exner))
Expand Down
10 changes: 5 additions & 5 deletions gusto/linear_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def solve(self, xrhs, dy):
# Solve the hybridized system
self.hybridized_solver.solve()

broken_u, rho1, _ = self.urhol0.split()
broken_u, rho1, _ = self.urhol0.subfunctions
u1 = self.u_hdiv

# Project broken_u into the HDiv space
Expand All @@ -387,7 +387,7 @@ def solve(self, xrhs, dy):
bc.apply(u1)

# Copy back into u and rho cpts of dy
u, rho, theta = dy.split()[0:3]
u, rho, theta = dy.subfunctions[0:3]
u.assign(u1)
rho.assign(rho1)

Expand Down Expand Up @@ -495,7 +495,7 @@ def trace_nullsp(T):
b = TrialFunction(Vb)
gamma = TestFunction(Vb)

u, p = self.up.split()
u, p = self.up.subfunctions
self.b = Function(Vb)

b_eqn = gamma*(b - b_in
Expand All @@ -522,8 +522,8 @@ def solve(self, xrhs, dy):
with timed_region("Gusto:VelocityPressureSolve"):
self.up_solver.solve()

u1, p1 = self.up.split()
u, p, b = dy.split()
u1, p1 = self.up.subfunctions
u, p, b = dy.subfunctions
u.assign(u1)
p.assign(p1)

Expand Down
32 changes: 16 additions & 16 deletions gusto/physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def __init__(self, equation, vapour_name='water_vapour',
# Vapour and cloud variables are needed for every form of this scheme
cloud_idx = equation.field_names.index(cloud_name)
vap_idx = equation.field_names.index(vapour_name)
cloud_water = self.X.split()[cloud_idx]
water_vapour = self.X.split()[vap_idx]
cloud_water = self.X.subfunctions[cloud_idx]
water_vapour = self.X.subfunctions[vap_idx]

# Indices of variables in mixed function space
V_idxs = [vap_idx, cloud_idx]
Expand All @@ -119,8 +119,8 @@ def __init__(self, equation, vapour_name='water_vapour',
if isinstance(equation, CompressibleEulerEquations):
rho_idx = equation.field_names.index('rho')
theta_idx = equation.field_names.index('theta')
rho = self.X.split()[rho_idx]
theta = self.X.split()[theta_idx]
rho = self.X.subfunctions[rho_idx]
theta = self.X.subfunctions[theta_idx]
if latent_heat:
V_idxs.append(theta_idx)

Expand All @@ -146,7 +146,7 @@ def __init__(self, equation, vapour_name='water_vapour',
if (active_tracer.phase == Phases.liquid
and active_tracer.chemical == 'H2O' and active_tracer.name != cloud_name):
liq_idx = equation.field_names.index(active_tracer.name)
liquid_water += self.X.split()[liq_idx]
liquid_water += self.X.subfunctions[liq_idx]

# define some parameters as attributes
self.dt = Constant(0.0)
Expand Down Expand Up @@ -280,7 +280,7 @@ def __init__(self, equation, rain_name, domain, transport_method,
self.X = Function(equation.X.function_space())

rain_idx = equation.field_names.index(rain_name)
rain = self.X.split()[rain_idx]
rain = self.X.subfunctions[rain_idx]

Vu = domain.spaces("HDiv")
# TODO: there must be a better way than forcing this into the equation
Expand Down Expand Up @@ -314,7 +314,7 @@ def __init__(self, equation, rain_name, domain, transport_method,
# this advects the third moment M3 of the raindrop
# distribution, which corresponds to the mean mass
rho_idx = equation.field_names.index('rho')
rho = self.X.split()[rho_idx]
rho = self.X.subfunctions[rho_idx]
rho_w = Constant(1000.0) # density of liquid water
# assume n(D) = n_0 * D^mu * exp(-Lambda*D)
# n_0 = N_r * Lambda^(1+mu) / gamma(1 + mu)
Expand Down Expand Up @@ -451,8 +451,8 @@ def evaluate(self, x_in, dt):
"""
# Update the values of internal variables
self.dt.assign(dt)
self.rain.assign(x_in.split()[self.rain_idx])
self.cloud_water.assign(x_in.split()[self.cloud_idx])
self.rain.assign(x_in.subfunctions[self.rain_idx])
self.cloud_water.assign(x_in.subfunctions[self.cloud_idx])
# Evaluate the source
self.source.assign(self.source_interpolator.interpolate())

Expand Down Expand Up @@ -509,8 +509,8 @@ def __init__(self, equation, rain_name='rain', vapour_name='water_vapour',
# Vapour and cloud variables are needed for every form of this scheme
rain_idx = equation.field_names.index(rain_name)
vap_idx = equation.field_names.index(vapour_name)
rain = self.X.split()[rain_idx]
water_vapour = self.X.split()[vap_idx]
rain = self.X.subfunctions[rain_idx]
water_vapour = self.X.subfunctions[vap_idx]

# Indices of variables in mixed function space
V_idxs = [rain_idx, vap_idx]
Expand All @@ -520,8 +520,8 @@ def __init__(self, equation, rain_name='rain', vapour_name='water_vapour',
if isinstance(equation, CompressibleEulerEquations):
rho_idx = equation.field_names.index('rho')
theta_idx = equation.field_names.index('theta')
rho = self.X.split()[rho_idx]
theta = self.X.split()[theta_idx]
rho = self.X.subfunctions[rho_idx]
theta = self.X.subfunctions[theta_idx]
if latent_heat:
V_idxs.append(theta_idx)

Expand All @@ -543,7 +543,7 @@ def __init__(self, equation, rain_name='rain', vapour_name='water_vapour',
if (active_tracer.phase == Phases.liquid
and active_tracer.chemical == 'H2O' and active_tracer.name != rain_name):
liq_idx = equation.field_names.index(active_tracer.name)
liquid_water += self.X.split()[liq_idx]
liquid_water += self.X.subfunctions[liq_idx]

# define some parameters as attributes
self.dt = Constant(0.0)
Expand Down Expand Up @@ -761,10 +761,10 @@ def evaluate(self, x_in, dt):
interval for the scheme.
"""
if self.convective_feedback:
self.D.assign(x_in.split()[self.VD_idx])
self.D.assign(x_in.subfunctions[self.VD_idx])
if self.time_varying_saturation:
self.saturation_curve.interpolate(self.saturation_computation(x_in))
if self.set_tau_to_dt:
self.tau.assign(dt)
self.water_v.assign(x_in.split()[self.Vv_idx])
self.water_v.assign(x_in.subfunctions[self.Vv_idx])
self.source.assign(self.source_interpolator.interpolate())
20 changes: 10 additions & 10 deletions gusto/preconditioners.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ def _reconstruction_calls(self, split_mixed_op, split_trace_op):
K_1 = Tensor(split_trace_op[(0, id1)])

# Split functions and reconstruct each bit separately
split_residual = self.broken_residual.split()
split_sol = self.broken_solution.split()
split_residual = self.broken_residual.subfunctions
split_sol = self.broken_solution.subfunctions
g = AssembledVector(split_residual[id0])
f = AssembledVector(split_residual[id1])
sigma = split_sol[id0]
Expand Down Expand Up @@ -316,8 +316,8 @@ def apply(self, pc, x, y):
# Transfer unbroken_rhs into broken_rhs
# NOTE: Scalar space is already "broken" so no need for
# any projections
unbroken_scalar_data = self.unbroken_residual.split()[self.pidx]
broken_scalar_data = self.broken_residual.split()[self.pidx]
unbroken_scalar_data = self.unbroken_residual.subfunctions[self.pidx]
broken_scalar_data = self.broken_residual.subfunctions[self.pidx]
unbroken_scalar_data.dat.copy(broken_scalar_data.dat)

with timed_region("VertHybridRHS"):
Expand All @@ -328,8 +328,8 @@ def apply(self, pc, x, y):
# basis functions that add together to give unbroken
# basis functions.

unbroken_res_hdiv = self.unbroken_residual.split()[self.vidx]
broken_res_hdiv = self.broken_residual.split()[self.vidx]
unbroken_res_hdiv = self.unbroken_residual.subfunctions[self.vidx]
broken_res_hdiv = self.broken_residual.subfunctions[self.vidx]
broken_res_hdiv.assign(0)
self.average_kernel.apply(broken_res_hdiv, self.weight, unbroken_res_hdiv)

Expand All @@ -351,13 +351,13 @@ def apply(self, pc, x, y):

with timed_region("VertHybridRecover"):
# Project the broken solution into non-broken spaces
broken_pressure = self.broken_solution.split()[self.pidx]
unbroken_pressure = self.unbroken_solution.split()[self.pidx]
broken_pressure = self.broken_solution.subfunctions[self.pidx]
unbroken_pressure = self.unbroken_solution.subfunctions[self.pidx]
broken_pressure.dat.copy(unbroken_pressure.dat)

# Compute the hdiv projection of the broken hdiv solution
broken_hdiv = self.broken_solution.split()[self.vidx]
unbroken_hdiv = self.unbroken_solution.split()[self.vidx]
broken_hdiv = self.broken_solution.subfunctions[self.vidx]
unbroken_hdiv = self.unbroken_solution.subfunctions[self.vidx]
unbroken_hdiv.assign(0)

self.average_kernel.apply(unbroken_hdiv, self.weight, broken_hdiv)
Expand Down
11 changes: 3 additions & 8 deletions gusto/recovery/recovery_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def apply(self, v_out, weighting, v_in):
par_loop(self._kernel, dx,
{"vo": (v_out, INC),
"w": (weighting, READ),
"v": (v_in, READ)},
is_loopy_kernel=True)
"v": (v_in, READ)})


class AverageWeightings(object):
Expand Down Expand Up @@ -103,8 +102,7 @@ def apply(self, w):
lives in the continuous target space.
"""
par_loop(self._kernel, dx,
{"w": (w, INC)},
is_loopy_kernel=True)
{"w": (w, INC)})


class BoundaryRecoveryExtruded():
Expand Down Expand Up @@ -167,7 +165,6 @@ def apply(self, x_out, x_in):
par_loop(self._bot_kernel, dx,
args={"x_out": (x_out, WRITE),
"x_in": (x_in, READ)},
is_loopy_kernel=True,
iteration_region=ON_BOTTOM)


Expand Down Expand Up @@ -240,7 +237,6 @@ def apply(self, x_out, x_in):
par_loop(self._top_kernel, dx,
args={"x_out": (x_out, WRITE),
"x_in": (x_in, READ)},
is_loopy_kernel=True,
iteration_region=ON_TOP)
par_loop(self._bot_kernel, dx,
args={"x_out": (x_out, WRITE),
Expand Down Expand Up @@ -521,5 +517,4 @@ def apply(self, v_DG1_old, v_DG1, act_coords, eff_coords, num_ext):
"DG1": (v_DG1, WRITE),
"ACT_COORDS": (act_coords, READ),
"EFF_COORDS": (eff_coords, READ),
"NUM_EXT": (num_ext, READ)},
is_loopy_kernel=True)
"NUM_EXT": (num_ext, READ)})
2 changes: 1 addition & 1 deletion gusto/timeloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def set_reference_profiles(self, reference_profiles):
assert field_name in self.equation.field_names, \
f'Cannot set reference profile as field {field_name} not found'
idx = self.equation.field_names.index(field_name)
X_ref = self.equation.X_ref.split()[idx]
X_ref = self.equation.X_ref.subfunctions[idx]
X_ref.assign(ref)

self.reference_profiles_initialised = True
Expand Down
6 changes: 3 additions & 3 deletions unit-tests/fml_tests/test_replace_perp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_replace_perp():

# make a function to replace the subject with and give it some values
U1 = Function(W)
u1, _ = U1.split()
u1, _ = U1.subfunctions
x, y = SpatialCoordinate(mesh)
u1.interpolate(as_vector([1, 2]))

Expand All @@ -40,9 +40,9 @@ def test_replace_perp():
U2 = Function(W)
solve(a == L.form, U2)

u2, _ = U2.split()
u2, _ = U2.subfunctions
U3 = Function(W)
u3, _ = U3.split()
u3, _ = U3.subfunctions
u3.interpolate(as_vector([-2, 1]))

assert errornorm(u2, u3) < 1e-14
Loading