Skip to content

Commit 638cf83

Browse files
authored
Merge pull request #2020 from su2code/custom_function_outputs_everywhere
Add simple custom outputs (functions of other outputs) to all solvers
2 parents 2bb4550 + e219c05 commit 638cf83

19 files changed

Lines changed: 101 additions & 296 deletions

Common/include/CConfig.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8658,7 +8658,6 @@ class CConfig {
86588658
unsigned short GetKind_Average(void) const { return Kind_Average; }
86598659

86608660
/*!
8661-
*
86628661
* \brief Get the direct differentation method.
86638662
* \return direct differentiation method.
86648663
*/

SU2_CFD/include/output/CFlowOutput.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ class CFlowOutput : public CFVMOutput{
215215
* \brief Helper for custom outputs, converts variable names to indices and pointers which are then used
216216
* to evaluate the custom expressions.
217217
*/
218-
void ConvertVariableSymbolsToIndices(const CPrimitiveIndices<unsigned long>& idx, CustomOutput& output) const;
218+
void ConvertVariableSymbolsToIndices(const CPrimitiveIndices<unsigned long>& idx, bool allowSkip,
219+
CustomOutput& output) const;
219220

220221
/*!
221222
* \brief Compute value of the Q criteration for vortex idenfitication
@@ -296,7 +297,7 @@ class CFlowOutput : public CFVMOutput{
296297
* \param[in] force_writing - boolean that forces writing of volume output
297298
* \param[in] iFile - index to the file that we need to consider for volume output
298299
*/
299-
bool WriteVolumeOutput(CConfig *config, unsigned long Iter, bool force_writing, unsigned short iFile) override;
300+
bool WriteVolumeOutput(CConfig *config, unsigned long Iter, bool force_writing, unsigned short iFile) override;
300301
/*!
301302
* \brief Write the forces breakdown file
302303
* \param[in] config - Definition of the particular problem per zone.

SU2_CFD/include/output/COutput.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ class COutput {
223223
We store pointers to the required outputs to speed-up access. ---*/
224224
std::vector<const su2double*> otherOutputs;
225225

226+
/*--- For discrete adjoint we may need to skip some expressions because there is one output class
227+
for the primal solver and one for the discrete adjoint (each with different variables). ---*/
228+
bool skip = false;
229+
226230
/*--- For evaluation, "vars" is a functor (i.e. has operator()) that returns the value of a variable at a given
227231
point. For example, it can be a wrapper to the primitives pointer, in which case varIndices needs to be setup
228232
with primitive indices. ---*/
@@ -807,6 +811,14 @@ class COutput {
807811
*/
808812
void SetCustomOutputs(const CConfig *config);
809813

814+
/*!
815+
* \brief Evaluates function-type custom outputs.
816+
* Derived classes can use this to compute simple expressions of other outputs if they
817+
* do not implement surface averages. This should be called just before evaluating the
818+
* custom objective function.
819+
*/
820+
void ComputeSimpleCustomOutputs(const CConfig *config);
821+
810822
/*!
811823
* \brief Load values of the history fields common for all solvers.
812824
* \param[in] config - Definition of the particular problem.

SU2_CFD/src/output/CAdjElasticityOutput.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ inline void CAdjElasticityOutput::LoadHistoryData(CConfig *config, CGeometry *ge
172172
SetHistoryOutputValue("BGS_ADJ_DISP_Z", log10(solver[ADJFEA_SOL]->GetRes_BGS(2)));
173173
}
174174
}
175+
176+
ComputeSimpleCustomOutputs(config);
175177
}
176178

177179
void CAdjElasticityOutput::LoadVolumeData(CConfig *config, CGeometry *geometry, CSolver **solver, unsigned long iPoint){

SU2_CFD/src/output/CAdjFlowCompOutput.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ void CAdjFlowCompOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, C
225225
}
226226

227227
LoadHistoryDataAdjScalar(config, solver);
228+
229+
ComputeSimpleCustomOutputs(config);
228230
}
229231

230232
void CAdjFlowCompOutput::SetVolumeOutputFields(CConfig *config) {

SU2_CFD/src/output/CAdjFlowIncOutput.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ void CAdjFlowIncOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CS
275275
}
276276

277277
LoadHistoryDataAdjScalar(config, solver);
278+
279+
ComputeSimpleCustomOutputs(config);
278280
}
279281

280282
void CAdjFlowIncOutput::SetVolumeOutputFields(CConfig *config) {

SU2_CFD/src/output/CAdjFlowOutput.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ void CAdjFlowOutput::LoadHistoryDataAdjScalar(const CConfig* config, const CSolv
172172
SetHistoryOutputValue("LINSOL_ITER_SPECIES", adjspecies_solver->GetIterLinSolver());
173173
SetHistoryOutputValue("LINSOL_RESIDUAL_SPECIES", log10(adjspecies_solver->GetResLinSolver()));
174174
}
175+
176+
ComputeSimpleCustomOutputs(config);
175177
}
176178

177179
void CAdjFlowOutput::SetVolumeOutputFieldsAdjScalarSolution(const CConfig* config) {

SU2_CFD/src/output/CAdjHeatOutput.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ void CAdjHeatOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CSolv
142142
SetHistoryOutputValue("DEFORM_RESIDUAL", log10(solver[MESH_SOL]->System.GetResidual()));
143143
}
144144

145+
ComputeSimpleCustomOutputs(config);
145146
}
146147

147148
void CAdjHeatOutput::SetVolumeOutputFields(CConfig *config){

SU2_CFD/src/output/CElasticityOutput.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ void CElasticityOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CS
146146
SetHistoryOutputValue("VOLUME_FRACTION", fea_solver->GetTotal_OFVolFrac());
147147
SetHistoryOutputValue("TOPOL_DISCRETENESS", fea_solver->GetTotal_OFDiscreteness());
148148
}
149+
150+
ComputeSimpleCustomOutputs(config);
151+
149152
/*--- Keep this as last, since it uses the history values that were set. ---*/
150153
SetCustomAndComboObjectives(FEA_SOL, config, solver);
151154

SU2_CFD/src/output/CFlowCompFEMOutput.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ void CFlowCompFEMOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, C
263263

264264
SetAerodynamicCoefficients(config, flow_solver);
265265

266+
ComputeSimpleCustomOutputs(config);
266267
}
267268

268269
bool CFlowCompFEMOutput::SetInitResiduals(const CConfig *config){

0 commit comments

Comments
 (0)