Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions .github/workflows/Check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ jobs:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: '1.11'
version: '1.12'
- uses: julia-actions/cache@v3
- uses: fredrikekre/runic-action@v1
with:
version: "1.4" # Keep version in sync with .pre-commit-config.yaml
version: "1.7" # Keep version in sync with .pre-commit-config.yaml
docstrings: true
extensions: 'jl,md'

explicit-imports:
runs-on: ubuntu-latest
Expand Down
8 changes: 6 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: 'https://github.com/fredrikekre/runic-pre-commit'
rev: v2.0.1
rev: v2.2.0
hooks:
- id: runic
args: ["--inplace", "--diff", "--docstrings"]
additional_dependencies:
- 'Runic@1.4' # Keep version in sync with .github/workflows/Check.yml
- 'Runic@1.7' # Keep version in sync with .github/workflows/Check.yml
- id: runic-md
additional_dependencies:
- 'Runic@1.7' # Keep version in sync with .github/workflows/Check.yml
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ more discussion).
# Linear Lagrange interpolation for a vector problem on the triangle (vector dimension
# same as the reference dimension)
ip_scalar = Lagrange{RefTriangle, 1}()
ip_vector = ip_scalar ^ 2 # or VectorizedInterpolation{2}(ip_scalar)
ip_vector = ip_scalar^2 # or VectorizedInterpolation{2}(ip_scalar)
```

- **Quadrature**: remove the first parameter (the reference dimension) and use new reference
Expand Down
4 changes: 2 additions & 2 deletions docs/src/topics/assembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ the row/column which corresponds to the degrees of freedom for the cell:

```julia
K[celldofs, celldofs] += ke
f[celldofs] += fe
f[celldofs] += fe
```

where `celldofs` is the vector containing the degrees of freedom for the cell.
Expand Down Expand Up @@ -57,7 +57,7 @@ which perform the following operations in an efficient manner:

```julia
K[celldofs, celldofs] += ke
f[celldofs] += fe
f[celldofs] += fe
```

## Pseudo-code for efficient assembly
Expand Down
4 changes: 2 additions & 2 deletions docs/src/topics/boundary_conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ the relevant `facetset` by using the [`FacetIterator`](@ref).
For a scalar field, this can be done as

```julia
grid = generate_grid(Quadrilateral, (3,3))
grid = generate_grid(Quadrilateral, (3, 3))
dh = DofHandler(grid); push!(dh, :u, 1); close!(dh)
fv = FacetValues(QuadratureRule{RefQuadrilateral}(2), Lagrange{RefQuadrilateral, 1}())
f = zeros(ndofs(dh))
Expand Down Expand Up @@ -326,7 +326,7 @@ initial conditions can be specified by the [`apply_analytical!`](@ref) function.
For example, specify the initial pressure as a function of the y-coordinate
```julia
ρ = 1000; g = 9.81 # density [kg/m³] and gravity [N/kg]
grid = generate_grid(Quadrilateral, (10,10))
grid = generate_grid(Quadrilateral, (10, 10))
dh = DofHandler(grid); add!(dh, :u, 2); add!(dh, :p, 1); close!(dh)
u = zeros(ndofs(dh))
apply_analytical!(u, dh, :p, x -> ρ * g * x[2])
Expand Down
22 changes: 12 additions & 10 deletions docs/src/topics/grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ Consider the following 2D mesh:
The cells of the grid can be described in the following way

```julia
cells = [Quadrilateral((1, 2, 5, 4)),
Quadrilateral((2, 3, 6, 5)),
Quadrilateral((4, 5, 8, 7)),
Quadrilateral((5, 6, 9, 8))]
cells = [
Quadrilateral((1, 2, 5, 4)),
Quadrilateral((2, 3, 6, 5)),
Quadrilateral((4, 5, 8, 7)),
Quadrilateral((5, 6, 9, 8)),
]
```

where each `Quadrilateral <: AbstractCell` is defined by the tuple of node IDs.
Expand Down Expand Up @@ -106,9 +108,9 @@ In case that certain structures are preserved from the `Ferrite.Grid` type, you
As a starting point, we choose a minimal working example from the test suite:

```julia
struct SmallGrid{dim,N,C<:Ferrite.AbstractCell} <: Ferrite.AbstractGrid{dim}
nodes_test::Vector{NTuple{dim,Float64}}
cells_test::NTuple{N,C}
struct SmallGrid{dim, N, C <: Ferrite.AbstractCell} <: Ferrite.AbstractGrid{dim}
nodes_test::Vector{NTuple{dim, Float64}}
cells_test::NTuple{N, C}
end
```

Expand All @@ -119,7 +121,7 @@ We start with the utility functions that are associated with the cells of the gr
```julia
Ferrite.getcells(grid::SmallGrid) = grid.cells_test
Ferrite.getcells(grid::SmallGrid, v::Union{Int, Vector{Int}}) = grid.cells_test[v]
Ferrite.getncells(grid::SmallGrid{dim,N}) where {dim,N} = N
Ferrite.getncells(grid::SmallGrid{dim, N}) where {dim, N} = N
Ferrite.getcelltype(grid::SmallGrid) = eltype(grid.cells_test)
Ferrite.getcelltype(grid::SmallGrid, i::Int) = typeof(grid.cells_test[i])
```
Expand All @@ -131,8 +133,8 @@ Ferrite.getnodes(grid::SmallGrid) = grid.nodes_test
Ferrite.getnodes(grid::SmallGrid, v::Union{Int, Vector{Int}}) = grid.nodes_test[v]
Ferrite.getnnodes(grid::SmallGrid) = length(grid.nodes_test)
Ferrite.get_coordinate_eltype(::SmallGrid) = Float64
Ferrite.get_coordinate_type(::SmallGrid{dim}) where dim = Vec{dim,Float64}
Ferrite.nnodes_per_cell(grid::SmallGrid, i::Int=1) = Ferrite.nnodes(grid.cells_test[i])
Ferrite.get_coordinate_type(::SmallGrid{dim}) where {dim} = Vec{dim, Float64}
Ferrite.nnodes_per_cell(grid::SmallGrid, i::Int = 1) = Ferrite.nnodes(grid.cells_test[i])
```

