Skip to content

Commit 85a9ae7

Browse files
authored
Merge pull request #2024 from ArneVoss/feature_python_interface_for_moving_frame
Python interface for updating translation and rotation rates of the moving frame
2 parents 9c0d454 + 54d9347 commit 85a9ae7

9 files changed

Lines changed: 434 additions & 46 deletions

File tree

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)

SU2_CFD/include/drivers/CDriver.hpp

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

511+
/*!
512+
* \brief Set the dynamic mesh translation rates.
513+
* \param[in] xDot - Value of translational velocity in x-direction.
514+
* \param[in] yDot - Value of translational velocity in y-direction.
515+
* \param[in] zDot - Value of translational velocity in z-direction.
516+
*/
517+
void SetTranslationRate(passivedouble xDot, passivedouble yDot, passivedouble zDot);
518+
519+
/*!
520+
* \brief Set the dynamic mesh rotation rates.
521+
* \param[in] rot_x - Value of Angular velocity about x-axes.
522+
* \param[in] rot_y - Value of Angular velocity about y-axes.
523+
* \param[in] rot_z - Value of Angular velocity about z-axes.
524+
*/
525+
void SetRotationRate(passivedouble rot_x, passivedouble rot_y, passivedouble rot_z);
526+
511527
/// \}
512528
};
513529

