Compare commits
No commits in common. "master" and "migrate-multichunk-to-c" have entirely different histories.
master
...
migrate-mu
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,6 +5,7 @@
|
||||
/.settings
|
||||
/.classpath
|
||||
/.project
|
||||
/.vscode
|
||||
/shared-folder
|
||||
/shared-folder/**
|
||||
/chunks
|
||||
/src/main/c/lib/**
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "src/main/c/lib/stb"]
|
||||
path = src/main/c/lib/stb
|
||||
url = https://github.com/nothings/stb.git
|
||||
22
.vscode/c_cpp_properties.json
vendored
22
.vscode/c_cpp_properties.json
vendored
@ -1,22 +0,0 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Win32",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"C:/Program Files/Eclipse Adoptium/jdk-21.0.5.11-hotspot/include/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE"
|
||||
],
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/ProgramData/mingw64/mingw64/bin/gcc.exe",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "windows-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
6
.vscode/extensions.json
vendored
6
.vscode/extensions.json
vendored
@ -1,6 +0,0 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"ms-vscode.cpptools-extension-pack",
|
||||
"vscjava.vscode-java-pack"
|
||||
]
|
||||
}
|
||||
20
.vscode/launch.json
vendored
20
.vscode/launch.json
vendored
@ -1,20 +0,0 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Launch Java Program",
|
||||
"request": "launch",
|
||||
"mainClass": "electrosphere.Main",
|
||||
"preLaunchTask": "compileNoSteps",
|
||||
"vmArgs": "-Djava.library.path=./shared-folder"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Launch Java Program (SAVE CHUNKS TO DISK)",
|
||||
"request": "launch",
|
||||
"mainClass": "electrosphere.Main",
|
||||
"preLaunchTask": "compileWithSteps",
|
||||
"vmArgs": "-Djava.library.path=./shared-folder"
|
||||
}
|
||||
]
|
||||
}
|
||||
21
.vscode/settings.json
vendored
21
.vscode/settings.json
vendored
@ -1,21 +0,0 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"files.associations": {
|
||||
"stdio.h": "c",
|
||||
"jni.h": "c",
|
||||
"immintrin.h": "c",
|
||||
"stdint.h": "c",
|
||||
"utilities.h": "c",
|
||||
"chunkmask.h": "c",
|
||||
"pthread.h": "c",
|
||||
"semaphore.h": "c",
|
||||
"libfluidsim.h": "c",
|
||||
"stb_ds.h": "c",
|
||||
"threadpool.h": "c",
|
||||
"electrosphere_fluidsim.h": "c",
|
||||
"type_traits": "c",
|
||||
"mainfunctions.h": "c",
|
||||
"chunk.h": "c",
|
||||
"simulation.h": "c"
|
||||
}
|
||||
}
|
||||
15
.vscode/tasks.json
vendored
15
.vscode/tasks.json
vendored
@ -1,15 +0,0 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "compileWithSteps",
|
||||
"type": "shell",
|
||||
"command": "SAVE_STEPS=1 ./src/main/c/compile.sh",
|
||||
},
|
||||
{
|
||||
"label": "compileNoSteps",
|
||||
"type": "shell",
|
||||
"command": "SAVE_STEPS=0 ./src/main/c/compile.sh",
|
||||
}
|
||||
]
|
||||
}
|
||||
11
README.md
11
README.md
@ -1,11 +0,0 @@
|
||||
# Fluid Sim
|
||||
|
||||
|
||||
|
||||
## How to run
|
||||
|
||||
Clone with `git clone --recurse-submodules git@git.austinwhoover.com:studiorailgun/fluid-sim.git`
|
||||
|
||||
Then run with VSCode debug plugin
|
||||
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
search_dir=./chunks
|
||||
for entry in "$search_dir"/*
|
||||
do
|
||||
if ! diff "/c/Users/satellite/Documents/fluid-sim/$entry" "/c/Users/satellite/Documents/fluid-sim-the-golden-code/$entry" > /dev/null;
|
||||
then
|
||||
echo "“$entry differs"
|
||||
fi
|
||||
done
|
||||
echo "done!"
|
||||
@ -73,9 +73,6 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>bash</executable>
|
||||
<environmentVariables>
|
||||
<SAVE_STEPS>0</SAVE_STEPS>
|
||||
</environmentVariables>
|
||||
<arguments>
|
||||
<argument>./src/main/c/compile.sh</argument>
|
||||
</arguments>
|
||||
@ -83,10 +80,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.2.5</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
@ -110,56 +103,6 @@
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.10.2</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>junit-platform-engine</artifactId>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>apiguardian-api</artifactId>
|
||||
<groupId>org.apiguardian</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-runner</artifactId>
|
||||
<version>1.10.2</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>junit</artifactId>
|
||||
<groupId>junit</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>junit-platform-launcher</artifactId>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>junit-platform-suite-api</artifactId>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>junit-platform-suite-commons</artifactId>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>apiguardian-api</artifactId>
|
||||
<groupId>org.apiguardian</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
'sleep' chunks if there are no massive velocity swings for ~100 frames
|
||||
- unsleep as soon as new density or velocity is added
|
||||
|
||||
VVV These two may not work because the projection phase currently iterates over all cells with avx instructions
|
||||
it also may generally not work as fast moving water basically works by having empty cells query area that already has water (so maybe no sleeping air)
|
||||
'sleep' individual cells that are full of water and fully surrounded by water
|
||||
'sleep' terrain cells
|
||||
'sleep' "inactive" cells
|
||||
- When reading data back into java, while iterating over each cell check if they've changed value
|
||||
- If not, add 1 to an accumulating array alongside the other ones (d, u, etc)
|
||||
- In C, if the accumulating array is >100 or some threshold, skip the cell
|
||||
- If a force gets added java side that is greater than some threshold, set all accumulating array to 0
|
||||
|
||||
multigrid method for projection code
|
||||
|
||||
intelligent neighbor awakening --
|
||||
If a neighbor is asleep (say a neighbor full of air above this cell),
|
||||
do not simulate that neighbor at all
|
||||
Instead poll the currently awake cell for large velocity spikes in the direction of the neighbor
|
||||
If there is a large spike, awake the neighbor cell
|
||||
if a neighbor is awoken, the simulator should go back through and simulate for that chunk as well (idk if this is possible)
|
||||
|
||||
|
||||
use avx bitmasking for handling terrain in projection code ???
|
||||
|
||||
|
||||
22
pom.xml
22
pom.xml
@ -64,7 +64,6 @@
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!--lwjgl-->
|
||||
<dependency>
|
||||
<groupId>org.lwjgl</groupId>
|
||||
<artifactId>lwjgl</artifactId>
|
||||
@ -110,19 +109,6 @@
|
||||
<artifactId>lwjgl-opengl</artifactId>
|
||||
<classifier>${lwjgl.natives}</classifier>
|
||||
</dependency>
|
||||
<!--junit-->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.10.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-runner</artifactId>
|
||||
<version>1.10.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -195,9 +181,6 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>bash</executable>
|
||||
<environmentVariables>
|
||||
<SAVE_STEPS>0</SAVE_STEPS>
|
||||
</environmentVariables>
|
||||
<arguments>
|
||||
<argument>./src/main/c/compile.sh</argument>
|
||||
</arguments>
|
||||
@ -205,11 +188,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.2.5</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
102
src/main/c/chunkmask.c
Normal file
102
src/main/c/chunkmask.c
Normal file
@ -0,0 +1,102 @@
|
||||
#include <jni.h>
|
||||
#include <stdint.h>
|
||||
#include "includes/utilities.h"
|
||||
#include "includes/chunkmask.h"
|
||||
|
||||
uint32_t matrix_transform(JNIEnv * env, jobjectArray jrx);
|
||||
|
||||
/**
|
||||
* Calculates the bitmask for available chunks for the provided chunk's neighbor array
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_electrosphere_FluidSim_calculateChunkMask(JNIEnv * env, jobject this, jobjectArray jrx){
|
||||
return matrix_transform(env,jrx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a mask that represents all nearby chunks that are actually accessible and exist
|
||||
*/
|
||||
uint32_t matrix_transform(JNIEnv * env, jobjectArray jrx){
|
||||
|
||||
//The returned value, an availability mask that contains the availability of each neighbor chunk
|
||||
uint32_t rVal = 0;
|
||||
|
||||
//Add to maks for initial chunks
|
||||
for(int i = 0; i < CENTER_LOC; i++){
|
||||
if((*env)->GetObjectArrayElement(env,jrx,i)!=NULL){
|
||||
rVal = rVal + 1;
|
||||
}
|
||||
rVal = rVal << 1;
|
||||
}
|
||||
//add 1 for center chunk because we already have that
|
||||
rVal = rVal + 1;
|
||||
rVal = rVal << 1;
|
||||
//continue on for remaining chunks
|
||||
for(int i = CENTER_LOC+1; i < 27; i++){
|
||||
if((*env)->GetObjectArrayElement(env,jrx,i)!=NULL){
|
||||
rVal = rVal + 1;
|
||||
}
|
||||
if(i < 26){
|
||||
rVal = rVal << 1;
|
||||
}
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
const uint32_t CHUNK_INDEX_ARR[] = {
|
||||
CHUNK_000, CHUNK_100, CHUNK_200,
|
||||
CHUNK_010, CHUNK_110, CHUNK_210,
|
||||
CHUNK_020, CHUNK_120, CHUNK_220,
|
||||
|
||||
CHUNK_001, CHUNK_101, CHUNK_201,
|
||||
CHUNK_011, CHUNK_111, CHUNK_211,
|
||||
CHUNK_021, CHUNK_121, CHUNK_221,
|
||||
|
||||
CHUNK_002, CHUNK_102, CHUNK_202,
|
||||
CHUNK_012, CHUNK_112, CHUNK_212,
|
||||
CHUNK_022, CHUNK_122, CHUNK_222,
|
||||
};
|
||||
|
||||
|
||||
//control offsetting the advect sampler location if a valid neighbor chunk is hit
|
||||
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,
|
||||
};
|
||||
|
||||
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,
|
||||
0, 0, 0,
|
||||
-1, -1, -1,
|
||||
};
|
||||
|
||||
const char CHUNK_NORMALIZE_W[] = {
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
|
||||
0, 0, 0,
|
||||
0, 0, 0,
|
||||
0, 0, 0,
|
||||
|
||||
-1, -1, -1,
|
||||
-1, -1, -1,
|
||||
-1, -1, -1,
|
||||
};
|
||||
@ -1,7 +1,5 @@
|
||||
cd ./src/main/c
|
||||
|
||||
echo "SAVE STEPS $SAVE_STEPS"
|
||||
|
||||
LIB_ENDING=".so"
|
||||
BASE_INCLUDE_DIR=""
|
||||
OS_INCLUDE_DIR=""
|
||||
@ -44,27 +42,22 @@ rm -f ./*.dll
|
||||
|
||||
#compile object files
|
||||
# COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow"
|
||||
# INPUT_FILES="./src/densitystep.c"
|
||||
# INPUT_FILES="./densitystep.c"
|
||||
# OUTPUT_FILE="./densitystep.o"
|
||||
# gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
||||
|
||||
# COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow"
|
||||
# INPUT_FILES="./src/velocitystep.c"
|
||||
# INPUT_FILES="./velocitystep.c"
|
||||
# OUTPUT_FILE="./velocitystep.o"
|
||||
# gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
||||
|
||||
# COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow"
|
||||
# INPUT_FILES="./src/chunkmask.c"
|
||||
# INPUT_FILES="./chunkmask.c"
|
||||
# OUTPUT_FILE="./chunkmask.o"
|
||||
# gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
||||
|
||||
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -DSAVE_STEPS=$SAVE_STEPS"
|
||||
INPUT_FILES="./src/javainterface.c"
|
||||
OUTPUT_FILE="./javainterface.o"
|
||||
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
||||
|
||||
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -DSAVE_STEPS=$SAVE_STEPS"
|
||||
INPUT_FILES="./src/fluidsim.c"
|
||||
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow"
|
||||
INPUT_FILES="./fluidsim.c"
|
||||
OUTPUT_FILE="./fluidsim.o"
|
||||
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
|
||||
|
||||
@ -73,7 +66,7 @@ gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OU
|
||||
#compile shared object file
|
||||
OUTPUT_FILE="libfluidsim$LIB_ENDING"
|
||||
COMPILE_FLAGS="-shared"
|
||||
INPUT_FILES="fluidsim.o javainterface.o"
|
||||
INPUT_FILES="fluidsim.o"
|
||||
gcc $COMPILE_FLAGS $INPUT_FILES -o $OUTPUT_FILE
|
||||
|
||||
#move to resources
|
||||
|
||||
@ -2,33 +2,39 @@
|
||||
#include <immintrin.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../includes/utilities.h"
|
||||
#include "../includes/chunkmask.h"
|
||||
#include "includes/utilities.h"
|
||||
#include "includes/chunkmask.h"
|
||||
|
||||
void advectDensity(uint32_t chunk_mask, int N, int b, float ** d, float ** d0, float * u, float * v, float * w, float dt);
|
||||
|
||||
/**
|
||||
* Adds density to the density array
|
||||
*/
|
||||
static inline void addDensity(
|
||||
/*
|
||||
* Class: electrosphere_FluidSim
|
||||
* Method: addDensity
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;F)V
|
||||
*/
|
||||
void Java_electrosphere_FluidSim_addDensity
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
float ** d,
|
||||
float ** d0,
|
||||
float dt
|
||||
){
|
||||
float dt){
|
||||
int i;
|
||||
int size=N*N*N;
|
||||
float * x = GET_ARR_RAW(d,CENTER_LOC);
|
||||
float * s = GET_ARR_RAW(d0,CENTER_LOC);
|
||||
float * x = GET_ARR_RAW(env,d,CENTER_LOC);
|
||||
float * s = GET_ARR_RAW(env,d0,CENTER_LOC);
|
||||
for(i=0; i<size; i++){
|
||||
x[i] += dt*s[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A single iteration of the jacobi to solve density diffusion
|
||||
* Class: electrosphere_FluidSim
|
||||
* Method: solveDiffuseDensity
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||
*/
|
||||
static inline void solveDiffuseDensity(
|
||||
void Java_electrosphere_FluidSim_solveDiffuseDensity
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
float ** d,
|
||||
@ -38,13 +44,12 @@ static inline void solveDiffuseDensity(
|
||||
float ** jrw,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
float dt){
|
||||
float a=dt*DIFFUSION_CONST*N*N*N;
|
||||
float c=1+6*a;
|
||||
int i, j, k, l, m;
|
||||
float * x = GET_ARR_RAW(d,CENTER_LOC);
|
||||
float * x0 = GET_ARR_RAW(d0,CENTER_LOC);
|
||||
float * x = GET_ARR_RAW(env,d,CENTER_LOC);
|
||||
float * x0 = GET_ARR_RAW(env,d0,CENTER_LOC);
|
||||
|
||||
__m256 aScalar = _mm256_set1_ps(a);
|
||||
__m256 cScalar = _mm256_set1_ps(c);
|
||||
@ -76,27 +81,41 @@ static inline void solveDiffuseDensity(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Advects the density based on the vectors
|
||||
*/
|
||||
static inline void advectDensity(uint32_t chunk_mask, int N, float ** d, float ** d0, float ** ur, float ** vr, float ** wr, float dt){
|
||||
/*
|
||||
* Class: electrosphere_FluidSim
|
||||
* Method: advectDensity
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||
*/
|
||||
void Java_electrosphere_FluidSim_advectDensity
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
float ** d,
|
||||
float ** d0,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt){
|
||||
advectDensity(chunk_mask,N,3,d,d0,GET_ARR_RAW(env,jru,CENTER_LOC),GET_ARR_RAW(env,jrv,CENTER_LOC),GET_ARR_RAW(env,jrw,CENTER_LOC),dt);
|
||||
}
|
||||
|
||||
void advectDensity(uint32_t chunk_mask, int N, int b, float ** d, float ** d0, float * u, float * v, float * w, float dt){
|
||||
int i, j, k, i0, j0, k0, i1, j1, k1;
|
||||
int m,n,o;
|
||||
float x, y, z, s0, t0, s1, t1, u1, u0, dtx,dty,dtz;
|
||||
|
||||
dtx=dty=dtz=dt*N;
|
||||
|
||||
float * center_d = GET_ARR_RAW(d,CENTER_LOC);
|
||||
float * center_d0 = GET_ARR_RAW(d0,CENTER_LOC);
|
||||
float * center_d = GET_ARR_RAW(env,d,CENTER_LOC);
|
||||
|
||||
float * u = GET_ARR_RAW(ur,CENTER_LOC);
|
||||
float * v = GET_ARR_RAW(vr,CENTER_LOC);
|
||||
float * w = GET_ARR_RAW(wr,CENTER_LOC);
|
||||
float * center_d0 = GET_ARR_RAW(env,d0,CENTER_LOC);
|
||||
|
||||
for(k=1; k<N-1; k++){
|
||||
for(j=1; j<N-1; j++){
|
||||
for(i=1; i<N-1; i++){
|
||||
center_d0 = GET_ARR_RAW(d0,CENTER_LOC);
|
||||
center_d0 = GET_ARR_RAW(env,d0,CENTER_LOC);
|
||||
//calculate location to pull from
|
||||
x = i-dtx*u[IX(i,j,k)];
|
||||
y = j-dty*v[IX(i,j,k)];
|
||||
778
src/main/c/fluidsim.c
Normal file
778
src/main/c/fluidsim.c
Normal file
@ -0,0 +1,778 @@
|
||||
#include <jni.h>
|
||||
#include <stdint.h>
|
||||
#include "includes/utilities.h"
|
||||
#include "includes/chunkmask.h"
|
||||
#include "includes/electrosphere_FluidSim.h"
|
||||
#include "includes/mainFunctions.h"
|
||||
|
||||
#include "./chunkmask.c"
|
||||
#include "./velocitystep.c"
|
||||
#include "./densitystep.c"
|
||||
|
||||
//include stb ds
|
||||
#define STB_DS_IMPLEMENTATION
|
||||
#include "./lib/stb/stb_ds.h"
|
||||
|
||||
#define DIM 18
|
||||
#define LINEARSOLVERTIMES 20
|
||||
|
||||
#define DIFFUSION_CONSTANT 0.000001
|
||||
#define VISCOSITY_CONSTANT 0.000001
|
||||
|
||||
/**
|
||||
* A chunk
|
||||
*/
|
||||
typedef struct {
|
||||
jobject jchunk;
|
||||
float * d[27];
|
||||
float * d0[27];
|
||||
float * u[27];
|
||||
float * v[27];
|
||||
float * w[27];
|
||||
float * u0[27];
|
||||
float * v0[27];
|
||||
float * w0[27];
|
||||
jobjectArray jd;
|
||||
jobjectArray jd0;
|
||||
jobjectArray ju;
|
||||
jobjectArray jv;
|
||||
jobjectArray jw;
|
||||
jobjectArray ju0;
|
||||
jobjectArray jv0;
|
||||
jobjectArray jw0;
|
||||
int chunkMask;
|
||||
} Chunk;
|
||||
|
||||
//all chunks
|
||||
Chunk ** chunks = NULL;
|
||||
|
||||
#define getChunk(i) (*env)->CallObjectMethod(env,chunkList,jListGet,i)
|
||||
#define getBuffArr(buffId) (*env)->GetObjectField(env,chunkJRaw,buffId)
|
||||
#define setBuffArr(buffId,value) (*env)->SetObjectField(env,chunkJRaw,buffId,value)
|
||||
|
||||
//jni help:
|
||||
//https://stackoverflow.com/questions/39823375/clarification-about-getfieldid
|
||||
|
||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_simulate(
|
||||
JNIEnv * env,
|
||||
jclass class,
|
||||
jobject chunkList,
|
||||
jfloat timestep
|
||||
){
|
||||
jclass listClass = (*env)->FindClass(env,"java/util/List");
|
||||
jclass fluidSimClass = (*env)->FindClass(env,"electrosphere/FluidSim");
|
||||
//JNIEnv *env, jclass clazz, const char *name, const char *sig
|
||||
jmethodID jListSize = (*env)->GetMethodID(env, listClass, "size", "()I");
|
||||
jmethodID jListGet = (*env)->GetMethodID(env, listClass, "get", "(I)Ljava/lang/Object;");
|
||||
jmethodID jListAdd = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z");
|
||||
|
||||
//ByteBuffer[]
|
||||
jfieldID dJId = (*env)->GetFieldID(env,fluidSimClass,"density","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID d0JId = (*env)->GetFieldID(env,fluidSimClass,"densityAddition","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID uJId = (*env)->GetFieldID(env,fluidSimClass,"uVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID vJId = (*env)->GetFieldID(env,fluidSimClass,"vVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID wJId = (*env)->GetFieldID(env,fluidSimClass,"wVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID u0JId = (*env)->GetFieldID(env,fluidSimClass,"uAdditionVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID v0JId = (*env)->GetFieldID(env,fluidSimClass,"vAdditionVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID w0JId = (*env)->GetFieldID(env,fluidSimClass,"wAdditionVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID chunkmaskJId = (*env)->GetFieldID(env,fluidSimClass,"chunkMask","I");
|
||||
|
||||
//the number of chunks
|
||||
int numChunks = (*env)->CallIntMethod(env,chunkList,jListSize);
|
||||
|
||||
//current chunk (this)
|
||||
jobject chunkJRaw;
|
||||
//current chunk fields
|
||||
jobjectArray jd;
|
||||
jobjectArray jd0;
|
||||
jobjectArray u;
|
||||
jobjectArray v;
|
||||
jobjectArray w;
|
||||
jobjectArray u0;
|
||||
jobjectArray v0;
|
||||
jobjectArray w0;
|
||||
int chunkMask;
|
||||
|
||||
//solve chunk mask
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
chunkJRaw = getChunk(i);
|
||||
chunkMask = Java_electrosphere_FluidSim_calculateChunkMask(env,chunkJRaw,getBuffArr(dJId));
|
||||
(*env)->SetIntField(env,chunkJRaw,chunkmaskJId,chunkMask);
|
||||
|
||||
Chunk * newChunk;
|
||||
if(i >= stbds_arrlen(chunks)){
|
||||
// printf("allocate chunk %d\n",i);
|
||||
// fflush(stdout);
|
||||
newChunk = (Chunk *)malloc(sizeof(Chunk));
|
||||
// printf("new chunk %p\n",newChunk);
|
||||
// fflush(stdout);
|
||||
stbds_arrput(chunks,newChunk);
|
||||
// printf("new chunk %p\n",chunks[i]);
|
||||
// fflush(stdout);
|
||||
} else {
|
||||
newChunk = chunks[i];
|
||||
// printf("get chunk %d: %p\n",i,newChunk);
|
||||
// fflush(stdout);
|
||||
}
|
||||
jd = (*env)->GetObjectField(env,chunkJRaw,dJId);
|
||||
jd0 = (*env)->GetObjectField(env,chunkJRaw,d0JId);
|
||||
u = (*env)->GetObjectField(env,chunkJRaw,uJId);
|
||||
v = (*env)->GetObjectField(env,chunkJRaw,vJId);
|
||||
w = (*env)->GetObjectField(env,chunkJRaw,wJId);
|
||||
u0 = (*env)->GetObjectField(env,chunkJRaw,u0JId);
|
||||
v0 = (*env)->GetObjectField(env,chunkJRaw,v0JId);
|
||||
w0 = (*env)->GetObjectField(env,chunkJRaw,w0JId);
|
||||
newChunk->jd = jd;
|
||||
newChunk->jd0 = jd0;
|
||||
newChunk->ju = u;
|
||||
newChunk->jv = v;
|
||||
newChunk->jw = w;
|
||||
newChunk->ju0 = u0;
|
||||
newChunk->jv0 = v0;
|
||||
newChunk->jw0 = w0;
|
||||
newChunk->jchunk = chunkJRaw;
|
||||
newChunk->chunkMask = chunkMask;
|
||||
for(int j = 0; j < 27; j++){
|
||||
if((chunkMask & CHUNK_INDEX_ARR[j]) > 0){
|
||||
newChunk->d[j] = GET_ARR(env,jd,j);
|
||||
newChunk->d0[j] = GET_ARR(env,jd0,j);
|
||||
newChunk->u[j] = GET_ARR(env,u,j);
|
||||
newChunk->v[j] = GET_ARR(env,v,j);
|
||||
newChunk->w[j] = GET_ARR(env,w,j);
|
||||
newChunk->u0[j] = GET_ARR(env,u0,j);
|
||||
newChunk->v0[j] = GET_ARR(env,v0,j);
|
||||
newChunk->w0[j] = GET_ARR(env,w0,j);
|
||||
}
|
||||
}
|
||||
// for(int j = 0; j < 27; j++){
|
||||
// newChunk.d[j] = GET_ARR(env,d,j);
|
||||
// }
|
||||
// chunks[i].d0 = getBuffArr(d0JId);
|
||||
// chunks[i].u = getBuffArr(uJId);
|
||||
// chunks[i].v = getBuffArr(vJId);
|
||||
// chunks[i].w = getBuffArr(wJId);
|
||||
// chunks[i].u0 = getBuffArr(u0JId);
|
||||
// chunks[i].v0 = getBuffArr(v0JId);
|
||||
// chunks[i].w0 = getBuffArr(w0JId);
|
||||
}
|
||||
|
||||
// printf("%p\n",chunks[0].d);
|
||||
|
||||
//solve chunk mask
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
//old assignments
|
||||
// chunkJRaw = getChunk(i);
|
||||
// chunkMask = (*env)->GetIntField(env,chunkJRaw,chunkmaskJId);
|
||||
// d = getBuffArr(dJId);
|
||||
// d0 = getBuffArr(d0JId);
|
||||
// u = getBuffArr(uJId);
|
||||
// v = getBuffArr(vJId);
|
||||
// w = getBuffArr(wJId);
|
||||
// u0 = getBuffArr(u0JId);
|
||||
// v0 = getBuffArr(v0JId);
|
||||
// w0 = getBuffArr(w0JId);
|
||||
Java_electrosphere_FluidSim_addSourceToVectors(
|
||||
DIM,
|
||||
chunkMask,
|
||||
currentChunk->u,
|
||||
currentChunk->v,
|
||||
currentChunk->w,
|
||||
currentChunk->u0,
|
||||
currentChunk->v0,
|
||||
currentChunk->w0,
|
||||
DIFFUSION_CONSTANT,
|
||||
VISCOSITY_CONSTANT,
|
||||
timestep
|
||||
);
|
||||
}
|
||||
//swap all vector fields
|
||||
{
|
||||
//swap vector fields
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
|
||||
float * tmpArr;
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->u[j];
|
||||
currentChunk->u[j] = currentChunk->u0[j];
|
||||
currentChunk->u0[j] = tmpArr;
|
||||
}
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->v[j];
|
||||
currentChunk->v[j] = currentChunk->v0[j];
|
||||
currentChunk->v0[j] = tmpArr;
|
||||
}
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->w[j];
|
||||
currentChunk->w[j] = currentChunk->w0[j];
|
||||
currentChunk->w0[j] = tmpArr;
|
||||
}
|
||||
}
|
||||
//copy neighbors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
}
|
||||
//solve vector diffusion
|
||||
{
|
||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||
//solve vector diffusion
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
Java_electrosphere_FluidSim_solveVectorDiffuse(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||
}
|
||||
}
|
||||
}
|
||||
//solve projection
|
||||
{
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||
}
|
||||
//setup projection
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
Java_electrosphere_FluidSim_setupProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||
}
|
||||
//samples u0, v0
|
||||
//sets u0
|
||||
//these should have just been mirrored in the above
|
||||
//
|
||||
//Perform main projection solver
|
||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
Java_electrosphere_FluidSim_solveProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
}
|
||||
}
|
||||
//samples u,v,w,u0
|
||||
//sets u,v,w
|
||||
//Finalize projection
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
Java_electrosphere_FluidSim_finalizeProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
//set boundaries a final time for u,v,w
|
||||
//...
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
}
|
||||
//swap all vector fields
|
||||
{
|
||||
//swap vector fields
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
|
||||
float * tmpArr;
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->u[j];
|
||||
currentChunk->u[j] = currentChunk->u0[j];
|
||||
currentChunk->u0[j] = tmpArr;
|
||||
}
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->v[j];
|
||||
currentChunk->v[j] = currentChunk->v0[j];
|
||||
currentChunk->v0[j] = tmpArr;
|
||||
}
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->w[j];
|
||||
currentChunk->w[j] = currentChunk->w0[j];
|
||||
currentChunk->w0[j] = tmpArr;
|
||||
}
|
||||
}
|
||||
//copy neighbors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
}
|
||||
//advect vectors across boundaries
|
||||
{
|
||||
//update border arrs
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
//advect
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
Java_electrosphere_FluidSim_advectVectors(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
//update neighbor arr
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||
}
|
||||
}
|
||||
//solve projection
|
||||
{
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||
}
|
||||
//setup projection
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
Java_electrosphere_FluidSim_setupProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||
}
|
||||
//samples u0, v0
|
||||
//sets u0
|
||||
//these should have just been mirrored in the above
|
||||
//
|
||||
//Perform main projection solver
|
||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
Java_electrosphere_FluidSim_solveProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
}
|
||||
}
|
||||
//samples u,v,w,u0
|
||||
//sets u,v,w
|
||||
//Finalize projection
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
Java_electrosphere_FluidSim_finalizeProjection(DIM,chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
//set boundaries a final time for u,v,w
|
||||
//...
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
u0 = currentChunk->ju0;
|
||||
v0 = currentChunk->jv0;
|
||||
w0 = currentChunk->jw0;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
//add density
|
||||
{
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
Java_electrosphere_FluidSim_addDensity(DIM,chunkMask,currentChunk->d,currentChunk->d0,timestep);
|
||||
}
|
||||
}
|
||||
//swap all density arrays
|
||||
{
|
||||
//swap vector fields
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
|
||||
float * tmpArr;
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->d[j];
|
||||
currentChunk->d[j] = currentChunk->d0[j];
|
||||
currentChunk->d0[j] = tmpArr;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
jd = currentChunk->jd;
|
||||
jd0 = currentChunk->jd0;
|
||||
copyNeighborsRaw(DIM,chunkMask,0,0,currentChunk->d);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,0,currentChunk->d0);
|
||||
}
|
||||
}
|
||||
//diffuse density
|
||||
{
|
||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
u = currentChunk->ju;
|
||||
v = currentChunk->jv;
|
||||
w = currentChunk->jw;
|
||||
Java_electrosphere_FluidSim_solveDiffuseDensity(DIM,chunkMask,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,0,currentChunk->d);
|
||||
}
|
||||
}
|
||||
}
|
||||
//swap all density arrays
|
||||
{
|
||||
//swap vector fields
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
float * tmpArr;
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->d[j];
|
||||
currentChunk->d[j] = currentChunk->d0[j];
|
||||
currentChunk->d0[j] = tmpArr;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
copyNeighborsRaw(DIM,chunkMask,0,0,currentChunk->d);
|
||||
copyNeighborsRaw(DIM,chunkMask,0,0,currentChunk->d0);
|
||||
}
|
||||
}
|
||||
//advect density
|
||||
{
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
Java_electrosphere_FluidSim_advectDensity(DIM,chunkMask,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
}
|
||||
//mirror densities
|
||||
{
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
chunkJRaw = currentChunk->jchunk;
|
||||
chunkMask = currentChunk->chunkMask;
|
||||
setBoundsToNeighborsRaw(DIM,chunkMask,0,currentChunk->d);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
#ifndef CHUNK_H
|
||||
#define CHUNK_H
|
||||
|
||||
/**
|
||||
* A chunk
|
||||
*/
|
||||
typedef struct {
|
||||
float * d[27];
|
||||
float * d0[27];
|
||||
float * u[27];
|
||||
float * v[27];
|
||||
float * w[27];
|
||||
float * u0[27];
|
||||
float * v0[27];
|
||||
float * w0[27];
|
||||
int chunkMask;
|
||||
} Chunk;
|
||||
|
||||
#endif
|
||||
@ -10,13 +10,13 @@ extern "C" {
|
||||
#undef electrosphere_FluidSim_DIM
|
||||
#define electrosphere_FluidSim_DIM 18L
|
||||
#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
|
||||
#define electrosphere_FluidSim_VISCOSITY_CONSTANT 1.0E-5f
|
||||
#define electrosphere_FluidSim_VISCOSITY_CONSTANT 0.0f
|
||||
#undef electrosphere_FluidSim_LINEARSOLVERTIMES
|
||||
#define electrosphere_FluidSim_LINEARSOLVERTIMES 20L
|
||||
#undef electrosphere_FluidSim_GRAVITY
|
||||
#define electrosphere_FluidSim_GRAVITY -1000.0f
|
||||
#define electrosphere_FluidSim_GRAVITY -100.0f
|
||||
/*
|
||||
* Class: electrosphere_FluidSim
|
||||
* Method: simulate
|
||||
|
||||
@ -1,13 +1,22 @@
|
||||
#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
|
||||
*/
|
||||
static inline void addSourceToVectors
|
||||
void Java_electrosphere_FluidSim_addSourceToVectors
|
||||
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||
|
||||
/*
|
||||
@ -15,7 +24,7 @@ static inline void addSourceToVectors
|
||||
* Method: solveVectorDiffuse
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||
*/
|
||||
static inline void solveVectorDiffuse
|
||||
void Java_electrosphere_FluidSim_solveVectorDiffuse
|
||||
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||
|
||||
/*
|
||||
@ -23,25 +32,15 @@ static inline void solveVectorDiffuse
|
||||
* Method: setupProjection
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||
*/
|
||||
static inline void setupProjection
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
float ** ur,
|
||||
float ** vr,
|
||||
float ** wr,
|
||||
float ** pr,
|
||||
float ** divr,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt);
|
||||
void Java_electrosphere_FluidSim_setupProjection
|
||||
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||
|
||||
/*
|
||||
* Class: electrosphere_FluidSim
|
||||
* Method: solveProjection
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||
*/
|
||||
static inline void solveProjection
|
||||
void Java_electrosphere_FluidSim_solveProjection
|
||||
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||
|
||||
/*
|
||||
@ -49,7 +48,7 @@ static inline void solveProjection
|
||||
* Method: finalizeProjection
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||
*/
|
||||
static inline void finalizeProjection
|
||||
void Java_electrosphere_FluidSim_finalizeProjection
|
||||
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||
|
||||
/*
|
||||
@ -57,7 +56,7 @@ static inline void finalizeProjection
|
||||
* Method: advectVectors
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||
*/
|
||||
static inline void advectVectors
|
||||
void Java_electrosphere_FluidSim_advectVectors
|
||||
(int, int, float **, float **, float **, float **, float **, float **, float, float, float);
|
||||
|
||||
/*
|
||||
@ -65,7 +64,7 @@ static inline void advectVectors
|
||||
* Method: addDensity
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;F)V
|
||||
*/
|
||||
static inline void addDensity
|
||||
void Java_electrosphere_FluidSim_addDensity
|
||||
(int, int, float **, float **, float);
|
||||
|
||||
/*
|
||||
@ -73,7 +72,7 @@ static inline void addDensity
|
||||
* Method: solveDiffuseDensity
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||
*/
|
||||
static inline void solveDiffuseDensity
|
||||
void Java_electrosphere_FluidSim_solveDiffuseDensity
|
||||
(int, int, float **, float **, float **, float **, float **, float, float, float);
|
||||
|
||||
/*
|
||||
@ -81,16 +80,17 @@ static inline void solveDiffuseDensity
|
||||
* Method: advectDensity
|
||||
* Signature: (II[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;[Ljava/nio/ByteBuffer;FFF)V
|
||||
*/
|
||||
static inline void advectDensity(uint32_t chunk_mask, int N, float ** d, float ** d0, float ** ur, float ** vr, float ** wr, float dt);
|
||||
void Java_electrosphere_FluidSim_advectDensity
|
||||
(int, int, float **, float **, float **, float **, float **, float, float, float);
|
||||
|
||||
static inline void setBoundsToNeighborsRaw
|
||||
void setBoundsToNeighborsRaw
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
int vector_dir,
|
||||
float ** neighborArray);
|
||||
|
||||
static inline void copyNeighborsRaw
|
||||
void copyNeighborsRaw
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
#ifndef SIMULATION_H
|
||||
#define SIMULATION_H
|
||||
|
||||
#include "./chunk.h"
|
||||
|
||||
void simulate(int numChunks, Chunk ** passedInChunks, float timestep);
|
||||
|
||||
#endif
|
||||
@ -1,3 +1,4 @@
|
||||
#include <jni.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef UTILITIES_H
|
||||
@ -6,7 +7,8 @@
|
||||
#define SWAP(x0,x) {float *tmp=x0;x0=x;x=tmp;}
|
||||
#define IX(i,j,k) ((i)+(N)*(j)+(N*N)*(k))
|
||||
#define CK(m,n,o) ((m)+(n)*(3)+(o)*(3)*(3))
|
||||
#define GET_ARR_RAW(src,i) src[i]
|
||||
#define GET_ARR(env,src,i) (*env)->GetDirectBufferAddress(env,(*env)->GetObjectArrayElement(env,src,i))
|
||||
#define GET_ARR_RAW(env,src,i) src[i]
|
||||
#define ARR_EXISTS(chunk_mask,m,n,o) (chunk_mask & CHUNK_INDEX_ARR[CK(m,n,o)]) > 0
|
||||
|
||||
#endif
|
||||
@ -1 +0,0 @@
|
||||
Subproject commit ae721c50eaf761660b4f90cc590453cdb0c2acd0
|
||||
@ -1,61 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include "../includes/utilities.h"
|
||||
#include "../includes/chunkmask.h"
|
||||
|
||||
const uint32_t CHUNK_INDEX_ARR[] = {
|
||||
CHUNK_000, CHUNK_100, CHUNK_200,
|
||||
CHUNK_010, CHUNK_110, CHUNK_210,
|
||||
CHUNK_020, CHUNK_120, CHUNK_220,
|
||||
|
||||
CHUNK_001, CHUNK_101, CHUNK_201,
|
||||
CHUNK_011, CHUNK_111, CHUNK_211,
|
||||
CHUNK_021, CHUNK_121, CHUNK_221,
|
||||
|
||||
CHUNK_002, CHUNK_102, CHUNK_202,
|
||||
CHUNK_012, CHUNK_112, CHUNK_212,
|
||||
CHUNK_022, CHUNK_122, CHUNK_222,
|
||||
};
|
||||
|
||||
|
||||
//control offsetting the advect sampler location if a valid neighbor chunk is hit
|
||||
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,
|
||||
};
|
||||
|
||||
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,
|
||||
0, 0, 0,
|
||||
-1, -1, -1,
|
||||
};
|
||||
|
||||
const char CHUNK_NORMALIZE_W[] = {
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
|
||||
0, 0, 0,
|
||||
0, 0, 0,
|
||||
0, 0, 0,
|
||||
|
||||
-1, -1, -1,
|
||||
-1, -1, -1,
|
||||
-1, -1, -1,
|
||||
};
|
||||
@ -1,542 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include "../includes/utilities.h"
|
||||
#include "../includes/chunkmask.h"
|
||||
#include "../includes/electrosphere_FluidSim.h"
|
||||
#include "../includes/mainFunctions.h"
|
||||
#include "../includes/chunk.h"
|
||||
#include "../includes/simulation.h"
|
||||
|
||||
#include "./chunkmask.c"
|
||||
#include "./velocitystep.c"
|
||||
#include "./densitystep.c"
|
||||
|
||||
#ifndef SAVE_STEPS
|
||||
#define SAVE_STEPS 0
|
||||
#endif
|
||||
|
||||
|
||||
#define DIM 18
|
||||
#define LINEARSOLVERTIMES 20
|
||||
#define REALLY_SMALL_VALUE 0.00001
|
||||
|
||||
#define DIFFUSION_CONSTANT 0.00001
|
||||
#define VISCOSITY_CONSTANT 0.00001
|
||||
|
||||
char fileNameBuff[50];
|
||||
|
||||
//all chunks
|
||||
Chunk ** chunks = NULL;
|
||||
|
||||
//jni help:
|
||||
//https://stackoverflow.com/questions/39823375/clarification-about-getfieldid
|
||||
|
||||
static inline void saveStep(float * values, const char * name);
|
||||
|
||||
void simulate(
|
||||
int numChunks,
|
||||
Chunk ** passedInChunks,
|
||||
jfloat timestep
|
||||
){
|
||||
chunks = passedInChunks;
|
||||
|
||||
// printf("%p\n",chunks[0].d);
|
||||
saveStep(chunks[0]->u[CENTER_LOC], "./chunks/beginU");
|
||||
saveStep(chunks[0]->v[CENTER_LOC], "./chunks/beginV");
|
||||
saveStep(chunks[0]->w[CENTER_LOC], "./chunks/beginW");
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], "./chunks/beginU0");
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], "./chunks/beginV0");
|
||||
saveStep(chunks[0]->w0[CENTER_LOC], "./chunks/beginW0");
|
||||
|
||||
//solve chunk mask
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
addSourceToVectors(
|
||||
DIM,
|
||||
currentChunk->chunkMask,
|
||||
currentChunk->u,
|
||||
currentChunk->v,
|
||||
currentChunk->w,
|
||||
currentChunk->u0,
|
||||
currentChunk->v0,
|
||||
currentChunk->w0,
|
||||
DIFFUSION_CONSTANT,
|
||||
VISCOSITY_CONSTANT,
|
||||
timestep
|
||||
);
|
||||
saveStep(currentChunk->u[CENTER_LOC], "./chunks/addSrcU");
|
||||
saveStep(currentChunk->v[CENTER_LOC], "./chunks/addSrcV");
|
||||
saveStep(currentChunk->w[CENTER_LOC], "./chunks/addSrcW");
|
||||
saveStep(currentChunk->u0[CENTER_LOC], "./chunks/addSrcU0");
|
||||
saveStep(currentChunk->v0[CENTER_LOC], "./chunks/addSrcV0");
|
||||
saveStep(currentChunk->w0[CENTER_LOC], "./chunks/addSrcW0");
|
||||
}
|
||||
//swap all vector fields
|
||||
{
|
||||
//swap vector fields
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
|
||||
float * tmpArr;
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->u[j];
|
||||
currentChunk->u[j] = currentChunk->u0[j];
|
||||
currentChunk->u0[j] = tmpArr;
|
||||
}
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->v[j];
|
||||
currentChunk->v[j] = currentChunk->v0[j];
|
||||
currentChunk->v0[j] = tmpArr;
|
||||
}
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->w[j];
|
||||
currentChunk->w[j] = currentChunk->w0[j];
|
||||
currentChunk->w0[j] = tmpArr;
|
||||
}
|
||||
}
|
||||
//copy neighbors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
}
|
||||
saveStep(chunks[0]->u[CENTER_LOC], "./chunks/swapU");
|
||||
saveStep(chunks[0]->v[CENTER_LOC], "./chunks/swapV");
|
||||
saveStep(chunks[0]->w[CENTER_LOC], "./chunks/swapW");
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], "./chunks/swapU0");
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], "./chunks/swapV0");
|
||||
saveStep(chunks[0]->w0[CENTER_LOC], "./chunks/swapW0");
|
||||
// printf("after swap vecs u\n");
|
||||
// printLayer(chunks[0]->u[CENTER_LOC],targetLayer);
|
||||
// printf("after swap vecs u0\n");
|
||||
// printLayer(chunks[0]->u0[CENTER_LOC],targetLayer);
|
||||
//solve vector diffusion
|
||||
{
|
||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||
//solve vector diffusion
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
solveVectorDiffuse(DIM,currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
if(SAVE_STEPS){
|
||||
sprintf(fileNameBuff, "./chunks/diffuseUStep%dx", l);
|
||||
saveStep(chunks[0]->u[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseUStep%dx0", l);
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseVStep%dx", l);
|
||||
saveStep(chunks[0]->v[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseVStep%dx0", l);
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseWStep%dx", l);
|
||||
saveStep(chunks[0]->w[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseWStep%dx0", l);
|
||||
saveStep(chunks[0]->w0[CENTER_LOC], fileNameBuff);
|
||||
}
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,3,currentChunk->w);
|
||||
// setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
// setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||
// setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->w0);
|
||||
}
|
||||
if(SAVE_STEPS){
|
||||
sprintf(fileNameBuff, "./chunks/diffuseUStep%dxBnd", l);
|
||||
saveStep(chunks[0]->u[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseUStep%dx0Bnd", l);
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseVStep%dxBnd", l);
|
||||
saveStep(chunks[0]->v[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseVStep%dx0Bnd", l);
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseWStep%dxBnd", l);
|
||||
saveStep(chunks[0]->w[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/diffuseWStep%dx0Bnd", l);
|
||||
saveStep(chunks[0]->w0[CENTER_LOC], fileNameBuff);
|
||||
}
|
||||
}
|
||||
}
|
||||
saveStep(chunks[0]->u[CENTER_LOC], "./chunks/diffuseU");
|
||||
saveStep(chunks[0]->v[CENTER_LOC], "./chunks/diffuseV");
|
||||
saveStep(chunks[0]->w[CENTER_LOC], "./chunks/diffuseW");
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], "./chunks/diffuseU0");
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], "./chunks/diffuseV0");
|
||||
saveStep(chunks[0]->w0[CENTER_LOC], "./chunks/diffuseW0");
|
||||
//solve projection
|
||||
{
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
// setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u);
|
||||
// setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v);
|
||||
// setBoundsToNeighborsRaw(DIM,chunkMask,3,currentChunk->w);
|
||||
// setBoundsToNeighborsRaw(DIM,chunkMask,1,currentChunk->u0);
|
||||
// setBoundsToNeighborsRaw(DIM,chunkMask,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v0);
|
||||
}
|
||||
//setup projection
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setupProjection(DIM,currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], "./chunks/setupProj1Div");
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], "./chunks/setupProj1P");
|
||||
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,0,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,0,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->v0);
|
||||
}
|
||||
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], "./chunks/setupProj1DivBnd");
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], "./chunks/setupProj1PBnd");
|
||||
|
||||
//samples u0, v0
|
||||
//sets u0
|
||||
//these should have just been mirrored in the above
|
||||
//
|
||||
//Perform main projection solver
|
||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
solveProjection(DIM,currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
if(SAVE_STEPS){
|
||||
sprintf(fileNameBuff, "./chunks/proj1Step%dx", l);
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/proj1Step%dx0", l);
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], fileNameBuff);
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,0,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->u0);
|
||||
}
|
||||
if(SAVE_STEPS){
|
||||
sprintf(fileNameBuff, "./chunks/proj1Step%dxBnd", l);
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], fileNameBuff);
|
||||
sprintf(fileNameBuff, "./chunks/proj1Step%dx0Bnd", l);
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], fileNameBuff);
|
||||
}
|
||||
}
|
||||
//samples u,v,w,u0
|
||||
//sets u,v,w
|
||||
//Finalize projection
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
finalizeProjection(DIM,currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
|
||||
saveStep(chunks[0]->u[CENTER_LOC], "./chunks/finalizeProj1U");
|
||||
saveStep(chunks[0]->v[CENTER_LOC], "./chunks/finalizeProj1V");
|
||||
saveStep(chunks[0]->w[CENTER_LOC], "./chunks/finalizeProj1W");
|
||||
// exit(0);
|
||||
//set boundaries a final time for u,v,w
|
||||
//...
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,3,currentChunk->w);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v0);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,3,currentChunk->w0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
}
|
||||
saveStep(chunks[0]->u[CENTER_LOC], "./chunks/projU");
|
||||
saveStep(chunks[0]->v[CENTER_LOC], "./chunks/projV");
|
||||
saveStep(chunks[0]->w[CENTER_LOC], "./chunks/projW");
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], "./chunks/projU0");
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], "./chunks/projV0");
|
||||
saveStep(chunks[0]->w0[CENTER_LOC], "./chunks/projW0");
|
||||
// exit(0);
|
||||
//swap all vector fields
|
||||
{
|
||||
//swap vector fields
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
|
||||
float * tmpArr;
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->u[j];
|
||||
currentChunk->u[j] = currentChunk->u0[j];
|
||||
currentChunk->u0[j] = tmpArr;
|
||||
}
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->v[j];
|
||||
currentChunk->v[j] = currentChunk->v0[j];
|
||||
currentChunk->v0[j] = tmpArr;
|
||||
}
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->w[j];
|
||||
currentChunk->w[j] = currentChunk->w0[j];
|
||||
currentChunk->w0[j] = tmpArr;
|
||||
}
|
||||
}
|
||||
//copy neighbors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
}
|
||||
saveStep(chunks[0]->u[CENTER_LOC], "./chunks/swap2U");
|
||||
saveStep(chunks[0]->v[CENTER_LOC], "./chunks/swap2V");
|
||||
saveStep(chunks[0]->w[CENTER_LOC], "./chunks/swap2W");
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], "./chunks/swap2U0");
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], "./chunks/swap2V0");
|
||||
saveStep(chunks[0]->w0[CENTER_LOC], "./chunks/swap2W0");
|
||||
//advect vectors across boundaries
|
||||
{
|
||||
//update border arrs
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,3,currentChunk->w);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v0);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,3,currentChunk->w0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
//advect
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
advectVectors(DIM,currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
//update neighbor arr
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w);
|
||||
}
|
||||
}
|
||||
saveStep(chunks[0]->u[CENTER_LOC], "./chunks/advectU");
|
||||
saveStep(chunks[0]->v[CENTER_LOC], "./chunks/advectV");
|
||||
saveStep(chunks[0]->w[CENTER_LOC], "./chunks/advectW");
|
||||
saveStep(chunks[0]->u0[CENTER_LOC], "./chunks/advectU0");
|
||||
saveStep(chunks[0]->v0[CENTER_LOC], "./chunks/advectV0");
|
||||
saveStep(chunks[0]->w0[CENTER_LOC], "./chunks/advectW0");
|
||||
//solve projection
|
||||
{
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,3,currentChunk->w);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v0);
|
||||
}
|
||||
//setup projection
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setupProjection(DIM,currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
//update array for vectors
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v0);
|
||||
}
|
||||
//samples u0, v0
|
||||
//sets u0
|
||||
//these should have just been mirrored in the above
|
||||
//
|
||||
//Perform main projection solver
|
||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
solveProjection(DIM,currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,0,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->u0);
|
||||
}
|
||||
}
|
||||
//samples u,v,w,u0
|
||||
//sets u,v,w
|
||||
//Finalize projection
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
finalizeProjection(DIM,currentChunk->chunkMask,currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
//set boundaries a final time for u,v,w
|
||||
//...
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,3,currentChunk->w);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,1,currentChunk->u0);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,2,currentChunk->v0);
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,3,currentChunk->w0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,1,currentChunk->u0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,2,currentChunk->v0);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,3,currentChunk->w0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
///------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
//add density
|
||||
{
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
addDensity(DIM,currentChunk->chunkMask,currentChunk->d,currentChunk->d0,timestep);
|
||||
}
|
||||
}
|
||||
//swap all density arrays
|
||||
{
|
||||
//swap vector fields
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
|
||||
float * tmpArr;
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->d[j];
|
||||
currentChunk->d[j] = currentChunk->d0[j];
|
||||
currentChunk->d0[j] = tmpArr;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->d);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->d0);
|
||||
}
|
||||
}
|
||||
//diffuse density
|
||||
{
|
||||
for(int l = 0; l < LINEARSOLVERTIMES; l++){
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
solveDiffuseDensity(DIM,currentChunk->chunkMask,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,DIFFUSION_CONSTANT,VISCOSITY_CONSTANT,timestep);
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,0,currentChunk->d);
|
||||
}
|
||||
}
|
||||
}
|
||||
//swap all density arrays
|
||||
{
|
||||
//swap vector fields
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
float * tmpArr;
|
||||
for(int j = 0; j < 27; j++){
|
||||
tmpArr = currentChunk->d[j];
|
||||
currentChunk->d[j] = currentChunk->d0[j];
|
||||
currentChunk->d0[j] = tmpArr;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->d);
|
||||
copyNeighborsRaw(DIM,currentChunk->chunkMask,0,0,currentChunk->d0);
|
||||
}
|
||||
}
|
||||
//advect density
|
||||
{
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
advectDensity(currentChunk->chunkMask,DIM,currentChunk->d,currentChunk->d0,currentChunk->u,currentChunk->v,currentChunk->w,timestep);
|
||||
}
|
||||
}
|
||||
//mirror densities
|
||||
{
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
Chunk * currentChunk = chunks[i];
|
||||
setBoundsToNeighborsRaw(DIM,currentChunk->chunkMask,0,currentChunk->d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline void saveStep(float * values, const char * name){
|
||||
if(SAVE_STEPS){
|
||||
FILE *fp;
|
||||
int N = DIM;
|
||||
|
||||
// ... fill the array somehow ...
|
||||
|
||||
fp = fopen(name, "w");
|
||||
// check for error here
|
||||
|
||||
for(int x = 0; x < DIM; x++){
|
||||
for(int y = 0; y < DIM; y++){
|
||||
for(int z = 0; z < DIM; z++){
|
||||
float val = values[IX(x,y,z)];
|
||||
if(val < REALLY_SMALL_VALUE && val > -REALLY_SMALL_VALUE){
|
||||
val = 0;
|
||||
}
|
||||
fprintf(fp, "%f\t", val);
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
@ -1,170 +0,0 @@
|
||||
#include <jni.h>
|
||||
|
||||
//library includes
|
||||
//include stb ds
|
||||
#define STB_DS_IMPLEMENTATION
|
||||
#include "../lib/stb/stb_ds.h"
|
||||
|
||||
//local includes
|
||||
#include "../includes/chunk.h"
|
||||
#include "../includes/chunkmask.h"
|
||||
#include "../includes/utilities.h"
|
||||
#include "../includes/simulation.h"
|
||||
|
||||
|
||||
//defines
|
||||
|
||||
|
||||
//function defines
|
||||
#define getChunk(i) (*env)->CallObjectMethod(env,chunkList,jListGet,i)
|
||||
#define getBuffArr(buffId) (*env)->GetObjectField(env,chunkJRaw,buffId)
|
||||
#define setBuffArr(buffId,value) (*env)->SetObjectField(env,chunkJRaw,buffId,value)
|
||||
#define GET_ARR(env,src,i) (*env)->GetDirectBufferAddress(env,(*env)->GetObjectArrayElement(env,src,i))
|
||||
|
||||
|
||||
|
||||
//declarations
|
||||
void readInChunks(JNIEnv * env, jobject chunkList);
|
||||
int calculateChunkMask(JNIEnv * env, jobjectArray jrx);
|
||||
uint32_t matrix_transform(JNIEnv * env, jobjectArray jrx);
|
||||
|
||||
|
||||
|
||||
//the list of chunks
|
||||
Chunk ** javaChunkView = NULL;
|
||||
//the number of chunks
|
||||
int numChunks = 0;
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_electrosphere_FluidSim_simulate(
|
||||
JNIEnv * env,
|
||||
jclass fluidSimClass,
|
||||
jobject chunkList,
|
||||
jfloat dt
|
||||
){
|
||||
readInChunks(env,chunkList);
|
||||
simulate(numChunks,javaChunkView,dt);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads chunks into the dynamic array
|
||||
*/
|
||||
void readInChunks(JNIEnv * env, jobject chunkList){
|
||||
jclass listClass = (*env)->FindClass(env,"java/util/List");
|
||||
jclass fluidSimClass = (*env)->FindClass(env,"electrosphere/FluidSim");
|
||||
//JNIEnv *env, jclass clazz, const char *name, const char *sig
|
||||
jmethodID jListSize = (*env)->GetMethodID(env, listClass, "size", "()I");
|
||||
jmethodID jListGet = (*env)->GetMethodID(env, listClass, "get", "(I)Ljava/lang/Object;");
|
||||
jmethodID jListAdd = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z");
|
||||
|
||||
//ByteBuffer[]
|
||||
jfieldID dJId = (*env)->GetFieldID(env,fluidSimClass,"density","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID d0JId = (*env)->GetFieldID(env,fluidSimClass,"densityAddition","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID uJId = (*env)->GetFieldID(env,fluidSimClass,"uVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID vJId = (*env)->GetFieldID(env,fluidSimClass,"vVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID wJId = (*env)->GetFieldID(env,fluidSimClass,"wVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID u0JId = (*env)->GetFieldID(env,fluidSimClass,"uAdditionVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID v0JId = (*env)->GetFieldID(env,fluidSimClass,"vAdditionVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID w0JId = (*env)->GetFieldID(env,fluidSimClass,"wAdditionVector","[Ljava/nio/ByteBuffer;");
|
||||
jfieldID chunkmaskJId = (*env)->GetFieldID(env,fluidSimClass,"chunkMask","I");
|
||||
|
||||
//the number of chunks
|
||||
numChunks = (*env)->CallIntMethod(env,chunkList,jListSize);
|
||||
|
||||
//current chunk (this)
|
||||
jobject chunkJRaw;
|
||||
//current chunk fields
|
||||
jobjectArray jd;
|
||||
jobjectArray jd0;
|
||||
jobjectArray u;
|
||||
jobjectArray v;
|
||||
jobjectArray w;
|
||||
jobjectArray u0;
|
||||
jobjectArray v0;
|
||||
jobjectArray w0;
|
||||
int chunkMask;
|
||||
|
||||
//solve chunk mask
|
||||
for(int i = 0; i < numChunks; i++){
|
||||
chunkJRaw = getChunk(i);
|
||||
chunkMask = calculateChunkMask(env,getBuffArr(dJId));
|
||||
(*env)->SetIntField(env,chunkJRaw,chunkmaskJId,chunkMask);
|
||||
|
||||
Chunk * newChunk;
|
||||
if(i >= stbds_arrlen(javaChunkView)){
|
||||
// printf("allocate chunk %d\n",i);
|
||||
// fflush(stdout);
|
||||
newChunk = (Chunk *)malloc(sizeof(Chunk));
|
||||
// printf("new chunk %p\n",newChunk);
|
||||
// fflush(stdout);
|
||||
stbds_arrput(javaChunkView,newChunk);
|
||||
// printf("new chunk %p\n",chunks[i]);
|
||||
// fflush(stdout);
|
||||
} else {
|
||||
newChunk = javaChunkView[i];
|
||||
// printf("get chunk %d: %p\n",i,newChunk);
|
||||
// fflush(stdout);
|
||||
}
|
||||
jd = (*env)->GetObjectField(env,chunkJRaw,dJId);
|
||||
jd0 = (*env)->GetObjectField(env,chunkJRaw,d0JId);
|
||||
u = (*env)->GetObjectField(env,chunkJRaw,uJId);
|
||||
v = (*env)->GetObjectField(env,chunkJRaw,vJId);
|
||||
w = (*env)->GetObjectField(env,chunkJRaw,wJId);
|
||||
u0 = (*env)->GetObjectField(env,chunkJRaw,u0JId);
|
||||
v0 = (*env)->GetObjectField(env,chunkJRaw,v0JId);
|
||||
w0 = (*env)->GetObjectField(env,chunkJRaw,w0JId);
|
||||
newChunk->chunkMask = chunkMask;
|
||||
for(int j = 0; j < 27; j++){
|
||||
if((chunkMask & CHUNK_INDEX_ARR[j]) > 0){
|
||||
newChunk->d[j] = GET_ARR(env,jd,j);
|
||||
newChunk->d0[j] = GET_ARR(env,jd0,j);
|
||||
newChunk->u[j] = GET_ARR(env,u,j);
|
||||
newChunk->v[j] = GET_ARR(env,v,j);
|
||||
newChunk->w[j] = GET_ARR(env,w,j);
|
||||
newChunk->u0[j] = GET_ARR(env,u0,j);
|
||||
newChunk->v0[j] = GET_ARR(env,v0,j);
|
||||
newChunk->w0[j] = GET_ARR(env,w0,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the bitmask for available chunks for the provided chunk's neighbor array
|
||||
*/
|
||||
int calculateChunkMask(JNIEnv * env, jobjectArray jrx){
|
||||
return matrix_transform(env,jrx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a mask that represents all nearby chunks that are actually accessible and exist
|
||||
*/
|
||||
uint32_t matrix_transform(JNIEnv * env, jobjectArray jrx){
|
||||
|
||||
//The returned value, an availability mask that contains the availability of each neighbor chunk
|
||||
uint32_t rVal = 0;
|
||||
|
||||
//Add to maks for initial chunks
|
||||
for(int i = 0; i < CENTER_LOC; i++){
|
||||
if((*env)->GetObjectArrayElement(env,jrx,i)!=NULL){
|
||||
rVal = rVal + 1;
|
||||
}
|
||||
rVal = rVal << 1;
|
||||
}
|
||||
//add 1 for center chunk because we already have that
|
||||
rVal = rVal + 1;
|
||||
rVal = rVal << 1;
|
||||
//continue on for remaining chunks
|
||||
for(int i = CENTER_LOC+1; i < 27; i++){
|
||||
if((*env)->GetObjectArrayElement(env,jrx,i)!=NULL){
|
||||
rVal = rVal + 1;
|
||||
}
|
||||
if(i < 26){
|
||||
rVal = rVal << 1;
|
||||
}
|
||||
}
|
||||
|
||||
return rVal;
|
||||
}
|
||||
@ -2,8 +2,8 @@
|
||||
#include <immintrin.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../includes/utilities.h"
|
||||
#include "../includes/chunkmask.h"
|
||||
#include "includes/utilities.h"
|
||||
#include "includes/chunkmask.h"
|
||||
|
||||
|
||||
#define BOUND_NO_DIR 0
|
||||
@ -14,16 +14,14 @@
|
||||
#define SET_BOUND_IGNORE 0
|
||||
#define SET_BOUND_USE_NEIGHBOR 1
|
||||
|
||||
#define LINEARSOLVERTIMES 20
|
||||
|
||||
static inline void add_source(int N, float * x, float * s, float dt);
|
||||
static inline void advect(uint32_t chunk_mask, int N, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt);
|
||||
void add_source(int N, float * x, float * s, float dt);
|
||||
void advect(uint32_t chunk_mask, int N, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt);
|
||||
|
||||
|
||||
/*
|
||||
* Adds force to all vectors
|
||||
*/
|
||||
static inline void addSourceToVectors
|
||||
void Java_electrosphere_FluidSim_addSourceToVectors
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
@ -36,15 +34,12 @@ static inline void addSourceToVectors
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt){
|
||||
add_source(N,GET_ARR_RAW(jru,CENTER_LOC),GET_ARR_RAW(jru0,CENTER_LOC),dt);
|
||||
add_source(N,GET_ARR_RAW(jrv,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),dt);
|
||||
add_source(N,GET_ARR_RAW(jrw,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
add_source(N,GET_ARR_RAW(env,jru,CENTER_LOC),GET_ARR_RAW(env,jru0,CENTER_LOC),dt);
|
||||
add_source(N,GET_ARR_RAW(env,jrv,CENTER_LOC),GET_ARR_RAW(env,jrv0,CENTER_LOC),dt);
|
||||
add_source(N,GET_ARR_RAW(env,jrw,CENTER_LOC),GET_ARR_RAW(env,jrw0,CENTER_LOC),dt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds from a source array to a destination array
|
||||
*/
|
||||
static inline void add_source(int N, float * x, float * s, float dt){
|
||||
void add_source(int N, float * x, float * s, float dt){
|
||||
int i;
|
||||
int size=N*N*N;
|
||||
for(i=0; i<size; i++){
|
||||
@ -55,7 +50,8 @@ static inline void add_source(int N, float * x, float * s, float dt){
|
||||
/*
|
||||
* Solves vector diffusion along all axis
|
||||
*/
|
||||
static inline void solveVectorDiffuse (
|
||||
void Java_electrosphere_FluidSim_solveVectorDiffuse
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
@ -66,17 +62,16 @@ static inline void solveVectorDiffuse (
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
float dt){
|
||||
float a=dt*VISCOSITY_CONST*N*N*N;
|
||||
float c=1+6*a;
|
||||
int i, j, k, l, m;
|
||||
float * u = GET_ARR_RAW(jru,CENTER_LOC);
|
||||
float * v = GET_ARR_RAW(jrv,CENTER_LOC);
|
||||
float * w = GET_ARR_RAW(jrw,CENTER_LOC);
|
||||
float * u0 = GET_ARR_RAW(jru0,CENTER_LOC);
|
||||
float * v0 = GET_ARR_RAW(jrv0,CENTER_LOC);
|
||||
float * w0 = GET_ARR_RAW(jrw0,CENTER_LOC);
|
||||
float * u = GET_ARR_RAW(env,jru,CENTER_LOC);
|
||||
float * v = GET_ARR_RAW(env,jrv,CENTER_LOC);
|
||||
float * w = GET_ARR_RAW(env,jrw,CENTER_LOC);
|
||||
float * u0 = GET_ARR_RAW(env,jru0,CENTER_LOC);
|
||||
float * v0 = GET_ARR_RAW(env,jrv0,CENTER_LOC);
|
||||
float * w0 = GET_ARR_RAW(env,jrw0,CENTER_LOC);
|
||||
|
||||
__m256 aScalar = _mm256_set1_ps(a);
|
||||
__m256 cScalar = _mm256_set1_ps(c);
|
||||
@ -163,31 +158,34 @@ static inline void solveVectorDiffuse (
|
||||
/*
|
||||
* Sets up a projection system of equations
|
||||
*/
|
||||
static inline void setupProjection(
|
||||
void Java_electrosphere_FluidSim_setupProjection
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
float ** ur,
|
||||
float ** vr,
|
||||
float ** wr,
|
||||
float ** pr,
|
||||
float ** divr,
|
||||
float ** jru,
|
||||
float ** jrv,
|
||||
float ** jrw,
|
||||
float ** jru0,
|
||||
float ** jrv0,
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
float dt){
|
||||
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 zeroVec = _mm256_set1_ps(0);
|
||||
__m256 vector, vector2, vector3;
|
||||
|
||||
float * u = GET_ARR_RAW(ur,CENTER_LOC);
|
||||
float * v = GET_ARR_RAW(vr,CENTER_LOC);
|
||||
float * w = GET_ARR_RAW(wr,CENTER_LOC);
|
||||
float * u = GET_ARR_RAW(env,jru,CENTER_LOC);
|
||||
float * v = GET_ARR_RAW(env,jrv,CENTER_LOC);
|
||||
float * w = GET_ARR_RAW(env,jrw,CENTER_LOC);
|
||||
|
||||
float * p = GET_ARR_RAW(pr,CENTER_LOC);
|
||||
float * div = GET_ARR_RAW(divr,CENTER_LOC);
|
||||
float * p = GET_ARR_RAW(env,jru0,CENTER_LOC);
|
||||
float * div = GET_ARR_RAW(env,jrv0,CENTER_LOC);
|
||||
|
||||
float scalar = 1.0/3.0;
|
||||
float h = 1.0/N;
|
||||
@ -201,15 +199,15 @@ static inline void setupProjection(
|
||||
//first part
|
||||
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
|
||||
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
|
||||
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
|
||||
vector = _mm256_add_ps(vector,_mm256_add_ps(vector2,vector3));
|
||||
vector = _mm256_mul_ps(vector,constScalar);
|
||||
@ -223,15 +221,15 @@ static inline void setupProjection(
|
||||
//first part
|
||||
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
|
||||
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
|
||||
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
|
||||
vector = _mm256_add_ps(vector,_mm256_add_ps(vector2,vector3));
|
||||
vector = _mm256_mul_ps(vector,constScalar);
|
||||
@ -239,6 +237,14 @@ static inline void setupProjection(
|
||||
_mm256_storeu_ps(&div[IX(i,j,k)],vector);
|
||||
_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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,7 +252,8 @@ static inline void setupProjection(
|
||||
/*
|
||||
* Solves a projection system of equations
|
||||
*/
|
||||
static inline void solveProjection(
|
||||
void Java_electrosphere_FluidSim_solveProjection
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
@ -257,16 +264,15 @@ static inline void solveProjection(
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
float dt){
|
||||
int a = 1;
|
||||
int c = 6;
|
||||
int i, j, k, l, m;
|
||||
__m256 aScalar = _mm256_set1_ps(a);
|
||||
__m256 cScalar = _mm256_set1_ps(c);
|
||||
|
||||
float * p = GET_ARR_RAW(jru0,CENTER_LOC);
|
||||
float * div = GET_ARR_RAW(jrv0,CENTER_LOC);
|
||||
float * p = GET_ARR_RAW(env,jru0,CENTER_LOC);
|
||||
float * div = GET_ARR_RAW(env,jrv0,CENTER_LOC);
|
||||
// update for each cell
|
||||
for(k=1; k<N-1; k++){
|
||||
for(j=1; j<N-1; j++){
|
||||
@ -279,7 +285,7 @@ static inline void solveProjection(
|
||||
vector = _mm256_add_ps(vector,_mm256_loadu_ps(&p[IX(i,j+1,k)]));
|
||||
vector = _mm256_add_ps(vector,_mm256_loadu_ps(&p[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(&div[IX(i,j,k)]));
|
||||
vector = _mm256_div_ps(vector,cScalar);
|
||||
_mm256_storeu_ps(&p[IX(i,j,k)],vector);
|
||||
@ -290,6 +296,9 @@ static inline void solveProjection(
|
||||
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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -297,7 +306,8 @@ static inline void solveProjection(
|
||||
/*
|
||||
* Finalizes a projection (subtract curl, set bounds, etc)
|
||||
*/
|
||||
static inline void finalizeProjection(
|
||||
void Java_electrosphere_FluidSim_finalizeProjection
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
@ -308,18 +318,22 @@ static inline void finalizeProjection(
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
float dt){
|
||||
int i, j, k;
|
||||
__m256 constScalar = _mm256_set1_ps(0.5f*N);
|
||||
// __m256 constScalar = _mm256_set1_ps(0.5f*N);
|
||||
__m256 xScalar = _mm256_set1_ps(0.5*N);
|
||||
__m256 yScalar = _mm256_set1_ps(0.5*N);
|
||||
__m256 zScalar = _mm256_set1_ps(0.5*N);
|
||||
__m256 vector, vector2, vector3;
|
||||
|
||||
float * u = GET_ARR_RAW(jru,CENTER_LOC);
|
||||
float * v = GET_ARR_RAW(jrv,CENTER_LOC);
|
||||
float * w = GET_ARR_RAW(jrw,CENTER_LOC);
|
||||
float * u = GET_ARR_RAW(env,jru,CENTER_LOC);
|
||||
float * v = GET_ARR_RAW(env,jrv,CENTER_LOC);
|
||||
float * w = GET_ARR_RAW(env,jrw,CENTER_LOC);
|
||||
|
||||
float * p = GET_ARR_RAW(jru0,CENTER_LOC);
|
||||
float * div = GET_ARR_RAW(jrv0,CENTER_LOC);
|
||||
float * p = GET_ARR_RAW(env,jru0,CENTER_LOC);
|
||||
float * div = GET_ARR_RAW(env,jrv0,CENTER_LOC);
|
||||
|
||||
float h = 1.0 / N;
|
||||
|
||||
for ( k=1 ; k<N-1 ; k++ ) {
|
||||
for ( j=1 ; j<N-1 ; j++ ) {
|
||||
@ -330,14 +344,14 @@ static inline void finalizeProjection(
|
||||
vector = _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_mul_ps(vector,constScalar);
|
||||
vector = _mm256_mul_ps(vector,xScalar);
|
||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&u[IX(1,j,k)]),vector);
|
||||
_mm256_storeu_ps(&u[IX(1,j,k)],vector);
|
||||
//upper
|
||||
vector = _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_mul_ps(vector,constScalar);
|
||||
vector = _mm256_mul_ps(vector,xScalar);
|
||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&u[IX(9,j,k)]),vector);
|
||||
_mm256_storeu_ps(&u[IX(9,j,k)],vector);
|
||||
//
|
||||
@ -347,14 +361,14 @@ static inline void finalizeProjection(
|
||||
vector = _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_mul_ps(vector,constScalar);
|
||||
vector = _mm256_mul_ps(vector,yScalar);
|
||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&v[IX(1,j,k)]),vector);
|
||||
_mm256_storeu_ps(&v[IX(1,j,k)],vector);
|
||||
//upper
|
||||
vector = _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_mul_ps(vector,constScalar);
|
||||
vector = _mm256_mul_ps(vector,yScalar);
|
||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&v[IX(9,j,k)]),vector);
|
||||
_mm256_storeu_ps(&v[IX(9,j,k)],vector);
|
||||
//
|
||||
@ -364,16 +378,21 @@ static inline void finalizeProjection(
|
||||
vector = _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_mul_ps(vector,constScalar);
|
||||
vector = _mm256_mul_ps(vector,zScalar);
|
||||
vector = _mm256_sub_ps(_mm256_loadu_ps(&w[IX(1,j,k)]),vector);
|
||||
_mm256_storeu_ps(&w[IX(1,j,k)],vector);
|
||||
//upper
|
||||
vector = _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_mul_ps(vector,constScalar);
|
||||
vector = _mm256_mul_ps(vector,zScalar);
|
||||
vector = _mm256_sub_ps(_mm256_loadu_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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -381,7 +400,8 @@ static inline void finalizeProjection(
|
||||
/*
|
||||
* Advects u, v, and w
|
||||
*/
|
||||
static inline void advectVectors(
|
||||
void Java_electrosphere_FluidSim_advectVectors
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
float ** jru,
|
||||
@ -392,31 +412,28 @@ static inline void advectVectors(
|
||||
float ** jrw0,
|
||||
float DIFFUSION_CONST,
|
||||
float VISCOSITY_CONST,
|
||||
float dt
|
||||
){
|
||||
advect(chunk_mask,N,1,jru,jru0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
advect(chunk_mask,N,2,jrv,jrv0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
advect(chunk_mask,N,3,jrw,jrw0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt);
|
||||
float dt){
|
||||
advect(chunk_mask,N,1,jru,jru0,GET_ARR_RAW(env,jru0,CENTER_LOC),GET_ARR_RAW(env,jrv0,CENTER_LOC),GET_ARR_RAW(env,jrw0,CENTER_LOC),dt);
|
||||
advect(chunk_mask,N,2,jrv,jrv0,GET_ARR_RAW(env,jru0,CENTER_LOC),GET_ARR_RAW(env,jrv0,CENTER_LOC),GET_ARR_RAW(env,jrw0,CENTER_LOC),dt);
|
||||
advect(chunk_mask,N,3,jrw,jrw0,GET_ARR_RAW(env,jru0,CENTER_LOC),GET_ARR_RAW(env,jrv0,CENTER_LOC),GET_ARR_RAW(env,jrw0,CENTER_LOC),dt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually performs the advection
|
||||
*/
|
||||
static inline void advect(uint32_t chunk_mask, int N, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt){
|
||||
|
||||
void advect(uint32_t chunk_mask, int N, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt){
|
||||
int i, j, k, i0, j0, k0, i1, j1, k1;
|
||||
int m,n,o;
|
||||
float x, y, z, s0, t0, s1, t1, u1, u0, dtx,dty,dtz;
|
||||
|
||||
dtx=dty=dtz=dt*N;
|
||||
|
||||
float * d = GET_ARR_RAW(jrd,CENTER_LOC);
|
||||
float * d = GET_ARR_RAW(env,jrd,CENTER_LOC);
|
||||
|
||||
float * d0 = GET_ARR_RAW(jrd0,CENTER_LOC);
|
||||
float * d0 = GET_ARR_RAW(env,jrd0,CENTER_LOC);
|
||||
|
||||
for(k=1; k<N-1; k++){
|
||||
for(j=1; j<N-1; j++){
|
||||
for(i=1; i<N-1; i++){
|
||||
d0 = GET_ARR_RAW(jrd0,CENTER_LOC);
|
||||
d0 = GET_ARR_RAW(env,jrd0,CENTER_LOC);
|
||||
//calculate location to pull from
|
||||
x = i-dtx*u[IX(i,j,k)];
|
||||
y = j-dty*v[IX(i,j,k)];
|
||||
@ -482,7 +499,7 @@ static inline void advect(uint32_t chunk_mask, int N, int b, float ** jrd, float
|
||||
|
||||
|
||||
// printf("Hit other chunk\n");
|
||||
d0 = GET_ARR_RAW(jrd0,CK(m,n,o));
|
||||
d0 = GET_ARR_RAW(env,jrd0,CK(m,n,o));
|
||||
x = x + CHUNK_NORMALIZE_U[CK(m,n,o)] * (N-2);
|
||||
// printf("%d => %f\n",m,x);
|
||||
y = y + CHUNK_NORMALIZE_V[CK(m,n,o)] * (N-2);
|
||||
@ -644,31 +661,34 @@ static inline void advect(uint32_t chunk_mask, int N, int b, float ** jrd, float
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bounds of this cube to those of its neighbor
|
||||
*/
|
||||
static inline void setBoundsToNeighborsRaw(
|
||||
void setBoundsToNeighborsRaw
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
int vector_dir,
|
||||
float ** neighborArray
|
||||
){
|
||||
float ** neighborArray){
|
||||
int DIM = N;
|
||||
float * target = GET_ARR_RAW(neighborArray,CENTER_LOC);
|
||||
float * target = GET_ARR_RAW(env,neighborArray,CENTER_LOC);
|
||||
float * source;
|
||||
//set the faces bounds
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
target[IX(0,x,y)] = vector_dir==BOUND_DIR_U ? -target[IX(1,x,y)] : target[IX(1,x,y)];
|
||||
}
|
||||
}
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
target[IX(DIM-1,x,y)] = vector_dir==BOUND_DIR_U ? -target[IX(DIM-2,x,y)] : target[IX(DIM-2,x,y)];
|
||||
}
|
||||
}
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
//((x)+(DIM)*(y) + (DIM)*(DIM)*(z))
|
||||
target[IX(0,x,y)] = vector_dir==BOUND_DIR_U ? -target[IX(1,x,y)] : target[IX(1,x,y)];
|
||||
target[IX(DIM-1,x,y)] = vector_dir==BOUND_DIR_U ? -target[IX(DIM-2,x,y)] : target[IX(DIM-2,x,y)];
|
||||
target[IX(x,0,y)] = vector_dir==BOUND_DIR_V ? -target[IX(x,1,y)] : target[IX(x,1,y)];
|
||||
target[IX(x,DIM-1,y)] = vector_dir==BOUND_DIR_V ? -target[IX(x,DIM-2,y)] : target[IX(x,DIM-2,y)];
|
||||
target[IX(x,y,0)] = vector_dir==BOUND_DIR_W ? -target[IX(x,y,1)] : target[IX(x,y,1)];
|
||||
target[IX(x,y,DIM-1)] = vector_dir==BOUND_DIR_W ? -target[IX(x,y,DIM-2)] : target[IX(x,y,DIM-2)];
|
||||
}
|
||||
}
|
||||
//sets the edges of the chunk
|
||||
for(int x = 1; x < DIM-1; x++){
|
||||
target[IX(x,0,0)] = (float)(0.5f * (target[IX(x,1,0)] + target[IX(x,0,1)]));
|
||||
target[IX(x,DIM-1,0)] = (float)(0.5f * (target[IX(x,DIM-2,0)] + target[IX(x,DIM-1,1)]));
|
||||
@ -687,7 +707,6 @@ static inline void setBoundsToNeighborsRaw(
|
||||
target[IX(DIM-1,DIM-1,x)] = (float)(0.5f * (target[IX(DIM-2,DIM-1,x)] + target[IX(DIM-1,DIM-2,x)]));
|
||||
|
||||
}
|
||||
//sets the corners of the chunk
|
||||
target[IX(0,0,0)] = (float)((target[IX(1,0,0)]+target[IX(0,1,0)]+target[IX(0,0,1)])/3.0);
|
||||
target[IX(DIM-1,0,0)] = (float)((target[IX(DIM-2,0,0)]+target[IX(DIM-1,1,0)]+target[IX(DIM-1,0,1)])/3.0);
|
||||
target[IX(0,DIM-1,0)] = (float)((target[IX(1,DIM-1,0)]+target[IX(0,DIM-2,0)]+target[IX(0,DIM-1,1)])/3.0);
|
||||
@ -702,15 +721,15 @@ static inline void setBoundsToNeighborsRaw(
|
||||
/**
|
||||
* This exclusively copies neighbors to make sure zeroing out stuff doesn't break sim
|
||||
*/
|
||||
static inline void copyNeighborsRaw(
|
||||
void copyNeighborsRaw
|
||||
(
|
||||
int N,
|
||||
int chunk_mask,
|
||||
int cx,
|
||||
int vector_dir,
|
||||
float ** neighborArray
|
||||
){
|
||||
float ** neighborArray){
|
||||
int DIM = N;
|
||||
float * target = GET_ARR_RAW(neighborArray,CENTER_LOC);
|
||||
float * target = GET_ARR_RAW(env,neighborArray,CENTER_LOC);
|
||||
float * source;
|
||||
|
||||
|
||||
@ -729,7 +748,7 @@ static inline void copyNeighborsRaw(
|
||||
//_mm256_loadu_ps
|
||||
//_mm256_storeu_ps
|
||||
if(ARR_EXISTS(chunk_mask,0,1,1)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(0,1,1));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(0,1,1));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
// transferVector = _mm512_loadu_ps(&source[IX(DIM-2,x,1)]);
|
||||
// _mm512_storeu_ps(&target[IX(0,x,1)],_mm512_loadu_ps(&source[IX(DIM-2,x,1)]));
|
||||
@ -740,7 +759,7 @@ static inline void copyNeighborsRaw(
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,2,1,1)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(2,1,1));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(2,1,1));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
// _mm512_storeu_ps(&target[IX(DIM-1,x,1)],_mm512_loadu_ps(&source[IX(1,x,1)]));
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
@ -750,7 +769,7 @@ static inline void copyNeighborsRaw(
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,1,0,1)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(1,0,1));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(1,0,1));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
target[IX(x,0,y)] = source[IX(x,DIM-2,y)];
|
||||
@ -759,7 +778,7 @@ static inline void copyNeighborsRaw(
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,1,2,1)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(1,2,1));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(1,2,1));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
target[IX(x,DIM-1,y)] = source[IX(x,1,y)];
|
||||
@ -768,7 +787,7 @@ static inline void copyNeighborsRaw(
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,1,1,0)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(1,1,0));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(1,1,0));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
target[IX(x,y,0)] = source[IX(x,y,DIM-2)];
|
||||
@ -777,7 +796,7 @@ static inline void copyNeighborsRaw(
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,1,1,2)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(1,1,2));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(1,1,2));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
for(int y = 1; y < DIM-1; y++){
|
||||
target[IX(x,y,DIM-1)] = source[IX(x,y,1)];
|
||||
@ -792,28 +811,28 @@ static inline void copyNeighborsRaw(
|
||||
//
|
||||
//
|
||||
if(ARR_EXISTS(chunk_mask,0,0,1)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(0,0,1));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(0,0,1));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(0,0,x)] = source[IX(DIM-2,DIM-2,x)];
|
||||
}
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,2,0,1)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(2,0,1));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(2,0,1));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(DIM-1,0,x)] = source[IX(1,DIM-2,x)];
|
||||
}
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,0,2,1)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(0,2,1));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(0,2,1));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(0,DIM-1,x)] = source[IX(DIM-2,1,x)];
|
||||
}
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,2,2,1)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(2,2,1));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(2,2,1));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(DIM-1,DIM-1,x)] = source[IX(1,1,x)];
|
||||
}
|
||||
@ -823,28 +842,28 @@ static inline void copyNeighborsRaw(
|
||||
//
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,0,1,0)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(0,1,0));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(0,1,0));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(0,x,0)] = source[IX(DIM-2,x,DIM-2)];
|
||||
}
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,2,1,0)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(2,1,0));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(2,1,0));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(DIM-1,x,0)] = source[IX(1,x,DIM-2)];
|
||||
}
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,0,1,2)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(0,1,2));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(0,1,2));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(0,x,DIM-1)] = source[IX(DIM-2,x,1)];
|
||||
}
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,2,1,2)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(2,1,2));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(2,1,2));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(DIM-1,x,DIM-1)] = source[IX(1,x,1)];
|
||||
}
|
||||
@ -854,28 +873,28 @@ static inline void copyNeighborsRaw(
|
||||
//
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,1,0,0)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(1,0,0));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(1,0,0));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(x,0,0)] = source[IX(x,DIM-2,DIM-2)];
|
||||
}
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,1,2,0)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(1,2,0));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(1,2,0));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(x,DIM-1,0)] = source[IX(x,1,DIM-2)];
|
||||
}
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,1,0,2)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(1,0,2));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(1,0,2));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(x,0,DIM-1)] = source[IX(x,DIM-2,1)];
|
||||
}
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,1,2,2)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(1,2,2));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(1,2,2));
|
||||
for(int x=1; x < DIM-1; x++){
|
||||
target[IX(x,DIM-1,DIM-1)] = source[IX(x,1,1)];
|
||||
}
|
||||
@ -889,22 +908,22 @@ static inline void copyNeighborsRaw(
|
||||
//
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,0,0,0)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(0,0,0));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(0,0,0));
|
||||
target[IX(0,0,0)] = source[IX(DIM-2,DIM-2,DIM-2)];
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,2,0,0)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(2,0,0));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(2,0,0));
|
||||
target[IX(DIM-1,0,0)] = source[IX(1,DIM-2,DIM-2)];
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,0,2,0)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(0,2,0));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(0,2,0));
|
||||
target[IX(0,DIM-1,0)] = source[IX(DIM-2,1,DIM-2)];
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,2,2,0)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(2,2,0));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(2,2,0));
|
||||
target[IX(DIM-1,DIM-1,0)] = source[IX(1,1,DIM-2)];
|
||||
}
|
||||
|
||||
@ -912,22 +931,22 @@ static inline void copyNeighborsRaw(
|
||||
//
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,0,0,2)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(0,0,2));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(0,0,2));
|
||||
target[IX(0,0,DIM-1)] = source[IX(DIM-2,DIM-2,1)];
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,2,0,2)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(2,0,2));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(2,0,2));
|
||||
target[IX(DIM-1,0,DIM-1)] = source[IX(1,DIM-2,1)];
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,0,2,2)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(0,2,2));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(0,2,2));
|
||||
target[IX(0,DIM-1,DIM-1)] = source[IX(DIM-2,1,1)];
|
||||
}
|
||||
|
||||
if(ARR_EXISTS(chunk_mask,2,2,2)){
|
||||
source = GET_ARR_RAW(neighborArray,CK(2,2,2));
|
||||
source = GET_ARR_RAW(env,neighborArray,CK(2,2,2));
|
||||
target[IX(DIM-1,DIM-1,DIM-1)] = source[IX(1,1,1)];
|
||||
}
|
||||
|
||||
@ -2,33 +2,30 @@ package electrosphere;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector3i;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
/**
|
||||
* Simulates a fluid via opencl
|
||||
*/
|
||||
public class FluidSim {
|
||||
|
||||
/**
|
||||
* Load fluid sim library
|
||||
*/
|
||||
static {
|
||||
String osName = System.getProperty("os.name").toLowerCase();
|
||||
System.out.println(osName);
|
||||
if(osName.contains("win")){
|
||||
System.load(new File("./shared-folder/libfluidsim.dll").toPath().toAbsolutePath().toString());
|
||||
} else {
|
||||
System.load(new File("./shared-folder/libfluidsim.so").toPath().toAbsolutePath().toString());
|
||||
}
|
||||
System.out.println(System.getProperty("user.dir"));
|
||||
System.load(System.getProperty("user.dir") + "/shared-folder/libfluidsim.dll");
|
||||
}
|
||||
|
||||
public static final int DIM = 18;
|
||||
@ -76,12 +73,12 @@ public class FluidSim {
|
||||
public int chunkMask = 0;
|
||||
|
||||
|
||||
static final float DIFFUSION_CONSTANT = 0.00001f;
|
||||
static final float VISCOSITY_CONSTANT = 0.00001f;
|
||||
static final float DIFFUSION_CONSTANT = 0.0f;
|
||||
static final float VISCOSITY_CONSTANT = 0.0f;
|
||||
|
||||
static final int LINEARSOLVERTIMES = 20;
|
||||
|
||||
static final float GRAVITY = -1000f;
|
||||
static final float GRAVITY = -100f;
|
||||
|
||||
public void setup(Vector3i offset){
|
||||
//allocate buffers for this chunk
|
||||
@ -109,51 +106,50 @@ public class FluidSim {
|
||||
FloatBuffer vf = vVector[13].asFloatBuffer();
|
||||
FloatBuffer wf = wVector[13].asFloatBuffer();
|
||||
|
||||
Random rand = new Random(1);
|
||||
//make a cube of water in the center
|
||||
for(int i = 0; i < DIM; i++){
|
||||
for(int j = 0; j < DIM; j++){
|
||||
for(int k = 0; k < DIM; k++){
|
||||
// if(offset.x == 0 && offset.y == 0 && offset.z == 0){
|
||||
if(offset.x == 0 && offset.y == 0 && offset.z == 0){
|
||||
if(
|
||||
Math.abs(16 - i) < 4 &&
|
||||
Math.abs(8 - j) < 4 &&
|
||||
Math.abs(10 - k) < 4
|
||||
// &&
|
||||
// i < 17 && i > 0 &&
|
||||
// j < 17 && j > 0 &&
|
||||
// k < 17 && k > 0
|
||||
Math.abs(16 - i) < 5 &&
|
||||
Math.abs(j) < 5 &&
|
||||
Math.abs(16 - k) < 5 &&
|
||||
i < 17 && i > 0 &&
|
||||
j < 17 && j > 0 &&
|
||||
k < 17 && k > 0
|
||||
){
|
||||
xf.put(1);
|
||||
uf.put(0.1f);
|
||||
vf.put(-1);
|
||||
wf.put(0.1f);
|
||||
}
|
||||
else {
|
||||
uf.put(50);
|
||||
vf.put(0);
|
||||
wf.put(0);
|
||||
} else {
|
||||
xf.put(0);
|
||||
uf.put(0);
|
||||
vf.put(0);
|
||||
wf.put(0);
|
||||
}
|
||||
// } else {
|
||||
// if(
|
||||
// Math.abs(0 - i) < 5 &&
|
||||
// Math.abs(j) < 5 &&
|
||||
// Math.abs(0 - k) < 5 &&
|
||||
// i < 17 && i > 0 &&
|
||||
// j < 17 && j > 0 &&
|
||||
// k < 17 && k > 0
|
||||
// ){
|
||||
// // xf.put(1);
|
||||
// // uf.put(50);
|
||||
// // vf.put(0);
|
||||
// // wf.put(rand.nextFloat() * 0.1f);
|
||||
// } else {
|
||||
// xf.put(0);
|
||||
// uf.put(0);
|
||||
// vf.put(0);
|
||||
// wf.put(0);
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
if(
|
||||
Math.abs(0 - i) < 5 &&
|
||||
Math.abs(j) < 5 &&
|
||||
Math.abs(0 - k) < 5 &&
|
||||
i < 17 && i > 0 &&
|
||||
j < 17 && j > 0 &&
|
||||
k < 17 && k > 0
|
||||
){
|
||||
// xf.put(1);
|
||||
// uf.put(50);
|
||||
// vf.put(0);
|
||||
// wf.put(rand.nextFloat() * 0.1f);
|
||||
} else {
|
||||
xf.put(0);
|
||||
uf.put(0);
|
||||
vf.put(0);
|
||||
wf.put(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -164,10 +160,6 @@ public class FluidSim {
|
||||
static double lastTime = 0;
|
||||
public static void simChunks(FluidSim[][][] simArray, int step, float timestep){
|
||||
|
||||
// simArray[0][1][2].density0ArrayView[IX(10,10,3)] = 3.0f;
|
||||
// simArray[2][1][2].density0ArrayView[IX(10,10,3)] = 3.0f;
|
||||
// simArray[2][1][0].density0ArrayView[IX(10,10,3)] = 3.0f;
|
||||
|
||||
List<FluidSim> chunksToSim = new LinkedList<FluidSim>();
|
||||
//
|
||||
//init data for upcoming frame
|
||||
@ -193,7 +185,7 @@ public class FluidSim {
|
||||
lastTime = GLFW.glfwGetTime();
|
||||
//
|
||||
//simulate
|
||||
simulateWrapper(chunksToSim,0.01f);
|
||||
simulateWrapper(chunksToSim,timestep);
|
||||
//clock
|
||||
time = time + (GLFW.glfwGetTime() - lastTime);
|
||||
i++;
|
||||
@ -201,6 +193,8 @@ public class FluidSim {
|
||||
System.out.println(time / 100.0 * 1000.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
//Read out of buffers back into accessible arrays
|
||||
@ -214,100 +208,6 @@ public class FluidSim {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(Main.endStep == 0){
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
//Management functions
|
||||
//
|
||||
//
|
||||
/**
|
||||
* Creates a fluid simulation array based on a given dimension set
|
||||
* @param dimx the x dimension
|
||||
* @param dimy the y dimension
|
||||
* @param dimz the z dimension
|
||||
* @return The array of fluid sim chunks
|
||||
*/
|
||||
public static FluidSim[][][] initFluidSim(int dimx, int dimy, int dimz){
|
||||
FluidSim[][][] simArray = new FluidSim[dimx][dimy][dimz];
|
||||
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] = new FluidSim();
|
||||
simArray[x][y][z].setup(new Vector3i(x,y,z));
|
||||
}
|
||||
}
|
||||
}
|
||||
//set sim adjacencies
|
||||
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++){
|
||||
FluidSim current = simArray[x][y][z];
|
||||
|
||||
for(int i = -1; i < 2; i++){
|
||||
for(int j = -1; j < 2; j++){
|
||||
for(int k = -1; k < 2; k++){
|
||||
if(i == j && j == k && k == 0){
|
||||
continue;
|
||||
}
|
||||
if(
|
||||
0 <= x + i && x + i < simArray.length &&
|
||||
0 <= y + j && y + j < simArray[0].length &&
|
||||
0 <= z + k && z + k < simArray[0][0].length
|
||||
){
|
||||
current.setNeighbor(i+1,j+1,k+1,simArray[x+i][y+j][z+k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return simArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void printLayer(FluidSim[][][] simArray, int step, int layer){
|
||||
if(step == 0){
|
||||
for(int x = 0; x < DIM; x++){
|
||||
for(int y = 0; y < DIM; y++){
|
||||
System.out.printf("%.2f\t",simArray[0][0][0].uArrayView[IX(x,layer,y)]);
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double sumAllDensity(FluidSim[][][] simArray){
|
||||
@ -447,23 +347,7 @@ public class FluidSim {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Dumps this chunk's density values to disk
|
||||
* @param path the path to dump to
|
||||
*/
|
||||
public void dumpToDisk(String path){
|
||||
OutputStream fileOS = null;
|
||||
try {
|
||||
fileOS = Files.newOutputStream(new File(path).toPath());
|
||||
ByteBuffer density = this.density[13];
|
||||
while(density.hasRemaining()){
|
||||
fileOS.write(density.get());
|
||||
}
|
||||
fileOS.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2,9 +2,9 @@ package electrosphere;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.joml.Vector3i;
|
||||
@ -17,40 +17,30 @@ import electrosphere.render.Mesh;
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
static boolean render = false;
|
||||
public static int endStep = -1;
|
||||
|
||||
public static final float TIMESTEP = 0.001f;
|
||||
|
||||
|
||||
public static void main(String args[]){
|
||||
|
||||
int dim = 3;
|
||||
int vdim = 3;
|
||||
int dim = 5;
|
||||
int i = 0;
|
||||
long time = 0;
|
||||
long lastTime = 0;
|
||||
Scanner scan = new Scanner(System.in);
|
||||
|
||||
try {
|
||||
|
||||
if(render){
|
||||
GLFWContext.init();
|
||||
GLFWContext.init();
|
||||
|
||||
//init shader program
|
||||
Mesh.initShaderProgram();
|
||||
}
|
||||
//init shader program
|
||||
Mesh.initShaderProgram();
|
||||
|
||||
|
||||
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,vdim,dim);
|
||||
FluidSim[][][] simArray = initFluidSim(dim,1,dim);
|
||||
|
||||
Mesh[][][] meshArray = null;
|
||||
if(render){
|
||||
meshArray = initMeshes(dim,vdim,dim,simArray);
|
||||
}
|
||||
Mesh[][][] meshArray = initMeshes(dim,1,dim,simArray);
|
||||
|
||||
|
||||
//uncomment this to generate test data
|
||||
// generateTestData();
|
||||
|
||||
while(true){
|
||||
try {
|
||||
@ -65,24 +55,20 @@ public class Main {
|
||||
//
|
||||
//Simulate
|
||||
//
|
||||
FluidSim.simChunks(simArray,i,TIMESTEP);
|
||||
FluidSim.simChunks(simArray,i,0.01f);
|
||||
//
|
||||
//Remesh
|
||||
//
|
||||
if(render){
|
||||
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++){
|
||||
meshArray[x][y][z].remesh();
|
||||
}
|
||||
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++){
|
||||
meshArray[x][y][z].remesh();
|
||||
}
|
||||
}
|
||||
}
|
||||
time = time + (System.currentTimeMillis() - lastTime);
|
||||
//redraw
|
||||
if(render){
|
||||
GLFWContext.redraw(meshArray);
|
||||
}
|
||||
GLFWContext.redraw(meshArray);
|
||||
i++;
|
||||
if(i == 100){
|
||||
System.out.println("overall time: " + time / 100.0);
|
||||
@ -96,6 +82,45 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
private static FluidSim[][][] initFluidSim(int dimx, int dimy, int dimz){
|
||||
FluidSim[][][] simArray = new FluidSim[dimx][dimy][dimz];
|
||||
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] = new FluidSim();
|
||||
simArray[x][y][z].setup(new Vector3i(x,y,z));
|
||||
}
|
||||
}
|
||||
}
|
||||
//set sim adjacencies
|
||||
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++){
|
||||
FluidSim current = simArray[x][y][z];
|
||||
|
||||
for(int i = -1; i < 2; i++){
|
||||
for(int j = -1; j < 2; j++){
|
||||
for(int k = -1; k < 2; k++){
|
||||
if(i == j && j == k && k == 0){
|
||||
continue;
|
||||
}
|
||||
if(
|
||||
0 <= x + i && x + i < simArray.length &&
|
||||
0 <= y + j && y + j < simArray[0].length &&
|
||||
0 <= z + k && z + k < simArray[0][0].length
|
||||
){
|
||||
current.setNeighbor(i+1,j+1,k+1,simArray[x+i][y+j][z+k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return simArray;
|
||||
}
|
||||
|
||||
private static Mesh[][][] initMeshes(int dimx, int dimy, int dimz, FluidSim[][][] simArray){
|
||||
Mesh[][][] meshArray = new Mesh[dimx][dimy][dimz];
|
||||
for(int x = 0; x < simArray.length; x++){
|
||||
@ -109,126 +134,4 @@ public class Main {
|
||||
return meshArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates test data on disk in the test resources folder
|
||||
*/
|
||||
private static void generateTestData(){
|
||||
|
||||
//variables that will be used in generating data
|
||||
int i = 0;
|
||||
int dim = 1;
|
||||
int length = 500;
|
||||
FluidSim[][][] simArray;
|
||||
int[] dims = new int[]{1,3,5};
|
||||
int[] lengths = new int[]{1,50,100,500};
|
||||
render = false;
|
||||
|
||||
//clean up existing data
|
||||
//this is scary recursive file logic, but the innermost callback has a guard to guarantee the file is underneath the testdata path
|
||||
while(Files.exists(new File("./src/test/resources/testdata").toPath())){
|
||||
try {
|
||||
Files.walk(new File("./src/test/resources/testdata").toPath()).forEach(path -> {
|
||||
Path parent = new File("./src/test/resources/testdata").toPath().toAbsolutePath();
|
||||
Path child = path.toAbsolutePath();
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(child.startsWith(parent)){
|
||||
try {
|
||||
System.out.println("Deleting " + path);
|
||||
Files.delete(path);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Failed to delete " + path);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//create folders to contain test data
|
||||
try {
|
||||
Files.createDirectory(new File("./src/test/resources/testdata").toPath());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
for(int dimIterator = 0; dimIterator < dims.length; dimIterator++){
|
||||
dim = dims[dimIterator];
|
||||
try {
|
||||
Files.createDirectory(new File("./src/test/resources/testdata/" + dim + "by" + dim).toPath());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
for(int lengthIterator = 0; lengthIterator < lengths.length; lengthIterator++){
|
||||
length = lengths[lengthIterator];
|
||||
try {
|
||||
Files.createDirectory(new File("./src/test/resources/testdata/" + dim + "by" + dim + "/" + length + "steps").toPath());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//main data generation loop
|
||||
for(int dimIterator = 0; dimIterator < dims.length; dimIterator++){
|
||||
for(int lengthIterator = 0; lengthIterator < lengths.length; lengthIterator++){
|
||||
|
||||
|
||||
//actual main routine to generate data starts here
|
||||
dim = dims[dimIterator];
|
||||
length = lengths[lengthIterator];
|
||||
System.out.println("Generating " + dim + "x" + dim + "x" + dim + " for " + length + " steps");
|
||||
|
||||
i = 0;
|
||||
simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
for(i = 0; i < length; i++){
|
||||
FluidSim.simChunks(simArray,i,TIMESTEP);
|
||||
}
|
||||
|
||||
for(int x = 0; x < dim; x++){
|
||||
for(int y = 0; y < dim; y++){
|
||||
for(int z = 0; z < dim; z++){
|
||||
simArray[x][y][z].dumpToDisk("./src/test/resources/testdata/" + dim + "by" + dim + "/" + length + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + length + "Step.data");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int x = 0; x < dim; x++){
|
||||
for(int y = 0; y < dim; y++){
|
||||
for(int z = 0; z < dim; z++){
|
||||
byte[] bytes;
|
||||
try {
|
||||
bytes = Files.readAllBytes(new File("./src/test/resources/testdata/" + dim + "by" + dim + "/" + length + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + length + "Step.data").toPath());
|
||||
ByteBuffer densityBytes = simArray[0][0][0].getDensityBuffer();
|
||||
i = 0;
|
||||
while(densityBytes.hasRemaining()){
|
||||
boolean pass = bytes[i] == densityBytes.get();
|
||||
if(!pass){
|
||||
System.err.println("failed to pass!");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package electrosphere.render;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL44;
|
||||
@ -37,6 +38,9 @@ public class GLFWContext {
|
||||
GLFW.glfwMakeContextCurrent(window);
|
||||
//Maximize it
|
||||
GLFW.glfwMaximizeWindow(window);
|
||||
//grab actual framebuffer
|
||||
int bufferWidth = 0;
|
||||
int bufferHeight = 0;
|
||||
|
||||
try(MemoryStack stack = MemoryStack.stackPush()){
|
||||
IntBuffer xBuffer = MemoryUtil.memAllocInt(1);
|
||||
@ -44,6 +48,9 @@ public class GLFWContext {
|
||||
GLFW.glfwGetFramebufferSize(window, xBuffer, yBuffer);
|
||||
MemoryUtil.memFree(xBuffer);
|
||||
MemoryUtil.memFree(yBuffer);
|
||||
|
||||
bufferWidth = xBuffer.get();
|
||||
bufferHeight = yBuffer.get();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
package electrosphere.render;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.file.Files;
|
||||
@ -14,8 +17,11 @@ import java.util.Map;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL33;
|
||||
import org.lwjgl.opengl.GL44;
|
||||
import org.lwjgl.opengl.GL45;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import electrosphere.FluidSim;
|
||||
@ -104,6 +110,7 @@ public class Mesh {
|
||||
FloatBuffer NormalArrayBufferData;
|
||||
if(normalCount > 0){
|
||||
NormalArrayBufferData = MemoryUtil.memAllocFloat(normalCount * 3);
|
||||
float[] temp = new float[3];
|
||||
for(float normalValue : data.normals){
|
||||
NormalArrayBufferData.put(normalValue);
|
||||
}
|
||||
@ -235,7 +242,8 @@ public class Mesh {
|
||||
|
||||
public static void initShaderProgram(){
|
||||
String vsSrc = "";
|
||||
try (BufferedReader is = new BufferedReader(Files.newBufferedReader(new File("./src/main/resources/shader.vs").toPath()))){
|
||||
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
||||
try (BufferedReader is = new BufferedReader(Files.newBufferedReader(new File("C:\\Users\\satellite\\Documents\\fluid-sim\\src\\main\\resources\\shader.vs").toPath()))){
|
||||
String temp;
|
||||
while((temp = is.readLine())!=null){
|
||||
vsSrc = vsSrc + temp + "\n";
|
||||
@ -246,7 +254,7 @@ public class Mesh {
|
||||
}
|
||||
|
||||
String fsSrc = "";
|
||||
try (BufferedReader is = new BufferedReader(Files.newBufferedReader(new File("./src/main/resources/shader.fs").toPath()))){
|
||||
try (BufferedReader is = new BufferedReader(Files.newBufferedReader(new File("C:\\Users\\satellite\\Documents\\fluid-sim\\src\\main\\resources\\shader.fs").toPath()))){
|
||||
String temp;
|
||||
while((temp = is.readLine())!=null){
|
||||
fsSrc = fsSrc + temp + "\n";
|
||||
|
||||
@ -10,7 +10,6 @@ vec3 dLDiffuse = vec3(0.5,0.5,0.5);
|
||||
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec3 rawPos;
|
||||
|
||||
|
||||
uniform vec3 viewPos;
|
||||
@ -27,15 +26,7 @@ void main(){
|
||||
|
||||
vec3 lightAmount = CalcDirLight(norm, viewDir);
|
||||
|
||||
vec3 color = vec3(0.3,0.7,0.9);
|
||||
if(
|
||||
rawPos.x < 2 || rawPos.x > 16 ||
|
||||
rawPos.y < 2 || rawPos.y > 16 ||
|
||||
rawPos.z < 2 || rawPos.z > 16
|
||||
){
|
||||
color = vec3(0.9,0.7,0.3);
|
||||
}
|
||||
color = color * lightAmount;
|
||||
vec3 color = vec3(0.3,0.7,0.9) * lightAmount;
|
||||
|
||||
//this final calculation is for transparency
|
||||
FragColor = vec4(color,1.0);
|
||||
|
||||
@ -16,7 +16,6 @@ uniform mat4 projection;
|
||||
//output buffers
|
||||
out vec3 Normal;
|
||||
out vec3 FragPos;
|
||||
out vec3 rawPos;
|
||||
|
||||
|
||||
|
||||
@ -30,7 +29,6 @@ void main() {
|
||||
//push frag, normal, and texture positions to fragment shader
|
||||
FragPos = vec3(model * FinalVertex);
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
rawPos = aPos;
|
||||
|
||||
|
||||
//set final position with opengl space
|
||||
|
||||
@ -1,185 +0,0 @@
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import electrosphere.FluidSim;
|
||||
import electrosphere.Main;
|
||||
|
||||
public class LongRunTests {
|
||||
|
||||
// @Test
|
||||
// public void test5by5Chunk1Step(){
|
||||
|
||||
// int dim = 5;
|
||||
// int maxTimestep = 1;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
|
||||
// fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// fromDiskBuffer.put(bytes);
|
||||
// fromDiskBuffer.flip();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = fromDiskBuffer.get() == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test5by5Chunk50Step(){
|
||||
|
||||
// int dim = 5;
|
||||
// int maxTimestep = 50;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = bytes[i] == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test5by5Chunk100Step(){
|
||||
|
||||
// int dim = 5;
|
||||
// int maxTimestep = 100;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = bytes[i] == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test5by5Chunk500Step(){
|
||||
|
||||
// int dim = 5;
|
||||
// int maxTimestep = 500;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = bytes[i] == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
@ -1,197 +0,0 @@
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import electrosphere.FluidSim;
|
||||
import electrosphere.Main;
|
||||
|
||||
public class MediumRunTests {
|
||||
|
||||
// @Test
|
||||
// public void test3by3Chunk1Step(){
|
||||
|
||||
// int dim = 3;
|
||||
// int maxTimestep = 1;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
|
||||
// fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// fromDiskBuffer.put(bytes);
|
||||
// fromDiskBuffer.flip();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = fromDiskBuffer.get() == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test3by3Chunk50Step(){
|
||||
|
||||
// int dim = 3;
|
||||
// int maxTimestep = 50;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
|
||||
// fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// fromDiskBuffer.put(bytes);
|
||||
// fromDiskBuffer.flip();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = fromDiskBuffer.get() == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test3by3Chunk100Step(){
|
||||
|
||||
// int dim = 3;
|
||||
// int maxTimestep = 100;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
|
||||
// fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// fromDiskBuffer.put(bytes);
|
||||
// fromDiskBuffer.flip();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = fromDiskBuffer.get() == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test3by3Chunk500Step(){
|
||||
|
||||
// int dim = 3;
|
||||
// int maxTimestep = 500;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
|
||||
// fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// fromDiskBuffer.put(bytes);
|
||||
// fromDiskBuffer.flip();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = fromDiskBuffer.get() == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
@ -1,202 +0,0 @@
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import electrosphere.FluidSim;
|
||||
import electrosphere.Main;
|
||||
|
||||
/**
|
||||
* Tests stepping a single chunk by a single frame
|
||||
*/
|
||||
public class ShortRunTest {
|
||||
|
||||
// @Test
|
||||
// public void test1by1Chunk1Step(){
|
||||
|
||||
// int dim = 1;
|
||||
// int maxTimestep = 1;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
|
||||
// fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// fromDiskBuffer.put(bytes);
|
||||
// fromDiskBuffer.flip();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = fromDiskBuffer.get() == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test1by1Chunk50Step(){
|
||||
|
||||
// int dim = 1;
|
||||
// int maxTimestep = 50;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
|
||||
// fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// fromDiskBuffer.put(bytes);
|
||||
// fromDiskBuffer.flip();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = fromDiskBuffer.get() == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test1by1Chunk100Step(){
|
||||
|
||||
// int dim = 1;
|
||||
// int maxTimestep = 100;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
|
||||
// fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// fromDiskBuffer.put(bytes);
|
||||
// fromDiskBuffer.flip();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = fromDiskBuffer.get() == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void test1by1Chunk500Step(){
|
||||
|
||||
// int dim = 1;
|
||||
// int maxTimestep = 500;
|
||||
|
||||
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
|
||||
|
||||
// //init chunk array
|
||||
// FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
|
||||
|
||||
// //simulate the chunk
|
||||
// for(int i = 0; i < maxTimestep; i++){
|
||||
// FluidSim.simChunks(simArray, i, Main.TIMESTEP);
|
||||
// }
|
||||
|
||||
// for(int x = 0; x < dim; x++){
|
||||
// for(int y = 0; y < dim; y++){
|
||||
// for(int z = 0; z < dim; z++){
|
||||
// InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
|
||||
// byte[] bytes;
|
||||
// try {
|
||||
// bytes = testFileIS.readAllBytes();
|
||||
// ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
|
||||
// fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// fromDiskBuffer.put(bytes);
|
||||
// fromDiskBuffer.flip();
|
||||
// ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
|
||||
// int i = 0;
|
||||
// while(densityBytes.hasRemaining()){
|
||||
// boolean pass = fromDiskBuffer.get() == densityBytes.get();
|
||||
// assert(pass);
|
||||
// i++;
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// assert(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.out.println("PASSED");
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
|
||||
vec3 color = vec3(0.3,0.7,0.9);
|
||||
|
||||
vec3 dLDirection = vec3(0.1,-0.9,0.1);
|
||||
vec3 dLDiffuse = vec3(0.5,0.5,0.5);
|
||||
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec3 rawPos;
|
||||
|
||||
|
||||
uniform vec3 viewPos;
|
||||
// uniform DirLight dirLight;
|
||||
// uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||
// uniform SpotLight spotLight;
|
||||
|
||||
// function prototypes
|
||||
vec3 CalcDirLight(vec3 normal, vec3 viewDir);
|
||||
|
||||
void main(){
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
vec3 lightAmount = CalcDirLight(norm, viewDir);
|
||||
|
||||
vec3 color = vec3(0.3,0.7,0.9);
|
||||
if(
|
||||
rawPos.x < 2 || rawPos.x > 16 ||
|
||||
rawPos.y < 2 || rawPos.y > 16 ||
|
||||
rawPos.z < 2 || rawPos.z > 16
|
||||
){
|
||||
color = vec3(0.9,0.7,0.3);
|
||||
}
|
||||
color = color * lightAmount;
|
||||
|
||||
//this final calculation is for transparency
|
||||
FragColor = vec4(color,1.0);
|
||||
}
|
||||
|
||||
vec3 CalcDirLight(vec3 normal, vec3 viewDir){
|
||||
vec3 lightDir = normalize(-dLDirection);
|
||||
// diffuse shading
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
// specular shading
|
||||
vec3 reflectDir = reflect(-lightDir, normal);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 0.6);
|
||||
// combine results
|
||||
vec3 diffuse = dLDiffuse * diff;
|
||||
|
||||
vec3 specular = spec * color;
|
||||
|
||||
return diffuse + specular;
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
//Vertex Shader
|
||||
#version 330 core
|
||||
|
||||
//input buffers
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
|
||||
|
||||
//coordinate space transformation matrices
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
|
||||
|
||||
//output buffers
|
||||
out vec3 Normal;
|
||||
out vec3 FragPos;
|
||||
out vec3 rawPos;
|
||||
|
||||
|
||||
|
||||
|
||||
void main() {
|
||||
//normalize posiiton and normal
|
||||
vec4 FinalVertex = vec4(aPos, 1.0);
|
||||
vec4 FinalNormal = vec4(aNormal, 1.0);
|
||||
|
||||
|
||||
//push frag, normal, and texture positions to fragment shader
|
||||
FragPos = vec3(model * FinalVertex);
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
rawPos = aPos;
|
||||
|
||||
|
||||
//set final position with opengl space
|
||||
gl_Position = projection * view * model * FinalVertex;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user