Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore in discrete adjoint bits #1257

Merged
merged 38 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fbc6e06
Remove commented out Inverse-Design code.
TobiKattmann Apr 7, 2021
bf048dc
Line breaks and mention missing comments in CDiscAdjVariable.
TobiKattmann Apr 7, 2021
f11964c
Minor cleanups in DA driver/iteration/solver.
TobiKattmann Apr 7, 2021
cf9c309
Using static_cast in CDriver for some output.
TobiKattmann Apr 7, 2021
9747887
Remove unused ExtractAdjoint_Geometry and G/Set_OldSolution_Geometry …
TobiKattmann Apr 7, 2021
56fe7d4
Merge remote-tracking branch 'origin/develop' into chore_discrete_adj…
TobiKattmann Apr 7, 2021
0564af1
minor build fix
TobiKattmann Apr 7, 2021
13721c3
Merge remote-tracking branch 'origin/develop' into chore_discrete_adj…
TobiKattmann Apr 7, 2021
3782885
More var declaration removed from function head.
TobiKattmann Apr 7, 2021
592ba61
minor build fix
TobiKattmann Apr 7, 2021
2c925e7
Merge branch 'develop' into chore_discrete_adjoint
TobiKattmann Apr 13, 2021
9d6fa20
Merge branch 'develop' into chore_discrete_adjoint
TobiKattmann Apr 16, 2021
1b59033
Merge remote-tracking branch 'origin/develop' into chore_discrete_adj…
TobiKattmann Apr 19, 2021
0027937
Merge remote-tracking branch 'origin/develop' into chore_discrete_adj…
TobiKattmann Apr 21, 2021
02f6bed
Some Var def changes.
TobiKattmann Apr 27, 2021
49013d4
Merge remote-tracking branch 'origin/develop' into chore_discrete_adj…
TobiKattmann Apr 27, 2021
5809597
Fix build error
TobiKattmann Apr 27, 2021
1e571d6
Little changes to PR #1259 of @cvencro
TobiKattmann Apr 28, 2021
f945eb1
Two remarks to PR #1268 of @bigfooted
TobiKattmann Apr 28, 2021
793101d
Merge remote-tracking branch 'origin/develop' into chore_discrete_adj…
TobiKattmann Apr 28, 2021
e28e7bb
Move COORDs to CommonFVMOutput. Following #1266 by @pcarruscag
TobiKattmann Apr 28, 2021
d662ce0
Fix build. Add Node_Geo to CommonFVMOutput
TobiKattmann Apr 28, 2021
b7bf9da
Revert "Fix build. Add Node_Geo to CommonFVMOutput"
TobiKattmann Apr 28, 2021
11ae1a9
Revert "Move COORDs to CommonFVMOutput. Following #1266 by @pcarruscag"
TobiKattmann Apr 28, 2021
d00346a
Merge remote-tracking branch 'origin/develop' into chore_discrete_adj…
TobiKattmann Apr 29, 2021
7c3ab4c
Clean CMultizoneDriver::Monitor
TobiKattmann Apr 29, 2021
0966845
Clean some more CMultizoneDriver.cpp
TobiKattmann Apr 29, 2021
1a50385
Merge remote-tracking branch 'origin/develop' into chore_discrete_adj…
TobiKattmann May 1, 2021
201b461
Add GetTemperature to heat Solver instead of GetSolution(iPoint,0)
TobiKattmann May 2, 2021
c1d65e7
Some more comments and cleanup in discadjsolver
TobiKattmann May 2, 2021
90624f1
remove superfluous comments from CDiscAdjVar
TobiKattmann May 2, 2021
30ddda9
Merge remote-tracking branch 'origin/develop' into chore_discrete_adj…
TobiKattmann May 4, 2021
14e3c74
Cleaning CDiscAdjHeatIteration a bit
TobiKattmann May 5, 2021
4b552b5
Various smaller cleanups in DiscAdj bits
TobiKattmann May 5, 2021
07c1184
Revert CDiscAdjVar to develop for easy merge with #1260
TobiKattmann May 5, 2021
c181b8e
Removing temporary comments + latest changes + revert CDiscAdjVar.cpp
TobiKattmann May 5, 2021
d9089d3
Adress PR comments: remove static-casts + minor things
TobiKattmann May 6, 2021
67354dc
Merge branch 'develop' into chore_discrete_adjoint
TobiKattmann May 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SU2_CFD/include/drivers/CMultizoneDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ class CMultizoneDriver : public CDriver {
*/
bool Transfer_Data(unsigned short donorZone, unsigned short targetZone);

/*!
* \brief Check if simulation converged and return appropriate boolean.
* \param[in] TimeIter - Current time iteration.
* \return Boolean that indicates to stop the iteration loop.
*/
bool Monitor(unsigned long TimeIter) override;

/*!
Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/include/solvers/CDiscAdjSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CDiscAdjSolver final : public CSolver {

/*!
* \brief Sets the adjoint values of the output of the flow (+turb.) iteration
* before evaluation of the tape.
* before evaluation of the tape.
* \param[in] geometry - The geometrical definition of the problem.
* \param[in] config - The particular config.
*/
Expand Down
58 changes: 44 additions & 14 deletions SU2_CFD/include/variables/CDiscAdjVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
*/
class CDiscAdjVariable final : public CVariable {
private:
MatrixType Sensitivity; /* Vector holding the derivative of target functional with respect to the coordinates at this node*/
MatrixType Solution_Direct; // TK:: Description missing
MatrixType DualTime_Derivative; // TK:: Description missing
MatrixType DualTime_Derivative_n; // TK:: Description missing
MatrixType Sensitivity; /*!< \brief Vector holding the derivative of target functional with respect to the coordinates at this node*/
MatrixType Solution_Direct; /*!< \brief TK:: ?? Stores the primal solution of the current timestep in order to be able to reset. */
MatrixType DualTime_Derivative; /*!< \brief Container holding all dual time contributions to the adjoint variable. */
MatrixType DualTime_Derivative_n; /*!< \brief Container holding dual time contributions to the adjoint variable used in the next timestep. */

MatrixType Solution_Geometry; // TK:: Description missing
MatrixType Solution_Geometry_Old; // TK:: Description missing
MatrixType Geometry_Direct; // TK:: Description missing
MatrixType Solution_Geometry; /*!< \brief TK:: Description missing. */
MatrixType Solution_Geometry_Old; /*!< \brief TK:: Description missing. */
MatrixType Geometry_Direct; /*!< \brief TK:: Description missing. */

MatrixType Solution_Geometry_BGS_k; // TK:: Description missing
MatrixType Solution_Geometry_BGS_k; /*!< \brief TK:: Description missing. */

public:
/*!
Expand All @@ -66,6 +66,7 @@ class CDiscAdjVariable final : public CVariable {

/*!
* \brief Set the sensitivity at the node
* \param[in] iPoint - Point index
* \param[in] iDim - spacial component
* \param[in] val - value of the Sensitivity
*/
Expand All @@ -75,40 +76,69 @@ class CDiscAdjVariable final : public CVariable {

/*!
* \brief Get the Sensitivity at the node
* \param[in] iPoint - Point index
* \param[in] iDim - spacial component
* \return value of the Sensitivity
*/
inline su2double GetSensitivity(unsigned long iPoint, unsigned long iDim) const override {
return Sensitivity(iPoint,iDim);
}

// TK:: Description missing
/*!
* \brief Set/store the dual time contributions to the adjoint variable. Contains contributions from 2 timesteps for dual time 2nd order.
* \param[in] iPoint - Point index
* \param[in] iVar - Index of the variable
* \param[in] der - Derivative value
*/
inline void SetDual_Time_Derivative(unsigned long iPoint, unsigned long iVar, su2double der) override {
DualTime_Derivative(iPoint,iVar) = der;
}

// TK:: Description missing
/*!
* \brief Set/store the dual time contributions to the adjoint variable for upcoming timestep.
* \param[in] iPoint - Point index
* \param[in] iVar - Index of the variable
* \param[in] der - Derivative value
*/
inline void SetDual_Time_Derivative_n(unsigned long iPoint, unsigned long iVar, su2double der) override {
DualTime_Derivative_n(iPoint,iVar) = der;
}

// TK:: Description missing
/*!
* \brief Return the dual time contributions to the adjoint variable. Contains contributions from 2 timesteps for dual time 2nd order.
* \param[in] iPoint - Point index
* \param[in] iVar - Index of the variable
* \return Derivative value
pcarruscag marked this conversation as resolved.
Show resolved Hide resolved
*/
inline su2double GetDual_Time_Derivative(unsigned long iPoint, unsigned long iVar) const override {
return DualTime_Derivative(iPoint,iVar);
}

// TK:: Description missing
/*!
* \brief Return the dual time contributions to the adjoint variable for upcoming timestep.
* \param[in] iPoint - Point index
* \param[in] iVar - Index of the variable
* \return Derivative value
*/
inline su2double GetDual_Time_Derivative_n(unsigned long iPoint, unsigned long iVar) const override {
return DualTime_Derivative_n(iPoint,iVar);
}

// TK:: Description missing
/*!
* \brief Set/store the primal solution for all variables of one point.
* \param[in] iPoint - Point index
* \param[in] *val_solution_direct - pointer to all variables of iPoint
*/
inline void SetSolution_Direct(unsigned long iPoint, const su2double *val_solution_direct) override {
for (unsigned long iVar = 0; iVar < nVar; iVar++)
Solution_Direct(iPoint,iVar) = val_solution_direct[iVar];
}

// TK:: Description missing
/*!
* \brief Returns the primal solution for all variables of one point.
* \param[in] iPoint - Point index
* \return Pointer to all variables of iPoint
*/
inline su2double* GetSolution_Direct(unsigned long iPoint) override { return Solution_Direct[iPoint]; }

/*!
Expand Down
6 changes: 6 additions & 0 deletions SU2_CFD/include/variables/CHeatVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ class CHeatVariable final : public CVariable {
inline CVectorOfMatrix& GetGradient_Reconstruction() final { return Gradient_Reconstruction; }
inline const CVectorOfMatrix& GetGradient_Reconstruction() const final { return Gradient_Reconstruction; }

/*!
* \brief Get the temperature of the point.
* \return Value of the temperature of the point.
*/
inline su2double GetTemperature(unsigned long iPoint) const final { return Solution(iPoint,0); }

};
4 changes: 2 additions & 2 deletions SU2_CFD/include/variables/CVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2260,7 +2260,7 @@ class CVariable {
}

/*!
* \brief Set the adjoint values of the solution at time n.
* \brief Set the adjoint values of the solution at time n. TK:: unused func
* \param[in] adj_sol - The adjoint values of the solution.
*/
inline void SetAdjointSolution_time_n(unsigned long iPoint, const su2double *adj_sol) {
Expand All @@ -2278,7 +2278,7 @@ class CVariable {
}

/*!
* \brief Set the adjoint values of the solution at time n-1.
* \brief Set the adjoint values of the solution at time n-1. TK:: unused func
* \param[in] adj_sol - The adjoint values of the solution.
*/
inline void SetAdjointSolution_time_n1(unsigned long iPoint, const su2double *adj_sol) {
Expand Down
23 changes: 12 additions & 11 deletions SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void CDiscAdjMultizoneDriver::StartSolver() {

cout << "\nSimulation Run using the Discrete Adjoint Multizone Driver" << endl;

if (driver_config->GetTime_Domain())
if (driver_config->GetTime_Domain()) // TobiKattmann:: Remove the error and introduce time iteration
SU2_MPI::Error("The discrete adjoint multizone driver is not ready for unsteady computations yet.",
CURRENT_FUNCTION);
}
Expand Down Expand Up @@ -173,7 +173,7 @@ bool CDiscAdjMultizoneDriver::Iterate(unsigned short iZone, unsigned long iInner
ComputeAdjoints(iZone, eval_transfer);

/*--- Extracting adjoints for solvers in iZone w.r.t. to outputs in iZone (diagonal part). ---*/

// TobiKattmann:: Make sure to extract correct sensitivities here
iteration_container[iZone][INST_0]->Iterate(output_container[iZone], integration_container, geometry_container,
solver_container, numerics_container, config_container,
surface_movement, grid_movement, FFDBox, iZone, INST_0);
Expand Down Expand Up @@ -288,13 +288,13 @@ void CDiscAdjMultizoneDriver::Run() {
* if the current recording is different from them.
*
* To set the tape appropriately, the following recording methods are provided:
* (1) NONE: All information from a previous recording is removed.
* (1) CLEAR_INDICES: All information from a previous recording is removed.
* (2) SOLUTION_VARIABLES: State variables of all solvers in a zone as input.
* (3) MESH_COORDS / MESH_DEFORM: Mesh coordinates as input.
* (4) SOLUTION_AND_MESH: Mesh coordinates and state variables as input.
*
* By default, all (state and mesh coordinate variables) will be declared as output,
* since it does not change the computational effort. ---*/
* since it does not change the computational effort, just the memory consumption of the tape. ---*/


/*--- If we want to set up zone-specific tapes (retape), we do not need to record
Expand Down Expand Up @@ -421,6 +421,8 @@ void CDiscAdjMultizoneDriver::Run() {
}
}

// TobiKattmann:: Add dual time terms dG/du from n+1 and N+2 to external
pcarruscag marked this conversation as resolved.
Show resolved Hide resolved

/*--- Compute residual from Solution and Solution_BGS_k and update the latter. ---*/

SetResidual_BGS(iZone);
Expand Down Expand Up @@ -828,18 +830,17 @@ void CDiscAdjMultizoneDriver::SetObjFunction(RECORDING kind_recording) {

void CDiscAdjMultizoneDriver::SetAdj_ObjFunction() {

bool time_stepping = config_container[ZONE_0]->GetTime_Marching() != TIME_MARCHING::STEADY;
unsigned long IterAvg_Obj = config_container[ZONE_0]->GetIter_Avg_Objective();
const auto IterAvg_Obj = config_container[ZONE_0]->GetIter_Avg_Objective();
su2double seeding = 1.0;

if (time_stepping){
if (config_container[ZONE_0]->GetTime_Marching() != TIME_MARCHING::STEADY){
if (TimeIter < IterAvg_Obj){
// Default behavior (in case no specific window is chosen) is to use Square-Windowing, i.e. the numerator equals 1.0
auto windowEvaluator = CWindowingTools();
su2double weight = windowEvaluator.GetWndWeight(config_container[ZONE_0]->GetKindWindow(), TimeIter, IterAvg_Obj-1);
seeding = weight / IterAvg_Obj;
}
else{
else {
seeding = 0.0;
}
}
Expand All @@ -850,8 +851,8 @@ void CDiscAdjMultizoneDriver::SetAdj_ObjFunction() {

void CDiscAdjMultizoneDriver::ComputeAdjoints(unsigned short iZone, bool eval_transfer) {

unsigned short enter_izone = iZone*2+1 + ITERATION_READY;
unsigned short leave_izone = iZone*2 + ITERATION_READY;
const unsigned short enter_izone = iZone*2+1 + ITERATION_READY;
const unsigned short leave_izone = iZone*2 + ITERATION_READY;

AD::ClearAdjoints();

Expand All @@ -864,7 +865,7 @@ void CDiscAdjMultizoneDriver::ComputeAdjoints(unsigned short iZone, bool eval_tr

AD::ComputeAdjoint(enter_izone, leave_izone);

/*--- Compute adjoints of transfer and mesh deformation routines, only stricktly needed
/*--- Compute adjoints of transfer and mesh deformation routines, only strictly needed
* on the last inner iteration. Structural problems have some minor issue and we
* need to evaluate this section on every iteration. ---*/

Expand Down
Loading