Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
FLUIDS: fluid simulation example

Data Structures

struct  N_FLUID
 structure of a fluid More...
 
struct  N_FLUID_THREAD_PARAMS
 structure passed to a threaded fluid process More...
 

Macros

#define _z(__fluid, __component)   ((__fluid->__component) > (__fluid->negative_float_tolerance) && (__fluid->__component) < (__fluid->positive_float_tolerance))
 test if component is near zero, according to fluid's precision
 
#define _zd(__fluid, __value)   ((__value) > (__fluid->negative_float_tolerance) && (__value) < (__fluid->positive_float_tolerance))
 test if value is near zero, according to fluid's precision
 

Functions

int destroy_n_fluid (N_FLUID **fluid)
 destroy a fluid simulation
 
int n_fluid_advectSmoke (N_FLUID *fluid)
 advect smoke density field
 
int n_fluid_advectVel (N_FLUID *fluid)
 advect velocity field
 
double n_fluid_avgU (N_FLUID *fluid, size_t i, size_t j)
 compute average U velocity at cell
 
double n_fluid_avgV (N_FLUID *fluid, size_t i, size_t j)
 compute average V velocity at cell
 
int n_fluid_draw (N_FLUID *fluid)
 draw the fluid simulation
 
int n_fluid_extrapolate (N_FLUID *fluid)
 extrapolate fluid boundaries
 
ALLEGRO_COLOR n_fluid_getSciColor (const N_FLUID *fluid, double val, double minVal, double maxVal)
 get a scientific color for a value
 
int n_fluid_integrate (N_FLUID *fluid)
 integrate fluid velocities
 
int n_fluid_resetObstacles (N_FLUID *fluid)
 reset all obstacles
 
double n_fluid_sampleField (N_FLUID *fluid, double x, double y, uint32_t field)
 sample a field value at given coordinates
 
int n_fluid_setObstacle (N_FLUID *fluid, double x, double y, double vx, double vy, double r)
 set an obstacle in the fluid
 
int n_fluid_simulate (N_FLUID *fluid)
 run one simulation step
 
int n_fluid_simulate_threaded (N_FLUID *fluid, THREAD_POOL *thread_pool)
 run one simulation step using thread pool
 
int n_fluid_solveIncompressibility (N_FLUID *fluid)
 solve incompressibility constraint
 
N_FLUIDnew_n_fluid (double density, double gravity, size_t numIters, double dt, double overRelaxation, size_t sx, size_t sy)
 create a new fluid simulation
 

Detailed Description


Data Structure Documentation

◆ N_FLUID

struct N_FLUID

structure of a fluid

Examples
ex_fluid.c, ex_fluid_config.c, and ex_fluid_config.h.

Definition at line 69 of file n_fluids.h.

+ Collaboration diagram for N_FLUID:
Data Fields
LIST * advectSmoke_chunk_list preprocessed list of threaded procs parameters, for n_fluid_advectSmoke
LIST * advectVel_chunk_list preprocessed list of threaded procs parameters, for n_fluid_advectVel
double cScale scale used to deduce cellX and cellY from screen/window width and height
double density density of the fluid (not working ?)
double dt time between frames
double fluid_production_percentage size of the produced fluid
double gravity gravity on Y
double h
LIST * integrate_chunk_list preprocessed list of threaded procs parameters, for n_fluid_integrate
double * m holder for m arrays
double negative_float_tolerance fluid double negative precision setting
double * newM holder for newM arrays
double * newU holder for newU arrays
double * newV holder for newV arrays
size_t numCells total number of cells
size_t numIters number of fluid processing iterations for each frame
size_t numX number of cells in X
size_t numY number of cells in Y
size_t numZ number of cells in Z
double overRelaxation over relaxation
double * p holder for p arrays
double positive_float_tolerance fluid double positive precision setting
double * s holder for s arrays
bool showPaint activate a fonky palette, override smoke and pressure display
bool showPressure display fluids pressures as color variations, can be combined with showSmoke
bool showSmoke display fluid as a colored cloud instead of black and white, can be combined with showPressure
LIST * solveIncompressibility_chunk_list preprocessed list of threaded procs parameters, for n_fluid_solveIncompressibility
double * u holder for u arrays
double * v holder for v arrays

