CFD Online Logo CFD Online URL
Home > Forums > Software User Forums > SU2

SU2 configuration

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Search this Thread Display Modes
Old   April 20, 2023, 04:00
Default SU2 configuration
New Member
Yuanyang Zou
Join Date: Apr 2023
Posts: 1
Rep Power: 0
Yuanyang ZOU is on a distinguished road
I ran my shape optimization Python program directly, and it seems to have started from the task manager, but there is no output in my terminal regarding the iteration information. I want to know if there is a problem with my configuration file or if my shape optimization Python program is not written correctly.Here is my Python program.
import os, sys, shutil, copy
from optparse import OptionParser
import SU2
import numpy as np

# -------------------------------------------------------------------
#  Main 
# -------------------------------------------------------------------

def main():

    parser.add_option("-f", "--file", dest="filename",
                      help="read config from FILE", metavar="FILE")
    parser.add_option("-r", "--name", dest="projectname", default='',
                      help="try to restart from project file NAME", metavar="NAME")
    parser.add_option("-n", "--partitions", dest="partitions", default=1,
                      help="number of PARTITIONS", metavar="PARTITIONS")
    parser.add_option("-g", "--gradient", dest="gradient", default="CONTINUOUS_ADJOINT",
                      help="Method for computing the GRADIENT (CONTINUOUS_ADJOINT, DISCRETE_ADJOINT, FINDIFF, NONE)", metavar="GRADIENT")
    parser.add_option("-o", "--optimization", dest="optimization", default="SLSQP",
                      help="OPTIMIZATION techique (SLSQP, CG, BFGS, POWELL)", metavar="OPTIMIZATION")
    parser.add_option("-q", "--quiet", dest="quiet", default="False",
                      help="True/False Quiet all SU2 output (optimizer output only)", metavar="QUIET")
    parser.add_option("-c", "--n_configs", dest="num_configs", default=1,
                      help="Number of config files (for weights NN FIML case)", metavar="NUM_CONFIGS")
    parser.add_option("-b", "--baseline_nn", dest="weights_file", default=None,
                      help="Baseline Weights File for Neural Network (If none defaults to random init)", metavar="BASE_NETWORK")
    (options, args)=parser.parse_args()
    # process inputs
    options.partitions  = int( options.partitions )
    options.quiet       = options.quiet.upper() == 'FALSE'
    options.gradient    = options.gradient.upper()
    sys.stdout.write('|    ___ _   _ ___                                                      |\n')
    sys.stdout.write('|   / __| | | |_  )   Release 5.0.0 \"Raven\"                             |\n')
    sys.stdout.write('|   \\__ \\ |_| |/ /                                                      |\n')
    sys.stdout.write('|   |___/\\___//___|   Aerodynamic Shape Optimization Script             |\n')
    sys.stdout.write('|                                                                       |\n')
    sys.stdout.write('| SU2 Lead Dev.: Dr. Francisco Palacios,|\n')
    sys.stdout.write('|                Dr. Thomas D. Economon,          |\n')
    sys.stdout.write('| SU2 Developers:                                                       |\n')
    sys.stdout.write('| - Prof. Juan J. Alonso\'s group at Stanford University.                |\n')
    sys.stdout.write('| - Prof. Piero Colonna\'s group at Delft University of Technology.      |\n')
    sys.stdout.write('| - Prof. Nicolas R. Gauger\'s group at Kaiserslautern U. of Technology. |\n')
    sys.stdout.write('| - Prof. Alberto Guardone\'s group at Polytechnic University of Milan.  |\n')
    sys.stdout.write('| - Prof. Rafael Palacios\' group at Imperial College London.            |\n')
    sys.stdout.write('| Copyright (C) 2012-2017 SU2, the open-source CFD code.                |\n')
    sys.stdout.write('|                                                                       |\n')
    sys.stdout.write('| SU2 is free software; you can redistribute it and/or                  |\n')
    sys.stdout.write('| modify it under the terms of the GNU Lesser General Public            |\n')
    sys.stdout.write('| License as published by the Free Software Foundation; either          |\n')
    sys.stdout.write('| version 2.1 of the License, or (at your option) any later version.    |\n')
    sys.stdout.write('|                                                                       |\n')
    sys.stdout.write('| SU2 is distributed in the hope that it will be useful,                |\n')
    sys.stdout.write('| but WITHOUT ANY WARRANTY; without even the implied warranty of        |\n')
    sys.stdout.write('| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |\n')
    sys.stdout.write('| Lesser General Public License for more details.                       |\n')
    sys.stdout.write('|                                                                       |\n')
    sys.stdout.write('| You should have received a copy of the GNU Lesser General Public      |\n')
    sys.stdout.write('| License along with SU2. If not, see <>.   |\n')

    shape_optimization( options.filename     ,
                        options.projectname  ,
                        options.partitions   ,
                        options.gradient     ,
                        options.optimization ,
                        options.quiet        ,
                        options.num_configs  ,
#: main()

def shape_optimization( filename                           ,
                        projectname = ''                   ,
                        partitions  = 0                    ,
                        gradient    = 'CONTINUOUS_ADJOINT' ,
                        optimization = 'SLSQP'             ,
                        quiet       = False                ,
                        num_configs = 1                    ,
                        weights_file = None):
    # Config
    config =
    #if num_configs > 1 :
#	config_vec = config #Use first configuration as default for rest of script JRH 09272018
#	for i in range(2,num_configs) :
#	    config_vec.append('.cfg'))
#	    config_vec[i].NUMBER_PART = partitions
#	    config_vec[i].GRADIENT_METHOD = 'gradient'
#	    if quiet: config_vec[i].CONSOLE = 'CONCISE'
    config.NUMBER_PART = partitions
    if quiet: config.CONSOLE = 'CONCISE'
    config.GRADIENT_METHOD = gradient
    its         = int ( config.OPT_ITERATIONS )
    accu        = float ( config.OPT_ACCURACY )
    bound_upper = float ( config.OPT_BOUND_UPPER )
    bound_lower = float ( config.OPT_BOUND_LOWER )
    def_dv      = config.DEFINITION_DV
    kind_dv     = config.DV_KIND
    if config.NPOIN == 0:
        n_dv        = sum(def_dv['SIZE'])
        x0          = [0.0]*n_dv
    else :
        if config.KIND_TRAIN_NN == 'WEIGHTS':
            if weights_file == None : 
                layers = int(config.N_HIDDEN_LAYERS)+2
                num_nodes = [5] #5 if using bias nodes
                for iLayer in range(1,layers-1) :
                num_nodes.append(1) #2 if using bias nodes
                num_inputs = [5] #5 if using bias nodes
                for iLayer in range(1,layers) :
                n_dv = 0
                x0 = []
                for iLayer in range(1,layers) :
                    for iNode in range(num_nodes[iLayer]) :
                        for iInput in range(num_inputs[iLayer-1]) :
                            if iLayer > 0 :  #JRH 09232018 - Removing input layer weights from costly computation
                sys.stdout.write('Total Number of Weights Set to ' + str(n_dv) + ' in\n')
            else :
                sys.stdout.write('Reading weights from' + str(weights_file) + '\n')
                weights = open(weights_file)
                x0 = []
                lines = weights.readlines()     #i am reading lines here
                n_dv = 0
                for line in lines:            #taking each line
                    x0.append(float(line))         #converting string to float	
                    n_dv = n_dv+1
                    #sys.stdout.write('n_dv ' + str(x0[n_dv-1]) +'\n')
                sys.stdout.write('Total Number of Weights Set to ' + str(n_dv) + ' in \n')
            if weights_file == None :
                n_dv = int (config.NPOIN)
                x0          = [float(config.DV_VALUE[0])-1.0]*n_dv # initial design
            else :
                sys.stdout.write('Reading betas from' + str(weights_file) + '\n')
                weights = open(weights_file)
                x0 = []
                lines = weights.readlines()     #i am reading lines here
                n_dv = 0
                for line in lines:            #taking each line
                    x0.append(float(line))         #converting string to float	
                    n_dv = n_dv+1
                    #sys.stdout.write('n_dv ' + str(x0[n_dv-1]) +'\n')
                sys.stdout.write('Total Number of Betas Set to ' + str(n_dv) + ' in \n')

    xb_low      = [float(bound_lower)]*n_dv # lower dv bound
    xb_up       = [float(bound_upper)]*n_dv # upper dv bound
    xb          = zip(xb_low,xb_up) # design bounds
    sys.stdout.write('NPOIN = %s\n' % config.NPOIN)
    # State
    state =
    # Project
    if os.path.exists(projectname):
        project =
        project.config = config
    #if num_configs > 1 :
    #project = SU2.opt.Project(config,state, config_vector = config_vec)
    #else :
        project = SU2.opt.Project(config,state)
    # Optimize
    if optimization == 'SLSQP':
    if optimization == 'CG':
    if optimization == 'BFGS':
    if optimization == 'BFGSJ':
    if optimization == 'STEEPJ':
    if optimization == 'POWELL':
    if optimization == 'BFGSG':
    if optimization == 'STEEP':
    if optimization == 'TNC':

    # rename project file
    if projectname:
    return project

#: shape_optimization()

# -------------------------------------------------------------------
#  Run Main Program
# -------------------------------------------------------------------

# this is only accessed if running from command prompt
if __name__ == '__main__':
Yuanyang ZOU is offline   Reply With Quote

Old   May 12, 2023, 02:54
Default Help
New Member
Join Date: May 2023
Posts: 3
Rep Power: 2
zhaoshuchang is on a distinguished road
Hello, I would like to ask you about the Python API of suave and su2, how does suave and su2 integrate?
zhaoshuchang is offline   Reply With Quote


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorials not working abby10 SU2 Installation 1 December 28, 2021 06:35
Introducing SU2 International Developers Society (IDS) fpalacios SU2 News & Announcements 1 June 17, 2019 22:38
Needed SU2 input configuration file for longer run Samirs SU2 Installation 0 July 5, 2018 01:02
RANS cases not converging in SU2 for Delta wing fighter aircraft configuration. kulls SU2 3 June 13, 2016 16:46
earnestly request for a standard configuration file template for very SU2 new version Tommy Chen SU2 1 June 13, 2013 18:07

All times are GMT -4. The time now is 09:58.