SU2_CFD/src/drivers/CDriver.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,56 +2547,11 @@ void CDriver::InitializeInterface(CConfig **config, CSolver***** solver, CGeomet
25472547
void CDriver::PreprocessStaticMesh(const CConfig *config, CGeometry** geometry){
25482548

25492549
unsigned short iMGlevel, iMGfine;
2550-
unsigned short Kind_Grid_Movement;
25512550

25522551
unsigned short iZone = config->GetiZone();
25532552

2554-
Kind_Grid_Movement = config->GetKind_GridMovement();
2555-
25562553
if (!fem_solver) {
25572554

2558-
switch (Kind_Grid_Movement) {
2559-
2560-
case ROTATING_FRAME:
2561-
2562-
/*--- Steadily rotating frame: set the grid velocities just once
2563-
before the first iteration flow solver. ---*/
2564-
2565-
if (rank == MASTER_NODE) {
2566-
cout << endl << " Setting rotating frame grid velocities";
2567-
cout << " for zone " << iZone << "." << endl;
2568-
}
2569-
2570-
/*--- Set the grid velocities on all multigrid levels for a steadily
2571-
rotating reference frame. ---*/
2572-
2573-
for (iMGlevel = 0; iMGlevel <= config_container[ZONE_0]->GetnMGLevels(); iMGlevel++){
2574-
geometry[iMGlevel]->SetRotationalVelocity(config, true);
2575-
geometry[iMGlevel]->SetShroudVelocity(config);
2576-
}
2577-
2578-
break;
2579-
2580-
case STEADY_TRANSLATION:
2581-
2582-
/*--- Set the translational velocity and hold the grid fixed during
2583-
the calculation (similar to rotating frame, but there is no extra
2584-
source term for translation). ---*/
2585-
2586-
if (rank == MASTER_NODE)
2587-
cout << endl << " Setting translational grid velocities." << endl;
2588-
2589-
/*--- Set the translational velocity on all grid levels. ---*/
2590-
2591-
for (iMGlevel = 0; iMGlevel <= config_container[ZONE_0]->GetnMGLevels(); iMGlevel++)
2592-
geometry_container[iZone][INST_0][iMGlevel]->SetTranslationalVelocity(config, true);
2593-
2594-
break;
2595-
2596-
default:
2597-
break;
2598-
}
2599-
26002555
if (config->GetnMarker_Moving() > 0) {
26012556

26022557
/*--- Fixed wall velocities: set the grid velocities only one time

SU2_CFD/src/iteration/CIteration.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,33 @@ void CIteration::SetGrid_Movement(CGeometry** geometry, CSurfaceMovement* surfac
6060

6161
break;
6262

63-
/*--- Already initialized in the static mesh movement routine at driver level. ---*/
6463
case STEADY_TRANSLATION:
64+
/*--- Set or update the translating frame mesh movement with the current translation rates,
65+
* which might be altered via the python interface. ---*/
66+
67+
if (rank == MASTER_NODE) cout << "\n Setting translational grid velocities." << endl;
68+
69+
/*--- Set the translational velocity on all grid levels. ---*/
70+
71+
for (auto iMGlevel = 0u; iMGlevel <= config->GetnMGLevels(); iMGlevel++)
72+
geometry[iMGlevel]->SetTranslationalVelocity(config, iMGlevel == 0);
73+
74+
break;
75+
6576
case ROTATING_FRAME:
77+
/*--- Set or update the rotating frame mesh movement with the current translation and rotation
78+
* rates, which might be altered via the python interface. ---*/
79+
80+
if (rank == MASTER_NODE) cout << "\n Setting rotating frame grid velocities." << endl;
81+
82+
/*--- Set the grid velocities on all multigrid levels for a steadily
83+
rotating reference frame. ---*/
84+
85+
for (auto iMGlevel = 0u; iMGlevel <= config->GetnMGLevels(); iMGlevel++){
86+
geometry[iMGlevel]->SetRotationalVelocity(config, iMGlevel == 0);
87+
geometry[iMGlevel]->SetShroudVelocity(config);
88+
}
89+
6690
break;
6791
}
6892

SU2_CFD/src/python_wrapper_structure.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,23 @@ void CDriver::BoundaryConditionsUpdate() {
136136
geometry_container[iZone][INST_0][MESH_0]->UpdateCustomBoundaryConditions(geometry_container[iZone][INST_0],config_container[iZone]);
137137
}
138138
}
139+
140+
////////////////////////////////////////////////////////////////////////////////
141+
/* Functions related to dynamic mesh */
142+
////////////////////////////////////////////////////////////////////////////////
143+
144+
void CDriver::SetTranslationRate(passivedouble xDot, passivedouble yDot, passivedouble zDot) {
145+
for (iZone = 0; iZone < nZone; iZone++) {
146+
config_container[iZone]->SetTranslation_Rate(0, xDot);
147+
config_container[iZone]->SetTranslation_Rate(1, yDot);
148+
config_container[iZone]->SetTranslation_Rate(2, zDot);
149+
}
150+
}
151+
152+
void CDriver::SetRotationRate(passivedouble rot_x, passivedouble rot_y, passivedouble rot_z) {
153+
for (iZone = 0; iZone < nZone; iZone++) {
154+
config_container[iZone]->SetRotation_Rate(0, rot_x);
155+
config_container[iZone]->SetRotation_Rate(1, rot_y);
156+
config_container[iZone]->SetRotation_Rate(2, rot_z);
157+
}
158+
}

TestCases/hybrid_regression.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,18 @@ def main():
751751
pywrapper_translating_naca0012.test_file = "forces_0.csv"
752752
pywrapper_translating_naca0012.enabled_on_cpu_arch = ["x86_64"]
753753
file_diff_list.append(pywrapper_translating_naca0012)
754+
755+
# NACA0012 with updated moving frame
756+
pywrapper_updated_moving_frame_naca0012 = TestCase('pywrapper_updated_moving_frame_naca0012')
757+
pywrapper_updated_moving_frame_naca0012.cfg_dir = "py_wrapper/updated_moving_frame_NACA12"
758+
pywrapper_updated_moving_frame_naca0012.cfg_file = "config.cfg"
759+
pywrapper_updated_moving_frame_naca0012.command = TestCase.Command(exec = "python", param = "run_su2.py")
760+
pywrapper_updated_moving_frame_naca0012.timeout = 60
761+
pywrapper_updated_moving_frame_naca0012.reference_file = "forces_0.csv.ref"
762+
pywrapper_updated_moving_frame_naca0012.reference_file_aarch64 = "forces_0_aarch64.csv.ref"
763+
pywrapper_updated_moving_frame_naca0012.test_file = "forces_0.csv"
764+
pywrapper_updated_moving_frame_naca0012.enabled_on_cpu_arch = ["x86_64"]
765+
file_diff_list.append(pywrapper_updated_moving_frame_naca0012)
754766

755767
######################################
756768
### RUN TESTS ###
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
% PROBLEM DEFINITION
2+
%
3+
SOLVER= EULER
4+
REF_DIMENSIONALIZATION= FREESTREAM_VEL_EQ_MACH
5+
MATH_PROBLEM= DIRECT
6+
RESTART_SOL= NO
7+
8+
% FREE-STREAM DEFINITION
9+
%
10+
% We are translating the domain instead of having farfield velocity.
11+
% Note: The rotating frame is intended for 3D cases. To use the feature in a 2D case,
12+
% care must be taken with respect to the axes, e.g. to obtain a pitching motion, a
13+
% rotation about the z-axis can be used.
14+
GRID_MOVEMENT= ROTATING_FRAME
15+
MOTION_ORIGIN= 0.0, 0.0, 0.0
16+
ROTATION_RATE= 0.0, 0.0, 0.0
17+
TRANSLATION_RATE= -265.05707641411146, 0.0, 0.0
18+
MACH_NUMBER= 0.0
19+
FREESTREAM_PRESSURE= 101325.0
20+
FREESTREAM_TEMPERATURE= 273.15
21+
22+
% REFERENCE VALUES
23+
%
24+
% The AOA is only needed to compute CD and CL, it should match the translation rate.
25+
AOA= 0.0
26+
% Same for the Mach number of the motion.
27+
MACH_MOTION= 0.8
28+
REF_ORIGIN_MOMENT_X= 0.00
29+
REF_ORIGIN_MOMENT_Y= 0.00
30+
REF_ORIGIN_MOMENT_Z= 0.00
31+
REF_LENGTH= 1.0
32+
REF_AREA= 1.0
33+
34+
% BOUNDARY CONDITIONS
35+
%
36+
MARKER_EULER= ( airfoil )
37+
MARKER_FAR= ( farfield )
38+
MARKER_PLOTTING= ( airfoil )
39+
MARKER_MONITORING= ( airfoil )
40+
% We are specifying this marker to have an easy way to access it in python.
41+
MARKER_DEFORM_MESH= ( airfoil )
42+
43+
% DISCRETIZATION METHODS
44+
%
45+
CONV_NUM_METHOD_FLOW= ROE
46+
MUSCL_FLOW= YES
47+
NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES
48+
SLOPE_LIMITER_FLOW= VENKATAKRISHNAN_WANG
49+
VENKAT_LIMITER_COEFF= 0.1
50+
51+
% SOLUTION ACCELERATION
52+
%
53+
CFL_NUMBER= 1e3
54+
CFL_ADAPT= NO
55+
%
56+
MGLEVEL= 3
57+
MGCYCLE= W_CYCLE
58+
%
59+
LINEAR_SOLVER= FGMRES
60+
LINEAR_SOLVER_PREC= ILU
61+
LINEAR_SOLVER_ERROR= 0.1
62+
LINEAR_SOLVER_ITER= 10
63+
64+
% CONVERGENCE PARAMETERS
65+
%
66+
ITER= 250
67+
CONV_FIELD= RMS_DENSITY
68+
CONV_RESIDUAL_MINVAL= -9
69+
70+
% INPUT/OUTPUT
71+
%
72+
MESH_FILENAME= ../../euler/naca0012/mesh_NACA0012_inv.su2
73+
MESH_FORMAT= SU2
74+
SCREEN_OUTPUT= (INNER_ITER, RMS_RES, FORCE_X, FORCE_Y, FORCE_Z, MOMENT_X, MOMENT_Y, MOMENT_Z)
75+
HISTORY_OUTPUT= (INNER_ITER, RMS_RES, AERO_COEFF)

0 commit comments

Comments
 (0)