! ******************************
! $Revision: 145002 $
! $Date: 2009-11-13 11:20:27 -0500 (Fri, 13 Nov 2009) $
! ******************************
! macro MTchkbc (_envnum)

! *** primary function: check for sufficient displacement constraints

! *** Notice - This file contains ANSYS Confidential information ***

!  input arguments:
!   _envnum    (arg1)    (int,sc)      environment number to check

!  output arguments:
!   _success            (int,sc)      =0 no success, =1 success  


/nopr
_SUCCESS=1

! --- debug
*if,_DEBUG,gt,0,then
!{
   /gopr
   *vwrite,arg1
   (' === MTchkbc:    envnum =',f3.0)
   *if,_DEBUG,lt,3,then
   !{
      /nopr
   !}
   *endif
!}
*endif

! --- check arguments
_envnum = ARG1
*if,_envnum,lt,1,then
!{
   *msg,error,_envnum
   MTchkbc error: The environment number envnum is %I
   _SUCCESS=0
!}
*elseif,_envnum,gt,_NUMENV,then
!{
   *msg,error,_envnum
   MTchkbc error: The environment number envnum is %I
   _SUCCESS=0
!}
*endif

*if,_SUCCESS,gt,0,then

_ACTENV = '_ENV%_envnum%'

*get,_keydim,active,,solu,dimn

*VFILL,_MASK2(1),ramp,_FREE,0
!
! test for ux
_existux=0
*if,_keydim,eq,1,then
   _existux=1      ! no ux needed for axisymmetric
*else
   *do,_i,1,3 
      *VOPER,_MASK1(1),%_ACTENV%(1,2,_i),NE,_MASK2(1)
      *VMASK,_MASK1(1)
      *VSCFUN,_xjunk,num,%_ACTENV%(1,2,_i)
      _existux=_existux+_xjunk
   *enddo
*endif
!
! test for uy
_existuy=0
*do,_i,1,3
   *VOPER,_MASK1(1),%_ACTENV%(1,3,_i),NE,_MASK2(1)
   *VMASK,_MASK1(1)
   *VSCFUN,_xjunk,num,%_ACTENV%(1,3,_i)
   _existuy=_existuy+_xjunk
*enddo
!
! test for uz
_existuz=0
*if,_keydim,le,2,then
   _existuz=1      ! no uz needed for 2-D or axisymmetric
*else
   *do,_i,1,3
      *VOPER,_MASK1(1),%_ACTENV%(1,4,_i),NE,_MASK2(1)
      *VMASK,_MASK1(1)
      *VSCFUN,_xjunk,num,%_ACTENV%(1,4,_i)
      _existuz=_existuz+_xjunk
   *enddo
*endif

_dirlab=' '
_dirlabx=' ' 
_dirlaby=' ' 
_dirlabz=' '
_SUCCESS=1
*if,_existux,eq,0,then
   _dirlabx='X'
   _SUCCESS=0
*endif

*if,_existuy,eq,0,then
   _dirlaby='Y'
   _SUCCESS=0
*endif

*if,_existuz,eq,0,then
   _dirlabz='Z'
   _SUCCESS=0
*endif

! check for any symmetry
*vmask,%_ACTENV%(1,12,1)
*vscfun,_xjunk8,num,%_ACTENV%(1,12,1) !number of areas w/ symmetry
*vmask,%_ACTENV%(1,12,2)
*vscfun,_xjunk9,num,%_ACTENV%(1,12,2) !number of lines w/ symmetry 
*if,(_xjunk8+_xjunk9),ge,1,then
   _SUCCESS=1
*endif

*if,_SUCCESS,eq,0,then
   _dirlab=strcat(_dirlabx,_dirlaby)
   _dirlab=strcat(_dirlab,_dirlabz)
   _i=_envnum
   *msg,ui,_dirlab,_ENVNAM(_i,1),_ENVNAM(_i,2),_ENVNAM(_i,3),_ENVNAM(_i,4)
   Constraints are needed in the %C direction(s) in order to solve environment %C %C %C %C
*endif


*endif

*if,_DEBUG,gt,0,then
!{
   /gopr
   /com, === leave MTchkbc
!}
*endif


! delete local variables
*del,_envnum
*del,_existux
*del,_existuy
*del,_existuz
*del,_dirlab
*del,_dirlabx
*del,_dirlaby
*del,_dirlabz
*del,_i
*del,_xjunk
*del,_xjunk8
*del,_xjunk9
*del,_keydim
