Compare commits
29 Commits
62373d266c
...
858859043b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
858859043b | ||
|
|
6a8a461298 | ||
|
|
1230ac51cb | ||
|
|
6f052e48e6 | ||
|
|
eac79e0afc | ||
|
|
f93936a96e | ||
|
|
79fa7715f0 | ||
|
|
10c3987f2d | ||
|
|
18ac90affa | ||
|
|
52e853f8ad | ||
|
|
6afbbd7e2a | ||
|
|
6b585b367b | ||
|
|
085cd18fdf | ||
|
|
fb81cc2982 | ||
|
|
70ab3b53e9 | ||
|
|
d699a16e08 | ||
|
|
12a5352ae9 | ||
|
|
1f39a03e06 | ||
|
|
1389b47ce1 | ||
|
|
880cd1b675 | ||
|
|
6867733a0f | ||
|
|
2c70036f07 | ||
|
|
f1d3c3d011 | ||
|
|
67f12b7eb4 | ||
|
|
a004e7e2c3 | ||
|
|
a41a848c04 | ||
|
|
9021125a74 | ||
|
|
12dfd9e6b4 | ||
|
|
e605a82df6 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
|||||||
[submodule "src/main/c/lib/stb"]
|
|
||||||
path = src/main/c/lib/stb
|
|
||||||
url = https://github.com/nothings/stb.git
|
|
||||||
@ -1,8 +1,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../includes/libfluidsim.h"
|
#include "includes/utilities.h"
|
||||||
#include "../includes/utilities.h"
|
#include "includes/chunkmask.h"
|
||||||
#include "../includes/chunkmask.h"
|
|
||||||
|
|
||||||
uint32_t matrix_transform(JNIEnv * env, jobjectArray jrx);
|
uint32_t matrix_transform(JNIEnv * env, jobjectArray jrx);
|
||||||
|
|
||||||
@ -41,29 +41,24 @@ rm -f ./*.dll
|
|||||||
|
|
||||||
|
|
||||||
#compile object files
|
#compile object files
|
||||||
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -O1"
|
# COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow"
|
||||||
INPUT_FILES="./src/densitystep.c"
|
# INPUT_FILES="./densitystep.c"
|
||||||
OUTPUT_FILE="./densitystep.o"
|
# OUTPUT_FILE="./densitystep.o"
|
||||||
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
# gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
||||||
|
|
||||||
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -O1"
|
# COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow"
|
||||||
INPUT_FILES="./src/velocitystep.c"
|
# INPUT_FILES="./velocitystep.c"
|
||||||
OUTPUT_FILE="./velocitystep.o"
|
# OUTPUT_FILE="./velocitystep.o"
|
||||||
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
# gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
||||||
|
|
||||||
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -O1"
|
# COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow"
|
||||||
INPUT_FILES="./src/chunkmask.c"
|
# INPUT_FILES="./chunkmask.c"
|
||||||
OUTPUT_FILE="./chunkmask.o"
|
# OUTPUT_FILE="./chunkmask.o"
|
||||||
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
# gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
||||||
|
|
||||||
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -O1"
|
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow"
|
||||||
INPUT_FILES="./src/threadpool.c"
|
INPUT_FILES="./fluidsim.c"
|
||||||
OUTPUT_FILE="./threadpool.o"
|
OUTPUT_FILE="./fluidsim.o"
|
||||||
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
|
||||||
|
|
||||||
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -O1"
|
|
||||||
INPUT_FILES="./src/libfluidsim.c"
|
|
||||||
OUTPUT_FILE="./libfluidsim.o"
|
|
||||||
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +66,7 @@ gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OU
|
|||||||
#compile shared object file
|
#compile shared object file
|
||||||
OUTPUT_FILE="libfluidsim$LIB_ENDING"
|
OUTPUT_FILE="libfluidsim$LIB_ENDING"
|
||||||
COMPILE_FLAGS="-shared"
|
COMPILE_FLAGS="-shared"
|
||||||
INPUT_FILES="densitystep.o velocitystep.o chunkmask.o threadpool.o libfluidsim.o"
|
INPUT_FILES="fluidsim.o"
|
||||||
gcc $COMPILE_FLAGS $INPUT_FILES -o $OUTPUT_FILE
|
gcc $COMPILE_FLAGS $INPUT_FILES -o $OUTPUT_FILE
|
||||||
|
|
||||||
#move to resources
|
#move to resources
|
||||||
|
|||||||
@ -2,39 +2,54 @@
|
|||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../includes/libfluidsim.h"
|
#include "includes/utilities.h"
|
||||||
#include "../includes/utilities.h"
|
#include "includes/chunkmask.h"
|
||||||
#include "../includes/chunkmask.h"
|
|
||||||
|
|
||||||
|
void advectDensity(uint32_t chunk_mask, int N, int b, float ** d, float ** d0, float * u, float * v, float * w, float dt);
|
||||||
|
|
||||||
void addDensity(
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: addDensity
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;F)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_addDensity
|
||||||
|
(
|
||||||
int N,
|
int N,
|
||||||
int chunk_mask,
|
int chunk_mask,
|
||||||
float * x,
|
float ** d,
|
||||||
float * s,
|
float ** d0,
|
||||||
float dt){
|
float dt){
|
||||||
int i;
|
int i;
|
||||||
int size=N*N*N;
|
int size=N*N*N;
|
||||||
|
float * x = GET_ARR_RAW(env,d,CENTER_LOC);
|
||||||
|
float * s = GET_ARR_RAW(env,d0,CENTER_LOC);
|
||||||
for(i=0; i<size; i++){
|
for(i=0; i<size; i++){
|
||||||
x[i] += dt*s[i];
|
x[i] += dt*s[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void diffuseDensity(
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: solveDiffuseDensity
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_solveDiffuseDensity
|
||||||
|
(
|
||||||
int N,
|
int N,
|
||||||
int chunk_mask,
|
int chunk_mask,
|
||||||
float * jrx,
|
float ** d,
|
||||||
float * jrx0,
|
float ** d0,
|
||||||
|
float ** jru,
|
||||||
|
float ** jrv,
|
||||||
|
float ** jrw,
|
||||||
float DIFFUSION_CONST,
|
float DIFFUSION_CONST,
|
||||||
float VISCOSITY_CONST,
|
float VISCOSITY_CONST,
|
||||||
float dt){
|
float dt){
|
||||||
float a=dt*DIFFUSION_CONST*N*N*N;
|
float a=dt*DIFFUSION_CONST*N*N*N;
|
||||||
float c=1+6*a;
|
float c=1+6*a;
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
float * x = jrx;
|
float * x = GET_ARR_RAW(env,d,CENTER_LOC);
|
||||||
float * x0 = jrx0;
|
float * x0 = GET_ARR_RAW(env,d0,CENTER_LOC);
|
||||||
|
|
||||||
|
|
||||||
__m256 aScalar = _mm256_set1_ps(a);
|
__m256 aScalar = _mm256_set1_ps(a);
|
||||||
__m256 cScalar = _mm256_set1_ps(c);
|
__m256 cScalar = _mm256_set1_ps(c);
|
||||||
@ -66,21 +81,41 @@ void diffuseDensity(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void advectDensity(uint32_t chunk_mask, int N, float * jrd, float * jrd0, float * u, float * v, float * w, float dt){
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: advectDensity
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_advectDensity
|
||||||
|
(
|
||||||
|
int N,
|
||||||
|
int chunk_mask,
|
||||||
|
float ** d,
|
||||||
|
float ** d0,
|
||||||
|
float ** jru,
|
||||||
|
float ** jrv,
|
||||||
|
float ** jrw,
|
||||||
|
float DIFFUSION_CONST,
|
||||||
|
float VISCOSITY_CONST,
|
||||||
|
float dt){
|
||||||
|
advectDensity(chunk_mask,N,3,d,d0,GET_ARR_RAW(env,jru,CENTER_LOC),GET_ARR_RAW(env,jrv,CENTER_LOC),GET_ARR_RAW(env,jrw,CENTER_LOC),dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void advectDensity(uint32_t chunk_mask, int N, int b, float ** d, float ** d0, float * u, float * v, float * w, float dt){
|
||||||
int i, j, k, i0, j0, k0, i1, j1, k1;
|
int i, j, k, i0, j0, k0, i1, j1, k1;
|
||||||
int m,n,o;
|
int m,n,o;
|
||||||
float x, y, z, s0, t0, s1, t1, u1, u0, dtx,dty,dtz;
|
float x, y, z, s0, t0, s1, t1, u1, u0, dtx,dty,dtz;
|
||||||
|
|
||||||
dtx=dty=dtz=dt*N;
|
dtx=dty=dtz=dt*N;
|
||||||
|
|
||||||
float * d = jrd;
|
float * center_d = GET_ARR_RAW(env,d,CENTER_LOC);
|
||||||
|
|
||||||
float * d0 = jrd0;
|
float * center_d0 = GET_ARR_RAW(env,d0,CENTER_LOC);
|
||||||
|
|
||||||
for(k=1; k<N-1; k++){
|
for(k=1; k<N-1; k++){
|
||||||
for(j=1; j<N-1; j++){
|
for(j=1; j<N-1; j++){
|
||||||
for(i=1; i<N-1; i++){
|
for(i=1; i<N-1; i++){
|
||||||
d0 = jrd0;
|
center_d0 = GET_ARR_RAW(env,d0,CENTER_LOC);
|
||||||
//calculate location to pull from
|
//calculate location to pull from
|
||||||
x = i-dtx*u[IX(i,j,k)];
|
x = i-dtx*u[IX(i,j,k)];
|
||||||
y = j-dty*v[IX(i,j,k)];
|
y = j-dty*v[IX(i,j,k)];
|
||||||
@ -88,12 +123,12 @@ void advectDensity(uint32_t chunk_mask, int N, float * jrd, float * jrd0, float
|
|||||||
|
|
||||||
m = n = o = 1;
|
m = n = o = 1;
|
||||||
|
|
||||||
// if(x < 1){ m -= 1; }
|
if(x < 1){ m -= 1; }
|
||||||
// if(x >= N-1){ m += 1; }
|
if(x >= N-1){ m += 1; }
|
||||||
// if(y < 1){ n -= 1; }
|
if(y < 1){ n -= 1; }
|
||||||
// if(y >= N-1){ n += 1; }
|
if(y >= N-1){ n += 1; }
|
||||||
// if(z < 1){ o -= 1; }
|
if(z < 1){ o -= 1; }
|
||||||
// if(z >= N-1){ o += 1; }
|
if(z >= N-1){ o += 1; }
|
||||||
|
|
||||||
//If the out of bounds coordinate is in bounds for a neighbor chunk, use that chunk as source instead
|
//If the out of bounds coordinate is in bounds for a neighbor chunk, use that chunk as source instead
|
||||||
// if(CK(m,n,o) != CENTER_LOC){
|
// if(CK(m,n,o) != CENTER_LOC){
|
||||||
@ -195,18 +230,18 @@ void advectDensity(uint32_t chunk_mask, int N, float * jrd, float * jrd0, float
|
|||||||
// if(k1 < 0){
|
// if(k1 < 0){
|
||||||
// k1 = 0;
|
// k1 = 0;
|
||||||
// }
|
// }
|
||||||
d[IX(i,j,k)] =
|
center_d[IX(i,j,k)] =
|
||||||
s0*(
|
s0*(
|
||||||
t0*u0*d0[IX(i0,j0,k0)]+
|
t0*u0*center_d0[IX(i0,j0,k0)]+
|
||||||
t1*u0*d0[IX(i0,j1,k0)]+
|
t1*u0*center_d0[IX(i0,j1,k0)]+
|
||||||
t0*u1*d0[IX(i0,j0,k1)]+
|
t0*u1*center_d0[IX(i0,j0,k1)]+
|
||||||
t1*u1*d0[IX(i0,j1,k1)]
|
t1*u1*center_d0[IX(i0,j1,k1)]
|
||||||
)+
|
)+
|
||||||
s1*(
|
s1*(
|
||||||
t0*u0*d0[IX(i1,j0,k0)]+
|
t0*u0*center_d0[IX(i1,j0,k0)]+
|
||||||
t1*u0*d0[IX(i1,j1,k0)]+
|
t1*u0*center_d0[IX(i1,j1,k0)]+
|
||||||
t0*u1*d0[IX(i1,j0,k1)]+
|
t0*u1*center_d0[IX(i1,j0,k1)]+
|
||||||
t1*u1*d0[IX(i1,j1,k1)]
|
t1*u1*center_d0[IX(i1,j1,k1)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
778
src/main/c/fluidsim.c
Normal file
778
src/main/c/fluidsim.c
Normal file
@ -0,0 +1,778 @@
|
|||||||
|
#include <jni.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "includes/utilities.h"
|
||||||
|
#include "includes/chunkmask.h"
|
||||||
|
#include "includes/electrosphere_FluidSim.h"
|
||||||
|
#include "includes/mainFunctions.h"
|
||||||
|
|
||||||
|
#include "./chunkmask.c"
|
||||||
|
#include "./velocitystep.c"
|
||||||
|
#include "./densitystep.c"
|
||||||
|
|
||||||
|
//include stb ds
|
||||||
|
#define STB_DS_IMPLEMENTATION
|
||||||
|
#include "./lib/stb/stb_ds.h"
|
||||||
|
|
||||||
|
#define DIM 18
|
||||||
|
#define LINEARSOLVERTIMES 20
|
||||||
|
|
||||||
|
#define DIFFUSION_CONSTANT 0.000001
|
||||||
|
#define VISCOSITY_CONSTANT 0.000001
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A chunk
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
jobject jchunk;
|
||||||
|
float * d[27];
|
||||||
|
float * d0[27];
|
||||||
|
float * u[27];
|
||||||
|
float * v[27];
|
||||||
|
float * w[27];
|
||||||
|
float * u0[27];
|
||||||
|
float * v0[27];
|
||||||
|
float * w0[27];
|
||||||
|
jobjectArray jd;
|
||||||
|
jobjectArray jd0;
|
||||||
|
jobjectArray ju;
|
||||||
|
jobjectArray jv;
|
||||||
|
jobjectArray jw;
|
||||||
|
jobjectArray ju0;
|
||||||
|
jobjectArray jv0;
|
||||||
|
jobjectArray jw0;
|
||||||
|
int chunkMask;
|
||||||
|
} Chunk;
|
||||||
|
|
||||||
|
//all chunks
|
||||||
|
Chunk ** chunks = NULL;
|
||||||
|
|
||||||
|
#define getChunk(i) (*env)->CallObjectMethod(env,chunkList,jListGet,i)
|
||||||
|
#define getBuffArr(buffId) (*env)->GetObjectField(env,chunkJRaw,buffId)
|
||||||
|
#define setBuffArr(buffId,value) (*env)->SetObjectField(env,chunkJRaw,buffId,value)
|
||||||
|
|
||||||
|
//jni help:
|
||||||
|
//https://stackoverflow.com/questions/39823375/clarification-about-getfieldid
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_simulate(
|
||||||
|
JNIEnv * env,
|
||||||
|
jclass class,
|
||||||
|
jobject chunkList,
|
||||||
|
jfloat timestep
|
||||||
|
){
|
||||||
|
jclass listClass = (*env)->FindClass(env,"java/util/List");
|
||||||
|
jclass fluidSimClass = (*env)->FindClass(env,"electrosphere/FluidSim");
|
||||||
|
//JNIEnv *env, jclass clazz, const char *name, const char *sig
|
||||||
|
jmethodID jListSize = (*env)->GetMethodID(env, listClass, "size", "()I");
|
||||||
|
jmethodID jListGet = (*env)->GetMethodID(env, listClass, "get", "(I)Ljava/lang/Object;");
|
||||||
|
jmethodID jListAdd = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z");
|
||||||
|
|
||||||
|
//ByteBuffer[]
|
||||||
|
jfieldID dJId = (*env)->GetFieldID(env,fluidSimClass,"density","[Ljava/nio/ByteBuffer;");
|
||||||
|
jfieldID d0JId = (*env)->GetFieldID(env,fluidSimClass,"densityAddition","[Ljava/nio/ByteBuffer;");
|
||||||
|
jfieldID uJId = (*env)->GetFieldID(env,fluidSimClass,"uVector","[Ljava/nio/ByteBuffer;");
|
||||||
|
jfieldID vJId = (*env)->GetFieldID(env,fluidSimClass,"vVector","[Ljava/nio/ByteBuffer;");
|
||||||
|
jfieldID wJId = (*env)->GetFieldID(env,fluidSimClass,"wVector","[Ljava/nio/ByteBuffer;");
|
||||||
|
jfieldID u0JId = (*env)->GetFieldID(env,fluidSimClass,"uAdditionVector","[Ljava/nio/ByteBuffer;");
|
||||||
|
jfieldID v0JId = (*env)->GetFieldID(env,fluidSimClass,"vAdditionVector","[Ljava/nio/ByteBuffer;");
|
||||||
|
jfieldID w0JId = (*env)->GetFieldID(env,fluidSimClass,"wAdditionVector","[Ljava/nio/ByteBuffer;");
|
||||||
|
jfieldID chunkmaskJId = (*env)->GetFieldID(env,fluidSimClass,"chunkMask","I");
|
||||||
|
|
||||||
|
//the number of chunks
|
||||||
|
int numChunks = (*env)->CallIntMethod(env,chunkList,jListSize);
|
||||||
|
|
||||||
|
//current chunk (this)
|
||||||
|
jobject chunkJRaw;
|
||||||
|
//current chunk fields
|
||||||
|
jobjectArray jd;
|
||||||
|
jobjectArray jd0;
|
||||||
|
jobjectArray u;
|
||||||
|
jobjectArray v;
|
||||||
|
jobjectArray w;
|
||||||
|
jobjectArray u0;
|
||||||
|
jobjectArray v0;
|
||||||
|
jobjectArray w0;
|
||||||
|
int chunkMask;
|
||||||
|
|
||||||
|
//solve chunk mask
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
chunkJRaw = getChunk(i);
|
||||||
|
chunkMask = Java_electrosphere_FluidSim_calculateChunkMask(env,chunkJRaw,getBuffArr(dJId));
|
||||||
|
(*env)->SetIntField(env,chunkJRaw,chunkmaskJId,chunkMask);
|
||||||
|
|
||||||
|
Chunk * newChunk;
|
||||||
|
if(i >= stbds_arrlen(chunks)){
|
||||||
|
// printf("allocate chunk %d\n",i);
|
||||||
|
// fflush(stdout);
|
||||||
|
newChunk = (Chunk *)malloc(sizeof(Chunk));
|
||||||
|
// printf("new chunk %p\n",newChunk);
|
||||||
|
// fflush(stdout);
|
||||||
|
stbds_arrput(chunks,newChunk);
|
||||||
|
// printf("new chunk %p\n",chunks[i]);
|
||||||
|
// fflush(stdout);
|
||||||
|
} else {
|
||||||
|
newChunk = chunks[i];
|
||||||
|
// printf("get chunk %d: %p\n",i,newChunk);
|
||||||
|
// fflush(stdout);
|
||||||
|
}
|
||||||
|
jd = (*env)->GetObjectField(env,chunkJRaw,dJId);
|
||||||
|
jd0 = (*env)->GetObjectField(env,chunkJRaw,d0JId);
|
||||||
|
u = (*env)->GetObjectField(env,chunkJRaw,uJId);
|
||||||
|
v = (*env)->GetObjectField(env,chunkJRaw,vJId);
|
||||||
|
w = (*env)->GetObjectField(env,chunkJRaw,wJId);
|
||||||
|
u0 = (*env)->GetObjectField(env,chunkJRaw,u0JId);
|
||||||
|
v0 = (*env)->GetObjectField(env,chunkJRaw,v0JId);
|
||||||
|
w0 = (*env)->GetObjectField(env,chunkJRaw,w0JId);
|
||||||
|
newChunk->jd = jd;
|
||||||
|
newChunk->jd0 = jd0;
|
||||||
|
newChunk->ju = u;
|
||||||
|
newChunk->jv = v;
|
||||||
|
newChunk->jw = w;
|
||||||
|
newChunk->ju0 = u0;
|
||||||
|
newChunk->jv0 = v0;
|
||||||
|
newChunk->jw0 = w0;
|
||||||
|
newChunk->jchunk = chunkJRaw;
|
||||||
|
newChunk->chunkMask = chunkMask;
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
if((chunkMask & CHUNK_INDEX_ARR[j]) > 0){
|
||||||
|
newChunk->d[j] = GET_ARR(env,jd,j);
|
||||||
|
newChunk->d0[j] = GET_ARR(env,jd0,j);
|
||||||
|
newChunk->u[j] = GET_ARR(env,u,j);
|
||||||
|
newChunk->v[j] = GET_ARR(env,v,j);
|
||||||
|
newChunk->w[j] = GET_ARR(env,w,j);
|
||||||
|
newChunk->u0[j] = GET_ARR(env,u0,j);
|
||||||
|
newChunk->v0[j] = GET_ARR(env,v0,j);
|
||||||
|
newChunk->w0[j] = GET_ARR(env,w0,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for(int j = 0; j < 27; j++){
|
||||||
|
// newChunk.d[j] = GET_ARR(env,d,j);
|
||||||
|
// }
|
||||||
|
// chunks[i].d0 = getBuffArr(d0JId);
|
||||||
|
// chunks[i].u = getBuffArr(uJId);
|
||||||
|
// chunks[i].v = getBuffArr(vJId);
|
||||||
|
// chunks[i].w = getBuffArr(wJId);
|
||||||
|
// chunks[i].u0 = getBuffArr(u0JId);
|
||||||
|
// chunks[i].v0 = getBuffArr(v0JId);
|
||||||
|
// chunks[i].w0 = getBuffArr(w0JId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// printf("%p\n",chunks[0].d);
|
||||||
|
|
||||||
|
//solve chunk mask
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
//old assignments
|
||||||
|
// chunkJRaw = getChunk(i);
|
||||||
|
// chunkMask = (*env)->GetIntField(env,chunkJRaw,chunkmaskJId);
|
||||||
|
// d = getBuffArr(dJId);
|
||||||
|
// d0 = getBuffArr(d0JId);
|
||||||
|
// u = getBuffArr(uJId);
|
||||||
|
// v = getBuffArr(vJId);
|
||||||
|
// w = getBuffArr(wJId);
|
||||||
|
// u0 = getBuffArr(u0JId);
|
||||||
|
// v0 = getBuffArr(v0JId);
|
||||||
|
// w0 = getBuffArr(w0JId);
|
||||||
|
Java_electrosphere_FluidSim_addSourceToVectors(
|
||||||
|
DIM,
|
||||||
|
chunkMask,
|
||||||
|
currentChunk->u,
|
||||||
|
currentChunk->v,
|
||||||
|
currentChunk->w,
|
||||||
|
currentChunk->u0,
|
||||||
|
currentChunk->v0,
|
||||||
|
currentChunk->w0,
|
||||||
|
DIFFUSION_CONSTANT,
|
||||||
|
VISCOSITY_CONSTANT,
|
||||||
|
timestep
|
||||||
|
);
|
||||||
|
}
|
||||||
|
//swap all vector fields
|
||||||
|
{
|
||||||
|
//swap vector fields
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
|
||||||
|
float * tmpArr;
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->u[j];
|
||||||
|
currentChunk->u[j] = currentChunk->u0[j];
|
||||||
|
currentChunk->u0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->v[j];
|
||||||
|
currentChunk->v[j] = currentChunk->v0[j];
|
||||||
|
currentChunk->v0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->w[j];
|
||||||
|
currentChunk->w[j] = currentChunk->w0[j];
|
||||||
|
currentChunk->w0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//copy neighbors
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//solve vector diffusion
|
||||||
|
{
|
||||||
|
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||||
|
//solve vector diffusion
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
Java_electrosphere_FluidSim_solveVectorDiffuse(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
//update array for vectors
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//solve projection
|
||||||
|
{
|
||||||
|
//update array for vectors
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||||
|
}
|
||||||
|
//setup projection
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
Java_electrosphere_FluidSim_setupProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
//update array for vectors
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||||
|
}
|
||||||
|
//samples u0, v0
|
||||||
|
//sets u0
|
||||||
|
//these should have just been mirrored in the above
|
||||||
|
//
|
||||||
|
//Perform main projection solver
|
||||||
|
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
Java_electrosphere_FluidSim_solveProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//samples u,v,w,u0
|
||||||
|
//sets u,v,w
|
||||||
|
//Finalize projection
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
Java_electrosphere_FluidSim_finalizeProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
//set boundaries a final time for u,v,w
|
||||||
|
//...
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//swap all vector fields
|
||||||
|
{
|
||||||
|
//swap vector fields
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
|
||||||
|
float * tmpArr;
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->u[j];
|
||||||
|
currentChunk->u[j] = currentChunk->u0[j];
|
||||||
|
currentChunk->u0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->v[j];
|
||||||
|
currentChunk->v[j] = currentChunk->v0[j];
|
||||||
|
currentChunk->v0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->w[j];
|
||||||
|
currentChunk->w[j] = currentChunk->w0[j];
|
||||||
|
currentChunk->w0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//copy neighbors
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//advect vectors across boundaries
|
||||||
|
{
|
||||||
|
//update border arrs
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||||
|
}
|
||||||
|
//advect
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
Java_electrosphere_FluidSim_advectVectors(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
//update neighbor arr
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//solve projection
|
||||||
|
{
|
||||||
|
//update array for vectors
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||||
|
}
|
||||||
|
//setup projection
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
Java_electrosphere_FluidSim_setupProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
//update array for vectors
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||||
|
}
|
||||||
|
//samples u0, v0
|
||||||
|
//sets u0
|
||||||
|
//these should have just been mirrored in the above
|
||||||
|
//
|
||||||
|
//Perform main projection solver
|
||||||
|
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
Java_electrosphere_FluidSim_solveProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//samples u,v,w,u0
|
||||||
|
//sets u,v,w
|
||||||
|
//Finalize projection
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
Java_electrosphere_FluidSim_finalizeProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
//set boundaries a final time for u,v,w
|
||||||
|
//...
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
u0 = currentChunk->ju0;
|
||||||
|
v0 = currentChunk->jv0;
|
||||||
|
w0 = currentChunk->jw0;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//add density
|
||||||
|
{
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
Java_electrosphere_FluidSim_addDensity(DIM,chunkMask,currentChunk->d,currentChunk->d0,timestep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//swap all density arrays
|
||||||
|
{
|
||||||
|
//swap vector fields
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
|
||||||
|
float * tmpArr;
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->d[j];
|
||||||
|
currentChunk->d[j] = currentChunk->d0[j];
|
||||||
|
currentChunk->d0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
jd = currentChunk->jd;
|
||||||
|
jd0 = currentChunk->jd0;
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,0,currentChunk->d);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,0,currentChunk->d0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//diffuse density
|
||||||
|
{
|
||||||
|
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
u = currentChunk->ju;
|
||||||
|
v = currentChunk->jv;
|
||||||
|
w = currentChunk->jw;
|
||||||
|
Java_electrosphere_FluidSim_solveDiffuseDensity(DIM,chunkMask,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,0,currentChunk->d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//swap all density arrays
|
||||||
|
{
|
||||||
|
//swap vector fields
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
float * tmpArr;
|
||||||
|
for(int j = 0; j < 27; j++){
|
||||||
|
tmpArr = currentChunk->d[j];
|
||||||
|
currentChunk->d[j] = currentChunk->d0[j];
|
||||||
|
currentChunk->d0[j] = tmpArr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,0,currentChunk->d);
|
||||||
|
copyNeighborsRaw(DIM,chunkMask,0,0,currentChunk->d0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//advect density
|
||||||
|
{
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
Java_electrosphere_FluidSim_advectDensity(DIM,chunkMask,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//mirror densities
|
||||||
|
{
|
||||||
|
for(int i = 0; i < numChunks; i++){
|
||||||
|
Chunk * currentChunk = chunks[i];
|
||||||
|
chunkJRaw = currentChunk->jchunk;
|
||||||
|
chunkMask = currentChunk->chunkMask;
|
||||||
|
setBoundsToNeighborsRaw(DIM,chunkMask,0,currentChunk->d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,46 +16,14 @@ extern "C" {
|
|||||||
#undef electrosphere_FluidSim_LINEARSOLVERTIMES
|
#undef electrosphere_FluidSim_LINEARSOLVERTIMES
|
||||||
#define electrosphere_FluidSim_LINEARSOLVERTIMES 20L
|
#define electrosphere_FluidSim_LINEARSOLVERTIMES 20L
|
||||||
#undef electrosphere_FluidSim_GRAVITY
|
#undef electrosphere_FluidSim_GRAVITY
|
||||||
#define electrosphere_FluidSim_GRAVITY 0.0f
|
#define electrosphere_FluidSim_GRAVITY -100.0f
|
||||||
/*
|
/*
|
||||||
* Class: electrosphere_FluidSim
|
* Class: electrosphere_FluidSim
|
||||||
* Method: createThreadpool
|
* Method: simulate
|
||||||
* Signature: (I)J
|
* Signature: (Ljava/util/List;F)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jlong JNICALL Java_electrosphere_FluidSim_createThreadpool
|
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_simulate
|
||||||
(JNIEnv *, jclass, jint);
|
(JNIEnv *, jclass, jobject, jfloat);
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: electrosphere_FluidSim
|
|
||||||
* Method: unlockThreads
|
|
||||||
* Signature: (J)J
|
|
||||||
*/
|
|
||||||
JNIEXPORT jlong JNICALL Java_electrosphere_FluidSim_unlockThreads
|
|
||||||
(JNIEnv *, jclass, jlong);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: electrosphere_FluidSim
|
|
||||||
* Method: queueChunk
|
|
||||||
* Signature: (JII[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_queueChunk
|
|
||||||
(JNIEnv *, jclass, jlong, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: electrosphere_FluidSim
|
|
||||||
* Method: submitWork
|
|
||||||
* Signature: (J)V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_submitWork
|
|
||||||
(JNIEnv *, jclass, jlong);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: electrosphere_FluidSim
|
|
||||||
* Method: fetchWork
|
|
||||||
* Signature: (J)V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_fetchWork
|
|
||||||
(JNIEnv *, jclass, jlong);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
//include guard
|
|
||||||
#ifndef LIB_FLUID_SIM
|
|
||||||
#define LIB_FLUID_SIM
|
|
||||||
|
|
||||||
#include "./threadpool.h"
|
|
||||||
|
|
||||||
void simulate(LibraryContext * context, int threadIndex);
|
|
||||||
|
|
||||||
void addDensity(int N, int chunk_mask, float * jrx, float * x0, float dt);
|
|
||||||
|
|
||||||
void diffuseDensity(int N, int chunk_mask, float * jrx, float * jrx0, float DIFFUSION_CONST, float VISCOSITY_CONST, float dt);
|
|
||||||
|
|
||||||
void advectDensity(uint32_t chunk_mask, int N, float * jrd, float * jrd0, float * u, float * v, float * w, float dt);
|
|
||||||
|
|
||||||
//close include guard
|
|
||||||
#endif
|
|
||||||
101
src/main/c/includes/mainFunctions.h
Normal file
101
src/main/c/includes/mainFunctions.h
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
#ifndef MAINFUNC
|
||||||
|
#define MAINFUNC
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: calculateChunkMask
|
||||||
|
* Signature: ([Ljava/nio/ByteBuffer;)I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_electrosphere_FluidSim_calculateChunkMask
|
||||||
|
(JNIEnv *, jobject, jobjectArray);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: addSourceToVectors
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_addSourceToVectors
|
||||||
|
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: solveVectorDiffuse
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_solveVectorDiffuse
|
||||||
|
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: setupProjection
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_setupProjection
|
||||||
|
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: solveProjection
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_solveProjection
|
||||||
|
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: finalizeProjection
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_finalizeProjection
|
||||||
|
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: advectVectors
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_advectVectors
|
||||||
|
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: addDensity
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;F)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_addDensity
|
||||||
|
(int, int, float **, float **, float);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: solveDiffuseDensity
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_solveDiffuseDensity
|
||||||
|
(int, int, float **, float **, float **, float **, float **, float, float, float);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: electrosphere_FluidSim
|
||||||
|
* Method: advectDensity
|
||||||
|
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||||
|
*/
|
||||||
|
void Java_electrosphere_FluidSim_advectDensity
|
||||||
|
(int, int, float **, float **, float **, float **, float **, float, float, float);
|
||||||
|
|
||||||
|
void setBoundsToNeighborsRaw
|
||||||
|
(
|
||||||
|
int N,
|
||||||
|
int chunk_mask,
|
||||||
|
int vector_dir,
|
||||||
|
float ** neighborArray);
|
||||||
|
|
||||||
|
void copyNeighborsRaw
|
||||||
|
(
|
||||||
|
int N,
|
||||||
|
int chunk_mask,
|
||||||
|
int cx,
|
||||||
|
int vector_dir,
|
||||||
|
float ** neighborArray);
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -1,48 +0,0 @@
|
|||||||
#ifndef THREADPOOL
|
|
||||||
#define THREADPOOL
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A threadpool used to distribute work
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
int numThreads;
|
|
||||||
pthread_t * threads;
|
|
||||||
pthread_barrier_t * barrierMain;
|
|
||||||
pthread_barrier_t * barrierWithParentThread;
|
|
||||||
} ThreadPool;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A single chunk to have fluid simulated
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
int chunkMask;
|
|
||||||
float timestep;
|
|
||||||
float * d;
|
|
||||||
float * u;
|
|
||||||
float * v;
|
|
||||||
float * w;
|
|
||||||
float * d0;
|
|
||||||
float * u0;
|
|
||||||
float * v0;
|
|
||||||
float * w0;
|
|
||||||
float diffuseConst;
|
|
||||||
float viscosityConst;
|
|
||||||
} Chunk;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overall state of the whole application
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
ThreadPool * threadpool;
|
|
||||||
Chunk * chunks;
|
|
||||||
int numChunks;
|
|
||||||
} LibraryContext;
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -4,19 +4,11 @@
|
|||||||
#ifndef UTILITIES_H
|
#ifndef UTILITIES_H
|
||||||
#define UTILITIES_H
|
#define UTILITIES_H
|
||||||
|
|
||||||
//swaps where two pointers are pointing
|
|
||||||
#define SWAP(x0,x) {float *tmp=x0;x0=x;x=tmp;}
|
#define SWAP(x0,x) {float *tmp=x0;x0=x;x=tmp;}
|
||||||
|
|
||||||
//gets the index of a 3d point in an N^3 array
|
|
||||||
#define IX(i,j,k) ((i)+(N)*(j)+(N*N)*(k))
|
#define IX(i,j,k) ((i)+(N)*(j)+(N*N)*(k))
|
||||||
|
|
||||||
//gets the index of a 3d point in a 3^3 array
|
|
||||||
#define CK(m,n,o) ((m)+(n)*(3)+(o)*(3)*(3))
|
#define CK(m,n,o) ((m)+(n)*(3)+(o)*(3)*(3))
|
||||||
|
|
||||||
//gets the raw array of a java buffer
|
|
||||||
#define GET_ARR(env,src,i) (*env)->GetDirectBufferAddress(env,(*env)->GetObjectArrayElement(env,src,i))
|
#define GET_ARR(env,src,i) (*env)->GetDirectBufferAddress(env,(*env)->GetObjectArrayElement(env,src,i))
|
||||||
|
#define GET_ARR_RAW(env,src,i) src[i]
|
||||||
//returns true if the array exists, false otherwise
|
|
||||||
#define ARR_EXISTS(chunk_mask,m,n,o) (chunk_mask & CHUNK_INDEX_ARR[CK(m,n,o)]) > 0
|
#define ARR_EXISTS(chunk_mask,m,n,o) (chunk_mask & CHUNK_INDEX_ARR[CK(m,n,o)]) > 0
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1 +0,0 @@
|
|||||||
Subproject commit ae721c50eaf761660b4f90cc590453cdb0c2acd0
|
|
||||||
@ -1,77 +0,0 @@
|
|||||||
#include <jni.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <immintrin.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
|
|
||||||
//git libs
|
|
||||||
#include "../lib/stb/stb_ds.h"
|
|
||||||
|
|
||||||
//all other headers
|
|
||||||
#include "../includes/libfluidsim.h"
|
|
||||||
#include "../includes/threadpool.h"
|
|
||||||
#include "../includes/chunkmask.h"
|
|
||||||
#include "../includes/utilities.h"
|
|
||||||
|
|
||||||
#define DIM 18
|
|
||||||
#define LINEARSOLVERTIMES 20
|
|
||||||
|
|
||||||
|
|
||||||
//call this if the child threads need to wait on one another
|
|
||||||
void sync(LibraryContext * context){
|
|
||||||
pthread_barrier_wait(context->threadpool->barrierMain);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main simulation function
|
|
||||||
*/
|
|
||||||
void simulate(LibraryContext * context, int threadIndex){
|
|
||||||
int numThreads = context->threadpool->numThreads;
|
|
||||||
int numChunks = context->numChunks;
|
|
||||||
|
|
||||||
//add densities to chunks
|
|
||||||
for(int i = threadIndex; i < numChunks; i = i + numThreads){
|
|
||||||
Chunk chunk = context->chunks[i];
|
|
||||||
addDensity(DIM,chunk.chunkMask,chunk.d,chunk.d0,chunk.timestep);
|
|
||||||
}
|
|
||||||
sync(context);
|
|
||||||
|
|
||||||
//diffuse density
|
|
||||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
|
||||||
for(int i = threadIndex; i < numChunks; i = i + numThreads){
|
|
||||||
Chunk chunk = context->chunks[i];
|
|
||||||
SWAP(chunk.d,chunk.d0);
|
|
||||||
diffuseDensity(
|
|
||||||
DIM,
|
|
||||||
chunk.chunkMask,
|
|
||||||
chunk.d,
|
|
||||||
chunk.d0,
|
|
||||||
chunk.diffuseConst,
|
|
||||||
chunk.viscosityConst,
|
|
||||||
chunk.timestep
|
|
||||||
);
|
|
||||||
SWAP(chunk.d,chunk.d0);
|
|
||||||
}
|
|
||||||
sync(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
//advect density
|
|
||||||
for(int i = threadIndex; i < numChunks; i = i + numThreads){
|
|
||||||
Chunk chunk = context->chunks[i];
|
|
||||||
advectDensity(
|
|
||||||
chunk.chunkMask,
|
|
||||||
DIM,
|
|
||||||
chunk.d,
|
|
||||||
chunk.d0,
|
|
||||||
chunk.u,
|
|
||||||
chunk.v,
|
|
||||||
chunk.w,
|
|
||||||
chunk.timestep
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//call this if the child threads need to wait on one another
|
|
||||||
sync(context);
|
|
||||||
}
|
|
||||||
@ -1,222 +0,0 @@
|
|||||||
#include <jni.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <immintrin.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
|
|
||||||
//include stb ds
|
|
||||||
#define STB_DS_IMPLEMENTATION
|
|
||||||
#include "../lib/stb/stb_ds.h"
|
|
||||||
|
|
||||||
//all other headers
|
|
||||||
#include "../includes/libfluidsim.h"
|
|
||||||
#include "../includes/threadpool.h"
|
|
||||||
#include "../includes/chunkmask.h"
|
|
||||||
#include "../includes/utilities.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
LibraryContext * libraryContext;
|
|
||||||
int threadIndex; //the index for this thread in all threadpool objects
|
|
||||||
} ThreadData;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main loops for the thread
|
|
||||||
*/
|
|
||||||
void * mainThreadLoop(void * data);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: electrosphere_FluidSim
|
|
||||||
* Method: createThreadpool
|
|
||||||
* Signature: (I)J
|
|
||||||
*/
|
|
||||||
JNIEXPORT jlong JNICALL Java_electrosphere_FluidSim_createThreadpool
|
|
||||||
(JNIEnv * env,
|
|
||||||
jclass class,
|
|
||||||
jint numThreads){
|
|
||||||
|
|
||||||
LibraryContext * libraryContext = (LibraryContext *)malloc(sizeof(LibraryContext));
|
|
||||||
libraryContext->numChunks = 0;
|
|
||||||
libraryContext->chunks = NULL; //must be tied to NULL at the start
|
|
||||||
|
|
||||||
//init threadpool
|
|
||||||
libraryContext->threadpool = (ThreadPool *)malloc(sizeof(ThreadPool));
|
|
||||||
ThreadPool * pool = libraryContext->threadpool;
|
|
||||||
pool->threads = (pthread_t *)malloc(sizeof(pthread_t) * numThreads);
|
|
||||||
pool->numThreads = numThreads;
|
|
||||||
|
|
||||||
//used for storing return codes from pthread calls
|
|
||||||
int retCode = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
//create thread barriers
|
|
||||||
printf("Creating barrier for %d threads\n",pool->numThreads);
|
|
||||||
pool->barrierMain = (pthread_barrier_t *)malloc(sizeof(pthread_barrier_t));
|
|
||||||
retCode = pthread_barrier_init(pool->barrierMain,NULL,pool->numThreads);
|
|
||||||
if(retCode != 0){
|
|
||||||
printf("Failed to create main barrier! %d\n",retCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
//+1 is for the main thread
|
|
||||||
printf("Creating barrier for %d threads\n",pool->numThreads+1);
|
|
||||||
pool->barrierWithParentThread = (pthread_barrier_t *)malloc(sizeof(pthread_barrier_t));
|
|
||||||
retCode = pthread_barrier_init(pool->barrierWithParentThread,NULL,(pool->numThreads)+1);
|
|
||||||
if(retCode != 0){
|
|
||||||
printf("Failed to create barrier with main thread! %d\n",retCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
//start threads
|
|
||||||
for(int i = 0; i < pool->numThreads; i++){
|
|
||||||
|
|
||||||
//create data to be sent to thread
|
|
||||||
ThreadData * threadData = (ThreadData *)malloc(sizeof(ThreadData));
|
|
||||||
threadData->libraryContext = libraryContext;
|
|
||||||
threadData->threadIndex = i;
|
|
||||||
|
|
||||||
//create thread
|
|
||||||
retCode = pthread_create(&pool->threads[i], NULL, mainThreadLoop, threadData);
|
|
||||||
if(retCode != 0){
|
|
||||||
printf("Failed to create thread!~ %d\n",retCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Finished creating threads\n");
|
|
||||||
|
|
||||||
return (jlong)libraryContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Debug function
|
|
||||||
*/
|
|
||||||
JNIEXPORT jlong JNICALL Java_electrosphere_FluidSim_unlockThreads(
|
|
||||||
JNIEnv * env,
|
|
||||||
jclass class,
|
|
||||||
jlong threadPoolPtrRaw){
|
|
||||||
LibraryContext * libraryContext = (LibraryContext *)threadPoolPtrRaw;
|
|
||||||
pthread_barrier_wait(libraryContext->threadpool->barrierWithParentThread);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Queues a single chunk to do work
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_queueChunk(
|
|
||||||
JNIEnv * env,
|
|
||||||
jclass class,
|
|
||||||
jlong libraryContextPtr,
|
|
||||||
jint DIM,
|
|
||||||
jint chunkMask,
|
|
||||||
jobjectArray dr,
|
|
||||||
jobjectArray d0r,
|
|
||||||
jobjectArray ur,
|
|
||||||
jobjectArray vr,
|
|
||||||
jobjectArray wr,
|
|
||||||
jobjectArray u0r,
|
|
||||||
jobjectArray v0r,
|
|
||||||
jobjectArray w0r,
|
|
||||||
jfloat DIFFUSION_CONSTANT,
|
|
||||||
jfloat VISCOSITY_CONSTANT,
|
|
||||||
jfloat timestep){
|
|
||||||
LibraryContext * libraryContext = (LibraryContext *)libraryContextPtr;
|
|
||||||
|
|
||||||
//if the array is full, malloc a new chunk, otherwise overwrite an existing one
|
|
||||||
int arrayCapacity = stbds_arrlen(libraryContext->chunks);
|
|
||||||
if(libraryContext->numChunks >= arrayCapacity){
|
|
||||||
Chunk * newChunk = (Chunk *)malloc(sizeof(Chunk));
|
|
||||||
newChunk->chunkMask = chunkMask;
|
|
||||||
newChunk->u = GET_ARR(env,ur,CENTER_LOC);
|
|
||||||
newChunk->v = GET_ARR(env,vr,CENTER_LOC);
|
|
||||||
newChunk->w = GET_ARR(env,wr,CENTER_LOC);
|
|
||||||
newChunk->u0 = GET_ARR(env,u0r,CENTER_LOC);
|
|
||||||
newChunk->v0 = GET_ARR(env,v0r,CENTER_LOC);
|
|
||||||
newChunk->w0 = GET_ARR(env,w0r,CENTER_LOC);
|
|
||||||
newChunk->d = GET_ARR(env,dr,CENTER_LOC);
|
|
||||||
newChunk->d0 = GET_ARR(env,d0r,CENTER_LOC);
|
|
||||||
newChunk->timestep = timestep;
|
|
||||||
newChunk->diffuseConst = DIFFUSION_CONSTANT;
|
|
||||||
newChunk->viscosityConst = VISCOSITY_CONSTANT;
|
|
||||||
stbds_arrput(libraryContext->chunks,newChunk[0]);
|
|
||||||
} else {
|
|
||||||
Chunk * currentChunk = &libraryContext->chunks[libraryContext->numChunks];
|
|
||||||
currentChunk->chunkMask = chunkMask;
|
|
||||||
currentChunk->u = GET_ARR(env,ur,CENTER_LOC);
|
|
||||||
currentChunk->v = GET_ARR(env,vr,CENTER_LOC);
|
|
||||||
currentChunk->w = GET_ARR(env,wr,CENTER_LOC);
|
|
||||||
currentChunk->u0 = GET_ARR(env,u0r,CENTER_LOC);
|
|
||||||
currentChunk->v0 = GET_ARR(env,v0r,CENTER_LOC);
|
|
||||||
currentChunk->w0 = GET_ARR(env,w0r,CENTER_LOC);
|
|
||||||
currentChunk->d = GET_ARR(env,dr,CENTER_LOC);
|
|
||||||
currentChunk->d0 = GET_ARR(env,d0r,CENTER_LOC);
|
|
||||||
currentChunk->timestep = timestep;
|
|
||||||
currentChunk->diffuseConst = DIFFUSION_CONSTANT;
|
|
||||||
currentChunk->viscosityConst = VISCOSITY_CONSTANT;
|
|
||||||
}
|
|
||||||
|
|
||||||
libraryContext->numChunks++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Submits a request to the threadpool to do all the simulation
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_submitWork(
|
|
||||||
JNIEnv * env,
|
|
||||||
jclass class,
|
|
||||||
jlong contextPtr
|
|
||||||
){
|
|
||||||
LibraryContext * libraryContext = (LibraryContext *)contextPtr;
|
|
||||||
//begin work
|
|
||||||
//wait to begin work until parent signals its ready
|
|
||||||
pthread_barrier_wait(libraryContext->threadpool->barrierWithParentThread);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* blocks until the simulation finishes, then grabs the results of the sim
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_fetchWork(
|
|
||||||
JNIEnv * env,
|
|
||||||
jclass class,
|
|
||||||
jlong contextPtr
|
|
||||||
){
|
|
||||||
LibraryContext * libraryContext = (LibraryContext *)contextPtr;
|
|
||||||
|
|
||||||
//Roll threads over to the beginning of the workflow again, meanwhile do main thread cleanup work
|
|
||||||
pthread_barrier_wait(libraryContext->threadpool->barrierWithParentThread);
|
|
||||||
|
|
||||||
//main thread does work to setup child chunks for receiving data here
|
|
||||||
libraryContext->numChunks = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main loop for threads
|
|
||||||
*/
|
|
||||||
void * mainThreadLoop(void * dataRaw){
|
|
||||||
ThreadData * threadData = (ThreadData *)dataRaw;
|
|
||||||
LibraryContext * libraryContext = threadData->libraryContext;
|
|
||||||
int threadIndex = threadData->threadIndex;
|
|
||||||
|
|
||||||
|
|
||||||
//main thread loop
|
|
||||||
int running = 1;
|
|
||||||
while(running==1){
|
|
||||||
|
|
||||||
//begin work
|
|
||||||
//wait to begin work until parent signals its ready
|
|
||||||
pthread_barrier_wait(libraryContext->threadpool->barrierWithParentThread);
|
|
||||||
|
|
||||||
//do main work
|
|
||||||
simulate(libraryContext,threadData->threadIndex);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//finalize work
|
|
||||||
//the parent thread needs to call the barrier as well with whatever method it uses to grab data from the sim back to java
|
|
||||||
pthread_barrier_wait(libraryContext->threadpool->barrierWithParentThread);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,11 +1,9 @@
|
|||||||
#include <jni.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../includes/libfluidsim.h"
|
#include "includes/utilities.h"
|
||||||
#include "../includes/utilities.h"
|
#include "includes/chunkmask.h"
|
||||||
#include "../includes/chunkmask.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define BOUND_NO_DIR 0
|
#define BOUND_NO_DIR 0
|
||||||
@ -17,29 +15,28 @@
|
|||||||
#define SET_BOUND_USE_NEIGHBOR 1
|
#define SET_BOUND_USE_NEIGHBOR 1
|
||||||
|
|
||||||
void add_source(int N, float * x, float * s, float dt);
|
void add_source(int N, float * x, float * s, float dt);
|
||||||
void advect(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, jobjectArray jrd0, float * u, float * v, float * w, float dt);
|
void advect(uint32_t chunk_mask, int N, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds force to all vectors
|
* Adds force to all vectors
|
||||||
*/
|
*/
|
||||||
void addSourceToVectors
|
void Java_electrosphere_FluidSim_addSourceToVectors
|
||||||
(JNIEnv * env,
|
(
|
||||||
jobject this,
|
int N,
|
||||||
jint N,
|
int chunk_mask,
|
||||||
jint chunk_mask,
|
float ** jru,
|
||||||
jobjectArray jru,
|
float ** jrv,
|
||||||
jobjectArray jrv,
|
float ** jrw,
|
||||||
jobjectArray jrw,
|
float ** jru0,
|
||||||
jobjectArray jru0,
|
float ** jrv0,
|
||||||
jobjectArray jrv0,
|
float ** jrw0,
|
||||||
jobjectArray jrw0,
|
float DIFFUSION_CONST,
|
||||||
jfloat DIFFUSION_CONST,
|
float VISCOSITY_CONST,
|
||||||
jfloat VISCOSITY_CONST,
|
float dt){
|
||||||
jfloat dt){
|
add_source(N,GET_ARR_RAW(env,jru,CENTER_LOC),GET_ARR_RAW(env,jru0,CENTER_LOC),dt);
|
||||||
add_source(N,GET_ARR(env,jru,CENTER_LOC),GET_ARR(env,jru0,CENTER_LOC),dt);
|
add_source(N,GET_ARR_RAW(env,jrv,CENTER_LOC),GET_ARR_RAW(env,jrv0,CENTER_LOC),dt);
|
||||||
add_source(N,GET_ARR(env,jrv,CENTER_LOC),GET_ARR(env,jrv0,CENTER_LOC),dt);
|
add_source(N,GET_ARR_RAW(env,jrw,CENTER_LOC),GET_ARR_RAW(env,jrw0,CENTER_LOC),dt);
|
||||||
add_source(N,GET_ARR(env,jrw,CENTER_LOC),GET_ARR(env,jrw0,CENTER_LOC),dt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_source(int N, float * x, float * s, float dt){
|
void add_source(int N, float * x, float * s, float dt){
|
||||||
@ -53,29 +50,28 @@ void add_source(int N, float * x, float * s, float dt){
|
|||||||
/*
|
/*
|
||||||
* Solves vector diffusion along all axis
|
* Solves vector diffusion along all axis
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveVectorDiffuse
|
void Java_electrosphere_FluidSim_solveVectorDiffuse
|
||||||
(JNIEnv * env,
|
(
|
||||||
jobject this,
|
int N,
|
||||||
jint N,
|
int chunk_mask,
|
||||||
jint chunk_mask,
|
float ** jru,
|
||||||
jobjectArray jru,
|
float ** jrv,
|
||||||
jobjectArray jrv,
|
float ** jrw,
|
||||||
jobjectArray jrw,
|
float ** jru0,
|
||||||
jobjectArray jru0,
|
float ** jrv0,
|
||||||
jobjectArray jrv0,
|
float ** jrw0,
|
||||||
jobjectArray jrw0,
|
float DIFFUSION_CONST,
|
||||||
jfloat DIFFUSION_CONST,
|
float VISCOSITY_CONST,
|
||||||
jfloat VISCOSITY_CONST,
|
float dt){
|
||||||
jfloat dt){
|
|
||||||
float a=dt*VISCOSITY_CONST*N*N*N;
|
float a=dt*VISCOSITY_CONST*N*N*N;
|
||||||
float c=1+6*a;
|
float c=1+6*a;
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
float * u = GET_ARR(env,jru,CENTER_LOC);
|
float * u = GET_ARR_RAW(env,jru,CENTER_LOC);
|
||||||
float * v = GET_ARR(env,jrv,CENTER_LOC);
|
float * v = GET_ARR_RAW(env,jrv,CENTER_LOC);
|
||||||
float * w = GET_ARR(env,jrw,CENTER_LOC);
|
float * w = GET_ARR_RAW(env,jrw,CENTER_LOC);
|
||||||
float * u0 = GET_ARR(env,jru0,CENTER_LOC);
|
float * u0 = GET_ARR_RAW(env,jru0,CENTER_LOC);
|
||||||
float * v0 = GET_ARR(env,jrv0,CENTER_LOC);
|
float * v0 = GET_ARR_RAW(env,jrv0,CENTER_LOC);
|
||||||
float * w0 = GET_ARR(env,jrw0,CENTER_LOC);
|
float * w0 = GET_ARR_RAW(env,jrw0,CENTER_LOC);
|
||||||
|
|
||||||
__m256 aScalar = _mm256_set1_ps(a);
|
__m256 aScalar = _mm256_set1_ps(a);
|
||||||
__m256 cScalar = _mm256_set1_ps(c);
|
__m256 cScalar = _mm256_set1_ps(c);
|
||||||
@ -162,20 +158,19 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveVectorDiffuse
|
|||||||
/*
|
/*
|
||||||
* Sets up a projection system of equations
|
* Sets up a projection system of equations
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setupProjection
|
void Java_electrosphere_FluidSim_setupProjection
|
||||||
(JNIEnv * env,
|
(
|
||||||
jobject this,
|
int N,
|
||||||
jint N,
|
int chunk_mask,
|
||||||
jint chunk_mask,
|
float ** jru,
|
||||||
jobjectArray jru,
|
float ** jrv,
|
||||||
jobjectArray jrv,
|
float ** jrw,
|
||||||
jobjectArray jrw,
|
float ** jru0,
|
||||||
jobjectArray jru0,
|
float ** jrv0,
|
||||||
jobjectArray jrv0,
|
float ** jrw0,
|
||||||
jobjectArray jrw0,
|
float DIFFUSION_CONST,
|
||||||
jfloat DIFFUSION_CONST,
|
float VISCOSITY_CONST,
|
||||||
jfloat VISCOSITY_CONST,
|
float dt){
|
||||||
jfloat dt){
|
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
|
|
||||||
__m256 xVector = _mm256_set1_ps(N);
|
__m256 xVector = _mm256_set1_ps(N);
|
||||||
@ -185,12 +180,12 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setupProjection
|
|||||||
__m256 zeroVec = _mm256_set1_ps(0);
|
__m256 zeroVec = _mm256_set1_ps(0);
|
||||||
__m256 vector, vector2, vector3;
|
__m256 vector, vector2, vector3;
|
||||||
|
|
||||||
float * u = GET_ARR(env,jru,CENTER_LOC);
|
float * u = GET_ARR_RAW(env,jru,CENTER_LOC);
|
||||||
float * v = GET_ARR(env,jrv,CENTER_LOC);
|
float * v = GET_ARR_RAW(env,jrv,CENTER_LOC);
|
||||||
float * w = GET_ARR(env,jrw,CENTER_LOC);
|
float * w = GET_ARR_RAW(env,jrw,CENTER_LOC);
|
||||||
|
|
||||||
float * p = GET_ARR(env,jru0,CENTER_LOC);
|
float * p = GET_ARR_RAW(env,jru0,CENTER_LOC);
|
||||||
float * div = GET_ARR(env,jrv0,CENTER_LOC);
|
float * div = GET_ARR_RAW(env,jrv0,CENTER_LOC);
|
||||||
|
|
||||||
float scalar = 1.0/3.0;
|
float scalar = 1.0/3.0;
|
||||||
float h = 1.0/N;
|
float h = 1.0/N;
|
||||||
@ -257,28 +252,27 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setupProjection
|
|||||||
/*
|
/*
|
||||||
* Solves a projection system of equations
|
* Solves a projection system of equations
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveProjection
|
void Java_electrosphere_FluidSim_solveProjection
|
||||||
(JNIEnv * env,
|
(
|
||||||
jobject this,
|
int N,
|
||||||
jint N,
|
int chunk_mask,
|
||||||
jint chunk_mask,
|
float ** jru,
|
||||||
jobjectArray jru,
|
float ** jrv,
|
||||||
jobjectArray jrv,
|
float ** jrw,
|
||||||
jobjectArray jrw,
|
float ** jru0,
|
||||||
jobjectArray jru0,
|
float ** jrv0,
|
||||||
jobjectArray jrv0,
|
float ** jrw0,
|
||||||
jobjectArray jrw0,
|
float DIFFUSION_CONST,
|
||||||
jfloat DIFFUSION_CONST,
|
float VISCOSITY_CONST,
|
||||||
jfloat VISCOSITY_CONST,
|
float dt){
|
||||||
jfloat dt){
|
|
||||||
int a = 1;
|
int a = 1;
|
||||||
int c = 6;
|
int c = 6;
|
||||||
int i, j, k, l, m;
|
int i, j, k, l, m;
|
||||||
__m256 aScalar = _mm256_set1_ps(a);
|
__m256 aScalar = _mm256_set1_ps(a);
|
||||||
__m256 cScalar = _mm256_set1_ps(c);
|
__m256 cScalar = _mm256_set1_ps(c);
|
||||||
|
|
||||||
float * p = GET_ARR(env,jru0,CENTER_LOC);
|
float * p = GET_ARR_RAW(env,jru0,CENTER_LOC);
|
||||||
float * div = GET_ARR(env,jrv0,CENTER_LOC);
|
float * div = GET_ARR_RAW(env,jrv0,CENTER_LOC);
|
||||||
// update for each cell
|
// update for each cell
|
||||||
for(k=1; k<N-1; k++){
|
for(k=1; k<N-1; k++){
|
||||||
for(j=1; j<N-1; j++){
|
for(j=1; j<N-1; j++){
|
||||||
@ -312,20 +306,19 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveProjection
|
|||||||
/*
|
/*
|
||||||
* Finalizes a projection (subtract curl, set bounds, etc)
|
* Finalizes a projection (subtract curl, set bounds, etc)
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_finalizeProjection
|
void Java_electrosphere_FluidSim_finalizeProjection
|
||||||
(JNIEnv * env,
|
(
|
||||||
jobject this,
|
int N,
|
||||||
jint N,
|
int chunk_mask,
|
||||||
jint chunk_mask,
|
float ** jru,
|
||||||
jobjectArray jru,
|
float ** jrv,
|
||||||
jobjectArray jrv,
|
float ** jrw,
|
||||||
jobjectArray jrw,
|
float ** jru0,
|
||||||
jobjectArray jru0,
|
float ** jrv0,
|
||||||
jobjectArray jrv0,
|
float ** jrw0,
|
||||||
jobjectArray jrw0,
|
float DIFFUSION_CONST,
|
||||||
jfloat DIFFUSION_CONST,
|
float VISCOSITY_CONST,
|
||||||
jfloat VISCOSITY_CONST,
|
float dt){
|
||||||
jfloat dt){
|
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
// __m256 constScalar = _mm256_set1_ps(0.5f*N);
|
// __m256 constScalar = _mm256_set1_ps(0.5f*N);
|
||||||
__m256 xScalar = _mm256_set1_ps(0.5*N);
|
__m256 xScalar = _mm256_set1_ps(0.5*N);
|
||||||
@ -333,12 +326,12 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_finalizeProjection
|
|||||||
__m256 zScalar = _mm256_set1_ps(0.5*N);
|
__m256 zScalar = _mm256_set1_ps(0.5*N);
|
||||||
__m256 vector, vector2, vector3;
|
__m256 vector, vector2, vector3;
|
||||||
|
|
||||||
float * u = GET_ARR(env,jru,CENTER_LOC);
|
float * u = GET_ARR_RAW(env,jru,CENTER_LOC);
|
||||||
float * v = GET_ARR(env,jrv,CENTER_LOC);
|
float * v = GET_ARR_RAW(env,jrv,CENTER_LOC);
|
||||||
float * w = GET_ARR(env,jrw,CENTER_LOC);
|
float * w = GET_ARR_RAW(env,jrw,CENTER_LOC);
|
||||||
|
|
||||||
float * p = GET_ARR(env,jru0,CENTER_LOC);
|
float * p = GET_ARR_RAW(env,jru0,CENTER_LOC);
|
||||||
float * div = GET_ARR(env,jrv0,CENTER_LOC);
|
float * div = GET_ARR_RAW(env,jrv0,CENTER_LOC);
|
||||||
|
|
||||||
float h = 1.0 / N;
|
float h = 1.0 / N;
|
||||||
|
|
||||||
@ -407,41 +400,40 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_finalizeProjection
|
|||||||
/*
|
/*
|
||||||
* Advects u, v, and w
|
* Advects u, v, and w
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_advectVectors
|
void Java_electrosphere_FluidSim_advectVectors
|
||||||
(JNIEnv * env,
|
(
|
||||||
jobject this,
|
int N,
|
||||||
jint N,
|
int chunk_mask,
|
||||||
jint chunk_mask,
|
float ** jru,
|
||||||
jobjectArray jru,
|
float ** jrv,
|
||||||
jobjectArray jrv,
|
float ** jrw,
|
||||||
jobjectArray jrw,
|
float ** jru0,
|
||||||
jobjectArray jru0,
|
float ** jrv0,
|
||||||
jobjectArray jrv0,
|
float ** jrw0,
|
||||||
jobjectArray jrw0,
|
float DIFFUSION_CONST,
|
||||||
jfloat DIFFUSION_CONST,
|
float VISCOSITY_CONST,
|
||||||
jfloat VISCOSITY_CONST,
|
float dt){
|
||||||
jfloat dt){
|
advect(chunk_mask,N,1,jru,jru0,GET_ARR_RAW(env,jru0,CENTER_LOC),GET_ARR_RAW(env,jrv0,CENTER_LOC),GET_ARR_RAW(env,jrw0,CENTER_LOC),dt);
|
||||||
advect(env,chunk_mask,N,1,jru,jru0,GET_ARR(env,jru0,CENTER_LOC),GET_ARR(env,jrv0,CENTER_LOC),GET_ARR(env,jrw0,CENTER_LOC),dt);
|
advect(chunk_mask,N,2,jrv,jrv0,GET_ARR_RAW(env,jru0,CENTER_LOC),GET_ARR_RAW(env,jrv0,CENTER_LOC),GET_ARR_RAW(env,jrw0,CENTER_LOC),dt);
|
||||||
advect(env,chunk_mask,N,2,jrv,jrv0,GET_ARR(env,jru0,CENTER_LOC),GET_ARR(env,jrv0,CENTER_LOC),GET_ARR(env,jrw0,CENTER_LOC),dt);
|
advect(chunk_mask,N,3,jrw,jrw0,GET_ARR_RAW(env,jru0,CENTER_LOC),GET_ARR_RAW(env,jrv0,CENTER_LOC),GET_ARR_RAW(env,jrw0,CENTER_LOC),dt);
|
||||||
advect(env,chunk_mask,N,3,jrw,jrw0,GET_ARR(env,jru0,CENTER_LOC),GET_ARR(env,jrv0,CENTER_LOC),GET_ARR(env,jrw0,CENTER_LOC),dt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void advect(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, jobjectArray jrd0, float * u, float * v, float * w, float dt){
|
void advect(uint32_t chunk_mask, int N, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt){
|
||||||
int i, j, k, i0, j0, k0, i1, j1, k1;
|
int i, j, k, i0, j0, k0, i1, j1, k1;
|
||||||
int m,n,o;
|
int m,n,o;
|
||||||
float x, y, z, s0, t0, s1, t1, u1, u0, dtx,dty,dtz;
|
float x, y, z, s0, t0, s1, t1, u1, u0, dtx,dty,dtz;
|
||||||
|
|
||||||
dtx=dty=dtz=dt*N;
|
dtx=dty=dtz=dt*N;
|
||||||
|
|
||||||
float * d = GET_ARR(env,jrd,CENTER_LOC);
|
float * d = GET_ARR_RAW(env,jrd,CENTER_LOC);
|
||||||
|
|
||||||
float * d0 = GET_ARR(env,jrd0,CENTER_LOC);
|
float * d0 = GET_ARR_RAW(env,jrd0,CENTER_LOC);
|
||||||
|
|
||||||
for(k=1; k<N-1; k++){
|
for(k=1; k<N-1; k++){
|
||||||
for(j=1; j<N-1; j++){
|
for(j=1; j<N-1; j++){
|
||||||
for(i=1; i<N-1; i++){
|
for(i=1; i<N-1; i++){
|
||||||
d0 = GET_ARR(env,jrd0,CENTER_LOC);
|
d0 = GET_ARR_RAW(env,jrd0,CENTER_LOC);
|
||||||
//calculate location to pull from
|
//calculate location to pull from
|
||||||
x = i-dtx*u[IX(i,j,k)];
|
x = i-dtx*u[IX(i,j,k)];
|
||||||
y = j-dty*v[IX(i,j,k)];
|
y = j-dty*v[IX(i,j,k)];
|
||||||
@ -507,7 +499,7 @@ void advect(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, j
|
|||||||
|
|
||||||
|
|
||||||
// printf("Hit other chunk\n");
|
// printf("Hit other chunk\n");
|
||||||
d0 = GET_ARR(env,jrd0,CK(m,n,o));
|
d0 = GET_ARR_RAW(env,jrd0,CK(m,n,o));
|
||||||
x = x + CHUNK_NORMALIZE_U[CK(m,n,o)] * (N-2);
|
x = x + CHUNK_NORMALIZE_U[CK(m,n,o)] * (N-2);
|
||||||
// printf("%d => %f\n",m,x);
|
// printf("%d => %f\n",m,x);
|
||||||
y = y + CHUNK_NORMALIZE_V[CK(m,n,o)] * (N-2);
|
y = y + CHUNK_NORMALIZE_V[CK(m,n,o)] * (N-2);
|
||||||
@ -669,15 +661,14 @@ void advect(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, j
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setBoundsToNeighbors
|
void setBoundsToNeighborsRaw
|
||||||
(JNIEnv * env,
|
(
|
||||||
jobject this,
|
int N,
|
||||||
jint N,
|
int chunk_mask,
|
||||||
jint chunk_mask,
|
int vector_dir,
|
||||||
jint vector_dir,
|
float ** neighborArray){
|
||||||
jobjectArray neighborArray){
|
|
||||||
int DIM = N;
|
int DIM = N;
|
||||||
float * target = GET_ARR(env,neighborArray,CENTER_LOC);
|
float * target = GET_ARR_RAW(env,neighborArray,CENTER_LOC);
|
||||||
float * source;
|
float * source;
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
for(int y = 1; y < DIM-1; y++){
|
for(int y = 1; y < DIM-1; y++){
|
||||||
@ -726,19 +717,19 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setBoundsToNeighbors
|
|||||||
target[IX(DIM-1,DIM-1,DIM-1)] = (float)((target[IX(DIM-1,DIM-1,DIM-2)]+target[IX(DIM-1,DIM-2,DIM-1)]+target[IX(DIM-1,DIM-1,DIM-2)])/3.0);
|
target[IX(DIM-1,DIM-1,DIM-1)] = (float)((target[IX(DIM-1,DIM-1,DIM-2)]+target[IX(DIM-1,DIM-2,DIM-1)]+target[IX(DIM-1,DIM-1,DIM-2)])/3.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This exclusively copies neighbors to make sure zeroing out stuff doesn't break sim
|
* This exclusively copies neighbors to make sure zeroing out stuff doesn't break sim
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
void copyNeighborsRaw
|
||||||
(JNIEnv * env,
|
(
|
||||||
jobject this,
|
int N,
|
||||||
jint N,
|
int chunk_mask,
|
||||||
jint chunk_mask,
|
int cx,
|
||||||
jint cx,
|
int vector_dir,
|
||||||
jint vector_dir,
|
float ** neighborArray){
|
||||||
jobjectArray neighborArray){
|
|
||||||
int DIM = N;
|
int DIM = N;
|
||||||
float * target = GET_ARR(env,neighborArray,CENTER_LOC);
|
float * target = GET_ARR_RAW(env,neighborArray,CENTER_LOC);
|
||||||
float * source;
|
float * source;
|
||||||
|
|
||||||
|
|
||||||
@ -747,9 +738,20 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
// PLANES
|
// PLANES
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
// __m512 transferVector;// = _mm512_set1_ps(0.5*N);
|
||||||
|
|
||||||
|
//__m256 vector = _mm256_loadu_ps(&p[IX(i-1,j,k)]);
|
||||||
|
//vector = _mm256_add_ps(vector,_mm256_loadu_ps(&p[IX(i+1,j,k)]));
|
||||||
|
//vector = _mm256_add_ps(vector,_mm256_loadu_ps(&p[IX(i,j-1,k)]));
|
||||||
|
//_mm256_storeu_ps(&p[IX(i,j,k)],vector);
|
||||||
|
//__m256
|
||||||
|
//_mm256_loadu_ps
|
||||||
|
//_mm256_storeu_ps
|
||||||
if(ARR_EXISTS(chunk_mask,0,1,1)){
|
if(ARR_EXISTS(chunk_mask,0,1,1)){
|
||||||
source = GET_ARR(env,neighborArray,CK(0,1,1));
|
source = GET_ARR_RAW(env,neighborArray,CK(0,1,1));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
|
// transferVector = _mm512_loadu_ps(&source[IX(DIM-2,x,1)]);
|
||||||
|
// _mm512_storeu_ps(&target[IX(0,x,1)],_mm512_loadu_ps(&source[IX(DIM-2,x,1)]));
|
||||||
for(int y = 1; y < DIM-1; y++){
|
for(int y = 1; y < DIM-1; y++){
|
||||||
target[IX(0,x,y)] = source[IX(DIM-2,x,y)];
|
target[IX(0,x,y)] = source[IX(DIM-2,x,y)];
|
||||||
}
|
}
|
||||||
@ -757,8 +759,9 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,2,1,1)){
|
if(ARR_EXISTS(chunk_mask,2,1,1)){
|
||||||
source = GET_ARR(env,neighborArray,CK(2,1,1));
|
source = GET_ARR_RAW(env,neighborArray,CK(2,1,1));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
|
// _mm512_storeu_ps(&target[IX(DIM-1,x,1)],_mm512_loadu_ps(&source[IX(1,x,1)]));
|
||||||
for(int y = 1; y < DIM-1; y++){
|
for(int y = 1; y < DIM-1; y++){
|
||||||
target[IX(DIM-1,x,y)] = source[IX(1,x,y)];
|
target[IX(DIM-1,x,y)] = source[IX(1,x,y)];
|
||||||
}
|
}
|
||||||
@ -766,7 +769,7 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,1,0,1)){
|
if(ARR_EXISTS(chunk_mask,1,0,1)){
|
||||||
source = GET_ARR(env,neighborArray,CK(1,0,1));
|
source = GET_ARR_RAW(env,neighborArray,CK(1,0,1));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
for(int y = 1; y < DIM-1; y++){
|
for(int y = 1; y < DIM-1; y++){
|
||||||
target[IX(x,0,y)] = source[IX(x,DIM-2,y)];
|
target[IX(x,0,y)] = source[IX(x,DIM-2,y)];
|
||||||
@ -775,7 +778,7 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,1,2,1)){
|
if(ARR_EXISTS(chunk_mask,1,2,1)){
|
||||||
source = GET_ARR(env,neighborArray,CK(1,2,1));
|
source = GET_ARR_RAW(env,neighborArray,CK(1,2,1));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
for(int y = 1; y < DIM-1; y++){
|
for(int y = 1; y < DIM-1; y++){
|
||||||
target[IX(x,DIM-1,y)] = source[IX(x,1,y)];
|
target[IX(x,DIM-1,y)] = source[IX(x,1,y)];
|
||||||
@ -784,7 +787,7 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,1,1,0)){
|
if(ARR_EXISTS(chunk_mask,1,1,0)){
|
||||||
source = GET_ARR(env,neighborArray,CK(1,1,0));
|
source = GET_ARR_RAW(env,neighborArray,CK(1,1,0));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
for(int y = 1; y < DIM-1; y++){
|
for(int y = 1; y < DIM-1; y++){
|
||||||
target[IX(x,y,0)] = source[IX(x,y,DIM-2)];
|
target[IX(x,y,0)] = source[IX(x,y,DIM-2)];
|
||||||
@ -793,7 +796,7 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,1,1,2)){
|
if(ARR_EXISTS(chunk_mask,1,1,2)){
|
||||||
source = GET_ARR(env,neighborArray,CK(1,1,2));
|
source = GET_ARR_RAW(env,neighborArray,CK(1,1,2));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
for(int y = 1; y < DIM-1; y++){
|
for(int y = 1; y < DIM-1; y++){
|
||||||
target[IX(x,y,DIM-1)] = source[IX(x,y,1)];
|
target[IX(x,y,DIM-1)] = source[IX(x,y,1)];
|
||||||
@ -808,28 +811,28 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
if(ARR_EXISTS(chunk_mask,0,0,1)){
|
if(ARR_EXISTS(chunk_mask,0,0,1)){
|
||||||
source = GET_ARR(env,neighborArray,CK(0,0,1));
|
source = GET_ARR_RAW(env,neighborArray,CK(0,0,1));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(0,0,x)] = source[IX(DIM-2,DIM-2,x)];
|
target[IX(0,0,x)] = source[IX(DIM-2,DIM-2,x)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,2,0,1)){
|
if(ARR_EXISTS(chunk_mask,2,0,1)){
|
||||||
source = GET_ARR(env,neighborArray,CK(2,0,1));
|
source = GET_ARR_RAW(env,neighborArray,CK(2,0,1));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(DIM-1,0,x)] = source[IX(1,DIM-2,x)];
|
target[IX(DIM-1,0,x)] = source[IX(1,DIM-2,x)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,0,2,1)){
|
if(ARR_EXISTS(chunk_mask,0,2,1)){
|
||||||
source = GET_ARR(env,neighborArray,CK(0,2,1));
|
source = GET_ARR_RAW(env,neighborArray,CK(0,2,1));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(0,DIM-1,x)] = source[IX(DIM-2,1,x)];
|
target[IX(0,DIM-1,x)] = source[IX(DIM-2,1,x)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,2,2,1)){
|
if(ARR_EXISTS(chunk_mask,2,2,1)){
|
||||||
source = GET_ARR(env,neighborArray,CK(2,2,1));
|
source = GET_ARR_RAW(env,neighborArray,CK(2,2,1));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(DIM-1,DIM-1,x)] = source[IX(1,1,x)];
|
target[IX(DIM-1,DIM-1,x)] = source[IX(1,1,x)];
|
||||||
}
|
}
|
||||||
@ -839,28 +842,28 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
//
|
//
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,0,1,0)){
|
if(ARR_EXISTS(chunk_mask,0,1,0)){
|
||||||
source = GET_ARR(env,neighborArray,CK(0,1,0));
|
source = GET_ARR_RAW(env,neighborArray,CK(0,1,0));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(0,x,0)] = source[IX(DIM-2,x,DIM-2)];
|
target[IX(0,x,0)] = source[IX(DIM-2,x,DIM-2)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,2,1,0)){
|
if(ARR_EXISTS(chunk_mask,2,1,0)){
|
||||||
source = GET_ARR(env,neighborArray,CK(2,1,0));
|
source = GET_ARR_RAW(env,neighborArray,CK(2,1,0));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(DIM-1,x,0)] = source[IX(1,x,DIM-2)];
|
target[IX(DIM-1,x,0)] = source[IX(1,x,DIM-2)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,0,1,2)){
|
if(ARR_EXISTS(chunk_mask,0,1,2)){
|
||||||
source = GET_ARR(env,neighborArray,CK(0,1,2));
|
source = GET_ARR_RAW(env,neighborArray,CK(0,1,2));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(0,x,DIM-1)] = source[IX(DIM-2,x,1)];
|
target[IX(0,x,DIM-1)] = source[IX(DIM-2,x,1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,2,1,2)){
|
if(ARR_EXISTS(chunk_mask,2,1,2)){
|
||||||
source = GET_ARR(env,neighborArray,CK(2,1,2));
|
source = GET_ARR_RAW(env,neighborArray,CK(2,1,2));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(DIM-1,x,DIM-1)] = source[IX(1,x,1)];
|
target[IX(DIM-1,x,DIM-1)] = source[IX(1,x,1)];
|
||||||
}
|
}
|
||||||
@ -870,28 +873,28 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
//
|
//
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,1,0,0)){
|
if(ARR_EXISTS(chunk_mask,1,0,0)){
|
||||||
source = GET_ARR(env,neighborArray,CK(1,0,0));
|
source = GET_ARR_RAW(env,neighborArray,CK(1,0,0));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(x,0,0)] = source[IX(x,DIM-2,DIM-2)];
|
target[IX(x,0,0)] = source[IX(x,DIM-2,DIM-2)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,1,2,0)){
|
if(ARR_EXISTS(chunk_mask,1,2,0)){
|
||||||
source = GET_ARR(env,neighborArray,CK(1,2,0));
|
source = GET_ARR_RAW(env,neighborArray,CK(1,2,0));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(x,DIM-1,0)] = source[IX(x,1,DIM-2)];
|
target[IX(x,DIM-1,0)] = source[IX(x,1,DIM-2)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,1,0,2)){
|
if(ARR_EXISTS(chunk_mask,1,0,2)){
|
||||||
source = GET_ARR(env,neighborArray,CK(1,0,2));
|
source = GET_ARR_RAW(env,neighborArray,CK(1,0,2));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(x,0,DIM-1)] = source[IX(x,DIM-2,1)];
|
target[IX(x,0,DIM-1)] = source[IX(x,DIM-2,1)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,1,2,2)){
|
if(ARR_EXISTS(chunk_mask,1,2,2)){
|
||||||
source = GET_ARR(env,neighborArray,CK(1,2,2));
|
source = GET_ARR_RAW(env,neighborArray,CK(1,2,2));
|
||||||
for(int x=1; x < DIM-1; x++){
|
for(int x=1; x < DIM-1; x++){
|
||||||
target[IX(x,DIM-1,DIM-1)] = source[IX(x,1,1)];
|
target[IX(x,DIM-1,DIM-1)] = source[IX(x,1,1)];
|
||||||
}
|
}
|
||||||
@ -905,22 +908,22 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
//
|
//
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,0,0,0)){
|
if(ARR_EXISTS(chunk_mask,0,0,0)){
|
||||||
source = GET_ARR(env,neighborArray,CK(0,0,0));
|
source = GET_ARR_RAW(env,neighborArray,CK(0,0,0));
|
||||||
target[IX(0,0,0)] = source[IX(DIM-2,DIM-2,DIM-2)];
|
target[IX(0,0,0)] = source[IX(DIM-2,DIM-2,DIM-2)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,2,0,0)){
|
if(ARR_EXISTS(chunk_mask,2,0,0)){
|
||||||
source = GET_ARR(env,neighborArray,CK(2,0,0));
|
source = GET_ARR_RAW(env,neighborArray,CK(2,0,0));
|
||||||
target[IX(DIM-1,0,0)] = source[IX(1,DIM-2,DIM-2)];
|
target[IX(DIM-1,0,0)] = source[IX(1,DIM-2,DIM-2)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,0,2,0)){
|
if(ARR_EXISTS(chunk_mask,0,2,0)){
|
||||||
source = GET_ARR(env,neighborArray,CK(0,2,0));
|
source = GET_ARR_RAW(env,neighborArray,CK(0,2,0));
|
||||||
target[IX(0,DIM-1,0)] = source[IX(DIM-2,1,DIM-2)];
|
target[IX(0,DIM-1,0)] = source[IX(DIM-2,1,DIM-2)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,2,2,0)){
|
if(ARR_EXISTS(chunk_mask,2,2,0)){
|
||||||
source = GET_ARR(env,neighborArray,CK(2,2,0));
|
source = GET_ARR_RAW(env,neighborArray,CK(2,2,0));
|
||||||
target[IX(DIM-1,DIM-1,0)] = source[IX(1,1,DIM-2)];
|
target[IX(DIM-1,DIM-1,0)] = source[IX(1,1,DIM-2)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -928,25 +931,25 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
//
|
//
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,0,0,2)){
|
if(ARR_EXISTS(chunk_mask,0,0,2)){
|
||||||
source = GET_ARR(env,neighborArray,CK(0,0,2));
|
source = GET_ARR_RAW(env,neighborArray,CK(0,0,2));
|
||||||
target[IX(0,0,DIM-1)] = source[IX(DIM-2,DIM-2,1)];
|
target[IX(0,0,DIM-1)] = source[IX(DIM-2,DIM-2,1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,2,0,2)){
|
if(ARR_EXISTS(chunk_mask,2,0,2)){
|
||||||
source = GET_ARR(env,neighborArray,CK(2,0,2));
|
source = GET_ARR_RAW(env,neighborArray,CK(2,0,2));
|
||||||
target[IX(DIM-1,0,DIM-1)] = source[IX(1,DIM-2,1)];
|
target[IX(DIM-1,0,DIM-1)] = source[IX(1,DIM-2,1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,0,2,2)){
|
if(ARR_EXISTS(chunk_mask,0,2,2)){
|
||||||
source = GET_ARR(env,neighborArray,CK(0,2,2));
|
source = GET_ARR_RAW(env,neighborArray,CK(0,2,2));
|
||||||
target[IX(0,DIM-1,DIM-1)] = source[IX(DIM-2,1,1)];
|
target[IX(0,DIM-1,DIM-1)] = source[IX(DIM-2,1,1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ARR_EXISTS(chunk_mask,2,2,2)){
|
if(ARR_EXISTS(chunk_mask,2,2,2)){
|
||||||
source = GET_ARR(env,neighborArray,CK(2,2,2));
|
source = GET_ARR_RAW(env,neighborArray,CK(2,2,2));
|
||||||
target[IX(DIM-1,DIM-1,DIM-1)] = source[IX(1,1,1)];
|
target[IX(DIM-1,DIM-1,DIM-1)] = source[IX(1,1,1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -15,6 +15,7 @@ import org.joml.Vector2i;
|
|||||||
import org.joml.Vector3i;
|
import org.joml.Vector3i;
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
import org.lwjgl.PointerBuffer;
|
import org.lwjgl.PointerBuffer;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,21 +41,21 @@ public class FluidSim {
|
|||||||
// +-------------+ (2,0,0) +---------------> X
|
// +-------------+ (2,0,0) +---------------> X
|
||||||
|
|
||||||
//Buffers that contain density for current frame
|
//Buffers that contain density for current frame
|
||||||
ByteBuffer[] density = new ByteBuffer[27];
|
public ByteBuffer[] density = new ByteBuffer[27];
|
||||||
//Buffers that contain new density to add to the simulation
|
//Buffers that contain new density to add to the simulation
|
||||||
ByteBuffer[] densityAddition = new ByteBuffer[27];
|
public ByteBuffer[] densityAddition = new ByteBuffer[27];
|
||||||
//Buffers that contain u vector directions
|
//Buffers that contain u vector directions
|
||||||
ByteBuffer[] uVector = new ByteBuffer[27];
|
public ByteBuffer[] uVector = new ByteBuffer[27];
|
||||||
//Buffers that contain v vector directions
|
//Buffers that contain v vector directions
|
||||||
ByteBuffer[] vVector = new ByteBuffer[27];
|
public ByteBuffer[] vVector = new ByteBuffer[27];
|
||||||
//Buffers that contain w vector directions
|
//Buffers that contain w vector directions
|
||||||
ByteBuffer[] wVector = new ByteBuffer[27];
|
public ByteBuffer[] wVector = new ByteBuffer[27];
|
||||||
//Buffers that contain u vector directions to add to the simulation
|
//Buffers that contain u vector directions to add to the simulation
|
||||||
ByteBuffer[] uAdditionVector = new ByteBuffer[27];
|
public ByteBuffer[] uAdditionVector = new ByteBuffer[27];
|
||||||
//Buffers that contain v vector directions to add to the simulation
|
//Buffers that contain v vector directions to add to the simulation
|
||||||
ByteBuffer[] vAdditionVector = new ByteBuffer[27];
|
public ByteBuffer[] vAdditionVector = new ByteBuffer[27];
|
||||||
//Buffers that contain w vector directions to add to the simulation
|
//Buffers that contain w vector directions to add to the simulation
|
||||||
ByteBuffer[] wAdditionVector = new ByteBuffer[27];
|
public ByteBuffer[] wAdditionVector = new ByteBuffer[27];
|
||||||
|
|
||||||
//The densities for every voxel for the current frame
|
//The densities for every voxel for the current frame
|
||||||
float[] densityArrayView = new float[DIM * DIM * DIM];
|
float[] densityArrayView = new float[DIM * DIM * DIM];
|
||||||
@ -69,9 +70,7 @@ public class FluidSim {
|
|||||||
public float[] v0ArrayView = new float[DIM * DIM * DIM];
|
public float[] v0ArrayView = new float[DIM * DIM * DIM];
|
||||||
float[] w0ArrayView = new float[DIM * DIM * DIM];
|
float[] w0ArrayView = new float[DIM * DIM * DIM];
|
||||||
|
|
||||||
int chunkMask = 0;
|
public int chunkMask = 0;
|
||||||
|
|
||||||
public static long threadpool;
|
|
||||||
|
|
||||||
|
|
||||||
static final float DIFFUSION_CONSTANT = 0.0f;
|
static final float DIFFUSION_CONSTANT = 0.0f;
|
||||||
@ -79,8 +78,7 @@ public class FluidSim {
|
|||||||
|
|
||||||
static final int LINEARSOLVERTIMES = 20;
|
static final int LINEARSOLVERTIMES = 20;
|
||||||
|
|
||||||
static final float GRAVITY = 0.0f;
|
static final float GRAVITY = -100f;
|
||||||
// static final float GRAVITY = -100f; //<-- original value
|
|
||||||
|
|
||||||
public void setup(Vector3i offset){
|
public void setup(Vector3i offset){
|
||||||
//allocate buffers for this chunk
|
//allocate buffers for this chunk
|
||||||
@ -157,8 +155,12 @@ public class FluidSim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static LinkedList<FluidSim> simArrayList = new LinkedList<FluidSim>();
|
static int i = 0;
|
||||||
|
static double time = 0;
|
||||||
|
static double lastTime = 0;
|
||||||
public static void simChunks(FluidSim[][][] simArray, int step, float timestep){
|
public static void simChunks(FluidSim[][][] simArray, int step, float timestep){
|
||||||
|
|
||||||
|
List<FluidSim> chunksToSim = new LinkedList<FluidSim>();
|
||||||
//
|
//
|
||||||
//init data for upcoming frame
|
//init data for upcoming frame
|
||||||
for(int x = 0; x < simArray.length; x++){
|
for(int x = 0; x < simArray.length; x++){
|
||||||
@ -173,44 +175,25 @@ public class FluidSim {
|
|||||||
//
|
//
|
||||||
simArray[x][y][z].writeNewStateIntoBuffers();
|
simArray[x][y][z].writeNewStateIntoBuffers();
|
||||||
//
|
//
|
||||||
//flag this chunk as being simulated in the upcoming frame
|
// add to queue
|
||||||
simArrayList.add(simArray[x][y][z]);
|
//
|
||||||
|
chunksToSim.add(simArray[x][y][z]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//for each chunk, send them to C land
|
lastTime = GLFW.glfwGetTime();
|
||||||
for(FluidSim chunk : simArrayList){
|
//
|
||||||
queueChunkWrapper(threadpool, chunk, timestep);
|
//simulate
|
||||||
|
simulateWrapper(chunksToSim,timestep);
|
||||||
|
//clock
|
||||||
|
time = time + (GLFW.glfwGetTime() - lastTime);
|
||||||
|
i++;
|
||||||
|
if(i == 100){
|
||||||
|
System.out.println(time / 100.0 * 1000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//call for work to be done
|
|
||||||
submitWorkWrapper(threadpool);
|
|
||||||
|
|
||||||
// //
|
|
||||||
// //Vector stage
|
|
||||||
// solveChunkMask(simArray);
|
|
||||||
// addVectorSources(simArray, timestep);
|
|
||||||
// swapAllVectorFields(simArray, timestep);
|
|
||||||
// solveVectorDiffusion(simArray, timestep);
|
|
||||||
// solveProjection(simArray, step, timestep);
|
|
||||||
// swapAllVectorFields(simArray, timestep);
|
|
||||||
// advectVectorsAcrossBoundaries(simArray, timestep);
|
|
||||||
// solveProjection(simArray, step, timestep);
|
|
||||||
|
|
||||||
// //
|
|
||||||
// //Density stage
|
|
||||||
// addDensity(simArray, timestep);
|
|
||||||
// swapAllDensityArrays(simArray, timestep);
|
|
||||||
// diffuseDensity(simArray, timestep);
|
|
||||||
// swapAllDensityArrays(simArray, timestep);
|
|
||||||
// advectDensity(simArray, timestep);
|
|
||||||
// // mirrorNeighborDensities(simArray, timestep);
|
|
||||||
|
|
||||||
//call for work to be done
|
|
||||||
fetchWorkWrapper(threadpool);
|
|
||||||
|
|
||||||
simArrayList.clear();
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -351,620 +334,16 @@ public class FluidSim {
|
|||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private static void solveChunkMask(FluidSim[][][] simArray){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].calculateChunkMaskWrapper();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void addVectorSources(FluidSim[][][] simArray, float timestep){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
|
|
||||||
// //Add source to all 3 vectors
|
|
||||||
// // add_source(N, u, u0, dt);
|
|
||||||
// // add_source(N, v, v0, dt);
|
|
||||||
// // add_source(N, w, w0, dt);
|
|
||||||
// simArray[x][y][z].addSourceToVectorsWrapper(timestep);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //swap
|
|
||||||
// //u <=> u0 etc for u, v, and w
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void solveVectorDiffusion(FluidSim[][][] simArray, float timestep){
|
|
||||||
// //samples u,v,w,u0,v0,w0
|
|
||||||
// //sets u,v,w
|
|
||||||
// // for(int x = 0; x < simArray.length; x++){
|
|
||||||
// // for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// // for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// // simArray[x][y][z].copyNeighborsWrapper(1, simArray[x][y][z].uVector);
|
|
||||||
// // simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].vVector);
|
|
||||||
// // simArray[x][y][z].copyNeighborsWrapper(3, simArray[x][y][z].wVector);
|
|
||||||
// // simArray[x][y][z].copyNeighborsWrapper(1, simArray[x][y][z].uAdditionVector);
|
|
||||||
// // simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].vAdditionVector);
|
|
||||||
// // simArray[x][y][z].copyNeighborsWrapper(3, simArray[x][y][z].wAdditionVector);
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// //lin_solve(env, chunk_mask, N, b, x, x0, a, 1+6*a);
|
|
||||||
// //+
|
|
||||||
// //set_bnd(env, chunk_mask, N, b, x);
|
|
||||||
// //for u, v, and w all in 1 shot
|
|
||||||
// simArray[x][y][z].solveVectorDiffuseWrapper(timestep);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(3, x, simArray[x][y][z].wVector);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void solveProjection(FluidSim[][][] simArray, int step, float timestep){
|
|
||||||
// //samples u,v,w
|
|
||||||
// //sets u0,v0
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(3, x, simArray[x][y][z].wVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vAdditionVector);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// // System.out.println("Setup " + x + " " + y + " " + z);
|
|
||||||
// //setup projection across boundaries
|
|
||||||
// //...
|
|
||||||
// //set boundaries appropriately
|
|
||||||
// //...
|
|
||||||
// simArray[x][y][z].setupProjectionWrapper(timestep);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(0, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(0, simArray[x][y][z].vAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].vAdditionVector);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //samples u0, v0
|
|
||||||
// //sets u0
|
|
||||||
// //these should have just been mirrored in the above
|
|
||||||
// //
|
|
||||||
// //Perform main projection solver
|
|
||||||
// for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// //lin_solve(env, chunk_mask, N, b, x, x0, a, 1+6*a);
|
|
||||||
// //for u, v, and w all in 1 shot
|
|
||||||
// simArray[x][y][z].solveProjectionWrapper(timestep);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //be sure to set boundaries to neighbor chunk values where appropriate
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(0, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].uAdditionVector);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //samples u,v,w,u0
|
|
||||||
// //sets u,v,w
|
|
||||||
// //Finalize projection
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// //Subtract curl field from current vector field
|
|
||||||
// //...
|
|
||||||
// simArray[x][y][z].finalizeProjectionWrapper(timestep);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //set boundaries a final time for u,v,w
|
|
||||||
// //...
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(3, x, simArray[x][y][z].wVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vAdditionVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].vAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].wAdditionVector);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void mirrorNeighborDensities(FluidSim[][][] simArray, float timestep){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(0, simArray[x][y][z].density);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void swapAllVectorFields(FluidSim[][][] simArray, float timestep){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].swapVectorFields();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //then need to mirror each array as relevant
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(3, x, simArray[x][y][z].wVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].wAdditionVector);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private void swapVectorFields(){
|
|
||||||
// ByteBuffer tmp;
|
|
||||||
// //swap x0 <-> x
|
|
||||||
// // tmp = densityAddition;
|
|
||||||
// // densityAddition = density[13];
|
|
||||||
// // density[13] = tmp;
|
|
||||||
// //swap u0 <-> u
|
|
||||||
// for(int i = 0; i < 27; i++){
|
|
||||||
// tmp = uAdditionVector[i];
|
|
||||||
// uAdditionVector[i] = uVector[i];
|
|
||||||
// uVector[i] = tmp;
|
|
||||||
// //swap v0 <-> v
|
|
||||||
// tmp = vAdditionVector[i];
|
|
||||||
// vAdditionVector[i] = vVector[i];
|
|
||||||
// vVector[i] = tmp;
|
|
||||||
// //swap w0 <-> w
|
|
||||||
// tmp = wAdditionVector[i];
|
|
||||||
// wAdditionVector[i] = wVector[i];
|
|
||||||
// wVector[i] = tmp;
|
|
||||||
// }
|
|
||||||
// //...
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void advectVectorsAcrossBoundaries(FluidSim[][][] simArray, float timestep){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vAdditionVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(3, x, simArray[x][y][z].wVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vAdditionVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(3, x, simArray[x][y][z].wAdditionVector);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //samples u,v,w,u0,v0,w0
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// // advect(env, chunk_mask, N, 1, jru, u0, u0, v0, w0, dt);
|
|
||||||
// // advect(env, chunk_mask, N, 2, jrv, v0, u0, v0, w0, dt);
|
|
||||||
// // advect(env, chunk_mask, N, 3, jrw, w0, u0, v0, w0, dt);
|
|
||||||
// //...
|
|
||||||
// simArray[x][y][z].advectVectorsWrapper(timestep);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //mirror neighbor data
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vVector);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(3, x, simArray[x][y][z].wVector);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void addDensity(FluidSim[][][] simArray, float timestep){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// //add_source(N, x, x0, dt);
|
|
||||||
// simArray[x][y][z].addDensityWrapper(timestep);
|
|
||||||
// //swap x <=> x0
|
|
||||||
// //swap arrays in java side...
|
|
||||||
// // simArray[x][y][z].swapDensityArrays();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void swapAllDensityArrays(FluidSim[][][] simArray, float timestep){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].swapDensityArrays();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].density);
|
|
||||||
// simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].densityAddition);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private void swapDensityArrays(){
|
|
||||||
// for(int i = 0; i < 27; i++){
|
|
||||||
// ByteBuffer tmp = density[i];
|
|
||||||
// density[i] = densityAddition[i];
|
|
||||||
// densityAddition[i] = tmp;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void diffuseDensity(FluidSim[][][] simArray, float timestep){
|
|
||||||
// for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// //lin_solve(env, chunk_mask, N, b, x, x0, a, 1+6*a);
|
|
||||||
// //+
|
|
||||||
// //set_bnd(env, chunk_mask, N, b, x);
|
|
||||||
// simArray[x][y][z].solveDiffuseDensityWrapper(timestep);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(0, simArray[x][y][z].density);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void advectDensity(FluidSim[][][] simArray, float timestep){
|
|
||||||
// for(int x = 0; x < simArray.length; x++){
|
|
||||||
// for(int y = 0; y < simArray[0].length; y++){
|
|
||||||
// for(int z = 0; z < simArray[0][0].length; z++){
|
|
||||||
// //swap x <=> x0 again
|
|
||||||
// // simArray[x][y][z].swapDensityArrays();
|
|
||||||
// //advect density
|
|
||||||
// simArray[x][y][z].advectDensityWrapper(timestep);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OLD NATIVE DECLARATIONS
|
* Main simulation function
|
||||||
|
* @param timestep
|
||||||
*/
|
*/
|
||||||
|
private static void simulateWrapper(List<FluidSim> chunks, float timestep){
|
||||||
|
simulate(chunks,timestep);
|
||||||
|
|
||||||
// /**
|
|
||||||
// * The native function call to simulate a frame of fluid
|
|
||||||
// * @param DIM_X
|
|
||||||
// * @param DIM_Y
|
|
||||||
// * @param DIM_Z
|
|
||||||
// * @param x
|
|
||||||
// * @param x0
|
|
||||||
// * @param u
|
|
||||||
// * @param v
|
|
||||||
// * @param w
|
|
||||||
// * @param u0
|
|
||||||
// * @param v0
|
|
||||||
// * @param w0
|
|
||||||
// * @param DIFFUSION_CONSTANT
|
|
||||||
// * @param VISCOSITY_CONSTANT
|
|
||||||
// * @param timestep
|
|
||||||
// */
|
|
||||||
// private native void simulate(
|
|
||||||
// int DIM_X,
|
|
||||||
// int chunkMask,
|
|
||||||
// ByteBuffer[] x,
|
|
||||||
// ByteBuffer x0,
|
|
||||||
// ByteBuffer[] u,
|
|
||||||
// ByteBuffer[] v,
|
|
||||||
// ByteBuffer[] w,
|
|
||||||
// ByteBuffer[] u0,
|
|
||||||
// ByteBuffer[] v0,
|
|
||||||
// ByteBuffer[] w0,
|
|
||||||
// float DIFFUSION_CONSTANT,
|
|
||||||
// float VISCOSITY_CONSTANT,
|
|
||||||
// float timestep
|
|
||||||
// );
|
|
||||||
|
|
||||||
// private void calculateChunkMaskWrapper(){
|
|
||||||
// this.chunkMask = this.calculateChunkMask(density);
|
|
||||||
// }
|
|
||||||
// /**
|
|
||||||
// * Calculates the mask of chunk neighbors
|
|
||||||
// * @param densityBuffers The neighbor array
|
|
||||||
// * @return The mask
|
|
||||||
// */
|
|
||||||
// private native int calculateChunkMask(ByteBuffer[] densityBuffers);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Add vector values to u, v, and w all at once
|
|
||||||
// */
|
|
||||||
// private void addSourceToVectorsWrapper(float timestep){
|
|
||||||
// addSourceToVectors(DIM, chunkMask, uVector, vVector, wVector, uAdditionVector, vAdditionVector, wAdditionVector, DIFFUSION_CONSTANT, VISCOSITY_CONSTANT, timestep);
|
|
||||||
// }
|
|
||||||
// private native void addSourceToVectors(int DIM_X, int chunkMask, ByteBuffer[] u, ByteBuffer v[], ByteBuffer w[], ByteBuffer u0[], ByteBuffer v0[], ByteBuffer w0[], float DIFFUSION_CONSTANT, float VISCOSITY_CONSTANT, float timestep);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Solves u, v, and w diffusion systems of equations
|
|
||||||
// */
|
|
||||||
// private void solveVectorDiffuseWrapper(float timestep){
|
|
||||||
// solveVectorDiffuse(DIM, chunkMask, uVector, vVector, wVector, uAdditionVector, vAdditionVector, wAdditionVector, DIFFUSION_CONSTANT, VISCOSITY_CONSTANT, timestep);
|
|
||||||
// }
|
|
||||||
// private native void solveVectorDiffuse(int DIM_X, int chunkMask, ByteBuffer[] u, ByteBuffer v[], ByteBuffer w[], ByteBuffer u0[], ByteBuffer v0[], ByteBuffer w0[], float DIFFUSION_CONSTANT, float VISCOSITY_CONSTANT, float timestep);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Setup projection system
|
|
||||||
// */
|
|
||||||
// private void setupProjectionWrapper(float timestep){
|
|
||||||
// setupProjection(DIM, chunkMask, uVector, vVector, wVector, uAdditionVector, vAdditionVector, wAdditionVector, DIFFUSION_CONSTANT, VISCOSITY_CONSTANT, timestep);
|
|
||||||
// }
|
|
||||||
// private native void setupProjection(int DIM_X, int chunkMask, ByteBuffer[] u, ByteBuffer v[], ByteBuffer w[], ByteBuffer u0[], ByteBuffer v0[], ByteBuffer w0[], float DIFFUSION_CONSTANT, float VISCOSITY_CONSTANT, float timestep);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Solve projection system
|
|
||||||
// */
|
|
||||||
// private void solveProjectionWrapper(float timestep){
|
|
||||||
// solveProjection(DIM, chunkMask, uVector, vVector, wVector, uAdditionVector, vAdditionVector, wAdditionVector, DIFFUSION_CONSTANT, VISCOSITY_CONSTANT, timestep);
|
|
||||||
// }
|
|
||||||
// private native void solveProjection(int DIM_X, int chunkMask, ByteBuffer[] u, ByteBuffer v[], ByteBuffer w[], ByteBuffer u0[], ByteBuffer v0[], ByteBuffer w0[], float DIFFUSION_CONSTANT, float VISCOSITY_CONSTANT, float timestep);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Does work like subtracting curl from vector field, setting boundaries, etc
|
|
||||||
// */
|
|
||||||
// private void finalizeProjectionWrapper(float timestep){
|
|
||||||
// finalizeProjection(DIM, chunkMask, uVector, vVector, wVector, uAdditionVector, vAdditionVector, wAdditionVector, DIFFUSION_CONSTANT, VISCOSITY_CONSTANT, timestep);
|
|
||||||
// }
|
|
||||||
// private native void finalizeProjection(int DIM_X, int chunkMask, ByteBuffer[] u, ByteBuffer v[], ByteBuffer w[], ByteBuffer u0[], ByteBuffer v0[], ByteBuffer w0[], float DIFFUSION_CONSTANT, float VISCOSITY_CONSTANT, float timestep);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Advects vectors
|
|
||||||
// */
|
|
||||||
// private void advectVectorsWrapper(float timestep){
|
|
||||||
// advectVectors(DIM, chunkMask, uVector, vVector, wVector, uAdditionVector, vAdditionVector, wAdditionVector, DIFFUSION_CONSTANT, VISCOSITY_CONSTANT, timestep);
|
|
||||||
// }
|
|
||||||
// private native void advectVectors(int DIM_X, int chunkMask, ByteBuffer[] u, ByteBuffer v[], ByteBuffer w[], ByteBuffer u0[], ByteBuffer v0[], ByteBuffer w0[], float DIFFUSION_CONSTANT, float VISCOSITY_CONSTANT, float timestep);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Adds density to the simulation
|
|
||||||
// */
|
|
||||||
// private void addDensityWrapper(float timestep){
|
|
||||||
// addDensity(DIM, chunkMask, density, densityAddition, timestep);
|
|
||||||
// }
|
|
||||||
// private native void addDensity(int DIM_X, int chunkMask, ByteBuffer[] x, ByteBuffer[] x0, float timestep);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Solve density diffusion
|
|
||||||
// */
|
|
||||||
// private void solveDiffuseDensityWrapper(float timestep){
|
|
||||||
// solveDiffuseDensity(DIM, chunkMask, density, densityAddition, uVector, vVector, wVector, DIFFUSION_CONSTANT, VISCOSITY_CONSTANT, timestep);
|
|
||||||
// }
|
|
||||||
// private native void solveDiffuseDensity(int DIM_X, int chunkMask, ByteBuffer[] x, ByteBuffer[] x0, ByteBuffer[] u, ByteBuffer v[], ByteBuffer w[], float DIFFUSION_CONSTANT, float VISCOSITY_CONSTANT, float timestep);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Solve density diffusion
|
|
||||||
// */
|
|
||||||
// private void advectDensityWrapper(float timestep){
|
|
||||||
// advectDensity(DIM, chunkMask, density, densityAddition, uVector, vVector, wVector, DIFFUSION_CONSTANT, VISCOSITY_CONSTANT, timestep);
|
|
||||||
// }
|
|
||||||
// private native void advectDensity(int DIM_X, int chunkMask, ByteBuffer[] x, ByteBuffer[] x0, ByteBuffer[] u, ByteBuffer v[], ByteBuffer w[], float DIFFUSION_CONSTANT, float VISCOSITY_CONSTANT, float timestep);
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Sets the bounds of the neighbormap to neighbor values if available
|
|
||||||
// */
|
|
||||||
// private void setBoundsToNeighborsWrapper(int vectorDir, ByteBuffer[] neighborMap){
|
|
||||||
// setBoundsToNeighbors(DIM, chunkMask, vectorDir, neighborMap);
|
|
||||||
// }
|
|
||||||
// private native void setBoundsToNeighbors(int DIM_X, int chunkMask, int vectorDir, ByteBuffer[] neighborMap);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Sets the bounds of the neighbormap to neighbor values if available, otherwise doesn't mess with them.
|
|
||||||
// * This is to make sure zeroing out doesn't mess up the sim
|
|
||||||
// */
|
|
||||||
// private void copyNeighborsWrapper(int vectorDir, int x, ByteBuffer[] neighborMap){
|
|
||||||
// copyNeighbors(DIM, chunkMask, x, vectorDir, neighborMap);
|
|
||||||
// }
|
|
||||||
// private native void copyNeighbors(int DIM_X, int chunkMask, int x, int vectorDir, ByteBuffer[] neighborMap);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the thread pool for handling main work of the c lib
|
|
||||||
*/
|
|
||||||
public static long createThreadpoolWrapper(int numThreads){
|
|
||||||
return createThreadpool(numThreads);
|
|
||||||
}
|
}
|
||||||
private static native long createThreadpool(int numThreads);
|
private static native void simulate(List<FluidSim> chunks, float timestep);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unlocks the C threadpool
|
|
||||||
*/
|
|
||||||
public static long unlockThreadsWrapper(){
|
|
||||||
return unlockThreads(threadpool);
|
|
||||||
}
|
|
||||||
private static native long unlockThreads(long threadPoolPtr);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Queues a single chunk to be simulated this frame
|
|
||||||
* @param chunk The chunk
|
|
||||||
* @param timestep The amount of time to simulate it for
|
|
||||||
*/
|
|
||||||
public static void queueChunkWrapper(long libraryContext, FluidSim chunk, float timestep){
|
|
||||||
queueChunk(
|
|
||||||
libraryContext,
|
|
||||||
DIM,
|
|
||||||
chunk.chunkMask,
|
|
||||||
chunk.density,
|
|
||||||
chunk.densityAddition,
|
|
||||||
chunk.uVector,
|
|
||||||
chunk.vVector,
|
|
||||||
chunk.wVector,
|
|
||||||
chunk.uAdditionVector,
|
|
||||||
chunk.vAdditionVector,
|
|
||||||
chunk.wAdditionVector,
|
|
||||||
DIFFUSION_CONSTANT,
|
|
||||||
VISCOSITY_CONSTANT,
|
|
||||||
timestep
|
|
||||||
);
|
|
||||||
}
|
|
||||||
public static native void queueChunk(
|
|
||||||
long libraryContext,
|
|
||||||
int DIM_X,
|
|
||||||
int chunkMask,
|
|
||||||
ByteBuffer[] d,
|
|
||||||
ByteBuffer[] d0,
|
|
||||||
ByteBuffer[] u,
|
|
||||||
ByteBuffer[] v,
|
|
||||||
ByteBuffer[] w,
|
|
||||||
ByteBuffer[] u0,
|
|
||||||
ByteBuffer[] v0,
|
|
||||||
ByteBuffer[] w0,
|
|
||||||
float DIFFUSION_CONSTANT,
|
|
||||||
float VISCOSITY_CONSTANT,
|
|
||||||
float timestep
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends work to the threadpool
|
|
||||||
*/
|
|
||||||
public static void submitWorkWrapper(long contextPtr){
|
|
||||||
submitWork(contextPtr);
|
|
||||||
}
|
|
||||||
public static native void submitWork(long contextPtr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches work from the threadpool
|
|
||||||
*/
|
|
||||||
public static void fetchWorkWrapper(long contextPtr){
|
|
||||||
fetchWork(contextPtr);
|
|
||||||
}
|
|
||||||
public static native void fetchWork(long contextPtr);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1114,7 +493,7 @@ public class FluidSim {
|
|||||||
for(int k = 0; k < DIM; k++){
|
for(int k = 0; k < DIM; k++){
|
||||||
index = ((i)+(DIM)*(j) + (DIM)*(DIM)*(k));
|
index = ((i)+(DIM)*(j) + (DIM)*(DIM)*(k));
|
||||||
u0ArrayView[index] = 0;
|
u0ArrayView[index] = 0;
|
||||||
v0ArrayView[index] = 0;
|
v0ArrayView[index] = densityArrayView[index] * GRAVITY;
|
||||||
w0ArrayView[index] = 0;
|
w0ArrayView[index] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public class Main {
|
|||||||
|
|
||||||
public static void main(String args[]){
|
public static void main(String args[]){
|
||||||
|
|
||||||
int dim = 10;
|
int dim = 5;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
long time = 0;
|
long time = 0;
|
||||||
long lastTime = 0;
|
long lastTime = 0;
|
||||||
@ -36,9 +36,9 @@ public class Main {
|
|||||||
Mesh.initShaderProgram();
|
Mesh.initShaderProgram();
|
||||||
|
|
||||||
|
|
||||||
FluidSim[][][] simArray = initFluidSim(dim,1,1);
|
FluidSim[][][] simArray = initFluidSim(dim,1,dim);
|
||||||
|
|
||||||
Mesh[][][] meshArray = initMeshes(dim,1,1,simArray);
|
Mesh[][][] meshArray = initMeshes(dim,1,dim,simArray);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -55,10 +55,7 @@ public class Main {
|
|||||||
//
|
//
|
||||||
//Simulate
|
//Simulate
|
||||||
//
|
//
|
||||||
FluidSim.unlockThreadsWrapper();
|
FluidSim.simChunks(simArray,i,0.01f);
|
||||||
FluidSim.simChunks(simArray,i,0.0001f);
|
|
||||||
FluidSim.unlockThreadsWrapper();
|
|
||||||
time = time + (System.currentTimeMillis() - lastTime);
|
|
||||||
//
|
//
|
||||||
//Remesh
|
//Remesh
|
||||||
//
|
//
|
||||||
@ -69,11 +66,12 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
time = time + (System.currentTimeMillis() - lastTime);
|
||||||
//redraw
|
//redraw
|
||||||
GLFWContext.redraw(meshArray);
|
GLFWContext.redraw(meshArray);
|
||||||
i++;
|
i++;
|
||||||
if(i == 100){
|
if(i == 100){
|
||||||
System.out.println(time / 100.0);
|
System.out.println("overall time: " + time / 100.0);
|
||||||
}
|
}
|
||||||
if(i > 3){
|
if(i > 3){
|
||||||
// scan.next();
|
// scan.next();
|
||||||
@ -85,7 +83,6 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static FluidSim[][][] initFluidSim(int dimx, int dimy, int dimz){
|
private static FluidSim[][][] initFluidSim(int dimx, int dimy, int dimz){
|
||||||
FluidSim.threadpool = FluidSim.createThreadpoolWrapper(5);
|
|
||||||
FluidSim[][][] simArray = new FluidSim[dimx][dimy][dimz];
|
FluidSim[][][] simArray = new FluidSim[dimx][dimy][dimz];
|
||||||
for(int x = 0; x < simArray.length; x++){
|
for(int x = 0; x < simArray.length; x++){
|
||||||
for(int y = 0; y < simArray[0].length; y++){
|
for(int y = 0; y < simArray[0].length; y++){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user