diff --git a/source/main.cpp b/source/main.cpp index 2430ab1..612d3e7 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -106,6 +106,10 @@ int main(int argc, char *argv[]) { // Constant timestep integration num_steps = boost::numeric::odeint::integrate_const( controlled_stepper, loop->CalculateDerivs, state, loop->parameters.tau, loop->parameters.total_time, loop->parameters.tau, obs->Observe); + if(obs->CheckNan(state)) + { + throw std::runtime_error("NaNs were detected in the output. Check the input configuration."); + } } //Print results to file diff --git a/source/observer.cpp b/source/observer.cpp index 2bba65c..6b74c10 100644 --- a/source/observer.cpp +++ b/source/observer.cpp @@ -60,3 +60,18 @@ int Observer::CheckNan(state_type &state, double &time, double &tau, double old_ // Pass otherwise return 0; } + +int Observer::CheckNan(state_type &state) +{ + // Check for NaNs in the state + for(int j=0; j class typedef Observer* OBSERVER; diff --git a/tests/test_solver.py b/tests/test_solver.py index 551bd55..9f78356 100644 --- a/tests/test_solver.py +++ b/tests/test_solver.py @@ -82,4 +82,16 @@ def test_insufficient_heating(base_config, value): config['use_adaptive_solver'] = False config['heating']['background'] = value with pytest.raises(EbtelPlusPlusError): - run_ebtelplusplus(config) \ No newline at end of file + run_ebtelplusplus(config) + +@pytest.mark.parametrize('use_adaptive_solver', [True, False]) +def test_NaNs_in_solver(base_config, use_adaptive_solver): + config = base_config.copy() + config['use_adaptive_solver'] = use_adaptive_solver + config['heating']['events'] = [ + {'event': {'rise_start': 0.0, 'rise_end': 100.0, 'decay_start': 100.0, + 'decay_end': 200.0, 'magnitude': -10.0}} + ] + with pytest.raises(EbtelPlusPlusError): + run_ebtelplusplus(config) +