CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > SU2

Define an objective function in gradient evaluation

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 27, 2021, 03:27
Post Define an objective function in gradient evaluation
  #1
Member
 
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 7
Zhen ZHANG is on a distinguished road
Hi all,
I want to define a new objective function in gradient evaluation, which describes the mean square error between a target temperature distribution and the calculated distribution at a wall.
Where is it defined in the code, and are there some similar objective functions I can refer to?
My solver is incompressible RANS with the S-A model.

Thanks!
Zhen ZHANG is offline   Reply With Quote

Old   April 27, 2021, 12:29
Default
  #2
pcg
Senior Member
 
Pedro Gomes
Join Date: Dec 2017
Posts: 465
Rep Power: 13
pcg is on a distinguished road
Hi,
See TestCases/disc_adj_euler/arina2k.
The function is implemented in CFlowOutput::Set_CpInverseDesign, line 706 of CFlowOutput.cpp
pcg is offline   Reply With Quote

Old   May 5, 2021, 23:38
Smile
  #3
Member
 
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 7
Zhen ZHANG is on a distinguished road
Hi, thank you for your reply.
I have read the codes in CFlowOutput.cpp and tried the test case these days. Basically, I understand the codes to calculate the difference between the two distributions, but I get some problems.
1. I cannot run the test case. When using the shape_optimiazation.py, it returns the following:
Code:
-------------------------------------------------------------------------
|    ___ _   _ ___                                                      |
|   / __| | | |_  )   Release 7.1.1 "Blackbird"                         |
|   \__ \ |_| |/ /                                                      |
|   |___/\___//___|   Aerodynamic Shape Optimization Script             |
|                                                                       |
-------------------------------------------------------------------------
| SU2 Project Website: https://su2code.github.io                        |
|                                                                       |
| The SU2 Project is maintained by the SU2 Foundation                   |
| (http://su2foundation.org)                                            |
-------------------------------------------------------------------------
| Copyright 2012-2020, SU2 Contributors (cf. AUTHORS.md)                |
|                                                                       |
| SU2 is free software; you can redistribute it and/or                  |
| modify it under the terms of the GNU Lesser General Public            |
| License as published by the Free Software Foundation; either          |
| version 2.1 of the License, or (at your option) any later version.    |
|                                                                       |
| SU2 is distributed in the hope that it will be useful,                |
| but WITHOUT ANY WARRANTY; without even the implied warranty of        |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
| Lesser General Public License for more details.                       |
|                                                                       |
| You should have received a copy of the GNU Lesser General Public      |
| License along with SU2. If not, see <http://www.gnu.org/licenses/>.   |
-------------------------------------------------------------------------
Found: Arina2Kmesh.su2
Found: TargetCp.dat
New Project: ./
Sequential Least SQuares Programming (SLSQP) parameters:
Number of design variables: 73 ( 73 )
Objective function scaling factor: [0.9]
Maximum number of iterations: 1
Requested accuracy: 9e-08
Initial guess for the independent variable(s): [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
Lower and upper bound for each independent variable: [(-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06), (-5e-06, 5e-06)]

  NIT    FC           OBJFUN            GNORM
Traceback (most recent call last):
  File "/usr/local/bin/shape_optimization.py", line 183, in <module>
    main()
  File "/usr/local/bin/shape_optimization.py", line 98, in main
    options.nzones      )
  File "/usr/local/bin/shape_optimization.py", line 159, in shape_optimization
    SU2.opt.SLSQP(project,x0,xb,its,accu)
  File "/usr/local/bin/SU2/opt/scipy_tools.py", line 133, in scipy_slsqp
    epsilon        = eps            )
  File "/home/zhen17/app/anaconda3/lib/python3.7/site-packages/scipy/optimize/slsqp.py", line 208, in fmin_slsqp
    constraints=cons, **opts)
  File "/home/zhen17/app/anaconda3/lib/python3.7/site-packages/scipy/optimize/slsqp.py", line 399, in _minimize_slsqp
    fx = func(x)
  File "/home/zhen17/app/anaconda3/lib/python3.7/site-packages/scipy/optimize/optimize.py", line 327, in function_wrapper
    return function(*(wrapper_args + args))
  File "/usr/local/bin/SU2/opt/scipy_tools.py", line 383, in obj_f
    obj_list = project.obj_f(x)
  File "/usr/local/bin/SU2/opt/project.py", line 237, in obj_f
    return self._eval(konfig, func,dvs)
  File "/usr/local/bin/SU2/opt/project.py", line 206, in _eval
    vals = design._eval(func,*args)
  File "/usr/local/bin/SU2/eval/design.py", line 147, in _eval
    vals = eval_func(*inputs)
  File "/usr/local/bin/SU2/eval/design.py", line 244, in obj_f
    func += su2func(this_obj,config,state) * sign * scale * global_factor
  File "/usr/local/bin/SU2/eval/functions.py", line 118, in function
    func_out = state['FUNCTIONS'][func_name]
