Search code examples
python-2.7openmdao

Declare a constraint for only some angles


I am not sure my question will be clear enough, please tell me anything to change in order to clarify !

I have a Group :

class Point(Group):
    def __init__(self, **d):
        super(Point, self).__init__()
        [...]
        for i in (...) :
            self.add('con%d' % i, 
                ExecComp('c{0} = x[{1}]*x[{1}] + x[{2}]*x[{2}]'.format(i, n, n+1)))
            self.connect('p.x', 'con%d.x' % i)

And a Problem :

class PointSolver(Problem):
    def __init__(self, options, *a, **d):
        super(PointSolver, self).__init__()
        [...]
        for i in (...)    
            self.driver.add_constraint('con{0}.c{0}'.format(i), upper=1.0)

I am seeing my constraints (x[{1}]² + x[{2}]² <= 1) as a circle. From that, if i had polar coordinates (r, theta), I would have (r <= 1). I would like to define a part of circle, like (r <= 1 AND theta in [30°, 90°]) dynamically. For now, I am calculating my r and theta coordinates inside the objective function, and setting the output to 0 when not in the zone [30°, 90°]. This does not seem to work very well with the gradient method (can be stuck in a "0 zone" without coming back). Does anyone see a way to define it inside the group definition ? I haven't seen any examples like this in the doc http://openmdao.readthedocs.io/en/1.7.3/index.html


Solution

  • Yeah, it gets stuck because the objective is zero anywhere outside of [30, 90], so if you end up (or start) in that region, the gradient is zero when measured locally by exploring nearby points. I think a better way to do this would be to allow output from the objective function at all angles, but add a couple of additional constraints on the angle to keep it between 30 and 90 degrees.