CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   SU2 Shape Design (http://www.cfd-online.com/Forums/su2-shape-design/)
-   -   Problem with restart solution in shape_optimization.py (http://www.cfd-online.com/Forums/su2-shape-design/116992-problem-restart-solution-shape_optimization-py.html)

robyTKD April 30, 2013 05:59

Problem with restart solution in shape_optimization.py
 
1 Attachment(s)
Hello SU2 developers,

I'm trying to perform a NACA0012 subsonic constrained shape optimization. I performed direct and two adjoint (the first with J=DRAG, the second with J=LIFT) simulations. My objective function is DRAG and the constraint is on the LIFT force.

My problem arises when I execute shape_optimization.py with restart solutions, everything seems to be ok, but, when the second adjoint simulation starts (the one on the LIFT), the solver can't reach the solution and residuals go to infinity, although the solution_adj_cl comes from a converged solution. Actually I used the same convergence criteria for all the three simulations (CAUCHY with CAUCHY_EPS=1E-6).

If I instead execute SU2_CFD with MATH_PROBLEM= ADJOINT and the same restart solution, the required convergence is reached.

I attach below the configuration file and the two log files.

Cheers,
Roberto

aniketaranake May 2, 2013 12:48

Dear Roberto,

Could you please provide your mesh as well as your restart files for this case?

Regards,
Aniket

robyTKD May 3, 2013 12:11

Thank you for the reply.

Here the mesh and restart files: https://dl.dropboxusercontent.com/u/...26solution.zip

robyTKD May 7, 2013 03:35

I tried to perform shape optimization without restart, but the tool takes a lot of time in executing SU2_MDC (1000 min); it seems that a first deformation is executed, but the direct simulation doesn't converge. Then another deformation starts, but it doesn't converge. Maybe there is something wrong with the scale factor of objective function, but I don't understand how to set that value. Here is the log file: https://dl.dropboxusercontent.com/u/...logSU2v2.0.txt

I also downloaded and compiled SU2v2.0.3; with the new version of the code, the shape optimization seems to stop after the first adjoint simulation with this error:
Code:

Traceback (most recent call last):
  File "/users/pieri/SU2/trunk/SU2Py/shape_optimization.py", line 121, in <module>
    main()
  File "/users/pieri/SU2/trunk/SU2Py/shape_optimization.py", line 66, in main
    options.step        )
  File "/users/pieri/SU2/trunk/SU2Py/shape_optimization.py", line 104, in shape_optimization
    SU2.opt.SLSQP(project,x0,xb,its)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/scipy_tools.py", line 86, in scipy_slsqp
    epsilon        = 1.0e-06    )
  File "/usr/lib/python2.6/dist-packages/scipy/optimize/slsqp.py", line 299, in fmin_slsqp
    g = append(fprime(x),0.0)
  File "/usr/lib/python2.6/dist-packages/scipy/optimize/optimize.py", line 97, in function_wrapper
    return function(x, *args)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/scipy_tools.py", line 120, in obj_df
    dobj = project.obj_df(x)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/project.py", line 180, in obj_df
    return self._eval(konfig, func,dvs)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/project.py", line 149, in _eval
    vals = design._eval(func,*args)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/design.py", line 119, in _eval
    vals = eval_func(*inputs)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/design.py", line 260, in obj_df
    grad = su2grad(this_obj,grad_method,config,state)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/gradients.py", line 77, in gradient
    grads = adjoint(func_name, config, state)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/gradients.py", line 205, in adjoint
    info = su2run.adjoint(config)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/run/adjoint.py", line 88, in adjoint
    history = su2io.read_history( history_filename )
  File "/users/pieri/SU2/trunk/SU2Py/SU2/io/tools.py", line 115, in read_history
    line_data = [ float(x.strip()) for x in line_data ] 
ValueError: invalid literal for float(): 0.0

