Skip to content

Commit 36bc84c

Browse files
committed
Apply more changes from code review.
Create a common template CFEASolverBase for solvers using the internal finite elements.
1 parent 6df5603 commit 36bc84c

20 files changed

Lines changed: 351 additions & 300 deletions

Common/include/CConfig.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ class CConfig {
446446
bool SmoothSepDim; /*!< \brief Flag for enabling separated calculation for every dimension. */
447447
bool SmoothOnSurface; /*!< \brief Flag for assembling the system only on the surface. */
448448
bool SmoothDirichletSurfaceBound; /*!< \brief Flag for using zero Dirichlet boundary in the surface case. */
449-
unsigned short SmoothNumMode; /*!< \brief temporary flag for some debuging stuff */
449+
ENUM_SOBOLEV_MODUS SmoothNumMode; /*!< \brief The mode in which the Sobolev smoothing solver is applied. */
450450

451451
unsigned short Kind_Grad_Linear_Solver, /*!< Numerical method to smooth the gradient */
452452
Kind_Grad_Linear_Solver_Prec; /*!< \brief Preconditioner of the linear solver. */
@@ -9616,7 +9616,7 @@ class CConfig {
96169616
* \brief The modus of operation for the Sobolev solver
96179617
* \return returns on what level we operate
96189618
*/
9619-
unsigned short GetSobMode(void) const { return SmoothNumMode; }
9619+
ENUM_SOBOLEV_MODUS GetSobMode(void) const { return SmoothNumMode; }
96209620

96219621
/*!
96229622
* \brief Get the name of the file with the hessian of the objective function.

Common/include/option_structure.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,18 +2367,18 @@ enum class LINEAR_SOLVER_MODE {
23672367
/*!
23682368
* \brief mode of operation for the sobolev smoothing solver.
23692369
*/
2370-
enum ENUM_SOBOLEV_MODUS {
2371-
NO_MODUS, /*!< \brief Default option if none is choosen. */
2370+
enum class ENUM_SOBOLEV_MODUS {
2371+
NONE, /*!< \brief Default option if none is choosen. */
23722372
PARAM_LEVEL_COMPLETE, /*!< \brief Operate on parameter level. */
23732373
MESH_LEVEL, /*!< \brief Operate on mesh level. */
2374-
DEBUG, /*!< \brief Special flag for debugging. */
2375-
ONLY_GRAD, /*!< \brief Flag for OneShot to only compute the original gradient. */
2374+
ONLY_GRAD, /*!< \brief Flag to only compute the original gradient. */
23762375
};
23772376
static const MapType<std::string, ENUM_SOBOLEV_MODUS> Sobolev_Modus_Map = {
2378-
MakePair("NONE", ENUM_SOBOLEV_MODUS::NO_MODUS)
2379-
MakePair("PARAM_LEVEL_COMPLETE", ENUM_SOBOLEV_MODUS::PARAM_LEVEL_COMPLETE)
2380-
MakePair("MESH_LEVEL", ENUM_SOBOLEV_MODUS::MESH_LEVEL) MakePair("DEBUG", ENUM_SOBOLEV_MODUS::DEBUG)
2381-
MakePair("ONLY_GRADIENT", ENUM_SOBOLEV_MODUS::ONLY_GRAD)};
2377+
MakePair("NONE", ENUM_SOBOLEV_MODUS::NONE)
2378+
MakePair("PARAM_LEVEL_COMPLETE", ENUM_SOBOLEV_MODUS::PARAM_LEVEL_COMPLETE)
2379+
MakePair("MESH_LEVEL", ENUM_SOBOLEV_MODUS::MESH_LEVEL)
2380+
MakePair("ONLY_GRADIENT", ENUM_SOBOLEV_MODUS::ONLY_GRAD)
2381+
};
23822382

23832383
#undef MakePair
23842384
/* END_CONFIG_ENUMS */

Common/src/CConfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ void CConfig::SetConfig_Options() {
20122012
/* DESCRIPTION: Switch to activate zero Dirichlet boundary for surface mode */
20132013
addBoolOption("DIRICHLET_SURFACE_BOUNDARY", SmoothDirichletSurfaceBound, false);
20142014
/* DESCRIPTION: Switch to activate the debbuging modus */
2015-
addEnumOption("SOBOLEV_MODE", SmoothNumMode, Sobolev_Modus_Map, ENUM_SOBOLEV_MODUS::NO_MODUS);
2015+
addEnumOption("SOBOLEV_MODE", SmoothNumMode, Sobolev_Modus_Map, ENUM_SOBOLEV_MODUS::NONE);
20162016
/*!\brief HESS_OBJFUNC_FILENAME
20172017
* \n DESCRIPTION: Output filename for the Sobolev Hessian approximation. \ingroup Config*/
20182018
addStringOption("HESS_OBJFUNC_FILENAME", ObjFunc_Hess_FileName, string("of_hess.dat"));

Common/src/geometry/elements/CTETRA1.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727

2828
#include "../../../include/geometry/elements/CElement.hpp"
29-
29+
#include "../../../include/toolboxes/geometry_toolbox.hpp"
3030

3131
CTETRA1::CTETRA1() : CElementWithKnownSizes<NGAUSS,NNODE,NDIM>() {
3232

@@ -85,11 +85,8 @@ su2double CTETRA1::ComputeVolume(const FrameType mode) const {
8585
r3[iDim] = Coord[3][iDim] - Coord[0][iDim];
8686
}
8787

88-
CrossProduct[0] = (r1[1]*r2[2] - r1[2]*r2[1])*r3[0];
89-
CrossProduct[1] = (r1[2]*r2[0] - r1[0]*r2[2])*r3[1];
90-
CrossProduct[2] = (r1[0]*r2[1] - r1[1]*r2[0])*r3[2];
91-
92-
Volume = fabs(CrossProduct[0] + CrossProduct[1] + CrossProduct[2])/6.0;
88+
GeometryToolbox::CrossProduct(r1, r2, CrossProduct);
89+
Volume = fabs(GeometryToolbox::DotProduct(3, CrossProduct, r3))/6.0;
9390

9491
return Volume;
9592

Common/src/geometry/elements/CTETRA4.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727

2828
#include "../../../include/geometry/elements/CElement.hpp"
29-
29+
#include "../../../include/toolboxes/geometry_toolbox.hpp"
3030

3131
CTETRA4::CTETRA4() : CElementWithKnownSizes<NGAUSS,NNODE,NDIM>() {
3232

@@ -90,11 +90,8 @@ su2double CTETRA4::ComputeVolume(const FrameType mode) const {
9090
r3[iDim] = Coord[3][iDim] - Coord[0][iDim];
9191
}
9292

93-
CrossProduct[0] = (r1[1]*r2[2] - r1[2]*r2[1])*r3[0];
94-
CrossProduct[1] = (r1[2]*r2[0] - r1[0]*r2[2])*r3[1];
95-
CrossProduct[2] = (r1[0]*r2[1] - r1[1]*r2[0])*r3[2];
96-
97-
Volume = fabs(CrossProduct[0] + CrossProduct[1] + CrossProduct[2])/6.0;
93+
GeometryToolbox::CrossProduct(r1, r2, CrossProduct);
94+
Volume = fabs(GeometryToolbox::DotProduct(3, CrossProduct, r3))/6.0;
9895

9996
return Volume;
10097

SU2_CFD/include/solvers/CFEASolver.hpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,15 @@
2727

2828
#pragma once
2929

30-
#include "CSolver.hpp"
31-
#include "../../../Common/include/geometry/elements/CElement.hpp"
32-
#include "../../../Common/include/parallelization/omp_structure.hpp"
30+
#include "CFEASolverBase.hpp"
3331

3432
/*!
3533
* \class CFEASolver
3634
* \brief Main class for defining a FEM solver for elastic structural problems.
3735
* \author R. Sanchez.
3836
*/
39-
class CFEASolver : public CSolver {
37+
class CFEASolver : public CFEASolverBase {
4038
protected:
41-
enum : size_t {MAXNNODE_2D = 4};
42-
enum : size_t {MAXNNODE_3D = 8};
43-
enum : size_t {MAXNVAR = 3};
44-
enum : size_t {MAXNDIM = 3};
45-
enum : size_t {OMP_MIN_SIZE = 32};
46-
enum : size_t {OMP_MAX_SIZE = 512};
4739

4840
unsigned long omp_chunk_size; /*!< \brief Chunk size used in light point loops. */
4941

@@ -91,7 +83,6 @@ class CFEASolver : public CSolver {
9183
CSysMatrix<su2double> MassMatrix;
9284
#endif
9385

94-
CElement*** element_container = nullptr; /*!< \brief Vector which the define the finite element structure for each problem. */
9586
CProperty** element_properties = nullptr; /*!< \brief Vector which stores the properties of each element */
9687

9788
#ifdef HAVE_OMP
@@ -108,22 +99,6 @@ class CFEASolver : public CSolver {
10899
bool topol_filter_applied; /*!< \brief True if density filtering has been performed. */
109100
bool initial_calc = true; /*!< \brief Becomes false after first call to Preprocessing. */
110101

111-
unsigned long nElement; /*!< \brief Number of elements. */
112-
113-
/*--- Extra vertices for row/column elimination, see Set_VertexEliminationSchedule. ---*/
114-
vector<unsigned long> ExtraVerticesToEliminate;
115-
116-
/*!
117-
* \brief The highest level in the variable hierarchy this solver can safely use,
118-
* CVariable is the common denominator between the FEA and Mesh deformation variables.
119-
*/
120-
CVariable* nodes = nullptr;
121-
122-
/*!
123-
* \brief Return nodes to allow CSolver::base_nodes to be set.
124-
*/
125-
inline CVariable* GetBaseClassPointerToNodes() override { return nodes; }
126-
127102
/*!
128103
* \brief Get the element container index and number of nodes of a given VTK type.
129104
* \param[in] VTK_Type - Type of element.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*!
2+
* \file CFEASolver.hpp
3+
* \brief Base class template for all FEA solvers using the SU2 internal finite elements.
4+
* \author T. Dick
5+
* \version 7.2.1 "Blackbird"
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-2021, 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 "CSolver.hpp"
31+
#include "../../../Common/include/geometry/elements/CElement.hpp"
32+
#include "../../../Common/include/parallelization/omp_structure.hpp"
33+
34+
class CFEASolverBase : public CSolver {
35+
public:
36+
enum : size_t {MAXNNODE_2D = 4};
37+
enum : size_t {MAXNNODE_3D = 8};
38+
enum : size_t {MAXNDIM = 3};
39+
enum : size_t {MAXNVAR = 3};
40+
enum : size_t {OMP_MIN_SIZE = 32};
41+
enum : size_t {OMP_MAX_SIZE = 512};
42+
43+
protected:
44+
45+
CElement*** element_container = nullptr; /*!< \brief Vector which the define the finite element structure for each problem. */
46+
unsigned long nElement; /*!< \brief Number of elements. */
47+
48+
vector<unsigned long> ExtraVerticesToEliminate; /*!< Extra vertices for row/column elimination, see CommunicateExtraEliminationVertices. */
49+
50+
/*!
51+
* \brief The highest level in the variable hierarchy all derived solvers can safely use,
52+
* CVariable is the common denominator between the FEA, Mesh deformation, and smoothing variables.
53+
*/
54+
CVariable* nodes = nullptr;
55+
56+
/*!
57+
* \brief Return nodes to allow CSolver::base_nodes to be set.
58+
*/
59+
inline CVariable* GetBaseClassPointerToNodes() override { return nodes; }
60+
61+
public:
62+
/*!
63+
* \brief Constructor of the class.
64+
* \param[in] mesh_deform_mode - mode of operation for the linear solver.
65+
*/
66+
CFEASolverBase(LINEAR_SOLVER_MODE mesh_deform_mode = LINEAR_SOLVER_MODE::STANDARD);
67+
68+
/*!
69+
* \overload
70+
* \param[in] geometry - Geometrical definition of the problem.
71+
* \param[in] config - Definition of the particular problem.
72+
* \param[in] mesh_deform_mode - mode of operation for the linear solver.
73+
*/
74+
CFEASolverBase(CGeometry *geometry, CConfig *config, LINEAR_SOLVER_MODE mesh_deform_mode = LINEAR_SOLVER_MODE::STANDARD);
75+
76+
/*!
77+
* \brief Destructor of the class.
78+
*/
79+
~CFEASolverBase();
80+
81+
/*!
82+
* \brief Communicate extra vertices for elimination in the linear system.
83+
* \param[in] geometry - Geometrical definition of the problem.
84+
* \param[in] myPoints - List of global point indeces to eliminate.
85+
* \param[in] val_coord - Location (x, y, z) of the max residual point.
86+
*/
87+
void CommunicateExtraEliminationVertices(const CGeometry* geometry, vector<unsigned long>& myPoints);
88+
89+
};

SU2_CFD/include/solvers/CGradientSmoothingSolver.hpp

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,17 @@
2727

2828
#pragma once
2929

30-
#include "../../../Common/include/geometry/elements/CElement.hpp"
3130
#include "../../../Common/include/linear_algebra/CMatrixVectorProduct.hpp"
3231
#include "../../../Common/include/toolboxes/CSquareMatrixCM.hpp"
33-
#include "../../../SU2_CFD/include/solvers/CSolver.hpp"
32+
#include "../../../SU2_CFD/include/solvers/CFEASolverBase.hpp"
3433

3534
/*! \class CGradientSmoothingSolver
3635
* \brief Main class for defining a gradient smoothing.
3736
* \author T. Dick.
3837
* \date March 25, 2019.
3938
*/
40-
class CGradientSmoothingSolver : public CSolver {
39+
class CGradientSmoothingSolver final : public CFEASolverBase {
4140
public:
42-
enum : size_t {MAXNNODE_2D = 4};
43-
enum : size_t {MAXNNODE_3D = 8};
44-
enum : size_t {MAXNDIM = 3};
4541

4642
/** Introduction of a new alias for the data type to allow compilation with forward mode.
4743
*
@@ -57,32 +53,18 @@ class CGradientSmoothingSolver : public CSolver {
5753
using MatrixType = C2DContainer<unsigned long, su2double, StorageType::RowMajor, 64, DynamicSize, DynamicSize>;
5854

5955
private:
60-
unsigned long nElement;
61-
CElement*** element_container = nullptr; /*!< \brief Container which stores the element information. */
56+
unsigned int curDim; /*!< \brief If we separate dimensions this tells us in what dimension we currently are. */
6257

63-
unsigned int dir; /*!< \brief If we separate dimensions this tells us in what dimension we currently are. */
64-
65-
CSysVector<su2double> auxVec; /*!< \brief Auxiliar vectors for output and debugging */
6658
CSysVector<su2double> activeCoord; /*!< \brief Auxiliar vector to keep the indeces of geometry->vertex->Coord */
6759

6860
CSysVector<su2matvecscalar> helperVecIn; /*!< \brief Helper vectors for projection and matrix vector product (must be su2mixedfloat) */
6961
CSysVector<su2matvecscalar> helperVecOut; /*!< \brief Helper vectors for projection and matrix vector product (must be su2mixedfloat) */
70-
CSysVector<su2matvecscalar> helperVecAux; /*!< \brief Helper vectors for matrix vector product if working on surface (smaller dim) */
71-
72-
CVariable* nodes = nullptr; /*!< \brief The highest level in the variable hierarchy this solver can safely use. */
62+
CSysVector<su2matvecscalar> helperVecAux; /*!< \brief Helper vectors for matrix vector product if working on surface (smaller dim) */
7363

7464
std::vector<su2double> deltaP; /*!< \brief The smoothed gradient with respect to the design variables. */
7565

7666
CSquareMatrixCM hessian; /*!< \brief The approximated Hessian with respect to the design variables. */
7767

78-
/*--- Extra vertices for row/column elimination, see Set_VertexEliminationSchedule. ---*/
79-
vector<unsigned long> ExtraVerticesToEliminate;
80-
81-
/*!
82-
* \brief Return nodes to allow CSolver::base_nodes to be set.
83-
*/
84-
inline CVariable* GetBaseClassPointerToNodes() override { return nodes; }
85-
8668
public:
8769
/*!
8870
* \brief Constructor of the class.
@@ -244,26 +226,24 @@ class CGradientSmoothingSolver : public CSolver {
244226
/*!
245227
* \brief Write the content of sensitivity in the nodes to the sensitivity in the geometry
246228
* \param[in] geometry - Geometrical definition of the problem.
247-
* \param[in] config - Definition of the particular problem.
248229
*/
249-
void WriteSens2Geometry(CGeometry* geometry, const CConfig* config);
230+
void WriteSensToGeometry(CGeometry* geometry) const override;
250231

251232
/*!
252233
* \brief Read the sensitivity for the geometry into the nodes
253234
* \param[in] geometry - Geometrical definition of the problem.
254-
* \param[in] config - Definition of the particular problem.
255235
*/
256-
void ReadSens2Geometry(CGeometry* geometry, const CConfig* config);
236+
void ReadSensFromGeometry(const CGeometry *geometry) override;
257237

258238
/*!
259239
* \brief Copy sensitivities from a vector into the geometry
260240
*/
261-
void WriteVector2Geometry(CGeometry* geometry, const CConfig* config, CSysVector<su2matvecscalar>& vector);
241+
void WriteVectorToGeometry(CGeometry* geometry, const CSysVector<su2matvecscalar>& vector) const;
262242

263243
/*!
264244
* \brief Copy sensitivities from the geometry into a vector
265245
*/
266-
void ReadVector2Geometry(CGeometry* geometry, const CConfig* config, CSysVector<su2matvecscalar>& vector);
246+
void ReadVectorToGeometry(const CGeometry* geometry, CSysVector<su2matvecscalar>& vector);
267247

268248
/*!
269249
* \brief Get the value of the reference coordinate to set on the element structure.
@@ -309,4 +289,14 @@ class CGradientSmoothingSolver : public CSolver {
309289
}
310290
}
311291

292+
private:
293+
294+
inline void SetCurrentDim(unsigned int iDim) {
295+
curDim=iDim;
296+
}
297+
298+
inline const unsigned int& GetCurrentDim() const {
299+
return curDim;
300+
}
301+
312302
};

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include <set>
3939
#include <stdlib.h>
4040
#include <stdio.h>
41+
#include <unordered_set>
42+
#include <unordered_map>
4143

4244
#include "../fluid/CFluidModel.hpp"
4345
#include "../task_definition.hpp"
@@ -4200,16 +4202,15 @@ class CSolver {
42004202
/*!
42014203
* \brief A virtual member.
42024204
* \param[in] geometry - Geometrical definition of the problem.
4203-
* \param[in] config - Definition of the particular problem.
42044205
*/
4205-
virtual void ReadSens2Geometry(CGeometry* geometry, const CConfig* config) {}
4206+
virtual void ReadSensFromGeometry(const CGeometry* geometry) {}
42064207

42074208
/*!
42084209
* \brief A virtual member.
42094210
* \param[in] geometry - Geometrical definition of the problem.
42104211
* \param[in] config - Definition of the particular problem.
42114212
*/
4212-
virtual void WriteSens2Geometry(CGeometry* geometry, const CConfig* config) {}
4213+
virtual void WriteSensToGeometry(CGeometry* geometry) const {}
42134214

42144215
/*!
42154216
* \brief Routine that sets the flag controlling implicit treatment for periodic BCs.

SU2_CFD/include/variables/CSobolevSmoothingVariable.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class CSobolevSmoothingVariable final : public CVariable {
3434
MatrixType Sensitivity; /*!< Vector holding the derivative of target functional with respect to the coordinates at this node */
3535

3636
bool* boundary_vertex; /*!< \brief Stores if a point belongs to the boundary of a boundary. */
37-
unsigned long nBoundPoints;
3837

3938
/*!
4039
* \brief Constructor of the class.
@@ -72,9 +71,4 @@ class CSobolevSmoothingVariable final : public CVariable {
7271
* \brief return wether a point is a boundary of a boundary
7372
*/
7473
bool GetIsBoundaryPoint(unsigned long iPoint) const override;
75-
76-
/*!
77-
* \brief return the number of marked points
78-
*/
79-
unsigned int GetNBoundPoints() const override;
8074
};

0 commit comments

Comments
 (0)