28
28
# the local error indicator ηK is computed as:
29
29
#
30
30
# ```math
31
- # \eta_K^2 = h_K^2\|f + \Delta u_h\|_{L^2(K)}^2 + h_K\|\jump{\ nabla u_h \cdot n} \|_{L^2(\partial K)}^2
31
+ # \eta_K^2 = h_K^2\|f + \Delta u_h\|_{L^2(K)}^2 + h_K\|\lbrack\!\lbrack \ nabla u_h \cdot n \rbrack\!\rbrack \|_{L^2(\partial K)}^2
32
32
# ```
33
33
#
34
34
# where:
35
- # - h_K is the diameter of element K
36
- # - u_h is the computed finite element solution
35
+ # - ` h_K` is the diameter of element K
36
+ # - ` u_h` is the computed finite element solution
37
37
# - The first term measures the element residual
38
38
# - The second term measures the jump in the normal derivative across element boundaries
39
39
#
@@ -96,12 +96,12 @@ l2_norm(xh,dΩ) = ∫(xh*xh)*dΩ
96
96
# 4. Refines the mesh using newest vertex bisection (NVB)
97
97
98
98
function amr_step (model,u_exact;order= 1 )
99
- # Create FE spaces with Dirichlet boundary conditions on all boundaries
99
+ " Create FE spaces with Dirichlet boundary conditions on all boundaries"
100
100
reffe = ReferenceFE (lagrangian,Float64,order)
101
101
V = TestFESpace (model,reffe;dirichlet_tags= [" boundary" ])
102
102
U = TrialFESpace (V,u_exact)
103
103
104
- # Setup integration measures
104
+ " Setup integration measures"
105
105
Ω = Triangulation (model)
106
106
Γ = Boundary (model)
107
107
Λ = Skeleton (model)
@@ -110,43 +110,43 @@ function amr_step(model,u_exact;order=1)
110
110
dΓ = Measure (Γ,2 * order)
111
111
dΛ = Measure (Λ,2 * order)
112
112
113
- # Compute cell sizes for error estimation
113
+ " Compute cell sizes for error estimation"
114
114
hK = CellField (sqrt .(collect (get_array (∫ (1 )dΩ))),Ω)
115
115
116
- # Get normal vectors for boundary and interface terms
116
+ " Get normal vectors for boundary and interface terms"
117
117
nΓ = get_normal_vector (Γ)
118
118
nΛ = get_normal_vector (Λ)
119
119
120
- # Define the weak form
120
+ " Define the weak form"
121
121
∇u (x) = ∇ (u_exact)(x)
122
122
f (x) = - Δ (u_exact)(x)
123
123
a (u,v) = ∫ (∇ (u)⋅ ∇ (v))dΩ
124
124
l (v) = ∫ (f* v)dΩ
125
125
126
- # Define the residual error estimator
127
- # It includes volume residual, boundary jump, and interface jump terms
126
+ " Define the residual error estimator
127
+ It includes volume residual, boundary jump, and interface jump terms"
128
128
ηh (u) = l2_norm (hK* (f + Δ (u)),dΩ) + # Volume residual
129
129
l2_norm (hK* (∇ (u) - ∇u)⋅ nΓ,dΓ) + # Boundary jump
130
130
l2_norm (jump (hK* ∇ (u)⋅ nΛ),dΛ) # Interface jump
131
131
132
- # Solve the FE problem
132
+ " Solve the FE problem"
133
133
op = AffineFEOperator (a,l,U,V)
134
134
uh = solve (op)
135
135
136
- # Compute error indicators
136
+ " Compute error indicators"
137
137
η = estimate (ηh,uh)
138
138
139
- # Mark cells for refinement using Dörfler marking
140
- # This strategy marks cells containing a fixed fraction (0.8) of the total error
139
+ " Mark cells for refinement using Dörfler marking
140
+ This strategy marks cells containing a fixed fraction (0.8) of the total error"
141
141
m = DorflerMarking (0.8 )
142
142
I = Adaptivity. mark (m,η)
143
143
144
- # Refine the mesh using newest vertex bisection
144
+ " Refine the mesh using newest vertex bisection"
145
145
method = Adaptivity. NVBRefinement (model)
146
146
amodel = refine (method,model;cells_to_refine= I)
147
147
fmodel = Adaptivity. get_model (amodel)
148
148
149
- # Compute the global error for convergence testing
149
+ " Compute the global error for convergence testing"
150
150
error = sum (l2_norm (uh - u_exact,dΩ))
151
151
return fmodel, uh, η, I, error
152
152
end
@@ -163,13 +163,10 @@ model = LShapedModel(10)
163
163
164
164
last_error = Inf
165
165
for i in 1 : nsteps
166
- # Perform one AMR step
167
166
fmodel, uh, η, I, error = amr_step (model,u_exact;order)
168
167
169
- # Create indicator field for refined cells
170
168
is_refined = map (i -> ifelse (i ∈ I, 1 , - 1 ), 1 : num_cells (model))
171
169
172
- # Visualize results
173
170
Ω = Triangulation (model)
174
171
writevtk (
175
172
Ω," model_$(i- 1 ) " ,append= false ,
@@ -181,7 +178,6 @@ for i in 1:nsteps
181
178
],
182
179
)
183
180
184
- # Print error information and verify convergence
185
181
println (" Error: $error , Error η: $(sum (η)) " )
186
182
@test (i < 3 ) || (error < last_error)
187
183
last_error = error
0 commit comments