ansys / pymapdl-reader

Legacy binary interface to MAPDL binary files.
https://reader.docs.pyansys.com
MIT License
47 stars 23 forks source link

mapdl.ndsurf() does not work as expected #201

Closed giiyms closed 1 year ago

giiyms commented 1 year ago

🔍 Before submitting the issue

🐞 Description of the bug

Hello,

I am trying to create a SURF152 surface on nodes using NDSURF.

When using

mapdl.ndsurf('SRF_N','FL1_E',3)

The surface elements are not created.

But if I copy the macro NDSURF.mac (from C:\Program Files\ANSYS Inc\v222\ansys\apdl\NDSURF.mac) to the working directory it works as expected by calling:

mapdl.use("'NDSURF.mac','SRF_N','FL1_E',3") # Works fine ?!

Any ideas?

Also if you do mapdl.nplot() then mapdl.eplot() at the end, it will crash mapdl.

📝 Steps to reproduce

Main script:


from ansys.mapdl.core import launch_mapdl
import os

curdir = os.getcwd()
mapdl = launch_mapdl(override=True, run_location=curdir, verbose=True, 
                     cleanup_on_exit=True)

mapdl.clear()
mapdl.prep7()
mapdl.shpp('on')

# Create fluid line type
mapdl.et(1,'FLUID116',1,1)
mapdl.type(1)

# Create start finish for line
mapdl.k(0,0,0,1)
mapdl.k(0,1,0,1)
mapdl.klist()

# Create real constant for fluid1516
mapdl.r(1,1,1,1)
mapdl.rmore(0,0,'',1,'',)
mapdl.rmore('')
mapdl.rmore('',0,1)
mapdl.real(1)

# Create line and mesh
mapdl.l(1,2)
mapdl.lmesh(1)
mapdl.esll()
mapdl.cm('FL1_E','ELEM')

# Create solid87 elem type
mapdl.et(2, 87)
mapdl.r(2)
mapdl.real(2)
mapdl.type(2)

# Create keypoints for surface
mapdl.k(10,0,-0.5,0)
mapdl.k(11,0,0.5,0)
mapdl.k(12,1,0.5,0)
mapdl.k(13,1,-0.5,0)

# Create area from keypoints
mapdl.a(10,11,12,13)
mapdl.alist()

# Create volume downwards and mesh
mapdl.vext(1, dz=-0.5)
mapdl.vlist()
mapdl.vmesh(1)

# Select initial surface and get nodes
mapdl.alist()
mapdl.asel('S','AREA','',1)
mapdl.nsla('s',1)
mapdl.cm('SRF_N','NODE')

# Create SURF152 element type with 1 extra node

# kopt5 - extra nodes - 1 See 3 lines below 
# One extra node (optional if KEYOPT (8) > 1; required if KEYOPT (9) > 0). Valid for convection and
# radiation calculations. Use this option if the bulk temperature is unknown. The extra node gets
# the bulk temperature from a FLUID116 (p. 350) element.

# kopt6 - use bulk temp for kopt5 - 0 Extra node temperature used as bulk temperature
# kopt8 - heat flux / conv loads - 4 Evaluate hf at fluid bulk temperature, TB

mapdl.et(3,'SURF152',2,0,2,1,1,0)
mapdl.keyopt(3,8,4)
mapdl.type(3)
mapdl.etlist()

# Add real constants
mapdl.r(3,1,1e-9,'',0,1,0)
mapdl.rmore(0,0,0,0,)
mapdl.rmore('',1,1) 
mapdl.real(3)

# BUG: NDSURF DOES NOT WORK 
# Copying C:\Program Files\ANSYS Inc\v222\ansys\apdl\NDSURF.mac to local dir
# And running NDSURF.mac using the *use command works fine

# mapdl.ndsurf('SRF_N','FL1_E',3) # Will not create a surface
mapdl.use("'NDSURF.mac','SRF_N','FL1_E',3") # Works fine ?!

# Get surface and create component
mapdl.cmsel('S','SRF_N')
mapdl.esln("s",1,'corner')
mapdl.esel('r','ename','',152)
mapdl.cm('SRF_E','ELEM')
mapdl.elist() 
mapdl.nsle()
mapdl.nplot() # This works

mapdl.eplot() # This crashes mapdl

mapdl.exit()

NDSURF.mac (created by Ansys) :

! ANSYS $RCSfile: NDSURF.MAC,v $
! Modified on $Date$ 
! Source ID = $Revision$
/nopr
!   ndsurf.mac
!   Macro to mesh surface effect elements with extra nodes 
!   arg1  = Component of nodes to be meshed with surface effect elements
!   arg2  = Component of target fluid elements
!   arg3  = Model dimensionality, must be 2 or 3.
!
*get,_rout,active,,rout
*get,_mnu,active,,menu
*if,_rout,ne,17,then
 finish
 /prep7
