Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
b1cf578
feat: implement AstigmaticGaussianBeamlet with synchronised tracing a…
TacHawkes Apr 27, 2026
b57742d
Fix docs
TacHawkes Apr 27, 2026
6427c34
Add some missing stuff
TacHawkes Apr 27, 2026
9ff6ac5
Improve AGB constructors to make the drop-in compatible
TacHawkes Apr 28, 2026
1a02154
Adapt exports slightly
TacHawkes Apr 28, 2026
f154c5c
Test AGBs
TacHawkes Apr 29, 2026
2c3abad
Flip Guoy phase sign, correct beam waist size and fix Surface-Spec
TacHawkes Apr 29, 2026
ed21f51
Address codex issues
TacHawkes Apr 29, 2026
fda03c1
Bump CI julia versions
TacHawkes Apr 30, 2026
18a1b7b
use built-in ellipse helper fc.t
Apr 30, 2026
7efd6bb
render all agb rays,, standard options as with GaussianBeamlet
Apr 30, 2026
efde7f7
add show_waist kwarg
Apr 30, 2026
2b4208c
Sample both directions of the parabasal vectors and consider the phas…
TacHawkes May 1, 2026
274590e
Re-add the check for on-axis waists
TacHawkes May 1, 2026
0a060e9
More fixes to the core math
TacHawkes May 1, 2026
4c14e57
More phase fixes
TacHawkes May 1, 2026
1a37903
Sort the math again so it makes more sense
TacHawkes May 1, 2026
6607691
Add Fraunhofer diffraction test case, add optical invariant check to …
TacHawkes May 2, 2026
51a5bbb
Add AGB beam groups, simple decomposition, docs and a lot of small th…
TacHawkes May 2, 2026
1a090a5
Add double-slit example
TacHawkes May 3, 2026
558a235
Fix whitespaces
TacHawkes May 3, 2026
d2abf92
Improve AGB explanation
TacHawkes May 3, 2026
1aec887
Minor cleanup
TacHawkes May 3, 2026
c64618a
Bump Julia compat and mark todos
TacHawkes May 3, 2026
0a65515
Improve comments
May 4, 2026
d9ce86a
disable detector.md figs if not in CI pipeline
May 4, 2026
774ce50
change agb show_beams color
May 4, 2026
a9cdee9
fix for render bug (?)
May 4, 2026
59b4409
Fix parabasal calculation, check all invariants and be way more stric…
TacHawkes May 4, 2026
c46a8e4
Address further issues
TacHawkes May 4, 2026
756c15d
Try unifying waist parameters
TacHawkes May 4, 2026
84046a7
Address new codex issues
TacHawkes May 5, 2026
760812f
Relax Logging compat
May 5, 2026
05a0824
rm deprecated GB constructor
May 5, 2026
562b089
allow disable of invariant check for some situations
May 5, 2026
58524c7
split beams.md
May 5, 2026
fc37b9f
add citations and some illustrations
May 5, 2026
d31c48e
Minor formatting changes
TacHawkes May 5, 2026
cd8c8f2
Use Preferences.jl for constants, add P0/E0 where necessary.
TacHawkes May 5, 2026
4511529
Forgot to commit Project.toml
TacHawkes May 5, 2026
776aa95
Some small fixes and minor speed optimizations
TacHawkes May 6, 2026
7483683
Introduce caching of propagation data for GB/AGBs to speed up electri…
TacHawkes May 6, 2026
0c3136f
add BMO.config to docs index (bug fix)
May 6, 2026
f40d1eb
update cond_save
May 6, 2026
acb3972
make cond_save even more retarded :D
May 6, 2026
23ede7b
agb docs
May 6, 2026
916087d
enable multiline matching...
May 6, 2026
ba43ef6
move double slit example to example section
May 6, 2026
33e697f
Minor improvements to detector optimization
TacHawkes May 7, 2026
c8dfae4
minor gb docs update
May 7, 2026
b038e65
Some more minor performance tweaks
TacHawkes May 7, 2026
1ddd1eb
minor agb doc changes
May 7, 2026
ac92e85
Merge branch 'AstigmaticGausslets' of https://github.com/JuliaPhysics…
May 7, 2026
0ce47dc
Fix polarization bug, improve field calculation and (re)tracing of AGBs.
TacHawkes May 8, 2026
4bb4e26
mini doc changes
May 8, 2026
5d21a79
Merge branch 'AstigmaticGausslets' of https://github.com/JuliaPhysics…
May 8, 2026
217edc4
Exp. fix for AGB twisting
TacHawkes May 9, 2026
f57c4b5
AGBs make my brain explode...
TacHawkes May 9, 2026
4c6d1ef
Merge remote-tracking branch 'refs/remotes/origin/AstigmaticGausslets…
TacHawkes May 9, 2026
6e4db6e
Elliptical beam groups, some QoL improvements, document the waist par…
TacHawkes May 9, 2026
4bd6ec6
Address codex issues
TacHawkes May 9, 2026
e669bd1
Fix doc errors
TacHawkes May 9, 2026
ffe985b
Add warning about invariant check to general AGB constructor
TacHawkes May 9, 2026
9cf1f14
Make sure all exported functions have docstrings
TacHawkes May 9, 2026
0aea026
Fix power convention issue
TacHawkes May 10, 2026
9336f9c
Fix and test AGB initialization with different waist offsets.
TacHawkes May 17, 2026
bc0ef47
move cond_incl to DocUtils.jl module
May 18, 2026
5708e23
update .gitignore to allow pre-rendered images
May 18, 2026
98adb60
add prerender_include fct
May 18, 2026
be60ec3
add docs to new DocUtils
May 18, 2026
5fa7782
rm placeholder statements
May 18, 2026
8fdcbf4
add calc_center_points tests
May 19, 2026
637f8a1
test calc_local_pos for gb
May 22, 2026
aa16f58
test calc_local_pos for agb
May 22, 2026
172dff7
Bump version
TacHawkes May 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.12'
- '1.10'
- '1.9'
- 'pre'
os:
- ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ Thumbs.db
*.jl.mem
.vscode

