ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
424 stars 120 forks source link

Script Translation issue #395

Closed xiepei1 closed 3 years ago

xiepei1 commented 3 years ago

Seemingly, there is a bug in script translation function 'ansys.mapdl.core.convert_script()'

ansys.mapdl-core version 0.58.4

The example in User Guide is with version 0.57.0, seemingly looking okay in that version?

for example: i need to convert following APDL script which is in file 'coordinates.mac'

/post1
*get,CPU_start0,active,0,time,wall
!!! suppress the error messages
/uis,msgpop,3
*set,focus_comp,'solder_all'
n_balls=21
starting=1
*get,CPU_start1,active,0,time,wall
!!! change background color to white
/RGB,INDEX,100,100,100, 0
/RGB,INDEX, 0, 0, 0,15
allsel,all
*dim,coordinates,array,n_balls,1
cmsel,s,focus_comp

with conversion code:

from ansys.mapdl import core as pymapdl

pymapdl.convert_script('coordinates.mac', 'coordinates.py')

get result:

""" Script generated by ansys-mapdl-core version 0.58.4 """

from ansys.mapdl.core

 import launch_mapdlmapdl = launch_mapdl(loglevel="WARNING")

mapdl.run("/post1")

mapdl.run("*get,CPU_start0,active,0,time,wall")

# suppress the error messages

mapdl.run("/uis,msgpop,3")

mapdl.run("*set,focus_comp,'solder_all'")

mapdl.run("n_balls=21")

mapdl.run("starting=1")

mapdl.run("*get,CPU_start1,active,0,time,wall")

# change background color to white

mapdl.run("/RGB,INDEX,100,100,100, 0")

mapdl.run("/RGB,INDEX, 0, 0, 0,15")

mapdl.allsel("all")

mapdl.run("*dim,coordinates,array,n_balls,1")

mapdl.cmsel("s", "focus_comp")

mapdl.exit()

We can see clearly that starting from line3, there is a problem there.

The rest seems working fine...

akaszynski commented 3 years ago

Thanks for posting this. I'll try to have a fix for this later this week (been busy with other bugs at the moment).

akaszynski commented 3 years ago

Fixed in 9bbb053f07b749c7e9d53e860b0dea0000efd37d.

A bunch of these converted commands (like "/RGB,INDEX,100,100,100, 0") won't have the same sort of meaning if you mean to convert entirely to a pythonic script. In the next release there will be run_multiline, (see #404), where you can just run a block of commands without having to convert it over. For example:


>>> cmd = '''/prep7
! Mat
MP,EX,1,200000
MP,NUXY,1,0.3
MP,DENS,1,7.85e-09
! Elements
et,1,186
et,2,154
! Geometry
BLC4,0,0,1000,100,10
! Mesh
esize,5
vmesh,all
nsel,s,loc,x,0
d,all,all
nsel,s,loc,x,999,1001
type,2
esurf
esel,s,type,,2
nsle
sfe,all,3,pres,,-10
allsel
/solu
antype,0
solve
/post1
set,last
plnsol,u,sum
'''
>>> resp = mapdl.run_multiline(cmd)
>>> resp
MATERIAL          1     EX   =   200000.0
MATERIAL          1     NUXY =  0.3000000
MATERIAL          1     DENS =  0.7850000E-08
ELEMENT TYPE          1 IS SOLID186     3-D 20-NODE STRUCTURAL SOLID
 KEYOPT( 1- 6)=        0      0      0        0      0      0
 KEYOPT( 7-12)=        0      0      0        0      0      0
 KEYOPT(13-18)=        0      0      0        0      0      0
output continues...

Also, you can run an input file using mapdl.input:

Load a simple ``"ds.dat"`` input file generated from Ansys
Workbench.

>>> output = mapdl.input('ds.dat')

Regardless, I've also fixed the script converter for anyone who uses this in the future. Will be out in the next release 0.58.8.