◆ N_FLUID_THREAD_PARAMS

struct N_FLUID_THREAD_PARAMS

structure passed to a threaded fluid process

Definition at line 55 of file n_fluids.h.

+ Collaboration diagram for N_FLUID_THREAD_PARAMS:
Data Fields
void * ptr pointer to data which will be used in the proc
size_t x_end x end point
size_t x_start x start point
size_t y_end y end point
size_t y_start y start point

Macro Definition Documentation

◆ _z

#define _z (   __fluid,
  __component 
)    ((__fluid->__component) > (__fluid->negative_float_tolerance) && (__fluid->__component) < (__fluid->positive_float_tolerance))

test if component is near zero, according to fluid's precision

Definition at line 46 of file n_fluids.h.

◆ _zd

#define _zd (   __fluid,
  __value 
)    ((__value) > (__fluid->negative_float_tolerance) && (__value) < (__fluid->positive_float_tolerance))

test if value is near zero, according to fluid's precision

Definition at line 51 of file n_fluids.h.

Function Documentation

◆ destroy_n_fluid()

int destroy_n_fluid ( N_FLUID **  fluid)

destroy a fluid simulation

destroy a fluid simulation

Parameters
fluidpointer to the structure to destroy
Returns
TRUE or FALSE

Definition at line 63 of file n_fluids.c.

References __n_assert, FreeNoLog, and list_destroy().

+ Here is the call graph for this function:

◆ n_fluid_advectSmoke()

int n_fluid_advectSmoke ( N_FLUID fluid)

advect smoke density field

advect smoke density field

Parameters
fluida N_FLUID ptr
Returns
TRUE or FALSE

Definition at line 590 of file n_fluids.c.

References __n_assert, _z, N_FLUID::dt, N_FLUID::h, N_FLUID::m, N_FLUID_S_FIELD, n_fluid_sampleField(), N_FLUID::newM, N_FLUID::numCells, N_FLUID::numX, N_FLUID::numY, N_FLUID::u, and N_FLUID::v.

Referenced by n_fluid_simulate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_fluid_advectVel()

int n_fluid_advectVel ( N_FLUID fluid)

advect velocity field

advect velocity field

Parameters
fluida N_FLUID ptr
Returns
TRUE or FALSE

Definition at line 510 of file n_fluids.c.

References __n_assert, _z, N_FLUID::dt, N_FLUID::h, n_fluid_avgU(), n_fluid_avgV(), n_fluid_sampleField(), N_FLUID_U_FIELD, N_FLUID_V_FIELD, N_FLUID::newU, N_FLUID::newV, N_FLUID::numCells, N_FLUID::numX, N_FLUID::numY, N_FLUID::u, and N_FLUID::v.

Referenced by n_fluid_simulate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_fluid_avgU()

double n_fluid_avgU ( N_FLUID fluid,
size_t  i,
size_t  j 
)

compute average U velocity at cell

compute average U velocity at cell

Parameters
fluidtargeted N_FLUID
iX position in the fluid grid
jY position in the fluid grid
Returns
the average computed value

Definition at line 434 of file n_fluids.c.

References __n_assert, N_FLUID::numY, and N_FLUID::u.

Referenced by n_fluid_advectVel(), and n_fluid_advectVel_proc().

+ Here is the caller graph for this function:

◆ n_fluid_avgV()

double n_fluid_avgV ( N_FLUID fluid,
size_t  i,
size_t  j 
)

compute average V velocity at cell

compute average V velocity at cell

Parameters
fluidtargeted N_FLUID
iX position in the fluid grid
jY position in the fluid grid
Returns
the average computed value

