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 3 commits into
base: main
Choose a base branch
from

Conversation

JordiManyer
Copy link
Member

No description provided.

@JordiManyer JordiManyer changed the title Re-implemented generate_coords without Float comparison ambiguities Remove Float comparison ambiguities from generate_coords Apr 23, 2024
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


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?

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])
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 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?

@amartinhuertas
Copy link
Member

amartinhuertas commented Apr 25, 2024

Hi @JordiManyer,

Thanks for your work.

I have completed a first round of review. Please see my comments.

Leaving aside my concern on why do we actually need geometric information for topology-related data (i.e., the coordinates of the corners, whatever they are defined mathematically), my main concern while going over the proposed strategy in this PR was (but no longer is) that we are still comparing numerical values to identify vertices. But I think it is fine, because we only have two different scenarios:

  1. The current vertex is located in exactly the same coordinate as an existing corner.
  2. The current vertex is not located in the same coordinate as an existing corner (in such a case, we have potentially a new vertex).

I think that, in order to be even safer, one may use equality instead of norm(coord-model_coords[vertex]) > eps(T). This is because the coordinates of a corner are assigned to be bit-wise the same (i.e., a copy) to the ones of one of the vertices clashing in the same corner. The same reasoning applies to pos = findfirst(x -> norm(x-coord) < eps(T), model_coords[n_corners+1:n_vertices]).

Note that norm(coord-model_coords[vertex]) > eps(T) might be false for a vertex-corner pair which are too close to each other, but not exactly in the same position.

Let me know if you agree or not here, or I might be missing something.

Finally, on another note, I still wonder myself if I could get some symbolic information out of p4est that allows us to separate vertices from corners, but I guess this requires much more time than the one I have now.

UPDATE/CAVEAT: In my reasoning above, I am assuming that p4est is going to return exactly (bit-wise equivalence) the same vertex coordinate for all cells surrounding a vertex. If this is not the case, I think we can force this as a post-process step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants