Skip to content

Commit

Permalink
updated .split() to .subfunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
acse-ej321 authored and stephankramer committed Dec 15, 2023
1 parent a51d859 commit 7d5dbbe
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 71 deletions.
86 changes: 43 additions & 43 deletions demos/01-2d-channel.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/swe2d/test_anisotropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ def estimate_error(mesh, **model_options):

# Plot
if not model_options.get("no_exports", False):
File("outputs/forward.pvd").write(*f0.split())
a0u, a0eta = a0.split()
File("outputs/forward.pvd").write(*f0.subfunctions)
a0u, a0eta = a0.subfunctions
a0u.rename("uv_2d (adjoint)")
a0eta.rename("elev_2d (adjoint)")
File("outputs/adjoint.pvd").write(a0u, a0eta)
Expand Down
2 changes: 1 addition & 1 deletion test/swe2d/test_atmospheric_pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_pressure_forcing(element_family, timestepper):
solverObj.assign_initial_conditions(uv=Constant((1e-7, 0.)))
solverObj.iterate()

uv, eta = solverObj.fields.solution_2d.split()
uv, eta = solverObj.fields.solution_2d.subfunctions
eta_ana = project(eta_expr, solverObj.function_spaces.H_2d)
eta_errs.append(errornorm(eta_ana, eta)/numpy.sqrt(area))

