Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python interface for updating translation and rotation rates of the moving frame #2024

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ae828e3
First try to implement a python wrapper for updating the dynamic mesh
ArneVoss Feb 27, 2023
1fcd7b2
Implementing the python wrapper for updating the translational mesh
ArneVoss Feb 27, 2023
aa786d8
Make sure that the velocity field from a rotating frame is reset in e…
ArneVoss Apr 13, 2023
9363637
Merge remote-tracking branch 'origin/develop' into
ArneVoss May 5, 2023
75777c7
Make comment more clear as suggested in code review
ArneVoss May 8, 2023
d7e3e6c
Add a test case that updates the translation and rotation rates given in
ArneVoss May 9, 2023
28f4133
Removed units from screen output as the values can be non-dimensional,
ArneVoss May 9, 2023
cf4fc61
Removed calculation of moving frame grid velocities due to Roating frame
ArneVoss May 9, 2023
faf2d2c
Added new testcase from previous commit to the regression tests.
ArneVoss May 9, 2023
4a5d80a
Aplly sugestion form Code scanning / CodeQL
ArneVoss May 9, 2023
c8c7931
Undoing 28f4133 as rotations are always in rad/s
ArneVoss May 12, 2023
4f00bcc
Removing print messages from python interface.
ArneVoss May 12, 2023
cdd2e61
Removing reference results file for
ArneVoss May 12, 2023
1d8e956
Move the translating frame as well so that it can be updated from the
ArneVoss May 12, 2023
e3a44fb
Apply sugestion form Code scanning / CodeQL
ArneVoss May 12, 2023
67f6e93
Revert "Removing reference results file for ARM64"
ArneVoss May 12, 2023
9dd3ecb
Removing reference results file in the right folder
ArneVoss May 12, 2023
3b60113
Use reference results calculated by GitHub runner
ArneVoss May 12, 2023
95628ce
Remove unused variable Kind_Grid_Movement
ArneVoss May 12, 2023
e93f258
C++ seems to require a break statement when using switch/case...
ArneVoss May 12, 2023
8331045
Apply suggestions from code review
pcarruscag May 12, 2023
c14d783
Apply suggestions from code review
pcarruscag May 12, 2023
254fe21
Update SU2_CFD/src/iteration/CIteration.cpp
pcarruscag May 12, 2023
dea5d41
Apply suggestions from code review
pcarruscag May 21, 2023
54d9347
Merge branch 'develop' into feature_python_interface_for_moving_frame
pcarruscag May 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Common/include/CConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5804,6 +5804,13 @@ class CConfig {
*/
su2double GetTranslation_Rate(unsigned short iDim) const { return Translation_Rate[iDim];}

/*!
* \brief Set the translational velocity of the mesh.
* \param[in] iDim - spatial component
* \return Translational velocity of the mesh.
*/
void SetTranslation_Rate(unsigned short iDim, su2double val) { Translation_Rate[iDim] = val;}

/*!
* \brief Get the translational velocity of the marker.
* \param[in] iMarkerMoving - Index of the moving marker (as specified in Marker_Moving)
Expand Down
16 changes: 16 additions & 0 deletions SU2_CFD/include/drivers/CDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,22 @@ class CDriver : public CDriverBase {
*/
void SetInletAngle(unsigned short iMarker, passivedouble alpha);

/*!
* \brief Set the dynamic mesh translation rates.
* \param[in] xDot - Value of translational velocity in x-direction.
* \param[in] yDot - Value of translational velocity in y-direction.
* \param[in] zDot - Value of translational velocity in z-direction.
*/
void SetTranslationRate(passivedouble xDot, passivedouble yDot, passivedouble zDot);

/*!
* \brief Set the dynamic mesh rotation rates.
* \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 SetRotationRate(passivedouble rot_x, passivedouble rot_y, passivedouble rot_z);

/// \}
};

Expand Down
45 changes: 0 additions & 45 deletions SU2_CFD/src/drivers/CDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2547,56 +2547,11 @@ void CDriver::InitializeInterface(CConfig **config, CSolver***** solver, CGeomet
void CDriver::PreprocessStaticMesh(const CConfig *config, CGeometry** geometry){

unsigned short iMGlevel, iMGfine;
unsigned short Kind_Grid_Movement;

unsigned short iZone = config->GetiZone();

Kind_Grid_Movement = config->GetKind_GridMovement();

if (!fem_solver) {

switch (Kind_Grid_Movement) {

case ROTATING_FRAME:

/*--- Steadily rotating frame: set the grid velocities just once
before the first iteration flow solver. ---*/

if (rank == MASTER_NODE) {
cout << endl << " Setting rotating frame grid velocities";
cout << " for zone " << iZone << "." << endl;
}

/*--- Set the grid velocities on all multigrid levels for a steadily
rotating reference frame. ---*/

for (iMGlevel = 0; iMGlevel <= config_container[ZONE_0]->GetnMGLevels(); iMGlevel++){
geometry[iMGlevel]->SetRotationalVelocity(config, true);
geometry[iMGlevel]->SetShroudVelocity(config);
}

break;

case STEADY_TRANSLATION:

/*--- Set the translational velocity and hold the grid fixed during
the calculation (similar to rotating frame, but there is no extra
source term for translation). ---*/

if (rank == MASTER_NODE)
cout << endl << " Setting translational grid velocities." << endl;

/*--- Set the translational velocity on all grid levels. ---*/

for (iMGlevel = 0; iMGlevel <= config_container[ZONE_0]->GetnMGLevels(); iMGlevel++)
geometry_container[iZone][INST_0][iMGlevel]->SetTranslationalVelocity(config, true);

break;

default:
break;
}