KeyError: 'INVERSE_DESIGN_PRESSURE'
When calculating separately, the SU2_CFD_AD works well, but the SU2_DOT fails and outputs the following:
Code:
-------------------------------------------------------------------------
|    ___ _   _ ___                                                      |
|   / __| | | |_  )   Release 7.1.1 "Blackbird"                         |
|   \__ \ |_| |/ /                                                      |
|   |___/\___//___|   Suite (Gradient Projection Code)                  |
|                                                                       |
-------------------------------------------------------------------------
| SU2 Project Website: https://su2code.github.io                        |
|                                                                       |
| The SU2 Project is maintained by the SU2 Foundation                   |
| (http://su2foundation.org)                                            |
-------------------------------------------------------------------------
| Copyright 2012-2020, SU2 Contributors                                 |
|                                                                       |
| SU2 is free software; you can redistribute it and/or                  |
| modify it under the terms of the GNU Lesser General Public            |
| License as published by the Free Software Foundation; either          |
| version 2.1 of the License, or (at your option) any later version.    |
|                                                                       |
| SU2 is distributed in the hope that it will be useful,                |
| but WITHOUT ANY WARRANTY; without even the implied warranty of        |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
| Lesser General Public License for more details.                       |
|                                                                       |
| You should have received a copy of the GNU Lesser General Public      |
| License along with SU2. If not, see <http://www.gnu.org/licenses/>.   |
-------------------------------------------------------------------------

----------------- Physical Case Definition ( Zone 0 ) -------------------
Input mesh file name: Arina2Kmesh.su2
Input sensitivity file name: solution_adj_invpress.dat.

-------------- Surface deformation parameters ( Zone 0 ) ----------------
Design variables definition (markers <-> value <-> param):
Hicks Henne <-> WALL1 <-> 0.01 <-> ( 0, 0.5 )

---------------- Design problem definition  ( Zone 0 ) ------------------
Inverse design (Cp) objective function.

-------------------- Output Information ( Zone 0 ) ----------------------
Output Volume Sensitivity file name: volume_sens.
Output Surface Sensitivity file name: surface_sens.
Output gradient file name: of_grad.dat.

------------- Config File Boundary Information ( Zone 0 ) ---------------
+-----------------------------------------------------------------------+
|                        Marker Type|                        Marker Name|
+-----------------------------------------------------------------------+
|                         Euler wall|                              WALL1|
+-----------------------------------------------------------------------+
|                     Symmetry plane|                           SYMMETRY|
+-----------------------------------------------------------------------+
|                     Inlet boundary|                             INFLOW|
+-----------------------------------------------------------------------+
|                    Outlet boundary|                            OUTFLOW|
+-----------------------------------------------------------------------+
Two dimensional problem.
1111 grid points.
2000 volume elements.
4 surface markers.
10 boundary elements in index 0 (Marker = INFLOW).
100 boundary elements in index 1 (Marker = WALL1).
10 boundary elements in index 2 (Marker = OUTFLOW).
100 boundary elements in index 3 (Marker = SYMMETRY).
2000 triangles.
Identify vertices.
Storing a mapping from global to local point index.

----------------------- Preprocessing computations ----------------------
Setting local point connectivity.
Checking the numerical grid orientation of the elements.
All volume elements are correctly orientend.
All surface elements are correctly orientend.
Identify edges and vertices.
Setting the bound control volume structure.
Storing a mapping from global to local point index.
Reading volume sensitivities at each node from file.
Reading in sensitivity at iteration 0.

---------------------- Mesh sensitivity computation ---------------------
Computing volumes of the grid elements.
Min. volume: 2.50135e-05, max. volume: 6.286e-05.
Min. distance: 0.00500837, max. distance: 0.125.
[node9:97674] *** Process received signal ***
[node9:97674] Signal: Segmentation fault (11)
[node9:97674] Signal code: Address not mapped (1)
[node9:97674] Failing at address: (nil)
[node9:97674] [ 0] /lib64/libpthread.so.0(+0xf6d0)[0x7f9ef7d886d0]
[node9:97674] [ 1] SU2_DOT[0x69898c]
[node9:97674] [ 2] SU2_DOT[0x7a8edb]
[node9:97674] [ 3] SU2_DOT[0x40d2ca]
[node9:97674] [ 4] /lib64/libc.so.6(__libc_start_main+0xf5)[0x7f9ef79ce445]
[node9:97674] [ 5] SU2_DOT[0x41df37]
[node9:97674] *** End of error message ***
Segmentation fault (core dumped)
2. How to separately call the SU2 components to do an optimization task, because I want to get the d(obj)_d(dv) to see what the code do and to verify the sensitivity calculation. Is the following correct after setting the file "test.cfg"?
Code:
SU2_CFD test.cfg
SU2_CFD_AD test.cfg
SU2_DOT test.cfg
I am new to SU2 and try to solve an inverse problem with new objective functions and design variables. There seem many things to do and thanks for the kind guide!

zhen
Zhen ZHANG is offline   Reply With Quote

Old   May 5, 2021, 23:41
Default
  #4
Member
 
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 7
Zhen ZHANG is on a distinguished road
btw, I tried v7.1.0 and v7.1.1, and both give the same error.
Zhen ZHANG is offline   Reply With Quote

Old   May 6, 2021, 13:19
Default
  #5
pcg
Senior Member
 
Pedro Gomes
Join Date: Dec 2017
Posts: 465
Rep Power: 13
pcg is on a distinguished road
Have you tried with SU2_DOT_AD?
pcg is offline   Reply With Quote

Old   May 6, 2021, 21:25
Default
  #6
Member
 
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 7
Zhen ZHANG is on a distinguished road
Hi,
Yes, the SU2_DOT_AD gives the same error:
Code:
[zhen17@node9 arina2k]$ SU2_DOT_AD arina2KRS.cfg

-------------------------------------------------------------------------
|    ___ _   _ ___                                                      |
|   / __| | | |_  )   Release 7.1.1 "Blackbird"                         |
|   \__ \ |_| |/ /                                                      |
|   |___/\___//___|   Suite (Gradient Projection Code)                  |
|                                                                       |
-------------------------------------------------------------------------
| SU2 Project Website: https://su2code.github.io                        |
|                                                                       |
| The SU2 Project is maintained by the SU2 Foundation                   |
| (http://su2foundation.org)                                            |
-------------------------------------------------------------------------
| Copyright 2012-2020, SU2 Contributors                                 |
|                                                                       |
| SU2 is free software; you can redistribute it and/or                  |
| modify it under the terms of the GNU Lesser General Public            |
| License as published by the Free Software Foundation; either          |
| version 2.1 of the License, or (at your option) any later version.    |
|                                                                       |
| SU2 is distributed in the hope that it will be useful,                |
| but WITHOUT ANY WARRANTY; without even the implied warranty of        |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
| Lesser General Public License for more details.                       |
|                                                                       |
| You should have received a copy of the GNU Lesser General Public      |
| License along with SU2. If not, see <http://www.gnu.org/licenses/>.   |
-------------------------------------------------------------------------

----------------- Physical Case Definition ( Zone 0 ) -------------------
Input mesh file name: Arina2Kmesh.su2
Input sensitivity file name: solution_adj_invpress.dat.

-------------- Surface deformation parameters ( Zone 0 ) ----------------
Design variables definition (markers <-> value <-> param):
Hicks Henne <-> WALL1 <-> 0.01 <-> ( 0, 0.5 )

---------------- Design problem definition  ( Zone 0 ) ------------------
Inverse design (Cp) objective function.

-------------------- Output Information ( Zone 0 ) ----------------------
Output Volume Sensitivity file name: volume_sens.
Output Surface Sensitivity file name: surface_sens.
Output gradient file name: of_grad.dat.

------------- Config File Boundary Information ( Zone 0 ) ---------------
+-----------------------------------------------------------------------+
|                        Marker Type|                        Marker Name|
+-----------------------------------------------------------------------+
|                         Euler wall|                              WALL1|
+-----------------------------------------------------------------------+
|                     Symmetry plane|                           SYMMETRY|
+-----------------------------------------------------------------------+
|                     Inlet boundary|                             INFLOW|
+-----------------------------------------------------------------------+
|                    Outlet boundary|                            OUTFLOW|
+-----------------------------------------------------------------------+
Two dimensional problem.
1111 grid points.
2000 volume elements.
4 surface markers.
10 boundary elements in index 0 (Marker = INFLOW).
100 boundary elements in index 1 (Marker = WALL1).
10 boundary elements in index 2 (Marker = OUTFLOW).
100 boundary elements in index 3 (Marker = SYMMETRY).
2000 triangles.
Identify vertices.
Storing a mapping from global to local point index.

----------------------- Preprocessing computations ----------------------
Setting local point connectivity.
Checking the numerical grid orientation of the elements.
All volume elements are correctly orientend.
All surface elements are correctly orientend.
Identify edges and vertices.
Setting the bound control volume structure.
Storing a mapping from global to local point index.
Reading volume sensitivities at each node from file.
Reading in sensitivity at iteration 0.

---------------------- Mesh sensitivity computation ---------------------
Computing volumes of the grid elements.
Min. volume: 2.50135e-05, max. volume: 6.286e-05.
Min. distance: 0.00500837, max. distance: 0.125.
[node9:116703] *** Process received signal ***
[node9:116703] Signal: Segmentation fault (11)
[node9:116703] Signal code: Address not mapped (1)
[node9:116703] Failing at address: (nil)
[node9:116703] [ 0] /lib64/libpthread.so.0(+0xf6d0)[0x7ff1e12c26d0]
[node9:116703] [ 1] SU2_DOT_AD[0x721c3d]
[node9:116703] [ 2] SU2_DOT_AD[0x8f3486]
[node9:116703] [ 3] SU2_DOT_AD[0x40d42e]
[node9:116703] [ 4] /lib64/libc.so.6(__libc_start_main+0xf5)[0x7ff1e0f08445]
[node9:116703] [ 5] SU2_DOT_AD[0x42ce27]
[node9:116703] *** End of error message ***
Segmentation fault (core dumped)
Zhen ZHANG is offline   Reply With Quote

Old   May 7, 2021, 04:22
Default
  #7
pcg
Senior Member
 
Pedro Gomes
Join Date: Dec 2017
Posts: 465
Rep Power: 13
pcg is on a distinguished road
Hi,
I cannot replicate that problem with the original case arina2KRS and version 7.1.1 of the code.
pcg is offline   Reply With Quote

Old   May 7, 2021, 05:19
Default
  #8
Member
 
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 7
Zhen ZHANG is on a distinguished road
Hi,
could you please tell me how you launch the test case? Do you use shape_optimization.py?
Because the Linux cluster I use has no access to the internet, I manually downloaded some external packages. Do you think their versions could be the cause?

Thanks, zhen
Zhen ZHANG is offline   Reply With Quote

Old   May 7, 2021, 16:11
Default
  #9
pcg
Senior Member
 
Pedro Gomes
Join Date: Dec 2017
Posts: 465
Rep Power: 13
pcg is on a distinguished road
I ran SU2_DOT_AD directly.
It is hard to say, if there was a bad mismatch I do not think the code would even start.
If you are running on a cluster maybe other errors are printed to stderr instead of stdout.
Wild guess, does this file solution_adj_invpress.dat exist in that folder?
pcg is offline   Reply With Quote

Old   May 8, 2021, 00:08
Default
  #10
Member
 
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 7
Zhen ZHANG is on a distinguished road
Hi,
thank you for the reply!
The solution_adj_invpress.dat exists in the folder, and I have updated the external packages and recompiled the code. Unfortunately, the code still fails when the SU2_DOT_AD is called.
I just use the original cfg file with no modification. Is that correct? The cfg file is attached below with txt extension.
Is there any way to find the cause?

BTW, I modified the interface.py in $SU2_RUN/SU2/run to print the commands the shape_optimization.py uses, and I have understood how the python wraper modifies the cfg files and calls the SU2 modules. I think after running this testcase, I can start to define my own objective function and design variables!
Thanks!
Attached Files
File Type: txt Arina2KRS.txt (25.1 KB, 12 views)
Zhen ZHANG is offline   Reply With Quote

Reply

Tags
objective function

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
question regarding LES of pipe flow - pimpleFoam Dan1788 OpenFOAM Running, Solving & CFD 37 December 26, 2017 14:42
Laminar Kinetic Energy Model (Walters 2008) logoswort Fluent UDF and Scheme Programming 2 May 19, 2017 19:41
Compile problem ivanyao OpenFOAM Running, Solving & CFD 1 October 12, 2012 09:31
Droplet Evaporation Christian Main CFD Forum 2 February 27, 2007 06:27
Free surface boudary conditions with SOLA-VOF Fan Main CFD Forum 10 September 9, 2006 12:24


All times are GMT -4. The time now is 21:33.