CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   SU2 (https://www.cfd-online.com/Forums/su2/)
-   -   Help with Discrete adjoint in SU2 (https://www.cfd-online.com/Forums/su2/175385-help-discrete-adjoint-su2.html)

anandps July 28, 2016 21:50

Help with Discrete adjoint in SU2
 
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,

talbring July 29, 2016 04:57

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

Amirkb May 9, 2019 06:56

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


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