Skip to content

Commit e348065

Browse files
authored
Merge branch 'develop' into gradient_type
2 parents 936fe67 + 56b6080 commit e348065

10 files changed

Lines changed: 230 additions & 5 deletions

File tree

Common/include/CConfig.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,13 @@ class CConfig {
11231123
INLET_INTERP_TYPE Kind_Inlet_InterpolationType; /*!brief type of spanwise interpolation data to use for the inlet face. */
11241124
bool PrintInlet_InterpolatedData; /*!brief option for printing the interpolated data file. */
11251125

1126+
/*--- libROM configure options ---*/
1127+
bool libROM; /*!< \brief Toggle saving to libROM. */
1128+
string libROMbase_FileName; /*!< \brief Base filename for libROM file saving. */
1129+
POD_KIND POD_Basis_Gen; /*!< \brief Type of POD basis generation (static or incremental). */
1130+
unsigned short maxBasisDim, /*!< \brief Maximum number of POD basis dimensions. */
1131+
rom_save_freq; /*!< \brief Frequency of unsteady time steps to save. */
1132+
11261133
/* other NEMO configure options*/
11271134
unsigned short nSpecies, /*!< \brief No of species present in flow */
11281135
iWall_Catalytic,
@@ -9292,4 +9299,33 @@ class CConfig {
92929299
*/
92939300
short FindInterfaceMarker(unsigned short iInterface) const;
92949301

9302+
/*!
9303+
* \brief Get whether or not to save solution data to libROM.
9304+
* \return True if specified in config file.
9305+
*/
9306+
bool GetSave_libROM(void) const {return libROM; }
9307+
9308+
/*!
9309+
* \brief Get the name of the file for libROM to save.
9310+
* \return Filename prefix for libROM to save to (default: "su2").
9311+
*/
9312+
string GetlibROMbase_FileName(void) const { return libROMbase_FileName; }
9313+
9314+
/*!
9315+
* \brief Static or incremental toggle for POD basis generation type.
9316+
* \return Type of POD generation type
9317+
*/
9318+
POD_KIND GetKind_PODBasis(void) const { return POD_Basis_Gen; }
9319+
9320+
/*!
9321+
* \brief Get maximum number of POD basis dimensions (default: 100).
9322+
* \return Maximum number of POD basis vectors.
9323+
*/
9324+
unsigned short GetMax_BasisDim(void) const { return maxBasisDim; }
9325+
9326+
/*!
9327+
* \brief Get frequency of unsteady time steps to save (default: 1).
9328+
* \return Save frequency for unsteady time steps.
9329+
*/
9330+
unsigned short GetRom_SaveFreq(void) const { return rom_save_freq; }
92959331
};

Common/include/option_structure.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,18 @@ struct StreamwisePeriodicValues {
22252225
su2double Streamwise_Periodic_InletTemperature; /*!< \brief Area avg static Temp [K] at the periodic inlet. Used for adaptive outlet heatsink. */
22262226
};
22272227

2228+
/*!
2229+
* \brief Type of POD basis generation (for use with libROM)
2230+
*/
2231+
enum class POD_KIND {
2232+
STATIC, /*!< \brief Use static SVD for POD basis generation. */
2233+
INCREMENTAL, /*!< \brief Use incremental SVD for POD basis generation. */
2234+
};
2235+
static const MapType<std::string, POD_KIND> POD_Map = {
2236+
MakePair("STATIC_POD", POD_KIND::STATIC)
2237+
MakePair("INCREMENTAL_POD", POD_KIND::INCREMENTAL)
2238+
};
2239+
22282240
#undef MakePair
22292241
/* END_CONFIG_ENUMS */
22302242

Common/src/CConfig.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,6 +2778,25 @@ void CConfig::SetConfig_Options() {
27782778

27792779
/* DESCRIPTION: Size of the edge groups colored for thread parallel edge loops (0 forces the reducer strategy). */
27802780
addUnsignedLongOption("EDGE_COLORING_GROUP_SIZE", edgeColorGroupSize, 512);
2781+
2782+
/*--- options that are used for libROM ---*/
2783+
/*!\par CONFIG_CATEGORY:libROM options \ingroup Config*/
2784+
2785+
/*!\brief SAVE_LIBROM \n DESCRIPTION: Flag for saving data with libROM. */
2786+
addBoolOption("SAVE_LIBROM", libROM, false);
2787+
2788+
/*!\brief LIBROM_BASE_FILENAME \n DESCRIPTION: Output base file name for libROM \ingroup Config*/
2789+
addStringOption("LIBROM_BASE_FILENAME", libROMbase_FileName, string("su2"));
2790+
2791+
/*!\brief BASIS_GENERATION \n DESCRIPTION: Flag for saving data with libROM. */
2792+
addEnumOption("BASIS_GENERATION", POD_Basis_Gen, POD_Map, POD_KIND::STATIC);
2793+
2794+
/*!\brief MAX_BASIS_DIM \n DESCRIPTION: Maximum number of basis vectors.*/
2795+
addUnsignedShortOption("MAX_BASIS_DIM", maxBasisDim, 100);
2796+
2797+
/*!\brief MAX_BASIS_DIM \n DESCRIPTION: Maximum number of basis vectors.*/
2798+
addUnsignedShortOption("ROM_SAVE_FREQ", rom_save_freq, 1);
2799+
27812800
/* END_CONFIG_OPTIONS */
27822801

27832802
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ You will find more information and the latest news in:
3838

3939
## Precompiled binaries for Linux, MacOS, Windows
4040

41-
You can find precompiled binaries of the latest version on our [download page](https://su2code.github.io/download/) or under [releases](https://github.com/su2code/SU2/releases).
41+
You can find precompiled binaries of the latest version on our [download page](https://su2code.github.io/download.html) or under [releases](https://github.com/su2code/SU2/releases).
4242

4343
## Build SU2
4444
The build system of SU2 is based on a combination of [meson](http://mesonbuild.com/) (as the front-end) and [ninja](https://ninja-build.org/) (as the back-end). Meson is an open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible. Ninja is a small low-level build system with a focus on speed.

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
#include "../../../Common/include/toolboxes/MMS/CVerificationSolution.hpp"
5757
#include "../variables/CVariable.hpp"
5858

59+
#ifdef HAVE_LIBROM
60+
#include "BasisGenerator.h"
61+
#include "QDEIM.h"
62+
#include "DEIM.h"
63+
#endif
64+
5965
using namespace std;
6066

6167
class CSolver {
@@ -196,6 +202,11 @@ class CSolver {
196202
CVerificationSolution *VerificationSolution; /*!< \brief Verification solution class used within the solver. */
197203

198204
vector<string> fields;
205+
206+
#ifdef HAVE_LIBROM
207+
std::unique_ptr<CAROM::BasisGenerator> u_basis_generator;
208+
#endif
209+
199210
/*!
200211
* \brief Constructor of the class.
201212
*/
@@ -4326,7 +4337,14 @@ class CSolver {
43264337
* \return Struct holding 4 su2doubles.
43274338
*/
43284339
virtual StreamwisePeriodicValues GetStreamwisePeriodicValues() const { return StreamwisePeriodicValues(); }
4329-
4340+
4341+
/*!
4342+
* \brief Save snapshot or POD data using libROM
4343+
* \param[in] geometry - Geometrical definition of the problem.
4344+
* \param[in] config - Definition of the particular problem.
4345+
* \param[in] converged - Whether or not solution has converged.
4346+
*/
4347+
void SavelibROM(CGeometry *geometry, CConfig *config, bool converged);
43304348

43314349
protected:
43324350
/*!

SU2_CFD/src/drivers/CSinglezoneDriver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ void CSinglezoneDriver::StartSolver() {
9393
/*--- Output the solution in files. ---*/
9494

9595
Output(TimeIter);
96+
97+
/*--- Save iteration solution for libROM ---*/
98+
if (config_container[MESH_0]->GetSave_libROM()) {
99+
solver_container[ZONE_0][INST_0][MESH_0][FLOW_SOL]->SavelibROM(geometry_container[ZONE_0][INST_0][MESH_0],
100+
config_container[ZONE_0], StopCalc);
101+
}
96102

97103
/*--- If the convergence criteria has been met, terminate the simulation. ---*/
98104

SU2_CFD/src/solvers/CSolver.cpp

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ CSolver::~CSolver(void) {
187187
delete [] Restart_Data;
188188

189189
delete VerificationSolution;
190-
191190
}
192191

193192
void CSolver::GetPeriodicCommCountAndType(const CConfig* config,
@@ -4212,3 +4211,93 @@ void CSolver::BasicLoadRestart(CGeometry *geometry, const CConfig *config, const
42124211
string("It could be empty lines at the end of the file."), CURRENT_FUNCTION);
42134212
}
42144213
}
4214+
4215+
void CSolver::SavelibROM(CGeometry *geometry, CConfig *config, bool converged) {
4216+
4217+
#if defined(HAVE_LIBROM) && !defined(CODI_FORWARD_TYPE) && !defined(CODI_REVERSE_TYPE)
4218+
const bool unsteady = config->GetTime_Domain();
4219+
const string filename = config->GetlibROMbase_FileName();
4220+
const unsigned long TimeIter = config->GetTimeIter();
4221+
const unsigned long nTimeIter = config->GetnTime_Iter();
4222+
const int maxBasisDim = config->GetMax_BasisDim();
4223+
const int save_freq = config->GetRom_SaveFreq();
4224+
int dim = int(nPointDomain * nVar);
4225+
bool incremental = false;
4226+
4227+
if (!u_basis_generator) {
4228+
4229+
/*--- Define SVD basis generator ---*/
4230+
auto timesteps = static_cast<int>(nTimeIter - TimeIter);
4231+
CAROM::Options svd_options = CAROM::Options(dim, timesteps, -1,
4232+
false, true).setMaxBasisDimension(int(maxBasisDim));
4233+
4234+
if (config->GetKind_PODBasis() == POD_KIND::STATIC) {
4235+
if (rank == MASTER_NODE) std::cout << "Creating static basis generator." << std::endl;
4236+
4237+
if (unsteady) {
4238+
if (rank == MASTER_NODE) std::cout << "Incremental basis generator recommended for unsteady simulations." << std::endl;
4239+
}
4240+
}
4241+
else {
4242+
if (rank == MASTER_NODE) std::cout << "Creating incremental basis generator." << std::endl;
4243+
4244+
svd_options.setIncrementalSVD(1.0e-3, config->GetDelta_UnstTime(),
4245+
1.0e-2, config->GetDelta_UnstTime()*nTimeIter, true).setDebugMode(false);
4246+
incremental = true;
4247+
}
4248+
4249+
u_basis_generator.reset(new CAROM::BasisGenerator(
4250+
svd_options, incremental,
4251+
filename));
4252+
4253+
// Save mesh ordering
4254+
std::ofstream f;
4255+
f.open(filename + "_mesh_" + to_string(rank) + ".csv");
4256+
for (unsigned long iPoint = 0; iPoint < nPointDomain; iPoint++) {
4257+
unsigned long globalPoint = geometry->nodes->GetGlobalIndex(iPoint);
4258+
auto Coord = geometry->nodes->GetCoord(iPoint);
4259+
4260+
for (unsigned long iDim; iDim < nDim; iDim++) {
4261+
f << Coord[iDim] << ", ";
4262+
}
4263+
f << globalPoint << "\n";
4264+
}
4265+
f.close();
4266+
}
4267+
4268+
if (unsteady && (TimeIter % save_freq == 0)) {
4269+
// give solution and time steps to libROM:
4270+
su2double dt = config->GetDelta_UnstTime();
4271+
su2double t = config->GetCurrent_UnstTime();
4272+
u_basis_generator->takeSample(const_cast<su2double*>(base_nodes->GetSolution().data()), t, dt);
4273+
}
4274+
4275+
/*--- End collection of data and save POD ---*/
4276+
4277+
if (converged) {
4278+
4279+
if (!unsteady) {
4280+
// dt is different for each node, so just use a placeholder dt
4281+
su2double dt = base_nodes->GetDelta_Time(0);
4282+
su2double t = dt*TimeIter;
4283+
u_basis_generator->takeSample(const_cast<su2double*>(base_nodes->GetSolution().data()), t, dt);
4284+
}
4285+
4286+
if (config->GetKind_PODBasis() == POD_KIND::STATIC) {
4287+
u_basis_generator->writeSnapshot();
4288+
}
4289+
4290+
if (rank == MASTER_NODE) std::cout << "Computing SVD" << std::endl;
4291+
int rom_dim = u_basis_generator->getSpatialBasis()->numColumns();
4292+
4293+
if (rank == MASTER_NODE) std::cout << "Basis dimension: " << rom_dim << std::endl;
4294+
u_basis_generator->endSamples();
4295+
4296+
if (rank == MASTER_NODE) std::cout << "ROM Sampling ended" << std::endl;
4297+
}
4298+
4299+
#else
4300+
SU2_MPI::Error("SU2 was not compiled with libROM support.", CURRENT_FUNCTION);
4301+
#endif
4302+
4303+
}

config_template.cfg

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,3 +1692,21 @@ DEFINITION_DV= ( 1, 1.0 | airfoil | 0, 0.05 ); ( 1, 1.0 | airfoil | 0, 0.10 ); (
16921692
%
16931693
% Use combined objective within gradient evaluation: may reduce cost to compute gradients when using the adjoint formulation.
16941694
OPT_COMBINE_OBJECTIVE = NO
1695+
%
1696+
% --------------------- LIBROM PARAMETERS -----------------------%
1697+
% LibROM can be found here: https://github.com/LLNL/libROM
1698+
%
1699+
% Toggle saving to librom (NO, YES)
1700+
SAVE_LIBROM = NO
1701+
%
1702+
% Prefix to the saved libROM files (default: su2)
1703+
LIBROM_BASE_FILENAME = su2
1704+
%
1705+
% Specify POD basis generation algorithm (STATIC_POD, INCREMENTAL_POD)
1706+
% STATIC_POD recommended for steady problems
1707+
BASIS_GENERATION = STATIC_POD
1708+
%
1709+
% Maximum number of basis vectors to keep (default: 100)
1710+
MAX_BASIS_DIM = 100
1711+
%
1712+

meson.build

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ elif get_option('enable-openblas')
169169

170170
endif
171171

172+
if get_option('enable-librom')
173+
174+
assert(get_option('librom_root')!='',
175+
'Must specify librom folder (-Dlibrom_root=path/to/libROM)')
176+
177+
su2_cpp_args += '-DHAVE_LIBROM'
178+
179+
librom_root = get_option('librom_root')
180+
librom_dep = declare_dependency(include_directories: librom_root,
181+
link_args: ['-L'+librom_root+'/build', '-lROM'])
182+
183+
su2_deps += librom_dep
184+
185+
endif
186+
172187
extra_deps = get_option('extra-deps').split(',')
173188
foreach dep : extra_deps
174189
if dep != ''
@@ -234,6 +249,7 @@ message('''---------------------------------------------------------------------
234249
OpenBlas: @8@
235250
PaStiX: @9@
236251
Mixed Float: @10@
252+
libROM: @11@
237253
238254
Please be sure to add the $SU2_HOME and $SU2_RUN environment variables,
239255
and update your $PATH (and $PYTHONPATH if applicable) with $SU2_RUN
@@ -245,10 +261,10 @@ message('''---------------------------------------------------------------------
245261
export PATH=$PATH:$SU2_RUN
246262
export PYTHONPATH=$PYTHONPATH:$SU2_RUN
247263
248-
Use './ninja -C @11@ install' to compile and install SU2
264+
Use './ninja -C @12@ install' to compile and install SU2
249265
'''.format(get_option('prefix')+'/bin', meson.source_root(), get_option('enable-tecio'), get_option('enable-cgns'),
250266
get_option('enable-autodiff'), get_option('enable-directdiff'), get_option('enable-pywrapper'), get_option('enable-mkl'),
251-
get_option('enable-openblas'), get_option('enable-pastix'), get_option('enable-mixedprec'), meson.build_root().split('/')[-1]))
267+
get_option('enable-openblas'), get_option('enable-pastix'), get_option('enable-mixedprec'), get_option('enable-librom'), meson.build_root().split('/')[-1]))
252268

253269
if get_option('enable-mpp')
254270
message(''' To run SU2 with Mutation++ library, add these lines to your .bashrc file:
@@ -258,3 +274,12 @@ if get_option('enable-mpp')
258274
259275
''')
260276
endif
277+
278+
if get_option('enable-librom')
279+
message(''' To run SU2 with libROM library, add this line to your .bashrc file:
280+
281+
export LD_LIBRARY_PATH=@0@/build/:$LD_LIBRARY_PATH
282+
283+
'''.format(get_option('librom_root')))
284+
285+
endif

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ option('enable-mixedprec', type : 'boolean', value : false, description: 'use si
1919
option('extra-deps', type : 'string', value : '', description: 'comma-separated list of extra (custom) dependencies to add for compilation')
2020
option('enable-mpp', type : 'boolean', value : false, description: 'enable Mutation++ support')
2121
option('opdi-backend', type : 'combo', choices : ['auto', 'macro', 'ompt'], value : 'auto', description: 'OpDiLib backend choice')
22+
option('librom_root', type : 'string', value : '', description: 'libROM base directory')
23+
option('enable-librom', type : 'boolean', value : false, description: 'enable LLNL libROM support')

0 commit comments

Comments
 (0)