sciforge_core/dynamics/electro/
fields.rs1use sciforge_hub::prelude::physics::electrodynamics::fields as sf_fields;
2use sciforge_hub::prelude::physics::electrodynamics::waves as sf_waves;
3
4#[derive(Debug, Clone, Copy)]
5pub struct ChargedParticle {
6 pub charge_c: f64,
7 pub mass_kg: f64,
8}
9
10impl ChargedParticle {
11 pub fn new(charge_c: f64, mass_kg: f64) -> Self {
12 Self { charge_c, mass_kg }
13 }
14
15 pub fn electron() -> Self {
16 Self {
17 charge_c: -sciforge_hub::prelude::constants::E_CHARGE,
18 mass_kg: sciforge_hub::prelude::constants::ELECTRON_MASS_KG,
19 }
20 }
21
22 pub fn proton() -> Self {
23 Self {
24 charge_c: sciforge_hub::prelude::constants::E_CHARGE,
25 mass_kg: sciforge_hub::prelude::constants::PROTON_MASS_KG,
26 }
27 }
28
29 pub fn cyclotron_frequency_rad_per_s(&self, b_t: f64) -> f64 {
30 sf_fields::cyclotron_frequency(self.charge_c, self.mass_kg, b_t)
31 }
32
33 pub fn cyclotron_frequency_hz(&self, b_t: f64) -> f64 {
34 self.cyclotron_frequency_rad_per_s(b_t) / (2.0 * std::f64::consts::PI)
35 }
36
37 pub fn larmor_radius_m(&self, v_perp_m_s: f64, b_t: f64) -> f64 {
38 sf_fields::larmor_radius(self.mass_kg, v_perp_m_s, self.charge_c, b_t)
39 }
40
41 pub fn lorentz_force_n(
42 &self,
43 velocity_m_s: [f64; 3],
44 e_v_per_m: [f64; 3],
45 b_t: [f64; 3],
46 ) -> [f64; 3] {
47 sf_fields::lorentz_force(self.charge_c, velocity_m_s, e_v_per_m, b_t)
48 }
49
50 pub fn larmor_radiation_power_w(&self, acceleration_m_s2: f64) -> f64 {
51 sf_waves::larmor_radiation_power(self.charge_c, acceleration_m_s2)
52 }
53
54 pub fn electric_field_v_per_m(&self, position_m: [f64; 3]) -> [f64; 3] {
55 sf_fields::electric_field_point_charge(self.charge_c, position_m)
56 }
57
58 pub fn electric_potential_v(&self, distance_m: f64) -> f64 {
59 sf_fields::electric_potential_point(self.charge_c, distance_m)
60 }
61}
62
63#[derive(Debug, Clone, Copy)]
64pub struct CurrentLoop {
65 pub current_a: f64,
66 pub radius_m: f64,
67}
68
69impl CurrentLoop {
70 pub fn new(current_a: f64, radius_m: f64) -> Self {
71 Self { current_a, radius_m }
72 }
73
74 pub fn axial_field_t(&self, z_m: f64) -> f64 {
75 sf_fields::magnetic_field_loop(self.current_a, self.radius_m, z_m)
76 }
77
78 pub fn center_field_t(&self) -> f64 {
79 self.axial_field_t(0.0)
80 }
81}
82
83#[derive(Debug, Clone, Copy)]
84pub struct StraightWire {
85 pub current_a: f64,
86}
87
88impl StraightWire {
89 pub fn new(current_a: f64) -> Self {
90 Self { current_a }
91 }
92
93 pub fn field_t_at_distance(&self, r_m: f64) -> f64 {
94 sf_fields::magnetic_field_wire(self.current_a, r_m)
95 }
96}