Skip to content

Commit

Permalink
Classes for making standard monitor functions (#114)
Browse files Browse the repository at this point in the history
Closes #96.
~~Blocked by #95.~~

---------

Co-authored-by: Davor Dundovic <[email protected]>
  • Loading branch information
jwallwork23 and ddundo authored Jan 14, 2025
1 parent 5281eb5 commit 9250565
Show file tree
Hide file tree
Showing 4 changed files with 602 additions and 67 deletions.
151 changes: 84 additions & 67 deletions demos/monge_ampere_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,16 @@
#
# for some values of the parameters :math:`\alpha`, :math:`\beta`, and :math:`\gamma`.
# Unity is added at the start to ensure that the monitor function doesn't get too
# close to zero.
# close to zero. Here we can think of :math:`\alpha` as relating to the amplitude of the
# monitor function, :math:`\beta` as relating to the width of the ring, and
# :math:`\gamma` as the radius of the ring.
#
# Here we can think of :math:`\alpha` as relating to the amplitude of the monitor
# function, :math:`\beta` as relating to the width of the ring, and :math:`\gamma` as
# the radius of the ring.


def ring_monitor(mesh):
alpha = Constant(20.0)
beta = Constant(200.0)
gamma = Constant(0.15)
x, y = SpatialCoordinate(mesh)
r = (x - 0.5) ** 2 + (y - 0.5) ** 2
return Constant(1.0) + alpha / cosh(beta * (r - gamma)) ** 2
# For convenience, Movement provides a builder class for ring monitors,
# :class:`~movement.monitor.RingMonitorBuilder`, amongst other commonly used
# monitor functions. ::

mb = RingMonitorBuilder(centre=(0.5, 0.5), radius=0.4, amplitude=20.0, width=200.0)
ring_monitor = mb.get_monitor()

# With an initial mesh and a monitor function, we are able to construct a
# :class:`~movement.monge_ampere.MongeAmpereMover` instance and adapt the mesh. By
Expand All @@ -102,60 +97,82 @@ def ring_monitor(mesh):
#
# .. code-block:: none
#
# 0 Volume ratio 11.49 Variation (σ/μ) 9.71e-01 Residual 9.39e-01
# 1 Volume ratio 8.32 Variation (σ/μ) 6.84e-01 Residual 5.35e-01
# 2 Volume ratio 5.74 Variation (σ/μ) 5.55e-01 Residual 3.83e-01
# 3 Volume ratio 6.86 Variation (σ/μ) 4.92e-01 Residual 3.06e-01
# 4 Volume ratio 5.91 Variation (σ/μ) 4.53e-01 Residual 2.69e-01
# 5 Volume ratio 8.38 Variation (σ/μ) 4.20e-01 Residual 2.22e-01
# 6 Volume ratio 7.34 Variation (σ/μ) 4.12e-01 Residual 2.14e-01
# 7 Volume ratio 7.68 Variation (σ/μ) 4.02e-01 Residual 2.03e-01
# 8 Volume ratio 7.93 Variation (σ/μ) 3.84e-01 Residual 1.84e-01
# 9 Volume ratio 7.81 Variation (σ/μ) 3.83e-01 Residual 1.86e-01
# 10 Volume ratio 7.60 Variation (σ/μ) 3.93e-01 Residual 1.97e-01
# 11 Volume ratio 7.99 Variation (σ/μ) 4.14e-01 Residual 2.13e-01
# 12 Volume ratio 8.22 Variation (σ/μ) 4.21e-01 Residual 2.20e-01
# 13 Volume ratio 10.79 Variation (σ/μ) 4.54e-01 Residual 2.13e-01
# 14 Volume ratio 9.66 Variation (σ/μ) 4.15e-01 Residual 1.33e-01
# 15 Volume ratio 10.52 Variation (σ/μ) 3.75e-01 Residual 9.77e-02
# 16 Volume ratio 10.00 Variation (σ/μ) 3.90e-01 Residual 8.64e-02
# 17 Volume ratio 9.00 Variation (σ/μ) 3.61e-01 Residual 6.33e-02
# 18 Volume ratio 9.53 Variation (σ/μ) 3.73e-01 Residual 4.41e-02
# 19 Volume ratio 8.86 Variation (σ/μ) 3.60e-01 Residual 3.71e-02
# 20 Volume ratio 9.38 Variation (σ/μ) 3.65e-01 Residual 2.71e-02
# 21 Volume ratio 8.95 Variation (σ/μ) 3.57e-01 Residual 2.23e-02
# 22 Volume ratio 9.15 Variation (σ/μ) 3.57e-01 Residual 1.32e-02
# 23 Volume ratio 8.90 Variation (σ/μ) 3.52e-01 Residual 8.93e-03
# 24 Volume ratio 8.87 Variation (σ/μ) 3.50e-01 Residual 3.93e-03
# 25 Volume ratio 8.80 Variation (σ/μ) 3.48e-01 Residual 2.61e-03
# 26 Volume ratio 8.85 Variation (σ/μ) 3.49e-01 Residual 1.51e-03
# 27 Volume ratio 8.83 Variation (σ/μ) 3.48e-01 Residual 1.15e-03
# 28 Volume ratio 8.85 Variation (σ/μ) 3.48e-01 Residual 7.98e-04
# 29 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 6.27e-04
# 30 Volume ratio 8.85 Variation (σ/μ) 3.48e-01 Residual 4.46e-04
# 31 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 3.46e-04
# 32 Volume ratio 8.85 Variation (σ/μ) 3.48e-01 Residual 2.39e-04
# 33 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 1.77e-04
# 34 Volume ratio 8.85 Variation (σ/μ) 3.48e-01 Residual 1.14e-04
# 35 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 7.82e-05
# 36 Volume ratio 8.85 Variation (σ/μ) 3.48e-01 Residual 4.69e-05
# 37 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 2.96e-05
# 38 Volume ratio 8.85 Variation (σ/μ) 3.48e-01 Residual 1.77e-05
# 39 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 1.11e-05
# 40 Volume ratio 8.85 Variation (σ/μ) 3.48e-01 Residual 7.43e-06
# 41 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 5.07e-06
# 42 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 3.86e-06
# 43 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 2.85e-06
# 44 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 2.30e-06
# 45 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 1.72e-06
# 46 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 1.38e-06
# 47 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 9.75e-07
# 48 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 7.42e-07
# 49 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 4.50e-07
# 50 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 3.00e-07
# 51 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 1.42e-07
# 52 Volume ratio 8.84 Variation (σ/μ) 3.48e-01 Residual 7.93e-08
# Solver converged in 52 iterations.
# 0 Volume ratio 12.91 Variation (σ/μ) 1.21e+00 Residual 1.16e+00
# 1 Volume ratio 6.77 Variation (σ/μ) 6.15e-01 Residual 4.85e-01
# 2 Volume ratio 5.84 Variation (σ/μ) 5.69e-01 Residual 4.26e-01
# 3 Volume ratio 6.34 Variation (σ/μ) 5.14e-01 Residual 3.74e-01
# 4 Volume ratio 6.38 Variation (σ/μ) 4.88e-01 Residual 3.22e-01
# 5 Volume ratio 12.05 Variation (σ/μ) 4.55e-01 Residual 2.57e-01
# 6 Volume ratio 11.69 Variation (σ/μ) 4.26e-01 Residual 2.30e-01
# 7 Volume ratio 11.98 Variation (σ/μ) 4.23e-01 Residual 1.98e-01
# 8 Volume ratio 11.81 Variation (σ/μ) 4.17e-01 Residual 1.95e-01
# 9 Volume ratio 12.00 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 10 Volume ratio 12.07 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 11 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 12 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 13 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 14 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 15 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 16 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 17 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 18 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 19 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 20 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 21 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 22 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 23 Volume ratio 12.09 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 24 Volume ratio 12.10 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 25 Volume ratio 12.18 Variation (σ/μ) 4.16e-01 Residual 1.94e-01
# 26 Volume ratio 12.38 Variation (σ/μ) 4.16e-01 Residual 1.93e-01
# 27 Volume ratio 12.43 Variation (σ/μ) 4.16e-01 Residual 1.93e-01
# 28 Volume ratio 12.44 Variation (σ/μ) 4.16e-01 Residual 1.93e-01
# 29 Volume ratio 12.44 Variation (σ/μ) 4.16e-01 Residual 1.93e-01
# 30 Volume ratio 12.44 Variation (σ/μ) 4.16e-01 Residual 1.93e-01
# 31 Volume ratio 12.44 Variation (σ/μ) 4.16e-01 Residual 1.93e-01
# 32 Volume ratio 12.44 Variation (σ/μ) 4.16e-01 Residual 1.93e-01
# 33 Volume ratio 12.44 Variation (σ/μ) 4.16e-01 Residual 1.93e-01
# 34 Volume ratio 12.44 Variation (σ/μ) 4.16e-01 Residual 1.93e-01
# 35 Volume ratio 13.34 Variation (σ/μ) 4.18e-01 Residual 1.94e-01
# 36 Volume ratio 15.21 Variation (σ/μ) 4.38e-01 Residual 2.09e-01
# 37 Volume ratio 17.20 Variation (σ/μ) 4.76e-01 Residual 2.22e-01
# 38 Volume ratio 11.89 Variation (σ/μ) 4.30e-01 Residual 1.45e-01
# 39 Volume ratio 12.41 Variation (σ/μ) 4.13e-01 Residual 1.01e-01
# 40 Volume ratio 8.76 Variation (σ/μ) 3.79e-01 Residual 7.36e-02
# 41 Volume ratio 10.00 Variation (σ/μ) 3.85e-01 Residual 6.36e-02
# 42 Volume ratio 8.57 Variation (σ/μ) 3.65e-01 Residual 5.17e-02
# 43 Volume ratio 9.48 Variation (σ/μ) 3.72e-01 Residual 4.17e-02
# 44 Volume ratio 8.70 Variation (σ/μ) 3.60e-01 Residual 3.51e-02
# 45 Volume ratio 9.31 Variation (σ/μ) 3.64e-01 Residual 2.69e-02
# 46 Volume ratio 8.82 Variation (σ/μ) 3.57e-01 Residual 2.23e-02
# 47 Volume ratio 9.20 Variation (σ/μ) 3.58e-01 Residual 1.44e-02
# 48 Volume ratio 8.95 Variation (σ/μ) 3.53e-01 Residual 1.03e-02
# 49 Volume ratio 9.08 Variation (σ/μ) 3.52e-01 Residual 4.91e-03
# 50 Volume ratio 9.05 Variation (σ/μ) 3.50e-01 Residual 3.98e-03
# 51 Volume ratio 9.13 Variation (σ/μ) 3.51e-01 Residual 2.81e-03
# 52 Volume ratio 9.11 Variation (σ/μ) 3.50e-01 Residual 2.28e-03
# 53 Volume ratio 9.17 Variation (σ/μ) 3.50e-01 Residual 1.51e-03
# 54 Volume ratio 9.15 Variation (σ/μ) 3.50e-01 Residual 1.11e-03
# 55 Volume ratio 9.19 Variation (σ/μ) 3.50e-01 Residual 5.28e-04
# 56 Volume ratio 9.18 Variation (σ/μ) 3.49e-01 Residual 2.89e-04
# 57 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 1.04e-04
# 58 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 7.69e-05
# 59 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 5.31e-05
# 60 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 3.80e-05
# 61 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 2.66e-05
# 62 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 1.87e-05
# 63 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 1.36e-05
# 64 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 9.55e-06
# 65 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 7.22e-06
# 66 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 5.04e-06
# 67 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 3.88e-06
# 68 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 2.50e-06
# 69 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 1.87e-06
# 70 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 9.04e-07
# 71 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 6.32e-07
# 72 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 2.67e-07
# 73 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 1.55e-07
# 74 Volume ratio 9.19 Variation (σ/μ) 3.49e-01 Residual 8.22e-08
# Solver converged in 74 iterations.
#
# The adapted mesh can be accessed via the `mesh` attribute of the mover. Plotting it,
# we see that the adapted mesh has its resolution focused around a ring, as expected.
Expand Down
1 change: 1 addition & 0 deletions movement/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from movement.monitor import * # noqa
from movement.tangling import * # noqa

from movement.laplacian_smoothing import * # noqa
Expand Down
Loading

0 comments on commit 9250565

Please sign in to comment.