Skip to content

Commit

Permalink
add some docstrings (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnutAM committed Feb 17, 2022
1 parent 9bfc3ad commit ea716bc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/src/reference/dofhandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ DocTestSetup = :(using Ferrite)

```@docs
DofHandler
CellIterator
ndofs
dof_range
```
8 changes: 7 additions & 1 deletion src/Dofs/DofHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ function Base.show(io::IO, ::MIME"text/plain", dh::DofHandler)
end
end

"""
ndofs(dh::AbstractDofHandler)
Return the number of degrees of freedom in `dh`
"""
ndofs(dh::AbstractDofHandler) = dh.ndofs[]
ndofs_per_cell(dh::AbstractDofHandler, cell::Int=1) = dh.cell_dofs_offset[cell+1] - dh.cell_dofs_offset[cell]
isclosed(dh::AbstractDofHandler) = dh.closed[]
Expand Down Expand Up @@ -81,7 +86,8 @@ end
Return the local dof range for `field_name`. Example:
```jldoctest
julia> grid = generate_grid(Triangle, (3, 3));
julia> grid = generate_grid(Triangle, (3, 3))
Grid{2, Triangle, Float64} with 18 Triangle cells and 16 nodes
julia> dh = DofHandler(grid); push!(dh, :u, 3); push!(dh, :p, 1); close!(dh);
Expand Down
12 changes: 10 additions & 2 deletions src/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@ UpdateFlags(; nodes::Bool=true, coords::Bool=true, celldofs::Bool=true) =

"""
CellIterator(grid::Grid)
CellIterator(grid::DofHandler)
CellIterator(dh::DofHandler)
CellIterator(mdh::MixedDofHandler)
Return a `CellIterator` to conveniently loop over all the cells in a grid.
# Examples
```julia
for cell in CellIterator(grid)
for cell in CellIterator(dh) # dh::DofHandler
coords = getcoordinates(cell) # get the coordinates
dofs = celldofs(cell) # get the dofs for this cell
reinit!(cv, cell) # reinit! the FE-base with a CellIterator
end
```
Here, `cell::CellIterator`. Looking at a specific cell (instead of
looping over all), e.g. nr 10, can be done by
```julia
cell = CellIterator(dh) # Refers to cell nr. 1 upon creation
reinit!(cell, 10) # Update to cell nr. 10
dofs = celldofs(cell) # Get the dofs for cell nr. 10
```
"""
struct CellIterator{dim,C,T,DH<:Union{AbstractDofHandler,Nothing}}
flags::UpdateFlags
Expand Down

0 comments on commit ea716bc

Please sign in to comment.