diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 37bc826e..73eba962 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1250,6 +1250,7 @@ Fix arena loading Refactoring fluid sim code Refactoring fluid sim headers Refactor native test code under src/test +More test file refactoring diff --git a/src/main/c/includes/fluid/queue/chunk.h b/src/main/c/includes/fluid/queue/chunk.h index 6a0f6c4f..bad886fb 100644 --- a/src/main/c/includes/fluid/queue/chunk.h +++ b/src/main/c/includes/fluid/queue/chunk.h @@ -43,156 +43,13 @@ typedef struct { * The world z coordinate of this chunk */ int z; + + /** + * The level of detail to simulate the chunk with + * NOTE: This is not a spatial LOD. It is a simulation LOD + */ + int simLOD; } Chunk; -/** - * The size of the main array's real data - */ -#define MAIN_ARRAY_DIM 16 - -/** - * The number of chunks to place next to one another - */ -#define SPARSE_ARRAY_CHUNK_DIM 7 - -/** - * The number of chunks to place next to one another - */ -#define SPARSE_ARRAY_CHUNK_RADIUS 3 - -/** - * The total number of chunks in the chunk tracking array - */ -#define SPARSE_ARRAY_TOTAL_CHUNKS (SPARSE_ARRAY_CHUNK_DIM * SPARSE_ARRAY_CHUNK_DIM * SPARSE_ARRAY_CHUNK_DIM) - -/** - * The extra values at the edges of the sparse array (to allow pulling data from borders) - */ -#define SPARSE_ARRAY_BORDER_SIZE 2 - -/** - * The size of the real data in the sparse array (not including bounds) - */ -#define SPARSE_ARRAY_REAL_DATA_SIZE (SPARSE_ARRAY_CHUNK_DIM * MAIN_ARRAY_DIM) - -/** - * Size of the cells we care about in the sparse array - */ -#define SPARSE_ARRAY_ACTUAL_DATA_DIM (SPARSE_ARRAY_REAL_DATA_SIZE + SPARSE_ARRAY_BORDER_SIZE) - -/** - * The size of the dimension of the memory of the sparse array - * While the SPARSE_ARRAY_ACTUAL_DATA_DIM may come out to 114, it will be more efficient CPU-instruction wise - * if we round that up to 128+2 - * That way we can call highly vectorized functions (ie avx128 instead of avx64+avx32+avx16+2) - */ -#define SPARSE_ARRAY_RAW_DIM (128 + SPARSE_ARRAY_BORDER_SIZE) - -/** - * The size of a sparse array in number of elements - */ -#define SPARSE_ARRAY_FULL_SIZE (SPARSE_ARRAY_RAW_DIM * SPARSE_ARRAY_RAW_DIM * SPARSE_ARRAY_RAW_DIM) - -/** - * The unit of spacial distance - */ -#define SPATIAL_UNIT 1 - -/** - * The size of the sparse array in spatial units - */ -#define SPARSE_ARRAY_SPATIAL_SIZE (SPARSE_ARRAY_ACTUAL_DATA_DIM * SPATIAL_UNIT) - -/** - * A set of sparse matricies for simulating fluids - */ -typedef struct { - - /** - * The density array - */ - float * d; - - /** - * The density delta array - */ - float * d0; - - /** - * The x velocity array - */ - float * u; - - /** - * The y velocity array - */ - float * v; - - /** - * The z velocity array - */ - float * w; - - /** - * The x velocity delta array - */ - float * u0; - - /** - * The y velocity delta array - */ - float * v0; - - /** - * The z velocity delta array - */ - float * w0; - - /** - * The chunks inside the array - */ - Chunk ** chunks; - -} SparseChunkArray; - - -/** - * Creates a sparse chunk array - */ -LIBRARY_API SparseChunkArray * fluid_sparse_array_create(); - -/** - * Frees a sparse chunk array - */ -LIBRARY_API void fluid_sparse_array_free(SparseChunkArray * array); - -/** - * Adds a chunk to the sparse array - */ -LIBRARY_API void fluid_sparse_array_add_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z); - -/** - * Adds a chunk to the sparse array - */ -LIBRARY_API void fluid_sparse_array_remove_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z); - -/** - * Gets the index for a point in the chunk - */ -LIBRARY_API int fluid_sparse_array_get_index(SparseChunkArray * array, int x, int y, int z); - -/** - * Cleans the sparse array - */ -LIBRARY_API void fluid_sparse_array_clean(SparseChunkArray * array); - -/** - * Gets the number of chunks in the sparse array - */ -LIBRARY_API int fluid_sparse_array_get_chunk_count(SparseChunkArray * array); - -int GCI(int x, int y, int z); -int GVI(int x, int y, int z); - #endif \ No newline at end of file diff --git a/src/main/c/includes/fluid/queue/islandsolver.h b/src/main/c/includes/fluid/queue/islandsolver.h index ceff8ca6..18999bfb 100644 --- a/src/main/c/includes/fluid/queue/islandsolver.h +++ b/src/main/c/includes/fluid/queue/islandsolver.h @@ -7,6 +7,7 @@ #define ISLANDSOLVER_H #include "fluid/queue/chunk.h" +#include "fluid/queue/sparse.h" /** * A set of sparse matricies for simulating fluids diff --git a/src/main/c/includes/fluid/queue/sparse.h b/src/main/c/includes/fluid/queue/sparse.h new file mode 100644 index 00000000..bb987a79 --- /dev/null +++ b/src/main/c/includes/fluid/queue/sparse.h @@ -0,0 +1,160 @@ +#ifndef FLUID_QUEUE_SPARSE_H +#define FLUID_QUEUE_SPARSE_H + +//Must be included for public functions to be imported/exported on windows +#include "public.h" + +#include "chunk.h" + + +/** + * The size of the main array's real data + */ +#define MAIN_ARRAY_DIM 16 + +/** + * The number of chunks to place next to one another + */ +#define SPARSE_ARRAY_CHUNK_DIM 7 + +/** + * The number of chunks to place next to one another + */ +#define SPARSE_ARRAY_CHUNK_RADIUS 3 + +/** + * The total number of chunks in the chunk tracking array + */ +#define SPARSE_ARRAY_TOTAL_CHUNKS (SPARSE_ARRAY_CHUNK_DIM * SPARSE_ARRAY_CHUNK_DIM * SPARSE_ARRAY_CHUNK_DIM) + +/** + * The extra values at the edges of the sparse array (to allow pulling data from borders) + */ +#define SPARSE_ARRAY_BORDER_SIZE 2 + +/** + * The size of the real data in the sparse array (not including bounds) + */ +#define SPARSE_ARRAY_REAL_DATA_SIZE (SPARSE_ARRAY_CHUNK_DIM * MAIN_ARRAY_DIM) + +/** + * Size of the cells we care about in the sparse array + */ +#define SPARSE_ARRAY_ACTUAL_DATA_DIM (SPARSE_ARRAY_REAL_DATA_SIZE + SPARSE_ARRAY_BORDER_SIZE) + +/** + * The size of the dimension of the memory of the sparse array + * While the SPARSE_ARRAY_ACTUAL_DATA_DIM may come out to 114, it will be more efficient CPU-instruction wise + * if we round that up to 128+2 + * That way we can call highly vectorized functions (ie avx128 instead of avx64+avx32+avx16+2) + */ +#define SPARSE_ARRAY_RAW_DIM (128 + SPARSE_ARRAY_BORDER_SIZE) + +/** + * The size of a sparse array in number of elements + */ +#define SPARSE_ARRAY_FULL_SIZE (SPARSE_ARRAY_RAW_DIM * SPARSE_ARRAY_RAW_DIM * SPARSE_ARRAY_RAW_DIM) + +/** + * The unit of spacial distance + */ +#define SPATIAL_UNIT 1 + +/** + * The size of the sparse array in spatial units + */ +#define SPARSE_ARRAY_SPATIAL_SIZE (SPARSE_ARRAY_ACTUAL_DATA_DIM * SPATIAL_UNIT) + +/** + * A set of sparse matricies for simulating fluids + */ +typedef struct { + + /** + * The density array + */ + float * d; + + /** + * The density delta array + */ + float * d0; + + /** + * The x velocity array + */ + float * u; + + /** + * The y velocity array + */ + float * v; + + /** + * The z velocity array + */ + float * w; + + /** + * The x velocity delta array + */ + float * u0; + + /** + * The y velocity delta array + */ + float * v0; + + /** + * The z velocity delta array + */ + float * w0; + + /** + * The chunks inside the array + */ + Chunk ** chunks; + +} SparseChunkArray; + + +/** + * Creates a sparse chunk array + */ +LIBRARY_API SparseChunkArray * fluid_sparse_array_create(); + +/** + * Frees a sparse chunk array + */ +LIBRARY_API void fluid_sparse_array_free(SparseChunkArray * array); + +/** + * Adds a chunk to the sparse array + */ +LIBRARY_API void fluid_sparse_array_add_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z); + +/** + * Adds a chunk to the sparse array + */ +LIBRARY_API void fluid_sparse_array_remove_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z); + +/** + * Gets the index for a point in the chunk + */ +LIBRARY_API int fluid_sparse_array_get_index(SparseChunkArray * array, int x, int y, int z); + +/** + * Cleans the sparse array + */ +LIBRARY_API void fluid_sparse_array_clean(SparseChunkArray * array); + +/** + * Gets the number of chunks in the sparse array + */ +LIBRARY_API int fluid_sparse_array_get_chunk_count(SparseChunkArray * array); + +int GCI(int x, int y, int z); +int GVI(int x, int y, int z); + + +#endif \ No newline at end of file diff --git a/src/main/c/src/fluid/queue/chunk.c b/src/main/c/src/fluid/queue/sparse.c similarity index 99% rename from src/main/c/src/fluid/queue/chunk.c rename to src/main/c/src/fluid/queue/sparse.c index eeb7f725..effbd8e3 100644 --- a/src/main/c/src/fluid/queue/chunk.c +++ b/src/main/c/src/fluid/queue/sparse.c @@ -2,6 +2,7 @@ #include "fluid/queue/chunk.h" +#include "fluid/queue/sparse.h" #include "fluid/queue/chunkmask.h" #include "fluid/env/utilities.h" diff --git a/src/test/c/fluid/islandsolver_tests.c b/src/test/c/fluid/queue/islandsolver_tests.c similarity index 77% rename from src/test/c/fluid/islandsolver_tests.c rename to src/test/c/fluid/queue/islandsolver_tests.c index 505bdee2..5cafac06 100644 --- a/src/test/c/fluid/islandsolver_tests.c +++ b/src/test/c/fluid/queue/islandsolver_tests.c @@ -5,45 +5,11 @@ #include "fluid/queue/chunkmask.h" #include "fluid/env/utilities.h" #include "fluid/queue/islandsolver.h" -#include "../test.h" -#include "chunk_test_utils.h" +#include "../../util/test.h" +#include "../../util/chunk_test_utils.h" -/** - * Creates a chunk at a world position - */ -Chunk * chunk_create(int x, int y, int z){ - Chunk * chunk1 = (Chunk *)malloc(sizeof(Chunk)); - chunk1->d[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); - chunk1->d0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); - chunk1->u[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); - chunk1->v[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); - chunk1->w[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); - chunk1->u0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); - chunk1->v0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); - chunk1->w0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); - chunk1->x = x; - chunk1->y = y; - chunk1->z = z; - return chunk1; -} - -/** - * Frees a chunk - */ -void chunk_free(Chunk * chunk){ - free(chunk->d[CENTER_LOC]); - free(chunk->d0[CENTER_LOC]); - free(chunk->u[CENTER_LOC]); - free(chunk->v[CENTER_LOC]); - free(chunk->w[CENTER_LOC]); - free(chunk->u0[CENTER_LOC]); - free(chunk->v0[CENTER_LOC]); - free(chunk->w0[CENTER_LOC]); - free(chunk); -} - /** * Sets a chunk's value * @param chunk The chunk @@ -86,7 +52,7 @@ void chunk_set_val(Chunk * chunk, int i, int arr){ } -int fluid_islandsolver_tests(int argc, char **argv){ +int fluid_queue_islandsolver_tests(int argc, char **argv){ int rVal = 0; //allocate a sparse array FluidIslandSolver * islandSolver = fluid_island_solver_create(); diff --git a/src/test/c/fluid/chunk_tests.c b/src/test/c/fluid/queue/sparse_tests.c similarity index 97% rename from src/test/c/fluid/chunk_tests.c rename to src/test/c/fluid/queue/sparse_tests.c index 4a54acbe..e7ca29e0 100644 --- a/src/test/c/fluid/chunk_tests.c +++ b/src/test/c/fluid/queue/sparse_tests.c @@ -2,9 +2,10 @@ #include #include "fluid/queue/chunk.h" +#include "fluid/queue/sparse.h" #include "fluid/queue/chunkmask.h" #include "fluid/env/utilities.h" -#include "../test.h" +#include "../../util/test.h" @@ -94,3 +95,10 @@ int fluid_chunk_tests(int argc, char **argv){ return rVal; } + +/** + * Empty test launcher + */ +int fluid_queue_sparse_tests(){ + return 0; +} \ No newline at end of file diff --git a/src/test/c/fluid/sparsesimulator_tests.c b/src/test/c/fluid/sim/sparsesimulator_tests.c similarity index 89% rename from src/test/c/fluid/sparsesimulator_tests.c rename to src/test/c/fluid/sim/sparsesimulator_tests.c index e329c695..bef04a11 100644 --- a/src/test/c/fluid/sparsesimulator_tests.c +++ b/src/test/c/fluid/sim/sparsesimulator_tests.c @@ -2,12 +2,13 @@ #include #include "fluid/queue/chunk.h" +#include "fluid/queue/sparse.h" #include "fluid/queue/chunkmask.h" #include "fluid/env/utilities.h" #include "fluid/queue/islandsolver.h" #include "fluid/sim/sparse/sparsesimulator.h" -#include "../test.h" -#include "chunk_test_utils.h" +#include "../../util/test.h" +#include "../../util/chunk_test_utils.h" #define TEST_DT 0.1 #define TEST_DIFF_CONST 0.0001 @@ -22,7 +23,7 @@ -int test_fluid_sparse_array_add_source(){ +int test_sparse_array_add_source(){ int rVal = 0; //allocate a sparse array FluidIslandSolver * islandSolver = fluid_island_solver_create(); @@ -75,7 +76,7 @@ int test_fluid_sparse_array_add_source(){ -int test_fluid_sparse_array_dens_step(){ +int test_sparse_array_dens_step(){ int rVal = 0; //allocate a sparse array FluidIslandSolver * islandSolver = fluid_island_solver_create(); @@ -127,11 +128,11 @@ int test_fluid_sparse_array_dens_step(){ -int fluid_sparsesimulator_tests(int argc, char **argv){ +int fluid_sim_sparsesimulator_tests(int argc, char **argv){ int rVal = 0; - rVal += test_fluid_sparse_array_add_source(); - rVal += test_fluid_sparse_array_dens_step(); + rVal += test_sparse_array_add_source(); + rVal += test_sparse_array_dens_step(); return rVal; } diff --git a/src/test/c/util/chunk_test_utils.c b/src/test/c/util/chunk_test_utils.c new file mode 100644 index 00000000..ce1f38a5 --- /dev/null +++ b/src/test/c/util/chunk_test_utils.c @@ -0,0 +1,45 @@ +#include + +#include "fluid/queue/chunk.h" +#include "fluid/queue/chunkmask.h" + +/** + * Creates a chunk at a world position + */ +Chunk * chunk_create(int x, int y, int z){ + Chunk * chunk1 = (Chunk *)malloc(sizeof(Chunk)); + chunk1->d[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk1->d0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk1->u[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk1->v[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk1->w[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk1->u0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk1->v0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk1->w0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk1->x = x; + chunk1->y = y; + chunk1->z = z; + return chunk1; +} + +/** + * Frees a chunk + */ +void chunk_free(Chunk * chunk){ + free(chunk->d[CENTER_LOC]); + free(chunk->d0[CENTER_LOC]); + free(chunk->u[CENTER_LOC]); + free(chunk->v[CENTER_LOC]); + free(chunk->w[CENTER_LOC]); + free(chunk->u0[CENTER_LOC]); + free(chunk->v0[CENTER_LOC]); + free(chunk->w0[CENTER_LOC]); + free(chunk); +} + +/** + * Empty test launcher + */ +int util_chunk_test_utils(){ + return 0; +} \ No newline at end of file diff --git a/src/test/c/fluid/chunk_test_utils.h b/src/test/c/util/chunk_test_utils.h similarity index 100% rename from src/test/c/fluid/chunk_test_utils.h rename to src/test/c/util/chunk_test_utils.h diff --git a/src/test/c/test.c b/src/test/c/util/test.c similarity index 98% rename from src/test/c/test.c rename to src/test/c/util/test.c index 1b9667d3..f83f71e4 100644 --- a/src/test/c/test.c +++ b/src/test/c/util/test.c @@ -58,7 +58,7 @@ int assertNotEqualsFloat(float a, float b, char * msg){ } -int test(){ +int util_test(){ return 0; } diff --git a/src/test/c/test.h b/src/test/c/util/test.h similarity index 100% rename from src/test/c/test.h rename to src/test/c/util/test.h