Coder Social home page Coder Social logo

polsim's Issues

Valid but useless beam definition causes a test to fail

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.

Add flags for only reporting one characteristic of the final beam

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:

  • Is it possible to print the full set of results even when one of these flags is present?
  • Does the output when the flag is present normalize properly when the -n/--normalize flag is present?

Add more units for convenience

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.

Better error message when file contains [[beam]] instead of [beam]

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].

Illustrate original/final polarizations with gnuplot

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"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.