Grid1D

Enum Grid1D 

Source
pub enum Grid1D<Domain1D: IntervalFinitePositiveLengthTrait> {
    Uniform(Grid1DUniform<Domain1D>),
    NonUniform(Grid1DNonUniform<Domain1D>),
}
Expand description

An enum representing a one-dimensional grid, which defines a partition of a bounded interval with positive length.

The Grid1D enum models a set of points that partition a bounded interval into adjacent, non-overlapping subintervals. It supports both uniform grids, where all subintervals have the same length, and non-uniform grids, where subintervals can have varying lengths.

§Type Parameters

  • Point1DType: The type of the points in the grid. It must implement the RealScalar trait, ensuring that the points are real numbers with additional mathematical properties.

§Variants

  • Uniform: Represents a grid where all subintervals have the same length. This is modeled by the Grid1DUniform struct.
  • NonUniform: Represents a grid where subintervals can have varying lengths. This is modeled by the Grid1DNonUniform struct.

§Features

  • Uniform Grids: All subintervals have the same length, making them suitable for evenly spaced computations.
  • Non-Uniform Grids: Subintervals can have varying lengths, allowing for more flexibility in grid design.
  • Integration with IntervalPartition: The Grid1D enum implements the IntervalPartition trait, providing methods for accessing intervals and performing operations on the grid.

§Examples

§Creating a Uniform Grid

use grid1d::{
    Grid1D, HasCoords1D, IntervalPartition,
    intervals::IntervalClosed,
    scalars::NumIntervals,
};
use std::ops::Deref;
use try_create::TryNew;

let domain = IntervalClosed::new(0.0, 1.0);
let grid = Grid1D::uniform(domain, NumIntervals::try_new(4).unwrap());

assert_eq!(grid.coords().deref(), &[0.0, 0.25, 0.5, 0.75, 1.0]);
assert_eq!(grid.num_intervals().as_ref(), &4);

§Creating a Non-Uniform Grid

use grid1d::{
    Coords1D, Grid1D, HasCoords1D,
    intervals::IntervalClosed,
};
use sorted_vec::partial::SortedSet;
use std::ops::Deref;

let coords = SortedSet::from_unsorted(vec![0.0, 0.5, 1.0, 2.0]);
let domain = IntervalClosed::new(0.0, 2.0);
let grid = Grid1D::try_from_sorted(domain, coords).unwrap();
assert_eq!(grid.coords().deref(), &[0.0, 0.5, 1.0, 2.0]);

§Handling Errors

use grid1d::{
    Grid1D, ErrorsGrid1D,
    intervals::IntervalClosed,
};
use sorted_vec::partial::SortedSet;

let coords = SortedSet::from_unsorted(vec![0.0]); // Only one point provided
let domain = IntervalClosed::new(0.0, 1.0);
let err = Grid1D::try_from_sorted(domain, coords).unwrap_err();
assert!(matches!(err, ErrorsGrid1D::RequiredAtLeastTwoDistinctPoints { .. }));

Variants§

§

Uniform(Grid1DUniform<Domain1D>)

All the intervals defined by the Grid1D object have the same length.

§

NonUniform(Grid1DNonUniform<Domain1D>)

The intervals defined by the Grid1D object have not the same length.

Implementations§

Source§

impl<Domain1D: IntervalFinitePositiveLengthTrait> Grid1D<Domain1D>

Source

pub fn uniform(domain: Domain1D, num_intervals: NumIntervals) -> Self

Creates a new uniform grid over the specified domain with the given number of intervals.

§Parameters
  • domain: The closed interval over which the grid is defined.
  • num_intervals: The number of subintervals in the grid.
§Returns

A Grid1D instance representing a uniform grid.

§Example
use grid1d::{
    Grid1D, HasCoords1D, IntervalPartition,
    intervals::IntervalClosed,
    scalars::NumIntervals,
};
use std::ops::Deref;
use try_create::TryNew;

let domain = IntervalClosed::new(0., 1.);
let grid = Grid1D::uniform(domain, NumIntervals::try_new(4).unwrap());

assert_eq!(grid.coords().deref(), &[0., 0.25, 0.5, 0.75, 1.]);
Source

pub fn try_from_sorted( domain: Domain1D, values: SortedSet<Domain1D::RealType>, ) -> Result<Self, ErrorsGrid1D<Domain1D>>

Creates a new grid from a sorted set of points (at least 2).

§Parameters
  • values: A sorted set of points defining the grid.
§Returns
  • Ok(Self): If at least two points are provided.
  • Err<ErrorsGrid1D>: If fewer than two points are provided.
§Errors
§Example
use grid1d::{
    Grid1D, HasCoords1D,
    intervals::IntervalClosed,
};
use sorted_vec::partial::SortedSet;
use std::ops::Deref;

let coords = SortedSet::from_unsorted(vec![0., 0.5, 1., 2.]);
let domain = IntervalClosed::new(0.0, 2.0);
let grid = Grid1D::try_from_sorted(domain, coords).unwrap();
assert_eq!(grid.coords().deref(), &[0., 0.5, 1., 2.]);
Source

