PhoenixLecture  2.0.0
Set of tools to make lectures
naive_propagation.cpp File Reference
#include <algorithm>
#include "naive_propagation.h"
+ Include dependency graph for naive_propagation.cpp:

Go to the source code of this file.

Functions

void grayscott_propagation (float *outMatU, float *outMatV, const float *matU, const float *matV, long nbRow, long nbCol, const float *matDeltaSquare, long nbStencilRow, long nbStencilCol, float diffudionRateU, float diffusionRateV, float feedRate, float killRate, float dt)
 Propagate the U and V species in the matU and matV. More...
 

Function Documentation

◆ grayscott_propagation()

void grayscott_propagation ( float *  outMatU,
float *  outMatV,
const float *  matU,
const float *  matV,
long  nbRow,
long  nbCol,
const float *  matDeltaSquare,
long  nbStencilRow,
long  nbStencilCol,
float  diffudionRateU,
float  diffusionRateV,
float  feedRate,
float  killRate,
float  dt 
)

Propagate the U and V species in the matU and matV.

Parameters
[out]outMatU: updated matrix U version
[out]outMatV: updated matrix V version
matU: input of matrix U
matV: input of matrix V
nbRow: number of rows of the matrices
nbCol: number of columns of the matrices
matDeltaSquare: matrix of the delta square values
nbStencilRow: number of rows of the matrix matDeltaSquare
nbStencilCol: number of columns of the matrix matDeltaSquare
diffudionRateU: diffusion rate of the U specie
diffudionRateV: diffusion rate of the V specie
feedRate: rate of the process which feeds U and drains U, V and P
killRate: rate of the process which converts V into P
dt: time interval between two steps

Definition at line 35 of file naive_propagation.cpp.

38 {
39 /*{
40 Nous déterminons les \textbf{offset} de notre \textbf{stencil} (le nombre de couches à partir de la cellule centrale) :
41 }*/
42  long offsetStencilRow((nbStencilRow - 1l)/2l);
43  long offsetStencilCol((nbStencilCol - 1l)/2l);
44 /*{
45 Nous bouclons sur les lignes et les colonnes de nos matrices pour mettre à jour toutes nos cellules :
46 }*/
47  for(long i(0l); i < nbRow; ++i){
48  for(long j(0l); j < nbCol; ++j){
49 /*{
50 Il faut maintenant déterminer les bornes de nos calculs (voir section \ref{secNaiveImplStencil}) :
51 }*/
52  long firstRowStencil(std::max(i - offsetStencilRow, 0l));
53  long firstColStencil(std::max(j - offsetStencilCol, 0l));
54 
55  long lastRowStencil(std::min(i + offsetStencilRow + 1l, nbRow));
56  long lastColStencil(std::min(j + offsetStencilCol + 1l, nbCol));
57 /*{
58 Définissons quelques variables temporaires :
59 }*/
60  long stencilIndexRow(0l);
61  float u(matU[i*nbCol + j]), v(matV[i*nbCol + j]);
62  float fullU(0.0f), fullV(0.0f);
63 /*{
64 Nous devons maintenant boucler sur les lignes et les colonnes de notre \textbf{stencil} :
65 }*/
66  for(long k(firstRowStencil); k < lastRowStencil; ++k){
67  long stencilIndexCol(0l);
68  for(long l(firstColStencil); l < lastColStencil; ++l){
69 /*{
70 Nous pouvons enfin calculer notre gradient :
71 }*/
72  float deltaSquare(matDeltaSquare[stencilIndexRow*nbStencilCol + stencilIndexCol]);
73  fullU += (matU[k*nbCol + l] - u)*deltaSquare;
74  fullV += (matV[k*nbCol + l] - v)*deltaSquare;
75 /*{
76 Il ne faut pas oublier d'incrémenter les indices qui nous permettent de parcourir la matrice \textbf{matDeltaSquare] :
77 }*/
78  ++stencilIndexCol;
79  }
80  ++stencilIndexRow;
81  }
82 /*{
83 On finalise le calcul :
84 }*/
85  float uvSquare(u*v*v);
86  float du(diffudionRateU*fullU - uvSquare + feedRate*(1.0f - u));
87  float dv(diffusionRateV*fullV + uvSquare - (feedRate + killRate)*v);
88 /*{
89 Et on sauvegarde le résultat :
90 }*/
91  outMatU[i*nbCol + j] = u + du*dt;
92  outMatV[i*nbCol + j] = v + dv*dt;
93 /*{
94 Fin des deux boucles sur les lignes et les colonnes :
95 }*/
96  }
97  }
98 /*{
99 Fin de la fonction :
100 }*/
101 }