Skip to content

Commit

Permalink
format with SciMLStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaLampert committed Sep 24, 2024
1 parent 41c5dfe commit f2238a1
Show file tree
Hide file tree
Showing 24 changed files with 380 additions and 354 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "sciml"
11 changes: 11 additions & 0 deletions .github/workflows/FormatPR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Format suggestions
on:
pull_request

jobs:
code-style:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/julia-format@v3
with:
version: '1' # Set `version` to '1.0.54' if you need to use JuliaFormatter.jl v1.0.54 (default: '1')
6 changes: 3 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Documenter
using MeshIntegrals

makedocs(
sitename="MeshIntegrals.jl",
sitename = "MeshIntegrals.jl",
pages = [
"Home" => [
"About" => "index.md",
Expand All @@ -17,5 +17,5 @@ makedocs(
)

deploydocs(repo = "github.com/mikeingold/MeshIntegrals.jl.git",
devbranch = "main",
push_preview = true)
devbranch = "main",
push_preview = true)
54 changes: 27 additions & 27 deletions src/MeshIntegrals.jl
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
module MeshIntegrals
using CoordRefSystems
using LinearAlgebra
using Meshes
using Unitful
using CoordRefSystems
using LinearAlgebra
using Meshes
using Unitful

import FastGaussQuadrature
import HCubature
import QuadGK
import FastGaussQuadrature
import HCubature
import QuadGK

include("utils.jl")
export jacobian, derivative, unitdirection
include("utils.jl")
export jacobian, derivative, unitdirection

include("integration_rules.jl")
export IntegrationRule, GaussKronrod, GaussLegendre, HAdaptiveCubature
include("integration_rules.jl")
export IntegrationRule, GaussKronrod, GaussLegendre, HAdaptiveCubature

include("integral.jl")
export integral
include("integral.jl")
export integral

include("integral_aliases.jl")
export lineintegral, surfaceintegral, volumeintegral
include("integral_aliases.jl")
export lineintegral, surfaceintegral, volumeintegral

# Integration methods specialized for particular geometries
include("specializations/BezierCurve.jl")
include("specializations/ConeSurface.jl")
include("specializations/CylinderSurface.jl")
include("specializations/FrustumSurface.jl")
include("specializations/Line.jl")
include("specializations/Plane.jl")
include("specializations/Ray.jl")
include("specializations/Ring.jl")
include("specializations/Rope.jl")
include("specializations/Tetrahedron.jl")
include("specializations/Triangle.jl")
# Integration methods specialized for particular geometries
include("specializations/BezierCurve.jl")
include("specializations/ConeSurface.jl")
include("specializations/CylinderSurface.jl")
include("specializations/FrustumSurface.jl")
include("specializations/Line.jl")
include("specializations/Plane.jl")
include("specializations/Ray.jl")
include("specializations/Ring.jl")
include("specializations/Rope.jl")
include("specializations/Tetrahedron.jl")
include("specializations/Triangle.jl")
end
87 changes: 43 additions & 44 deletions src/integral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,35 @@ function integral end

# If only f and geometry are specified, select default rule
function integral(
f::F,
geometry::G
) where {F<:Function, G<:Meshes.Geometry}
f::F,
geometry::G
) where {F <: Function, G <: Meshes.Geometry}
N = Meshes.paramdim(geometry)
rule = (N == 1) ? GaussKronrod() : HAdaptiveCubature()
_integral(f, geometry, rule)
end

# with rule and T specified
function integral(
f::F,
geometry::G,
rule::I,
FP::Type{T} = Float64
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationRule, T<:AbstractFloat}
f::F,
geometry::G,
rule::I,
FP::Type{T} = Float64
) where {F <: Function, G <: Meshes.Geometry, I <: IntegrationRule, T <: AbstractFloat}
_integral(f, geometry, rule, FP)
end


################################################################################
# Generalized (n-Dimensional) Worker Methods
################################################################################

# GaussKronrod
function _integral(
f,
geometry,
rule::GaussKronrod,
FP::Type{T} = Float64
) where {T<:AbstractFloat}
f,
geometry,
rule::GaussKronrod,
FP::Type{T} = Float64
) where {T <: AbstractFloat}
# Run the appropriate integral type
N = Meshes.paramdim(geometry)
if N == 1
Expand All @@ -68,11 +67,11 @@ end

# GaussLegendre
function _integral(
f,
geometry,
rule::GaussLegendre,
FP::Type{T} = Float64
) where {T<:AbstractFloat}
f,
geometry,
rule::GaussLegendre,
FP::Type{T} = Float64
) where {T <: AbstractFloat}
N = Meshes.paramdim(geometry)

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

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

function integrand((weights, nodes))
ts = t.(nodes)
prod(weights) * f(geometry(ts...)) * differential(geometry, ts)
end

return FP(1//(2^N)) .* sum(integrand, zip(weights, nodes))
return FP(1 // (2^N)) .* sum(integrand, zip(weights, nodes))
end

# HAdaptiveCubature
function _integral(
f,
geometry,
rule::HAdaptiveCubature,
FP::Type{T} = Float64
) where {T<:AbstractFloat}
f,
geometry,
rule::HAdaptiveCubature,
FP::Type{T} = Float64
) where {T <: AbstractFloat}
N = Meshes.paramdim(geometry)

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

# Reapply units
return value .* integrandunits
Expand All @@ -120,32 +119,32 @@ end
################################################################################

function _integral_1d(
f,
geometry,
rule::GaussKronrod,
FP::Type{T} = Float64
) where {T<:AbstractFloat}
f,
geometry,
rule::GaussKronrod,
FP::Type{T} = Float64
) where {T <: AbstractFloat}
integrand(t) = f(geometry(t)) * differential(geometry, (t))
return QuadGK.quadgk(integrand, zero(FP), one(FP); rule.kwargs...)[1]
end

function _integral_2d(
f,
geometry2d,
rule::GaussKronrod,
FP::Type{T} = Float64
) where {T<:AbstractFloat}
integrand(u,v) = f(geometry2d(u,v)) * differential(geometry2d, (u,v))
∫₁(v) = QuadGK.quadgk(u -> integrand(u,v), zero(FP), one(FP); rule.kwargs...)[1]
f,
geometry2d,
rule::GaussKronrod,
FP::Type{T} = Float64
) where {T <: AbstractFloat}
integrand(u, v) = f(geometry2d(u, v)) * differential(geometry2d, (u, v))
∫₁(v) = QuadGK.quadgk(u -> integrand(u, v), zero(FP), one(FP); rule.kwargs...)[1]
return QuadGK.quadgk(v -> ∫₁(v), zero(FP), one(FP); rule.kwargs...)[1]
end

# Integrating volumes with GaussKronrod not supported by default
function _integral_3d(
f,
geometry,
rule::GaussKronrod,
FP::Type{T} = Float64
) where {T<:AbstractFloat}
f,
geometry,
rule::GaussKronrod,
FP::Type{T} = Float64
) where {T <: AbstractFloat}
error("Integrating this volume type with GaussKronrod not supported.")
end
Loading

0 comments on commit f2238a1

Please sign in to comment.