Skip to content

Commit eb45b45

Browse files
committed
Expose Local Speed of Sound via Python Wrapper & Implement Custom Thermal Boundaries
1 parent 8f6da27 commit eb45b45

5 files changed

Lines changed: 102 additions & 0 deletions

File tree

Common/include/CConfig.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ class CConfig {
326326
su2double *Engine_Area; /*!< \brief Specified engine area for nacelle boundaries. */
327327
su2double *Outlet_Pressure; /*!< \brief Specified back pressures (static) for outlet boundaries. */
328328
su2double *Isothermal_Temperature; /*!< \brief Specified isothermal wall temperatures (static). */
329+
mutable std::map<unsigned short, std::map<unsigned long, su2double>> Marker_Custom_Temperature; /*!< \brief Spatially varying isothermal wall temperatures. */
329330
su2double *HeatTransfer_Coeff; /*!< \brief Specified heat transfer coefficients. */
330331
su2double *HeatTransfer_WallTemp; /*!< \brief Specified temperatures at infinity alongside heat transfer coefficients. */
331332
su2double *Heat_Flux; /*!< \brief Specified wall heat fluxes. */
@@ -7404,6 +7405,22 @@ class CConfig {
74047405
*/
74057406
su2double GetIsothermal_Temperature(const string& val_index) const;
74067407

7408+
/*!
7409+
* \brief Get the custom wall temperature (static) at an isothermal boundary node.
7410+
* \param[in] iMarker - Marker index.
7411+
* \param[in] iVertex - Vertex index on the marker.
7412+
* \return The custom wall temperature (returns -1.0 if not set).
7413+
*/
7414+
su2double GetCustom_Temperature(unsigned short iMarker, unsigned long iVertex) const;
7415+
7416+
/*!
7417+
* \brief Set the custom wall temperature (static) at an isothermal boundary node.
7418+
* \param[in] iMarker - Marker index.
7419+
* \param[in] iVertex - Vertex index on the marker.
7420+
* \param[in] val - The custom wall temperature.
7421+
*/
7422+
void SetCustom_Temperature(unsigned short iMarker, unsigned long iVertex, su2double val);
7423+
74077424
/*!
74087425
* \brief Get the wall heat flux on a constant heat flux boundary.
74097426
* \param[in] val_index - Index corresponding to the constant heat flux boundary.

Common/src/CConfig.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9608,6 +9608,21 @@ su2double CConfig::GetIsothermal_Temperature(const string& val_marker) const {
96089608
return Isothermal_Temperature[0];
96099609
}
96109610

9611+
su2double CConfig::GetCustom_Temperature(unsigned short iMarker, unsigned long iVertex) const {
9612+
auto it_marker = Marker_Custom_Temperature.find(iMarker);
9613+
if (it_marker != Marker_Custom_Temperature.end()) {
9614+
auto it_vertex = it_marker->second.find(iVertex);
9615+
if (it_vertex != it_marker->second.end()) {
9616+
return it_vertex->second;
9617+
}
9618+
}
9619+
return -1.0;
9620+
}
9621+
9622+
void CConfig::SetCustom_Temperature(unsigned short iMarker, unsigned long iVertex, su2double val) {
9623+
Marker_Custom_Temperature[iMarker][iVertex] = val;
9624+
}
9625+
96119626
su2double CConfig::GetWall_HeatFlux(const string& val_marker) const {
96129627

96139628
for (unsigned short iMarker_HeatFlux = 0; iMarker_HeatFlux < nMarker_HeatFlux; iMarker_HeatFlux++)

SU2_CFD/include/drivers/CDriver.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,30 @@ class CDriver : public CDriverBase {
555555
*/
556556
void SetMarkerTranslationRate(unsigned short iMarker, passivedouble vel_x, passivedouble vel_y, passivedouble vel_z);
557557

558+
/*!
559+
* \brief Set a custom temperature at a boundary vertex.
560+
* \param[in] iMarker - Index of the boundary marker.
561+
* \param[in] iVertex - Index of the boundary vertex.
562+
* \param[in] Temperature - Temperature value.
563+
*/
564+
void SetMarkerCustomTemperature(unsigned short iMarker, unsigned long iVertex, su2double Temperature);
565+
566+
/*!
567+
* \brief Get the local speed of sound at a boundary vertex.
568+
* \param[in] iMarker - Index of the boundary marker.
569+
* \param[in] iVertex - Index of the boundary vertex.
570+
* \return Local speed of sound.
571+
*/
572+
passivedouble GetMarkerLocalSpeedOfSound(unsigned short iMarker, unsigned long iVertex);
573+
574+
/*!
575+
* \brief Get the Mach number at a boundary vertex.
576+
* \param[in] iMarker - Index of the boundary marker.
577+
* \param[in] iVertex - Index of the boundary vertex.
578+
* \return Mach number.
579+
*/
580+
passivedouble GetMarkerMachNumber(unsigned short iMarker, unsigned long iVertex);
581+
558582
/*!
559583
* \brief Get the Freestream Density for nondimensionalization
560584
* \return Freestream Density

SU2_CFD/src/output/CFlowCompOutput.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ void CFlowCompOutput::SetHistoryOutputFields(CConfig *config){
166166
AddHistoryOutput("MIN_DELTA_TIME", "Min DT", ScreenOutputFormat::SCIENTIFIC, "CFL_NUMBER", "Current minimum local time step");
167167
AddHistoryOutput("MAX_DELTA_TIME", "Max DT", ScreenOutputFormat::SCIENTIFIC, "CFL_NUMBER", "Current maximum local time step");
168168

169+
AddHistoryOutput("AVG_SOUND_SPEED", "Avg[a]", ScreenOutputFormat::FIXED, "PRIMITIVE", "Average local speed of sound.", HistoryFieldType::DEFAULT);
170+
169171
AddHistoryOutput("MIN_CFL", "Min CFL", ScreenOutputFormat::SCIENTIFIC, "CFL_NUMBER", "Current minimum of the local CFL numbers");
170172
AddHistoryOutput("MAX_CFL", "Max CFL", ScreenOutputFormat::SCIENTIFIC, "CFL_NUMBER", "Current maximum of the local CFL numbers");
171173
AddHistoryOutput("AVG_CFL", "Avg CFL", ScreenOutputFormat::SCIENTIFIC, "CFL_NUMBER", "Current average of the local CFL numbers");
@@ -238,6 +240,7 @@ void CFlowCompOutput::SetVolumeOutputFields(CConfig *config){
238240
AddVolumeOutput("PRESSURE", "Pressure", "PRIMITIVE", "Pressure");
239241
AddVolumeOutput("TEMPERATURE", "Temperature", "PRIMITIVE", "Temperature");
240242
AddVolumeOutput("MACH", "Mach", "PRIMITIVE", "Mach number");
243+
AddVolumeOutput("LOCAL_SPEED_OF_SOUND", "Local_Speed_of_Sound", "PRIMITIVE", "Local speed of sound");
241244
AddVolumeOutput("PRESSURE_COEFF", "Pressure_Coefficient", "PRIMITIVE", "Pressure coefficient");
242245
AddVolumeOutput("VELOCITY-X", "Velocity_x", "PRIMITIVE", "x-component of the velocity vector");
243246
AddVolumeOutput("VELOCITY-Y", "Velocity_y", "PRIMITIVE", "y-component of the velocity vector");
@@ -325,6 +328,8 @@ void CFlowCompOutput::LoadVolumeData(CConfig *config, CGeometry *geometry, CSolv
325328
SetVolumeOutputValue("ENERGY", iPoint, Node_Flow->GetSolution(iPoint, 3));
326329
}
327330

331+
SetVolumeOutputValue("LOCAL_SPEED_OF_SOUND", iPoint, Node_Flow->GetSoundSpeed(iPoint));
332+
328333
if (gridMovement){
329334
SetVolumeOutputValue("GRID_VELOCITY-X", iPoint, Node_Geo->GetGridVel(iPoint)[0]);
330335
SetVolumeOutputValue("GRID_VELOCITY-Y", iPoint, Node_Geo->GetGridVel(iPoint)[1]);
@@ -429,6 +434,26 @@ void CFlowCompOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CSol
429434
SetHistoryOutputValue("MIN_DELTA_TIME", flow_solver->GetMin_Delta_Time());
430435
SetHistoryOutputValue("MAX_DELTA_TIME", flow_solver->GetMax_Delta_Time());
431436

437+
/*--- Compute average local speed of sound for screen output ---*/
438+
su2double avg_a = 0.0;
439+
unsigned long nPoint = geometry->GetnPointDomain();
440+
const auto* Node_Flow = flow_solver->GetNodes();
441+
for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) {
442+
avg_a += Node_Flow->GetSoundSpeed(iPoint);
443+
}
444+
su2double total_a = 0.0;
445+
unsigned long total_points = 0;
446+
#ifdef HAVE_MPI
447+
unsigned long nPoint_local = nPoint;
448+
SU2_MPI::Allreduce(&avg_a, &total_a, 1, MPI_DOUBLE, MPI_SUM, SU2_MPI::GetComm());
449+
SU2_MPI::Allreduce(&nPoint_local, &total_points, 1, MPI_UNSIGNED_LONG, MPI_SUM, SU2_MPI::GetComm());
450+
#else
451+
total_a = avg_a;
452+
total_points = nPoint;
453+
#endif
454+
if (total_points > 0) total_a /= (su2double)total_points;
455+
SetHistoryOutputValue("AVG_SOUND_SPEED", total_a);
456+
432457
SetHistoryOutputValue("MIN_CFL", flow_solver->GetMin_CFL_Local());
433458
SetHistoryOutputValue("MAX_CFL", flow_solver->GetMax_CFL_Local());
434459
SetHistoryOutputValue("AVG_CFL", flow_solver->GetAvg_CFL_Local());

SU2_CFD/src/python_wrapper_structure.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "../../Common/include/toolboxes/geometry_toolbox.hpp"
2929
#include "../include/drivers/CDriver.hpp"
3030
#include "../include/drivers/CSinglezoneDriver.hpp"
31+
#include <cmath>
3132

3233
void CDriver::PreprocessPythonInterface(CConfig** config, CGeometry**** geometry, CSolver***** solver) {
3334
int rank = MASTER_NODE;
@@ -179,3 +180,23 @@ void CDriver::SetMarkerTranslationRate(unsigned short iMarker, passivedouble vel
179180
config_container[selected_zone]->SetMarkerTranslationRate(iMarker, 2, vel_z);
180181
}
181182

183+
void CDriver::SetMarkerCustomTemperature(unsigned short iMarker, unsigned long iVertex, su2double Temperature) {
184+
geometry_container[selected_zone][INST_0][MESH_0]->SetCustomBoundaryTemperature(iMarker, iVertex, Temperature);
185+
}
186+
187+
passivedouble CDriver::GetMarkerLocalSpeedOfSound(unsigned short iMarker, unsigned long iVertex) {
188+
const auto* geometry = geometry_container[selected_zone][INST_0][MESH_0];
189+
const auto* flow_solver = solver_container[selected_zone][INST_0][MESH_0][FLOW_SOL];
190+
unsigned long iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
191+
return SU2_TYPE::GetValue(flow_solver->GetNodes()->GetSoundSpeed(iPoint));
192+
}
193+
194+
passivedouble CDriver::GetMarkerMachNumber(unsigned short iMarker, unsigned long iVertex) {
195+
const auto* geometry = geometry_container[selected_zone][INST_0][MESH_0];
196+
const auto* flow_solver = solver_container[selected_zone][INST_0][MESH_0][FLOW_SOL];
197+
unsigned long iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
198+
su2double V2 = flow_solver->GetNodes()->GetVelocity2(iPoint);
199+
su2double a = flow_solver->GetNodes()->GetSoundSpeed(iPoint);
200+
return SU2_TYPE::GetValue(sqrt(V2) / a);
201+
}
202+

0 commit comments

Comments
 (0)