Nilorea Library
C utilities for networking, threading, graphics
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, __componant)   ( (__fluid->__componant) > (__fluid->negative_float_tolerance) && (__fluid->__componant) < (__fluid->positive_float_tolerance) )
 test if componant is near zero, according to fluid's precision More...
 
#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 More...
 

Functions

int destroy_n_fluid (N_FLUID **fluid)
 ddestroy a fluid structure More...
 
int n_fluid_advectSmoke (N_FLUID *fluid)
 non threaded version of add smoke function More...
 
int n_fluid_advectVel (N_FLUID *fluid)
 non threaded version of add velocities function More...
 
double n_fluid_avgU (N_FLUID *fluid, size_t i, size_t j)
 compute the average U value at a fluid position using it's surrounding More...
 
double n_fluid_avgV (N_FLUID *fluid, size_t i, size_t j)
 compute the average V value at a fluid position using it's surrounding More...
 
int n_fluid_draw (N_FLUID *fluid)
 draw a N_FLUID on screen / targert bitmap More...
 
int n_fluid_extrapolate (N_FLUID *fluid)
 non threaded extrapolation function More...
 
ALLEGRO_COLOR n_fluid_getSciColor (N_FLUID *fluid, double val, double minVal, double maxVal)
 get fonky colors for the fluid More...
 
int n_fluid_integrate (N_FLUID *fluid)
 non threaded version of integration function More...
 
int n_fluid_resetObstacles (N_FLUID *fluid)
 reset the obstacles set in a N_FLUID More...
 
double n_fluid_sampleField (N_FLUID *fluid, double x, double y, uint32_t field)
 compute a sample value at a field position More...
 
int n_fluid_setObstacle (N_FLUID *fluid, double x, double y, double vx, double vy, double r)
 set an obstacle in the fluid grid More...
 
int n_fluid_simulate (N_FLUID *fluid)
 non threaded version of N_FLUID global processing function More...
 
int n_fluid_simulate_threaded (N_FLUID *fluid, THREAD_POOL *thread_pool)
 a threaded version of N_FLUID global processing function More...
 
int n_fluid_solveIncompressibility (N_FLUID *fluid)
 non threaded version of incompressibility solving function More...
 
N_FLUIDnew_n_fluid (double density, double gravity, size_t numIters, double dt, double overRelaxation, size_t sx, size_t sy)
 ! More...
 

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 53 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 38 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,
  __componant 
)    ( (__fluid->__componant) > (__fluid->negative_float_tolerance) && (__fluid->__componant) < (__fluid->positive_float_tolerance) )

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

Definition at line 29 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 34 of file n_fluids.h.

Function Documentation

◆ destroy_n_fluid()

int destroy_n_fluid ( N_FLUID **  fluid)

ddestroy a fluid structure

Parameters
fluidpointer to the structure to destroy
Returns
TRUE or FALSE

Definition at line 48 of file n_fluids.c.

References __n_assert, and FreeNoLog.

◆ n_fluid_advectSmoke()

int n_fluid_advectSmoke ( N_FLUID fluid)

non threaded version of add smoke function

Parameters
fluida N_FLUID ptr
Returns
TRUE or FALSE

Definition at line 582 of file n_fluids.c.

References __n_assert, _z, N_FLUID_S_FIELD, n_fluid_sampleField(), N_FLUID::newM, 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)

non threaded version of add velocities function

Parameters
fluida N_FLUID ptr
Returns
TRUE or FALSE

Definition at line 492 of file n_fluids.c.

References __n_assert, _z, 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::numY, 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 the average U value at a fluid position using it's surrounding

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

Definition at line 408 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 the average V value at a fluid position using it's surrounding

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

Definition at line 428 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 a N_FLUID on screen / targert bitmap

Parameters
fluidthe N_FLUID to draw
Returns
TRUE or FALSE

Definition at line 861 of file n_fluids.c.

References __n_assert, and n_fluid_getSciColor().

+ Here is the call graph for this function:

◆ n_fluid_extrapolate()

int n_fluid_extrapolate ( N_FLUID fluid)

non threaded extrapolation function

Parameters
fluida N_FLUID to extrapolate
Returns
TRUE or FALSE

Definition at line 333 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 ( N_FLUID fluid,
double  val,
double  minVal,
double  maxVal 
)

get fonky colors for the fluid

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

Definition at line 827 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)

non threaded version of integration function

Parameters
fluida N_FLUID to integrate_chunk_list
Returns
TRUE or FALSE

Definition at line 225 of file n_fluids.c.

References __n_assert, and _z.

Referenced by n_fluid_simulate().

+ Here is the caller graph for this function:

◆ n_fluid_resetObstacles()

int n_fluid_resetObstacles ( N_FLUID fluid)

reset the obstacles set in a N_FLUID

Parameters
fluidthe targeted N_FLUID
Returns
TRUE or FALSE

Definition at line 756 of file n_fluids.c.

References __n_assert.

◆ n_fluid_sampleField()

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

compute a sample value at a field position

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 359 of file n_fluids.c.

References __n_assert, N_FLUID::m, N_FLUID_S_FIELD, N_FLUID_U_FIELD, N_FLUID_V_FIELD, 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 grid

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 722 of file n_fluids.c.

References __n_assert.

◆ n_fluid_simulate()

int n_fluid_simulate ( N_FLUID fluid)

non threaded version of N_FLUID global processing function

Parameters
fluida N_FLUID ptr
Returns
TRUE or FALSE

Definition at line 621 of file n_fluids.c.

References __n_assert, n_fluid_advectSmoke(), n_fluid_advectVel(), n_fluid_extrapolate(), n_fluid_integrate(), and n_fluid_solveIncompressibility().

+ Here is the call graph for this function:

◆ n_fluid_simulate_threaded()

int n_fluid_simulate_threaded ( N_FLUID fluid,
THREAD_POOL thread_pool 
)

a threaded version of N_FLUID global processing function

Parameters
fluida N_FLUID ptr
thread_poola THREAD_POOL pool to use
Returns
TRUE or FALSE

Definition at line 641 of file n_fluids.c.

References __n_assert, add_threaded_process(), list_foreach, n_fluid_advectSmoke_proc(), n_fluid_advectVel_proc(), n_fluid_extrapolate(), n_fluid_integrate_proc(), n_fluid_solveIncompressibility_proc(), refresh_thread_pool(), start_threaded_pool(), SYNCED_PROC, and wait_for_synced_threaded_pool().

+ Here is the call graph for this function:

◆ n_fluid_solveIncompressibility()

int n_fluid_solveIncompressibility ( N_FLUID fluid)

non threaded version of incompressibility solving function

Parameters
fluidN_FLUID to solve
Returns
TRUE or FALSE

Definition at line 289 of file n_fluids.c.

References __n_assert, _z, _zd, 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 
)

!

return a newly allocated fluid

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 78 of file n_fluids.c.

References __n_assert, get_nb_cpu_cores(), list_push(), Malloc, n_memset(), and new_generic_list().

+ Here is the call graph for this function: