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

Add analytical unit tests for Cylinder and CylinderSurface #162

Merged
merged 6 commits into from
Dec 31, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Improved unit tests for `Meshes.Cylinder` and `Meshes.CylinderSurface` ([GitHub Issue #67](https://github.com/JuliaGeometry/MeshIntegrals.jl/issues/67)).

## [0.16.1] - 2024-12-29

Expand Down
44 changes: 32 additions & 12 deletions test/combinations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This file includes tests for:
===============================================================================#

@testsnippet Combinations begin
using CoordRefSystems
using LinearAlgebra: norm
using Meshes
using MeshIntegrals
Expand Down Expand Up @@ -331,13 +332,21 @@ end

@testitem "Meshes.Cylinder" setup=[Combinations] begin
# Geometry
pt_w = Point(-1, 0, 0)
pt_e = Point(1, 0, 0)
cyl = Cylinder(pt_e, pt_w, 2.5)
h = 8.5u"m"
ρ₀ = 1.3u"m"
pt_a = Point(0u"m", 0u"m", 0u"m")
pt_b = Point(0u"m", 0u"m", h)
cyl = Cylinder(pt_a, pt_b, ρ₀)

# Integrand & Solution
integrand(p) = 1.0u"A"
solution = Meshes.measure(cyl) * u"A"
function integrand(p::Meshes.Point)
p_cyl = convert(Cylindrical, Cartesian(to(p)...))
ρ = p_cyl.ρ
φ = p_cyl.ϕ
z = p_cyl.z
ρ^(-1) * (ρ + φ * u"m" + z) * u"A"
end
solution = ((π * h * ρ₀^2) + (π * h^2 * ρ₀) + (2π * π * u"m" * h * ρ₀)) * u"A"

# Package and run tests
testable = TestableGeometry(integrand, cyl, solution)
Expand All @@ -346,13 +355,26 @@ end

@testitem "Meshes.CylinderSurface" setup=[Combinations] begin
# Geometry
pt_w = Point(-1, 0, 0)
pt_e = Point(1, 0, 0)
cyl = CylinderSurface(pt_e, pt_w, 2.5)
h = 8.5u"m"
ρ₀ = 1.3u"m"
pt_a = Point(0u"m", 0u"m", 0u"m")
pt_b = Point(0u"m", 0u"m", h)
cyl = CylinderSurface(pt_a, pt_b, ρ₀)

# Integrand & Solution
integrand(p) = 1.0u"A"
solution = Meshes.measure(cyl) * u"A"
function integrand(p::Meshes.Point)
p_cyl = convert(Cylindrical, Cartesian(to(p)...))
ρ = p_cyl.ρ
φ = p_cyl.ϕ
z = p_cyl.z
ρ^(-1) * (ρ + φ * u"m" + z) * u"A"
end
solution = let
disk_a = (2π * h * ρ₀) + (π * ρ₀^2) + (π * u"m" * ρ₀ * 2π)
disk_b = (π * ρ₀^2) + (π * u"m" * ρ₀ * 2π)
walls = (2π * h * ρ₀) + (2π^2 * u"m" * h) + (π * h^2)
(disk_a + disk_b + walls) * u"A"
end

# Package and run tests
testable = TestableGeometry(integrand, cyl, solution)
Expand Down Expand Up @@ -631,8 +653,6 @@ end
end

@testitem "Meshes.Sphere 3D" setup=[Combinations] begin
using CoordRefSystems: Cartesian, Spherical

# Geometry
center = Point(1, 2, 3)
radius = 4.4u"m"
Expand Down
Loading