Skip to content

Commit 9f082de

Browse files
bigfootedpcarruscagEvertBunschoten
authored
Multizone with species transport (#1821)
Co-authored-by: Pedro Gomes <38071223+pcarruscag@users.noreply.github.com> * move slidingstates to scalarsolver * regression testcase for multizone * added bc_fluid_interface to speciessolver Co-authored-by: EvertBunschoten <evertbun@xs4all.nl>
1 parent 7132d99 commit 9f082de

14 files changed

Lines changed: 481 additions & 267 deletions

File tree

Common/src/CConfig.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5354,7 +5354,8 @@ void CConfig::SetPostprocessing(SU2_COMPONENT val_software, unsigned short val_i
53545354
Kind_Solver != MAIN_SOLVER::NAVIER_STOKES &&
53555355
Kind_Solver != MAIN_SOLVER::RANS &&
53565356
Kind_Solver != MAIN_SOLVER::DISC_ADJ_NAVIER_STOKES &&
5357-
Kind_Solver != MAIN_SOLVER::DISC_ADJ_RANS)
5357+
Kind_Solver != MAIN_SOLVER::DISC_ADJ_RANS &&
5358+
Kind_Solver != MAIN_SOLVER::MULTIPHYSICS)
53585359
SU2_MPI::Error("Species transport currently only available for compressible and incompressible flow.", CURRENT_FUNCTION);
53595360

53605361
/*--- Species specific OF currently can only handle one entry in Marker_Analyze. ---*/

SU2_CFD/include/solvers/CScalarSolver.hpp

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <vector>
3030

3131
#include "../../../Common/include/parallelization/omp_structure.hpp"
32+
#include "../../../Common/include/toolboxes/geometry_toolbox.hpp"
3233
#include "../variables/CScalarVariable.hpp"
3334
#include "CSolver.hpp"
3435

@@ -57,6 +58,9 @@ class CScalarSolver : public CSolver {
5758

5859
const bool Conservative; /*!< \brief Transported Variable is conservative. Solution has to be multiplied with rho. */
5960

61+
vector<su2matrix<su2double*> > SlidingState; // vector of matrix of pointers... inner dim alloc'd elsewhere (welcome, to the twilight zone)
62+
vector<vector<int> > SlidingStateNodes;
63+
6064
/*--- Shallow copy of grid coloring for OpenMP parallelization. ---*/
6165

6266
#ifdef HAVE_OMP
@@ -135,6 +139,122 @@ class CScalarSolver : public CSolver {
135139
}
136140
}
137141

