From f3ba3f97f9abea8c4aff5c27588059b4fc823b4e Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Tue, 31 Dec 2024 11:50:27 -0500 Subject: [PATCH 1/6] Add analytical test for Cylinder --- test/combinations.jl | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test/combinations.jl b/test/combinations.jl index 22de4bc5..fc0925d3 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -14,6 +14,7 @@ This file includes tests for: ===============================================================================# @testsnippet Combinations begin + using CoordRefSystems using LinearAlgebra: norm using Meshes using MeshIntegrals @@ -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 * ρ₀ * (ρ₀ + h + 2π * u"m") * u"A" # Package and run tests testable = TestableGeometry(integrand, cyl, solution) From 4fcbc62589b83a8949b9716fe2167bbc2914a1b7 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Tue, 31 Dec 2024 11:51:11 -0500 Subject: [PATCH 2/6] CRS is now available file-wide --- test/combinations.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/combinations.jl b/test/combinations.jl index fc0925d3..77baf64a 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -640,8 +640,6 @@ end end @testitem "Meshes.Sphere 3D" setup=[Combinations] begin - using CoordRefSystems: Cartesian, Spherical - # Geometry center = Point(1, 2, 3) radius = 4.4u"m" From 1d2bbc4d59fb9d8f44908f092a210a93098140fb Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Tue, 31 Dec 2024 12:00:56 -0500 Subject: [PATCH 3/6] Add test for CylinderSurface --- test/combinations.jl | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/test/combinations.jl b/test/combinations.jl index 77baf64a..ab756579 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -355,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) From 729cca7707957c8a06ae0a534043613ebb5845b2 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Tue, 31 Dec 2024 12:03:59 -0500 Subject: [PATCH 4/6] Add note --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d780ccd6..13971714 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 75898e90458700d4be12ab63377781f5bed10dab Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Tue, 31 Dec 2024 12:10:24 -0500 Subject: [PATCH 5/6] Use less-simplified solution for clarity --- test/combinations.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/combinations.jl b/test/combinations.jl index ab756579..5767dc17 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -346,7 +346,7 @@ end z = p_cyl.z ρ^(-1) * (ρ + φ * u"m" + z) * u"A" end - solution = π * h * ρ₀ * (ρ₀ + h + 2π * u"m") * u"A" + solution = ((π * h * ρ₀^2) + (π * h^2 * ρ₀) + (2π * π * u"m" * h * ρ₀)) * u"A" # Package and run tests testable = TestableGeometry(integrand, cyl, solution) From fc474a615c5a4b6956d55386d9a8aa24aecb89d1 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Tue, 31 Dec 2024 12:10:47 -0500 Subject: [PATCH 6/6] Apply format suggestion Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- test/combinations.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/combinations.jl b/test/combinations.jl index 5767dc17..dac7bdf3 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -369,7 +369,7 @@ end z = p_cyl.z ρ^(-1) * (ρ + φ * u"m" + z) * u"A" end - solution = let + 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)