Documentation 6b54b78464
Loading...
Searching...
No Matches
correctGradientsSymmetry.hpp
Go to the documentation of this file.
1/*!
2 * \file correctGradientsSymmetry.hpp
3 * \brief Implements the symmetry boundary conditions for the gradient computations.
4 * \author N. Beishuizen
5 * \version 8.5.0 "Harrier"
6 *
7 * SU2 Project Website: https://su2code.github.io
8 *
9 * The SU2 Project is maintained by the SU2 Foundation
10 * (http://su2foundation.org)
11 *
12 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
13 *
14 * SU2 is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SU2 is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
30#include <vector>
31#include <algorithm>
32
33#include "../../../Common/include/parallelization/omp_structure.hpp"
34#include "../../../Common/include/toolboxes/geometry_toolbox.hpp"
35
36namespace detail {
37/*!
38 * \brief Correct the gradient on a symmetry plane.
39 * \ingroup FvmAlgos
40 * \param[in] varBegin - Start of the variables.
41 * \param[in] varEnd - End of the variables.
42 * \param[in] idxVel - Variable index where velocity gradients start (-1 if all variables are scalars).
43 * \param[in] n - Normal direction.
44 * \param[in, out] gradients - The gradients to be modified.
45 */
46template <size_t nDim, class Matrix, class Scalar>
47inline void correctGradient(const size_t varBegin, const size_t varEnd, const int idxVel, const Scalar* n,
48 Matrix&& gradients) {
49
50 /*--- First we correct the part that involves velocities. ---*/
51
52 if (idxVel >= static_cast<int>(varBegin) && idxVel + nDim <= varEnd) {
53 /*--- Normal gradient of velocity components and gradient of normal velocity. ---*/
54 su2double normalGrad[nDim] = {}, gradNormalVel[nDim] = {};
55
56 for (size_t iDim = 0; iDim < nDim; iDim++) {
57 normalGrad[iDim] = GeometryToolbox::DotProduct(nDim, gradients[idxVel + iDim], n);
58
59 for (size_t jDim = 0; jDim < nDim; jDim++) {
60 gradNormalVel[jDim] += n[iDim] * gradients[idxVel + iDim][jDim];
61 }
62 }
63
64 /*--- Normal gradient of the normal velocity. ---*/
65 const su2double normalGradNormalVel = GeometryToolbox::DotProduct(nDim, n, gradNormalVel);
66
67 /*--- Remove the tangential projection (I - n.n^T) of the normal gradients.
68 * And the normal projection (n.n^T) of the tangential gradients.
69 * dV = dV - (I - n.n^T) dV n.n^T - n.n^T dV (I - n.n^T) ---*/
70
71 for (size_t iDim = 0; iDim < nDim; iDim++) {
72 for (size_t jDim = 0; jDim < nDim; jDim++) {
73 gradients[idxVel + iDim][jDim] -= normalGrad[iDim] * n[jDim] + n[iDim] * gradNormalVel[jDim];
74 gradients[idxVel + iDim][jDim] += 2 * n[iDim] * normalGradNormalVel * n[jDim];
75 }
76 }
77 }
78
79 /*--- Remove the normal component for all scalars (excluding velocities). ---*/
80
81 for (auto iVar = varBegin; iVar < varEnd; iVar++) {
82 if (idxVel != -1 && static_cast<int>(iVar) >= idxVel && iVar < idxVel + nDim) continue;
83
84 const su2double normalGrad = GeometryToolbox::DotProduct(nDim, n, gradients[iVar]);
85 for (size_t iDim = 0; iDim < nDim; iDim++) {
86 gradients[iVar][iDim] -= normalGrad * n[iDim];
87 }
88 }
89}
90}
91
92/*!
93 * \brief Correct gradients on symmetry and Euler (slip) markers to respect the conditions:
94 * 1. n.grad(phi) = 0
95 * 2. n.grad(v.t) = 0
96 * 3. t.grad(v.n) = 0
97 * \note See Blazek eq. 8.40.
98 * \ingroup FvmAlgos
99 * \param[in] geometry - Geometric grid properties.
100 * \param[in] config - Configuration of the problem, used to identify types of boundaries.
101 * \param[in] varBegin - Index of first variable for which to compute the gradient.
102 * \param[in] varEnd - Index of last variable for which to compute the gradient.
103 * \param[in] idxVel - Index to velocity, -1 if no velocity is present in the solver.
104 * \param[in,out] gradient - Generic object implementing operator (iPoint, iVar, iDim).
105 */
106template <size_t nDim, class GradientType>
107void correctGradientsSymmetry(CGeometry& geometry, const CConfig& config, const size_t varBegin,
108 const size_t varEnd, const int idxVel, GradientType& gradient) {
109
110 /*--- Check how many symmetry planes there are. ---*/
111 std::vector<unsigned short> symMarkers;
112 for (auto iMarker = 0u; iMarker < geometry.GetnMarker(); ++iMarker) {
113 if (config.GetMarker_All_KindBC(iMarker) == SYMMETRY_PLANE ||
114 config.GetMarker_All_KindBC(iMarker) == EULER_WALL) {
115 symMarkers.push_back(iMarker);
116 }
117 }
118
119 for (const auto iMarker : symMarkers) {
121 for (size_t iVertex = 0; iVertex < geometry.GetnVertex(iMarker); ++iVertex) {
122
123 const auto iPoint = geometry.vertex[iMarker][iVertex]->GetNode();
124
125 /*--- Get the normal of the current symmetry. This may be the original normal of the vertex
126 * or a modified normal if there are intersecting symmetries. ---*/
127
128 su2double unitNormal[nDim] = {};
129 const auto it = geometry.symmetryNormals[iMarker].find(iVertex);
130
131 if (it != geometry.symmetryNormals[iMarker].end()) {
132 for (auto iDim = 0u; iDim < nDim; iDim++) unitNormal[iDim] = it->second[iDim];
133 } else {
134 geometry.vertex[iMarker][iVertex]->GetNormal(unitNormal);
135 const su2double area = GeometryToolbox::Norm(nDim, unitNormal);
136 for (auto iDim = 0u; iDim < nDim; iDim++) unitNormal[iDim] /= area;
137 }
138
139 detail::correctGradient<nDim>(varBegin, varEnd, idxVel, unitNormal, gradient[iPoint]);
140
141 } // loop over vertices
143 } // markers
144
145}
146
CNewtonIntegration::Scalar Scalar
Definition CNewtonIntegration.cpp:31
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
unsigned short GetMarker_All_KindBC(unsigned short val_marker) const
Get the kind of boundary for each marker.
Definition CConfig.hpp:3556
Parent class for defining the geometry of the problem (complete geometry, multigrid agglomerated geom...
Definition CGeometry.hpp:75
unsigned long GetnVertex(unsigned short val_marker) const
Get number of vertices.
Definition CGeometry.hpp:637
vector< std::unordered_map< unsigned long, std::array< su2double, MAXNDIM > > > symmetryNormals
Bool if boundary-marker is straight(2D)/plane(3D) for each local marker.
Definition CGeometry.hpp:263
CVertex *** vertex
Boundary Vertex vector (dual grid information).
Definition CGeometry.hpp:255
unsigned short GetnMarker() const
Get number of markers.
Definition CGeometry.hpp:623
void GetNormal(su2double *val_normal) const override
Copy the the normal vector of a face.
Definition CVertex.hpp:94
unsigned long GetNode() const
Get the node of the vertex.
Definition CVertex.hpp:70
passivedouble su2double
Definition code_config.hpp:181
void correctGradient(const size_t varBegin, const size_t varEnd, const int idxVel, const Scalar *n, Matrix &&gradients)
Correct the gradient on a symmetry plane.
Definition correctGradientsSymmetry.hpp:47
void correctGradientsSymmetry(CGeometry &geometry, const CConfig &config, const size_t varBegin, const size_t varEnd, const int idxVel, GradientType &gradient)
Correct gradients on symmetry and Euler (slip) markers to respect the conditions:
Definition correctGradientsSymmetry.hpp:107
T DotProduct(Int nDim, const T *a, const T *b)
Definition geometry_toolbox.hpp:65
T Norm(Int nDim, const T *a)
Definition geometry_toolbox.hpp:79
Definition computeGradientsGreenGauss.hpp:37
#define END_SU2_OMP_FOR
Definition omp_structure.hpp:158
#define SU2_OMP_FOR_STAT(CHUNK)
Definition omp_structure.hpp:151
@ EULER_WALL
Boundary Euler wall definition.
Definition option_structure.hpp:1815
@ SYMMETRY_PLANE
Boundary symmetry plane definition.
Definition option_structure.hpp:1817