Definition at line 452 of file n_fluids.c.

References __n_assert, N_FLUID::numY, and N_FLUID::v.

Referenced by n_fluid_advectVel(), and n_fluid_advectVel_proc().

+ Here is the caller graph for this function:

◆ n_fluid_draw()

int n_fluid_draw ( N_FLUID fluid)

draw the fluid simulation

draw the fluid simulation

Parameters
fluidthe N_FLUID to draw
Returns
TRUE or FALSE

Definition at line 842 of file n_fluids.c.

References __n_assert, N_FLUID::cScale, N_FLUID::m, n_fluid_getSciColor(), N_FLUID::numCells, N_FLUID::numX, N_FLUID::numY, N_FLUID::p, N_FLUID::showPaint, N_FLUID::showPressure, and N_FLUID::showSmoke.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_fluid_extrapolate()

int n_fluid_extrapolate ( N_FLUID fluid)

extrapolate fluid boundaries

extrapolate fluid boundaries

Parameters
fluida N_FLUID to extrapolate
Returns
TRUE or FALSE

Definition at line 352 of file n_fluids.c.

References __n_assert, N_FLUID::numX, N_FLUID::numY, N_FLUID::u, and N_FLUID::v.

Referenced by n_fluid_simulate(), and n_fluid_simulate_threaded().

+ Here is the caller graph for this function:

◆ n_fluid_getSciColor()

ALLEGRO_COLOR n_fluid_getSciColor ( const N_FLUID fluid,
double  val,
double  minVal,
double  maxVal 
)

get a scientific color for a value

get a scientific color for a value

Parameters
fluidtargeted N_FLUID
valvalue mixer
minValminimum output value
maxValmaximum output value
Returns
the generated ALLEGRO_COLOR

Definition at line 799 of file n_fluids.c.

References _zd.

Referenced by n_fluid_draw().

+ Here is the caller graph for this function:

◆ n_fluid_integrate()

int n_fluid_integrate ( N_FLUID fluid)

integrate fluid velocities

integrate fluid velocities

Parameters
fluida N_FLUID to integrate_chunk_list
Returns
TRUE or FALSE

Definition at line 259 of file n_fluids.c.

References __n_assert, _z, N_FLUID::dt, N_FLUID::gravity, N_FLUID::numX, N_FLUID::numY, and N_FLUID::v.

Referenced by n_fluid_simulate().

+ Here is the caller graph for this function:

◆ n_fluid_resetObstacles()

int n_fluid_resetObstacles ( N_FLUID fluid)

reset all obstacles

reset all obstacles

Parameters
fluidthe targeted N_FLUID
Returns
TRUE or FALSE

Definition at line 739 of file n_fluids.c.

References __n_assert, N_FLUID::numX, N_FLUID::numY, and N_FLUID::s.

Referenced by main().

+ Here is the caller graph for this function:

◆ n_fluid_sampleField()

double n_fluid_sampleField ( N_FLUID fluid,
double  x,
double  y,
uint32_t  field 
)

sample a field value at given coordinates

sample a field value at given coordinates

Parameters
fluidtarget N_FLUID
xX position in the fluid grid
yY position in the fluid grid
fieldtype of field wanted, one of N_FLUID_U_FIELD, N_FLUID_V_FIELD, N_FLUID_S_FIELD
Returns
the computed value

Definition at line 374 of file n_fluids.c.

References __n_assert, N_FLUID::h, N_FLUID::m, N_FLUID_S_FIELD, N_FLUID_U_FIELD, N_FLUID_V_FIELD, N_FLUID::numX, N_FLUID::numY, N_FLUID::u, and N_FLUID::v.

Referenced by n_fluid_advectSmoke(), n_fluid_advectSmoke_proc(), n_fluid_advectVel(), and n_fluid_advectVel_proc().

+ Here is the caller graph for this function:

◆ n_fluid_setObstacle()

