Documentation 6b54b78464
Loading...
Searching...
No Matches
CParallelDataSorter.hpp
Go to the documentation of this file.
1/*!
2 * \file CParallelDataSorter.hpp
3 * \brief Headers fo the data sorter class.
4 * \author T. Albring, 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 "../../../../Common/include/parallelization/mpi_structure.hpp"
31#include "../../../../Common/include/option_structure.hpp"
32#include "../../../../Common/include/toolboxes/CLinearPartitioner.hpp"
33#include <array>
34#include <cassert>
35
36class CGeometry;
37class CConfig;
38
40protected:
41
42 /*!
43 * \brief The MPI rank
44 */
45 const int rank;
46
47 /*!
48 * \brief The MPI size, aka the number of processors.
49 */
50 const int size;
51
52 unsigned long nGlobalPointBeforeSort; //!< Global number of points without halos before sorting
53 unsigned long nLocalPointsBeforeSort; //!< Local number of points without halos before sorting on this proc
54
55 int *Conn_Line_Par; //!< Local connectivity of line elements
56 int *Conn_Tria_Par; //!< Local connectivity of triangle elements
57 int *Conn_Quad_Par; //!< Local connectivity of quad elements
58 int *Conn_Tetr_Par; //!< Local connectivity of tetrahedral elements
59 int *Conn_Hexa_Par; //!< Local connectivity of hexahedral elements
60 int *Conn_Pris_Par; //!< Local connectivity of prism elements
61 int *Conn_Pyra_Par; //!< Local connectivity of pyramid elements
62
63 array<unsigned long, N_ELEM_TYPES> nElemPerTypeGlobal; //!< Global number of elements after sorting on this proc
64 array<unsigned long, N_ELEM_TYPES> nElemPerType; //!< Local number of elements after sorting on this proc
65
66 /*!
67 * \brief Map that stores the index for each GEO_TYPE type where to find information
68 * in the element arrays.
69 */
70 struct {
71 static unsigned short at(unsigned short type) {
72 switch(type) {
73 case LINE: return 0;
74 case TRIANGLE: return 1;
75 case QUADRILATERAL: return 2;
76 case TETRAHEDRON: return 3;
77 case HEXAHEDRON: return 4;
78 case PRISM: return 5;
79 case PYRAMID: return 6;
80 default: assert(false); return 0;
81 };
82 }
84
85 unsigned long nPointsGlobal; //!< Global number of points without halos
86 unsigned long nElemGlobal; //!< Global number of elems without halos
87 unsigned long nConnGlobal; //!< Global size of the connectivity array
88 unsigned long nPoints; //!< Local number of points
89 unsigned long nElem; //!< Local number of elements
90 unsigned long nConn; //!< Local size of the connectivity array
91
92 CLinearPartitioner linearPartitioner; //!< Linear partitioner based on the global number of points.
93
94 unsigned short GlobalField_Counter; //!< Number of output fields
95
96 bool connectivitySorted; //!< Boolean to store information on whether the connectivity is sorted
97
98 int *nPoint_Send; //!< Number of points this processor has to send to other processors
99 int *nPoint_Recv; //!< Number of points this processor receives from other processors
100 int *nElem_Send; //!< Number of elements this processor has to send to other processors
101 int *nElem_Cum; //!< Cumulative number of elements
102 unsigned long *nElemConn_Send; //!< Number of element connectivity this processor has to send to other processors
103 unsigned long *nElemConn_Cum; //!< Cumulative number of element connectivity entries
104 unsigned long *Index; //!< Index each point has in the send buffer
105 passivedouble *connSend; //!< Send buffer holding the data that will be send to other processors
106 passivedouble *dataBuffer; //!< Buffer holding the sorted, partitioned data as passivedouble types
107 unsigned long *idSend; //!< Send buffer holding global indices that will be send to other processors
108 int nSends, //!< Number of sends
109 nRecvs; //!< Number of receives
110
111 vector<string> fieldNames; //!< Vector with names of all the output fields
112 vector<string> requiredFieldNames; //!< Vector with names of the required output fields that we write to file
113
114 unsigned short nDim; //!< Spatial dimension of the data
115
116 /*!
117 * \brief Prepare the send buffers by filling them with the global indices.
118 * After calling this function, the data buffer for sending can be filled with the
119 * ::SetUnsorted_Data() routine.
120 * \param[in] globalID - Vector containing the global indices of the points
121 */
122 void PrepareSendBuffers(std::vector<unsigned long>& globalID);
123
124public:
125
126 /*!
127 * \brief Constructor
128 * \param[in] config - Pointer to the current config structure
129 * \param[in] valFieldNames - Vector containing the field names
130 */
131 CParallelDataSorter(CConfig *config, const vector<string> &valFieldNames);
132
133 /*!
134 * \brief Destructor
135 */
136 virtual ~CParallelDataSorter();
137
138 /*!
139 * \brief Sort the output data for each grid node into a linear partitioning across all processors.
140 */
141 virtual void SortOutputData();
142
143 /*!
144 * \brief Sort the connectivities (volume and surface) into data structures.
145 * \param[in] config - Definition of the particular problem.
146 * \param[in] geometry - Geometrical definition of the problem.
147 * \param[in] val_sort - boolean controlling whether the elements are sorted or simply loaded by their owning rank.
148 */
149 virtual void SortConnectivity(CConfig *config, CGeometry *geometry, bool val_sort = true){}
150
151 /*!
152 * \brief Sort the connectivities into data structures (only for surface data sorters).
153 * \param[in] config - Definition of the particular problem.
154 * \param[in] geometry - Geometrical definition of the problem.
155 * \param[in] markerList - A list of marker names that should be sorted.
156 */
157 virtual void SortConnectivity(CConfig *config, CGeometry *geometry, const vector<string> &markerList){}
158
159 /*!
160 * \brief Get the number of points the local rank owns.
161 * \return local number of points.
162 */
163 unsigned long GetnPoints() const {return nPoints;}
164
165 /*!
166 * \brief Get the number of points to sort.
167 * \return local number of points.
168 */
169 unsigned long GetnLocalPointsBeforeSort() const {return nLocalPointsBeforeSort;}
170
171 /*!
172 * \brief Get the global number of points (accumulated from all ranks)
173 * \return Global number of points.
174 */
175 unsigned long GetnPointsGlobal() const {return nPointsGlobal;}
176
177 /*!
178 * \brief Get the global of elements (accumulated from all ranks and element types)
179 * \return Global number elements.
180 */
181 unsigned long GetnElem() const {return nElem;}
182
183 /*!
184 * \brief Get the local number of elements of a specific type that the current rank owns
185 * \input type - The type of element, ref GEO_TYPE
186 * \return Local number of elements of a specific type.
187 */
188 unsigned long GetnElem(GEO_TYPE type) const {
189 return nElemPerType[TypeMap.at(type)];
190 }
191
192 /*!
193 * \brief Get the global number of elements of a specific type
194 * \input type - The type of element, ref GEO_TYPE
195 * \return global number of elements of a specific type.
196 */
197 unsigned long GetnElemGlobal(GEO_TYPE type) const {
198 return nElemPerTypeGlobal[TypeMap.at(type)];
199 }
200
201 /*!
202 * \brief Get the global number of elements
203 * \return global number of elements.
204 */
205 unsigned long GetnElemGlobal() const {
206 return nElemGlobal;
207 }
208
209 /*!
210 * \brief Get the global number entries of the connectivity array
211 * \return global number of entries of the connectivity array
212 */
213 unsigned long GetnConnGlobal() const {
214 return nConnGlobal;
215 }
216
217 /*!
218 * \brief Get the local number entries of the connectivity array
219 * \return local number of entries of the connectivity array
220 */
221 unsigned long GetnConn() const {
222 return nConn;
223 }
224
225 /*!
226 * \brief Get the cumulated number of elements
227 * \input rank - the processor rank.
228 * \return The cumulated number of elements
229 */
230 unsigned long GetnElemCumulative(unsigned short rank) const {
231 return nElem_Cum[rank];
232 }
233
234 /*!
235 * \brief Get the cumulated number of entries of the connectivity array
236 * \input rank - the processor rank.
237 * \return The cumulated number of entries of the connectivity array
238 */
239 unsigned long GetnElemConnCumulative(unsigned short rank) const {
240 return nElemConn_Cum[rank];
241 }
242
243 /*!
244 * \brief Get the connectivity of specific element.
245 * \input type - The type of element, ref GEO_TYPE
246 * \input iElem - The element ID
247 * \input iNode - The node ID
248 * \return the connected node.
249 */
250 unsigned long GetElemConnectivity(GEO_TYPE type, unsigned long iElem, unsigned long iNode) const ;
251
252 /*!
253 * \brief Beginning node ID of the linear partition owned by a specific processor.
254 * \input rank - the processor rank.
255 * \return The beginning node ID.
256 */
257 virtual unsigned long GetNodeBegin(unsigned short rank) const {
259 }
260
261 /*!
262 * \brief Ending node ID of the linear partition owned by a specific processor.
263 * \param rank - the processor rank.
264 * \return The ending node ID.
265 */
266 unsigned long GetNodeEnd(unsigned short rank) const {
268 }
269
270 /*!
271 * \brief Get the value of the linear partitioned data.
272 * \input iField - the output field ID.
273 * \input iPoint - the point ID.
274 * \return the value of the data field at a point.
275 */
276 passivedouble GetData(unsigned short iField, unsigned long iPoint) const {return dataBuffer[iPoint*GlobalField_Counter + iField];}
277
278 /*!
279 * \brief Get the pointer to the sorted linear partitioned data.
280 * \return Pointer to the sorted data.
281 */
282 const passivedouble *GetData() const {return dataBuffer;}
283
284 /*!
285 * \brief Get the global index of a point.
286 * \input iPoint - the point ID.
287 * \return Global index of a specific point.
288 */
289 virtual unsigned long GetGlobalIndex(unsigned long iPoint) const { return 0; }
290
291 /*!
292 * \brief Get the cumulated number of points
293 * \input rank - the processor rank.
294 * \return The cumulated number of points up to certain processor rank.
295 */
296 virtual unsigned long GetnPointCumulative(unsigned short rank) const {return linearPartitioner.GetCumulativeSizeBeforeRank(rank);}
297
298 /*!
299 * \brief Get the linear number of points
300 * \input rank - the processor rank.
301 * \return The linear number of points up to certain processor rank.
302 */
303 unsigned long GetnPointLinear(unsigned short rank) const {return linearPartitioner.GetSizeOnRank(rank);}
304
305 /*!
306 * \brief Check whether the current connectivity is sorted (i.e. if SortConnectivity has been called)
307 * \return <TRUE> if the connectivity is sorted.
308 */
310
311 /*!
312 * \brief Set the value of a specific field at a point.
313 * ::PrepareSendBuffers must be called before using this function.
314 *
315 * \param[in] iPoint - ID of the point
316 * \param[in] iField - Index of the field
317 * \param[in] data - Value of the field
318 */
319 void SetUnsortedData(unsigned long iPoint, unsigned short iField, su2double data){
320 connSend[Index[iPoint] + iField] = SU2_TYPE::GetValue(data);
321 }
322
323 passivedouble GetUnsortedData(unsigned long iPoint, unsigned short iField) const {
324 return connSend[Index[iPoint] + iField];
325 }
326
327 /*!
328 * \brief Get the Processor ID a Point belongs to.
329 * \param[in] iPoint - global renumbered ID of the point
330 * \return The rank/processor number.
331 */
332 virtual unsigned short FindProcessor(unsigned long iPoint) const {
334 }
335
336 /*!
337 * \brief Get the vector containing the names of the output fields
338 * \return Vector of strings containing the field names
339 */
340 const vector<string>& GetFieldNames() const{
341 return fieldNames;
342 }
343
344 /*!
345 * \brief Get the vector containing the names of the required output fields
346 * \return Vector of strings containing the required field names
347 */
348 const vector<string>& GetRequiredFieldNames() const{
349 return requiredFieldNames;
350 }
351
352 /*!
353 * \brief Set the vector of required output fields.
354 * \return None.
355 */
356 void SetRequiredFieldNames(const vector<string>& req_field_names) {
357 requiredFieldNames = req_field_names;
358 }
359
360 /*!
361 * \brief Get the spatial dimension
362 * \return The spatial dimension
363 */
364 unsigned short GetnDim() const {
365 return nDim;
366 }
367
368 /*!
369 * \brief Set the total number of elements after sorting individual element types
370 */
371 void SetTotalElements();
372
373};
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
Parent class for defining the geometry of the problem (complete geometry, multigrid agglomerated geom...
Definition CGeometry.hpp:75
Helper class that provides the counts for each rank in a linear partitioning given the global count a...
Definition CLinearPartitioner.hpp:43
unsigned long GetCumulativeSizeBeforeRank(int rank) const
Get the cumulative size of all linear partitions before the current rank.
Definition CLinearPartitioner.hpp:107
unsigned long GetRankContainingIndex(unsigned long index) const
Get the rank that owns the index based on the linear partitioning.
Definition CLinearPartitioner.cpp:73
unsigned long GetLastIndexOnRank(int rank) const
Get the last index of the current rank's linear partition.
Definition CLinearPartitioner.hpp:93
unsigned long GetFirstIndexOnRank(int rank) const
Get the first index of the current rank's linear partition.
Definition CLinearPartitioner.hpp:86
unsigned long GetSizeOnRank(int rank) const
Get the total size of the current rank's linear partition.
Definition CLinearPartitioner.hpp:100
Definition CParallelDataSorter.hpp:39
CLinearPartitioner linearPartitioner
Linear partitioner based on the global number of points.
Definition CParallelDataSorter.hpp:92
int * Conn_Tria_Par
Local connectivity of triangle elements.
Definition CParallelDataSorter.hpp:56
virtual void SortConnectivity(CConfig *config, CGeometry *geometry, bool val_sort=true)
Sort the connectivities (volume and surface) into data structures.
Definition CParallelDataSorter.hpp:149
unsigned long * idSend
Send buffer holding global indices that will be send to other processors.
Definition CParallelDataSorter.hpp:107
vector< string > requiredFieldNames
Vector with names of the required output fields that we write to file.
Definition CParallelDataSorter.hpp:112
unsigned short GlobalField_Counter
Number of output fields.
Definition CParallelDataSorter.hpp:94
virtual ~CParallelDataSorter()
Destructor.
Definition CParallelDataSorter.cpp:70
unsigned long GetnLocalPointsBeforeSort() const
Get the number of points to sort.
Definition CParallelDataSorter.hpp:169
unsigned long nConnGlobal
Global size of the connectivity array.
Definition CParallelDataSorter.hpp:87
const passivedouble * GetData() const
Get the pointer to the sorted linear partitioned data.
Definition CParallelDataSorter.hpp:282
array< unsigned long, N_ELEM_TYPES > nElemPerType
Local number of elements after sorting on this proc.
Definition CParallelDataSorter.hpp:64
unsigned long GetnElemGlobal(GEO_TYPE type) const
Get the global number of elements of a specific type \input type - The type of element,...
Definition CParallelDataSorter.hpp:197
unsigned short nDim
Spatial dimension of the data.
Definition CParallelDataSorter.hpp:114
void SetTotalElements()
Set the total number of elements after sorting individual element types.
Definition CParallelDataSorter.cpp:373
virtual unsigned long GetNodeBegin(unsigned short rank) const
Beginning node ID of the linear partition owned by a specific processor. \input rank - the processor ...
Definition CParallelDataSorter.hpp:257
unsigned long GetnConnGlobal() const
Get the global number entries of the connectivity array.
Definition CParallelDataSorter.hpp:213
const vector< string > & GetRequiredFieldNames() const
Get the vector containing the names of the required output fields.
Definition CParallelDataSorter.hpp:348
virtual void SortOutputData()
Sort the output data for each grid node into a linear partitioning across all processors.
Definition CParallelDataSorter.cpp:96
unsigned long GetElemConnectivity(GEO_TYPE type, unsigned long iElem, unsigned long iNode) const
Get the connectivity of specific element. \input type - The type of element, ref GEO_TYPE \input iEle...
Definition CParallelDataSorter.cpp:340
unsigned long nGlobalPointBeforeSort
Global number of points without halos before sorting.
Definition CParallelDataSorter.hpp:52
unsigned long nPointsGlobal
Global number of points without halos.
Definition CParallelDataSorter.hpp:85
unsigned long nElemGlobal
Global number of elems without halos.
Definition CParallelDataSorter.hpp:86
unsigned long GetnElemCumulative(unsigned short rank) const
Get the cumulated number of elements \input rank - the processor rank.
Definition CParallelDataSorter.hpp:230
void SetUnsortedData(unsigned long iPoint, unsigned short iField, su2double data)
Set the value of a specific field at a point. PrepareSendBuffers must be called before using this fun...
Definition CParallelDataSorter.hpp:319
struct CParallelDataSorter::@88 TypeMap
Map that stores the index for each GEO_TYPE type where to find information in the element arrays.
int * nElem_Send
Number of elements this processor has to send to other processors.
Definition CParallelDataSorter.hpp:100
passivedouble GetData(unsigned short iField, unsigned long iPoint) const
Get the value of the linear partitioned data. \input iField - the output field ID....
Definition CParallelDataSorter.hpp:276
unsigned short GetnDim() const
Get the spatial dimension.
Definition CParallelDataSorter.hpp:364
unsigned long * Index
Index each point has in the send buffer.
Definition CParallelDataSorter.hpp:104
virtual unsigned short FindProcessor(unsigned long iPoint) const
Get the Processor ID a Point belongs to.
Definition CParallelDataSorter.hpp:332
unsigned long GetnElem(GEO_TYPE type) const
Get the local number of elements of a specific type that the current rank owns \input type - The type...
Definition CParallelDataSorter.hpp:188
unsigned long nConn
Local size of the connectivity array.
Definition CParallelDataSorter.hpp:90
const int size
The MPI size, aka the number of processors.
Definition CParallelDataSorter.hpp:50
void SetRequiredFieldNames(const vector< string > &req_field_names)
Set the vector of required output fields.
Definition CParallelDataSorter.hpp:356
unsigned long nLocalPointsBeforeSort
Local number of points without halos before sorting on this proc.
Definition CParallelDataSorter.hpp:53
int * Conn_Pyra_Par
Local connectivity of pyramid elements.
Definition CParallelDataSorter.hpp:61
virtual unsigned long GetnPointCumulative(unsigned short rank) const
Get the cumulated number of points \input rank - the processor rank.
Definition CParallelDataSorter.hpp:296
unsigned long * nElemConn_Send
Number of element connectivity this processor has to send to other processors.
Definition CParallelDataSorter.hpp:102
array< unsigned long, N_ELEM_TYPES > nElemPerTypeGlobal
Global number of elements after sorting on this proc.
Definition CParallelDataSorter.hpp:63
int nSends
Number of sends.
Definition CParallelDataSorter.hpp:108
bool connectivitySorted
Boolean to store information on whether the connectivity is sorted.
Definition CParallelDataSorter.hpp:96
unsigned long * nElemConn_Cum
Cumulative number of element connectivity entries.
Definition CParallelDataSorter.hpp:103
const vector< string > & GetFieldNames() const
Get the vector containing the names of the output fields.
Definition CParallelDataSorter.hpp:340
int nRecvs
Number of receives.
Definition CParallelDataSorter.hpp:109
const int rank
The MPI rank.
Definition CParallelDataSorter.hpp:45
passivedouble GetUnsortedData(unsigned long iPoint, unsigned short iField) const
Definition CParallelDataSorter.hpp:323
unsigned long GetnPointsGlobal() const
Get the global number of points (accumulated from all ranks)
Definition CParallelDataSorter.hpp:175
unsigned long GetnElem() const
Get the global of elements (accumulated from all ranks and element types)
Definition CParallelDataSorter.hpp:181
int * nPoint_Recv
Number of points this processor receives from other processors.
Definition CParallelDataSorter.hpp:99
int * Conn_Quad_Par
Local connectivity of quad elements.
Definition CParallelDataSorter.hpp:57
int * Conn_Line_Par
Local connectivity of line elements.
Definition CParallelDataSorter.hpp:55
bool GetConnectivitySorted() const
Check whether the current connectivity is sorted (i.e. if SortConnectivity has been called)
Definition CParallelDataSorter.hpp:309
passivedouble * dataBuffer
Buffer holding the sorted, partitioned data as passivedouble types.
Definition CParallelDataSorter.hpp:106
passivedouble * connSend
Send buffer holding the data that will be send to other processors.
Definition CParallelDataSorter.hpp:105
int * Conn_Tetr_Par
Local connectivity of tetrahedral elements.
Definition CParallelDataSorter.hpp:58
vector< string > fieldNames
Vector with names of all the output fields.
Definition CParallelDataSorter.hpp:111
virtual unsigned long GetGlobalIndex(unsigned long iPoint) const
Get the global index of a point. \input iPoint - the point ID.
Definition CParallelDataSorter.hpp:289
int * nPoint_Send
Number of points this processor has to send to other processors.
Definition CParallelDataSorter.hpp:98
void PrepareSendBuffers(std::vector< unsigned long > &globalID)
Prepare the send buffers by filling them with the global indices. After calling this function,...
Definition CParallelDataSorter.cpp:242
unsigned long GetnPoints() const
Get the number of points the local rank owns.
Definition CParallelDataSorter.hpp:163
int * Conn_Hexa_Par
Local connectivity of hexahedral elements.
Definition CParallelDataSorter.hpp:59
unsigned long nPoints
Local number of points.
Definition CParallelDataSorter.hpp:88
int * nElem_Cum
Cumulative number of elements.
Definition CParallelDataSorter.hpp:101
unsigned long GetNodeEnd(unsigned short rank) const
Ending node ID of the linear partition owned by a specific processor.
Definition CParallelDataSorter.hpp:266
unsigned long GetnElemConnCumulative(unsigned short rank) const
Get the cumulated number of entries of the connectivity array \input rank - the processor rank.
Definition CParallelDataSorter.hpp:239
unsigned long GetnConn() const
Get the local number entries of the connectivity array.
Definition CParallelDataSorter.hpp:221
unsigned long GetnElemGlobal() const
Get the global number of elements.
Definition CParallelDataSorter.hpp:205
int * Conn_Pris_Par
Local connectivity of prism elements.
Definition CParallelDataSorter.hpp:60
unsigned long GetnPointLinear(unsigned short rank) const
Get the linear number of points \input rank - the processor rank.
Definition CParallelDataSorter.hpp:303
unsigned long nElem
Local number of elements.
Definition CParallelDataSorter.hpp:89
virtual void SortConnectivity(CConfig *config, CGeometry *geometry, const vector< string > &markerList)
Sort the connectivities into data structures (only for surface data sorters).
Definition CParallelDataSorter.hpp:157
double passivedouble
Definition code_config.hpp:129
passivedouble su2double
Definition code_config.hpp:181
passivedouble GetValue(const su2double &data)
Get the (primitive) value of the datatype (needs to be specialized for active types).
Definition datatype_structure.hpp:113
GEO_TYPE
Types of geometric entities based on VTK nomenclature.
Definition option_structure.hpp:131
@ TRIANGLE
VTK nomenclature for defining a triangle element.
Definition option_structure.hpp:134
@ PYRAMID
VTK nomenclature for defining a pyramid element.
Definition option_structure.hpp:139
@ PRISM
VTK nomenclature for defining a prism element.
Definition option_structure.hpp:138
@ QUADRILATERAL
VTK nomenclature for defining a quadrilateral element.
Definition option_structure.hpp:135
@ HEXAHEDRON
VTK nomenclature for defining a hexahedron element.
Definition option_structure.hpp:137
@ LINE
VTK nomenclature for defining a line element.
Definition option_structure.hpp:133
@ TETRAHEDRON
VTK nomenclature for defining a tetrahedron element.
Definition option_structure.hpp:136