Skip to content

Commit

Permalink
electronics: Add builtin voltage
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Aug 13, 2023
1 parent 0917c3f commit 4b922c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions electronics/src/builtin_voltage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
// Use of this source is governed by General Public License that can be found
// in the LICENSE file.

// TEMPERATURE (unit = K)
pub const T: f64 = 300.0;
pub const BOLTZMANN: f64 = 1.380_649e-23;
pub const ELECTRON_VOLT: f64 = 1.602_176_634e-19;

/// This function can calculate the Builtin Voltage of a pn junction diode.
///
/// This is calculated from the given three values.
///
/// # Parameters
/// - `donor_conc` - donor concentration
/// - `acceptor_conc` - acceptor concentration
/// - `intrinsic_conc` - intrinsic concentration
#[must_use]
pub fn builtin_voltage(donor_conc: f64, acceptor_conc: f64, intrinsic_conc: f64) -> f64 {
debug_assert!(donor_conc > 0.0);
debug_assert!(acceptor_conc > 0.0);
debug_assert!(intrinsic_conc > 0.0);
debug_assert!(donor_conc > intrinsic_conc);
debug_assert!(acceptor_conc > intrinsic_conc);
BOLTZMANN * T * ((donor_conc * acceptor_conc) / intrinsic_conc.powi(2)).ln() / ELECTRON_VOLT
}

#[cfg(test)]
mod tests {
use super::builtin_voltage;

#[test]
fn test_builtin_voltage() {
assert_eq!(builtin_voltage(1e17, 1e17, 1e10), 0.833370010652644);
}
}
1 change: 1 addition & 0 deletions electronics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
)]

//pub mod apparent_power;
pub mod builtin_voltage;
pub mod electric_power;
pub mod ohms_law;

0 comments on commit 4b922c6

Please sign in to comment.