From c01290bfe4119096f35a37ab0edbf0a561602926 Mon Sep 17 00:00:00 2001 From: Peter Simon Date: Tue, 26 Nov 2024 19:45:31 -0800 Subject: [PATCH] Add orient keyword to rectstrip element (#57) --- .../rectstrip/demo_rect4.jl | 18 ++++++++++++++++++ .../rectstrip/demo_rect5.jl | 18 ++++++++++++++++++ docs/notebooks/angular_ss_example.ipynb | 6 +++--- docs/notebooks/band_pass_filter.ipynb | 6 +++--- docs/notebooks/cpss1.ipynb | 6 +++--- docs/notebooks/cpss2.ipynb | 6 +++--- docs/notebooks/cpss_optimization.ipynb | 6 +++--- .../cross_on_dielectric_substrate.ipynb | 6 +++--- docs/notebooks/flexible_absorber.ipynb | 6 +++--- docs/notebooks/manual.ipynb | 6 +++--- docs/notebooks/reflectarray_example.ipynb | 6 +++--- docs/notebooks/resistive_square_patch.ipynb | 6 +++--- docs/notebooks/splitring_cpss.ipynb | 6 +++--- docs/notebooks/splitringexample.ipynb | 6 +++--- docs/notebooks/square_loop_absorber.ipynb | 6 +++--- docs/notebooks/symmetric_strip.ipynb | 6 +++--- src/Elements.jl | 8 ++++++-- src/Sheets.jl | 19 ++++++++++++++++++- test/Elements_test.jl | 8 +++++++- 19 files changed, 109 insertions(+), 46 deletions(-) create mode 100644 docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect4.jl create mode 100644 docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect5.jl diff --git a/docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect4.jl b/docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect4.jl new file mode 100644 index 00000000..5d959544 --- /dev/null +++ b/docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect4.jl @@ -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)) diff --git a/docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect5.jl b/docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect5.jl new file mode 100644 index 00000000..39c66744 --- /dev/null +++ b/docs/PSS_&_FSS_Element_Gallery/rectstrip/demo_rect5.jl @@ -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)) diff --git a/docs/notebooks/angular_ss_example.ipynb b/docs/notebooks/angular_ss_example.ipynb index db3956a5..704b7780 100644 --- a/docs/notebooks/angular_ss_example.ipynb +++ b/docs/notebooks/angular_ss_example.ipynb @@ -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" } }, diff --git a/docs/notebooks/band_pass_filter.ipynb b/docs/notebooks/band_pass_filter.ipynb index 690584d8..5ca5eb41 100644 --- a/docs/notebooks/band_pass_filter.ipynb +++ b/docs/notebooks/band_pass_filter.ipynb @@ -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" } }, diff --git a/docs/notebooks/cpss1.ipynb b/docs/notebooks/cpss1.ipynb index fb1d508a..d2573f6c 100644 --- a/docs/notebooks/cpss1.ipynb +++ b/docs/notebooks/cpss1.ipynb @@ -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" } }, diff --git a/docs/notebooks/cpss2.ipynb b/docs/notebooks/cpss2.ipynb index c16ebd22..c8f6ccfc 100644 --- a/docs/notebooks/cpss2.ipynb +++ b/docs/notebooks/cpss2.ipynb @@ -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" } }, diff --git a/docs/notebooks/cpss_optimization.ipynb b/docs/notebooks/cpss_optimization.ipynb index ac0eae26..0a84ca71 100644 --- a/docs/notebooks/cpss_optimization.ipynb +++ b/docs/notebooks/cpss_optimization.ipynb @@ -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" } }, diff --git a/docs/notebooks/cross_on_dielectric_substrate.ipynb b/docs/notebooks/cross_on_dielectric_substrate.ipynb index 5eef69ea..57b2ca46 100644 --- a/docs/notebooks/cross_on_dielectric_substrate.ipynb +++ b/docs/notebooks/cross_on_dielectric_substrate.ipynb @@ -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" } }, diff --git a/docs/notebooks/flexible_absorber.ipynb b/docs/notebooks/flexible_absorber.ipynb index a9f33442..1a12febe 100644 --- a/docs/notebooks/flexible_absorber.ipynb +++ b/docs/notebooks/flexible_absorber.ipynb @@ -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" } }, diff --git a/docs/notebooks/manual.ipynb b/docs/notebooks/manual.ipynb index f19bc908..1cc8a19a 100644 --- a/docs/notebooks/manual.ipynb +++ b/docs/notebooks/manual.ipynb @@ -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" } }, diff --git a/docs/notebooks/reflectarray_example.ipynb b/docs/notebooks/reflectarray_example.ipynb index 21302b3d..b039ce86 100644 --- a/docs/notebooks/reflectarray_example.ipynb +++ b/docs/notebooks/reflectarray_example.ipynb @@ -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" } }, diff --git a/docs/notebooks/resistive_square_patch.ipynb b/docs/notebooks/resistive_square_patch.ipynb index 36bcf8f5..02de13b4 100644 --- a/docs/notebooks/resistive_square_patch.ipynb +++ b/docs/notebooks/resistive_square_patch.ipynb @@ -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" } }, diff --git a/docs/notebooks/splitring_cpss.ipynb b/docs/notebooks/splitring_cpss.ipynb index 36de5dde..6759b05b 100644 --- a/docs/notebooks/splitring_cpss.ipynb +++ b/docs/notebooks/splitring_cpss.ipynb @@ -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" } }, diff --git a/docs/notebooks/splitringexample.ipynb b/docs/notebooks/splitringexample.ipynb index 537fa17a..5d69d572 100644 --- a/docs/notebooks/splitringexample.ipynb +++ b/docs/notebooks/splitringexample.ipynb @@ -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" } }, diff --git a/docs/notebooks/square_loop_absorber.ipynb b/docs/notebooks/square_loop_absorber.ipynb index 177912a6..af06353f 100644 --- a/docs/notebooks/square_loop_absorber.ipynb +++ b/docs/notebooks/square_loop_absorber.ipynb @@ -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" } }, diff --git a/docs/notebooks/symmetric_strip.ipynb b/docs/notebooks/symmetric_strip.ipynb index d5c6b593..f31e5596 100644 --- a/docs/notebooks/symmetric_strip.ipynb +++ b/docs/notebooks/symmetric_strip.ipynb @@ -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" } }, diff --git a/src/Elements.jl b/src/Elements.jl index 43d3836c..72be295c 100644 --- a/src/Elements.jl +++ b/src/Elements.jl @@ -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, ⋅, × @@ -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) @@ -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] diff --git a/src/Sheets.jl b/src/Sheets.jl index 0c2d15bf..01a54d92 100644 --- a/src/Sheets.jl +++ b/src/Sheets.jl @@ -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 @@ -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) diff --git a/test/Elements_test.jl b/test/Elements_test.jl index 56b7351a..d5a83b57 100644 --- a/test/Elements_test.jl +++ b/test/Elements_test.jl @@ -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] @@ -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