PLaSK User Manual

vec Class

class plask.vec(z, x, y, dtype=None)
class plask.vec(r, z, dtype=None)
class plask.vec(3, 1, 2)
class plask.vec(1, 3, 2)
class plask.vec(2, 4, 6)
class plask.vec(11, 22, 33)
class plask.vec((2+0j), (0+0j))
class plask.vec(x, y, dtype=None)
class plask.vec(0, 1-2j)
class plask.vec(r, p, z, dtype=None)
class plask.vec(x, y, z, dtype=None)
class plask.vec(z, x, dtype=None)

PLaSK vector.

The constructor arguments depend on the current value of plask.config.axes. However, you must either specify all the components either as the unnamed sequence or as the named keywords.

Parameters:
  • _letter_ (dtype) – Vector components. Their choice depends on the current value of plask.config.axes.
  • dtype (type) – type of the vector components. If this argument is omitted or None, the type is determined automatically.

The order of vector components is always [longitudinal, transverse, vertical] for 3D vectors or [transverse, vertical] for 2D vectors. However, the component names depend on the axes configuration option. Changing this option will change the order of component names (even for existing vectors) accordingly:

plask.config.axes value 2D vector components 3D vector components
xyz, yz, z_up [y, z] [x, y, z]
zxy, xy, y_up [x, y] [z, x, y]
prz, rz, rad [r, z] [p, r, z]
ltv, abs [t, v] [l, t, v]
long,tran,vert, absolute [tran, vert] [long, tran, vert]

Examples

Create two-dimensional vector:

>>> vector(1, 2)
vector(1, 2)

Create 3D vector specifying components in rotated coordinate system:

>>> config.axes = 'xy'
>>> vec(x=1, y=2, z=3)
Create 3D vector specifying components:
>>> config.axes = 'xyz'
>>> vec(x=1, z=2, y=3)
Create 2D vector in cylindrical coordinates, specifying dtype:
>>> config.axes = 'rz'
>>> vec(r=2, z=0, dtype=complex)

To access vector components you may either use attribute names or numerical indexing. The ordering and naming rules are the same as for the construction.

Examples

>>> config.axes = 'xyz'
>>> v = vec(1, 2, 3)
>>> v.z
3
>>> v[0]
1

You may perform all the proper algebraic operations on PLaSK vectors like addition, subtraction, multiplication by scalar, multiplication by another vector (which results in a dot product).

Example

>>> v1 = vec(1, 2, 3)
>>> v2 = vec(10, 20, 30)
>>> v1 + v2
>>> 2 * v1
>>> v1 * v2
140.0
>>> abs(v1)
>>> v3 = vec(0, 1+2j)
>>> v3.conj()
>>> v3.abs2()
5.0

Methods

abs() Magnitude of the vector.
abs2() Squared magnitude of the vector.
conj() Conjugate of the vector.
conjugate() Conjugate of the vector.
copy() Copy of the vector.
dot(other) Dot product with another vector.

Static Attributes

dtype Value type.

Descriptions

Method Details

vec.abs()

Magnitude of the vector. It is always a real number.

vec.abs2()

Squared magnitude of the vector. It is always a real number equal to v * v.

vec.conj()

Conjugate of the vector. It can be called for real vectors, but then it simply returns self

vec.conjugate()

Conjugate of the vector. Alias for conj().

vec.copy()

Copy of the vector. Normally vectors behave like Python containers, and assignement operation makes shallow copy only. Use this method if you want to modify the copy without changing the source.

vec.dot(other)

Dot product with another vector. It is equal to self * other, so the self vector is conjugated.

Static Attribute Details

plask.vec.dtype

Value type.

This attribute is the type of a single element in this vector.