Skip to content

Instantly share code, notes, and snippets.

@ThomasdenH
Created July 3, 2018 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasdenH/d11a3fe376e1839c193764ce4621969e to your computer and use it in GitHub Desktop.
Save ThomasdenH/d11a3fe376e1839c193764ce4621969e to your computer and use it in GitHub Desktop.
Casimir eigenmode summation
use std::f32::consts::PI;
/// The exponent coefficient. Determines the contribution from higher frequencies.
const S: f32 = 0.01;
/// The discrete distance difference to use.
const DELTA_D: f32 = 0.01;
/// The total size of the box, after which the geometry is periodic.
const TOTAL_DISTANCE: f32 = 1.0;
/// After the contribution from a frequency is lower than this value, the computation will stop.
const MIN_CONTRIBUTION: f32 = 1e-10;
fn main() {
let start = DELTA_D * 5.0;
let end = TOTAL_DISTANCE * 0.1;
let step = 0.001;
let mut d = start;
println!("distance force");
while d < end {
println!("{} {}", d, casimir_force(d));
d += step;
}
}
fn casimir_force(distance: f32) -> f32 {
(total_casimir_energy(distance + DELTA_D / 2.0) - total_casimir_energy(distance - DELTA_D / 2.0)) / DELTA_D
}
fn total_casimir_energy(distance: f32) -> f32 {
partial_casimir_energy(distance) + partial_casimir_energy(TOTAL_DISTANCE - distance)
}
fn partial_casimir_energy(distance: f32) -> f32 {
let mut energy = 0.0;
for n in 1.. {
let omega = PI * n as f32 / distance;
let contribution = omega * (-S * omega).exp();
energy += contribution;
if contribution < MIN_CONTRIBUTION {
break;
}
}
0.5 * energy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment