Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_fluids.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
27#ifndef __N_FLUID_HEADER
28#define __N_FLUID_HEADER
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
39#include "allegro5/allegro.h"
40#include <allegro5/allegro_primitives.h>
41#include "nilorea/n_list.h"
43
44#ifndef _z
46#define _z(__fluid, __component) ((__fluid->__component) > (__fluid->negative_float_tolerance) && (__fluid->__component) < (__fluid->positive_float_tolerance))
47#endif
48
49#ifndef _zd
51#define _zd(__fluid, __value) ((__value) > (__fluid->negative_float_tolerance) && (__value) < (__fluid->positive_float_tolerance))
52#endif
53
55typedef struct N_FLUID_THREAD_PARAMS {
57 void* ptr;
59 size_t x_start;
61 size_t x_end;
63 size_t y_start;
65 size_t y_end;
67
69typedef struct N_FLUID {
71 size_t numX;
73 size_t numY;
75 size_t numZ;
77 size_t numCells;
79 size_t numIters;
81 double density;
83 double dt;
85 double h;
87 double gravity;
96
101
105 double cScale;
106
108 double* u;
110 double* newU;
111
113 double* v;
115 double* newV;
116
118 double* p;
120 double* s;
121
123 double* m;
125 double* newM;
126
135
136} N_FLUID;
137
139int destroy_n_fluid(N_FLUID** fluid);
141N_FLUID* new_n_fluid(double density, double gravity, size_t numIters, double dt, double overRelaxation, size_t sx, size_t sy);
142
144int n_fluid_integrate(N_FLUID* fluid);
148int n_fluid_extrapolate(N_FLUID* fluid);
149
151double n_fluid_sampleField(N_FLUID* fluid, double x, double y, uint32_t field);
153double n_fluid_avgU(N_FLUID* fluid, size_t i, size_t j);
155double n_fluid_avgV(N_FLUID* fluid, size_t i, size_t j);
156
158int n_fluid_advectVel(N_FLUID* fluid);
160int n_fluid_advectSmoke(N_FLUID* fluid);
161
163int n_fluid_simulate(N_FLUID* fluid);
166
168int n_fluid_setObstacle(N_FLUID* fluid, double x, double y, double vx, double vy, double r);
171
173ALLEGRO_COLOR n_fluid_getSciColor(const N_FLUID* fluid, double val, double minVal, double maxVal);
175int n_fluid_draw(N_FLUID* fluid);
176
181#ifdef __cplusplus
182}
183#endif
184
185#endif
THREAD_POOL * thread_pool
Definition ex_fluid.c:77
Structure of a generic LIST container.
Definition n_list.h:58
double h
Definition n_fluids.h:85
double * newU
holder for newU arrays
Definition n_fluids.h:110
size_t numY
number of cells in Y
Definition n_fluids.h:73
size_t y_start
y start point
Definition n_fluids.h:63
double fluid_production_percentage
size of the produced fluid
Definition n_fluids.h:103
bool showSmoke
display fluid as a colored cloud instead of black and white, can be combined with showPressure
Definition n_fluids.h:91
size_t numX
number of cells in X
Definition n_fluids.h:71
LIST * advectSmoke_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_advectSmoke
Definition n_fluids.h:134
double overRelaxation
over relaxation
Definition n_fluids.h:89
bool showPressure
display fluids pressures as color variations, can be combined with showSmoke
Definition n_fluids.h:95
void * ptr
pointer to data which will be used in the proc
Definition n_fluids.h:57
double positive_float_tolerance
fluid double positive precision setting
Definition n_fluids.h:100
LIST * solveIncompressibility_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_solveIncompressibility
Definition n_fluids.h:130
size_t x_end
x end point
Definition n_fluids.h:61
bool showPaint
activate a fonky palette, override smoke and pressure display
Definition n_fluids.h:93
double * u
holder for u arrays
Definition n_fluids.h:108
LIST * integrate_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_integrate
Definition n_fluids.h:128
double * newV
holder for newV arrays
Definition n_fluids.h:115
double dt
time between frames
Definition n_fluids.h:83
double * s
holder for s arrays
Definition n_fluids.h:120
double * v
holder for v arrays
Definition n_fluids.h:113
size_t numCells
total number of cells
Definition n_fluids.h:77
size_t numIters
number of fluid processing iterations for each frame
Definition n_fluids.h:79
double density
density of the fluid (not working ?)
Definition n_fluids.h:81
LIST * advectVel_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_advectVel
Definition n_fluids.h:132
double * m
holder for m arrays
Definition n_fluids.h:123
double cScale
scale used to deduce cellX and cellY from screen/window width and height
Definition n_fluids.h:105
double * newM
holder for newM arrays
Definition n_fluids.h:125
size_t numZ
number of cells in Z
Definition n_fluids.h:75
double * p
holder for p arrays
Definition n_fluids.h:118
size_t x_start
x start point
Definition n_fluids.h:59
double gravity
gravity on Y
Definition n_fluids.h:87
size_t y_end
y end point
Definition n_fluids.h:65
double negative_float_tolerance
fluid double negative precision setting
Definition n_fluids.h:98
double n_fluid_avgV(N_FLUID *fluid, size_t i, size_t j)
compute average V velocity at cell
Definition n_fluids.c:452
int n_fluid_draw(N_FLUID *fluid)
draw the fluid simulation
Definition n_fluids.c:842
int n_fluid_simulate_threaded(N_FLUID *fluid, THREAD_POOL *thread_pool)
run one simulation step using thread pool
Definition n_fluids.c:640
int n_fluid_simulate(N_FLUID *fluid)
run one simulation step
Definition n_fluids.c:623
double n_fluid_avgU(N_FLUID *fluid, size_t i, size_t j)
compute average U velocity at cell
Definition n_fluids.c:434
double n_fluid_sampleField(N_FLUID *fluid, double x, double y, uint32_t field)
sample a field value at given coordinates
Definition n_fluids.c:374
int n_fluid_extrapolate(N_FLUID *fluid)
extrapolate fluid boundaries
Definition n_fluids.c:352
int n_fluid_advectSmoke(N_FLUID *fluid)
advect smoke density field
Definition n_fluids.c:590
int n_fluid_solveIncompressibility(N_FLUID *fluid)
solve incompressibility constraint
Definition n_fluids.c:314
ALLEGRO_COLOR n_fluid_getSciColor(const N_FLUID *fluid, double val, double minVal, double maxVal)
get a scientific color for a value
Definition n_fluids.c:799
int n_fluid_resetObstacles(N_FLUID *fluid)
reset all obstacles
Definition n_fluids.c:739
int n_fluid_integrate(N_FLUID *fluid)
integrate fluid velocities
Definition n_fluids.c:259
int n_fluid_setObstacle(N_FLUID *fluid, double x, double y, double vx, double vy, double r)
set an obstacle in the fluid
Definition n_fluids.c:712
int destroy_n_fluid(N_FLUID **fluid)
destroy a fluid simulation
Definition n_fluids.c:63
int n_fluid_advectVel(N_FLUID *fluid)
advect velocity field
Definition n_fluids.c:510
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
Definition n_fluids.c:95
structure of a fluid
Definition n_fluids.h:69
structure passed to a threaded fluid process
Definition n_fluids.h:55
Structure of a thread pool.
List structures and definitions.
Thread pool declaration.