Skip to content

Commit bd586f6

Browse files
authored
Merge pull request #1372 from su2code/improve_mg
Cleanup and document the multigrid agglomeration strategy
2 parents d1e3568 + c4f27dc commit bd586f6

11 files changed

Lines changed: 448 additions & 610 deletions

File tree

Common/include/geometry/CGeometry.hpp

Lines changed: 58 additions & 62 deletions
Large diffs are not rendered by default.

Common/include/geometry/CMultiGridGeometry.hpp

Lines changed: 102 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,7 @@
3636
* \author F. Palacios
3737
*/
3838
class CMultiGridGeometry final : public CGeometry {
39-
40-
public:
41-
/*--- This is to suppress Woverloaded-virtual, omitting it has no negative impact. ---*/
42-
using CGeometry::SetVertex;
43-
using CGeometry::SetControlVolume;
44-
using CGeometry::SetBoundControlVolume;
45-
using CGeometry::SetPoint_Connectivity;
46-
47-
/*!
48-
* \brief Constructor of the class.
49-
* \param[in] geometry - Geometrical definition of the problem.
50-
* \param[in] config - Definition of the particular problem.
51-
* \param[in] iMesh - Level of the multigrid.
52-
* \param[in] iZone - Current zone in the mesh.
53-
*/
54-
CMultiGridGeometry(CGeometry **geometry, CConfig *config_container, unsigned short iMesh);
55-
39+
private:
5640
/*!
5741
* \brief Determine if a CVPoint van be agglomerated, if it have the same marker point as the seed.
5842
* \param[in] CVPoint - Control volume to be agglomerated.
@@ -61,101 +45,159 @@ class CMultiGridGeometry final : public CGeometry {
6145
* \param[in] config - Definition of the particular problem.
6246
* \return <code>TRUE</code> or <code>FALSE</code> depending if the control volume can be agglomerated.
6347
*/
64-
bool SetBoundAgglomeration(unsigned long CVPoint, short marker_seed, CGeometry *fine_grid, CConfig *config);
48+
bool SetBoundAgglomeration(unsigned long CVPoint, short marker_seed, const CGeometry *fine_grid,
49+
const CConfig *config) const;
6550

6651
/*!
6752
* \brief Determine if a can be agglomerated using geometrical criteria.
6853
* \param[in] iPoint - Seed point.
6954
* \param[in] fine_grid - Geometrical definition of the problem.
7055
* \param[in] config - Definition of the particular problem.
7156
*/
72-
bool GeometricalCheck(unsigned long iPoint, CGeometry *fine_grid, CConfig *config);
57+
bool GeometricalCheck(unsigned long iPoint, const CGeometry *fine_grid, const CConfig *config) const;
7358

7459
/*!
7560
* \brief Determine if a CVPoint van be agglomerated, if it have the same marker point as the seed.
76-
* \param[in] Suitable_Indirect_Neighbors - List of Indirect Neighbours that can be agglomerated.
61+
* \param[out] Suitable_Indirect_Neighbors - List of Indirect Neighbours that can be agglomerated.
7762
* \param[in] iPoint - Seed point.
7863
* \param[in] Index_CoarseCV - Index of agglomerated point.
7964
* \param[in] fine_grid - Geometrical definition of the problem.
8065
*/
81-
void SetSuitableNeighbors(vector<unsigned long> *Suitable_Indirect_Neighbors, unsigned long iPoint,
82-
unsigned long Index_CoarseCV, CGeometry *fine_grid);
66+
void SetSuitableNeighbors(vector<unsigned long>& Suitable_Indirect_Neighbors, unsigned long iPoint,
67+
unsigned long Index_CoarseCV, const CGeometry *fine_grid) const;
8368

8469
/*!
85-
* \brief Set boundary vertex.
86-
* \param[in] geometry - Geometrical definition of the problem.
87-
* \param[in] config - Definition of the particular problem.
70+
* \brief Set a representative wall value of the agglomerated control volumes on a particular boundary marker.
71+
* \param[in] fine_grid - Geometrical definition of the problem.
72+
* \param[in] val_marker - Index of the boundary marker.
73+
* \param[in] wall_quantity - Object with methods Get(iVertex_fine) and Set(iVertex_coarse, val).
8874
*/
89-
void SetVertex(CGeometry *geometry, CConfig *config) override;
75+
template <class T>
76+
void SetMultiGridWallQuantity(const CGeometry *fine_grid, unsigned short val_marker, T& wall_quantity) {
77+
78+
for (auto iVertex = 0ul; iVertex < nVertex[val_marker]; iVertex++) {
79+
const auto Point_Coarse = vertex[val_marker][iVertex]->GetNode();
80+
81+
if (!nodes->GetDomain(Point_Coarse)) continue;
82+
83+
su2double Area_Parent = 0.0;
84+
85+
/*--- Compute area parent by taking into account only volumes that are on the marker. ---*/
86+
for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(Point_Coarse); iChildren++) {
87+
const auto Point_Fine = nodes->GetChildren_CV(Point_Coarse, iChildren);
88+
const auto isVertex = fine_grid->nodes->GetDomain(Point_Fine) &&
89+
(fine_grid->nodes->GetVertex(Point_Fine, val_marker) != -1);
90+
if (isVertex) {
91+
Area_Parent += fine_grid->nodes->GetVolume(Point_Fine);
92+
}
93+
}
94+
95+
su2double Quantity_Coarse = 0.0;
96+
97+
/*--- Loop again to average coarser value. ---*/
98+
for (auto iChildren = 0u; iChildren < nodes->GetnChildren_CV(Point_Coarse); iChildren++) {
99+
const auto Point_Fine = nodes->GetChildren_CV(Point_Coarse, iChildren);
100+
const auto isVertex = fine_grid->nodes->GetDomain(Point_Fine) &&
101+
(fine_grid->nodes->GetVertex(Point_Fine, val_marker) != -1);
102+
if (isVertex) {
103+
const auto Vertex_Fine = fine_grid->nodes->GetVertex(Point_Fine, val_marker);
104+
const auto Area_Children = fine_grid->nodes->GetVolume(Point_Fine);
105+
Quantity_Coarse += wall_quantity.Get(Vertex_Fine) * Area_Children / Area_Parent;
106+
}
107+
}
108+
109+
/*--- Set the value at the coarse level. ---*/
110+
wall_quantity.Set(iVertex, Quantity_Coarse);
111+
}
112+
113+
}
114+
115+
public:
116+
/*--- This is to suppress Woverloaded-virtual, omitting it has no negative impact. ---*/
117+
using CGeometry::SetVertex;
118+
using CGeometry::SetControlVolume;
119+
using CGeometry::SetBoundControlVolume;
120+
using CGeometry::SetPoint_Connectivity;
90121

