Skip to content

Commit

Permalink
handle variables of other solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarruscag committed Jul 24, 2022
1 parent 805bdbc commit f1bb97a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 25 deletions.
41 changes: 27 additions & 14 deletions SU2_CFD/include/output/CFlowOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class CFlowOutput : public CFVMOutput{
* \param[in] geometry - Geometrical definition of the problem.
* \param[in] config - Definition of the particular problem.
*/
void SetCustomOutputs(const CSolver *solver, const CGeometry *geometry, const CConfig *config);
void SetCustomOutputs(const CSolver* const* solver, const CGeometry *geometry, const CConfig *config);

/*!
* \brief Helper for custom outputs, converts variable names to indices and pointers which are then used
Expand All @@ -216,21 +216,34 @@ class CFlowOutput : public CFVMOutput{

static const auto knownVariables =
"TEMPERATURE, TEMPERATURE_VE, VELOCITY_X, VELOCITY_Y, VELOCITY_Z, PRESSURE,\n"
"DENSITY, ENTHALPY, SOUND_SPEED, LAMINAR_VISCOSITY, EDDY_VISCOSITY, THERMAL_CONDUCTIVITY";
"DENSITY, ENTHALPY, SOUND_SPEED, LAMINAR_VISCOSITY, EDDY_VISCOSITY, THERMAL_CONDUCTIVITY\n"
"TURB[0,1,...], RAD[0,1,...], SPECIES[0,1,...]";

auto IndexOfVariable = [&](const FlowIndices& idx, const std::string& var) {
if ("TEMPERATURE" == var) return idx.Temperature();
if ("TEMPERATURE_VE" == var) return idx.Temperature_ve();
if ("VELOCITY_X" == var) return idx.Velocity();
if ("VELOCITY_Y" == var) return idx.Velocity() + 1;
if ("VELOCITY_Z" == var) return idx.Velocity() + 2;
if ("PRESSURE" == var) return idx.Pressure();
if ("DENSITY" == var) return idx.Density();
if ("ENTHALPY" == var) return idx.Enthalpy();
if ("SOUND_SPEED" == var) return idx.SoundSpeed();
if ("LAMINAR_VISCOSITY" == var) return idx.LaminarViscosity();
if ("EDDY_VISCOSITY" == var) return idx.EddyViscosity();
if ("THERMAL_CONDUCTIVITY" == var) return idx.ThermalConductivity();
/*--- Primitives of the flow solver. ---*/
const auto flow_offset = FLOW_SOL * CustomOutput::MAX_VARS_PER_SOLVER;

if ("TEMPERATURE" == var) return flow_offset + idx.Temperature();
if ("TEMPERATURE_VE" == var) return flow_offset + idx.Temperature_ve();
if ("VELOCITY_X" == var) return flow_offset + idx.Velocity();
if ("VELOCITY_Y" == var) return flow_offset + idx.Velocity() + 1;
if ("VELOCITY_Z" == var) return flow_offset + idx.Velocity() + 2;
if ("PRESSURE" == var) return flow_offset + idx.Pressure();
if ("DENSITY" == var) return flow_offset + idx.Density();
if ("ENTHALPY" == var) return flow_offset + idx.Enthalpy();
if ("SOUND_SPEED" == var) return flow_offset + idx.SoundSpeed();
if ("LAMINAR_VISCOSITY" == var) return flow_offset + idx.LaminarViscosity();
if ("EDDY_VISCOSITY" == var) return flow_offset + idx.EddyViscosity();
if ("THERMAL_CONDUCTIVITY" == var) return flow_offset + idx.ThermalConductivity();

/*--- Index-based (no name) access to variables of other solvers. ---*/
auto GetIndex = [](const std::string& s, int offset) {
return std::stoi(std::string(s.begin() + offset + 1, s.end() - 1));
};
if (var.rfind("SPECIES", 0) == 0) return SPECIES_SOL * CustomOutput::MAX_VARS_PER_SOLVER + GetIndex(var, 7);
if (var.rfind("TURB", 0) == 0) return TURB_SOL * CustomOutput::MAX_VARS_PER_SOLVER + GetIndex(var, 4);
if (var.rfind("RAD", 0) == 0) return RAD_SOL * CustomOutput::MAX_VARS_PER_SOLVER + GetIndex(var, 3);

return CustomOutput::NOT_A_VARIABLE;
};

