Skip to content

Commit 418576d

Browse files
Merge branch 'develop' of https://github.com/su2code/SU2 into bug_fix_cht_flamelet_solver
2 parents 48b094a + 2a0fd69 commit 418576d

29 files changed

Lines changed: 1294 additions & 7 deletions

.github/workflows/regression.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ jobs:
2626
config_set: [BaseMPI, ReverseMPI, ForwardMPI, BaseNoMPI, ReverseNoMPI, ForwardNoMPI, BaseOMP, ReverseOMP, ForwardOMP]
2727
include:
2828
- config_set: BaseMPI
29-
flags: '-Denable-pywrapper=true -Denable-coolprop=true -Denable-tests=true --warnlevel=2 --werror'
29+
flags: '-Denable-pywrapper=true -Denable-coolprop=true -Denable-mlpcpp=true -Denable-tests=true --warnlevel=2 --werror'
3030
- config_set: ReverseMPI
3131
flags: '-Denable-autodiff=true -Denable-normal=false -Denable-pywrapper=true -Denable-tests=true --warnlevel=3 --werror'
3232
- config_set: ForwardMPI
3333
flags: '-Denable-directdiff=true -Denable-normal=false -Denable-tests=true --warnlevel=3 --werror'
3434
- config_set: BaseNoMPI
35-
flags: '-Denable-pywrapper=true -Denable-openblas=true -Dwith-mpi=disabled -Denable-tests=true --warnlevel=3 --werror'
35+
flags: '-Denable-pywrapper=true -Denable-openblas=true -Dwith-mpi=disabled -Denable-mlpcpp=true -Denable-tests=true --warnlevel=3 --werror'
3636
- config_set: ReverseNoMPI
3737
flags: '-Denable-autodiff=true -Denable-normal=false -Dwith-mpi=disabled -Denable-pywrapper=true -Denable-tests=true --warnlevel=3 --werror'
3838
- config_set: ForwardNoMPI

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@
2424
[submodule "externals/mel"]
2525
path = externals/mel
2626
url = https://github.com/pcarruscag/MEL.git
27+
[submodule "subprojects/MLPCpp"]
28+
path = subprojects/MLPCpp
29+
url = https://github.com/EvertBunschoten/MLPCpp.git

