Skip to content

Commit 56a16b3

Browse files
authored
Merge pull request #1450 from su2code/clean_loadrestart
Clean LoadRestart for Flow/Turb/Heat
2 parents a4836f4 + 746118d commit 56a16b3

5 files changed

Lines changed: 167 additions & 167 deletions

File tree

Common/include/CConfig.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ class CConfig {
554554
STRUCT_DEFORMATION Kind_Struct_Solver; /*!< \brief Determines the geometric condition (small or large deformations) for structural analysis. */
555555
unsigned short Kind_DV_FEA; /*!< \brief Kind of Design Variable for FEA problems.*/
556556

557+
unsigned short nTurbVar; /*!< \brief Number of Turbulence variables, i.e. 1 for SA-types, 2 for SST. */
557558
TURB_MODEL Kind_Turb_Model; /*!< \brief Turbulent model definition. */
558559
unsigned short Kind_SGS_Model; /*!< \brief LES SGS model definition. */
559560
unsigned short Kind_Trans_Model, /*!< \brief Transition model definition. */
@@ -4179,6 +4180,12 @@ class CConfig {
41794180
*/
41804181
void SetKind_SU2(SU2_COMPONENT val_kind_su2) { Kind_SU2 = val_kind_su2 ; }
41814182

4183+
/*!
4184+
* \brief Get the number of Turbulence Variables.
4185+
* \return Number of Turbulence Variables.
4186+
*/
4187+
unsigned short GetnTurbVar(void) const { return nTurbVar; }
4188+
41824189
/*!
41834190
* \brief Get the kind of the turbulence model.
41844191
* \return Kind of the turbulence model.

Common/src/CConfig.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5075,6 +5075,17 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
50755075
if (GetGasModel() == "ARGON") {monoatomic = true;}
50765076
else {monoatomic = false;}
50775077

5078+
/*--- Set number of Turbulence Variables. ---*/
5079+
switch(Kind_Turb_Model) {
5080+
case TURB_MODEL::NONE:
5081+
nTurbVar = 0; break;
5082+
case TURB_MODEL::SA: case TURB_MODEL::SA_COMP: case TURB_MODEL::SA_E_COMP: case TURB_MODEL::SA_E:
5083+
case TURB_MODEL::SA_NEG:
5084+
nTurbVar = 1; break;
5085+
case TURB_MODEL::SST: case TURB_MODEL::SST_SUST:
5086+
nTurbVar = 2; break;
5087+
}
5088+
50785089
// This option is deprecated. After a grace period until 7.2.0 the usage warning should become an error.
50795090
if(OptionIsSet("CONV_CRITERIA") && rank == MASTER_NODE) {
50805091
cout << "\n\nWARNING: CONV_CRITERIA is deprecated. SU2 will choose the criteria automatically based on the CONV_FIELD.\n"

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 100 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -718,139 +718,119 @@ void CFVMFlowSolverBase<V, R>::SetUniformInlet(const CConfig* config, unsigned s
718718
}
719719

720720
template <class V, ENUM_REGIME R>
721-
void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver ***solver, CConfig *config,
722-
int iter, bool update_geo, su2double* SolutionRestart,
721+
void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver ***solver, CConfig *config, int iter,
722+
bool update_geo, su2double* SolutionRestart,
723723
unsigned short nVar_Restart) {
724-
725724
/*--- Restart the solution from file information ---*/
726725

727-
unsigned short iDim, iVar, iMesh;
728-
unsigned long iPoint, index, iChildren, Point_Fine;
729-
TURB_MODEL turb_model = config->GetKind_Turb_Model();
730-
su2double Area_Children, Area_Parent;
731-
const su2double* Solution_Fine = nullptr;
732-
const passivedouble* Coord = nullptr;
733-
bool dual_time = ((config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_1ST) ||
734-
(config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND));
735-
bool static_fsi = ((config->GetTime_Marching() == TIME_MARCHING::STEADY) && config->GetFSI_Simulation());
736-
bool steady_restart = config->GetSteadyRestart();
737-
bool turbulent = (config->GetKind_Turb_Model() != TURB_MODEL::NONE);
738-
739-
string restart_filename = config->GetFilename(config->GetSolution_FileName(), "", iter);
726+
const string restart_filename = config->GetFilename(config->GetSolution_FileName(), "", iter);
727+
const bool static_fsi = ((config->GetTime_Marching() == TIME_MARCHING::STEADY) && config->GetFSI_Simulation());
740728

741729
/*--- To make this routine safe to call in parallel most of it can only be executed by one thread. ---*/
742730
SU2_OMP_MASTER {
743731

744-
if (nVar_Restart == 0) nVar_Restart = nVar;
732+
if (nVar_Restart == 0) nVar_Restart = nVar;
745733

746-
/*--- Skip coordinates ---*/
734+
/*--- Skip coordinates ---*/
747735

748-
unsigned short skipVars = geometry[MESH_0]->GetnDim();
736+
unsigned short skipVars = nDim;
749737

750-
/*--- Store the number of variables for the turbulence model
751-
(that could appear in the restart file before the grid velocities). ---*/
752-
unsigned short turbVars = 0;
753-
if (turbulent){
754-
if ((turb_model == TURB_MODEL::SST) || (turb_model == TURB_MODEL::SST_SUST)) turbVars = 2;
755-
else turbVars = 1;
756-
}
738+
/*--- Read the restart data from either an ASCII or binary SU2 file. ---*/
757739

758-
/*--- Read the restart data from either an ASCII or binary SU2 file. ---*/
759-
760-
if (config->GetRead_Binary_Restart()) {
761-
Read_SU2_Restart_Binary(geometry[MESH_0], config, restart_filename);
762-
} else {
763-
Read_SU2_Restart_ASCII(geometry[MESH_0], config, restart_filename);
764-
}
740+
if (config->GetRead_Binary_Restart()) {
741+
Read_SU2_Restart_Binary(geometry[MESH_0], config, restart_filename);
742+
} else {
743+
Read_SU2_Restart_ASCII(geometry[MESH_0], config, restart_filename);
744+
}
765745

766-
if (update_geo && dynamic_grid) {
767-
auto notFound = fields.end();
768-
if (find(fields.begin(), notFound, string("\"Grid_Velocity_x\"")) == notFound) {
769-
if (rank == MASTER_NODE)
770-
cout << "\nWARNING: The restart file does not contain grid velocities, these will be set to zero.\n" << endl;
771-
steady_restart = true;
746+
bool steady_restart = config->GetSteadyRestart();
747+
if (update_geo && dynamic_grid) {
748+
auto notFound = fields.end();
749+
if (find(fields.begin(), notFound, string("\"Grid_Velocity_x\"")) == notFound) {
750+
if (rank == MASTER_NODE)
751+
cout << "\nWARNING: The restart file does not contain grid velocities, these will be set to zero.\n" << endl;
752+
steady_restart = true;
753+
}
772754
}
773-
}
774755

775-
/*--- Load data from the restart into correct containers. ---*/
756+
/*--- Load data from the restart into correct containers. ---*/
776757

777-
unsigned long counter = 0, iPoint_Global = 0;
778-
for (; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) {
758+
unsigned long counter = 0;
759+
for (auto iPoint_Global = 0ul; iPoint_Global < geometry[MESH_0]->GetGlobal_nPointDomain(); iPoint_Global++) {
779760

780-
/*--- Retrieve local index. If this node from the restart file lives
781-
on the current processor, we will load and instantiate the vars. ---*/
761+
/*--- Retrieve local index. If this node from the restart file lives
762+
on the current processor, we will load and instantiate the vars. ---*/
782763

783-
auto iPoint_Local = geometry[MESH_0]->GetGlobal_to_Local_Point(iPoint_Global);
764+
const auto iPoint_Local = geometry[MESH_0]->GetGlobal_to_Local_Point(iPoint_Global);
784765

785-
if (iPoint_Local > -1) {
766+
if (iPoint_Local > -1) {
786767

787-
/*--- We need to store this point's data, so jump to the correct
788-
offset in the buffer of data from the restart file and load it. ---*/
768+
/*--- We need to store this point's data, so jump to the correct
769+
offset in the buffer of data from the restart file and load it. ---*/
789770

790-
index = counter*Restart_Vars[1] + skipVars;
771+
auto index = counter * Restart_Vars[1] + skipVars;
791772

792-
if (SolutionRestart == nullptr) {
793-
for (iVar = 0; iVar < nVar_Restart; iVar++)
794-
nodes->SetSolution(iPoint_Local, iVar, Restart_Data[index+iVar]);
795-
}
796-
else {
797-
/*--- Used as buffer, allows defaults for nVar > nVar_Restart. ---*/
798-
for (iVar = 0; iVar < nVar_Restart; iVar++)
799-
SolutionRestart[iVar] = Restart_Data[index+iVar];
800-
nodes->SetSolution(iPoint_Local, SolutionRestart);
801-
}
773+
if (SolutionRestart == nullptr) {
774+
for (auto iVar = 0u; iVar < nVar_Restart; iVar++)
775+
nodes->SetSolution(iPoint_Local, iVar, Restart_Data[index+iVar]);
776+
}
777+
else {
778+
/*--- Used as buffer, allows defaults for nVar > nVar_Restart. ---*/
779+
for (auto iVar = 0u; iVar < nVar_Restart; iVar++)
780+
SolutionRestart[iVar] = Restart_Data[index + iVar];
781+
nodes->SetSolution(iPoint_Local, SolutionRestart);
782+
}
802783

803-
/*--- For dynamic meshes, read in and store the
804-
grid coordinates and grid velocities for each node. ---*/
784+
/*--- For dynamic meshes, read in and store the
785+
grid coordinates and grid velocities for each node. ---*/
805786

806-
if (dynamic_grid && update_geo) {
787+
if (dynamic_grid && update_geo) {
807788

808-
/*--- Read in the next 2 or 3 variables which are the grid velocities ---*/
809-
/*--- If we are restarting the solution from a previously computed static calculation (no grid movement) ---*/
810-
/*--- the grid velocities are set to 0. This is useful for FSI computations ---*/
789+
/*--- Read in the next 2 or 3 variables which are the grid velocities ---*/
790+
/*--- If we are restarting the solution from a previously computed static calculation (no grid movement) ---*/
791+
/*--- the grid velocities are set to 0. This is useful for FSI computations ---*/
811792

812-
/*--- Rewind the index to retrieve the Coords. ---*/
813-
index = counter*Restart_Vars[1];
814-
Coord = &Restart_Data[index];
815-
816-
su2double GridVel[MAXNDIM] = {0.0};
817-
if (!steady_restart) {
818-
/*--- Move the index forward to get the grid velocities. ---*/
819-
index += skipVars + nVar_Restart + turbVars;
820-
for (iDim = 0; iDim < nDim; iDim++) { GridVel[iDim] = Restart_Data[index+iDim]; }
821-
}
793+
/*--- Rewind the index to retrieve the Coords. ---*/
794+
index = counter * Restart_Vars[1];
795+
const auto* Coord = &Restart_Data[index];
822796

823-
for (iDim = 0; iDim < nDim; iDim++) {
824-
geometry[MESH_0]->nodes->SetCoord(iPoint_Local, iDim, Coord[iDim]);
825-
geometry[MESH_0]->nodes->SetGridVel(iPoint_Local, iDim, GridVel[iDim]);
797+
su2double GridVel[MAXNDIM] = {0.0};
798+
if (!steady_restart) {
799+
/*--- Move the index forward to get the grid velocities. ---*/
800+
index += skipVars + nVar_Restart + config->GetnTurbVar();
801+
for (auto iDim = 0u; iDim < nDim; iDim++) { GridVel[iDim] = Restart_Data[index+iDim]; }
802+
}
803+
804+
for (auto iDim = 0u; iDim < nDim; iDim++) {
805+
geometry[MESH_0]->nodes->SetCoord(iPoint_Local, iDim, Coord[iDim]);
806+
geometry[MESH_0]->nodes->SetGridVel(iPoint_Local, iDim, GridVel[iDim]);
807+
}
826808
}
827-
}
828809

829-
/*--- For static FSI problems, grid_movement is 0 but we need to read in and store the
830-
grid coordinates for each node (but not the grid velocities, as there are none). ---*/
810+
/*--- For static FSI problems, grid_movement is 0 but we need to read in and store the
811+
grid coordinates for each node (but not the grid velocities, as there are none). ---*/
831812

832-
if (static_fsi && update_geo) {
833-
/*--- Rewind the index to retrieve the Coords. ---*/
834-
index = counter*Restart_Vars[1];
835-
Coord = &Restart_Data[index];
813+
if (static_fsi && update_geo) {
814+
/*--- Rewind the index to retrieve the Coords. ---*/
815+
index = counter*Restart_Vars[1];
816+
const auto* Coord = &Restart_Data[index];
836817

837-
for (iDim = 0; iDim < nDim; iDim++) {
838-
geometry[MESH_0]->nodes->SetCoord(iPoint_Local, iDim, Coord[iDim]);
818+
for (auto iDim = 0u; iDim < nDim; iDim++) {
819+
geometry[MESH_0]->nodes->SetCoord(iPoint_Local, iDim, Coord[iDim]);
820+
}
839821
}
840-
}
841822

842-
/*--- Increment the overall counter for how many points have been loaded. ---*/
843-
counter++;
823+
/*--- Increment the overall counter for how many points have been loaded. ---*/
824+
counter++;
825+
}
844826
}
845827

846-
}
847-
848-
/*--- Detect a wrong solution file ---*/
828+
/*--- Detect a wrong solution file ---*/
849829

850-
if (counter != nPointDomain) {
851-
SU2_MPI::Error(string("The solution file ") + restart_filename + string(" doesn't match with the mesh file!\n") +
852-
string("It could be empty lines at the end of the file."), CURRENT_FUNCTION);
853-
}
830+
if (counter != nPointDomain) {
831+
SU2_MPI::Error(string("The solution file ") + restart_filename + string(" does not match with the mesh file.\n") +
832+
string("This can be caused by empty lines at the end of the file."), CURRENT_FUNCTION);
833+
}
854834
}
855835
END_SU2_OMP_MASTER
856836
SU2_OMP_BARRIER
@@ -862,10 +842,10 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
862842
CGeometry::UpdateGeometry(geometry, config);
863843

864844
if (dynamic_grid) {
865-
for (iMesh = 0; iMesh <= config->GetnMGLevels(); iMesh++) {
845+
for (auto iMesh = 0u; iMesh <= config->GetnMGLevels(); iMesh++) {
866846

867847
/*--- Compute the grid velocities on the coarser levels. ---*/
868-
if (iMesh) geometry[iMesh]->SetRestricted_GridVelocity(geometry[iMesh-1]);
848+
if (iMesh) geometry[iMesh]->SetRestricted_GridVelocity(geometry[iMesh - 1]);
869849
else {
870850
geometry[MESH_0]->InitiateComms(geometry[MESH_0], config, GRID_VELOCITY);
871851
geometry[MESH_0]->CompleteComms(geometry[MESH_0], config, GRID_VELOCITY);
@@ -884,23 +864,26 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
884864

885865
/*--- For turbulent simulations the flow preprocessing is done by the turbulence solver
886866
* after it loads its variables (they are needed to compute flow primitives). ---*/
887-
if (!turbulent) {
867+
if (config->GetKind_Turb_Model() == TURB_MODEL::NONE) {
888868
solver[MESH_0][FLOW_SOL]->Preprocessing(geometry[MESH_0], solver[MESH_0], config, MESH_0, NO_RK_ITER, RUNTIME_FLOW_SYS, false);
889869
}
890870

891871
/*--- Interpolate the solution down to the coarse multigrid levels ---*/
892872

893-
for (iMesh = 1; iMesh <= config->GetnMGLevels(); iMesh++) {
873+
for (auto iMesh = 1u; iMesh <= config->GetnMGLevels(); iMesh++) {
874+
894875
SU2_OMP_FOR_STAT(omp_chunk_size)
895-
for (iPoint = 0; iPoint < geometry[iMesh]->GetnPoint(); iPoint++) {
896-
Area_Parent = geometry[iMesh]->nodes->GetVolume(iPoint);
876+
for (auto iPoint = 0ul; iPoint < geometry[iMesh]->GetnPoint(); iPoint++) {
877+
const su2double Area_Parent = geometry[iMesh]->nodes->GetVolume(iPoint);
897878
su2double Solution_Coarse[MAXNVAR] = {0.0};
898-
for (iChildren = 0; iChildren < geometry[iMesh]->nodes->GetnChildren_CV(iPoint); iChildren++) {
899-
Point_Fine = geometry[iMesh]->nodes->GetChildren_CV(iPoint, iChildren);
900-
Area_Children = geometry[iMesh-1]->nodes->GetVolume(Point_Fine);
901-
Solution_Fine = solver[iMesh-1][FLOW_SOL]->GetNodes()->GetSolution(Point_Fine);
902-
for (iVar = 0; iVar < nVar; iVar++) {
903-
Solution_Coarse[iVar] += Solution_Fine[iVar]*Area_Children/Area_Parent;
879+
880+
for (auto iChildren = 0ul; iChildren < geometry[iMesh]->nodes->GetnChildren_CV(iPoint); iChildren++) {
881+
const auto Point_Fine = geometry[iMesh]->nodes->GetChildren_CV(iPoint, iChildren);
882+
const su2double Area_Children = geometry[iMesh - 1]->nodes->GetVolume(Point_Fine);
883+
const su2double* Solution_Fine = solver[iMesh - 1][FLOW_SOL]->GetNodes()->GetSolution(Point_Fine);
884+
885+
for (auto iVar = 0u; iVar < nVar; iVar++) {
886+
Solution_Coarse[iVar] += Solution_Fine[iVar] * Area_Children / Area_Parent;
904887
}
905888
}
906889
solver[iMesh][FLOW_SOL]->GetNodes()->SetSolution(iPoint,Solution_Coarse);
@@ -910,12 +893,14 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
910893
solver[iMesh][FLOW_SOL]->InitiateComms(geometry[iMesh], config, SOLUTION);
911894
solver[iMesh][FLOW_SOL]->CompleteComms(geometry[iMesh], config, SOLUTION);
912895

913-
if (!turbulent) {
896+
if (config->GetKind_Turb_Model() == TURB_MODEL::NONE) {
914897
solver[iMesh][FLOW_SOL]->Preprocessing(geometry[iMesh], solver[iMesh], config, iMesh, NO_RK_ITER, RUNTIME_FLOW_SYS, false);
915898
}
916899
}
917900

918901
/*--- Update the old geometry (coordinates n and n-1) in dual time-stepping strategy. ---*/
902+
const bool dual_time = ((config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_1ST) ||
903+
(config->GetTime_Marching() == TIME_MARCHING::DT_STEPPING_2ND));
919904
if (dual_time && config->GetGrid_Movement() && !config->GetDeform_Mesh() &&
920905
(config->GetKind_GridMovement() != RIGID_MOTION)) {
921906
Restart_OldGeometry(geometry[MESH_0], config);
@@ -926,13 +911,13 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
926911
{
927912
/*--- Delete the class memory that is used to load the restart. ---*/
928913

929-
delete [] Restart_Vars; Restart_Vars = nullptr;
930-
delete [] Restart_Data; Restart_Data = nullptr;
931-
914+
delete [] Restart_Vars;
915+
Restart_Vars = nullptr;
916+
delete [] Restart_Data;
917+
Restart_Data = nullptr;
932918
}
933919
END_SU2_OMP_MASTER
934920
SU2_OMP_BARRIER
935-
936921
}
937922

938923
template <class V, ENUM_REGIME R>

0 commit comments

Comments
 (0)