# ignore image formats
*.png
*.gif
*.svg

# allow pre-rendered images within docs folder
!docs/src/**/*.png
!docs/src/**/*.gif
!docs/src/**/*.svg

snoop_compile/

/Manifest.toml
Expand Down
12 changes: 9 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BeamletOptics"
uuid = "c387492b-ffec-4e51-9a46-bd230226031c"
version = "0.13.0"
authors = ["Hugo Uittenbosch <hugo.uittenbosch@dlr.de>, Oliver Kliebisch <oliver.kliebisch@dlr.de> and Thomas Dekorsy <thomas.dekorsy@dlr.de>"]
version = "0.12.1"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand All @@ -13,6 +13,8 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MarchingCubes = "299715c1-40a9-479a-aaf9-4a633d36f717"
MeshIO = "7269a6da-0436-5bbc-96c2-40638cbb6118"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Trapz = "592b5752-818d-11e9-1e9a-2b8ca4a44cd1"

Expand All @@ -30,18 +32,22 @@ ForwardDiff = "0.10, 1.0.1"
GeometryBasics = "0.5"
InteractiveUtils = "1"
LinearAlgebra = "1"
Logging = "1"
Makie = "0.22, 0.23, 0.24"
MarchingCubes = "0.1"
MeshIO = "0.5"
PrecompileTools = "1"
Preferences = "1.5.2"
Random = "1"
StaticArrays = "1"
Test = "1"
Trapz = "2"
julia = "1.9.4"
julia = "1.10"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test"]
test = ["Aqua", "Test", "Logging"]
128 changes: 128 additions & 0 deletions docs/DocUtils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
module DocUtils

using GLMakie: Figure, Axis, hidedecorations!, text!, save
using Dates: now

const GLOBAL_USE_PLACEHOLDERS = true

"""
conditional_include(fname; use_placeholder=!haskey(ENV, "CI"))

This is a function to speed up compilation time when building the docs locally.
It checks whether the `include` call is made locally or from within the **CI environment**.
In the former case, script evaluation is avoided and a placeholder figure is created for
each `save` call within the script.

Evaluation can be forced by setting `use_placeholder = false`. Global evaluation can be forced
by setting `GLOBAL_USE_PLACEHOLDERS = false` in this file (does not apply for CI env.).
"""
function conditional_include(fname::String; use_placeholder::Bool=!haskey(ENV, "CI"))
# Check for global flag if not within CI env.
if !haskey(ENV, "CI") && !GLOBAL_USE_PLACEHOLDERS
use_placeholder = false
end
# Check if to run script
if use_placeholder
content = read(fname, String)
# match save("filename") but ignore comments, i.e. # save(...)
pattern = Regex("^[ \\t]*save\\(\\s*\"([^\"]+)\"\\s*,\\s*([a-zA-Z_][a-zA-Z0-9_]*)", "m")
for match in eachmatch(pattern, content)
save_name = match.captures[1]
fig_name = match.captures[2]
offset = match.offset
prior_content = content[1:offset]
# find last missing fig_name variable match
npattern = Regex("\\Q$fig_name\\E\\s*=\\s*Figure\\(.*?size\\s*=\\s*\\(([\\d]+)\\s*,\\s*([\\d]+)\\)")
matches = collect(eachmatch(npattern, prior_content))
if !isempty(matches)
nmatch = last(matches)
_width = parse(Int, nmatch.captures[1])
_height = parse(Int, nmatch.captures[2])
else
@info "Using default height for $fig_name"
_width = 600
_height = 300
end
# save placeholder
fig = Figure(size=(_width, _height))
ax = Axis(fig[1,1], backgroundcolor=:gray)
hidedecorations!(ax)
text!(ax, 0, 0;
text="$save_name\n($_width x $_height)",
align=(:center, :center),
color=:white,
fontsize=20
)
save(save_name, fig)
@info "Saving placeholder for $save_name (Size: $_width x $_height, fig_var_name=$fig_name)"
end
else
@info "Running script for $fname"
t1 = now()
include(fname)
t2 = now()
@info " Runtime: $(t2-t1)"
end
end

