Skip to content

Commit

Permalink
Convert y_fn_x (analytical solution) to Fn
Browse files Browse the repository at this point in the history
  • Loading branch information
cpmech committed May 15, 2024
1 parent 82c7082 commit b1a6486
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
13 changes: 5 additions & 8 deletions russell_ode/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ use std::io::BufReader;
use std::marker::PhantomData;
use std::path::Path;

/// Defines a function to compute y(x) (e.g, the analytical solution)
///
/// Use `|y, x, args|` or `|y: &mut Vector, x: f64, args, &mut A|`
pub type YxFunction<A> = fn(&mut Vector, f64, &mut A);

/// Holds the data generated at an accepted step or during the dense output
#[derive(Clone, Debug, Deserialize)]
pub struct OutData {
Expand Down Expand Up @@ -129,7 +124,7 @@ pub struct Output<'a, A> {
y_aux: Vector,

/// Holds the y(x) function (e.g., to compute the correct/analytical solution)
yx_function: Option<YxFunction<A>>,
yx_function: Option<Box<dyn Fn(&mut Vector, f64, &mut A) + 'a>>,

/// Handles the generic argument
phantom: PhantomData<fn() -> A>,
Expand Down Expand Up @@ -374,8 +369,10 @@ impl<'a, A> Output<'a, A> {
}

/// Sets the function to compute the correct/reference results y(x)
pub fn set_yx_correct(&mut self, y_fn_x: fn(&mut Vector, f64, &mut A)) -> &mut Self {
self.yx_function = Some(y_fn_x);
///
/// Use `|y, x, args|` or `|y: &mut Vector, x: f64, args, &mut A|`
pub fn set_yx_correct(&mut self, y_fn_x: impl Fn(&mut Vector, f64, &mut A) + 'a) -> &mut Self {
self.yx_function = Some(Box::new(y_fn_x));
self
}

Expand Down
12 changes: 6 additions & 6 deletions russell_ode/src/samples.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::StrError;
use crate::{HasJacobian, NoArgs, PdeDiscreteLaplacian2d, Side, System, YxFunction};
use crate::{HasJacobian, NoArgs, PdeDiscreteLaplacian2d, Side, System};
use russell_lab::math::PI;
use russell_lab::Vector;
use russell_sparse::{CooMatrix, Genie, Sym};
Expand Down Expand Up @@ -53,7 +53,7 @@ impl Samples {
f64,
Vector,
NoArgs,
YxFunction<NoArgs>,
impl Fn(&mut Vector, f64, &mut NoArgs),
) {
// system
let ndim = 1;
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Samples {
f64,
Vector,
NoArgs,
YxFunction<NoArgs>,
impl Fn(&mut Vector, f64, &mut NoArgs),
) {
// selected symmetric option (for both Mass and Jacobian matrices)
let sym = genie.symmetry(symmetric);
Expand Down Expand Up @@ -820,7 +820,7 @@ impl Samples {
f64,
Vector,
NoArgs,
YxFunction<NoArgs>,
impl Fn(&mut Vector, f64, &mut NoArgs),
) {
// constants
const L: f64 = -50.0; // lambda
Expand Down Expand Up @@ -1225,7 +1225,7 @@ impl Samples {
f64,
Vector,
NoArgs,
YxFunction<NoArgs>,
impl Fn(&mut Vector, f64, &mut NoArgs),
) {
// system
let ndim = 1;
Expand Down Expand Up @@ -1306,7 +1306,7 @@ impl Samples {
f64,
Vector,
NoArgs,
YxFunction<NoArgs>,
impl Fn(&mut Vector, f64, &mut NoArgs),
) {
// system
let ndim = 2;
Expand Down

0 comments on commit b1a6486

Please sign in to comment.