-
Notifications
You must be signed in to change notification settings - Fork 917
Numerics refactoring for CAvgGrad- and CUpwSca- classes #422
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
Conversation
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @clarkpede, thanks a lot for contributing to the SU2 code. Looking at your summary it seems to be a great addition to SU2 that we should extend to other parts of the software. I'm going to expend some time reviewing your source code and I'll let you know if there is something that we need to work on.
Thanks a lot for your time an generosity!
Francisco
| @@ -66,13 +66,13 @@ class CNumerics { | |||
| su2double *Enthalpy_formation; | |||
| su2double Prandtl_Lam; /*!< \brief Laminar Prandtl's number. */ | |||
| su2double Prandtl_Turb; /*!< \brief Turbulent Prandtl's number. */ | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing these extra spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is intended. Usually in some editors the default is to remove empty lines when saving the file. In fact, I would suggest to revert these changes as they give the potential to lead to conflicts in the future. We should be consistent regarding the handling of white spaces and empty lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just reverted the unnecessary whitespace changes. I agree that they should be eliminated to reduce the number of "false conflicts," and I also agree that SU2 could benefit from more consistent use of whitespace.
| @@ -2071,34 +2071,64 @@ class CUpwLin_AdjTurb : public CNumerics { | |||
| }; | |||
|
|
|||
| /*! | |||
| * \class CUpwSca_TurbSA | |||
| * \brief Class for doing a scalar upwind solver for the Spalar-Allmaral turbulence model equations. | |||
| * \class CUpwSca_Abstract | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes a lot of sense to me. By the way, we are using a very basic linear upwind scheme based on the velocity. Have you ever tried to use a more elaborate upwind? (e.g. something similar to the upwind scheme that we use for the mass conservation equation like using Roe's averaged variables).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I haven't looked into using the higher order upwinding in the turbulence classes. For the most part, our group has had other priorities (like implementing a higher order time-stepping).
| * \class CUpwSca_TurbML | ||
| * \brief Class for doing a scalar upwind solver for the Spalar-Allmaral turbulence model equations. | ||
| * \class CUpwSca_TurbSA | ||
| * \brief Class for doing a scalar upwind solver for the Spalar-Allmaras turbulence model equations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the typo in Allmaras!
| * \ingroup ConvDiscr | ||
| * \author A. Bueno. | ||
| * \version 5.0.0 "Raven" | ||
| */ | ||
| class CUpwSca_TurbML : public CNumerics { | ||
| class CUpwSca_TurbSA : public CUpwSca_Abstract { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good opportunity to fix this problem. If you have a while could you please eliminate all classes and subroutines with "TurbML": CUpwSca_TurbML, CAvgGrad_TurbML, CAvgGradCorrected_TurbML, CTurbMLVariable. ML stands for Machine Learning, that was an old implementation that was eliminated from the main SU2 distribution... but it seems that there are still some residuals. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had no idea what those classes were for. Thanks for the clarification. I'll make that change one of my next commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for removing the TurbML stuff!
| if (spalart_allmaras) numerics_container[iMGlevel][TURB_SOL][VISC_TERM] = new CAvgGradCorrected_TurbSA(nDim, nVar_Turb, config); | ||
| else if (neg_spalart_allmaras) numerics_container[iMGlevel][TURB_SOL][VISC_TERM] = new CAvgGradCorrected_TurbSA_Neg(nDim, nVar_Turb, config); | ||
| else if (menter_sst) numerics_container[iMGlevel][TURB_SOL][VISC_TERM] = new CAvgGradCorrected_TurbSST(nDim, nVar_Turb, constants, config); | ||
| if (spalart_allmaras) numerics_container[iMGlevel][TURB_SOL][VISC_TERM] = new CAvgGrad_TurbSA(nDim, nVar_Turb, true, config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for simplifying the structure. And yes, a boolean works better... in fact, in the future we should probably only use the corrected version which is quite standard.
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a very useful contribution, and an example for future implementations. I only have two questions related with the naming convention:
- What is the subroutine "FinishResidualCalc" is it a new name to call "ComputeResidual" if that is the case, for consistency with the rest of the code we should probably use "ComputeResidual"
- You are adding the prefix "_Abstract" to the new parent classes. For the time being, as we are applying this only for the turbulence model, would it be possible to add also the key word "Turb". And... are you completely sure about using the word "Abstract" does it makes sense to use something like for example CAvgGrad_TurbBaseline instead of CAvgGrad_Abstract. What do you think?
Best,
Francisco
|
In reply to:
I would have liked to have named it the way you suggested. But unfortunately, it's not possible. There's two reasons for this: one is more philosophical, the other is due to a programming restriction.
I'm not fixed on the name. Honestly, I picked it somewhat arbitrarily. I just know that "ComputeResidual" isn't an option. What do you suggest as a better name? |
|
In reply to:
I'm not fixed on "Abstract". In fact, I wanted to use the suffix "Template" instead, and only decided on "Abstract" as a less satisfactory second choice. As the code currently stands, I totally agree with you. "Turb" would be a better suffix. But I was also thinking about possible changes in the future. I can see these classes ( I didn't picture the transition model as part of this pull request's scope. I wanted to include the transition model as a separate pull request. If we do want to refactor the transition model to eliminate the duplicate code there, then I don't think "Turb" or "TurbBaseline" are good suffixes. If you do want the duplicate code in the transition model eliminated, then which would you prefer: "Baseline", "Abstract", "Outline", or "Scalar"? Or do you have another idea? |
talbring
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @clarkpede for these changes. That really simplifies the turbulent numerics and could be also be done for the other classes in the future.
I just have some minor comments below.
| @@ -66,13 +66,13 @@ class CNumerics { | |||
| su2double *Enthalpy_formation; | |||
| su2double Prandtl_Lam; /*!< \brief Laminar Prandtl's number. */ | |||
| su2double Prandtl_Turb; /*!< \brief Turbulent Prandtl's number. */ | |||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is intended. Usually in some editors the default is to remove empty lines when saving the file. In fact, I would suggest to revert these changes as they give the potential to lead to conflicts in the future. We should be consistent regarding the handling of white spaces and empty lines.
| su2double **Mean_GradTurbVar; | ||
| su2double *Proj_Mean_GradTurbVar_Kappa, *Proj_Mean_GradTurbVar_Edge; | ||
| su2double *Edge_Vector; | ||
| class CAvgGrad_Abstract : public CNumerics { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to use a different name for this class. Simply CAvgGrad_Turb would be ok I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you get a chance to look at my earlier reply to Dr. Palacios' similar comment? What are your thoughts? Should we put the suffix as "Turb", and change it in the future, or have the name be more general, such as "Baseline", "Abstract", "Outline", or "Scalar"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops sorry. Didn't read that.
|
@clarkpede, @talbring, @fpalacios: I think this is a great discussion, and a good opportunity to think about future expansion of the code with this naming (the changes to other classes could come later). I envision that we will use the same high-level conv/visc schemes abstracted here for the transition model but also for general scalar transport equations in the future, such as passive scalars, combustion models, etc. I am fine with "Turb" but "Scalar" could be the most general. |
|
I agree that if we plan to have it even more general in the future, then we should probably go with the term "Scalar". |
|
Yep, "Scalar" sounds great. As for me, just implement that small change and I would very happy with your implementation. Thanks again, |
|
All right. I changed the suffixes from "_Abstract" to "_Scalar". I think that resolves all previous issues. I noticed Codacy flagged some code quality issues that predate this pull request. I can change those in a separate pull request, unless any of you want me to do that here. |
economon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR that cleans up redundant code - this type of thing keeps with the C++ philosophy of code reuse, and we should encourage as much of this as possible. Nice work!
Just one comment in the review, and don't worry about Codacy. We are just trying it out at the moment.
| * \version 5.0.0 "Raven" | ||
| */ | ||
| class CUpwSca_TurbSA : public CNumerics { | ||
| class CUpwSca_Scalar : public CNumerics { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, CUpwSca_Scalar is a bit redundant... CUpw_Scalar or CUpwScalar might be better. Perhaps the latter is best, as later child classes can be more specific to the model, e.g., CUpwScalar_TurbSA, etc.
|
Hi @talbring are you happy with this version of the pull request? Thanks! |
|
Looks good now ! Thanks ! |
|
Looks good to me too now, thanks for the changes, merging... |
I noticed there was a lot of duplicate code in the turbulent numerics files (
numerics_structure.hppandnumerics_direct_turbulent.cpp). Since I'm working with new model equations for hybrid RANS/LES, I didn't want to add to the technical debt. So I decided to refactor the turbulence numerics using the template design pattern.Basically, I moved common behavior for the viscous and the upwinding residuals to respective base classes and then left the specifics of each model to derived classes. I did my best to not change any of the underlying behavior.
The source residual calculations for SST and SA have little in common. I did not apply the template design pattern to them.
I named the template classes
CUpwSca_AbstractandCAvgGrad_Abstractbecause the_Templatesuffix was already taken.I also noticed that there were almost no difference between the old
CAvgGrad_classes and theCAvgGradCorrected_classes. The gradient correction is such a small change that it's better to have a single class with a switch than two classes that are about 95% similar. So I added a boolean property and logical switching if correction is to be applied to the gradients. This boolean parameter is now a parameter for the constructor.Overall, these changes trim down a lot of duplicate code (40% of the lines in
numerics_direct_turbulent.cpp). These changes could be extended to other areas (such as the transition model), but I left that to future pull requests.