[ANSYS, Inc. Logo] return to home search
next up previous contents index

3.4.4 Vector Operation Macros

There are macros that you can use in your UDFs that will allow you to perform operations such as computing the vector magnitude, dot product, and cross product. For example, you can use the real function NV_MAG(V) to compute the magnitude of vector V. Alternatively, you can use the real function NV_MAG2(V) to obtain the square of the magnitude of vector V.



Vector Magnitude Using NV_MAG and NV_MAG2


The utility NV_MAG computes the magnitude of a vector. This is taken as the square root of the sum of the squares of the vector components.

NV_MAG(x) 

    2D:  sqrt(x[0]*x[0] + x[1]*x[1]); 
    3D:  sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);

The utility NV_MAG2 computes the sum of squares of vector components.

NV_MAG2(x) 

    2D:  (x[0]*x[0] + x[1]*x[1]); 
    3D:  (x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);

See Section  2.5.1 for an example UDF that utilizes NV_MAG.



Dot Product


The following utilities compute the dot product of two sets of vector components.

ND_DOT(x, y, z, u, v, w) 

    2D:  (x*u + y*v); 
    3D:  (x*u + y*v + z*w); 
  

NV_DOT(x, u) 

    2D:  (x[0]*u[0] + x[1]*u[1]); 
    3D:  (x[0]*u[0] + x[1]*u[1] + x[2]*u[2]); 
  

NVD_DOT(x, u, v, w) 

    2D:  (x[0]*u + x[1]*v); 
    3D:  (x[0]*u + x[1]*v + x[2]*w);

See Section  2.3.6 for an example UDF that utilizes NV_DOT.



Cross Product


For 3D, the CROSS macros return the specified component of the vector cross product. For 2D, the macros return the cross product of the vectors with the $z$-component of each vector set to $0$.

ND_CROSS_X(x0,x1,x2,y0,y1,y2)
   2D:  0.0
   3D:  (((x1)*(y2))-(y1)*(x2)))

ND_CROSS_Y(x0,x1,x2,y0,y1,y2)
   2D:  0.0
   3D:  (((x2)*(y0))-(y2)*(x0)))

ND_CROSS_Z(x0,x1,x2,y0,y1,y2)
   2D and 3D: (((x0)*(y1))-(y0)*(x1)))

NV_CROSS_X(x,y)
   ND_CROSS_X(x[0],x[1],x[2],u[0],y[1],y[2])

NV_CROSS_Y(x,y)
    ND_CROSS_X(x[0],x[1],x[2],u[0],y[1],y[2])

NV_CROSS_Z(x,y)
    ND_CROSS_X(x[0],x[1],x[2],u[0],y[1],y[2])

NV_CROSS(a,x,y)

    a[0] = NV_CROSS_X(x,y);
    a[1] = NV_CROSS_Y(x,y);
    a[2] = NV_CROSS_Z(x,y);

See Section  2.6.4 for an example UDF that utilizes NV_CROSS.


next up previous contents index Previous: 3.4.3 The NV Macros
Up: 3.4 Vector and Dimension
Next: 3.5 Time-Dependent Macros
Release 12.0 © ANSYS, Inc. 2009-01-14