Skip to content

Commit

Permalink
Add orient keyword to rectstrip element (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonp0420 authored Nov 27, 2024
1 parent 7aee785 commit c01290b
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 46 deletions.
18 changes: 18 additions & 0 deletions docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect4.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ---
# title: Rotated Rectangular Strip
# cover: "assets/demo_rect4.png"
# description: "Rotated rectangular strips created by the rectstrip function"
# ---

# This example uses the `rot` keyword and should be compared to the
# [`diagstrip` example](../diagstrip/demo_diagstrip1.html) and the
# [`rectstrip` example](./demo_rect5.html) that uses the `orient` keyword.


using Plots, PSSFSS
strip = rectstrip(Nx=10, Ny=2, Px=1, Py=1, Lx=0.5, Ly=0.1, rot=45, units=cm)
p1 = plot(strip, unitcell=true, linecolor=:red)
plot(strip, axis=false, xlabel="", ylabel="", xtick=[], ytick=[], linecolor=:green, size=(300,300), rep=(4,3)) #src
savefig("assets/demo_rect4.png") #src
p2 = plot(strip, rep=(3,3), linecolor=:blue)
plot(p1, p2, layout=(1,2), size=(600,300))
18 changes: 18 additions & 0 deletions docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect5.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ---
# title: Oriented Rectangular Strip
# cover: "assets/demo_rect5.png"
# description: "Oriented rectangular strips created by the rectstrip function"
# ---

# This example uses the `orient` keyword and should be compared to the
# [`diagstrip` example](../diagstrip/demo_diagstrip1.html) and the
# [`rectstrip` example](./demo_rect4.html) that uses the `rot` keyword.


using Plots, PSSFSS
strip = rectstrip(Nx=10, Ny=2, Px=1, Py=1, Lx=0.5, Ly=0.1, orient=45, units=cm)
p1 = plot(strip, unitcell=true, linecolor=:red)
plot(strip, axis=false, xlabel="", ylabel="", xtick=[], ytick=[], linecolor=:green, size=(400,300), rep=(4,3)) #src
savefig("assets/demo_rect5.png") #src
p2 = plot(strip, rep=(3,3), linecolor=:blue)
plot(p1, p2, layout=(1,2), size=(600,300))
6 changes: 3 additions & 3 deletions docs/notebooks/angular_ss_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/band_pass_filter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/cpss1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/cpss2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/cpss_optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/cross_on_dielectric_substrate.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/flexible_absorber.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/manual.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1154,11 +1154,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/reflectarray_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/resistive_square_patch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/splitring_cpss.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/splitringexample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/square_loop_absorber.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/symmetric_strip.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.2"
"version": "1.11.1"
},
"kernelspec": {
"name": "julia-1.10",
"display_name": "Julia 1.10.2",
"name": "julia-1.11",
"display_name": "Julia 1.11.1",
"language": "julia"
}
},
Expand Down
8 changes: 6 additions & 2 deletions src/Elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Elements
export diagstrip, jerusalemcross, loadedcross, manji, meander, pecsheet, pmcsheet, polyring, rectstrip, sinuous, splitring

using ..PSSFSSLen: mm, cm, inch, mil, PSSFSSLength
using ..Sheets: RWGSheet, rotate!, translate!, combine, recttri, SV2
using ..Sheets: RWGSheet, rotate!, translate!, combine, recttri, SV2, orient!
using ..Meshsub: meshsub
using StaticArrays: SA
using LinearAlgebra: norm, , ×
Expand Down Expand Up @@ -1342,9 +1342,12 @@ All arguments are keyword arguments which can be entered in any order.
rectangles, which are triangulated by adding a diagonal to each rectangle.
## Optional arguments:
- `orient::Real=0.0`: Counterclockwise rotation angle in degrees applied to the strip within the unrotated unit cell.
This rotation is applied prior to any offsets specified in `dx` and `dy` and any unit cell rotation specified
by `rot`.
$(optional_kwargs)
"""
function rectstrip(; Lx::Real, Ly::Real, Nx::Int, Ny::Int, Px::Real, Py::Real, units::PSSFSSLength,
function rectstrip(; Lx::Real, Ly::Real, Nx::Int, Ny::Int, Px::Real, Py::Real, units::PSSFSSLength, orient::Real=0.0,
kwarg...)::RWGSheet
kwargs = Dict{Symbol,Any}(kwarg)
haskey(kwargs, :fufp) || (kwargs[:fufp] = true)
Expand Down Expand Up @@ -1377,6 +1380,7 @@ function rectstrip(; Lx::Real, Ly::Real, Nx::Int, Ny::Int, Px::Real, Py::Real, u
# Handle remaining optional arguments
sheet.fufp = kwargs[:fufp]
sheet.class = kwargs[:class]
iszero(orient) || orient!(sheet, orient, 0.5 * SV2(Px,Py))
rotate!(sheet, kwargs[:rot])
dxdy = SV2([kwargs[:dx], kwargs[:dy]])
if dxdy [0.0, 0.0]
Expand Down
19 changes: 18 additions & 1 deletion src/Sheets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ end
"""
rotate!(sh::RWGSheet, rot::Real)
Rotate a sheet by rot degrees (counter-clockwise).
Rotate a sheet by rot degrees (counter-clockwise). The entire unit cell and its
contents are rotated.
"""
function rotate!(sh::RWGSheet, rot::Real)
rot == 0 && return
Expand All @@ -287,6 +288,22 @@ function rotate!(sh::RWGSheet, rot::Real)
return sh
end

"""
orient!(sh::RWGSheet, rot::Real, center::AbstractVector)
Rotate a sheet by rot degrees (counter-clockwise) about the point specified by `center`.
Only the content of the unit cell (the triangulation) is rotated. The unit cell is left unchanged.
"""
function orient!(sh::RWGSheet, rot::Real, center::AbstractVector)
rot == 0 && return
s, c = sincosd(rot)
rotmat = SMatrix{2,2}([c -s; s c])
for n in eachindex(sh.ρ)
sh.ρ[n] = center + rotmat * (sh.ρ[n] - center)
end
return sh
end


"""
translate!(sh::RWGSheet, dx, dy)
Expand Down
8 changes: 7 additions & 1 deletion test/Elements_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Test
using LinearAlgebra: norm

sh1 = rectstrip(Lx=1, Ly=1.0, Nx=1, Ny=1, Px=1, Py=1, units=inch)

sh2 = deepcopy(sh1)
@testset "recstrip" begin
@test length(sh1.ρ) == 4
@test sh1.ρ[2] - sh1.ρ[1] == [1, 0]
Expand All @@ -25,6 +25,12 @@ sh1 = rectstrip(Lx=1, Ly=1.0, Nx=1, Ny=1, Px=1, Py=1, units=inch)
@test sh1.Zs == 0
end

@testset "orient!" begin
PSSFSS.Sheets.orient!(sh2, 45, [0,0])
PSSFSS.Sheets.orient!(sh2, -45, [0,0])
@test sh1.ρ sh2.ρ
end

Z = 0.2 + 0.3im
sh2 = rectstrip(Lx=1, Ly=1.0, Nx=1, Ny=1, Px=1, Py=1, units=inch, Zsheet=Z)
@testset "Zsheet" begin
Expand Down

0 comments on commit c01290b

Please sign in to comment.