Skip to content

Commit eb7328a

Browse files
committed
make the extra allocation more generic
1 parent 01eb182 commit eb7328a

7 files changed

Lines changed: 29 additions & 20 deletions

File tree

SU2_CFD/include/solvers/CIncEulerSolver.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,9 @@ class CIncEulerSolver : public CFVMFlowSolverBase<CIncEulerVariable, ENUM_REGIME
404404
* \brief Register In- or Output.
405405
* \param[in] input - Boolean whether In- or Output should be registered.
406406
* \param[in] config - The particular config.
407+
* \returns The number of extra variables.
407408
*/
408-
void RegisterSolutionExtra(bool input, const CConfig* config) final;
409+
unsigned long RegisterSolutionExtra(bool input, const CConfig* config) final;
409410

410411
/*!
411412
* \brief Seed the adjoint of the extra solution at the output.

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3547,8 +3547,9 @@ class CSolver {
35473547
* \brief Register In- or Output.
35483548
* \param[in] input - Boolean whether In- or Output should be registered.
35493549
* \param[in] config - The particular config.
3550+
* \returns The number of extra variables.
35503551
*/
3551-
virtual void RegisterSolutionExtra(bool input, const CConfig* config) {}
3552+
virtual unsigned long RegisterSolutionExtra(bool input, const CConfig* config) { return 0; }
35523553

35533554
/*!
35543555
* \brief Seed the adjoint of the extra solution at the output.

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/src/solvers/CDiscAdjSolver.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,19 @@
2929
#include "../../../Common/include/toolboxes/geometry_toolbox.hpp"
3030
#include "../../../Common/include/parallelization/omp_structure.hpp"
3131

32-
CDiscAdjSolver::CDiscAdjSolver(CGeometry *geometry, CConfig *config, CSolver *direct_solver,
32+
CDiscAdjSolver::CDiscAdjSolver(CGeometry *geometry, CConfig *config, CSolver *direct_sol,
3333
unsigned short Kind_Solver, unsigned short iMesh) : CSolver() {
3434

35+
/*-- Store some information about direct solver ---*/
36+
37+
KindDirect_Solver = Kind_Solver;
38+
direct_solver = direct_sol;
39+
3540
adjoint = true;
3641

3742
nVar = direct_solver->GetnVar();
3843
nDim = geometry->GetnDim();
3944

40-
/*--- Initialize arrays to NULL ---*/
41-
42-
/*-- Store some information about direct solver ---*/
43-
this->KindDirect_Solver = Kind_Solver;
44-
this->direct_solver = direct_solver;
45-
4645
nMarker = config->GetnMarker_All();
4746
nPoint = geometry->GetnPoint();
4847
nPointDomain = geometry->GetnPointDomain();
@@ -86,6 +85,11 @@ CDiscAdjSolver::CDiscAdjSolver(CGeometry *geometry, CConfig *config, CSolver *di
8685
nodes = new CDiscAdjVariable(Solution.data(), nPoint, nDim, nVar, config);
8786
SetBaseClassPointerToNodes();
8887

88+
/*--- Allocate extra solution variables, if any are in use. ---*/
89+
90+
const auto nVarExtra = direct_solver->RegisterSolutionExtra(true, config);
91+
nodes->AllocateAdjointSolutionExtra(nVarExtra);
92+
8993
switch(KindDirect_Solver){
9094
case RUNTIME_FLOW_SYS:
9195
SolverName = "ADJ.FLOW";

SU2_CFD/src/solvers/CIncEulerSolver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3106,11 +3106,13 @@ void CIncEulerSolver::SetFreeStream_Solution(const CConfig *config){
31063106

31073107
}
31083108

3109-
void CIncEulerSolver::RegisterSolutionExtra(bool input, const CConfig* config) {
3109+
unsigned long CIncEulerSolver::RegisterSolutionExtra(bool input, const CConfig* config) {
31103110
if (config->GetKind_Streamwise_Periodic() == ENUM_STREAMWISE_PERIODIC::MASSFLOW) {
31113111
if (input) AD::RegisterInput(SPvals.Streamwise_Periodic_PressureDrop);
31123112
else AD::RegisterOutput(SPvalsUpdated.Streamwise_Periodic_PressureDrop);
3113+
return 1;
31133114
}
3115+
return 0;
31143116
}
31153117

31163118
void CIncEulerSolver::SetAdjoint_SolutionExtra(const su2activevector& adj_sol, const CConfig* config) {

SU2_CFD/src/variables/CDiscAdjVariable.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ void CDiscAdjVariable::Set_External_To_DualTimeDer() {
4949
assert(External.size() == DualTime_Derivative.size());
5050
parallelCopy(External.size(), DualTime_Derivative.data(), External.data());
5151
}
52+
53+
void CDiscAdjVariable::AllocateAdjointSolutionExtra(unsigned long nVarExtra) {
54+
if (nVarExtra == 0) return;
55+
SolutionExtra.resize(nVarExtra) = su2double(1e-16);
56+
/*--- These are only for multizone, but since nVarExtra is small we allocate by default. ---*/
57+
SolutionExtra_BGS_k.resize(nVarExtra) = su2double(1e-16);
58+
ExternalExtra.resize(nVarExtra) = su2double(0.0);
59+
}

SU2_CFD/src/variables/CVariable.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ CVariable::CVariable(unsigned long npoint, unsigned long ndim, unsigned long nva
7272
AD_InputIndex.resize(nPoint,nVar) = -1;
7373
AD_OutputIndex.resize(nPoint,nVar) = -1;
7474
}
75-
76-
if (config->GetKind_Streamwise_Periodic() == ENUM_STREAMWISE_PERIODIC::MASSFLOW) {
77-
SolutionExtra.resize(1) = su2double(1e-16);
78-
if (config->GetMultizone_Problem()) {
79-
SolutionExtra_BGS_k.resize(1) = su2double(1e-16);
80-
ExternalExtra.resize(1) = su2double(0.0);
81-
}
82-
}
8375
}
8476

8577
if (config->GetMultizone_Problem())

0 commit comments

Comments
 (0)