3535
3636#include " ../../../Common/include/CConfig.hpp"
3737#include " ../../../Common/include/linear_algebra/blas_structure.hpp"
38+ #include " ../../../Common/include/toolboxes/geometry_toolbox.hpp"
3839
3940class CElement ;
4041class CFluidModel ;
@@ -46,7 +47,7 @@ class CFluidModel;
4647 */
4748class CNumerics {
4849protected:
49- enum : size_t { MAXNDIM = 3 } ; /* !< \brief Max number of space dimensions, used in some static arrays. */
50+ static constexpr size_t MAXNDIM = 3 ; /* !< \brief Max number of space dimensions, used in some static arrays. */
5051
5152 unsigned short nDim, nVar; /* !< \brief Number of dimensions and variables. */
5253 su2double Gamma; /* !< \brief Fluid's Gamma constant (ratio of specific heats). */
@@ -1146,15 +1147,77 @@ class CNumerics {
11461147 /* !
11471148 * \brief Computation of the matrix P, this matrix diagonalize the conservative Jacobians in
11481149 * the form $P^{-1}(A.Normal)P=Lambda$.
1149- * \param[in] val_density - Value of the density.
1150- * \param[in] val_velocity - Value of the velocity.
1151- * \param[in] val_soundspeed - Value of the sound speed.
1152- * \param[in] val_normal - Normal vector, the norm of the vector is the area of the face.
1153- * \param[out] val_p_tensor - Pointer to the P matrix.
1154- */
1155- void GetPMatrix (const su2double *val_density, const su2double *val_velocity,
1156- const su2double *val_soundspeed, const su2double *val_normal,
1157- su2double **val_p_tensor) const ;
1150+ * \param[in] density - Value of the density.
1151+ * \param[in] velocity - Velocity vector.
1152+ * \param[in] soundspeed - Value of the sound speed.
1153+ * \param[in] normal - Normal vector, the norm of the vector is the area of the face.
1154+ * \param[out] p_tensor - P matrix.
1155+ */
1156+ template <typename Matrix>
1157+ void GetPMatrix (const su2double& density, const su2double* velocity,
1158+ const su2double& soundspeed, const su2double* normal,
1159+ Matrix& p_tensor) const {
1160+ const su2double rhooc = density / soundspeed;
1161+ const su2double rhoxc = density * soundspeed;
1162+
1163+ if (nDim == 2 ) {
1164+ const su2double ke = 0.5 * GeometryToolbox::SquaredNorm (2 , velocity);
1165+ const su2double projvel = GeometryToolbox::DotProduct (2 , velocity, normal);
1166+
1167+ p_tensor[0 ][0 ] = 1.0 ;
1168+ p_tensor[0 ][1 ] = 0.0 ;
1169+ p_tensor[0 ][2 ] = 0.5 * rhooc;
1170+ p_tensor[0 ][3 ] = 0.5 * rhooc;
1171+
1172+ p_tensor[1 ][0 ] = velocity[0 ];
1173+ p_tensor[1 ][1 ] = density * normal[1 ];
1174+ p_tensor[1 ][2 ] = 0.5 * (velocity[0 ] * rhooc + normal[0 ] * density);
1175+ p_tensor[1 ][3 ] = 0.5 * (velocity[0 ] * rhooc - normal[0 ] * density);
1176+
1177+ p_tensor[2 ][0 ] = velocity[1 ];
1178+ p_tensor[2 ][1 ] = -density * normal[0 ];
1179+ p_tensor[2 ][2 ] = 0.5 * (velocity[1 ] * rhooc + normal[1 ] * density);
1180+ p_tensor[2 ][3 ] = 0.5 * (velocity[1 ] * rhooc - normal[1 ] * density);
1181+
1182+ p_tensor[3 ][0 ] = ke;
1183+ p_tensor[3 ][1 ] = density * (velocity[0 ] * normal[1 ] - velocity[1 ] * normal[0 ]);
1184+ p_tensor[3 ][2 ] = 0.5 * (ke * rhooc + density * projvel + rhoxc / Gamma_Minus_One);
1185+ p_tensor[3 ][3 ] = 0.5 * (ke * rhooc - density * projvel + rhoxc / Gamma_Minus_One);
1186+ } else {
1187+ const su2double ke = 0.5 * GeometryToolbox::SquaredNorm (3 , velocity);
1188+ const su2double projvel = GeometryToolbox::DotProduct (3 , velocity, normal);
1189+
1190+ p_tensor[0 ][0 ] = normal[0 ];
1191+ p_tensor[0 ][1 ] = normal[1 ];
1192+ p_tensor[0 ][2 ] = normal[2 ];
1193+ p_tensor[0 ][3 ] = 0.5 * rhooc;
1194+ p_tensor[0 ][4 ] = 0.5 * rhooc;
1195+
1196+ p_tensor[1 ][0 ] = velocity[0 ] * normal[0 ];
1197+ p_tensor[1 ][1 ] = velocity[0 ] * normal[1 ] - density * normal[2 ];
1198+ p_tensor[1 ][2 ] = velocity[0 ] * normal[2 ] + density * normal[1 ];
1199+ p_tensor[1 ][3 ] = 0.5 * (velocity[0 ] * rhooc + density * normal[0 ]);
1200+ p_tensor[1 ][4 ] = 0.5 * (velocity[0 ] * rhooc - density * normal[0 ]);
1201+
1202+ p_tensor[2 ][0 ] = velocity[1 ] * normal[0 ] + density * normal[2 ];
1203+ p_tensor[2 ][1 ] = velocity[1 ] * normal[1 ];
1204+ p_tensor[2 ][2 ] = velocity[1 ] * normal[2 ] - density * normal[0 ];
1205+ p_tensor[2 ][3 ] = 0.5 * (velocity[1 ] * rhooc + density * normal[1 ]);
1206+ p_tensor[2 ][4 ] = 0.5 * (velocity[1 ] * rhooc - density * normal[1 ]);
1207+
1208+ p_tensor[3 ][0 ] = velocity[2 ] * normal[0 ] - density * normal[1 ];
1209+ p_tensor[3 ][1 ] = velocity[2 ] * normal[1 ] + density * normal[0 ];
1210+ p_tensor[3 ][2 ] = velocity[2 ] * normal[2 ];
1211+ p_tensor[3 ][3 ] = 0.5 * (velocity[2 ] * rhooc + density * normal[2 ]);
1212+ p_tensor[3 ][4 ] = 0.5 * (velocity[2 ] * rhooc - density * normal[2 ]);
1213+
1214+ p_tensor[4 ][0 ] = ke * normal[0 ] + density * (velocity[1 ] * normal[2 ] - velocity[2 ] * normal[1 ]);
1215+ p_tensor[4 ][1 ] = ke * normal[1 ] + density * (velocity[2 ] * normal[0 ] - velocity[0 ] * normal[2 ]);
1216+ p_tensor[4 ][2 ] = ke * normal[2 ] + density * (velocity[0 ] * normal[1 ] - velocity[1 ] * normal[0 ]);
1217+ p_tensor[4 ][3 ] = 0.5 * (ke * rhooc + density * projvel + rhoxc / Gamma_Minus_One);
1218+ p_tensor[4 ][4 ] = 0.5 * (ke * rhooc - density * projvel + rhoxc / Gamma_Minus_One);
1219+ }
1220+ }
11581221
11591222 /* !
11601223 * \brief Computation of the matrix Rinv*Pe.
@@ -1261,15 +1324,83 @@ class CNumerics {
12611324 /* !
12621325 * \brief Computation of the matrix P^{-1}, this matrix diagonalize the conservative Jacobians
12631326 * in the form $P^{-1}(A.Normal)P=Lambda$.
1264- * \param[in] val_density - Value of the density.
1265- * \param[in] val_velocity - Value of the velocity.
1266- * \param[in] val_soundspeed - Value of the sound speed.
1267- * \param[in] val_normal - Normal vector, the norm of the vector is the area of the face.
1268- * \param[out] val_invp_tensor - Pointer to inverse of the P matrix.
1269- */
1270- void GetPMatrix_inv (const su2double *val_density, const su2double *val_velocity,
1271- const su2double *val_soundspeed, const su2double *val_normal,
1272- su2double **val_invp_tensor) const ;
1327+ * \param[in] density - Value of the density.
1328+ * \param[in] velocity - Velocity vector.
1329+ * \param[in] soundspeed - Value of the sound speed.
1330+ * \param[in] normal - Normal vector, the norm of the vector is the area of the face.
1331+ * \param[out] inv_p_tensor - Pointer to inverse of the P matrix.
1332+ */
1333+ template <typename Matrix>
1334+ void GetPMatrix_inv (const su2double& density, const su2double* velocity,
1335+ const su2double& soundspeed, const su2double* normal,
1336+ Matrix& inv_p_tensor) const {
1337+ const su2double rhoxc = density * soundspeed;
1338+ const su2double c2 = pow (soundspeed, 2 );
1339+ const su2double gm1 = Gamma_Minus_One;
1340+ const su2double k0orho = normal[0 ] / density;
1341+ const su2double k1orho = normal[1 ] / density;
1342+ const su2double gm1_o_c2 = gm1 / c2;
1343+ const su2double gm1_o_rhoxc = gm1 / rhoxc;
1344+
1345+ if (nDim == 3 ) {
1346+ const su2double k2orho = normal[2 ] / density;
1347+ const su2double ke = 0.5 * GeometryToolbox::SquaredNorm (3 , velocity);
1348+ const su2double projvel_o_rho = GeometryToolbox::DotProduct (3 , velocity, normal) / density;
1349+
1350+ inv_p_tensor[0 ][0 ] = normal[0 ] + k1orho * velocity[2 ] - k2orho * velocity[1 ] - normal[0 ] * gm1_o_c2 * ke;
1351+ inv_p_tensor[0 ][1 ] = normal[0 ] * gm1_o_c2 * velocity[0 ];
1352+ inv_p_tensor[0 ][2 ] = k2orho + normal[0 ] * gm1_o_c2 * velocity[1 ];
1353+ inv_p_tensor[0 ][3 ] = -k1orho + normal[0 ] * gm1_o_c2 * velocity[2 ];
1354+ inv_p_tensor[0 ][4 ] = -normal[0 ] * gm1_o_c2;
1355+
1356+ inv_p_tensor[1 ][0 ] = normal[1 ] + k2orho * velocity[0 ] - k0orho * velocity[2 ] - normal[1 ] * gm1_o_c2 * ke;
1357+ inv_p_tensor[1 ][1 ] = -k2orho + normal[1 ] * gm1_o_c2 * velocity[0 ];
1358+ inv_p_tensor[1 ][2 ] = normal[1 ] * gm1_o_c2 * velocity[1 ];
1359+ inv_p_tensor[1 ][3 ] = k0orho + normal[1 ] * gm1_o_c2 * velocity[2 ];
1360+ inv_p_tensor[1 ][4 ] = -normal[1 ] * gm1_o_c2;
1361+
1362+ inv_p_tensor[2 ][0 ] = normal[2 ] + k0orho * velocity[1 ] - k1orho * velocity[0 ] - normal[2 ] * gm1_o_c2 * ke;
1363+ inv_p_tensor[2 ][1 ] = k1orho + normal[2 ] * gm1_o_c2 * velocity[0 ];
1364+ inv_p_tensor[2 ][2 ] = -k0orho + normal[2 ] * gm1_o_c2 * velocity[1 ];
1365+ inv_p_tensor[2 ][3 ] = normal[2 ] * gm1_o_c2 * velocity[2 ];
1366+ inv_p_tensor[2 ][4 ] = -normal[2 ] * gm1_o_c2;
1367+
1368+ inv_p_tensor[3 ][0 ] = -projvel_o_rho + gm1_o_rhoxc * ke;
1369+ inv_p_tensor[3 ][1 ] = k0orho - gm1_o_rhoxc * velocity[0 ];
1370+ inv_p_tensor[3 ][2 ] = k1orho - gm1_o_rhoxc * velocity[1 ];
1371+ inv_p_tensor[3 ][3 ] = k2orho - gm1_o_rhoxc * velocity[2 ];
1372+ inv_p_tensor[3 ][4 ] = gm1_o_rhoxc;
1373+
1374+ inv_p_tensor[4 ][0 ] = projvel_o_rho + gm1_o_rhoxc * ke;
1375+ inv_p_tensor[4 ][1 ] = -k0orho - gm1_o_rhoxc * velocity[0 ];
1376+ inv_p_tensor[4 ][2 ] = -k1orho - gm1_o_rhoxc * velocity[1 ];
1377+ inv_p_tensor[4 ][3 ] = -k2orho - gm1_o_rhoxc * velocity[2 ];
1378+ inv_p_tensor[4 ][4 ] = gm1_o_rhoxc;
1379+ } else {
1380+ const su2double ke = 0.5 * GeometryToolbox::SquaredNorm (2 , velocity);
1381+ const su2double projvel_o_rho = GeometryToolbox::DotProduct (2 , velocity, normal) / density;
1382+
1383+ inv_p_tensor[0 ][0 ] = 1 - gm1_o_c2 * ke;
1384+ inv_p_tensor[0 ][1 ] = gm1_o_c2 * velocity[0 ];
1385+ inv_p_tensor[0 ][2 ] = gm1_o_c2 * velocity[1 ];
1386+ inv_p_tensor[0 ][3 ] = -gm1_o_c2;
1387+
1388+ inv_p_tensor[1 ][0 ] = -k1orho * velocity[0 ] + k0orho * velocity[1 ];
1389+ inv_p_tensor[1 ][1 ] = k1orho;
1390+ inv_p_tensor[1 ][2 ] = -k0orho;
1391+ inv_p_tensor[1 ][3 ] = 0 ;
1392+
1393+ inv_p_tensor[2 ][0 ] = -projvel_o_rho + gm1_o_rhoxc * ke;
1394+ inv_p_tensor[2 ][1 ] = k0orho - gm1_o_rhoxc * velocity[0 ];
1395+ inv_p_tensor[2 ][2 ] = k1orho - gm1_o_rhoxc * velocity[1 ];
1396+ inv_p_tensor[2 ][3 ] = gm1_o_rhoxc;
1397+
1398+ inv_p_tensor[3 ][0 ] = projvel_o_rho + gm1_o_rhoxc * ke;
1399+ inv_p_tensor[3 ][1 ] = -k0orho - gm1_o_rhoxc * velocity[0 ];
1400+ inv_p_tensor[3 ][2 ] = -k1orho - gm1_o_rhoxc * velocity[1 ];
1401+ inv_p_tensor[3 ][3 ] = gm1_o_rhoxc;
1402+ }
1403+ }
12731404
12741405 /* !
12751406 * \brief Compute viscous residual and jacobian.
0 commit comments