142+
/*!
143+
* \brief Generic implementation of the fluid interface boundary condition for scalar solvers.
144+
* \tparam SolverSpecificNumericsFunc - lambda that implements solver specific contributions to viscous numerics.
145+
* \note The functor has to implement (iPoint)
146+
* \param[in] geometry - Geometrical definition of the problem.
147+
* \param[in] solver_container - Container vector with all the solutions.
148+
* \param[in] conv_numerics - Description of the numerical method.
149+
* \param[in] visc_numerics - Description of the numerical method.
150+
* \param[in] config - Definition of the particular problem.
151+
*/
152+
template <class SolverSpecificNumericsFunc>
153+
void BC_Fluid_Interface_impl(const SolverSpecificNumericsFunc& SolverSpecificNumerics, CGeometry *geometry,
154+
CSolver **solver_container, CNumerics *conv_numerics, CNumerics *visc_numerics,
155+
CConfig *config) {
156+
const auto nPrimVar = solver_container[FLOW_SOL]->GetnPrimVar();
157+
su2activevector PrimVar_j(nPrimVar);
158+
su2double solution_j[MAXNVAR] = {0.0};
159+
160+
for (auto iMarker = 0u; iMarker < config->GetnMarker_All(); iMarker++) {
161+
162+
if (config->GetMarker_All_KindBC(iMarker) != FLUID_INTERFACE) continue;
163+
164+
SU2_OMP_FOR_STAT(OMP_MIN_SIZE)
165+
for (auto iVertex = 0u; iVertex < geometry->nVertex[iMarker]; iVertex++) {
166+
167+
const auto iPoint = geometry->vertex[iMarker][iVertex]->GetNode();
168+
169+
if (!geometry->nodes->GetDomain(iPoint)) continue;
170+
171+
const auto Point_Normal = geometry->vertex[iMarker][iVertex]->GetNormal_Neighbor();
172+
const auto nDonorVertex = GetnSlidingStates(iMarker,iVertex);
173+
174+
su2double Normal[MAXNDIM] = {0.0};
175+
for (auto iDim = 0u; iDim < nDim; iDim++)
176+
Normal[iDim] = -geometry->vertex[iMarker][iVertex]->GetNormal()[iDim];
177+
178+
su2double* PrimVar_i = solver_container[FLOW_SOL]->GetNodes()->GetPrimitive(iPoint);
179+
180+
auto Jacobian_i = Jacobian.GetBlock(iPoint,iPoint);
181+
182+
/*--- Loop over the nDonorVertexes and compute the averaged flux ---*/
183+
184+
for (auto jVertex = 0; jVertex < nDonorVertex; jVertex++) {
185+
186+
for (auto iVar = 0u; iVar < nPrimVar; iVar++)
187+
PrimVar_j[iVar] = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, iVar, jVertex);
188+
189+
/*--- Get the weight computed in the interpolator class for the j-th donor vertex ---*/
190+
191+
const su2double weight = solver_container[FLOW_SOL]->GetSlidingState(iMarker, iVertex, nPrimVar, jVertex);
192+
193+
/*--- Set primitive variables ---*/
194+
195+
conv_numerics->SetPrimitive( PrimVar_i, PrimVar_j.data() );
196+
197+
/*--- Set the scalar variable states ---*/
198+
199+
for (auto iVar = 0u; iVar < nVar; ++iVar)
200+
solution_j[iVar] = GetSlidingState(iMarker, iVertex, iVar, jVertex);
201+
202+
conv_numerics->SetScalarVar(nodes->GetSolution(iPoint), solution_j);
203+
204+
/*--- Set the normal vector ---*/
205+
206+
conv_numerics->SetNormal(Normal);
207+
208+
if (dynamic_grid)
209+
conv_numerics->SetGridVel(geometry->nodes->GetGridVel(iPoint), geometry->nodes->GetGridVel(iPoint));
210+
211+
auto residual = conv_numerics->ComputeResidual(config);
212+
213+
/*--- Accumulate the residuals to compute the average ---*/
214+
215+
for (auto iVar = 0u; iVar < nVar; iVar++) {
216+
LinSysRes(iPoint,iVar) += weight*residual[iVar];
217+
for (auto jVar = 0u; jVar < nVar; jVar++)
218+
Jacobian_i[iVar*nVar+jVar] += SU2_TYPE::GetValue(weight*residual.jacobian_i[iVar][jVar]);
219+
}
220+
}
221+
222+
/*--- Set the normal vector and the coordinates ---*/
223+
224+
visc_numerics->SetNormal(Normal);
225+
su2double Coord_Reflected[MAXNDIM];
226+
GeometryToolbox::PointPointReflect(nDim, geometry->nodes->GetCoord(Point_Normal),
227+
geometry->nodes->GetCoord(iPoint), Coord_Reflected);
228+
visc_numerics->SetCoord(geometry->nodes->GetCoord(iPoint), Coord_Reflected);
229+
230+
/*--- Primitive variables ---*/
231+
232+
visc_numerics->SetPrimitive(PrimVar_i, PrimVar_j.data());
233+
234+
/*--- Scalar variables and their gradients ---*/
235+
236+
visc_numerics->SetScalarVar(nodes->GetSolution(iPoint), solution_j);
237+
visc_numerics->SetScalarVarGradient(nodes->GetGradient(iPoint), nodes->GetGradient(iPoint));
238+
239+
/*--- Allow derived solvers to set more variables in numerics. ---*/
240+
241+
SolverSpecificNumerics(iPoint);
242+
243+
/*--- Compute and update residual ---*/
244+
245+
auto residual = visc_numerics->ComputeResidual(config);
246+
247+
LinSysRes.SubtractBlock(iPoint, residual);
248+
249+
/*--- Jacobian contribution for implicit integration ---*/
250+
251+
Jacobian.SubtractBlock2Diag(iPoint, residual.jacobian_i);
252+
253+
}
254+
END_SU2_OMP_FOR
255+
}
256+
}
257+
138258
/*!
139259
* \brief Gradient and Limiter computation.
140260
* \param[in] geometry - Geometrical definition of the problem.
@@ -255,6 +375,20 @@ class CScalarSolver : public CSolver {
255375
*/
256376
void BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, CConfig* config) final;
257377

