Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format repo and use formatter workflow #86

Closed
wants to merge 3 commits into from
Closed
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
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')
16 changes: 5 additions & 11 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ using Documenter
using MeshIntegrals

makedocs(
sitename="MeshIntegrals.jl",
sitename = "MeshIntegrals.jl",
pages = [
"Home" => [
"About" => "index.md",
"Support Matrix" => "supportmatrix.md",
"Example Usage" => "usage.md"
],
"Derivations" => [
"Integrating a Triangle" => "triangle.md"
],
"Home" => ["About" => "index.md", "Support Matrix" => "supportmatrix.md",
"Example Usage" => "usage.md"],
"Derivations" => ["Integrating a Triangle" => "triangle.md"],
"Public API" => "api.md"
]
)

deploydocs(repo = "github.com/mikeingold/MeshIntegrals.jl.git",
devbranch = "main",
push_preview = true)
devbranch = "main", push_preview = true)
52 changes: 26 additions & 26 deletions src/MeshIntegrals.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
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_algorithms.jl")
export GaussKronrod, GaussLegendre, HAdaptiveCubature
include("integration_algorithms.jl")
export GaussKronrod, GaussLegendre, HAdaptiveCubature

include("integral.jl")
include("integral_aliases.jl")
export integral, lineintegral, surfaceintegral, volumeintegral
include("integral.jl")
include("integral_aliases.jl")
export integral, 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
78 changes: 26 additions & 52 deletions src/integral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,30 @@ contrast, increasing `FP` to e.g. `BigFloat` will typically increase precision
function integral end

# If only f and geometry are specified, select default algorithm
function integral(
f::F,
geometry::G
) where {F<:Function, G<:Meshes.Geometry}
function integral(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 algorithm and T specified
function integral(
f::F,
geometry::G,
settings::I,
FP::Type{T} = Float64
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationAlgorithm, T<:AbstractFloat}
f::F,
geometry::G,
settings::I,
FP::Type{T} = Float64
) where {
F <: Function, G <: Meshes.Geometry, I <: IntegrationAlgorithm, T <: AbstractFloat}
_integral(f, geometry, settings, FP)
end


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

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

# GaussLegendre
function _integral(
f,
geometry,
settings::GaussLegendre,
FP::Type{T} = Float64
) where {T<:AbstractFloat}
function _integral(f, geometry, settings::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,35 +70,32 @@ 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,
settings::HAdaptiveCubature,
FP::Type{T} = Float64
) where {T<:AbstractFloat}
function _integral(f, geometry, settings::HAdaptiveCubature,
FP::Type{T} = Float64) where {T <: AbstractFloat}
Dim = Meshes.paramdim(geometry)

integrand(t) = f(geometry(t...)) * differential(geometry, t)

# HCubature doesn't support functions that output Unitful Quantity types
# Establish the units that are output by f
testpoint_parametriccoord = fill(FP(0.5),Dim)
testpoint_parametriccoord = fill(FP(0.5), Dim)
integrandunits = Unitful.unit.(integrand(testpoint_parametriccoord))
# 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,Dim), ones(FP,Dim); settings.kwargs...)[1]
value = HCubature.hcubature(
uintegrand, zeros(FP, Dim), ones(FP, Dim); settings.kwargs...)[1]

# Reapply units
return value .* integrandunits
Expand All @@ -119,33 +105,21 @@ end
# Specialized GaussKronrod Methods
################################################################################

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

function _integral_2d(
f,
geometry2d,
settings::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), FP(0), FP(1); settings.kwargs...)[1]
function _integral_2d(f, geometry2d, settings::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), FP(0), FP(1); settings.kwargs...)[1]
return QuadGK.quadgk(v -> ∫₁(v), FP(0), FP(1); settings.kwargs...)[1]
end

