Documentation 6b54b78464
Loading...
Searching...
No Matches
CEdge.hpp
Go to the documentation of this file.
1/*!
2 * \file CEdge.hpp
3 * \brief Declaration of the edge class <i>CEdge.cpp</i> file.
4 * \author F. Palacios, T. Economon
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 "../../containers/C2DContainer.hpp"
31
33
34/*!
35 * \class CEdge
36 * \brief Class for defining the edges of the dual grid.
37 * \author F. Palacios
38 */
39class CEdge {
40 static_assert(su2activematrix::IsRowMajor, "Needed to return normal as pointer.");
41
42 private:
43 using Index = unsigned long;
45 NodeArray Nodes; /*!< \brief Vector to store the node indices of the edge. */
46 su2activematrix Normal; /*!< \brief Normal (area) of the edge. */
47 const Index nEdge, nEdgeSIMD;
48
49 friend class CPhysicalGeometry;
50
51 public:
52 enum NodePosition : unsigned long { LEFT = 0, RIGHT = 1 };
53
54 /*!
55 * \brief Constructor of the class.
56 * \param[in] nEdge - Number of edges
57 * \param[in] nDim - Number of dimensions of the problem.
58 */
59 CEdge(unsigned long nEdge, unsigned long nDim);
60
61 /*!
62 * \brief No default construction.
63 */
64 CEdge() = delete;
65
66 /*!
67 * \brief Get left/right node index defining the edge.
68 * \param[in] iEdge - Edge index.
69 * \param[in] iNode - Node index 0 or 1, LEFT or RIGHT.
70 * \return Index of the node that composes the edge.
71 */
72 inline unsigned long GetNode(unsigned long iEdge, unsigned long iNode) const { return Nodes(iEdge, iNode); }
73
74 /*!
75 * \brief SIMD version of GetNode, iNode returned for contiguous iEdges.
76 */
77 template <class T, size_t N>
78 FORCEINLINE simd::Array<T, N> GetNode(simd::Array<T, N> iEdge, unsigned long iNode) const {
79 return simd::Array<T, N>(&Nodes(iEdge[0], iNode));
80 }
81
82 /*!
83 * \brief Sets the tail of "Nodes" to repeat one of the last edges.
84 * \note This is needed when using the SIMD version of GetNode and
85 * the number of edges is not a multiple of the simd width.
86 */
88 for (auto iEdge = nEdge; iEdge < nEdgeSIMD; ++iEdge) {
89 /*--- Pad nodes by repeating the first edge in the last SIMD group. ---*/
90 const auto iEdge0 = nEdgeSIMD - simd::preferredLen<su2double>();
91 Nodes(iEdge, LEFT) = Nodes(iEdge0, LEFT);
92 Nodes(iEdge, RIGHT) = Nodes(iEdge0, RIGHT);
93 }
94 }
95
96 /*!
97 * \brief Set the node indices of an edge.
98 * \param[in] iEdge - Edge index.
99 * \param[in] iPoint - Index of left node.
100 * \param[in] jPoint - Index of right node.
101 */
102 inline void SetNodes(unsigned long iEdge, unsigned long iPoint, unsigned long jPoint) {
103 Nodes(iEdge, LEFT) = iPoint;
104 Nodes(iEdge, RIGHT) = jPoint;
105 }
106
107 /*!
108 * \brief Get the number of nodes of an edge (2).
109 */
110 inline unsigned long GetnNodes() const { return 2; }
111
112 /*!
113 * \brief Compute the volume associated with an edge (3D version).
114 * \param[in] coord_Edge_CG - Coordinates of the centre of gravity of the edge.
115 * \param[in] coord_FaceElem_CG - Coordinates of the centre of gravity of the face of an element.
116 * \param[in] coord_Elem_CG - Coordinates of the centre of gravity of the element.
117 * \param[in] coord_Point - Coordinates of the point that form the control volume.
118 * \return Local volume associated to the edge.
119 */
120 static su2double GetVolume(const su2double* coord_Edge_CG, const su2double* coord_FaceElem_CG,
121 const su2double* coord_Elem_CG, const su2double* coord_Point);
122
123 /*!
124 * \brief Compute the volume associated with an edge (2D version).
125 * \param[in] coord_Edge_CG - Coordinates of the centre of gravity of the edge.
126 * \param[in] coord_Elem_CG - Coordinates of the centre of gravity of the element.
127 * \param[in] coord_Point - Coordinates of the point that form the control volume.
128 * \return Local volume associated to the edge.
129 */
130 static su2double GetVolume(const su2double* coord_Edge_CG, const su2double* coord_Elem_CG,
131 const su2double* coord_Point);
132
133 /*!
134 * \brief Set the face that corresponds to an edge (3D version).
135 * \param[in] iEdge - Edge index.
136 * \param[in] coord_Edge_CG - Coordinates of the centre of gravity of the edge.
137 * \param[in] coord_FaceElem_CG - Coordinates of the centre of gravity of the face of an element.
138 * \param[in] coord_Elem_CG - Coordinates of the centre of gravity of the element.
139 * \param[in] config - Definition of the particular problem.
140 * \return Compute the normal (dimensional) to the face that makes the control volume boundaries.
141 */
142 void SetNodes_Coord(unsigned long iEdge, const su2double* coord_Edge_CG, const su2double* coord_FaceElem_CG,
143 const su2double* coord_Elem_CG);
144
145 /*!
146 * \brief Set the face that corresponds to an edge (2D version).
147 * \param[in] iEdge - Edge index.
148 * \param[in] coord_Edge_CG - Coordinates of the centre of gravity of the edge.
149 * \param[in] coord_Elem_CG - Coordinates of the centre of gravity of the element.
150 * \param[in] config - Definition of the particular problem.
151 * \return Compute the normal (dimensional) to the face that makes the contorl volume boundaries.
152 */
153 void SetNodes_Coord(unsigned long iEdge, const su2double* coord_Edge_CG, const su2double* coord_Elem_CG);
154
155 /*!
156 * \brief Copy the the normal vector of a face.
157 * \param[in] iEdge - Edge index.
158 * \param[out] normal - Object into which the normal (dimensional) will be copied.
159 */
160 template <class T>
161 inline void GetNormal(unsigned long iEdge, T& normal) const {
162 for (auto iDim = 0ul; iDim < Normal.cols(); iDim++) normal[iDim] = Normal(iEdge, iDim);
163 }
164
165 /*!
166 * \brief Get the normal to a face of the control volume asociated with an edge.
167 * \param[in] iEdge - Edge index.
168 * \return Dimensional normal vector, the modulus is the area of the face.
169 */
170 inline const su2double* GetNormal(unsigned long iEdge) const { return Normal[iEdge]; }
171
172 /*!
173 * \brief Get the entire matrix of edge normals.
174 */
175 inline const su2activematrix& GetNormal() const { return Normal; }
176
177 /*!
178 * \brief Initialize normal vector to 0.
179 */
180 void SetZeroValues(void);
181
182 /*!
183 * \brief Set the normal vector of an edge.
184 * \param[in] iEdge - Edge index.
185 * \param[in] normal - Vector to initialize the normal vector.
186 * \return Value of the normal vector.
187 */
188 template <class T>
189 void SetNormal(unsigned long iEdge, const T& normal) {
190 for (auto iDim = 0ul; iDim < Normal.cols(); ++iDim) Normal(iEdge, iDim) = normal[iDim];
191 }
192
193 /*!
194 * \brief Add a vector to the normal vector of an edge.
195 * \param[in] iEdge - Edge index.
196 * \param[in] normal - Vector to add to the normal vector.
197 */
198 template <class T>
199 void AddNormal(unsigned long iEdge, const T& normal) {
200 for (auto iDim = 0ul; iDim < Normal.cols(); ++iDim) Normal(iEdge, iDim) += normal[iDim];
201 }
202
203 /*!
204 * \brief Subtract a vector to the normal vector of an edge.
205 * \param[in] iEdge - Edge index.
206 * \param[in] normal - Vector to add to the normal vector.
207 */
208 template <class T>
209 void SubNormal(unsigned long iEdge, const T& normal) {
210 for (auto iDim = 0ul; iDim < Normal.cols(); ++iDim) Normal(iEdge, iDim) -= normal[iDim];
211 }
212};
Index_t cols() const noexcept
Definition C2DContainer.hpp:222
static constexpr bool IsRowMajor
Definition C2DContainer.hpp:391
Class for defining the edges of the dual grid.
Definition CEdge.hpp:39
void SetNormal(unsigned long iEdge, const T &normal)
Set the normal vector of an edge.
Definition CEdge.hpp:189
simd::Array< T, N > GetNode(simd::Array< T, N > iEdge, unsigned long iNode) const
SIMD version of GetNode, iNode returned for contiguous iEdges.
Definition CEdge.hpp:78
unsigned long GetnNodes() const
Get the number of nodes of an edge (2).
Definition CEdge.hpp:110
void SetNodes_Coord(unsigned long iEdge, const su2double *coord_Edge_CG, const su2double *coord_FaceElem_CG, const su2double *coord_Elem_CG)
Set the face that corresponds to an edge (3D version).
Definition CEdge.cpp:70
void AddNormal(unsigned long iEdge, const T &normal)
Add a vector to the normal vector of an edge.
Definition CEdge.hpp:199
CEdge()=delete
No default construction.
void SubNormal(unsigned long iEdge, const T &normal)
Subtract a vector to the normal vector of an edge.
Definition CEdge.hpp:209
void GetNormal(unsigned long iEdge, T &normal) const
Copy the the normal vector of a face.
Definition CEdge.hpp:161
const su2double * GetNormal(unsigned long iEdge) const
Get the normal to a face of the control volume asociated with an edge.
Definition CEdge.hpp:170
unsigned long GetNode(unsigned long iEdge, unsigned long iNode) const
Get left/right node index defining the edge.
Definition CEdge.hpp:72
void SetPaddingNodes()
Sets the tail of "Nodes" to repeat one of the last edges.
Definition CEdge.hpp:87
static su2double GetVolume(const su2double *coord_Edge_CG, const su2double *coord_FaceElem_CG, const su2double *coord_Elem_CG, const su2double *coord_Point)
Compute the volume associated with an edge (3D version).
Definition CEdge.cpp:43
NodePosition
Definition CEdge.hpp:52
@ RIGHT
Definition CEdge.hpp:52
@ LEFT
Definition CEdge.hpp:52
void SetZeroValues(void)
Initialize normal vector to 0.
Definition CEdge.cpp:41
const su2activematrix & GetNormal() const
Get the entire matrix of edge normals.
Definition CEdge.hpp:175
void SetNodes(unsigned long iEdge, unsigned long iPoint, unsigned long jPoint)
Set the node indices of an edge.
Definition CEdge.hpp:102
Class for reading a defining the primal grid which is read from the grid file in ....
Definition CPhysicalGeometry.hpp:41
A simple SIMD type relying on implicit vectorization, i.e. done by the compiler, explicitly vectorize...
Definition vectorization.hpp:89
#define FORCEINLINE
Definition code_config.hpp:44
passivedouble su2double
Definition code_config.hpp:181
constexpr size_t preferredLen< su2double >()
Definition vectorization.hpp:68