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

Classes for making standard monitor functions #114

Merged
merged 22 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
23 changes: 10 additions & 13 deletions demos/monge_ampere1.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#
# We begin the example by importing from the namespaces of Firedrake and Movement. ::

import numpy as np
from firedrake import *

from movement import *
Expand Down Expand Up @@ -73,21 +74,17 @@
#
# 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, amongst other
# commonly used monitor functions. ::
jwallwork23 marked this conversation as resolved.
Show resolved Hide resolved

mb = RingMonitorBuilder(
centre=(0.5, 0.5), radius=np.sqrt(0.15), amplitude=20.0, width=200.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling that using radius=np.sqrt(0.15) might be confusing and lead people to think they need to input the sqrt of the radius. Why not just input e.g. radius=0.4?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9cda85f.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! But the optimisation callback should be updated too. It looks like this now:

   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.09   Variation (σ/μ) 4.16e-01   Residual 1.94e-01
  25   Volume ratio 12.09   Variation (σ/μ) 4.16e-01   Residual 1.94e-01
  26   Volume ratio 12.10   Variation (σ/μ) 4.16e-01   Residual 1.94e-01
  27   Volume ratio 12.18   Variation (σ/μ) 4.16e-01   Residual 1.94e-01
  28   Volume ratio 12.38   Variation (σ/μ) 4.16e-01   Residual 1.93e-01
  29   Volume ratio 12.43   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 12.44   Variation (σ/μ) 4.16e-01   Residual 1.93e-01
  36   Volume ratio 12.44   Variation (σ/μ) 4.16e-01   Residual 1.93e-01
  37   Volume ratio 13.34   Variation (σ/μ) 4.18e-01   Residual 1.94e-01
  38   Volume ratio 15.21   Variation (σ/μ) 4.38e-01   Residual 2.09e-01
  39   Volume ratio 17.20   Variation (σ/μ) 4.76e-01   Residual 2.22e-01
  40   Volume ratio 11.89   Variation (σ/μ) 4.30e-01   Residual 1.45e-01
  41   Volume ratio 12.41   Variation (σ/μ) 4.13e-01   Residual 1.01e-01
  42   Volume ratio  8.76   Variation (σ/μ) 3.79e-01   Residual 7.36e-02
  43   Volume ratio 10.00   Variation (σ/μ) 3.85e-01   Residual 6.36e-02
  44   Volume ratio  8.57   Variation (σ/μ) 3.65e-01   Residual 5.17e-02
  45   Volume ratio  9.48   Variation (σ/μ) 3.72e-01   Residual 4.17e-02
  46   Volume ratio  8.70   Variation (σ/μ) 3.60e-01   Residual 3.51e-02
  47   Volume ratio  9.31   Variation (σ/μ) 3.64e-01   Residual 2.69e-02
  48   Volume ratio  8.82   Variation (σ/μ) 3.57e-01   Residual 2.23e-02
  49   Volume ratio  9.20   Variation (σ/μ) 3.58e-01   Residual 1.44e-02
  50   Volume ratio  8.95   Variation (σ/μ) 3.53e-01   Residual 1.03e-02
  51   Volume ratio  9.08   Variation (σ/μ) 3.52e-01   Residual 4.91e-03
  52   Volume ratio  9.05   Variation (σ/μ) 3.50e-01   Residual 3.98e-03
  53   Volume ratio  9.13   Variation (σ/μ) 3.51e-01   Residual 2.81e-03
  54   Volume ratio  9.11   Variation (σ/μ) 3.50e-01   Residual 2.28e-03
  55   Volume ratio  9.17   Variation (σ/μ) 3.50e-01   Residual 1.51e-03
  56   Volume ratio  9.15   Variation (σ/μ) 3.50e-01   Residual 1.11e-03
  57   Volume ratio  9.19   Variation (σ/μ) 3.50e-01   Residual 5.28e-04
  58   Volume ratio  9.18   Variation (σ/μ) 3.49e-01   Residual 2.89e-04
  59   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 1.04e-04
  60   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 7.69e-05
  61   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 5.31e-05
  62   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 3.80e-05
  63   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 2.66e-05
  64   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 1.87e-05
  65   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 1.36e-05
  66   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 9.55e-06
  67   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 7.22e-06
  68   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 5.04e-06
  69   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 3.88e-06
  70   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 2.50e-06
  71   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 1.87e-06
  72   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 9.04e-07
  73   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 6.32e-07
  74   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 2.67e-07
  75   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 1.55e-07
  76   Volume ratio  9.19   Variation (σ/μ) 3.49e-01   Residual 8.22e-08
Solver converged in 76 iterations.

Quite a few more iterations (up from 52 with np.sqrt(0.15) since it gets stuck a bit as you can see.

This also made me wonder - where did the solver parameters in movement.solver_parameters come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a few more iterations (up from 52 with np.sqrt(0.15) since it gets stuck a bit as you can see.

Updated in a6636e0 using output from my machine. I imagine it's due to how the initial mesh is lined up, but would need to investigate in more detail. Opened a new issue: #148.

This also made me wonder - where did the solver parameters in movement.solver_parameters come from?

The ones for MA are based on the ones in Andrew McRae's 2018 paper.

)
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 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
Loading