aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-02-20 23:58:15 +0100
committerAdrian Kummerlaender2019-02-20 23:58:15 +0100
commit1870b510acb351b5956402a21572835aa0d2dee0 (patch)
treefb54ba5d6c9d3593246e096458f5d76325094246 /src
parent409ca238ec8f4f405443931947b2a85c03754bc9 (diff)
downloadcompustream-1870b510acb351b5956402a21572835aa0d2dee0.tar
compustream-1870b510acb351b5956402a21572835aa0d2dee0.tar.gz
compustream-1870b510acb351b5956402a21572835aa0d2dee0.tar.bz2
compustream-1870b510acb351b5956402a21572835aa0d2dee0.tar.lz
compustream-1870b510acb351b5956402a21572835aa0d2dee0.tar.xz
compustream-1870b510acb351b5956402a21572835aa0d2dee0.tar.zst
compustream-1870b510acb351b5956402a21572835aa0d2dee0.zip
Tidy up streaming and bounce back boundary handling
Introduce a inactive receive-only outer boundary to simplify streaming. Extract and generalize bounce back handling. Further work will require tracking cell _material_ to enable both easier definition and dynamic updating of the geometry.
Diffstat (limited to 'src')
-rw-r--r--src/shader/code/collide.glsl18
-rw-r--r--src/shader/code/stream.glsl47
2 files changed, 49 insertions, 16 deletions
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl
index 23e98f9..cb950cb 100644
--- a/src/shader/code/collide.glsl
+++ b/src/shader/code/collide.glsl
@@ -110,6 +110,16 @@ float getExternalPressureInflux(uint x, uint y) {
}
}
+/// Domain description
+
+bool isEndOfWorld(uint x, uint y) {
+ return x == 0 || x == nX-1 || y == 0 || y == nY-1;
+}
+
+bool isOuterWall(uint x, uint y) {
+ return x == 1 || x == nX-2 || y == 1 || y == nY-2;
+}
+
/// Actual collide kernel
void main() {
@@ -120,6 +130,14 @@ void main() {
return;
}
+ if ( isEndOfWorld(x,y) ) {
+ return;
+ }
+
+ if ( isOuterWall(x,y) ) {
+ return;
+ }
+
const float d = max(getExternalPressureInflux(x,y), density(x,y));
const vec2 v = velocity(x,y,d);
diff --git a/src/shader/code/stream.glsl b/src/shader/code/stream.glsl
index 1a2abe3..345127d 100644
--- a/src/shader/code/stream.glsl
+++ b/src/shader/code/stream.glsl
@@ -33,6 +33,26 @@ void set(uint x, uint y, int i, int j, float v) {
streamCells[indexOfLatticeCell(x,y) + indexOfDirection(i,j)] = v;
}
+/// Domain description
+
+bool isEndOfWorld(uint x, uint y) {
+ return x == 0 || x == nX-1 || y == 0 || y == nY-1;
+}
+
+bool isOuterWall(uint x, uint y) {
+ return x == 1 || x == nX-2 || y == 1 || y == nY-2;
+}
+
+/// Boundary conditions
+
+void bounceBack(uint x, uint y) {
+ for ( int i = -1; i <= 1; ++i ) {
+ for ( int j = -1; j <= 1; ++j ) {
+ set(x,y,i,j, get(x,y,(-1)*i,(-1)*j));
+ }
+ }
+}
+
/// Actual stream kernel
void main() {
@@ -43,22 +63,17 @@ void main() {
return;
}
- if ( x != 0 && x != nX-1 && y != 0 && y != nY-1 ) {
- for ( int i = -1; i <= 1; ++i ) {
- for ( int j = -1; j <= 1; ++j ) {
- set(x+i,y+j,i,j, get(x,y,i,j));
- }
- }
- } else {
- // rudimentary bounce back boundary handling
- for ( int i = -1; i <= 1; ++i ) {
- for ( int j = -1; j <= 1; ++j ) {
- if ( (x > 0 || i >= 0) && x+i <= nX-1 && (y > 0 || j >= 0) && y+j <= nY-1 ) {
- set(x+i,y+j,i,j, get(x,y,i,j));
- } else {
- set(x,y,i*(-1),j*(-1), get(x,y,i,j));
- }
- }
+ if ( isEndOfWorld(x,y) ) {
+ return;
+ }
+
+ if ( isOuterWall(x,y) ) {
+ bounceBack(x,y);
+ }
+
+ for ( int i = -1; i <= 1; ++i ) {
+ for ( int j = -1; j <= 1; ++j ) {
+ set(x+i,y+j,i,j, get(x,y,i,j));
}
}
}