diff --git a/docs/Doxyfile b/docs/Doxyfile index 166952de..5df2968c 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -949,7 +949,8 @@ WARN_LOGFILE = DoxygenWarningLog.txt # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = ../src \ +INPUT = ../src/main/java \ + ../src/main/c/includes \ ./src \ ./src/mainpage.md diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index ba66339c..73b912ab 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1243,6 +1243,7 @@ Small collision engine code formatting (14/04/2024) Fix testing apparatus for native code on windows +Fix doxygen also pointing at native code lib folder diff --git a/src/main/c/includes/fluid/chunk.h b/src/main/c/includes/fluid/chunk.h index f30cdc60..956bdc99 100644 --- a/src/main/c/includes/fluid/chunk.h +++ b/src/main/c/includes/fluid/chunk.h @@ -53,7 +53,7 @@ typedef struct { /** * The size of the dimension of the memory of the sparse array */ -#define SPARSE_ARRAY_RAW_DIM SPARSE_ARRAY_CHUNK_DIM * MAIN_ARRAY_DIM + SPARSE_ARRAY_BORDER_SIZE +#define SPARSE_ARRAY_RAW_DIM ((SPARSE_ARRAY_CHUNK_DIM * MAIN_ARRAY_DIM) + SPARSE_ARRAY_BORDER_SIZE) /** * The size of a sparse array in number of elements @@ -116,21 +116,26 @@ typedef struct { /** * Creates a sparse chunk array */ -LIBRARY_API SparseChunkArray * fluid_create_sparse_array(); +LIBRARY_API SparseChunkArray * fluid_sparse_array_create(); /** * Frees a sparse chunk array */ -LIBRARY_API void fluid_free_sparse_array(SparseChunkArray * array); +LIBRARY_API void fluid_sparse_array_free(SparseChunkArray * array); /** * Adds a chunk to the sparse array */ -LIBRARY_API void fluid_add_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z); +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_remove_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z, int copy); +LIBRARY_API void fluid_sparse_array_remove_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z, int copy); + +/** + * 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); #endif \ No newline at end of file diff --git a/src/main/c/includes/fluid/utilities.h b/src/main/c/includes/fluid/utilities.h index ab128a5d..e951296a 100644 --- a/src/main/c/includes/fluid/utilities.h +++ b/src/main/c/includes/fluid/utilities.h @@ -1,10 +1,12 @@ #include +#include "chunk.h" + #ifndef UTILITIES_H #define UTILITIES_H #define SWAP(x0,x) {float *tmp=x0;x0=x;x=tmp;} -#define IX(i,j,k) ((i)+(N)*(j)+(N*N)*(k)) +#define IX(i,j,k) ((i)+(DIM)*(j)+(DIM*DIM)*(k)) #define CK(m,n,o) ((m)+(n)*(3)+(o)*(3)*(3)) #define GET_ARR_RAW(src,i) src[i] #define ARR_EXISTS(chunk_mask,m,n,o) (chunk_mask & CHUNK_INDEX_ARR[CK(m,n,o)]) > 0 diff --git a/src/main/c/src/fluid/chunk.c b/src/main/c/src/fluid/chunk.c index 8ea8c277..39a467a1 100644 --- a/src/main/c/src/fluid/chunk.c +++ b/src/main/c/src/fluid/chunk.c @@ -14,7 +14,7 @@ int solveOffset(int chunkPos); /** * Creates a sparse chunk array */ -LIBRARY_API SparseChunkArray * fluid_create_sparse_array(){ +LIBRARY_API SparseChunkArray * fluid_sparse_array_create(){ //allocate the object itself SparseChunkArray * rVal = (SparseChunkArray *)malloc(sizeof(SparseChunkArray)); @@ -38,7 +38,7 @@ LIBRARY_API SparseChunkArray * fluid_create_sparse_array(){ /** * Frees a sparse chunk array */ -LIBRARY_API void fluid_free_sparse_array(SparseChunkArray * array){ +LIBRARY_API void fluid_sparse_array_free(SparseChunkArray * array){ //free the constituent arrays free(array->d); @@ -61,15 +61,18 @@ LIBRARY_API void fluid_free_sparse_array(SparseChunkArray * array){ /** * Adds a chunk to the sparse array */ -LIBRARY_API void fluid_add_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z){ +LIBRARY_API void fluid_sparse_array_add_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z){ //solve chunk offsets int offsetX = solveOffset(x); int offsetY = solveOffset(y); int offsetZ = solveOffset(z); int minPos = SPARSE_ARRAY_BORDER_SIZE / 2; - int N = DIM; int i, j, k; + if(array->chunks[GCI(x,y,z)] != NULL){ + return; + } + for(int m = 0; m < MAIN_ARRAY_DIM; m++){ for(int n = 0; n < MAIN_ARRAY_DIM; n++){ for(int o = 0; o < MAIN_ARRAY_DIM; o++){ @@ -129,13 +132,12 @@ LIBRARY_API void fluid_add_chunk(SparseChunkArray * array, Chunk * chunk, int x, /** * Adds a chunk to the sparse array */ -LIBRARY_API void fluid_remove_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z, int copy){ +LIBRARY_API void fluid_sparse_array_remove_chunk(SparseChunkArray * array, Chunk * chunk, int x, int y, int z, int copy){ //solve chunk offsets int offsetX = solveOffset(x); int offsetY = solveOffset(y); int offsetZ = solveOffset(z); int minPos = SPARSE_ARRAY_BORDER_SIZE / 2; - int N = DIM; int i, j, k; for(int m = 0; m < MAIN_ARRAY_DIM; m++){ @@ -244,6 +246,13 @@ LIBRARY_API void fluid_remove_chunk(SparseChunkArray * array, Chunk * chunk, int array->chunks[GCI(x,y,z)] = NULL; } +/** + * 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){ + return GVI(x,y,z); +} + /** * Gets the index of the chunk at a given position within the sparse array */ diff --git a/test/c/TestAsdf.c b/test/c/TestAsdf.c deleted file mode 100644 index 90e16719..00000000 --- a/test/c/TestAsdf.c +++ /dev/null @@ -1,5 +0,0 @@ - - -int TestAsdf(){ - return 0; -} \ No newline at end of file diff --git a/test/c/fluid/FluidMemoryManagementTests.c b/test/c/fluid/FluidMemoryManagementTests.c deleted file mode 100644 index a596536f..00000000 --- a/test/c/fluid/FluidMemoryManagementTests.c +++ /dev/null @@ -1,19 +0,0 @@ -#include - -#include "fluid/chunk.h" - - - - -int fluid_FluidMemoryManagementTests(int argc, char **argv){ - - //allocate a sparse array - SparseChunkArray * sparseArray = fluid_create_sparse_array(); - - - - //free a sparse array - fluid_free_sparse_array(sparseArray); - - return 0; -} diff --git a/test/c/fluid/chunk_tests.c b/test/c/fluid/chunk_tests.c new file mode 100644 index 00000000..0f38665c --- /dev/null +++ b/test/c/fluid/chunk_tests.c @@ -0,0 +1,69 @@ +#include +#include + +#include "fluid/chunk.h" +#include "fluid/chunkmask.h" +#include "fluid/utilities.h" +#include "../test.h" + + + + +int fluid_chunk_tests(int argc, char **argv){ + int rVal = 0; + //allocate a sparse array + SparseChunkArray * sparseArray = fluid_sparse_array_create(); + + //create chunks to add to the sparse array + 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)); + for(int x = 0; x < DIM; x++){ + for(int y = 0; y < DIM; y++){ + for(int z = 0; z < DIM; z++){ + chunk1->d[CENTER_LOC][x * DIM * DIM + y * DIM + z] = 1; + } + } + } + Chunk * chunk2 = (Chunk *)malloc(sizeof(Chunk)); + chunk2->d[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk2->d0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk2->u[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk2->v[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk2->w[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk2->u0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk2->v0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + chunk2->w0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float)); + for(int x = 0; x < DIM; x++){ + for(int y = 0; y < DIM; y++){ + for(int z = 0; z < DIM; z++){ + chunk1->d[CENTER_LOC][x * DIM * DIM + y * DIM + z] = 2; + } + } + } + + //add a chunk + fluid_sparse_array_add_chunk(sparseArray,chunk1,0,0,0); + rVal =+ assertEquals(sparseArray->d[fluid_sparse_array_get_index(sparseArray,0,0,0)],0,"index 0,0,0 in the sparse array should be a border value -- %d %d\n"); + rVal =+ assertEquals(chunk1->d[CENTER_LOC][IX(1,1,1)],1,"chunk1 should have a value of 1 -- %d %d\n"); + rVal =+ assertEquals(sparseArray->d[fluid_sparse_array_get_index(sparseArray,1,1,1)],chunk1->d[CENTER_LOC][IX(1,1,1)],"index 1,1,1 in the sparse array should be 0,0,0 of the chunk stored at 0,0,0 -- %d %d\n"); + + //make sure adding a second chunk doesn't override the first one + fluid_sparse_array_add_chunk(sparseArray,chunk2,1,0,0); + rVal =+ assertEquals(sparseArray->d[fluid_sparse_array_get_index(sparseArray,0,0,0)],0,"index 0,0,0 in the sparse array should be a border value -- %d %d\n"); + rVal =+ assertEquals(sparseArray->d[fluid_sparse_array_get_index(sparseArray,1,1,1)],chunk1->d[CENTER_LOC][IX(1,1,1)],"index 1,1,1 in the sparse array should be 0,0,0 of the chunk stored at 0,0,0 -- %d %d\n"); + rVal =+ assertEquals(sparseArray->d[fluid_sparse_array_get_index(sparseArray,16,16,16)],chunk1->d[CENTER_LOC][IX(15,15,15)],"index 16,16,16 in the sparse array should be 15,15,15 of the chunk stored at 0,0,0 -- %d %d\n"); + rVal =+ assertEquals(sparseArray->d[fluid_sparse_array_get_index(sparseArray,17,17,17)],chunk2->d[CENTER_LOC][IX(1,1,1)],"index 17,17,17 in the sparse array should be 1,1,1 of the chunk stored at 1,0,0 -- %d %d\n"); + + + //free a sparse array + fluid_sparse_array_free(sparseArray); + + return rVal; +} diff --git a/test/c/test.c b/test/c/test.c new file mode 100644 index 00000000..56d6bbb4 --- /dev/null +++ b/test/c/test.c @@ -0,0 +1,26 @@ +#include +#include + +#include "test.h" + +int assertEquals(int a, int b, char * msg){ + int rVal = (a != b); + if(rVal){ + printf(msg, a, b); + } + return rVal; +} + +int assertNotEquals(int a, int b, char * msg){ + int rVal = (a == b); + if(rVal){ + printf(msg, a, b); + } + return rVal; +} + + +int test(){ + return 0; +} + diff --git a/test/c/test.h b/test/c/test.h new file mode 100644 index 00000000..4714b815 --- /dev/null +++ b/test/c/test.h @@ -0,0 +1,8 @@ + +#ifndef TEST_H +#define TEST_H + +int assertEquals(int a, int b, char * msg); +int assertNotEquals(int a, int b, char * msg); + +#endif \ No newline at end of file