Definition of Nonlinear Constraint within pyipopt solver

Issue #40 new
max leo correa created an issue

Hello guys! I am completely new with fenics and dolfin-adjoint. I have seen some tutorials and I want to implement problems with general nonlinear constraints, i.e., f (m) >= 0, where f is a general nonlinear function. I have found that the pyipopt solver can deal with this kind of problems and I want to start with the Poisson example with the following nonlinear constraint

f(m) = sin(m) >= 0

However, I cannot find a good example about how to implement this constraint. In the pyipopt tutorial, the constraint is defined as follows

class VolumeConstraint(InequalityConstraint):
        def __init__(self, V):
            self.V  = float(V)
            self.smass  = assemble(TestFunction(A) * Constant(1) * dx)
            self.tmpvec = Function(A)

        def function(self, m):
            reduced_functional_numpy.set_local(self.tmpvec.vector().array(), m)
            integral = self.smass.inner(self.tmpvec.vector())
            return [[self.V - integral]]

        def jacobian(self, m):
            return [[-self.smass]]

        def output_workspace(self):
            return [0.0]

        def length(self):
            return 1

As I can notice, " function(self, m) " compute the constraints f(m), which in the tutorial is only a scalar, and returns a numeric value. If I want to implement the constraint sin(m)>=0, should the output be a scalar or a numpy vector? .

"jacobian(self, m):" computes the jacobian and in this example returns a 'dolfin.cpp.la.Vector' (self.smass). For a general constraint, how can I compute the jacobian function. Does it should be a "vector" or a "matrix"? Is it possible to tell pyipopt to compute an approximation of the jacobian as in Ipopt?

Finally. what does output_workspace does? because when running without this definition, there appears an error. Must the parameter length(self) be the length of the output of " function(self, m) " .

I hope that I don't bother you with my questions but I really want to know how can I use pyipopt solver for my project. Thanks in advance Max .

Comments (0)

  1. Log in to comment