diff --git a/Team25/shape.py b/Team25/shape.py index 95d57ec1d191753ee6d10e047da2e76a8c638643..25ca547f3c82b0b34a734d50e70182098c5be463 100644 --- a/Team25/shape.py +++ b/Team25/shape.py @@ -3,8 +3,8 @@ # import numpy as np -import conveks import onelab +import conveks c = onelab.client(__file__) @@ -106,13 +106,6 @@ conveks.mma.initialize(initialPoint, lowerBound, upperBound) # Set some options for MMA conveks.mma.option.setNumber('General.Verbosity', 4) -conveks.mma.option.setNumber('General.SaveHistory', 0) -conveks.mma.option.setNumber('SubProblem.isRobustMoveLimit', 1) -conveks.mma.option.setNumber('SubProblem.isRobustAsymptotes', 1) -conveks.mma.option.setNumber('SubProblem.type', 0) -conveks.mma.option.setNumber('SubProblem.addConvexity', 0) -conveks.mma.option.setNumber('SubProblem.asymptotesRmax', 100.0) -conveks.mma.option.setNumber('SubProblem.asymptotesRmin', 0.001) # Get iteration count (here it will be 1 - could be different in case of restart) it = conveks.mma.getOuterIteration() @@ -121,10 +114,10 @@ change = 1.0 while it <= maxIter and c.getString('shape/Action') != 'stop': c.setNumber('Optimization/01Current iteration', value=it, readOnly=1, - attributes={'Highlight':'LightYellow'}) + attributes={'Highlight':'LightYellow'}) # get (copy of) current point - xFromMMA = np.array(conveks.mma.getCurrentPoint()) + xFromMMA = conveks.mma.getCurrentPoint() # send the current point to GetDP model for label, var in x.iteritems(): @@ -137,30 +130,23 @@ while it <= maxIter and c.getString('shape/Action') != 'stop': # mesh the geometry c.runSubClient('myGmsh', mygmsh + ' -2') - # generate the velocity field of each design variable - getVelocityField(x) - # compute objective function and constraints c.runSubClient('myGetDP', mygetdp + '-solve GetPerformances') + objective = np.sum(readSimpleTable(c.getPath('res_opt/w.txt'))) + constraints = np.array([np.sum(xFromMMA)/np.sum(upperBound)-1.0]) - # as well as their sensitivity with respect to design variables at `x' + # generate the velocity field of each design variable + getVelocityField(x) + + # compute the sensitivity with respect to design variables at `x' for dv, var in x.iteritems(): c.runNonBlockingSubClient('myGetDP', mygetdp \ + ' -setnumber VelocityTag '+str(dv)\ + ' -solve GetGradient_wrt_dv') c.waitOnSubClients() - - # get the value of the objective function and of the constraints - # as well as their sensitivity with respect to design variables at `x' - objective = np.sum(readSimpleTable(c.getPath('res_opt/w.txt'))) - constraints = np.array([np.sum(xFromMMA)/100.0-1.0]) grad_objective = np.asarray([np.sum(readSimpleTable(c.getPath('res_opt/Grad_w_wrt_dv_'+str(dv)+'.txt')))\ for dv in xrange(numVariables)]) - grad_constraints = np.ones(numVariables)/100.0 - - if it == 1: fscale = 1.0 / objective - objective *= fscale - grad_objective *= fscale + grad_constraints = np.ones(numVariables)/np.sum(upperBound) print('*'*50) print('iteration: ', it) @@ -171,7 +157,7 @@ while it <= maxIter and c.getString('shape/Action') != 'stop': c.sendInfo('Optimization: it. {}, obj. {}, constr. {}'.format(it,objective,constraints[0])) # call MMA and update the current point - conveks.mma.setMoveLimits(lowerBound, upperBound, 1.0e-4) + conveks.mma.setMoveLimits(lowerBound, upperBound, 1.0e-3) conveks.mma.updateCurrentPoint(constraints,grad_objective,grad_constraints) change = conveks.mma.getDesignChange() it = conveks.mma.getOuterIteration()