Particle::Particle(){ setInitCondition(ofGetWindowWidth()/2, ofGetWindowHeight()/2, 0, 0); damping = 0.03f; size = ofRandom(1, 3); a = ofRandom(40, 110); r = 255; g = 255; b = 255; }
void solverDFeqn(double alpha, double dt, int dim, int N, int *nx, int L, double **domain, double ***S, double ***T, int type, int solver){ /* solver = 1: SOR | solver = 2: FMA type = 1: BE | type = 2: Crank Nocolson */ double dx = (double)L/nx[1]; /* double C = alpha*dt/pow(dx,2); /* none steady state equation */ double C = alpha/pow(dx,2); /* steady state equation f( u_t+1 ) = rho */ int x, y, z, k; unsigned long i, j, h; unsigned long X = pow(nx[1],dim); /* dimension of the matrix */ double *b = dvector(1, X); double *u = dvector(1, X); double ***ufma = dmatrix3d(1,nx[3]+2,1,nx[1]+2,1,nx[2]+2); setCartesianDomain(dim, nx, L, domain); /* set up cartesian domain */ printf(" Domain created ...\n"); setInitCondition(dim, nx, domain, T); printf(" Initional condition set...\n"); setBoundCondition(nx, T); printf(" Boundary condition set...\n"); /*printmat(Ap, X, dim*2+1, "matAp.csv", "w"); printmat(Afp, X, X, "matAfp.csv", "w");*/ for(i=1; i<=N; i++){ printf(" timestep loop #%ld", i); j = 1; if (type==1){ /* backward Euler */ for(z=2; z<=nx[3]+1; z++) /* prepare coefficient matrix A and RHS b */ for(x=2; x<=nx[1]+1; x++) for(y=2; y<=nx[2]+1; y++, j++){ b[j] = C + S[z][x][y]; /* steady state rho */ ufma[x][y][z] = b[j]; } }else{ /* Crank Nicolson */ for(z=2; z<=nx[3]+1; z++) /* prepare coefficient matrix A and RHS b */ for(x=2; x<=nx[1]+1; x++) for(y=2; y<=nx[2]+1; y++, j++){ /* steady state rho */ b[j] = C - (T[z][x-1][y] + T[z][x+1][y] + T[z][x][y-1] + T[z][x][y+1] + T[z-1][x][y] + T[z+1][x][y] - 6*T[z][x][y])+ S[z][x][y]; ufma[x][y][z] = b[j]; } } /* sloving for diagonal system */ if (solver==1){ /* SOR:=1 */ printf(" solving linear equation with SOR...\n"); printf(" make coefficient matrix...\n"); double **Afp = dmatrix(1, X, 1, X); /* coefficient matrix as diagnols */ makeMatrix(Afp, X, nx[1], C, dim); /* to fill the coefficient matrix Afp to diagnols from the sparce matrix Ap */ /*printvec(b, X, "matb.csv", "w"); printmat(Af, X, X, "matAf.csv", "w");*/ int k; for (k=1; k<=X; k++) /* seed SOR */ u[k] = 0; int bs = linearSolver_SOR(Afp, b, u, X); free_dmatrix(Afp, 1, X, 1, X); if(bs==1){ printf(" SOR failed with 200 iteration...\n"); } j = 1; for(z=2; z<=nx[3]+1; z++) /* T(t+1) */ for(x=2; x<=nx[1]+1; x++) for(y=2; y<=nx[2]+1; y++, j++) T[z][x][y] = u[j]; free_dvector(b, 1, X); free_dvector(u, 1, X); }else{ /* FMA:=2 */ printf(" solving linear equation with FMA...\n"); printf(" dimension = %ld\n", X); mglin(ufma, nx[1], NCYCLE_); j = 1; for(z=2; z<=nx[3]+1; z++) /* T(t+1) */ for(x=2; x<=nx[1]+1; x++) for(y=2; y<=nx[2]+1; y++, j++) T[z][x][y] = ufma[z][x][y]; free_dmatrix3d(ufma,1,nx[3]+2,1,nx[1]+2,1,nx[2]+2); } printf(" linear diag solved...\n"); setBoundCondition(nx, T); printf(" Boundary condition set...\n"); } }