Skip to content

Commit 6878471

Browse files
committed
Format embedded Julia source code in docstrings and markdown files
1 parent 4eec1a3 commit 6878471

22 files changed

Lines changed: 93 additions & 80 deletions

.github/workflows/Check.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ jobs:
2323
- uses: actions/checkout@v6
2424
- uses: julia-actions/setup-julia@v2
2525
with:
26-
version: '1.11'
26+
version: '1.12'
2727
- uses: julia-actions/cache@v3
2828
- uses: fredrikekre/runic-action@v1
2929
with:
30-
version: "1.4" # Keep version in sync with .pre-commit-config.yaml
30+
version: "1.7" # Keep version in sync with .pre-commit-config.yaml
31+
docstrings: true
32+
extensions: 'jl,md'
3133

3234
explicit-imports:
3335
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ repos:
1010
- id: mixed-line-ending
1111
- id: trailing-whitespace
1212
- repo: 'https://github.com/fredrikekre/runic-pre-commit'
13-
rev: v2.0.1
13+
rev: v2.2.0
1414
hooks:
1515
- id: runic
16+
args: ["--inplace", "--diff", "--docstrings"]
1617
additional_dependencies:
17-
- 'Runic@1.4' # Keep version in sync with .github/workflows/Check.yml
18+
- 'Runic@1.7' # Keep version in sync with .github/workflows/Check.yml
19+
- id: runic-md
20+
additional_dependencies:
21+
- 'Runic@1.7' # Keep version in sync with .github/workflows/Check.yml

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ more discussion).
161161
# Linear Lagrange interpolation for a vector problem on the triangle (vector dimension
162162
# same as the reference dimension)
163163
ip_scalar = Lagrange{RefTriangle, 1}()
164-
ip_vector = ip_scalar ^ 2 # or VectorizedInterpolation{2}(ip_scalar)
164+
ip_vector = ip_scalar^2 # or VectorizedInterpolation{2}(ip_scalar)
165165
```
166166

167167
- **Quadrature**: remove the first parameter (the reference dimension) and use new reference

docs/src/topics/assembly.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ the row/column which corresponds to the degrees of freedom for the cell:
1414

1515
```julia
1616
K[celldofs, celldofs] += ke
17-
f[celldofs] += fe
17+
f[celldofs] += fe
1818
```
1919

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

5858
```julia
5959
K[celldofs, celldofs] += ke
60-
f[celldofs] += fe
60+
f[celldofs] += fe
6161
```
6262

6363
## Pseudo-code for efficient assembly

docs/src/topics/boundary_conditions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ the relevant `facetset` by using the [`FacetIterator`](@ref).
123123
For a scalar field, this can be done as
124124

125125
```julia
126-
grid = generate_grid(Quadrilateral, (3,3))
126+
grid = generate_grid(Quadrilateral, (3, 3))
127127
dh = DofHandler(grid); push!(dh, :u, 1); close!(dh)
128128
fv = FacetValues(QuadratureRule{RefQuadrilateral}(2), Lagrange{RefQuadrilateral, 1}())
129129
f = zeros(ndofs(dh))
@@ -326,7 +326,7 @@ initial conditions can be specified by the [`apply_analytical!`](@ref) function.
326326
For example, specify the initial pressure as a function of the y-coordinate
327327
```julia
328328
ρ = 1000; g = 9.81 # density [kg/m³] and gravity [N/kg]
329-
grid = generate_grid(Quadrilateral, (10,10))
329+
grid = generate_grid(Quadrilateral, (10, 10))
330330
dh = DofHandler(grid); add!(dh, :u, 2); add!(dh, :p, 1); close!(dh)
331331
u = zeros(ndofs(dh))
332332
apply_analytical!(u, dh, :p, x -> ρ * g * x[2])

docs/src/topics/grid.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ Consider the following 2D mesh:
6262
The cells of the grid can be described in the following way
6363

6464
```julia
65-
cells = [Quadrilateral((1, 2, 5, 4)),
66-
Quadrilateral((2, 3, 6, 5)),
67-
Quadrilateral((4, 5, 8, 7)),
68-
Quadrilateral((5, 6, 9, 8))]
65+
cells = [
66+
Quadrilateral((1, 2, 5, 4)),
67+
Quadrilateral((2, 3, 6, 5)),
68+
Quadrilateral((4, 5, 8, 7)),
69+
Quadrilateral((5, 6, 9, 8)),
70+
]
6971
```
7072

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

108110
```julia
109-
struct SmallGrid{dim,N,C<:Ferrite.AbstractCell} <: Ferrite.AbstractGrid{dim}
110-
nodes_test::Vector{NTuple{dim,Float64}}
111-
cells_test::NTuple{N,C}
111+
struct SmallGrid{dim, N, C <: Ferrite.AbstractCell} <: Ferrite.AbstractGrid{dim}
112+
nodes_test::Vector{NTuple{dim, Float64}}
113+
cells_test::NTuple{N, C}
112114
end
113115
```
114116

@@ -119,7 +121,7 @@ We start with the utility functions that are associated with the cells of the gr
119121
```julia
120122
Ferrite.getcells(grid::SmallGrid) = grid.cells_test
121123
Ferrite.getcells(grid::SmallGrid, v::Union{Int, Vector{Int}}) = grid.cells_test[v]
122-
Ferrite.getncells(grid::SmallGrid{dim,N}) where {dim,N} = N
124+
Ferrite.getncells(grid::SmallGrid{dim, N}) where {dim, N} = N
123125
Ferrite.getcelltype(grid::SmallGrid) = eltype(grid.cells_test)
124126
Ferrite.getcelltype(grid::SmallGrid, i::Int) = typeof(grid.cells_test[i])
125127
```
@@ -131,8 +133,8 @@ Ferrite.getnodes(grid::SmallGrid) = grid.nodes_test
131133
Ferrite.getnodes(grid::SmallGrid, v::Union{Int, Vector{Int}}) = grid.nodes_test[v]
132134
Ferrite.getnnodes(grid::SmallGrid) = length(grid.nodes_test)
133135
Ferrite.get_coordinate_eltype(::SmallGrid) = Float64
134-
Ferrite.get_coordinate_type(::SmallGrid{dim}) where dim = Vec{dim,Float64}
135-
Ferrite.nnodes_per_cell(grid::SmallGrid, i::Int=1) = Ferrite.nnodes(grid.cells_test[i])
136+
Ferrite.get_coordinate_type(::SmallGrid{dim}) where {dim} = Vec{dim, Float64}
137+
Ferrite.nnodes_per_cell(grid::SmallGrid, i::Int = 1) = Ferrite.nnodes(grid.cells_test[i])
136138
```
137139

