Skip to content

Commit

Permalink
Speed up a few calls in grid processing
Browse files Browse the repository at this point in the history
  • Loading branch information
moyner committed Mar 5, 2024
1 parent 84cffab commit 1d4f3d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/CornerPointGrid/processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function cpgrid_primitives(coord, zcorn, cartdims; actnum = missing, pinch = mis
@assert nliney*nlinex == size(coord, 1)

function generate_line(p1, p2)
line_length_hint = nz
line_length_hint = 4*nz
z = sizehint!(Vector{Float64}(), line_length_hint)
cells = sizehint!(Vector{Int}(), line_length_hint)
cellpos = sizehint!(Vector{Int}(), line_length_hint)
Expand Down Expand Up @@ -51,7 +51,7 @@ function cpgrid_primitives(coord, zcorn, cartdims; actnum = missing, pinch = mis
return layer_offset - ij_to_linear(i, j, cartdims[1:2])
end

function cell_index(i, j, k)
function cell_index(i, j, k, actnum)
ix = ijk_to_linear(i, j, k, cartdims)
if actnum[i, j, k]
cell = remapped_indices[ix]
Expand All @@ -76,7 +76,7 @@ function cpgrid_primitives(coord, zcorn, cartdims; actnum = missing, pinch = mis
for j = 1:ny
for k = 1:nz
ix = ijk_to_linear(i, j, k, cartdims)
active_cell_index = cell_index(i, j, k)
active_cell_index = cell_index(i, j, k, actnum)
for I1 in (0, 1)
for I2 in (0, 1)
L = lines[i + I2, j + I1]
Expand Down Expand Up @@ -148,7 +148,7 @@ function cpgrid_primitives(coord, zcorn, cartdims; actnum = missing, pinch = mis
prev = boundary_index(i, j, true)
push!(col.cells, prev)
for k in 1:nz
cell = cell_index(i, j, k)
cell = cell_index(i, j, k, actnum)
if cell != prev
push!(col.cells, cell)
end
Expand Down
6 changes: 4 additions & 2 deletions src/CornerPointGrid/processing_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ function traverse_column_pair(col_a, col_b, l1, l2)

ord_a = cell_top_bottom(col_a.cells, l1, l2)
ord_b = cell_top_bottom(col_b.cells, l1, l2)
sizehint!(overlaps, max(length(ord_a), length(ord_b)))
function get_local_line(pos, is_line1::Bool)
if is_line1
d = pos.line1
Expand All @@ -419,7 +418,10 @@ function traverse_column_pair(col_a, col_b, l1, l2)
return determine_cell_overlap_inside_line(a_start, a_stop, b_start, b_stop)
end
cell_pairs = Tuple{Int, Int}[]
sizehint!(cell_pairs, 2*max(length(ord_a), length(ord_b)))
cellhint = 2*max(length(ord_a), length(ord_b))
sizehint!(cell_pairs, cellhint)
sizehint!(overlaps, cellhint)

for pos_a in ord_a
for pos_b in ord_b
# @info "Cell pair: $((pos_a.cell, pos_b.cell))"
Expand Down

0 comments on commit 1d4f3d3

Please sign in to comment.