Skip to content

Commit

Permalink
Reduce unnecessary allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibolm committed Mar 4, 2024
1 parent 72573f8 commit 4b0bc4f
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/solvers/fv_t8code/containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,12 @@ function init_elements!(elements, mesh::T8codeMesh, solver::FV)
(; forest) = mesh

n_dims = ndims(mesh)
(; max_number_faces) = mesh
(; level, volume, dx, num_faces, face_areas) = elements
(; level, volume, dx, num_faces, face_areas, face_midpoints, face_normals) = elements

midpoint = Vector{Cdouble}(undef, n_dims)

face_midpoints = Matrix{Cdouble}(undef, 3, max_number_faces) # Need NDIMS=3 for t8code API. Also, consider that Julia is column major.
face_normals = Matrix{Cdouble}(undef, 3, max_number_faces) # Need NDIMS=3 for t8code API. Also, consider that Julia is column major.
face_midpoint = Vector{Cdouble}(undef, 3) # Need NDIMS=3 for t8code API
face_normal = Vector{Cdouble}(undef, 3) # Need NDIMS=3 for t8code API

num_local_trees = t8_forest_get_num_local_trees(forest)

Expand Down Expand Up @@ -156,19 +155,17 @@ function init_elements!(elements, mesh::T8codeMesh, solver::FV)
for iface in 1:num_faces[current_index]
# C++ is zero-indexed
t8_forest_element_face_centroid(forest, itree, element, iface - 1,
@views(face_midpoints[:, iface]))
face_areas[iface, current_index] = t8_forest_element_face_area(forest,
itree,
element,
iface -
1)
face_midpoint)

face_area = t8_forest_element_face_area(forest, itree, element,
iface - 1)
face_areas[iface, current_index] = face_area

t8_forest_element_face_normal(forest, itree, element, iface - 1,
@views(face_normals[:, iface]))
face_normal)
for dim in 1:n_dims
elements.face_midpoints[dim, iface, current_index] = face_midpoints[dim,
iface]
elements.face_normals[dim, iface, current_index] = face_normals[dim,
iface]
face_midpoints[dim, iface, current_index] = face_midpoint[dim]
face_normals[dim, iface, current_index] = face_normal[dim]
end
end
end
Expand Down

0 comments on commit 4b0bc4f

Please sign in to comment.