-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
name 'MapdlRuntimeError' is not defined when trying to use mapdl.noninteractive #2209
Comments
Hi @Artyom-K You could instead write an MAPDL input file then read that in, but then you would need to retrieve the node X values collected. I think it might be better to instead gather the nodes to an array and parse through that for the needed information. Please try this example: from ansys.mapdl.core import launch_mapdl
import numpy as np
import os
path = os.getcwd()
mapdl = launch_mapdl(run_location=path)
mapdl.clear()
mapdl.prep7()
mapdl.n(1,0,0,0)
mapdl.n(2,1,0,0)
mapdl.n(3,2,0,0)
mapdl.n(4,3,0,0)
mapdl.n(5,4,0,0)
mapdl.n(6,5,0,0)
mapdl.n(7,6,0,0)
n_list = [2, 4, 7]
node = mapdl.mesh.nodes
node_num =mapdl.mesh.nnum
nodes_x = []
for i in n_list:
print("node " +str(i)+ " x is " + str(node[np.where(node_num == i)[0][0]][0]))
nodes_x.append(node[np.where(node_num == i)[0][0]][0])
nodes_x Which will result in: Then don't forget the mapdl.exit() |
Hi @Artyom-K The queries module is not compatible with However you are right, that the If I were you, and needed speed, I would just do: nodes = mapdl.mesh.nodes
def nx(i):
return nodes[i,0]
def ny(i):
return nodes[i,1]
def nz(i):
return nodes[i,2]
# and then:
for i in nlist:
x = nx(i) This way you avoid multiple calls to the MAPDL instance. |
Hi @mikerife I would like to suggest a small improvement to your snippet: >>> # Assuming this are the node ids you want to return
>>> n_list = [2, 4, 7] # mapdl indexing
>>> n_list_ = np.array(n_list) - 1 # python indexing
>>> node = mapdl.mesh.nodes
>>> nodes_x = node[n_list_]
array([[1., 0., 0.],
[3., 0., 0.],
[6., 0., 0.]]) |
@germa89 Thanks! I'll have to dig into that more - I'm wondering if that will work if there are gaps in the node numbering (which is always a concern of mine). Mike |
It is a VERY valid concern honestly. In case the nodes are not contiguous: from ansys.mapdl.core import launch_mapdl
import numpy as np
import os
path = os.getcwd()
mapdl = launch_mapdl(run_location=path)
mapdl.clear()
mapdl.prep7()
# node ids are the same as the x coordinates
mapdl.n(1,1,0,0)
mapdl.n(2,2,0,0)
mapdl.n(3,3,0,0)
mapdl.n(6,6,0,0)
mapdl.n(7,7,0,0)
mapdl.n(10,10,0,0)
mapdl.n(12,12,0,0)
n_list = [2, 7, 12]
nnum = mapdl.mesh.nnum
nodes = mapdl.mesh.nodes
indices = np.in1d(nnum, n_list)
mynodes = nodes[indices,:]
assert np.allclose(mynodes[:,0], n_list) You will love numpy.in1d from now on! 😉 |
🤓 Before submitting the issue
pip install --upgrade --upgrade-strategy eager ansys-mapdl-core
.🔍 Description of the bug
NameError: name 'MapdlRuntimeError' is not defined when using inline function inside of with mapdl.non_interactive
🕵️ Steps To Reproduce
Initially I had a loop
It was very slow so I wanted to try the following
Now I get this error
💻 Which Operating System are you using?
None
🐍 Which Python version are you using?
3.11
📝 PyMAPDL Report
Show the Report!
📝 Installed packages
Show the installed packages!
📝 Logger output file
Show the logger output file.
The text was updated successfully, but these errors were encountered: