use newton_rootfinder as nrf; use nrf::iteratives; use nrf::model::Model; use nrf::residuals; pub fn run_closure_case_fd( problem_size: usize, closure: &dyn Fn(&nalgebra::DVector) -> nalgebra::DVector, init: nalgebra::DVector, solution: nalgebra::DVector, resolution_method: nrf::solver::ResolutionMethod, damping: bool, ) { let vec_iter_params = iteratives::default_vec_iteratives_fd(problem_size); let iter_params = iteratives::Iteratives::new(&vec_iter_params); let stopping_residuals = vec![residuals::NormalizationMethod::Abs; problem_size]; let update_methods = vec![residuals::NormalizationMethod::Abs; problem_size]; let res_config = residuals::ResidualsConfig::new(&stopping_residuals, &update_methods); let mut rf = nrf::solver::default_with_guess( init, &iter_params, &res_config, resolution_method, damping, ); let mut user_model = nrf::model::UserModelFromClosure::new(problem_size, closure); rf.solve(&mut user_model).unwrap(); for i in 0..problem_size { assert!(float_cmp::approx_eq!( f64, user_model.get_iteratives()[i], solution[i], epsilon = 1e-6 )); } } pub fn run_closure_case_jac( problem_size: usize, closure: &dyn Fn(&nalgebra::DVector) -> nalgebra::DVector, jac: &dyn Fn(&nalgebra::DVector) -> nalgebra::DMatrix, init: nalgebra::DVector, solution: nalgebra::DVector, resolution_method: nrf::solver::ResolutionMethod, damping: bool, ) { let vec_iter_params = iteratives::default_vec_iteratives(problem_size); let iter_params = iteratives::Iteratives::new(&vec_iter_params); let stopping_residuals = vec![residuals::NormalizationMethod::Abs; problem_size]; let update_methods = vec![residuals::NormalizationMethod::Abs; problem_size]; let res_config = residuals::ResidualsConfig::new(&stopping_residuals, &update_methods); let mut rf = nrf::solver::default_with_guess( init, &iter_params, &res_config, resolution_method, damping, ); let mut user_model = nrf::model::UserModelFromClosureAndJacobian::new(problem_size, closure, jac); rf.solve(&mut user_model).unwrap(); for i in 0..problem_size { assert!(float_cmp::approx_eq!( f64, user_model.get_iteratives()[i], solution[i], epsilon = 1e-6 )); } }