Convert: Msor To Sor ((better))
Here’s an interesting feature you could include in a tool or script that converts MSOR (Modified Successive Over-Relaxation) to SOR (Successive Over-Relaxation):
6. Practical Considerations
- Performance: SOR uses one parameter to tune; MSOR can potentially converge faster if parameters are optimized per equation, but conversion loses this flexibility.
- Implementation: Removing per-equation parameter storage reduces memory and simplifies code.
- Convergence: After conversion, standard SOR convergence theory applies (e.g., for consistently ordered matrices).
Part 5: Common Pitfalls When You Convert MSOR to SOR
Avoid these mistakes during your conversion:
| Pitfall | Why It Happens | Solution | |--------|----------------|----------| | Divergence after conversion | MSOR’s dual parameters may stabilize a near-singular system; SOR with a single ( \omega ) diverges. | Use a smaller ( \omega ) (e.g., 0.9) or switch to SSOR. | | Slower convergence | MSOR exploits problem structure (e.g., anisotropy). SOR ignores that structure. | Convert to SOR with Chebyshev acceleration or use a problem-specific preconditioner. | | Parameter mismatch | The heuristic ( \omega = (\omega_1 + \omega_2)/2 ) is too simplistic for non-symmetric matrices. | Compute the spectral radius numerically for candidate ( \omega ) values. | | Ordering dependency | MSOR often uses red-black ordering; SOR uses natural ordering. The convergence changes. | Reorder your matrix to match SOR’s natural ordering before conversion. | convert msor to sor
Part 6: When NOT to Convert MSOR to SOR
Despite the desire for simplicity, there are scenarios where converting MSOR to SOR is a bad idea:
- Block-diagonal dominance: If your matrix consists of two loosely coupled subsystems, MSOR with ( \omega_1 \gg \omega_2 ) can converge in O(log n) iterations, while SOR will take O(n).
- Anisotropic PDEs: For problems like ( \epsilon u_xx + u_yy = f ) with ( \epsilon \ll 1 ), MSOR (with different omegas for x and y directions) is vastly superior.
- Parallel computing: MSOR’s red-black form is naturally parallelizable. SOR in natural ordering is sequential. If you convert, you lose parallel efficiency.
Complexity
- Building graph: O(n + m) where n = tokens, m = dependency edges.
- Topological sort: O(n + m).
- Overall deterministic tie-breaking adds O(n log n) if using priority queue.
4. Convert MSOR to SOR
To convert to standard SOR:
- Choose a single ( \omega ) (typically the optimal SOR parameter for your matrix).
- Set ( \omega_r = \omega ) and ( \omega_b = \omega ).
- The iteration becomes identical for all equations.
- The ordering (red-black) no longer matters for the parameter choice — you just have SOR with natural ordering or whatever ordering you prefer.
Original MSOR Code
import numpy as np
def msor_solve(A, b, omega1, omega2, tol=1e-6, max_iter=1000): n = len(b) x = np.zeros_like(b) for _ in range(max_iter): x_old = x.copy() # Red points (even indices, for example) for i in range(0, n, 2): sigma = np.dot(A[i, :], x) - A[i, i] * x[i] x[i] = (1 - omega1) * x[i] + (omega1 / A[i, i]) * (b[i] - sigma) # Black points (odd indices) for i in range(1, n, 2): sigma = np.dot(A[i, :], x) - A[i, i] * x[i] x[i] = (1 - omega2) * x[i] + (omega2 / A[i, i]) * (b[i] - sigma) if np.linalg.norm(x - x_old) < tol: break return x
Conversion in action:
A = np.array([[4, -1, 0], [-1, 4, -1], [0, -1, 4]], dtype=float) b = np.array([1, 2, 3])
Leave a Comment