From c134f1423adac6c12a8004825ca6806a6ee06599 Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Tue, 23 Apr 2024 18:29:50 +1000 Subject: [PATCH 1/2] Re-implemented generate_coords without Float comparison ambiguities --- ...mlyRefinedForestOfOctreesDiscreteModels.jl | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/UniformlyRefinedForestOfOctreesDiscreteModels.jl b/src/UniformlyRefinedForestOfOctreesDiscreteModels.jl index 8d0660a..9fc8514 100644 --- a/src/UniformlyRefinedForestOfOctreesDiscreteModels.jl +++ b/src/UniformlyRefinedForestOfOctreesDiscreteModels.jl @@ -552,38 +552,31 @@ function generate_coords( model_cell_coords :: Gridap.Arrays.Table{<:VectorValue{Dp,T}} ) where {Ti,Dp,T} n_corners = maximum(topo_cell_ids.data;init=0) - n_vertices = length(unique(model_cell_coords.data)) - - model_coords = fill(VectorValue(fill(T(Inf),Dp)),n_vertices) + + n_vertices_max = length(model_cell_coords.data) + model_coords = fill(VectorValue(fill(T(Inf),Dp)),n_vertices_max) for (vertex,coord) in zip(topo_cell_ids.data,model_cell_coords.data) model_coords[vertex] = min(model_coords[vertex],coord) end - - # A) Non-periodic case: geometry == topology - if n_corners == n_vertices - return topo_cell_ids, model_coords, model_coords - end - - # B) Periodic case: geometry != topology - topo_coords = model_coords[1:n_corners] - current = n_corners - model_cell_ids = copy(topo_cell_ids) - new_nodes = Dict{VectorValue{Dp,T},Ti}() + n_vertices = n_corners + model_cell_ids = Gridap.Arrays.Table(copy(topo_cell_ids.data),copy(topo_cell_ids.ptrs)) for (k,(vertex,coord)) in enumerate(zip(topo_cell_ids.data,model_cell_coords.data)) - if coord != topo_coords[vertex] - if haskey(new_nodes,coord) - model_cell_ids.data[k] = new_nodes[coord] + if norm(coord-model_coords[vertex]) > eps(T) + pos = findfirst(x -> norm(x-coord) < eps(T), model_coords[n_corners+1:n_vertices]) + if !isnothing(pos) + model_cell_ids.data[k] = model_coords[n_corners+pos] else - current += 1 - model_coords[current] = coord - new_nodes[coord] = current - model_cell_ids.data[k] = current + n_vertices += 1 + model_coords[n_vertices] = coord + model_cell_ids.data[k] = n_vertices end end end - @assert current == n_vertices + @debug "function generate_coords :: n_vertices=$n_vertices, n_corners=$n_corners." + resize!(model_coords,n_vertices) + topo_coords = (n_vertices == n_corners) ? model_coords : model_coords[1:n_corners] return model_cell_ids, model_coords, topo_coords end From d03085aa24a3a269c0369139b09df34b1d6e835b Mon Sep 17 00:00:00 2001 From: JordiManyer Date: Wed, 24 Apr 2024 09:21:02 +1000 Subject: [PATCH 2/2] Bugfix --- src/UniformlyRefinedForestOfOctreesDiscreteModels.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UniformlyRefinedForestOfOctreesDiscreteModels.jl b/src/UniformlyRefinedForestOfOctreesDiscreteModels.jl index 9fc8514..b3971a9 100644 --- a/src/UniformlyRefinedForestOfOctreesDiscreteModels.jl +++ b/src/UniformlyRefinedForestOfOctreesDiscreteModels.jl @@ -565,7 +565,7 @@ function generate_coords( if norm(coord-model_coords[vertex]) > eps(T) pos = findfirst(x -> norm(x-coord) < eps(T), model_coords[n_corners+1:n_vertices]) if !isnothing(pos) - model_cell_ids.data[k] = model_coords[n_corners+pos] + model_cell_ids.data[k] = n_corners+pos else n_vertices += 1 model_coords[n_vertices] = coord