I also give you the log file (https://dl.dropboxusercontent.com/u/...gSU2v2.0.3.txt), while the config file is the same as before.

Best regards,
Roberto

aniketaranake May 9, 2013 13:01

Hi Roberto,

The mesh deformation procedure should not take this long. Could you please visualize the deformation by setting the option VISUALIZE_DEFORMATION in your config file to YES?

Regards,
Aniket

rktchip May 10, 2013 03:02

Hi Roberto,

I'm having trouble running your configuration file, and it seems strange that you are able to run this config with 2.0.3.

It looks like the optimization options need to be updated, please see this post - here

also, i'm not able to run su2_ddc without adding a MARKER_EULER= (AIRFOIL). i think this is a bug we need to work out yet.

i'm sure this is unlikely the issue, but just in case, can you please confirm that your path and environment variables point to the new version?

finally, one thing to note in 2.0.3 is to use restarts for an optimization you should set RESTART_SOL=YES in the config file.

lots of things to try out, maybe one will stick?
best,
-trent

robyTKD May 10, 2013 11:55

@aniketaranake:
Quote:

Originally Posted by aniketaranake (Post 426394)
Hi Roberto,

The mesh deformation procedure should not take this long. Could you please visualize the deformation by setting the option VISUALIZE_DEFORMATION in your config file to YES?

I started a new simulation with VISUALIZE_DEFORMATION set to YES, maybe I will not have results until Monday because the simulation is not performed in parallel.

@rktchip:
Quote:

Originally Posted by rktchip (Post 426467)
I'm having trouble running your configuration file, and it seems strange that you are able to run this config with 2.0.3.

It looks like the optimization options need to be updated, please see this post - here

Sorry for my imprecision, the config file is the same as before, but I modified shape optimization options. However here you can find the config file used with version 2.0.3: https://dl.dropboxusercontent.com/u/...0012v2.0.3.cfg

Quote:

Originally Posted by rktchip (Post 426467)
also, i'm not able to run su2_ddc without adding a MARKER_EULER= (AIRFOIL). i think this is a bug we need to work out yet.

I didn't use parallel computation with SU2v2.0 because there are some implementation problems I think (completely different results with serial or parallel computation), while with version 2.0.3 all seems to be ok, up to now...

Quote:

Originally Posted by rktchip (Post 426467)
i'm sure this is unlikely the issue, but just in case, can you please confirm that your path and environment variables point to the new version?

Every time I compile a new version I move all the products in the same directory of the previous version in order to avoid to change the path. I don't think this could be a problem because I can call all executable and python scripts without any problem. However I am checking.

Quote:

Originally Posted by rktchip (Post 426467)
finally, one thing to note in 2.0.3 is to use restarts for an optimization you should set RESTART_SOL=YES in the config file.

Obviously when I ran shape optimization with previous direct&adjoint solutions I set to YES the option RESTART_SOL.

rktchip May 11, 2013 05:25

Hi Roberto,

So it sounds like you've run a couple different scenarios in different versions, but the core problem you're facing is that the adjoint problem for a subsonic pseudo-incompressible turbulent naca0012 is not converging, correct? please keep in mind that the subsonic pseudo-incompressible turbulent problem you're exploring is very much outside of the original intent of that test case, which is very cool! But that might mean some solver development will be needed in this area.

At any rate, would you please test/comment on this troubleshooting tree with 2.0.3? no need to rerun a step you've already done of course. we'll know where to look based on which of these fail.

1. naca 0012 standard test case optimization (euler, transonic)
2. one naca 0012 turbulent evaluation with parallel_computation
3. naca0012 turbulent optimization with small number of external iterations (this is to test the the optimization framework is behaving)
4. your optimization test case.

thanks,
- trent

robyTKD May 11, 2013 06:35

Hi trent,

thank you for the reply. The adjoint solution seems to be ok either with drag or lift objective function. The problem is the shape optimization that, with the 2.0.3 version, stops with the error posted above.

However I am setting the "troubleshooting tree".

1. I have to use the same config file in test cases on my mesh and I run it in serial, is it right?

2. Should this case be transonic or subsonic? I already have some results in subsonic Mach range: https://dl.dropboxusercontent.com/u/...bsonicTurb.zip

3. What do you mean for small number of external iterations? Is it the maximum number of iteration of the optimization?

Best regards,
Roberto

rktchip May 11, 2013 11:03

Hi Roberto,

Great. As you mentioned parallel will be much faster, so I would try to sort out why that isn't working first (which may be another thread in itself). Your config will be the same for steps 2-4, but not for step 1, which you should get from the original naca0012 euler test case. small number of iterations is a trick we use to test that the optimizer is working. you can set EXT_ITER=9 for example. this separates out the solver in some sense. So if you see that it works with small number of iterations, but fails when fully converging the solution, that tells you something. we can explore this when you get your results.

sorry there isn't an easy answer for this one. this troubleshooting is basically what i would be doing, but unfortunately i'm in the middle of writing a paper, so i only have time to guide you through finding the solution.

best,
- trent

robyTKD May 12, 2013 12:45

I am facing some troubles with adjoint euler on my NACA0012 mesh. The file configuration is the same in your test cases.

Concerning about my case, the problem is not related to parallel (actually with the version 2.0.3 it seems to be ok because the test case on cylinder converges, differently from version 2.0), but with shape optimization. The error (also posted above) is:

Code:

Traceback (most recent call last):
  File "/users/pieri/SU2/trunk/SU2Py/shape_optimization.py", line 121, in <module>
    main()
  File "/users/pieri/SU2/trunk/SU2Py/shape_optimization.py", line 66, in main
    options.step        )
  File "/users/pieri/SU2/trunk/SU2Py/shape_optimization.py", line 104, in shape_optimization
    SU2.opt.SLSQP(project,x0,xb,its)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/scipy_tools.py", line 86, in scipy_slsqp
    epsilon        = 1.0e-06    )
  File "/usr/lib/python2.6/dist-packages/scipy/optimize/slsqp.py", line 299, in fmin_slsqp
    g = append(fprime(x),0.0)
  File "/usr/lib/python2.6/dist-packages/scipy/optimize/optimize.py", line 97, in function_wrapper
    return function(x, *args)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/scipy_tools.py", line 120, in obj_df
    dobj = project.obj_df(x)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/project.py", line 180, in obj_df
    return self._eval(konfig, func,dvs)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/project.py", line 149, in _eval
    vals = design._eval(func,*args)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/design.py", line 119, in _eval
    vals = eval_func(*inputs)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/design.py", line 260, in obj_df
    grad = su2grad(this_obj,grad_method,config,state)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/gradients.py", line 77, in gradient
    grads = adjoint(func_name, config, state)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/gradients.py", line 205, in adjoint
    info = su2run.adjoint(config)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/run/adjoint.py", line 88, in adjoint
    history = su2io.read_history( history_filename )
  File "/users/pieri/SU2/trunk/SU2Py/SU2/io/tools.py", line 115, in read_history
    line_data = [ float(x.strip()) for x in line_data ] 