These definitions make many of Ferrite functions work out of the box, e.g. you can now call
Expand Down
34 changes: 18 additions & 16 deletions src/Dofs/ConstraintHandler.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# abstract type Constraint end
"""
Dirichlet(u::Symbol, ∂Ω::AbstractVecOrSet, f::Function, components=nothing)
Dirichlet(u::Symbol, ∂Ω::AbstractVecOrSet, f::Function, components = nothing)

Create a Dirichlet boundary condition on `u` on the `∂Ω` part of
the boundary. `f` is a function of the form `f(x)` or `f(x, t)`
Expand Down Expand Up @@ -135,7 +135,7 @@ end

const DofCoefficients{T} = Vector{Pair{Int, T}}
"""
AffineConstraint(constrained_dof::Int, entries::Vector{Pair{Int,T}}, b::T) where T
AffineConstraint(constrained_dof::Int, entries::Vector{Pair{Int, T}}, b::T) where {T}

Define an affine/linear constraint to constrain one degree of freedom, `u[i]`,
such that `u[i] = ∑(u[j] * a[j]) + b`,
Expand All @@ -148,7 +148,7 @@ struct AffineConstraint{T}
end

"""
ConstraintHandler([T=Float64], dh::AbstractDofHandler)
ConstraintHandler([T = Float64], dh::AbstractDofHandler)

A collection of constraints associated with the dof handler `dh`.
`T` is the numeric type for stored values.
Expand Down Expand Up @@ -208,7 +208,7 @@ function get_rhs_data(ch::ConstraintHandler, A::SparseMatrixCSC)
end

"""
apply_rhs!(data::RHSData, f::AbstractVector, ch::ConstraintHandler, applyzero::Bool=false)
apply_rhs!(data::RHSData, f::AbstractVector, ch::ConstraintHandler, applyzero::Bool = false)

