From 1d4f3d3cf966374c3a3bde839b612db80100a266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20M=C3=B8yner?= Date: Tue, 5 Mar 2024 22:10:18 +0100 Subject: [PATCH] Speed up a few calls in grid processing --- src/CornerPointGrid/processing.jl | 8 ++++---- src/CornerPointGrid/processing_utils.jl | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/CornerPointGrid/processing.jl b/src/CornerPointGrid/processing.jl index 463a208..0a37394 100644 --- a/src/CornerPointGrid/processing.jl +++ b/src/CornerPointGrid/processing.jl @@ -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) @@ -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] @@ -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] @@ -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 diff --git a/src/CornerPointGrid/processing_utils.jl b/src/CornerPointGrid/processing_utils.jl index d41516c..3c8d76b 100644 --- a/src/CornerPointGrid/processing_utils.jl +++ b/src/CornerPointGrid/processing_utils.jl @@ -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 @@ -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))"