Revision: 48050
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48050
Author:   genscher
Date:     2012-06-18 18:12:18 +0000 (Mon, 18 Jun 2012)
Log Message:
-----------
- Fix stopping criteria of CG

Modified Paths:
--------------
    branches/smoke2/intern/smoke/intern/FLUID_3D_SOLVERS.cpp

Modified: branches/smoke2/intern/smoke/intern/FLUID_3D_SOLVERS.cpp
===================================================================
--- branches/smoke2/intern/smoke/intern/FLUID_3D_SOLVERS.cpp    2012-06-18 
17:55:38 UTC (rev 48049)
+++ branches/smoke2/intern/smoke/intern/FLUID_3D_SOLVERS.cpp    2012-06-18 
18:12:18 UTC (rev 48050)
@@ -181,10 +181,11 @@
        size_t index;
        float *_q, *_Precond, *_z, *_r, *_p;
 
-       float alpha = 0.0f, beta = 0;
+       float alpha = 0.0f, beta = 0.0f;
 
        float eps  = SOLVER_ACCURACY;
-       float currentR = 0.0;
+       float currentR = 0.0f;
+       float targetR = 0.0f;
 
        int k = 0;
 
@@ -248,8 +249,12 @@
 
                // p = z
                _p[index] = _z[index];
+
+               targetR += b[index] * b[index];
        }
 
+       targetR = targetR * eps * eps;
+
        while (k < _iterations)
        {
                alpha = 0.0f;
@@ -302,11 +307,11 @@
                        // r_k+1 = r_k - alpha A p
                        _r[index] -= alpha * _q[index];
 
-                       currentR = (_r[index] > currentR) ? _r[index] : 
currentR;
+                       currentR += _r[index] * _r[index];
                }
 
                //if (r_k+1 > EPSILON) exit
-               if(currentR < 0.001*eps)
+               if(currentR < targetR)
                        break;
 
                deltaNew = 0.0f;
@@ -330,7 +335,8 @@
 
                k++;
        }
-       cout << k << " iterations converged to " << sqrt(currentR) << endl;
+       // tol_error = sqrt(residualNorm2 / rhsNorm2); FROM Eigen3
+       cout << k << " iterations converged to " << sqrt(currentR / targetR) << 
endl;
 
        if (_Precond) delete[] _Precond;
        if (_r) delete[] _r;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to