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

Set up custom objective function

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

Like Tree1Likes
  • 1 Post By bigfootedrockmidget

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 4, 2025, 09:22
Default Set up custom objective function
  #1
New Member
 
Qi Wang
Join Date: Oct 2024
Posts: 7
Rep Power: 2
QiWang is on a distinguished road
I'm trying to set up adjoint computation for a objective function that is a single-point pressure. Where exactly should I change the code?

I did see hints on custom objective functions in COutput.cpp

Code:
void COutput::SetCustomAndComboObjectives(int idxSol, const CConfig *config, CSolver **solver) {

  if (config->GetKind_ObjFunc() == CUSTOM_OBJFUNC && !config->GetCustomObjFunc().empty()) {
    if (!customObjFunc.ready) {
      SetupCustomHistoryOutput(config->GetCustomObjFunc(), customObjFunc);
    }
    solver[idxSol]->SetTotal_Custom_ObjFunc(customObjFunc.Eval());
  }
  solver[idxSol]->Evaluate_ObjFunc(config, solver);
  SetHistoryOutputValue("COMBO", solver[idxSol]->GetTotal_ComboObj());
}
But I still don't know how to set it up.


Sorry I searched and found similar questions asked around 2013, before the discrete adjoint capabilities were developed, so I'll simply ask again.
QiWang is offline   Reply With Quote

Old   January 4, 2025, 11:27
Default
  #2
Senior Member
 
bigfoot
Join Date: Dec 2011
Location: Netherlands
Posts: 719
Rep Power: 21
bigfootedrockmidget is on a distinguished road
use CUSTOM_OBJFUNC. I never tried it together with a probe before. Let us know how that works out.





Quote:
%
% User defined expressions of solver variables and other history outputs.
% The syntax to define a custom output is 'name : type{expression}[markers]'.
% NOTE: To obtain the list of available solver variables write an invalid
% expression (e.g. 'x : AreaAvg{INVALID}[]') and run SU2.
% Different outputs need to be separated by ";". The available types are:
% - Macro: Introduces a new field that can only be used in other expressions,
% it is not an output by itself (note the "$" symbol to reference macros).
% - Function: Introduces a new scalar output that is a function of other scalar
% outputs, it cannot reference fields (e.g. velocity).
% - AreaAvg and AreaInt: Computes an area average or integral of a field (the
% expression) over the list of markers.
% - MassFlowAvg and MassFlowInt: Computes a mass flow average or integral.
% - Probe: Evaluates the expression using the values of the mesh point closest
% to the coordinates specified inside "[]", [x, y] or [x, y, z] (2 or 3D).
% NOTE: Each custom output can only use one type, e.g. it is not possible to
% write 'p_drop : AreaAvg{PRESSURE}[inlet] - AreaAvg{PRESSURE}[outlet]'. This
% would need to be separated into two AreaAvg outputs and one Function to
% compute their difference.
CUSTOM_OUTPUTS= 'velocity : Macro{sqrt(pow(VELOCITY_X, 2) + pow(VELOCITY_Y, 2) + pow(VELOCITY_Z, 2))};\
avg_vel : AreaAvg{$velocity}[z_minus, z_plus];\
var_vel : AreaAvg{pow($velocity - avg_vel, 2)}[z_minus, z_plus];\
dev_vel : Function{sqrt(var_vel) / avg_vel};\
probe1 : Probe{$velocity}[0.005, 0.005, 0.05]'
%
% "COMBO" is the name and group of the output for the objective function
% (regardless of definition). "CUSTOM" is the group for all custom outputs.
SCREEN_OUTPUT= INNER_ITER, RMS_DENSITY, RMS_ENERGY, LINSOL_RESIDUAL, FORCE_Z,\
SURFACE_MASSFLOW, SURFACE_TOTAL_TEMPERATURE, avg_vel, dev_vel, probe1, COMBO
HISTORY_OUTPUT = ITER, AERO_COEFF, FLOW_COEFF, FLOW_COEFF_SURF, CUSTOM, COMBO
OBJECTIVE_FUNCTION= CUSTOM_OBJFUNC
% Here we define how the custom objective is computed from other outputs. For
% example, force in the z direction (computed for all MARKER_MONITORING and part
% of AERO_COEFF) plus the absolute value of massflow across the second surface
% ([1]) in MARKER_ANALYZE, scaled by a factor of 1000. It is also possible to
% use "per surface" values from MARKER_MONITORING (use the dry-run mode to see
% the names of available outputs, e.g. SU2_CFD -d lam_flatplate.cfg).
% For multizone problems the CUSTOM_OBJFUNC should be defined for each zone
% individually (with the outputs of that zone), the total for the problem is
% the sum over zones, see disc_adj_fsi/Airfoil_2d.
CUSTOM_OBJFUNC= '1e3 * (FORCE_Z + fabs(SURFACE_MASSFLOW[1])) + dev_vel'
QiWang likes this.
bigfootedrockmidget is offline   Reply With Quote

Reply

Tags
adjoint solver, su2

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
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 13 March 7, 2022 18:22
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 12:04
[blockMesh] Errors during blockMesh meshing Madeleine P. Vincent OpenFOAM Meshing & Mesh Conversion 51 May 30, 2016 11:51
Running UDF with Supercomputer roi247 FLUENT 4 October 15, 2015 14:41
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 13:21


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