Skip to content
Snippets Groups Projects
Commit 8f0c0cdc authored by Erin Kuci's avatar Erin Kuci
Browse files

some cleaning

parent 492f4526
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
# #
import numpy as np import numpy as np
import conveks
import onelab import onelab
import conveks
c = onelab.client(__file__) c = onelab.client(__file__)
...@@ -106,13 +106,6 @@ conveks.mma.initialize(initialPoint, lowerBound, upperBound) ...@@ -106,13 +106,6 @@ conveks.mma.initialize(initialPoint, lowerBound, upperBound)
# Set some options for MMA # Set some options for MMA
conveks.mma.option.setNumber('General.Verbosity', 4) 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) # Get iteration count (here it will be 1 - could be different in case of restart)
it = conveks.mma.getOuterIteration() it = conveks.mma.getOuterIteration()
...@@ -121,10 +114,10 @@ change = 1.0 ...@@ -121,10 +114,10 @@ change = 1.0
while it <= maxIter and c.getString('shape/Action') != 'stop': while it <= maxIter and c.getString('shape/Action') != 'stop':
c.setNumber('Optimization/01Current iteration', value=it, readOnly=1, c.setNumber('Optimization/01Current iteration', value=it, readOnly=1,
attributes={'Highlight':'LightYellow'}) attributes={'Highlight':'LightYellow'})
# get (copy of) current point # get (copy of) current point
xFromMMA = np.array(conveks.mma.getCurrentPoint()) xFromMMA = conveks.mma.getCurrentPoint()
# send the current point to GetDP model # send the current point to GetDP model
for label, var in x.iteritems(): for label, var in x.iteritems():
...@@ -137,30 +130,23 @@ while it <= maxIter and c.getString('shape/Action') != 'stop': ...@@ -137,30 +130,23 @@ while it <= maxIter and c.getString('shape/Action') != 'stop':
# mesh the geometry # mesh the geometry
c.runSubClient('myGmsh', mygmsh + ' -2') c.runSubClient('myGmsh', mygmsh + ' -2')
# generate the velocity field of each design variable
getVelocityField(x)
# compute objective function and constraints # compute objective function and constraints
c.runSubClient('myGetDP', mygetdp + '-solve GetPerformances') 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(): for dv, var in x.iteritems():
c.runNonBlockingSubClient('myGetDP', mygetdp \ c.runNonBlockingSubClient('myGetDP', mygetdp \
+ ' -setnumber VelocityTag '+str(dv)\ + ' -setnumber VelocityTag '+str(dv)\
+ ' -solve GetGradient_wrt_dv') + ' -solve GetGradient_wrt_dv')
c.waitOnSubClients() 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')))\ grad_objective = np.asarray([np.sum(readSimpleTable(c.getPath('res_opt/Grad_w_wrt_dv_'+str(dv)+'.txt')))\
for dv in xrange(numVariables)]) for dv in xrange(numVariables)])
grad_constraints = np.ones(numVariables)/100.0 grad_constraints = np.ones(numVariables)/np.sum(upperBound)
if it == 1: fscale = 1.0 / objective
objective *= fscale
grad_objective *= fscale
print('*'*50) print('*'*50)
print('iteration: ', it) print('iteration: ', it)
...@@ -171,7 +157,7 @@ while it <= maxIter and c.getString('shape/Action') != 'stop': ...@@ -171,7 +157,7 @@ while it <= maxIter and c.getString('shape/Action') != 'stop':
c.sendInfo('Optimization: it. {}, obj. {}, constr. {}'.format(it,objective,constraints[0])) c.sendInfo('Optimization: it. {}, obj. {}, constr. {}'.format(it,objective,constraints[0]))
# call MMA and update the current point # 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) conveks.mma.updateCurrentPoint(constraints,grad_objective,grad_constraints)
change = conveks.mma.getDesignChange() change = conveks.mma.getDesignChange()
it = conveks.mma.getOuterIteration() it = conveks.mma.getOuterIteration()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment