autotwin / automesh

Automatic mesh generation.
https://autotwin.github.io/automesh
MIT License
1 stars 0 forks source link

Node-to-element connectivity is slow. #133

Closed mrbuche closed 1 week ago

mrbuche commented 1 week ago

Describe the bug

The calculation of the node-to-element connectivity appears to be much slower than other operations.

To Reproduce

$ cargo run -qr -F profile -- mesh -i spheres_resolution_2.npy -o target/foo.inp
    automesh 0.1.10
     Reading spheres_resolution_2.npy
        Done 201.338µs
     Meshing target/foo.inp
           ⤷ Filter 3.053172ms
             Connectivity 1.756722ms
             Coordinates 5.495238ms
             Mapping 492.783µs
             Removal 61.794µs
             Renumbering 193.295µs
        Done 11.419183ms
   Smoothing target/foo.inp
           ⤷ Node-to-element connectivity 8.314554166s 
             Node-to-node connectivity 26.056589ms 
             Nodal hierarchy 7.161734ms 
        Done 8.347809164s
     Writing target/foo.inp
           ⤷ Coordinates 34.842501ms
             Connectivity 24.634797ms
        Done 66.325293ms
$ cargo run -qr -F profile -- mesh -i spheres_resolution_3.npy -o target/foo.inp
    automesh 0.1.10
     Reading spheres_resolution_3.npy
        Done 487.264µs
     Meshing target/foo.inp
           ⤷ Filter 22.320514ms
             Connectivity 18.962217ms
             Coordinates 46.409529ms
             Mapping 2.836481ms
             Removal 558.733µs
             Renumbering 2.519586ms
        Done 95.556747ms
   Smoothing target/foo.inp
           ⤷ Node-to-element connectivity 768.169208482s 
             Node-to-node connectivity 233.107442ms 
             Nodal hierarchy 57.136488ms 
        Done 768.459505013s
     Writing target/foo.inp
           ⤷ Coordinates 261.19101ms
             Connectivity 224.191682ms
        Done 551.462813ms

Expected behavior

Appears to be $O(N^2)$ rather than $O(N)$, which is likely due to looping over the element-to-node connectivity within the loop over the node-to-element connectivity in order to populate it.

Additional context

Reproduce using this commit. The node-to-element connectivity is currently needed to calculate the node-to-node connectivity and the nodal hierarchy.

mrbuche commented 1 week ago

Fixed in #134.

$ cargo run -qr -F profile -- mesh -i spheres_resolution_4.npy -o target/foo.inp --smooth
    automesh 0.1.10
     Reading spheres_resolution_4.npy
        Done 7.246989ms
     Meshing target/foo.inp
           ⤷ Removed voxels 327.585084ms
             Element-to-node connectivity 284.005907ms
             Nodal coordinates 691.668606ms
             Renumbered nodes 85.932201ms
        Done 1.410858943s
   Smoothing target/foo.inp
           ⤷ Node-to-element connectivity 489.889089ms 
             Node-to-node connectivity 5.430347083s 
             Nodal hierarchy 846.394093ms 
        Done 6.766705079s
     Writing target/foo.inp
           ⤷ Nodal coordinates 4.626956897s
             Element-to-node connectivity 3.780540771s
        Done 9.124938823s
hovey commented 1 week ago

@mrbuche Just finished new timing results with automesh version 0.0.10