Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv committed Sep 18, 2024
1 parent a195d34 commit ad2eacf
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/refinement/tri.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct TriRefinement{F} <: RefinementMethod
pred::F
end

TriRefinement() = TriRefinement(_ -> true)
TriRefinement() = TriRefinement(nothing)

function refine(mesh, method::TriRefinement)
assertion(paramdim(mesh) == 2, "TriRefinement only defined for surface meshes")
Expand All @@ -36,20 +36,29 @@ function refine(mesh, method::TriRefinement)
# offset to new vertex indices
offset = length(points)

# predicate function
pred = if isnothing(method.pred)
_ -> true
else
eᵢ -> method.pred(element(mesh, eᵢ))

Check warning on line 43 in src/refinement/tri.jl

View check run for this annotation

Codecov / codecov/patch

src/refinement/tri.jl#L43

Added line #L43 was not covered by tests
end

# add centroids of elements and connect vertices
# into new triangles if necessary
newpoints = copy(points)
newconnec = Connectivity{Triangle,3}[]
for eᵢ in 1:nelements(t)
elem = element(mesh, eᵢ)
# check if the element should be refined
if method.pred(elem)
if pred(eᵢ)
verts = ∂₂₀(eᵢ)
nv = length(verts)

# add new centroid vertex
push!(newpoints, centroid(elem))
cₒ = sum(i -> to(points[i]), verts) / length(verts)
pₒ = withcrs(mesh, cₒ)
push!(newpoints, pₒ)

# add new connectivities
verts = ∂₂₀(eᵢ)
nv = length(verts)
for i in 1:nv
u = eᵢ + offset
v = verts[mod1(i, nv)]
Expand Down

0 comments on commit ad2eacf

Please sign in to comment.