3232
3333CDiscAdjFEAIteration::CDiscAdjFEAIteration (const CConfig *config) : CIteration(config), CurrentRecording(NONE) {
3434 fem_iteration = new CFEAIteration (config);
35-
36- // TEMPORARY output only for standalone structural problems
37- if (config->GetAdvanced_FEAElementBased () && (rank == MASTER_NODE)) {
38- bool de_effects = config->GetDE_Effects ();
39- unsigned short iVar;
40-
41- /* --- Header of the temporary output file ---*/
42- ofstream myfile_res;
43- myfile_res.open (" Results_Reverse_Adjoint.txt" );
44-
45- myfile_res << " Obj_Func"
46- << " " ;
47- for (iVar = 0 ; iVar < config->GetnElasticityMod (); iVar++) myfile_res << " Sens_E_" << iVar << " \t " ;
48-
49- for (iVar = 0 ; iVar < config->GetnPoissonRatio (); iVar++) myfile_res << " Sens_Nu_" << iVar << " \t " ;
50-
51- if (config->GetTime_Domain ()) {
52- for (iVar = 0 ; iVar < config->GetnMaterialDensity (); iVar++) myfile_res << " Sens_Rho_" << iVar << " \t " ;
53- }
54-
55- if (de_effects) {
56- for (iVar = 0 ; iVar < config->GetnElectric_Field (); iVar++) myfile_res << " Sens_EField_" << iVar << " \t " ;
57- }
58-
59- myfile_res << " \n " ;
60- }
6135}
6236
6337CDiscAdjFEAIteration::~CDiscAdjFEAIteration () = default ;
@@ -71,31 +45,49 @@ void CDiscAdjFEAIteration::Preprocess(COutput* output, CIntegration**** integrat
7145 auto dirNodes = solvers0[FEA_SOL]->GetNodes ();
7246 auto adjNodes = solvers0[ADJFEA_SOL]->GetNodes ();
7347
74- /* --- For the dynamic adjoint, load direct solutions from restart files. ---*/
48+ auto StoreDirectSolution = [&]() {
49+ for (auto iPoint = 0ul ; iPoint < geometry0->GetnPoint (); iPoint++) {
50+ adjNodes->SetSolution_Direct (iPoint, dirNodes->GetSolution (iPoint));
51+ }
52+ };
53+
54+ /* --- For the dynamic adjoint, load direct solutions from restart files.
55+ * For steady, store the direct solution to be able to reset it later. ---*/
7556
7657 if (config[iZone]->GetTime_Domain ()) {
7758 const int TimeIter = config[iZone]->GetTimeIter ();
7859 const int Direct_Iter = SU2_TYPE::Int (config[iZone]->GetUnst_AdjointIter ()) - TimeIter - 1 ;
7960
80- /* --- We want to load the already converged solution at timesteps n and n-1 ---*/
81-
82- /* --- Load solution at timestep n-1 ---*/
61+ /* --- We need the already converged solution at timesteps n and n-1. On the first
62+ * adjoint time step we load both, then n-1 becomes "n" and we only load n-2. ---*/
8363
84- LoadDynamic_Solution (geometry, solver, config, iZone, iInst, Direct_Iter - 1 );
64+ if (TimeIter > 0 ) {
65+ /* --- Save n-1 to become n. ---*/
66+ for (auto iPoint = 0ul ; iPoint < geometry0->GetnPoint (); iPoint++) {
67+ adjNodes->SetSolution_Direct (iPoint, dirNodes->GetSolution_time_n (iPoint));
68+ }
69+ }
8570
86- /* --- Push solution back to correct array ---*/
71+ /* --- Load solution at timestep n-1 and push back to correct array. ---*/
8772
73+ LoadDynamic_Solution (geometry, solver, config, iZone, iInst, Direct_Iter - 1 );
8874 dirNodes->Set_Solution_time_n ();
8975
90- /* --- Load solution timestep n ---*/
76+ /* --- Load or set solution at timestep n. ---*/
9177
92- LoadDynamic_Solution (geometry, solver, config, iZone, iInst, Direct_Iter);
93- }
94-
95- /* --- Store FEA solution also in the adjoint solver in order to be able to reset it later. ---*/
78+ if (TimeIter == 0 ) {
79+ LoadDynamic_Solution (geometry, solver, config, iZone, iInst, Direct_Iter);
80+ StoreDirectSolution ();
81+ } else {
82+ /* --- Set n-1 as n. ---*/
83+ for (auto iPoint = 0ul ; iPoint < geometry0->GetnPoint (); iPoint++)
84+ for (auto iVar = 0u ; iVar < solvers0[ADJFEA_SOL]->GetnVar (); iVar++)
85+ dirNodes->SetSolution (iPoint, iVar, adjNodes->GetSolution_Direct (iPoint)[iVar]);
86+ }
9687
97- for (auto iPoint = 0ul ; iPoint < geometry0->GetnPoint (); iPoint++) {
98- adjNodes->SetSolution_Direct (iPoint, dirNodes->GetSolution (iPoint));
88+ } else {
89+ /* --- Steady. ---*/
90+ StoreDirectSolution ();
9991 }
10092
10193 solvers0[ADJFEA_SOL]->Preprocessing (geometry0, solvers0, config[iZone], MESH_0, 0 , RUNTIME_ADJFEA_SYS, false );
@@ -178,7 +170,7 @@ void CDiscAdjFEAIteration::SetDependencies(CSolver***** solver, CGeometry**** ge
178170 const int mat_knowles = MAT_KNOWLES+offset;
179171 const int de_term = DE_TERM+offset;
180172
181- for (unsigned short iProp = 0 ; iProp < config[iZone]->GetnElasticityMod (); iProp++) {
173+ for (unsigned short iProp = 0 ; iProp < config[iZone]->GetnElasticityMat (); iProp++) {
182174 su2double E = adj_solver->GetVal_Young (iProp);
183175 su2double nu = adj_solver->GetVal_Poisson (iProp);
184176 su2double rho = adj_solver->GetVal_Rho (iProp);
@@ -302,45 +294,8 @@ void CDiscAdjFEAIteration::Postprocess(COutput* output, CIntegration**** integra
302294 CSolver***** solver, CNumerics****** numerics, CConfig** config,
303295 CSurfaceMovement** surface_movement, CVolumetricMovement*** grid_movement,
304296 CFreeFormDefBox*** FFDBox, unsigned short iZone, unsigned short iInst) {
305- const bool dynamic = (config[iZone]->GetTime_Domain ());
306297 auto solvers0 = solver[iZone][iInst][MESH_0];
307298
308- // TEMPORARY output only for standalone structural problems
309- if (config[iZone]->GetAdvanced_FEAElementBased () && (rank == MASTER_NODE)) {
310- unsigned short iVar;
311-
312- const bool de_effects = config[iZone]->GetDE_Effects ();
313-
314- /* --- Header of the temporary output file ---*/
315- ofstream myfile_res;
316- myfile_res.open (" Results_Reverse_Adjoint.txt" , ios::app);
317-
318- myfile_res.precision (15 );
319-
320- myfile_res << config[iZone]->GetTimeIter () << " \t " ;
321-
322- solvers0[FEA_SOL]->Evaluate_ObjFunc (config[iZone], solvers0);
323- myfile_res << scientific << solvers0[FEA_SOL]->GetTotal_ComboObj () << " \t " ;
324-
325- for (iVar = 0 ; iVar < config[iZone]->GetnElasticityMod (); iVar++)
326- myfile_res << scientific << solvers0[ADJFEA_SOL]->GetTotal_Sens_E (iVar) << " \t " ;
327- for (iVar = 0 ; iVar < config[iZone]->GetnPoissonRatio (); iVar++)
328- myfile_res << scientific << solvers0[ADJFEA_SOL]->GetTotal_Sens_Nu (iVar) << " \t " ;
329- if (dynamic) {
330- for (iVar = 0 ; iVar < config[iZone]->GetnMaterialDensity (); iVar++)
331- myfile_res << scientific << solvers0[ADJFEA_SOL]->GetTotal_Sens_Rho (iVar) << " \t " ;
332- }
333- if (de_effects) {
334- for (iVar = 0 ; iVar < config[iZone]->GetnElectric_Field (); iVar++)
335- myfile_res << scientific << solvers0[ADJFEA_SOL]->GetTotal_Sens_EField (iVar) << " \t " ;
336- }
337- for (iVar = 0 ; iVar < solvers0[ADJFEA_SOL]->GetnDVFEA (); iVar++) {
338- myfile_res << scientific << solvers0[ADJFEA_SOL]->GetTotal_Sens_DVFEA (iVar) << " \t " ;
339- }
340-
341- myfile_res << " \n " ;
342- }
343-
344299 // TEST: for implementation of python framework in standalone structural problems
345300 if (config[iZone]->GetAdvanced_FEAElementBased () && (rank == MASTER_NODE)) {
346301 /* --- Header of the temporary output file ---*/
0 commit comments