function replace_build_with_src(path::String)
clean_path = abspath(path)
build_segment = joinpath("docs", "build")
src_segment = joinpath("docs", "src")
src_path = replace(clean_path, build_segment => src_segment)
return src_path
end

"""
prerender_include(fname::String, cname::String)

This function runs the build script and places the images within the docs\\src folder when run outside of the CI/CD pipeline.
It is recommended to use this approach when the rendered image is too computationally intensive for the github runner.
If a prerendered image already exists, it has to be **deleted manually** in order to trigger a re-run.

# Arguments

- `fname`: points to the BMO render script
- `cname`: points to the executing markdown script

!!! info
It is highly recommended that the `@__FILE__` macro is passed into `cname` within the executing markdown block.
E.g. within a .md file:

`Main.DocUtils.prerender_include("myscript.jl", @__FILE__)`
"""
function prerender_include(fname::String, cname::String)
location = replace_build_with_src(dirname(cname))
content = read(fname, String)
pattern = Regex("^[ \\t]*save\\(\\s*\"([^\"]+)\"\\s*,\\s*([a-zA-Z_][a-zA-Z0-9_]*)", "m")
all_files_there = true
for match in eachmatch(pattern, content)
# check if file already exists
save_name = match.captures[1]
if !isfile(joinpath(location, save_name))
if haskey(ENV, "CI")
throw(ErrorException("Running $fname in CI pipeline, missing $save_name at $location"))
end
all_files_there = false
break
end
end
# if all pre-rendered files exist, do nothing
if all_files_there
@info "Found pre-rendered images for $fname"
return nothing
end
# if files missing, run script
@warn "Detected missing pre-rendered file/s for script $fname, running..."
include(fname)
# scan for figs, copy to src folder
for match in eachmatch(pattern, content)
save_name = match.captures[1]
path_name = dirname(cname)
@info "Copying $save_name from \\build to \\src"
cp(joinpath(path_name, save_name), joinpath(location, save_name); force=true)
end
return nothing
end

end
17 changes: 15 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ using BeamletOptics
using Documenter
using DocumenterCitations

DocMeta.setdocmeta!(BeamletOptics, :DocTestSetup, :(using BeamletOptics); recursive=true)
include(joinpath(@__DIR__, "DocUtils.jl"))

DocMeta.setdocmeta!(
BeamletOptics,
:DocTestSetup,
:(using BeamletOptics);
recursive=true
)

bib = CitationBibliography(joinpath(@__DIR__, "src", "refs.bib"))

