Skip to content

Commit 2756cfb

Browse files
committed
test, place custom_residual in CSolver
1 parent da794f4 commit 2756cfb

16 files changed

+269
-82
lines changed

Common/include/CConfig.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ class CConfig {
707707
Wrt_Restart_Overwrite, /*!< \brief Overwrite restart files or append iteration number.*/
708708
Wrt_Surface_Overwrite, /*!< \brief Overwrite surface output files or append iteration number.*/
709709
Wrt_Volume_Overwrite, /*!< \brief Overwrite volume output files or append iteration number.*/
710+
PyCustom_Source, /*!< \brief Use a user defined custom source term .*/
710711
Restart_Flow; /*!< \brief Restart flow solution for adjoint and linearized problems. */
711712
unsigned short nMarker_Monitoring, /*!< \brief Number of markers to monitor. */
712713
nMarker_Designing, /*!< \brief Number of markers for the objective function. */
@@ -3087,6 +3088,12 @@ class CConfig {
30873088
*/
30883089
unsigned short GetnMarker_PyCustom(void) const { return nMarker_PyCustom; }
30893090

3091+
/*!
3092+
* \brief Get the Python custom source term activation.
3093+
* \return Custom source term is active or not.
3094+
*/
3095+
bool GetPyCustom_Source(void) const { return PyCustom_Source; }
3096+
30903097
/*!
30913098
* \brief Get the total number of moving markers.
30923099
* \return Total number of moving markers.

Common/src/CConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,9 @@ void CConfig::SetConfig_Options() {
15481548
/*!\brief MARKER_PYTHON_CUSTOM\n DESCRIPTION: Python customizable marker(s) \ingroup Config*/
15491549
addStringListOption("MARKER_PYTHON_CUSTOM", nMarker_PyCustom, Marker_PyCustom);
15501550

1551+
/*!\brief PYTHON_CUSTOM_SOURCE\n DESCRIPTION: Python custom source \ingroup Config*/
1552+
addBoolOption("PYTHON_CUSTOM_SOURCE", PyCustom_Source, false);
1553+
15511554
/*!\brief MARKER_WALL_FUNCTIONS\n DESCRIPTION: Viscous wall markers for which wall functions must be applied.
15521555
Format: (Wall function marker, wall function type, ...) \ingroup Config*/
15531556
addWallFunctionOption("MARKER_WALL_FUNCTIONS", nMarker_WallFunctions, Marker_WallFunctions,

SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -316,36 +316,36 @@ class CFVMFlowSolverBase : public CSolver {
316316
}
317317

318318

319-
inline void Custom_Source_Residual(CGeometry *geometry, CSolver **solver_container,
320-
CNumerics **numerics_container, CConfig *config, unsigned short iMesh) {
319+
// inline void Custom_Source_Residual(CGeometry *geometry, CSolver **solver_container,
320+
// CNumerics **numerics_container, CConfig *config, unsigned short iMesh) {
321321

322-
/*--- Pick one numerics object per thread. ---*/
323-
CNumerics* numerics = numerics_container[SOURCE_SECOND_TERM + omp_get_thread_num()*MAX_TERMS];
322+
// /*--- Pick one numerics object per thread. ---*/
323+
// CNumerics* numerics = numerics_container[SOURCE_SECOND_TERM + omp_get_thread_num()*MAX_TERMS];
324324

325-
unsigned short iVar;
326-
unsigned long iPoint;
327-
AD::StartNoSharedReading();
325+
// unsigned short iVar;
326+
// unsigned long iPoint;
327+
// AD::StartNoSharedReading();
328328

329-
SU2_OMP_FOR_STAT(omp_chunk_size)
330-
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
329+
// SU2_OMP_FOR_STAT(omp_chunk_size)
330+
// for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
331331

332-
/*--- Load the volume of the dual mesh cell ---*/
332+
// /*--- Load the volume of the dual mesh cell ---*/
333333

334-
numerics->SetVolume(geometry->nodes->GetVolume(iPoint));
334+
// numerics->SetVolume(geometry->nodes->GetVolume(iPoint));
335335

336-
/*--- Get control volume size. ---*/
337-
su2double Volume = geometry->nodes->GetVolume(iPoint);
336+
// /*--- Get control volume size. ---*/
337+
// su2double Volume = geometry->nodes->GetVolume(iPoint);
338338

339-
/*--- Compute the residual for this control volume and subtract. ---*/
340-
for (iVar = 0; iVar < nVar; iVar++) {
341-
LinSysRes(iPoint, iVar) += nodes->GetUserDefinedSource(iPoint)[iVar] * Volume;
342-
}
343-
}
344-
END_SU2_OMP_FOR
339+
// /*--- Compute the residual for this control volume and subtract. ---*/
340+
// for (iVar = 0; iVar < nVar; iVar++) {
341+
// LinSysRes(iPoint, iVar) += nodes->GetUserDefinedSource(iPoint)[iVar] * Volume;
342+
// }
343+
// }
344+
// END_SU2_OMP_FOR
345345

346-
AD::EndNoSharedReading();
346+
// AD::EndNoSharedReading();
347347

348-
}
348+
// }
349349

350350

351351
/*!

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,11 +1573,11 @@ class CSolver {
15731573
* \param[in] config - Definition of the particular problem.
15741574
* \param[in] iMesh - Index of the mesh in multigrid computations.
15751575
*/
1576-
inline virtual void Custom_Source_Residual(CGeometry *geometry,
1577-
CSolver **solver_container,
1578-
CNumerics **numerics_container,
1579-
CConfig *config,
1580-
unsigned short iMesh) { }
1576+
// inline virtual void Custom_Source_Residual(CGeometry *geometry,
1577+
// CSolver **solver_container,
1578+
// CNumerics **numerics_container,
1579+
// CConfig *config,
1580+
// unsigned short iMesh) { }
15811581

15821582
/*!
15831583
* \brief A virtual member.
@@ -4346,6 +4346,35 @@ class CSolver {
43464346
END_SU2_OMP_FOR
43474347
}
43484348

4349+
/*--- Why not do this? ---*/
4350+
inline void Custom_Source_Residual(CGeometry *geometry, CSolver **solver_container,
4351+
CNumerics **numerics_container, CConfig *config, unsigned short iMesh) {
4352+
4353+
/*--- Pick one numerics object per thread. ---*/
4354+
CNumerics* numerics = numerics_container[SOURCE_SECOND_TERM + omp_get_thread_num()*MAX_TERMS];
4355+
4356+
unsigned short iVar;
4357+
unsigned long iPoint;
4358+
AD::StartNoSharedReading();
4359+
4360+
SU2_OMP_FOR_STAT(omp_chunk_size)
4361+
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
4362+
4363+
/*--- Load the volume of the dual mesh cell ---*/
4364+
numerics->SetVolume(geometry->nodes->GetVolume(iPoint));
4365+
4366+
/*--- Get control volume size. ---*/
4367+
su2double Volume = geometry->nodes->GetVolume(iPoint);
4368+
/*--- Compute the residual for this control volume and subtract. ---*/
4369+
for (iVar = 0; iVar < nVar; iVar++) {
4370+
LinSysRes(iPoint,iVar) -= base_nodes->GetUserDefinedSource(iPoint)[iVar] * Volume;
4371+
}
4372+
}
4373+
END_SU2_OMP_FOR
4374+
4375+
AD::EndNoSharedReading();
4376+
}
4377+
43494378
protected:
43504379
/*!
43514380
* \brief Allocate the memory for the verification solution, if necessary.

SU2_CFD/include/solvers/CSpeciesSolver.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class CSpeciesSolver : public CScalarSolver<CSpeciesVariable> {
170170
* \param[in] config - Definition of the particular problem.
171171
* \param[in] iMesh - Index of the mesh in multigrid computations.
172172
*/
173-
void Custom_Source_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, CConfig* config,
174-
unsigned short iMesh) override;
173+
// void Custom_Source_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, CConfig* config,
174+
// unsigned short iMesh) override;
175175