*endif

_arg1=arg1
*get,_cchk,parm,_arg1,type
*if,_cchk,eq,0,then
 _ok=1
 *if,_mnu,eq,1,then
 *msg,warn
  Component name containing nodes must be input
 *else
 *msg,warn 
 Component name must be input (and enclosed in single quotes)
 *endif
*endif
*if,_cchk,ge,3,then
_snode=arg1
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
 _ok=1
*endif

*if,_ok,ne,1,then

_arg2=arg2
*get,_cchk,parm,_arg2,type
*if,_cchk,eq,0,then
 _ok=1
 *if,_mnu,eq,1,then
 *msg,warn
  Component name containing fluid elements must be input
 *else
 *msg,warn
 Component name must be input (and enclosed in single quotes)
 *endif
*endif
*if,_cchk,ge,3,then
_telem=arg2
*elseif,_arg2,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
 _ok=1
*endif
_arg3=arg3
*get,_cchk,parm,_arg3,type  ! obtain type of parameter
*if,_cchk,ne,0,then
   *msg,error
   Input value for model dimensionality must be numeric
   _ok=1
*endif
_dimn=arg3
*if,arg3,ne,3,then
 *if,arg3,ne,2,then
   *msg,error
 Input value for model dimensionality must be 2 or 3 only.
   _ok=1
 *endif
*endif

*endif
*if,_ok,ne,1,then

cm,_lines,line  ! store existing selected sets of entities
cm,_nodes,node  ! store existing selected sets of entities
cm,_elems,elem  ! store existing selected sets of entities
*get,_csys,active,,csys

*get,_stype,comp,_snode,type
*if,_stype,ne,1,then
 *msg,error,_snode
  The component %c contains no nodes 
 _ok=1
*else
cmsel,s,_snode
*endif

esln
cm,_selem,elem

*get,_ttype,comp,_telem,type
*if,_ttype,ne,2,then
 *msg,error,_telem
 The component %c contains no elements
 _ok=1
*else
cmsel,s,_telem
*get,_num2,elem,,count
*endif
cm,_areas,area
cmsel,s,_elems
cmsel,s,_nodes
cmsel,s,_lines

*endif

*get,_etnum,active,,type
*get,_etkop,etyp,_etnum,attr,kop4  ! 2D 3/4 node or 3D 4/8 option
*get,_etxn,etyp,_etnum,attr,kop5    ! extra node option
*get,_etaw,etyp,_etnum,attr,kop6    ! extra node option

*if,_ok,ne,1,then               ! process 

 *if,_etkop,eq,1,then
  *if,_dimn,eq,2,then
    _maxnod = 3
  *else
    _maxnod = 5
  *endif
 *elseif,_etkop,eq,0,then
  *if,_dimn,eq,2,then
    _maxnod = 4
  *else
    _maxnod = 9
  *endif
 *endif
 type,_etnum
 keyopt,_etnum,6,0
 keyopt,_etnum,5,0
 cmsel,s,_snode
 cmsel,s,_selem
 cmsel,s,_lines
 esurf              ! ESURF surface elements
 *if,_status,ge,2,then
    *msg,error
    Some surfaces were not meshed, check model
    _ok=1
 *endif
 esln,s,1
 esel,r,type,,_etnum
 *get,_noelm,elem,,count ! number of meshed surface elements
 cm,_surfe,elem     ! meshed surface elements
cmsel,s,_nodes
cmsel,s,_elems
cmsel,s,_lines
cmsel,s,_areas
keyopt,_etnum,5,1
keyopt,_etnum,6,_etaw

*endif
*if,_ok,ne,1,then

 *dim,_nodelm,array,_maxnod
 cmsel,s,_telem
 nsle,s             ! get nodes from elements TELEM
 csys,0
  cmsel,s,_surfe
  *get,_elmin,elem,,num,min
  *get,_elmax,elem,,num,max
  *do,_j,_elmin,_elmax             
   *if,esel(_j),ne,1,cycle
   *vget,_nodelm(1),elem,_j,node,1,,,4
   *get,_cx,elem,_j,cent,x
   *get,_cy,elem,_j,cent,y
   *get,_cz,elem,_j,cent,z
   _nodelm(_maxnod) = node(_cx,_cy,_cz)
   *if,_maxnod,eq,4,then
    en,_j,_nodelm(1),_nodelm(2),_nodelm(3),_nodelm(4)
   *elseif,_maxnod,eq,3,then
    en,_j,_nodelm(1),_nodelm(2),_nodelm(3)
   *elseif,_maxnod,eq,9,then
    en,_j,_nodelm(1),_nodelm(2),_nodelm(3),_nodelm(4),_nodelm(5),_nodelm(6),_nodelm(7),_nodelm(8)
    emore,_nodelm(9)
   *elseif,_maxnod,eq,5,then
    en,_j,_nodelm(1),_nodelm(2),_nodelm(3),_nodelm(4),_nodelm(5)
   *endif
  *enddo

esel,s,ename,,116
esel,a,ename,,66
*if,_dimn,eq,2,then
  esel,a,ename,,19
  esel,a,ename,,151
*else
  esel,a,ename,,21
  esel,a,ename,,152
*endif
nsle,s
eplot

cmsel,s,_lines
cmsel,s,_nodes
cmsel,s,_elems
esel,a,type,,_etnum
csys,_csys

*if,_etxn,ne,1,then
 *msg,note,_etnum
 Element type %i extra node option was reset (Keyopt(5)=1)
*endif

*endif

*if,_ok,ne,1,then
 /out,ndsurf,out
 *msg,info
 %/_________________________ NDSURF RESULTS_____________________________
  *vwrite,_noelm
  (/,4x,'NUMBER OF SURFACE ELEMENTS CREATED = ', f5.0)
  *msg,info
  %/_____________________________________________________________________
 /out
*endif

*if,_ok,ne,1,then       ! no error
 *if,_mnu,ne,1,then     ! menu off
  *list,ndsurf,out      ! batch listing
  *else
  *list,ndsurf,out      ! batch listing
! *uilist,ndsurf,out    ! interactive listing
 *endif
*endif

cmdele,_lines
cmdele,_nodes
cmdele,_elem
cmdele,_surfe
cmdele,_areas

_ok= $_rout= $_cchk= $_arg1= $_mnu= $_arg2= $_telem= $_snode=
_csys= $_num2= $_etnum= $_etkop= $_etxn= $_etaw= 
_ntot=  $_type= $_etyp= $_maxnod= $_nodelm=
_count= $_elmin= $_i= $_j= $_cx= $_cy= $_cz=
_noelm= $_stype= $_ttype= $_dimn= $_arg3=

💻 Which operating system are you using?

Windows

🐍 Which Python version are you using?

3.10

📦 Installed packages

ansys-api-fluent==0.3.5
ansys-api-mapdl==0.5.1
ansys-api-platform-instancemanagement==1.0.0b3
ansys-dpf-core==0.6.0
ansys-dpf-gate==0.2.1
ansys-dpf-gatebin==0.3.0
ansys-dpf-post==0.2.5
ansys-fluent-core==0.11.0
ansys-grantami-bomanalytics==1.0.1
ansys-grantami-bomanalytics-openapi==1.0.0
ansys-grpc-dpf==0.7.0
ansys-mapdl-core==0.63.2
ansys-mapdl-reader==0.52.6
ansys-openapi-common==1.1.1
ansys-platform-instancemanagement==1.0.2
appdirs==1.4.4
cachetools==5.2.1
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==2.1.1
clr-loader==0.2.5
colorama==0.4.6
contourpy==1.0.6
cryptography==39.0.0
cycler==0.11.0
fonttools==4.38.0
geomdl==5.3.1
google-api-core==2.10.1
google-api-python-client==2.71.0
google-auth==2.15.0
google-auth-httplib2==0.1.0
googleapis-common-protos==1.56.4
grpcio==1.51.1
h5py==3.7.0
httplib2==0.21.0
idna==3.4
imageio==2.24.0
importlib-metadata==6.0.0
kiwisolver==1.4.4
matplotlib==3.6.2
ntlm-auth==1.5.0
numpy==1.24.1
packaging==23.0
pandas==1.5.2
Pillow==9.4.0
plumbum==1.8.1
pooch==1.6.0
protobuf==3.20.1
protoc-gen-swagger==0.1.0
psutil==5.9.4
pyaedt==0.6.3
pyansys==2023.1.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pyiges==0.2.1
pyparsing==3.0.9
pypiwin32==223
python-dateutil==2.8.2
pythonnet==3.0.0rc6
pytz==2022.7
pyvista==0.37.0
pywin32==305
requests==2.28.1
requests-negotiate-sspi==0.5.2
requests-ntlm==1.1.0
rpyc==5.0.1
rsa==4.9
scipy==1.10.0
scooby==0.7.0
six==1.16.0
tqdm==4.64.1
uritemplate==4.1.1
urllib3==1.26.13
vtk==9.2.5
zipp==3.11.0
giiyms commented 1 year ago

Closed as moved to pyansys/pyansys repo