91122
/*!
92-
* \brief Set points which surround a point.
93-
* \param[in] geometry - Geometrical definition of the problem.
123+
* \brief Constructor of the class.
124+
* \param[in] fine_grid - Geometrical definition of the problem.
125+
* \param[in] config - Definition of the particular problem.
126+
* \param[in] iMesh - Level of the multigrid.
94127
*/
95-
void SetPoint_Connectivity(CGeometry *geometry) override;
128+
CMultiGridGeometry(CGeometry *fine_grid, CConfig *config, unsigned short iMesh);
96129

97130
/*!
98-
* \brief Set the edge structure of the agglomerated control volume.
131+
* \brief Set boundary vertex.
132+
* \param[in] fine_grid - Geometrical definition of the problem.
99133
* \param[in] config - Definition of the particular problem.
100-
* \param[in] geometry - Geometrical definition of the problem.
101-
* \param[in] action - Allocate or not the new elements.
102134
*/
103-
void SetControlVolume(CConfig *config, CGeometry *geometry, unsigned short action) override;
135+
void SetVertex(const CGeometry *fine_grid, const CConfig *config) override;
104136

105137
/*!
106-
* \brief Mach the near field boundary condition.
107-
* \param[in] config - Definition of the particular problem.
138+
* \brief Set points which surround a point.
139+
* \param[in] fine_grid - Geometrical definition of the child grid.
108140
*/
109-
void MatchActuator_Disk(CConfig *config) override;
141+
void SetPoint_Connectivity(const CGeometry *fine_grid) override;
110142

111143
/*!
112-
* \brief Mach the periodic boundary conditions.
113-
* \param[in] config - Definition of the particular problem.
114-
* \param[in] val_periodic - Index of the first periodic face in a pair.
144+
* \brief Set the edge structure of the agglomerated control volume.
145+
* \param[in] fine_grid - Geometrical definition of the problem.
146+
* \param[in] action - Allocate or not the new elements.
115147
*/
116-
void MatchPeriodic(CConfig *config, unsigned short val_periodic) override;
148+
void SetControlVolume(const CGeometry *fine_grid, unsigned short action) override;
117149