138140
These definitions make many of Ferrite functions work out of the box, e.g. you can now call

src/Dofs/ConstraintHandler.jl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# abstract type Constraint end
22
"""
3-
Dirichlet(u::Symbol, ∂Ω::AbstractVecOrSet, f::Function, components=nothing)
3+
Dirichlet(u::Symbol, ∂Ω::AbstractVecOrSet, f::Function, components = nothing)
44
55
Create a Dirichlet boundary condition on `u` on the `∂Ω` part of
66
the boundary. `f` is a function of the form `f(x)` or `f(x, t)`
@@ -135,7 +135,7 @@ end
135135

136136
const DofCoefficients{T} = Vector{Pair{Int, T}}
137137
"""
138-
AffineConstraint(constrained_dof::Int, entries::Vector{Pair{Int,T}}, b::T) where T
138+
AffineConstraint(constrained_dof::Int, entries::Vector{Pair{Int, T}}, b::T) where {T}
139139
140140
Define an affine/linear constraint to constrain one degree of freedom, `u[i]`,
141141
such that `u[i] = ∑(u[j] * a[j]) + b`,
@@ -148,7 +148,7 @@ struct AffineConstraint{T}
148148
end
149149

150150
"""
151-
ConstraintHandler([T=Float64], dh::AbstractDofHandler)
151+
ConstraintHandler([T = Float64], dh::AbstractDofHandler)
152152
153153
A collection of constraints associated with the dof handler `dh`.
154154
`T` is the numeric type for stored values.
@@ -208,7 +208,7 @@ function get_rhs_data(ch::ConstraintHandler, A::SparseMatrixCSC)
208208
end
209209

210210
"""
211-
apply_rhs!(data::RHSData, f::AbstractVector, ch::ConstraintHandler, applyzero::Bool=false)
211+
apply_rhs!(data::RHSData, f::AbstractVector, ch::ConstraintHandler, applyzero::Bool = false)
212212
213213
Applies the boundary condition to the right-hand-side vector without modifying the stiffness matrix.
214214
@@ -349,7 +349,7 @@ function add!(ch::ConstraintHandler, ac::AffineConstraint)
349349
end
350350

