I want to optimize the vertex positions in a mesh, with a given cost function on the associated triangles. The paper gives a cost function, which evaluates to an real number by using a sum over the triangles in the mesh, which connect the vertices to a valid simplical complex. They suggest to use a L-BFGS solver and i want to use PETSc to for the calculations.

The solver interface for L-BFGS (and some other algorithms) in PETSc gets a vector with the current values and has a pointer to a output vector for the residual values, with the same cardinality.

How do i design the cost function and the residual vector based on the cost function to evaluate the cost of vertex positions based on the resulting triangles?

i filled the f vector like this: $[v_1^x, v_1^y, v_1^z, \dots, v_N^x, v_N^y, v_N^z]$.

What do it put in the vector returned to get a good solution? I tried ...

  • all the same: $\text{cost}(v) \equiv cost \in \mathbb{R}\ \forall v$ (VecSet(r, cost).)
  • $\text{cost}(v_i^x) = \text{cost}(v_i^y) = \text{cost}(v_i^z) = \sum_{t \in T, v_i\in t} \text{cost}(t)\ \forall i=1\dots N$ with $T$ as the set of all triangles and the relation $v \in t$ when $v$ is a vertex of a triangle $t$.

Both do not obtain good solutions. Further i guess the residual may need to differ in x,y,z to get useful gradients for moving the vertices.

  • 2
    $\begingroup$ "The paper gives a cost function, which evaluates to an real number by using a sum over the triangles in the mesh, which are connecting the triangles to a valid simplex complex." What paper? $\endgroup$ Commented Mar 2, 2015 at 21:04
  • 1
    $\begingroup$ What is the cost function you want to use?? $\endgroup$
    – nicoguaro
    Commented Mar 3, 2015 at 0:49
  • $\begingroup$ dl.acm.org/citation.cfm?id=2631978.2602143 section 6.2 $\endgroup$
    – allo
    Commented Mar 3, 2015 at 12:11
  • $\begingroup$ You already wrote the answer: the vector needs to have the residual in it. $\endgroup$ Commented Mar 4, 2015 at 0:16
  • $\begingroup$ I am still not sure, how you would define this residual. I have a cost function and i may split it into cost functions for triangles. The per vertex residual is not directly defined. The cost function optimal solution would be zero. Now the value(s) of the cost function need to be split into residuals for the vertices. $\endgroup$
    – allo
    Commented Mar 4, 2015 at 14:36

1 Answer 1


If I'm not mistaken, the SNES interface in PETSc deals only with nonlinear equations, not optimization problems. So you may be using the wrong software here. Remember that your cost functional yields only a single scalar value, so you don't want to have a vector-valued cost function.

If you want to stay with PETSc, it seems the TAO toolkit may be what you are looking for:


  • $\begingroup$ I thought SNES with the BFGS type solver would be the way to go for PETSc: mcs.anl.gov/petsc/petsc-current/docs/manualpages/SNES/… $\endgroup$
    – allo
    Commented Mar 3, 2015 at 12:08
  • $\begingroup$ If you look at the page for SNESQN, it states "Limited-Memory Quasi-Newton methods for the solution of nonlinear systems." And below: "... for the solution of F(x) = b..." $\endgroup$
    – cfh
    Commented Mar 3, 2015 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.