118150
/*!
119151
* \brief Set boundary vertex structure of the agglomerated control volume.
120-
* \param[in] config - Definition of the particular problem.
121-
* \param[in] geometry - Geometrical definition of the problem.
152+
* \param[in] fine_grid - Geometrical definition of the problem.
122153
* \param[in] action - Allocate or not the new elements.
123154
*/
124-
void SetBoundControlVolume(CConfig *config, CGeometry *geometry, unsigned short action) override;
155+
void SetBoundControlVolume(const CGeometry *fine_grid, unsigned short action) override;
125156

126157
/*!
127158
* \brief Set a representative coordinates of the agglomerated control volume.
128-
* \param[in] geometry - Geometrical definition of the problem.
159+
* \param[in] fine_grid - Geometrical definition of the problem.
129160
*/
130-
void SetCoord(CGeometry *geometry) override;
161+
void SetCoord(const CGeometry *fine_grid) override;
131162

132163
/*!
133-
* \brief Set a representative wall normal heat flux of the agglomerated control volume on a particular boundary marker.
134-
* \param[in] geometry - Geometrical definition of the problem.
135-
* \param[in] val_marker - Index of the boundary marker.
164+
* \brief Set the grid velocity at each node in the coarse mesh level based
165+
* on a restriction from a finer mesh.
166+
* \param[in] fine_grid - Geometry container for the finer mesh level.
136167
*/
137-
void SetMultiGridWallHeatFlux(CGeometry *geometry, unsigned short val_marker) override;
168+
void SetRestricted_GridVelocity(const CGeometry *fine_grid) override;
138169

139170
/*!
140-
* \brief Set a representative wall temperature of the agglomerated control volume on a particular boundary marker.
141-
* \param[in] geometry - Geometrical definition of the problem.
142-
* \param[in] val_marker - Index of the boundary marker.
171+
* \brief Find and store the closest neighbor to a vertex.
172+
* \param[in] config - Definition of the particular problem.
143173
*/
144-
void SetMultiGridWallTemperature(CGeometry *geometry, unsigned short val_marker) override;
174+
void FindNormal_Neighbor(const CConfig *config) override;
145175

146176
/*!
147-
* \brief Set the grid velocity at each node in the coarse mesh level based
148-
* on a restriction from a finer mesh.
149-
* \param[in] fine_mesh - Geometry container for the finer mesh level.
177+
* \brief Mach the near field boundary condition.
150178
* \param[in] config - Definition of the particular problem.
151179
*/
152-
void SetRestricted_GridVelocity(CGeometry *fine_mesh, const CConfig *config) override;
180+
void MatchActuator_Disk(const CConfig *config) override;
153181

154182
/*!
155-
* \brief Find and store the closest neighbor to a vertex.
183+
* \brief Mach the periodic boundary conditions.
156184
* \param[in] config - Definition of the particular problem.
185+
* \param[in] val_periodic - Index of the first periodic face in a pair.
157186
*/
158-
void FindNormal_Neighbor(CConfig *config) override;
187+
void MatchPeriodic(const CConfig *config, unsigned short val_periodic) override;
159188

160-
};
189+
/*!
190+
* \brief Set a representative wall normal heat flux of the agglomerated control volume on a particular boundary marker.
191+
* \param[in] fine_grid - Geometrical definition of the problem.
192+
* \param[in] val_marker - Index of the boundary marker.
193+
*/
194+
void SetMultiGridWallHeatFlux(const CGeometry *fine_grid, unsigned short val_marker) override;
161195

196+
/*!
197+
* \brief Set a representative wall temperature of the agglomerated control volume on a particular boundary marker.
198+
* \param[in] fine_grid - Geometrical definition of the problem.
199+
* \param[in] val_marker - Index of the boundary marker.
200+
*/
201+
void SetMultiGridWallTemperature(const CGeometry *fine_grid, unsigned short val_marker) override;
202+
203+
};