ValueError: invalid literal for float(): 0.0

Since I am a bit in a hurry with my master's thesis, it would be great to solve this problem.
However I am also working to make euler adjoint converge.

Quote:

Originally Posted by rktchip (Post 426467)
sorry there isn't an easy answer for this one. this troubleshooting is basically what i would be doing, but unfortunately i'm in the middle of writing a paper, so i only have time to guide you through finding the solution.

Don't worry, I understand you are very busy in this period.

@Aniket:
shape optimization stops during SU2_MDC, as you requested I set to YES the option VISUALIZE_DEFORMATION. Do you need deformed_surface_grid.vtk and deformed_volumetric_grid.vtk? files are here:
https://dl.dropboxusercontent.com/u/...etric_grid.vtk
https://dl.dropboxusercontent.com/u/...rface_grid.vtk
But the mesh doesn't seem to be deformed.

rktchip May 12, 2013 12:57

do you get this error when you run continuous_adjoint.py?

-trent

robyTKD May 12, 2013 16:58

No, I don't. It runs without any problem.

Roberto

rktchip May 12, 2013 19:17

strange. so let me make sure i'm synced with your status - you've compiled serially correct? with autoconf? and for the naca0012 test case shape optimization fails on the first iteration with restart?

if you're running serially, can you try using a -p 0 (zero) option for shape optimization. it this doesnt work, please zip up the design folder that fails and post it.

thanks dude,
- trent

robyTKD May 13, 2013 09:53

5 Attachment(s)
I'll try to explain my situation more clearly.