Expand Down Expand Up @@ -34,12 +41,18 @@ makedocs(;
"Aspherical lenses" => joinpath("examples", "aspherical_lenses.md"),
"Double Gauss lens" => joinpath("examples", "double_gauss.md"),
"Lens groups" => joinpath("examples", "lens_groups.md"),
"Double slit" => joinpath("examples", "double_slit.md"),
],
],
"Basics" => Any[
"Introduction" => joinpath("basics", "intro.md"),
"Rays" => joinpath("basics", "rays.md"),
"Beams" => joinpath("basics", "beams.md"),
"Beams" => Any[
"Basic beam" => joinpath("basics", "beams", "beams.md"),
"Stigmatic Gaussian" => joinpath("basics", "beams", "stigmatic_beam.md"),
"Astigmatic Gaussian" => joinpath("basics", "beams", "astigmatic_beam.md"),
"Beam groups" => joinpath("basics", "beams", "beam_groups.md"),
],
"Optical components" => Any[
"Overview" => joinpath("basics", "components", "components.md"),
"Mirrors" => joinpath("basics", "components", "mirrors.md"),
Expand Down
7 changes: 3 additions & 4 deletions docs/src/api/docdev.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ In general, you can generate and include figures into your documentation section
- files will be saved with respect to the calling environment
3. In the markdown file that contains your documentation and should load your images, do the following:
1. create a `@setup` code block
2. include the `conditional_include` via e.g. `include(joinpath(@__DIR__, "..", "assets", "cond_save.jl"))`
- ensure that the relative file path is correct
3. load your script during build via `conditional_include`
- more info on this function is provided in the `cond_save.jl` file
2. load your script during build via `Main.DocUtils.conditional_include`
- more info on this function is provided in the `DocUtils.jl` file
3. Or, alternatively use `Main.DocUtils.prerender_include` to generate the image locally
4. Load the image within your markdown file via `![My figure](my_fig.png)`

Examples for this pattern can be found at the top of most .md files of the documentation, e.g. `beamsplitters.md`.
Expand Down
4 changes: 1 addition & 3 deletions docs/src/api/meshes.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
```@setup rays
include(joinpath(@__DIR__, "..", "assets", "cond_save.jl"))

dir = joinpath(@__DIR__, "..", "assets")

conditional_include(joinpath(dir, "meshes.jl"))
Main.DocUtils.conditional_include(joinpath(dir, "meshes.jl"))
```

# Meshes
Expand Down
4 changes: 1 addition & 3 deletions docs/src/api/sdfs.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
```@setup rays
include(joinpath(@__DIR__, "..", "assets", "cond_save.jl"))

dir = joinpath(@__DIR__, "..", "assets")

conditional_include(joinpath(dir, "raymarching.jl"))
Main.DocUtils.conditional_include(joinpath(dir, "raymarching.jl"))
```

# Signed Distance Functions (SDFs)
Expand Down
98 changes: 98 additions & 0 deletions docs/src/assets/beam_renders/agb_showcase.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using GLMakie, BeamletOptics

GLMakie.activate!(; ssao=true)

const BMO = BeamletOptics

const mm = 1e-3

include(joinpath(@__DIR__, "..", "render_utils.jl"))

##
c_view = [
0.605459 0.783477 -0.139944 -0.0298959
-0.0484677 0.211806 0.976109 -0.0106539
0.7944 -0.584211 0.166213 -1.69474
0.0 0.0 0.0 1.0
]

agb = AstigmaticGaussianBeamlet([0,0,0], [0,1,0], 9e-4, 2e-3; support=[0,0,1])

l = ThinLens(20e-3, 20e-3, BMO.inch, 1.5)
s = System([l])

translate3d!(l, [0, 30e-3, 0])

fig1 = Figure(size=(600,300))
display(fig1)
ax = LScene(fig1[1,1])
hide_axis(ax)

render!(ax, agb; flen=0.1-0.03, show_beams=true, show_pos=true, color=RGBAf(1,0,0,0.1))

set_orthographic(ax)
set_view(ax, c_view)

save("agbtest1.png", fig1; px_per_unit=8, update = false)

##
solve_system!(s, agb; check_invariant=false)

fig = Figure(size=(600,300))
display(fig)
ax = LScene(fig[1,1])
hide_axis(ax)
render!(ax, agb; flen=0.1-0.03, show_beams=true, show_pos=true, color=RGBAf(1,0,0,0.1))
render!(ax, l; color=RGBAf(1, 1, 1, .1))

c_view = [
0.653709 0.756746 -5.27356e-16 -0.0173098
-0.352701 0.304679 0.884744 -0.00702154
0.669526 -0.578366 0.466077 -0.0223342
0.0 0.0 0.0 1.0
]

set_view(ax, c_view)
save("agbtest2.png", fig; px_per_unit=8, update = false)

##
s1 = BMO.CylinderSDF(BMO.inch/2, BMO.inch)
s2 = BMO.CylinderSDF(BMO.inch/2, BMO.inch)
l1 = BMO.Lens(s1, n->1.5)
l2 = BMO.Lens(s2, n->1.5)
translate3d!(l1, [0, 50mm, 0])
translate3d!(l2, [0, 100mm, 0])
xrotate3d!(l1, deg2rad(90))
xrotate3d!(l2, deg2rad(90))
yrotate3d!(l1, deg2rad(90))
translate3d!(l2, [5mm, 0, 0])

system = System([l1, l2])

z_os = 0e-3
w0 = 2mm
λ0 = 1000e-9
dir = [0,1,0]
E0 = [0,0,1]
beam = AstigmaticGaussianBeamlet([0., 0, z_os], dir, λ0, w0; E0, support=[0,0,1])

solve_system!(system, beam; check_invariant=false)

##
fig = Figure(size=(600,400))
display(fig)
ax = LScene(fig[1,1])
hide_axis(ax)
render!(ax, l1; color=RGBAf(1, 1, 1, .2))
render!(ax, l2; color=RGBAf(1, 1, 1, .2))
render!(ax, beam; color=RGBAf(1,0,0,0.2), z_res=4, r_res=20, show_waist=true, markersize=4, flen=0.1)

view = [
0.763832 0.645415 3.88578e-16 -0.0541476
-0.444252 0.525762 0.725407 -0.0339012
0.468188 -0.554089 0.68832 -0.0967937
0.0 0.0 0.0 1.0
]

set_view(ax, view)
save("agbtest3.png", fig; px_per_unit=8, update = false)
Loading