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

Investigate alternative to CellValues #62

Open
termi-official opened this issue Jan 18, 2024 · 0 comments
Open

Investigate alternative to CellValues #62

termi-official opened this issue Jan 18, 2024 · 0 comments
Labels
architecture Issues affecting the structural and design aspects of the software performance Something affecting the performance (e.g. scalability or flat runtime)

Comments

@termi-official
Copy link
Owner

termi-official commented Jan 18, 2024

It is interesting to explore alternative evaluation modes to CellValues. Resizing arrays is cheap and in most cases non-allocating, so we can easily call it once per cell.

julia> @btime resize!($A,5)
  4.160 ns (0 allocations: 0 bytes)
5-element Vector{Float64}:
 -9.112500000000002e-5
  0.00011137500000000004
 -0.00013612500000000004
  0.00011137500000000004
  0.00011137500000000004

julia> @btime resize!($A,5)
  3.810 ns (0 allocations: 0 bytes)
5-element Vector{Float64}:
 -9.112500000000002e-5
  0.00011137500000000004
 -0.00013612500000000004
  0.00011137500000000004
  0.00011137500000000004

Furthermore the evaluation of ansatz functions per quadrature point is also not that bad.

julia> ip = Lagrange{RefHexahedron,2}()
Lagrange{RefHexahedron, 2}()

julia> @btime Ferrite.shape_values!($A, $ip, Vec((0.1,0.1,0.1)))
  142.555 ns (0 allocations: 0 bytes)

julia> B = zeros(Vec{3}, 27)
27-element Vector{Vec{3, Float64}}:
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]

julia> @btime Ferrite.shape_gradients_and_values!($B, $A, $ip, Vec((0.1,0.1,0.1)))
  451.777 ns (0 allocations: 0 bytes)

and there is room for optimization

julia> function shape_values(A, ip::Lagrange{RefHexahedron, 1}, ξ::Vec{3})
           ξ_x = ξ[1]
           ξ_y = ξ[2]
           ξ_z = ξ[3]
           Nx = ((1 - ξ_x), (1 + ξ_x))
           Ny = ((1 - ξ_y), (1 + ξ_y))
           Nz = ((1 - ξ_z), (1 + ξ_z))
           A[1] = Nx[1] * Ny[1] * Nz[1] / 8
           A[2] = Nx[2] * Ny[1] * Nz[1] / 8
           A[3] = Nx[2] * Ny[2] * Nz[1] / 8
           A[4] = Nx[1] * Ny[2] * Nz[1] / 8
           A[5] = Nx[1] * Ny[1] * Nz[2] / 8
           A[6] = Nx[2] * Ny[1] * Nz[2] / 8
           A[7] = Nx[2] * Ny[2] * Nz[2] / 8
           A[8] = Nx[1] * Ny[2] * Nz[2] / 8
       end
shape_values (generic function with 2 methods)

julia> @btime Ferrite.shape_values!($A, $ip, Vec((0.1,0.1,0.1)))
  39.889 ns (0 allocations: 0 bytes)

julia> @btime shape_values($A, $ip, Vec((0.1,0.1,0.1)))
  6.930 ns (0 allocations: 0 bytes)
@termi-official termi-official added performance Something affecting the performance (e.g. scalability or flat runtime) architecture Issues affecting the structural and design aspects of the software labels Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture Issues affecting the structural and design aspects of the software performance Something affecting the performance (e.g. scalability or flat runtime)
Projects
None yet
Development

No branches or pull requests

1 participant