Skip to content

Commit 3832a8f

Browse files
authored
Merge pull request #1536 from su2code/feature_StreamPer_massflow_PlzWörkDisTime
Fix adjoint for streamwise periodic massflow + General handling of adjoints of additional solution variables
2 parents 1be5ed2 + 4784c30 commit 3832a8f

21 files changed

Lines changed: 531 additions & 73 deletions

Common/include/option_structure.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,8 @@ struct StreamwisePeriodicValues {
22542254
su2double Streamwise_Periodic_MassFlow; /*!< \brief Value of current massflow [kg/s] which results in a delta p and therefore an artificial body force vector. */
22552255
su2double Streamwise_Periodic_IntegratedHeatFlow; /*!< \brief Value of of the net sum of heatflow [W] into the domain. */
22562256
su2double Streamwise_Periodic_InletTemperature; /*!< \brief Area avg static Temp [K] at the periodic inlet. Used for adaptive outlet heatsink. */
2257+
su2double Streamwise_Periodic_BoundaryArea; /*!< \brief Global Surface area of the streamwise periodic interface. */
2258+
su2double Streamwise_Periodic_AvgDensity; /*!< \brief Area avg density on the periodic interface. */
22572259
};
22582260

22592261
/*!

Common/src/CConfig.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4803,8 +4803,6 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
48034803
SU2_MPI::Error("A MARKER_PERIODIC pair has to be set with KIND_STREAMWISE_PERIODIC != NONE.", CURRENT_FUNCTION);
48044804
if (Energy_Equation && Streamwise_Periodic_Temperature && nMarker_Isothermal != 0)
48054805
SU2_MPI::Error("No MARKER_ISOTHERMAL marker allowed with STREAMWISE_PERIODIC_TEMPERATURE= YES, only MARKER_HEATFLUX & MARKER_SYM.", CURRENT_FUNCTION);
4806-
if (DiscreteAdjoint && Kind_Streamwise_Periodic == ENUM_STREAMWISE_PERIODIC::MASSFLOW)
4807-
SU2_MPI::Error("Discrete Adjoint currently not validated for prescribed MASSFLOW.", CURRENT_FUNCTION);
48084806
if (Ref_Inc_NonDim != DIMENSIONAL)
48094807
SU2_MPI::Error("Streamwise Periodicity only works with \"INC_NONDIM= DIMENSIONAL\", the nondimensionalization with source terms doesn;t work in general.", CURRENT_FUNCTION);
48104808
if (Axisymmetric)

SU2_CFD/include/solvers/CIncEulerSolver.hpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
class CIncEulerSolver : public CFVMFlowSolverBase<CIncEulerVariable, ENUM_REGIME::INCOMPRESSIBLE> {
4040
protected:
4141
vector<CFluidModel*> FluidModel; /*!< \brief fluid model used in the solver. */
42-
StreamwisePeriodicValues SPvals;
42+
StreamwisePeriodicValues SPvals, SPvalsUpdated;
4343

