LatticeCyclic

Struct LatticeCyclic 

Source
pub struct LatticeCyclic<const D: usize> { /* private fields */ }
Expand description

A Cyclic lattice in space. Does not store point and links but is used to generate them.

The generic parameter D is the dimension.

This lattice is Cyclic more precisely if the lattice has N points in each direction. Then we can move alongside a direction going though point 0, 1, … N-1. The next step in the same direction goes back to the point at 0.

This structure is used for operation on LatticePoint, LatticeLink and LatticeLinkCanonical. access data on the lattice. These data are stored LinkMatrix and EField which are just a wrapper around a Vec. LatticeCyclic is used to convert the lattice element to an index to access these data.

This contain very few data and can be cloned at almost no cost even though it does not implement Copy.

Implementations§

Source§

impl<const D: usize> LatticeCyclic<D>

Source

pub const fn dim_st() -> usize

Number space + time dimension, this is the D parameter.

Not to confuse with LatticeCyclic::dim which is the number of point per dimension.

see LatticeLinkCanonical, a conical link is a link whose direction is always positive. That means that a link form [x, y, z, t] with direction -x the link return is [x - 1, y, z, t] (modulo the lattice::dim()``) with direction +x`

§Example
fn main() -> Result<(), Box<dyn std::error::Error>> {
let lattice = LatticeCyclic::<4>::new(1_f64, 4)?;
let point = LatticePoint::<4>::new([1, 0, 2, 0].into());
assert_eq!(
    lattice.link_canonical(point, DirectionEnum::XNeg.into()),
    LatticeLinkCanonical::new(LatticePoint::new([0, 0, 2, 0].into()), DirectionEnum::XPos.into()).ok_or(ImplementationError::OptionWithUnexpectedNone)?
);
assert_eq!(
    lattice.link_canonical(point, DirectionEnum::XPos.into()),
    LatticeLinkCanonical::new(LatticePoint::new([1, 0, 2, 0].into()), DirectionEnum::XPos.into()).ok_or(ImplementationError::OptionWithUnexpectedNone)?
);
assert_eq!(
    lattice.link_canonical(point, DirectionEnum::YNeg.into()),
    LatticeLinkCanonical::new(LatticePoint::new([1, 3, 2, 0].into()), DirectionEnum::YPos.into()).ok_or(ImplementationError::OptionWithUnexpectedNone)?
);

Return a link build from pos and dir.

It is similar to LatticeLink::new. It however enforce that the point is inside the bounds. If it is not, it will use the modulus of the bound.

§Example
fn main() -> Result<(), Box<dyn std::error::Error>> {
let l = LatticeCyclic::<3>::new(1_f64, 4)?;
let dir = Direction::new(0, true).ok_or(ImplementationError::OptionWithUnexpectedNone)?;
let pt = LatticePoint::new(SVector::<_, 3>::new(1, 2, 5));
let link = l.link(pt, dir);
assert_eq!(
    *link.pos(),
    LatticePoint::new(SVector::<_, 3>::new(1, 2, 1))
);
Source

pub fn into_canonical(&self, l: LatticeLink<D>) -> LatticeLinkCanonical<D>

Source

pub const fn dim(&self) -> usize

Get the number of points in a single direction.

use LatticeCyclic::number_of_points for the total number of points. Not to confuse with LatticeCyclic::dim_st which is the dimension of space-time.

Source

pub fn get_points(&self) -> IteratorLatticePoint<'_, D>

Get an Iterator over all points of the lattice.

§Example
for i in [4, 8, 16, 32, 64].into_iter() {
    let l = LatticeCyclic::<4>::new(1_f64, i)?;
    assert_eq!(l.get_points().size_hint().0, l.number_of_points());
}

Get an Iterator over all canonical link of the lattice.

§Example
for i in [4, 8, 16, 32, 64].into_iter() {
    let l = LatticeCyclic::<4>::new(1_f64, i)?;
    assert_eq!(
        l.get_links().size_hint().0,
        l.number_of_canonical_links_space()
    );
}
Source

pub fn new(size: Real, dim: usize) -> Result<Self, LatticeInitializationError>

create a new lattice with size the lattice size parameter, and dim the number of points in each spatial dimension.

§Errors

Size should be greater than 0 and dim greater or equal to 2, otherwise return an error.

Total number of canonical links oriented in space for a set time.

Basically the number of element return by LatticeCyclic::get_links.

§Example
let l = LatticeCyclic::<4>::new(1_f64, 8)?;
assert_eq!(l.number_of_canonical_links_space(), 8_usize.pow(4) * 4);

let l = LatticeCyclic::<4>::new(1_f64, 16)?;
assert_eq!(l.number_of_canonical_links_space(), 16_usize.pow(4) * 4);

let l = LatticeCyclic::<3>::new(1_f64, 8)?;
assert_eq!(l.number_of_canonical_links_space(), 8_usize.pow(3) * 3);
Source

pub fn number_of_points(&self) -> usize

Total number of point in the lattice for a set time.

§Example
let l = LatticeCyclic::<4>::new(1_f64, 8)?;
assert_eq!(l.number_of_points(), 8_usize.pow(4));

let l = LatticeCyclic::<4>::new(1_f64, 16)?;
assert_eq!(l.number_of_points(), 16_usize.pow(4));

let l = LatticeCyclic::<3>::new(1_f64, 8)?;
assert_eq!(l.number_of_points(), 8_usize.pow(3));
Source

pub const fn size(&self) -> Real

Return the lattice size factor.

Source

pub fn add_point_direction( &self, point: LatticePoint<D>, dir: &Direction<D>, ) -> LatticePoint<D>

Get the next point in the lattice following the direction dir. It follows the Cyclic property of the lattice.

§Example
let lattice = LatticeCyclic::<4>::new(1_f64, 4)?;
let point = LatticePoint::<4>::from([1, 0, 2, 0]);
assert_eq!(
    lattice.add_point_direction(point, &DirectionEnum::XPos.into()),
    LatticePoint::from([2, 0, 2, 0])
);
// In the following case we get [_, 3, _, _] because `dim = 4`, and this lattice is Cyclic.
assert_eq!(
    lattice.add_point_direction(point, &DirectionEnum::YNeg.into()),
    LatticePoint::from([1, 3, 2, 0])
);
Source

pub fn add_point_direction_n( &self, point: LatticePoint<D>, dir: &Direction<D>, shift_number: usize, ) -> LatticePoint<D>

Returns the point given y moving shift_number times in direction dir from position point. It follows the Cyclic property of the lattice.

It is equivalent of doing Self::add_point_direction n times.

§Example
let lattice = LatticeCyclic::<4>::new(1_f64, 4)?;
let point = LatticePoint::<4>::from([1, 0, 2, 0]);
assert_eq!(
    lattice.add_point_direction_n(point, &DirectionEnum::XPos.into(), 2),
    LatticePoint::from([3, 0, 2, 0])
);
// In the following case we get [_, 1, _, _] because `dim = 4`, and this lattice is Cyclic.
assert_eq!(
    lattice.add_point_direction_n(point, &DirectionEnum::YNeg.into(), 3),
    LatticePoint::from([1, 1, 2, 0])
);

Returns whether the number of canonical link is the same as the length of links.

Source

pub fn has_compatible_length_e_field(&self, e_field: &EField<D>) -> bool

Returns wether the number of point is the same as the length of e_field.

Source

pub fn has_compatible_length( &self, links: &LinkMatrix, e_field: &EField<D>, ) -> bool

Returns the length is compatible for both links and e_field. See Self::has_compatible_length_links and Self::has_compatible_length_e_field.

Trait Implementations§

Source§

impl<const D: usize> Clone for LatticeCyclic<D>

Source§

fn clone(&self) -> LatticeCyclic<D>

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<const D: usize> Debug for LatticeCyclic<D>

Source§

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

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

impl<'de, const D: usize> Deserialize<'de> for LatticeCyclic<D>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const D: usize> Display for LatticeCyclic<D>

Source§

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

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

impl<const D: usize> PartialEq for LatticeCyclic<D>

Source§

fn eq(&self, other: &LatticeCyclic<D>) -> 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<const D: usize> Serialize for LatticeCyclic<D>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<const D: usize> StructuralPartialEq for LatticeCyclic<D>

Auto Trait Implementations§

§

impl<const D: usize> Freeze for LatticeCyclic<D>

§

impl<const D: usize> RefUnwindSafe for LatticeCyclic<D>

§

impl<const D: usize> Send for LatticeCyclic<D>

§

impl<const D: usize> Sync for LatticeCyclic<D>

§

impl<const D: usize> Unpin for LatticeCyclic<D>

§

impl<const D: usize> UnwindSafe for LatticeCyclic<D>

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> 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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,