Skip to content

Commit 08a46ed

Browse files
authored
adapt for MeshSequence (#655)
1 parent 703ccf1 commit 08a46ed

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

gusto/core/io.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,38 @@ def setup_dump(self, state_fields, t, pick_up=False):
473473
self.to_dump_latlon = []
474474
for name in self.output.dumplist_latlon:
475475
f = state_fields(name)
476-
field = Function(
477-
functionspaceimpl.WithGeometry.create(
478-
f.function_space(), mesh_ll),
479-
val=f.topological, name=name+'_ll')
476+
V = f.function_space()
477+
try: # firedrake main
478+
from firedrake import MeshSequenceGeometry
479+
480+
if V.parent and isinstance(V.parent.topological, functionspaceimpl.MixedFunctionSpace):
481+
if not isinstance(V.parent.mesh(), MeshSequenceGeometry):
482+
raise ValueError("Expecting a MeshSequenceGeometry")
483+
if len(set(V.parent.mesh().meshes)) > 1:
484+
raise ValueError("Expecting a single mesh")
485+
parent = functionspaceimpl.WithGeometry.create(
486+
V.parent.topological,
487+
MeshSequenceGeometry(
488+
tuple(mesh_ll for _ in V.parent.mesh().meshes),
489+
),
490+
)
491+
else:
492+
parent = None
493+
field = Function(
494+
functionspaceimpl.WithGeometry.create(
495+
V.topological, mesh_ll, parent=parent,
496+
),
497+
val=f.topological,
498+
name=name+'_ll',
499+
)
500+
except ImportError: # firedrake release
501+
field = Function(
502+
functionspaceimpl.WithGeometry.create(
503+
V.topological, mesh_ll,
504+
),
505+
val=f.topological,
506+
name=name+'_ll',
507+
)
480508
self.to_dump_latlon.append(field)
481509

482510
# we create new netcdf files to write to, unless pick_up=True and they

gusto/solvers/preconditioners.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def initialize(self, pc):
6666

6767
V = test.function_space()
6868
mesh = V.mesh()
69+
try:
70+
from firedrake import MeshSequenceGeometry # noqa: F401
71+
72+
unique_mesh = mesh.unique()
73+
except ImportError:
74+
unique_mesh = mesh
6975

7076
# Magically determine which spaces are vector and scalar valued
7177
for i, Vi in enumerate(V):
@@ -96,7 +102,7 @@ def initialize(self, pc):
96102
DG = FiniteElement("DG", cell, deg)
97103
CG = FiniteElement("CG", interval, 1)
98104
Vv_tr_element = TensorProductElement(DG, CG)
99-
Vv_tr = FunctionSpace(mesh, Vv_tr_element)
105+
Vv_tr = FunctionSpace(unique_mesh, Vv_tr_element)
100106

101107
# Break the spaces
102108
broken_elements = MixedElement([BrokenElement(Vi.ufl_element()) for Vi in V])
@@ -121,7 +127,7 @@ def initialize(self, pc):
121127
trial: TrialFunction(V_d)}
122128
Atilde = Tensor(replace(self.ctx.a, arg_map))
123129
gammar = TestFunction(Vv_tr)
124-
n = FacetNormal(mesh)
130+
n = FacetNormal(unique_mesh)
125131
sigma = TrialFunctions(V_d)[self.vidx]
126132

127133
# Again, assumes tensor product structure. Why use this if you
@@ -157,7 +163,7 @@ def initialize(self, pc):
157163
trace_subdomains.extend(sorted({"top", "bottom"} - extruded_neumann_subdomains))
158164

159165
measures.extend((ds(sd) for sd in sorted(neumann_subdomains)))
160-
markers = [int(x) for x in mesh.exterior_facets.unique_markers]
166+
markers = [int(x) for x in unique_mesh.exterior_facets.unique_markers]
161167
dirichlet_subdomains = set(markers) - neumann_subdomains
162168
trace_subdomains.extend(sorted(dirichlet_subdomains))
163169

0 commit comments

Comments
 (0)