cleanup java side somewhat
All checks were successful
studiorailgun/fluid-sim/pipeline/head This commit looks good

This commit is contained in:
unknown 2024-03-10 15:54:07 -04:00
parent 9021125a74
commit a41a848c04
4 changed files with 105 additions and 632 deletions

View File

@ -3,6 +3,7 @@
#include "includes/utilities.h"
#include "includes/chunkmask.h"
#include "includes/electrosphere_FluidSim.h"
#include "includes/mainFunctions.h"
#define DIM 18
#define LINEARSOLVERTIMES 20

View File

@ -17,102 +17,6 @@ extern "C" {
#define electrosphere_FluidSim_LINEARSOLVERTIMES 20L
#undef electrosphere_FluidSim_GRAVITY
#define electrosphere_FluidSim_GRAVITY -100.0f
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_addSourceToVectors
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveVectorDiffuse
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setupProjection
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveProjection
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_finalizeProjection
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_advectVectors
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* Class: electrosphere_FluidSim
* Method: addDensity
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;F)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_addDensity
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jfloat);
/*
* Class: electrosphere_FluidSim
* Method: solveDiffuseDensity
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveDiffuseDensity
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* Class: electrosphere_FluidSim
* Method: advectDensity
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_advectDensity
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* Class: electrosphere_FluidSim
* Method: setBoundsToNeighbors
* Signature: (III[Ljava/nio/ByteBuffer;)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setBoundsToNeighbors
(JNIEnv *, jobject, jint, jint, jint, jobjectArray);
/*
* Class: electrosphere_FluidSim
* Method: copyNeighbors
* Signature: (IIII[Ljava/nio/ByteBuffer;)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
(JNIEnv *, jobject, jint, jint, jint, jint, jobjectArray);
/*
* Class: electrosphere_FluidSim
* Method: simulate

View File

@ -0,0 +1,102 @@
#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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_addSourceToVectors
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveVectorDiffuse
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setupProjection
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveProjection
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_finalizeProjection
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* 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
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_advectVectors
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* Class: electrosphere_FluidSim
* Method: addDensity
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;F)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_addDensity
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jfloat);
/*
* Class: electrosphere_FluidSim
* Method: solveDiffuseDensity
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_solveDiffuseDensity
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* Class: electrosphere_FluidSim
* Method: advectDensity
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_advectDensity
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jobjectArray, jfloat, jfloat, jfloat);
/*
* Class: electrosphere_FluidSim
* Method: setBoundsToNeighbors
* Signature: (III[Ljava/nio/ByteBuffer;)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_setBoundsToNeighbors
(JNIEnv *, jobject, jint, jint, jint, jobjectArray);
/*
* Class: electrosphere_FluidSim
* Method: copyNeighbors
* Signature: (IIII[Ljava/nio/ByteBuffer;)V
*/
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_copyNeighbors
(JNIEnv *, jobject, jint, jint, jint, jint, jobjectArray);
#endif

View File

@ -184,25 +184,9 @@ public class FluidSim {
lastTime = GLFW.glfwGetTime();
//
//Vector stage
//simulate
simulateWrapper(chunksToSim,timestep);
// 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);
//clock
time = time + (GLFW.glfwGetTime() - lastTime);
i++;
if(i == 100){
@ -350,524 +334,6 @@ public class FluidSim {
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);
}
}
}
}
// /**
// * 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);
/**