Skip to content

Commit

Permalink
Merge branch 'develop' into feature_new_flamelet
Browse files Browse the repository at this point in the history
  • Loading branch information
EvertBunschoten authored Jan 3, 2024
2 parents ee5c4aa + 2c9fbb6 commit 93b85b6
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 24 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Eduardo Molina
Edwin van der Weide
Ethan Alan Hereth
Florian Dittmann
Filip Hahs
Francesco Poli
Francisco D. Palacios
Gaurav Bansal
Expand Down
25 changes: 25 additions & 0 deletions Common/include/CConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,7 @@ class CConfig {
string caseName; /*!< \brief Name of the current case */

unsigned long edgeColorGroupSize; /*!< \brief Size of the edge groups colored for OpenMP parallelization of edge loops. */
bool edgeColoringRelaxDiscAdj; /*!< \brief Allow fallback to smaller edge color group sizes and use more colors for the discrete adjoint. */

INLET_SPANWISE_INTERP Kind_InletInterpolationFunction; /*!brief type of spanwise interpolation function to use for the inlet face. */
INLET_INTERP_TYPE Kind_Inlet_InterpolationType; /*!brief type of spanwise interpolation data to use for the inlet face. */
Expand Down Expand Up @@ -5947,6 +5948,15 @@ class CConfig {
*/
su2double GetMarkerTranslationRate(unsigned short iMarkerMoving, unsigned short iDim) const { return MarkerTranslation_Rate[3*iMarkerMoving + iDim];}

/*!
* \brief Set the translation rate of the marker.
* \param[in] iDim - spatial component
* \param[in] val - translational velocity
*/
void SetMarkerTranslationRate(unsigned short iMarkerMoving, unsigned short iDim, su2double val) {
MarkerTranslation_Rate[3 * iMarkerMoving + iDim] = val;
}

/*!
* \brief Get the rotation rate of the mesh.
* \param[in] iDim - spatial component
Expand All @@ -5970,6 +5980,16 @@ class CConfig {
*/
su2double GetMarkerRotationRate(unsigned short iMarkerMoving, unsigned short iDim) const { return MarkerRotation_Rate[3*iMarkerMoving + iDim];}

/*!
* \brief Set the rotation rate of the marker.
* \param[in] iMarkerMoving - Index of the moving marker (as specified in Marker_Moving)
* \param[in] iDim - spatial component
* \param[in] val - Rotational velocity
*/
void SetMarkerRotationRate(unsigned short iMarkerMoving, unsigned short iDim, su2double val) {
MarkerRotation_Rate[3 * iMarkerMoving + iDim] = val;
}

/*!
* \brief Get the pitching rate of the mesh.
* \param[in] iDim - spatial component
Expand Down Expand Up @@ -9678,6 +9698,11 @@ class CConfig {
*/
unsigned long GetEdgeColoringGroupSize(void) const { return edgeColorGroupSize; }

/*!
* \brief Check if the discrete adjoint is allowed to relax the coloring, that is, allow smaller edge color group sizes and allow more colors.
*/
bool GetEdgeColoringRelaxDiscAdj() const { return edgeColoringRelaxDiscAdj; }

/*!
* \brief Get the ParMETIS load balancing tolerance.
*/
Expand Down
6 changes: 5 additions & 1 deletion Common/include/geometry/CGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1720,10 +1720,14 @@ class CGeometry {
/*!
* \brief Get the edge coloring.
* \note This method computes the coloring if that has not been done yet.
* \note Can be instructed to determine and use the maximum edge color group size between 1 and
* CGeometry::edgeColorGroupSize that yields a coloring that is at least as efficient as #COLORING_EFF_THRESH.
* \param[out] efficiency - optional output of the coloring efficiency.
* \param[in] maximizeEdgeColorGroupSize - use the maximum edge color group size that gives an efficient coloring.
* \return Reference to the coloring.
*/
const CCompressedSparsePatternUL& GetEdgeColoring(su2double* efficiency = nullptr);
const CCompressedSparsePatternUL& GetEdgeColoring(su2double* efficiency = nullptr,
bool maximizeEdgeColorGroupSize = false);

/*!
* \brief Force the natural (sequential) edge coloring.
Expand Down
2 changes: 1 addition & 1 deletion Common/include/toolboxes/graph_toolbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ T createNaturalColoring(Index_t numInnerIndexes) {
* \param[out] indexColor - Optional, vector with colors given to the outer indices.
* \return Coloring in the same type of the input pattern.
*/
template <typename Color_t = char, size_t MaxColors = 64, size_t MaxMB = 128, class T>
template <typename Color_t = unsigned char, size_t MaxColors = 255, size_t MaxMB = 128, class T>
T colorSparsePattern(const T& pattern, size_t groupSize = 1, bool balanceColors = false,
std::vector<Color_t>* indexColor = nullptr) {
static_assert(std::is_integral<Color_t>::value, "");
Expand Down
3 changes: 3 additions & 0 deletions Common/src/CConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,9 @@ void CConfig::SetConfig_Options() {
/* DESCRIPTION: Size of the edge groups colored for thread parallel edge loops (0 forces the reducer strategy). */
addUnsignedLongOption("EDGE_COLORING_GROUP_SIZE", edgeColorGroupSize, 512);

/* DESCRIPTION: Allow fallback to smaller edge color group sizes for the discrete adjoint and allow more colors. */
addBoolOption("EDGE_COLORING_RELAX_DISC_ADJ", edgeColoringRelaxDiscAdj, true);

/*--- options that are used for libROM ---*/
/*!\par CONFIG_CATEGORY:libROM options \ingroup Config*/

Expand Down
57 changes: 55 additions & 2 deletions Common/src/geometry/CGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3609,7 +3609,7 @@ const su2vector<unsigned long>& CGeometry::GetTransposeSparsePatternMap(Connecti
return pattern.transposePtr();
}

const CCompressedSparsePatternUL& CGeometry::GetEdgeColoring(su2double* efficiency) {
const CCompressedSparsePatternUL& CGeometry::GetEdgeColoring(su2double* efficiency, bool maximizeEdgeColorGroupSize) {
/*--- Check for dry run mode with dummy geometry. ---*/
if (nEdge == 0) return edgeColoring;

Expand Down Expand Up @@ -3637,7 +3637,60 @@ const CCompressedSparsePatternUL& CGeometry::GetEdgeColoring(su2double* efficien

/*--- Color the edges. ---*/
constexpr bool balanceColors = true;
edgeColoring = colorSparsePattern(pattern, edgeColorGroupSize, balanceColors);

/*--- If requested, find an efficient coloring with maximum color group size (up to edgeColorGroupSize). ---*/
if (maximizeEdgeColorGroupSize) {
auto upperEdgeColorGroupSize = edgeColorGroupSize + 1; /* upper bound that is deemed too large */
auto nextEdgeColorGroupSize = edgeColorGroupSize; /* next value that we are going to try */
auto lowerEdgeColorGroupSize = 1ul; /* lower bound that is known to work */

bool admissibleColoring = false; /* keep track wether the last tested coloring is admissible */

while (true) {
edgeColoring = colorSparsePattern(pattern, nextEdgeColorGroupSize, balanceColors);

/*--- If the coloring fails, reduce the color group size. ---*/
if (edgeColoring.empty()) {
upperEdgeColorGroupSize = nextEdgeColorGroupSize;
admissibleColoring = false;
}
/*--- If the coloring succeeds, check the efficiency. ---*/
else {
const su2double currentEfficiency =
coloringEfficiency(edgeColoring, omp_get_max_threads(), nextEdgeColorGroupSize);

/*--- If the coloring is not efficient, reduce the color group size. ---*/
if (currentEfficiency < COLORING_EFF_THRESH) {
upperEdgeColorGroupSize = nextEdgeColorGroupSize;
admissibleColoring = false;
}
/*--- Otherwise, enlarge the color group size. ---*/
else {
lowerEdgeColorGroupSize = nextEdgeColorGroupSize;
admissibleColoring = true;
}
}

const auto increment = (upperEdgeColorGroupSize - lowerEdgeColorGroupSize) / 2;
nextEdgeColorGroupSize = lowerEdgeColorGroupSize + increment;

/*--- Terminating condition. ---*/
if (increment == 0) {
break;
}
}

edgeColorGroupSize = nextEdgeColorGroupSize;

/*--- If the last tested coloring was not admissible, recompute the final coloring. ---*/
if (!admissibleColoring) {
edgeColoring = colorSparsePattern(pattern, edgeColorGroupSize, balanceColors);
}
}
/*--- No adaptivity. ---*/
else {
edgeColoring = colorSparsePattern(pattern, edgeColorGroupSize, balanceColors);
}

/*--- If the coloring fails use the natural coloring. This is a
* "soft" failure as this "bad" coloring should be detected
Expand Down
18 changes: 18 additions & 0 deletions SU2_CFD/include/drivers/CDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,24 @@ class CDriver : public CDriverBase {
*/
void SetRotationRate(passivedouble rot_x, passivedouble rot_y, passivedouble rot_z);

/*!
* \brief Set the moving wall marker rotation rates.
* \param[in] iMaker - Index of moving wall marker.
* \param[in] rot_x - Value of Angular velocity about x-axes.
* \param[in] rot_y - Value of Angular velocity about y-axes.
* \param[in] rot_z - Value of Angular velocity about z-axes.
*/
void SetMarkerRotationRate(unsigned short iMarker, passivedouble rot_x, passivedouble rot_y, passivedouble rot_z);

/*!
* \brief Set the moving wall marker translation rates.
* \param[in] iMaker - Index of moving wall marker.
* \param[in] vel_x - Value of velocity along x-axis.
* \param[in] vel_y - Value of velocity along y-axis.
* \param[in] vel_z - Value of velocity along z-axis.
*/
void SetMarkerTranslationRate(unsigned short iMarker, passivedouble vel_x, passivedouble vel_y, passivedouble vel_z);

/// \}
};

Expand Down
32 changes: 32 additions & 0 deletions SU2_CFD/include/solvers/CFVMFlowSolverBase.inl
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,16 @@ void CFVMFlowSolverBase<V, R>::HybridParallelInitialization(const CConfig& confi
* sum the fluxes for each cell and set the diagonal of the system matrix. ---*/

su2double parallelEff = 1.0;

#ifdef CODI_REVERSE_TYPE
/*--- For the discrete adjoint, the reducer strategy is costly. Prefer coloring, possibly with reduced edge color
* group size. Find the maximum edge color group size that yields an efficient coloring. Also, allow larger numbers
* of colors. ---*/
const bool relax = config.GetEdgeColoringRelaxDiscAdj();
const auto& coloring = geometry.GetEdgeColoring(&parallelEff, relax);
#else
const auto& coloring = geometry.GetEdgeColoring(&parallelEff);
#endif

/*--- The decision to use the strategy is local to each rank. ---*/
ReducerStrategy = parallelEff < COLORING_EFF_THRESH;
Expand Down Expand Up @@ -324,6 +333,29 @@ void CFVMFlowSolverBase<V, R>::HybridParallelInitialization(const CConfig& confi
<< "\n The memory usage of the discrete adjoint solver is higher when using the fallback."
#endif
<< endl;
} else {
if (SU2_MPI::GetRank() == MASTER_NODE) {
cout << "All ranks use edge coloring." << endl;
}
}

const su2double coloredParallelEff = ReducerStrategy ? 1.0 : parallelEff;
su2double minColoredParallelEff = 1.0;
SU2_MPI::Reduce(&coloredParallelEff, &minColoredParallelEff, 1, MPI_DOUBLE, MPI_MIN, MASTER_NODE, SU2_MPI::GetComm());

const unsigned long coloredNumColors = ReducerStrategy ? 0 : coloring.getOuterSize();
unsigned long maxColoredNumColors = 0;
SU2_MPI::Reduce(&coloredNumColors, &maxColoredNumColors, 1, MPI_UNSIGNED_LONG, MPI_MAX, MASTER_NODE, SU2_MPI::GetComm());

const unsigned long coloredEdgeColorGroupSize = ReducerStrategy ? 1 << 30 : geometry.GetEdgeColorGroupSize();
unsigned long minColoredEdgeColorGroupSize = 1 << 30;
SU2_MPI::Reduce(&coloredEdgeColorGroupSize, &minColoredEdgeColorGroupSize, 1, MPI_UNSIGNED_LONG, MPI_MIN, MASTER_NODE, SU2_MPI::GetComm());

if (SU2_MPI::GetRank() == MASTER_NODE && numRanksUsingReducer != SU2_MPI::GetSize()) {
cout << "Among the ranks that use edge coloring,\n"
<< " the minimum efficiency is " << minColoredParallelEff << ",\n"
<< " the maximum number of colors is " << maxColoredNumColors << ",\n"
<< " the minimum edge color group size is " << minColoredEdgeColorGroupSize << "." << endl;
}
}

Expand Down
8 changes: 8 additions & 0 deletions SU2_CFD/include/solvers/CScalarSolver.inl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ CScalarSolver<VariableType>::CScalarSolver(CGeometry* geometry, CConfig* config,
#ifdef HAVE_OMP
/*--- Get the edge coloring, see notes in CEulerSolver's constructor. ---*/
su2double parallelEff = 1.0;
#ifdef CODI_REVERSE_TYPE
/*--- For the discrete adjoint, the reducer strategy is costly. Prefer coloring, possibly with reduced edge color
* group size. Find the maximum edge color group size that yields an efficient coloring. Also, allow larger numbers
* of colors. ---*/
const bool relax = config->GetEdgeColoringRelaxDiscAdj();
const auto& coloring = geometry->GetEdgeColoring(&parallelEff, relax);
#else
const auto& coloring = geometry->GetEdgeColoring(&parallelEff);
#endif

ReducerStrategy = parallelEff < COLORING_EFF_THRESH;

Expand Down
9 changes: 8 additions & 1 deletion SU2_CFD/src/iteration/CIteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ void CIteration::SetGrid_Movement(CGeometry** geometry, CSurfaceMovement* surfac
break;
}

if (config->GetSurface_Movement(AEROELASTIC) || config->GetSurface_Movement(AEROELASTIC_RIGID_MOTION)) {
if (config->GetSurface_Movement(AEROELASTIC) || config->GetSurface_Movement(AEROELASTIC_RIGID_MOTION) || config->GetSurface_Movement(MOVING_WALL)) {
/*--- Apply rigid mesh transformation to entire grid first, if necessary ---*/

if (IntIter == 0) {

if (Kind_Grid_Movement == AEROELASTIC_RIGID_MOTION) {
if (rank == MASTER_NODE) cout << endl << " Performing rigid mesh transformation." << endl;

Expand All @@ -110,6 +112,11 @@ void CIteration::SetGrid_Movement(CGeometry** geometry, CSurfaceMovement* surfac

grid_movement->UpdateMultiGrid(geometry, config);
}
if (config->GetSurface_Movement(MOVING_WALL)) {
for (auto iMGlevel = 0u; iMGlevel <= config->GetnMGLevels(); iMGlevel++) {
geometry[iMGlevel]->SetWallVelocity(config, iMGlevel == 0u);
}
}

}

Expand Down
20 changes: 10 additions & 10 deletions SU2_CFD/src/output/filewriter/CCGNSFileWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ void CCGNSFileWriter::WriteData(string val_filename) {

/*--- We append the pre-defined suffix (extension) to the filename (prefix) ---*/
val_filename.append(fileExt);

/*--- Open the CGNS file for writing. ---*/
InitializeMeshFile(val_filename);

Expand Down Expand Up @@ -132,15 +131,16 @@ void CCGNSFileWriter::WriteField(int iField, const string& FieldName) {
/*--- Coordinate vector is written in blocks, one for each process. ---*/
cgsize_t nodeBegin = 1;
auto nodeEnd = static_cast<cgsize_t>(nLocalPoints);

if (isCoord) {
int CoordinateNumber;
CallCGNS(cg_coord_partial_write(cgnsFileID, cgnsBase, cgnsZone, dataType, FieldName.c_str(), &nodeBegin, &nodeEnd,
sendBufferField.data(), &CoordinateNumber));
} else {
int fieldNumber;
CallCGNS(cg_field_partial_write(cgnsFileID, cgnsBase, cgnsZone, cgnsFields, dataType, FieldName.c_str(), &nodeBegin,
&nodeEnd, sendBufferField.data(), &fieldNumber));
if (nLocalPoints > 0) {
if (isCoord) {
int CoordinateNumber;
CallCGNS(cg_coord_partial_write(cgnsFileID, cgnsBase, cgnsZone, dataType, FieldName.c_str(), &nodeBegin, &nodeEnd,
sendBufferField.data(), &CoordinateNumber));
} else {
int fieldNumber;
CallCGNS(cg_field_partial_write(cgnsFileID, cgnsBase, cgnsZone, cgnsFields, dataType, FieldName.c_str(), &nodeBegin,
&nodeEnd, sendBufferField.data(), &fieldNumber));
}
}

for (int i = 0; i < size; ++i) {
Expand Down
12 changes: 12 additions & 0 deletions SU2_CFD/src/python_wrapper_structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,15 @@ void CDriver::SetRotationRate(passivedouble rot_x, passivedouble rot_y, passived
main_config->SetRotation_Rate(2, rot_z);
}

void CDriver::SetMarkerRotationRate(unsigned short iMarker, passivedouble rot_x, passivedouble rot_y, passivedouble rot_z) {
config_container[selected_zone]->SetMarkerRotationRate(iMarker, 0, rot_x);
config_container[selected_zone]->SetMarkerRotationRate(iMarker, 1, rot_y);
config_container[selected_zone]->SetMarkerRotationRate(iMarker, 2, rot_z);
}

void CDriver::SetMarkerTranslationRate(unsigned short iMarker, passivedouble vel_x, passivedouble vel_y, passivedouble vel_z) {
config_container[selected_zone]->SetMarkerTranslationRate(iMarker, 0, vel_x);
config_container[selected_zone]->SetMarkerTranslationRate(iMarker, 1, vel_y);
config_container[selected_zone]->SetMarkerTranslationRate(iMarker, 2, vel_z);
}

Loading

0 comments on commit 93b85b6

Please sign in to comment.