public float GetCFL() { float maxv2 = Mathf.Max(h * gravity, sqr(u.InfNorm()) + sqr(v.InfNorm())); if (maxv2 < 1e-16) { maxv2 = 1e-16f; } return(h / Mathf.Sqrt(maxv2)); }
public void SolvePressure(int maxits, double tolerance) { int its; double tol = tolerance * r.InfNorm(); pressure.Reset(); if (r.InfNorm() == 0) { return; } ApplyPreconditioner(r, z, m); z.CopyTo(s); float rho = z.Dot(r); if (rho == 0) { return; } for (its = 0; its < maxits; ++its) { ApplyPoisson(s, z); float alpha = rho / s.Dot(z); pressure.Increment(alpha, s); r.Increment(-alpha, z); if (r.InfNorm() <= tol) { Debug.LogFormat("pressure converged to {0} in {1} iterations\n", r.InfNorm(), its); return; } ApplyPreconditioner(r, z, m); float rhonew = z.Dot(r); float beta = rhonew / rho; s.ScaleAndIncrement(beta, z); rho = rhonew; } Debug.LogFormat("Didn't converge in pressure solve (its={0}, tol={1}, |r|={2})\n", its, tol, r.InfNorm()); }