-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Differentiability wrt. to mesh vertex positions #187
Comments
When using the |
I'm trying to adapt the cylinder FVM example to include a simple derivative wrt. mesh vertices, but running into several issues.
File ~/.virtualenvs/science/lib/python3.12/site-packages/phiml/math/_optimize.py:199, in SolveInfo.convergence_check(self, only_warn)
197 warnings.warn(self.msg, ConvergenceWarning)
198 else:
--> 199 raise Diverged(self)
200 if not self.converged.trajectory[-1].all:
201 if NotConverged not in self.solve.suppress:
Diverged: Solve diverged within -1 iterations using scipy.sparse.linalg.spsolve. Any suggestions on how to fix it, or another example that we could use for prototyping that uses an unstructured mesh? |
Hey @dionhaefner Could you update to the develop branch?
That should hopefully fix the errors. |
It fixes the errors at import but not the runtime errors in the cylinder FVM example.
(We'd preferably use JAX so a workaround for that would be most appreciated.) |
To verify that the gradient w.r.t. vertex positions works in principle, you can start with this: mesh = geom.load_gmsh('cylinder.msh', ('y-', 'x+', 'y+', 'x-', 'cyl+', 'cyl-'))
def loss_function(mesh: Mesh):
return math.l2_loss(mesh.center)
d_mesh: Mesh = gradient(loss_function, 'mesh', False)(mesh)
show(PointCloud(mesh.vertices, -.05 * d_mesh.vertices.center)) Yeah, the divergence error looks like a numerics problem. v, p = fluid.make_incompressible(v, (), Solve('scipy-direct', suppress=[Diverged, NotConverged])) Not sure why the solve doesn't converge, it should be easily solveable with a ZERO_GRADIENT boundary condition... |
I'm currently trying to figure out whether phiflow supports differentiability wrt to mesh vertex positions. My initial assessment of the way the mesh is setup and initial failed experiments make me believe this is not supported.
The text was updated successfully, but these errors were encountered: