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

VTK API update #131

Merged
merged 1 commit into from
Mar 7, 2024
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
4 changes: 2 additions & 2 deletions demos/gray_scott.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def qoi():
if not test:
ic = mesh_seq.get_initial_condition()
for field, sols in solutions.items():
fwd_outfile = File(f"gray_scott/{field}_forward.pvd")
adj_outfile = File(f"gray_scott/{field}_adjoint.pvd")
fwd_outfile = VTKFile(f"gray_scott/{field}_forward.pvd")
adj_outfile = VTKFile(f"gray_scott/{field}_adjoint.pvd")
fwd_outfile.write(*ic[field].subfunctions)
for i, mesh in enumerate(mesh_seq):
for sol in sols["forward"][i]:
Expand Down
4 changes: 2 additions & 2 deletions demos/gray_scott_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def qoi():
if not test:
ic = mesh_seq.get_initial_condition()
for field, sols in solutions.items():
fwd_outfile = File(f"gray_scott_split/{field}_forward.pvd")
adj_outfile = File(f"gray_scott_split/{field}_adjoint.pvd")
fwd_outfile = VTKFile(f"gray_scott_split/{field}_forward.pvd")
adj_outfile = VTKFile(f"gray_scott_split/{field}_adjoint.pvd")
fwd_outfile.write(ic[field])
for i, mesh in enumerate(mesh_seq):
for sol in sols["forward"][i]:
Expand Down
4 changes: 2 additions & 2 deletions demos/solid_body_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ def qoi():

if not test:
for field, sols in solutions.items():
fwd_outfile = File(f"solid_body_rotation/{field}_forward.pvd")
adj_outfile = File(f"solid_body_rotation/{field}_adjoint.pvd")
fwd_outfile = VTKFile(f"solid_body_rotation/{field}_forward.pvd")
adj_outfile = VTKFile(f"solid_body_rotation/{field}_adjoint.pvd")
for i, mesh in enumerate(mesh_seq):
for sol in sols["forward"][i]:
fwd_outfile.write(sol)
Expand Down
4 changes: 2 additions & 2 deletions demos/solid_body_rotation_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def get_qoi_split(mesh_seq, sols, index):

if not test:
for field, sols in solutions.items():
fwd_outfile = File(f"solid_body_rotation_split/{field}_forward.pvd")
adj_outfile = File(f"solid_body_rotation_split/{field}_adjoint.pvd")
fwd_outfile = VTKFile(f"solid_body_rotation_split/{field}_forward.pvd")
adj_outfile = VTKFile(f"solid_body_rotation_split/{field}_adjoint.pvd")
for i, mesh in enumerate(mesh_seq):
for sol in sols["forward"][i]:
fwd_outfile.write(sol)
Expand Down
10 changes: 4 additions & 6 deletions goalie/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ def Mesh(arg, **kwargs) -> firedrake.mesh.MeshGeometry:
return mesh


class File(firedrake.output.File):
class VTKFile(firedrake.output.VTKFile):
"""
Overload :class:`firedrake.output.File` so that
it uses ``adaptive`` mode by default. Whilst
this means that the mesh topology is
recomputed at every export, it removes any
need for the user to reset it manually.
Overload :class:`firedrake.output.VTKFile` so that it uses ``adaptive`` mode by
default. Whilst this means that the mesh topology is recomputed at every export, it
removes any need for the user to reset it manually.
"""

def __init__(self, *args, **kwargs):
Expand Down
10 changes: 5 additions & 5 deletions test/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
# ---------------------------


class TestPVD(unittest.TestCase):
class TestVTK(unittest.TestCase):
"""
Test the subclass of Firedrake's :class:`File`.
Test the subclass of Firedrake's :class:`VTKFile`.
"""

def setUp(self):
Expand All @@ -41,22 +41,22 @@ def tearDown(self):
os.remove(fname + ext)

def test_adaptive(self):
file = File(self.fname)
file = VTKFile(self.fname)
self.assertTrue(os.path.exists(self.fname))
self.assertTrue(file._adaptive)

def test_different_fnames(self):
f = Function(self.fs, name="f")
g = Function(self.fs, name="g")
file = File(self.fname)
file = VTKFile(self.fname)
file.write(f)
file.write(g)
self.assertEqual("f", g.name())

def test_different_lengths(self):
f = Function(self.fs, name="f")
g = Function(self.fs, name="g")
file = File(self.fname)
file = VTKFile(self.fname)
file.write(f)
with self.assertRaises(ValueError) as cm:
file.write(f, g)
Expand Down
10 changes: 5 additions & 5 deletions test_adjoint/test_adjoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ def plot_solutions(problem, qoi_type, debug=True):
output_dir = os.path.join(os.path.dirname(__file__), "outputs", problem)
outfiles = AttrDict(
{
"forward": File(os.path.join(output_dir, "forward.pvd")),
"forward_old": File(os.path.join(output_dir, "forward_old.pvd")),
"adjoint": File(os.path.join(output_dir, "adjoint.pvd")),
"forward": VTKFile(os.path.join(output_dir, "forward.pvd")),
"forward_old": VTKFile(os.path.join(output_dir, "forward_old.pvd")),
"adjoint": VTKFile(os.path.join(output_dir, "adjoint.pvd")),
}
)
if not steady:
outfiles.adjoint_next = File(os.path.join(output_dir, "adjoint_next.pvd"))
outfiles.adj_value = File(os.path.join(output_dir, "adj_value.pvd"))
outfiles.adjoint_next = VTKFile(os.path.join(output_dir, "adjoint_next.pvd"))
outfiles.adj_value = VTKFile(os.path.join(output_dir, "adj_value.pvd"))
for label in outfiles:
for k in range(time_partition.num_exports_per_subinterval[0] - 1):
to_plot = []
Expand Down
Loading