Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

naive_propagation.cpp 2.53 KB
Newer Older
1 2 3 4 5 6
/***************************************
	Auteur : Pierre Aubert
	Mail : aubertp7@gmail.com
	Licence : CeCILL-C
****************************************/

7
#include <algorithm>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include "naive_propagation.h"


///Propagate the U and V species in the matU and matV
/**	@param[out] outMatU : updated matrix U version
 * 	@param[out] outMatV : updated matrix V version
 * 	@param matU : input of matrix U
 * 	@param matV : input of matrix V
 * 	@param nbRow : number of rows of the matrices
 * 	@param nbCol : number of columns of the matrices
 * 	@param matDeltaSquare : matrix of the delta square values
 * 	@param nbStencilRow : number of rows of the matrix matDeltaSquare
 * 	@param nbStencilCol : number of columns of the matrix matDeltaSquare
 * 	@param diffudionRateU : diffusion rate of the U specie
 * 	@param diffudionRateV : diffusion rate of the V specie
 * 	@param feedRate : rate of the process which feeds U and drains U, V and P
24
 * 	@param killRate : rate of the process which converts V into P
25
 * 	@param dt : time interval between two steps
26
*/
27 28
void naive_propagation(float * outMatU, float * outMatV, const float * matU, const float * matV, long nbRow, long nbCol,
		       const float * matDeltaSquare, long nbStencilRow, long nbStencilCol,
29
		       float diffudionRateU, float diffusionRateV, float feedRate, float killRate, float dt)
30
{
31 32
	long offsetStencilRow((nbStencilRow - 1l)/2l);
	long offsetStencilCol((nbStencilCol - 1l)/2l);
33
	
34 35 36 37 38 39 40 41 42 43
	for(long i(0l); i < nbRow; ++i){
		for(long j(0l); j < nbCol; ++j){
			float fullU(0.0f), fullV(0.0f);
			
			long firstRowStencil(std::max(i - offsetStencilRow, 0l));
			long firstColStencil(std::max(j - offsetStencilCol, 0l));
			
			long lastRowStencil(std::min(i + offsetStencilRow + 1l, nbStencilRow));
			long lastColStencil(std::min(j + offsetStencilCol + 1l, nbStencilCol));
			
44 45
			long stencilIndexRow(0l), stencilIndexCol(0l);
			float u(matU[i*nbCol + j]), v(matV[i*nbCol + j]);
46 47
			for(long k(firstRowStencil); k < lastRowStencil; ++k){
				for(long l(firstColStencil); l < lastColStencil; ++l){
48 49 50 51 52
// 					float deltaSquare(matDeltaSquare[stencilIndexRow*nbStencilCol + stencilIndexCol]);
					float deltaSquare(1.0f);
					fullU += (matU[k*nbCol + l] - u)*deltaSquare;
					fullV += (matV[k*nbCol + l] - v)*deltaSquare;
					++stencilIndexCol;
53
				}
54
				++stencilIndexRow;
55 56
			}
			float uvSquare(u*v*v);
57 58
			float du(diffudionRateU*fullU*u - uvSquare + feedRate*(1 - u));
			float dv(diffusionRateV*fullV*v + uvSquare - (feedRate + killRate)*v);
59
			
60 61
			outMatU[i*nbCol + j] = u + du*dt;
			outMatV[i*nbCol + j] = v + dv*dt;
62 63
		}
	}
64 65
}