pub fn try_from_coords( domain: Domain1D, coords: Coords1D<Domain1D::RealType>, ) -> Result<Self, ErrorsGrid1D<Domain1D>>

Trait Implementations§

Source§

impl<Domain1D: Clone + IntervalFinitePositiveLengthTrait> Clone for Grid1D<Domain1D>

Source§

fn clone(&self) -> Grid1D<Domain1D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Domain1D: Debug + IntervalFinitePositiveLengthTrait> Debug for Grid1D<Domain1D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Domain1D: IntervalFinitePositiveLengthTrait> HasCoords1D for Grid1D<Domain1D>

Source§

type Point1DType = <Domain1D as IntervalOperations>::RealType

The type of the 1D points.
Source§

fn coords(&self) -> &Coords1D<Domain1D::RealType>

Get the coordinates of the 1D points. Read more
Source§

fn num_points(&self) -> PositiveNumPoints1D

Get the number of points. Read more
Source§

impl<Domain1D: IntervalFinitePositiveLengthTrait> HasDomain1D for Grid1D<Domain1D>

Source§

type Domain1D = Domain1D

The type of interval upon which the current one-dimensional domain is defined.
Source§

fn domain(&self) -> &Domain1D

Return a reference of the one-dimensional domain upon which the current structure is defined.
Source§

impl<Domain1D: IntervalInPartitionBuilder> IntervalPartition for Grid1D<Domain1D>

Source§

type UniformlyRefinedGrid1DType = Grid1D<Domain1D>

Source§

fn refine_uniform( self, num_extra_points_each_interval: &PositiveNumPoints1D, ) -> Grid1DUniformRefinement<Self>

Source§

fn refine( self, intervals_to_refine: &[(IntervalId, PositiveNumPoints1D)], ) -> Grid1DNonUniformRefinement<Self>

Source§

fn num_intervals(&self) -> NumIntervals

Get the number of intervals defining the partition. Read more
Source§

fn interval(&self, i: &IntervalId) -> SubIntervalInPartition<Self::Point1DType>

Returns the i-th interval as SubIntervalInPartition.
Source§

fn iter_intervals( &self, ) -> impl Iterator<Item = (IntervalId, SubIntervalInPartition<Self::Point1DType>)> + '_

Returns an iterator over all intervals in the partition. Read more
Source§

fn interval_length( &self, interval_id: &IntervalId, ) -> PositiveRealScalar<Self::Point1DType>

Returns the interval length at the specified index. Read more
Source§

fn find_interval_id_of_point(&self, x: &Self::Point1DType) -> IntervalId

Returns the id of the interval that contains_point the value x. Read more
Source§

fn try_find_interval_id_of_point( &self, x: &Self::Point1DType, ) -> Option<IntervalId>

Finds the ID of the interval containing the point x, returning None if the point is outside the domain. Read more
Source§

fn find_intervals_for_points( &self, points: &[Self::Point1DType], ) -> Vec<Option<IntervalId>>

Finds all intervals that contain any of the given points. Read more
Source§

fn max_interval_length(&self) -> PositiveRealScalar<Self::Point1DType>

Returns the maximum interval length in the partition. Read more
Source§

fn min_interval_length(&self) -> PositiveRealScalar<Self::Point1DType>

Returns the minimum interval length in the partition. Read more
Source§

fn uniformity_ratio(&self) -> PositiveRealScalar<Self::Point1DType>

Returns the ratio between maximum and minimum interval lengths. Read more
Source§

fn intervals_in_intersection<IntervalType: IntervalFinitePositiveLengthTrait<RealType = Self::Point1DType>>( &self, domain_in: &IntervalType, ) -> Vec<(IntervalId, IntervalFinitePositiveLength<Self::Point1DType>)>

Performs the intersection of the input domain with the current IntervalPartition. Read more
Source§

impl<Domain1D: PartialEq + IntervalFinitePositiveLengthTrait> PartialEq for Grid1D<Domain1D>

Source§

fn eq(&self, other: &Grid1D<Domain1D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Domain1D: IntervalFinitePositiveLengthTrait> StructuralPartialEq for Grid1D<Domain1D>

Auto Trait Implementations§

§

impl<Domain1D> Freeze for Grid1D<Domain1D>
where Domain1D: Freeze, <Domain1D as IntervalOperations>::RealType: Freeze,

§

impl<Domain1D> RefUnwindSafe for Grid1D<Domain1D>
where Domain1D: RefUnwindSafe, <Domain1D as IntervalOperations>::RealType: RefUnwindSafe,

§

impl<Domain1D> Send for Grid1D<Domain1D>
where Domain1D: Send,

§

impl<Domain1D> Sync for Grid1D<Domain1D>
where Domain1D: Sync,

§

impl<Domain1D> Unpin for Grid1D<Domain1D>
where Domain1D: Unpin, <Domain1D as IntervalOperations>::RealType: Unpin,

§

impl<Domain1D> UnwindSafe for Grid1D<Domain1D>
where Domain1D: UnwindSafe, <Domain1D as IntervalOperations>::RealType: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.