Skip to content

Commit 0a6eaaf

Browse files
Implement JuliaFormatter with SciML style (#87)
* format with SciMLStyle * Tighten up notation to prevent multi-line spans * Condense some lines to prevent multi-line spans * Specify kwargs type as Pairs --------- Co-authored-by: Michael Ingold <[email protected]>
1 parent 41c5dfe commit 0a6eaaf

24 files changed

+375
-356
lines changed

.JuliaFormatter.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "sciml"

.github/workflows/FormatPR.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Format suggestions
2+
on:
3+
pull_request
4+
5+
jobs:
6+
code-style:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: julia-actions/julia-format@v3
10+
with:
11+
version: '1' # Set `version` to '1.0.54' if you need to use JuliaFormatter.jl v1.0.54 (default: '1')

docs/make.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using Documenter
22
using MeshIntegrals
33

44
makedocs(
5-
sitename="MeshIntegrals.jl",
5+
sitename = "MeshIntegrals.jl",
66
pages = [
77
"Home" => [
88
"About" => "index.md",
@@ -17,5 +17,5 @@ makedocs(
1717
)
1818

1919
deploydocs(repo = "github.com/mikeingold/MeshIntegrals.jl.git",
20-
devbranch = "main",
21-
push_preview = true)
20+
devbranch = "main",
21+
push_preview = true)

src/MeshIntegrals.jl

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
module MeshIntegrals
2-
using CoordRefSystems
3-
using LinearAlgebra
4-
using Meshes
5-
using Unitful
2+
using CoordRefSystems
3+
using LinearAlgebra
4+
using Meshes
5+
using Unitful
66

7-
import FastGaussQuadrature
8-
import HCubature
9-
import QuadGK
7+
import FastGaussQuadrature
8+
import HCubature
9+
import QuadGK
1010

11-
include("utils.jl")
12-
export jacobian, derivative, unitdirection
11+
include("utils.jl")
12+
export jacobian, derivative, unitdirection
1313

14-
include("integration_rules.jl")
15-
export IntegrationRule, GaussKronrod, GaussLegendre, HAdaptiveCubature
14+
include("integration_rules.jl")
15+
export IntegrationRule, GaussKronrod, GaussLegendre, HAdaptiveCubature
1616

17-
include("integral.jl")
18-
export integral
17+
include("integral.jl")
18+
export integral
1919

20-
include("integral_aliases.jl")
21-
export lineintegral, surfaceintegral, volumeintegral
20+
include("integral_aliases.jl")
21+
export lineintegral, surfaceintegral, volumeintegral
2222

23-
# Integration methods specialized for particular geometries
24-
include("specializations/BezierCurve.jl")
25-
include("specializations/ConeSurface.jl")
26-
include("specializations/CylinderSurface.jl")
27-
include("specializations/FrustumSurface.jl")
28-
include("specializations/Line.jl")
29-
include("specializations/Plane.jl")
30-
include("specializations/Ray.jl")
31-
include("specializations/Ring.jl")
32-
include("specializations/Rope.jl")
33-
include("specializations/Tetrahedron.jl")
34-
include("specializations/Triangle.jl")
23+
# Integration methods specialized for particular geometries
24+
include("specializations/BezierCurve.jl")
25+
include("specializations/ConeSurface.jl")
26+
include("specializations/CylinderSurface.jl")
27+
include("specializations/FrustumSurface.jl")
28+
include("specializations/Line.jl")
29+
include("specializations/Plane.jl")
30+
include("specializations/Ray.jl")
31+
include("specializations/Ring.jl")
32+
include("specializations/Rope.jl")
33+
include("specializations/Tetrahedron.jl")
34+
include("specializations/Triangle.jl")
3535
end

src/integral.jl

+43-44
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,35 @@ function integral end
2525

2626
# If only f and geometry are specified, select default rule
2727
function integral(
28-
f::F,
29-
geometry::G
30-
) where {F<:Function, G<:Meshes.Geometry}
28+
f::F,
29+
geometry::G
30+
) where {F <: Function, G <: Meshes.Geometry}
3131
N = Meshes.paramdim(geometry)
3232
rule = (N == 1) ? GaussKronrod() : HAdaptiveCubature()
3333
_integral(f, geometry, rule)
3434
end
3535

3636
# with rule and T specified
3737
function integral(
38-
f::F,
39-
geometry::G,
40-
rule::I,
41-
FP::Type{T} = Float64
42-
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationRule, T<:AbstractFloat}
38+
f::F,
39+
geometry::G,
40+
rule::I,
41+
FP::Type{T} = Float64
42+
) where {F <: Function, G <: Meshes.Geometry, I <: IntegrationRule, T <: AbstractFloat}
4343
_integral(f, geometry, rule, FP)
4444
end
4545

46-
4746
################################################################################
4847
# Generalized (n-Dimensional) Worker Methods
4948
################################################################################
5049

5150
# GaussKronrod
5251
function _integral(
53-
f,
54-
geometry,
55-
rule::GaussKronrod,
56-
FP::Type{T} = Float64
57-
) where {T<:AbstractFloat}
52+
f,
53+
geometry,
54+
rule::GaussKronrod,
55+
FP::Type{T} = Float64
56+
) where {T <: AbstractFloat}
5857
# Run the appropriate integral type
5958
N = Meshes.paramdim(geometry)
6059
if N == 1
@@ -68,11 +67,11 @@ end
6867