Applies the boundary condition to the right-hand-side vector without modifying the stiffness matrix.

Expand Down Expand Up @@ -349,7 +349,7 @@ function add!(ch::ConstraintHandler, ac::AffineConstraint)
end

"""
add_prescribed_dof!(ch, constrained_dof::Int, inhomogeneity, dofcoefficients=nothing)
add_prescribed_dof!(ch, constrained_dof::Int, inhomogeneity, dofcoefficients = nothing)

Add a constrained dof directly to the `ConstraintHandler`.
This function checks if the `constrained_dof` is already constrained, and overrides the old
Expand Down Expand Up @@ -468,7 +468,7 @@ function _add!(ch::ConstraintHandler, dbc::Dirichlet, bcnodes::AbstractVecOrSet{
end

"""
update!(ch::ConstraintHandler, time::Real=0.0)
update!(ch::ConstraintHandler, time::Real = 0.0)

Update time-dependent inhomogeneities for the new time. This calls `f(x)` or `f(x, t)` when
applicable, where `f` is the function(s) corresponding to the constraints in the handler, to
Expand Down Expand Up @@ -1011,9 +1011,9 @@ struct PeriodicFacetPair
end

"""
PeriodicDirichlet(u::Symbol, facet_mapping, components=nothing)
PeriodicDirichlet(u::Symbol, facet_mapping, R::AbstractMatrix, components=nothing)
PeriodicDirichlet(u::Symbol, facet_mapping, f::Function, components=nothing)
PeriodicDirichlet(u::Symbol, facet_mapping, components = nothing)
PeriodicDirichlet(u::Symbol, facet_mapping, R::AbstractMatrix, components = nothing)
PeriodicDirichlet(u::Symbol, facet_mapping, f::Function, components = nothing)

Create a periodic Dirichlet boundary condition for the field `u` on the facet-pairs given in
`facet_mapping`. The mapping can be computed with [`collect_periodic_facets`](@ref). The
Expand Down Expand Up @@ -1373,7 +1373,7 @@ function rotate_local_dofs(local_facet_dofs, local_facet_dofs_offset, ip::Lagran
end

"""
collect_periodic_facets(grid::Grid, mset, iset, transform::Union{Function,Nothing}=nothing; tol=1e-12)
collect_periodic_facets(grid::Grid, mset, iset, transform::Union{Function, Nothing} = nothing; tol = 1.0e-12)

