Skip to main content

Field

Struct Field 

Source
pub struct Field<T> { /* private fields */ }
Expand description

A flat array over all cells or faces, with element-wise arithmetic.

Mirrors Foam::Field<Type> from src/OpenFOAM/fields/Fields/Field/Field.H. The raw storage is Vec<T> with no dimension bookkeeping — that lives in the wrapping VolField/SurfaceField.

Implementations§

Source§

impl<T: Clone> Field<T>

Source

pub fn new(data: Vec<T>) -> Self

Wrap an existing Vec<T> as a field (no copy).

Source

pub fn uniform(n: usize, value: T) -> Self

Field of n elements all equal to value.

Source

pub fn from_fn(n: usize, f: impl Fn(usize) -> T) -> Self

Field of n elements, element i set to f(i).

Source

pub fn len(&self) -> usize

Number of elements in the field.

Source

pub fn is_empty(&self) -> bool

True if the field has no elements.

Source

pub fn as_slice(&self) -> &[T]

Borrow the underlying storage as a slice.

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Mutably borrow the underlying storage as a slice.

Source

pub fn into_vec(self) -> Vec<T>

Consume the field, returning its underlying Vec<T>.

Source

pub fn iter(&self) -> Iter<'_, T> ⓘ

Iterator over element references.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ

Iterator over mutable element references.

Source

pub fn map<U: Clone>(&self, f: impl Fn(&T) -> U) -> Field<U>

Map f element-wise, returning a new Field<U> of the same length.

Source§

impl Field<f64>

Source

pub fn zeros(n: usize) -> Self

Scalar field of n zeros.

Source

pub fn ones(n: usize) -> Self

Scalar field of n ones.

Source

pub fn sum(&self) -> f64

Sum of all elements.

Source

pub fn mean(&self) -> f64

Arithmetic mean of all elements; returns 0.0 for an empty field.

Source

pub fn min(&self) -> f64

Smallest element (+∞ for an empty field).

Source

pub fn max(&self) -> f64

Largest element (−∞ for an empty field).

Source

pub fn l2_norm(&self) -> f64

Euclidean (L2) norm: sqrt(sum(x_i²)).

Source

pub fn abs(&self) -> Self

Element-wise absolute value.

Source

pub fn clamp(&self, lo: f64, hi: f64) -> Self

Element-wise clamp.

Source

pub fn pointwise_mul(&self, rhs: &Self) -> Self

Element-wise product of two scalar fields.

Source

pub fn pointwise_div(&self, rhs: &Self) -> Self

Element-wise division of two scalar fields.

Source

pub fn weighted_sum(&self, weights: &Field<f64>) -> f64

Weighted sum: sum(w[i] * x[i]).

Source§

impl Field<Vector3>

Source

pub fn zero_vec(n: usize) -> Self

Vector field of n zero vectors.

Source

pub fn dot_field(&self, rhs: &Field<Vector3>) -> Field<f64>

Element-wise dot product → scalar field.

Source

pub fn scale(&self, s: &Field<f64>) -> Self

Scale each element by the corresponding scalar field entry.

Trait Implementations§

Source§

impl<T: Add<Output = T> + Clone> Add for Field<T>

Source§

type Output = Field<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl<T: Add<Output = T> + Clone> AddAssign for Field<T>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T> AsRef<[T]> for Field<T>

Source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone> Clone for Field<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Field<T>

Source§

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

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

impl Default for Field<f64>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Default for Field<Vector3>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Default for Field<Tensor>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Default for Field<SymmTensor>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Default for Field<SphericalTensor>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Div for Field<f64>

Source§

type Output = Field<f64>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self

Performs the / operation. Read more
Source§

impl<T: Mul<f64, Output = T> + Clone> Div<f64> for Field<T>

Source§

type Output = Field<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self

Performs the / operation. Read more
Source§

impl<T: Clone> From<Vec<T>> for Field<T>

Source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> Index<usize> for Field<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for Field<T>

Source§

fn index_mut(&mut self, i: usize) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> IntoIterator for Field<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a Field<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Mul for Field<f64>

Source§

type Output = Field<f64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl Mul<Field<Vector3>> for f64

Source§

type Output = Field<Vector3>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Field<Vector3>) -> Field<Vector3>

Performs the * operation. Read more
Source§

impl Mul<Field<Vector3>> for Field<f64>

Source§

type Output = Field<Vector3>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Field<Vector3>) -> Field<Vector3>

Performs the * operation. Read more
Source§

impl Mul<Field<f64>> for f64

Source§

type Output = Field<f64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Field<f64>) -> Field<f64>

Performs the * operation. Read more
Source§

impl Mul<Field<f64>> for Field<Vector3>

Source§

type Output = Field<Vector3>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Field<f64>) -> Field<Vector3>

Performs the * operation. Read more
Source§

impl<T: Mul<f64, Output = T> + Clone> Mul<f64> for Field<T>

Source§

type Output = Field<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self

Performs the * operation. Read more
Source§

impl<T: Neg<Output = T> + Clone> Neg for Field<T>

Source§

type Output = Field<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<T: PartialEq> PartialEq for Field<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Field<T>

Source§

impl<T: Sub<Output = T> + Clone> Sub for Field<T>

Source§

type Output = Field<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<T: Sub<Output = T> + Clone> SubAssign for Field<T>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Field<T>
where Vec<T>: Freeze,

§

impl<T> RefUnwindSafe for Field<T>
where Vec<T>: RefUnwindSafe,

§

impl<T> Send for Field<T>
where Vec<T>: Send,

§

impl<T> Sync for Field<T>
where Vec<T>: Sync,

§

impl<T> Unpin for Field<T>
where Vec<T>: Unpin,

§

impl<T> UnsafeUnpin for Field<T>
where Vec<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Field<T>
where Vec<T>: 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> 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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.