# Integrating volumes with GaussKronrod not supported by default
function _integral_3d(
f,
geometry,
settings::GaussKronrod,
FP::Type{T} = Float64
) where {T<:AbstractFloat}
function _integral_3d(f, geometry, settings::GaussKronrod,
FP::Type{T} = Float64) where {T <: AbstractFloat}
error("Integrating this volume type with GaussKronrod not supported.")
end
71 changes: 27 additions & 44 deletions src/integral_aliases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ Algorithm types available:
- GaussLegendre
- HAdaptiveCubature
"""
function lineintegral(
f::F,
geometry::G,
) where {F<:Function, G<:Meshes.Geometry}
function lineintegral(f::F, geometry::G) where {F <: Function, G <: Meshes.Geometry}
Dim = Meshes.paramdim(geometry)

if Dim == 1
Expand All @@ -29,11 +26,8 @@ function lineintegral(
end
end

function lineintegral(
f::F,
geometry::G,
settings::I
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationAlgorithm}
function lineintegral(f::F, geometry::G,
settings::I) where {F <: Function, G <: Meshes.Geometry, I <: IntegrationAlgorithm}
Dim = Meshes.paramdim(geometry)

if Dim == 1
Expand All @@ -44,11 +38,12 @@ function lineintegral(
end

function lineintegral(
f::F,
geometry::G,
settings::I,
FP::Type{T}
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationAlgorithm, T<:AbstractFloat}
f::F,
geometry::G,
settings::I,
FP::Type{T}
) where {
F <: Function, G <: Meshes.Geometry, I <: IntegrationAlgorithm, T <: AbstractFloat}
Dim = Meshes.paramdim(geometry)

if Dim == 1
Expand All @@ -58,7 +53,6 @@ function lineintegral(
end
end


################################################################################
# Surface Integral
################################################################################
Expand All @@ -77,10 +71,7 @@ Algorithm types available:
- GaussLegendre
- HAdaptiveCubature (default)
"""
function surfaceintegral(
f::F,
geometry::G,
) where {F<:Function, G<:Meshes.Geometry}
function surfaceintegral(f::F, geometry::G) where {F <: Function, G <: Meshes.Geometry}
Dim = Meshes.paramdim(geometry)

if Dim == 2
Expand All @@ -90,11 +81,8 @@ function surfaceintegral(
end
end

function surfaceintegral(
f::F,
geometry::G,
settings::I
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationAlgorithm}
function surfaceintegral(f::F, geometry::G,
settings::I) where {F <: Function, G <: Meshes.Geometry, I <: IntegrationAlgorithm}
Dim = Meshes.paramdim(geometry)

if Dim == 2
Expand All @@ -105,11 +93,12 @@ function surfaceintegral(
end

function surfaceintegral(
f::F,
geometry::G,
settings::I,
FP::Type{T}
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationAlgorithm, T<:AbstractFloat}
f::F,
geometry::G,
settings::I,
FP::Type{T}
) where {
F <: Function, G <: Meshes.Geometry, I <: IntegrationAlgorithm, T <: AbstractFloat}
Dim = Meshes.paramdim(geometry)

if Dim == 2
Expand All @@ -119,7 +108,6 @@ function surfaceintegral(
end
end


################################################################################
# Volume Integral
################################################################################
Expand All @@ -138,10 +126,7 @@ Algorithm types available:
- GaussLegendre
- HAdaptiveCubature (default)
"""
function volumeintegral(
f::F,
geometry::G,
) where {F<:Function, G<:Meshes.Geometry}
function volumeintegral(f::F, geometry::G) where {F <: Function, G <: Meshes.Geometry}
Dim = Meshes.paramdim(geometry)

if Dim == 3
Expand All @@ -151,11 +136,8 @@ function volumeintegral(
end
end

function volumeintegral(
f::F,
geometry::G,
settings::I
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationAlgorithm}
function volumeintegral(f::F, geometry::G,
settings::I) where {F <: Function, G <: Meshes.Geometry, I <: IntegrationAlgorithm}
Dim = Meshes.paramdim(geometry)

if Dim == 3
Expand All @@ -166,11 +148,12 @@ function volumeintegral(
end

function volumeintegral(
f::F,
geometry::G,
settings::I,
FP::Type{T}
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationAlgorithm, T<:AbstractFloat}
f::F,
geometry::G,
settings::I,
FP::Type{T}
) where {
F <: Function, G <: Meshes.Geometry, I <: IntegrationAlgorithm, T <: AbstractFloat}
Dim = Meshes.paramdim(geometry)

if Dim == 3
Expand Down
Loading
Loading