Skip to content

Commit 35389df

Browse files
Add python interface for setting AoA and AoS (#2045)
* Add python methods for setting AoA and AoS --------- Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com>
1 parent c435309 commit 35389df

5 files changed

Lines changed: 52 additions & 20 deletions

File tree

SU2_CFD/include/drivers/CDriver.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,18 @@ class CDriver : public CDriverBase {
508508
*/
509509
void SetInletAngle(unsigned short iMarker, passivedouble alpha);
510510

511+
/*!
512+
* \brief Set the angle of attack of the farfield.
513+
* \param[in] alpha - Angle (degree).
514+
*/
515+
void SetFarFieldAoA(passivedouble alpha);
516+
517+
/*!
518+
* \brief Set the angle of sideslip of the farfield.
519+
* \param[in] beta - Angle (degree).
520+
*/
521+
void SetFarFieldAoS(passivedouble beta);
522+
511523
/*!
512524
* \brief Set the dynamic mesh translation rates.
513525
* \param[in] xDot - Value of translational velocity in x-direction.

SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,29 @@ class CFVMFlowSolverBase : public CSolver {
21982198
Inlet_FlowDir[val_marker][val_vertex][val_dim] = val_flowdir;
21992199
}
22002200

2201+
/*!
2202+
* \brief Updates the components of the farfield velocity vector.
2203+
*/
2204+
inline void UpdateFarfieldVelocity(const CConfig* config) final {
2205+
/*--- Retrieve the AoA and AoS (degrees) ---*/
2206+
const su2double AoA = config->GetAoA() * PI_NUMBER / 180.0;
2207+
const su2double AoS = config->GetAoS() * PI_NUMBER / 180.0;
2208+
/*--- Update the freestream velocity vector at the farfield
2209+
* Compute the new freestream velocity with the updated AoA,
2210+
* "Velocity_Inf" is shared with config. ---*/
2211+
2212+
const su2double Vel_Infty_Mag = GeometryToolbox::Norm(nDim, Velocity_Inf);
2213+
2214+
if (nDim == 2) {
2215+
Velocity_Inf[0] = cos(AoA) * Vel_Infty_Mag;
2216+
Velocity_Inf[1] = sin(AoA) * Vel_Infty_Mag;
2217+
} else {
2218+
Velocity_Inf[0] = cos(AoA) * cos(AoS) * Vel_Infty_Mag;
2219+
Velocity_Inf[1] = sin(AoS) * Vel_Infty_Mag;
2220+
Velocity_Inf[2] = sin(AoA) * cos(AoS) * Vel_Infty_Mag;
2221+
}
2222+
}
2223+
22012224
/*!
22022225
* \brief Compute the global error measures (L2, Linf) for verification cases.
22032226
* \param[in] geometry - Geometrical definition.

SU2_CFD/include/solvers/CSolver.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,6 +2871,11 @@ class CSolver {
28712871
unsigned short val_dim,
28722872
su2double val_flowdir) { }
28732873

2874+
/*!
2875+
* \brief Updates the components of the farfield velocity vector.
2876+
*/
2877+
inline virtual void UpdateFarfieldVelocity(const CConfig* config) {}
2878+
28742879
/*!
28752880
* \brief A virtual member
28762881
* \param[in] iMarker - Marker identifier.

SU2_CFD/src/python_wrapper_structure.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ void CDriver::SetInletAngle(unsigned short iMarker, passivedouble alpha) {
9797
}
9898
}
9999

100+
void CDriver::SetFarFieldAoA(const passivedouble AoA) {
101+
config_container[ZONE_0]->SetAoA(AoA);
102+
solver_container[ZONE_0][INST_0][MESH_0][FLOW_SOL]->UpdateFarfieldVelocity(config_container[ZONE_0]);
103+
}
104+
105+
void CDriver::SetFarFieldAoS(const passivedouble AoS) {
106+
config_container[ZONE_0]->SetAoS(AoS);
107+
solver_container[ZONE_0][INST_0][MESH_0][FLOW_SOL]->UpdateFarfieldVelocity(config_container[ZONE_0]);
108+
}
109+
100110
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101111
/* Functions related to simulation control, high level functions (reset convergence, set initial mesh, etc.) */
102112
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -156,3 +166,4 @@ void CDriver::SetRotationRate(passivedouble rot_x, passivedouble rot_y, passived
156166
config_container[iZone]->SetRotation_Rate(2, rot_z);
157167
}
158168
}
169+

SU2_CFD/src/solvers/CEulerSolver.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4061,8 +4061,6 @@ void CEulerSolver::SetFarfield_AoA(CGeometry *geometry, CSolver **solver_contain
40614061
CConfig *config, unsigned short iMesh, bool Output) {
40624062

40634063
const auto InnerIter = config->GetInnerIter();
4064-
const su2double AoS = config->GetAoS()*PI_NUMBER/180.0;
4065-
40664064
/* --- Initialize values at first iteration --- */
40674065

40684066
if (InnerIter == 0) {
@@ -4101,24 +4099,7 @@ void CEulerSolver::SetFarfield_AoA(CGeometry *geometry, CSolver **solver_contain
41014099
AoA = AoA + AoA_inc;
41024100
config->SetAoA(AoA);
41034101
}
4104-
4105-
AoA *= PI_NUMBER/180.0;
4106-
4107-
/*--- Update the freestream velocity vector at the farfield
4108-
* Compute the new freestream velocity with the updated AoA,
4109-
* "Velocity_Inf" is shared with config. ---*/
4110-
4111-
const su2double Vel_Infty_Mag = GeometryToolbox::Norm(nDim, Velocity_Inf);
4112-
4113-
if (nDim == 2) {
4114-
Velocity_Inf[0] = cos(AoA)*Vel_Infty_Mag;
4115-
Velocity_Inf[1] = sin(AoA)*Vel_Infty_Mag;
4116-
}
4117-
else {
4118-
Velocity_Inf[0] = cos(AoA)*cos(AoS)*Vel_Infty_Mag;
4119-
Velocity_Inf[1] = sin(AoS)*Vel_Infty_Mag;
4120-
Velocity_Inf[2] = sin(AoA)*cos(AoS)*Vel_Infty_Mag;
4121-
}
4102+
UpdateFarfieldVelocity(config);
41224103
}
41234104
}
41244105

0 commit comments

Comments
 (0)