udfGetGlobalVector()

Return a user global vector.

Syntax

vec = udfGetGlobalVector( udfHd, name, nDims ) ;

Type

AcuSolve User-Defined Function Global

Parameters

udfHd
The opaque handle (pointer) which was passed to the user function.
name (char*)
Pointer to name of the global vector.
nDims (integer)
Dimension.

Return Value

vec (real)
Pointer to the global vector.

Description

This routine returns a pointer to a named user global vector. For example, the user_function usrMotionRigidBody() computes and stores a motion vector in the global vector named "motion". For example,
MULTIPLIER_FUNCTION( "Fairing" ) {
  type = user_function
  user_function = "usrMotionRigidBody"
  ...
}
where usrMotionRigidBody() has the form:
Void usrMotionRigidBody( UdfHd udfHd,
   Real* outVec,
   Integer nItems,
   Integer vecDim )
{
   Real xDisp ; /* displacement in x */
   Real yDisp ; /* displacement in y */
   Real zRot ; /* rotation in z */
   ...
   /* Calculate displacements and rotation */
   ...
   /* Store displacements and rotation in user global vector */
   vec = udfGetGlobalVector(udfHd, "motion", 3 ) ;
   vec[0] = xDisp ;
   vec[1] = yDsip ;
   vec[2] = zRot ;
   ...
}
The motion vector can be retrieved and used in a nodal boundary condition as follows:
NODAL_BOUNDARY_CONDTION( "x_motion" ) {
  type = user_function
  user_function = "usrMotionNBC"
  user_values = { 1, 0.00150704, 0., -1., 3., .2, -2., 2., .2, .2 }
  nodes = Read( "MESH.DIR/all_nodes.nbc" )
  variable = mesh_x_displacement
}
where the user-defined function usrMotionNBC may be implemented as:
Void usrMotionNBC( UdfHd udfHd, /* opaque handle for accessing information */
               Real* outVec, /* output vector */
               Integer nItems, /* No. of items in outVec (=nNodes here) */
               Integer vecDim ) /* vector dimension of outVec (=1 here) */
{
   Integer dir ; /* direction being computed */
   Integer i ; /* a running index */
   Real* crd ; /* nodal coordinates */
   Real ct ; /* cos( zRot ) - 1 */
   Real dx ; /* change in x */
   Real dy ; /* change in y */
   Real r ; /* distance to CM */
   Real rWidth ; /* r width */
   Real st ; /* sin( zRot ) */
   Real* usrVals ; /* user supplied values */
   Real* vec ; /* computed motion */
   Real xDisp ; /* displacement in x */
   Real xMax ; /* max x location */
   Real xMin ; /* min x location */
   Real xOrg ; /* center of mass */
   Real xs ; /* x scale factor */
   Real xWidth ; /* x width */
   Real x ; /* x location of the point */
   Real yDisp ; /* displacement in y */
   Real yMax ; /* max y location */
   Real yMin ; /* min y location */
   Real yOrg ; /* center of mass */
   Real ys ; /* y scale factor */
   Real yWidth ; /* y width */
   Real y ; /* y location of the point */
   Real zRot ; /* rotation in z */
/* Get the user data. Expected format:
   * user_values =
   * { <direction>, <xOrg>, <yOrg>, <xMin>, <xMax>, <xWidth>,
   * <yMin>, <yMax>, <yWidth>, <rWidth> }
   */
   udfCheckNumUsrVals( udfHd, 10 ) ;
   usrVals = udfGetUsrVals( udfHd ) ;
   dir = (Integer) usrVals[0] ;
   xOrg = usrVals[1] ;
   yOrg = usrVals[2] ;
   xMin = usrVals[3] ;
   xMax = usrVals[4] ;
   xWidth = usrVals[5] ;
   yMin = usrVals[6] ;
   yMax = usrVals[7] ;
   yWidth = usrVals[8] ;
   rWidth = usrVals[9] ;
/* Get the motion */
   vec = udfGetGlobalVector( udfHd, "motion", 3 ) ;
   xDisp = vec[0] ;
   yDisp = vec[1] ;
   zRot = vec[2] ;
/* Get the coordinates */
   crd = udfGetNbcRefCrd( udfHd ) ;
/* Compute the motion */
   for ( i = 0 ; i < nItems ; i++ ) {
         x = crd[0*nItems+i] - xOrg ;
         y = crd[1*nItems+i] - yOrg ;
         xs = 1 ;
         ys = 1 ;
         r = sqrt( x * x + y * y ) / rWidth ;
         r = max( 1, r ) ;
         r = pow( r, 0.7 ) ;
         if ( x > +xWidth ) { xs = 1 - (x - xWidth) / (xMax - xWidth) ; }
         if ( x < -xWidth ) { xs = 1 - (x + xWidth) / (xMin + xWidth) ; }
         if ( y > +yWidth ) { ys = 1 - (y - yWidth) / (yMax - yWidth) ; }
         if ( y < -yWidth ) { ys = 1 - (y + yWidth) / (yMin + yWidth) ; }
         ct = cos( zRot / r ) ;
         st = sin( zRot / r ) ;
         dx = xs * ( xDisp + ct * x - st * y - x ) ;
         dy = ys * ( yDisp + st * x + ct * y - y ) ;
         if ( dir == 1 ) {
         outVec[i] = dx ;
         } else {
         outVec[i] = dy ;
         }
   }
} /* end of usrMotionNBC() */

Errors

This routine expects a valid udfHd.