378+
/*!
379+
* \brief Impose the fluid interface boundary condition using transfer data.
380+
* \param[in] geometry - Geometrical definition of the problem.
381+
* \param[in] solver_container - Container vector with all the solutions.
382+
* \param[in] conv_numerics - Description of the numerical method.
383+
* \param[in] visc_numerics - Description of the numerical method.
384+
* \param[in] config - Definition of the particular problem.
385+
*/
386+
void BC_Fluid_Interface(CGeometry *geometry, CSolver **solver_container, CNumerics *conv_numerics,
387+
CNumerics *visc_numerics, CConfig *config) override {
388+
/*--- By default instantiate the generic implementation w/o extra variables, derived solvers can override. ---*/
389+
BC_Fluid_Interface_impl([](unsigned long){}, geometry, solver_container, conv_numerics, visc_numerics, config);
390+
}
391+
258392
/*!
259393
* \brief Set the solution using the Freestream values.
260394
* \param[in] config - Definition of the particular problem.
@@ -326,4 +460,71 @@ class CScalarSolver : public CSolver {
326460
* \brief Scalar solvers support OpenMP+MPI.
327461
*/
328462
inline bool GetHasHybridParallel() const override { return true; }
463+
464+
/*!
465+
* \brief Get the outer state for fluid interface nodes.
466+
* \param[in] val_marker - marker index
467+
* \param[in] val_vertex - vertex index
468+
* \param[in] val_state - requested state component
469+
* \param[in] donor_index- index of the donor node to get
470+
*/
471+
inline su2double GetSlidingState(unsigned short val_marker,
472+
unsigned long val_vertex,
473+
unsigned short val_state,
474+
unsigned long donor_index) const final {
475+
return SlidingState[val_marker][val_vertex][val_state][donor_index];
476+
}
477+
478+
/*!
479+
* \brief Allocates the final pointer of SlidingState depending on how many donor vertex donate to it. That number is stored in SlidingStateNodes[val_marker][val_vertex].
480+
* \param[in] val_marker - marker index
481+
* \param[in] val_vertex - vertex index
482+
*/
483+
inline void SetSlidingStateStructure(unsigned short val_marker, unsigned long val_vertex) final {
484+
int iVar;
485+
486+
for( iVar = 0; iVar < nVar+1; iVar++){
487+
if( SlidingState[val_marker][val_vertex][iVar] != nullptr )
488+
delete [] SlidingState[val_marker][val_vertex][iVar];
489+
}
490+
491+
for( iVar = 0; iVar < nVar+1; iVar++)
492+
SlidingState[val_marker][val_vertex][iVar] = new su2double[ GetnSlidingStates(val_marker, val_vertex) ];
493+
}
494+
495+
/*!
496+
* \brief Set the outer state for fluid interface nodes.
497+
* \param[in] val_marker - marker index
498+
* \param[in] val_vertex - vertex index
499+
* \param[in] val_state - requested state component
500+
* \param[in] donor_index - index of the donor node to set
501+
* \param[in] component - set value
502+
*/
503+
inline void SetSlidingState(unsigned short val_marker,
504+
unsigned long val_vertex,
505+
unsigned short val_state,
506+
unsigned long donor_index,
507+
su2double component) final {
508+
SlidingState[val_marker][val_vertex][val_state][donor_index] = component;
509+
}
510+
511+
/*!
512+
* \brief Set the number of outer state for fluid interface nodes.
513+
* \param[in] val_marker - marker index
514+
* \param[in] val_vertex - vertex index
515+
* \param[in] value - number of outer states
516+
*/
517+
inline void SetnSlidingStates(unsigned short val_marker,
518+
unsigned long val_vertex,
519+
int value) final { SlidingStateNodes[val_marker][val_vertex] = value; }
520+
521+
/*!
522+
* \brief Get the number of outer state for fluid interface nodes.
523+
* \param[in] val_marker - marker index
524+
* \param[in] val_vertex - vertex index
525+
*/
526+
inline int GetnSlidingStates(unsigned short val_marker, unsigned long val_vertex) const final {
527+
return SlidingStateNodes[val_marker][val_vertex];
528+
}
529+
329530
};

