Successful multichunking
This commit is contained in:
parent
fbf4e62d9c
commit
8a67458470
@ -60,43 +60,43 @@ const uint32_t CHUNK_INDEX_ARR[] = {
|
|||||||
|
|
||||||
//control offsetting the advect sampler location if a valid neighbor chunk is hit
|
//control offsetting the advect sampler location if a valid neighbor chunk is hit
|
||||||
const char CHUNK_NORMALIZE_U[] = {
|
const char CHUNK_NORMALIZE_U[] = {
|
||||||
-1, 0, 1,
|
1, 0, -1,
|
||||||
-1, 0, 1,
|
1, 0, -1,
|
||||||
-1, 0, 1,
|
1, 0, -1,
|
||||||
|
|
||||||
-1, 0, 1,
|
1, 0, -1,
|
||||||
-1, 0, 1,
|
1, 0, -1,
|
||||||
-1, 0, 1,
|
1, 0, -1,
|
||||||
|
|
||||||
-1, 0, 1,
|
1, 0, -1,
|
||||||
-1, 0, 1,
|
1, 0, -1,
|
||||||
-1, 0, 1,
|
1, 0, -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const char CHUNK_NORMALIZE_V[] = {
|
const char CHUNK_NORMALIZE_V[] = {
|
||||||
-1, -1, -1,
|
|
||||||
0, 0, 0,
|
|
||||||
1, 1, 1,
|
1, 1, 1,
|
||||||
|
0, 0, 0,
|
||||||
|
-1, -1, -1,
|
||||||
|
|
||||||
-1, -1, -1,
|
1, 1, 1,
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
1, 1, 1,
|
-1, -1, -1,
|
||||||
|
|
||||||
-1, -1, -1,
|
1, 1, 1,
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
1, 1, 1,
|
-1, -1, -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const char CHUNK_NORMALIZE_W[] = {
|
const char CHUNK_NORMALIZE_W[] = {
|
||||||
-1, -1, -1,
|
1, 1, 1,
|
||||||
-1, -1, -1,
|
1, 1, 1,
|
||||||
-1, -1, -1,
|
1, 1, 1,
|
||||||
|
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
|
|
||||||
1, 1, 1,
|
-1, -1, -1,
|
||||||
1, 1, 1,
|
-1, -1, -1,
|
||||||
1, 1, 1,
|
-1, -1, -1,
|
||||||
};
|
};
|
||||||
@ -105,7 +105,7 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_advectDensity
|
|||||||
advectDensity(env,chunk_mask,N,3,jrx,jrx0,GET_ARR(env,jru,CENTER_LOC),GET_ARR(env,jrv,CENTER_LOC),GET_ARR(env,jrw,CENTER_LOC),dt);
|
advectDensity(env,chunk_mask,N,3,jrx,jrx0,GET_ARR(env,jru,CENTER_LOC),GET_ARR(env,jrv,CENTER_LOC),GET_ARR(env,jrw,CENTER_LOC),dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void advectDensity(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, jobjectArray d0, float * u, float * v, float * w, float dt){
|
void advectDensity(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, jobjectArray 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;
|
||||||
@ -114,14 +114,12 @@ void advectDensity(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray
|
|||||||
|
|
||||||
float * d = GET_ARR(env,jrd,CENTER_LOC);
|
float * d = GET_ARR(env,jrd,CENTER_LOC);
|
||||||
|
|
||||||
float * x0 = GET_ARR(env,d0,CENTER_LOC);
|
float * d0 = GET_ARR(env,jrd0,CENTER_LOC);
|
||||||
|
|
||||||
float * sampleArr = x0;
|
|
||||||
|
|
||||||
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++){
|
||||||
sampleArr = x0;
|
d0 = GET_ARR(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)];
|
||||||
@ -145,31 +143,56 @@ void advectDensity(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray
|
|||||||
// }
|
// }
|
||||||
// if(CK(m,n,o) != CENTER_LOC && ARR_EXISTS(chunk_mask,m,n,o)){
|
// if(CK(m,n,o) != CENTER_LOC && ARR_EXISTS(chunk_mask,m,n,o)){
|
||||||
// // printf("Hit other chunk\n");
|
// // printf("Hit other chunk\n");
|
||||||
// sampleArr = GET_ARR(env,jrd,CK(m,n,o));
|
// d0 = GET_ARR(env,jrd0,CK(m,n,o));
|
||||||
// x = x + CHUNK_NORMALIZE_U[CK(m,n,o)] * N;
|
// x = x + CHUNK_NORMALIZE_U[CK(m,n,o)] * (N-1);
|
||||||
// y = y + CHUNK_NORMALIZE_V[CK(m,n,o)] * N;
|
// y = y + CHUNK_NORMALIZE_V[CK(m,n,o)] * (N-1);
|
||||||
// z = z + CHUNK_NORMALIZE_W[CK(m,n,o)] * N;
|
// z = z + CHUNK_NORMALIZE_W[CK(m,n,o)] * (N-1);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if(x < 0.001f){
|
||||||
|
//cases to consider:
|
||||||
|
//m = 0, x = -10
|
||||||
|
//m = 2, x = 0.01
|
||||||
|
x=0.001f;
|
||||||
|
i0=(int)0;
|
||||||
|
i1=1;
|
||||||
|
s0 = 0.999f;
|
||||||
|
s1 = 0.001f;
|
||||||
|
} else if(x >= N - 1){
|
||||||
|
//cases to consider:
|
||||||
|
//m = 0, x = 17.01
|
||||||
|
//m = 2, x = 20
|
||||||
|
x = N-1;
|
||||||
|
i0=(int)N-2;
|
||||||
|
i1=N-1;
|
||||||
|
s0 = 0.001f;
|
||||||
|
s1 = 0.999f;
|
||||||
|
} else {
|
||||||
|
i0=(int)x;
|
||||||
|
i1=i0+1;
|
||||||
|
s1 = x-i0;
|
||||||
|
s0 = 1-s1;
|
||||||
|
}
|
||||||
|
|
||||||
//clamp location within chunk
|
//clamp location within chunk
|
||||||
if (x<0.5f) x=0.5f;
|
// if (x<0.5f) x=0.5f;
|
||||||
if (x>N+0.5f) x=N+0.5f;
|
// if (x>N+0.5f) x=N+0.5f;
|
||||||
if (y<0.5f) y=0.5f;
|
if (y<0.5f) y=0.5f;
|
||||||
if (y>N+0.5f) y=N+0.5f;
|
if (y>N+0.5f) y=N+0.5f;
|
||||||
if (z<0.5f) z=0.5f;
|
if (z<0.5f) z=0.5f;
|
||||||
if (z>N+0.5f) z=N+0.5f;
|
if (z>N+0.5f) z=N+0.5f;
|
||||||
|
|
||||||
//get actual indices
|
//get actual indices
|
||||||
i0=(int)x;
|
// i0=(int)x;
|
||||||
i1=i0+1;
|
// i1=i0+1;
|
||||||
j0=(int)y;
|
j0=(int)y;
|
||||||
j1=j0+1;
|
j1=j0+1;
|
||||||
k0=(int)z;
|
k0=(int)z;
|
||||||
k1=k0+1;
|
k1=k0+1;
|
||||||
|
|
||||||
//calculate percentage of each index
|
//calculate percentage of each index
|
||||||
s1 = x-i0;
|
// s1 = x-i0;
|
||||||
s0 = 1-s1;
|
// s0 = 1-s1;
|
||||||
t1 = y-j0;
|
t1 = y-j0;
|
||||||
t0 = 1-t1;
|
t0 = 1-t1;
|
||||||
u1 = z-k0;
|
u1 = z-k0;
|
||||||
@ -213,16 +236,16 @@ void advectDensity(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray
|
|||||||
// }
|
// }
|
||||||
d[IX(i,j,k)] =
|
d[IX(i,j,k)] =
|
||||||
s0*(
|
s0*(
|
||||||
t0*u0*sampleArr[IX(i0,j0,k0)]+
|
t0*u0*d0[IX(i0,j0,k0)]+
|
||||||
t1*u0*sampleArr[IX(i0,j1,k0)]+
|
t1*u0*d0[IX(i0,j1,k0)]+
|
||||||
t0*u1*sampleArr[IX(i0,j0,k1)]+
|
t0*u1*d0[IX(i0,j0,k1)]+
|
||||||
t1*u1*sampleArr[IX(i0,j1,k1)]
|
t1*u1*d0[IX(i0,j1,k1)]
|
||||||
)+
|
)+
|
||||||
s1*(
|
s1*(
|
||||||
t0*u0*sampleArr[IX(i1,j0,k0)]+
|
t0*u0*d0[IX(i1,j0,k0)]+
|
||||||
t1*u0*sampleArr[IX(i1,j1,k0)]+
|
t1*u0*d0[IX(i1,j1,k0)]+
|
||||||
t0*u1*sampleArr[IX(i1,j0,k1)]+
|
t0*u1*d0[IX(i1,j0,k1)]+
|
||||||
t1*u1*sampleArr[IX(i1,j1,k1)]
|
t1*u1*d0[IX(i1,j1,k1)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,13 +10,13 @@ extern "C" {
|
|||||||
#undef electrosphere_FluidSim_DIM
|
#undef electrosphere_FluidSim_DIM
|
||||||
#define electrosphere_FluidSim_DIM 18L
|
#define electrosphere_FluidSim_DIM 18L
|
||||||
#undef electrosphere_FluidSim_DIFFUSION_CONSTANT
|
#undef electrosphere_FluidSim_DIFFUSION_CONSTANT
|
||||||
#define electrosphere_FluidSim_DIFFUSION_CONSTANT 1.0E-5f
|
#define electrosphere_FluidSim_DIFFUSION_CONSTANT 0.0f
|
||||||
#undef electrosphere_FluidSim_VISCOSITY_CONSTANT
|
#undef electrosphere_FluidSim_VISCOSITY_CONSTANT
|
||||||
#define electrosphere_FluidSim_VISCOSITY_CONSTANT 1.0E-5f
|
#define electrosphere_FluidSim_VISCOSITY_CONSTANT 0.0f
|
||||||
#undef electrosphere_FluidSim_LINEARSOLVERTIMES
|
#undef electrosphere_FluidSim_LINEARSOLVERTIMES
|
||||||
#define electrosphere_FluidSim_LINEARSOLVERTIMES 10L
|
#define electrosphere_FluidSim_LINEARSOLVERTIMES 20L
|
||||||
#undef electrosphere_FluidSim_GRAVITY
|
#undef electrosphere_FluidSim_GRAVITY
|
||||||
#define electrosphere_FluidSim_GRAVITY -1000.0f
|
#define electrosphere_FluidSim_GRAVITY -100.0f
|
||||||
/*
|
/*
|
||||||
* Class: electrosphere_FluidSim
|
* Class: electrosphere_FluidSim
|
||||||
* Method: simulate
|
* Method: simulate
|
||||||
@ -116,10 +116,10 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setBoundsToNeighbors
|
|||||||
/*
|
/*
|
||||||
* Class: electrosphere_FluidSim
|
* Class: electrosphere_FluidSim
|
||||||
* Method: copyNeighbors
|
* Method: copyNeighbors
|
||||||
* Signature: (III[Ljava/nio/ByteBuffer;)V
|
* Signature: (IIII[Ljava/nio/ByteBuffer;)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
||||||
(JNIEnv *, jobject, jint, jint, jint, jobjectArray);
|
(JNIEnv *, jobject, jint, jint, jint, jint, jobjectArray);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
#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, float * d0, float * u, float * v, float * w, 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);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -66,7 +66,7 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveVectorDiffuse
|
|||||||
jfloat DIFFUSION_CONST,
|
jfloat DIFFUSION_CONST,
|
||||||
jfloat VISCOSITY_CONST,
|
jfloat VISCOSITY_CONST,
|
||||||
jfloat dt){
|
jfloat dt){
|
||||||
float a=dt*DIFFUSION_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(env,jru,CENTER_LOC);
|
||||||
@ -177,7 +177,9 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setupProjection
|
|||||||
jfloat dt){
|
jfloat dt){
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
|
|
||||||
__m256 nVector = _mm256_set1_ps(N);
|
__m256 xVector = _mm256_set1_ps(N);
|
||||||
|
__m256 yVector = _mm256_set1_ps(N);
|
||||||
|
__m256 zVector = _mm256_set1_ps(N);
|
||||||
__m256 constScalar = _mm256_set1_ps(-1.0/3.0);
|
__m256 constScalar = _mm256_set1_ps(-1.0/3.0);
|
||||||
__m256 zeroVec = _mm256_set1_ps(0);
|
__m256 zeroVec = _mm256_set1_ps(0);
|
||||||
__m256 vector, vector2, vector3;
|
__m256 vector, vector2, vector3;
|
||||||
@ -189,52 +191,64 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setupProjection
|
|||||||
float * p = GET_ARR(env,jru0,CENTER_LOC);
|
float * p = GET_ARR(env,jru0,CENTER_LOC);
|
||||||
float * div = GET_ARR(env,jrv0,CENTER_LOC);
|
float * div = GET_ARR(env,jrv0,CENTER_LOC);
|
||||||
|
|
||||||
|
float scalar = 1.0/3.0;
|
||||||
|
float h = 1.0/N;
|
||||||
|
|
||||||
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++){
|
||||||
i = 1;
|
// i = 1;
|
||||||
//
|
// //
|
||||||
//lower
|
// //lower
|
||||||
//
|
// //
|
||||||
//first part
|
// //first part
|
||||||
vector = _mm256_loadu_ps(&u[IX(i+1,j,k)]);
|
// vector = _mm256_loadu_ps(&u[IX(i+1,j,k)]);
|
||||||
vector = _mm256_sub_ps(vector,_mm256_loadu_ps(&u[IX(i-1,j,k)]));
|
// vector = _mm256_sub_ps(vector,_mm256_loadu_ps(&u[IX(i-1,j,k)]));
|
||||||
vector = _mm256_div_ps(vector,nVector);
|
// vector = _mm256_div_ps(vector,xVector);
|
||||||
//second part
|
// //second part
|
||||||
vector2 = _mm256_loadu_ps(&v[IX(i,j+1,k)]);
|
// vector2 = _mm256_loadu_ps(&v[IX(i,j+1,k)]);
|
||||||
vector2 = _mm256_sub_ps(vector2,_mm256_loadu_ps(&v[IX(i,j-1,k)]));
|
// vector2 = _mm256_sub_ps(vector2,_mm256_loadu_ps(&v[IX(i,j-1,k)]));
|
||||||
vector2 = _mm256_div_ps(vector2,nVector);
|
// vector2 = _mm256_div_ps(vector2,yVector);
|
||||||
//third part
|
// //third part
|
||||||
vector3 = _mm256_loadu_ps(&w[IX(i,j,k+1)]);
|
// vector3 = _mm256_loadu_ps(&w[IX(i,j,k+1)]);
|
||||||
vector3 = _mm256_sub_ps(vector3,_mm256_loadu_ps(&w[IX(i,j,k-1)]));
|
// vector3 = _mm256_sub_ps(vector3,_mm256_loadu_ps(&w[IX(i,j,k-1)]));
|
||||||
vector3 = _mm256_div_ps(vector3,nVector);
|
// vector3 = _mm256_div_ps(vector3,zVector);
|
||||||
//multiply and finalize
|
// //multiply and finalize
|
||||||
vector = _mm256_add_ps(vector,_mm256_add_ps(vector2,vector3));
|
// vector = _mm256_add_ps(vector,_mm256_add_ps(vector2,vector3));
|
||||||
vector = _mm256_mul_ps(vector,constScalar);
|
// vector = _mm256_mul_ps(vector,constScalar);
|
||||||
//store
|
// //store
|
||||||
_mm256_storeu_ps(&div[IX(i,j,k)],vector);
|
// _mm256_storeu_ps(&div[IX(i,j,k)],vector);
|
||||||
_mm256_storeu_ps(&p[IX(i,j,k)],zeroVec);
|
// _mm256_storeu_ps(&p[IX(i,j,k)],zeroVec);
|
||||||
i = 9;
|
// i = 9;
|
||||||
//
|
// //
|
||||||
//upper
|
// //upper
|
||||||
//
|
// //
|
||||||
//first part
|
// //first part
|
||||||
vector = _mm256_loadu_ps(&u[IX(i+1,j,k)]);
|
// vector = _mm256_loadu_ps(&u[IX(i+1,j,k)]);
|
||||||
vector = _mm256_sub_ps(vector,_mm256_loadu_ps(&u[IX(i-1,j,k)]));
|
// vector = _mm256_sub_ps(vector,_mm256_loadu_ps(&u[IX(i-1,j,k)]));
|
||||||
vector = _mm256_div_ps(vector,nVector);
|
// vector = _mm256_div_ps(vector,xVector);
|
||||||
//second part
|
// //second part
|
||||||
vector2 = _mm256_loadu_ps(&v[IX(i,j+1,k)]);
|
// vector2 = _mm256_loadu_ps(&v[IX(i,j+1,k)]);
|
||||||
vector2 = _mm256_sub_ps(vector2,_mm256_loadu_ps(&v[IX(i,j-1,k)]));
|
// vector2 = _mm256_sub_ps(vector2,_mm256_loadu_ps(&v[IX(i,j-1,k)]));
|
||||||
vector2 = _mm256_div_ps(vector2,nVector);
|
// vector2 = _mm256_div_ps(vector2,yVector);
|
||||||
//third part
|
// //third part
|
||||||
vector3 = _mm256_loadu_ps(&w[IX(i,j,k+1)]);
|
// vector3 = _mm256_loadu_ps(&w[IX(i,j,k+1)]);
|
||||||
vector3 = _mm256_sub_ps(vector3,_mm256_loadu_ps(&w[IX(i,j,k-1)]));
|
// vector3 = _mm256_sub_ps(vector3,_mm256_loadu_ps(&w[IX(i,j,k-1)]));
|
||||||
vector3 = _mm256_div_ps(vector3,nVector);
|
// vector3 = _mm256_div_ps(vector3,zVector);
|
||||||
//multiply and finalize
|
// //multiply and finalize
|
||||||
vector = _mm256_add_ps(vector,_mm256_add_ps(vector2,vector3));
|
// vector = _mm256_add_ps(vector,_mm256_add_ps(vector2,vector3));
|
||||||
vector = _mm256_mul_ps(vector,constScalar);
|
// vector = _mm256_mul_ps(vector,constScalar);
|
||||||
//store
|
// //store
|
||||||
_mm256_storeu_ps(&div[IX(i,j,k)],vector);
|
// _mm256_storeu_ps(&div[IX(i,j,k)],vector);
|
||||||
_mm256_storeu_ps(&p[IX(i,j,k)],zeroVec);
|
// _mm256_storeu_ps(&p[IX(i,j,k)],zeroVec);
|
||||||
|
|
||||||
|
|
||||||
|
for(i = 1; i < N - 1; i++){
|
||||||
|
div[IX(i,j,k)] =
|
||||||
|
-scalar*h*(u[IX(i+1,j,k)]-u[IX(i-1,j,k)]+
|
||||||
|
v[IX(i,j+1,k)]-v[IX(i,j-1,k)]+
|
||||||
|
w[IX(i,j,k+1)]-w[IX(i,j,k-1)]);
|
||||||
|
p[IX(i,j,k)] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,30 +276,33 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveProjection
|
|||||||
__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 * x = GET_ARR(env,jru0,CENTER_LOC);
|
float * p = GET_ARR(env,jru0,CENTER_LOC);
|
||||||
float * x0 = GET_ARR(env,jrv0,CENTER_LOC);
|
float * div = GET_ARR(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++){
|
||||||
int n = 0;
|
int n = 0;
|
||||||
//solve as much as possible vectorized
|
//solve as much as possible vectorized
|
||||||
for(i = 1; i < N-1; i=i+8){
|
// for(i = 1; i < N-1; i=i+8){
|
||||||
__m256 vector = _mm256_loadu_ps(&x[IX(i-1,j,k)]);
|
// __m256 vector = _mm256_loadu_ps(&p[IX(i-1,j,k)]);
|
||||||
vector = _mm256_add_ps(vector,_mm256_loadu_ps(&x[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(&x[IX(i,j-1,k)]));
|
// vector = _mm256_add_ps(vector,_mm256_loadu_ps(&p[IX(i,j-1,k)]));
|
||||||
vector = _mm256_add_ps(vector,_mm256_loadu_ps(&x[IX(i,j+1,k)]));
|
// vector = _mm256_add_ps(vector,_mm256_loadu_ps(&p[IX(i,j+1,k)]));
|
||||||
vector = _mm256_add_ps(vector,_mm256_loadu_ps(&x[IX(i,j,k-1)]));
|
// vector = _mm256_add_ps(vector,_mm256_loadu_ps(&p[IX(i,j,k-1)]));
|
||||||
vector = _mm256_add_ps(vector,_mm256_loadu_ps(&x[IX(i,j,k+1)]));
|
// vector = _mm256_add_ps(vector,_mm256_loadu_ps(&p[IX(i,j,k+1)]));
|
||||||
vector = _mm256_mul_ps(vector,aScalar);
|
// // vector = _mm256_mul_ps(vector,aScalar);
|
||||||
vector = _mm256_add_ps(vector,_mm256_loadu_ps(&x0[IX(i,j,k)]));
|
// vector = _mm256_add_ps(vector,_mm256_loadu_ps(&div[IX(i,j,k)]));
|
||||||
vector = _mm256_div_ps(vector,cScalar);
|
// vector = _mm256_div_ps(vector,cScalar);
|
||||||
_mm256_storeu_ps(&x[IX(i,j,k)],vector);
|
// _mm256_storeu_ps(&p[IX(i,j,k)],vector);
|
||||||
}
|
// }
|
||||||
//If there is any leftover, perform manual solving
|
// //If there is any leftover, perform manual solving
|
||||||
if(i>N-1){
|
// if(i>N-1){
|
||||||
for(i=i-8; i < N-1; i++){
|
// for(i=i-8; i < N-1; i++){
|
||||||
x[IX(i,j,k)] = (x0[IX(i,j,k)] + a*(x[IX(i-1,j,k)]+x[IX(i+1,j,k)]+x[IX(i,j-1,k)]+x[IX(i,j+1,k)]+x[IX(i,j,k-1)]+x[IX(i,j,k+1)]))/c;
|
// p[IX(i,j,k)] = (div[IX(i,j,k)] + a*(p[IX(i-1,j,k)]+p[IX(i+1,j,k)]+p[IX(i,j-1,k)]+p[IX(i,j+1,k)]+p[IX(i,j,k-1)]+p[IX(i,j,k+1)]))/c;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
for(i=1; i < N-1; i++){
|
||||||
|
p[IX(i,j,k)] = (div[IX(i,j,k)] + a*(p[IX(i-1,j,k)]+p[IX(i+1,j,k)]+p[IX(i,j-1,k)]+p[IX(i,j+1,k)]+p[IX(i,j,k-1)]+p[IX(i,j,k+1)]))/c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,9 +326,10 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_finalizeProjection
|
|||||||
jfloat VISCOSITY_CONST,
|
jfloat VISCOSITY_CONST,
|
||||||
jfloat dt){
|
jfloat dt){
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
__m256 nVector = _mm256_set1_ps(N);
|
// __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 zeroVec = _mm256_set1_ps(0);
|
__m256 yScalar = _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(env,jru,CENTER_LOC);
|
||||||
@ -321,59 +339,66 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_finalizeProjection
|
|||||||
float * p = GET_ARR(env,jru0,CENTER_LOC);
|
float * p = GET_ARR(env,jru0,CENTER_LOC);
|
||||||
float * div = GET_ARR(env,jrv0,CENTER_LOC);
|
float * div = GET_ARR(env,jrv0,CENTER_LOC);
|
||||||
|
|
||||||
|
float h = 1.0 / N;
|
||||||
|
|
||||||
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++ ) {
|
||||||
//
|
//
|
||||||
//v
|
//v
|
||||||
//
|
//
|
||||||
//lower
|
//lower
|
||||||
vector = _mm256_loadu_ps(&p[IX(1+1,j,k)]);
|
// vector = _mm256_loadu_ps(&p[IX(1+1,j,k)]);
|
||||||
vector2 = _mm256_loadu_ps(&p[IX(1-1,j,k)]);
|
// vector2 = _mm256_loadu_ps(&p[IX(1-1,j,k)]);
|
||||||
vector = _mm256_sub_ps(vector,vector2);
|
// vector = _mm256_sub_ps(vector,vector2);
|
||||||
vector = _mm256_mul_ps(vector,constScalar);
|
// vector = _mm256_mul_ps(vector,xScalar);
|
||||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&u[IX(1,j,k)]),vector);
|
// vector = _mm256_sub_ps(_mm256_loadu_ps(&u[IX(1,j,k)]),vector);
|
||||||
_mm256_storeu_ps(&u[IX(1,j,k)],vector);
|
// _mm256_storeu_ps(&u[IX(1,j,k)],vector);
|
||||||
//upper
|
// //upper
|
||||||
vector = _mm256_loadu_ps(&p[IX(9+1,j,k)]);
|
// vector = _mm256_loadu_ps(&p[IX(9+1,j,k)]);
|
||||||
vector2 = _mm256_loadu_ps(&p[IX(9-1,j,k)]);
|
// vector2 = _mm256_loadu_ps(&p[IX(9-1,j,k)]);
|
||||||
vector = _mm256_sub_ps(vector,vector2);
|
// vector = _mm256_sub_ps(vector,vector2);
|
||||||
vector = _mm256_mul_ps(vector,constScalar);
|
// vector = _mm256_mul_ps(vector,xScalar);
|
||||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&u[IX(9,j,k)]),vector);
|
// vector = _mm256_sub_ps(_mm256_loadu_ps(&u[IX(9,j,k)]),vector);
|
||||||
_mm256_storeu_ps(&u[IX(9,j,k)],vector);
|
// _mm256_storeu_ps(&u[IX(9,j,k)],vector);
|
||||||
//
|
// //
|
||||||
//v
|
// //v
|
||||||
//
|
// //
|
||||||
//lower
|
// //lower
|
||||||
vector = _mm256_loadu_ps(&p[IX(1,j+1,k)]);
|
// vector = _mm256_loadu_ps(&p[IX(1,j+1,k)]);
|
||||||
vector2 = _mm256_loadu_ps(&p[IX(1,j-1,k)]);
|
// vector2 = _mm256_loadu_ps(&p[IX(1,j-1,k)]);
|
||||||
vector = _mm256_sub_ps(vector,vector2);
|
// vector = _mm256_sub_ps(vector,vector2);
|
||||||
vector = _mm256_mul_ps(vector,constScalar);
|
// vector = _mm256_mul_ps(vector,yScalar);
|
||||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&v[IX(1,j,k)]),vector);
|
// vector = _mm256_sub_ps(_mm256_loadu_ps(&v[IX(1,j,k)]),vector);
|
||||||
_mm256_storeu_ps(&v[IX(1,j,k)],vector);
|
// _mm256_storeu_ps(&v[IX(1,j,k)],vector);
|
||||||
//upper
|
// //upper
|
||||||
vector = _mm256_loadu_ps(&p[IX(9,j+1,k)]);
|
// vector = _mm256_loadu_ps(&p[IX(9,j+1,k)]);
|
||||||
vector2 = _mm256_loadu_ps(&p[IX(9,j-1,k)]);
|
// vector2 = _mm256_loadu_ps(&p[IX(9,j-1,k)]);
|
||||||
vector = _mm256_sub_ps(vector,vector2);
|
// vector = _mm256_sub_ps(vector,vector2);
|
||||||
vector = _mm256_mul_ps(vector,constScalar);
|
// vector = _mm256_mul_ps(vector,yScalar);
|
||||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&v[IX(9,j,k)]),vector);
|
// vector = _mm256_sub_ps(_mm256_loadu_ps(&v[IX(9,j,k)]),vector);
|
||||||
_mm256_storeu_ps(&v[IX(9,j,k)],vector);
|
// _mm256_storeu_ps(&v[IX(9,j,k)],vector);
|
||||||
//
|
// //
|
||||||
//w
|
// //w
|
||||||
//
|
// //
|
||||||
//lower
|
// //lower
|
||||||
vector = _mm256_loadu_ps(&p[IX(1,j,k+1)]);
|
// vector = _mm256_loadu_ps(&p[IX(1,j,k+1)]);
|
||||||
vector2 = _mm256_loadu_ps(&p[IX(1,j,k-1)]);
|
// vector2 = _mm256_loadu_ps(&p[IX(1,j,k-1)]);
|
||||||
vector = _mm256_sub_ps(vector,vector2);
|
// vector = _mm256_sub_ps(vector,vector2);
|
||||||
vector = _mm256_mul_ps(vector,constScalar);
|
// vector = _mm256_mul_ps(vector,zScalar);
|
||||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&w[IX(1,j,k)]),vector);
|
// vector = _mm256_sub_ps(_mm256_loadu_ps(&w[IX(1,j,k)]),vector);
|
||||||
_mm256_storeu_ps(&w[IX(1,j,k)],vector);
|
// _mm256_storeu_ps(&w[IX(1,j,k)],vector);
|
||||||
//upper
|
// //upper
|
||||||
vector = _mm256_loadu_ps(&p[IX(9,j,k+1)]);
|
// vector = _mm256_loadu_ps(&p[IX(9,j,k+1)]);
|
||||||
vector2 = _mm256_loadu_ps(&p[IX(9,j,k-1)]);
|
// vector2 = _mm256_loadu_ps(&p[IX(9,j,k-1)]);
|
||||||
vector = _mm256_sub_ps(vector,vector2);
|
// vector = _mm256_sub_ps(vector,vector2);
|
||||||
vector = _mm256_mul_ps(vector,constScalar);
|
// vector = _mm256_mul_ps(vector,zScalar);
|
||||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&w[IX(9,j,k)]),vector);
|
// vector = _mm256_sub_ps(_mm256_loadu_ps(&w[IX(9,j,k)]),vector);
|
||||||
_mm256_storeu_ps(&w[IX(9,j,k)],vector);
|
// _mm256_storeu_ps(&w[IX(9,j,k)],vector);
|
||||||
|
for(i = 1; i < N-1; i++){
|
||||||
|
u[IX(i,j,k)] = u[IX(i,j,k)] - 0.5 * (p[IX(i+1,j,k)] - p[IX(i-1,j,k)]) / h;
|
||||||
|
v[IX(i,j,k)] = v[IX(i,j,k)] - 0.5 * (p[IX(i,j+1,k)] - p[IX(i,j-1,k)]) / h;
|
||||||
|
w[IX(i,j,k)] = w[IX(i,j,k)] - 0.5 * (p[IX(i,j,k+1)] - p[IX(i,j,k-1)]) / h;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,13 +420,13 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_advectVectors
|
|||||||
jfloat DIFFUSION_CONST,
|
jfloat DIFFUSION_CONST,
|
||||||
jfloat VISCOSITY_CONST,
|
jfloat VISCOSITY_CONST,
|
||||||
jfloat dt){
|
jfloat dt){
|
||||||
advect(env,chunk_mask,N,1,jru,GET_ARR(env,jru0,CENTER_LOC),GET_ARR(env,jru0,CENTER_LOC),GET_ARR(env,jrv0,CENTER_LOC),GET_ARR(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(env,chunk_mask,N,2,jrv,GET_ARR(env,jrv0,CENTER_LOC),GET_ARR(env,jru0,CENTER_LOC),GET_ARR(env,jrv0,CENTER_LOC),GET_ARR(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(env,chunk_mask,N,3,jrw,GET_ARR(env,jrw0,CENTER_LOC),GET_ARR(env,jru0,CENTER_LOC),GET_ARR(env,jrv0,CENTER_LOC),GET_ARR(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, float * d0, float * u, float * v, float * w, 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){
|
||||||
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;
|
||||||
@ -410,12 +435,12 @@ void advect(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, f
|
|||||||
|
|
||||||
float * d = GET_ARR(env,jrd,CENTER_LOC);
|
float * d = GET_ARR(env,jrd,CENTER_LOC);
|
||||||
|
|
||||||
float * sampleArr = d0;
|
float * d0 = GET_ARR(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++){
|
||||||
sampleArr = d0;
|
d0 = GET_ARR(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)];
|
||||||
@ -423,55 +448,175 @@ void advect(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, f
|
|||||||
|
|
||||||
m = n = o = 1;
|
m = n = o = 1;
|
||||||
|
|
||||||
if(x < 1){ m -= 1; }
|
if(x < 0){ m += 1; }
|
||||||
if(x >= N-1){ m += 1; }
|
else if(x >= N){ m -= 1; }
|
||||||
if(y < 1){ n -= 1; }
|
if(y < 0){ n += 1; }
|
||||||
if(y >= N-1){ n += 1; }
|
else if(y >= N){ n -= 1; }
|
||||||
if(z < 1){ o -= 1; }
|
if(z < 0){ o += 1; }
|
||||||
if(z >= N-1){ o += 1; }
|
else if(z >= N){ 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 && ARR_EXISTS(chunk_mask,m,n,o)){
|
||||||
// printf("Looking in border chunk\n");
|
|
||||||
// }
|
// if(i == 1 && j == 1 && k == 1){
|
||||||
// if(x > 16){
|
// printf("\narr indices: %d %d %d\n\n",m,n,o);
|
||||||
// printf("%f %d %d %d\n",m,n,o);
|
// }
|
||||||
// }
|
|
||||||
// if(CK(m,n,o) != CENTER_LOC && ARR_EXISTS(chunk_mask,m,n,o)){
|
//cases:
|
||||||
// // printf("Hit other chunk\n");
|
//if x = 17.01, m = 2
|
||||||
// sampleArr = GET_ARR(env,jrd,CK(m,n,o));
|
// 17 in current array is 1 in neighbor
|
||||||
// x = x + CHUNK_NORMALIZE_U[CK(m,n,o)] * N;
|
// 18 in current array is 2 in neighbor
|
||||||
// y = y + CHUNK_NORMALIZE_V[CK(m,n,o)] * N;
|
// 19 in current array is 3 in neighbor
|
||||||
// z = z + CHUNK_NORMALIZE_W[CK(m,n,o)] * N;
|
//want to sample neighbor array at 1 & 2
|
||||||
// }
|
//x becomes 1.01, sampling new array (keep in mind that 0 in the new array should contain the current array values)
|
||||||
|
//modification: subtract 16
|
||||||
|
|
||||||
|
//cases:
|
||||||
|
//if x = 16.99, m = 2
|
||||||
|
// 16 in current array is 0 in neighbor
|
||||||
|
// 17 in current array is 1 in neighbor
|
||||||
|
// 18 in current array is 2 in neighbor
|
||||||
|
// 19 in current array is 3 in neighbor
|
||||||
|
//want to sample current array still
|
||||||
|
//x becomes 1.01, sampling new array (keep in mind that 0 in the new array should contain the current array values)
|
||||||
|
//modification: no modification
|
||||||
|
|
||||||
|
//if x = 0.01, m = 0
|
||||||
|
// 0 in current array is 16 in neighbor
|
||||||
|
//-1 in current array is 15 in neighbor
|
||||||
|
//-2 in current array is 14 in neighbor
|
||||||
|
//want to sample current array still
|
||||||
|
//x becomes 15.01, sampling new array (keep in mind that 17 in the new array should contain the current array)
|
||||||
|
//modification: no modification
|
||||||
|
|
||||||
|
//if x = -0.01, m = 0
|
||||||
|
// 0 in current array is 16 in neighbor
|
||||||
|
//-1 in current array is 15 in neighbor
|
||||||
|
//-2 in current array is 14 in neighbor
|
||||||
|
//want to sample -1 & 0, so i0 becomes 15
|
||||||
|
//x becomes 15.99, sampling new array (keep in mind that 17 in the new array should contain the current array)
|
||||||
|
//modification: add 16
|
||||||
|
|
||||||
|
//if x = -2, m = 0
|
||||||
|
// 0 in current array is 16 in neighbor
|
||||||
|
//-1 in current array is 15 in neighbor
|
||||||
|
//-2 in current array is 14 in neighbor
|
||||||
|
//x becomes 14, sampling new array (keep in mind that 17 in the new array should contain the current array)
|
||||||
|
//modification: add 16
|
||||||
|
|
||||||
|
|
||||||
|
// printf("Hit other chunk\n");
|
||||||
|
d0 = GET_ARR(env,jrd0,CK(m,n,o));
|
||||||
|
x = x + CHUNK_NORMALIZE_U[CK(m,n,o)] * (N-2);
|
||||||
|
// printf("%d => %f\n",m,x);
|
||||||
|
y = y + CHUNK_NORMALIZE_V[CK(m,n,o)] * (N-2);
|
||||||
|
z = z + CHUNK_NORMALIZE_W[CK(m,n,o)] * (N-2);
|
||||||
|
}
|
||||||
|
|
||||||
//clamp location within chunk
|
//clamp location within chunk
|
||||||
if (x<0.5f) x=0.5f;
|
//get indices, and calculate percentage to pull from each index
|
||||||
if (x>N+0.5f) x=N+0.5f;
|
if(x < 0.001f){
|
||||||
if (y<0.5f) y=0.5f;
|
//cases to consider:
|
||||||
if (y>N+0.5f) y=N+0.5f;
|
//m = 0, x = -10
|
||||||
if (z<0.5f) z=0.5f;
|
//m = 2, x = 0.01
|
||||||
if (z>N+0.5f) z=N+0.5f;
|
x=0.001f;
|
||||||
|
i0=(int)0;
|
||||||
|
i1=1;
|
||||||
|
s0 = 0.999f;
|
||||||
|
s1 = 0.001f;
|
||||||
|
} else if(x > N - 1){
|
||||||
|
//cases to consider:
|
||||||
|
//m = 0, x = 17.01
|
||||||
|
//m = 2, x = 20
|
||||||
|
x = N-1;
|
||||||
|
i0=(int)N-2;
|
||||||
|
i1=N-1;
|
||||||
|
s0 = 0.001f;
|
||||||
|
s1 = 0.999f;
|
||||||
|
} else {
|
||||||
|
i0=(int)x;
|
||||||
|
i1=i0+1;
|
||||||
|
s1 = x-i0;
|
||||||
|
s0 = 1-s1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(y < 0.001f){
|
||||||
|
//cases to consider:
|
||||||
|
//m = 0, x = -10
|
||||||
|
//m = 2, x = 0.01
|
||||||
|
y=0.001f;
|
||||||
|
j0=(int)0;
|
||||||
|
j1=1;
|
||||||
|
t0 = 0.999f;
|
||||||
|
t1 = 0.001f;
|
||||||
|
} else if(y > N - 1){
|
||||||
|
//cases to consider:
|
||||||
|
//m = 0, x = 17.01
|
||||||
|
//m = 2, x = 20
|
||||||
|
y = N-1;
|
||||||
|
j0=(int)N-2;
|
||||||
|
j1=N-1;
|
||||||
|
t0 = 0.001f;
|
||||||
|
t1 = 0.999f;
|
||||||
|
} else {
|
||||||
|
j0=(int)y;
|
||||||
|
j1=j0+1;
|
||||||
|
t1 = y-j0;
|
||||||
|
t0 = 1-t1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(z < 0.001f){
|
||||||
|
//cases to consider:
|
||||||
|
//m = 0, x = -10
|
||||||
|
//m = 2, x = 0.01
|
||||||
|
z=0.001f;
|
||||||
|
k0=(int)0;
|
||||||
|
k1=1;
|
||||||
|
u0 = 0.999f;
|
||||||
|
u1 = 0.001f;
|
||||||
|
} else if(z > N - 1){
|
||||||
|
//cases to consider:
|
||||||
|
//m = 0, x = 17.01
|
||||||
|
//m = 2, x = 20
|
||||||
|
z = N-1;
|
||||||
|
k0=(int)N-2;
|
||||||
|
k1=N-1;
|
||||||
|
u0 = 0.001f;
|
||||||
|
u1 = 0.999f;
|
||||||
|
} else {
|
||||||
|
k0=(int)z;
|
||||||
|
k1=k0+1;
|
||||||
|
u1 = z-k0;
|
||||||
|
u0 = 1-u1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (x<0.001f) x=0.001f;
|
||||||
|
// if (x>N+0.5f) x=N+0.5f;
|
||||||
|
// if (y<0.001f) y=0.001f;
|
||||||
|
// if (y>N+0.5f) y=N+0.5f;
|
||||||
|
// if (z<0.001f) z=0.001f;
|
||||||
|
// if (z>N+0.5f) z=N+0.5f;
|
||||||
|
|
||||||
//get actual indices
|
//get actual indices
|
||||||
i0=(int)x;
|
// i0=(int)x;
|
||||||
i1=i0+1;
|
// i1=i0+1;
|
||||||
j0=(int)y;
|
// j0=(int)y;
|
||||||
j1=j0+1;
|
// j1=j0+1;
|
||||||
k0=(int)z;
|
// k0=(int)z;
|
||||||
k1=k0+1;
|
// k1=k0+1;
|
||||||
|
|
||||||
//calculate percentage of each index
|
//calculate percentage of each index
|
||||||
s1 = x-i0;
|
// s1 = x-i0;
|
||||||
s0 = 1-s1;
|
// s0 = 1-s1;
|
||||||
t1 = y-j0;
|
// t1 = y-j0;
|
||||||
t0 = 1-t1;
|
// t0 = 1-t1;
|
||||||
u1 = z-k0;
|
// u1 = z-k0;
|
||||||
u0 = 1-u1;
|
// u0 = 1-u1;
|
||||||
|
|
||||||
if(i0 >= N){
|
// if(i0 >= N){
|
||||||
i0 = N - 1;
|
// i0 = N - 1;
|
||||||
}
|
// }
|
||||||
// if(i0 < 0){
|
// if(i0 < 0){
|
||||||
// i0 = 0;
|
// i0 = 0;
|
||||||
// }
|
// }
|
||||||
@ -487,9 +632,9 @@ void advect(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, f
|
|||||||
// if(k0 < 0){
|
// if(k0 < 0){
|
||||||
// k0 = 0;
|
// k0 = 0;
|
||||||
// }
|
// }
|
||||||
if(i1 >= N){
|
// if(i1 >= N){
|
||||||
i1 = N - 1;
|
// i1 = N - 1;
|
||||||
}
|
// }
|
||||||
// if(i1 < 0){
|
// if(i1 < 0){
|
||||||
// i1 = 0;
|
// i1 = 0;
|
||||||
// }
|
// }
|
||||||
@ -507,17 +652,25 @@ void advect(JNIEnv * env, uint32_t chunk_mask, int N, int b, jobjectArray jrd, f
|
|||||||
// }
|
// }
|
||||||
d[IX(i,j,k)] =
|
d[IX(i,j,k)] =
|
||||||
s0*(
|
s0*(
|
||||||
t0*u0*sampleArr[IX(i0,j0,k0)]+
|
t0*u0*d0[IX(i0,j0,k0)]+
|
||||||
t1*u0*sampleArr[IX(i0,j1,k0)]+
|
t1*u0*d0[IX(i0,j1,k0)]+
|
||||||
t0*u1*sampleArr[IX(i0,j0,k1)]+
|
t0*u1*d0[IX(i0,j0,k1)]+
|
||||||
t1*u1*sampleArr[IX(i0,j1,k1)]
|
t1*u1*d0[IX(i0,j1,k1)]
|
||||||
)+
|
)+
|
||||||
s1*(
|
s1*(
|
||||||
t0*u0*sampleArr[IX(i1,j0,k0)]+
|
t0*u0*d0[IX(i1,j0,k0)]+
|
||||||
t1*u0*sampleArr[IX(i1,j1,k0)]+
|
t1*u0*d0[IX(i1,j1,k0)]+
|
||||||
t0*u1*sampleArr[IX(i1,j0,k1)]+
|
t0*u1*d0[IX(i1,j0,k1)]+
|
||||||
t1*u1*sampleArr[IX(i1,j1,k1)]
|
t1*u1*d0[IX(i1,j1,k1)]
|
||||||
);
|
);
|
||||||
|
// if(i == 1 && j == 1 && k == 1 && m == 2){
|
||||||
|
// printf("%d %d %d\n",m,n,o);
|
||||||
|
// printf("%d %d %d %d %d %d\n",i0,i1,j0,j1,k0,k1);
|
||||||
|
// printf("%.2f vs\n",d0[IX(i,j,k)]);
|
||||||
|
// printf("%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n\n",
|
||||||
|
// d0[IX(i0,j0,k0)],d0[IX(i1,j0,k0)],d0[IX(i0,j1,k0)],d0[IX(i1,j1,k0)],
|
||||||
|
// d0[IX(i0,j0,k1)],d0[IX(i1,j0,k1)],d0[IX(i0,j1,k1)],d0[IX(i1,j1,k1)]);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -607,6 +760,7 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
jobject this,
|
jobject this,
|
||||||
jint N,
|
jint N,
|
||||||
jint chunk_mask,
|
jint chunk_mask,
|
||||||
|
jint cx,
|
||||||
jint vector_dir,
|
jint vector_dir,
|
||||||
jobjectArray neighborArray){
|
jobjectArray neighborArray){
|
||||||
int DIM = N;
|
int DIM = N;
|
||||||
@ -821,4 +975,4 @@ JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -66,18 +66,18 @@ public class FluidSim {
|
|||||||
float[] wArrayView = new float[DIM * DIM * DIM];
|
float[] wArrayView = new float[DIM * DIM * DIM];
|
||||||
//these should be set to the
|
//these should be set to the
|
||||||
float[] u0ArrayView = new float[DIM * DIM * DIM];
|
float[] u0ArrayView = new float[DIM * DIM * DIM];
|
||||||
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;
|
int chunkMask = 0;
|
||||||
|
|
||||||
|
|
||||||
static final float DIFFUSION_CONSTANT = 0.00001f;
|
static final float DIFFUSION_CONSTANT = 0.0f;
|
||||||
static final float VISCOSITY_CONSTANT = 0.00001f;
|
static final float VISCOSITY_CONSTANT = 0.0f;
|
||||||
|
|
||||||
static final int LINEARSOLVERTIMES = 10;
|
static final int LINEARSOLVERTIMES = 20;
|
||||||
|
|
||||||
static final float GRAVITY = -1000f;
|
static final float GRAVITY = -100f;
|
||||||
|
|
||||||
public void setup(Vector3i offset){
|
public void setup(Vector3i offset){
|
||||||
//allocate buffers for this chunk
|
//allocate buffers for this chunk
|
||||||
@ -110,17 +110,17 @@ public class FluidSim {
|
|||||||
for(int i = 0; i < DIM; i++){
|
for(int i = 0; i < DIM; i++){
|
||||||
for(int j = 0; j < DIM; j++){
|
for(int j = 0; j < DIM; j++){
|
||||||
for(int k = 0; k < DIM; k++){
|
for(int k = 0; k < DIM; k++){
|
||||||
if(offset.x == 1){
|
if(offset.x == 0 && offset.y == 0 && offset.z == 0){
|
||||||
if(
|
if(
|
||||||
Math.abs(16 - i) < 4 &&
|
Math.abs(16 - i) < 5 &&
|
||||||
Math.abs(j) < 4 &&
|
Math.abs(j) < 5 &&
|
||||||
Math.abs(16 - k) < 4 &&
|
Math.abs(16 - k) < 5 &&
|
||||||
i < 17 && i > 0 &&
|
i < 17 && i > 0 &&
|
||||||
j < 17 && j > 0 &&
|
j < 17 && j > 0 &&
|
||||||
k < 17 && k > 0
|
k < 17 && k > 0
|
||||||
){
|
){
|
||||||
xf.put(1);
|
xf.put(1);
|
||||||
uf.put(-50);
|
uf.put(50);
|
||||||
vf.put(0);
|
vf.put(0);
|
||||||
wf.put(0);
|
wf.put(0);
|
||||||
} else {
|
} else {
|
||||||
@ -131,17 +131,17 @@ public class FluidSim {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(
|
if(
|
||||||
Math.abs(0 - i) < 4 &&
|
Math.abs(0 - i) < 5 &&
|
||||||
Math.abs(j) < 4 &&
|
Math.abs(j) < 5 &&
|
||||||
Math.abs(0 - k) < 4 &&
|
Math.abs(0 - k) < 5 &&
|
||||||
i < 17 && i > 0 &&
|
i < 17 && i > 0 &&
|
||||||
j < 17 && j > 0 &&
|
j < 17 && j > 0 &&
|
||||||
k < 17 && k > 0
|
k < 17 && k > 0
|
||||||
){
|
){
|
||||||
xf.put(1);
|
// xf.put(1);
|
||||||
uf.put(50);
|
// uf.put(50);
|
||||||
vf.put(0);
|
// vf.put(0);
|
||||||
wf.put(rand.nextFloat() * 0.1f);
|
// wf.put(rand.nextFloat() * 0.1f);
|
||||||
} else {
|
} else {
|
||||||
xf.put(0);
|
xf.put(0);
|
||||||
uf.put(0);
|
uf.put(0);
|
||||||
@ -175,13 +175,34 @@ public class FluidSim {
|
|||||||
//
|
//
|
||||||
//Vector stage
|
//Vector stage
|
||||||
solveChunkMask(simArray);
|
solveChunkMask(simArray);
|
||||||
|
// System.out.println("Prior to add");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
addVectorSources(simArray, timestep);
|
addVectorSources(simArray, timestep);
|
||||||
|
// System.out.println("after add");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
swapAllVectorFields(simArray, timestep);
|
swapAllVectorFields(simArray, timestep);
|
||||||
|
// System.out.println("after swap 11");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
solveVectorDiffusion(simArray, timestep);
|
solveVectorDiffusion(simArray, timestep);
|
||||||
solveProjection(simArray, timestep);
|
// System.out.println("after diffuse");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
|
solveProjection(simArray, step, timestep);
|
||||||
|
// System.out.println("after proj 1");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
swapAllVectorFields(simArray, timestep);
|
swapAllVectorFields(simArray, timestep);
|
||||||
|
// System.out.println("after swap 2");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
advectVectorsAcrossBoundaries(simArray, timestep);
|
advectVectorsAcrossBoundaries(simArray, timestep);
|
||||||
solveProjection(simArray, timestep);
|
// System.out.println("after advect");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
|
solveProjection(simArray, step, timestep);
|
||||||
|
// System.out.println("after proj 2");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
|
// System.out.println("\n\n\n\n\n");
|
||||||
|
// if(step == 7){
|
||||||
|
// System.out.println(step);
|
||||||
|
// // System.exit(1);
|
||||||
|
// }
|
||||||
|
|
||||||
//
|
//
|
||||||
//Density stage
|
//Density stage
|
||||||
@ -191,6 +212,19 @@ public class FluidSim {
|
|||||||
swapAllDensityArrays(simArray, timestep);
|
swapAllDensityArrays(simArray, timestep);
|
||||||
advectDensity(simArray, timestep);
|
advectDensity(simArray, timestep);
|
||||||
// mirrorNeighborDensities(simArray, timestep);
|
// mirrorNeighborDensities(simArray, 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++){
|
||||||
|
// //
|
||||||
|
// //Reads out the results of the fluid sim
|
||||||
|
// //
|
||||||
|
// simArray[x][y][z].readDataIntoArrays();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// System.out.println("End density stage");
|
||||||
|
// System.out.println(sumAllDensity(simArray));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -208,6 +242,130 @@ public class FluidSim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static double sumAllDensity(FluidSim[][][] simArray){
|
||||||
|
double rVal = 0;
|
||||||
|
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++){
|
||||||
|
rVal = rVal + simArray[x][y][z].sumDensity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double sumDensity(){
|
||||||
|
double rVal = 0;
|
||||||
|
for(int x = 1; x < DIM - 1; x++){
|
||||||
|
for(int y = 1; y < DIM - 1; y++){
|
||||||
|
for(int z = 1; z < DIM - 1; z++){
|
||||||
|
rVal = rVal + densityArrayView[IX(x,y,z)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double sumU(){
|
||||||
|
double rVal = 0;
|
||||||
|
for(int x = 1; x < DIM - 1; x++){
|
||||||
|
for(int y = 1; y < DIM - 1; y++){
|
||||||
|
for(int z = 1; z < DIM - 1; z++){
|
||||||
|
rVal = rVal + Math.abs(uArrayView[IX(x,y,z)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double sumAllU(FluidSim[][][] simArray){
|
||||||
|
double rVal = 0;
|
||||||
|
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].readDataIntoArrays();
|
||||||
|
rVal = rVal + simArray[x][y][z].sumU();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double sumU0(){
|
||||||
|
double rVal = 0;
|
||||||
|
for(int x = 1; x < DIM - 1; x++){
|
||||||
|
for(int y = 1; y < DIM - 1; y++){
|
||||||
|
for(int z = 1; z < DIM - 1; z++){
|
||||||
|
rVal = rVal + Math.abs(u0ArrayView[IX(x,y,z)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double sumAllU0(FluidSim[][][] simArray){
|
||||||
|
double rVal = 0;
|
||||||
|
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].readDataIntoArrays();
|
||||||
|
rVal = rVal + simArray[x][y][z].sumU0();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double sumV(){
|
||||||
|
double rVal = 0;
|
||||||
|
for(int x = 1; x < DIM - 1; x++){
|
||||||
|
for(int y = 1; y < DIM - 1; y++){
|
||||||
|
for(int z = 1; z < DIM - 1; z++){
|
||||||
|
rVal = rVal + Math.abs(vArrayView[IX(x,y,z)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double sumAllV(FluidSim[][][] simArray){
|
||||||
|
double rVal = 0;
|
||||||
|
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].readDataIntoArrays();
|
||||||
|
rVal = rVal + simArray[x][y][z].sumV();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double sumV0(){
|
||||||
|
double rVal = 0;
|
||||||
|
for(int x = 1; x < DIM - 1; x++){
|
||||||
|
for(int y = 1; y < DIM - 1; y++){
|
||||||
|
for(int z = 1; z < DIM - 1; z++){
|
||||||
|
rVal = rVal + Math.abs(v0ArrayView[IX(x,y,z)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double sumAllV0(FluidSim[][][] simArray){
|
||||||
|
double rVal = 0;
|
||||||
|
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].readDataIntoArrays();
|
||||||
|
rVal = rVal + simArray[x][y][z].sumV0();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
private static void solveChunkMask(FluidSim[][][] simArray){
|
private static void solveChunkMask(FluidSim[][][] simArray){
|
||||||
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++){
|
||||||
@ -239,18 +397,18 @@ public class FluidSim {
|
|||||||
private static void solveVectorDiffusion(FluidSim[][][] simArray, float timestep){
|
private static void solveVectorDiffusion(FluidSim[][][] simArray, float timestep){
|
||||||
//samples u,v,w,u0,v0,w0
|
//samples u,v,w,u0,v0,w0
|
||||||
//sets u,v,w
|
//sets u,v,w
|
||||||
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++){
|
||||||
for(int z = 0; z < simArray[0][0].length; z++){
|
// 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(1, simArray[x][y][z].uVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].vVector);
|
// 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(3, simArray[x][y][z].wVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(1, simArray[x][y][z].uAdditionVector);
|
// 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(2, simArray[x][y][z].vAdditionVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(3, simArray[x][y][z].wAdditionVector);
|
// simArray[x][y][z].copyNeighborsWrapper(3, simArray[x][y][z].wAdditionVector);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||||
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++){
|
||||||
@ -269,29 +427,73 @@ public class FluidSim {
|
|||||||
simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector);
|
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(2, simArray[x][y][z].vVector);
|
||||||
simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
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, float timestep){
|
private static void solveProjection(FluidSim[][][] simArray, int step, float timestep){
|
||||||
//samples u,v,w
|
//samples u,v,w
|
||||||
//sets u0,v0
|
//sets u0,v0
|
||||||
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++){
|
||||||
for(int z = 0; z < simArray[0][0].length; z++){
|
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].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].vVector);
|
simArray[x][y][z].setBoundsToNeighborsWrapper(2, simArray[x][y][z].vVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(3, simArray[x][y][z].wVector);
|
simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(1, simArray[x][y][z].uAdditionVector);
|
simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uAdditionVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].vAdditionVector);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// System.out.println("after swap in proj");
|
||||||
|
// System.out.println(sumAllV(simArray) + " " + sumAllV0(simArray));
|
||||||
|
// simArray[0][0][0].copyNeighborsWrapper(2, 0, simArray[0][0][0].vAdditionVector);
|
||||||
|
// simArray[1][0][0].copyNeighborsWrapper(2, 1, simArray[1][0][0].vAdditionVector);
|
||||||
|
// simArray[0][0][0].readDataIntoArrays();
|
||||||
|
// simArray[1][0][0].readDataIntoArrays();
|
||||||
|
// System.out.println("\n\n\n");
|
||||||
|
// System.out.println("0 0 0");
|
||||||
|
// for(int i = 0; i < 18; i++){
|
||||||
|
// for(int j = 0; j < 18; j++){
|
||||||
|
// System.out.print(simArray[0][0][0].vArrayView[IX(16,i,j)] + " ");
|
||||||
|
// }
|
||||||
|
// System.out.println();
|
||||||
|
// }
|
||||||
|
// System.out.println("\n\n\n");
|
||||||
|
// System.out.println("1 0 0");
|
||||||
|
// for(int i = 0; i < 18; i++){
|
||||||
|
// for(int j = 0; j < 18; j++){
|
||||||
|
// System.out.print(simArray[1][0][0].vArrayView[IX(0,i,j)] + " ");
|
||||||
|
// }
|
||||||
|
// System.out.println();
|
||||||
|
// }
|
||||||
|
// System.out.println("\n\n\n");
|
||||||
|
// for(int i = 0; i < 18; i++){
|
||||||
|
// for(int j = 0; j < 18; j++){
|
||||||
|
// System.out.print(simArray[1][0][0].vArrayView[IX(0,i,j)] - simArray[0][0][0].vArrayView[IX(16,i,j)] + " ");
|
||||||
|
// }
|
||||||
|
// System.out.println();
|
||||||
|
// }
|
||||||
|
// float value = simArray[1][0][0].vArrayView[IX(0,1,1)] - simArray[0][0][0].vArrayView[IX(16,1,1)];
|
||||||
|
// System.out.println(simArray[0][0][0].vArrayView[IX(17,1,1)] + " " + simArray[1][0][0].vArrayView[IX(1,1,1)]);
|
||||||
|
// System.out.println("\n\n\n");
|
||||||
|
// if(step == 1){
|
||||||
|
// System.exit(1);
|
||||||
|
// }
|
||||||
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++){
|
||||||
for(int z = 0; z < simArray[0][0].length; z++){
|
for(int z = 0; z < simArray[0][0].length; z++){
|
||||||
|
// System.out.println("Setup " + x + " " + y + " " + z);
|
||||||
//setup projection across boundaries
|
//setup projection across boundaries
|
||||||
//...
|
//...
|
||||||
//set boundaries appropriately
|
//set boundaries appropriately
|
||||||
@ -300,14 +502,20 @@ public class FluidSim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// System.out.println("after setup proj");
|
||||||
|
// System.out.println(sumAllV(simArray) + " " + sumAllV0(simArray));
|
||||||
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++){
|
||||||
for(int z = 0; z < simArray[0][0].length; z++){
|
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].uAdditionVector);
|
||||||
simArray[x][y][z].setBoundsToNeighborsWrapper(0, simArray[x][y][z].vAdditionVector);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// System.out.println("after bound set 1 in proj");
|
||||||
|
// System.out.println(sumAllV(simArray) + " " + sumAllV0(simArray));
|
||||||
//samples u0, v0
|
//samples u0, v0
|
||||||
//sets u0
|
//sets u0
|
||||||
//these should have just been mirrored in the above
|
//these should have just been mirrored in the above
|
||||||
@ -328,11 +536,15 @@ public class FluidSim {
|
|||||||
for(int y = 0; y < simArray[0].length; y++){
|
for(int y = 0; y < simArray[0].length; y++){
|
||||||
for(int z = 0; z < simArray[0][0].length; z++){
|
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].uAdditionVector);
|
||||||
// simArray[x][y][z].setBoundsToNeighborsWrapper(0, simArray[x][y][z].vAdditionVector);
|
simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].uAdditionVector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// System.out.println("after proj iteration");
|
||||||
|
// System.out.println(sumAllV(simArray) + " " + sumAllV0(simArray));
|
||||||
}
|
}
|
||||||
|
// System.out.println("after proj solver");
|
||||||
|
// System.out.println(sumAllV(simArray) + " " + sumAllV0(simArray));
|
||||||
//samples u,v,w,u0
|
//samples u,v,w,u0
|
||||||
//sets u,v,w
|
//sets u,v,w
|
||||||
//Finalize projection
|
//Finalize projection
|
||||||
@ -345,6 +557,8 @@ public class FluidSim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// System.out.println("after finalize proj");
|
||||||
|
// System.out.println(sumAllV(simArray) + " " + sumAllV0(simArray));
|
||||||
//set boundaries a final time for u,v,w
|
//set boundaries a final time for u,v,w
|
||||||
//...
|
//...
|
||||||
for(int x = 0; x < simArray.length; x++){
|
for(int x = 0; x < simArray.length; x++){
|
||||||
@ -353,9 +567,15 @@ public class FluidSim {
|
|||||||
simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector);
|
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(2, simArray[x][y][z].vVector);
|
||||||
simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].uAdditionVector);
|
simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].vAdditionVector);
|
simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].wAdditionVector);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,11 +603,12 @@ public class FluidSim {
|
|||||||
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++){
|
||||||
for(int z = 0; z < simArray[0][0].length; z++){
|
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(1, x, simArray[x][y][z].uVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].vVector);
|
simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(3, simArray[x][y][z].wVector);
|
simArray[x][y][z].copyNeighborsWrapper(3, x, simArray[x][y][z].wVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(1, simArray[x][y][z].uAdditionVector);
|
simArray[x][y][z].copyNeighborsWrapper(1, x, simArray[x][y][z].uAdditionVector);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(2, simArray[x][y][z].vAdditionVector);
|
simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].vAdditionVector);
|
||||||
|
simArray[x][y][z].copyNeighborsWrapper(2, x, simArray[x][y][z].wAdditionVector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,21 +621,43 @@ public class FluidSim {
|
|||||||
// densityAddition = density[13];
|
// densityAddition = density[13];
|
||||||
// density[13] = tmp;
|
// density[13] = tmp;
|
||||||
//swap u0 <-> u
|
//swap u0 <-> u
|
||||||
tmp = uAdditionVector[13];
|
for(int i = 0; i < 27; i++){
|
||||||
uAdditionVector[13] = uVector[13];
|
tmp = uAdditionVector[i];
|
||||||
uVector[13] = tmp;
|
uAdditionVector[i] = uVector[i];
|
||||||
//swap v0 <-> v
|
uVector[i] = tmp;
|
||||||
tmp = vAdditionVector[13];
|
//swap v0 <-> v
|
||||||
vAdditionVector[13] = vVector[13];
|
tmp = vAdditionVector[i];
|
||||||
vVector[13] = tmp;
|
vAdditionVector[i] = vVector[i];
|
||||||
//swap w0 <-> w
|
vVector[i] = tmp;
|
||||||
tmp = wAdditionVector[13];
|
//swap w0 <-> w
|
||||||
wAdditionVector[13] = wVector[13];
|
tmp = wAdditionVector[i];
|
||||||
wVector[13] = tmp;
|
wAdditionVector[i] = wVector[i];
|
||||||
|
wVector[i] = tmp;
|
||||||
|
}
|
||||||
//...
|
//...
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void advectVectorsAcrossBoundaries(FluidSim[][][] simArray, float timestep){
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// System.out.println("after first bound swap in advect");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
//samples u,v,w,u0,v0,w0
|
//samples u,v,w,u0,v0,w0
|
||||||
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++){
|
||||||
@ -427,6 +670,8 @@ public class FluidSim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// System.out.println("before bound swap in advect");
|
||||||
|
// System.out.println(sumAllU(simArray) + " " + sumAllU0(simArray));
|
||||||
//mirror neighbor data
|
//mirror neighbor data
|
||||||
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++){
|
||||||
@ -434,6 +679,9 @@ public class FluidSim {
|
|||||||
simArray[x][y][z].setBoundsToNeighborsWrapper(1, simArray[x][y][z].uVector);
|
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(2, simArray[x][y][z].vVector);
|
||||||
simArray[x][y][z].setBoundsToNeighborsWrapper(3, simArray[x][y][z].wVector);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -464,17 +712,19 @@ public class FluidSim {
|
|||||||
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++){
|
||||||
for(int z = 0; z < simArray[0][0].length; z++){
|
for(int z = 0; z < simArray[0][0].length; z++){
|
||||||
simArray[x][y][z].copyNeighborsWrapper(0, simArray[x][y][z].density);
|
simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].density);
|
||||||
simArray[x][y][z].copyNeighborsWrapper(0, simArray[x][y][z].densityAddition);
|
simArray[x][y][z].copyNeighborsWrapper(0, x, simArray[x][y][z].densityAddition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void swapDensityArrays(){
|
private void swapDensityArrays(){
|
||||||
ByteBuffer tmp = density[13];
|
for(int i = 0; i < 27; i++){
|
||||||
density[13] = densityAddition[13];
|
ByteBuffer tmp = density[i];
|
||||||
densityAddition[13] = tmp;
|
density[i] = densityAddition[i];
|
||||||
|
densityAddition[i] = tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void diffuseDensity(FluidSim[][][] simArray, float timestep){
|
private static void diffuseDensity(FluidSim[][][] simArray, float timestep){
|
||||||
@ -622,14 +872,6 @@ public class FluidSim {
|
|||||||
}
|
}
|
||||||
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);
|
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);
|
||||||
|
|
||||||
/**
|
|
||||||
* Solve projection system
|
|
||||||
*/
|
|
||||||
// private void setProjectionBordersWrapper(float timestep){
|
|
||||||
// setProjectionBorders(DIM, chunkMask, uVector, vVector, wVector, uAdditionVector, vAdditionVector, wAdditionVector, DIFFUSION_CONSTANT, VISCOSITY_CONSTANT, timestep);
|
|
||||||
// }
|
|
||||||
// private native void setProjectionBorders(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
|
* Does work like subtracting curl from vector field, setting boundaries, etc
|
||||||
*/
|
*/
|
||||||
@ -683,10 +925,11 @@ public class FluidSim {
|
|||||||
* Sets the bounds of the neighbormap to neighbor values if available, otherwise doesn't mess with them.
|
* 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
|
* This is to make sure zeroing out doesn't mess up the sim
|
||||||
*/
|
*/
|
||||||
private void copyNeighborsWrapper(int vectorDir, ByteBuffer[] neighborMap){
|
private void copyNeighborsWrapper(int vectorDir, int x, ByteBuffer[] neighborMap){
|
||||||
copyNeighbors(DIM, chunkMask, vectorDir, neighborMap);
|
copyNeighbors(DIM, chunkMask, x, vectorDir, neighborMap);
|
||||||
}
|
}
|
||||||
private native void copyNeighbors(int DIM_X, int chunkMask, int vectorDir, ByteBuffer[] neighborMap);
|
private native void copyNeighbors(int DIM_X, int chunkMask, int x, int vectorDir, ByteBuffer[] neighborMap);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -759,10 +1002,22 @@ public class FluidSim {
|
|||||||
if(wVector[13].position() > 0){
|
if(wVector[13].position() > 0){
|
||||||
wVector[13].position(0);
|
wVector[13].position(0);
|
||||||
}
|
}
|
||||||
|
if(uAdditionVector[13].position() > 0){
|
||||||
|
uAdditionVector[13].position(0);
|
||||||
|
}
|
||||||
|
if(vAdditionVector[13].position() > 0){
|
||||||
|
vAdditionVector[13].position(0);
|
||||||
|
}
|
||||||
|
if(wAdditionVector[13].position() > 0){
|
||||||
|
wAdditionVector[13].position(0);
|
||||||
|
}
|
||||||
FloatBuffer xFloatView = density[13].asFloatBuffer();
|
FloatBuffer xFloatView = density[13].asFloatBuffer();
|
||||||
FloatBuffer uFloatView = uVector[13].asFloatBuffer();
|
FloatBuffer uFloatView = uVector[13].asFloatBuffer();
|
||||||
FloatBuffer vFloatView = vVector[13].asFloatBuffer();
|
FloatBuffer vFloatView = vVector[13].asFloatBuffer();
|
||||||
FloatBuffer wFloatView = wVector[13].asFloatBuffer();
|
FloatBuffer wFloatView = wVector[13].asFloatBuffer();
|
||||||
|
FloatBuffer u0FloatView = uAdditionVector[13].asFloatBuffer();
|
||||||
|
FloatBuffer v0FloatView = vAdditionVector[13].asFloatBuffer();
|
||||||
|
FloatBuffer w0FloatView = wAdditionVector[13].asFloatBuffer();
|
||||||
for(int i = 0; i < DIM; i++){
|
for(int i = 0; i < DIM; i++){
|
||||||
for(int j = 0; j < DIM; j++){
|
for(int j = 0; j < DIM; j++){
|
||||||
for(int k = 0; k < DIM; k++){
|
for(int k = 0; k < DIM; k++){
|
||||||
@ -770,6 +1025,9 @@ public class FluidSim {
|
|||||||
uArrayView[IX(i,j,k)] = uFloatView.get();
|
uArrayView[IX(i,j,k)] = uFloatView.get();
|
||||||
vArrayView[IX(i,j,k)] = vFloatView.get();
|
vArrayView[IX(i,j,k)] = vFloatView.get();
|
||||||
wArrayView[IX(i,j,k)] = wFloatView.get();
|
wArrayView[IX(i,j,k)] = wFloatView.get();
|
||||||
|
u0ArrayView[IX(i,j,k)] = u0FloatView.get();
|
||||||
|
v0ArrayView[IX(i,j,k)] = v0FloatView.get();
|
||||||
|
w0ArrayView[IX(i,j,k)] = w0FloatView.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -814,7 +1072,9 @@ public class FluidSim {
|
|||||||
for(int i = 0; i < DIM; i++){
|
for(int i = 0; i < DIM; i++){
|
||||||
for(int j = 0; j < DIM; j++){
|
for(int j = 0; j < DIM; j++){
|
||||||
for(int k = 0; k < DIM; k++){
|
for(int k = 0; k < DIM; k++){
|
||||||
|
u0ArrayView[IX(i,j,k)] = 0;
|
||||||
v0ArrayView[IX(i,j,k)] = densityArrayView[IX(i,j,k)] * GRAVITY;
|
v0ArrayView[IX(i,j,k)] = densityArrayView[IX(i,j,k)] * GRAVITY;
|
||||||
|
w0ArrayView[IX(i,j,k)] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public class Main {
|
|||||||
|
|
||||||
public static void main(String args[]){
|
public static void main(String args[]){
|
||||||
|
|
||||||
int dim = 2;
|
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,dim,dim);
|
FluidSim[][][] simArray = initFluidSim(dim,1,dim);
|
||||||
|
|
||||||
Mesh[][][] meshArray = initMeshes(dim,dim,dim,simArray);
|
Mesh[][][] meshArray = initMeshes(dim,1,dim,simArray);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public class Main {
|
|||||||
//
|
//
|
||||||
//Simulate
|
//Simulate
|
||||||
//
|
//
|
||||||
FluidSim.simChunks(simArray,i,0.001f);
|
FluidSim.simChunks(simArray,i,0.01f);
|
||||||
time = time + (System.currentTimeMillis() - lastTime);
|
time = time + (System.currentTimeMillis() - lastTime);
|
||||||
//
|
//
|
||||||
//Remesh
|
//Remesh
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user