Using version 2.0 of the software, direct and adjoint simulations converge. The next step would be shape optimization, but python routine stops during mesh deformation (after 1000 mins it doesn't converge). Remind that I can't use parallel computation because the cylinder test case gives different results if run in parallel or serial, therefore I discarded parallel computation. The restart of the solution with shape optimization is also a problem, actually adjoint simulation starts but it diverges after some tens of iterations (while if I run SU2_CFD from a previous solution it converges without any problem).

Concerning version 2.0.3, parallel seems to work, but problems with restart solution remain. Recently I faced with the error posted above. Today I discovered that it is related to the way SU2_CFD save data in history.csv (or .plt); actually in column 11, related to Res_AdjTurb[0], there is a symbol (as you can see from picture attached below). I solved the problem adding these lines in tools.py after line 114:

Code:

for i,x in enumerate(line_data):
    if i==11:
        line_data[i] = '0.0'

This is a rough solution, but it works. Now SU2_MDC converges (attached below there are pictures of original and deformed - in red - grid), but another error occurs:

Code:

!!! Error: NaNs detected in solution. Now exiting... !!!
Traceback (most recent call last):
  File "/users/pieri/SU2/trunk/SU2Py/shape_optimization.py", line 121, in <module>
    main()
  File "/users/pieri/SU2/trunk/SU2Py/shape_optimization.py", line 66, in main
    options.step        )
  File "/users/pieri/SU2/trunk/SU2Py/shape_optimization.py", line 104, in shape_optimization
    SU2.opt.SLSQP(project,x0,xb,its)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/scipy_tools.py", line 86, in scipy_slsqp
    epsilon        = 1.0e-06    )
  File "/usr/lib/python2.6/dist-packages/scipy/optimize/slsqp.py", line 268, in fmin_slsqp
    fx = func(x)
  File "/usr/lib/python2.6/dist-packages/scipy/optimize/optimize.py", line 97, in function_wrapper
    return function(x, *args)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/scipy_tools.py", line 104, in obj_f
    obj = project.obj_f(x)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/project.py", line 175, in obj_f
    return self._eval(konfig, func,dvs)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/opt/project.py", line 149, in _eval
    vals = design._eval(func,*args)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/design.py", line 119, in _eval
    vals = eval_func(*inputs)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/design.py", line 209, in obj_f
    func = su2func(this_obj,config,state)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/functions.py", line 75, in function
    aero = aerodynamics( config, state )
  File "/users/pieri/SU2/trunk/SU2Py/SU2/eval/functions.py", line 196, in aerodynamics
    info = su2run.direct(config)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/run/direct.py", line 75, in direct
    SU2_CFD(konfig)
  File "/users/pieri/SU2/trunk/SU2Py/SU2/run/interface.py", line 91, in CFD
    run_command( the_Command )
  File "/users/pieri/SU2/trunk/SU2Py/SU2/run/interface.py", line 275, in run_command
    raise Exception , message
Exception: SU2 process returned error '1'

I think the error is related to the mesh deformation, but I am not able to fix it. From the picture below, you can see that the mesh near trailing edge is not so regular as the original one; could this be the problem? Which parameter of grid deformation could I change to fix it?

Concerning the troubleshooting tree, I get the same error in step number 3, for which I set EXT_ITER= 9.

economon May 13, 2013 16:05

Hi Roberto,

It does indeed look like your problem involves the mesh deformation (at least this is the first issue :) ). Before attempting any optimization, can you please try running SU2_MDC with your mesh and the following options:

% Grid deformation technique (SPRING, TORSIONAL_SPRING, ALGEBRAIC)
GRID_DEFORM_METHOD= TORSIONAL_SPRING
%
% Maximum error in the grid deformation
GRID_DEFORM_ERROR= 1E-10

It looks like you are using a structured mesh, and we have found that the torsional spring method works a little better in this situation. Lowering the error tolerance should also help a little too with convergence. Once you have a deformed mesh, please check that the deformation was successful (no inverted cells, should be a smooth deformation near the airfoil) and try to run a simulation with the new mesh to make sure there are no quality issues.

Hope this helps!
Tom

robyTKD May 17, 2013 14:55

3 Attachment(s)
Thank you Tom for the reply.

I followed your advice. Now, with torsional spring method, the deformation is more regular near the profile; surface and mesh have been deformed using SU2_MDC with the following options:

DV_KIND= HICKS_HENNE
DV_PARAM= (1, 0.05)
DV_VALUE_NEW= 0.0001

The deformation is good and there aren't topology errors, direct simulation also converges. Unfortunately, when I simulate the flow around the airfoil deformed following shape sensitivity, calculated by adjoint method, I am not able to reach convergence.

