PhoenixLecture  2.0.0
Set of tools to make lectures
naive_propagation.cpp
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 /*{
8 Nous aurons besoin des fonctions \func{std::min} et \func{std::max} qui sont disponible dans \file{algorithm} :
9 }*/
10 #include <algorithm>
11 /*{
12 Ensuite, nous incluons notre header :
13 }*/
14 #include "naive_propagation.h"
15 
16 /*{
17 Et nous commençons l'implementation de notre fonction :
18 }*/
20 
35 void grayscott_propagation(float * outMatU, float * outMatV, const float * matU, const float * matV, long nbRow, long nbCol,
36  const float * matDeltaSquare, long nbStencilRow, long nbStencilCol,
37  float diffudionRateU, float diffusionRateV, float feedRate, float killRate, float dt)
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 }
102 
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.