Merge branch 'master' of git.austinwhoover.com:studiorailgun/fluid-sim
All checks were successful
studiorailgun/fluid-sim/pipeline/head This commit looks good

This commit is contained in:
unknown 2024-03-15 21:18:55 -04:00
commit db89bc4ff4
9 changed files with 365 additions and 313 deletions

1
.gitignore vendored
View File

@ -7,5 +7,4 @@
/.project /.project
/shared-folder /shared-folder
/shared-folder/** /shared-folder/**
/src/main/c/lib/**
/chunks /chunks

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "src/main/c/lib/stb"]
path = src/main/c/lib/stb
url = https://github.com/nothings/stb.git

View File

@ -58,12 +58,12 @@ rm -f ./*.dll
# OUTPUT_FILE="./chunkmask.o" # OUTPUT_FILE="./chunkmask.o"
# gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE # gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow" COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -DSAVE_STEPS=$SAVE_STEPS"
INPUT_FILES="./src/javainterface.c" INPUT_FILES="./src/javainterface.c"
OUTPUT_FILE="./javainterface.o" OUTPUT_FILE="./javainterface.o"
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE
COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -msse -msse2 -msse3 -mmmx -m3dnow -DSAVE_STEPS=$SAVE_STEPS" COMPILE_FLAGS="-c -fPIC -m64 -mavx -mavx2 -march=native -Ofast -DSAVE_STEPS=$SAVE_STEPS"
INPUT_FILES="./src/fluidsim.c" INPUT_FILES="./src/fluidsim.c"
OUTPUT_FILE="./fluidsim.o" OUTPUT_FILE="./fluidsim.o"
gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE gcc $COMPILE_FLAGS -I"$BASE_INCLUDE_DIR" -I"$OS_INCLUDE_DIR" $INPUT_FILES -o $OUTPUT_FILE

1
src/main/c/lib/stb Submodule

@ -0,0 +1 @@
Subproject commit ae721c50eaf761660b4f90cc590453cdb0c2acd0

View File

@ -24,9 +24,17 @@ import org.lwjgl.system.MemoryUtil;
*/ */
public class FluidSim { public class FluidSim {
/**
* Load fluid sim library
*/
static { static {
System.out.println(System.getProperty("user.dir")); String osName = System.getProperty("os.name").toLowerCase();
System.load(System.getProperty("user.dir") + "/shared-folder/libfluidsim.dll"); 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());
}
} }
public static final int DIM = 18; public static final int DIM = 18;

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -28,8 +29,8 @@ public class Main {
public static void main(String args[]){ public static void main(String args[]){
int dim = 5; int dim = 1;
int vdim = 5; int vdim = 1;
int i = 0; int i = 0;
long time = 0; long time = 0;
long lastTime = 0; long lastTime = 0;
@ -52,6 +53,7 @@ public class Main {
meshArray = initMeshes(dim,vdim,dim,simArray); meshArray = initMeshes(dim,vdim,dim,simArray);
} }
//uncomment this to generate test data //uncomment this to generate test data
// generateTestData(); // generateTestData();

View File

@ -1,6 +1,7 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.junit.Test; import org.junit.Test;
@ -9,47 +10,51 @@ import electrosphere.Main;
public class LongRunTests { public class LongRunTests {
@Test // @Test
public void test5by5Chunk1Step(){ // public void test5by5Chunk1Step(){
int dim = 5; // int dim = 5;
int maxTimestep = 1; // int maxTimestep = 1;
System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps"); // System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
//init chunk array // //init chunk array
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim); // FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
//simulate the chunk // //simulate the chunk
for(int i = 0; i < maxTimestep; i++){ // for(int i = 0; i < maxTimestep; i++){
FluidSim.simChunks(simArray, i, Main.TIMESTEP); // FluidSim.simChunks(simArray, i, Main.TIMESTEP);
} // }
for(int x = 0; x < dim; x++){ // for(int x = 0; x < dim; x++){
for(int y = 0; y < dim; y++){ // for(int y = 0; y < dim; y++){
for(int z = 0; z < dim; z++){ // 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"); // InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
byte[] bytes; // byte[] bytes;
try { // try {
bytes = testFileIS.readAllBytes(); // bytes = testFileIS.readAllBytes();
ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer(); // ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
int i = 0; // fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
while(densityBytes.hasRemaining()){ // fromDiskBuffer.put(bytes);
boolean pass = bytes[i] == densityBytes.get(); // fromDiskBuffer.flip();
assert(pass); // ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
i++; // int i = 0;
} // while(densityBytes.hasRemaining()){
} catch (IOException e) { // boolean pass = fromDiskBuffer.get() == densityBytes.get();
e.printStackTrace(); // assert(pass);
assert(false); // i++;
} // }
} // } catch (IOException e) {
} // e.printStackTrace();
} // assert(false);
// }
// }
// }
// }
System.out.println("PASSED"); // System.out.println("PASSED");
} // }
// @Test // @Test
// public void test5by5Chunk50Step(){ // public void test5by5Chunk50Step(){

View File

@ -1,6 +1,7 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.junit.Test; import org.junit.Test;
@ -9,172 +10,188 @@ import electrosphere.Main;
public class MediumRunTests { public class MediumRunTests {
@Test // @Test
public void test3by3Chunk1Step(){ // public void test3by3Chunk1Step(){
int dim = 3; // int dim = 3;
int maxTimestep = 1; // int maxTimestep = 1;
System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps"); // System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
//init chunk array // //init chunk array
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim); // FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
//simulate the chunk // //simulate the chunk
for(int i = 0; i < maxTimestep; i++){ // for(int i = 0; i < maxTimestep; i++){
FluidSim.simChunks(simArray, i, Main.TIMESTEP); // FluidSim.simChunks(simArray, i, Main.TIMESTEP);
} // }
for(int x = 0; x < dim; x++){ // for(int x = 0; x < dim; x++){
for(int y = 0; y < dim; y++){ // for(int y = 0; y < dim; y++){
for(int z = 0; z < dim; z++){ // 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"); // InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
byte[] bytes; // byte[] bytes;
try { // try {
bytes = testFileIS.readAllBytes(); // bytes = testFileIS.readAllBytes();
ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer(); // ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
int i = 0; // fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
while(densityBytes.hasRemaining()){ // fromDiskBuffer.put(bytes);
boolean pass = bytes[i] == densityBytes.get(); // fromDiskBuffer.flip();
assert(pass); // ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
i++; // int i = 0;
} // while(densityBytes.hasRemaining()){
} catch (IOException e) { // boolean pass = fromDiskBuffer.get() == densityBytes.get();
e.printStackTrace(); // assert(pass);
assert(false); // i++;
} // }
} // } catch (IOException e) {
} // e.printStackTrace();
} // assert(false);
// }
// }
// }
// }
System.out.println("PASSED"); // System.out.println("PASSED");
} // }
@Test // @Test
public void test3by3Chunk50Step(){ // public void test3by3Chunk50Step(){
int dim = 3; // int dim = 3;
int maxTimestep = 50; // int maxTimestep = 50;
System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps"); // System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
//init chunk array // //init chunk array
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim); // FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
//simulate the chunk // //simulate the chunk
for(int i = 0; i < maxTimestep; i++){ // for(int i = 0; i < maxTimestep; i++){
FluidSim.simChunks(simArray, i, Main.TIMESTEP); // FluidSim.simChunks(simArray, i, Main.TIMESTEP);
} // }
for(int x = 0; x < dim; x++){ // for(int x = 0; x < dim; x++){
for(int y = 0; y < dim; y++){ // for(int y = 0; y < dim; y++){
for(int z = 0; z < dim; z++){ // 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"); // InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
byte[] bytes; // byte[] bytes;
try { // try {
bytes = testFileIS.readAllBytes(); // bytes = testFileIS.readAllBytes();
ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer(); // ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
int i = 0; // fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
while(densityBytes.hasRemaining()){ // fromDiskBuffer.put(bytes);
boolean pass = bytes[i] == densityBytes.get(); // fromDiskBuffer.flip();
assert(pass); // ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
i++; // int i = 0;
} // while(densityBytes.hasRemaining()){
} catch (IOException e) { // boolean pass = fromDiskBuffer.get() == densityBytes.get();
e.printStackTrace(); // assert(pass);
assert(false); // i++;
} // }
} // } catch (IOException e) {
} // e.printStackTrace();
} // assert(false);
// }
System.out.println("PASSED"); // }
// }
} // }
@Test // System.out.println("PASSED");
public void test3by3Chunk100Step(){
// }
int dim = 3;
int maxTimestep = 100; // @Test
// public void test3by3Chunk100Step(){
System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
// int dim = 3;
//init chunk array // int maxTimestep = 100;
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
//simulate the chunk
for(int i = 0; i < maxTimestep; i++){ // //init chunk array
FluidSim.simChunks(simArray, i, Main.TIMESTEP); // FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
}
// //simulate the chunk
for(int x = 0; x < dim; x++){ // for(int i = 0; i < maxTimestep; i++){
for(int y = 0; y < dim; y++){ // FluidSim.simChunks(simArray, i, Main.TIMESTEP);
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; // for(int x = 0; x < dim; x++){
try { // for(int y = 0; y < dim; y++){
bytes = testFileIS.readAllBytes(); // for(int z = 0; z < dim; z++){
ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer(); // InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
int i = 0; // byte[] bytes;
while(densityBytes.hasRemaining()){ // try {
boolean pass = bytes[i] == densityBytes.get(); // bytes = testFileIS.readAllBytes();
assert(pass); // ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
i++; // fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
} // fromDiskBuffer.put(bytes);
} catch (IOException e) { // fromDiskBuffer.flip();
e.printStackTrace(); // ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
assert(false); // int i = 0;
} // while(densityBytes.hasRemaining()){
} // boolean pass = fromDiskBuffer.get() == densityBytes.get();
} // assert(pass);
} // i++;
// }
System.out.println("PASSED"); // } catch (IOException e) {
// e.printStackTrace();
} // assert(false);
// }
@Test // }
public void test3by3Chunk500Step(){ // }
// }
int dim = 3;
int maxTimestep = 500; // System.out.println("PASSED");
System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps"); // }
//init chunk array // @Test
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim); // public void test3by3Chunk500Step(){
//simulate the chunk // int dim = 3;
for(int i = 0; i < maxTimestep; i++){ // int maxTimestep = 500;
FluidSim.simChunks(simArray, i, Main.TIMESTEP);
} // System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
for(int x = 0; x < dim; x++){ // //init chunk array
for(int y = 0; y < dim; y++){ // FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
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"); // //simulate the chunk
byte[] bytes; // for(int i = 0; i < maxTimestep; i++){
try { // FluidSim.simChunks(simArray, i, Main.TIMESTEP);
bytes = testFileIS.readAllBytes(); // }
ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
int i = 0; // for(int x = 0; x < dim; x++){
while(densityBytes.hasRemaining()){ // for(int y = 0; y < dim; y++){
boolean pass = bytes[i] == densityBytes.get(); // for(int z = 0; z < dim; z++){
assert(pass); // InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
i++; // byte[] bytes;
} // try {
} catch (IOException e) { // bytes = testFileIS.readAllBytes();
e.printStackTrace(); // ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
assert(false); // fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
} // fromDiskBuffer.put(bytes);
} // fromDiskBuffer.flip();
} // ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
} // int i = 0;
// while(densityBytes.hasRemaining()){
System.out.println("PASSED"); // boolean pass = fromDiskBuffer.get() == densityBytes.get();
// assert(pass);
} // i++;
// }
// } catch (IOException e) {
// e.printStackTrace();
// assert(false);
// }
// }
// }
// }
// System.out.println("PASSED");
// }
} }

