|
#define | math_degrad 0.0174532925199432957692 |
| One degree in radians.
|
|
#define | math_raddeg 57.295779513082320876798 |
| One radian in degrees.
|
|
#define | math_maxSimpsonDepth 20 |
| Maximum recursion depth for the simpson integral rule.
|
|
#define | math_copy(a, b) do { a[0]=b[0];a[1]=b[1];a[2]=b[2]; } while(0) |
| Copies elements of vector b to vector a.
|
|
#define | math_matcopy(a, b) |
| Copies elements of matrix b to matrix a.
|
|
#define | math_dot(a, b) (a[0]*b[0]+a[1]*b[1]+a[2]*b[2]) |
| Calculate dot product a[3] dot b[3].
|
|
#define | math_cross(a, b, c) |
| Calculate cross product for 3D vectors c = a x b.
|
|
#define | math_scalar_triple_product(a, b, c) |
| the mixed or triple product of three vectors (a cross b) dot c mathematica: a={a0,a1,a2};b={b0,b1,b2};c={c0,c1,c2};FullSimplify[Dot[Cross[a,b],c]] -(a2 b1 c0) + a1 b2 c0 + a2 b0 c1 - a0 b2 c1 - a1 b0 c2 + a0 b1 c2
|
|
#define | math_sumew(a, b) do { a[0]=a[0]+b[0];a[1]=a[1]+b[1];a[2]=a[2]+b[2] } while(0) |
| Elementwise vector sum a = a + b.
|
|
#define | math_prod(a, b) do { a[0]=a[0]*b;a[1]=a[1]*b;a[2]=a[2]*b; } while(0) |
| Multiply vector elements with a scalar a = b*a.
|
|
#define | math_matsumew(a, b) |
| Elementwise matrix sum a = a + b.
|
|
#define | math_matprod(a, b) |
| Multiply matrix a with scalar b: a = b*a.
|
|
#define | math_norm(a) (sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])) |
| Calculate norm of 3D vector a.
|
|
#define | math_normc(a1, a2, a3) (sqrt(a1*a1+a2*a2+a3*a3)) |
| Calculate norm of 3D vector from its components a1, a2, a3.
|
|
#define | math_unit(a, b) |
| Calculate unit vector b from a 3D vector a.
|
|
#define | math_xyz2rpz(xyz, rpz) |
| Convert cartesian coordinates xyz to cylindrical coordinates rpz.
|
|
#define | math_rpz2xyz(rpz, xyz) |
| Convert cylindrical coordinates rpz to cartesian coordinates xyz.
|
|
#define | math_vec_rpz2xyz(vrpz, vxyz, phi) |
| Transform vector from cylindrical to cartesian basis: vrpz -> vxyz, phi is the toroidal angle in radians.
|
|
#define | math_vec_xyz2rpz(vxyz, vrpz, phi) |
| Transform vector from cartesian to cylindrical basis: vxyz -> vrpz, phi is the toroidal angle in radians.
|
|
#define | math_determinant3x3(x1, x2, x3, y1, y2, y3, z1, z2, z3) |
| Direct expansion of 3x3 matrix determinant.
|
|
#define | math_deg2rad(a) (a * math_degrad) |
| Convert degrees to radians.
|
|
#define | math_rad2deg(a) (a * math_raddeg) |
| Convert radians to degrees.
|
|
|
DECLARE_TARGET real | fmod (real x, real y) |
| Compute the modulus of two real numbers.
|
|
DECLARE_TARGET_END DECLARE_TARGET_SIMD void | math_jac_rpz2xyz (real *rpz, real *xyz, real r, real phi) |
| Convert a Jacobian from cylindrical to cartesian coordinates.
|
|
GPU_DECLARE_TARGET_SIMD void | math_jac_xyz2rpz (real *xyz, real *rpz, real r, real phi) |
| Convert a Jacobian from cartesian to cylindrical coordinates.
|
|
DECLARE_TARGET_END GPU_DECLARE_TARGET_SIMD void | math_matmul (real *matA, real *matB, int d1, int d2, int d3, real *matC) |
| Matrix multiplication.
|
|
DECLARE_TARGET_END DECLARE_TARGET_SIMD real | math_normal_rand () |
| Generate normally distributed random numbers.
|
|
DECLARE_TARGET_SIMD int | math_ipow (int a, int p) |
| Calculate a^p where both a and p are integers (p >= 0)
|
|
double | math_simpson (double(*f)(double), double a, double b, double epsilon) |
| Adaptive Simpsons rule for integral.
|
|
void | math_linspace (real *vec, real a, real b, int n) |
| Generate linearly spaced vector.
|
|
DECLARE_TARGET_SIMD int | math_point_on_plane (real q[3], real t1[3], real t2[3], real t3[3]) |
| Find if a point is on a given plane.
|
|
DECLARE_TARGET_SIMD void | math_barycentric_coords_triangle (real AP[3], real AB[3], real AC[3], real n[3], real *s, real *t) |
| Find barycentric coordinates for a given point.
|
|
void | math_uniquecount (int *in, int *unique, int *count, int n) |
| Find unique numbers and their frequency in given array.
|
|
DECLARE_TARGET_SIMD real * | math_rsearch (const real key, const real *base, int num) |
| Search for array element preceding a key value.
|
|
int | math_point_in_polygon (real r, real z, real *rv, real *zv, int n) |
| Check if coordinates are within polygon.
|
|
Header file for math.c.
Definition in file math.h.
#define math_scalar_triple_product |
( |
| a, |
|
|
| b, |
|
|
| c ) |
Value: ( - (a[2] * b[1] * c[0] ) \
+ (a[1] * b[2] * c[0] ) \
+ (a[2] * b[0] * c[1] ) \
- (a[0] * b[2] * c[1] ) \
- (a[1] * b[0] * c[2] ) \
+ (a[0] * b[1] * c[2] ) )
the mixed or triple product of three vectors (a cross b) dot c mathematica: a={a0,a1,a2};b={b0,b1,b2};c={c0,c1,c2};FullSimplify[Dot[Cross[a,b],c]] -(a2 b1 c0) + a1 b2 c0 + a2 b0 c1 - a0 b2 c1 - a1 b0 c2 + a0 b1 c2
Definition at line 39 of file math.h.
DECLARE_TARGET_END DECLARE_TARGET_SIMD void math_jac_rpz2xyz |
( |
real * | rpz, |
|
|
real * | xyz, |
|
|
real | r, |
|
|
real | phi ) |
Convert a Jacobian from cylindrical to cartesian coordinates.
This function converts a Jacobian located at angle phi and radius r from cylindrical to cartesian coordinates. The input Jacobian is an array with
[Br dBr/dr dBr/dphi dBr/dz Bphi dBphi/dr dBphi/dphi dBphi/dz Bz dBz/dr dBz/dphi dBz/dz]
an the output is
[Bx dBx/dx dBx/dy dBx/dz By dBy/dx dBy/dy dBy/dz Bz dBz/dx dBz/dy dBz/dz].
- Parameters
-
rpz | input rpz coordinates in a 3-length array |
xyz | output xyz coordinates in a 3-length array |
r | r coordinate of the gradient |
phi | phi coordinate of the gradient |
Definition at line 44 of file math.c.
GPU_DECLARE_TARGET_SIMD void math_jac_xyz2rpz |
( |
real * | xyz, |
|
|
real * | rpz, |
|
|
real | r, |
|
|
real | phi ) |
Convert a Jacobian from cartesian to cylindrical coordinates.
This function converts a Jacobian located at angle phi and radius r from cartesian to cylindrical coordinates. The input Jacobian is an array with
[Bx dBx/dx dBx/dy dBx/dz By dBy/dx dBy/dy dBy/dz Bz dBz/dx dBz/dy dBz/dz]
an the output is
[Br dBr/dr dBr/dphi dBr/dz Bphi dBphi/dr dBphi/dphi dBphi/dz Bz dBz/dr dBz/dphi dBz/dz].
- Parameters
-
xyz | output xyz coordinates in a 3-length array |
rpz | input rpz coordinates in a 3-length array |
r | r coordinate of the gradient |
phi | phi coordinate of the gradient |
Definition at line 103 of file math.c.
DECLARE_TARGET_END DECLARE_TARGET_SIMD real math_normal_rand |
( |
void | | ) |
|
Generate normally distributed random numbers.
This function generates normally distributed random numbers with expected value of 0 and variance of 1 using the polar method [1]. The rand48 random number generator should be initialized with srand48() before calling this function.
[1] G. Marsaglia, T. A. Bray. A convenient method for generating normal variables. Siam Review 6.3 (1964): 260-264. http://epubs.siam.org/doi/abs/10.1137/1006063:w
- Todo
Currently only one of the generated numbers is returned; a second independent variate is Y = v2 * sqrt(-2*log(s) / s)
Try other random number generators such as those in Intel MKL
Definition at line 188 of file math.c.
DECLARE_TARGET_SIMD int math_point_on_plane |
( |
real | q[3], |
|
|
real | t1[3], |
|
|
real | t2[3], |
|
|
real | t3[3] ) |
Find if a point is on a given plane.
Let t1=(x1, y1, z1), t2=(x2, y2, z2), and t3=(x3, y3, z3) be non-collinear points on the plane. Let q =(x, y, z) be an arbitrary point. It lies in the plane if:
det( |x -x1 y -y1 z -z1| |x2-x1 y2-y1 z2-z1| |x3-x1 y3-y1 z3-z1| ) == 0
det( |x -x1 y -y1 z -z1| |x -x2 y -y2 z -z2| |x -x3 y -y3 z -z3| ) == 0
- Parameters
-
q | xyz coordinates of a query point |
t1 | xyz coordinates of the first point defining the plane |
t2 | xyz coordinates of the second point defining the plane |
t3 | xyz coordinates of the third point defining the plane |
Definition at line 324 of file math.c.
Check if coordinates are within polygon.
This function checks if the given coordinates are within a 2D polygon using a modified axis crossing method [1]. Origin is moved to the coordinates and the number of wall segments crossing the positive r-axis are calculated. If this is odd, the point is inside the polygon.
[1] D.G. Alciatore, R. Miranda. A Winding Number and Point-in-Polygon Algorithm. Technical report, Colorado State University, 1995. http://www.engr.colostate.edu/~dga/dga/papers/point_in_polygon.pdf
- Parameters
-
r | r coordinate |
z | z coordinate |
rv | array of r points for the polygon |
zv | array of z points for the polygon |
n | number of points in the polygon |
Definition at line 427 of file math.c.