Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
30 changes: 16 additions & 14 deletions src/dipole/force.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub mod tests {
assert_approx_eq!(-3.11151847e-23, sim_result_force[2], 2e-24_f64);
}

#[test]
#[test] // Modified by Yijun on 2024/07/16
fn test_apply_dipole_force_and_gradient_system() {
let mut test_world = World::new();

Expand All @@ -171,7 +171,7 @@ pub mod tests {
intersection: Vector3::new(0.0, 0.0, 0.0),
e_radius,
power,
direction: Vector3::x(),
direction: Vector3::y(),
rayleigh_range: crate::laser::gaussian::calculate_rayleigh_range(&1064.0e-9, &e_radius),
ellipticity: 0.0,
};
Expand All @@ -186,15 +186,15 @@ pub mod tests {
initiated: true,
})
.with(laser::frame::Frame {
x_vector: Vector3::y(),
y_vector: Vector3::z(),
x_vector: Vector3::z(),
y_vector: Vector3::x(),
})
.build();
let gaussian_beam = GaussianBeam {
intersection: Vector3::new(0.0, 0.0, 0.0),
e_radius,
power,
direction: Vector3::y(),
direction: Vector3::x(),
rayleigh_range: crate::laser::gaussian::calculate_rayleigh_range(&1064.0e-9, &e_radius),
ellipticity: 0.0,
};
Expand All @@ -209,7 +209,7 @@ pub mod tests {
initiated: true,
})
.with(laser::frame::Frame {
x_vector: Vector3::x(),
x_vector: Vector3::y(),
y_vector: Vector3::z(),
})
.build();
Expand All @@ -218,7 +218,7 @@ pub mod tests {
let atom1 = test_world
.create_entity()
.with(crate::atom::Position {
pos: Vector3::new(-1.0e-4, -1.0e-4, -2.0e-4),
pos: Vector3::new(-1.0e-4, -1.0e-4, 2.0e-4),
})
.with(Force {
force: Vector3::new(0.0, 0.0, 0.0),
Expand Down Expand Up @@ -248,21 +248,23 @@ pub mod tests {
//println!("force is: {}", sim_result_force);
//println!("gradient 1 is: {}", sim_result_grad[0].gradient);
//println!("gradient 2 is: {}", sim_result_grad[1].gradient);

println!("force x is: {}", sim_result_force[0]);
println!("force y is: {}", sim_result_force[1]);
println!("force z is: {}", sim_result_force[2]);
assert_approx_eq!(
0.000000000000000000000000000000000127913190642808,
0.00000000000000000000000000000000012749214960,
sim_result_force[0],
3e-46_f64
3e-40_f64
);
assert_approx_eq!(
0.000000000000000000000000000000000127913190642808,
0.00000000000000000000000000000000012749214960,
sim_result_force[1],
2e-46_f64
2e-40_f64
);
assert_approx_eq!(
0.000000000000000000000000000000000511875188257342,
-0.0000000000000000000000000000000005101862262458,
sim_result_force[2],
2e-46_f64
2e-40_f64
);
}
}
29 changes: 27 additions & 2 deletions src/laser/gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ pub fn get_gaussian_beam_intensity_gradient(

let spot_size_squared =
2.0 * beam.e_radius.powf(2.0) * (1. + (z / beam.rayleigh_range).powf(2.0));
let vector = -4. * (reference_frame.x_vector * x + reference_frame.y_vector * y)
let vector = -4. * (reference_frame.x_vector / semi_major_axis.powf(0.5) * x + reference_frame.y_vector * y * semi_major_axis.powf(0.5))
// /semi_major_axis.powf(0.5) AND *semi_major_axis.powf(0.5) here accounts for the chain rule when calculation gradient force
+ beam.direction * z / (beam.rayleigh_range.powf(2.0) + z.powf(2.0))
* (- 2.0 * spot_size_squared + 4. * (x.powf(2.0) + y.powf(2.0)));
let intensity = 2. * beam.power / PI / spot_size_squared
Expand Down Expand Up @@ -274,7 +275,31 @@ pub mod tests {
let gradient = get_gaussian_beam_intensity_gradient(&beam, &pos1, &grf);
assert_approx_eq!(gradient[0], -2.49605032e+13, 1e+8_f64);
assert_approx_eq!(gradient[1], 0.0, 1e+9_f64);
assert_approx_eq!(gradient[2], -2.06143366e+08, 1e+6_f64);
assert_approx_eq!(gradient[2], -4.20876029e+08, 1e+6_f64); // Modified by Yijun on 2024/07/16
}

#[test] // added by Yijun on 2024/07/16 to test the gradient calculation for a beam with ellipticity
fn test_get_elliptic_gaussian_beam_intensity_gradient() {
let beam = GaussianBeam {
direction: Vector3::z(),
intersection: Vector3::new(0.0, 0.0, 0.0),
e_radius: 70.71067812e-6,
power: 100.0,
rayleigh_range: calculate_rayleigh_range(&1064.0e-9, &70.71067812e-6),
ellipticity: 0.5,
};
let pos1 = Position {
pos: Vector3::new(10.0e-6, 10.0e-6, 30.0e-6),
};
let grf = Frame {
x_vector: Vector3::x(),
y_vector: Vector3::y(),
};

let gradient = get_gaussian_beam_intensity_gradient(&beam, &pos1, &grf);
assert_approx_eq!(gradient[0], -2.11796152e+13, 1e+8_f64);
assert_approx_eq!(gradient[1], -2.82394869e+13, 1e+9_f64);
assert_approx_eq!(gradient[2], -4.03781010e+08, 1e+6_f64);
}

#[test]
Expand Down
16 changes: 8 additions & 8 deletions src/laser/intensity_gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub mod tests {
1e+5_f64
);
}
#[test]
#[test] // modified by Yijun on 2024/07/16
fn test_sample_laser_intensity_gradient_again_system() {
let mut test_world = World::new();

Expand Down Expand Up @@ -204,8 +204,8 @@ pub mod tests {
})
.with(beam)
.with(Frame {
x_vector: Vector3::y(),
y_vector: Vector3::z(),
x_vector: Vector3::z(),
y_vector: Vector3::y(),
})
.with(DipoleLight {
wavelength: 1064.0e-9,
Expand All @@ -215,7 +215,7 @@ pub mod tests {
let atom1 = test_world
.create_entity()
.with(Position {
pos: Vector3::new(20.0e-6, 20.0e-6, 20.0e-6),
pos: Vector3::new(20.0e-6, 25.0e-6, 20.0e-6),
})
.with(LaserIntensityGradientSamplers {
contents: [LaserIntensityGradientSampler::default();
Expand All @@ -232,9 +232,9 @@ pub mod tests {
.expect("Entity not found!")
.contents[0]
.gradient;

assert_approx_eq!(-8.4628e+7, sim_result_gradient[0], 1e+5_f64);
assert_approx_eq!(-4.33992902e+13, sim_result_gradient[1], 1e+8_f64);
assert_approx_eq!(-4.33992902e+13, sim_result_gradient[2], 1e+8_f64);
println!("Gradient: x = {}, y = {}, z = {}", sim_result_gradient[0], sim_result_gradient[1], sim_result_gradient[2]);
assert_approx_eq!(-1.89173404e+08, sim_result_gradient[0], 1e+5_f64);
assert_approx_eq!(-5.18620162e+13, sim_result_gradient[1], 1e+8_f64);
assert_approx_eq!(-4.14896130e+13, sim_result_gradient[2], 1e+8_f64);
}
}