Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_fluids.c File Reference

Fluid management functions , ported from https://www.youtube.com/watch?v=iKAVRgIrUOU&t=522s. More...

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <strings.h>
#include "nilorea/n_fluids.h"
#include "nilorea/n_common.h"
#include "nilorea/n_thread_pool.h"
Include dependency graph for n_fluids.c:

Go to the source code of this file.

Macros

#define N_FLUID_S_FIELD   2
 array number for s
#define N_FLUID_U_FIELD   0
 array number for u
#define N_FLUID_V_FIELD   1
 array number for v

Functions

int destroy_n_fluid (N_FLUID **fluid)
 destroy a fluid structure
int n_fluid_advectSmoke (N_FLUID *fluid)
 non threaded version of add smoke function
void * n_fluid_advectSmoke_proc (void *ptr)
 ready to be threaded add smoke function
int n_fluid_advectVel (N_FLUID *fluid)
 non threaded version of add velocities function
void * n_fluid_advectVel_proc (void *ptr)
 ready to be threaded add velocities function
double n_fluid_avgU (const N_FLUID *fluid, size_t i, size_t j)
 compute the average U value at a fluid position using it's surrounding
double n_fluid_avgV (const N_FLUID *fluid, size_t i, size_t j)
 compute the average V value at a fluid position using it's surrounding
int n_fluid_draw (N_FLUID *fluid)
 draw a N_FLUID on screen / targert bitmap
int n_fluid_extrapolate (N_FLUID *fluid)
 non threaded extrapolation function
ALLEGRO_COLOR n_fluid_getSciColor (const N_FLUID *fluid, double val, double minVal, double maxVal)
 get funky colors for the fluid
int n_fluid_integrate (N_FLUID *fluid)
 non threaded version of integration function
void * n_fluid_integrate_proc (void *ptr)
 ready to be threaded integration function
int n_fluid_resetObstacles (N_FLUID *fluid)
 reset the obstacles set in a N_FLUID
double n_fluid_sampleField (N_FLUID *fluid, double x, double y, uint32_t field)
 compute a sample value at a field position
int n_fluid_setObstacle (N_FLUID *fluid, double x, double y, double vx, double vy, double r)
 set an obstacle in the fluid grid
int n_fluid_setObstacleFromBitmap (N_FLUID *fluid, ALLEGRO_BITMAP *bitmap, double x, double y, double vx, double vy, double r)
 set an obstacle in the fluid grid from a bitmap mask
int n_fluid_simulate (N_FLUID *fluid)
 non threaded version of N_FLUID global processing function
int n_fluid_simulate_threaded (N_FLUID *fluid, THREAD_POOL *thread_pool)
 a threaded version of N_FLUID global processing function
int n_fluid_solveIncompressibility (N_FLUID *fluid)
 non threaded version of incompressibility solving function
void * n_fluid_solveIncompressibility_proc (void *ptr)
 ready to be threaded incompressibility solving function
void n_memset (void *dst, const void *val, size_t size, size_t count)
 memset bytes to a custom value
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

Detailed Description

Fluid management functions , ported from https://www.youtube.com/watch?v=iKAVRgIrUOU&t=522s.

Author
Castagnier Mickael aka Gull Ra Driel
Version
1.0
Date
31/12/2022

Definition in file n_fluids.c.

Macro Definition Documentation

◆ N_FLUID_S_FIELD

#define N_FLUID_S_FIELD   2

array number for s

Definition at line 42 of file n_fluids.c.

Referenced by n_fluid_advectSmoke(), n_fluid_advectSmoke_proc(), and n_fluid_sampleField().

◆ N_FLUID_U_FIELD

#define N_FLUID_U_FIELD   0

array number for u

Definition at line 38 of file n_fluids.c.

Referenced by n_fluid_advectVel(), n_fluid_advectVel_proc(), and n_fluid_sampleField().

◆ N_FLUID_V_FIELD

#define N_FLUID_V_FIELD   1

array number for v

Definition at line 40 of file n_fluids.c.

Referenced by n_fluid_advectVel(), n_fluid_advectVel_proc(), and n_fluid_sampleField().

Function Documentation

◆ n_fluid_advectSmoke_proc()

void * n_fluid_advectSmoke_proc ( void * ptr)

ready to be threaded add smoke function

Parameters
ptra N_FLUID_THREAD_PARAMS ptr
Returns
NULL

Definition at line 564 of file n_fluids.c.

References _z, N_FLUID::dt, N_FLUID::h, N_FLUID_S_FIELD, n_fluid_sampleField(), N_FLUID::newM, N_FLUID::numY, N_FLUID_THREAD_PARAMS::ptr, N_FLUID::u, N_FLUID::v, N_FLUID_THREAD_PARAMS::x_start, and N_FLUID_THREAD_PARAMS::y_start.

Referenced by n_fluid_simulate_threaded().

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

◆ n_fluid_advectVel_proc()

void * n_fluid_advectVel_proc ( void * ptr)

ready to be threaded add velocities function

Parameters
ptra N_FLUID_THREAD_PARAMS ptr
Returns
NULL

Definition at line 468 of file n_fluids.c.

References _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::numY, N_FLUID_THREAD_PARAMS::ptr, N_FLUID::u, N_FLUID::v, N_FLUID_THREAD_PARAMS::x_start, and N_FLUID_THREAD_PARAMS::y_start.

Referenced by n_fluid_simulate_threaded().

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

◆ n_fluid_integrate_proc()

void * n_fluid_integrate_proc ( void * ptr)

ready to be threaded integration function

Parameters
ptra N_FLUID_THREAD_PARAMS ptr
Returns
NULL

Definition at line 241 of file n_fluids.c.

References _z, N_FLUID::dt, N_FLUID::gravity, N_FLUID::numY, N_FLUID_THREAD_PARAMS::ptr, N_FLUID::v, N_FLUID_THREAD_PARAMS::x_start, and N_FLUID_THREAD_PARAMS::y_start.

Referenced by n_fluid_simulate_threaded().

Here is the caller graph for this function:

◆ n_fluid_setObstacleFromBitmap()

int n_fluid_setObstacleFromBitmap ( N_FLUID * fluid,
ALLEGRO_BITMAP * bitmap,
double x,
double y,
double vx,
double vy,
double r )

set an obstacle in the fluid grid from a bitmap mask

Parameters
fluidtargeted N_FLUID
bitmapthe bitmap source mask
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 764 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.

◆ n_fluid_solveIncompressibility_proc()

void * n_fluid_solveIncompressibility_proc ( void * ptr)

ready to be threaded incompressibility solving function

Parameters
ptra N_FLUID_THREAD_PARAMS ptr
Returns
NULL

Definition at line 278 of file n_fluids.c.

References _z, _zd, N_FLUID::density, N_FLUID::dt, N_FLUID::h, N_FLUID::numY, N_FLUID::overRelaxation, N_FLUID::p, N_FLUID_THREAD_PARAMS::ptr, N_FLUID::s, N_FLUID::u, N_FLUID::v, N_FLUID_THREAD_PARAMS::x_start, and N_FLUID_THREAD_PARAMS::y_start.

Referenced by n_fluid_simulate_threaded().

Here is the caller graph for this function:

◆ n_memset()

void n_memset ( void * dst,
const void * val,
size_t size,
size_t count )

memset bytes to a custom value

Parameters
dstdestination pointer
valvalue to write
sizesize of value
counthow many val are we writting

Definition at line 51 of file n_fluids.c.

Referenced by new_n_fluid().

Here is the caller graph for this function: