Low precision in array retrieval
Clauperezma opened this issue · comments
🤓 Before submitting the issue
- I have visited the Troubleshooting section.
- I have searched among the existing issues.
- I am using a Python virtual environment.
- I am using the latest version of PyMAPDL and its dependencies (fully updated virtual environment). You can update them using
pip install --upgrade --upgrade-strategy eager ansys-mapdl-core
in your activated virtual environment.
🔍 Description of the bug
After performing a FEM analysis, I was able to retrieve the displacement values using the following lines of code:
U_ma= np.zeros(2*nnods_ma)
mapdl2.dim('U_nodal',"ARRAY",nnods_ma,2)
mapdl2.starvget('U_nodal(1,1)',"NODE",1,"U","X")
mapdl2.starvget('U_nodal(1,2)',"NODE",1,"U","Y")
U1=mapdl2.parameters["U_nodal"]
Even though the values are correct, they do not have enough significant digits, especially for small displacements. I tried to increase the number of significant digits by adding:
mapdl2.format(20)
U_ma= np.zeros(2*nnods_ma)
mapdl2.dim('U_nodal',"ARRAY",nnods_ma,2)
mapdl2.starvget('U_nodal(1,1)',"NODE",1,"U","X")
mapdl2.starvget('U_nodal(1,2)',"NODE",1,"U","Y")
U1=mapdl2.parameters["U_nodal"]
However, it hasn't worked yet. I would like to know how I can increase the significant numbers when retrieving this value. Given that I'm losing information passing from Ansys to Python. Thank you very much.
🕵️ Steps To Reproduce
mapdl2.format(20)
U_ma= np.zeros(2*nnods_ma)
mapdl2.dim('U_nodal',"ARRAY",nnods_ma,2)
mapdl2.starvget('U_nodal(1,1)',"NODE",1,"U","X")
mapdl2.starvget('U_nodal(1,2)',"NODE",1,"U","Y")
U1=mapdl2.parameters["U_nodal"]
💻 Which Operating System are you using?
None
🐍 Which Python version are you using?
None
📝 PyMAPDL Report
Show the Report!
# PASTE HERE THE OUTPUT OF `python -c "from ansys.mapdl import core as pymapdl; print(pymapdl.Report())"` here
📝 Installed packages
Show the installed packages!
# PASTE HERE THE OUTPUT OF `python -m pip freeze` here
📝 Logger output file
Show the logger output file.
# PASTE HERE THE CONTENT OF THE LOGGER OUTPUT FILE.
Hi @Clauperezma
Can you share a minimum working example? So I can check changes against it?
Here is an example:
from ansys.mapdl.core import launch_mapdl
mapdl= launch_mapdl(additional_switches='-smp')
import numpy as np
ma_Lx=0.03
ma_Ly=0.05
ma_nelx=4
ma_nely=2
xmin=1e-3
p=3
nel_ma=ma_nelx*ma_nely
DH1=[[2.19963816e+11, 6.51264991e+10, -5.36441803e-07],
[ 6.51264991e+10, 2.19963816e+11, 5.36441803e-07],
[ 2.38418579e-07, -3.57627869e-07, 7.62813778e+10]]
elem_list = np.arange(1, nel_ma + 1)
S=np.linalg.inv(DH1)
Ex=1/S[0,0]
Ey=1/S[1,1]
vh=-S[1,0]/S[0,0]
Gh=1/S[2,2]
G2=Ex/(2*(1+vh))
mapdl.clear()
mapdl.prep7()
mapdl.mp("EX",1, Ex)
mapdl.mp("EY",1, Ey)
mapdl.mp("EZ",1, Ex)
mapdl.mp("PRXY",1,vh)
#mapdl2.mp("PRYZ",1,vh)
#mapdl2.mp("PRXZ",1,vh)
mapdl.mp("GXY",1,Gh)
mapdl.mp("GYZ",1,Gh)
mapdl.mp("GXZ",1,Gh)
mapdl.mp("EX",2,xmin**p)
mapdl.mp("PRXY",2,vh)
mapdl.et(1,"PLANE42",kop2=1)
mapdl.blc4(0,0,ma_Lx,ma_Ly)
mapdl.mat(1)
mapdl.allsel()
mapdl.lsel("S", "LOC", "X",0)
mapdl.lsel("A", "LOC", "X",ma_Lx)
mapdl.lesize("ALL","","",ma_nely)
mapdl.allsel()
mapdl.lsel("S", "LOC", "Y",0)
mapdl.lsel("A", "LOC", "Y",ma_Ly)
mapdl.lesize("ALL","","",ma_nelx)
mapdl.allsel()
mapdl.amesh("ALL")
F = -100 # downward 100 newton force
mapdl.nsel("S", "LOC", "X",0) # select nodes at x=0
mapdl.d("ALL", "ALL",0) # set all dof of selected nodes to 0
mapdl.allsel() # select all nodes
mapdl.nsel("S", "LOC", "X", ma_Lx) # select nodes at x=len_x
#mapdl.nsel("R", "LOC", "Y", Ly) # select subset of nodes in the y region
mapdl.nsel("R", "LOC", "Y", 0.5*ma_Ly) # select subset of nodes in the y region
mapdl.f("ALL","FY", F) # apply force
mapdl.allsel() # reselect all entities
nel_ma=int(mapdl.get("ELEM_sum","ELEMENT",0,"COUNT"))
nnods_ma=int(mapdl.get("NODE_sum","NODE",0,"COUNT"))
#print("nel=",nel_ma)
#print("nnods=",nnods_ma)
coor_ma = np.copy(mapdl.mesh.nodes[:, [0, 1]]) # coordinates matrix
elem_prop_ma = np.array(mapdl.mesh.elem)
inci_ma= np.copy(elem_prop_ma[:, -4::])
mapdl.run("/SOLU")
mapdl.antype("STATIC")
mapdl.solve()
mapdl.run("/POST1 ") # Post-processor module
# Cálculo del desplazamiento
mapdl.format(20)
U_ma= np.zeros(2*nnods_ma)
mapdl.dim('U_nodal',"ARRAY",nnods_ma,2)
mapdl.starvget('U_nodal(1,1)',"NODE",1,"U","X")
mapdl.starvget('U_nodal(1,2)',"NODE",1,"U","Y")
U1=mapdl.parameters["U_nodal"]
for k in range(1,nnods_ma+1):
U_ma[(2*k)-2]=U1[k-1,0]
U_ma[(2*k)-1]=U1[k-1,1]
From this code I compared the results in the variable U_ma. With the results reported in Ansys: Here is the comparison:
There are significant digits that are lost when I want to collect an Ansys variable to use in Python. Which in this case is displacement. I would like to know how I can increase that number of significant digits, so as not to lose precision, because I must use that offset value for subsequent calculations.