Skip to content

Commit 7818474

Browse files
Add analytical unit tests for Cylinder and CylinderSurface (#162)
* Add analytical test for Cylinder * CRS is now available file-wide * Add test for CylinderSurface * Add note * Use less-simplified solution for clarity * Apply format suggestion Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent dc4fe79 commit 7818474

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Changed
11+
12+
- Improved unit tests for `Meshes.Cylinder` and `Meshes.CylinderSurface` ([GitHub Issue #67](https://github.com/JuliaGeometry/MeshIntegrals.jl/issues/67)).
813

914
## [0.16.1] - 2024-12-29
1015

test/combinations.jl

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This file includes tests for:
1414
===============================================================================#
1515

1616
@testsnippet Combinations begin
17+
using CoordRefSystems
1718
using LinearAlgebra: norm
1819
using Meshes
1920
using MeshIntegrals
@@ -331,13 +332,21 @@ end
331332

332333
@testitem "Meshes.Cylinder" setup=[Combinations] begin
333334
# Geometry
334-
pt_w = Point(-1, 0, 0)
335-
pt_e = Point(1, 0, 0)
336-
cyl = Cylinder(pt_e, pt_w, 2.5)
335+
h = 8.5u"m"
336+
ρ₀ = 1.3u"m"
337+
pt_a = Point(0u"m", 0u"m", 0u"m")
338+
pt_b = Point(0u"m", 0u"m", h)
339+
cyl = Cylinder(pt_a, pt_b, ρ₀)
337340

338341
# Integrand & Solution
339-
integrand(p) = 1.0u"A"
340-
solution = Meshes.measure(cyl) * u"A"
342+
function integrand(p::Meshes.Point)
343+
p_cyl = convert(Cylindrical, Cartesian(to(p)...))
344+
ρ = p_cyl.ρ
345+
φ = p_cyl.ϕ
346+
z = p_cyl.z
347+
ρ^(-1) *+ φ * u"m" + z) * u"A"
348+
end
349+
solution = ((π * h * ρ₀^2) +* h^2 * ρ₀) + (2π * π * u"m" * h * ρ₀)) * u"A"
341350

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

347356
@testitem "Meshes.CylinderSurface" setup=[Combinations] begin
348357
# Geometry
349-
pt_w = Point(-1, 0, 0)
350-
pt_e = Point(1, 0, 0)
351-
cyl = CylinderSurface(pt_e, pt_w, 2.5)
358+
h = 8.5u"m"
359+
ρ₀ = 1.3u"m"
360+
pt_a = Point(0u"m", 0u"m", 0u"m")
361+
pt_b = Point(0u"m", 0u"m", h)
362+
cyl = CylinderSurface(pt_a, pt_b, ρ₀)
352363

353364
# Integrand & Solution
354-
integrand(p) = 1.0u"A"
355-
solution = Meshes.measure(cyl) * u"A"
365+
function integrand(p::Meshes.Point)
366+
p_cyl = convert(Cylindrical, Cartesian(to(p)...))
367+
ρ = p_cyl.ρ
368+
φ = p_cyl.ϕ
369+
z = p_cyl.z
370+
ρ^(-1) *+ φ * u"m" + z) * u"A"
371+
end
372+
solution = let
373+
disk_a = (2π * h * ρ₀) +* ρ₀^2) +* u"m" * ρ₀ * 2π)
374+
disk_b =* ρ₀^2) +* u"m" * ρ₀ * 2π)
375+
walls = (2π * h * ρ₀) + (2π^2 * u"m" * h) +* h^2)
376+
(disk_a + disk_b + walls) * u"A"
377+
end
356378

357379
# Package and run tests
358380
testable = TestableGeometry(integrand, cyl, solution)
@@ -631,8 +653,6 @@ end
631653
end
632654

633655
@testitem "Meshes.Sphere 3D" setup=[Combinations] begin
634-
using CoordRefSystems: Cartesian, Spherical
635-
636656
# Geometry
637657
center = Point(1, 2, 3)
638658
radius = 4.4u"m"

0 commit comments

Comments
 (0)