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

Refactor SA source terms to modularize the specification of model variants and correction terms #1413

Merged
merged 39 commits into from
Mar 3, 2022

Conversation

suargi
Copy link
Contributor

@suargi suargi commented Oct 22, 2021

Pull request description

The idea of this pull request is to provide a new code structure to implement the turbulence models in SU2. In the new approach, "all" variations/correction from a turbulence model should be compatible with each other and the user can use them simultaneously. Most of these variations/corrections only affect to the source terms, thus it forms the main contribution to this pull request.

Short history summary

Originally the idea behind such an approach is given by @clarkpede in here.
The code implementation was suggested by @pcarruscag in here.
For the user interface, this is being or was discussed in here.

Some time ago, I made a PR #1066 to correct the SA model in SU2. Further I had the intention to implement the above presented approach to the SA for that pull request. However since the the presented approach can also be applied to the SST or any turbulence model, I decided to create a new pull request.

Please note that this is a very draft pull request, it is not meant to work at all.

Documentation

Down below I will explain the "theory" behind it as well as the code structure that I will try to follow, just in case someone wants to replicate it for the SST.

Regarding the user interface, I did not work on that yet. I will address it at the end.

Theory

The Spalart-Allamaras correction/variation models to be implemented in SU2 are listed below. One can find a detailed description for example in NASA TMR website.

  • Spalart-Allmaras standard
  • Spalart-Allmaras negative
  • Spalart-Allmaras yes ft2 term
  • Spalart-Allmaras mixing layer compressibility correction
  • Spalart-Allmaras Edwards modification
  • Spalart-Allmaras QCR-2000

The first step is to identify the core, i.e., the mathematical formulation that is shared/common between all of them. Below I provide a very short description of their main characteristics.

Spalart-Allmaras standard

In the literature one can find a correction that sets the ft2-term to zero. However, the current baseline model in SU2 sets this ft2-term to zero. As discussed in here in order to keep compatibility with previous SU2 versions results it is preferable to keep the current nomenclature, i.e., SA will refer to the SA-noft2 variant.

Spalart-Allmaras negative

The model is the same as the "baseline" version when the turbulence variable $\tilde \nu$ is greater than or equal to zero. The modified vorticity is modified to prevent it from acquiring negative values. When $\tilde \nu$ is negative a slightly different integral equation is solved. The viscous fluxes are redefined as well.

The boundary conditions are the same as for the standard S-A.

Spalart-Allmaras nonzero ft2 term

This is the approach corresponds to the faithful baseline. The equations are the same as for the "baseline" version (SA), except we take the term $f_{t2}$ into account.

Spalart-Allmaras mixing layer compressibility correction

This version is the same as for the "baseline" version except that an additional term is included on the right hand side of the equation.

Spalart-Allmaras Edwards modification

This version is the same as for the "baseline" version, except that $f_{t2}$ is ignored, and two variables are redefined: the modified vorticity $\tilde{S}$ and $r$.

Note that this correction is not compatible with the negative SA model. Since there is no literature on how to handle both corrections simultaneously, the community decision was to prompt an error when trying to use them.

Spalart-Allmaras QCR-2000

The QCR correction modifies the turbulent stresses definition.

Code structure

The approach that I decided to follow is:
The baseline/standalone SA class will have several templates parameters. Each of them will correspond to one of those variables that are subject to change in a SA correction/variation. Then, when creating the SA turbulence model, one just needs to replace each of these templates by the appropriate class.

For those corrections/variations that just introduce an additional source term, I think it is better to implement them using decorators. Hence multiple corrections/variations introducing source terms can be simultaneously used.

Here is a minimal example:

‼️ IMPORTANT: the following code served as a first draft and orientation. The final version has slightly changed to improve efficiency, reusability and readability. ‼️

template<class ft2_c, class ModVort_c>
class SA_Base : public CNumerics {
public:
  SA_Base() {}

  void computeResidual() final {
    ft2 = ft2_c::Compute()
    S_hat = ModVort_c::Compute(2.0,10)
  }
};

// the term "bsl" stands for baseline
class ft2_bsl     { static double Compute() { return 0.0; } }; 
class ft2_nonzero { static double Copmute() { return ...; } };
class ModVort_bsl { static double Compute(const double x, const int y){ return x*y; } };
class ModVort_Neg { static double Compute(const double x, const int y){ return x*y; } };
class ModVort_Edw { static double Compute(const double x, const int y){ return x+y; } };

/*-- Numerics preprocessing --*/
// From the config file (.cfg) determine which corrections/variations we have to use: ft2_variant, ModVort_variant, etc
// Create Frankenstein SA
if(ft2_variant==0 && ModVort_variant==0) numerics[i] = new SA_Base<ft2_bsl, ModVort_bsl>();
if(ft2_variant==0 && ModVort_variant==1) numerics[i] = new SA_Base<ft2_bsl, ModVort_Neg>();
if(ft2_variant==0 && ModVort_variant==2) numerics[i] = new SA_Base<ft2_bsl, ModVort_Edw>();
if(ft2_variant==1 && ModVort_variant==0) numerics[i] = new SA_Base<ft2_nonzero, ModVort_bsl>();
if(ft2_variant==1 && ModVort_variant==1) numerics[i] = new SA_Base<ft2_nonzero, ModVort_Neg>();
// so on

// Proceed to compute the turbulent sources residual as always

Related Work

This PR closes the PR #1066.
This PR closes the issue #1364.
This PR will hopefully close the discussion #1403.

PR Checklist

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with the '-Wall -Wextra -Wno-unused-parameter -Wno-empty-body' compiler flags, or simply --warnlevel=2 when using meson).
  • My contribution is commented and consistent with SU2 style.
  • 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.

With new implementation of turbulence modeling, the current turb_sources.cpp and turb_sources.hpp are no longer useful. Because of that, I deleted almost everything related to SA in order to start from scratch.
@pr-triage pr-triage bot added the PR: draft label Oct 22, 2021
Create a test cases directory for turbulence modeling. The selected geometry if the RAE2822 airfoil. Created the config files for the SA turb. mod. variations:
- baseline
- negative
- Edwards
- Compressibility
- Edwards and Compressibility
- ft2
- QCR
@TobiKattmann
Copy link
Contributor

hmm, 0f4977f must have introduced sth that made the two (streamwise periodic) testcases fail. I think the defining feature here is, that they use the SST-turb model.

But looking at the mentioned commit, the changes look equal to me 🤔

Comment on lines +507 to +508
/// TODO: Factory method to create combinations of the different variations based on the config.
/// See PR #1413, the combinations exposed should follow https://turbmodels.larc.nasa.gov/spalart.html
Copy link
Member

@pcarruscag pcarruscag Mar 3, 2022

Choose a reason for hiding this comment

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

  • Main TODO for a future PR

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