Skip to content

Commit c66a1e2

Browse files
committed
Minor
1 parent 64dd5e9 commit c66a1e2

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

src/geometry_dev.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,10 @@ function get_face_to_face_graph(topo,Df)
150150
face_to_face = Vector{Vector{Int}}(undef,n_faces)
151151
for face in 1:n_faces
152152
nbors = Int[]
153-
# Find faces sharing vertices with current face
154153
for vertex in face_to_vertices[face]
155-
append!(nbors,vertex_to_faces[vertex])
154+
append!(nbors,vertex_to_faces[vertex]) # Add incident faces
156155
end
157-
# Remove self-reference and duplicates
158-
face_to_face[face] = filter(!isequal(face),unique(nbors))
156+
face_to_face[face] = filter(!isequal(face),unique(nbors)) # Remove self-reference and duplicates
159157
end
160158

161159
return face_to_face

src/poisson_amr.jl

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
# the local error indicator ηK is computed as:
2929
#
3030
# ```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
3232
# ```
3333
#
3434
# 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
3737
# - The first term measures the element residual
3838
# - The second term measures the jump in the normal derivative across element boundaries
3939
#
@@ -96,12 +96,12 @@ l2_norm(xh,dΩ) = ∫(xh*xh)*dΩ
9696
# 4. Refines the mesh using newest vertex bisection (NVB)
9797

9898
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"
100100
reffe = ReferenceFE(lagrangian,Float64,order)
101101
V = TestFESpace(model,reffe;dirichlet_tags=["boundary"])
102102
U = TrialFESpace(V,u_exact)
103103

104-
# Setup integration measures
104+
"Setup integration measures"
105105
Ω = Triangulation(model)
106106
Γ = Boundary(model)
107107
Λ = Skeleton(model)
@@ -110,43 +110,43 @@ function amr_step(model,u_exact;order=1)
110110
= Measure(Γ,2*order)
111111
= Measure(Λ,2*order)
112112

113-
# Compute cell sizes for error estimation
113+
"Compute cell sizes for error estimation"
114114
hK = CellField(sqrt.(collect(get_array((1)dΩ))),Ω)
115115

116-
# Get normal vectors for boundary and interface terms
116+
"Get normal vectors for boundary and interface terms"
117117
= get_normal_vector(Γ)
118118
= get_normal_vector(Λ)
119119

120-
# Define the weak form
120+
"Define the weak form"
121121
∇u(x) = (u_exact)(x)
122122
f(x) = -Δ(u_exact)(x)
123123
a(u,v) = ((u)(v))dΩ
124124
l(v) = (f*v)dΩ
125125

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"
128128
ηh(u) = l2_norm(hK*(f + Δ(u)),dΩ) + # Volume residual
129129
l2_norm(hK*((u) - ∇u)nΓ,dΓ) + # Boundary jump
130130
l2_norm(jump(hK*(u)nΛ),dΛ) # Interface jump
131131

132-
# Solve the FE problem
132+
"Solve the FE problem"
133133
op = AffineFEOperator(a,l,U,V)
134134
uh = solve(op)
135135

136-
# Compute error indicators
136+
"Compute error indicators"
137137
η = estimate(ηh,uh)
138138

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"
141141
m = DorflerMarking(0.8)
142142
I = Adaptivity.mark(m,η)
143143

144-
# Refine the mesh using newest vertex bisection
144+
"Refine the mesh using newest vertex bisection"
145145
method = Adaptivity.NVBRefinement(model)
146146
amodel = refine(method,model;cells_to_refine=I)
147147
fmodel = Adaptivity.get_model(amodel)
148148

149-
# Compute the global error for convergence testing
149+
"Compute the global error for convergence testing"
150150
error = sum(l2_norm(uh - u_exact,dΩ))
151151
return fmodel, uh, η, I, error
152152
end
@@ -163,13 +163,10 @@ model = LShapedModel(10)
163163

164164
last_error = Inf
165165
for i in 1:nsteps
166-
# Perform one AMR step
167166
fmodel, uh, η, I, error = amr_step(model,u_exact;order)
168167

169-
# Create indicator field for refined cells
170168
is_refined = map(i -> ifelse(i I, 1, -1), 1:num_cells(model))
171169

172-
# Visualize results
173170
Ω = Triangulation(model)
174171
writevtk(
175172
Ω,"model_$(i-1)",append=false,
@@ -181,7 +178,6 @@ for i in 1:nsteps
181178
],
182179
)
183180

184-
# Print error information and verify convergence
185181
println("Error: $error, Error η: $(sum(η))")
186182
@test (i < 3) || (error < last_error)
187183
last_error = error

0 commit comments

Comments
 (0)