Renderer/src/main/c/includes/fluid/sim/grid2/velocity.h
austin d0593f4e88
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
projection solver tests
2024-12-09 21:40:39 -05:00

135 lines
2.7 KiB
C

#ifndef FLUID_GRID2_VELOCITY
#define FLUID_GRID2_vELOCITY
#include <stdint.h>
#include "fluid/env/environment.h"
/**
* Used for signaling the bounds setting method to not use adjacent cells when evaluating borders
*/
#define FLUID_GRID2_BOUND_NO_DIR 0
/**
* Used for signaling the bounds setting method to use adjacent cells when evaluating x axis borders
*/
#define FLUID_GRID2_BOUND_DIR_U 1
/**
* Used for signaling the bounds setting method to use adjacent cells when evaluating y axis borders
*/
#define FLUID_GRID2_BOUND_DIR_V 2
/**
* Used for signaling the bounds setting method to use adjacent cells when evaluating z axis borders
*/
#define FLUID_GRID2_BOUND_DIR_W 3
/**
* Adds the sources to the destinations
*/
void fluid_grid2_addSourceToVectors(
float ** jru,
float ** jrv,
float ** jrw,
float ** jru0,
float ** jrv0,
float ** jrw0,
float dt
);
/**
* Sets up a projection system of equations
* It stores the first derivative of the field in pr, and zeroes out divr.
* This allows you to calculate the second derivative into divr using the derivative stored in pr.
* @param ur The x velocity grid
* @param vr The y velocity grid
* @param wr The z velocity grid
* @param pr The grid that will contain the first derivative
* @param divr The grid that will be zeroed out in preparation of the solver
* @param dt The timestep for the simulation
*/
LIBRARY_API void fluid_grid2_setupProjection(
float ** ur,
float ** vr,
float ** wr,
float ** pr,
float ** divr,
float dt
);
/**
* Solves a projection system of equations.
* This performs a single iteration across a the p grid to approximate the gradient field.
* @param jru0 The gradient field
* @param jrv0 The first derivative field
*/
LIBRARY_API void fluid_grid2_solveProjection(
float ** jru0,
float ** jrv0,
float dt
);
/**
* Finalizes a projection.
* This subtracts the difference delta along the approximated gradient field.
* Thus we are left with an approximately mass-conserved field.
*/
LIBRARY_API void fluid_grid2_finalizeProjection(
float ** jru,
float ** jrv,
float ** jrw,
float ** jru0,
float ** jrv0,
float dt
);
/*
* Advects u, v, and w
*/
LIBRARY_API void fluid_grid2_advectVectors(
float ** jru,
float ** jrv,
float ** jrw,
float ** jru0,
float ** jrv0,
float ** jrw0,
float dt
);
/**
* Actually performs the advection
*/
void fluid_grid2_advect_velocity(int b, float ** jrd, float ** jrd0, float * u, float * v, float * w, float dt);
/*
* Solves vector diffusion along all axis
*/
LIBRARY_API void fluid_grid2_solveVectorDiffuse (
float ** jru,
float ** jrv,
float ** jrw,
float ** jru0,
float ** jrv0,
float ** jrw0,
float dt
);
#endif