// Test a given solver on an ODE which has a stopping event defined void MyTestSolverOnOdesWithEvents(AbstractIvpOdeSolver& rSolver) { // ODE which has solution y0 = cos(t), and stopping event y0<0, // ie should stop when t = pi/2; OdeSecondOrderWithEvents ode_with_events; OdeSolution solutions; std::vector<double> state_variables = ode_with_events.GetInitialConditions(); solutions = rSolver.Solve(&ode_with_events, state_variables, 0.0, 2.0, 0.001, 0.001); unsigned num_timesteps = solutions.GetNumberOfTimeSteps(); // Final time should be around pi/2 TS_ASSERT_DELTA( solutions.rGetTimes()[num_timesteps], M_PI_2, 0.01); // Penultimate y0 should be greater than zero TS_ASSERT_LESS_THAN( 0, solutions.rGetSolutions()[num_timesteps-1][0]); // Final y0 should be less than zero TS_ASSERT_LESS_THAN( solutions.rGetSolutions()[num_timesteps][0], 0); // Solver should correctly state the stopping event occurred TS_ASSERT_EQUALS(rSolver.StoppingEventOccurred(), true); // This is to cover the exception when a stopping event occurs before the first timestep. TS_ASSERT_THROWS_ANYTHING(rSolver.Solve(&ode_with_events, state_variables, 2.0, 3.0, 0.001)); /////////////////////////////////////////////// // Repeat with sampling time larger than dt /////////////////////////////////////////////// state_variables = ode_with_events.GetInitialConditions(); solutions = rSolver.Solve(&ode_with_events, state_variables, 0.0, 2.0, 0.001, 0.01); num_timesteps = solutions.GetNumberOfTimeSteps(); // Final time should be around pi/2 TS_ASSERT_DELTA( solutions.rGetTimes()[num_timesteps], M_PI_2, 0.01); // Penultimate y0 should be greater than zero TS_ASSERT_LESS_THAN( 0, solutions.rGetSolutions()[num_timesteps-1][0]); // Final y0 should be less than zero TS_ASSERT_LESS_THAN( solutions.rGetSolutions()[num_timesteps][0], 0); // Solver should correctly state the stopping event occurred TS_ASSERT_EQUALS(rSolver.StoppingEventOccurred(), true); // Cover the check event isn't initially true exception std::vector<double> bad_init_cond; bad_init_cond.push_back(-1); //y0 < 0 so stopping event true bad_init_cond.push_back(0.0); TS_ASSERT_THROWS_ANYTHING(rSolver.Solve(&ode_with_events, bad_init_cond, 0.0, 2.0, 0.001, 0.01)); }
inline void check_node_throws(std::shared_ptr<execution_node> node) { size_t consumer_id = node->register_consumer(); TS_ASSERT_THROWS_ANYTHING(node->get_next(consumer_id)); }
void TestCorrectVersion(void) throw(Exception) { TS_ASSERT_THROWS_NOTHING(READER_2D("mesh/test/data/square_4_elements_gmsh.msh")); TS_ASSERT_THROWS_ANYTHING(READER_2D("mesh/test/data/square_4_elements_bad_version.msh")); }
void TestFilesOpen(void) throw(Exception) { TS_ASSERT_THROWS_NOTHING(READER_2D("mesh/test/data/square_4_elements_gmsh.msh")); TS_ASSERT_THROWS_ANYTHING(READER_2D("mesh/test/data/no_file.msh")); }
void test_initialize_zero_vector( void ) { Vector v(0); int result = v.get_size(); TS_ASSERT_EQUALS( result, 0 ); TS_ASSERT_THROWS_ANYTHING( v.get(-1) ); }