more test file refactoring
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-06 13:31:43 -05:00
parent b9fe5b3ebe
commit 7740672e2c
12 changed files with 235 additions and 195 deletions

View File

@ -1250,6 +1250,7 @@ Fix arena loading
Refactoring fluid sim code Refactoring fluid sim code
Refactoring fluid sim headers Refactoring fluid sim headers
Refactor native test code under src/test Refactor native test code under src/test
More test file refactoring

View File

@ -44,155 +44,12 @@ typedef struct {
*/ */
int z; 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; } 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 #endif

View File

@ -7,6 +7,7 @@
#define ISLANDSOLVER_H #define ISLANDSOLVER_H
#include "fluid/queue/chunk.h" #include "fluid/queue/chunk.h"
#include "fluid/queue/sparse.h"
/** /**
* A set of sparse matricies for simulating fluids * A set of sparse matricies for simulating fluids

View File

@ -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

View File

@ -2,6 +2,7 @@
#include "fluid/queue/chunk.h" #include "fluid/queue/chunk.h"
#include "fluid/queue/sparse.h"
#include "fluid/queue/chunkmask.h" #include "fluid/queue/chunkmask.h"
#include "fluid/env/utilities.h" #include "fluid/env/utilities.h"

View File

@ -5,45 +5,11 @@
#include "fluid/queue/chunkmask.h" #include "fluid/queue/chunkmask.h"
#include "fluid/env/utilities.h" #include "fluid/env/utilities.h"
#include "fluid/queue/islandsolver.h" #include "fluid/queue/islandsolver.h"
#include "../test.h" #include "../../util/test.h"
#include "chunk_test_utils.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 * Sets a chunk's value
* @param chunk The chunk * @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; int rVal = 0;
//allocate a sparse array //allocate a sparse array
FluidIslandSolver * islandSolver = fluid_island_solver_create(); FluidIslandSolver * islandSolver = fluid_island_solver_create();

View File

@ -2,9 +2,10 @@
#include <stdlib.h> #include <stdlib.h>
#include "fluid/queue/chunk.h" #include "fluid/queue/chunk.h"
#include "fluid/queue/sparse.h"
#include "fluid/queue/chunkmask.h" #include "fluid/queue/chunkmask.h"
#include "fluid/env/utilities.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; return rVal;
} }
/**
* Empty test launcher
*/
int fluid_queue_sparse_tests(){
return 0;
}

View File

@ -2,12 +2,13 @@
#include <stdlib.h> #include <stdlib.h>
#include "fluid/queue/chunk.h" #include "fluid/queue/chunk.h"
#include "fluid/queue/sparse.h"
#include "fluid/queue/chunkmask.h" #include "fluid/queue/chunkmask.h"
#include "fluid/env/utilities.h" #include "fluid/env/utilities.h"
#include "fluid/queue/islandsolver.h" #include "fluid/queue/islandsolver.h"
#include "fluid/sim/sparse/sparsesimulator.h" #include "fluid/sim/sparse/sparsesimulator.h"
#include "../test.h" #include "../../util/test.h"
#include "chunk_test_utils.h" #include "../../util/chunk_test_utils.h"
#define TEST_DT 0.1 #define TEST_DT 0.1
#define TEST_DIFF_CONST 0.0001 #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; int rVal = 0;
//allocate a sparse array //allocate a sparse array
FluidIslandSolver * islandSolver = fluid_island_solver_create(); 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; int rVal = 0;
//allocate a sparse array //allocate a sparse array
FluidIslandSolver * islandSolver = fluid_island_solver_create(); 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; int rVal = 0;
rVal += test_fluid_sparse_array_add_source(); rVal += test_sparse_array_add_source();
rVal += test_fluid_sparse_array_dens_step(); rVal += test_sparse_array_dens_step();
return rVal; return rVal;
} }

View File

@ -0,0 +1,45 @@
#include <stdlib.h>
#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;
}

View File

@ -58,7 +58,7 @@ int assertNotEqualsFloat(float a, float b, char * msg){
} }
int test(){ int util_test(){
return 0; return 0;
} }