Match all mirror facets in `mset` with a corresponding image facet in `iset`. Return a
dictionary which maps each mirror facet to a image facet. The result can then be passed to
Expand All @@ -1397,7 +1397,7 @@ function collect_periodic_facets(grid::Grid, mset::Union{AbstractSet{FacetIndex}
end

"""
collect_periodic_facets(grid::Grid, all_facets::Union{AbstractSet{FacetIndex},String,Nothing}=nothing; tol=1e-12)
collect_periodic_facets(grid::Grid, all_facets::Union{AbstractSet{FacetIndex}, String, Nothing} = nothing; tol = 1.0e-12)

Split all facets in `all_facets` into image and mirror sets. For each matching pair, the facet
located further along the vector `(1, 1, 1)` becomes the image facet.
Expand All @@ -1413,7 +1413,7 @@ end


"""
collect_periodic_facets!(facet_map::Vector{PeriodicFacetPair}, grid::Grid, mset, iset, transform::Union{Function,Nothing}; tol=1e-12)
collect_periodic_facets!(facet_map::Vector{PeriodicFacetPair}, grid::Grid, mset, iset, transform::Union{Function, Nothing}; tol = 1.0e-12)

Same as [`collect_periodic_facets`](@ref) but adds all matches to the existing `facet_map`.
"""
Expand Down Expand Up @@ -1793,10 +1793,12 @@ end
@noinline missing_global() = error("can not condense constraint without the global matrix and vector")

"""
_condense_local!(local_matrix::AbstractMatrix, local_vector::AbstractVector,
global_matrix#=::SparseMatrixCSC=#, global_vector#=::Vector=#,
global_dofs::AbstractVector, dofmapping::Dict, dofcoefficients::Vector,
isconstrained::BitVector)
_condense_local!(
local_matrix::AbstractMatrix, local_vector::AbstractVector,
global_matrix #=::SparseMatrixCSC=#, global_vector #=::Vector=#,
global_dofs::AbstractVector, dofmapping::Dict, dofcoefficients::Vector,
isconstrained::BitVector
)

Condensation of affine constraints on element level. If possible this function only
modifies the local arrays.
Expand Down
24 changes: 12 additions & 12 deletions src/Dofs/DofHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ n_components(sdh::SubDofHandler, field_idx::Int) = n_components(sdh.field_interp
n_components(sdh::SubDofHandler, field_name::Symbol) = n_components(sdh, find_field(sdh, field_name))

"""
n_components(dh::DofHandler, field_idxs::NTuple{2,Int})
n_components(dh::DofHandler, field_idxs::NTuple{2, Int})
n_components(dh::DofHandler, field_name::Symbol)
n_components(sdh::SubDofHandler, field_idx::Int)
n_components(sdh::SubDofHandler, field_name::Symbol)
Expand Down Expand Up @@ -663,7 +663,7 @@ described therein.
end

"""
sortedge(edge::Tuple{Int,Int})
sortedge(edge::Tuple{Int, Int})

Returns the unique representation of an edge and its orientation.
Here the unique representation is the sorted node index tuple. The
Expand All @@ -688,9 +688,9 @@ end

"""
sortface(face::Tuple{Int})
sortface(face::Tuple{Int,Int})
sortface(face::Tuple{Int,Int,Int})
sortface(face::Tuple{Int,Int,Int,Int})
sortface(face::Tuple{Int, Int})
sortface(face::Tuple{Int, Int, Int})
sortface(face::Tuple{Int, Int, Int, Int})

Returns the unique representation of a face.
Here the unique representation is the sorted node index tuple.
Expand All @@ -701,9 +701,9 @@ function sortface end

"""
sortface_fast(face::Tuple{Int})
sortface_fast(face::Tuple{Int,Int})
sortface_fast(face::Tuple{Int,Int,Int})
sortface_fast(face::Tuple{Int,Int,Int,Int})
sortface_fast(face::Tuple{Int, Int})
sortface_fast(face::Tuple{Int, Int, Int})
sortface_fast(face::Tuple{Int, Int, Int, Int})

Returns the unique representation of a face.
Here the unique representation is the sorted node index tuple.
Expand Down Expand Up @@ -799,7 +799,7 @@ sortfacet_fast(facet::NTuple{3, Int}) = sortface_fast(facet)
sortfacet_fast(facet::NTuple{4, Int}) = sortface_fast(facet)

"""
find_field(dh::DofHandler, field_name::Symbol)::NTuple{2,Int}
find_field(dh::DofHandler, field_name::Symbol)::NTuple{2, Int}

Return the index of the field with name `field_name` in a `DofHandler`. The index is a
`NTuple{2,Int}`, where the 1st entry is the index of the `SubDofHandler` within which the
Expand Down Expand Up @@ -886,7 +886,7 @@ julia> dof_range(dh, :u)
julia> dof_range(dh, :p)
10:12

julia> dof_range(dh, (1,1)) # field :u
julia> dof_range(dh, (1, 1)) # field :u
1:9

julia> dof_range(dh.subdofhandlers[1], 2) # field :p
Expand All @@ -910,7 +910,7 @@ function dof_range(dh::DofHandler, field_name::Symbol)
end

"""
getfieldinterpolation(dh::DofHandler, field_idxs::NTuple{2,Int})
getfieldinterpolation(dh::DofHandler, field_idxs::NTuple{2, Int})
getfieldinterpolation(sdh::SubDofHandler, field_idx::Int)
getfieldinterpolation(sdh::SubDofHandler, field_name::Symbol)

Expand All @@ -926,7 +926,7 @@ getfieldinterpolation(sdh::SubDofHandler, field_idx::Int) = sdh.field_interpolat
getfieldinterpolation(sdh::SubDofHandler, field_name::Symbol) = getfieldinterpolation(sdh, find_field(sdh, field_name))

"""
evaluate_at_grid_nodes(dh::AbstractDofHandler, u::AbstractVector{T}, fieldname::Symbol) where T
evaluate_at_grid_nodes(dh::AbstractDofHandler, u::AbstractVector{T}, fieldname::Symbol) where {T}

Evaluate the approximated solution for field `fieldname` at the node
coordinates of the grid given the Dof handler `dh` and the solution vector `u`.
Expand Down
3 changes: 2 additions & 1 deletion src/Dofs/apply_analytical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ end
"""
apply_analytical!(
a::AbstractVector, dh::AbstractDofHandler, fieldname::Symbol,
f::Function, cellset=1:getncells(get_grid(dh)))
f::Function, cellset = 1:getncells(get_grid(dh))
)

Apply a solution `f(x)` by modifying the values in the degree of freedom vector `a`
pertaining to the field `fieldname` for all cells in `cellset`.
Expand Down
4 changes: 2 additions & 2 deletions src/Export/VTK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function component_names(::Type{S}) where {S}
end

"""
write_solution(vtk::VTKGridFile, dh::AbstractDofHandler, u::AbstractVector, suffix="")
write_solution(vtk::VTKGridFile, dh::AbstractDofHandler, u::AbstractVector, suffix = "")

Save the values at the nodes in the degree of freedom vector `u` to `vtk`.
Each field in `dh` will be saved separately, and `suffix` can be used to append
Expand Down Expand Up @@ -363,7 +363,7 @@ function write_constraints(vtk, ch::ConstraintHandler)
end

"""
write_cell_colors(vtk::VTKGridFile, grid::AbstractGrid, cell_colors, name="coloring")
write_cell_colors(vtk::VTKGridFile, grid::AbstractGrid, cell_colors, name = "coloring")

Write cell colors (see [`create_coloring`](@ref)) to a VTK file for visualization.

Expand Down
2 changes: 1 addition & 1 deletion src/FEValues/InterfaceValues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function reinit!(
end

"""
getnormal(iv::InterfaceValues, qp::Int; here::Bool=true)
getnormal(iv::InterfaceValues, qp::Int; here::Bool = true)

Return the normal vector in the quadrature point `qp` on the interface. If `here = true`
(default) the outward normal to the "here" element is returned, otherwise the outward normal
Expand Down
2 changes: 1 addition & 1 deletion src/Grid/coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const GREEDY = ColoringAlgorithm.Greedy
const WORKSTREAM = ColoringAlgorithm.WorkStream

"""
create_coloring(g::Grid, cellset=1:getncells(g); alg::ColoringAlgorithm)
create_coloring(g::Grid, cellset = 1:getncells(g); alg::ColoringAlgorithm)

Create a coloring of the cells in grid `g` such that no neighboring cells
have the same color. If only a subset of cells should be colored, the cells to color can be specified by `cellset`.
Expand Down
4 changes: 2 additions & 2 deletions src/Grid/grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ function transform_coordinates!(g::AbstractGrid, f::Function)
end

"""
getcoordinates(grid::AbstractGrid, idx::Union{Int,CellIndex})
getcoordinates(grid::AbstractGrid, idx::Union{Int, CellIndex})
getcoordinates(cache::CellCache)

Get a vector with the coordinates of the cell corresponding to `idx` or `cache`
Expand All @@ -595,7 +595,7 @@ end
@inline getcoordinates(grid::AbstractGrid, cell::CellIndex) = getcoordinates(grid, cell.idx)

"""
getcoordinates!(x::Vector{<:Vec}, grid::AbstractGrid, idx::Union{Int,CellIndex})
getcoordinates!(x::Vector{<:Vec}, grid::AbstractGrid, idx::Union{Int, CellIndex})
getcoordinates!(x::Vector{<:Vec}, grid::AbstractGrid, cell::AbstractCell)

Mutate `x` to the coordinates of the cell corresponding to `idx` or `cell`.
Expand Down
Loading
Loading