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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeshIntegrals"
uuid = "dadec2fd-bbe0-4da4-9dbe-476c782c8e47"
authors = ["Mike Ingold <mike.ingold@gmail.com>"]
version = "0.11.6"
version = "0.11.7"

[deps]
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ integral(f, unit_circle_bz, GaussKronrod())
|--------|---------|
| :white_check_mark: | Implemented, passes tests |
| :x: | Planned but not yet implemented |
| :warning: | Unable to implement until parameterization not available (see [Issue #28](https://github.com/mikeingold/MeshIntegrals.jl/issues/28)) |
| :warning: | Unable to implement: parameterization not available (see [Issue #28](https://github.com/mikeingold/MeshIntegrals.jl/issues/28)) |

### Integral
| Geometry | Gauss-Legendre | Gauss-Kronrod | H-Adaptive Cubature |
Expand Down Expand Up @@ -85,5 +85,6 @@ integral(f, unit_circle_bz, GaussKronrod())
| `SimpleMesh{Dim,T,V}` | :x: | :x: | :x: |
| `Sphere{2,T}` | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| `Sphere{3,T}` | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| `Tetrahedron{3,T}` | :x: | :white_check_mark: | :x: |
| `Triangle{T}` | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| `Torus{T}` | :white_check_mark: | :white_check_mark: | :white_check_mark: |
37 changes: 37 additions & 0 deletions src/integral_volume.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,43 @@ function _integral_3d(
end


################################################################################
# Specialized Methods for Tetrahedron
################################################################################

function integral(
f::F,
tetrahedron::Meshes.Tetrahedron{3,T},
settings::GaussLegendre
) where {F<:Function, T}
error("Integrating a Tetrahedron{3,T} with GaussLegendre not supported.")
end

function integral(
f::F,
tetrahedron::Meshes.Tetrahedron{3,T},
settings::GaussKronrod
) where {F<:Function, T}
# Validate the provided integrand function
_validate_integrand(f,3,T)

inner∫₂(v,w) = QuadGK.quadgk(u -> f(tetrahedron(u,v,w)), T(0), T(1-v-w); settings.kwargs...)[1]
inner∫₁(w) = QuadGK.quadgk(v -> inner∫₂(v,w), T(0), T(1-w); settings.kwargs...)[1]
outer∫ = QuadGK.quadgk(w -> inner∫₁(w), T(0), T(1); settings.kwargs...)[1]

# Apply barycentric domain correction (volume: 1/6 → actual)
return 6 * volume(tetrahedron) * outer∫
end

function integral(
f::F,
tetrahedron::Meshes.Tetrahedron{3,T},
settings::HAdaptiveCubature
) where {F<:Function, T}
error("Integrating a Tetrahedron{3,T} with HAdaptiveCubature not supported.")
end


################################################################################
# Unsupported Placeholders
################################################################################
Expand Down
12 changes: 7 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,19 @@ end
segment(T) = Segment(pt_e(T), pt_n(T))
sphere2d(T) = Sphere(origin2d(T), T(2.5))
sphere3d(T) = Sphere(origin3d(T), T(2.5))
tetra(T) = Tetrahedron(pt_n(T), pt_w(T), pt_e(T), pt_n(T)+ẑ(T))
triangle(T) = Ngon(pt_e(T), pt_n(T), pt_w(T))
torus(T) = Torus(origin3d(T), ẑ(T), T(3.5), T(1.25))

SUPPORT_MATRIX(T) = [
# Name, T type, example, integral,line,surface,volume, GaussLegendre,GaussKronrod,HAdaptiveCubature
SupportItem("Ball{2,$T}", T, ball2d(T), 1, 0, 1, 0, 1, 1, 1),
SupportItem("Ball{3,$T}", T, ball3d(T), 1, 0, 0, 1, 1, 0, 1),
SupportItem("Ball{2,$T}", T, ball2d(T), 1, 0, 1, 0, 1, 1, 1),
SupportItem("Ball{3,$T}", T, ball3d(T), 1, 0, 0, 1, 1, 0, 1),
# Ball{Dim,T}
SupportItem("BezierCurve{$T}", T, bezier(T), 1, 1, 0, 0, 1, 1, 1),
SupportItem("Box{1,$T}", T, box1d(T), 1, 1, 0, 0, 1, 1, 1),
SupportItem("Box{2,$T}", T, box2d(T), 1, 0, 1, 0, 1, 1, 1),
SupportItem("Box{3,$T}", T, box3d(T), 1, 0, 0, 1, 1, 0, 1),
SupportItem("Box{1,$T}", T, box1d(T), 1, 1, 0, 0, 1, 1, 1),
SupportItem("Box{2,$T}", T, box2d(T), 1, 0, 1, 0, 1, 1, 1),
SupportItem("Box{3,$T}", T, box3d(T), 1, 0, 0, 1, 1, 0, 1),
# Box{Dim,T}
SupportItem("Circle{$T}", T, circle(T), 1, 1, 0, 0, 1, 1, 1),
# Cone
Expand All @@ -133,6 +134,7 @@ end
# SimpleMesh
SupportItem("Sphere{2,$T}", T, sphere2d(T), 1, 1, 0, 0, 1, 1, 1),
SupportItem("Sphere{3,$T}", T, sphere3d(T), 1, 0, 1, 0, 1, 1, 1),
SupportItem("Tetrahedron", T, tetra(T), 1, 0, 0, 1, 0, 1, 0),
SupportItem("Triangle{$T}", T, triangle(T), 1, 0, 1, 0, 1, 1, 1),
SupportItem("Torus{$T}", T, torus(T), 1, 0, 1, 0, 1, 1, 1),
]
Expand Down