rename project

This commit is contained in:
Magnus Ulimoen 2020-01-27 21:20:34 +01:00
parent eda4eb4904
commit e40ca4ba47
7 changed files with 25 additions and 22 deletions

View File

@ -1,5 +1,5 @@
[package] [package]
name = "maxwell" name = "sbp"
version = "0.1.1" version = "0.1.1"
authors = ["Magnus Ulimoen <flymagnus@gmail.com>"] authors = ["Magnus Ulimoen <flymagnus@gmail.com>"]
edition = "2018" edition = "2018"

View File

@ -1,6 +1,6 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion}; use criterion::{black_box, criterion_group, criterion_main, Criterion};
use maxwell::operators::{SbpOperator, Upwind4, UpwindOperator, SBP4}; use sbp::operators::{SbpOperator, Upwind4, UpwindOperator, SBP4};
use maxwell::EulerSystem; use sbp::EulerSystem;
fn advance_system<SBP: SbpOperator>(universe: &mut EulerSystem<SBP>, n: usize) { fn advance_system<SBP: SbpOperator>(universe: &mut EulerSystem<SBP>, n: usize) {
for _ in 0..n { for _ in 0..n {

View File

@ -1,21 +1,21 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion}; use criterion::{black_box, criterion_group, criterion_main, Criterion};
use maxwell::operators::{SbpOperator, Upwind4, UpwindOperator, SBP4}; use sbp::operators::{SbpOperator, Upwind4, UpwindOperator, SBP4};
use maxwell::System; use sbp::MaxwellSystem;
fn advance_system<SBP: SbpOperator>(universe: &mut System<SBP>, n: usize) { fn advance_system<SBP: SbpOperator>(universe: &mut MaxwellSystem<SBP>, n: usize) {
for _ in 0..n { for _ in 0..n {
universe.advance(0.01); universe.advance(0.01);
} }
} }
fn advance_system_upwind<UO: UpwindOperator>(universe: &mut System<UO>, n: usize) { fn advance_system_upwind<UO: UpwindOperator>(universe: &mut MaxwellSystem<UO>, n: usize) {
for _ in 0..n { for _ in 0..n {
universe.advance_upwind(0.01); universe.advance_upwind(0.01);
} }
} }
fn performance_benchmark(c: &mut Criterion) { fn performance_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("System"); let mut group = c.benchmark_group("MaxwellSystem");
group.sample_size(25); group.sample_size(25);
let w = 40; let w = 40;
@ -23,7 +23,8 @@ fn performance_benchmark(c: &mut Criterion) {
let x = ndarray::Array2::from_shape_fn((h, w), |(_, i)| i as f32 / (w - 1) as f32); let x = ndarray::Array2::from_shape_fn((h, w), |(_, i)| i as f32 / (w - 1) as f32);
let y = ndarray::Array2::from_shape_fn((h, w), |(j, _)| j as f32 / (h - 1) as f32); let y = ndarray::Array2::from_shape_fn((h, w), |(j, _)| j as f32 / (h - 1) as f32);
let mut universe = System::<Upwind4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap()); let mut universe =
MaxwellSystem::<Upwind4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap());
group.bench_function("advance", |b| { group.bench_function("advance", |b| {
b.iter(|| { b.iter(|| {
universe.set_gaussian(0.5, 0.5); universe.set_gaussian(0.5, 0.5);
@ -31,7 +32,8 @@ fn performance_benchmark(c: &mut Criterion) {
}) })
}); });
let mut universe = System::<Upwind4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap()); let mut universe =
MaxwellSystem::<Upwind4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap());
group.bench_function("advance_upwind", |b| { group.bench_function("advance_upwind", |b| {
b.iter(|| { b.iter(|| {
universe.set_gaussian(0.5, 0.5); universe.set_gaussian(0.5, 0.5);
@ -39,7 +41,8 @@ fn performance_benchmark(c: &mut Criterion) {
}) })
}); });
let mut universe = System::<SBP4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap()); let mut universe =
MaxwellSystem::<SBP4>::new(w, h, x.as_slice().unwrap(), y.as_slice().unwrap());
group.bench_function("advance_trad4", |b| { group.bench_function("advance_trad4", |b| {
b.iter(|| { b.iter(|| {
universe.set_gaussian(0.5, 0.5); universe.set_gaussian(0.5, 0.5);

View File

@ -5,7 +5,7 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="generator" content="by-hand" /> <meta name="generator" content="by-hand" />
<meta name="viewpost" context="width=device-width, inital-scale=1.0, user-scalable=yes" /> <meta name="viewpost" context="width=device-width, inital-scale=1.0, user-scalable=yes" />
<title>Maxwell waves</title> <title>SBP waves</title>
<link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="style.css">
<script async type="module" src="main.js"></script> <script async type="module" src="main.js"></script>
</head> </head>

View File

@ -1,11 +1,11 @@
import { EulerUniverse, Universe, default as init, set_panic_hook as setPanicHook } from "./maxwell.js"; import { EulerUniverse, MaxwellUniverse, default as init, set_panic_hook as setPanicHook } from "./sbp.js";
/** /**
* Initialises and runs the Maxwell solver, * Initialises and runs the Maxwell solver,
* plotting the solution to a canvas using webgl * plotting the solution to a canvas using webgl
*/ */
(async function run() { (async function run() {
const wasm = await init("./maxwell_bg.wasm"); const wasm = await init("./sbp_bg.wasm");
setPanicHook(); setPanicHook();
const DIAMOND = false; const DIAMOND = false;
const UPWIND = true; const UPWIND = true;

View File

@ -29,7 +29,7 @@ if __name__ == "__main__":
pathlib.Path("target") pathlib.Path("target")
.joinpath(target_triple) .joinpath(target_triple)
.joinpath("release" if args.release else "debug") .joinpath("release" if args.release else "debug")
.joinpath("maxwell.wasm") .joinpath("sbp.wasm")
) )
if args.release: if args.release:
command.append("--release") command.append("--release")
@ -53,7 +53,7 @@ if __name__ == "__main__":
try: try:
with tempfile.TemporaryDirectory() as d_: with tempfile.TemporaryDirectory() as d_:
d = pathlib.Path(d_) d = pathlib.Path(d_)
wasm_bg = publish.joinpath("maxwell_bg.wasm") wasm_bg = publish.joinpath("sbp_bg.wasm")
wasm_to_opt = d.joinpath("before-wasm-opt.wasm") wasm_to_opt = d.joinpath("before-wasm-opt.wasm")
copyfile(wasm_bg, wasm_to_opt) copyfile(wasm_bg, wasm_to_opt)
check_call(["wasm-opt", "-O4", str(wasm_to_opt), "-o", str(wasm_bg)]) check_call(["wasm-opt", "-O4", str(wasm_to_opt), "-o", str(wasm_bg)])

View File

@ -18,13 +18,13 @@ pub fn set_panic_hook() {
} }
#[wasm_bindgen] #[wasm_bindgen]
pub struct Universe(System<operators::Upwind4>); pub struct MaxwellUniverse(MaxwellSystem<operators::Upwind4>);
#[wasm_bindgen] #[wasm_bindgen]
impl Universe { impl MaxwellUniverse {
#[wasm_bindgen(constructor)] #[wasm_bindgen(constructor)]
pub fn new(width: usize, height: usize, x: &[f32], y: &[f32]) -> Self { pub fn new(width: usize, height: usize, x: &[f32], y: &[f32]) -> Self {
Self(System::new(width as usize, height as usize, x, y)) Self(MaxwellSystem::new(width as usize, height as usize, x, y))
} }
pub fn init(&mut self, x0: f32, y0: f32) { pub fn init(&mut self, x0: f32, y0: f32) {
@ -52,13 +52,13 @@ impl Universe {
} }
} }
pub struct System<SBP: operators::SbpOperator> { pub struct MaxwellSystem<SBP: operators::SbpOperator> {
sys: (Field, Field), sys: (Field, Field),
wb: WorkBuffers, wb: WorkBuffers,
grid: Grid<SBP>, grid: Grid<SBP>,
} }
impl<SBP: operators::SbpOperator> System<SBP> { impl<SBP: operators::SbpOperator> MaxwellSystem<SBP> {
pub fn new(width: usize, height: usize, x: &[f32], y: &[f32]) -> Self { pub fn new(width: usize, height: usize, x: &[f32], y: &[f32]) -> Self {
assert_eq!((width * height), x.len()); assert_eq!((width * height), x.len());
assert_eq!((width * height), y.len()); assert_eq!((width * height), y.len());
@ -97,7 +97,7 @@ impl<SBP: operators::SbpOperator> System<SBP> {
} }
} }
impl<UO: operators::UpwindOperator> System<UO> { impl<UO: operators::UpwindOperator> MaxwellSystem<UO> {
/// Using artificial dissipation with the upwind operator /// Using artificial dissipation with the upwind operator
pub fn advance_upwind(&mut self, dt: f32) { pub fn advance_upwind(&mut self, dt: f32) {
maxwell::advance_upwind( maxwell::advance_upwind(