Expand Down
2 changes: 1 addition & 1 deletion test/swe2d/test_standing_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_standing_wave_channel(timesteps, max_rel_err, timestepper, tmpdir, do_e

solver_obj.iterate()

uv, eta = solver_obj.fields.solution_2d.split()
uv, eta = solver_obj.fields.solution_2d.subfunctions

area = lx*ly
rel_err = errornorm(elev_init, eta)/math.sqrt(area)
Expand Down
4 changes: 2 additions & 2 deletions test/swe2d/test_steady_state_basin_mms.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ def run(setup, refinement, order, do_export=True, options=None,

solver_obj.iterate()

elev_l2_err = errornorm(elev_ana_ho, solver_obj.fields.solution_2d.split()[1])/numpy.sqrt(area)
uv_l2_err = errornorm(uv_ana_ho, solver_obj.fields.solution_2d.split()[0])/numpy.sqrt(area)
elev_l2_err = errornorm(elev_ana_ho, solver_obj.fields.solution_2d.subfunctions[1])/numpy.sqrt(area)
uv_l2_err = errornorm(uv_ana_ho, solver_obj.fields.solution_2d.subfunctions[0])/numpy.sqrt(area)
print_output('elev L2 error {:.12f}'.format(elev_l2_err))
print_output('uv L2 error {:.12f}'.format(uv_l2_err))
return elev_l2_err, uv_l2_err
Expand Down
2 changes: 1 addition & 1 deletion test/swe2d/test_steady_state_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_steady_state_channel(do_export=False):

solver_obj.iterate()

uv, eta = solver_obj.fields.solution_2d.split()
uv, eta = solver_obj.fields.solution_2d.subfunctions

x_2d, y_2d = SpatialCoordinate(mesh2d)
eta_ana = interpolate(1 - x_2d/lx, p1_2d)
Expand Down
2 changes: 1 addition & 1 deletion test/swe2d/test_steady_state_channel_mms.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_steady_state_channel_mms(element_family, do_exports=False):
File('source_{}.pvd'.format(i)).write(source_func)
solver_obj.iterate()

uv, eta = solver_obj.fields.solution_2d.split()
uv, eta = solver_obj.fields.solution_2d.subfunctions

eta_ana = project(eta_expr, solver_obj.function_spaces.H_2d)
if do_exports:
Expand Down
2 changes: 1 addition & 1 deletion test/swe2d/test_thacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_thacker(stepper, n, dt, max_err):

# run for one cycle
solverObj.iterate()
uv, eta = solverObj.fields.solution_2d.split()
uv, eta = solverObj.fields.solution_2d.subfunctions

# mask out dry areas with a smooth function
r = sqrt((x-X0)**2 + (y-Y0)**2)
Expand Down
4 changes: 2 additions & 2 deletions test/time_integration/test_convergence_ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SimpleODEEquation(Equation):
"""
def __init__(self, function_space, alpha, mode='explicit'):
super(SimpleODEEquation, self).__init__(function_space)
self.a_space, self.b_space = function_space.split()
self.a_space, self.b_space = function_space.subfunctions
self.a_test, self.b_test = TestFunctions(function_space)
self.alpha = alpha
if mode == 'imex':
Expand Down Expand Up @@ -134,7 +134,7 @@ def run(timeintegrator_class, timeintegrator_options, refinement=1):
ti = timeintegrator_class(equation, solution, fields, dt, timeintegrator_options(), {})
ti.initialize(solution)
simulation_time = 0
sol_a, sol_b = solution.split()
sol_a, sol_b = solution.subfunctions
values[0, :] = sol_a.dat.data[0], sol_b.dat.data[0]
for i in range(ntimesteps):
simulation_time = (i+1)*dt
Expand Down
2 changes: 1 addition & 1 deletion thetis/assembledschur.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(self, pc):

test, trial = a.arguments()
W = test.function_space()
V, Q = W.split()
V, Q = W.subfunctions
v = TestFunction(V)
u = TrialFunction(V)
mass = dot(v, u)*dx
Expand Down
2 changes: 1 addition & 1 deletion thetis/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self, field_2d, hessian_2d, gradient_2d=None, **kwargs):
g, H = TrialFunctions(W)
phi, tau = TestFunctions(W)
sol = Function(W)
self._gradient, self._hessian = sol.split()
self._gradient, self._hessian = sol.subfunctions

# The formulation is chosen such that f does not need to have any
# finite element derivatives
Expand Down
2 changes: 1 addition & 1 deletion thetis/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ def add_tracer_system_2d(self, labels, names, filenames, shortnames=None, units=
kwargs[label]['mixed'] = True
self.tracer_fields[','.join(labels)] = function
if function is not None:
for label, child in zip(labels, function.split()):
for label, child in zip(labels, function.subfunctions):
kwargs[label]['function'] = child
for label, name, filename, shortname, unit in zip(labels, names, filenames, shortnames, units):
self.add_tracer_2d(label, name, filename, shortname=shortname, unit=unit, **kwargs[label])
Expand Down
4 changes: 2 additions & 2 deletions thetis/shallowwater_eq.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ def __init__(self, function_space, depth, options, tidal_farms=None):
super(ShallowWaterEquations, self).__init__(function_space, depth, options)

u_test, eta_test = TestFunctions(function_space)
u_space, eta_space = function_space.split()
u_space, eta_space = function_space.subfunctions

self.add_momentum_terms(u_test, u_space, eta_space, depth, options, tidal_farms=tidal_farms)

Expand Down Expand Up @@ -945,7 +945,7 @@ def __init__(self, function_space, depth, options):
super(ModeSplit2DEquations, self).__init__(function_space, depth, options)

u_test, eta_test = TestFunctions(function_space)
u_space, eta_space = function_space.split()
u_space, eta_space = function_space.subfunctions

self.add_momentum_terms(u_test, u_space, eta_space, depth, options)

Expand Down
2 changes: 1 addition & 1 deletion thetis/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def create_fields(self):
# ----- fields
self.fields.solution_2d = Function(self.function_spaces.V_2d)
# correct treatment of the split 2d functions
uv_2d, eta2d = self.fields.solution_2d.split()
uv_2d, eta2d = self.fields.solution_2d.subfunctions
self.fields.uv_2d = uv_2d
self.fields.elev_2d = eta2d
# elevation field seen by the 3D mode, different from elev_2d
Expand Down
18 changes: 9 additions & 9 deletions thetis/solver2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def create_fields(self):

# Add fields for shallow water modelling
self.fields.solution_2d = Function(self.function_spaces.V_2d, name='solution_2d')
uv_2d, elev_2d = self.fields.solution_2d.split() # correct treatment of the split 2d functions
uv_2d, elev_2d = self.fields.solution_2d.subfunctions # correct treatment of the split 2d functions
self.fields.uv_2d = uv_2d
self.fields.elev_2d = elev_2d

Expand All @@ -424,7 +424,7 @@ def create_fields(self):
if num_labels > 1:
self.fields[system] = parent
self.options.tracer_fields[system] = parent
children = [parent] if num_labels == 1 else parent.split()
children = [parent] if num_labels == 1 else parent.subfunctions
for label, function in zip(labels, children):
tracer = self.options.tracer[label]
function.rename(label)
Expand Down Expand Up @@ -480,7 +480,7 @@ def create_equations(self):
tidal_farms=self.tidal_farms
)
self.equations.sw.bnd_functions = self.bnd_functions['shallow_water']
uv_2d, elev_2d = self.fields.solution_2d.split()
uv_2d, elev_2d = self.fields.solution_2d.subfunctions

# Passive tracer equations
for system, parent in self.options.tracer_fields.items():
Expand Down Expand Up @@ -566,7 +566,7 @@ def get_tracer_timestepper(self, integrator, system):
"""
Gets tracer timestepper object with appropriate parameters
"""
uv, elev = self.fields.solution_2d.split()
uv, elev = self.fields.solution_2d.subfunctions
fields = {
'elev_2d': elev,
'uv_2d': uv,
Expand All @@ -591,7 +591,7 @@ def get_sediment_timestepper(self, integrator):
"""
Gets sediment timestepper object with appropriate parameters
"""
uv, elev = self.fields.solution_2d.split()
uv, elev = self.fields.solution_2d.subfunctions
fields = {
'elev_2d': elev,
'uv_2d': uv,
Expand All @@ -608,7 +608,7 @@ def get_exner_timestepper(self, integrator):
"""
Gets exner timestepper object with appropriate parameters
"""
uv, elev = self.fields.solution_2d.split()
uv, elev = self.fields.solution_2d.subfunctions
if not self.options.sediment_model_options.solve_suspended_sediment:
self.fields.sediment_2d = Function(elev.function_space()).interpolate(Constant(0.0))
fields = {
Expand Down Expand Up @@ -746,7 +746,7 @@ def assign_initial_conditions(self, elev=None, uv=None, sediment=None, **tracers
"""
if not self._initialized:
self.initialize()
uv_2d, elev_2d = self.fields.solution_2d.split()
uv_2d, elev_2d = self.fields.solution_2d.subfunctions
if elev is not None:
elev_2d.project(elev)
if uv is not None:
Expand Down Expand Up @@ -912,8 +912,8 @@ def print_state(self, cputime, print_header=False):
e = (label, norm_q, '10.4f')
entries.append(e)
else:
norm_h = norm(self.fields.solution_2d.split()[1])
norm_u = norm(self.fields.solution_2d.split()[0])
norm_h = norm(self.fields.solution_2d.subfunctions[1])
norm_u = norm(self.fields.solution_2d.subfunctions[0])
entries += [
('eta norm', norm_h, '14.4f'),
('u norm', norm_u, '14.4f'),
Expand Down
4 changes: 2 additions & 2 deletions thetis/timeintegrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ def __init__(self, equation, equation_mom, solution, fields, dt, options, bnd_co
self.solution_lagged = Function(self.equation.function_space)
else:
self.solution_lagged = self.solution_old
uv_lagged, eta_lagged = self.solution_lagged.split()
uv_old, eta_old = self.solution_old.split()
uv_lagged, eta_lagged = self.solution_lagged.subfunctions
uv_old, eta_old = self.solution_old.subfunctions

if (solver_parameters['ksp_type'] == 'preonly'
and 'fieldsplit_H_2d' in solver_parameters
Expand Down

0 comments on commit 7d5dbbe

Please sign in to comment.