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

Fix PETSc errors in CI #152

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions movement/monge_ampere.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import firedrake.exceptions as fexc
import numpy as np
import ufl
from animate.utility import function2cofunction
from firedrake.petsc import PETSc
from pyadjoint import no_annotations

Expand Down Expand Up @@ -503,7 +504,7 @@ def move(self):
# Update monitor function
self.to_physical_coordinates()
self.monitor.interpolate(self.monitor_function(self.mesh))
firedrake.assemble(self.L_P0, tensor=self.volume)
firedrake.assemble(self.L_P0, tensor=function2cofunction(self.volume))
self.volume.interpolate(self.volume / self.original_volume)
self.to_computational_coordinates()

Expand Down Expand Up @@ -576,6 +577,10 @@ def __init__(self, mesh, monitor_function, phi_init=None, H_init=None, **kwargs)
:kwarg dtol: divergence tolerance for the residual
:type dtol: :class:`float`
"""
if mesh.topological_dimension() == 1:
raise NotImplementedError(
"1D case not implemented for quasi-Newton method."
)
super().__init__(mesh, monitor_function=monitor_function, **kwargs)

# Initialise phi and H
Expand Down Expand Up @@ -703,7 +708,7 @@ def callback(snes, i, rnorm):
cursol = snes.getSolution()
update_monitor(cursol)
self.to_physical_coordinates()
firedrake.assemble(self.L_P0, tensor=self.volume)
firedrake.assemble(self.L_P0, tensor=function2cofunction(self.volume))
self.volume.interpolate(self.volume / self.original_volume)
self.to_computational_coordinates()
PETSc.Sys.Print(
Expand Down
14 changes: 7 additions & 7 deletions test/test_monge_ampere.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def test_no_monitor_valueerror(self):
MongeAmpereMover(self.dummy_mesh, None)
self.assertEqual(str(cm.exception), "Please supply a monitor function.")

def test_1d_quasi_newton_valueerror(self):
mesh = self.mesh(dim=1)
with self.assertRaises(NotImplementedError) as cm:
MongeAmpereMover(mesh, self.dummy_monitor, method="quasi_newton")
msg = "1D case not implemented for quasi-Newton method."
self.assertEqual(str(cm.exception), msg)

@parameterized.expand([("relaxation"), ("quasi_newton")])
def test_maxiter_convergenceerror(self, method):
"""
Expand Down Expand Up @@ -167,7 +174,6 @@ class TestMonitor(BaseClasses.TestMongeAmpere):
@parameterized.expand(
[
(1, "relaxation"),
(1, "quasi_newton"),
(2, "relaxation"),
(2, "quasi_newton"),
(3, "relaxation"),
Expand Down Expand Up @@ -281,7 +287,6 @@ def _test_boundary_preservation(self, mesh, method, fixed_boundaries):
@parameterized.expand(
[
(1, "relaxation"),
(1, "quasi_newton"),
(2, "relaxation"),
(2, "quasi_newton"),
(3, "relaxation"),
Expand Down Expand Up @@ -317,9 +322,6 @@ def test_initial_guess_valueerror(self):
(1, "relaxation", "on_boundary"),
(1, "relaxation", [1]),
(1, "relaxation", []),
(1, "quasi_newton", "on_boundary"),
(1, "quasi_newton", [1]),
(1, "quasi_newton", []),
(2, "relaxation", "on_boundary"),
(2, "relaxation", [1]),
(2, "relaxation", []),
Expand Down Expand Up @@ -443,7 +445,6 @@ class TestMisc(BaseClasses.TestMongeAmpere):
@parameterized.expand(
[
(1, "relaxation"),
(1, "quasi_newton"),
(2, "relaxation"),
(2, "quasi_newton"),
(3, "relaxation"),
Expand Down Expand Up @@ -478,7 +479,6 @@ def test_continue(self, dim, method):
@parameterized.expand(
[
(1, "relaxation"),
(1, "quasi_newton"),
(2, "relaxation"),
(2, "quasi_newton"),
(3, "relaxation"),
Expand Down