351351
"""
352-
add_prescribed_dof!(ch, constrained_dof::Int, inhomogeneity, dofcoefficients=nothing)
352+
add_prescribed_dof!(ch, constrained_dof::Int, inhomogeneity, dofcoefficients = nothing)
353353
354354
Add a constrained dof directly to the `ConstraintHandler`.
355355
This function checks if the `constrained_dof` is already constrained, and overrides the old
@@ -468,7 +468,7 @@ function _add!(ch::ConstraintHandler, dbc::Dirichlet, bcnodes::AbstractVecOrSet{
468468
end
469469

470470
"""
471-
update!(ch::ConstraintHandler, time::Real=0.0)
471+
update!(ch::ConstraintHandler, time::Real = 0.0)
472472
473473
Update time-dependent inhomogeneities for the new time. This calls `f(x)` or `f(x, t)` when
474474
applicable, where `f` is the function(s) corresponding to the constraints in the handler, to
@@ -1011,9 +1011,9 @@ struct PeriodicFacetPair
10111011
end
10121012

10131013
"""
1014-
PeriodicDirichlet(u::Symbol, facet_mapping, components=nothing)
1015-
PeriodicDirichlet(u::Symbol, facet_mapping, R::AbstractMatrix, components=nothing)
1016-
PeriodicDirichlet(u::Symbol, facet_mapping, f::Function, components=nothing)
1014+
PeriodicDirichlet(u::Symbol, facet_mapping, components = nothing)
1015+
PeriodicDirichlet(u::Symbol, facet_mapping, R::AbstractMatrix, components = nothing)
1016+
PeriodicDirichlet(u::Symbol, facet_mapping, f::Function, components = nothing)
10171017
10181018
Create a periodic Dirichlet boundary condition for the field `u` on the facet-pairs given in
10191019
`facet_mapping`. The mapping can be computed with [`collect_periodic_facets`](@ref). The
@@ -1373,7 +1373,7 @@ function rotate_local_dofs(local_facet_dofs, local_facet_dofs_offset, ip::Lagran
13731373
end
13741374

13751375
"""
1376-
collect_periodic_facets(grid::Grid, mset, iset, transform::Union{Function,Nothing}=nothing; tol=1e-12)
1376+
collect_periodic_facets(grid::Grid, mset, iset, transform::Union{Function, Nothing} = nothing; tol = 1.0e-12)
13771377
13781378
Match all mirror facets in `mset` with a corresponding image facet in `iset`. Return a
13791379
dictionary which maps each mirror facet to a image facet. The result can then be passed to
@@ -1397,7 +1397,7 @@ function collect_periodic_facets(grid::Grid, mset::Union{AbstractSet{FacetIndex}
13971397
end
13981398

13991399
"""
1400-
collect_periodic_facets(grid::Grid, all_facets::Union{AbstractSet{FacetIndex},String,Nothing}=nothing; tol=1e-12)
1400+
collect_periodic_facets(grid::Grid, all_facets::Union{AbstractSet{FacetIndex}, String, Nothing} = nothing; tol = 1.0e-12)
14011401
14021402
Split all facets in `all_facets` into image and mirror sets. For each matching pair, the facet
14031403
located further along the vector `(1, 1, 1)` becomes the image facet.
@@ -1413,7 +1413,7 @@ end
14131413

14141414

14151415
"""
1416-
collect_periodic_facets!(facet_map::Vector{PeriodicFacetPair}, grid::Grid, mset, iset, transform::Union{Function,Nothing}; tol=1e-12)
1416+
collect_periodic_facets!(facet_map::Vector{PeriodicFacetPair}, grid::Grid, mset, iset, transform::Union{Function, Nothing}; tol = 1.0e-12)
14171417
14181418
Same as [`collect_periodic_facets`](@ref) but adds all matches to the existing `facet_map`.
14191419
"""
@@ -1793,10 +1793,12 @@ end
17931793
@noinline missing_global() = error("can not condense constraint without the global matrix and vector")
17941794

17951795
"""
1796-
_condense_local!(local_matrix::AbstractMatrix, local_vector::AbstractVector,
1797-
global_matrix#=::SparseMatrixCSC=#, global_vector#=::Vector=#,
1798-
global_dofs::AbstractVector, dofmapping::Dict, dofcoefficients::Vector,
1799-
isconstrained::BitVector)
1796+
_condense_local!(
1797+
local_matrix::AbstractMatrix, local_vector::AbstractVector,
1798+
global_matrix #=::SparseMatrixCSC=#, global_vector #=::Vector=#,
1799+
global_dofs::AbstractVector, dofmapping::Dict, dofcoefficients::Vector,
1800+
isconstrained::BitVector
1801+
)
18001802
18011803
Condensation of affine constraints on element level. If possible this function only
18021804
modifies the local arrays.

src/Dofs/DofHandler.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ n_components(sdh::SubDofHandler, field_idx::Int) = n_components(sdh.field_interp
251251
n_components(sdh::SubDofHandler, field_name::Symbol) = n_components(sdh, find_field(sdh, field_name))
252252

253253
"""
254-
n_components(dh::DofHandler, field_idxs::NTuple{2,Int})
254+
n_components(dh::DofHandler, field_idxs::NTuple{2, Int})
255255
n_components(dh::DofHandler, field_name::Symbol)
256256
n_components(sdh::SubDofHandler, field_idx::Int)
257257
n_components(sdh::SubDofHandler, field_name::Symbol)
@@ -663,7 +663,7 @@ described therein.
663663
end
664664

665665
"""
666-
sortedge(edge::Tuple{Int,Int})
666+
sortedge(edge::Tuple{Int, Int})
667667
668668
Returns the unique representation of an edge and its orientation.
669669
Here the unique representation is the sorted node index tuple. The
@@ -688,9 +688,9 @@ end
688688

689689
"""
690690
sortface(face::Tuple{Int})
691-
sortface(face::Tuple{Int,Int})
692-
sortface(face::Tuple{Int,Int,Int})
693-
sortface(face::Tuple{Int,Int,Int,Int})
691+
sortface(face::Tuple{Int, Int})
692+
sortface(face::Tuple{Int, Int, Int})
693+
sortface(face::Tuple{Int, Int, Int, Int})
694694
695695
Returns the unique representation of a face.
696696
Here the unique representation is the sorted node index tuple.
@@ -701,9 +701,9 @@ function sortface end
701701

702702
"""
703703
sortface_fast(face::Tuple{Int})
704-
sortface_fast(face::Tuple{Int,Int})
705-
sortface_fast(face::Tuple{Int,Int,Int})
706-
sortface_fast(face::Tuple{Int,Int,Int,Int})
704+
sortface_fast(face::Tuple{Int, Int})
705+
sortface_fast(face::Tuple{Int, Int, Int})
706+
sortface_fast(face::Tuple{Int, Int, Int, Int})
707707
708708
Returns the unique representation of a face.
709709
Here the unique representation is the sorted node index tuple.
@@ -799,7 +799,7 @@ sortfacet_fast(facet::NTuple{3, Int}) = sortface_fast(facet)
799799
sortfacet_fast(facet::NTuple{4, Int}) = sortface_fast(facet)
800800

801801
"""
802-
find_field(dh::DofHandler, field_name::Symbol)::NTuple{2,Int}
802+
find_field(dh::DofHandler, field_name::Symbol)::NTuple{2, Int}
803803
804804
Return the index of the field with name `field_name` in a `DofHandler`. The index is a
805805
`NTuple{2,Int}`, where the 1st entry is the index of the `SubDofHandler` within which the
@@ -886,7 +886,7 @@ julia> dof_range(dh, :u)
886886
julia> dof_range(dh, :p)
887887
10:12
888888
889-
julia> dof_range(dh, (1,1)) # field :u
889+
julia> dof_range(dh, (1, 1)) # field :u
890890
1:9
891891
892892
julia> dof_range(dh.subdofhandlers[1], 2) # field :p
@@ -910,7 +910,7 @@ function dof_range(dh::DofHandler, field_name::Symbol)
910910
end
911911

912912
"""
913-
getfieldinterpolation(dh::DofHandler, field_idxs::NTuple{2,Int})
913+
getfieldinterpolation(dh::DofHandler, field_idxs::NTuple{2, Int})
914914
getfieldinterpolation(sdh::SubDofHandler, field_idx::Int)
915915
getfieldinterpolation(sdh::SubDofHandler, field_name::Symbol)
916916
@@ -926,7 +926,7 @@ getfieldinterpolation(sdh::SubDofHandler, field_idx::Int) = sdh.field_interpolat
926926
getfieldinterpolation(sdh::SubDofHandler, field_name::Symbol) = getfieldinterpolation(sdh, find_field(sdh, field_name))
927927

928928
"""
929-
evaluate_at_grid_nodes(dh::AbstractDofHandler, u::AbstractVector{T}, fieldname::Symbol) where T
929+
evaluate_at_grid_nodes(dh::AbstractDofHandler, u::AbstractVector{T}, fieldname::Symbol) where {T}
930930
931931
Evaluate the approximated solution for field `fieldname` at the node
932932
coordinates of the grid given the Dof handler `dh` and the solution vector `u`.

src/Dofs/apply_analytical.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ end
77
"""
88
apply_analytical!(
99
a::AbstractVector, dh::AbstractDofHandler, fieldname::Symbol,
10-
f::Function, cellset=1:getncells(get_grid(dh)))
10+
f::Function, cellset = 1:getncells(get_grid(dh))
11+
)
1112
1213
Apply a solution `f(x)` by modifying the values in the degree of freedom vector `a`
1314
pertaining to the field `fieldname` for all cells in `cellset`.

src/Export/VTK.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function component_names(::Type{S}) where {S}
195195
end
196196

197197
"""
198-
write_solution(vtk::VTKGridFile, dh::AbstractDofHandler, u::AbstractVector, suffix="")
198+
write_solution(vtk::VTKGridFile, dh::AbstractDofHandler, u::AbstractVector, suffix = "")
199199
200200
Save the values at the nodes in the degree of freedom vector `u` to `vtk`.
201201
Each field in `dh` will be saved separately, and `suffix` can be used to append
@@ -363,7 +363,7 @@ function write_constraints(vtk, ch::ConstraintHandler)
363363
end
364364

365365
"""
366-
write_cell_colors(vtk::VTKGridFile, grid::AbstractGrid, cell_colors, name="coloring")
366+
write_cell_colors(vtk::VTKGridFile, grid::AbstractGrid, cell_colors, name = "coloring")
367367
368368
Write cell colors (see [`create_coloring`](@ref)) to a VTK file for visualization.
369369

0 commit comments

Comments
 (0)