Common/include/geometry/CPhysicalGeometry.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class CPhysicalGeometry final : public CGeometry {
400400
* \brief Set boundary vertex.
401401
* \param[in] config - Definition of the particular problem.
402402
*/
403-
void SetVertex(CConfig *config) override;
403+
void SetVertex(const CConfig *config) override;
404404

405405
/*!
406406
* \brief Set number of span wise level for turbomachinery computation.
@@ -449,14 +449,14 @@ class CPhysicalGeometry final : public CGeometry {
449449
* \brief Mach the near field boundary condition.
450450
* \param[in] config - Definition of the particular problem.
451451
*/
452-
void MatchActuator_Disk(CConfig *config) override;
452+
void MatchActuator_Disk(const CConfig *config) override;
453453

454454
/*!
455455
* \brief Mach the periodic boundary conditions.
456456
* \param[in] config - Definition of the particular problem.
457457
* \param[in] val_periodic - Index of the first periodic face in a pair.
458458
*/
459-
void MatchPeriodic(CConfig *config, unsigned short val_periodic) override;
459+
void MatchPeriodic(const CConfig *config, unsigned short val_periodic) override;
460460

461461
/*!
462462
* \brief Set boundary vertex structure of the control volume.
@@ -580,7 +580,7 @@ class CPhysicalGeometry final : public CGeometry {
580580
* \brief Find and store the closest neighbor to a vertex.
581581
* \param[in] config - Definition of the particular problem.
582582
*/
583-
void FindNormal_Neighbor(CConfig *config) override;
583+
void FindNormal_Neighbor(const CConfig *config) override;
584584

585585
/*!
586586
* \brief Read the sensitivity from an input file.

Common/src/fem/geometry_structure_fem_part.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ void CPhysicalGeometry::Read_SU2_Format_Parallel_FEM(CConfig *config,
583583

584584
/*--- Allocate the memory for the coordinates to be stored on this rank. ---*/
585585
nPoint = nodeIDsElemLoc.size();
586-
nPointNode = nPoint;
587586
nodes = new CPoint(nPoint, nDim);
588587

589588
/*--- Open the grid file again and go to the position where
@@ -1146,7 +1145,6 @@ void CPhysicalGeometry::Read_CGNS_Format_Parallel_FEM(CConfig *config,
11461145

11471146
/*--- Allocate the memory for the coordinates to be stored on this rank. ---*/
11481147
nPoint = nodeIDsElemLoc.size();
1149-
nPointNode = nPoint;
11501148
nodes = new CPoint(nPoint, nDim);
11511149

11521150
/*--- Store the global ID's of the nodes in such a way that they can
@@ -1283,7 +1281,6 @@ void CPhysicalGeometry::Read_CGNS_Format_Parallel_FEM(CConfig *config,
12831281
/*--- Sequential mode. Create the data for the points. The global
12841282
number of points equals the local number of points. ---*/
12851283
nPoint = Global_nPoint;
1286-
nPointNode = nPoint;
12871284
nodes = new CPoint(nPoint, nDim);
12881285

12891286
for(unsigned long i=0; i<nPoint; ++i) {

Common/src/geometry/CGeometry.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ void CGeometry::TestGeometry(void) const {
14871487
}
14881488

14891489
bool CGeometry::SegmentIntersectsPlane(const su2double *Segment_P0, const su2double *Segment_P1, su2double Variable_P0, su2double Variable_P1,
1490-
const su2double *Plane_P0, const su2double *Plane_Normal, su2double *Intersection, su2double &Variable_Interp) {
1490+
const su2double *Plane_P0, const su2double *Plane_Normal, su2double *Intersection, su2double &Variable_Interp) {
14911491
su2double u[3], v[3], Denominator, Numerator, Aux, ModU;
14921492
su2double epsilon = 1E-6; // An epsilon is added to eliminate, as much as possible, the posibility of a line that intersects a point
14931493
unsigned short iDim;
@@ -2430,8 +2430,8 @@ void CGeometry::UpdateGeometry(CGeometry **geometry_container, CConfig *config)
24302430
for (unsigned short iMesh = 1; iMesh <= config->GetnMGLevels(); iMesh++) {
24312431
/*--- Update the control volume structures ---*/
24322432

2433-
geometry_container[iMesh]->SetControlVolume(config,geometry_container[iMesh-1], UPDATE);
2434-
geometry_container[iMesh]->SetBoundControlVolume(config,geometry_container[iMesh-1], UPDATE);
2433+
geometry_container[iMesh]->SetControlVolume(geometry_container[iMesh-1], UPDATE);
2434+
geometry_container[iMesh]->SetBoundControlVolume(geometry_container[iMesh-1], UPDATE);
24352435
geometry_container[iMesh]->SetCoord(geometry_container[iMesh-1]);
24362436

24372437
}

0 commit comments

Comments
 (0)