176176

177177
/*!

SU2_CFD/src/integration/CIntegration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void CIntegration::Space_Integration(CGeometry *geometry,
6464
solver_container[MainSolver]->Source_Residual(geometry, solver_container, numerics, config, iMesh);
6565

6666
/*--- Compute custom (python wrapper) source term residuals ---*/
67-
solver_container[MainSolver]->Custom_Source_Residual(geometry, solver_container, numerics, config, iMesh);
67+
//solver_container[MainSolver]->Custom_Source_Residual(geometry, solver_container, numerics, config, iMesh);
6868

6969
/*--- Add viscous and convective residuals, and compute the Dual Time Source term ---*/
7070

SU2_CFD/src/solvers/CEulerSolver.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,15 +2053,12 @@ void CEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain
20532053
/*--- Pick one numerics object per thread. ---*/
20542054
CNumerics* numerics = numerics_container[SOURCE_FIRST_TERM + omp_get_thread_num()*MAX_TERMS];
20552055

2056-
unsigned short iVar;
2057-
unsigned long iPoint;
2058-
20592056
if (body_force) {
20602057

20612058
/*--- Loop over all points ---*/
20622059
AD::StartNoSharedReading();
20632060
SU2_OMP_FOR_STAT(omp_chunk_size)
2064-
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
2061+
for (auto iPoint = 0; iPoint < nPointDomain; iPoint++) {
20652062

20662063
/*--- Load the conservative variables ---*/
20672064
numerics->SetConservative(nodes->GetSolution(iPoint),
@@ -2091,7 +2088,7 @@ void CEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain
20912088
/*--- Loop over all points ---*/
20922089
AD::StartNoSharedReading();
20932090
SU2_OMP_FOR_DYN(omp_chunk_size)
2094-
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
2091+
for (auto iPoint = 0; iPoint < nPointDomain; iPoint++) {
20952092

20962093
/*--- Load the conservative variables ---*/
20972094
numerics->SetConservative(nodes->GetSolution(iPoint),
@@ -2124,7 +2121,7 @@ void CEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain
21242121
/*--- loop over points ---*/
21252122
AD::StartNoSharedReading();
21262123
SU2_OMP_FOR_DYN(omp_chunk_size)
2127-
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
2124+
for (auto iPoint = 0; iPoint < nPointDomain; iPoint++) {
21282125

21292126
/*--- Set solution ---*/
21302127
numerics->SetConservative(nodes->GetSolution(iPoint), nodes->GetSolution(iPoint));
@@ -2177,7 +2174,7 @@ void CEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain
21772174

21782175
/*--- loop over points ---*/
21792176
SU2_OMP_FOR_DYN(omp_chunk_size)
2180-
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
2177+
for (auto iPoint = 0; iPoint < nPointDomain; iPoint++) {
21812178

21822179
/*--- Set solution ---*/
21832180
numerics->SetConservative(nodes->GetSolution(iPoint), nodes->GetSolution(iPoint));
@@ -2200,13 +2197,13 @@ void CEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain
22002197

22012198
/*--- loop over points ---*/
22022199
SU2_OMP_FOR_STAT(omp_chunk_size)
2203-
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
2200+
for (auto iPoint = 0; iPoint < nPointDomain; iPoint++) {
22042201

22052202
/*--- Get control volume ---*/
22062203
su2double Volume = geometry->nodes->GetVolume(iPoint);
22072204

22082205
/*--- Get stored time spectral source term and add to residual ---*/
2209-
for (iVar = 0; iVar < nVar; iVar++) {
2206+
for (auto iVar = 0; iVar < nVar; iVar++) {
22102207
LinSysRes(iPoint,iVar) += Volume * nodes->GetHarmonicBalance_Source(iPoint,iVar);
22112208
}
22122209
}
@@ -2223,7 +2220,7 @@ void CEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain
22232220

22242221
/*--- set vorticity magnitude as auxilliary variable ---*/
22252222
SU2_OMP_FOR_STAT(omp_chunk_size)
2226-
for (iPoint = 0; iPoint < nPoint; iPoint++) {
2223+
for (auto iPoint = 0; iPoint < nPoint; iPoint++) {
22272224
const su2double VorticityMag = max(GeometryToolbox::Norm(3, nodes->GetVorticity(iPoint)), 1e-12);
22282225
nodes->SetAuxVar(iPoint, 0, VorticityMag);
22292226
}
@@ -2233,7 +2230,7 @@ void CEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain
22332230
SetAuxVar_Gradient_GG(geometry, config);
22342231

22352232
SU2_OMP_FOR_DYN(omp_chunk_size)
2236-
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
2233+
for (auto iPoint = 0; iPoint < nPointDomain; iPoint++) {
22372234
second_numerics->SetPrimitive(nodes->GetPrimitive(iPoint), nullptr);
22382235
second_numerics->SetVorticity(nodes->GetVorticity(iPoint), nullptr);
22392236
second_numerics->SetAuxVarGrad(nodes->GetAuxVarGradient(iPoint), nullptr);
@@ -2260,7 +2257,7 @@ void CEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain
22602257

22612258
/*--- Loop over points ---*/
22622259
SU2_OMP_FOR_DYN(omp_chunk_size)
2263-
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
2260+
for (auto iPoint = 0; iPoint < nPointDomain; iPoint++) {
22642261

22652262
/*--- Get control volume size. ---*/
22662263
su2double Volume = geometry->nodes->GetVolume(iPoint);
@@ -2273,14 +2270,34 @@ void CEulerSolver::Source_Residual(CGeometry *geometry, CSolver **solver_contain
22732270
VerificationSolution->GetMMSSourceTerm(coor, time, sourceMan.data());
22742271

22752272
/*--- Compute the residual for this control volume and subtract. ---*/
2276-
for (iVar = 0; iVar < nVar; iVar++) {
2273+
for (auto iVar = 0; iVar < nVar; iVar++) {
22772274
LinSysRes(iPoint,iVar) -= sourceMan[iVar]*Volume;
22782275
}
22792276
}
22802277
END_SU2_OMP_FOR
22812278
}
22822279
}
22832280

2281+
/*--- Custom user defined source term (from the python wrapper) ---*/
2282+
if (config->GetPyCustom_Source() ) {
2283+
SU2_OMP_FOR_STAT(omp_chunk_size)
2284+
for (auto iPoint = 0; iPoint < nPointDomain; iPoint++) {
2285+
2286+
/*--- Load the volume of the dual mesh cell ---*/
2287+
2288+
numerics->SetVolume(geometry->nodes->GetVolume(iPoint));
2289+
2290+
/*--- Get control volume size. ---*/
2291+
su2double Volume = geometry->nodes->GetVolume(iPoint);
2292+
2293+
/*--- Compute the residual for this control volume and subtract. ---*/
2294+
for (auto iVar = 0; iVar < nVar; iVar++) {
2295+
LinSysRes(iPoint, iVar) += nodes->GetUserDefinedSource(iPoint)[iVar] * Volume;
2296+
}
2297+
}
2298+
END_SU2_OMP_FOR
2299+
}
2300+
22842301
AD::EndNoSharedReading();
22852302
}
22862303

0 commit comments

Comments
 (0)