Skip to content

Commit 845d7c5

Browse files
committed
removed duplicate nodevalues!
1 parent c2f3a39 commit 845d7c5

1 file changed

Lines changed: 88 additions & 114 deletions

File tree

src/interpolations.jl

Lines changed: 88 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -260,52 +260,31 @@ end
260260
"""
261261
````
262262
function nodevalues!(
263-
target::AbstractArray{<:Real,2},
264-
source::AbstractArray{T,1},
265-
FE::FESpace{Tv,Ti,FEType,AT},
266-
operator::Type{<:AbstractFunctionOperator} = Identity;
267-
kwargs...)
268-
````
269-
270-
calls the nodevalues_subset! function with all nodes of the dofgrid, see nodevalues_subset!(target, source, FE, operator; nodes = 1:num_nodes(FE.dofgrid), kwargs...)
271-
"""
272-
function nodevalues!(
273-
target::AbstractArray{T, 2},
274-
source::AbstractArray{T, 1},
275-
FE::FESpace{Tv, Ti, FEType, AT},
276-
operator::Type{<:AbstractFunctionOperator} = Identity;
277-
kwargs...
278-
) where {T, Tv, Ti, FEType, AT}
279-
280-
nodevalues_subset!(target, source, FE, operator; nodes = 1:num_nodes(FE.dofgrid), kwargs...)
281-
282-
return nothing
283-
end
284-
285-
"""
286-
````
287-
piecewise_nodevalues!(
288-
target::AbstractArray{T, 2},
289-
source::AbstractArray{T, 1},
290-
FE::FESpace{Tv, Ti, FEType, AT},
263+
target::AbstractArray{<:Real,2},
264+
source::AbstractArray{T,1},
265+
FE::FESpace{Tv,Ti,FEType,AT},
291266
operator::Type{<:AbstractFunctionOperator} = Identity;
292267
abs::Bool = false,
293268
factor = 1,
294-
regions::Array{Int, 1} = [0],
269+
regions::Array{Int,1} = [0],
295270
target_offset::Int = 0,
296271
source_offset::Int = 0,
297272
zero_target::Bool = true,
298273
continuous::Bool = false
299274
)
300275
````
301276
302-
Evaluate a finite element function (given by the coefficient vector `source` and FE space `FE`) at all nodes, but store the results in a piecewise (cellwise) fashion, i.e., for each cell, the values at its local nodes are written into `target`. The result is organized so that each column of `target` corresponds to a cell, and each row corresponds to the values at the cell's nodes.
277+
Evaluate a finite element function (given by the coefficient vector `source` and FE space `FE`) at all nodes of the grid, applying an optional function operator, and write the results into `target`.
278+
279+
By default, the function is evaluated at every node in the mesh. If `continuous` is `false`, the value at each node is averaged over all neighboring cells (suitable for discontinuous quantities). If `continuous` is `true`, the value is taken from a single cell per node (suitable for continuous quantities). The result can optionally be scaled, offset, or restricted to specific regions.
303280
304281
# Arguments
305-
- `target`: Output array to store the evaluated values (size: result dimension × number of nodes per cell, number of cells).
282+
- `target`: Output array to store the evaluated values (size: result dimension × number of nodes).
306283
- `source`: Coefficient vector for the FE function.
307284
- `FE`: The finite element space.
308-
- `operator`: Function operator to apply (default: `Identity`).
285+
- `operator`: Function operator to apply at each node (default: `Identity`).
286+
287+
# Keyword Arguments
309288
- `abs`: If `true`, store the Euclidean norm of the result at each node (default: `false`).
310289
- `factor`: Scaling factor applied to the result (default: `1`).
311290
- `regions`: List of region indices to restrict evaluation (default: all regions).
@@ -316,8 +295,11 @@ Evaluate a finite element function (given by the coefficient vector `source` and
316295
317296
# Notes
318297
- The result dimension is determined by the FE space, the operator, and the `abs` argument.
298+
- The function modifies `target` in-place.
299+
- For vector-valued or higher-dimensional results, the first dimension of `target` corresponds to the result dimension.
300+
319301
"""
320-
function piecewise_nodevalues!(
302+
function nodevalues!(
321303
target::AbstractArray{T, 2},
322304
source::AbstractArray{T, 1},
323305
FE::FESpace{Tv, Ti, FEType, AT},
@@ -327,7 +309,8 @@ function piecewise_nodevalues!(
327309
regions::Array{Int, 1} = [0],
328310
target_offset::Int = 0,
329311
source_offset::Int = 0,
330-
zero_target::Bool = true
312+
zero_target::Bool = true,
313+
continuous::Bool = false
331314
) where {T, Tv, Ti, FEType, AT}
332315

333316
xgrid = FE.dofgrid
@@ -354,11 +337,14 @@ function piecewise_nodevalues!(
354337
fill!(target, 0)
355338
end
356339

340+
nnodes::Int = num_sources(xgrid[Coordinates])
341+
nneighbours::Array{Int, 1} = zeros(Int, nnodes)
342+
flag4node::Array{Bool, 1} = zeros(Bool, nnodes)
343+
357344
function barrier(EG, qf, BE)
358345
node::Int = 0
359346
dof::Ti = 0
360347
weights::Array{T, 1} = qf.w
361-
nweights = length(weights)
362348
basisvals = BE.cvals
363349
ndofs = size(basisvals, 2)
364350
cvals_resultdim::Int = size(basisvals, 1)
@@ -378,32 +364,29 @@ function piecewise_nodevalues!(
378364
for i in eachindex(weights) # vertices
379365
node = xItemNodes[i, item]
380366
fill!(localT, 0)
381-
382-
for dof_i in 1:ndofs
383-
dof = xItemDofs[dof_i, item]
384-
eval_febe!(temp, BE, dof_i, i)
385-
for k in 1:cvals_resultdim
386-
localT[k] += source[source_offset + dof] * temp[k]
387-
#target[k+target_offset,node] += temp[k] * source[source_offset + dof]
388-
end
389-
end
390-
localT .*= factor
391-
if abs
392-
for k in 1:cvals_resultdim
393-
target[target_offset + i, item] += localT[k]^2
367+
if continuous == false || flag4node[node] == false
368+
nneighbours[node] += 1
369+
flag4node[node] = true
370+
for dof_i in 1:ndofs
371+
dof = xItemDofs[dof_i, item]
372+
eval_febe!(temp, BE, dof_i, i)
373+
for k in 1:cvals_resultdim
374+
localT[k] += source[source_offset + dof] * temp[k]
375+
#target[k+target_offset,node] += temp[k] * source[source_offset + dof]
376+
end
394377
end
395-
else
396-
for k in 1:cvals_resultdim
397-
target[target_offset + i + (k - 1) * nweights, item] += localT[k]
378+
localT .*= factor
379+
if abs
380+
for k in 1:cvals_resultdim
381+
target[1 + target_offset, node] += localT[k]^2
382+
end
383+
else
384+
for k in 1:cvals_resultdim
385+
target[k + target_offset, node] += localT[k]
386+
end
398387
end
399388
end
400389
end
401-
402-
if abs
403-
for i in 1:nweights
404-
target[i + target_offset, item] = sqrt(target[i + target_offset, item])
405-
end
406-
end
407390
break # region for loop
408391
end # if in region
409392
end # region for loop
@@ -417,38 +400,48 @@ function piecewise_nodevalues!(
417400
barrier(EG[j], qf, BE)
418401
end
419402

403+
404+
if continuous == false
405+
for n in 1:nnodes, k in 1:target_resultdim
406+
if nneighbours[n] > 0
407+
target[k + target_offset, n] /= nneighbours[n]
408+
end
409+
end
410+
end
411+
412+
if abs
413+
for n in 1:nnodes
414+
target[1 + target_offset, n] = sqrt(target[1 + target_offset, n])
415+
end
416+
end
417+
420418
return nothing
421419
end
422420

423-
424421
"""
425422
````
426-
function nodevalues!(
427-
target::AbstractArray{<:Real,2},
428-
source::AbstractArray{T,1},
429-
FE::FESpace{Tv,Ti,FEType,AT},
423+
piecewise_nodevalues!(
424+
target::AbstractArray{T, 2},
425+
source::AbstractArray{T, 1},
426+
FE::FESpace{Tv, Ti, FEType, AT},
430427
operator::Type{<:AbstractFunctionOperator} = Identity;
431428
abs::Bool = false,
432429
factor = 1,
433-
regions::Array{Int,1} = [0],
430+
regions::Array{Int, 1} = [0],
434431
target_offset::Int = 0,
435432
source_offset::Int = 0,
436433
zero_target::Bool = true,
437434
continuous::Bool = false
438435
)
439436
````
440437
441-
Evaluate a finite element function (given by the coefficient vector `source` and FE space `FE`) at all nodes of the grid, applying an optional function operator, and write the results into `target`.
442-
443-
By default, the function is evaluated at every node in the mesh. If `continuous` is `false`, the value at each node is averaged over all neighboring cells (suitable for discontinuous quantities). If `continuous` is `true`, the value is taken from a single cell per node (suitable for continuous quantities). The result can optionally be scaled, offset, or restricted to specific regions.
438+
Evaluate a finite element function (given by the coefficient vector `source` and FE space `FE`) at all nodes, but store the results in a piecewise (cellwise) fashion, i.e., for each cell, the values at its local nodes are written into `target`. The result is organized so that each column of `target` corresponds to a cell, and each row corresponds to the values at the cell's nodes.
444439
445440
# Arguments
446-
- `target`: Output array to store the evaluated values (size: result dimension × number of nodes).
441+
- `target`: Output array to store the evaluated values (size: result dimension × number of nodes per cell, number of cells).
447442
- `source`: Coefficient vector for the FE function.
448443
- `FE`: The finite element space.
449-
- `operator`: Function operator to apply at each node (default: `Identity`).
450-
451-
# Keyword Arguments
444+
- `operator`: Function operator to apply (default: `Identity`).
452445
- `abs`: If `true`, store the Euclidean norm of the result at each node (default: `false`).
453446
- `factor`: Scaling factor applied to the result (default: `1`).
454447
- `regions`: List of region indices to restrict evaluation (default: all regions).
@@ -459,11 +452,8 @@ By default, the function is evaluated at every node in the mesh. If `continuous`
459452
460453
# Notes
461454
- The result dimension is determined by the FE space, the operator, and the `abs` argument.
462-
- The function modifies `target` in-place.
463-
- For vector-valued or higher-dimensional results, the first dimension of `target` corresponds to the result dimension.
464-
465455
"""
466-
function nodevalues!(
456+
function piecewise_nodevalues!(
467457
target::AbstractArray{T, 2},
468458
source::AbstractArray{T, 1},
469459
FE::FESpace{Tv, Ti, FEType, AT},
@@ -473,8 +463,7 @@ function nodevalues!(
473463
regions::Array{Int, 1} = [0],
474464
target_offset::Int = 0,
475465
source_offset::Int = 0,
476-
zero_target::Bool = true,
477-
continuous::Bool = false
466+
zero_target::Bool = true
478467
) where {T, Tv, Ti, FEType, AT}
479468

480469
xgrid = FE.dofgrid
@@ -501,14 +490,11 @@ function nodevalues!(
501490
fill!(target, 0)
502491
end
503492

504-
nnodes::Int = num_sources(xgrid[Coordinates])
505-
nneighbours::Array{Int, 1} = zeros(Int, nnodes)
506-
flag4node::Array{Bool, 1} = zeros(Bool, nnodes)
507-
508493
function barrier(EG, qf, BE)
509494
node::Int = 0
510495
dof::Ti = 0
511496
weights::Array{T, 1} = qf.w
497+
nweights = length(weights)
512498
basisvals = BE.cvals
513499
ndofs = size(basisvals, 2)
514500
cvals_resultdim::Int = size(basisvals, 1)
@@ -528,27 +514,30 @@ function nodevalues!(
528514
for i in eachindex(weights) # vertices
529515
node = xItemNodes[i, item]
530516
fill!(localT, 0)
531-
if continuous == false || flag4node[node] == false
532-
nneighbours[node] += 1
533-
flag4node[node] = true
534-
for dof_i in 1:ndofs
535-
dof = xItemDofs[dof_i, item]
536-
eval_febe!(temp, BE, dof_i, i)
537-
for k in 1:cvals_resultdim
538-
localT[k] += source[source_offset + dof] * temp[k]
539-
#target[k+target_offset,node] += temp[k] * source[source_offset + dof]
540-
end
517+
518+
for dof_i in 1:ndofs
519+
dof = xItemDofs[dof_i, item]
520+
eval_febe!(temp, BE, dof_i, i)
521+
for k in 1:cvals_resultdim
522+
localT[k] += source[source_offset + dof] * temp[k]
523+
#target[k+target_offset,node] += temp[k] * source[source_offset + dof]
541524
end
542-
localT .*= factor
543-
if abs
544-
for k in 1:cvals_resultdim
545-
target[1 + target_offset, node] += localT[k]^2
546-
end
547-
else
548-
for k in 1:cvals_resultdim
549-
target[k + target_offset, node] += localT[k]
550-
end
525+
end
526+
localT .*= factor
527+
if abs
528+
for k in 1:cvals_resultdim
529+
target[target_offset + i, item] += localT[k]^2
551530
end
531+
else
532+
for k in 1:cvals_resultdim
533+
target[target_offset + i + (k - 1) * nweights, item] += localT[k]
534+
end
535+
end
536+
end
537+
538+
if abs
539+
for i in 1:nweights
540+
target[i + target_offset, item] = sqrt(target[i + target_offset, item])
552541
end
553542
end
554543
break # region for loop
@@ -564,21 +553,6 @@ function nodevalues!(
564553
barrier(EG[j], qf, BE)
565554
end
566555

567-
568-
if continuous == false
569-
for n in 1:nnodes, k in 1:target_resultdim
570-
if nneighbours[n] > 0
571-
target[k + target_offset, n] /= nneighbours[n]
572-
end
573-
end
574-
end
575-
576-
if abs
577-
for n in 1:nnodes
578-
target[1 + target_offset, n] = sqrt(target[1 + target_offset, n])
579-
end
580-
end
581-
582556
return nothing
583557
end
584558

0 commit comments

Comments
 (0)