Skip to content

Commit ce99e01

Browse files
committed
Turbulent combustion (TFC)
1 parent 1e64b8d commit ce99e01

File tree

15 files changed

+890
-4
lines changed

15 files changed

+890
-4
lines changed

Common/include/option_structure.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ enum ENUM_FLUIDMODEL {
549549
FLUID_MIXTURE = 9, /*!< \brief Species mixture model. */
550550
COOLPROP = 10, /*!< \brief Thermodynamics library. */
551551
FLUID_FLAMELET = 11, /*!< \brief lookup table (LUT) method for premixed flamelets. */
552-
DATADRIVEN_FLUID = 12, /*!< \brief multi-layer perceptron driven fluid model. */
552+
DATADRIVEN_FLUID = 12, /*!< \brief multi-layer perceptron driven fluid model. */
553+
USER_DEFINED = 13, /*!< \brief user defined through python wrapper. */
553554
};
554555
static const MapType<std::string, ENUM_FLUIDMODEL> FluidModel_Map = {
555556
MakePair("STANDARD_AIR", STANDARD_AIR)
@@ -565,6 +566,7 @@ static const MapType<std::string, ENUM_FLUIDMODEL> FluidModel_Map = {
565566
MakePair("COOLPROP", COOLPROP)
566567
MakePair("DATADRIVEN_FLUID", DATADRIVEN_FLUID)
567568
MakePair("FLUID_FLAMELET", FLUID_FLAMELET)
569+
MakePair("USER_DEFINED", USER_DEFINED)
568570
};
569571

570572
/*!

SU2_CFD/include/drivers/CDriverBase.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,9 @@ class CDriverBase {
767767
*/
768768
void SetPointCustomSource(unsigned short iSolver, unsigned long iPoint, std::vector<passivedouble> values) {
769769
auto* solver = solver_container[selected_zone][INST_0][MESH_0][iSolver];
770+
771+
//if (values[0]>1.0e-6)
772+
// cout << "iPoint="<<iPoint << ", setting custom point source" << values[0]<< endl;
770773
solver->SetCustomPointSource(iPoint, values);
771774
}
772775

@@ -787,6 +790,23 @@ inline vector<passivedouble> GetSolutionVector(unsigned short iSolver, unsigned
787790
return solutionvector;
788791
}
789792

793+
/* The vector with actual solution values */
794+
inline void SetSolutionVector(unsigned short iSolver, unsigned long iPoint, vector<passivedouble> solutionVector) {
795+
auto* solver = solver_container[selected_zone][INST_0][MESH_0][iSolver];
796+
auto* nodes = solver->GetNodes();
797+
798+
/*--- check the size of the solver variables ---*/
799+
unsigned short nVar = GetNumberSolverVars(iSolver);
800+
if (nVar != solutionVector.size() )
801+
SU2_MPI::Error("Solution Vector size is not equal to Solver size.", CURRENT_FUNCTION);
802+
//cout << "setting solution vector " << nodes->GetSolution(iPoint,0) << " " << solutionVector[0] << ", "<< nVar<< endl;
803+
for (unsigned int iVar = 0u; iVar < nVar; ++iVar) {
804+
nodes->SetSolution(iPoint,iVar, solutionVector[iVar]);
805+
nodes->SetSolution_Old(iPoint,iVar, solutionVector[iVar]);
806+
}
807+
}
808+
809+
790810
/*!
791811
* \brief Get the primitive variables vector in a point for a specific solver
792812
* \param[in] iSolver - Solver index.
@@ -804,6 +824,25 @@ inline vector<passivedouble> GetPrimitiveVector(unsigned short iSolver, unsigned
804824
return solutionvector;
805825
}
806826

827+
828+
/*!
829+
* \brief Get the primitive variables vector in a point for a specific solver
830+
* \param[in] iSolver - Solver index.
831+
* \param[in] iPoint - Point index.
832+
* \param[out] solutionvector - Vector values of the primitive variables.
833+
*/
834+
inline void SetPrimitiveVector(unsigned short iSolver, unsigned long iPoint, vector<passivedouble> primitiveVector) {
835+
auto* solver = solver_container[selected_zone][INST_0][MESH_0][iSolver];
836+
auto* nodes = solver->GetNodes();
837+
auto nPrimvar = GetNumberPrimitiveVars(iSolver);
838+
vector<passivedouble> solutionvector(nPrimvar, 0.0);
839+
//cout << "setting primitive vector " << nodes->GetPrimitive(iPoint,0) << " " << primitiveVector[0] << ", "<< nPrimvar<< endl;
840+
841+
for (auto iVar = 0u; iVar < nPrimvar; ++iVar) {
842+
nodes->SetPrimitive(iPoint,iVar, primitiveVector[iVar]);
843+
}
844+
}
845+
807846
/// \}
808847

809848
protected:

SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,7 @@ class CFVMFlowSolverBase : public CSolver {
22252225
vector<passivedouble> val_source) final {
22262226
/*--- Since this call can be accessed indirectly using python, do some error
22272227
* checking to prevent segmentation faults ---*/
2228+
//cout << "flow" << endl;
22282229
if (val_point > nPointDomain)
22292230
SU2_MPI::Error("Out-of-bounds point index used on solver.", CURRENT_FUNCTION);
22302231
else if (val_source.size() > nVar)

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {
124124

125125
AllocVectorOfMatrices(nVertex, nDim, Inlet_FlowDir);
126126
PointSource.resize(nPointDomain,nVar);
127-
127+
PointSource.setConstant(0.0);
128+
128129
/*--- Force definition and coefficient arrays for all of the markers ---*/
129130

130131
AllocVectorOfVectors(nVertex, CPressure);

SU2_CFD/include/solvers/CScalarSolver.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class CScalarSolver : public CSolver {
6464
vector<su2matrix<su2double*> > SlidingState; // vector of matrix of pointers... inner dim alloc'd elsewhere (welcome, to the twilight zone)
6565
vector<vector<int> > SlidingStateNodes;
6666

67+
6768
/*--- Shallow copy of grid coloring for OpenMP parallelization. ---*/
6869

6970
#ifdef HAVE_OMP
@@ -578,4 +579,5 @@ class CScalarSolver : public CSolver {
578579
return SlidingStateNodes[val_marker][val_vertex];
579580
}
580581

582+
581583
};

SU2_CFD/include/solvers/CScalarSolver.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ CScalarSolver<VariableType>::CScalarSolver(CGeometry* geometry, CConfig* config,
3636
config->GetNEMOProblem(), geometry->GetnDim(), config->GetnSpecies()) {
3737
nMarker = config->GetnMarker_All();
3838

39+
3940
/*--- Store the number of vertices on each marker for deallocation later ---*/
4041
nVertex.resize(nMarker);
4142
for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++) nVertex[iMarker] = geometry->nVertex[iMarker];

SU2_CFD/include/solvers/CSpeciesSolver.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CSpeciesSolver : public CScalarSolver<CSpeciesVariable> {
4040
protected:
4141
unsigned short Inlet_Position; /*!< \brief Column index for scalar variables in inlet files. */
4242
vector<su2activematrix> Inlet_SpeciesVars; /*!< \brief Species variables at inlet profiles. */
43+
su2activematrix SpeciesPointSource; /*!< \brief Value of the Flow Direction. */
4344

4445
public:
4546
/*!
@@ -162,6 +163,16 @@ class CSpeciesSolver : public CScalarSolver<CSpeciesVariable> {
162163
*/
163164
void Source_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, CConfig* config,
164165
unsigned short iMesh) override;
166+
/*!
167+
* \brief Source term computation for axisymmetric flow.
168+
* \param[in] geometry - Geometrical definition of the problem.
169+
* \param[in] solver_container - Container vector with all the solutions.
170+
* \param[in] numerics_container - Container for description of the numerical method.
171+
* \param[in] config - Definition of the particular problem.
172+
* \param[in] iMesh - Index of the mesh in multigrid computations.
173+
*/
174+
void Custom_Source_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, CConfig* config,
175+
unsigned short iMesh) override;
165176

166177

167178
/*!
@@ -183,4 +194,42 @@ class CSpeciesSolver : public CScalarSolver<CSpeciesVariable> {
183194
},
184195
geometry, solver_container, conv_numerics, visc_numerics, config);
185196
}
197+
198+
199+
/*!
200+
* \brief Set a component of the unit vector representing the flow direction at an inlet boundary.
201+
* \param[in] val_marker - Surface marker where the flow direction is set.
202+
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the flow direction is set.
203+
* \param[in] val_dim - The component of the flow direction unit vector to be set
204+
* \param[in] val_flowdir - Component of a unit vector representing the flow direction.
205+
*/
206+
inline void SetCustomPointSource(unsigned long val_point,
207+
vector<passivedouble> val_source) final {
208+
/*--- Since this call can be accessed indirectly using python, do some error
209+
* checking to prevent segmentation faults ---*/
210+
//cout << "***** set custom point source species *****" << endl;
211+
if (val_point > nPointDomain)
212+
SU2_MPI::Error("Out-of-bounds point index used on solver.", CURRENT_FUNCTION);
213+
else if (val_source.size() > nVar)
214+
SU2_MPI::Error("Out-of-bounds source size used on solver.", CURRENT_FUNCTION);
215+
else {
216+
for (size_t iVar=0; iVar < val_source.size(); iVar++) {
217+
SpeciesPointSource[val_point][iVar] = val_source[iVar];
218+
//if (SpeciesPointSource[val_point][iVar] > 1.0e-6)
219+
// cout << iVar<<", setcustompointsource: "<< SpeciesPointSource[val_point][iVar] << endl;
220+
}
221+
}
222+
}
223+
/*!
224+
* \brief A component of the unit vector representing the flow direction at an inlet boundary.
225+
* \param[in] val_marker - Surface marker where the flow direction is evaluated
226+
* \param[in] val_vertex - Vertex of the marker <i>val_marker</i> where the flow direction is evaluated
227+
* \param[in] val_dim - The component of the flow direction unit vector to be evaluated
228+
* \return Component of a unit vector representing the flow direction.
229+
*/
230+
inline su2double GetCustomPointSource(unsigned long val_point,
231+
unsigned short val_var) const final {
232+
return SpeciesPointSource[val_point][val_var];
233+
}
234+
186235
};

SU2_CFD/src/numerics/flow/flow_sources.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ CNumerics::ResidualType<> CSourceIncBodyForce::ComputeResidual(const CConfig* co
427427

428428
residual[nDim+1] = 0.0;
429429

430-
431430
return ResidualType<>(residual, jacobian, nullptr);
432431
}
433432

SU2_CFD/src/solvers/CIncEulerSolver.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ void CIncEulerSolver::SetNondimensionalization(CConfig *config, unsigned short i
303303

304304
config->SetGas_Constant(UNIVERSAL_GAS_CONSTANT/(config->GetMolecular_Weight()/1000.0));
305305
Pressure_Thermodynamic = Density_FreeStream*Temperature_FreeStream*config->GetGas_Constant();
306+
cout << "gas constant = " << config->GetGas_Constant() << endl;
307+
cout << "pressure = " << Pressure_Thermodynamic << endl;
308+
cout << "rho="<< Density_FreeStream<< endl;
309+
cout << "T="<< Temperature_FreeStream<< endl;
306310
auxFluidModel = new CIncIdealGas(config->GetSpecific_Heat_Cp(), config->GetGas_Constant(), Pressure_Thermodynamic);
307311
auxFluidModel->SetTDState_T(Temperature_FreeStream);
308312
Pressure_Thermodynamic = auxFluidModel->GetPressure();
@@ -342,6 +346,9 @@ void CIncEulerSolver::SetNondimensionalization(CConfig *config, unsigned short i
342346
auxFluidModel->SetTDState_T(Temperature_FreeStream, config->GetSpecies_Init());
343347
break;
344348

349+
case USER_DEFINED:
350+
break;
351+
345352
default:
346353

347354
SU2_MPI::Error("Fluid model not implemented for incompressible solver.", CURRENT_FUNCTION);
@@ -1835,6 +1842,7 @@ void CIncEulerSolver::Custom_Source_Residual(CGeometry *geometry, CSolver **solv
18351842

18361843
/*--- Compute the residual for this control volume and subtract. ---*/
18371844
for (iVar = 0; iVar < nVar; iVar++) {
1845+
//cout << iPoint << " " << iVar << ",S="<< PointSource[iPoint][iVar]<< endl;
18381846
LinSysRes[iPoint*nVar+iVar] += PointSource[iPoint][iVar] * Volume;
18391847
}
18401848
// cout << "source = " << iPoint << " " << PointSource[iPoint][0]*Volume

SU2_CFD/src/solvers/CSpeciesSolver.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void CSpeciesSolver::Initialize(CGeometry* geometry, CConfig* config, unsigned s
9494
/*--- Store if an implicit scheme is used, for use during periodic boundary conditions. ---*/
9595
SetImplicitPeriodic(config->GetKind_TimeIntScheme_Species() == EULER_IMPLICIT);
9696

97+
9798
nPrimVar = nVar;
9899

99100
if (nVar > MAXNVAR)
@@ -111,6 +112,12 @@ void CSpeciesSolver::Initialize(CGeometry* geometry, CConfig* config, unsigned s
111112
nDim = geometry->GetnDim();
112113

113114

115+
116+
std::cout << "resize species pointsource, nVar="<<nVar <<" npointdomain="<<nPointDomain << endl;
117+
SpeciesPointSource.resize(nPointDomain,nVar);
118+
SpeciesPointSource.setConstant(0.0);
119+
120+
114121
if (iMesh == MESH_0 || config->GetMGCycle() == FULLMG_CYCLE) {
115122

116123
/*--- Define some auxiliary vector related with the residual ---*/
@@ -181,7 +188,7 @@ if (iMesh == MESH_0 || config->GetMGCycle() == FULLMG_CYCLE) {
181188
void CSpeciesSolver::LoadRestart(CGeometry** geometry, CSolver*** solver, CConfig* config, int val_iter,
182189
bool val_update_geo) {
183190
/*--- Restart the solution from file information ---*/
184-
191+
cout<<"speciessolver:loadrestart" << endl;
185192
const string restart_filename = config->GetFilename(config->GetSolution_FileName(), "", val_iter);
186193

187194
/*--- To make this routine safe to call in parallel most of it can only be executed by one thread. ---*/
@@ -569,3 +576,42 @@ void CSpeciesSolver::Source_Residual(CGeometry *geometry, CSolver **solver_conta
569576
END_SU2_OMP_FOR
570577
}
571578
}
579+
580+
581+
void CSpeciesSolver::Custom_Source_Residual(CGeometry *geometry, CSolver **solver_container,
582+
CNumerics **numerics_container, CConfig *config, unsigned short iMesh) {
583+
584+
/*--- Pick one numerics object per thread. ---*/
585+
CNumerics* numerics = numerics_container[SOURCE_SECOND_TERM + omp_get_thread_num()*MAX_TERMS];
586+
587+
unsigned short iVar;
588+
unsigned long iPoint;
589+
AD::StartNoSharedReading();
590+
591+
SU2_OMP_FOR_STAT(omp_chunk_size)
592+
for (iPoint = 0; iPoint < nPointDomain; iPoint++) {
593+
594+
/*--- Load the volume of the dual mesh cell ---*/
595+
596+
numerics->SetVolume(geometry->nodes->GetVolume(iPoint));
597+
598+
/*--- Get control volume size. ---*/
599+
su2double Volume = geometry->nodes->GetVolume(iPoint);
600+
601+
/*--- Compute the residual for this control volume and subtract. ---*/
602+
for (iVar = 0; iVar < nVar; iVar++) {
603+
//if (SpeciesPointSource[iPoint][iVar] > 1.0e-6)
604+
//cout << iPoint << " " << iVar << ",Species ="<< SpeciesPointSource[iPoint][iVar]<< endl;
605+
LinSysRes[iPoint*nVar+iVar] -= SpeciesPointSource[iPoint][iVar] * Volume;
606+
}
607+
// cout << "source = " << iPoint << " " << PointSource[iPoint][0]*Volume
608+
// << " " << PointSource[iPoint][1]*Volume
609+
// << " " << PointSource[iPoint][2]*Volume
610+
// << " " << PointSource[iPoint][3]*Volume << endl;
611+
612+
}
613+
END_SU2_OMP_FOR
614+
615+
AD::EndNoSharedReading();
616+
617+
}

0 commit comments

Comments
 (0)