@trent:

About point 1 of troubleshooting:
Direct simulation, as you can see from figures, converges without any problem. However I have problem involving adjoint, actually Residuals diverge. Configuration file is attached below, while the mesh is the same of some post before (post number 425040)

robyTKD May 18, 2013 04:19

@trent
Concernin point 3 - naca0012 turbulent optimization with small number of external iterations (this is to test the the optimization framework is behaving) - this is the history.plt after 12 iterations (DRAG is the function to minimize):

VARIABLES="EVALUATION","LIFT","DRAG","SIDEFORCE"," MOMENT_X","MOMENT_Y","MOMENT_Z","FORCE_X","FORCE_Y ","FORCE_Z","EFFICIENCY","DIRECT","ADJOINT_DRAG"," ADJOINT_LIFT"
1, 1.0829666056, 0.0141155287, 0.0, 0.0, 0.0, 0.0325941642, -0.1741540955, 1.0689650453, 0.0, 76.7216468778, 8.0, 8.0, 8.0
2, 1.0834360561, 0.0145389486, 0.0, 0.0, 0.0, 0.0332726955, -0.1738186274, 1.0695008899, 0.0, 74.5195600929, 8.0, 0.0, 0.0
3, 1.0835383216, 0.0144136617, 0.0, 0.0, 0.0, 0.0334454807, -0.1739597692, 1.0695798459, 0.0, 75.1743968871, 8.0, 0.0, 0.0
4, 1.0835485479, 0.0144011433, 0.0, 0.0, 0.0, 0.0334627603, -0.1739738732, 1.0695877431, 0.0, 75.2404533776, 8.0, 0.0, 0.0
5, 1.0835495706, 0.0143998915, 0.0, 0.0, 0.0, 0.0334644883, -0.1739752835, 1.0695885328, 0.0, 75.2470648046, 8.0, 0.0, 0.0
6, 1.0835496728, 0.0143997663, 0.0, 0.0, 0.0, 0.0334646611, -0.1739754246, 1.0695886118, 0.0, 75.2477260051, 8.0, 0.0, 0.0
7, 1.0835496831, 0.0143997538, 0.0, 0.0, 0.0, 0.0334646783, -0.1739754387, 1.0695886197, 0.0, 75.2477921257, 8.0, 0.0, 0.0
8, 1.0835496841, 0.0143997526, 0.0, 0.0, 0.0, 0.0334646801, -0.1739754401, 1.0695886204, 0.0, 75.2477987377, 8.0, 0.0, 0.0
9, 1.0835496842, 0.0143997525, 0.0, 0.0, 0.0, 0.0334646802, -0.1739754402, 1.0695886205, 0.0, 75.247799399, 8.0, 0.0, 0.0
10, 1.0835496842, 0.0143997524, 0.0, 0.0, 0.0, 0.0334646803, -0.1739754402, 1.0695886205, 0.0, 75.2477994653, 8.0, 0.0, 0.0
11, 1.0835496842, 0.0143997524, 0.0, 0.0, 0.0, 0.0334646803, -0.1739754402, 1.0695886205, 0.0, 75.2477994717, 8.0, 0.0, 0.0
12, 1.0835496842, 0.0143997524, 0.0, 0.0, 0.0, 0.0334646803, -0.1739754402, 1.0695886205, 0.0, 75.2477994724, 8.0, 0.0, 0.0

The number of external iterations is 9 and optimization started from a converged solution.

rktchip May 22, 2013 03:22

Hey Roberto,

Great, it looks like you're making some progress. If you've been able to run the naca0012 euler optimization then we can say the optimization framework is working for you. (this is nice for me to hear because it's still a it new) the adjoint is indeed a tricky thing to simulate for this case, but i believe the new version has been updated to address this. so see if you could try to run an adjoint solution with 2.0.4

- trent

robyTKD May 22, 2013 08:34

Thank you Trent.

Problems concerning shape optimization are related to adjoint solutions, actually I think that shape sensitivities are wrong.

I compiled the new SU2v2.0.4, but MARKER_NS is no more defined in SU2_CFD code. Have you changed the syntax to impose Navier-Stokes wall conditions?

Best regards.


All times are GMT -4. The time now is 19:17.