if (config->GetnMarker_Moving() > 0) {

/*--- Fixed wall velocities: set the grid velocities only one time
Expand Down
26 changes: 25 additions & 1 deletion SU2_CFD/src/iteration/CIteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,33 @@ void CIteration::SetGrid_Movement(CGeometry** geometry, CSurfaceMovement* surfac

break;

/*--- Already initialized in the static mesh movement routine at driver level. ---*/
case STEADY_TRANSLATION:
/*--- Set or update the translating frame mesh movement with the current translation rates,
* which might be altered via the python interface. ---*/

if (rank == MASTER_NODE) cout << "\n Setting translational grid velocities." << endl;

/*--- Set the translational velocity on all grid levels. ---*/

for (auto iMGlevel = 0u; iMGlevel <= config->GetnMGLevels(); iMGlevel++)
geometry[iMGlevel]->SetTranslationalVelocity(config, iMGlevel == 0);

break;

case ROTATING_FRAME:
/*--- Set or update the rotating frame mesh movement with the current translation and rotation
* rates, which might be altered via the python interface. ---*/

if (rank == MASTER_NODE) cout << "\n Setting rotating frame grid velocities." << endl;

/*--- Set the grid velocities on all multigrid levels for a steadily
rotating reference frame. ---*/

for (auto iMGlevel = 0u; iMGlevel <= config->GetnMGLevels(); iMGlevel++){
geometry[iMGlevel]->SetRotationalVelocity(config, iMGlevel == 0);
geometry[iMGlevel]->SetShroudVelocity(config);
}

break;
}

Expand Down
20 changes: 20 additions & 0 deletions SU2_CFD/src/python_wrapper_structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,23 @@ void CDriver::BoundaryConditionsUpdate() {
geometry_container[iZone][INST_0][MESH_0]->UpdateCustomBoundaryConditions(geometry_container[iZone][INST_0],config_container[iZone]);
}
}

////////////////////////////////////////////////////////////////////////////////
/* Functions related to dynamic mesh */
////////////////////////////////////////////////////////////////////////////////

void CDriver::SetTranslationRate(passivedouble xDot, passivedouble yDot, passivedouble zDot) {
ArneVoss marked this conversation as resolved.
Show resolved Hide resolved
for (iZone = 0; iZone < nZone; iZone++) {
config_container[iZone]->SetTranslation_Rate(0, xDot);
config_container[iZone]->SetTranslation_Rate(1, yDot);
config_container[iZone]->SetTranslation_Rate(2, zDot);
}
}

void CDriver::SetRotationRate(passivedouble rot_x, passivedouble rot_y, passivedouble rot_z) {
for (iZone = 0; iZone < nZone; iZone++) {
config_container[iZone]->SetRotation_Rate(0, rot_x);
config_container[iZone]->SetRotation_Rate(1, rot_y);
config_container[iZone]->SetRotation_Rate(2, rot_z);
}
}
12 changes: 12 additions & 0 deletions TestCases/hybrid_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,18 @@ def main():
pywrapper_translating_naca0012.test_file = "forces_0.csv"
pywrapper_translating_naca0012.enabled_on_cpu_arch = ["x86_64"]
file_diff_list.append(pywrapper_translating_naca0012)

