Skip to content

Commit

Permalink
Remove Ferrite.nfields
Browse files Browse the repository at this point in the history
This patch deprecates the internal function `nfields(dh)` in favor of
`length(getfieldnames(dh))`. The reason is twofold: `nfields` where
barely used, not even internally, and `nfields` was easy to confuse with
the existing `Base.nfields` function that would still work, but behave
quite differently.

Closes #444.
  • Loading branch information
Dennis Ogiermann authored and fredrikekre committed Apr 1, 2023
1 parent a917a24 commit b7a79b7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Internal changes
- `Ferrite.ndim(dh, fieldname)` has been removed, use `Ferrite.getfielddim(dh,
fieldname)` instead. ([#658][github-658])
- `Ferrite.nfields(dh)` has been removed, use `length(Ferrite.getfieldnames(dh))` instead.
([#444][github-444], [#653][github-653])
- `getfielddims(::FieldHandler)` and `getfieldinterpolations(::FieldHandler)` removed ([#647][github-647]) (Note that `getfieldnames(::FieldHandler)` was re-introduced in [#659][github-659])

## [0.3.13] - 2023-03-23
Expand Down Expand Up @@ -297,6 +299,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[github-428]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/428
[github-431]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/431
[github-436]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/436
[github-444]: https://github.com/Ferrite-FEM/Ferrite.jl/issues/444
[github-453]: https://github.com/Ferrite-FEM/Ferrite.jl/issues/453
[github-455]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/455
[github-456]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/456
Expand Down Expand Up @@ -384,9 +387,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[github-621]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/621
[github-633]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/633
[github-645]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/645
[github-647]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/647
[github-650]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/650
[github-653]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/653
[github-658]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/658
[github-647]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/647
[github-659]: https://github.com/Ferrite-FEM/Ferrite.jl/pull/659

[Unreleased]: https://github.com/Ferrite-FEM/Ferrite.jl/compare/v0.3.13...HEAD
Expand Down
15 changes: 8 additions & 7 deletions src/Dofs/DofHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ end
function Base.show(io::IO, ::MIME"text/plain", dh::DofHandler)
println(io, "DofHandler")
println(io, " Fields:")
for i in 1:nfields(dh)
println(io, " ", repr(dh.field_names[i]), ", interpolation: ", dh.field_interpolations[i],", dim: ", dh.field_dims[i])
for (i, name) in pairs(getfieldnames(dh))
println(io, " ", repr(name), ", interpolation: ", dh.field_interpolations[i],", dim: ", dh.field_dims[i])
end
if !isclosed(dh)
print(io, " Not closed!")
Expand All @@ -40,7 +40,6 @@ function Base.show(io::IO, ::MIME"text/plain", dh::DofHandler)
end

ndofs_per_cell(dh::AbstractDofHandler, cell::Int=1) = dh.cell_dofs_offset[cell+1] - dh.cell_dofs_offset[cell]
nfields(dh::AbstractDofHandler) = length(dh.field_names)
getfieldnames(dh::AbstractDofHandler) = dh.field_names

function find_field(dh::DofHandler, field_name::Symbol)
Expand Down Expand Up @@ -124,23 +123,25 @@ end
function __close!(dh::DofHandler{dim}) where {dim}
@assert !isclosed(dh)

numfields = length(dh.field_names)

# `vertexdict` keeps track of the visited vertices. The first dof added to vertex v is
# stored in vertexdict[v]
# TODO: No need to allocate this vector for fields that don't have vertex dofs
vertexdicts = [zeros(Int, getnnodes(dh.grid)) for _ in 1:nfields(dh)]
vertexdicts = [zeros(Int, getnnodes(dh.grid)) for _ in 1:numfields]

# `edgedict` keeps track of the visited edges, this will only be used for a 3D problem
# An edge is determined from two vertices, but we also need to store the direction
# of the first edge we encounter and add dofs too. When we encounter the same edge
# the next time we check if the direction is the same, otherwise we reuse the dofs
# in the reverse order
edgedicts = [Dict{Tuple{Int,Int},Tuple{Int,Bool}}() for _ in 1:nfields(dh)]
edgedicts = [Dict{Tuple{Int,Int},Tuple{Int,Bool}}() for _ in 1:numfields]

# `facedict` keeps track of the visited faces. We only need to store the first dof we
# added to the face; if we encounter the same face again we *always* reverse the order
# In 2D a face (i.e. a line) is uniquely determined by 2 vertices, and in 3D a
# face (i.e. a surface) is uniquely determined by 3 vertices.
facedicts = [Dict{NTuple{dim,Int},Int}() for _ in 1:nfields(dh)]
facedicts = [Dict{NTuple{dim,Int},Int}() for _ in 1:numfields]

# celldofs are never shared between different cells so there is no need
# for a `celldict` to keep track of which cells we have added dofs too.
Expand All @@ -163,7 +164,7 @@ function __close!(dh::DofHandler{dim}) where {dim}
# loop over all the cells, and distribute dofs for all the fields
for (ci, cell) in enumerate(getcells(dh.grid))
@debug println("cell #$ci")
for field_idx in 1:nfields(dh)
for field_idx in 1:numfields
interpolation_info = interpolation_infos[field_idx]
@debug println(" field: $(dh.field_names[field_idx])")
for (vi, vertex) in enumerate(vertices(cell))
Expand Down
3 changes: 2 additions & 1 deletion src/Dofs/DofRenumbering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ Dof order passed to [`renumber!`](@ref) to renumber global dofs field wise resul
globally blocked system.
The default behavior is to group dofs of each field into their own block, with the same
order as in the DofHandler. This can be customized by passing a vector of length `nfields`
order as in the DofHandler. This can be customized by passing a vector of the same length
as the total number of fields in the DofHandler (see `getfieldnames(dh)`)
that maps each field to a "target block": to renumber a DofHandler with three fields `:u`,
`:v`, `:w` such that dofs for `:u` and `:w` end up in the first global block, and dofs for
`:v` in the second global block use `DofOrder.FieldWise([1, 2, 1])`.
Expand Down
7 changes: 0 additions & 7 deletions src/Dofs/MixedDofHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,6 @@ function getfielddim(dh::MixedDofHandler, field_idxs::NTuple{2, Int})
end
getfielddim(dh::MixedDofHandler, name::Symbol) = getfielddim(dh, find_field(dh, name))

"""
nfields(dh::MixedDofHandler)
Returns the number of unique fields defined.
"""
nfields(dh::MixedDofHandler) = length(getfieldnames(dh))

"""
add!(dh::MixedDofHandler, fh::FieldHandler)
Expand Down
3 changes: 2 additions & 1 deletion src/Dofs/sparsity_pattern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ with stored values in the correct places.
The keyword argument `coupling` can be used to specify how fields (or components) in the dof
handler couple to each other. `coupling` should be a square matrix of booleans with
`nfields` (or `ncomponents`) rows/columns with `true` if fields are coupled and `false` if
number of rows/columns equal to the total number of fields, or total number of components,
in the DofHandler with `true` if fields are coupled and `false` if
not. By default full coupling is assumed.
See the [Sparsity Pattern](@ref) section of the manual.
Expand Down
1 change: 1 addition & 0 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ import Base: push!
@deprecate vertices(ip::Interpolation) vertexdof_indices(ip) false
@deprecate faces(ip::Interpolation) facedof_indices(ip) false
@deprecate edges(ip::Interpolation) edgedof_indices(ip) false
@deprecate nfields(dh::AbstractDofHandler) length(getfieldnames(dh)) false

0 comments on commit b7a79b7

Please sign in to comment.