diff --git a/.gitignore b/.gitignore
index d8fcca8..e828b8c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
node_modules/
target/
pkg/
-dist/
\ No newline at end of file
+dist/
+.DS_Store
diff --git a/index.html b/index.html
index 5f76c01..6ceb046 100644
--- a/index.html
+++ b/index.html
@@ -26,6 +26,10 @@
Eulerian Fluid Simulation
+
+
+
+
diff --git a/index.js b/index.js
index c7da8ba..f53aad5 100644
--- a/index.js
+++ b/index.js
@@ -17,6 +17,9 @@ import('./pkg')
// Get the streamlines_spacing slider
const streamlines_spacing_slider = document.getElementById("streamlines_spacing");
+ // Get the in_vel slider
+ const in_vel_slider = document.getElementById("in_vel");
+
// Get the colormap selector
const colormap_selector = document.getElementById("colormap");
@@ -58,10 +61,12 @@ import('./pkg')
const overrelaxation = 1.9;
- const gravity = -9.81;
+ const gravity = 0.;
+
+ const in_vel = 0.8;
// Create the fluid simulation
- const fluid = wasm.Fluid.create(gravity, numX, numY, h, density)
+ const fluid = wasm.Fluid.create(gravity, in_vel, numX, numY, h, density)
// Setup the obstacles
fluid.clear_obstacles();
@@ -71,6 +76,7 @@ import('./pkg')
simu_canvas, scenario_selector,
pressure_checkbox, streamlines_checkbox,
streamlines_num_seg_slider, streamlines_spacing_slider,
+ in_vel_slider,
colormap_selector,
sim_to_canvas_ratio)
diff --git a/src/lib.rs b/src/lib.rs
index 720508f..38f9fb1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -39,6 +39,7 @@ pub fn run_with_selector(
streamlines_checkbox: web_sys::HtmlInputElement,
streamlines_num_segs: web_sys::HtmlInputElement,
streamlines_spacing: web_sys::HtmlInputElement,
+ in_vel: web_sys::HtmlInputElement,
colormap_selector: web_sys::HtmlSelectElement,
sim_to_canvas_ratio: u32,
) -> Result<(), JsValue> {
@@ -47,7 +48,7 @@ pub fn run_with_selector(
let previous_frame = Rc::new(RefCell::new(Instant::now()));
- let scenario = Rc::new(RefCell::new(None::));
+ let scenario = Rc::new(RefCell::new(None::<(String, f32)>));
let context = canvas
.get_context("2d")
@@ -75,6 +76,8 @@ pub fn run_with_selector(
let streamlines_num_segs = streamlines_num_segs.value_as_number() as usize;
let streamlines_spacing = streamlines_spacing.value_as_number() as usize;
+ let in_vel = in_vel.value_as_number() as f32;
+
let options = DrawOptions {
pressure,
obstacle: true,
@@ -90,27 +93,33 @@ pub fn run_with_selector(
// If the scenario is not set or has changed, update the fluid.
let mut scenario = scenario.borrow_mut();
match scenario.as_ref() {
- Some(sv) if sv == scenario_value.as_str() => {}
+ Some((sv, in_vel_)) if (sv == scenario_value.as_str()) && (*in_vel_ == in_vel) => {}
_ => {
- scenario.replace(scenario_value.clone());
+ scenario.replace((scenario_value.clone(), in_vel));
match scenario_value.as_str() {
"rectangular" => {
fluid.clear_obstacles();
- fluid.vortex_shedding(vec![ObstacleType::Rectangular {
- x: 0.2,
- y: 0.5,
- w: 0.1,
- h: 0.3,
- }]);
+ fluid.vortex_shedding(
+ in_vel,
+ vec![ObstacleType::Rectangular {
+ x: 0.2,
+ y: 0.5,
+ w: 0.1,
+ h: 0.3,
+ }],
+ );
}
_ => {
fluid.clear_obstacles();
- fluid.vortex_shedding(vec![ObstacleType::Circular {
- x: 0.5,
- y: 0.5,
- r: 0.2,
- }]);
+ fluid.vortex_shedding(
+ in_vel,
+ vec![ObstacleType::Circular {
+ x: 0.5,
+ y: 0.5,
+ r: 0.2,
+ }],
+ );
}
}
}
diff --git a/src/simu.rs b/src/simu.rs
index 3c259a3..888d62a 100644
--- a/src/simu.rs
+++ b/src/simu.rs
@@ -35,6 +35,8 @@ use web_sys::CanvasRenderingContext2d;
pub struct Fluid {
/// gravity
gravity: f32,
+ /// in_vel - horizontal velocity at the inlet
+ in_vel: f32,
/// density of the fluid
density: f32,
@@ -357,10 +359,12 @@ impl Fluid {
let r = ctx.put_image_data(&data, 0.0, 0.0);
let text = format!(
- "min: {:>8.1}\tmax: {:>8.1}\t{:>8.1} fps",
+ "min: {:>8.1}\tmax: {:>8.1}\t{:>8.1} fps\tin_vel: {:>4.2}\t gravity: {:>4.2}",
min_p,
max_p,
- 1. / dt
+ 1. / dt,
+ self.in_vel,
+ self.gravity
);
let _ = ctx.fill_text(&text, 12., 12.);
@@ -488,12 +492,10 @@ impl Fluid {
}
/// flow in a pipe and around obstacles with no gravity
- pub fn vortex_shedding(&mut self, obstacles: Vec) {
+ pub fn vortex_shedding(&mut self, in_vel: f32, obstacles: Vec) {
const FLUID: f32 = 1.0;
const OBSTACLE: f32 = 0.0;
- let in_vel = 2.0;
-
let n = self.num_y;
for i in 0..self.num_x {
@@ -521,6 +523,7 @@ impl Fluid {
}
self.gravity = 0.;
+ self.in_vel = in_vel;
self.add_obstacles(obstacles.into_iter().map(|x| x.into()).collect());
}
@@ -596,7 +599,14 @@ impl Fluid {
#[wasm_bindgen]
impl Fluid {
- pub fn create(gravity: f32, num_x: usize, num_y: usize, h: f32, density: f32) -> Fluid {
+ pub fn create(
+ gravity: f32,
+ in_vel: f32,
+ num_x: usize,
+ num_y: usize,
+ h: f32,
+ density: f32,
+ ) -> Fluid {
let num_x = num_x + 2; // 2 border cells
let num_y = num_y + 2;
@@ -611,6 +621,7 @@ impl Fluid {
let new_m = vec![0.0; num_cells];
Fluid {
gravity,
+ in_vel,
density,
num_x,
num_y,