Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Float comparison ambiguities from generate_coords #67

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions src/UniformlyRefinedForestOfOctreesDiscreteModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Copy link
Member

@amartinhuertas amartinhuertas Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would improve the naming convention.

E.g.

topo_cell_ids => cell_corners
model_cell_coords => cell_vertices_coords
model_coords => vertex_coords
model_cell_ids => cell_vertices
topo_coords => corner_coords

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use here the relative error instead of the absolute one?

pos = findfirst(x -> norm(x-coord) < eps(T), model_coords[n_corners+1:n_vertices])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model_coords[n_corners+1:n_vertices] creates a dynamically allocated copy, use view instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !isnothing(pos)
model_cell_ids.data[k] = 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a more general question here regarding the need for topo_coords. I understand it is because it is a requirement of the UnstructuredGridTopology constructor.

HOWEVER, if we are separating among topology and geometry, etc. Why do we need the coordinates of the corners in GridTopology??? What am I missing here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ... how is the coordinate of a corner defined mathematically and why?

Right now, the code is assigning (arbitrarily?) the minimum coordinate among the coordinates of the all vertices that clash into the same corner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea, it might never be used. But it is required, so we might as well give it something consistent, right?

end

Expand Down
Loading