Skip to content

Commit 2fbdc3f

Browse files
committed
Better report any convergence errors in harder precip with newton solver
1 parent 6c21f43 commit 2fbdc3f

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/modules/Harder_precip_phase.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void Harder_precip_phase::run(mesh_elem& face)
7878
double Ta = (*face)["t"_s]+273.15; //K
7979
double T = (*face)["t"_s];
8080
double RH = (*face)["rh"_s];
81-
double ea = RH/100 * 0.611*exp( (17.3*T) / (237.3+T));
81+
double ea = RH/100.0 * 0.611*exp( (17.3*T) / (237.3+T));
8282

8383
// (A.6)
8484
double D = 2.06 * pow(10,-5) * pow(Ta/273.15,1.75);
@@ -117,7 +117,29 @@ void Harder_precip_phase::run(mesh_elem& face)
117117
double max = 50;
118118
double digits = 6;
119119

120-
double Ti = boost::math::tools::newton_raphson_iterate(fx, guess, min, max, digits);
120+
double Ti = 0;
121+
122+
try
123+
{
124+
Ti = boost::math::tools::newton_raphson_iterate(fx, guess, min, max, digits);
125+
}
126+
catch(...)
127+
{
128+
SPDLOG_ERROR("Ta={}, RH={}, ea={}, guess={}, min={}, max={}",
129+
Ta, RH, ea, guess, min, max);
130+
try
131+
{
132+
// try again but instrument it this time to see what went wrong
133+
#define BOOST_MATH_INSTRUMENT
134+
Ti = boost::math::tools::newton_raphson_iterate(fx, guess, min, max, digits);
135+
#undef BOOST_MATH_INSTRUMENT
136+
}
137+
catch(...)
138+
{
139+
}
140+
CHM_THROW_EXCEPTION(module_error, "Harder_precip_phase newton_raphson_iterate failed to converge");
141+
}
142+
121143

122144
double frTi = 1.0 / (1.0+b*pow(c,Ti));
123145

0 commit comments

Comments
 (0)