void Fluid::project(float* u, float* v, float* p, float* div) { int i, j, k, currentIndex; float n = fieldDimension+2; float h = 1.0f/fieldDimension; for (j = 1; j <= FLUIDSIZE; j++) { for (i = 1 ;i <= FLUIDSIZE; i++) { currentIndex = IX3D(i,j,1); div[currentIndex] = -0.5*( u[IX3D(i+1,j,1)]- u[IX3D(i-1,j,1)]+ v[IX3D(i,j+1,1)]- v[IX3D(i,j-1,1)] ) / n; p[currentIndex] = 0; } } setBnd ( 0, div ); setBnd ( 0, p ); linSolve( 0, p, div, 1, 4 ); for ( j=1 ; j<=FLUIDSIZE; j++ ) { for ( i=1 ; i<=FLUIDSIZE; i++ ) { u[IX3D(i,j,1)] -= 0.5*(p[IX3D(i+1,j,1)]-p[IX3D(i-1,j,1)])*n; v[IX3D(i,j,1)] -= 0.5*(p[IX3D(i,j+1,1)]-p[IX3D(i,j-1,1)])*n; } } setBnd ( 1, u ); setBnd ( 2, v ); }
//Calcul commitor par résolution syst linéR void commitor_bruteforce(const Matrix<float>& Q, Vector<float>& q) { int n=Q.ncol(); assert(EstCarreN(Q,n)); q.setSize(n); Matrix< float > A = (Q - Matrix<float>::Identity(n)); Matrix< float > B = A.getSubMat(1,n-2,1,n-2); Vector<float> u=A.getCol(n-1); Vector<float> u2(n-2); for(int i=1;i<n-1;i++) u2[i-1]=-1*u[i]; Vector<float> v=linSolve(B,u2); q[0]=0; q[n-1]=1; for(int i=1;i<n-1;i++) q[i]=v[i-1]; }