by luchak · 16y ago · 0 comments
def __init__(self, mesh):
div_matrix = op_mesh.n_to_nm1_boundary.T * op_mesh.F_matrix
boundary_matrix = op_mesh.F_matrix - op_mesh.FB_matrix
self.C_matrix = sparse.vstack((div_matrix, boundary_matrix))
self.CCT_matrix = self.C_matrix * self.C_matrix.T
def Project(self, velocities):
lam = linalg.cg(-self.CCT_matrix, self.C_matrix * velocities)[0]
return velocities + self.C_matrix.T * lam
It's pretty simple (constrained least squares optimization) and it's missing some stuff (preconditioner), but it runs fast enough (~1 minute/frame for > 1M tetrahedra), and only required minimal testing: it's all built up from operators I was already using elsewhere. Since it's the fourth or fifth projection method I've tried for this code, that makes a big difference. The fact that I'm using Python is almost immaterial: all of the "interesting" code is library calls.Have you seen the FiPy project? It's a full-featured finite volume code in Python, which is very easy to extend (they did struggle with performance in early releases, not sure how the current status is).
I guess that's the area where dynamic or functional languages can be useful, in that they are easier to build generic libraries for, and can give rise to codes with easier extensibility.