Formatting changes

This commit is contained in:
Connor Johnstone
2023-10-16 14:16:44 -06:00
parent 16e958c5db
commit 9d82f92c07
7 changed files with 194 additions and 103 deletions

View File

@@ -14,12 +14,15 @@ pub struct PIController {
pub old_h: f64,
}
impl<const D:usize> Controller<D> for PIController {
impl<const D: usize> Controller<D> for PIController {
/// Determines if the previously run step size and error were valid or not. Either way, it also
/// returns what the next step size should be
fn determine_step(&mut self, h: f64, err: f64) -> (bool, f64) {
let factor_11 = err.powf(self.alpha);
let factor = self.factor_c2.max(self.factor_c1.min(factor_11 * self.factor_old.powf(-self.beta) / self.safety_factor));
let factor = self.factor_c2.max(
self.factor_c1
.min(factor_11 * self.factor_old.powf(-self.beta) / self.safety_factor),
);
let mut h_new = h / factor;
if err <= 1.0 {
// Accept the stepsize
@@ -39,7 +42,15 @@ impl<const D:usize> Controller<D> for PIController {
}
impl PIController {
pub fn new(alpha:f64, beta:f64, max_factor: f64, min_factor: f64, h_max: f64, safety_factor: f64, initial_h: f64) -> Self {
pub fn new(
alpha: f64,
beta: f64,
max_factor: f64,
min_factor: f64,
h_max: f64,
safety_factor: f64,
initial_h: f64,
) -> Self {
Self {
alpha: alpha,
beta: beta,
@@ -66,8 +77,8 @@ mod tests {
assert!(controller.alpha == 0.17);
assert!(controller.beta == 0.04);
assert!(controller.factor_c1 == 1.0/0.2);
assert!(controller.factor_c2 == 1.0/10.0);
assert!(controller.factor_c1 == 1.0 / 0.2);
assert!(controller.factor_c2 == 1.0 / 10.0);
assert!(controller.factor_old == 1.0e-4);
assert!(controller.h_max == 10.0);
assert!(controller.safety_factor == 0.9);