Expand Down
7 changes: 5 additions & 2 deletions SU2_CFD/include/output/COutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,15 @@ class COutput {
is passed to a functor that returns the value associated with the symbol. This functor is an input to "eval()"
and needs to be generated on-the-fly for each point. The functor approach is more generic than a pointer, for
example it allows wrapping the access to multiple solvers. The interpretation of these indices is dictated by
the functor used in eval, for example indices may be established as 1000 * solver_idx + variable_idx.
the functor used in eval, for example indices may be established as 32 * solver_idx + variable_idx.
The parts of the code that assign and interpret indices need to be in sync. ---*/
std::vector<unsigned long> varIndices;

/*--- Offset between varIndices of different solvers (see above). Power of 2 to make decoding faster. ---*/
static constexpr unsigned long MAX_VARS_PER_SOLVER = 32;

/*--- Arbitrary number to indicate that a string did not match a variable. ---*/
static constexpr unsigned long NOT_A_VARIABLE = 1000;
static constexpr unsigned long NOT_A_VARIABLE = MAX_SOLS * MAX_VARS_PER_SOLVER;

/*--- Other outputs can be referenced in expressions, e.g. to compute variance.
We store pointers to the required outputs to speed-up access. ---*/
Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/output/CFlowCompOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void CFlowCompOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CSol

/*--- Keep this as last, since it uses the history values that were set. ---*/

SetCustomOutputs(flow_solver, geometry, config);
SetCustomOutputs(solver, geometry, config);

SetCustomAndComboObjectives(FLOW_SOL, config, solver);

Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/output/CFlowIncOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void CFlowIncOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CSolv

/*--- Keep this as last, since it uses the history values that were set. ---*/

SetCustomOutputs(flow_solver, geometry, config);
SetCustomOutputs(solver, geometry, config);

SetCustomAndComboObjectives(FLOW_SOL, config, solver);

Expand Down
12 changes: 9 additions & 3 deletions SU2_CFD/src/output/CFlowOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,10 @@ void CFlowOutput::SetAnalyzeSurface_SpeciesVariance(const CSolver* const*solver,
SetHistoryOutputValue("SURFACE_SPECIES_VARIANCE", Tot_Surface_SpeciesVariance);
}

void CFlowOutput::SetCustomOutputs(const CSolver *solver, const CGeometry *geometry, const CConfig *config) {
void CFlowOutput::SetCustomOutputs(const CSolver* const* solver, const CGeometry *geometry, const CConfig *config) {

const bool axisymmetric = config->GetAxisymmetric();
const auto* flowNodes = solver->GetNodes();
const auto* flowNodes = su2staticcast_p<const CFlowVariable*>(solver[FLOW_SOL]->GetNodes());

for (auto& output : customOutputs) {
if (output.varIndices.empty()) {
Expand Down Expand Up @@ -807,7 +807,13 @@ void CFlowOutput::SetCustomOutputs(const CSolver *solver, const CGeometry *geome

auto Functor = [&](unsigned long i) {
if (i < CustomOutput::NOT_A_VARIABLE) {
return flowNodes->GetPrimitive(iPoint, i);
const auto solIdx = i / CustomOutput::MAX_VARS_PER_SOLVER;
const auto varIdx = i % CustomOutput::MAX_VARS_PER_SOLVER;
if (solIdx == FLOW_SOL) {
return flowNodes->GetPrimitive(iPoint, varIdx);
} else {
return solver[solIdx]->GetNodes()->GetSolution(iPoint, varIdx);
}
} else {
return *output.otherOutputs[i - CustomOutput::NOT_A_VARIABLE];
}
Expand Down
2 changes: 1 addition & 1 deletion SU2_CFD/src/output/CNEMOCompOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void CNEMOCompOutput::LoadHistoryData(CConfig *config, CGeometry *geometry, CSol

/*--- Keep this as last, since it uses the history values that were set. ---*/

SetCustomOutputs(NEMO_solver, geometry, config);
SetCustomOutputs(solver, geometry, config);

SetCustomAndComboObjectives(FLOW_SOL, config, solver);

Expand Down
4 changes: 2 additions & 2 deletions TestCases/parallel_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,8 +1689,8 @@ def main():
species_passive_val.cfg_dir = "species_transport/passive_transport_validation"
species_passive_val.cfg_file = "passive_transport.cfg"
species_passive_val.test_iter = 50
species_passive_val.test_vals = [-16.559189, -16.315116, -16.908670, -4.257599, 10.000000, -4.523292, 8.000000, -5.193350]
species_passive_val.test_vals_aarch64 = [-16.538551, -16.312552, -16.882823, -4.257599, 10.000000, -4.585464, 8.000000, -5.193350]
species_passive_val.test_vals = [-16.559189, -16.315116, -16.908670, -4.257599, 10, -4.523292, 8, -5.19335, 0.18661, 0]
species_passive_val.test_vals_aarch64 = [-16.538551, -16.312552, -16.882823, -4.257599, 10, -4.585464, 8, -5.19335, 0.18661, 0]
species_passive_val.su2_exec = "mpirun -n 2 SU2_CFD"
species_passive_val.timeout = 1600
species_passive_val.new_output = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ MARKER_INLET_SPECIES = (gas_inlet, 1.0, air_inlet, 0.0 )
INC_OUTLET_TYPE= PRESSURE_OUTLET
MARKER_OUTLET= ( outlet, 0 )
%
MARKER_ANALYZE= ( outlet )
%
% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------%
%
NUM_METHOD_GRAD= GREEN_GAUSS
Expand Down Expand Up @@ -90,7 +92,10 @@ CONV_STARTITER= 10
%
MESH_FILENAME = rectangle_mixing.su2
%
SCREEN_OUTPUT = INNER_ITER WALL_TIME RMS_PRESSURE RMS_VELOCITY-X RMS_VELOCITY-Y RMS_SPECIES_0 LINSOL_ITER LINSOL_RESIDUAL LINSOL_ITER_SPECIES LINSOL_RESIDUAL_SPECIES
CUSTOM_OUTPUTS = 'avg_species : MassFlowAvg{SPECIES[0]}[outlet];\
avg_check : Function{avg_species - SURFACE_SPECIES_0}'
%
SCREEN_OUTPUT = INNER_ITER WALL_TIME RMS_RES LINSOL CUSTOM
SCREEN_WRT_FREQ_INNER= 10
%
HISTORY_OUTPUT = RMS_RES MAX_RES FLOW_COEFF
Expand Down

0 comments on commit f1bb97a

Please sign in to comment.