int main(int argv, char *argc[]) { info I, J; int N; double *u; if (argv > 1) {sscanf(argc[1],"%d", &N);} else {N = 100;} // if (scanf("%d", &N)) {} else {N = 40;} iinit(&I, N); u = advection(I.N, I.M); compare(u, I.N); residual(u, &I); iprint(I); free(u); N *= 2; iinit(&J, N); u = advection(J.N, J.M); compare(u, J.N); residual(u, &J); iprint(J); free(u); printf("Degree of convergence = %lg\n\n", log(I.S/J.S)/log(I.h/J.h)); return 0; }
void FluidSimulator::step_velocity(float *u, float *v, float *u0, float *v0, float viscosity){ add_source(u,u0); add_source(v,v0); swap(u0,u); diffusion(1, u, u0, viscosity); swap(v0,v); diffusion(2, v, v0, viscosity); project(u,v,u0,v0); swap(u0,u); swap(v0,v); advection(1,u,u0,u0,v0); advection(2,v,v0,u0,v0); project(u,v,u0,v0); }
void StableSolver2D::anim_tex() { if(running == 0) return; SWAP(tx0, tx); SWAP(ty0, ty); advection(tx, tx0, vx, vy, 0); advection(ty, ty0, vx, vy, 0); SWAP(tx0, tx); SWAP(ty0, ty); diffusion(tx, tx0, diff, 0); diffusion(ty, ty0, diff, 0); }
void SPHSystem::animation() { buildGrid(); compDensPressure(); compForce(); //compTimeStep(); advection(); }
//Animating Velocity void StableSolver2D::anim_vel() { if(running == 0) return; SWAP(vx0, vx); SWAP(vy0, vy); diffusion(vx, vx0, visc, 1); diffusion(vy, vy0, visc, 2); projection(); SWAP(vx0, vx); SWAP(vy0, vy); advection(vx, vx0, vx0, vy0, 1); advection(vy, vy0, vx0, vy0, 2); projection(); }
//Animating Density void StableSolver2D::anim_den() { if(running == 0) return; SWAP(d0, d); advection(d, d0, vx, vy, 0); SWAP(d0, d); diffusion(d, d0, diff, 0); }
geom::FieldCell<Scal> CalcRadiationField( const Mesh& mesh, const geom::MapFace<std::shared_ptr<solver::ConditionFace>>& mf_cond_radiation_shared, const geom::FieldCell<Scal>& fc_absorption_rate, Vect radiation_direction, geom::FieldCell<Scal> initial_guess) { if (radiation_direction.norm() == 0.) { return initial_guess; } radiation_direction /= radiation_direction.norm(); geom::FieldFace<Scal> ff_flux(mesh); for (auto idxface : mesh.Faces()) { ff_flux[idxface] = radiation_direction.dot(mesh.GetSurface(idxface)); } Scal time_step = 1e16; for (auto idxcell : mesh.Cells()) { for (size_t i = 0; i < mesh.GetNumNeighbourFaces(idxcell); ++i) { auto idxface = mesh.GetNeighbourFace(idxcell, i); Vect vect = mesh.GetCenter(idxcell) - mesh.GetCenter(idxface); Scal vel_dot_vect = std::abs(radiation_direction.dot(vect)); if (vel_dot_vect != 0.) { time_step = std::min(time_step, vect.sqrnorm() / vel_dot_vect); } } } geom::FieldCell<Scal> fc_source(mesh, 0.); solver::AdvectionSolverExplicit<Mesh, geom::FieldFace<Scal>> advection( mesh, initial_guess, mf_cond_radiation_shared, &ff_flux, &fc_source, 0., time_step); Scal error = 1e16; size_t count = 0; for (; count < 10 && error > 1e-3; ++count) { for (auto idxcell : mesh.Cells()) { fc_source[idxcell] = -fc_absorption_rate[idxcell] * advection.GetField()[idxcell]; } advection.StartStep(); advection.MakeIteration(); error = advection.GetConvergenceIndicator(); advection.FinishStep(); } return advection.GetField(); }
void SPHSystem::animation() { if(sys_running == 0) { return; } build_table(); comp_dens_pres(); comp_force_adv(); advection(); }
void SPHSystem::animation() { if(sys_running == 0) { return; } build_table(); if(sys_render == 1) { interp_scalar(); } if(enable_split == 1 && tick == 0 || enable_merge == 1 && tick == 1) { comp_scalar(); find_surface(); comp_dist(); //comp_energy(); } comp_dens_pres(); comp_force_adv(); if(enable_split == 1 && tick == 0) { comp_split(); } if(enable_merge == 1 && tick == 1) { comp_merge(); } advection(); tick=1-tick; }
void FluidSimulator::step_density(float *x, float *x0, float*u, float *v, float diffusion_rate){ add_source(x, x0); swap(x0, x); diffusion(0, x, x0, diffusion_rate); swap(x0, x); advection(0, x, x0, u, v); }