Skip to content

Commit 49e7a81

Browse files
authored
Merge branch 'develop' into feature_small_restart
2 parents cedd0b3 + dc6fd60 commit 49e7a81

File tree

15 files changed

+214
-183
lines changed

15 files changed

+214
-183
lines changed

Common/include/toolboxes/geometry_toolbox.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ inline T Norm(Int nDim, const T* a) {
7979
return sqrt(SquaredNorm(nDim, a));
8080
}
8181

82+
/*! \brief dn = max(abs(n.(a-b)), 0.05 * ||a-b|| */
83+
template <class T, typename Int>
84+
inline T NormalDistance(Int nDim, const T* n, const T* a, const T* b) {
85+
T d[3] = {0};
86+
Distance(nDim, a, b, d);
87+
return fmax(fabs(DotProduct(nDim, n, d)), 0.05 * Norm(nDim, d));
88+
}
89+
8290
/*! \brief c = a x b */
8391
template <class T>
8492
inline void CrossProduct(const T* a, const T* b, T* c) {

SU2_CFD/include/numerics/turbulent/turb_sources.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,19 @@ struct Bsl {
345345

346346
/*--- Limiting of \hat{S} based on "Modifications and Clarifications for the Implementation of the Spalart-Allmaras Turbulence Model"
347347
* Note 1 option c in https://turbmodels.larc.nasa.gov/spalart.html ---*/
348+
const su2double d_Sbar = (var.fv2 + nue * var.d_fv2) * var.inv_k2_d2;
348349
if (Sbar >= - c2 * var.Omega) {
349350
var.Shat = var.Omega + Sbar;
351+
var.d_Shat = d_Sbar;
350352
} else {
351353
const su2double Num = var.Omega * (c2 * c2 * var.Omega + c3 * Sbar);
352354
const su2double Den = (c3 - 2 * c2) * var.Omega - Sbar;
353355
var.Shat = var.Omega + Num / Den;
356+
var.d_Shat = d_Sbar * (c3 * var.Omega + Num / Den) / Den;
354357
}
355358
if (var.Shat <= 1e-10) {
356359
var.Shat = 1e-10;
357360
var.d_Shat = 0.0;
358-
} else {
359-
var.d_Shat = (var.fv2 + nue * var.d_fv2) * var.inv_k2_d2;
360361
}
361362
}
362363
};

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,12 +2357,11 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
23572357
const su2double *Coord = nullptr, *Coord_Normal = nullptr, *Normal = nullptr;
23582358
const su2double minYPlus = config->GetwallModel_MinYPlus();
23592359

2360-
string Marker_Tag, Monitoring_Tag;
2361-
23622360
const su2double Alpha = config->GetAoA() * PI_NUMBER / 180.0;
23632361
const su2double Beta = config->GetAoS() * PI_NUMBER / 180.0;
23642362
const su2double RefLength = config->GetRefLength();
23652363
const su2double RefHeatFlux = config->GetHeat_Flux_Ref();
2364+
const su2double RefTemperature = config->GetTemperature_Ref();
23662365
const su2double Gas_Constant = config->GetGas_ConstantND();
23672366
auto Origin = config->GetRefOriginMoment(0);
23682367

@@ -2393,15 +2392,17 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
23932392

