API
PhysicalVectors.AbstractMetric
— TypeAbstractMetric{D, T}
An abstract type representing a metric tensor in a D
-dimensional space with elements of type T
. This type is a subtype of AbstractMatrix{T}
, indicating that it behaves like a matrix and can be used to define geometric properties such as distances and angles in a given space.
Parameters
D
: dimensionality of the spaceT
: element type of the metric tensor
This type is intended to be extended by concrete implementations of specific metrics.
PhysicalVectors.AbstractPhysicalVector
— TypeAbstractPhysicalVector{D, T}
An abstract type representing a physical vector with a specific dimension D
and element type T
.
This type inherits from AbstractVector{T}
and serves as a base type for defining vectors that have physical or geometric interpretations.
Parameters
D
: dimension of the vector (e.g., 2 for 2D, 3 for 3D)T
: type of the elements in the vector (e.g.,Float64
)
This type is intended to be extended by concrete implementations that define specific behaviours and properties of physical vectors. For instance, VectorLorentz
and VectorEuclidean
are such concrete sub-types.
PhysicalVectors.FourCurrentDensity
— Typestruct FourCurrentDensity{D, T, V <: StaticVector{D, T}} <: AbstractPhysicalVector{D, T}
Constructors for the FourCurrentDensity
type. This is a usual FourXXX
quantity. This structure allows for new methods and explicit dispatching.
Parameters
D
: the dimensionality of the vectorT
: the numeric type of the vector elements (e.g.,AbstractFloat
)V
: a subtype ofStaticVector
representing the underlying vector type
PhysicalVectors.FourMomentum
— Typestruct FourMomentum{D, T, V <: StaticVector{D, T}} <: AbstractPhysicalVector{D, T}
Constructors for the FourMomentum
type. This is a usual FourXXX
quantity. This structure allows for new methods and explicit dispatching.
Parameters
D
: the dimensionality of the vectorT
: the numeric type of the vector elements (e.g.,AbstractFloat
)V
: a subtype ofStaticVector
representing the underlying vector type
PhysicalVectors.FourPosition
— Typestruct FourPosition{D, T, V <: StaticVector{D, T}} <: AbstractPhysicalVector{D, T}
Constructors for the FourPosition
type. This is a usual FourXXX
quantity. This structure allows for new methods and explicit dispatching.
Parameters
D
: the dimensionality of the vectorT
: the numeric type of the vector elements (e.g.,AbstractFloat
)V
: a subtype ofStaticVector
representing the underlying vector type
PhysicalVectors.FourVelocity
— Typestruct FourVelocity{D, T, V <: StaticVector{D, T}} <: AbstractPhysicalVector{D, T}
Constructors for the FourVelocity
type. This is a usual FourXXX
quantity. This structure allows for new methods and explicit dispatching.
Parameters
D
: the dimensionality of the vectorT
: the numeric type of the vector elements (e.g.,AbstractFloat
)V
: a subtype ofStaticVector
representing the underlying vector type
PhysicalVectors.MetricEuclid
— TypeMetricEuclid
A structure representing an Euclidean metric in D
-dimensional space. This metric is parameterised by:
D
: the dimensionality of the spaceT
: the numeric type of the elements (e.g.,Float64
)
This type is a subtype of AbstractMetric{N, T}
and is used to represent and work with Euclidean metrics in a statically-typed manner.
Fields
metric::V
: a static matrix that defines the Euclidean metric
Available constructors
MetricEuclid(m::AbstractMatrix{D, D, T})
MetricEuclid(d::Integer, ::Type{T})
MetricEuclid(d::Integer)
PhysicalVectors.MetricMinkowski
— TypeMetricMinkowski
A structure representing the Minkowski metric in an N-dimensional space. This metric is parameterised by:
D
: the dimensionality of the spaceT
: the numeric type of the elements (e.g.,Float64
,Int64
)
This type is a subtype of AbstractMetric{D, T}
and is used to represent and work with Euclidean metrics in a statically-typed manner. The last element of the metric is the time-dependent one.
Fields
metric::V
: a static matrix that defines the Minkowski metric
Available constructors
MetricMinkowski(d::Integer, ::Type{T}, ::Type{S})
MetricMinkowski(d::Integer, ::Type{S}, ::Type{T})
MetricMinkowski(d::Integer, ::Type{T})
MetricMinkowski(d::Integer, ::Type{S})
MetricMinkowski(d::Integer)
PhysicalVectors.MetricSignatureConvention
— TypeMetricSignatureConvention
Abstract type representing a convention for metric signature in spacetime geometries. This is implemented for completeness. The mostly-plus signature is obviously the better one, despite the wide adoption of the mostly-minus convetion in high-energy physics.
Sub-types
MostlyMinus
: Represents the "mostly minus" convention, where the metric signature is typically (+, -, -, -, ...)MostlyPlus
: Represents the "mostly plus" convention, where the metric signature is typically (-, +, +, +, ...)
These types can be used to specify the metric signature convention in calculations involving spacetime metrics.
PhysicalVectors.MostlyMinus
— TypeMostlyMinus
In this case, the corresponding Minkowski-like metric has the signature (+, -, -, -). This is the convention used in high-energy physics, where the time component is positive and the spatial components are negative.
PhysicalVectors.MostlyPlus
— TypeMostlyPlus
In this case, the corresponding Minkowski-like metric has the signature (-, +, +, +). This is the convention used in general relativity, where the time component is negative and the spatial components are positive.
PhysicalVectors.VectorLorentz
— TypeVectorLorentz{D, T, V <: StaticVector{D, T}}
A structure representing a Lorentzian vector in a physical vector space.\ It is parameterised by:
- D
: dimensionality of the vector
- T
: element type of the vector
- V
: sub-type of StaticVector{D, T}
representing the underlying static vector
Fields
vector::V
: the underlying static vector storing the data
Available constructors
VectorLorentz(v::StaticVector{D, T})
VectorLorentz(v::AbstractVector{T})
VectorLorentz(vs::Vararg{<: Number})
PhysicalVectors.VectorSpatial
— TypeVectorSpatial{D, T, V <: StaticVector{D, T}}
A structure representing a spatial vector in a physical vector space.\ It is parameterised by:
- D
: dimensionality of the vector
- T
: element type of the vector
- V
: sub-type of StaticVector{D, T}
representing the underlying static vector
Fields
vector::V
: the underlying static vector storing the data.
Available constructors
VectorSpatial(v::StaticVector{D, T})
VectorSpatial(v::AbstractVector{T})
VectorSpatial(vs::Vararg{<: Number})
LinearAlgebra.cross
— Functioncross
Defines the cross
function commonly used for vector products. This is a placeholder definition and should be extended with specific methods for the desired types.
LinearAlgebra.cross
— Methodcross(v1::VectorSpatial, v2::VectorSpatial) -> VectorSpatial
Compute the cross product of two 3D spatial vectors v1
and v2
.
This function is only defined for 3-dimensional vectors.
It throw a DimensionMismatch
error if the vectors are not 3D.
Input
v1::VectorSpatial
: first 3D spatial vectorv2::VectorSpatial
: second 3D spatial vector
Output
- A new
VectorSpatial
object representing the cross product ofv1
andv2
.
Notes
The cross product is only defined for 3-dimensional vectors. Ensure that both input vectors have a length of 3 before calling this function.
LinearAlgebra.dot
— Functiondot
Defines the dot
function, which is typically used to compute the dot product of two vectors. This is a placeholder definition and should be extended with specific methods for the desired types.
LinearAlgebra.dot
— Methoddot(v1::VectorSpatial{D, T1}, v2::VectorSpatial{D, T2}) -> Number
dot(v1::VectorSpatial{D, T1}, v2::VectorSpatial{D, T2}, m::AbstractMetric) -> Number
Computes the dot product of two spatial vectors v1
and v2
using their internal vector representations, for a given metric m
.
The metric here makes no difference whatsoever, as the dot product is invariant under any metric, by construction.
The method involving the metric is included for consistency with the Lorentzian case.
Input
v1::VectorLorentz
: first Lorentz vectorv2::VectorLorentz
: second Lorentz vector
. (optional) m::AbstractMetric
: an AbstractMetric
-type object; defaults to Minkowski
Output
Number
: the dot product of the two Lorentz vectors
LinearAlgebra.dot
— Methoddot(v1::VectorLorentz, v2::VectorLorentz, m::AbstractMetric) -> Number
dot(v1::VectorLorentz{D, T1, V}, v2::VectorLorentz{D, T2, V}, ::MetricEuclid{D, U}) -> T
dot(v1::VectorLorentz{D, T1, V}, v2::VectorLorentz{D, T2, V}, ::MetricMinkowski{D, U, S}) -> T
Computes the dot product of two Lorentz vectors v1
and v2
using their internal vector representations, for a given metric m
.
Input
v1::VectorLorentz
: first Lorentz vectorv2::VectorLorentz
: second Lorentz vector
Output
"- Number
: the dot product of the two Lorentz vectors."
LinearAlgebra.norm
— Methodnorm(v::AbstractPhysicalVector{D, T}) -> T
norm(v::AbstractPhysicalVector{D, T}, m::AbstractMetric{D, U}) -> T
Compute the norm of a Lorentz vector v
using the default metric. The norm is defined as the square root of the dot product of the vector with itself.
Input
v::VectorLorentz
: the Lorentz vector whose norm is to be computed.
Output
T
: The computed norm of the Lorentz vector
PhysicalVectors._getSignature
— Method_getSignature(d::Integer, ::Type{MostlyPlus}, ::Type{T}) where {T <: AbstractFloat}
_getSignature(d::Integer, ::Type{MostlyMinus}, ::Type{T}) where {T <: AbstractFloat}
Computes the signature vector for a Minkowski metric with d
dimensions, where the metric is mostly positive/negative. The resulting vector has d-1
positive (negative) entries (1.0) followed by a single negative (positive) entry (-1.0).
Input
d::Integer
: number of dimensions::Type{MostlyPlus}
: type marker indicating a mostly positive metric::Type{T}
: floating-point type of the resulting vector elements
Output
A static vector (SVector
) of type T
representing the signature.
PhysicalVectors.getChargeDensity
— MethodgetChargeDensity(v::FourCurrentDensity) -> AbstractFloat
Computes the charge density of a FourCurrentDensity
object v
. The charge density is calculated as the temporal part of the four-current divided by the speed of light c
.
Input
v::FourCurrentDensity
: four-current object for which the charge density is to be computed
Output
AbstractFloat
: the charge density corresponding to the given four-current in units of C/m³
PhysicalVectors.getCurrentDensity
— MethodgetCurrent(v::FourCurrentDensity) -> VectorSpatial
Extracts the spatial part of a FourCurrentDensity
object.
Input
v::FourCurrentDensity
: the four-current object from which the spatial part (current) is to be extracted
Output
- The
VectorSpatial
representing the spatial current component of the inputFourCurrentDensity
PhysicalVectors.getEnergy
— MethodgetEnergy(v::FourMomentum) -> AbstractFloat
Compute the energy of a FourMomentum
object v
. The energy is calculated as the temporal part of the four-momentum multiplied by the speed of light c
.
Input
v::FourMomentum
: four-momentum object for which the energy is to be computed
Output
AbstractFloat
: the energy corresponding to the given four-momentum in units of Joules
PhysicalVectors.getMetricTensor
— MethodgetMetric(m::AbstractMetric{D, T}) -> T
Retrieve the metric tensor from an AbstractMetric
object.
Input
m::AbstractMetric{D, T}
: an instance of a subtype ofAbstractMetric
, whereD
is the dimensionality andT
is the type of the metric tensor.
Output
T
: the metric tensor associated with the givenAbstractMetric
object.
PhysicalVectors.getMomentum
— MethodgetMomentum(v::FourMomentum) -> VectorSpatial
Extracts the spatial part of a FourMomentum
object.
Input
v::FourMomentum
: the four-momentum object from which the spatial part (momentum) is to be extracted
Output
- The
VectorSpatial
representing the spatial momentum component of the inputFourMomentum
PhysicalVectors.getPosition
— MethodgetPosition(p::FourPosition) -> VectorSpatial
Retrieve the spatial part of a FourPosition
object.
Input
x::FourPosition
: four-position object from which the time component is extracted
Output
VectorSpatial
: the spatial part of the four-position
PhysicalVectors.getSpatialPart
— MethodgetSpatialPart(v::VectorLorentz) -> VectorSpatial
Extracts the spatial part of a VectorLorentz
object.
The spatial part is obtained by taking all elements of the internal vector except the last one.
Input
v::VectorLorentz
: a Lorentz vector from which the spatial part is to be extracted.m::AbstractMetric
: anAbstractMetric
-type object; defaults to Minkowski
Output
VectorSpatial
: an Euclidean vector containing the spatial components of the input Lorentz vector.
PhysicalVectors.getTemporalPart
— MethodgetTemporalPart(v::VectorLorentz) -> Vector{T}
Extracts the temporal part of a VectorLorentz
object.
The temporal part is assumed to be the last element of the vector representation.
Input
v::VectorLorentz
: Lorentz vector from which the temporal part is to be extracted
Output
- A one-element vector containing the temporal part of the input
VectorLorentz
PhysicalVectors.getTime
— MethodgetTime(p::FourPosition) -> AbstractFloat
Computes the time component of a FourPosition
object by dividing its temporal part by the speed of light c
.
Input
x::FourPosition
: four-position object from which the time component is extracted
Output
AbstractFloat
: the time component of the four-position
PhysicalVectors.isMostlyPlus
— MethodisMostlyPlus(m::MetricMinkowski) -> Bool
isMostlyMinus(m::MetricMinkowski) -> Bool
Determines the signature convention of the Minkowski metric.
Input
m::MetricMinkowski{D, T, MostlyPlus}
: Minkowski metric object with "mostly plus" conventionm::MetricMinkowski{D, T, MostlyMinus}
: Minkowski metric object with "mostly minus" convention
Output
true
if the metric is "mostly plus"false
if the metric is "mostly minus"
PhysicalVectors.norm2
— Methodnorm2(v::AbstractPhysicalVector{D, T}) -> T
norm2(v::AbstractPhysicalVector{D, T}, m::AbstractMetric{D, U}) -> T
norm²(args...) -> T
Compute the squared norm of a Lorentz vector v
using the default metric. The norm is defined as the square root of the dot product of the vector with itself.
Input
v::AbstractPhysicalVector
: the vectorm::AbstractMetric
: the metric used to compute the dot product (optional)
Output
T
: The computed norm2 of the Lorentz vector
PhysicalVectors.numberOfDimensions
— FunctionnumberOfDimensions(metric::AbstractMetric{D, T}) -> D
numberOfDimensions(vector::AbstractPhysicalVector{D, T}) -> D
Retrieve the number of dimensions of an object. This function is not exported, as it is intended for internal use within packages.
PhysicalVectors.numberOfDimensions
— MethodnumberOfDimensions(v::AbstractPhysicalVector{D, T}) -> D
Returns the number of dimensions of a given physical vector.
PhysicalVectors.speedOfLightFor
— MethodspeedOfLightFor(v::AbstractPhysicalVector{D, T}) -> c
Returns the speed of light in vacuum for a given physical vector. If T is a subtype of Unitful.Quantity
, it returns the speed of light in the same units as the vector. If T is not a subtype of Unitful.Quantity
, it returns the speed of light in SI units (m/s).
Input
v
: a physical vector of typeAbstractPhysicalVector{D, T}
whereD
is the dimension andT
is the element type
Output
c
: the speed of light in the same units as the vector if T is a subtype ofUnitful.Quantity
, otherwise in SI units (m/s)
PhysicalVectors.@generateFourVector
— Macro@generateFourVector(quantity)
Macro to generate a FourQuantity
type and its associated methods.
This macro defines a new struct type for a four-dimensional physical quantity, along with constructors and utility methods for operations such as dot products and accessing temporal and spatial parts.
Input
quantity
: name of the four-dimensional quantity to be generated
Generated Code
- A struct definition for the
quantity
type, which is a subtype ofAbstractPhysicalVector
- Constructors for the
quantity
type:
-- from a `VectorLorentz` object
-- from an `AbstractVector`
-- from a variable number of scalar arguments
- Overloaded
Base.getproperty
to delegate property access to the underlyingVectorLorentz
- Utility functions:
-- `getTemporalPart`: the temporal part of the vector
-- `getSpatialPart`:retrieves the spatial part of the vector
-- `dot`: computes the dot product of two `quantity` objects, optionally using a metric
PhysicalVectors.@physicalVectorConstructors
— Macro@physicalVectorConstructors(vector)
A macro that generates constructor methods for a custom VectorXXX
sub-typing from AbstractPhysicalVector
.
This macro is not exported and is intended for internal use within the package.
The generated constructors allow for the creation of VectorXXX
instances from different input types, including:
1. Static Vectors (SVector
):
. Accepts an SVector{D, T}
where D
is the dimension and T
is a subtype of Number
.
. Returns an instance of vector
parameterised by D
, T
, and the type of the input vector.
2. Abstract Vectors:
. Accepts an AbstractVector{T}
where T
is a subtype of Number
.
. Converts the input vector to a mutable MVector
and returns an instance of vector
parameterised by the length of the input vector, T
, and the type of the converted vector.
3. Varargs:
. Accepts a variable number of arguments of type T
(where T
is a subtype of Number
).
. Constructs an MVector
from the arguments and returns an instance of vector
.
This macro simplifies the creation of constructors for custom vector types, ensuring compatibility with various input formats.