@@ -856,6 +856,47 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
856856 }
857857 }
858858
859+ /* --- Check for missing fields and prepare field-based lookup ---*/
860+ const bool incompressible = (config->GetKind_Regime () == ENUM_REGIME::INCOMPRESSIBLE);
861+ const bool energy = config->GetEnergy_Equation ();
862+ const bool weakly_coupled_heat = config->GetWeakly_Coupled_Heat ();
863+ const bool flamelet = (config->GetKind_FluidModel () == FLUID_FLAMELET);
864+
865+ /* --- Find field indices for solution variables ---*/
866+ int fieldIdx_Pressure = -1 , fieldIdx_Temperature = -1 ;
867+ int fieldIdx_Velocity[MAXNDIM] = {-1 , -1 , -1 };
868+ int fieldIdx_Density = -1 , fieldIdx_Energy = -1 ;
869+ int fieldIdx_Momentum[MAXNDIM] = {-1 , -1 , -1 };
870+
871+ if (incompressible) {
872+ fieldIdx_Pressure = FindFieldIndex (" Pressure" );
873+ for (auto iDim = 0u ; iDim < nDim; iDim++) {
874+ string velName = " Velocity_" + string (iDim == 0 ? " x" : (iDim == 1 ? " y" : " z" ));
875+ fieldIdx_Velocity[iDim] = FindFieldIndex (velName);
876+ }
877+ if (energy || weakly_coupled_heat || flamelet) {
878+ fieldIdx_Temperature = FindFieldIndex (" Temperature" );
879+ }
880+ } else {
881+ /* --- Compressible flow ---*/
882+ fieldIdx_Density = FindFieldIndex (" Density" );
883+ for (auto iDim = 0u ; iDim < nDim; iDim++) {
884+ string momName = " Momentum_" + string (iDim == 0 ? " x" : (iDim == 1 ? " y" : " z" ));
885+ fieldIdx_Momentum[iDim] = FindFieldIndex (momName);
886+ }
887+ fieldIdx_Energy = FindFieldIndex (" Energy" );
888+ }
889+
890+ /* --- Warn about missing fields and prepare defaults ---*/
891+ su2double default_Temperature = 0.0 ;
892+ if (incompressible && (energy || weakly_coupled_heat || flamelet) && fieldIdx_Temperature < 0 ) {
893+ if (rank == MASTER_NODE) {
894+ cout << " \n WARNING: The restart file does not contain Temperature field." << endl;
895+ cout << " Temperature will be initialized from config (INC_TEMPERATURE_INIT)." << endl;
896+ }
897+ default_Temperature = config->GetInc_Temperature_Init () / config->GetInc_Temperature_Ref ();
898+ }
899+
859900 /* --- Load data from the restart into correct containers. ---*/
860901
861902 unsigned long counter = 0 ;
@@ -868,19 +909,103 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
868909
869910 if (iPoint_Local > -1 ) {
870911
871- /* --- We need to store this point's data, so jump to the correct
872- offset in the buffer of data from the restart file and load it. ---*/
873-
874- auto index = counter * Restart_Vars[1 ] + skipVars;
875-
876- if (SolutionRestart == nullptr ) {
877- for (auto iVar = 0u ; iVar < nVar_Restart; iVar++)
878- nodes->SetSolution (iPoint_Local, iVar, Restart_Data[index+iVar]);
912+ /* --- Base index for this point in the restart data ---*/
913+ auto baseIndex = counter * Restart_Vars[1 ];
914+
915+ /* --- Initialize solution buffer with defaults ---*/
916+ su2double solutionBuffer[MAXNVAR] = {0.0 };
917+
918+ /* --- Load solution variables using field-based lookup ---*/
919+ if (incompressible) {
920+ /* --- Incompressible flow: Pressure, Velocity_x, Velocity_y, [Velocity_z], [Temperature] ---*/
921+
922+ /* --- Load Pressure (index 0) ---*/
923+ if (fieldIdx_Pressure >= 0 ) {
924+ solutionBuffer[0 ] = Restart_Data[baseIndex + fieldIdx_Pressure];
925+ } else {
926+ /* --- Use default from config ---*/
927+ solutionBuffer[0 ] = config->GetPressure_FreeStreamND ();
928+ if (rank == MASTER_NODE && counter == 0 ) {
929+ cout << " WARNING: Pressure field not found in restart file, using config default." << endl;
930+ }
931+ }
932+
933+ /* --- Load Velocity components (indices 1..nDim) ---*/
934+ const su2double* Velocity_Inf = config->GetVelocity_FreeStreamND ();
935+ for (auto iDim = 0u ; iDim < nDim; iDim++) {
936+ if (fieldIdx_Velocity[iDim] >= 0 ) {
937+ solutionBuffer[iDim + 1 ] = Restart_Data[baseIndex + fieldIdx_Velocity[iDim]];
938+ } else {
939+ /* --- Use default from config ---*/
940+ solutionBuffer[iDim + 1 ] = Velocity_Inf[iDim];
941+ if (rank == MASTER_NODE && counter == 0 ) {
942+ cout << " WARNING: Velocity_" << (iDim == 0 ? " x" : (iDim == 1 ? " y" : " z" ))
943+ << " field not found in restart file, using config default." << endl;
944+ }
945+ }
946+ }
947+
948+ /* --- Load Temperature (index nDim+1) if energy equation is enabled ---*/
949+ if (energy || weakly_coupled_heat || flamelet) {
950+ if (fieldIdx_Temperature >= 0 ) {
951+ solutionBuffer[nDim + 1 ] = Restart_Data[baseIndex + fieldIdx_Temperature];
952+ } else {
953+ /* --- Use default from config ---*/
954+ solutionBuffer[nDim + 1 ] = default_Temperature;
955+ }
956+ }
957+ } else {
958+ /* --- Compressible flow: Density, Momentum_x, Momentum_y, [Momentum_z], Energy ---*/
959+
960+ /* --- Load Density (index 0) ---*/
961+ if (fieldIdx_Density >= 0 ) {
962+ solutionBuffer[0 ] = Restart_Data[baseIndex + fieldIdx_Density];
963+ } else {
964+ solutionBuffer[0 ] = config->GetDensity_FreeStreamND ();
965+ if (rank == MASTER_NODE && counter == 0 ) {
966+ cout << " WARNING: Density field not found in restart file, using config default." << endl;
967+ }
968+ }
969+
970+ /* --- Load Momentum components (indices 1..nDim) ---*/
971+ const su2double* Velocity_Inf_Comp = config->GetVelocity_FreeStreamND ();
972+ for (auto iDim = 0u ; iDim < nDim; iDim++) {
973+ if (fieldIdx_Momentum[iDim] >= 0 ) {
974+ solutionBuffer[iDim + 1 ] = Restart_Data[baseIndex + fieldIdx_Momentum[iDim]];
975+ } else {
976+ /* --- Compute from density and velocity defaults ---*/
977+ solutionBuffer[iDim + 1 ] = config->GetDensity_FreeStreamND () * Velocity_Inf_Comp[iDim];
978+ if (rank == MASTER_NODE && counter == 0 ) {
979+ cout << " WARNING: Momentum_" << (iDim == 0 ? " x" : (iDim == 1 ? " y" : " z" ))
980+ << " field not found in restart file, using config default." << endl;
981+ }
982+ }
983+ }
984+
985+ /* --- Load Energy (index nDim+1) ---*/
986+ if (fieldIdx_Energy >= 0 ) {
987+ solutionBuffer[nDim + 1 ] = Restart_Data[baseIndex + fieldIdx_Energy];
988+ } else {
989+ /* --- Compute from config defaults ---*/
990+ su2double vel2 = 0.0 ;
991+ for (auto iDim = 0u ; iDim < nDim; iDim++) {
992+ su2double vel = Velocity_Inf_Comp[iDim];
993+ vel2 += vel * vel;
994+ }
995+ solutionBuffer[nDim + 1 ] = config->GetEnergy_FreeStreamND ();
996+ if (rank == MASTER_NODE && counter == 0 ) {
997+ cout << " WARNING: Energy field not found in restart file, using config default." << endl;
998+ }
999+ }
8791000 }
880- else {
881- /* --- Used as buffer, allows defaults for nVar > nVar_Restart. ---*/
882- for (auto iVar = 0u ; iVar < nVar_Restart; iVar++)
883- SolutionRestart[iVar] = Restart_Data[index + iVar];
1001+
1002+ /* --- Set solution from buffer ---*/
1003+ if (SolutionRestart == nullptr ) {
1004+ for (auto iVar = 0u ; iVar < nVar; iVar++)
1005+ nodes->SetSolution (iPoint_Local, iVar, solutionBuffer[iVar]);
1006+ } else {
1007+ for (auto iVar = 0u ; iVar < nVar; iVar++)
1008+ SolutionRestart[iVar] = solutionBuffer[iVar];
8841009 nodes->SetSolution (iPoint_Local, SolutionRestart);
8851010 }
8861011
@@ -894,14 +1019,22 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
8941019 /* --- the grid velocities are set to 0. This is useful for FSI computations ---*/
8951020
8961021 /* --- Rewind the index to retrieve the Coords. ---*/
897- index = counter * Restart_Vars[ 1 ] ;
1022+ auto index = baseIndex ;
8981023 const auto * Coord = &Restart_Data[index];
8991024
9001025 su2double GridVel[MAXNDIM] = {0.0 };
9011026 if (!steady_restart) {
902- /* --- Move the index forward to get the grid velocities. ---*/
903- index += skipVars + nVar_Restart + config->GetnTurbVar ();
904- for (auto iDim = 0u ; iDim < nDim; iDim++) { GridVel[iDim] = Restart_Data[index+iDim]; }
1027+ /* --- Load grid velocities using field-based lookup ---*/
1028+ int fieldIdx_GridVel[MAXNDIM] = {-1 , -1 , -1 };
1029+ for (auto iDim = 0u ; iDim < nDim; iDim++) {
1030+ string gridVelName = " Grid_Velocity_" + string (iDim == 0 ? " x" : (iDim == 1 ? " y" : " z" ));
1031+ fieldIdx_GridVel[iDim] = FindFieldIndex (gridVelName);
1032+ if (fieldIdx_GridVel[iDim] >= 0 ) {
1033+ GridVel[iDim] = Restart_Data[baseIndex + fieldIdx_GridVel[iDim]];
1034+ } else {
1035+ GridVel[iDim] = 0.0 ; /* --- Default to zero if not found ---*/
1036+ }
1037+ }
9051038 }
9061039
9071040 for (auto iDim = 0u ; iDim < nDim; iDim++) {
@@ -915,7 +1048,7 @@ void CFVMFlowSolverBase<V, R>::LoadRestart_impl(CGeometry **geometry, CSolver **
9151048
9161049 if (static_fsi && update_geo) {
9171050 /* --- Rewind the index to retrieve the Coords. ---*/
918- index = counter*Restart_Vars[ 1 ] ;
1051+ auto index = baseIndex ;
9191052 const auto * Coord = &Restart_Data[index];
9201053
9211054 for (auto iDim = 0u ; iDim < nDim; iDim++) {
0 commit comments