You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: demos/adaptive_multigrid/adaptive_multigrid.py.rst
+14-11Lines changed: 14 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,9 +51,9 @@ Our approach strongly follows the similar problem in this `lecture course <https
51
51
52
52
def solve_poisson(mesh, params):
53
53
V = FunctionSpace(mesh, "CG", 1)
54
-
uh = Function(V, name="Solution")
54
+
uh = Function(V, name="solution")
55
55
v = TestFunction(V)
56
-
bc = DirichletBC(V, Constant(0), "on_boundary")
56
+
bc = DirichletBC(V, 0, "on_boundary")
57
57
f = Constant(1)
58
58
F = inner(grad(uh), grad(v))*dx - inner(f, v)*dx
59
59
@@ -146,16 +146,16 @@ Our approach will be to compute the estimator over all elements and selectively
146
146
error_est = eta_.norm()
147
147
return eta, error_est
148
148
149
-
The next step is to choose which elements to refine. For this we use Dörfler marking [Dörfler1996]:
149
+
The next step is to choose which elements to refine. For this we use Dörfler marking :cite:`Dorfler1996`:
150
150
151
151
.. math::
152
152
\eta_K \geq\theta\text{max}_L \eta_L
153
153
154
-
The logic is to select an element :math:`K` to refine if the estimator is greater than some factor :math:`\theta` of the maximum error estimate of the mesh, where :math:`\theta` ranges from 0 to 1. In our code we choose :math:`theta=0.5`.
154
+
The logic is to select an element :math:`K` to refine if the estimator is greater than some factor :math:`\theta` of the maximum error estimate of the mesh, where :math:`\theta` ranges from 0 to 1. In our code we choose :math:`\theta=0.5`.
155
155
With these helper functions complete, we can solve the system iteratively. In the max_iterations is the number of total levels we want to perform multigrid on. We will solve for 15 levels. At every level :math:`l`, we first compute the solution using multigrid with patch relaxation up till level :math:`l`. We then use the current approximation of the solution to estimate the error across the mesh. Finally, we refine the mesh and repeat. ::
156
156
157
157
theta = 0.5
158
-
max_iterations = 10
158
+
max_iterations = 15
159
159
est_errors = []
160
160
dofs = []
161
161
for i in range(max_iterations):
@@ -187,10 +187,10 @@ With these helper functions complete, we can solve the system iteratively. In th
To perform Dörfler marking, refine the current mesh, and add the mesh to the :class:`.AdaptiveMeshHierarchy`, we use the ``amh.adapt(eta, theta)`` method. In this method the input is the recently computed error estimator :math:`eta` and the Dörfler marking parameter :math:`theta`. The method always performs this on the current fine mesh in the hierarchy. There is another method for adding a mesh to the hierarchy: ``amh.add_mesh(mesh)``. In this method, refinement on the mesh is performed externally by some custom procedure and the resulting mesh directly gets added to the hierarchy.
193
+
To perform Dörfler marking, refine the current mesh, and add the mesh to the :class:`.AdaptiveMeshHierarchy`, we use the ``amh.adapt(eta, theta)`` method. In this method the input is the recently computed error estimator ``eta`` and the Dörfler marking parameter ``theta``. The method always performs this on the current fine mesh in the hierarchy. There is another method for adding a mesh to the hierarchy: ``amh.add_mesh(mesh)``. In this method, refinement on the mesh is performed externally by some custom procedure and the resulting mesh directly gets added to the hierarchy.
194
194
The meshes now refine according to the error estimator. The error estimators at levels 3,5, and 15 are shown below. Zooming into the vertex of the L-shape at level 15 shows the error indicator remains strongest there. Further refinements will focus on that area.
0 commit comments