6968
# GaussLegendre
7069
function _integral(
71-
f,
72-
geometry,
73-
rule::GaussLegendre,
74-
FP::Type{T} = Float64
75-
) where {T<:AbstractFloat}
70+
f,
71+
geometry,
72+
rule::GaussLegendre,
73+
FP::Type{T} = Float64
74+
) where {T <: AbstractFloat}
7675
N = Meshes.paramdim(geometry)
7776

7877
# Get Gauss-Legendre nodes and weights for a region [-1,1]^N
@@ -81,23 +80,23 @@ function _integral(
8180
nodes = Iterators.product(ntuple(Returns(xs), N)...)
8281

8382
# Domain transformation: x [-1,1] ↦ t [0,1]
84-
t(x) = FP(1//2) * x + FP(1//2)
83+
t(x) = FP(1 // 2) * x + FP(1 // 2)
8584

8685
function integrand((weights, nodes))
8786
ts = t.(nodes)
8887
prod(weights) * f(geometry(ts...)) * differential(geometry, ts)
8988
end
9089

91-
return FP(1//(2^N)) .* sum(integrand, zip(weights, nodes))
90+
return FP(1 // (2^N)) .* sum(integrand, zip(weights, nodes))
9291
end
9392

9493
# HAdaptiveCubature
9594
function _integral(
96-
f,
97-
geometry,
98-
rule::HAdaptiveCubature,
99-
FP::Type{T} = Float64
100-
) where {T<:AbstractFloat}
95+
f,
96+
geometry,
97+
rule::HAdaptiveCubature,
98+
FP::Type{T} = Float64
99+
) where {T <: AbstractFloat}
101100
N = Meshes.paramdim(geometry)
102101

103102
integrand(t) = f(geometry(t...)) * differential(geometry, t)
@@ -109,7 +108,7 @@ function _integral(
109108
# Create a wrapper that returns only the value component in those units
110109
uintegrand(uv) = Unitful.ustrip.(integrandunits, integrand(uv))
111110
# Integrate only the unitless values
112-
value = HCubature.hcubature(uintegrand, zeros(FP,N), ones(FP,N); rule.kwargs...)[1]
111+
value = HCubature.hcubature(uintegrand, zeros(FP, N), ones(FP, N); rule.kwargs...)[1]
113112

114113
# Reapply units
115114
return value .* integrandunits
@@ -120,32 +119,32 @@ end
120119
################################################################################
121120

122121
function _integral_1d(
123-
f,
124-
geometry,
125-
rule::GaussKronrod,
126-
FP::Type{T} = Float64
127-
) where {T<:AbstractFloat}
122+
f,
123+
geometry,
124+
rule::GaussKronrod,
125+
FP::Type{T} = Float64
126+
) where {T <: AbstractFloat}
128127
integrand(t) = f(geometry(t)) * differential(geometry, (t))
129128
return QuadGK.quadgk(integrand, zero(FP), one(FP); rule.kwargs...)[1]
130129
end
131130

132131
function _integral_2d(
133-
f,
134-
geometry2d,
135-
rule::GaussKronrod,
136-
FP::Type{T} = Float64
137-
) where {T<:AbstractFloat}
138-
integrand(u,v) = f(geometry2d(u,v)) * differential(geometry2d, (u,v))
139-
∫₁(v) = QuadGK.quadgk(u -> integrand(u,v), zero(FP), one(FP); rule.kwargs...)[1]
132+
f,
133+
geometry2d,
134+
rule::GaussKronrod,
135+
FP::Type{T} = Float64
136+
) where {T <: AbstractFloat}
137+
integrand(u, v) = f(geometry2d(u, v)) * differential(geometry2d, (u, v))
138+
∫₁(v) = QuadGK.quadgk(u -> integrand(u, v), zero(FP), one(FP); rule.kwargs...)[1]
140139
return QuadGK.quadgk(v -> ∫₁(v), zero(FP), one(FP); rule.kwargs...)[1]
141140
end
142141

143142
# Integrating volumes with GaussKronrod not supported by default
144143
function _integral_3d(
145-
f,
146-
geometry,
147-
rule::GaussKronrod,
148-
FP::Type{T} = Float64
149-
) where {T<:AbstractFloat}
144+
f,
145+
geometry,
146+
rule::GaussKronrod,
147+
FP::Type{T} = Float64
148+
) where {T <: AbstractFloat}
150149
error("Integrating this volume type with GaussKronrod not supported.")
151150
end

0 commit comments

Comments
 (0)