SU2_CFD/include/solvers/CSpeciesSolver.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,25 @@ class CSpeciesSolver : public CScalarSolver<CSpeciesVariable> {
161161
*/
162162
void Source_Residual(CGeometry* geometry, CSolver** solver_container, CNumerics** numerics_container, CConfig* config,
163163
unsigned short iMesh) override;
164+
165+
166+
/*!
167+
* \brief Impose the fluid interface boundary condition using tranfer data.
168+
* \param[in] geometry - Geometrical definition of the problem.
169+
* \param[in] solver_container - Container vector with all the solutions.
170+
* \param[in] conv_numerics - Description of the numerical method.
171+
* \param[in] visc_numerics - Description of the numerical method.
172+
* \param[in] config - Definition of the particular problem.
173+
*/
174+
void BC_Fluid_Interface(CGeometry *geometry,
175+
CSolver **solver_container,
176+
CNumerics *conv_numerics,
177+
CNumerics *visc_numerics,
178+
CConfig *config) final {
179+
BC_Fluid_Interface_impl(
180+
[&](unsigned long iPoint) {
181+
visc_numerics->SetDiffusionCoeff(nodes->GetDiffusivity(iPoint), nodes->GetDiffusivity(iPoint));
182+
},
183+
geometry, solver_container, conv_numerics, visc_numerics, config);
184+
}
164185
};

SU2_CFD/include/solvers/CTurbSSTSolver.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,26 @@ class CTurbSSTSolver final : public CTurbSolver {
248248
CConfig *config,
249249
unsigned short val_marker) override;
250250

251+
/*!
252+
* \brief Impose the fluid interface boundary condition using tranfer data.
253+
* \param[in] geometry - Geometrical definition of the problem.
254+
* \param[in] solver_container - Container vector with all the solutions.
255+
* \param[in] conv_numerics - Description of the numerical method.
256+
* \param[in] visc_numerics - Description of the numerical method.
257+
* \param[in] config - Definition of the particular problem.
258+
*/
259+
void BC_Fluid_Interface(CGeometry *geometry,
260+
CSolver **solver_container,
261+
CNumerics *conv_numerics,
262+
CNumerics *visc_numerics,
263+
CConfig *config) final {
264+
BC_Fluid_Interface_impl(
265+
[&](unsigned long iPoint) {
266+
visc_numerics->SetF1blending(nodes->GetF1blending(iPoint), nodes->GetF1blending(iPoint));
267+
},
268+
geometry, solver_container, conv_numerics, visc_numerics, config);
269+
}
270+
251271
/*!
252272
* \brief Get the constants for the SST model.
253273
* \return A pointer to an array containing a set of constants

0 commit comments

Comments
 (0)