Skip to content

Commit

Permalink
Add method for integrating Tetrahedron (#41)
Browse files Browse the repository at this point in the history
* Add tetrahedron to tests

* Add QuadGK method for integrating Tetrahedron

* Fix copy/paste error

* Bugfix - domain correction

* Bugfix - domain correction

* Bump package version

* Update support matrix
  • Loading branch information
mikeingold authored Apr 14, 2024
1 parent 167c3e8 commit 77a2b06
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
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 <[email protected]>"]
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

2 comments on commit 77a2b06

@mikeingold
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104890

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.7 -m "<description of version>" 77a2b067c7456787e5e6f9bbb23fc4a90624a627
git push origin v0.11.7

Please sign in to comment.