Common/include/CConfig.hpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,12 @@ class CConfig {
519519
Kind_TimeIntScheme_AdjTurb, /*!< \brief Time integration for the adjoint turbulence model. */
520520
Kind_TimeIntScheme_Species, /*!< \brief Time integration for the species model. */
521521
Kind_TimeIntScheme_Heat, /*!< \brief Time integration for the wave equations. */
522-
Kind_TimeStep_Heat; /*!< \brief Time stepping method for the (fvm) heat equation. */
522+
Kind_TimeStep_Heat, /*!< \brief Time stepping method for the (fvm) heat equation. */
523+
n_Datadriven_files;
524+
ENUM_DATADRIVEN_METHOD Kind_DataDriven_Method; /*!< \brief Method used for datset regression in data-driven fluid models. */
525+
526+
su2double DataDriven_Relaxation_Factor; /*!< \brief Relaxation factor for Newton solvers in data-driven fluid models. */
527+
523528
STRUCT_TIME_INT Kind_TimeIntScheme_FEA; /*!< \brief Time integration for the FEA equations. */
524529
STRUCT_SPACE_ITE Kind_SpaceIteScheme_FEA; /*!< \brief Iterative scheme for nonlinear structural analysis. */
525530
unsigned short
@@ -800,7 +805,8 @@ class CConfig {
800805
SurfAdjCoeff_FileName, /*!< \brief Output file with the adjoint variables on the surface. */
801806
SurfSens_FileName, /*!< \brief Output file for the sensitivity on the surface (discrete adjoint). */
802807
VolSens_FileName, /*!< \brief Output file for the sensitivity in the volume (discrete adjoint). */
803-
ObjFunc_Hess_FileName; /*!< \brief Hessian approximation obtained by the Sobolev smoothing solver. */
808+
ObjFunc_Hess_FileName, /*!< \brief Hessian approximation obtained by the Sobolev smoothing solver. */
809+
*DataDriven_Method_FileNames; /*!< \brief Dataset information for data-driven fluid models. */
804810

805811
bool
806812
Wrt_Performance, /*!< \brief Write the performance summary at the end of a calculation. */
@@ -3844,6 +3850,29 @@ class CConfig {
38443850
*/
38453851
unsigned short GetKind_FluidModel(void) const { return Kind_FluidModel; }
38463852

3853+
/*!
3854+
* \brief Datadriven method for EoS evaluation.
3855+
*/
3856+
ENUM_DATADRIVEN_METHOD GetKind_DataDriven_Method(void) const { return Kind_DataDriven_Method; }
3857+
3858+
/*!
3859+
* \brief Get name of the input file for the data-driven fluid model interpolation method.
3860+
* \return Name of the input file for the interpolation method.
3861+
*/
3862+
const string* GetDataDriven_FileNames(void) const { return DataDriven_Method_FileNames; }
3863+
3864+
/*!
3865+
* \brief Get number of listed look-up table or multi-layer perceptron input files.
3866+
* \return Number of listed data-driven method input files.
3867+
*/
3868+
unsigned short GetNDataDriven_Files(void) const { return n_Datadriven_files; }
3869+
3870+
/*!
3871+
* \brief Get Newton solver relaxation factor for data-driven fluid models.
3872+
* \return Newton solver relaxation factor.
3873+
*/
3874+
su2double GetRelaxation_DataDriven(void) const { return DataDriven_Relaxation_Factor; }
3875+
38473876
/*!
38483877
* \brief Returns the name of the fluid we are using in CoolProp.
38493878
*/

Common/include/option_structure.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ enum ENUM_FLUIDMODEL {
548548
FLUID_MIXTURE = 9, /*!< \brief Species mixture model. */
549549
COOLPROP = 10, /*!< \brief Thermodynamics library. */
550550
FLUID_FLAMELET = 11, /*!< \brief lookup table (LUT) method for premixed flamelets. */
551+
DATADRIVEN_FLUID = 12, /*!< \brief multi-layer perceptron driven fluid model. */
551552
};
552553
static const MapType<std::string, ENUM_FLUIDMODEL> FluidModel_Map = {
553554
MakePair("STANDARD_AIR", STANDARD_AIR)
@@ -561,6 +562,7 @@ static const MapType<std::string, ENUM_FLUIDMODEL> FluidModel_Map = {
561562
MakePair("SU2_NONEQ", SU2_NONEQ)
562563
MakePair("FLUID_MIXTURE", FLUID_MIXTURE)
563564
MakePair("COOLPROP", COOLPROP)
565+
MakePair("DATADRIVEN_FLUID", DATADRIVEN_FLUID)
564566
MakePair("FLUID_FLAMELET", FLUID_FLAMELET)
565567
};
566568

@@ -590,6 +592,19 @@ MakePair("ARGON-SID",ARGON_SID)
590592
MakePair("ONESPECIES", ONESPECIES)
591593
};
592594

595+
/*!
596+
* \brief Types of interpolation methods for data-driven fluid models.
597+
*/
598+
enum class ENUM_DATADRIVEN_METHOD {
599+
LUT = 0,
600+
MLP = 1
601+
};
602+
603+
static const MapType<std::string, ENUM_DATADRIVEN_METHOD> DataDrivenMethod_Map = {
604+
MakePair("LUT", ENUM_DATADRIVEN_METHOD::LUT)
605+
MakePair("MLP", ENUM_DATADRIVEN_METHOD::MLP)
606+
};
607+
593608
/*!
594609
* \brief types of coefficient transport model
595610
*/

Common/src/CConfig.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,14 @@ void CConfig::SetConfig_Options() {
11691169
/*!\brief FLUID_NAME \n DESCRIPTION: Fluid name \n OPTIONS: see coolprop homepage \n DEFAULT: nitrogen \ingroup Config*/
11701170
addStringOption("FLUID_NAME", FluidName, string("nitrogen"));
11711171

1172+
/*!\par CONFIG_CATEGORY: Data-driven fluid model parameters \ingroup Config*/
1173+
/*!\brief INTERPOLATION_METHOD \n DESCRIPTION: Interpolation method used to determine the thermodynamic state of the fluid. \n OPTIONS: See \link DataDrivenMethod_Map \endlink DEFAULT: MLP \ingroup Config*/
1174+
addEnumOption("INTERPOLATION_METHOD",Kind_DataDriven_Method, DataDrivenMethod_Map, ENUM_DATADRIVEN_METHOD::LUT);
1175+
/*!\brief FILENAME_INTERPOLATOR \n DESCRIPTION: Input file for the interpolation method. \n \ingroup Config*/
1176+
addStringListOption("FILENAMES_INTERPOLATOR", n_Datadriven_files, DataDriven_Method_FileNames);
1177+
/*!\brief DATADRIVEN_NEWTON_RELAXATION \n DESCRIPTION: Relaxation factor for Newton solvers in data-driven fluid model. \n \ingroup Config*/
1178+
addDoubleOption("DATADRIVEN_NEWTON_RELAXATION", DataDriven_Relaxation_Factor, 0.05);
1179+
11721180
/*!\brief CONFINEMENT_PARAM \n DESCRIPTION: Input Confinement Parameter for Vorticity Confinement*/
11731181
addDoubleOption("CONFINEMENT_PARAM", Confinement_Param, 0.0);
11741182

@@ -4972,6 +4980,11 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
49724980
}
49734981
}
49744982

4983+
/*--- Data-driven fluid model is currently only supported for compressible flow problems. ---*/
4984+
if ((Kind_Solver == MAIN_SOLVER::INC_EULER || Kind_Solver == MAIN_SOLVER::INC_NAVIER_STOKES || Kind_Solver == MAIN_SOLVER::INC_RANS) && (Kind_FluidModel == DATADRIVEN_FLUID)) {
4985+
SU2_MPI::Error("Data-driven fluid model can only be used for compressible flows.", CURRENT_FUNCTION);
4986+
}
4987+
49754988
if ((Kind_Solver == MAIN_SOLVER::INC_EULER || Kind_Solver == MAIN_SOLVER::INC_NAVIER_STOKES || Kind_Solver == MAIN_SOLVER::INC_RANS) && (Kind_FluidModel == INC_IDEAL_GAS_POLY)) {
49764989
su2double sum = 0.0;
49774990
for (unsigned short iVar = 0; iVar < N_POLY_COEFFS; iVar++) {

Docs/docmain.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,9 @@
225225
* \brief Classes for explicit (done by the programmer) vectorization (SIMD) of computations.
226226
* \ingroup Toolboxes
227227
*/
228+
229+
/*!
230+
* \defgroup Multi-Layer Perceptrons (MLP)
231+
* \brief Data look up and interpolation via dense, feed-forward multi-layer perceptrons.
232+
* \ingroup Toolboxes
233+
*/
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/*!
2+
* \file CDataDrivenFluid.hpp
3+
* \brief Defines a template fluid model class using multilayer perceptrons
4+
* for theromodynamic state definition
5+
* \author E.C.Bunschoten
6+
* \version 7.5.1 "Blackbird"
7+
*
8+
* SU2 Project Website: https://su2code.github.io
9+
*
10+
* The SU2 Project is maintained by the SU2 Foundation
11+
* (http://su2foundation.org)
12+
*
13+
* Copyright 2012-2023, SU2 Contributors (cf. AUTHORS.md)
14+
*
15+
* SU2 is free software; you can redistribute it and/or
16+
* modify it under the terms of the GNU Lesser General Public
17+
* License as published by the Free Software Foundation; either
18+
* version 2.1 of the License, or (at your option) any later version.
19+
*
20+
* SU2 is distributed in the hope that it will be useful,
21+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23+
* Lesser General Public License for more details.
24+
*
25+
* You should have received a copy of the GNU Lesser General Public
26+
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
27+
*/
28+
29+
#pragma once
30+
31+
#include <vector>
32+
#include "../../../Common/include/containers/CLookUpTable.hpp"
33+
#if defined(HAVE_MLPCPP)
34+
#define MLP_CUSTOM_TYPE su2double
35+
#include "../../../subprojects/MLPCpp/include/CLookUp_ANN.hpp"
36+
#define USE_MLPCPP
37+
#endif
38+
#include "CFluidModel.hpp"
39+
40+
/*!
41+
* \class CDataDrivenFluid
42+
* \brief Template class for fluid model definition using multi-layer perceptrons for
43+
* fluid dynamic state definition.
44+
* \author: E.C.Bunschoten.
45+
*/
46+
class CDataDrivenFluid final : public CFluidModel {
47+
protected:
48+
int rank{MASTER_NODE}; /*!< \brief MPI Rank. */
49+
ENUM_DATADRIVEN_METHOD Kind_DataDriven_Method =
50+
ENUM_DATADRIVEN_METHOD::LUT; /*!< \brief Interpolation method for data set evaluation. */
51+
52+
string varname_rho, /*!< \brief Controlling variable name for density. */
53+
varname_e; /*!< \brief Controlling variable name for static energy. */
54+
55+
size_t idx_rho, /*!< \brief Interpolator index for density input. */
56+
idx_e; /*!< \brief Interpolator index for energy input. */
57+
58+
su2double Newton_Relaxation, /*!< \brief Relaxation factor for Newton solvers. */
59+
rho_start, /*!< \brief Starting value for the density in Newton solver processes. */
60+
e_start, /*!< \brief Starting value for the energy in Newton solver processes. */
61+
Newton_Tolerance, /*!< \brief Normalized tolerance for Newton solvers. */
62+
rho_min, rho_max, /*!< \brief Minimum and maximum density values in data set. */
63+
e_min, e_max; /*!< \brief Minimum and maximum energy values in data set. */
64+
65+
unsigned long MaxIter_Newton; /*!< \brief Maximum number of iterations for Newton solvers. */
66+
67+
su2double dsde_rho, /*!< \brief Entropy derivative w.r.t. density. */
68+
dsdrho_e, /*!< \brief Entropy derivative w.r.t. static energy. */
69+
d2sde2, /*!< \brief Entropy second derivative w.r.t. static energy. */
70+
d2sdedrho, /*!< \brief Entropy second derivative w.r.t. density and static energy. */
71+
d2sdrho2; /*!< \brief Entropy second derivative w.r.t. static density. */
72+
73+
su2double R_idealgas, /*!< \brief Approximated ideal gas constant. */
74+
Cp_idealgas, /*!< \brief Approximated ideal gas specific heat at constant pressure. */
75+
gamma_idealgas, /*!< \brief Approximated ideal gas specific heat ratio. */
76+
Cv_idealgas, /*!< \brief Approximated ideal gas specific heat at constant volume. */
77+
P_middle, /*!< \brief Pressure computed from the centre of the data set. */
78+
T_middle; /*!< \brief Temperature computed from the centre of the data set. */
79+
80+
su2double Enthalpy, /*!< \brief Fluid enthalpy value [J kg^-1] */
81+
dhdrho_e, /*!< \brief Enthalpy derivative w.r.t. density. */
82+
dhde_rho; /*!< \brief Enthalpy derivative w.r.t. static energy. */
83+
84+
vector<string> input_names_rhoe, /*!< \brief Data-driven method input variable names of the independent variables
85+
(density, energy). */
86+
output_names_rhoe; /*!< \brief Output variable names listed in the data-driven method input file name. */
87+
88+
vector<su2double*> outputs_rhoe; /*!< \brief Pointers to output variables. */
89+
90+
/*--- Class variables for the multi-layer perceptron method ---*/
91+
#ifdef USE_MLPCPP
92+
MLPToolbox::CLookUp_ANN* lookup_mlp; /*!< \brief Multi-layer perceptron collection. */
93+
MLPToolbox::CIOMap* iomap_rhoe; /*!< \brief Input-output map. */
94+
#endif
95+
vector<su2double> MLP_inputs; /*!< \brief Inputs for the multi-layer perceptron look-up operation. */
96+
97+
CLookUpTable* lookup_table; /*!< \brief Look-up table regression object. */
98+
99+
unsigned long outside_dataset, /*!< \brief Density-energy combination lies outside data set. */
100+
nIter_Newton; /*!< \brief Number of Newton solver iterations. */
101+
102+
/*!
103+
* \brief Map dataset variables to specific look-up operations.
104+
*/
105+
void MapInputs_to_Outputs();
106+
107+
/*!
108+
* \brief Evaluate dataset through multi-layer perceptron.
109+
* \param[in] rho - Density value.
110+
* \param[in] e - Static energy value.
111+
* \return Query point lies outside MLP normalization range (0 is inside, 1 is outside).
112+
*/
113+
unsigned long Predict_MLP(su2double rho, su2double e);
114+
115+
/*!
116+
* \brief Evaluate dataset through look-up table.
117+
* \param[in] rho - Density value.
118+
* \param[in] e - Static energy value.
119+
* \return Query point lies outside table data range (0 is inside, 1 is outside).
120+
*/
121+
unsigned long Predict_LUT(su2double rho, su2double e);
122+
123+
/*!
124+
* \brief Evaluate the data set.
125+
* \param[in] rho - Density value.
126+
* \param[in] e - Static energy value.
127+
*/
128+
void Evaluate_Dataset(su2double rho, su2double e);
129+
130+
/*!
131+
* \brief 2D Newton solver for computing the density and energy corresponding to Y1_target and Y2_target.
132+
* \param[in] Y1_target - Target value for output quantity 1.
133+
* \param[in] Y2_target - Target value for output quantity 2.
134+
* \param[in] Y1 - Pointer to output quantity 1.
135+
* \param[in] Y2 - Pointer to output quantity 2.
136+
* \param[in] dY1drho - Pointer to the partial derivative of quantity 1 w.r.t. density at constant energy.
137+
* \param[in] dY1de - Pointer to the partial derivative of quantity 1 w.r.t. energy at constant density.
138+
* \param[in] dY2drho - Pointer to the partial derivative of quantity 2 w.r.t. density at constant energy.
139+
* \param[in] dY2de - Pointer to the partial derivative of quantity 2 w.r.t. energy at constant density.
140+
*/
141+
void Run_Newton_Solver(su2double Y1_target, su2double Y2_target, su2double* Y1, su2double* Y2, su2double* dY1drho,
142+
su2double* dY1de, su2double* dY2drho, su2double* dY2de);
143+
144+
/*!
145+
* \brief 1D Newton solver for computing the density or energy corresponding to Y_target.
146+
* \param[in] Y_target - Target quantity value.
147+
* \param[in] Y - Pointer to output quantity.
148+
* \param[in] X - Pointer to controlling variable (density or energy).
149+
* \param[in] dYdX - Pointer to the partial derivative of target quantity w.r.t. controlling variable.
150+
*/
151+
void Run_Newton_Solver(su2double Y_target, su2double* Y, su2double* X, su2double* dYdX);
152+
153+
void ComputeIdealGasQuantities();
154+
public:
155+
/*!
156+
* \brief Constructor of the class.
157+
*/
158+
CDataDrivenFluid(const CConfig* config, bool display = true);
159+
160+
~CDataDrivenFluid();
161+
/*!
162+
* \brief Set the Dimensionless State using Density and Internal Energy.
163+
* \param[in] rho - first thermodynamic variable (density).
164+
* \param[in] e - second thermodynamic variable (static energy).
165+
*/
166+
void SetTDState_rhoe(su2double rho, su2double e) override;
167+
168+
/*!
169+
* \brief Set the Dimensionless State using Pressure and Temperature.
170+
* \param[in] P - first thermodynamic variable (pressure).
171+
* \param[in] T - second thermodynamic variable (temperature).
172+
*/
173+
void SetTDState_PT(su2double P, su2double T) override;
174+
175+
/*!
176+
* \brief Set the Dimensionless State using Pressure and Density.
177+
* \param[in] P - first thermodynamic variable (pressure).
178+
* \param[in] rho - second thermodynamic variable (density).
179+
*/
180+
void SetTDState_Prho(su2double P, su2double rho) override;
181+
182+
/*!
183+
* \brief Set the Dimensionless Internal Energy using Pressure and Density.
184+
* \param[in] P - first thermodynamic variable (pressure).
185+
* \param[in] rho - second thermodynamic variable (density).
186+
*/
187+
void SetEnergy_Prho(su2double P, su2double rho) override;
188+
189+
/*!
190+
* \brief Set the Dimensionless Internal Energy using Pressure and Density.
191+
* \param[in] rho - second thermodynamic variable (density).
192+
*/
193+
void SetTDState_rhoT(su2double rho, su2double T) override;
194+
195+
/*!
196+
* \brief Set the Dimensionless State using Enthalpy and Entropy.
197+
* \param[in] h - first thermodynamic variable (h).
198+
* \param[in] s - second thermodynamic variable (s).
199+
*/
200+
void SetTDState_hs(su2double h, su2double s) override;
201+
202+
/*!
203+
* \brief Set the Dimensionless State using Pressure and Entropy.
204+
* \param[in] P - first thermodynamic variable (P).
205+
* \param[in] s - second thermodynamic variable (s).
206+
*/
207+
void SetTDState_Ps(su2double P, su2double s) override;
208+
209+
/*!
210+
* \brief Get fluid model extrapolation instance.
211+
* \return Query point lies outside fluid model data range.
212+
*/
213+
unsigned long GetExtrapolation() override { return outside_dataset; }
214+
215+
/*!
216+
* \brief Get number of Newton solver iterations.
217+
* \return Newton solver iteration count at termination.
218+
*/
219+
unsigned long GetnIter_Newton() override { return nIter_Newton; }
220+
};

SU2_CFD/include/fluid/CFluidModel.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,16 @@ class CFluidModel {
344344
* \brief Set fluid eddy viscosity provided by a turbulence model needed for computing effective thermal conductivity.
345345
*/
346346
void SetEddyViscosity(su2double val_Mu_Turb) { Mu_Turb = val_Mu_Turb; }
347+
348+
/*!
349+
* \brief Get fluid model extrapolation instance
350+
* \return Query point lies outside fluid model data range.
351+
*/
352+
virtual unsigned long GetExtrapolation() { return 0; }
353+
354+
/*!
355+
* \brief Get number of Newton solver iterations.
356+
* \return Newton solver iteration count at termination.
357+
*/
358+
virtual unsigned long GetnIter_Newton() { return 0; }
347359
};

0 commit comments

Comments
 (0)