@@ -43,79 +43,64 @@ void CDiscAdjHeatIteration::Preprocess(COutput* output, CIntegration**** integra
4343 /* --- For the unsteady adjoint, load direct solutions from restart files. ---*/
4444
4545 if (config[val_iZone]->GetTime_Marching () != TIME_MARCHING::STEADY) {
46- const int Direct_Iter = static_cast <int >(config[val_iZone]->GetUnst_AdjointIter ()) - static_cast <int >(TimeIter) - 2 + dual_time;
46+ const int Direct_Iter = static_cast <int >(config[val_iZone]->GetUnst_AdjointIter ()) -
47+ static_cast <int >(TimeIter) - 2 + dual_time;
4748
48- /* --- For dual-time stepping we want to load the already converged solution at timestep n ---*/
49+ /* --- For dual-time stepping we want to load the already converged solution at previous timesteps.
50+ * In general we only load one file and shift the previously loaded solutions, on the first we
51+ * load one or two more (depending on dual time order). ---*/
4952
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 ---*/
53+ if (dual_time_2nd) {
54+ LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter - 2 );
55+ } else if (dual_time_1st) {
56+ LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter - 1 );
57+ }
5758
59+ if (TimeIter == 0 ) {
60+ /* --- Push solution back one level. ---*/
61+ if (dual_time) {
5862 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
5963 solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n ();
60- 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. Push the previous time step to n-1 and the
68+ loaded time step to n. ---*/
69+ if (dual_time_2nd) {
6670 LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter - 1 );
6771
68- /* --- Push solution back to correct array ---*/
69-
7072 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
73+ solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n1 ();
7174 solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n ();
7275 }
7376 }
7477
75- /* --- Load solution timestep n ---*/
76-
78+ /* --- Load current solution. ---*/
7779 LoadUnsteady_Solution (geometry, solver, config, val_iZone, val_iInst, Direct_Iter);
7880 }
7981 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-
8482 /* --- Temporarily store the loaded solution in the Solution_Old array ---*/
85-
8683 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++)
8784 solvers[iMesh][HEAT_SOL]->Set_OldSolution ();
8885
89- /* --- Set Solution at timestep n to solution at n-1 ---*/
90-
86+ /* --- Move timestep n to current solution. ---*/
9187 for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
9288 for (auto iPoint = 0ul ; iPoint < geometry[val_iZone][val_iInst][iMesh]->GetnPoint (); iPoint++) {
9389 solvers[iMesh][HEAT_SOL]->GetNodes ()->SetSolution (
9490 iPoint, solvers[iMesh][HEAT_SOL]->GetNodes ()->GetSolution_time_n (iPoint));
9591 }
9692 }
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- }
106- if (dual_time_2nd) {
107- /* --- Set Solution at timestep n-1 to solution at n-2 ---*/
108- for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
109- for (auto iPoint = 0ul ; iPoint < geometry[val_iZone][val_iInst][iMesh]->GetnPoint (); iPoint++) {
110- solvers[iMesh][HEAT_SOL]->GetNodes ()->Set_Solution_time_n (
111- iPoint, solvers[iMesh][HEAT_SOL]->GetNodes ()->GetSolution_time_n1 (iPoint));
112- }
113- }
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));
93+
94+ /* --- Finally, place the loaded solution in the correct place (n or n-1 depending on order). ---*/
95+ for (auto iMesh = 0u ; iMesh <= config[val_iZone]->GetnMGLevels (); iMesh++) {
96+ auto * heatSol = solvers[iMesh][HEAT_SOL];
97+ for (auto iPoint = 0ul ; iPoint < geometry[val_iZone][val_iInst][iMesh]->GetnPoint (); iPoint++) {
98+ if (dual_time_2nd) {
99+ /* --- If required also move timestep n-1 to timestep n. ---*/
100+ heatSol->GetNodes ()->Set_Solution_time_n (iPoint, heatSol->GetNodes ()->GetSolution_time_n1 (iPoint));
101+ heatSol->GetNodes ()->Set_Solution_time_n1 (iPoint, heatSol->GetNodes ()->GetSolution_Old (iPoint));
102+ } else {
103+ heatSol->GetNodes ()->Set_Solution_time_n (iPoint, heatSol->GetNodes ()->GetSolution_Old (iPoint));
119104 }
120105 }
121106 }
@@ -140,23 +125,23 @@ void CDiscAdjHeatIteration::Preprocess(COutput* output, CIntegration**** integra
140125void CDiscAdjHeatIteration::LoadUnsteady_Solution (CGeometry**** geometry, CSolver***** solver, CConfig** config,
141126 unsigned short val_iZone, unsigned short val_iInst,
142127 int val_DirectIter) {
128+ auto solvers = solver[val_iZone][val_iInst];
129+ auto geometries = geometry[val_iZone][val_iInst];
143130
144131 if (val_DirectIter >= 0 ) {
145132 if (rank == MASTER_NODE)
146133 cout << " Loading heat solution from direct iteration " << val_DirectIter << " for zone " << val_iZone << " ." << endl;
147134
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 );
135+ solvers[MESH_0][HEAT_SOL]->LoadRestart (geometries, solvers, config[val_iZone], val_DirectIter, false );
150136 }
151137 else {
152138 /* --- If there is no solution file we set the freestream condition ---*/
153139 if (rank == MASTER_NODE)
154140 cout << " Setting freestream conditions at direct iteration " << val_DirectIter << " for zone " << val_iZone << " ." << endl;
155141
156142 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);
143+ solvers[iMesh][HEAT_SOL]->SetFreeStream_Solution (config[val_iZone]);
144+ solvers[iMesh][HEAT_SOL]->Postprocessing (geometries[iMesh], solvers[iMesh], config[val_iZone], iMesh);
160145 }
161146 }
162147}
@@ -177,26 +162,28 @@ void CDiscAdjHeatIteration::InitializeAdjoint(CSolver***** solver, CGeometry****
177162
178163void CDiscAdjHeatIteration::RegisterInput (CSolver***** solver, CGeometry**** geometry, CConfig** config,
179164 unsigned short iZone, unsigned short iInst, RECORDING kind_recording) {
165+ auto solvers0 = solver[iZone][iInst][MESH_0];
166+ auto geometry0 = geometry[iZone][iInst][MESH_0];
180167
181168 if (kind_recording == RECORDING::SOLUTION_VARIABLES || kind_recording == RECORDING::SOLUTION_AND_MESH) {
182169 /* --- Register flow and turbulent variables as input ---*/
183170
184- solver[iZone][iInst][MESH_0][ ADJHEAT_SOL]->RegisterSolution (geometry[iZone][iInst][MESH_0] , config[iZone]);
171+ solvers0[ ADJHEAT_SOL]->RegisterSolution (geometry0 , config[iZone]);
185172
186- solver[iZone][iInst][MESH_0][ ADJHEAT_SOL]->RegisterVariables (geometry[iZone][iInst][MESH_0] , config[iZone]);
173+ solvers0[ ADJHEAT_SOL]->RegisterVariables (geometry0 , config[iZone]);
187174 }
188175 else if (kind_recording == RECORDING::MESH_COORDS) {
189176 /* --- Register node coordinates as input ---*/
190177
191- geometry[iZone][iInst][MESH_0] ->RegisterCoordinates ();
178+ geometry0 ->RegisterCoordinates ();
192179 }
193180 else if (kind_recording == RECORDING::MESH_DEFORM) {
194181 /* --- Register the variables of the mesh deformation ---*/
195182 /* --- Undeformed mesh coordinates ---*/
196- solver[iZone][iInst][MESH_0][ ADJMESH_SOL]->RegisterSolution (geometry[iZone][iInst][MESH_0] , config[iZone]);
183+ solvers0[ ADJMESH_SOL]->RegisterSolution (geometry0 , config[iZone]);
197184
198185 /* --- Boundary displacements ---*/
199- solver[iZone][iInst][MESH_0][ ADJMESH_SOL]->RegisterVariables (geometry[iZone][iInst][MESH_0] , config[iZone]);
186+ solvers0[ ADJMESH_SOL]->RegisterVariables (geometry0 , config[iZone]);
200187 }
201188}
202189
0 commit comments