Skip to content

error in meshvariable to meshvariable projection #3

Closed

Description

@gthyagi

Hi @lmoresi and @julesghub,

I’m using the mesh-to-mesh variable projection from this section of the code.

It works well in general, except at the origin (0, 0, 0).

I’m attaching a simple Python script to reproduce the issue. The projected values between meshes can be found in the variable v_soln_2_m1tom2.

demo_meshvar2meshvar_err-Copy1.py.zip

Thanks for taking a look!

Activity

  1. gthyagi commented on Jul 2, 2025

    @gthyagi
    ContributorAuthor

    When I change the origin from (0, 0, 0) to (10, 10, 10), the issue with anomalous values at the cell containing (0, 0, 0) disappears. This suggests it’s related to floating point precision.

    Note: I haven’t checked yet whether this issue originates from the Gmsh level or the DMPlex level.

  2. gthyagi commented on Jul 4, 2025

    @gthyagi
    ContributorAuthor

    @knepley I believe this issue is occurring at the DMPlex and DMSwarm level. Do you have any comments on this?

    It seems that if the model’s bounding box coordinates include zero, there’s a floating point precision error involving the zero value.

    Note: Mesh1 and Mesh2 have the same bounding box coordinates but different cell sizes.

    Image

  3. knepley commented on Jul 5, 2025

    @knepley
    Contributor

    @gthyagi What routine has the problem?

  4. jcgraciosa commented on Jul 8, 2025

    @jcgraciosa
    Contributor

    @gthyagi, I had a look at the attached code. The main cause of the issue is the behaviour of swarm.dm.addNPoints() inside mesh2mesh_swarm:

    • If the swarm is still empty, to add N points, you need to to do swarm.dm.addNPoints(N + 1) and this is what you see in lines 105 - 108.
    • If the swarm already has particles inside, then to add M points, you need to do swarm.dm.addNPoints(M)

    With this, even if n_found1 is equal to zero, adds will be equal to 1. Consequently, addNPoints in line 161 adds a particle, but is not assigned a proper coordinate so it retains its default coordinate of (0., 0., 0.). This results to the issue you see.

    One way to fix this is Putting lines 158 to 166 and 171 to 172 in mesh2mesh_swarm inside the if n_found1 > 0: clause.

  5. gthyagi commented on Jul 9, 2025

    @gthyagi
    ContributorAuthor

    @jcgraciosa, if this is a PETSc issue rather than Underworld, could you please provide a brief explanation along with a reproducible script to @knepley? Thanks for investigating the issue and implementing a temporary fix. Cheers!

  6. jcgraciosa commented on Jul 9, 2025

    @jcgraciosa
    Contributor

    Sure! Here's a simple example @gthyagi, @knepley:

    import underworld3 as uw
    
    mesh = uw.meshing.UnstructuredSimplexBox(minCoords  = (0., 0.),
                                                maxCoords   = (1, 1.),
                                                cellSize    = 1/2,
                                                regular     = False)
    
    swarm = uw.swarm.Swarm(mesh)
    swarm_var = uw.swarm.SwarmVariable(name = "test", swarm = swarm, size = 1)
    swarm.dm.finalizeFieldRegister()
    
    # add 10 particles to a blank swarm
    swarm.dm.addNPoints(10) 
    with swarm.access():
        print(swarm.data.shape) # WRONGLY adds only 9 instead of 10 particles
    
    # add 2 more particles 
    swarm.dm.addNPoints(2) 
    with swarm.access():
        print(swarm.data.shape) # this time, CORRECTLY added 2 particles 
  7. julesghub commented on Jul 9, 2025

    @julesghub
    Member
  8. jcgraciosa commented on Jul 9, 2025

    @jcgraciosa
    Contributor

    @julesghub For the example, doing swarm.dm.getSize() after swarm.dm.addNPoints(10) returns 9. Calling it again after swarm.dm.addNPoints(2) returns 11.

  9. knepley commented on Jul 10, 2025

    @knepley
    Contributor

    Embarassing. The initial size was -1, so addition functions did not work. I was using all direct sets. Here is the fix: https://gitlab.com/petsc/petsc/-/merge_requests/8541

  10. jcgraciosa commented on Jul 10, 2025

    @jcgraciosa
    Contributor

    All good! Thank you so much for providing the fix @knepley!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions