-
Notifications
You must be signed in to change notification settings - Fork 847
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
SU2-NEMO - Optimize initialization time #1340
Conversation
rho = fluidmodel->GetDensity(); | ||
soundspeed = fluidmodel->ComputeSoundSpeed(); | ||
for (iDim = 0; iDim < nDim; iDim++){ | ||
sqvel += val_mach[iDim]*soundspeed * val_mach[iDim]*soundspeed; | ||
} | ||
energies = fluidmodel->ComputeMixtureEnergies(); |
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.
rho = fluidmodel->GetDensity(); | |
soundspeed = fluidmodel->ComputeSoundSpeed(); | |
for (iDim = 0; iDim < nDim; iDim++){ | |
sqvel += val_mach[iDim]*soundspeed * val_mach[iDim]*soundspeed; | |
} | |
energies = fluidmodel->ComputeMixtureEnergies(); | |
const su2double rho = fluidmodel->GetDensity(); | |
const su2double soundspeed = fluidmodel->ComputeSoundSpeed(); | |
const su2double sqvel = GeometryToolbox::SquaredNorm(nDim, val_mach) * pow(soundspeed,2); | |
const auto& energies = fluidmodel->ComputeMixtureEnergies(); |
You may need the include for geometry_toolbox.hpp.
Be aware of the methods in CNEMOGas that return by reference, those little copies of std::vector add up and it is an easy fix.
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.
That is true, and may be the main reason of the slowness of SU2-NEMO iterations. I will try to address that in my next PR.
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.
👍 You can have a look at #716 (scroll down) for how to use perf-tools to profile the code and point you to the hot spots "first rule of performance is that you need to measure it". There should be hotter areas in NEMO than vector copies.
@@ -168,14 +166,9 @@ CNEMOEulerVariable::CNEMOEulerVariable(su2double val_pressure, | |||
|
|||
Solution(iPoint,nSpecies+nDim) = rho*(energies[0]+0.5*sqvel); | |||
Solution(iPoint,nSpecies+nDim+1) = rho*(energies[1]); | |||
|
|||
Solution_Old = Solution; |
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.
If you suspect this may be happening somewhere else I can tell you how to instrument the code to find it.
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 Pedro, I still need to check what is happening at each iteration, but first wanted to sort out the initialization issue
This pull request fixes 1 alert when merging 040da9e into cf4677b - view on LGTM.com fixed alerts:
|
Thanks @fmpmorgado! NEMO definitely needs some speed up! This looks good! Regarding the preprocessing, why is the ComputeSoundSpeed() function returning slightly different results? |
Inside the CNEMOEulerVariable, you set the fluidmodel with the freestream conditions written in the config file and use the ComputeSoundSpeed(). However, in the CNEMOEulerSolver, in the deleted loop, you had GetSoundSpeed(), which retrieves the solution already estabilished in the Primitive Matrix. The Primitive Matrix was estabilished inside the SetPrimVar() function. However, inside the function, we set the fluidmodel with slightly different values than the ones used in the config file, because we first run the iterative process to find the translational and vibrational temperature with the given energies. This iterative process provides slightly different temperatures than the ones in the config file, thus computing slightly different sound speeds |
Proposed Changes
Optimize the SU2-NEMO solver initialization time
Related Work
None that I remember
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.
Work Overview
I have optimized the initialization time of SU2-NEMO. You can check the time comparison between the old and new version at the table below.
Some steps that I have done:
CNEMOEulerVariable.cpp
CNEMOEulerSolver.cpp
CSolverFactory.cpp
The residuals may slightly different, because of the removal of the for loop inside CNEMOEulerSolver.cpp. Notice that inside that for loop, the soundspeed is obtained using the function FluidModel->GetSoundSpeed(), which gives a slight different value than the one calculated inside CNEMOEulerVariable.cpp using FluidModel->ComputeSoundSpeed(). This means that the regression tests may fail.