Skip to content

Commit

Permalink
Implement a parametrization function for Wedge (#1162)
Browse files Browse the repository at this point in the history
* Add draft parametrization function

* Improve parametrization of Wedge

* Change naming

* Fix test

* Use API instead of direct struct access

* Add a test_throws for out-of-bounds coord, add T converts

* Update error type

* Change parametrization to use Quadrangles instead of Triangles

* Simplify code

---------

Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
  • Loading branch information
mikeingold and juliohm authored Jan 20, 2025
1 parent 3f12c6a commit 58d5b28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/geometries/polytopes/wedge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ nvertices(::Type{<:Wedge}) = 6

Base.isapprox(t₁::Wedge, t₂::Wedge; atol=atol(lentype(t₁)), kwargs...) =
all(isapprox(v₁, v₂; atol, kwargs...) for (v₁, v₂) in zip(t₁.vertices, t₂.vertices))

function (wedge::Wedge)(u, v, w)
if (u < 0 || u > 1) || (v < 0 || v > 1) || (w < 0 || w > 1)
throw(DomainError((u, v, w), "wedge(u, v, w) is not defined for u, v, w outside [0, 1]³."))
end
a₁, a₂, a₃, b₁, b₂, b₃ = vertices(wedge)
q₁ = Quadrangle(a₁, b₁, b₂, a₂)
q₂ = Quadrangle(a₁, b₁, b₃, a₃)
s = Segment(q₁(u, v), q₂(u, v))
s(w)
end
2 changes: 2 additions & 0 deletions test/polytopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,8 @@ end
@test crs(w) <: Cartesian{NoDatum}
@test Meshes.lentype(w) ==
@test volume(w) T(1 / 2) * u"m^3"
@test w(T(1), T(1), T(1)) == vertices(w)[6]
@test_throws DomainError w(T(0), T(0), T(1.5))
m = boundary(w)
@test m isa Mesh
@test nelements(m) == 5
Expand Down

0 comments on commit 58d5b28

Please sign in to comment.