Nilorea Library
C utilities for networking, threading, graphics
Go to the documentation of this file.
10#ifndef __N_FLUID_HEADER
11#define __N_FLUID_HEADER
13#ifdef __cplusplus
14extern "C" {
22#include "allegro5/allegro.h"
23#include <allegro5/allegro_primitives.h>
24#include "nilorea/n_list.h"
27#ifndef _z
29#define _z( __fluid , __componant ) ( (__fluid->__componant) > (__fluid->negative_float_tolerance) && (__fluid->__componant) < (__fluid->positive_float_tolerance) )
32#ifndef _zd
34#define _zd( __fluid , __value ) ( (__value) > (__fluid->negative_float_tolerance) && (__value) < (__fluid->positive_float_tolerance) )
38 typedef struct N_FLUID_THREAD_PARAMS
39 {
41 void *ptr ;
43 size_t x_start ;
45 size_t x_end ;
47 size_t y_start ;
49 size_t y_end ;
53 typedef struct N_FLUID
54 {
56 size_t numX ;
58 size_t numY ;
60 size_t numZ ;
62 size_t numCells ;
64 size_t numIters ;
66 double density ;
68 double dt ;
70 double h ;
72 double gravity ;
76 bool showSmoke ;
78 bool showPaint ;
90 double cScale ;
93 double *u ;
95 double *newU ;
98 double *v ;
100 double *newV ;
103 double *p ;
105 double *s ;
108 double *m ;
110 double *newM ;
121 } N_FLUID ;
123 int destroy_n_fluid( N_FLUID **fluid );
124 N_FLUID *new_n_fluid( double density , double gravity , size_t numIters , double dt , double overRelaxation , size_t sx , size_t sy );
126 int n_fluid_integrate( N_FLUID *fluid );
128 int n_fluid_extrapolate( N_FLUID *fluid );
130 double n_fluid_sampleField( N_FLUID *fluid , double x , double y , uint32_t field );
131 double n_fluid_avgU( N_FLUID *fluid , size_t i , size_t j );
132 double n_fluid_avgV( N_FLUID *fluid , size_t i , size_t j );
134 int n_fluid_advectVel( N_FLUID *fluid );
135 int n_fluid_advectSmoke( N_FLUID *fluid );
137 int n_fluid_simulate( N_FLUID *fluid );
138 int n_fluid_simulate_threaded( N_FLUID *fluid , THREAD_POOL *thread_pool );
140 int n_fluid_setObstacle( N_FLUID *fluid , double x , double y , double vx , double vy , double r );
141 int n_fluid_resetObstacles( N_FLUID *fluid );
143 ALLEGRO_COLOR n_fluid_getSciColor( N_FLUID *fluid , double val , double minVal , double maxVal );
144 int n_fluid_draw( N_FLUID *fluid );
150#ifdef __cplusplus
Structure of a generic LIST container.
Definition: n_list.h:45
double * newU
holder for newU arrays
Definition: n_fluids.h:95
size_t numY
number of cells in Y
Definition: n_fluids.h:58
size_t y_start
y start point
Definition: n_fluids.h:47
double fluid_production_percentage
size of the produced fluid
Definition: n_fluids.h:88
bool showSmoke
display fluid as a colored cloud instead of black and white, can be combined with showPressure
Definition: n_fluids.h:76
size_t numX
number of cells in X
Definition: n_fluids.h:56
LIST * advectSmoke_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_advectSmoke
Definition: n_fluids.h:119
double overRelaxation
over relaxation
Definition: n_fluids.h:74
bool showPressure
display fluids pressures as color variations, can be combined with showSmoke
Definition: n_fluids.h:80
void * ptr
pointer to data which will be used in the proc
Definition: n_fluids.h:41
double positive_float_tolerance
fluid double positive precision setting
Definition: n_fluids.h:85
LIST * solveIncompressibility_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_solveIncompressibility
Definition: n_fluids.h:115
size_t x_end
x end point
Definition: n_fluids.h:45
bool showPaint
activate a fonky palette, override smoke and pressure display
Definition: n_fluids.h:78
double * u
holder for u arrays
Definition: n_fluids.h:93
LIST * integrate_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_integrate
Definition: n_fluids.h:113
double * newV
holder for newV arrays
Definition: n_fluids.h:100
double dt
time between frames
Definition: n_fluids.h:68
double * s
holder for s arrays
Definition: n_fluids.h:105
double * v
holder for v arrays
Definition: n_fluids.h:98
size_t numCells
total number of cells
Definition: n_fluids.h:62
size_t numIters
number of fluid processing iterations for each frame
Definition: n_fluids.h:64
double density
density of the fluid (not working ?)
Definition: n_fluids.h:66
LIST * advectVel_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_advectVel
Definition: n_fluids.h:117
double * m
holder for m arrays
Definition: n_fluids.h:108
double cScale
scale used to deduce cellX and cellY from screen/window width and height
Definition: n_fluids.h:90
double * newM
holder for newM arrays
Definition: n_fluids.h:110
size_t numZ
number of cells in Z
Definition: n_fluids.h:60
double * p
holder for p arrays
Definition: n_fluids.h:103
size_t x_start
x start point
Definition: n_fluids.h:43
double gravity
gravity on Y
Definition: n_fluids.h:72
size_t y_end
y end point
Definition: n_fluids.h:49
double negative_float_tolerance
fluid double negative precision setting
Definition: n_fluids.h:83
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
Definition: n_fluids.c:428
int n_fluid_draw(N_FLUID *fluid)
draw a N_FLUID on screen / targert bitmap
Definition: n_fluids.c:861
int n_fluid_simulate_threaded(N_FLUID *fluid, THREAD_POOL *thread_pool)
a threaded version of N_FLUID global processing function
Definition: n_fluids.c:641
int n_fluid_simulate(N_FLUID *fluid)
non threaded version of N_FLUID global processing function
Definition: n_fluids.c:621
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
Definition: n_fluids.c:408
double n_fluid_sampleField(N_FLUID *fluid, double x, double y, uint32_t field)
compute a sample value at a field position
Definition: n_fluids.c:359
ALLEGRO_COLOR n_fluid_getSciColor(N_FLUID *fluid, double val, double minVal, double maxVal)
get fonky colors for the fluid
Definition: n_fluids.c:827
int n_fluid_extrapolate(N_FLUID *fluid)
non threaded extrapolation function
Definition: n_fluids.c:333
int n_fluid_advectSmoke(N_FLUID *fluid)
non threaded version of add smoke function
Definition: n_fluids.c:582
int n_fluid_solveIncompressibility(N_FLUID *fluid)
non threaded version of incompressibility solving function
Definition: n_fluids.c:289
int n_fluid_resetObstacles(N_FLUID *fluid)
reset the obstacles set in a N_FLUID
Definition: n_fluids.c:756
int n_fluid_integrate(N_FLUID *fluid)
non threaded version of integration function
Definition: n_fluids.c:225
int n_fluid_setObstacle(N_FLUID *fluid, double x, double y, double vx, double vy, double r)
set an obstacle in the fluid grid
Definition: n_fluids.c:722
int destroy_n_fluid(N_FLUID **fluid)
ddestroy a fluid structure
Definition: n_fluids.c:48
int n_fluid_advectVel(N_FLUID *fluid)
non threaded version of add velocities function
Definition: n_fluids.c:492
N_FLUID * new_n_fluid(double density, double gravity, size_t numIters, double dt, double overRelaxation, size_t sx, size_t sy)
Definition: n_fluids.c:78
structure of a fluid
Definition: n_fluids.h:54
structure passed to a threaded fluid process
Definition: n_fluids.h:39
Structure of a trhead pool.
Definition: n_thread_pool.h:81
List structures and definitions.
Thread pool declaration.