From ea716bc7a73da0b7970f81187b9b8b26ea502598 Mon Sep 17 00:00:00 2001 From: Knut Andreas Meyer Date: Thu, 17 Feb 2022 10:45:44 +0100 Subject: [PATCH] add some docstrings (#414) --- docs/src/reference/dofhandler.md | 3 +++ src/Dofs/DofHandler.jl | 8 +++++++- src/iterators.jl | 12 ++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/src/reference/dofhandler.md b/docs/src/reference/dofhandler.md index 7e36b1fdeb..9b248dcec2 100644 --- a/docs/src/reference/dofhandler.md +++ b/docs/src/reference/dofhandler.md @@ -6,4 +6,7 @@ DocTestSetup = :(using Ferrite) ```@docs DofHandler +CellIterator +ndofs +dof_range ``` diff --git a/src/Dofs/DofHandler.jl b/src/Dofs/DofHandler.jl index 1db8389109..1c214fb334 100644 --- a/src/Dofs/DofHandler.jl +++ b/src/Dofs/DofHandler.jl @@ -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[] @@ -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); diff --git a/src/iterators.jl b/src/iterators.jl index 382232ea75..16877ba910 100644 --- a/src/iterators.jl +++ b/src/iterators.jl @@ -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