Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify evaluate_at_grid_nodes #1097

Merged
merged 6 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/devdocs/FEValues.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Ferrite.BCValues
## Internal utilities
```@docs
Ferrite.embedding_det
Ferrite.shape_value_type
Ferrite.shape_value_type(::Ferrite.AbstractValues)
Ferrite.shape_gradient_type
Ferrite.ValuesUpdateFlags
```
Expand Down
1 change: 1 addition & 0 deletions docs/src/devdocs/interpolations.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Ferrite.reference_shape_values!
Ferrite.reference_shape_gradients!
Ferrite.reference_shape_gradients_and_values!
Ferrite.reference_shape_hessians_gradients_and_values!
Ferrite.shape_value_type(ip::Interpolation, ::Type{T}) where T<:Number
```

### Required methods to implement for all subtypes of `Interpolation` to define a new finite element
Expand Down
27 changes: 7 additions & 20 deletions src/Dofs/DofHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -930,13 +930,13 @@
end

# Internal method that have the vtk option to allocate the output differently
function _evaluate_at_grid_nodes(dh::DofHandler, u::AbstractVector{T}, fieldname::Symbol, ::Val{vtk} = Val(false)) where {T, vtk}
function _evaluate_at_grid_nodes(dh::DofHandler{sdim}, u::AbstractVector{T}, fieldname::Symbol, ::Val{vtk}=Val(false)) where {T, vtk, sdim}

Check warning on line 933 in src/Dofs/DofHandler.jl

View check run for this annotation

Codecov / codecov/patch

src/Dofs/DofHandler.jl#L933

Added line #L933 was not covered by tests
# Make sure the field exists
fieldname ∈ getfieldnames(dh) || error("Field $fieldname not found.")
# Figure out the return type (scalar or vector)
field_idx = find_field(dh, fieldname)
ip = getfieldinterpolation(dh, field_idx)
RT = ip isa ScalarInterpolation ? T : Vec{n_components(ip), T}
RT = shape_value_type(ip, T)

Check warning on line 939 in src/Dofs/DofHandler.jl

View check run for this annotation

Codecov / codecov/patch

src/Dofs/DofHandler.jl#L939

Added line #L939 was not covered by tests
if vtk
# VTK output of solution field (or L2 projected scalar data)
n_c = n_components(ip)
Expand All @@ -957,39 +957,26 @@
ip_geo = geometric_interpolation(CT)
local_node_coords = reference_coordinates(ip_geo)
qr = QuadratureRule{getrefshape(ip)}(zeros(length(local_node_coords)), local_node_coords)
if ip isa VectorizedInterpolation
# TODO: Remove this hack when embedding works...
cv = CellValues(qr, ip.ip, ip_geo)
else
cv = CellValues(qr, ip, ip_geo)
end
cv = CellValues(qr, ip, ip_geo^sdim; update_gradients = false, update_hessians = false, update_detJdV = false)

Check warning on line 960 in src/Dofs/DofHandler.jl

View check run for this annotation

Codecov / codecov/patch

src/Dofs/DofHandler.jl#L960

Added line #L960 was not covered by tests
drange = dof_range(sdh, field_idx)
# Function barrier
_evaluate_at_grid_nodes!(data, sdh, u, cv, drange, RT)
_evaluate_at_grid_nodes!(data, sdh, u, cv, drange)

Check warning on line 963 in src/Dofs/DofHandler.jl

View check run for this annotation

Codecov / codecov/patch

src/Dofs/DofHandler.jl#L963

Added line #L963 was not covered by tests
end
return data
end

# Loop over the cells and use shape functions to compute the value
function _evaluate_at_grid_nodes!(
data::Union{Vector, Matrix}, sdh::SubDofHandler,
u::AbstractVector{T}, cv::CellValues, drange::UnitRange, ::Type{RT}
) where {T, RT}
function _evaluate_at_grid_nodes!(data::Union{Vector,Matrix}, sdh::SubDofHandler,

Check warning on line 969 in src/Dofs/DofHandler.jl

View check run for this annotation

Codecov / codecov/patch

src/Dofs/DofHandler.jl#L969

Added line #L969 was not covered by tests
u::AbstractVector{T}, cv::CellValues, drange::UnitRange) where {T}
ue = zeros(T, length(drange))
# TODO: Remove this hack when embedding works...
if RT <: Vec && function_interpolation(cv) isa ScalarInterpolation
uer = reinterpret(RT, ue)
else
uer = ue
end
for cell in CellIterator(sdh)
# Note: We are only using the shape functions: no reinit!(cv, cell) necessary
@assert getnquadpoints(cv) == length(cell.nodes)
for (i, I) in pairs(drange)
ue[i] = u[cell.dofs[I]]
end
for (qp, nodeid) in pairs(cell.nodes)
val = function_value(cv, qp, uer)
val = function_value(cv, qp, ue)

Check warning on line 979 in src/Dofs/DofHandler.jl

View check run for this annotation

Codecov / codecov/patch

src/Dofs/DofHandler.jl#L979

Added line #L979 was not covered by tests
if data isa Matrix # VTK
data[1:length(val), nodeid] .= val
data[(length(val) + 1):end, nodeid] .= 0 # purge the NaN
Expand Down
11 changes: 11 additions & 0 deletions src/interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@
# Number of components that are allowed to prescribe in e.g. Dirichlet BC
n_dbc_components(ip::Interpolation) = n_components(ip)

"""
shape_value_type(ip::Interpolation, ::Type{T}) where T<:Number

Return the type of `shape_value(ip::Interpolation, ξ::Vec, ib::Int)`.
"""
shape_value_type(::Interpolation, ::Type{T}) where {T <: Number}

shape_value_type(::ScalarInterpolation, ::Type{T}) where {T <: Number} = T
shape_value_type(::VectorInterpolation{vdim}, ::Type{T}) where {vdim, T <: Number} = Vec{vdim, T}

Check warning on line 68 in src/interpolations.jl

View check run for this annotation

Codecov / codecov/patch

src/interpolations.jl#L67-L68

Added lines #L67 - L68 were not covered by tests
#shape_value_type(::MatrixInterpolation, T::Type) = Tensor #958

# TODO: Add a fallback that errors if there are multiple dofs per edge/face instead to force
# interpolations to opt-out instead of silently do nothing.
"""
Expand Down
Loading