View File

@ -3,6 +3,7 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.junit.Test; import org.junit.Test;
@ -14,172 +15,188 @@ import electrosphere.Main;
*/ */
public class ShortRunTest { public class ShortRunTest {
@Test // @Test
public void test1by1Chunk1Step(){ // public void test1by1Chunk1Step(){
int dim = 1; // int dim = 1;
int maxTimestep = 1; // int maxTimestep = 1;
System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps"); // System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
//init chunk array // //init chunk array
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim); // FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
//simulate the chunk // //simulate the chunk
for(int i = 0; i < maxTimestep; i++){ // for(int i = 0; i < maxTimestep; i++){
FluidSim.simChunks(simArray, i, Main.TIMESTEP); // FluidSim.simChunks(simArray, i, Main.TIMESTEP);
} // }
for(int x = 0; x < dim; x++){ // for(int x = 0; x < dim; x++){
for(int y = 0; y < dim; y++){ // for(int y = 0; y < dim; y++){
for(int z = 0; z < dim; z++){ // 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"); // InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
byte[] bytes; // byte[] bytes;
try { // try {
bytes = testFileIS.readAllBytes(); // bytes = testFileIS.readAllBytes();
ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer(); // ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
int i = 0; // fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
while(densityBytes.hasRemaining()){ // fromDiskBuffer.put(bytes);
boolean pass = bytes[i] == densityBytes.get(); // fromDiskBuffer.flip();
assert(pass); // ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
i++; // int i = 0;
} // while(densityBytes.hasRemaining()){
} catch (IOException e) { // boolean pass = fromDiskBuffer.get() == densityBytes.get();
e.printStackTrace(); // assert(pass);
assert(false); // i++;
} // }
} // } catch (IOException e) {
} // e.printStackTrace();
} // assert(false);
// }
// }
// }
// }
System.out.println("PASSED"); // System.out.println("PASSED");
} // }
@Test // @Test
public void test1by1Chunk50Step(){ // public void test1by1Chunk50Step(){
int dim = 1; // int dim = 1;
int maxTimestep = 50; // int maxTimestep = 50;
System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps"); // System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
//init chunk array // //init chunk array
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim); // FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
//simulate the chunk // //simulate the chunk
for(int i = 0; i < maxTimestep; i++){ // for(int i = 0; i < maxTimestep; i++){
FluidSim.simChunks(simArray, i, Main.TIMESTEP); // FluidSim.simChunks(simArray, i, Main.TIMESTEP);
} // }
for(int x = 0; x < dim; x++){ // for(int x = 0; x < dim; x++){
for(int y = 0; y < dim; y++){ // for(int y = 0; y < dim; y++){
for(int z = 0; z < dim; z++){ // 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"); // InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
byte[] bytes; // byte[] bytes;
try { // try {
bytes = testFileIS.readAllBytes(); // bytes = testFileIS.readAllBytes();
ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer(); // ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
int i = 0; // fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
while(densityBytes.hasRemaining()){ // fromDiskBuffer.put(bytes);
boolean pass = bytes[i] == densityBytes.get(); // fromDiskBuffer.flip();
assert(pass); // ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
i++; // int i = 0;
} // while(densityBytes.hasRemaining()){
} catch (IOException e) { // boolean pass = fromDiskBuffer.get() == densityBytes.get();
e.printStackTrace(); // assert(pass);
assert(false); // i++;
} // }
} // } catch (IOException e) {
} // e.printStackTrace();
} // assert(false);
// }
System.out.println("PASSED"); // }
// }
} // }
@Test // System.out.println("PASSED");
public void test1by1Chunk100Step(){
// }
int dim = 1;
int maxTimestep = 100; // @Test
// public void test1by1Chunk100Step(){
System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
// int dim = 1;
//init chunk array // int maxTimestep = 100;
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
// System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
//simulate the chunk
for(int i = 0; i < maxTimestep; i++){ // //init chunk array
FluidSim.simChunks(simArray, i, Main.TIMESTEP); // FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
}
// //simulate the chunk
for(int x = 0; x < dim; x++){ // for(int i = 0; i < maxTimestep; i++){
for(int y = 0; y < dim; y++){ // FluidSim.simChunks(simArray, i, Main.TIMESTEP);
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; // for(int x = 0; x < dim; x++){
try { // for(int y = 0; y < dim; y++){
bytes = testFileIS.readAllBytes(); // for(int z = 0; z < dim; z++){
ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer(); // InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
int i = 0; // byte[] bytes;
while(densityBytes.hasRemaining()){ // try {
boolean pass = bytes[i] == densityBytes.get(); // bytes = testFileIS.readAllBytes();
assert(pass); // ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
i++; // fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
} // fromDiskBuffer.put(bytes);
} catch (IOException e) { // fromDiskBuffer.flip();
e.printStackTrace(); // ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
assert(false); // int i = 0;
} // while(densityBytes.hasRemaining()){
} // boolean pass = fromDiskBuffer.get() == densityBytes.get();
} // assert(pass);
} // i++;
// }
System.out.println("PASSED"); // } catch (IOException e) {
// e.printStackTrace();
} // assert(false);
// }
@Test // }
public void test1by1Chunk500Step(){ // }
// }
int dim = 1;
int maxTimestep = 500; // System.out.println("PASSED");
System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps"); // }
//init chunk array // @Test
FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim); // public void test1by1Chunk500Step(){
//simulate the chunk // int dim = 1;
for(int i = 0; i < maxTimestep; i++){ // int maxTimestep = 500;
FluidSim.simChunks(simArray, i, Main.TIMESTEP);
} // System.out.println("TEST: " + dim + "x" + dim + "x" + dim + " for " + maxTimestep + " steps");
for(int x = 0; x < dim; x++){ // //init chunk array
for(int y = 0; y < dim; y++){ // FluidSim[][][] simArray = FluidSim.initFluidSim(dim,dim,dim);
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"); // //simulate the chunk
byte[] bytes; // for(int i = 0; i < maxTimestep; i++){
try { // FluidSim.simChunks(simArray, i, Main.TIMESTEP);
bytes = testFileIS.readAllBytes(); // }
ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
int i = 0; // for(int x = 0; x < dim; x++){
while(densityBytes.hasRemaining()){ // for(int y = 0; y < dim; y++){
boolean pass = bytes[i] == densityBytes.get(); // for(int z = 0; z < dim; z++){
assert(pass); // InputStream testFileIS = this.getClass().getResourceAsStream("./testdata/" + dim + "by" + dim + "/" + maxTimestep + "steps/chunk_" + x + "_" + y + "_" + z + "_" + dim + "by" + dim + "Chunk" + maxTimestep + "Step.data");
i++; // byte[] bytes;
} // try {
} catch (IOException e) { // bytes = testFileIS.readAllBytes();
e.printStackTrace(); // ByteBuffer fromDiskBuffer = ByteBuffer.allocate(FluidSim.DIM * FluidSim.DIM * FluidSim.DIM * 4);
assert(false); // fromDiskBuffer.order(ByteOrder.LITTLE_ENDIAN);
} // fromDiskBuffer.put(bytes);
} // fromDiskBuffer.flip();
} // ByteBuffer densityBytes = simArray[x][y][z].getDensityBuffer();
} // int i = 0;
// while(densityBytes.hasRemaining()){
System.out.println("PASSED"); // boolean pass = fromDiskBuffer.get() == densityBytes.get();
// assert(pass);
} // i++;
// }
// } catch (IOException e) {
// e.printStackTrace();
// assert(false);
// }
// }
// }
// }
// System.out.println("PASSED");
// }
} }