Skip to content

Commit 4b13ae7

Browse files
committed
avoid creating unnecessary views in InterfaceValues
fixes #1301
1 parent 2ecfdd4 commit 4b13ae7

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/FEValues/InterfaceValues.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ for func in (:function_value, :function_gradient)
326326
@boundscheck checkbounds(u, 1:getnbasefunctions(iv))
327327
if here
328328
dof_range_here = 1:getnbasefunctions(iv.here)
329-
return $(func)(iv.here, q_point, @view(u[dof_range_here]))
329+
return $(func)(iv.here, q_point, u, dof_range_here)
330330
else # there
331331
dof_range_there = (1:getnbasefunctions(iv.there)) .+ getnbasefunctions(iv.here)
332-
return $(func)(iv.there, q_point, @view(u[dof_range_there]))
332+
return $(func)(iv.there, q_point, u, dof_range_there)
333333
end
334334
end
335335
function $(func)(
@@ -360,8 +360,8 @@ for (func, f_, is_avg) in (
360360
@boundscheck checkbounds(u, getnbasefunctions(iv))
361361
dof_range_here = 1:getnbasefunctions(iv.here)
362362
dof_range_there = (1:getnbasefunctions(iv.there)) .+ getnbasefunctions(iv.here)
363-
f_here = $(f_)(iv.here, qp, @view(u[dof_range_here]))
364-
f_there = $(f_)(iv.there, qp, @view(u[dof_range_there]))
363+
f_here = $(f_)(iv.here, qp, u, dof_range_here)
364+
f_there = $(f_)(iv.there, qp, u, dof_range_there)
365365
return $(is_avg ? :((f_here + f_there) / 2) : :(f_there - f_here))
366366
end
367367
function $(func)(

src/FEValues/common_values.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function function_value(fe_v::AbstractValues, q_point::Int, u::AbstractVector, d
180180
@boundscheck checkbounds(u, dof_range)
181181
@boundscheck checkquadpoint(fe_v, q_point)
182182
val = function_value_init(fe_v, u)
183-
@inbounds for (i, j) in pairs(dof_range)
183+
@inbounds for (i, j) in enumerate(dof_range)
184184
val += shape_value(fe_v, q_point, i) * u[j]
185185
end
186186
return val
@@ -220,20 +220,21 @@ function function_gradient(fe_v::AbstractValues, q_point::Int, u::AbstractVector
220220
@boundscheck checkbounds(u, dof_range)
221221
@boundscheck checkquadpoint(fe_v, q_point)
222222
grad = function_gradient_init(fe_v, u)
223-
@inbounds for (i, j) in pairs(dof_range)
223+
@inbounds for (i, j) in enumerate(dof_range)
224224
grad += shape_gradient(fe_v, q_point, i) * u[j]
225225
end
226226
return grad
227227
end
228228

229229
# TODO: Deprecate this, nobody is using this in practice...
230-
function function_gradient(fe_v::AbstractValues, q_point::Int, u::AbstractVector{<:Vec})
230+
function function_gradient(fe_v::AbstractValues, q_point::Int, u::AbstractVector{<:Vec}, dof_range = eachindex(u))
231231
n_base_funcs = getnbasefunctions(fe_v)
232-
length(u) == n_base_funcs || throw_incompatible_dof_length(length(u), n_base_funcs)
232+
length(dof_range) == n_base_funcs || throw_incompatible_dof_length(length(dof_range), n_base_funcs)
233+
@boundscheck checkbounds(u, dof_range)
233234
@boundscheck checkquadpoint(fe_v, q_point)
234235
grad = function_gradient_init(fe_v, u)
235-
@inbounds for i in 1:n_base_funcs
236-
grad += u[i] shape_gradient(fe_v, q_point, i)
236+
@inbounds for (i, j) in enumerate(dof_range)
237+
grad += u[j] shape_gradient(fe_v, q_point, i)
237238
end
238239
return grad
239240
end
@@ -267,7 +268,7 @@ function function_hessian(fe_v::AbstractValues, q_point::Int, u::AbstractVector,
267268
@boundscheck checkbounds(u, dof_range)
268269
@boundscheck checkquadpoint(fe_v, q_point)
269270
hess = function_hessian_init(fe_v, u)
270-
@inbounds for (i, j) in pairs(dof_range)
271+
@inbounds for (i, j) in enumerate(dof_range)
271272
hess += shape_hessian(fe_v, q_point, i) * u[j]
272273
end
273274
return hess

0 commit comments

Comments
 (0)