|
[Sponsors] |
Define an objective function in gradient evaluation |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 27, 2021, 04:27 |
Define an objective function in gradient evaluation
|
#1 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
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! |
|
April 27, 2021, 13:29 |
|
#2 |
Senior Member
Pedro Gomes
Join Date: Dec 2017
Posts: 466
Rep Power: 14 |
Hi,
See TestCases/disc_adj_euler/arina2k. The function is implemented in CFlowOutput::Set_CpInverseDesign, line 706 of CFlowOutput.cpp |
|
May 6, 2021, 00:38 |
|
#3 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
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' 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) Code:
SU2_CFD test.cfg SU2_CFD_AD test.cfg SU2_DOT test.cfg zhen |
|
May 6, 2021, 00:41 |
|
#4 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
btw, I tried v7.1.0 and v7.1.1, and both give the same error.
|
|
May 6, 2021, 14:19 |
|
#5 |
Senior Member
Pedro Gomes
Join Date: Dec 2017
Posts: 466
Rep Power: 14 |
Have you tried with SU2_DOT_AD?
|
|
May 6, 2021, 22:25 |
|
#6 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
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) |
|
May 7, 2021, 05:22 |
|
#7 |
Senior Member
Pedro Gomes
Join Date: Dec 2017
Posts: 466
Rep Power: 14 |
Hi,
I cannot replicate that problem with the original case arina2KRS and version 7.1.1 of the code. |
|
May 7, 2021, 06:19 |
|
#8 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
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 |
|
May 7, 2021, 17:11 |
|
#9 |
Senior Member
Pedro Gomes
Join Date: Dec 2017
Posts: 466
Rep Power: 14 |
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? |
|
May 8, 2021, 01:08 |
|
#10 |
Member
Zhen ZHANG
Join Date: Jun 2018
Location: Beijing, China
Posts: 56
Rep Power: 8 |
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! |
|
Tags |
objective function |
|
|
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 15:42 |
Laminar Kinetic Energy Model (Walters 2008) | logoswort | Fluent UDF and Scheme Programming | 2 | May 19, 2017 20:41 |
Compile problem | ivanyao | OpenFOAM Running, Solving & CFD | 1 | October 12, 2012 10:31 |
Droplet Evaporation | Christian | Main CFD Forum | 2 | February 27, 2007 07:27 |
Free surface boudary conditions with SOLA-VOF | Fan | Main CFD Forum | 10 | September 9, 2006 13:24 |