Celeritas 0.7+d9d378c
Loading...
Searching...
No Matches
Functions
SpanUtils.hh File Reference

Math functions using celeritas::Span. More...

#include <cstddef>
#include "corecel/cont/Span.hh"
#include "ArrayUtils.hh"
#include "detail/SpanUtilsImpl.hh"

Functions

template<class T , std::size_t N>
void celeritas::copy (Span< T const, N > src, Span< T, N > dst)
 Copy all elements from src to dst.
 
template<class T , std::size_t N>
void celeritas::fill (T value, Span< T, N > dst)
 Fill all elements of dst with a constant value.
 
template<class T , std::size_t N>
void celeritas::axpy (T a, Span< T const, N > x, Span< T, N > y)
 Increment a vector span by another vector span multiplied by a scalar.
 
template<class T , std::size_t N>
T celeritas::dot_product (Span< T const, N > x, Span< T const, N > y)
 Dot product of two vector spans.
 
template<class T >
void celeritas::cross_product (Span< T const, 3 > x, Span< T const, 3 > y, Span< T, 3 > dst)
 Cross product of two space vector spans, written into dst.
 
template<class T , std::size_t N>
T celeritas::norm (Span< T const, N > v)
 Calculate the Euclidean (2) norm of a vector span.
 
template<class T , std::size_t N>
void celeritas::make_unit_vector (Span< T const, N > v, Span< T, N > dst)
 Write a unit-magnitude version of v into dst.
 
template<class T , std::size_t N>
void celeritas::make_orthogonal (Span< T const, N > x, Span< T const, N > y, Span< T, N > dst)
 Write the component of x orthogonal to the unit vector y into dst.
 
template<class T , std::size_t N>
bool celeritas::is_soft_orthogonal (Span< T const, N > x, Span< T const, N > y)
 Check whether two unit vector spans are approximately orthogonal.
 
template<class T , std::size_t N>
bool celeritas::is_soft_collinear (Span< T const, N > x, Span< T const, N > y)
 Check whether two unit vector spans are approximately collinear.
 
template<class T , std::size_t N>
T celeritas::distance (Span< T const, N > x, Span< T const, N > y)
 Calculate the Euclidean (2) distance between two point spans.
 
template<class T >
void celeritas::from_spherical (T costheta, T phi, Span< T, 3 > dst)
 Write a Cartesian unit vector from spherical coordinates into dst.
 
template<class T >
void celeritas::rotate (Span< T const, 3 > dir, Span< T const, 3 > rot, Span< T, 3 > dst)
 Rotate a direction span by the rotation defined by rot, writing to dst.
 

Detailed Description

Math functions using celeritas::Span.

See also
SpanUtils.test.cc

Function Documentation

◆ axpy()

template<class T , std::size_t N>
void celeritas::axpy ( T  a,
Span< T const, N >  x,
Span< T, N >  y 
)
inline

Increment a vector span by another vector span multiplied by a scalar.

\[ y \gets \alpha x + y \]

Precondition
x and y must not overlap.

◆ copy()

template<class T , std::size_t N>
void celeritas::copy ( Span< T const, N >  src,
Span< T, N >  dst 
)
inline

Copy all elements from src to dst.

Precondition
src and dst must not overlap.

The current implementation does not take advantage of the lack of overlap.

◆ cross_product()

template<class T >
void celeritas::cross_product ( Span< T const, 3 >  x,
Span< T const, 3 >  y,
Span< T, 3 >  dst 
)
inline

Cross product of two space vector spans, written into dst.

Precondition
x, y, and dst must not overlap.

◆ from_spherical()

template<class T >
void celeritas::from_spherical ( T  costheta,
T  phi,
Span< T, 3 >  dst 
)
inline

Write a Cartesian unit vector from spherical coordinates into dst.

Theta is the angle between the z axis and the outgoing vector, and phi is the angle between the x axis and the projection onto the x-y plane.

◆ is_soft_collinear()

template<class T , std::size_t N>
bool celeritas::is_soft_collinear ( Span< T const, N >  x,
Span< T const, N >  y 
)
inline

Check whether two unit vector spans are approximately collinear.

Precondition
Spans must represent normalized vectors.

◆ make_orthogonal()

template<class T , std::size_t N>
void celeritas::make_orthogonal ( Span< T const, N >  x,
Span< T const, N >  y,
Span< T, N >  dst 
)
inline

Write the component of x orthogonal to the unit vector y into dst.

In this implementation, y must be normalized, and the result is not normalized.

\[ \mathbf{x}' \gets \mathbf{x} - (\mathbf{x} \cdot \mathbf{y}) \mathbf{y} \, , \quad \|\mathbf{y}\| = 1 \]

Precondition
x, y, and dst must not overlap.

◆ make_unit_vector()

template<class T , std::size_t N>
void celeritas::make_unit_vector ( Span< T const, N >  v,
Span< T, N >  dst 
)
inline

Write a unit-magnitude version of v into dst.

Precondition
v and dst must not overlap.

◆ rotate()

template<class T >
void celeritas::rotate ( Span< T const, 3 >  dir,
Span< T const, 3 >  rot,
Span< T, 3 >  dst 
)
inline

Rotate a direction span by the rotation defined by rot, writing to dst.

Precondition
dir, rot, and dst must not overlap.
See also
celeritas::rotate in ArrayUtils.hh for the full description.