Skip to content

Commit

Permalink
Implement for CylinderSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeingold committed Dec 20, 2024
1 parent 53e86a8 commit 2e1038d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ rules = (
HAdaptiveCubature()
)
geometries = (
let= Vec(0, 0, 1)
CylinderSurface(Plane(Point(0, 0, 0), ẑ), Plane(Point(0, 0, 3), ẑ), 2.5)
end,
Segment(Point(0, 0, 0), Point(1, 1, 1)),
Sphere(Point(0, 0, 0), 1.0)
)
Expand Down
30 changes: 30 additions & 0 deletions src/specializations/CylinderSurface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,33 @@ function integral(

return sides + top + bottom
end

function integral(
f,
cyl::Meshes.CylinderSurface,
rule::HAdaptiveCubature;
FP::Type{T} = Float64,
diff_method::DM = _default_diff_method(cyl, FP),
kwargs...
) where {T <: AbstractFloat, DM <: DifferentiationMethod}
_check_diff_method_support(cyl, diff_method)

# Use a sample integrand to develop and append a buffer to the given rule
f_sample(ts) = Unitful.ustrip.(f(cyl(ts...)) * differential(cyl, ts))
N = Meshes.paramdim(cyl)
buffer = HCubature.hcubature_buffer(f_sample, _zeros(FP, N), _ones(FP, N))
rule = HAdaptiveCubature(rule.kwargs..., buffer = buffer)

# The generic method only parametrizes the sides
sides = _integral(f, cyl, rule; diff_method = diff_method, FP = FP, kwargs...)

# Integrate the Disk at the top
disk_top = Meshes.Disk(cyl.top, cyl.radius)
top = _integral(f, disk_top, rule; diff_method = diff_method, FP = FP, kwargs...)

# Integrate the Disk at the bottom
disk_bottom = Meshes.Disk(cyl.bot, cyl.radius)
bottom = _integral(f, disk_bottom, rule; diff_method = diff_method, FP = FP, kwargs...)

return sides + top + bottom
end

0 comments on commit 2e1038d

Please sign in to comment.