adaptive integration option
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
 | 
			
		||||
use sbp::euler::System;
 | 
			
		||||
use sbp::operators::{SbpOperator2d, Upwind4, UpwindOperator2d, SBP4};
 | 
			
		||||
use sbp::Float;
 | 
			
		||||
 | 
			
		||||
fn advance_system<SBP: SbpOperator2d>(universe: &mut System<SBP>, n: usize) {
 | 
			
		||||
    for _ in 0..n {
 | 
			
		||||
@@ -14,6 +15,19 @@ fn advance_system_upwind<UO: UpwindOperator2d>(universe: &mut System<UO>, n: usi
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn advance_embedded<UO: UpwindOperator2d>(universe: &mut System<UO>, embedded: bool) {
 | 
			
		||||
    let dt = 0.2 / std::cmp::max(universe.nx(), universe.ny()) as Float;
 | 
			
		||||
    let t = 1.0;
 | 
			
		||||
    if embedded {
 | 
			
		||||
        let mut dt = dt;
 | 
			
		||||
        universe.advance_adaptive(t, &mut dt, 1e-2);
 | 
			
		||||
    } else {
 | 
			
		||||
        for _ in 0..(t / dt).round() as isize {
 | 
			
		||||
            universe.advance_upwind(dt);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn performance_benchmark(c: &mut Criterion) {
 | 
			
		||||
    let mut group = c.benchmark_group("EulerSystem");
 | 
			
		||||
    group.sample_size(25);
 | 
			
		||||
@@ -48,7 +62,23 @@ fn performance_benchmark(c: &mut Criterion) {
 | 
			
		||||
            advance_system(&mut universe, black_box(20))
 | 
			
		||||
        })
 | 
			
		||||
    });
 | 
			
		||||
    group.finish();
 | 
			
		||||
 | 
			
		||||
    let mut group = c.benchmark_group("adaptive integration");
 | 
			
		||||
    group.sample_size(10);
 | 
			
		||||
    let mut universe = System::new(x.into_owned(), y.into_owned(), Upwind4);
 | 
			
		||||
    group.bench_function("static dt", |b| {
 | 
			
		||||
        b.iter(|| {
 | 
			
		||||
            universe.init_with_vortex(0.0, 0.0);
 | 
			
		||||
            advance_embedded(&mut universe, false);
 | 
			
		||||
        })
 | 
			
		||||
    });
 | 
			
		||||
    group.bench_function("adaptive dt", |b| {
 | 
			
		||||
        b.iter(|| {
 | 
			
		||||
            universe.init_with_vortex(0.0, 0.0);
 | 
			
		||||
            advance_embedded(&mut universe, true);
 | 
			
		||||
        })
 | 
			
		||||
    });
 | 
			
		||||
    group.finish();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user