/* * stuck * sets out[i] to 0 where i in dat is a stuck value */ int stuck(signed char *out, const double *dat, size_t len, double reso, int num) { int i,j,k; int i_max; num=abs(num); if(num==0) num=10; int *tmp = malloc(sizeof(int) * (num-1)); for(i=0;i<(len - num + 1);i++) { i_max = int_min(i+num, len)-1; if(comp_res(dat[i], dat[i_max], reso)) { for(j=i;j<i_max;j++) { tmp[(i_max)-1-j] = comp_res(dat[j], dat[i_max], reso); } if(all(tmp, num-1)) { for(k=i;k<=i_max;k++) { out[k] = 0; } } } } free(tmp); return 0; }
// Solves the discrete poisson equation using the SOR method std::pair<unsigned, REAL> SOR_Poisson(const Config::geo& geoConfig, const Config::solver solverConfig, const Geometry& geometry, Matrix& P, const Matrix& rhs) { // comupte initial residual REAL res = comp_res(geoConfig, geometry, P, rhs); const REAL omega = solverConfig.omega; const REAL delx2 = geoConfig.delx*geoConfig.delx; const REAL dely2 = geoConfig.dely*geoConfig.dely; const auto& fluid = geometry.get_fluid(); unsigned it = 0, i=0, j=0; for(it = 1; it<solverConfig.itmax && res>solverConfig.eps; ++it) { updatePressureBoundary(geoConfig, geometry, P); // compute next iteration for(const auto& cell : fluid){ i=cell.first; j=cell.second; P.at(i,j) = (1-omega)*P.at(i,j) + omega/(2*(1/delx2 + 1/dely2)) *((P.at(i+1,j)+P.at(i-1,j))/delx2 + (P.at(i,j+1)+P.at(i,j-1))/dely2 - rhs.at(i,j)); } // compute residual res = comp_res(geoConfig, geometry, P, rhs); } return std::make_pair(it, res); }