4444
/*!
4545
* \brief Preprocessing actions common to the Euler and NS solvers.
@@ -395,8 +395,30 @@ class CIncEulerSolver : public CFVMFlowSolverBase<CIncEulerVariable, ENUM_REGIME
395395
inline bool GetHasHybridParallel() const final { return true; }
396396

397397
/*!
398-
* \brief Get values for streamwise periodic flow: delta P, m_dot, inlet T, integrated heat.
399-
* \return Struct holding 4 su2doubles.
398+
* \brief Get values for streamwise periodic flow: delta P, m_dot, inlet T, integrated heat, etc.
399+
* \return Struct holding streamwise periodic values.
400400
*/
401401
StreamwisePeriodicValues GetStreamwisePeriodicValues() const final { return SPvals; }
402+
403+
/*!
404+
* \brief Register In- or Output.
405+
* \param[in] input - Boolean whether In- or Output should be registered.
406+
* \param[in] config - The particular config.
407+
* \returns The number of extra variables.
408+
*/
409+
unsigned long RegisterSolutionExtra(bool input, const CConfig* config) final;
410+
411+
/*!
412+
* \brief Seed the adjoint of the extra solution at the output.
413+
* \param[in] adj_sol - Vector containing the adjoint solution to seed.
414+
* \param[in] config - The particular config.
415+
*/
416+
void SetAdjoint_SolutionExtra(const su2activevector& adj_sol, const CConfig* config) final;
417+
418+
/*!
419+
* \brief Extract the adjoint of the extra solution at the input.
420+
* \param[out] adj_sol - Vector to store the adjoint into.
421+
* \param[in] config - The particular config.
422+
*/
423+
void ExtractAdjoint_SolutionExtra(su2activevector& adj_sol, const CConfig* config) final;
402424
};

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,6 +3543,28 @@ class CSolver {
35433543
*/
35443544
inline virtual void ExtractAdjoint_Solution(CGeometry *geometry, CConfig *config, bool CrossTerm){}
35453545

3546+
/*!
3547+
* \brief Register In- or Output.
3548+
* \param[in] input - Boolean whether In- or Output should be registered.
3549+
* \param[in] config - The particular config.
3550+
* \returns The number of extra variables.
3551+
*/
3552+
virtual unsigned long RegisterSolutionExtra(bool input, const CConfig* config) { return 0; }
3553+
3554+
/*!
3555+
* \brief Seed the adjoint of the extra solution at the output.
3556+
* \param[in] adj_sol - Vector containing the adjoint solution to seed.
3557+
* \param[in] config - The particular config.
3558+
*/
3559+
virtual void SetAdjoint_SolutionExtra(const su2activevector& adj_sol, const CConfig* config) {}
3560+
3561+
/*!
3562+
* \brief Extract the adjoint of the extra solution at the input.
3563+
* \param[out] adj_sol - Vector to store the adjoint into.
3564+
* \param[in] config - The particular config.
3565+
*/
3566+
virtual void ExtractAdjoint_SolutionExtra(su2activevector& adj_sol, const CConfig* config) {}
3567+
35463568
/*!
35473569
* \brief A virtual member.
35483570
* \param[in] geometry - Geometrical definition of the problem.
@@ -4281,8 +4303,8 @@ class CSolver {
42814303
inline virtual bool GetHasHybridParallel() const { return false; }
42824304

42834305
/*!
4284-
* \brief Get values for streamwise periodc flow: delta P, m_dot, inlet T, integrated heat.
4285-
* \return Struct holding 4 su2doubles.
4306+
* \brief Get values for streamwise periodic flow: delta P, m_dot, inlet T, integrated heat, etc.
4307+
* \return Struct holding streamwise periodic values.
42864308
*/
42874309
virtual StreamwisePeriodicValues GetStreamwisePeriodicValues() const { return StreamwisePeriodicValues(); }
42884310

SU2_CFD/include/variables/CDiscAdjVariable.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ class CDiscAdjVariable : public CVariable {
5454
CDiscAdjVariable(const su2double* sol, unsigned long npoint, unsigned long ndim, unsigned long nvar, CConfig *config);
5555

5656
/*!
57-
* \brief Destructor of the class.
57+
* \brief Allocate extra adjoint variables.
58+
* \param[in] nVarExtra - Number of extra variables.
5859
*/
59-
~CDiscAdjVariable() override = default;
60+
void AllocateAdjointSolutionExtra(unsigned long nVarExtra);
6061

6162
/*!
6263
* \brief Set the sensitivity at the node

SU2_CFD/include/variables/CHeatVariable.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
*/
3838
class CHeatVariable final : public CVariable {
3939
protected:
40-
MatrixType Solution_Direct; /*!< \brief Direct solution container for use in the adjoint Heat solver. */
41-
4240
CVectorOfMatrix& Gradient_Reconstruction; /*!< \brief Reference to the gradient of the primitive variables for MUSCL reconstruction for the convective term */
4341
CVectorOfMatrix Gradient_Aux; /*!< \brief Auxiliary structure to store a second gradient for reconstruction, if required. */
4442

SU2_CFD/include/variables/CVariable.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ class CVariable {
9494
su2matrix<int> AD_InputIndex; /*!< \brief Indices of Solution variables in the adjoint vector. */
9595
su2matrix<int> AD_OutputIndex; /*!< \brief Indices of Solution variables in the adjoint vector after having been updated. */
9696

97+
VectorType SolutionExtra; /*!< \brief Stores adjoint solution for extra solution variables.
98+
Currently only streamwise periodic pressure-drop for massflow prescribed flows. */
99+
VectorType ExternalExtra; /*!< \brief External storage for the adjoint value (i.e. for the OF mainly */
100+
101+
VectorType SolutionExtra_BGS_k; /*!< \brief Intermediate storage, enables cross term extraction as that is also pushed to Solution. */
102+
103+
protected:
97104
unsigned long nPoint = 0; /*!< \brief Number of points in the domain. */
98105
unsigned long nDim = 0; /*!< \brief Number of dimension of the problem. */
99106
unsigned long nVar = 0; /*!< \brief Number of variables of the problem. */
@@ -406,6 +413,31 @@ class CVariable {
406413
for(unsigned long iVar = 0; iVar < nVar; iVar++) External(iPoint,iVar) += val_sol[iVar];
407414
}
408415

416+
/*!
417+
* \brief Store the adjoint solution of the extra adjoint into the external container.
418+
*/
419+
void Set_ExternalExtra_To_SolutionExtra() {
420+
assert(SolutionExtra.size() == ExternalExtra.size());
421+
for (auto iEntry = 0ul; iEntry < SolutionExtra.size(); iEntry++)
422+
ExternalExtra[iEntry] = SolutionExtra[iEntry];
423+
}
424+
425+
/*!
426+
* \brief Add the external contribution to the solution for the extra adjoint solutions.
427+
*/
428+
void Add_ExternalExtra_To_SolutionExtra() {
429+
assert(SolutionExtra.size() == ExternalExtra.size());
430+
for (auto iEntry = 0ul; iEntry < SolutionExtra.size(); iEntry++)
431+
SolutionExtra[iEntry] += ExternalExtra[iEntry];
432+
}
433+
434+
/*!
435+
* \brief Return the extra adjoint solution.
436+
* \return Reference to extra adjoint solution.
437+
*/
438+
inline VectorType& GetSolutionExtra() { return SolutionExtra; }
439+
inline const VectorType& GetSolutionExtra() const { return SolutionExtra; }
440+
409441
/*!
410442
* \brief Update the variables using a conservative format.
411443
* \param[in] iPoint - Point index.

SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ void CDiscAdjMultizoneDriver::Run() {
430430
/*--- Compute residual from Solution and Solution_BGS_k and update the latter. ---*/
431431

432432
SetResidual_BGS(iZone);
433-
433+
Set_BGSSolution_k_To_Solution(iZone);
434434
}
435435

436436
/*--- Set the multizone output. ---*/

SU2_CFD/src/drivers/CMultizoneDriver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,10 @@ bool CMultizoneDriver::OuterConvergence(unsigned long OuterIter) {
403403
auto solvers = solver_container[iZone][INST_0][MESH_0];
404404

405405
for (unsigned short iSol = 0; iSol < MAX_SOLS; iSol++){
406-
if (solvers[iSol] != nullptr)
406+
if (solvers[iSol] != nullptr) {
407407
solvers[iSol]->ComputeResidual_Multizone(geometry_container[iZone][INST_0][MESH_0], config_container[iZone]);
408+
solvers[iSol]->GetNodes()->Set_BGSSolution_k();
409+
}
408410
}
409411

410412
/*--- Make sure that everything is loaded into the output container. ---*/

SU2_CFD/src/output/CAdjFlowIncOutput.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ void CAdjFlowIncOutput::SetHistoryOutputFields(CConfig *config){
113113
/// DESCRIPTION: Maximum residual of the temperature.
114114
AddHistoryOutput("RMS_ADJ_TEMPERATURE", "rms[A_T]", ScreenOutputFormat::FIXED, "RMS_RES", "Root-mean square residual of the adjoint temperature.", HistoryFieldType::RESIDUAL);
115115

116+
if (config->GetKind_Streamwise_Periodic() == ENUM_STREAMWISE_PERIODIC::MASSFLOW) {
117+
AddHistoryOutput("ADJOINT_SOLEXTRA", "Adjoint_SolExtra", ScreenOutputFormat::FIXED, "ADJOINT_SOLEXTRA", "Adjoint value of the first extra Solution.", HistoryFieldType::COEFFICIENT);
118+
}
119+
116120
AddHistoryOutputFields_AdjScalarRMS_RES(config);
117121

118122
if (config->AddRadiation()){
@@ -205,6 +209,11 @@ void CAdjFlowIncOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CS
205209
if (config->AddRadiation()){
206210
SetHistoryOutputValue("RMS_ADJ_RAD_ENERGY", log10(adjrad_solver->GetRes_RMS(0)));
207211
}
212+
213+
if (config->GetKind_Streamwise_Periodic() == ENUM_STREAMWISE_PERIODIC::MASSFLOW) {
214+
SetHistoryOutputValue("ADJOINT_SOLEXTRA", adjflow_solver->GetNodes()->GetSolutionExtra()[0]);
215+
}
216+
208217
SetHistoryOutputValue("MAX_ADJ_PRESSURE", log10(adjflow_solver->GetRes_Max(0)));
209218
SetHistoryOutputValue("MAX_ADJ_VELOCITY-X", log10(adjflow_solver->GetRes_Max(1)));
210219
SetHistoryOutputValue("MAX_ADJ_VELOCITY-Y", log10(adjflow_solver->GetRes_Max(2)));

0 commit comments

Comments
 (0)