int n_fluid_setObstacle ( N_FLUID fluid,
double  x,
double  y,
double  vx,
double  vy,
double  r 
)

set an obstacle in the fluid

set an obstacle in the fluid

Parameters
fluidtargeted N_FLUID
xX position in fluid grid
yy position in fluid grid
vxX velocity for the point
vyY velocity for the point
rradius
Returns
TRUE or FALSE

Definition at line 712 of file n_fluids.c.

References __n_assert, N_FLUID::m, N_FLUID::numX, N_FLUID::numY, N_FLUID::s, N_FLUID::u, and N_FLUID::v.

Referenced by main().

+ Here is the caller graph for this function:

◆ n_fluid_simulate()

int n_fluid_simulate ( N_FLUID fluid)

run one simulation step

run one simulation step

Parameters
fluida N_FLUID ptr
Returns
TRUE or FALSE

Definition at line 623 of file n_fluids.c.

References __n_assert, n_fluid_advectSmoke(), n_fluid_advectVel(), n_fluid_extrapolate(), n_fluid_integrate(), n_fluid_solveIncompressibility(), N_FLUID::numCells, and N_FLUID::p.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_fluid_simulate_threaded()

int n_fluid_simulate_threaded ( N_FLUID fluid,
THREAD_POOL thread_pool 
)

◆ n_fluid_solveIncompressibility()

int n_fluid_solveIncompressibility ( N_FLUID fluid)

solve incompressibility constraint

solve incompressibility constraint

Parameters
fluidN_FLUID to solve
Returns
TRUE or FALSE

Definition at line 314 of file n_fluids.c.

References __n_assert, _z, _zd, N_FLUID::density, N_FLUID::dt, N_FLUID::h, N_FLUID::numIters, N_FLUID::numX, N_FLUID::numY, N_FLUID::overRelaxation, N_FLUID::p, N_FLUID::s, N_FLUID::u, and N_FLUID::v.

Referenced by n_fluid_simulate().

+ Here is the caller graph for this function:

◆ new_n_fluid()

N_FLUID * new_n_fluid ( double  density,
double  gravity,
size_t  numIters,
double  dt,
double  overRelaxation,
size_t  sx,
size_t  sy 
)

create a new fluid simulation

create a new fluid simulation

Parameters
densitydensity of the fluid
gravitygravity applied (Y axe)
numIterspredefined number of iterations for each frames
dtpreconfigured delta time
overRelaxationover predefined over relaxation value
sxnumber of cells on x axis
synumber of cells on y axis
Returns
a newly allocated N_FLUID structure

Definition at line 95 of file n_fluids.c.

References __n_assert, N_FLUID::advectSmoke_chunk_list, N_FLUID::advectVel_chunk_list, N_FLUID::cScale, N_FLUID::density, N_FLUID::dt, LIST::end, N_FLUID::fluid_production_percentage, FreeNoLog, get_nb_cpu_cores(), N_FLUID::gravity, N_FLUID::h, N_FLUID::integrate_chunk_list, list_push(), N_FLUID::m, Malloc, n_memset(), N_FLUID::negative_float_tolerance, new_generic_list(), N_FLUID::newM, N_FLUID::newU, N_FLUID::newV, N_FLUID::numCells, N_FLUID::numIters, N_FLUID::numX, N_FLUID::numY, N_FLUID::numZ, N_FLUID::overRelaxation, N_FLUID::p, N_FLUID::positive_float_tolerance, N_FLUID_THREAD_PARAMS::ptr, LIST_NODE::ptr, N_FLUID::s, N_FLUID::showPaint, N_FLUID::showPressure, N_FLUID::showSmoke, N_FLUID::solveIncompressibility_chunk_list, N_FLUID::u, N_FLUID::v, N_FLUID_THREAD_PARAMS::x_end, N_FLUID_THREAD_PARAMS::x_start, N_FLUID_THREAD_PARAMS::y_end, and N_FLUID_THREAD_PARAMS::y_start.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: