aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cc9
-rw-r--r--src/shader/code/collide.glsl39
-rw-r--r--src/shader/code/vertex.glsl20
3 files changed, 49 insertions, 19 deletions
diff --git a/src/main.cc b/src/main.cc
index 5df6892..5c27306 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -26,7 +26,8 @@
GLuint maxLUPS = 100;
GLuint nX = 512;
GLuint nY = 256;
-bool open_boundaries = false;
+bool open_boundaries = false;
+bool show_fluid_quality = false;
float getWorldHeight(int window_width, int window_height, float world_width) {
return world_width / window_width * window_height;
@@ -199,6 +200,7 @@ int render() {
{
auto guard = collide_shader->use();
+ collide_shader->setUniform("fluidQuality", show_fluid_quality);
collide_shader->setUniform("iT", iT);
iT += 1;
@@ -215,6 +217,7 @@ int render() {
scene_shader->setUniform("MVP", MVP);
scene_shader->setUniform("nX", nX);
scene_shader->setUniform("nY", nY);
+ scene_shader->setUniform("fluidQuality", show_fluid_quality);
glClear(GL_COLOR_BUFFER_BIT);
fluid->draw();
@@ -267,6 +270,10 @@ bool parseArguments(int argc, char* argv[]) {
if ( arg == "--open" ) {
open_boundaries = true;
}
+
+ if ( arg == "--quality" ) {
+ show_fluid_quality = true;
+ }
}
return true;
}
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl
index 9ff6ab3..45e06f8 100644
--- a/src/shader/code/collide.glsl
+++ b/src/shader/code/collide.glsl
@@ -11,6 +11,8 @@ uniform uint nX;
uniform uint nY;
uniform uint iT;
+uniform bool fluidQuality;
+
/// Fluid characteristics
const float physCharLength = 1.0;
@@ -154,6 +156,20 @@ float getExternalMassInflux(int material) {
}
};
+float getLocalKnudsenApproximation(uint x, uint y, float d, vec2 v) {
+ float knudsen = 0.0;
+
+ for ( int i = -1; i <= 1; ++i ) {
+ for ( int j = -1; j <= 1; ++j ) {
+ const float feq = equilibrium(d,v,i,j);
+ const float fneq = get(x,y,i,j) - feq;
+ knudsen += abs(fneq / feq);
+ }
+ }
+
+ return knudsen / q;
+}
+
/// Actual collide&stream kernel
void main() {
@@ -177,29 +193,26 @@ void main() {
d = 1.0;
}
- //setFluidVelocity(x,y,v);
-
- float knudsen = 0.0;
+ if ( fluidQuality ) {
+ const float approxKn = getLocalKnudsenApproximation(x,y,d,v);
+ setFluidQuality(x,y, approxKn, int(round(log2(approxKn / Kn))));
+ } else {
+ setFluidVelocity(x,y,v);
+ }
for ( int i = -1; i <= 1; ++i ) {
for ( int j = -1; j <= 1; ++j ) {
- const float feq = equilibrium(d,v,i,j);
- const float fneq = get(x,y,i,j) - feq;
- knudsen += abs(fneq / feq);
-
- set(x+i,y+j,i,j, get(x,y,i,j) + relaxationFrequency * (feq - get(x,y,i,j)));
+ set(x+i,y+j,i,j,
+ get(x,y,i,j) + relaxationFrequency * (equilibrium(d,v,i,j) - get(x,y,i,j)));
}
}
-
- knudsen /= q;
-
- setFluidQuality(x,y,knudsen,int(round(log2(knudsen / Kn))));
}
if ( isBounceBackCell(material) ) {
for ( int i = -1; i <= 1; ++i ) {
for ( int j = -1; j <= 1; ++j ) {
- set(x+(-1)*i,y+(-1)*j,(-1)*i,(-1)*j, get(x,y,i,j) + relaxationFrequency * (equilibrium(d,v,i,j) - get(x,y,i,j)));
+ set(x+(-1)*i,y+(-1)*j,(-1)*i,(-1)*j,
+ get(x,y,i,j) + relaxationFrequency * (equilibrium(d,v,i,j) - get(x,y,i,j)));
}
}
}
diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl
index 7851292..8958600 100644
--- a/src/shader/code/vertex.glsl
+++ b/src/shader/code/vertex.glsl
@@ -10,6 +10,8 @@ out VS_OUT {
uniform uint nX;
uniform uint nY;
+uniform bool fluidQuality;
+
const float velocityDisplayAmplifier = 3.0;
const int qualityDisplayRestrictor = 6;
@@ -66,11 +68,19 @@ void main() {
} else if ( isWallFrontier(material) ) {
vs_out.color = vec3(0.0, 0.0, 0.0);
} else {
- vs_out.color = mix(
- vec3(0.0, 1.0, 0.0),
- vec3(1.0, 0.0, 0.0),
- restrictedQuality(VertexPosition.y)
- );
+ if ( fluidQuality ) {
+ vs_out.color = mix(
+ vec3(0.0, 1.0, 0.0),
+ vec3(1.0, 0.0, 0.0),
+ restrictedQuality(VertexPosition.y)
+ );
+ } else {
+ vs_out.color = mix(
+ vec3(-0.5, 0.0, 1.0),
+ vec3( 1.0, 0.0, 0.0),
+ velocityDisplayAmplifier * norm(VertexPosition.xy)
+ );
+ }
}
}
)";