@@ -45,78 +45,66 @@ void CDiscAdjHeatIteration::Preprocess(COutput* output, CIntegration**** integra
4545 if (config[val_iZone]->GetTime_Marching () != TIME_MARCHING::STEADY) {
4646 const int Direct_Iter = static_cast <int >(config[val_iZone]->GetUnst_AdjointIter ()) - static_cast <int >(TimeIter) - 2 + dual_time;
4747
48- /* --- For dual-time stepping we want to load the already converged solution at timestep n ---*/
48+ /* --- For dual-time stepping we want to load the already converged solution at previous timesteps.
49+ * In general we only load one file and shift the previously loaded solutions, on the first we
50+ * load one or two more (depending on dual time order). ---*/
4951
50- if (TimeIter == 0 ) {
51- if (dual_time_2nd) {
52- /* --- Load solution at timestep n-2 ---*/
53-
54- LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter - 2 );
55-
56- /* --- Push solution back to correct array ---*/
52+ if (dual_time_2nd) {
53+ LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter - 2 );
54+ } else if (dual_time_1st) {
55+ LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter - 1 );
56+ }
5757
58+ if (TimeIter == 0 ) {
59+ /* --- Push solution back one or two levels, ---*/
60+ if (dual_time) {
5861 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
5962 solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n ();
60- solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n1 ();
63+ if (dual_time_2nd) solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n1 ();
6164 }
6265 }
63- if (dual_time) {
64- /* --- Load solution at timestep n-1 ---*/
6566
67+ /* --- If required load another time step. ---*/
68+ if (dual_time_2nd) {
6669 LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter - 1 );
6770
68- /* --- Push solution back to correct array ---*/
69-
7071 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
7172 solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n ();
7273 }
7374 }
7475
75- /* --- Load solution timestep n ---*/
76-
76+ /* --- Load current solution. ---*/
7777 LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter);
7878 }
7979 if ((TimeIter > 0 ) && dual_time) {
80- /* --- Load solution timestep n - 2 ---*/
81-
82- LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter - 2 );
83-
8480 /* --- Temporarily store the loaded solution in the Solution_Old array ---*/
85-
8681 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++)
8782 solvers[iMesh][HEAT_SOL]->Set_OldSolution ();
8883
89- /* --- Set Solution at timestep n to solution at n-1 ---*/
90-
84+ /* --- Move timestep n to current solution. ---*/
9185 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
9286 for (auto iPoint = 0ul ; iPoint < geometry[val_iZone][val_iInst][iMesh]->GetnPoint (); iPoint++) {
9387 solvers[iMesh][HEAT_SOL]->GetNodes ()->SetSolution (
9488 iPoint, solvers[iMesh][HEAT_SOL]->GetNodes ()->GetSolution_time_n (iPoint));
9589 }
9690 }
97- if (dual_time_1st) {
98- /* --- Set Solution at timestep n-1 to the previously loaded solution ---*/
99- for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
100- for (auto iPoint = 0ul ; iPoint < geometry[val_iZone][val_iInst][iMesh]->GetnPoint (); iPoint++) {
101- solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n (
102- iPoint, solvers[iMesh][HEAT_SOL]->GetNodes ()->GetSolution_time_n1 (iPoint));
103- }
104- }
105- }
91+
92+ /* --- If required also move timestep n-1 to timestep n. ---*/
10693 if (dual_time_2nd) {
107- /* --- Set Solution at timestep n-1 to solution at n-2 ---*/
10894 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
10995 for (auto iPoint = 0ul ; iPoint < geometry[val_iZone][val_iInst][iMesh]->GetnPoint (); iPoint++) {
11096 solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n (
11197 iPoint, solvers[iMesh][HEAT_SOL]->GetNodes ()->GetSolution_time_n1 (iPoint));
11298 }
11399 }
114- /* --- Set Solution at timestep n-2 to the previously loaded solution ---*/
115- for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
116- for (auto iPoint = 0ul ; iPoint < geometry[val_iZone][val_iInst][iMesh]->GetnPoint (); iPoint++) {
117- solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n1 (
118- iPoint, solvers[iMesh][HEAT_SOL]->GetNodes ()->GetSolution_Old (iPoint));
119- }
100+ }
101+
102+ /* --- Finally, place the loaded solution in the correct place (n or n-1 depending on order). ---*/
103+ for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
104+ for (auto iPoint = 0ul ; iPoint < geometry[val_iZone][val_iInst][iMesh]->GetnPoint (); iPoint++) {
105+ const auto sol = solvers[iMesh][HEAT_SOL]->GetNodes ()->GetSolution_Old (iPoint);
106+ if (dual_time_2nd) solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n1 (iPoint, sol);
107+ else solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n (iPoint, sol);
120108 }
121109 }
122110 }
@@ -140,23 +128,23 @@ void CDiscAdjHeatIteration::Preprocess(COutput* output, CIntegration**** integra
140128void CDiscAdjHeatIteration::LoadUnsteady_Solution (CGeometry**** geometry, CSolver***** solver, CConfig** config,
141129 unsigned short val_iZone, unsigned short val_iInst,
142130 int val_DirectIter) {
131+ auto solvers = solver[val_iZone][val_iInst];
132+ auto geometries = geometry[val_iZone][val_iInst];
143133
144134 if (val_DirectIter >= 0 ) {
145135 if (rank == MASTER_NODE)
146136 cout << " Loading heat solution from direct iteration " << val_DirectIter << " for zone " << val_iZone << " ." << endl;
147137
148- solver[val_iZone][val_iInst][MESH_0][HEAT_SOL]->LoadRestart (
149- geometry[val_iZone][val_iInst], solver[val_iZone][val_iInst], config[val_iZone], val_DirectIter, false );
138+ solvers[MESH_0][HEAT_SOL]->LoadRestart (geometries, solvers, config[val_iZone], val_DirectIter, false );
150139 }
151140 else {
152141 /* --- If there is no solution file we set the freestream condition ---*/
153142 if (rank == MASTER_NODE)
154143 cout << " Setting freestream conditions at direct iteration " << val_DirectIter << " for zone " << val_iZone << " ." << endl;
155144
156145 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
157- solver[val_iZone][val_iInst][iMesh][HEAT_SOL]->SetFreeStream_Solution (config[val_iZone]);
158- solver[val_iZone][val_iInst][iMesh][HEAT_SOL]->Postprocessing (
159- geometry[val_iZone][val_iInst][iMesh], solver[val_iZone][val_iInst][iMesh], config[val_iZone], iMesh);
146+ solvers[iMesh][HEAT_SOL]->SetFreeStream_Solution (config[val_iZone]);
147+ solvers[iMesh][HEAT_SOL]->Postprocessing (geometries[iMesh], solvers[iMesh], config[val_iZone], iMesh);
160148 }
161149 }
162150}
@@ -177,26 +165,28 @@ void CDiscAdjHeatIteration::InitializeAdjoint(CSolver***** solver, CGeometry****
177165
178166void CDiscAdjHeatIteration::RegisterInput (CSolver***** solver, CGeometry**** geometry, CConfig** config,
179167 unsigned short iZone, unsigned short iInst, RECORDING kind_recording) {
168+ auto solvers0 = solver[iZone][iInst][MESH_0];
169+ auto geometry0 = geometry[iZone][iInst][MESH_0];
180170
181171 if (kind_recording == RECORDING::SOLUTION_VARIABLES || kind_recording == RECORDING::SOLUTION_AND_MESH) {
182172 /* --- Register flow and turbulent variables as input ---*/
183173
184- solver[iZone][iInst][MESH_0][ ADJHEAT_SOL]->RegisterSolution (geometry[iZone][iInst][MESH_0] , config[iZone]);
174+ solvers0[ ADJHEAT_SOL]->RegisterSolution (geometry0 , config[iZone]);
185175
186- solver[iZone][iInst][MESH_0][ ADJHEAT_SOL]->RegisterVariables (geometry[iZone][iInst][MESH_0] , config[iZone]);
176+ solvers0[ ADJHEAT_SOL]->RegisterVariables (geometry0 , config[iZone]);
187177 }
188178 else if (kind_recording == RECORDING::MESH_COORDS) {
189179 /* --- Register node coordinates as input ---*/
190180
191- geometry[iZone][iInst][MESH_0] ->RegisterCoordinates ();
181+ geometry0 ->RegisterCoordinates ();
192182 }
193183 else if (kind_recording == RECORDING::MESH_DEFORM) {
194184 /* --- Register the variables of the mesh deformation ---*/
195185 /* --- Undeformed mesh coordinates ---*/
196- solver[iZone][iInst][MESH_0][ ADJMESH_SOL]->RegisterSolution (geometry[iZone][iInst][MESH_0] , config[iZone]);
186+ solvers0[ ADJMESH_SOL]->RegisterSolution (geometry0 , config[iZone]);
197187
198188 /* --- Boundary displacements ---*/
199- solver[iZone][iInst][MESH_0][ ADJMESH_SOL]->RegisterVariables (geometry[iZone][iInst][MESH_0] , config[iZone]);
189+ solvers0[ ADJMESH_SOL]->RegisterVariables (geometry0 , config[iZone]);
200190 }
201191}
202192
0 commit comments