Struct newton_rootfinder::model::UserModelFromFunctionAndJacobian [−][src]
pub struct UserModelFromFunctionAndJacobian {
pub inputs: DVector<f64>,
pub func: fn(_: &DVector<f64>) -> DVector<f64>,
pub jac: fn(_: &DVector<f64>) -> DMatrix<f64>,
pub left: DVector<f64>,
pub right: DVector<f64>,
// some fields omitted
}
Expand description
Blanket implementation to easily adapt user functions to the Model trait required by the solver to work with a jacobian provided
The right side of the equation is a constant and by default zero. No other outputs are computed
Examples
pub fn square(x: &nalgebra::DVector::<f64>) -> nalgebra::DVector::<f64> {
x*x
}
pub fn dsquare(x: &nalgebra::DVector::<f64>) -> nalgebra::DMatrix::<f64> {
let mut jac = nalgebra::DMatrix::zeros(1,1);
jac[(0,0)] = 2.0*x[0];
jac
}
use newton_rootfinder as nrf;
use nrf::model::Model; // trait import required
let iteratives = nalgebra::DVector::from_vec(vec!(2.0));
let mut user_model = nrf::model::UserModelFromFunctionAndJacobian::new(1, square, dsquare);
user_model.set_iteratives(&iteratives);
user_model.evaluate();
assert_eq!(user_model.len_problem(), 1);
assert_eq!(user_model.get_iteratives(), nalgebra::DVector::from_vec(vec!(2.0)));
assert_eq!(user_model.get_residuals().get_values(0), (4.0, 0.0));
assert_eq!(user_model.jacobian_provided(), true);
let jacobians_values = user_model.get_jacobian().unwrap();
let (jac_left, jac_right) = jacobians_values.get_jacobians();
assert_eq!(jac_left[(0,0)], 4.0);
assert_eq!(jac_right[(0,0)], 0.0);
Fields
inputs: DVector<f64>
func: fn(_: &DVector<f64>) -> DVector<f64>
jac: fn(_: &DVector<f64>) -> DMatrix<f64>
left: DVector<f64>
right: DVector<f64>
Implementations
Trait Implementations
type InaccurateValuesError = Infallible
type UnusableValuesError = Infallible
This method should update the values of the outputs of the model by using as inputs the values set by the Model::set_iteratives method. Read more
This method gets the values of the output for the solver. The return argument is in a specific format, separating left and right member of an equation. Read more
This method is required to access the values of the iteratives variables during the resolution process. The values returned should be the same one as the one set by the Model::set_iteratives method. Read more
This method provides the solver a mecanism to set the iteratives values and perform the resolution
This method defines the dimension of the problem. Read more
This method allows the solver to know if the jacobian is provided by the user or not Read more
Method allowing to access the jacobian matrix This method takes a mutable model, as it allows to compute the jacobian when needed and not only when the model is evaluated. Read more
This method allow the solver to memorize information after calculating the reference point and before the jacobian evaluation by finite-difference. Read more
This method is called in-between the computation of each column of the jacobian matrix, in order to reset the values to the ones from the Model::get_memory Read more
Auto Trait Implementations
impl Send for UserModelFromFunctionAndJacobian
impl Sync for UserModelFromFunctionAndJacobian
impl Unpin for UserModelFromFunctionAndJacobian
Blanket Implementations
Mutably borrows from an owned value. Read more
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.