Skip to content

Commit 772483b

Browse files
authored
Merge branch 'develop' into develop
2 parents f58d73e + 35389df commit 772483b

45 files changed

Lines changed: 1318 additions & 617 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Common/include/CConfig.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5804,6 +5804,13 @@ class CConfig {
58045804
*/
58055805
su2double GetTranslation_Rate(unsigned short iDim) const { return Translation_Rate[iDim];}
58065806

5807+
/*!
5808+
* \brief Set the translational velocity of the mesh.
5809+
* \param[in] iDim - spatial component
5810+
* \return Translational velocity of the mesh.
5811+
*/
5812+
void SetTranslation_Rate(unsigned short iDim, su2double val) { Translation_Rate[iDim] = val;}
5813+
58075814
/*!
58085815
* \brief Get the translational velocity of the marker.
58095816
* \param[in] iMarkerMoving - Index of the moving marker (as specified in Marker_Moving)

Common/include/basic_types/ad_structure.hpp

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ inline void RegisterInput(su2double& data, bool push_index = true) {}
7474
*/
7575
inline void RegisterOutput(su2double& data) {}
7676

77+
/*!
78+
* \brief Resize the adjoint vector, for subsequent access without bounds checking.
79+
*/
80+
inline void ResizeAdjoints() {}
81+
7782
/*!
7883
* \brief Sets the adjoint value at index to val
7984
* \param[in] index - Position in the adjoint vector.
@@ -369,11 +374,27 @@ FORCEINLINE void Reset() {
369374
}
370375
}
371376

377+
FORCEINLINE void ResizeAdjoints() { AD::getTape().resizeAdjointVector(); }
378+
372379
FORCEINLINE void SetIndex(int& index, const su2double& data) { index = data.getIdentifier(); }
373380

374-
FORCEINLINE void SetDerivative(int index, const double val) { AD::getTape().setGradient(index, val); }
381+
// WARNING: For performance reasons, this method does not perform bounds checking.
382+
// When using it, please ensure sufficient adjoint vector size by a call to AD::ResizeAdjoints().
383+
FORCEINLINE void SetDerivative(int index, const double val) {
384+
if (index == 0) // Allow multiple threads to "set the derivative" of passive variables without causing data races.
385+
return;
375386

376-
FORCEINLINE double GetDerivative(int index) { return AD::getTape().getGradient(index); }
387+
using BoundsChecking = codi::GradientAccessTapeInterface<su2double::Gradient, su2double::Identifier>::BoundsChecking;
388+
AD::getTape().setGradient(index, val, BoundsChecking::False);
389+
}
390+
391+
// WARNING: For performance reasons, this method does not perform bounds checking.
392+
// If called after tape evaluations, the adjoints should exist.
393+
// Otherwise, please ensure sufficient adjoint vector size by a call to AD::ResizeAdjoints().
394+
FORCEINLINE double GetDerivative(int index) {
395+
using BoundsChecking = codi::GradientAccessTapeInterface<su2double::Gradient, su2double::Identifier>::BoundsChecking;
396+
return AD::getTape().getGradient(index, BoundsChecking::False);
397+
}
377398

378399
FORCEINLINE bool IsIdentifierActive(su2double const& value) {
379400
return getTape().isIdentifierActive(value.getIdentifier());
@@ -523,26 +544,14 @@ FORCEINLINE void delete_handler(void* handler) {
523544

524545
FORCEINLINE bool BeginPassive() {
525546
if (AD::getTape().isActive()) {
526-
StopRecording();
547+
AD::getTape().setPassive();
527548
return true;
528549
}
529550
return false;
530551
}
531552

532553
FORCEINLINE void EndPassive(bool wasActive) {
533-
if (wasActive) StartRecording();
534-
}
535-
536-
FORCEINLINE bool PausePreaccumulation() {
537-
const auto current = PreaccEnabled;
538-
if (!current) return false;
539-
SU2_OMP_SAFE_GLOBAL_ACCESS(PreaccEnabled = false;)
540-
return true;
541-
}
542-
543-
FORCEINLINE void ResumePreaccumulation(bool wasActive) {
544-
if (!wasActive) return;
545-
SU2_OMP_SAFE_GLOBAL_ACCESS(PreaccEnabled = true;)
554+
if (wasActive) AD::getTape().setActive();
546555
}
547556

548557
FORCEINLINE void StartNoSharedReading() {
@@ -558,6 +567,19 @@ FORCEINLINE void EndNoSharedReading() {
558567
opdi::logic->addReverseBarrier();
559568
#endif
560569
}
570+
571+
FORCEINLINE bool PausePreaccumulation() {
572+
const auto current = PreaccEnabled;
573+
if (!current) return false;
574+
SU2_OMP_SAFE_GLOBAL_ACCESS(PreaccEnabled = false;)
575+
return true;
576+
}
577+
578+
FORCEINLINE void ResumePreaccumulation(bool wasActive) {
579+
if (!wasActive) return;
580+
SU2_OMP_SAFE_GLOBAL_ACCESS(PreaccEnabled = true;)
581+
}
582+
561583
#endif // CODI_REVERSE_TYPE
562584

563585
void Initialize();

Common/include/code_config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ FORCEINLINE Out su2staticcast_p(In ptr) {
9696
#include "codi/tools/data/externalFunctionUserData.hpp"
9797

9898
#if defined(HAVE_OMP)
99-
using su2double = codi::RealReverseIndexOpenMP;
99+
using su2double = codi::RealReverseIndexOpenMPGen<double, double>;
100100
#else
101101
#if defined(CODI_INDEX_TAPE)
102102
using su2double = codi::RealReverseIndex;

Common/include/geometry/CGeometry.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,6 @@ class CGeometry {
595595
return FindEdge(first_point, second_point, false) >= 0;
596596
}
597597

598-
/*!
599-
* \brief Get the distance between a plane (defined by three point) and a point.
600-
* \param[in] Coord - Coordinates of the point.
601-
* \param[in] iCoord - Coordinates of the first point that defines the plane.
602-
* \param[in] jCoord - Coordinates of the second point that defines the plane.
603-
* \param[in] kCoord - Coordinates of the third point that defines the plane.
604-
* \return Signed distance.
605-
*/
606-
su2double Point2Plane_Distance(const su2double* Coord, const su2double* iCoord, const su2double* jCoord,
607-
const su2double* kCoord);
608-
609598
/*!
610599
* \brief Create a file for testing the geometry.
611600
*/

Common/include/grid_movement/CFreeFormDefBox.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,10 @@ class CFreeFormDefBox : public CGridMovement {
642642
}
643643

644644
/*!
645-
* \brief Set, at each vertex, the index of the free form FFDBox that contains the vertex.
646-
* \param[in] geometry - Geometrical definition of the problem.
647-
* \param[in] config - Definition of the particular problem.
648-
* \param[in] iFFDBox - Index of the FFDBox.
645+
* \brief Returns true if the point is inside the FFD.
646+
* \param[in] coord - Coordinate of the point to check.
649647
*/
650-
bool GetPointFFD(CGeometry* geometry, CConfig* config, unsigned long iPoint) const;
648+
bool CheckPointInsideFFD(const su2double* coord) const;
651649

652650
/*!
653651
* \brief Set the zone of the computational domain that is going to be deformed.

Common/include/option_structure.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,11 +779,13 @@ static const MapType<std::string, ENUM_GUST_TYPE> Gust_Type_Map = {
779779
*/
780780
enum ENUM_GUST_DIR {
781781
X_DIR = 0, /*!< \brief Gust direction-X. */
782-
Y_DIR = 1 /*!< \brief Gust direction-Y. */
782+
Y_DIR = 1, /*!< \brief Gust direction-Y. */
783+
Z_DIR = 2 /*!< \brief Gust direction-Z. */
783784
};
784785
static const MapType<std::string, ENUM_GUST_DIR> Gust_Dir_Map = {
785786
MakePair("X_DIR", X_DIR)
786787
MakePair("Y_DIR", Y_DIR)
788+
MakePair("Z_DIR", Z_DIR)
787789
};
788790

789791
// If you add to ENUM_CENTERED, you must also add the option to ENUM_CONVECTIVE

Common/include/parallelization/omp_structure.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,14 @@ void omp_finalize();
188188
* thread, with all threads and memory views synchronized both beforehand and afterwards.
189189
*/
190190

191-
#define BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS \
192-
SU2_OMP_BARRIER \
191+
#define BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS \
192+
SU2_OMP_BARRIER \
193+
if (omp_in_parallel()) AD::StartNoSharedReading(); \
193194
SU2_OMP_MASTER
194195

195-
#define END_SU2_OMP_SAFE_GLOBAL_ACCESS \
196-
END_SU2_OMP_MASTER \
196+
#define END_SU2_OMP_SAFE_GLOBAL_ACCESS \
197+
END_SU2_OMP_MASTER \
198+
if (omp_in_parallel()) AD::EndNoSharedReading(); \
197199
SU2_OMP_BARRIER
198200

199201
#define SU2_OMP_SAFE_GLOBAL_ACCESS(...) BEGIN_SU2_OMP_SAFE_GLOBAL_ACCESS{__VA_ARGS__} END_SU2_OMP_SAFE_GLOBAL_ACCESS

Common/include/toolboxes/geometry_toolbox.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ inline void QuadrilateralNormal(const T& coords, U* normal) {
150150
normal[2] *= 0.5;
151151
}
152152

153+
/*! \brief Signed distance from a point to a plane defined by 3 coordinates. */
154+
template <class T, class U>
155+
inline U PointToPlaneDistance(const T& coords, const U* point) {
156+
U normal[3], distance[3];
157+
TriangleNormal(coords, normal);
158+
Distance(3, point, coords[0], distance);
159+
return DotProduct(3, distance, normal) / Norm(3, normal);
160+
}
161+
153162
/*!
154163
* \brief Compute a 3D rotation matrix.
155164
* \note The implicit ordering is rotation about the x, y, and then z axis.

Common/src/geometry/CGeometry.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,30 +1246,6 @@ void CGeometry::PostPeriodicSends(CGeometry* geometry, const CConfig* config, un
12461246
#endif
12471247
}
12481248

1249-
su2double CGeometry::Point2Plane_Distance(const su2double* Coord, const su2double* iCoord, const su2double* jCoord,
1250-
const su2double* kCoord) {
1251-
su2double CrossProduct[3], iVector[3], jVector[3], distance, modulus;
1252-
unsigned short iDim;
1253-
1254-
for (iDim = 0; iDim < 3; iDim++) {
1255-
iVector[iDim] = jCoord[iDim] - iCoord[iDim];
1256-
jVector[iDim] = kCoord[iDim] - iCoord[iDim];
1257-
}
1258-
1259-
CrossProduct[0] = iVector[1] * jVector[2] - iVector[2] * jVector[1];
1260-
CrossProduct[1] = iVector[2] * jVector[0] - iVector[0] * jVector[2];
1261-
CrossProduct[2] = iVector[0] * jVector[1] - iVector[1] * jVector[0];
1262-
1263-
modulus =
1264-
sqrt(CrossProduct[0] * CrossProduct[0] + CrossProduct[1] * CrossProduct[1] + CrossProduct[2] * CrossProduct[2]);
1265-
1266-
distance = 0.0;
1267-
for (iDim = 0; iDim < 3; iDim++) distance += CrossProduct[iDim] * (Coord[iDim] - iCoord[iDim]);
1268-
distance /= modulus;
1269-
1270-
return distance;
1271-
}
1272-
12731249
void CGeometry::SetEdges() {
12741250
nEdge = 0;
12751251
for (auto iPoint = 0ul; iPoint < nPoint; iPoint++) {

Common/src/grid_movement/CFreeFormDefBox.cpp

Lines changed: 20 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "../../include/grid_movement/CFreeFormDefBox.hpp"
2929
#include "../../include/grid_movement/CBezierBlending.hpp"
3030
#include "../../include/grid_movement/CBSplineBlending.hpp"
31+
#include "../../include/toolboxes/geometry_toolbox.hpp"
3132

3233
CFreeFormDefBox::CFreeFormDefBox() : CGridMovement() {}
3334

@@ -1014,13 +1015,8 @@ su2double* CFreeFormDefBox::GetParametricCoord_Iterative(unsigned long iPoint, s
10141015
return ParamCoord;
10151016
}
10161017

1017-
bool CFreeFormDefBox::GetPointFFD(CGeometry* geometry, CConfig* config, unsigned long iPoint) const {
1018-
bool Inside = true;
1019-
bool cylindrical = (config->GetFFD_CoordSystem() == CYLINDRICAL);
1020-
bool spherical = (config->GetFFD_CoordSystem() == SPHERICAL);
1021-
bool polar = (config->GetFFD_CoordSystem() == POLAR);
1022-
1023-
/*--- indices of the FFD box. Note that the front face is labelled 0,1,2,3 and the back face is 4,5,6,7 ---*/
1018+
bool CFreeFormDefBox::CheckPointInsideFFD(const su2double* coord) const {
1019+
/*--- Indices of the FFD box. Note that the front face is labelled 0,1,2,3 and the back face is 4,5,6,7 ---*/
10241020

10251021
unsigned short Index[6][5] = {{0, 1, 2, 3, 0}, // front side
10261022
{1, 5, 6, 2, 1}, // right side
@@ -1029,76 +1025,34 @@ bool CFreeFormDefBox::GetPointFFD(CGeometry* geometry, CConfig* config, unsigned
10291025
{4, 5, 1, 0, 4}, // bottom side
10301026
{4, 7, 6, 5, 4}}; // back side
10311027

1032-
/*--- The current approach is to subdivide each of the 6 faces of the hexahedral FFD box into 4 triangles
1033-
by defining a supporting middle point. This allows nonplanar FFD boxes.
1034-
Note that the definition of the FFD box is as follows: the FFD box is a 6-sided die and we are looking at the side
1035-
"1". The opposite side is side "6". If we are looking at side "1", we define the nodes counterclockwise. If we are
1036-
looking at side "6", we define the face clockwise ---*/
1037-
1038-
unsigned short nDim = geometry->GetnDim();
1039-
1040-
su2double Coord[3] = {0.0, 0.0, 0.0};
1041-
for (unsigned short iDim = 0; iDim < nDim; iDim++) Coord[iDim] = geometry->nodes->GetCoord(iPoint, iDim);
1042-
1043-
su2double X_0, Y_0, Z_0, Xbar, Ybar, Zbar;
1044-
1045-
if (cylindrical) {
1046-
X_0 = config->GetFFD_Axis(0);
1047-
Y_0 = config->GetFFD_Axis(1);
1048-
Z_0 = config->GetFFD_Axis(2);
1049-
1050-
Xbar = Coord[0] - X_0;
1051-
Ybar = Coord[1] - Y_0;
1052-
Zbar = Coord[2] - Z_0;
1053-
1054-
Coord[0] = sqrt(Ybar * Ybar + Zbar * Zbar);
1055-
Coord[1] = atan2(Zbar, Ybar);
1056-
if (Coord[1] > PI_NUMBER / 2.0) Coord[1] -= 2.0 * PI_NUMBER;
1057-
Coord[2] = Xbar;
1028+
/*--- The current approach is to subdivide each of the 6 faces of the hexahedral FFD box into 4 triangles by defining
1029+
a supporting middle point. This allows nonplanar FFD boxes. Note that the definition of the FFD box is as follows:
1030+
the FFD box is a 6-sided die and we are looking at the side "1". The opposite side is side "6". If we are looking at
1031+
side "1", we define the nodes counterclockwise. If we are looking at side "6", we define the face clockwise. ---*/
10581032

1059-
}
1060-
1061-
else if (spherical || polar) {
1062-
X_0 = config->GetFFD_Axis(0);
1063-
Y_0 = config->GetFFD_Axis(1);
1064-
Z_0 = config->GetFFD_Axis(2);
1065-
1066-
Xbar = Coord[0] - X_0;
1067-
Ybar = Coord[1] - Y_0;
1068-
Zbar = Coord[2] - Z_0;
1069-
1070-
Coord[0] = sqrt(Xbar * Xbar + Ybar * Ybar + Zbar * Zbar);
1071-
Coord[1] = atan2(Zbar, Ybar);
1072-
if (Coord[1] > PI_NUMBER / 2.0) Coord[1] -= 2.0 * PI_NUMBER;
1073-
Coord[2] = acos(Xbar / Coord[0]);
1074-
}
1033+
/*--- Loop over the faces of the FFD box. ---*/
10751034

1076-
/*--- loop over the faces of the FFD box ---*/
1035+
for (unsigned short iFace = 0; iFace < 6; iFace++) {
1036+
/*--- Every face needs an interpolated middle point for the triangles. ---*/
10771037

1078-
for (unsigned short iVar = 0; iVar < 6; iVar++) {
10791038
su2double P[3] = {0.0, 0.0, 0.0};
1080-
1081-
/*--- every face needs an interpolated middle point for the triangles ---*/
1082-
10831039
for (int p = 0; p < 4; p++) {
1084-
P[0] += 0.25 * Coord_Corner_Points[Index[iVar][p]][0];
1085-
P[1] += 0.25 * Coord_Corner_Points[Index[iVar][p]][1];
1086-
P[2] += 0.25 * Coord_Corner_Points[Index[iVar][p]][2];
1040+
P[0] += 0.25 * Coord_Corner_Points[Index[iFace][p]][0];
1041+
P[1] += 0.25 * Coord_Corner_Points[Index[iFace][p]][1];
1042+
P[2] += 0.25 * Coord_Corner_Points[Index[iFace][p]][2];
10871043
}
10881044

1089-
/*--- loop over the 4 triangles making up the FFD box. The sign is equal for all distances ---*/
1045+
/*--- Loop over the 4 triangles making up the FFD box. The sign should be equal for all distances. ---*/
10901046

1091-
for (unsigned short jVar = 0; jVar < 4; jVar++) {
1092-
su2double Distance_Point = geometry->Point2Plane_Distance(Coord, Coord_Corner_Points[Index[iVar][jVar]],
1093-
Coord_Corner_Points[Index[iVar][jVar + 1]], P);
1094-
if (Distance_Point < 0) {
1095-
Inside = false;
1096-
return Inside;
1047+
for (int iNode = 0; iNode < 4; iNode++) {
1048+
const su2double* plane[] = {P, Coord_Corner_Points[Index[iFace][iNode]],
1049+
Coord_Corner_Points[Index[iFace][iNode + 1]]};
1050+
if (GeometryToolbox::PointToPlaneDistance(plane, coord) < 0) {
1051+
return false;
10971052
}
10981053
}
10991054
}
1100-
1101-
return Inside;
1055+
return true;
11021056
}
11031057

11041058
su2double CFreeFormDefBox::GetDerivative1(su2double* uvw, unsigned short val_diff, unsigned short* ijk,

0 commit comments

Comments
 (0)