zmitchell / polsim Goto Github PK
View Code? Open in Web Editor NEWA command line utility for doing polarization simulations
License: Apache License 2.0
A command line utility for doing polarization simulations
License: Apache License 2.0
If you define a useless yet valid beam as follows
[beam]
polarization = "elliptical"
x_mag = 0
y_mag = 0
x_phase = 0
y_phase = 0
angle_units = "degrees"
it will trigger the following test failure:
---- validate::test::test_validate_elliptical_pol_rejects_invalid_def stdout ----
thread 'validate::test::test_validate_elliptical_pol_rejects_invalid_def' panicked at 'Test failed: assertion failed: validate_elliptical_pol(&def).is_err() at src\validate.rs:584; minimal failing input: def = BeamDef { polarization: Elliptical, angle: None, angle_units: None, x_mag: Some(-0.0), x_phase: Some(0.0), y_mag: Some(0.0), y_phase: Some(0.0), phase_units: Some(Degrees), handedness: None }
successes: 134
local rejects: 201
201 times at float is not well-behaved
global rejects: 0
', src\validate.rs:516:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Maybe you only care about the intensity, or maybe you're going to feed the output of polsim
to another program and you don't want to deal with parsing the output to select just the intensity. In that case you should be able to invoke polsim
like this:
$ polsim --intensity my-simulation.toml
0.75
These are the flags that I think would be useful to implement:
--intensity
--x_mag
--x_phase
--y_mag
--y_phase
--ellipse-angle
--ellipse-major-axis
--ellipse-minor-axis
--eccentricity
Some ideas for useful tests:
-n/--normalize
flag is present?Currently you can only specify the units of an angle in degrees or radians. No one in the history of the universe has ever said "the angle is 1.5705 radians," but plenty of people have said "the angle is pi/2." To make describing angles more natural, it makes sense to allow the user to specify angles in units of pi. This is how that would look:
# defining an angle of pi/2
angle = 0.5
angle_units = "pi"
Another instance of this awkwardness is when you define the retardation of an optical retarder (phase plate). It would be natural to say that the retarder has a delay of some fraction of a wavelength, so adding a wavelengths
unit would also be a quality of life improvement.
This is an easy mistake to make since the elements
section is an array and thus requires [[elements]]
. The current error message
error: invalid type: map, expected enum PolType for key `beam`
doesn't tell the user that they've entered [[beam]]
when they should have entered [beam]
.
If you're running a simulation to see how some elements affect a beam, it's helpful to see a visual representation of the beam.
In general the polarization is an ellipse (linear and circular polarization are special cases), so this problem boils down to using the information in the polarization vector to plot an ellipse in Gnuplot. I want to use Gnuplot because it doesn't make sense to reinvent the wheel here.
To plot an ellipse you need to know the lengths of the major and minor axes, and the angle the ellipse makes with the +x-axis. Those equations can be found in the following (free) book:
Physics of Light and Optics - Section 6.3 (PDF)
In Gnuplot you plot an ellipse as a parametric equation. The parametric equations for a rotated ellipse can be found in this post.
The Gnuplot commands to plot a single ellipse would look something like this:
r_maj = ...
r_min = ...
angle = ...
fx(t) = ...
fy(t) = ...
set parametric
set trange [0:2*pi]
plot fx(t), fy(t) title "Ellipse"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.