From 1b36112e249cf005038dba3ca6f02eb1e6a978b0 Mon Sep 17 00:00:00 2001 From: austin Date: Mon, 9 Dec 2024 18:01:27 -0500 Subject: [PATCH] refactoring grid2 headers --- .vscode/settings.json | 5 +- src/main/c/includes/fluid/sim/grid2/density.h | 67 ++++++++ .../fluid/sim/grid2/{simulation.h => grid2.h} | 59 ++++++- .../c/includes/fluid/sim/grid2/utilities.h | 58 +++++++ .../sim/grid2/{mainFunctions.h => velocity.h} | 154 ++---------------- src/main/c/src/fluid/queue/javainterface.c | 2 +- .../sim/grid2/{densitystep.c => density.c} | 1 + src/main/c/src/fluid/sim/grid2/fluidsim.c | 6 +- .../sim/grid2/{velocitystep.c => velocity.c} | 11 +- src/main/c/src/fluid/sim/simulator.c | 2 +- 10 files changed, 209 insertions(+), 156 deletions(-) create mode 100644 src/main/c/includes/fluid/sim/grid2/density.h rename src/main/c/includes/fluid/sim/grid2/{simulation.h => grid2.h} (50%) create mode 100644 src/main/c/includes/fluid/sim/grid2/utilities.h rename src/main/c/includes/fluid/sim/grid2/{mainFunctions.h => velocity.h} (58%) rename src/main/c/src/fluid/sim/grid2/{densitystep.c => density.c} (99%) rename src/main/c/src/fluid/sim/grid2/{velocitystep.c => velocity.c} (97%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 17a210db..32fb9d47 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -38,6 +38,9 @@ "limits": "c", "boundsolver.h": "c", "randutils.h": "c", - "mathutils.h": "c" + "mathutils.h": "c", + "velocity.h": "c", + "density.h": "c", + "grid2.h": "c" } } \ No newline at end of file diff --git a/src/main/c/includes/fluid/sim/grid2/density.h b/src/main/c/includes/fluid/sim/grid2/density.h new file mode 100644 index 00000000..9730893f --- /dev/null +++ b/src/main/c/includes/fluid/sim/grid2/density.h @@ -0,0 +1,67 @@ + +#ifndef FLUID_GRID2_DENSITY_H +#define FLUID_GRID2_DENSITY_H + +#include +#include "fluid/env/environment.h" + + + +/** + * Actually performs the advection +*/ +void fluid_grid2_advect(uint32_t chunk_mask, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt); + + + +/** + * Adds density to the density array + * @return The change in density within this chunk for this frame +*/ +void fluid_grid2_addDensity( + Environment * environment, + int chunk_mask, + float ** d, + float ** d0, + float dt +); + + + + +/* + * A single iteration of the jacobi to solve density diffusion + */ +void fluid_grid2_solveDiffuseDensity( + int chunk_mask, + float ** d, + float ** d0, + float ** jru, + float ** jrv, + float ** jrw, + float DIFFUSION_CONST, + float VISCOSITY_CONST, + float dt +); + + + + + +/** + * Advects the density based on the vectors +*/ +void fluid_grid2_advectDensity(uint32_t chunk_mask, float ** d, float ** d0, float ** ur, float ** vr, float ** wr, float dt); + + + +/** + * Normalizes the density array with a given ratio + */ +void fluid_grid2_normalizeDensity(float ** d, float ratio); + + + + + +#endif \ No newline at end of file diff --git a/src/main/c/includes/fluid/sim/grid2/simulation.h b/src/main/c/includes/fluid/sim/grid2/grid2.h similarity index 50% rename from src/main/c/includes/fluid/sim/grid2/simulation.h rename to src/main/c/includes/fluid/sim/grid2/grid2.h index a4ae5d1a..d0812c58 100644 --- a/src/main/c/includes/fluid/sim/grid2/simulation.h +++ b/src/main/c/includes/fluid/sim/grid2/grid2.h @@ -1,9 +1,17 @@ -#ifndef FLUID_GRID2_SIMULATION_H -#define FLUID_GRID2_SIMULATION_H -#include "fluid/queue/chunk.h" +#ifndef FLUID_GRID2_MAINFUNC +#define FLUID_GRID2_MAINFUNC + + #include "fluid/env/environment.h" + + + + + + + /** * Performs the main simulation * @param numChunks The number of chunks @@ -13,4 +21,49 @@ */ void fluid_grid2_simulate(int numChunks, Chunk ** passedInChunks, Environment * environment, float timestep); + + + + + +/** + * The main simulation function + */ +void fluid_grid2_simulate( + int numChunks, + Chunk ** passedInChunks, + Environment * environment, + jfloat timestep +); + + + + + + + + + +/** + * Allocates the arrays necessary for grid2 simulation + */ +void fluid_grid2_allocate_arrays(); + + + + + + + + + + + + + + + + + + #endif \ No newline at end of file diff --git a/src/main/c/includes/fluid/sim/grid2/utilities.h b/src/main/c/includes/fluid/sim/grid2/utilities.h new file mode 100644 index 00000000..09273ae4 --- /dev/null +++ b/src/main/c/includes/fluid/sim/grid2/utilities.h @@ -0,0 +1,58 @@ + +#ifndef FLUID_GRID2_UTILITIES_H +#define FLUID_GRID2_UTILITIES_H + +#include + + + +/** + * Adds from a source array to a destination array +*/ +void fluid_grid2_add_source(float * x, float * s, float dt); + + + +/** + * Sets the bounds of this cube to those of its neighbor +*/ +void fluid_grid2_setBoundsToNeighborsRaw( + int chunk_mask, + int vector_dir, + float ** neighborArray +); + + +/** + * This exclusively copies neighbors to make sure zeroing out stuff doesn't break sim +*/ +void fluid_grid2_copyNeighborsRaw( + int chunk_mask, + int cx, + int vector_dir, + float ** neighborArray +); + + + + + + + + + + +/** + * Sums the density of the chunk + */ +double fluid_grid2_calculateSum(uint32_t chunk_mask, float ** d); + + + + + + + + + +#endif \ No newline at end of file diff --git a/src/main/c/includes/fluid/sim/grid2/mainFunctions.h b/src/main/c/includes/fluid/sim/grid2/velocity.h similarity index 58% rename from src/main/c/includes/fluid/sim/grid2/mainFunctions.h rename to src/main/c/includes/fluid/sim/grid2/velocity.h index 8d01b84a..635c14b6 100644 --- a/src/main/c/includes/fluid/sim/grid2/mainFunctions.h +++ b/src/main/c/includes/fluid/sim/grid2/velocity.h @@ -1,8 +1,10 @@ + +#ifndef FLUID_GRID2_VELOCITY +#define FLUID_GRID2_vELOCITY + #include #include "fluid/env/environment.h" -#ifndef FLUID_GRID2_MAINFUNC -#define FLUID_GRID2_MAINFUNC @@ -12,27 +14,6 @@ #define FLUID_GRID2_BOUND_DIR_W 3 - - - - - - - - - - -/** - * The main simulation function - */ -void fluid_grid2_simulate( - int numChunks, - Chunk ** passedInChunks, - Environment * environment, - jfloat timestep -); - - /** * Adds the sources to the destinations */ @@ -49,28 +30,6 @@ void fluid_grid2_addSourceToVectors float VISCOSITY_CONST, float dt); -/** - * Adds from a source array to a destination array -*/ -void fluid_grid2_add_source(float * x, float * s, float dt); - - - -/* - * Solves vector diffusion along all axis - */ -void fluid_grid2_solveVectorDiffuse ( - int chunk_mask, - float ** jru, - float ** jrv, - float ** jrw, - float ** jru0, - float ** jrv0, - float ** jrw0, - float DIFFUSION_CONST, - float VISCOSITY_CONST, - float dt -); @@ -140,6 +99,7 @@ void fluid_grid2_finalizeProjection( ); + /* * Advects u, v, and w */ @@ -156,64 +116,23 @@ void fluid_grid2_advectVectors( float dt ); - /** * Actually performs the advection */ -void fluid_grid2_advect(uint32_t chunk_mask, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt); - - -/** - * Sets the bounds of this cube to those of its neighbor -*/ -void fluid_grid2_setBoundsToNeighborsRaw( - int chunk_mask, - int vector_dir, - float ** neighborArray -); - - -/** - * This exclusively copies neighbors to make sure zeroing out stuff doesn't break sim -*/ -void fluid_grid2_copyNeighborsRaw( - int chunk_mask, - int cx, - int vector_dir, - float ** neighborArray -); - - - - - - - -/** - * Adds density to the density array - * @return The change in density within this chunk for this frame -*/ -void fluid_grid2_addDensity( - Environment * environment, - int chunk_mask, - float ** d, - float ** d0, - float dt -); - - +void fluid_grid2_advect_velocity(uint32_t chunk_mask, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt); /* - * A single iteration of the jacobi to solve density diffusion + * Solves vector diffusion along all axis */ -void fluid_grid2_solveDiffuseDensity( +void fluid_grid2_solveVectorDiffuse ( int chunk_mask, - float ** d, - float ** d0, float ** jru, float ** jrv, float ** jrw, + float ** jru0, + float ** jrv0, + float ** jrw0, float DIFFUSION_CONST, float VISCOSITY_CONST, float dt @@ -223,56 +142,5 @@ void fluid_grid2_solveDiffuseDensity( -/** - * Advects the density based on the vectors -*/ -void fluid_grid2_advectDensity(uint32_t chunk_mask, float ** d, float ** d0, float ** ur, float ** vr, float ** wr, float dt); - - - - - - -/** - * Sums the density of the chunk - */ -double fluid_grid2_calculateSum(uint32_t chunk_mask, float ** d); - - - - - - -/** - * Normalizes the density array with a given ratio - */ -void fluid_grid2_normalizeDensity(float ** d, float ratio); - - - - - - -/** - * Allocates the arrays necessary for grid2 simulation - */ -void fluid_grid2_allocate_arrays(); - - - - - - - - - - - - - - - - - #endif \ No newline at end of file diff --git a/src/main/c/src/fluid/queue/javainterface.c b/src/main/c/src/fluid/queue/javainterface.c index 167dafb6..5e40e154 100644 --- a/src/main/c/src/fluid/queue/javainterface.c +++ b/src/main/c/src/fluid/queue/javainterface.c @@ -13,7 +13,7 @@ #include "fluid/env/environment.h" #include "fluid/env/utilities.h" #include "fluid/sim/grid/simulation.h" -#include "fluid/sim/grid2/simulation.h" +#include "fluid/sim/grid2/grid2.h" #include "fluid/sim/simulator.h" #include "fluid/dispatch/dispatcher.h" diff --git a/src/main/c/src/fluid/sim/grid2/densitystep.c b/src/main/c/src/fluid/sim/grid2/density.c similarity index 99% rename from src/main/c/src/fluid/sim/grid2/densitystep.c rename to src/main/c/src/fluid/sim/grid2/density.c index 375c1ef8..9c24842a 100644 --- a/src/main/c/src/fluid/sim/grid2/densitystep.c +++ b/src/main/c/src/fluid/sim/grid2/density.c @@ -8,6 +8,7 @@ #include "fluid/env/environment.h" #include "fluid/queue/chunk.h" #include "fluid/sim/grid2/solver_consts.h" +#include "fluid/sim/grid2/utilities.h" /** diff --git a/src/main/c/src/fluid/sim/grid2/fluidsim.c b/src/main/c/src/fluid/sim/grid2/fluidsim.c index ee2a07c6..cd35d348 100644 --- a/src/main/c/src/fluid/sim/grid2/fluidsim.c +++ b/src/main/c/src/fluid/sim/grid2/fluidsim.c @@ -8,10 +8,12 @@ //fluid lib #include "fluid/env/utilities.h" #include "fluid/queue/chunkmask.h" -#include "fluid/sim/grid2/mainFunctions.h" #include "fluid/queue/chunk.h" -#include "fluid/sim/grid2/simulation.h" +#include "fluid/sim/grid2/grid2.h" #include "fluid/sim/grid2/solver_consts.h" +#include "fluid/sim/grid2/velocity.h" +#include "fluid/sim/grid2/density.h" +#include "fluid/sim/grid2/utilities.h" #ifndef SAVE_STEPS #define SAVE_STEPS 0 diff --git a/src/main/c/src/fluid/sim/grid2/velocitystep.c b/src/main/c/src/fluid/sim/grid2/velocity.c similarity index 97% rename from src/main/c/src/fluid/sim/grid2/velocitystep.c rename to src/main/c/src/fluid/sim/grid2/velocity.c index d342e979..706f7590 100644 --- a/src/main/c/src/fluid/sim/grid2/velocitystep.c +++ b/src/main/c/src/fluid/sim/grid2/velocity.c @@ -6,7 +6,8 @@ #include "fluid/queue/chunkmask.h" #include "fluid/queue/chunk.h" #include "fluid/sim/grid2/solver_consts.h" -#include "fluid/sim/grid2/mainFunctions.h" +#include "fluid/sim/grid2/velocity.h" +#include "fluid/sim/grid2/utilities.h" #define SET_BOUND_IGNORE 0 #define SET_BOUND_USE_NEIGHBOR 1 @@ -398,15 +399,15 @@ void fluid_grid2_advectVectors( float VISCOSITY_CONST, float dt ){ - fluid_grid2_advect(chunk_mask,1,jru,jru0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt); - fluid_grid2_advect(chunk_mask,2,jrv,jrv0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt); - fluid_grid2_advect(chunk_mask,3,jrw,jrw0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt); + fluid_grid2_advect_velocity(chunk_mask,1,jru,jru0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt); + fluid_grid2_advect_velocity(chunk_mask,2,jrv,jrv0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt); + fluid_grid2_advect_velocity(chunk_mask,3,jrw,jrw0,GET_ARR_RAW(jru0,CENTER_LOC),GET_ARR_RAW(jrv0,CENTER_LOC),GET_ARR_RAW(jrw0,CENTER_LOC),dt); } /** * Actually performs the advection */ -void fluid_grid2_advect(uint32_t chunk_mask, int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt){ +void fluid_grid2_advect_velocity(uint32_t chunk_mask, 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; diff --git a/src/main/c/src/fluid/sim/simulator.c b/src/main/c/src/fluid/sim/simulator.c index 35a04531..e74cd187 100644 --- a/src/main/c/src/fluid/sim/simulator.c +++ b/src/main/c/src/fluid/sim/simulator.c @@ -5,7 +5,7 @@ #include "fluid/dispatch/dispatcher.h" #include "fluid/sim/simulator.h" #include "fluid/sim/grid/simulation.h" -#include "fluid/sim/grid2/simulation.h" +#include "fluid/sim/grid2/grid2.h" #include "fluid/sim/cellular/cellular.h" #include "fluid/queue/chunk.h" #include "fluid/env/environment.h"