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 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
28#ifndef __N_FLUID_HEADER
29#define __N_FLUID_HEADER
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
40#include "allegro5/allegro.h"
41#include <allegro5/allegro_primitives.h>
42#include "nilorea/n_list.h"
44
45#ifndef _z
47#define _z(__fluid, __component) ((__fluid->__component) > (__fluid->negative_float_tolerance) && (__fluid->__component) < (__fluid->positive_float_tolerance))
48#endif
49
50#ifndef _zd
52#define _zd(__fluid, __value) ((__value) > (__fluid->negative_float_tolerance) && (__value) < (__fluid->positive_float_tolerance))
53#endif
54
56typedef struct N_FLUID_THREAD_PARAMS {
58 void* ptr;
60 size_t x_start;
62 size_t x_end;
64 size_t y_start;
66 size_t y_end;
68
70typedef struct N_FLUID {
72 size_t numX;
74 size_t numY;
76 size_t numZ;
78 size_t numCells;
80 size_t numIters;
82 double density;
84 double dt;
86 double h;
88 double gravity;
97
102
106 double cScale;
107
109 double* u;
111 double* newU;
112
114 double* v;
116 double* newV;
117
119 double* p;
121 double* s;
122
124 double* m;
126 double* newM;
127
136
137} N_FLUID;
138
140int destroy_n_fluid(N_FLUID** fluid);
142N_FLUID* new_n_fluid(double density, double gravity, size_t numIters, double dt, double overRelaxation, size_t sx, size_t sy);
143
145int n_fluid_integrate(N_FLUID* fluid);
149int n_fluid_extrapolate(N_FLUID* fluid);
150
152double n_fluid_sampleField(N_FLUID* fluid, double x, double y, uint32_t field);
154double n_fluid_avgU(const N_FLUID* fluid, size_t i, size_t j);
156double n_fluid_avgV(const N_FLUID* fluid, size_t i, size_t j);
157
159int n_fluid_advectVel(N_FLUID* fluid);
161int n_fluid_advectSmoke(N_FLUID* fluid);
162
164int n_fluid_simulate(N_FLUID* fluid);
167
169int n_fluid_setObstacle(N_FLUID* fluid, double x, double y, double vx, double vy, double r);
172
174ALLEGRO_COLOR n_fluid_getSciColor(const N_FLUID* fluid, double val, double minVal, double maxVal);
176int n_fluid_draw(N_FLUID* fluid);
177
182#ifdef __cplusplus
183}
184#endif
185
186#endif
THREAD_POOL * thread_pool
Definition ex_fluid.c:76
Structure of a generic LIST container.
Definition n_list.h:59
double h
Definition n_fluids.h:86
double * newU
holder for newU arrays
Definition n_fluids.h:111
size_t numY
number of cells in Y
Definition n_fluids.h:74
size_t y_start
y start point
Definition n_fluids.h:64
double fluid_production_percentage
size of the produced fluid
Definition n_fluids.h:104
bool showSmoke
display fluid as a colored cloud instead of black and white, can be combined with showPressure
Definition n_fluids.h:92
size_t numX
number of cells in X
Definition n_fluids.h:72
LIST * advectSmoke_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_advectSmoke
Definition n_fluids.h:135
double overRelaxation
over relaxation
Definition n_fluids.h:90
bool showPressure
display fluids pressures as color variations, can be combined with showSmoke
Definition n_fluids.h:96
void * ptr
pointer to data which will be used in the proc
Definition n_fluids.h:58
double positive_float_tolerance
fluid double positive precision setting
Definition n_fluids.h:101
LIST * solveIncompressibility_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_solveIncompressibility
Definition n_fluids.h:131
size_t x_end
x end point
Definition n_fluids.h:62
bool showPaint
activate a fonky palette, override smoke and pressure display
Definition n_fluids.h:94
double * u
holder for u arrays
Definition n_fluids.h:109
LIST * integrate_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_integrate
Definition n_fluids.h:129
double * newV
holder for newV arrays
Definition n_fluids.h:116
double dt
time between frames
Definition n_fluids.h:84
double * s
holder for s arrays
Definition n_fluids.h:121
double * v
holder for v arrays
Definition n_fluids.h:114
size_t numCells
total number of cells
Definition n_fluids.h:78
size_t numIters
number of fluid processing iterations for each frame
Definition n_fluids.h:80
double density
density of the fluid (not working ?)
Definition n_fluids.h:82
LIST * advectVel_chunk_list
preprocessed list of threaded procs parameters, for n_fluid_advectVel
Definition n_fluids.h:133
double * m
holder for m arrays
Definition n_fluids.h:124
double cScale
scale used to deduce cellX and cellY from screen/window width and height
Definition n_fluids.h:106
double * newM
holder for newM arrays
Definition n_fluids.h:126
size_t numZ
number of cells in Z
Definition n_fluids.h:76
double * p
holder for p arrays
Definition n_fluids.h:119
size_t x_start
x start point
Definition n_fluids.h:60
double gravity
gravity on Y
Definition n_fluids.h:88
size_t y_end
y end point
Definition n_fluids.h:66
double negative_float_tolerance
fluid double negative precision setting
Definition n_fluids.h:99
int n_fluid_draw(N_FLUID *fluid)
draw the fluid simulation
Definition n_fluids.c:843
int n_fluid_simulate_threaded(N_FLUID *fluid, THREAD_POOL *thread_pool)
run one simulation step using thread pool
Definition n_fluids.c:641
int n_fluid_simulate(N_FLUID *fluid)
run one simulation step
Definition n_fluids.c:624
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:375
int n_fluid_extrapolate(N_FLUID *fluid)
extrapolate fluid boundaries
Definition n_fluids.c:353
int n_fluid_advectSmoke(N_FLUID *fluid)
advect smoke density field
Definition n_fluids.c:591
int n_fluid_solveIncompressibility(N_FLUID *fluid)
solve incompressibility constraint
Definition n_fluids.c:315
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:800
double n_fluid_avgU(const N_FLUID *fluid, size_t i, size_t j)
compute average U velocity at cell
Definition n_fluids.c:435
int n_fluid_resetObstacles(N_FLUID *fluid)
reset all obstacles
Definition n_fluids.c:740
int n_fluid_integrate(N_FLUID *fluid)
integrate fluid velocities
Definition n_fluids.c:260
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:713
int destroy_n_fluid(N_FLUID **fluid)
destroy a fluid simulation
Definition n_fluids.c:64
double n_fluid_avgV(const N_FLUID *fluid, size_t i, size_t j)
compute average V velocity at cell
Definition n_fluids.c:453
int n_fluid_advectVel(N_FLUID *fluid)
advect velocity field
Definition n_fluids.c:511
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:96
structure of a fluid
Definition n_fluids.h:70
structure passed to a threaded fluid process
Definition n_fluids.h:56
Structure of a thread pool.
List structures and definitions.
Thread pool declaration.