void CConvective_Template::ComputeResidual(double *val_residual, double **val_Jacobian_i, double **val_Jacobian_j, CConfig *config) { Area = 0; for (iDim = 0; iDim < nDim; iDim++) /*!< \brief Normal: Normal vector, it norm is the area of the face. */ Area += Normal[iDim]*Normal[iDim]; Area = sqrt(Area); /*! Area of the face*/ for (iDim = 0; iDim < nDim; iDim++) UnitNormal[iDim] = Normal[iDim]/Area; /* ! Unit Normal*/ /*--- Point i, Needs to recompute SoundSpeed / Pressure / Enthalpy in case of 2nd order reconstruction ---*/ Density_i = U_i[0]; sq_vel = 0; for (iDim = 0; iDim < nDim; iDim++) { Velocity_i[iDim] = U_i[iDim+1] / Density_i; sq_vel += Velocity_i[iDim]*Velocity_i[iDim]; } Energy_i = U_i[nDim+1] / Density_i; SoundSpeed_i = sqrt(Gamma*Gamma_Minus_One*(Energy_i-0.5*sq_vel)); Pressure_i = (SoundSpeed_i * SoundSpeed_i * Density_i) / Gamma; Enthalpy_i = (U_i[nDim+1] + Pressure_i) / Density_i; /*--- Point j, Needs to recompute SoundSpeed / Pressure / Enthalpy in case of 2nd order reconstruction ---*/ Density_j = U_j[0]; sq_vel = 0; for (iDim = 0; iDim < nDim; iDim++) { Velocity_j[iDim] = U_j[iDim+1] / Density_j; sq_vel += Velocity_j[iDim]*Velocity_j[iDim]; } Energy_j = U_j[nDim+1] / Density_j; SoundSpeed_j = sqrt(Gamma*Gamma_Minus_One*(Energy_j-0.5*sq_vel)); Pressure_j = (SoundSpeed_j * SoundSpeed_j * Density_j) / Gamma; Enthalpy_j = (U_j[nDim+1] + Pressure_j) / Density_j; /*--- Promediate Roe variables iPoint and jPoint ---*/ R = sqrt(Density_j/Density_i); RoeDensity = R*Density_i; sq_vel = 0; for (iDim = 0; iDim < nDim; iDim++) { RoeVelocity[iDim] = (R*Velocity_j[iDim]+Velocity_i[iDim])/(R+1); sq_vel += RoeVelocity[iDim]*RoeVelocity[iDim]; } RoeEnthalpy = (R*Enthalpy_j+Enthalpy_i)/(R+1); RoeSoundSpeed = sqrt((Gamma-1)*(RoeEnthalpy-0.5*sq_vel)); /*--- Compute Proj_flux_tensor_i ---*/ GetInviscidProjFlux(&Density_i, Velocity_i, &Pressure_i, &Enthalpy_i, Normal, Proj_flux_tensor_i); /*--- Compute Proj_flux_tensor_j ---*/ GetInviscidProjFlux(&Density_j, Velocity_j, &Pressure_j, &Enthalpy_j, Normal, Proj_flux_tensor_j); /*--- Compute P and Lambda (do it with the Normal) ---*/ GetPMatrix(&RoeDensity, RoeVelocity, &RoeSoundSpeed, UnitNormal, P_Tensor); ProjVelocity = 0.0; ProjVelocity_i = 0.0; ProjVelocity_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { ProjVelocity += RoeVelocity[iDim]*UnitNormal[iDim]; ProjVelocity_i += Velocity_i[iDim]*UnitNormal[iDim]; ProjVelocity_j += Velocity_j[iDim]*UnitNormal[iDim]; } /*--- Flow eigenvalues and Entropy correctors ---*/ for (iDim = 0; iDim < nDim; iDim++) { Lambda[iDim] = ProjVelocity; Epsilon[iDim] = 4.0*max(0.0, max(Lambda[iDim]-ProjVelocity_i,ProjVelocity_j-Lambda[iDim])); } Lambda[nVar-2] = ProjVelocity + RoeSoundSpeed; Epsilon[nVar-2] = 4.0*max(0.0, max(Lambda[nVar-2]-(ProjVelocity_i+SoundSpeed_i),(ProjVelocity_j+SoundSpeed_j)-Lambda[nVar-2])); Lambda[nVar-1] = ProjVelocity - RoeSoundSpeed; Epsilon[nVar-1] = 4.0*max(0.0, max(Lambda[nVar-1]-(ProjVelocity_i-SoundSpeed_i),(ProjVelocity_j-SoundSpeed_j)-Lambda[nVar-1])); /*--- Entropy correction ---*/ for (iVar = 0; iVar < nVar; iVar++) if ( fabs(Lambda[iVar]) < Epsilon[iVar] ) Lambda[iVar] = (Lambda[iVar]*Lambda[iVar] + Epsilon[iVar]*Epsilon[iVar])/(2.0*Epsilon[iVar]); else Lambda[iVar] = fabs(Lambda[iVar]); if (!implicit) { /*--- Compute wave amplitudes (characteristics) ---*/ proj_delta_vel = 0.0; for (iDim = 0; iDim < nDim; iDim++) { delta_vel[iDim] = Velocity_j[iDim] - Velocity_i[iDim]; proj_delta_vel += delta_vel[iDim]*Normal[iDim]; } delta_p = Pressure_j - Pressure_i; delta_rho = Density_j - Density_i; proj_delta_vel = proj_delta_vel/Area; if (nDim == 3) { delta_wave[0] = delta_rho - delta_p/(RoeSoundSpeed*RoeSoundSpeed); delta_wave[1] = UnitNormal[0]*delta_vel[2]-UnitNormal[2]*delta_vel[0]; delta_wave[2] = UnitNormal[1]*delta_vel[0]-UnitNormal[0]*delta_vel[1]; delta_wave[3] = proj_delta_vel + delta_p/(RoeDensity*RoeSoundSpeed); delta_wave[4] = -proj_delta_vel + delta_p/(RoeDensity*RoeSoundSpeed); } else { delta_wave[0] = delta_rho - delta_p/(RoeSoundSpeed*RoeSoundSpeed); delta_wave[1] = UnitNormal[1]*delta_vel[0]-UnitNormal[0]*delta_vel[1]; delta_wave[2] = proj_delta_vel + delta_p/(RoeDensity*RoeSoundSpeed); delta_wave[3] = -proj_delta_vel + delta_p/(RoeDensity*RoeSoundSpeed); } /*--- Roe's Flux approximation ---*/ for (iVar = 0; iVar < nVar; iVar++) { val_residual[iVar] = 0.5*(Proj_flux_tensor_i[iVar]+Proj_flux_tensor_j[iVar]); for (jVar = 0; jVar < nVar; jVar++) val_residual[iVar] -= 0.5*Lambda[jVar]*delta_wave[jVar]*P_Tensor[iVar][jVar]*Area; } } else { /*--- Compute inverse P ---*/ GetPMatrix_inv(&RoeDensity, RoeVelocity, &RoeSoundSpeed, UnitNormal, invP_Tensor); /*--- Jacobias of the inviscid flux, scale = 0.5 because val_resconv ~ 0.5*(fc_i+fc_j)*Normal ---*/ GetInviscidProjJac(Velocity_i, &Energy_i, Normal, 0.5, val_Jacobian_i); GetInviscidProjJac(Velocity_j, &Energy_j, Normal, 0.5, val_Jacobian_j); /*--- Diference variables iPoint and jPoint ---*/ for (iVar = 0; iVar < nVar; iVar++) Diff_U[iVar] = U_j[iVar]-U_i[iVar]; /*--- Roe's Flux approximation ---*/ for (iVar = 0; iVar < nVar; iVar++) { val_residual[iVar] = 0.5*(Proj_flux_tensor_i[iVar]+Proj_flux_tensor_j[iVar]); for (jVar = 0; jVar < nVar; jVar++) { Proj_ModJac_Tensor_ij = 0.0; /*--- Compute |Proj_ModJac_Tensor| = P x |Lambda| x inverse P ---*/ for (kVar = 0; kVar < nVar; kVar++) Proj_ModJac_Tensor_ij += P_Tensor[iVar][kVar]*Lambda[kVar]*invP_Tensor[kVar][jVar]; val_residual[iVar] -= 0.5*Proj_ModJac_Tensor_ij*Diff_U[jVar]*Area; val_Jacobian_i[iVar][jVar] += 0.5*Proj_ModJac_Tensor_ij*Area; val_Jacobian_j[iVar][jVar] -= 0.5*Proj_ModJac_Tensor_ij*Area; } } } }
void CCentJST_LinFlow::ComputeResidual (double *val_resconv, double *val_resvisc, double **val_Jacobian_i, double **val_Jacobian_j, CConfig *config) { /*--- Mean Values of the linealized variables ---*/ MeanDeltaRho = 0.5*(DeltaU_i[0]+DeltaU_j[0]); for (iDim = 0; iDim < nDim; iDim++) MeanDeltaVel[iDim] = 0.5*(DeltaU_i[iDim+1]+DeltaU_j[iDim+1]); MeanDeltaE = 0.5*(DeltaU_i[nVar-1]+DeltaU_j[nVar-1]); /*--- Values of the flow variables at point i ---*/ Density_i = U_i[0]; ProjVelocity_i = 0; Area = 0; sq_vel = 0; for (iDim = 0; iDim < nDim; iDim++) { Velocity_i[iDim] = U_i[iDim+1] / Density_i; ProjVelocity_i += Velocity_i[iDim]*Normal[iDim]; sq_vel += Velocity_i[iDim]*Velocity_i[iDim]; Area += Normal[iDim]*Normal[iDim]; } Area = sqrt(Area); DensityEnergy_i = U_i[nDim+1]; Energy_i = DensityEnergy_i / Density_i; SoundSpeed_i = sqrt(Gamma*Gamma_Minus_One*(Energy_i-0.5*sq_vel)); Pressure_i = (SoundSpeed_i * SoundSpeed_i * Density_i) / Gamma; Enthalpy_i = (DensityEnergy_i + Pressure_i) / Density_i; /*--- Values of the flow variables at point j ---*/ Density_j = U_j[0]; ProjVelocity_j = 0; sq_vel = 0; for (iDim = 0; iDim < nDim; iDim++) { Velocity_j[iDim] = U_j[iDim+1] / Density_j; ProjVelocity_j += Velocity_j[iDim]*Normal[iDim]; sq_vel += Velocity_j[iDim]*Velocity_j[iDim]; } DensityEnergy_j = U_j[nDim+1]; Energy_j = DensityEnergy_j / Density_j; SoundSpeed_j = sqrt(Gamma*Gamma_Minus_One*(Energy_j-0.5*sq_vel)); Pressure_j = (SoundSpeed_j * SoundSpeed_j * Density_j) / Gamma; Enthalpy_j = (DensityEnergy_j + Pressure_j) / Density_j; /*--- Mean values the flow variables ---*/ MeanDensity = 0.5*(Density_i + Density_j); for (iDim = 0; iDim < nDim; iDim++) MeanVelocity[iDim] = 0.5*(Velocity_j[iDim] + Velocity_i[iDim]); MeanPressure = 0.5*(Pressure_i + Pressure_j); MeanEnthalpy = 0.5*(Enthalpy_j+Enthalpy_i); MeanEnergy = 0.5*(Energy_j+Energy_i); /*--- Compute projected inviscid Jacobian (scale = 0.5 because val_resconv ~ 0.5*(fc_i+fc_j)*Normal) ---*/ GetInviscidProjJac(Velocity_i, &Energy_i, Normal, 0.5, Jacobian_i); GetInviscidProjJac(Velocity_j, &Energy_j, Normal, 0.5, Jacobian_j); /*--- Compute inviscid flux $Jacobian x DeltaU$ ---*/ for (iVar = 0; iVar < nVar; iVar++) { val_resconv[iVar] = 0.0; for (jVar = 0; jVar < nVar; jVar++) val_resconv[iVar] += Jacobian_i[iVar][jVar] * DeltaU_i[jVar] + Jacobian_j[iVar][jVar] * DeltaU_j[jVar]; } /*--- Computes differences btw. variables and Laplacians ---*/ for (iVar = 0; iVar < nVar; iVar++) Diff_Lapl[iVar] = Und_Lapl_i[iVar]-Und_Lapl_j[iVar]; /*--- Calcula el radio espectral local, Factor de stretching factor ---*/ Local_Lambda_i = (fabs(ProjVelocity_i)+SoundSpeed_i*Area); Local_Lambda_j = (fabs(ProjVelocity_j)+SoundSpeed_j*Area); MeanLambda = 0.5*(Local_Lambda_i+Local_Lambda_j); Phi_i = pow(0.5*max(0.0,(Lambda_i - MeanLambda)/(MeanLambda)), Param_p); Phi_j = pow(0.5*max(0.0,(Lambda_j - MeanLambda)/(MeanLambda)), Param_p); StretchingFactor = 4.0*Phi_i*Phi_j/(Phi_i+Phi_j); sc4 = 9.0/(double(Neighbor_i*(1+Neighbor_i))) + 9.0/(double(Neighbor_j*(1+Neighbor_j))); Epsilon_4 = Param_Kappa_4*sc4; for (iVar = 0; iVar < nVar; iVar++) val_resvisc[iVar] = -Epsilon_4*Diff_Lapl[iVar]*StretchingFactor*MeanLambda; }
void CUpwRoeTurkel_Flow::ComputeResidual(double *val_residual, double **val_Jacobian_i, double **val_Jacobian_j, CConfig *config) { /*--- Face area (norm or the normal vector) ---*/ Area = 0.0; for (iDim = 0; iDim < nDim; iDim++) Area += Normal[iDim]*Normal[iDim]; Area = sqrt(Area); /*-- Unit Normal ---*/ for (iDim = 0; iDim < nDim; iDim++) UnitNormal[iDim] = Normal[iDim]/Area; /*--- Primitive variables at point i ---*/ for (iDim = 0; iDim < nDim; iDim++) Velocity_i[iDim] = V_i[iDim+1]; Pressure_i = V_i[nDim+1]; Density_i = V_i[nDim+2]; Enthalpy_i = V_i[nDim+3]; Energy_i = Enthalpy_i - Pressure_i/Density_i; /*--- Primitive variables at point j ---*/ for (iDim = 0; iDim < nDim; iDim++) Velocity_j[iDim] = V_j[iDim+1]; Pressure_j = V_j[nDim+1]; Density_j = V_j[nDim+2]; Enthalpy_j = V_j[nDim+3]; Energy_j = Enthalpy_j - Pressure_j/Density_j; /*--- Recompute conservative variables ---*/ double U_i[5], U_j[5]; U_i[0] = Density_i; U_j[0] = Density_j; for (iDim = 0; iDim < nDim; iDim++) { U_i[iDim+1] = Density_i*Velocity_i[iDim]; U_j[iDim+1] = Density_j*Velocity_j[iDim]; } U_i[nDim+1] = Density_i*Energy_i; U_j[nDim+1] = Density_j*Energy_j; /*--- Roe-averaged variables at interface between i & j ---*/ R = sqrt(Density_j/Density_i); RoeDensity = R*Density_i; sq_vel = 0.0; for (iDim = 0; iDim < nDim; iDim++) { RoeVelocity[iDim] = (R*Velocity_j[iDim]+Velocity_i[iDim])/(R+1); sq_vel += RoeVelocity[iDim]*RoeVelocity[iDim]; } RoeEnthalpy = (R*Enthalpy_j+Enthalpy_i)/(R+1); RoeSoundSpeed = sqrt((Gamma-1)*(RoeEnthalpy-0.5*sq_vel)); RoePressure = RoeDensity/Gamma*RoeSoundSpeed*RoeSoundSpeed; /*--- Compute Proj_flux_tensor_i ---*/ GetInviscidProjFlux(&Density_i, Velocity_i, &Pressure_i, &Enthalpy_i, Normal, Proj_flux_tensor_i); /*--- Compute Proj_flux_tensor_j ---*/ GetInviscidProjFlux(&Density_j, Velocity_j, &Pressure_j, &Enthalpy_j, Normal, Proj_flux_tensor_j); ProjVelocity = 0.0; ProjVelocity_i = 0.0; ProjVelocity_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { ProjVelocity += RoeVelocity[iDim]*UnitNormal[iDim]; ProjVelocity_i += Velocity_i[iDim]*UnitNormal[iDim]; ProjVelocity_j += Velocity_j[iDim]*UnitNormal[iDim]; } /*--- First few flow eigenvalues of A.Normal with the normal---*/ for (iDim = 0; iDim < nDim; iDim++) Lambda[iDim] = ProjVelocity; local_Mach = sqrt(sq_vel)/RoeSoundSpeed; Beta = max(Beta_min,min(local_Mach,Beta_max)); Beta2 = Beta*Beta; one_m_Betasqr = 1.0 - Beta2; // 1-Beta*Beta one_p_Betasqr = 1.0 + Beta2; // 1+Beta*Beta sqr_one_m_Betasqr_Lam1 = pow((one_m_Betasqr*Lambda[0]),2); // [(1-Beta^2)*Lambda[0]]^2 sqr_two_Beta_c_Area = pow(2.0*Beta*RoeSoundSpeed*Area,2); // [2*Beta*c*Area]^2 /*--- The rest of the flow eigenvalues of preconditioned matrix---*/ Lambda[nVar-2] = 0.5 * ( one_p_Betasqr*Lambda[0] + sqrt( sqr_one_m_Betasqr_Lam1 + sqr_two_Beta_c_Area)); Lambda[nVar-1] = 0.5 * ( one_p_Betasqr*Lambda[0] - sqrt( sqr_one_m_Betasqr_Lam1 + sqr_two_Beta_c_Area)); s_hat = 1.0/Area * (Lambda[nVar-1] - Lambda[0]*Beta2); r_hat = 1.0/Area * (Lambda[nVar-2] - Lambda[0]*Beta2); t_hat = 0.5/Area * (Lambda[nVar-1] - Lambda[nVar-2]); rhoB2a2 = RoeDensity*Beta2*RoeSoundSpeed*RoeSoundSpeed; /*--- Diference variables iPoint and jPoint and absolute value of the eigen values---*/ for (iVar = 0; iVar < nVar; iVar++) { Diff_U[iVar] = U_j[iVar]-U_i[iVar]; Lambda[iVar] = fabs(Lambda[iVar]); } /*--- Compute the absolute Preconditioned Jacobian in entropic Variables (do it with the Unitary Normal) ---*/ GetPrecondJacobian(Beta2, r_hat, s_hat, t_hat, rhoB2a2, Lambda, UnitNormal, absPeJac); /*--- Compute the matrix from entropic variables to conserved variables ---*/ GetinvRinvPe(Beta2, RoeEnthalpy, RoeSoundSpeed, RoeDensity, RoeVelocity, invRinvPe); /*--- Compute the matrix from entropic variables to conserved variables ---*/ GetRMatrix(RoePressure, RoeSoundSpeed, RoeDensity, RoeVelocity, R_Tensor); if (implicit) { /*--- Jacobians of the inviscid flux, scaled by 0.5 because val_residual ~ 0.5*(fc_i+fc_j)*Normal ---*/ GetInviscidProjJac(Velocity_i, &Energy_i, Normal, 0.5, val_Jacobian_i); GetInviscidProjJac(Velocity_j, &Energy_j, Normal, 0.5, val_Jacobian_j); } for (iVar = 0; iVar < nVar; iVar ++){ for (jVar = 0; jVar < nVar; jVar ++) { Matrix[iVar][jVar] = 0.0; for (kVar = 0; kVar < nVar; kVar++) Matrix[iVar][jVar] += absPeJac[iVar][kVar]*R_Tensor[kVar][jVar]; } } for (iVar = 0; iVar < nVar; iVar ++){ for (jVar = 0; jVar < nVar; jVar ++) { Art_Visc[iVar][jVar] = 0.0; for (kVar = 0; kVar < nVar; kVar++) Art_Visc[iVar][jVar] += invRinvPe[iVar][kVar]*Matrix[kVar][jVar]; } } /*--- Roe's Flux approximation ---*/ for (iVar = 0; iVar < nVar; iVar++) { val_residual[iVar] = 0.5*(Proj_flux_tensor_i[iVar]+Proj_flux_tensor_j[iVar]); for (jVar = 0; jVar < nVar; jVar++) { val_residual[iVar] -= 0.5*Art_Visc[iVar][jVar]*Diff_U[jVar]; if (implicit) { val_Jacobian_i[iVar][jVar] += 0.5*Art_Visc[iVar][jVar]; val_Jacobian_j[iVar][jVar] -= 0.5*Art_Visc[iVar][jVar]; } } } }
void CUpwRoe_Flow::ComputeResidual(double *val_residual, double **val_Jacobian_i, double **val_Jacobian_j, CConfig *config) { /*--- Face area (norm or the normal vector) ---*/ Area = 0.0; for (iDim = 0; iDim < nDim; iDim++) Area += Normal[iDim]*Normal[iDim]; Area = sqrt(Area); /*-- Unit Normal ---*/ for (iDim = 0; iDim < nDim; iDim++) UnitNormal[iDim] = Normal[iDim]/Area; /*--- Primitive variables at point i ---*/ for (iDim = 0; iDim < nDim; iDim++) Velocity_i[iDim] = V_i[iDim+1]; Pressure_i = V_i[nDim+1]; Density_i = V_i[nDim+2]; Enthalpy_i = V_i[nDim+3]; Energy_i = Enthalpy_i - Pressure_i/Density_i; SoundSpeed_i = sqrt(Pressure_i*Gamma/Density_i); /*--- Primitive variables at point j ---*/ for (iDim = 0; iDim < nDim; iDim++) Velocity_j[iDim] = V_j[iDim+1]; Pressure_j = V_j[nDim+1]; Density_j = V_j[nDim+2]; Enthalpy_j = V_j[nDim+3]; Energy_j = Enthalpy_j - Pressure_j/Density_j; SoundSpeed_j = sqrt(Pressure_j*Gamma/Density_j); /*--- Recompute conservative variables ---*/ double U_i[5], U_j[5]; U_i[0] = Density_i; U_j[0] = Density_j; for (iDim = 0; iDim < nDim; iDim++) { U_i[iDim+1] = Density_i*Velocity_i[iDim]; U_j[iDim+1] = Density_j*Velocity_j[iDim]; } U_i[nDim+1] = Density_i*Energy_i; U_j[nDim+1] = Density_j*Energy_j; /*--- Roe-averaged variables at interface between i & j ---*/ R = sqrt(fabs(Density_j/Density_i)); RoeDensity = R*Density_i; sq_vel = 0; for (iDim = 0; iDim < nDim; iDim++) { RoeVelocity[iDim] = (R*Velocity_j[iDim]+Velocity_i[iDim])/(R+1); sq_vel += RoeVelocity[iDim]*RoeVelocity[iDim]; } RoeEnthalpy = (R*Enthalpy_j+Enthalpy_i)/(R+1); RoeSoundSpeed = sqrt((Gamma-1)*(RoeEnthalpy-0.5*sq_vel)); /*--- Compute Proj_flux_tensor_i ---*/ GetInviscidProjFlux(&Density_i, Velocity_i, &Pressure_i, &Enthalpy_i, Normal, Proj_flux_tensor_i); /*--- Compute Proj_flux_tensor_j ---*/ GetInviscidProjFlux(&Density_j, Velocity_j, &Pressure_j, &Enthalpy_j, Normal, Proj_flux_tensor_j); /*--- Compute P and Lambda (do it with the Normal) ---*/ GetPMatrix(&RoeDensity, RoeVelocity, &RoeSoundSpeed, UnitNormal, P_Tensor); ProjVelocity = 0.0; ProjVelocity_i = 0.0; ProjVelocity_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { ProjVelocity += RoeVelocity[iDim]*UnitNormal[iDim]; ProjVelocity_i += Velocity_i[iDim]*UnitNormal[iDim]; ProjVelocity_j += Velocity_j[iDim]*UnitNormal[iDim]; } /*--- Flow eigenvalues and entropy correctors ---*/ for (iDim = 0; iDim < nDim; iDim++) Lambda[iDim] = ProjVelocity; Lambda[nVar-2] = ProjVelocity + RoeSoundSpeed; Lambda[nVar-1] = ProjVelocity - RoeSoundSpeed; // /*--- Harten and Hyman (1983) entropy correction ---*/ // for (iDim = 0; iDim < nDim; iDim++) // Epsilon[iDim] = 4.0*max(0.0, max(Lambda[iDim]-ProjVelocity_i,ProjVelocity_j-Lambda[iDim])); // // Epsilon[nVar-2] = 4.0*max(0.0, max(Lambda[nVar-2]-(ProjVelocity_i+SoundSpeed_i),(ProjVelocity_j+SoundSpeed_j)-Lambda[nVar-2])); // Epsilon[nVar-1] = 4.0*max(0.0, max(Lambda[nVar-1]-(ProjVelocity_i-SoundSpeed_i),(ProjVelocity_j-SoundSpeed_j)-Lambda[nVar-1])); // // for (iVar = 0; iVar < nVar; iVar++) // if ( fabs(Lambda[iVar]) < Epsilon[iVar] ) // Lambda[iVar] = (Lambda[iVar]*Lambda[iVar] + Epsilon[iVar]*Epsilon[iVar])/(2.0*Epsilon[iVar]); // else // Lambda[iVar] = fabs(Lambda[iVar]); for (iVar = 0; iVar < nVar; iVar++) Lambda[iVar] = fabs(Lambda[iVar]); if (!implicit) { /*--- Compute wave amplitudes (characteristics) ---*/ proj_delta_vel = 0.0; for (iDim = 0; iDim < nDim; iDim++) { delta_vel[iDim] = Velocity_j[iDim] - Velocity_i[iDim]; proj_delta_vel += delta_vel[iDim]*Normal[iDim]; } delta_p = Pressure_j - Pressure_i; delta_rho = Density_j - Density_i; proj_delta_vel = proj_delta_vel/Area; if (nDim == 2) { delta_wave[0] = delta_rho - delta_p/(RoeSoundSpeed*RoeSoundSpeed); delta_wave[1] = UnitNormal[1]*delta_vel[0]-UnitNormal[0]*delta_vel[1]; delta_wave[2] = proj_delta_vel + delta_p/(RoeDensity*RoeSoundSpeed); delta_wave[3] = -proj_delta_vel + delta_p/(RoeDensity*RoeSoundSpeed); } else { delta_wave[0] = delta_rho - delta_p/(RoeSoundSpeed*RoeSoundSpeed); delta_wave[1] = UnitNormal[0]*delta_vel[2]-UnitNormal[2]*delta_vel[0]; delta_wave[2] = UnitNormal[1]*delta_vel[0]-UnitNormal[0]*delta_vel[1]; delta_wave[3] = proj_delta_vel + delta_p/(RoeDensity*RoeSoundSpeed); delta_wave[4] = -proj_delta_vel + delta_p/(RoeDensity*RoeSoundSpeed); } /*--- Roe's Flux approximation ---*/ for (iVar = 0; iVar < nVar; iVar++) { val_residual[iVar] = 0.5*(Proj_flux_tensor_i[iVar]+Proj_flux_tensor_j[iVar]); for (jVar = 0; jVar < nVar; jVar++) val_residual[iVar] -= 0.5*Lambda[jVar]*delta_wave[jVar]*P_Tensor[iVar][jVar]*Area; } } else { /*--- Compute inverse P ---*/ GetPMatrix_inv(&RoeDensity, RoeVelocity, &RoeSoundSpeed, UnitNormal, invP_Tensor); /*--- Jacobians of the inviscid flux, scaled by 0.5 because val_resconv ~ 0.5*(fc_i+fc_j)*Normal ---*/ GetInviscidProjJac(Velocity_i, &Energy_i, Normal, 0.5, val_Jacobian_i); GetInviscidProjJac(Velocity_j, &Energy_j, Normal, 0.5, val_Jacobian_j); /*--- Diference variables iPoint and jPoint ---*/ for (iVar = 0; iVar < nVar; iVar++) Diff_U[iVar] = U_j[iVar]-U_i[iVar]; /*--- Roe's Flux approximation ---*/ for (iVar = 0; iVar < nVar; iVar++) { val_residual[iVar] = 0.5*(Proj_flux_tensor_i[iVar]+Proj_flux_tensor_j[iVar]); for (jVar = 0; jVar < nVar; jVar++) { Proj_ModJac_Tensor_ij = 0.0; /*--- Compute |Proj_ModJac_Tensor| = P x |Lambda| x inverse P ---*/ for (kVar = 0; kVar < nVar; kVar++) Proj_ModJac_Tensor_ij += P_Tensor[iVar][kVar]*Lambda[kVar]*invP_Tensor[kVar][jVar]; val_residual[iVar] -= 0.5*Proj_ModJac_Tensor_ij*Diff_U[jVar]*Area; val_Jacobian_i[iVar][jVar] += 0.5*Proj_ModJac_Tensor_ij*Area; val_Jacobian_j[iVar][jVar] -= 0.5*Proj_ModJac_Tensor_ij*Area; } } } }
void CCentJST_Flow::ComputeResidual(double *val_residual, double **val_Jacobian_i, double **val_Jacobian_j, CConfig *config) { /*--- Pressure, density, enthalpy, energy, and velocity at points i and j ---*/ Pressure_i = V_i[nDim+1]; Pressure_j = V_j[nDim+1]; Density_i = V_i[nDim+2]; Density_j = V_j[nDim+2]; Enthalpy_i = V_i[nDim+3]; Enthalpy_j = V_j[nDim+3]; SoundSpeed_i = V_i[nDim+4]; SoundSpeed_j = V_j[nDim+4]; Energy_i = Enthalpy_i - Pressure_i/Density_i; Energy_j = Enthalpy_j - Pressure_j/Density_j; sq_vel_i = 0.0; sq_vel_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { Velocity_i[iDim] = V_i[iDim+1]; Velocity_j[iDim] = V_j[iDim+1]; sq_vel_i += 0.5*Velocity_i[iDim]*Velocity_i[iDim]; sq_vel_j += 0.5*Velocity_j[iDim]*Velocity_j[iDim]; } /*--- Recompute conservative variables ---*/ double U_i[5], U_j[5]; U_i[0] = Density_i; U_j[0] = Density_j; for (iDim = 0; iDim < nDim; iDim++) { U_i[iDim+1] = Density_i*Velocity_i[iDim]; U_j[iDim+1] = Density_j*Velocity_j[iDim]; } U_i[nDim+1] = Density_i*Energy_i; U_j[nDim+1] = Density_j*Energy_j; /*--- Compute mean values of the variables ---*/ MeanDensity = 0.5*(Density_i+Density_j); MeanPressure = 0.5*(Pressure_i+Pressure_j); MeanEnthalpy = 0.5*(Enthalpy_i+Enthalpy_j); for (iDim = 0; iDim < nDim; iDim++) MeanVelocity[iDim] = 0.5*(Velocity_i[iDim]+Velocity_j[iDim]); MeanEnergy = 0.5*(Energy_i+Energy_j); /*--- Get projected flux tensor ---*/ GetInviscidProjFlux(&MeanDensity, MeanVelocity, &MeanPressure, &MeanEnthalpy, Normal, Proj_flux_tensor); /*--- Residual of the inviscid flux ---*/ for (iVar = 0; iVar < nVar; iVar++) val_residual[iVar] = Proj_flux_tensor[iVar]; /*--- Jacobians of the inviscid flux, scale = 0.5 because val_residual ~ 0.5*(fc_i+fc_j)*Normal ---*/ if (implicit) { GetInviscidProjJac(MeanVelocity, &MeanEnergy, Normal, 0.5, val_Jacobian_i); for (iVar = 0; iVar < nVar; iVar++) for (jVar = 0; jVar < nVar; jVar++) val_Jacobian_j[iVar][jVar] = val_Jacobian_i[iVar][jVar]; } /*--- Computes differences btw. Laplacians and conservative variables, with a correction for the enthalpy ---*/ for (iVar = 0; iVar < nVar; iVar++) { Diff_Lapl[iVar] = Und_Lapl_i[iVar]-Und_Lapl_j[iVar]; Diff_U[iVar] = U_i[iVar]-U_j[iVar]; } Diff_U[nVar-1] = Density_i*Enthalpy_i-Density_j*Enthalpy_j; /*--- Compute the local spectral radius and the stretching factor ---*/ ProjVelocity_i = 0.0; ProjVelocity_j = 0.0; Area = 0.0; for (iDim = 0; iDim < nDim; iDim++) { ProjVelocity_i += Velocity_i[iDim]*Normal[iDim]; ProjVelocity_j += Velocity_j[iDim]*Normal[iDim]; Area += Normal[iDim]*Normal[iDim]; } Area = sqrt(Area); Local_Lambda_i = (fabs(ProjVelocity_i)+SoundSpeed_i*Area); Local_Lambda_j = (fabs(ProjVelocity_j)+SoundSpeed_j*Area); MeanLambda = 0.5*(Local_Lambda_i+Local_Lambda_j); Phi_i = pow(Lambda_i/(4.0*MeanLambda), Param_p); Phi_j = pow(Lambda_j/(4.0*MeanLambda), Param_p); StretchingFactor = 4.0*Phi_i*Phi_j/(Phi_i+Phi_j); sc2 = 3.0*(double(Neighbor_i)+double(Neighbor_j))/(double(Neighbor_i)*double(Neighbor_j)); sc4 = sc2*sc2/4.0; Epsilon_2 = Param_Kappa_2*0.5*(Sensor_i+Sensor_j)*sc2; Epsilon_4 = max(0.0, Param_Kappa_4-Epsilon_2)*sc4; /*--- Compute viscous part of the residual ---*/ for (iVar = 0; iVar < nVar; iVar++) val_residual[iVar] += (Epsilon_2*Diff_U[iVar] - Epsilon_4*Diff_Lapl[iVar])*StretchingFactor*MeanLambda; /*--- Jacobian computation ---*/ if (implicit) { cte_0 = (Epsilon_2 + Epsilon_4*double(Neighbor_i+1))*StretchingFactor*MeanLambda; cte_1 = (Epsilon_2 + Epsilon_4*double(Neighbor_j+1))*StretchingFactor*MeanLambda; for (iVar = 0; iVar < (nVar-1); iVar++) { val_Jacobian_i[iVar][iVar] += cte_0; val_Jacobian_j[iVar][iVar] -= cte_1; } /*--- Last row of Jacobian_i ---*/ val_Jacobian_i[nVar-1][0] += cte_0*Gamma_Minus_One*sq_vel_i; for (iDim = 0; iDim < nDim; iDim++) val_Jacobian_i[nVar-1][iDim+1] -= cte_0*Gamma_Minus_One*Velocity_i[iDim]; val_Jacobian_i[nVar-1][nVar-1] += cte_0*Gamma; /*--- Last row of Jacobian_j ---*/ val_Jacobian_j[nVar-1][0] -= cte_1*Gamma_Minus_One*sq_vel_j; for (iDim = 0; iDim < nDim; iDim++) val_Jacobian_j[nVar-1][iDim+1] += cte_1*Gamma_Minus_One*Velocity_j[iDim]; val_Jacobian_j[nVar-1][nVar-1] -= cte_1*Gamma; } }
void CUpwHLLC_Flow::ComputeResidual(double *val_residual, double **val_Jacobian_i, double **val_Jacobian_j, CConfig *config) { /*--- Face area (norm or the normal vector) ---*/ Area = 0.0; for (iDim = 0; iDim < nDim; iDim++) Area += Normal[iDim]*Normal[iDim]; Area = sqrt(Area); /*-- Unit Normal ---*/ for (iDim = 0; iDim < nDim; iDim++) UnitNormal[iDim] = Normal[iDim]/Area; /*--- Primitive variables at point i ---*/ sq_vel_i = 0.0; for (iDim = 0; iDim < nDim; iDim++) { Velocity_i[iDim] = V_i[iDim+1]; sq_vel_i += Velocity_i[iDim]*Velocity_i[iDim]; } Pressure_i = V_i[nDim+1]; Density_i = V_i[nDim+2]; Enthalpy_i = V_i[nDim+3]; Energy_i = Enthalpy_i - Pressure_i/Density_i; SoundSpeed_i = sqrt(Gamma*Gamma_Minus_One*(Energy_i-0.5*sq_vel_i)); /*--- Primitive variables at point j ---*/ sq_vel_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { Velocity_j[iDim] = V_j[iDim+1]; sq_vel_j += Velocity_j[iDim]*Velocity_j[iDim]; } Pressure_j = V_j[nDim+1]; Density_j = V_j[nDim+2]; Enthalpy_j = V_j[nDim+3]; Energy_j = Enthalpy_j - Pressure_j/Density_j; SoundSpeed_j = sqrt(Gamma*Gamma_Minus_One*(Energy_j-0.5*sq_vel_j)); /*--- Projected velocities ---*/ ProjVelocity_i = 0.0; ProjVelocity_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { ProjVelocity_i += Velocity_i[iDim]*UnitNormal[iDim]; ProjVelocity_j += Velocity_j[iDim]*UnitNormal[iDim]; } /*--- Roe's averaging ---*/ Rrho = sqrt(Density_j/Density_i); tmp = 1.0/(1.0+Rrho); for (iDim = 0; iDim < nDim; iDim++) velRoe[iDim] = tmp*(Velocity_i[iDim] + Velocity_j[iDim]*Rrho); uRoe = 0.0; for (iDim = 0; iDim < nDim; iDim++) uRoe += velRoe[iDim]*UnitNormal[iDim]; gamPdivRho = tmp*((Gamma*Pressure_i/Density_i+0.5*(Gamma-1.0)*sq_vel_i) + (Gamma*Pressure_j/Density_j+0.5*(Gamma-1.0)*sq_vel_j)*Rrho); sq_velRoe = 0.0; for (iDim = 0; iDim < nDim; iDim++) sq_velRoe += velRoe[iDim]*velRoe[iDim]; cRoe = sqrt(gamPdivRho - ((Gamma+Gamma)*0.5-1.0)*0.5*sq_velRoe); /*--- Speed of sound at L and R ---*/ sL = min(uRoe-cRoe, ProjVelocity_i-SoundSpeed_i); sR = max(uRoe+cRoe, ProjVelocity_j+SoundSpeed_j); /*--- speed of contact surface ---*/ sM = (Pressure_i-Pressure_j - Density_i*ProjVelocity_i*(sL-ProjVelocity_i) + Density_j*ProjVelocity_j*(sR-ProjVelocity_j)) /(Density_j*(sR-ProjVelocity_j)-Density_i*(sL-ProjVelocity_i)); /*--- Pressure at right and left (Pressure_j=Pressure_i) side of contact surface ---*/ pStar = Density_j * (ProjVelocity_j-sR)*(ProjVelocity_j-sM) + Pressure_j; if (sM >= 0.0) { if (sL > 0.0) { val_residual[0] = Density_i*ProjVelocity_i; for (iDim = 0; iDim < nDim; iDim++) val_residual[iDim+1] = Density_i*Velocity_i[iDim]*ProjVelocity_i + Pressure_i*UnitNormal[iDim]; val_residual[nVar-1] = Energy_i*Density_i*ProjVelocity_i + Pressure_i*ProjVelocity_i; } else { invSLmSs = 1.0/(sL-sM); sLmuL = sL-ProjVelocity_i; rhoSL = Density_i*sLmuL*invSLmSs; for (iDim = 0; iDim < nDim; iDim++) rhouSL[iDim] = (Density_i*Velocity_i[iDim]*sLmuL+(pStar-Pressure_i)*UnitNormal[iDim])*invSLmSs; eSL = (sLmuL*Energy_i*Density_i-Pressure_i*ProjVelocity_i+pStar*sM)*invSLmSs; val_residual[0] = rhoSL*sM; for (iDim = 0; iDim < nDim; iDim++) val_residual[iDim+1] = rhouSL[iDim]*sM + pStar*UnitNormal[iDim]; val_residual[nVar-1] = (eSL+pStar)*sM; } } else { if (sR >= 0.0) { invSRmSs = 1.0/(sR-sM); sRmuR = sR-ProjVelocity_j; rhoSR = Density_j*sRmuR*invSRmSs; for (iDim = 0; iDim < nDim; iDim++) rhouSR[iDim] = (Density_j*Velocity_j[iDim]*sRmuR+(pStar-Pressure_j)*UnitNormal[iDim])*invSRmSs; eSR = (sRmuR*Energy_j*Density_j-Pressure_j*ProjVelocity_j+pStar*sM)*invSRmSs; val_residual[0] = rhoSR*sM; for (iDim = 0; iDim < nDim; iDim++) val_residual[iDim+1] = rhouSR[iDim]*sM + pStar*UnitNormal[iDim]; val_residual[nVar-1] = (eSR+pStar)*sM; } else { val_residual[0] = Density_j*ProjVelocity_j; for (iDim = 0; iDim < nDim; iDim++) val_residual[iDim+1] = Density_j*Velocity_j[iDim]*ProjVelocity_j + Pressure_j*UnitNormal[iDim]; val_residual[nVar-1] = Energy_j*Density_j*ProjVelocity_j + Pressure_j*ProjVelocity_j; } } for (iVar = 0; iVar < nVar; iVar++) val_residual[iVar] *= Area; if (implicit) { /*--- Average Roe variables iPoint and jPoint ---*/ R = sqrt(Density_j/Density_i); RoeDensity = R*Density_i; sq_vel = 0.0; for (iDim = 0; iDim < nDim; iDim++) { RoeVelocity[iDim] = (R*Velocity_j[iDim]+Velocity_i[iDim])/(R+1); sq_vel += RoeVelocity[iDim]*RoeVelocity[iDim]; } RoeEnthalpy = (R*Enthalpy_j+Enthalpy_i)/(R+1); RoeSoundSpeed = sqrt((Gamma-1)*(RoeEnthalpy-0.5*sq_vel)); /*--- Compute P and Lambda (do it with the Normal) ---*/ GetPMatrix(&RoeDensity, RoeVelocity, &RoeSoundSpeed, UnitNormal, P_Tensor); ProjVelocity = 0.0; ProjVelocity_i = 0.0; ProjVelocity_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { ProjVelocity += RoeVelocity[iDim]*UnitNormal[iDim]; ProjVelocity_i += Velocity_i[iDim]*UnitNormal[iDim]; ProjVelocity_j += Velocity_j[iDim]*UnitNormal[iDim]; } /*--- Flow eigenvalues and Entropy correctors ---*/ for (iDim = 0; iDim < nDim; iDim++) Lambda[iDim] = ProjVelocity; Lambda[nVar-2] = ProjVelocity + RoeSoundSpeed; Lambda[nVar-1] = ProjVelocity - RoeSoundSpeed; /*--- Compute inverse P ---*/ GetPMatrix_inv(&RoeDensity, RoeVelocity, &RoeSoundSpeed, UnitNormal, invP_Tensor); /*--- Jacobias of the inviscid flux, scale = 0.5 because val_residual ~ 0.5*(fc_i+fc_j)*Normal ---*/ GetInviscidProjJac(Velocity_i, &Energy_i, Normal, 0.5, val_Jacobian_i); GetInviscidProjJac(Velocity_j, &Energy_j, Normal, 0.5, val_Jacobian_j); /*--- Roe's Flux approximation ---*/ for (iVar = 0; iVar < nVar; iVar++) { for (jVar = 0; jVar < nVar; jVar++) { Proj_ModJac_Tensor_ij = 0.0; /*--- Compute |Proj_ModJac_Tensor| = P x |Lambda| x inverse P ---*/ for (kVar = 0; kVar < nVar; kVar++) Proj_ModJac_Tensor_ij += P_Tensor[iVar][kVar]*fabs(Lambda[kVar])*invP_Tensor[kVar][jVar]; val_Jacobian_i[iVar][jVar] += 0.5*Proj_ModJac_Tensor_ij*Area; val_Jacobian_j[iVar][jVar] -= 0.5*Proj_ModJac_Tensor_ij*Area; } } } }
void CUpwAUSM_Flow::ComputeResidual(double *val_residual, double **val_Jacobian_i, double **val_Jacobian_j, CConfig *config) { /*--- Face area (norm or the normal vector) ---*/ Area = 0.0; for (iDim = 0; iDim < nDim; iDim++) Area += Normal[iDim]*Normal[iDim]; Area = sqrt(Area); /*-- Unit Normal ---*/ for (iDim = 0; iDim < nDim; iDim++) UnitNormal[iDim] = Normal[iDim]/Area; /*--- Primitive variables at point i ---*/ sq_vel = 0.0; for (iDim = 0; iDim < nDim; iDim++) { Velocity_i[iDim] = V_i[iDim+1]; sq_vel += Velocity_i[iDim]*Velocity_i[iDim]; } Pressure_i = V_i[nDim+1]; Density_i = V_i[nDim+2]; Enthalpy_i = V_i[nDim+3]; Energy_i = Enthalpy_i - Pressure_i/Density_i; SoundSpeed_i = sqrt(Gamma*Gamma_Minus_One*(Energy_i-0.5*sq_vel)); /*--- Primitive variables at point j ---*/ sq_vel = 0.0; for (iDim = 0; iDim < nDim; iDim++) { Velocity_j[iDim] = V_j[iDim+1]; sq_vel += Velocity_j[iDim]*Velocity_j[iDim]; } Pressure_j = V_j[nDim+1]; Density_j = V_j[nDim+2]; Enthalpy_j = V_j[nDim+3]; Energy_j = Enthalpy_j - Pressure_j/Density_j; SoundSpeed_j = sqrt(Gamma*Gamma_Minus_One*(Energy_j-0.5*sq_vel)); /*--- Projected velocities ---*/ ProjVelocity_i = 0.0; ProjVelocity_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { ProjVelocity_i += Velocity_i[iDim]*UnitNormal[iDim]; ProjVelocity_j += Velocity_j[iDim]*UnitNormal[iDim]; } mL = ProjVelocity_i/SoundSpeed_i; mR = ProjVelocity_j/SoundSpeed_j; if (fabs(mL) <= 1.0) mLP = 0.25*(mL+1.0)*(mL+1.0); else mLP = 0.5*(mL+fabs(mL)); if (fabs(mR) <= 1.0) mRM = -0.25*(mR-1.0)*(mR-1.0); else mRM = 0.5*(mR-fabs(mR)); mF = mLP + mRM; if (fabs(mL) <= 1.0) pLP = 0.25*Pressure_i*(mL+1.0)*(mL+1.0)*(2.0-mL); else pLP = 0.5*Pressure_i*(mL+fabs(mL))/mL; if (fabs(mR) <= 1.0) pRM = 0.25*Pressure_j*(mR-1.0)*(mR-1.0)*(2.0+mR); else pRM = 0.5*Pressure_j*(mR-fabs(mR))/mR; pF = pLP + pRM; Phi = fabs(mF); val_residual[0] = 0.5*(mF*((Density_i*SoundSpeed_i)+(Density_j*SoundSpeed_j))-Phi*((Density_j*SoundSpeed_j)-(Density_i*SoundSpeed_i))); for (iDim = 0; iDim < nDim; iDim++) val_residual[iDim+1] = 0.5*(mF*((Density_i*SoundSpeed_i*Velocity_i[iDim])+(Density_j*SoundSpeed_j*Velocity_j[iDim])) -Phi*((Density_j*SoundSpeed_j*Velocity_j[iDim])-(Density_i*SoundSpeed_i*Velocity_i[iDim])))+UnitNormal[iDim]*pF; val_residual[nVar-1] = 0.5*(mF*((Density_i*SoundSpeed_i*Enthalpy_i)+(Density_j*SoundSpeed_j*Enthalpy_j))-Phi*((Density_j*SoundSpeed_j*Enthalpy_j)-(Density_i*SoundSpeed_i*Enthalpy_i))); for (iVar = 0; iVar < nVar; iVar++) val_residual[iVar] *= Area; /*--- Roe's Jacobian for AUSM (this must be fixed) ---*/ if (implicit) { /*--- Promediate Roe variables iPoint and jPoint ---*/ R = sqrt(Density_j/Density_i); RoeDensity = R*Density_i; sq_vel = 0.0; for (iDim = 0; iDim < nDim; iDim++) { RoeVelocity[iDim] = (R*Velocity_j[iDim]+Velocity_i[iDim])/(R+1); sq_vel += RoeVelocity[iDim]*RoeVelocity[iDim]; } RoeEnthalpy = (R*Enthalpy_j+Enthalpy_i)/(R+1); RoeSoundSpeed = sqrt((Gamma-1)*(RoeEnthalpy-0.5*sq_vel)); /*--- Compute P and Lambda (do it with the Normal) ---*/ GetPMatrix(&RoeDensity, RoeVelocity, &RoeSoundSpeed, UnitNormal, P_Tensor); ProjVelocity = 0.0; ProjVelocity_i = 0.0; ProjVelocity_j = 0.0; for (iDim = 0; iDim < nDim; iDim++) { ProjVelocity += RoeVelocity[iDim]*UnitNormal[iDim]; ProjVelocity_i += Velocity_i[iDim]*UnitNormal[iDim]; ProjVelocity_j += Velocity_j[iDim]*UnitNormal[iDim]; } /*--- Flow eigenvalues and Entropy correctors ---*/ for (iDim = 0; iDim < nDim; iDim++) Lambda[iDim] = ProjVelocity; Lambda[nVar-2] = ProjVelocity + RoeSoundSpeed; Lambda[nVar-1] = ProjVelocity - RoeSoundSpeed; /*--- Compute inverse P ---*/ GetPMatrix_inv(&RoeDensity, RoeVelocity, &RoeSoundSpeed, UnitNormal, invP_Tensor); /*--- Jacobias of the inviscid flux, scale = 0.5 because val_residual ~ 0.5*(fc_i+fc_j)*Normal ---*/ GetInviscidProjJac(Velocity_i, &Energy_i, Normal, 0.5, val_Jacobian_i); GetInviscidProjJac(Velocity_j, &Energy_j, Normal, 0.5, val_Jacobian_j); /*--- Roe's Flux approximation ---*/ for (iVar = 0; iVar < nVar; iVar++) { for (jVar = 0; jVar < nVar; jVar++) { Proj_ModJac_Tensor_ij = 0.0; /*--- Compute |Proj_ModJac_Tensor| = P x |Lambda| x inverse P ---*/ for (kVar = 0; kVar < nVar; kVar++) Proj_ModJac_Tensor_ij += P_Tensor[iVar][kVar]*fabs(Lambda[kVar])*invP_Tensor[kVar][jVar]; val_Jacobian_i[iVar][jVar] += 0.5*Proj_ModJac_Tensor_ij*Area; val_Jacobian_j[iVar][jVar] -= 0.5*Proj_ModJac_Tensor_ij*Area; } } } }