Skip to content

Commit 537783b

Browse files
authored
Merge pull request #2392 from su2code/fix_cornernode_normal
Fix cornernode normal
2 parents c725fc1 + c5527d3 commit 537783b

File tree

24 files changed

+274
-231
lines changed

24 files changed

+274
-231
lines changed

Common/include/geometry/CMultiGridGeometry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class CMultiGridGeometry final : public CGeometry {
123123
void SetRestricted_GridVelocity(const CGeometry* fine_grid) override;
124124

125125
/*!
126-
* \brief Find and store the closest neighbor to a vertex.
126+
* \brief Find and store the closest, most normal, neighbor to a vertex.
127127
* \param[in] config - Definition of the particular problem.
128128
*/
129129
void FindNormal_Neighbor(const CConfig* config) override;

Common/include/geometry/CPhysicalGeometry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ class CPhysicalGeometry final : public CGeometry {
607607
void ComputeMeshQualityStatistics(const CConfig* config) override;
608608

609609
/*!
610-
* \brief Find and store the closest neighbor to a vertex.
610+
* \brief Find and store the closest, most normal, neighbor to a vertex.
611611
* \param[in] config - Definition of the particular problem.
612612
*/
613613
void FindNormal_Neighbor(const CConfig* config) override;

Common/include/geometry/dual_grid/CVertex.hpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class CVertex : public CDualGrid {
4545
long PeriodicPoint[5] = {-1}; /*!< \brief Store the periodic point of a boundary (iProcessor, iPoint) */
4646
bool ActDisk_Perimeter = false; /*!< \brief Identify nodes at the perimeter of the actuator disk */
4747
short Rotation_Type; /*!< \brief Type of rotation associated with the vertex (MPI and periodic) */
48-
unsigned long Normal_Neighbor; /*!< \brief Index of the closest neighbor. */
48+
unsigned long Normal_Neighbor; /*!< \brief Index of the closest, most normal, neighbor. */
49+
su2double NearestNeighborDist = 0.0; /*!< \brief Distance to nearest internal neighbor that is not a wall. */
4950
su2double Basis_Function[3] = {0.0}; /*!< \brief Basis function values for interpolation across zones. */
5051

5152
public:
@@ -98,7 +99,7 @@ class CVertex : public CDualGrid {
9899
* \brief Get the normal to a face of the control volume asociated with a vertex.
99100
* \return Dimensional normal vector, the modulus is the area of the face.
100101
*/
101-
inline su2double* GetNormal(void) override { return Normal; }
102+
inline su2double* GetNormal() override { return Normal; }
102103

103104
/*!
104105
* \brief Get the ith component of the normal.
@@ -108,7 +109,7 @@ class CVertex : public CDualGrid {
108109
/*!
109110
* \brief Initialize normal vector.
110111
*/
111-
inline void SetZeroValues(void) override {
112+
inline void SetZeroValues() override {
112113
for (unsigned short iDim = 0; iDim < nDim; iDim++) Normal[iDim] = 0.0;
113114
}
114115

@@ -122,7 +123,7 @@ class CVertex : public CDualGrid {
122123
* \brief Get the value of an auxiliary variable for gradient computation.
123124
* \return Value of the auxiliar variable.
124125
*/
125-
inline su2double GetAuxVar(void) const { return Aux_Var; }
126+
inline su2double GetAuxVar() const { return Aux_Var; }
126127

127128
/*!
128129
* \brief Add the value of an auxiliary variable for gradient computation.
@@ -167,7 +168,7 @@ class CVertex : public CDualGrid {
167168
* \brief Get the value of the coordinate variation due to a surface modification.
168169
* \return Variation of the coordinate.
169170
*/
170-
inline su2double* GetVarCoord(void) { return VarCoord; }
171+
inline su2double* GetVarCoord() { return VarCoord; }
171172

172173
/*!
173174
* \brief Set the value of the cartesian coordinate for the vertex.
@@ -181,7 +182,7 @@ class CVertex : public CDualGrid {
181182
* \brief Get the value of the cartesian coordinate for the vertex.
182183
* \return Value of the cartesian coordinate of the vertex.
183184
*/
184-
inline su2double* GetCoord(void) override { return CartCoord; }
185+
inline su2double* GetCoord() override { return CartCoord; }
185186

186187
/*!
187188
* \brief Get the value of the cartesian coordinate for the vertex.
@@ -200,7 +201,7 @@ class CVertex : public CDualGrid {
200201
* \brief Get the type of rotation associated to the vertex.
201202
* \return Value of the rotation that must be applied to the solution of the vertex
202203
*/
203-
inline short GetRotation_Type(void) const { return Rotation_Type; }
204+
inline short GetRotation_Type() const { return Rotation_Type; }
204205

205206
/*!
206207
* \overload
@@ -250,49 +251,49 @@ class CVertex : public CDualGrid {
250251
* \brief Get the value of the periodic point of a vertex.
251252
* \return Value of the periodic point of a vertex.
252253
*/
253-
inline long GetDonorPoint(void) const { return PeriodicPoint[0]; }
254+
inline long GetDonorPoint() const { return PeriodicPoint[0]; }
254255

255256
/*!
256257
* \brief Get the value of the periodic point of a vertex.
257258
* \return Value of the periodic point of a vertex.
258259
*/
259-
inline long GetDonorMarker(void) const { return PeriodicPoint[4]; }
260+
inline long GetDonorMarker() const { return PeriodicPoint[4]; }
260261

261262
/*!
262263
* \brief Get the value of the periodic point of a vertex.
263264
* \return Value of the periodic point of a vertex.
264265
*/
265-
inline long GetDonorVertex(void) const { return PeriodicPoint[3]; }
266+
inline long GetDonorVertex() const { return PeriodicPoint[3]; }
266267

267268
/*!
268269
* \brief Get the value of the periodic point of a vertex.
269270
* \return Value of the periodic point of a vertex.
270271
*/
271-
inline long GetDonorGlobalIndex(void) const { return PeriodicPoint[2]; }
272+
inline long GetDonorGlobalIndex() const { return PeriodicPoint[2]; }
272273

273274
/*!
274275
* \brief Get the value of the periodic point of a vertex.
275276
* \return Value of the periodic point of a vertex.
276277
*/
277-
inline long GetGlobalDonorPoint(void) const { return PeriodicPoint[2]; }
278+
inline long GetGlobalDonorPoint() const { return PeriodicPoint[2]; }
278279

279280
/*!
280281
* \brief Get the value of the periodic point of a vertex.
281282
* \return Value of the periodic point of a vertex.
282283
*/
283-
inline long GetDonorProcessor(void) const { return PeriodicPoint[1]; }
284+
inline long GetDonorProcessor() const { return PeriodicPoint[1]; }
284285

285286
/*!
286287
* \brief Get the value of the periodic point of a vertex, and its somain
287288
* \return Value of the periodic point of a vertex, and the domain.
288289
*/
289-
inline long* GetPeriodicPointDomain(void) { return PeriodicPoint; }
290+
inline long* GetPeriodicPointDomain() { return PeriodicPoint; }
290291

291292
/*!
292293
* \brief Get the value of the periodic point of a vertex, and its somain
293294
* \return Value of the periodic point of a vertex, and the domain.
294295
*/
295-
inline bool GetActDisk_Perimeter(void) const { return ActDisk_Perimeter; }
296+
inline bool GetActDisk_Perimeter() const { return ActDisk_Perimeter; }
296297

297298
/*!
298299
* \brief Set the finite element basis functions needed for interpolation.
@@ -318,5 +319,15 @@ class CVertex : public CDualGrid {
318319
* \brief Get the value of the closest neighbor.
319320
* \return Index of the closest neighbor.
320321
*/
321-
inline unsigned long GetNormal_Neighbor(void) const { return Normal_Neighbor; }
322+
inline unsigned long GetNormal_Neighbor() const { return Normal_Neighbor; }
323+
324+
/*!
325+
* \brief Set the distance of the nearest internal neighbor that is not a wall.
326+
*/
327+
inline void SetNearestNeighborDistance(const su2double& val) { NearestNeighborDist = val; }
328+
329+
/*!
330+
* \brief Get the distance to the nearest internal neighbor that is not a wall.
331+
*/
332+
inline const su2double& GetNearestNeighborDistance() const { return NearestNeighborDist; }
322333
};

Common/src/geometry/CGeometry.cpp

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,36 @@ const CGeometry::CLineletInfo& CGeometry::GetLineletInfo(const CConfig* config)
39023902
return li;
39033903
}
39043904

3905+
namespace {
3906+
su2double NearestNeighborDistance(CGeometry* geometry, const CConfig* config, const unsigned long iPoint) {
3907+
const su2double max = std::numeric_limits<su2double>::max();
3908+
su2double distance = max;
3909+
for (const auto jPoint : geometry->nodes->GetPoints(iPoint)) {
3910+
const su2double dist = geometry->nodes->GetWall_Distance(jPoint);
3911+
if (dist > EPS) distance = fmin(distance, dist);
3912+
}
3913+
if (distance > 0 && distance < max) return distance;
3914+
3915+
/*--- The point only has wall neighbors, which all have 0 wall distance.
3916+
* Compute an alternative distance based on volume and wall area. ---*/
3917+
3918+
const auto nDim = geometry->GetnDim();
3919+
su2double Normal[3] = {};
3920+
for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) {
3921+
if (!config->GetViscous_Wall(iMarker)) continue;
3922+
3923+
const auto iVertex = geometry->nodes->GetVertex(iPoint, iMarker);
3924+
if (iVertex < 0) continue;
3925+
3926+
for (auto iDim = 0u; iDim < nDim; iDim++) {
3927+
Normal[iDim] += geometry->vertex[iMarker][iVertex]->GetNormal(iDim);
3928+
}
3929+
}
3930+
const su2double Vol = geometry->nodes->GetVolume(iPoint) + geometry->nodes->GetPeriodicVolume(iPoint);
3931+
return 2 * Vol / GeometryToolbox::Norm(nDim, Normal);
3932+
}
3933+
} // namespace
3934+
39053935
void CGeometry::ComputeWallDistance(const CConfig* const* config_container, CGeometry**** geometry_container) {
39063936
int nZone = config_container[ZONE_0]->GetnZone();
39073937
bool allEmpty = true;
@@ -3946,27 +3976,53 @@ void CGeometry::ComputeWallDistance(const CConfig* const* config_container, CGeo
39463976
CGeometry* geometry = geometry_container[iZone][iInst][MESH_0];
39473977
geometry->SetWallDistance(0.0);
39483978
}
3979+
continue;
39493980
}
3950-
/*--- Otherwise, set wall roughnesses. ---*/
3951-
if (!allEmpty) {
3952-
/*--- Store all wall roughnesses in a common data structure. ---*/
3953-
// [iZone][iMarker] -> roughness, for this rank
3954-
auto roughness_f = make_pair(nZone, [config_container, geometry_container, iInst](unsigned long iZone) {
3955-
const CConfig* config = config_container[iZone];
3956-
const auto nMarker = geometry_container[iZone][iInst][MESH_0]->GetnMarker();
3957-
3958-
return make_pair(nMarker, [config](unsigned long iMarker) {
3959-
return config->GetWallRoughnessProperties(config->GetMarker_All_TagBound(iMarker)).second;
3960-
});
3981+
3982+
/*--- Otherwise, set wall roughnesses, storing them in a common data structure. ---*/
3983+
// [iZone][iMarker] -> roughness, for this rank
3984+
auto roughness_f = make_pair(nZone, [config_container, geometry_container, iInst](unsigned long iZone) {
3985+
const CConfig* config = config_container[iZone];
3986+
const auto nMarker = geometry_container[iZone][iInst][MESH_0]->GetnMarker();
3987+
3988+
return make_pair(nMarker, [config](unsigned long iMarker) {
3989+
return config->GetWallRoughnessProperties(config->GetMarker_All_TagBound(iMarker)).second;
39613990
});
3962-
NdFlattener<2> roughness_local(roughness_f);
3963-
// [rank][iZone][iMarker] -> roughness
3964-
NdFlattener<3> roughness_global(Nd_MPI_Environment(), roughness_local);
3965-
// use it to update roughnesses
3966-
for (int jZone = 0; jZone < nZone; jZone++) {
3967-
if (wallDistanceNeeded[jZone] && config_container[jZone]->GetnRoughWall() > 0) {
3968-
geometry_container[jZone][iInst][MESH_0]->nodes->SetWallRoughness(roughness_global);
3991+
});
3992+
NdFlattener<2> roughness_local(roughness_f);
3993+
// [rank][iZone][iMarker] -> roughness
3994+
NdFlattener<3> roughness_global(Nd_MPI_Environment(), roughness_local);
3995+
// use it to update roughnesses
3996+
for (int jZone = 0; jZone < nZone; jZone++) {
3997+
if (wallDistanceNeeded[jZone] && config_container[jZone]->GetnRoughWall() > 0) {
3998+
geometry_container[jZone][iInst][MESH_0]->nodes->SetWallRoughness(roughness_global);
3999+
}
4000+
}
4001+
4002+
for (int iZone = 0; iZone < nZone; iZone++) {
4003+
/*--- For the FEM solver, we use a different mesh structure ---*/
4004+
MAIN_SOLVER kindSolver = config_container[iZone]->GetKind_Solver();
4005+
if (!wallDistanceNeeded[iZone] || kindSolver == MAIN_SOLVER::FEM_LES || kindSolver == MAIN_SOLVER::FEM_RANS) {
4006+
continue;
4007+
}
4008+
const auto* config = config_container[iZone];
4009+
auto* geometry = geometry_container[iZone][iInst][MESH_0];
4010+
4011+
for (unsigned short iMarker = 0; iMarker < config->GetnMarker_All(); ++iMarker) {
4012+
const auto viscous = config->GetViscous_Wall(iMarker);
4013+
4014+
SU2_OMP_FOR_STAT(OMP_MIN_SIZE)
4015+
for (auto iVertex = 0u; iVertex < geometry->nVertex[iMarker]; iVertex++) {
4016+
const auto iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
4017+
su2double dist = 0;
4018+
if (viscous && geometry->nodes->GetDomain(iPoint)) {
4019+
dist = NearestNeighborDistance(geometry, config, iPoint);
4020+
} else {
4021+
dist = geometry->nodes->GetWall_Distance(iPoint);
4022+
}
4023+
geometry->vertex[iMarker][iVertex]->SetNearestNeighborDistance(dist);
39694024
}
4025+
END_SU2_OMP_FOR
39704026
}
39714027
}
39724028
}

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,7 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
23502350

23512351
unsigned long iVertex, iPoint, iPointNormal;
23522352
unsigned short iMarker, iMarker_Monitoring, iDim, jDim;
2353-
su2double Viscosity = 0.0, Area, Density = 0.0, WallDistMod, FrictionVel,
2353+
su2double Viscosity = 0.0, Area, Density = 0.0, FrictionVel,
23542354
UnitNormal[3] = {0.0}, TauElem[3] = {0.0}, Tau[3][3] = {{0.0}}, Cp,
23552355
thermal_conductivity, MaxNorm = 8.0, Grad_Vel[3][3] = {{0.0}}, Grad_Temp[3] = {0.0},
23562356
Grad_Temp_ve[3] = {0.0}, AxiFactor;
@@ -2497,11 +2497,9 @@ void CFVMFlowSolverBase<V, FlowRegime>::Friction_Forces(const CGeometry* geometr
24972497

24982498
FrictionVel = sqrt(fabs(WallShearStress[iMarker][iVertex]) / Density);
24992499

2500-
if (!wallfunctions && (MGLevel == MESH_0 || geometry->nodes->GetDomain(iPoint))) {
2501-
// for CMultiGridGeometry, the normal neighbor of halo nodes in not set
2502-
iPointNormal = geometry->vertex[iMarker][iVertex]->GetNormal_Neighbor();
2503-
Coord_Normal = geometry->nodes->GetCoord(iPointNormal);
2504-
WallDistMod = GeometryToolbox::Distance(nDim, Coord, Coord_Normal);
2500+
if (!wallfunctions && MGLevel == MESH_0 && geometry->nodes->GetDomain(iPoint)) {
2501+
// for CMultiGridGeometry and halos, the nearest neighbor distance is not set
2502+
const su2double WallDistMod = geometry->vertex[iMarker][iVertex]->GetNearestNeighborDistance();
25052503
YPlus[iMarker][iVertex] = WallDistMod * FrictionVel / (Viscosity / Density);
25062504
}
25072505

SU2_CFD/include/solvers/CTurbSSTSolver.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class CTurbSSTSolver final : public CTurbSolver {
5353
CSolver **solver_container,
5454
const CConfig *config,
5555
unsigned short val_marker);
56-
5756
public:
5857
/*!
5958
* \brief Constructor.
@@ -302,5 +301,4 @@ class CTurbSSTSolver final : public CTurbSolver {
302301
*/
303302
inline su2double GetOmega_Inf(void) const override { return Solution_Inf[1]; }
304303

305-
306304
};

SU2_CFD/include/variables/CFlowVariable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class CFlowVariable : public CVariable {
260260
* \param[in] iPoint - Point index.
261261
* \return Value of magnitude.
262262
*/
263-
inline su2double GetStrainMag(unsigned long iPoint) const final { return StrainMag(iPoint); }
263+
inline su2double GetStrainMag(unsigned long iPoint) const { return StrainMag(iPoint); }
264264

265265
/*!
266266
* \brief Get the entire vector of the rate of strain magnitude.

SU2_CFD/include/variables/CVariable.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,13 +1147,6 @@ class CVariable {
11471147
inline virtual su2double *GetVorticity(unsigned long iPoint) { return nullptr; }
11481148
inline virtual const su2double *GetVorticity(unsigned long iPoint) const { return nullptr; }
11491149

1150-
/*!
1151-
* \brief A virtual member.
1152-
* \param[in] iPoint - Point index.
1153-
* \return Value of the rate of strain magnitude.
1154-
*/
1155-
inline virtual su2double GetStrainMag(unsigned long iPoint) const { return 0.0; }
1156-
11571150
/*!
11581151
* \brief A virtual member.
11591152
* \param[in] iPoint - Point index.

SU2_CFD/src/drivers/CDriver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ void CDriver::InitializeGeometryFVM(CConfig *config, CGeometry **&geometry) {
833833
geometry[iMGlevel]->SetBoundControlVolume(geometry[iMGlevel-1], config, ALLOCATE);
834834
geometry[iMGlevel]->SetCoord(geometry[iMGlevel-1]);
835835

836-
/*--- Find closest neighbor to a surface point ---*/
836+
/*--- Find closest, most normal, neighbor to a surface point ---*/
837837

838838
geometry[iMGlevel]->FindNormal_Neighbor(config);
839839

@@ -2517,7 +2517,7 @@ void CDriver::InitializeInterface(CConfig **config, CSolver***** solver, CGeomet
25172517
else
25182518
interface_type = NO_TRANSFER;
25192519
}
2520-
2520+
25212521
if (interface_type != NO_TRANSFER) {
25222522
auto nVar = 4;
25232523
interface[donor][target] = new CConjugateHeatInterface(nVar, 0);

SU2_CFD/src/solvers/CIncNSSolver.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,7 @@ void CIncNSSolver::SetTau_Wall_WF(CGeometry *geometry, CSolver **solver_containe
685685
const su2double VelTangMod = GeometryToolbox::Norm(int(MAXNDIM), VelTang);
686686

687687
/*--- Compute normal distance of the interior point from the wall ---*/
688-
689-
su2double WallDist[MAXNDIM] = {0.0};
690-
GeometryToolbox::Distance(nDim, Coord, Coord_Normal, WallDist);
691-
692-
su2double WallDistMod = GeometryToolbox::Norm(int(MAXNDIM), WallDist);
688+
const su2double WallDistMod = GeometryToolbox::Distance(nDim, Coord, Coord_Normal);
693689

694690
su2double Density_Wall = nodes->GetDensity(iPoint);
695691

0 commit comments

Comments
 (0)