# NACA0012 with updated moving frame
pywrapper_updated_moving_frame_naca0012 = TestCase('pywrapper_updated_moving_frame_naca0012')
pywrapper_updated_moving_frame_naca0012.cfg_dir = "py_wrapper/updated_moving_frame_NACA12"
pywrapper_updated_moving_frame_naca0012.cfg_file = "config.cfg"
pywrapper_updated_moving_frame_naca0012.command = TestCase.Command(exec = "python", param = "run_su2.py")
pywrapper_updated_moving_frame_naca0012.timeout = 60
pywrapper_updated_moving_frame_naca0012.reference_file = "forces_0.csv.ref"
pywrapper_updated_moving_frame_naca0012.reference_file_aarch64 = "forces_0_aarch64.csv.ref"
pywrapper_updated_moving_frame_naca0012.test_file = "forces_0.csv"
pywrapper_updated_moving_frame_naca0012.enabled_on_cpu_arch = ["x86_64"]
file_diff_list.append(pywrapper_updated_moving_frame_naca0012)

######################################
### RUN TESTS ###
Expand Down
75 changes: 75 additions & 0 deletions TestCases/py_wrapper/updated_moving_frame_NACA12/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
% PROBLEM DEFINITION
%
SOLVER= EULER
pcarruscag marked this conversation as resolved.
Show resolved Hide resolved
REF_DIMENSIONALIZATION= FREESTREAM_VEL_EQ_MACH
MATH_PROBLEM= DIRECT
RESTART_SOL= NO

% FREE-STREAM DEFINITION
%
% We are translating the domain instead of having farfield velocity.
% Note: The rotating frame is intended for 3D cases. To use the feature in a 2D case,
% care must be taken with respect to the axes, e.g. to obtain a pitching motion, a
% rotation about the z-axis can be used.
GRID_MOVEMENT= ROTATING_FRAME
MOTION_ORIGIN= 0.0, 0.0, 0.0
ROTATION_RATE= 0.0, 0.0, 0.0
TRANSLATION_RATE= -265.05707641411146, 0.0, 0.0
MACH_NUMBER= 0.0
FREESTREAM_PRESSURE= 101325.0
FREESTREAM_TEMPERATURE= 273.15

% REFERENCE VALUES
%
% The AOA is only needed to compute CD and CL, it should match the translation rate.
AOA= 0.0
% Same for the Mach number of the motion.
MACH_MOTION= 0.8
REF_ORIGIN_MOMENT_X= 0.00
REF_ORIGIN_MOMENT_Y= 0.00
REF_ORIGIN_MOMENT_Z= 0.00
REF_LENGTH= 1.0
REF_AREA= 1.0

% BOUNDARY CONDITIONS
%
MARKER_EULER= ( airfoil )
MARKER_FAR= ( farfield )
MARKER_PLOTTING= ( airfoil )
MARKER_MONITORING= ( airfoil )
% We are specifying this marker to have an easy way to access it in python.
MARKER_DEFORM_MESH= ( airfoil )

% DISCRETIZATION METHODS
%
CONV_NUM_METHOD_FLOW= ROE
MUSCL_FLOW= YES
NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES
SLOPE_LIMITER_FLOW= VENKATAKRISHNAN_WANG
VENKAT_LIMITER_COEFF= 0.1

% SOLUTION ACCELERATION
%
CFL_NUMBER= 1e3
CFL_ADAPT= NO
%
MGLEVEL= 3
MGCYCLE= W_CYCLE
%
LINEAR_SOLVER= FGMRES
LINEAR_SOLVER_PREC= ILU
LINEAR_SOLVER_ERROR= 0.1
LINEAR_SOLVER_ITER= 10

% CONVERGENCE PARAMETERS
%
ITER= 250
CONV_FIELD= RMS_DENSITY
CONV_RESIDUAL_MINVAL= -9

% INPUT/OUTPUT
%
MESH_FILENAME= ../../euler/naca0012/mesh_NACA0012_inv.su2
MESH_FORMAT= SU2
SCREEN_OUTPUT= (INNER_ITER, RMS_RES, FORCE_X, FORCE_Y, FORCE_Z, MOMENT_X, MOMENT_Y, MOMENT_Z)
HISTORY_OUTPUT= (INNER_ITER, RMS_RES, AERO_COEFF)
Loading