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 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 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 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; } } } }