Skip to content

Commit 1567259

Browse files
authored
Merge pull request #1461 from su2code/feature_species
Feature species - more adjoint parts
2 parents 1249f9f + df093ba commit 1567259

34 files changed

Lines changed: 859 additions & 446 deletions

Common/include/CConfig.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ class CConfig {
378378
su2double *Surface_TotalTemperature; /*!< \brief Total temperature at the boundaries. */
379379
su2double *Surface_TotalPressure; /*!< \brief Total pressure at the boundaries. */
380380
su2double *Surface_PressureDrop; /*!< \brief Pressure drop between boundaries. */
381+
su2double* Surface_Species_0; /*!< \brief Average Species_0 at the boundaries. */
382+
su2double* Surface_Species_Variance; /*!< \brief Species Variance at the boundaries. */
381383
su2double *Surface_DC60; /*!< \brief Specified surface DC60 for nacelle boundaries. */
382384
su2double *Surface_IDC; /*!< \brief Specified IDC for nacelle boundaries. */
383385
su2double *Surface_IDC_Mach; /*!< \brief Specified IDC mach for nacelle boundaries. */
@@ -7580,6 +7582,20 @@ class CConfig {
75807582
*/
75817583
void SetSurface_PressureDrop(unsigned short val_marker, su2double val_surface_pressuredrop) { Surface_PressureDrop[val_marker] = val_surface_pressuredrop; }
75827584

7585+
/*!
7586+
* \brief Set the average of species_0 at the surface.
7587+
* \param[in] val_marker - Index corresponding to boundary.
7588+
* \param[in] val_surface_species_0 - Value of avg species_0.
7589+
*/
7590+
void SetSurface_Species_0(unsigned short val_marker, su2double val_surface_species_0) { Surface_Species_0[val_marker] = val_surface_species_0; }
7591+
7592+
/*!
7593+
* \brief Set the species variance at the surface.
7594+
* \param[in] val_marker - Index corresponding to boundary.
7595+
* \param[in] val_surface_species_variance - Value of the species variance.
7596+
*/
7597+
void SetSurface_Species_Variance(unsigned short val_marker, su2double val_surface_species_variance) { Surface_Species_Variance[val_marker] = val_surface_species_variance; }
7598+
75837599
/*!
75847600
* \brief Get the back pressure (static) at an outlet boundary.
75857601
* \param[in] val_index - Index corresponding to the outlet boundary.
@@ -7846,6 +7862,20 @@ class CConfig {
78467862
*/
78477863
su2double GetSurface_PressureDrop(unsigned short val_marker) const { return Surface_PressureDrop[val_marker]; }
78487864

7865+
/*!
7866+
* \brief Get avg species_0 at a boundary.
7867+
* \param[in] val_index - Index corresponding to the boundary.
7868+
* \return The avg species_0.
7869+
*/
7870+
su2double GetSurface_Species_0(unsigned short val_marker) const { return Surface_Species_0[val_marker]; }
7871+
7872+
/*!
7873+
* \brief Get the species variance at a boundary.
7874+
* \param[in] val_index - Index corresponding to the boundary.
7875+
* \return The species variance.
7876+
*/
7877+
su2double GetSurface_Species_Variance(unsigned short val_marker) const { return Surface_Species_Variance[val_marker]; }
7878+
78497879
/*!
78507880
* \brief Get the back pressure (static) at an outlet boundary.
78517881
* \param[in] val_index - Index corresponding to the outlet boundary.

Common/include/option_structure.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,34 @@ static const MapType<std::string, TURB_MODEL> Turb_Model_Map = {
929929
MakePair("SST_SUST", TURB_MODEL::SST_SUST)
930930
};
931931

932+
/*!
933+
* \brief Families of turbulence models
934+
*/
935+
enum class TURB_FAMILY {
936+
NONE, /*!< \brief No turbulence model. */
937+
SA, /*!< \brief Spalart-Allmaras variants. */
938+
KW, /*!< \brief k-w models. */
939+
};
940+
/*!
941+
* \brief Associate turb models with their family
942+
*/
943+
inline TURB_FAMILY TurbModelFamily(TURB_MODEL model) {
944+
switch (model) {
945+
case TURB_MODEL::NONE:
946+
return TURB_FAMILY::NONE;
947+
case TURB_MODEL::SA:
948+
case TURB_MODEL::SA_NEG:
949+
case TURB_MODEL::SA_E:
950+
case TURB_MODEL::SA_COMP:
951+
case TURB_MODEL::SA_E_COMP:
952+
return TURB_FAMILY::SA;
953+
case TURB_MODEL::SST:
954+
case TURB_MODEL::SST_SUST:
955+
return TURB_FAMILY::KW;
956+
}
957+
return TURB_FAMILY::NONE;
958+
}
959+
932960
/*!
933961
* \brief Types of transition models
934962
*/
@@ -1536,6 +1564,8 @@ enum ENUM_OBJECTIVE {
15361564
SURFACE_MOM_DISTORTION = 54, /*!< \brief Momentum distortion objective function definition. */
15371565
SURFACE_SECOND_OVER_UNIFORM = 55, /*!< \brief Secondary over uniformity (relative secondary strength) objective function definition. */
15381566
SURFACE_PRESSURE_DROP = 56, /*!< \brief Pressure drop objective function definition. */
1567+
SURFACE_SPECIES_0 = 58, /*!< \brief Surface Avg. Species_0 objective function definition. */
1568+
SURFACE_SPECIES_VARIANCE = 59,/*!< \brief Species Variance objective function definition. */
15391569
CUSTOM_OBJFUNC = 31, /*!< \brief Custom objective function definition. */
15401570
TOTAL_PRESSURE_LOSS = 39,
15411571
KINETIC_ENERGY_LOSS = 40,
@@ -1588,6 +1618,8 @@ static const MapType<std::string, ENUM_OBJECTIVE> Objective_Map = {
15881618
MakePair("SURFACE_MOM_DISTORTION", SURFACE_MOM_DISTORTION)
15891619
MakePair("SURFACE_SECOND_OVER_UNIFORM", SURFACE_SECOND_OVER_UNIFORM)
15901620
MakePair("SURFACE_PRESSURE_DROP", SURFACE_PRESSURE_DROP)
1621+
MakePair("SURFACE_SPECIES_0", SURFACE_SPECIES_0)
1622+
MakePair("SURFACE_SPECIES_VARIANCE", SURFACE_SPECIES_VARIANCE)
15911623
MakePair("CUSTOM_OBJFUNC", CUSTOM_OBJFUNC)
15921624
MakePair("TOTAL_EFFICIENCY", TOTAL_EFFICIENCY)
15931625
MakePair("TOTAL_STATIC_EFFICIENCY", TOTAL_STATIC_EFFICIENCY)

Common/src/CConfig.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,8 @@ void CConfig::SetPointersNull(void) {
910910
ActDisk_ReverseMassFlow = nullptr; Surface_MassFlow = nullptr; Surface_Mach = nullptr;
911911
Surface_Temperature = nullptr; Surface_Pressure = nullptr; Surface_Density = nullptr; Surface_Enthalpy = nullptr;
912912
Surface_NormalVelocity = nullptr; Surface_TotalTemperature = nullptr; Surface_TotalPressure = nullptr; Surface_PressureDrop = nullptr;
913-
Surface_DC60 = nullptr; Surface_IDC = nullptr;
913+
Surface_DC60 = nullptr; Surface_IDC = nullptr;
914+
Surface_Species_Variance = nullptr; Surface_Species_0 = nullptr;
914915

915916
Outlet_MassFlow = nullptr; Outlet_Density = nullptr; Outlet_Area = nullptr;
916917

@@ -3530,14 +3531,17 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
35303531
case SURFACE_MOM_DISTORTION:
35313532
case SURFACE_SECOND_OVER_UNIFORM:
35323533
case SURFACE_PRESSURE_DROP:
3534+
case SURFACE_SPECIES_0:
3535+
case SURFACE_SPECIES_VARIANCE:
35333536
case CUSTOM_OBJFUNC:
35343537
if (Kind_ObjFunc[iObj] != Obj_0) {
35353538
SU2_MPI::Error(string("The following objectives can only be used for the first surface in a multi-objective \n")+
35363539
string("problem or as a single objective applied to multiple monitoring markers:\n")+
35373540
string("INVERSE_DESIGN_PRESSURE, INVERSE_DESIGN_HEATFLUX, THRUST_COEFFICIENT, TORQUE_COEFFICIENT\n")+
35383541
string("FIGURE_OF_MERIT, SURFACE_TOTAL_PRESSURE, SURFACE_STATIC_PRESSURE, SURFACE_MASSFLOW\n")+
35393542
string("SURFACE_UNIFORMITY, SURFACE_SECONDARY, SURFACE_MOM_DISTORTION, SURFACE_SECOND_OVER_UNIFORM\n")+
3540-
string("SURFACE_PRESSURE_DROP, SURFACE_STATIC_TEMPERATURE, CUSTOM_OBJFUNC.\n"), CURRENT_FUNCTION);
3543+
string("SURFACE_PRESSURE_DROP, SURFACE_STATIC_TEMPERATURE, SURFACE_SPECIES_0\n")+
3544+
string("SURFACE_SPECIES_VARIANCE, CUSTOM_OBJFUNC.\n"), CURRENT_FUNCTION);
35413545
}
35423546
break;
35433547
default:
@@ -5138,13 +5142,12 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
51385142
else {monoatomic = false;}
51395143

51405144
/*--- Set number of Turbulence Variables. ---*/
5141-
switch(Kind_Turb_Model) {
5142-
case TURB_MODEL::NONE:
5145+
switch (TurbModelFamily(Kind_Turb_Model)) {
5146+
case TURB_FAMILY::NONE:
51435147
nTurbVar = 0; break;
5144-
case TURB_MODEL::SA: case TURB_MODEL::SA_COMP: case TURB_MODEL::SA_E_COMP: case TURB_MODEL::SA_E:
5145-
case TURB_MODEL::SA_NEG:
5148+
case TURB_FAMILY::SA:
51465149
nTurbVar = 1; break;
5147-
case TURB_MODEL::SST: case TURB_MODEL::SST_SUST:
5150+
case TURB_FAMILY::KW:
51485151
nTurbVar = 2; break;
51495152
}
51505153

@@ -5160,6 +5163,15 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
51605163
Kind_Solver != MAIN_SOLVER::DISC_ADJ_RANS)
51615164
SU2_MPI::Error("Species transport currently only avaialble for compressible and incompressible flow.", CURRENT_FUNCTION);
51625165

5166+
/*--- Species specific OF currently can only handle one entry in Marker_Analyze. ---*/
5167+
for (unsigned short iObj = 0; iObj < nObj; iObj++) {
5168+
if ((Kind_ObjFunc[iObj] == SURFACE_SPECIES_0 ||
5169+
Kind_ObjFunc[iObj] == SURFACE_SPECIES_VARIANCE) &&
5170+
nMarker_Analyze > 1) {
5171+
SU2_MPI::Error("SURFACE_SPECIES_0 and SURFACE_SPECIES_VARIANCE currently can only handle one entry to MARKER_ANALYZE.", CURRENT_FUNCTION);
5172+
}
5173+
}
5174+
51635175
// For now, do not allow axisymmetric simulations
51645176
if (Axisymmetric) SU2_MPI::Error("Species transport currently not possible with axissymmetric flow.", CURRENT_FUNCTION);
51655177

@@ -5335,6 +5347,8 @@ void CConfig::SetMarkers(SU2_COMPONENT val_software) {
53355347
Surface_TotalTemperature = new su2double[nMarker_Analyze] ();
53365348
Surface_TotalPressure = new su2double[nMarker_Analyze] ();
53375349
Surface_PressureDrop = new su2double[nMarker_Analyze] ();
5350+
Surface_Species_0 = new su2double[nMarker_Analyze] ();
5351+
Surface_Species_Variance = new su2double[nMarker_Analyze] ();
53385352
Surface_DC60 = new su2double[nMarker_Analyze] ();
53395353
Surface_IDC = new su2double[nMarker_Analyze] ();
53405354
Surface_IDC_Mach = new su2double[nMarker_Analyze] ();
@@ -5862,7 +5876,7 @@ void CConfig::SetOutput(SU2_COMPONENT val_software, unsigned short val_izone) {
58625876
break;
58635877
case MAIN_SOLVER::MULTIPHYSICS:
58645878
cout << "Multiphysics solver" << endl;
5865-
break;
5879+
break;
58665880
default:
58675881
SU2_MPI::Error("No valid solver was chosen", CURRENT_FUNCTION);
58685882

@@ -7877,6 +7891,8 @@ CConfig::~CConfig(void) {
78777891
delete[] Surface_TotalTemperature;
78787892
delete[] Surface_TotalPressure;
78797893
delete[] Surface_PressureDrop;
7894+
delete[] Surface_Species_0;
7895+
delete[] Surface_Species_Variance;
78807896
delete[] Surface_DC60;
78817897
delete[] Surface_IDC;
78827898
delete[] Surface_IDC_Mach;
@@ -8223,6 +8239,8 @@ string CConfig::GetObjFunc_Extension(string val_filename) const {
82238239
case SURFACE_MOM_DISTORTION: AdjExt = "_distort"; break;
82248240
case SURFACE_SECOND_OVER_UNIFORM: AdjExt = "_sou"; break;
82258241
case SURFACE_PRESSURE_DROP: AdjExt = "_dp"; break;
8242+
case SURFACE_SPECIES_0: AdjExt = "_avgspec0"; break;
8243+
case SURFACE_SPECIES_VARIANCE: AdjExt = "_specvar"; break;
82268244
case SURFACE_MACH: AdjExt = "_mach"; break;
82278245
case CUSTOM_OBJFUNC: AdjExt = "_custom"; break;
82288246
case KINETIC_ENERGY_LOSS: AdjExt = "_ke"; break;
@@ -8452,7 +8470,7 @@ void CConfig::SetGlobalParam(MAIN_SOLVER val_solver,
84528470
break;
84538471

84548472
default:
8455-
break;
8473+
break;
84568474
}
84578475
}
84588476

SU2_CFD/include/output/CAdjFlowCompOutput.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,14 @@
2727

2828
#pragma once
2929

30-
#include "COutput.hpp"
30+
#include "CAdjFlowOutput.hpp"
3131

3232
/*! \class CAdjFlowCompOutput
3333
* \brief Output class for compressible flow adjoint problems.
3434
* \author R. Sanchez, T. Albring.
3535
* \date June 5, 2018.
3636
*/
37-
class CAdjFlowCompOutput final: public COutput {
38-
private:
39-
40-
bool cont_adj; /*!< \brief Boolean indicating whether we run a cont. adjoint problem */
41-
bool frozen_visc; /*!< \brief Boolean indicating whether frozen viscosity/turbulence is used. */
42-
TURB_MODEL turb_model; /*!< \brief The kind of turbulence model*/
43-
37+
class CAdjFlowCompOutput final: public CAdjFlowOutput {
4438
public:
4539

4640
/*!

SU2_CFD/include/output/CAdjFlowIncOutput.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@
2727

2828
#pragma once
2929

30-
#include "COutput.hpp"
30+
#include "CAdjFlowOutput.hpp"
3131

3232
/*! \class CAdjFlowIncOutput
3333
* \brief Output class for incompressible flow discrete adjoint problems.
3434
* \author R. Sanchez, T. Albring.
3535
* \date June 5, 2018.
3636
*/
37-
class CAdjFlowIncOutput final: public COutput {
37+
class CAdjFlowIncOutput final: public CAdjFlowOutput {
3838
private:
3939

40-
TURB_MODEL turb_model; /*!< \brief The kind of turbulence model*/
4140
RADIATION_MODEL rad_model; /*!< \brief The kind of radiation model */
4241
bool heat; /*!< \brief Boolean indicating whether have a heat problem*/
4342
bool weakly_coupled_heat; /*!< \brief Boolean indicating whether have a weakly coupled heat equation*/
44-
bool cont_adj; /*!< \brief Boolean indicating whether we run a cont. adjoint problem */
45-
bool frozen_visc; /*!< \brief Boolean indicating whether frozen viscosity/turbulence is used. */
4643

4744
public:
4845

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*!
2+
* \file CAdjFlowOutput.hpp
3+
* \brief Headers of the adjoint flow output.
4+
* \author T. Kattmann
5+
* \version 7.2.1 "Blackbird"
6+
*
7+
* SU2 Project Website: https://su2code.github.io
8+
*
9+
* The SU2 Project is maintained by the SU2 Foundation
10+
* (http://su2foundation.org)
11+
*
12+
* Copyright 2012-2021, SU2 Contributors (cf. AUTHORS.md)
13+
*
14+
* SU2 is free software; you can redistribute it and/or
15+
* modify it under the terms of the GNU Lesser General Public
16+
* License as published by the Free Software Foundation; either
17+
* version 2.1 of the License, or (at your option) any later version.
18+
*
19+
* SU2 is distributed in the hope that it will be useful,
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22+
* Lesser General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU Lesser General Public
25+
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
28+
#pragma once
29+
30+
#include "COutput.hpp"
31+
32+
/*! \class CAdjFlowOutput
33+
* \brief Output class for flow discrete adjoint problems.
34+
* \author T. Kattmann
35+
* \date December 3, 2021.
36+
*/
37+
class CAdjFlowOutput : public COutput {
38+
protected:
39+
const TURB_MODEL turb_model; /*!< \brief The kind of turbulence model*/
40+
const bool cont_adj; /*!< \brief Boolean indicating whether we run a cont. adjoint problem */
41+
const bool frozen_visc; /*!< \brief Boolean indicating whether frozen viscosity/turbulence is used. */
42+
43+
public:
44+
/*!
45+
* \brief Constructor of the class
46+
* \param[in] config - Definition of the particular problem.
47+
*/
48+
CAdjFlowOutput(CConfig* config, unsigned short nDim);
49+
50+
/*!
51+
* \brief Add scalar (turbulence/species) history fields for the Residual RMS (FVMComp, FVMInc, FVMNEMO).
52+
*/
53+
void AddHistoryOutputFields_AdjScalarRMS_RES(const CConfig* config);
54+
55+
/*!
56+
* \brief Add scalar (turbulence/species) history fields for the max Residual (FVMComp, FVMInc, FVMNEMO).
57+
*/
58+
void AddHistoryOutputFields_AdjScalarMAX_RES(const CConfig* config);
59+
60+
/*!
61+
* \brief Add scalar (turbulence/species) history fields for the BGS Residual (FVMComp, FVMInc, FVMNEMO).
62+
*/
63+
void AddHistoryOutputFields_AdjScalarBGS_RES(const CConfig* config);
64+
65+
/*!
66+
* \brief Add scalar (turbulence/species) history fields for the linear solver (FVMComp, FVMInc, FVMNEMO).
67+
*/
68+
void AddHistoryOutputFields_AdjScalarLinsol(const CConfig* config);
69+
70+
/*!
71+
* \brief Set all scalar (turbulence/species) history field values.
72+
*/
73+
void LoadHistoryData_AdjScalar(const CConfig* config, const CSolver* const* solver);
74+
75+
/*!
76+
* \brief Add scalar (turbulence/species) volume solution fields for a point (FVMComp, FVMInc, FVMNEMO).
77+
* \note The order of fields in restart files is fixed. Therefore the split-up.
78+
* \param[in] config - Definition of the particular problem.
79+
*/
80+
void SetVolumeOutputFields_AdjScalarSolution(const CConfig* config);
81+
82+
/*!
83+
* \brief Add scalar (turbulence/species) volume solution fields for a point (FVMComp, FVMInc, FVMNEMO).
84+
* \note The order of fields in restart files is fixed. Therefore the split-up.
85+
* \param[in] config - Definition of the particular problem.
86+
*/
87+
void SetVolumeOutputFields_AdjScalarResidual(const CConfig* config);
88+
89+
/*!
90+
* \brief Set all scalar (turbulence/species) volume field values for a point.
91+
* \param[in] config - Definition of the particular problem.
92+
* \param[in] solver - The container holding all solution data.
93+
* \param[in] iPoint - Index of the point.
94+
*/
95+
void LoadVolumeData_AdjScalar(const CConfig* config, const CSolver* const* solver, const unsigned long iPoint);
96+
};

SU2_CFD/include/output/CFlowOutput.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ class CFlowOutput : public CFVMOutput{
8282
const vector<su2double>& Surface_Area_Total);
8383

8484
/*!
85-
* \brief Add scalar (turbulence/species) history fields for the linear solver (FVMComp, FVMInc, FVMNEMO).
85+
* \brief Add scalar (turbulence/species) history fields for the Residual RMS (FVMComp, FVMInc, FVMNEMO).
8686
*/
8787
void AddHistoryOutputFields_ScalarRMS_RES(const CConfig* config);
8888

8989
/*!
90-
* \brief Add scalar (turbulence/species) history fields for the linear solver (FVMComp, FVMInc, FVMNEMO).
90+
* \brief Add scalar (turbulence/species) history fields for the max Residual (FVMComp, FVMInc, FVMNEMO).
9191
*/
9292
void AddHistoryOutputFields_ScalarMAX_RES(const CConfig* config);
9393

9494
/*!
95-
* \brief Add scalar (turbulence/species) history fields for the linear solver (FVMComp, FVMInc, FVMNEMO).
95+
* \brief Add scalar (turbulence/species) history fields for the BGS Residual (FVMComp, FVMInc, FVMNEMO).
9696
*/
9797
void AddHistoryOutputFields_ScalarBGS_RES(const CConfig* config);
9898

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,12 @@ su2double CFVMFlowSolverBase<V,R>::EvaluateCommonObjFunc(const CConfig& config)
30153015
case SURFACE_PRESSURE_DROP:
30163016
objFun += weight * config.GetSurface_PressureDrop(0);
30173017
break;
3018+
case SURFACE_SPECIES_0:
3019+
objFun += weight * config.GetSurface_Species_0(0);
3020+
break;
3021+
case SURFACE_SPECIES_VARIANCE:
3022+
objFun += weight * config.GetSurface_Species_Variance(0);
3023+
break;
30183024
case CUSTOM_OBJFUNC:
30193025
objFun += weight * Total_Custom_ObjFunc;
30203026
break;

0 commit comments

Comments
 (0)