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

Help with Discrete adjoint in SU2

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By talbring

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 28, 2016, 21:50
Default Help with Discrete adjoint in SU2
  #1
New Member
 
Anand Pratap Singh
Join Date: Jul 2014
Posts: 1
Rep Power: 0
anandps is on a distinguished road
Hi,
I have some issues trying to use discrete adjoint on SU2. It will be really helpful if you could provide me some pointers.

My problem setup is as follows:

I am using the setup of discadj_naca0012 at AoA = 10 degree with NO change in configuration file (except for changing direct to discrete_adoint).

My design variable (beta) is a field of size = number of grid points, I multiply these to the corresponding SA production in CSourcePieceWise_TurbSA::ComputeResidual.

Therefore dRdbeta = Production and hence dobjective_dbeta = psi_sa*Production (assuming no explicit dependence of objective on beta). I write out the production from CSourcePieceWise_TurbSA::ComputeResidual function.

Using this, I get the following solution:

dCd_finite diff: -0.01165
dCd_adjoint @ beta_{all} = 1 + 1e-2 (perturb all beta) -0.000184900879096
dCd_adjoint @ beta__{all} = 1 - 1e-2 -0.000181856832584
avg dCd_adjoint -0.00018337885584

I am printing sum_i {dobjective_dbeta_i} or total derivative.

Apart from trivial errors, which I have checked multiple times, I could think of following reasons for this discrepancy:

1. Since the error is so large I thought whether I am missing some internal normalization of the production term. I tried bunch of scaling without any luck. Essentially the dimensions of Production should be consistent with psi_sa in restart file. Do you think this can be an issue?

2. The AD part in the function CSourcePieceWise_TurbSA::ComputeResidual is commented out, is it correct? To verify I calculated dCd_dmach for the same case, which are as follows:

dCd_fd: - 0.07515
dCd_adjoint @ .15 + 0.01 -0.098246
dCd_adjoint @ .15 - 0.01 -0.12189
avg dCd_adjoint -0.110068

This at least seem reasonable, however in this case the sensitivity is weakly dependent on turbulence model so its effect might not show up.

I would greatly appreciate if you could provide some pointers on these issues.


The only two changes I made was to read beta field from a file and multiply to the SA production and write out production to a file.

commit history: https://github.com/anandpratap/SU2/c...756a2abf649f4e

Thanks,
anandps is offline   Reply With Quote

Old   July 29, 2016, 04:57
Default
  #2
Super Moderator
 
Tim Albring
Join Date: Sep 2015
Posts: 195
Rep Power: 10
talbring is on a distinguished road
Hi Anand,

Please note that when you want to add new design variables you have to declare them as input inside of the discrete adjoint solver so that you can extract the derivatives later.

The best place is in CDiscAdjSolver::RegisterVariables using the AD::RegisterInput function. For example like this:

Code:
// We only want to do it for the turbulent solver
if (KindDirect_Solver == RUNTIME_TURB_SYS)){
  for (iPoint = 0; iPoint < nPoint; iPoint++){
    Beta = direct_solver->node[iPoint]->GetBeta();
    // Declare it as input of the iteration
    AD::RegisterInput(Beta);
    direct_solver->node[iPoint]->SetBeta(Beta);
  }
}|
Finally you can extract the derivatives in CDiscAdjSolver::ExtractAdjoint_Variables:

Code:
// We only want to do it for the turbulent solver
if (KindDirect_Solver == RUNTIME_TURB_SYS)){
  for (iPoint = 0; iPoint < nPoint; iPoint++){
    Beta_Sens[iPoint] = AD::GetDerivative(direct_solver->node[iPoint]->GetBeta());
  }
}|
Beta_Sens then contains the derivative of the obj function with respect to beta.

If you want to add your own obj. function have a look at CDiscAdjSolver::RegisterObj_Func().

If you have further questions, let me know.

Tim
OSE and Zhen ZHANG like this.
talbring is offline   Reply With Quote

Old   May 9, 2019, 06:56
Default
  #3
New Member
 
Amir Bagheri
Join Date: Feb 2019
Location: Southampton, UK
Posts: 11
Rep Power: 7
Amirkb is on a distinguished road
Hi Anand,


I wonder if you managed to get AD to give you the derivatives for the new design variables?


I am facing a similar problem. I want the gradient of an objective function with respect to the SA closure coefficients. I have modified the code so that the SA coefficients are read from the config file as opposed to them being hardcoded, so I can call them from the CConfig class.


Now I use AD::RegisterInput inside CDiscAdjSolver::RegisterVariables, to register the closure coefficients, then I use SU2_TYPE::GetDerivative inside CDiscAdjSolver::ExtractAdjoint_Variables to get the gradients. However for some reason the gradient for the closure coefficients is always returned as 0.


Have you had something similar with your case? I have a feeling I am missing an intermediary step between registering the variables and getting the gradients.


Any help would be appreciated.


Thanks,
Amir
Amirkb is offline   Reply With Quote

Reply

Tags
adjoint solver


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
wrong SU2 calculation for lift and drag coefficient for NAC4421 mechy SU2 7 January 9, 2017 05:18
The discrete adjoint method uses too large memory. Yminjo SU2 1 April 27, 2016 10:52
hard to convergent with SU2 4.0 for Euler adjoint Xianguu SU2 1 July 14, 2015 17:09
Discrete Adjoint Euler Computation doan.nak SU2 2 June 6, 2014 04:01
best setting for SU2 mechy SU2 3 April 20, 2014 19:13


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