Skip to content

Commit 87fd85e

Browse files
committed
update density implementation for flow solver
1 parent e683930 commit 87fd85e

File tree

15 files changed

+154
-31
lines changed

15 files changed

+154
-31
lines changed

Common/include/option_structure.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,6 +2565,7 @@ enum class MPI_QUANTITIES {
25652565
SOLUTION_FEA , /*!< \brief FEA solution communication. */
25662566
MESH_DISPLACEMENTS , /*!< \brief Mesh displacements at the interface. */
25672567
SOLUTION_TIME_N , /*!< \brief Solution at time n. */
2568+
// DENSITY_TIME_N , /*!< \brief Density at time n. */
25682569
SOLUTION_TIME_N1 , /*!< \brief Solution at time n-1. */
25692570
};
25702571

SU2_CFD/include/solvers/CFVMFlowSolverBase.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,9 @@ class CFVMFlowSolverBase : public CSolver {
991991
for (unsigned short iVar = 0; iVar < nVar; iVar++) {
992992
nodes->AddSolution(iPoint, iVar, nodes->GetUnderRelaxation(iPoint)*LinSysSol[iPoint*nVar+iVar]);
993993
}
994+
// nijso: here we can update the density (for incompressible euler including energy equation)
995+
// but: we do not need the intermediate density fields actually.
996+
nodes->AddDensity(iPoint,0,nodes->GetDensity(iPoint));
994997
}
995998
END_SU2_OMP_FOR
996999
}

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,8 @@ void CFVMFlowSolverBase<V, R>::ImplicitEuler_Iteration(CGeometry *geometry, CSol
613613
END_SU2_OMP_SAFE_GLOBAL_ACCESS
614614

615615
CompleteImplicitIteration(geometry, nullptr, config);
616+
617+
// can we update density here?
616618
}
617619