23942393
for (iMarker = 0; iMarker < nMarker; iMarker++) {
23952394

2396-
Marker_Tag = config->GetMarker_All_TagBound(iMarker);
23972395
if (!config->GetViscous_Wall(iMarker)) continue;
2396+
const auto Marker_Tag = config->GetMarker_All_TagBound(iMarker);
2397+
2398+
const bool py_custom = config->GetMarker_All_PyCustom(iMarker);
23982399

23992400
/*--- Obtain the origin for the moment computation for a particular marker ---*/
24002401

24012402
const auto Monitoring = config->GetMarker_All_Monitoring(iMarker);
24022403
if (Monitoring == YES) {
24032404
for (iMarker_Monitoring = 0; iMarker_Monitoring < config->GetnMarker_Monitoring(); iMarker_Monitoring++) {
2404-
Monitoring_Tag = config->GetMarker_Monitoring_TagBound(iMarker_Monitoring);
2405+
const auto Monitoring_Tag = config->GetMarker_Monitoring_TagBound(iMarker_Monitoring);
24052406
if (Marker_Tag == Monitoring_Tag) Origin = config->GetRefOriginMoment(iMarker_Monitoring);
24062407
}
24072408
}
@@ -2506,26 +2507,47 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
25062507

25072508
/*--- Compute total and maximum heat flux on the wall ---*/
25082509

2509-
su2double dTdn = -GeometryToolbox::DotProduct(nDim, Grad_Temp, UnitNormal);
2510-
2511-
if (!nemo){
2512-
2510+
if (!nemo) {
25132511
if (FlowRegime == ENUM_REGIME::COMPRESSIBLE) {
2514-
25152512
Cp = (Gamma / Gamma_Minus_One) * Gas_Constant;
25162513
thermal_conductivity = Cp * Viscosity / Prandtl_Lam;
25172514
}
25182515
if (FlowRegime == ENUM_REGIME::INCOMPRESSIBLE) {
2519-
if (!energy) dTdn = 0.0;
25202516
thermal_conductivity = nodes->GetThermalConductivity(iPoint);
25212517
}
2522-
HeatFlux[iMarker][iVertex] = -thermal_conductivity * dTdn * RefHeatFlux;
25232518

2519+
if (config->GetMarker_All_KindBC(iMarker) == BC_TYPE::HEAT_FLUX) {
2520+
if (py_custom) {
2521+
HeatFlux[iMarker][iVertex] = -geometry->GetCustomBoundaryHeatFlux(iMarker, iVertex);
2522+
} else {
2523+
HeatFlux[iMarker][iVertex] = -config->GetWall_HeatFlux(Marker_Tag);
2524+
if (config->GetIntegrated_HeatFlux()) {
2525+
HeatFlux[iMarker][iVertex] /= geometry->GetSurfaceArea(config, iMarker);
2526+
}
2527+
}
2528+
} else if (config->GetMarker_All_KindBC(iMarker) == BC_TYPE::ISOTHERMAL) {
2529+
su2double Twall = 0.0;
2530+
if (py_custom) {
2531+
Twall = geometry->GetCustomBoundaryTemperature(iMarker, iVertex) / RefTemperature;
2532+
} else {
2533+
Twall = config->GetIsothermal_Temperature(Marker_Tag) / RefTemperature;
2534+
}
2535+
iPointNormal = geometry->vertex[iMarker][iVertex]->GetNormal_Neighbor();
2536+
Coord_Normal = geometry->nodes->GetCoord(iPointNormal);
2537+
const su2double dist_ij = GeometryToolbox::NormalDistance(nDim, UnitNormal, Coord, Coord_Normal);
2538+
const su2double There = nodes->GetTemperature(iPointNormal);
2539+
HeatFlux[iMarker][iVertex] = thermal_conductivity * (There - Twall) / dist_ij * RefHeatFlux;
2540+
} else {
2541+
su2double dTdn = GeometryToolbox::DotProduct(nDim, Grad_Temp, UnitNormal);
2542+
if (FlowRegime == ENUM_REGIME::INCOMPRESSIBLE && !energy) dTdn = 0.0;
2543+
HeatFlux[iMarker][iVertex] = thermal_conductivity * dTdn * RefHeatFlux;
2544+
}
25242545
} else {
25252546

25262547
const auto& thermal_conductivity_tr = nodes->GetThermalConductivity(iPoint);
25272548
const auto& thermal_conductivity_ve = nodes->GetThermalConductivity_ve(iPoint);
25282549

2550+
const su2double dTdn = -GeometryToolbox::DotProduct(nDim, Grad_Temp, UnitNormal);
25292551
const su2double dTvedn = -GeometryToolbox::DotProduct(nDim, Grad_Temp_ve, UnitNormal);
25302552

25312553
/*--- Surface energy balance: trans-rot heat flux, vib-el heat flux ---*/
@@ -2653,8 +2675,7 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
26532675
/*--- Compute the coefficients per surface ---*/
26542676

26552677
for (iMarker_Monitoring = 0; iMarker_Monitoring < config->GetnMarker_Monitoring(); iMarker_Monitoring++) {
2656-
Monitoring_Tag = config->GetMarker_Monitoring_TagBound(iMarker_Monitoring);
2657-
Marker_Tag = config->GetMarker_All_TagBound(iMarker);
2678+
const auto Monitoring_Tag = config->GetMarker_Monitoring_TagBound(iMarker_Monitoring);
26582679
if (Marker_Tag == Monitoring_Tag) {
26592680
SurfaceViscCoeff.CL[iMarker_Monitoring] += ViscCoeff.CL[iMarker];
26602681
SurfaceViscCoeff.CD[iMarker_Monitoring] += ViscCoeff.CD[iMarker];

SU2_CFD/src/solvers/CIncNSSolver.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ void CIncNSSolver::BC_Wall_Generic(const CGeometry *geometry, const CConfig *con
341341
/*--- Variables for streamwise periodicity ---*/
342342
const bool streamwise_periodic = (config->GetKind_Streamwise_Periodic() != ENUM_STREAMWISE_PERIODIC::NONE);
343343
const bool streamwise_periodic_temperature = config->GetStreamwise_Periodic_Temperature();
344-
su2double Cp, thermal_conductivity, dot_product, scalar_factor;
345344

346345
/*--- Identify the boundary by string name ---*/
347346

@@ -434,15 +433,17 @@ void CIncNSSolver::BC_Wall_Generic(const CGeometry *geometry, const CConfig *con
434433
/*--- With streamwise periodic flow and heatflux walls an additional term is introduced in the boundary formulation ---*/
435434
if (streamwise_periodic && streamwise_periodic_temperature) {
436435

437-
Cp = nodes->GetSpecificHeatCp(iPoint);
438-
thermal_conductivity = nodes->GetThermalConductivity(iPoint);
436+
const su2double Cp = nodes->GetSpecificHeatCp(iPoint);
437+
const su2double thermal_conductivity = nodes->GetThermalConductivity(iPoint);
439438

440439
/*--- Scalar factor of the residual contribution ---*/
441440
const su2double norm2_translation = GeometryToolbox::SquaredNorm(nDim, config->GetPeriodic_Translation(0));
442-
scalar_factor = SPvals.Streamwise_Periodic_IntegratedHeatFlow*thermal_conductivity / (SPvals.Streamwise_Periodic_MassFlow * Cp * norm2_translation);
441+
const su2double scalar_factor =
442+
SPvals.Streamwise_Periodic_IntegratedHeatFlow*thermal_conductivity /
443+
(SPvals.Streamwise_Periodic_MassFlow * Cp * norm2_translation);
443444

444445
/*--- Dot product ---*/
445-
dot_product = GeometryToolbox::DotProduct(nDim, config->GetPeriodic_Translation(0), Normal);
446+
const su2double dot_product = GeometryToolbox::DotProduct(nDim, config->GetPeriodic_Translation(0), Normal);
446447

447448
LinSysRes(iPoint, nDim+1) += scalar_factor*dot_product;
448449
} // if streamwise_periodic
@@ -472,18 +473,17 @@ void CIncNSSolver::BC_Wall_Generic(const CGeometry *geometry, const CConfig *con
472473

473474
const auto Coord_i = geometry->nodes->GetCoord(iPoint);
474475
const auto Coord_j = geometry->nodes->GetCoord(Point_Normal);
475-
su2double Edge_Vector[MAXNDIM];
476-
GeometryToolbox::Distance(nDim, Coord_j, Coord_i, Edge_Vector);
477-
su2double dist_ij_2 = GeometryToolbox::SquaredNorm(nDim, Edge_Vector);
478-
su2double dist_ij = sqrt(dist_ij_2);
476+
su2double UnitNormal[MAXNDIM] = {0.0};
477+
for (auto iDim = 0u; iDim < nDim; ++iDim) UnitNormal[iDim] = Normal[iDim] / Area;
478+
const su2double dist_ij = GeometryToolbox::NormalDistance(nDim, UnitNormal, Coord_i, Coord_j);
479479

480480
/*--- Compute the normal gradient in temperature using Twall ---*/
481481

482-
su2double dTdn = -(nodes->GetTemperature(Point_Normal) - Twall)/dist_ij;
482+
const su2double dTdn = -(nodes->GetTemperature(Point_Normal) - Twall)/dist_ij;
483483

484484
/*--- Get thermal conductivity ---*/
485485

486-
su2double thermal_conductivity = nodes->GetThermalConductivity(iPoint);
486+
const su2double thermal_conductivity = nodes->GetThermalConductivity(iPoint);
487487

488488
/*--- Apply a weak boundary condition for the energy equation.
489489
Compute the residual due to the prescribed heat flux. ---*/
@@ -493,10 +493,7 @@ void CIncNSSolver::BC_Wall_Generic(const CGeometry *geometry, const CConfig *con
493493
/*--- Jacobian contribution for temperature equation. ---*/
494494

495495
if (implicit) {
496-
su2double proj_vector_ij = 0.0;
497-
if (dist_ij_2 > 0.0)
498-
proj_vector_ij = GeometryToolbox::DotProduct(nDim, Edge_Vector, Normal) / dist_ij_2;
499-
Jacobian.AddVal2Diag(iPoint, nDim+1, thermal_conductivity*proj_vector_ij);
496+
Jacobian.AddVal2Diag(iPoint, nDim+1, thermal_conductivity * Area / dist_ij);
500497
}
501498
break;
502499
} // switch

SU2_CFD/src/solvers/CNSSolver.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -672,22 +672,19 @@ void CNSSolver::BC_Isothermal_Wall_Generic(CGeometry *geometry, CSolver **solver
672672

673673
const auto Coord_i = geometry->nodes->GetCoord(iPoint);
674674
const auto Coord_j = geometry->nodes->GetCoord(Point_Normal);
675-
676-
su2double dist_ij = GeometryToolbox::Distance(nDim, Coord_i, Coord_j);
675+
const su2double dist_ij = GeometryToolbox::NormalDistance(nDim, UnitNormal, Coord_i, Coord_j);
677676

678677
/*--- Store the corrected velocity at the wall which will
679678
be zero (v = 0), unless there is grid motion (v = u_wall)---*/
680679

681680
if (dynamic_grid) {
682681
nodes->SetVelocity_Old(iPoint, geometry->nodes->GetGridVel(iPoint));
683-
}
684-
else {
682+
} else {
685683
su2double zero[MAXNDIM] = {0.0};
686684
nodes->SetVelocity_Old(iPoint, zero);
687685
}
688686

689-
for (auto iDim = 0u; iDim < nDim; iDim++)
690-
LinSysRes(iPoint, iDim+1) = 0.0;
687+
for (auto iDim = 0u; iDim < nDim; iDim++) LinSysRes(iPoint, iDim+1) = 0.0;
691688
nodes->SetVel_ResTruncError_Zero(iPoint);
692689

693690
/*--- Get transport coefficients ---*/
@@ -708,8 +705,7 @@ void CNSSolver::BC_Isothermal_Wall_Generic(CGeometry *geometry, CSolver **solver
708705
if (cht_mode) {
709706
Twall = GetCHTWallTemperature(config, val_marker, iVertex, dist_ij,
710707
thermal_conductivity, There, Temperature_Ref);
711-
}
712-
else if (config->GetMarker_All_PyCustom(val_marker)) {
708+
} else if (config->GetMarker_All_PyCustom(val_marker)) {
713709
Twall = geometry->GetCustomBoundaryTemperature(val_marker, iVertex) / Temperature_Ref;
714710
}
715711

SU2_CFD/src/solvers/CSolver.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,7 +3163,8 @@ void CSolver::InterpolateRestartData(const CGeometry *geometry, const CConfig *c
31633163
const unsigned long nFields = Restart_Vars[1];
31643164
const unsigned long nPointFile = Restart_Vars[2];
31653165
const auto t0 = SU2_MPI::Wtime();
3166-
auto nRecurse = 0;
3166+
int nRecurse = 0;
3167+
const int maxNRecurse = 128;
31673168

31683169
if (rank == MASTER_NODE) {
31693170
cout << "\nThe number of points in the restart file (" << nPointFile << ") does not match "
@@ -3262,7 +3263,7 @@ void CSolver::InterpolateRestartData(const CGeometry *geometry, const CConfig *c
32623263
bool done = false;
32633264

32643265
SU2_OMP_PARALLEL
3265-
while (!done) {
3266+
while (!done && nRecurse < maxNRecurse) {
32663267
SU2_OMP_FOR_DYN(roundUpDiv(nPointDomain,2*omp_get_num_threads()))
32673268
for (auto iPoint = 0ul; iPoint < nPointDomain; ++iPoint) {
32683269
/*--- Do not change points that are already interpolated. ---*/
@@ -3273,7 +3274,8 @@ void CSolver::InterpolateRestartData(const CGeometry *geometry, const CConfig *c
32733274

32743275
for (const auto jPoint : geometry->nodes->GetPoints(iPoint)) {
32753276
if (!isMapped[jPoint]) continue;
3276-
if (boundary_i != geometry->nodes->GetSolidBoundary(jPoint)) continue;
3277+
/*--- Take data from anywhere if we are looping too many times. ---*/
3278+
if (boundary_i != geometry->nodes->GetSolidBoundary(jPoint) && nRecurse < 8) continue;
32773279

32783280
nDonor[iPoint]++;
32793281

@@ -3315,6 +3317,10 @@ void CSolver::InterpolateRestartData(const CGeometry *geometry, const CConfig *c
33153317

33163318
} // everything goes out of scope except "localVars"
33173319

3320+
if (nRecurse == maxNRecurse) {
3321+
SU2_MPI::Error("Limit number of recursions reached, the meshes may be too different.", CURRENT_FUNCTION);
3322+
}
3323+
33183324
/*--- Move to Restart_Data in ascending order of global index, which is how a matching restart would have been read. ---*/
33193325

33203326
Restart_Data.resize(nPointDomain*nFields);
@@ -3329,9 +3335,11 @@ void CSolver::InterpolateRestartData(const CGeometry *geometry, const CConfig *c
33293335
counter++;
33303336
}
33313337
}
3338+
int nRecurseMax = 0;
3339+
SU2_MPI::Reduce(&nRecurse, &nRecurseMax, 1, MPI_INT, MPI_MAX, MASTER_NODE, SU2_MPI::GetComm());
33323340

33333341
if (rank == MASTER_NODE) {
3334-
cout << "Number of recursions: " << nRecurse << ".\n"
3342+
cout << "Number of recursions: " << nRecurseMax << ".\n"
33353343
"Elapsed time: " << SU2_MPI::Wtime()-t0 << "s.\n" << endl;
33363344
}
33373345
}

0 commit comments

Comments
 (0)