@@ -1986,9 +1986,8 @@ void CSU2TCLib::ThermalConductivitiesGY(){
19861986
19871987}
19881988
1989- vector<su2double>& CSU2TCLib::ComputeTemperatures (vector<su2double>& val_rhos, su2double rhoE, su2double rhoEve, su2double rhoEvel) {
1989+ vector<su2double>& CSU2TCLib::ComputeTemperatures (vector<su2double>& val_rhos, su2double rhoE, su2double rhoEve, su2double rhoEvel, su2double Tve_old) {
19901990
1991- vector<su2double> val_eves;
19921991 rhos = val_rhos;
19931992
19941993 /* ----------Translational temperature----------*/
@@ -2004,39 +2003,77 @@ vector<su2double>& CSU2TCLib::ComputeTemperatures(vector<su2double>& val_rhos, s
20042003 T = (rhoE - rhoEve - rhoE_f + rhoE_ref - rhoEvel) / rhoCvtr;
20052004
20062005 /* --- Set temperature clipping values ---*/
2007- su2double Tmin = 50.0 ; su2double Tmax = 8E4 ;
2008- su2double Tve_o = 50.0 ; su2double Tve2 = 8E4 ;
2006+ const su2double Tmin = 50.0 ; const su2double Tmax = 8E4 ;
2007+ const su2double Tvemin = 50.0 ; const su2double Tvemax = 8E4 ;
2008+ su2double Tve_o = 50.0 ; su2double Tve2 = 8E4 ;
20092009
20102010 /* Determine if the temperature lies within the acceptable range */
2011- if (T < Tmin) T = Tmin;
2012- else if (T > Tmax) T = Tmax;
2011+ if (Tve_old < 1 ) Tve_old = T; // For first fluid iteration
2012+ if (T < Tmin) T = Tmin; else if (T > Tmax) T = Tmax;
2013+ if (Tve_old<Tvemin) Tve_old = Tvemin; else if (Tve_old>Tvemax) Tve_old = Tvemax;
20132014
20142015 /* --- Set vibrational temperature algorithm parameters ---*/
2015- su2double Btol = 1.0E-6 ; // Tolerance for the Bisection method
2016- unsigned short maxBIter = 50 ; // Maximum Bisection method iterations
2016+ const su2double NRtol = 1.0E-6 ; // Tolerance for the Newton-Raphson method
2017+ const su2double Btol = 1.0E-6 ; // Tolerance for the Bisection method
2018+ const unsigned short maxBIter = 50 ; // Maximum Bisection method iterations
2019+ const unsigned short maxNIter = 50 ; // Maximum Newton-Raphson iterations
2020+ const su2double scale = 0.9 ; // Scaling factor for Newton-Raphson step
20172021
2022+ /* --- Execute a Newton-Raphson root-finding method for Tve ---*/
20182023 // Initialize solution
2019- Tve = T ;
2024+ Tve = Tve_old ;
20202025
2021- // Execute the root-finding method
20222026 bool Bconvg = false ;
2023- su2double rhoEve_t = 0.0 ;
2024-
2025- for (unsigned short iIter = 0 ; iIter < maxBIter; iIter++) {
2026- Tve = (Tve_o+Tve2)/2.0 ;
2027- val_eves = ComputeSpeciesEve (Tve);
2028- rhoEve_t = 0.0 ;
2029- for (iSpecies = 0 ; iSpecies < nSpecies; iSpecies++) rhoEve_t += rhos[iSpecies] * val_eves[iSpecies];
2030- if (fabs (rhoEve_t - rhoEve) < Btol) {
2031- Bconvg = true ;
2032- break ;
2027+ bool NRconvg = false ;
2028+ su2double rhoEve_t = 0.0 , rhoCvve = 0.0 ;
2029+
2030+ /* --- Newton-Raphson Method --*/
2031+ for (unsigned short iIter = 0 ; iIter < maxNIter; iIter++) {
2032+ rhoEve_t = rhoCvve = 0.0 ;
2033+ const auto & val_eves = ComputeSpeciesEve (Tve);
2034+ const auto & val_cvves = ComputeSpeciesCvVibEle (Tve);
2035+
2036+ for (iSpecies = 0 ; iSpecies < nSpecies; iSpecies++){
2037+ rhoEve_t += rhos[iSpecies] * val_eves[iSpecies];
2038+ rhoCvve += rhos[iSpecies] * val_cvves[iSpecies];
2039+ }
2040+
2041+ /* --- Find the roots ---*/
2042+ su2double f = rhoEve - rhoEve_t;
2043+ su2double df = -rhoCvve;
2044+ Tve2 = Tve - (f/df)*scale;
2045+
2046+ /* --- Check for convergence ---*/
2047+ if ((fabs (Tve2-Tve) < NRtol) && (Tve > Tvemin) && (Tve < Tvemax)) {
2048+ NRconvg = true ;
2049+ Tve = Tve2;
2050+ break ;
20332051 } else {
2034- if (rhoEve_t > rhoEve) Tve2 = Tve;
2035- else Tve_o = Tve;
2052+ Tve = Tve2;
20362053 }
20372054 }
2055+
2056+ // If the Newton-Raphson method has converged, assign the value of Tve.
2057+ // Otherwise, execute a bisection root-finding method
2058+ Tve_o = Tvemin; Tve2 = Tvemax;
2059+ if (!NRconvg) {
2060+ for (unsigned short iIter = 0 ; iIter < maxBIter; iIter++) {
2061+ Tve = (Tve_o+Tve2)/2.0 ;
2062+ const auto & val_eves = ComputeSpeciesEve (Tve);
2063+ rhoEve_t = 0.0 ;
2064+ for (iSpecies = 0 ; iSpecies < nSpecies; iSpecies++) rhoEve_t += rhos[iSpecies] * val_eves[iSpecies];
2065+ if (fabs (rhoEve_t - rhoEve) < Btol) {
2066+ Bconvg = true ;
2067+ break ;
2068+ } else {
2069+ if (rhoEve_t > rhoEve) Tve2 = Tve;
2070+ else Tve_o = Tve;
2071+ }
2072+ }
2073+ }
2074+
20382075 // If absolutely no convergence, then assign to the TR temperature
2039- if (!Bconvg) {
2076+ if (!NRconvg && ! Bconvg ) {
20402077 Tve = T;
20412078 cout <<" Warning: temperatures did not converge, error= " << fabs (rhoEve_t-rhoEve)<<endl;
20422079 }
0 commit comments