618620
template <class V, ENUM_REGIME R>
@@ -1065,10 +1067,14 @@ void CFVMFlowSolverBase<V, R>::PushSolutionBackInTime(unsigned long TimeIter, bo
10651067
CConfig* config) {
10661068
/*--- Push back the initial condition to previous solution containers
10671069
for a 1st-order restart or when simply initializing to freestream. ---*/
1068-
1070+
cout << "restart for unsteady solution" << endl;
10691071
for (unsigned short iMesh = 0; iMesh <= config->GetnMGLevels(); iMesh++) {
10701072
solver_container[iMesh][FLOW_SOL]->GetNodes()->Set_Solution_time_n();
1073+
// nijso:note only for second order!
10711074
solver_container[iMesh][FLOW_SOL]->GetNodes()->Set_Solution_time_n1();
1075+
//if ((config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE) && (config->GetEnergy_Equation()==true))
1076+
solver_container[iMesh][FLOW_SOL]->GetNodes()->Set_Density_time_n();
1077+
10721078
if (rans) {
10731079
solver_container[iMesh][TURB_SOL]->GetNodes()->Set_Solution_time_n();
10741080
solver_container[iMesh][TURB_SOL]->GetNodes()->Set_Solution_time_n1();
@@ -1574,7 +1580,7 @@ void CFVMFlowSolverBase<V, FlowRegime>::SetResidual_DualTime(CGeometry *geometry
15741580
TimeStep = config->GetDelta_UnstTimeND();
15751581

15761582
/*--- Compute the dual time-stepping source term for static meshes ---*/
1577-
1583+
cout << "setresidual_dualtime cfvmflowsolverbase" << endl;
15781584
if (!dynamic_grid) {
15791585

15801586
/*--- Loop over all nodes (excluding halos) ---*/

SU2_CFD/include/variables/CIncEulerVariable.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class CIncEulerVariable : public CFlowVariable {
7171

7272
VectorType Streamwise_Periodic_RecoveredPressure, /*!< \brief Recovered/Physical pressure [Pa] for streamwise periodic flow. */
7373
Streamwise_Periodic_RecoveredTemperature; /*!< \brief Recovered/Physical temperature [K] for streamwise periodic flow. */
74-
VectorType Density_time_n; /*!< \brief density at timestep n for time-dependent flow. */
75-
VectorType Cp_time_n; /*!< \brief Cp at timestep n for time-dependent flow. */
74+
//VectorType Density_time_n; /*!< \brief density at timestep n for time-dependent flow. */
75+
//VectorType Cp_time_n; /*!< \brief Cp at timestep n for time-dependent flow. */
7676

7777
public:
7878
/*!
@@ -85,7 +85,7 @@ class CIncEulerVariable : public CFlowVariable {
8585
* \param[in] nvar - Number of variables of the problem.
8686
* \param[in] config - Definition of the particular problem.
8787
*/
88-
CIncEulerVariable(su2double pressure, const su2double *velocity, su2double temperature,
88+
CIncEulerVariable(su2double density, su2double pressure, const su2double *velocity, su2double temperature,
8989
unsigned long npoint, unsigned long ndim, unsigned long nvar, const CConfig *config);
9090

9191
/*!

SU2_CFD/include/variables/CIncNSVariable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CIncNSVariable final : public CIncEulerVariable {
5252
* \param[in] nvar - Number of variables of the problem.
5353
* \param[in] config - Definition of the particular problem.
5454
*/
55-
CIncNSVariable(su2double pressure, const su2double *velocity, su2double temperature,
55+
CIncNSVariable(su2double density, su2double pressure, const su2double *velocity, su2double temperature,
5656
unsigned long npoint, unsigned long ndim, unsigned long nvar, const CConfig *config);
5757

5858
/*!

SU2_CFD/include/variables/CVariable.hpp

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class CVariable {
5353
using MatrixType = C2DContainer<unsigned long, su2double, StorageType::RowMajor, 64, DynamicSize, DynamicSize>;
5454

5555
MatrixType Solution; /*!< \brief Solution of the problem. */
56+
// necessary?
57+
VectorType Density; /*!< \brief Solution of the problem. */
5658
MatrixType Solution_Old; /*!< \brief Old solution of the problem R-K. */
5759

5860
MatrixType External; /*!< \brief External (outer) contribution in discrete adjoint multizone problems. */
@@ -67,7 +69,9 @@ class CVariable {
6769

6870
MatrixType Solution_time_n; /*!< \brief Solution of the problem at time n for dual-time stepping technique. */
6971
MatrixType Solution_time_n1; /*!< \brief Solution of the problem at time n-1 for dual-time stepping technique. */
72+
VectorType Density_time_n; /*!< \brief Solution of the problem at time n-1 for dual-time stepping technique. */
7073
VectorType Delta_Time; /*!< \brief Time step. */
74+
VectorType Cp_time_n; /*!< \brief Solution of the problem at time n-1 for dual-time stepping technique. */
7175

7276
CVectorOfMatrix Gradient; /*!< \brief Gradient of the solution of the problem. */
7377
C3DDoubleMatrix Rmatrix; /*!< \brief Geometry-based matrix for weighted least squares gradient calculations. */
@@ -270,6 +274,11 @@ class CVariable {
270274
*/
271275
void Set_Solution_time_n();
272276

277+
/*!
278+
* \brief Set the variable solution at time n.
279+
*/
280+
void Set_Density_time_n();
281+
273282
/*!
274283
* \brief Set the variable solution at time n-1.
275284
*/
@@ -280,6 +289,7 @@ class CVariable {
280289
* \param[in] iPoint - Point index.
281290
*/
282291
inline void Set_Solution_time_n(unsigned long iPoint, const su2double* val_sol) {
292+
cout <<"cvariable: set_solution_time_n" << endl;
283293
for (unsigned long iVar = 0; iVar < nVar; iVar++) Solution_time_n(iPoint,iVar) = val_sol[iVar];
284294
}
285295

@@ -297,8 +307,27 @@ class CVariable {
297307
* \param[in] iPoint - Point index.
298308
*/
299309
inline void Set_Solution_time_n(unsigned long iPoint, unsigned long iVar, su2double val_sol) {
310+
cout <<"cvariable: set_solution_time_n 111" << endl;
300311
Solution_time_n(iPoint,iVar) = val_sol;
301312
}
313+
/*!
314+
* \brief Set the variable solution at time n.
315+
* \param[in] iPoint - Point index.
316+
*/
317+
318+
inline void Set_Density_time_n(unsigned long iPoint, su2double val_sol) {
319+
Density_time_n(iPoint) = val_sol;
320+
}
321+
322+
/*!
323+
* \brief Add density.
324+
* \param[in] iPoint - Point index.
325+
* \param[in] iVar - Number of the variable.
326+
* \param[in] solution - Value that we want to add to the solution.
327+
*/
328+
inline void AddDensity(unsigned long iPoint, unsigned long iVar, su2double solution) {
329+
Density(iPoint) = solution;
330+
}
302331

303332
/*!
304333
* \brief Set the variable solution at time n-1.
@@ -462,14 +491,18 @@ class CVariable {
462491
* \return Reference to the solution matrix.
463492
*/
464493
inline const MatrixType& GetSolution() const { return Solution; }
465-
inline MatrixType& GetSolution() { return Solution; }
494+
inline MatrixType& GetSolution() {
495+
return Solution;
496+
}
466497

467498
/*!
468499
* \brief Get the solution of the problem.
469500
* \param[in] iPoint - Point index.
470501
* \return Pointer to the solution vector.
471502
*/
472-
inline su2double *GetSolution(unsigned long iPoint) { return Solution[iPoint]; }
503+
inline su2double *GetSolution(unsigned long iPoint) {
504+
return Solution[iPoint];
505+
}
473506

474507
/*!
475508
* \brief Get the old solution of the problem (Runge-Kutta method)
@@ -491,8 +524,23 @@ class CVariable {
491524
* \param[in] iPoint - Point index.
492525
* \return Pointer to the solution (at time n) vector.
493526
*/
494-
inline su2double *GetSolution_time_n(unsigned long iPoint) { return Solution_time_n[iPoint]; }
495-
inline MatrixType& GetSolution_time_n() { return Solution_time_n; }
527+
inline su2double *GetSolution_time_n(unsigned long iPoint) {
528+
return Solution_time_n[iPoint]; }
529+
inline MatrixType& GetSolution_time_n() {
530+
cout << "getsolution"<<endl;
531+
return Solution_time_n; }
532+
533+
/*!
534+
* \brief Get the solution at time n.
535+
* \param[in] iPoint - Point index.
536+
* \return Pointer to the solution (at time n) vector.
537+
*/
538+
// we do not use this, we use the one in cinceulervariable
539+
//inline su2double GetDensity_time_n(unsigned long iPoint) {
540+
// return Density_time_n[iPoint]; }
541+
//inline VectorType& GetDensity_time_n() {
542+
// cout << "getsolution"<<endl;
543+
// return Density_time_n; }
496544

497545
/*!
498546
* \brief Get the solution at time n-1.
@@ -2154,6 +2202,17 @@ class CVariable {
21542202
*/
21552203
void RegisterSolution_time_n1();
21562204

2205+
/*!
2206+
* \brief Register the Density_time_n array as input/output variable.
2207+
*/
2208+
//void RegisterDensity_time_n();
2209+
2210+
2211+
/*!
2212+
* \brief Register the variables in the solution_time_n1 array as input/output variable.
2213+
*/
2214+
//void RegisterDensity_time_n1();
2215+
21572216
/*!
21582217
* \brief Set the adjoint values of the solution.
21592218
* \param[in] adj_sol - The adjoint values of the solution.

SU2_CFD/src/integration/CIntegration.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,13 @@ void CIntegration::SetDualTime_Solver(const CGeometry *geometry, CSolver *solver
246246
SU2_OMP_PARALLEL
247247
{
248248
/*--- Store old solution ---*/
249+
// nijso: note that we only need time_n1 for second order timestepping, we can save some memory here.
249250
solver->GetNodes()->Set_Solution_time_n1();
250251
solver->GetNodes()->Set_Solution_time_n();
251252

253+
solver->GetNodes()->Set_Density_time_n();
254+
//solver->GetNodes()->Set_Density_time_n1();
255+
252256
SU2_OMP_SAFE_GLOBAL_ACCESS(solver->ResetCFLAdapt();)
253257

254258
SU2_OMP_FOR_STAT(roundUpDiv(geometry->GetnPoint(), omp_get_num_threads()))

SU2_CFD/src/solvers/CDiscAdjSolver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ void CDiscAdjSolver::RegisterSolution(CGeometry *geometry, CConfig *config) {
167167
if (time_n_needed)
168168
direct_solver->GetNodes()->RegisterSolution_time_n();
169169

170+
// nijso: we probably need this as well for adjoint unsteady incompressible with varying density...
171+
//if (time_n_needed)
172+
// direct_solver->GetNodes()->RegisterDensity_time_n();
173+
170174
if (time_n1_needed)
171175
direct_solver->GetNodes()->RegisterSolution_time_n1();
172176
}

SU2_CFD/src/solvers/CIncEulerSolver.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ CIncEulerSolver::CIncEulerSolver(CGeometry *geometry, CConfig *config, unsigned
208208
/*--- Initialize the solution to the far-field state everywhere. ---*/
209209

210210
if (navier_stokes) {
211-
nodes = new CIncNSVariable(Pressure_Inf, Velocity_Inf, Temperature_Inf, nPoint, nDim, nVar, config);
211+
nodes = new CIncNSVariable(Density_Inf, Pressure_Inf, Velocity_Inf, Temperature_Inf, nPoint, nDim, nVar, config);
212212
} else {
213-
nodes = new CIncEulerVariable(Pressure_Inf, Velocity_Inf, Temperature_Inf, nPoint, nDim, nVar, config);
213+
nodes = new CIncEulerVariable(Density_Inf, Pressure_Inf, Velocity_Inf, Temperature_Inf, nPoint, nDim, nVar, config);
214214
}
215215
SetBaseClassPointerToNodes();
216216

@@ -2717,16 +2717,18 @@ void CIncEulerSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver
27172717
//Cp_time_n = nodes->GetSpecificHeatCp(iPoint);
27182718

27192719
Density_time_n = nodes->GetDensity_time_n(iPoint);
2720-
Cp_time_n = nodes->GetCp_time_n(iPoint);
2720+
//Cp_time_n = nodes->GetCp_time_n(iPoint);
27212721

27222722

27232723

27242724
/*--- Compute the conservative variable vector for all time levels. ---*/
2725-
2725+
27262726
V2U(Density, Cp, V_time_nM1, U_time_nM1);
2727-
V2U(Density_time_n, Cp_time_n, V_time_n, U_time_n);
2727+
//V2U(Density_time_n, Cp_time_n, V_time_n, U_time_n);
2728+
V2U(Density_time_n, Cp, V_time_n, U_time_n);
27282729
V2U(Density, Cp, V_time_nP1, U_time_nP1);
2729-
2730+
if (iPoint == 10065)
2731+
cout << iPoint << ", " << Density << ", " << Density_time_n << ", " << V_time_nP1[0] << ", " << V_time_n[0] << endl;
27302732
/*--- CV volume at time n+1. As we are on a static mesh, the volume
27312733
of the CV will remained fixed for all time steps. ---*/
27322734

@@ -2909,15 +2911,15 @@ void CIncEulerSolver::SetResidual_DualTime(CGeometry *geometry, CSolver **solver
29092911

29102912

29112913
// update the density and cp
2912-
SU2_OMP_FOR_STAT(omp_chunk_size)
2913-
for (iPoint = 0; iPoint < nPointDomain; iPoint++) { // set density of time n to density of time n+1
2914-
Density = nodes->GetDensity(iPoint);
2915-
Cp = nodes->GetSpecificHeatCp(iPoint);
2916-
2917-
nodes->SetDensity_time_n(iPoint, Density);
2918-
nodes->SetCp_time_n(iPoint, Cp);
2919-
}
2920-
END_SU2_OMP_FOR
2914+
//SU2_OMP_FOR_STAT(omp_chunk_size)
2915+
//for (iPoint = 0; iPoint < nPointDomain; iPoint++) { // set density of time n to density of time n+1
2916+
// Density = nodes->GetDensity(iPoint);
2917+
// //Cp = nodes->GetSpecificHeatCp(iPoint);
2918+
2919+
// nodes->SetDensity_time_n(iPoint, Density);
2920+
//nodes->SetCp_time_n(iPoint, Cp);
2921+
//}
2922+
//END_SU2_OMP_FOR
29212923

29222924

29232925
}

SU2_CFD/src/solvers/CMeshSolver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ void CMeshSolver::RestartOldGeometry(CGeometry *geometry, const CConfig *config)
881881
for(unsigned short iStep = 1; iStep <= nSteps; ++iStep) {
882882

883883
MPI_QUANTITIES CommType = (iStep == 1) ? MPI_QUANTITIES::SOLUTION_TIME_N : MPI_QUANTITIES::SOLUTION_TIME_N1;
884+
//MPI_QUANTITIES CommType = (iStep == 1) ? MPI_QUANTITIES::DENSITY_TIME_N : MPI_QUANTITIES::DENSITY_TIME_N1;
884885

885886
/*--- Modify file name for an unsteady restart ---*/
886887
int Unst_RestartIter;

0 commit comments

Comments
 (0)