# ARYSUB

ModelingCalculates the values for a user-defined input array element.

## Use

<Reference_Array
id                  = "30100100"
type                = "U"
num_element         = "6"
usrsub_param_string = "USER(502,11401020,11701100,339.3,207)"
usrsub_dll_name     = "NULL"
usrsub_fnc_name     = "ARYSUB"
/>

## Format

Fortran Calling Syntax
SUBROUTINE ARYSUB (ID, TIME, PAR, NPAR, DFLAG, IFLAG, NVALUE, VALUE)
C/C++ Calling Syntax
void STDCALL ARYSUB (int *id, double *time, double *par, int *npar, int *dflag, int *iflag, int *nvalue, double *value)
Python Calling Syntax
def ARYSUB(id, time, par, npar, dflag, iflag, nvalue):
MATLAB Calling Syntax
function value = ARYSUB(id, time, par, npar, dflag, iflag, nvalue)

## Attributes

ID
[integer]
The array element identifier.
TIME
[double precision]
The current simulation time.
PAR
[double precision]
An array that contains the constant arguments from the list provided in the user-defined statement.
NPAR
[integer]
The number of entries in the PAR array.
DFLAG
[logical]
A Boolean variable that MotionSolve sets to true when it needs partial derivatives. Otherwise, it is set to false.
IFLAG
[logical]
A Boolean variable that MotionSolve sets to true when it needs to know on which functions CNFSUB depends. When the flag is set to false, then the values of the user-defined expressions are computed.
NVALUES
The number of values the user-defined Reference_Array contains.

## Output

VALUES
[double precision]
Output array that contains the values for the user-defined Reference_Array.

## Example

This example describes how ARYSUB is used to calculate six state-dependent quantities that obey the following mathematical law:

$\begin{array}{l}A=-F\left(X\right)-CV\\ B=-{K}_{t}Y-{C}_{t}\omega \end{array}$

$X$ is a 3x1 matrix that represents the displacement vector from the origin of a J Marker to the origin of the I Marker as measured in the global coordinate system.

$V$ is a 3x1 matrix that represents the time derivative of {X}.

$Y$ is a 3x1 matrix that represents the small angle rotation of the I Marker with respect to the J Marker.

$\omega$ is a 3x1 matrix that represents angular velocity of the I Marker with respect to the J Marker as measured in the ground coordinate system.

$C,{K}_{T},{C}_{T}$ are 3x3 diagonal matrices that are passed in to ARYSUB through the PAR array.

$F\left(X\right)$ is a 3x1 matrix whose entries are defined as spline functions of the displacement X.

def ARYSUB(id, time, par, npar, dflag, iflag, nvalue)
# Initialize outputs first
errflg =0
value = 6*[0.0]

# Get I/J, the spline ids and [K]/[C] matrices from PAR
Ipar = []
ipar.append(int(par))
ipar.append(int(par))

kx_spl_id=int(par)
ky_spl_id=int(par)
kz_spl_id=int(par)

ktx=par
kty=par
ktz=par

cx=par
cy=par
cz=par

ctx=par
cty=par
ctz=par

# Calculate AX(I,J),AY(I,J),AZ(I,J)
[ax,errflg]=py_sysfnc("ax",ipar)
[ay,errflg]=py_sysfnc("ay",ipar)
[az,errflg]=py_sysfnc("az",ipar)

#CalculateDX(I,J,J),DY(I,J,J),DZ(I,J,J)
ipar.append(int(par))
[dx,errflg]=py_sysfnc("dx",ipar)
[dy,errflg]=py_sysfnc("dy",ipar)
[dz,errflg]=py_sysfnc("dz",ipar)

#CalculateWX(I,J,J),WY(I,J,J),WZ(I,J,J)
[wx,errflg]=py_sysfnc("wx",ipar)
[wy,errflg]=py_sysfnc("wy",ipar)
[wz,errflg]=py_sysfnc("wz",ipar)

#CalculateVX(I,J,J,J),VY(I,J,J,J),VZ(I,J,J,J)
ipar.append(int(par))
[vx,errflg]=py_sysfnc("vx",ipar)
[vy,errflg]=py_sysfnc("vy",ipar)
[vz,errflg]=py_sysfnc("vz",ipar)

#Calculate{F(x)}
[fx,errflg]=py_akispl(-dx,0.0,kx_spl_id,0)
[fy,errflg]=py_akispl(-dy,0.0,ky_spl_id,0)
[fz,errflg]=py_akispl(-dz,0.0,kz_spl_id,0)

#{a}
value=fx-cx*vx
value=fy-cy*vy
value=fz-cz*vz

#{b}
value=-ktx*ax-ctx*wx
value=-kty*ay-cty*wy
value=-ktz*az-ctz*wz
return value

1. ARYSUB can only be defined for an input array element. For example: Reference_Array with type="U".
2. The ID of the Reference_Array, defined with ARYSUB, may be referenced as the u_array_id in Control_StateEqn or Force_StateEqn element. For example:
<Control_StateEqn
id                  = "301001"
type                = "USERSUB"
x_array_id          = "30100200"
y_array_id          = "30100300"
u_array_id          = "30100100"
num_state           = "2"
num_output          = "1"
is_static_hold      = "FALSE"
usrsub_param_string = "USER(998,0,1,-10,.1,10,0,0,1)"
usrsub_dll_name     = "NULL"
usrsub_fnc_name     = "GSESUB"
usrsub_der1_name    = "GSEXX"
usrsub_der2_name    = "GSEXU"
usrsub_der3_name    = "GSEYX"
/>
<Force_StateEqn
id                  = "301001"
type                = "USERSUB"
x_array_id          = "535050504"
y_array_id          = "535050508"
u_array_id          = "535050505"
num_state           = "2"
num_output          = "6"
usrsub_param_string = "USER(1001,100.,0.31625,0.0004,1.,5.,5,3,0.5,0.3,0.)"
usrsub_dll_name     = "ms_csubdll"
usrsub_fnc_name     = "YFOSUB"
is_static_hold      = "FALSE"
i_marker_id         = "30101020"
j_floating_marker_id= "30102020"
ref_marker_id       = "30102020"
/>