|
29 | 29 | #include <vector> |
30 | 30 |
|
31 | 31 | #include "../../../Common/include/parallelization/omp_structure.hpp" |
| 32 | +#include "../../../Common/include/toolboxes/geometry_toolbox.hpp" |
32 | 33 | #include "../variables/CScalarVariable.hpp" |
33 | 34 | #include "CSolver.hpp" |
34 | 35 |
|
@@ -57,6 +58,9 @@ class CScalarSolver : public CSolver { |
57 | 58 |
|
58 | 59 | const bool Conservative; /*!< \brief Transported Variable is conservative. Solution has to be multiplied with rho. */ |
59 | 60 |
|
| 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 | + |
60 | 64 | /*--- Shallow copy of grid coloring for OpenMP parallelization. ---*/ |
61 | 65 |
|
62 | 66 | #ifdef HAVE_OMP |
@@ -135,6 +139,122 @@ class CScalarSolver : public CSolver { |
135 | 139 | } |
136 | 140 | } |
137 | 141 |
|
| 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 | + |
138 | 258 | /*! |
139 | 259 | * \brief Gradient and Limiter computation. |
140 | 260 | * \param[in] geometry - Geometrical definition of the problem. |
@@ -255,6 +375,20 @@ class CScalarSolver : public CSolver { |
255 | 375 | */ |
256 | 376 | void BC_Periodic(CGeometry* geometry, CSolver** solver_container, CNumerics* numerics, CConfig* config) final; |
257 | 377 |
|
| 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 | + |
258 | 392 | /*! |
259 | 393 | * \brief Set the solution using the Freestream values. |
260 | 394 | * \param[in] config - Definition of the particular problem. |
@@ -326,4 +460,71 @@ class CScalarSolver : public CSolver { |
326 | 460 | * \brief Scalar solvers support OpenMP+MPI. |
327 | 461 | */ |
328 | 462 | 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 | + |
329 | 530 | }; |
0 commit comments