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

Conversation

ArneVoss
Copy link
Member

@ArneVoss ArneVoss commented May 4, 2023

Proposed Changes

Current situation: The translation velocities and rotation rates of a moving frame (activated with GRID_MOVEMENT= ROTATING_FRAME) can only be set in the config file using parameters TRANSLATION_RATE and ROTATION_RATE. During a trim analysis of a free-flying aircraft, these parameters are modified until an equilibrium is achieved.

Problem: A change of these parameters requires a new initialization of the solver, which can be time-consuming depending on the mesh size.

Proposed solution: A python interface is implemented that allows to change the parameters on-the-fly. The grid velocities are updated before a new iteration.

Related Work

This is an extension to pull request #1621.

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

@kursatyurt
Copy link
Contributor

It sounds like you are using an older commit of develop as a base branch, could you please resolve the conflicts?

@ArneVoss
Copy link
Member Author

ArneVoss commented May 5, 2023

OK, I see that some refactoring happened e.g. to the python wrapper in the meantime. What's the best way to resolve the conflicts? --> If I hit the Resolve conflicts button, there is nothing I can do.

@kursatyurt
Copy link
Contributor

OK, I see that some refactoring happened e.g. to the python wrapper in the meantime. What's the best way to resolve the conflicts? --> If I hit the Resolve conflicts button, there is nothing I can do.

Sorry, mistakenly I removed your functions from conflicted files github somewhat allow me to solve the conflict but not added any new commit or revert it.

Feel free to add them as an additional commit or revert my commit.

Normally if you have a merge conflict easiest way is to solve the conflict from your IDE. Pull the latest develop and merge to your branch, while merging you need to resolve the merge conflict.

This was an easy case you only have a few conflict, git write conflicts ass

>>> code from your branch
void xyz()
/* your implementation */
===  develop
void xyz()
/* their implementation */
<<< 

your need to replace that part with whichever code you want to keep or delete both of them etc. Then mark from the top right corner as resolved.

I am sorry, I am a bit tired and did not identify your part of the code from the previous implementation since it is in the middle. I removed all of them and GitHub automatically push it.

The required code pieces are these if I am not wrong. I am really sorry about the mistake.

from SU2_CFD/src/python_wrapper_structure.cpp

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

void CDriver::SetTranslationRate(passivedouble xDot, passivedouble yDot, passivedouble zDot) {
  if (rank == MASTER_NODE) {
    cout << endl << " Setting new translational velocity in x, y, z direction.";
  }
  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) {
  if (rank == MASTER_NODE) {
    cout << endl << " Setting new angular velocity about x, y, z axes.";
  }
  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);
  }
}

and from ``SU2_CFD/include/drivers/CDriver.hpp)

  /*!
   * \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);

@ArneVoss ArneVoss force-pushed the feature_python_interface_for_moving_frame branch from c2707b0 to aa786d8 Compare May 5, 2023 11:38
@ArneVoss
Copy link
Member Author

ArneVoss commented May 5, 2023

And where did all the python wrapper functions go?? I see that there is nearly nothing left in the python_wrapper_structure.cpp with respect to version 7.5.1 ? The problem is that I was using several of the functions which are now missing...

@pcarruscag
Copy link
Member

They are in CDriverBase

feature_python_interface_for_moving_frame
@ArneVoss
Copy link
Member Author

ArneVoss commented May 5, 2023

Ok, I see - So where do you think should my new functions go?

Now that a bunch of function names changed, I am sure I need to refactor my side as well, so I can't tell if this proposal is still working.

Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a python wrapper testcase for this.
Just for completeness, note that changing the grid velocities in an unsteady simulation will not be totally correct with these changes because the acceleration terms (d v_grid / dt) are not being added to the momentum source terms.

SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/python_wrapper_structure.cpp Show resolved Hide resolved
@ArneVoss
Copy link
Member Author

ArneVoss commented May 9, 2023

The test case seems to work, I only see small differences in the last digit w.r.t the results I computed on my workstation, which is ok from my side. How can I access the results computed by GitHub?

Common/src/geometry/CGeometry.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/drivers/CDriver.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/python_wrapper_structure.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/python_wrapper_structure.cpp Outdated Show resolved Hide resolved
@pcarruscag
Copy link
Member

Access the solution files? I'm not sure if that is possible, the runners are not persisted after the tests. But updating the results based on the test logs is fine.

@ArneVoss ArneVoss force-pushed the feature_python_interface_for_moving_frame branch from b8029b8 to 95628ce Compare May 12, 2023 12:09
@ArneVoss
Copy link
Member Author

Thank you @pcarruscag and @kursatyurt for your comments and suggestions! I hope that I understood and applied them as intended, if not, please let me know. This is all new to me and because I'm still learning C++, it took me a few extra commits but now all tests seem to pass :) Have a good weekend!

@ArneVoss ArneVoss requested review from kursatyurt and pcarruscag May 12, 2023 14:54
SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
@pcarruscag
Copy link
Member

Thanks @ArneVoss lgtm

@ArneVoss
Copy link
Member Author

Thank you @pcarruscag for your help :)

@ArneVoss
Copy link
Member Author

Just a detail: I noticed that we get the print messages three times now, presumably for all multigrid levels? This is just aesthetic, but is it possible print only the first message and to suppress all following ones?

Setting rotating frame grid velocities.
Rotational origin (x, y, z): ( 4.77293, 2.52512e-06, -0.0373385 )
Angular velocity about x, y, z axes: ( 0, 0, 0 ) rad/s
Translational velocity in x, y, z direction: (-135.786, 0, -9.49509).
Rotational origin (x, y, z): ( 4.77293, 2.52512e-06, -0.0373385 )
Angular velocity about x, y, z axes: ( 0, 0, 0 ) rad/s
Translational velocity in x, y, z direction: (-135.786, 0, -9.49509).
Rotational origin (x, y, z): ( 4.77293, 2.52512e-06, -0.0373385 )
Angular velocity about x, y, z axes: ( 0, 0, 0 ) rad/s
Translational velocity in x, y, z direction: (-135.786, 0, -9.49509).
Rotational origin (x, y, z): ( 4.77293, 2.52512e-06, -0.0373385 )
Angular velocity about x, y, z axes: ( 0, 0, 0 ) rad/s
Translational velocity in x, y, z direction: (-135.786, 0, -9.49509).

Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following should work

SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
SU2_CFD/src/iteration/CIteration.cpp Outdated Show resolved Hide resolved
@pcarruscag pcarruscag merged commit 85a9ae7 into su2code:develop May 21, 2023
@ArneVoss ArneVoss deleted the feature_python_interface_for_moving_frame branch May 22, 2023 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants