-
Notifications
You must be signed in to change notification settings - Fork 115
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
MAPDL server connection terminated when using parameters #2989
Comments
Hi @Clauperezma Try turning off the logging. Then add a mapdl.wait(1) right before the mapdl.solve() command. Also add mapdl.run("*del, U_nodal") to after the U1 = mapdl.parameters["U_NODAL"]. Lastly we really don't need to *get the node count every time before the *do loop that defines the applied force. Just define it when modeling. So after the amesh and allsel command I added mapdl.parameters["num_nodes"] = len(mapdl.mesh.nnum). Ran this a few times and each time completed all 200 solves. Mike p.s. MAPDL can define some material properties as functions of displacement. May be easier than a manual routine. |
Hi @mikerife, thanks very much for your help. I made all the changes you suggested in the code, but I´m still getting the same issue. I even tried deleting the variable Fg given that this variable will be different for every iteration in the original code, but doesn´t work either. I´m including the code in case I´m forgetting something. Should I reinstall mapdl, or try to change the Ansys version? I´m also using Anaconda, could that be the issue?. import numpy as np
from ansys.mapdl.core import launch_mapdl
#from ansys.mapdl.core import LOG
#LOG.setLevel("DEBUG")
#LOG.log_to_file("mylog.log")
mapdl =launch_mapdl(additional_switches='-smp')
mapdl.prep7()
def F_hom(nel_mi,inci_mi,coord_mi,nnods_mi,D):
import numpy as np
for i in range(0,nel_mi-1): # Read the element and its incidence
nel_i = inci_mi[i, :]-1
# Determine the x and y positions of the element nodes
posxy = coord_mi[nel_i[0:], 0:3]
# Gauss points
ng = 2
pxi = [-1/np.sqrt(3), 1/np.sqrt(3)]
peta = [-1/np.sqrt(3), 1/np.sqrt(3)]
wi = 1
wj = 1
Nfun = len(nel_i) # Number of nodes in the element
Fg = np.zeros((2*nnods_mi,3))
kel = np.zeros((2 * Nfun, 2 * Nfun)) # Initialize the element matrix
fel = np.zeros((2 * Nfun, 3)) # Initialize the element matrix
Bs = np.zeros((3, 2 * Nfun)) # Initialize the strain matrix
DH=np.zeros((3, 3))
DH1=np.zeros((3, 3))
De = np.zeros((3, 3))
De1 = np.zeros((3, 3))
for j in range(ng):
xi = pxi[j]
for k in range(ng):
eta = peta[k]
N = np.array([1/4 * (1 - xi) * (1 - eta), 1/4 * (1 + xi) * (1 - eta), 1/4 * (1 + xi) * (1 + eta), 1/4 * (1 - xi) * (1 + eta)])
dNxi = np.array([eta/4 - 1/4, 1/4 - eta/4, eta/4 + 1/4, -eta/4 - 1/4])
dNeta = np.array([xi/4 - 1/4, -xi/4 - 1/4, xi/4 + 1/4, 1/4 - xi/4])
# Jacobian
J = np.dot(np.array([dNxi, dNeta]), posxy)
iJ = np.linalg.inv(J)
# Strain matrix Bs - solid
p = np.arange(0, 8, 2)
Bs[0, p] = (iJ[0, 0] * dNxi) + (iJ[0, 1] * dNeta)
Bs[1, p+1] = iJ[1, 0] * dNxi + iJ[1, 1] * dNeta
Bs[2, p] = Bs[1, p+1]
Bs[2, p+1] = Bs[0, p]
fel=fel+np.dot(np.dot(Bs.T, D), np.linalg.det(J)) * wi * wj
return fel
def solveU_homg(mapdl, nnods_mi,Fg,case_xy):
mapdl.antype("STATIC")
mapdl.parameters["Fg"]=Fg
mapdl.allsel()
mapdl.ddele("ALL","ALL")
mapdl.fdele("ALL","ALL")
if case_xy==True:
mapdl.d("x_nodes","UY",0)
mapdl.d("y_nodes","UX",0)
mapdl.allsel()
else:
mapdl.d("x_nodes","UX",0)
mapdl.d("y_nodes","UY",0)
mapdl.allsel()
# Apply nodal forces and solve the system
with mapdl.non_interactive:
#mapdl.run('*get,num_nodes,node,0,count,max')
mapdl.run('*do,i,1,num_nodes,1')
mapdl.f('i','FX','Fg((2*i)-1)')
mapdl.f('i','FY','Fg(2*i)')
mapdl.run('*enddo')
#for i in range(1, nnods_mi + 1):
#mapdl.f(i, "FX", Fg[2 * i - 2])
#mapdl.f(i, "FY", Fg[2 * i - 1])
mapdl.wait(1)
mapdl.solve()
# Retrieve nodal displacements for X and Y directions
mapdl.dim('U_nodal','ARRAY', 'num_nodes',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']
mapdl.run("*del, U_nodal")
mapdl.run("*del, Fg")
# Combine X and Y displacements into a single vector
U_carga = np.zeros(2 * nnods_mi)
U_carga[::2] = U1[:, 0] # Assign X displacements to even indices
U_carga[1::2] = U1[:, 1] # Assign Y displacements to odd indices
return U_carga
mi_nelx =100; # Número de Elementos em x da célula de base
mi_nely =100; # Número de Elementos em y da célula de base
mi_Lx = 1; # Comprimento no eixo x da célula de base
mi_Ly = 1; # Comprimento no eixo y da célula de base
mi_t = 1; # Espessura da célula de base
nel_mi=mi_nelx*mi_nely
mi_elist = list(range(1,nel_mi + 1))
tol=0.1/100
# Def41inir propiedades del material
E = 1 # Young's modulus in N/m
v = 0.3 # Poisson's ratio
xmin = 1E-3
p=3
steel_mat = 1
mapdl.mp("EX", steel_mat, E)
mapdl.mp("PRXY", steel_mat,v)
void_mat = 2
mapdl.mp("EX", void_mat, E*(xmin**p))
mapdl.mp("PRXY", void_mat,v)
mapdl.et(1,"PLANE42",kop2=1)
mapdl.blc4(-mi_Lx/2,-mi_Ly/2,mi_Lx,mi_Ly)
mapdl.mat(steel_mat)
mapdl.allsel()
mapdl.lsel("S", "LOC", "X",-mi_Lx/2)
mapdl.lsel("A", "LOC", "X",mi_Lx/2)
mapdl.lesize("ALL","","",mi_nely)
mapdl.allsel()
mapdl.lsel("S", "LOC", "Y",-mi_Ly/2)
mapdl.lsel("A", "LOC", "Y",mi_Ly/2)
mapdl.lesize("ALL","","",mi_nelx)
mapdl.allsel()
mapdl.amesh("ALL")
mapdl.allsel("ALL")
mapdl.parameters["num_nodes"] = len(mapdl.mesh.nnum)
#Condiciones de frontera
nel_mi=int(mapdl.get("ELEM_sum","ELEMENT",0,"COUNT"))
nnods_mi=int(mapdl.get("NODE_sum","NODE",0,"COUNT"))
coord_mi = np.copy(mapdl.mesh.nodes[:, [0, 1]]) # coordinates matrix
elem_prop_mi = np.array(mapdl.mesh.elem)
inci_mi= np.copy(elem_prop_mi[:, -4::])
# Calculo sensibilidade
#mapdl.run("/POST1 ") # Post-processor module
#mapdl.etable("energy","SENE",'')
#alpha1=mapdl.starvget('alpha',"ELEM","",'ETAB',"energy","","",2)
#alpha=mapdl.parameters["alpha"]
#Calculate x
V= np.zeros(nel_mi)
C = []
x = np.ones(nel_mi,dtype=bool)
x_anterior=np.ones(nel_mi,dtype=bool)
ite=0
factor = E / (1 - v**2)
D = factor * np.array([[1, v, 0],
[v, 1, 0],
[0, 0, (1 - v) / 2]])
vol_frac = []
#vol_frac.append(sum(x)/nel_mi) # topology vector
#Condiciones de contorno U
mapdl.nsel("S","LOC","x",-mi_Lx/2-tol,-mi_Lx/2+tol)
mapdl.cm("x0_nodes","NODE")
mapdl.nsel("S","LOC","x",mi_Lx/2-tol,mi_Lx/2+tol)
mapdl.cm("xa1_nodes","NODE")
mapdl.cmsel("S","x0_nodes")
mapdl.cmsel("A","xa1_nodes")
mapdl.cm("x_nodes","NODE")
mapdl.allsel("ALL")
#Select side 0 and Ly
mapdl.nsel("S","LOC","y",-mi_Ly/2-tol,-mi_Ly/2+tol)
mapdl.cm("y0_nodes","NODE")
mapdl.nsel("S","LOC","y",mi_Ly/2-tol,mi_Ly/2+tol)
mapdl.cm("ya2_nodes","NODE")
mapdl.cmsel("S","y0_nodes")
mapdl.cmsel("A","ya2_nodes")
mapdl.cm("y_nodes","NODE")
fel=F_hom(nel_mi,inci_mi,coord_mi,nnods_mi,D)
for ite in range(200):
# Update material properties based on changes in x
index_x = np.argwhere(x != x_anterior)
for i in index_x.flat:
mat_id = 1 if x[i] else 2
mapdl.emodif(int(i + 1), "MAT", mat_id)
# Initialize arrays
Fg = np.zeros((2 * nnods_mi, 3))
# Loop over material indices
for elem_idx in np.flatnonzero(x == 1):
nodes = inci_mi[elem_idx]
ind = np.ravel([[2 * node - 2, 2 * node - 1] for node in nodes])
Fg[ind, :] += fel
mapdl.parameters["Fg"]=Fg
mat_indices = np.argwhere(x ==1)
# Solve the system for every load
mapdl.run("/SOLU")
Ux=solveU_homg(mapdl,nnods_mi,Fg[:, 0],False)
Uy=solveU_homg(mapdl,nnods_mi,Fg[:, 1],False)
Uxy=solveU_homg(mapdl,nnods_mi,Fg[:,2],True)
mapdl.finish()
print("ite",ite) And this is the error: File ~\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec File c:\users\user\documents\codigos casa_marzo19\pyansys_micro_verif_reduz_marzo19\ejemplo__cambiosgithub.py:217 File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\parameters.py:400 in setitem File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\misc.py:398 in wrapper File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\parameters.py:638 in _set_parameter_array File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\mapdl_core.py:1376 in exit File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\mapdl_grpc.py:1971 in _flush_stored File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\errors.py:319 in wrapper MapdlExitedError: MAPDL server connection terminated with the following error |
@Clauperezma there are very few issues where reinstalling MAPDL is a solution. And I don't think this issue is one of them. Can you take Anaconda out of the equation and test? |
Hi @mikerife, you were right. I reinstalled python and pymadl without Anaconda, but I keep getting the same error. Any other ideas I can try? Thanks again for all the help! |
@Clauperezma try a system power reboot then run the PyMAPDL script again. What happens? |
@mikerife I rebooted my computer but the problem persists. It did run once for 200 iterations, but then the next crashed after 40 iterations. I did the same modifications and ran it on my laptop but I keep getting the same error. Sometimes it will run successfully but then will crash, sometimes after a few iterations, and others when the count is very advanced. Thanks again for all the help. I'm editing the comment, and add that I did this a couple of times and It does seem to improve once the PC is rebooted... The second time it ran 2 times for 200 iterations and crashed on the third try. The third time I reboot it and run for 3 times without crashing. On my laptop, however, I haven't had the same results. |
🤓 Before submitting the issue
pip install --upgrade --upgrade-strategy eager ansys-mapdl-core
in your activated virtual environment.🔍 Description of the bug
I have encountered this error frequently and have seen other posts about it, but none of them come up with a specific solution. Currently I can't roll my code, sometimes it breaks after a few iterations and some others after #40. I am attaching a part of the code to be rolled. The code is longer and in general the vector x is updated for each iteration. In this case I left it fixed just to see how it behaved and the error always occurs with the use of mapdl.parameters just like in my original code. I wanted to know if there is already a solution for this problem and if it may be related to memory usage. Thanks a lot.
🕵️ Steps To Reproduce
💻 Which Operating System are you using?
Windows
🐍 Which Python version are you using?
3.11
💾 Which MAPDL version are you using?
ansys-mapdl-core-0.68.1
📝 PyMAPDL Report
Show the Report!
📝 Installed packages
Show the installed packages!
📝 Logger output file
Show the logger output file.
The error that I get is this:The text was updated successfully, but these errors were encountered: