pymapdl
pymapdl copied to clipboard
mapdl.ndsurf() does not work as expected
Before submitting the issue
- [X] I have visited the Troubleshooting section.
- [X] I have searched among the existing issues.
- [X] I am using a Python virtual environment.
- [X] I have a fully updated virtual environment (i.e.
pip install --upgrade --upgrade-strategy eager ansys-mapdl-core)
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")
Any ideas?
Also if you do mapdl.nplot() then mapdl.eplot() at the end, it will crash mapdl.
Steps To Reproduce
📝 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
PyMAPDL Report
Show the Report!
-------------------------------------------------------------------------------
PyMAPDL Software and Environment Report
Packages Requirements
*********************
Core packages
-------------
ansys.mapdl.core : 0.63.2
numpy : 1.24.1
appdirs : 1.4.4
scipy : 1.10.0
grpc : Package not found
ansys.api.mapdl.v0 : Package not found
ansys.mapdl.reader : 0.52.6
google.protobuf : Package not found
Optional packages
-----------------
matplotlib : 3.6.2
pyvista : 0.37.0
pyiges : 0.2.1
tqdm : 4.64.1
Ansys Installation
******************
Version Location
------------------
222 C:\Program Files\ANSYS Inc\v222
Ansys Environment Variables
***************************
ANSYS ENV. VARIABLE ANSYS_SYSDIR=winx64
ANSYS222_DIR C:\Program Files\ANSYS Inc\v222\ANSYS
AWP_LOCALE222 en-us
AWP_ROOT222 C:\Program Files\ANSYS Inc\v222
CADOE_LIBDIR222 C:\Program Files\ANSYS Inc\v222\CommonFiles\Language\en-us
Installed packages
Show the 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
asttokens==2.2.1
backcall==0.2.0
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
comm==0.1.2
contourpy==1.0.6
cryptography==39.0.0
cycler==0.11.0
debugpy==1.6.5
decorator==5.1.1
entrypoints==0.4
executing==1.2.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
ipykernel==6.20.1
ipython==8.8.0
jedi==0.18.2
jupyter_client==7.4.8
jupyter_core==5.1.3
kiwisolver==1.4.4
matplotlib==3.6.2
matplotlib-inline==0.1.6
nest-asyncio==1.5.6
ntlm-auth==1.5.0
numpy==1.24.1
packaging==23.0
pandas==1.5.2
parso==0.8.3
pickleshare==0.7.5
Pillow==9.4.0
platformdirs==2.6.2
plumbum==1.8.1
pooch==1.6.0
prompt-toolkit==3.0.36
protobuf==3.20.1
protoc-gen-swagger==0.1.0
psutil==5.9.4
pure-eval==0.2.2
pyaedt==0.6.3
pyansys==2023.1.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
Pygments==2.14.0
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
pyzmq==25.0.0
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
stack-data==0.6.2
tornado==6.2
tqdm==4.64.1
traitlets==5.8.1
uritemplate==4.1.1
urllib3==1.26.13
vtk==9.2.5
wcwidth==0.2.5
zipp==3.11.0
Logger output file
Show the logger output file.
# PASTE HERE THE CONTENT OF THE LOGGER OUTPUT FILE.
Hi @giiyms MAPDL requires the NDSURF command needs the component names in single quotes - I'm not sure if that is happening. @germa89 can you weigh in here? In the meantime the ndsurf command can be used in non-interactive mode like so:
with mapdl.non_interactive:
mapdl.run("ndsurf,'SRF_N','FL1_E',3")
Mike
@giiyms @germa89 Small update; I thought that maybe this format would work:
mapdl.ndsurf("'SRF_N'","'FL1_E'",3)
If I capture the APDL log file with launch_mapdl option log_apdl then it does capture the command:

But it seems to not be running the command...guess non-interactive is the only answer for now.
Mike
@germa89 The other APDL macro command to create elements, AFSURF, does not work either. But LSSOLVE does (which is a APDL macro as well). I did not test LFSURF. I'm really puzzled....
I'm having a look...
Indeed the NDSURF command does not work.
The plotting does work though (even if no surfaces are generated):
NPLOT

EPLOT

(However, once EPLOT crashed python ... )
The ' are important:

but indeed, it does not fix the issue.
UPDATE
The non_interactive mode does not work here.... interesting.
This is going to need more careful debugging on the MAPDL side. Because the command seems to be streamed properly.
Pinging @FredAns for visibility
@germa89 The other APDL macro command to create elements, AFSURF, does not work either. But LSSOLVE does (which is a APDL macro as well). I did not test LFSURF. I'm really puzzled....
Are the commands exactly the same as the macro?? (I guess they are) So I can use the macro to do some debugging... Just run the stuff step by step and see where it fails... ?
@germa89 yes; the APDL 'command' NDSURF is calling the ndsurf.mac in the installation here:
C:\Program Files\ANSYS Inc\v222\ansys\apdl
I started down the "change the ndsurf.mac file and see where the problem is" road but got nowhere. It seemed like the command was not actually processed by mapdl.
Re-pinging @FredAns for input.