Comments (6)
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.
from pymapdl.
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:
Traceback (most recent call last):
File ~\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\users\user\documents\codigos casa_marzo19\pyansys_micro_verif_reduz_marzo19\ejemplo__cambiosgithub.py:217
mapdl.parameters["Fg"]=Fg
File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\parameters.py:400 in setitem
self._set_parameter_array(key, value)
File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\misc.py:398 in wrapper
out = func(*args, **kwargs)
File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\parameters.py:638 in _set_parameter_array
with self._mapdl.non_interactive:
File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\mapdl_core.py:1376 in exit
self._parent()._flush_stored()
File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\mapdl_grpc.py:1971 in _flush_stored
out = self.input(
File ~\anaconda3\Lib\site-packages\ansys\mapdl\core\errors.py:319 in wrapper
raise MapdlExitedError(
MapdlExitedError: MAPDL server connection terminated with the following error
<_MultiThreadedRendezvous of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "Connection reset"
debug_error_string = "UNKNOWN:Error received from peer {created_time:"2024-04-11T14:14:01.5404325+00:00", grpc_status:14, grpc_message:"Connection reset"}"
from pymapdl.
@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?
from pymapdl.
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!
from pymapdl.
@Clauperezma try a system power reboot then run the PyMAPDL script again. What happens?
from pymapdl.
@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.
from pymapdl.
Related Issues (20)
- missing f string
- Bug located in DIM command. HOT 2
- Just Command, Not GUI picking HOT 4
- Allow arrays/tables as arguments HOT 2
- Add `SFE` and `SF` to enriched command output
- Implement client side retry
- Implement `PYMAPDL_DEBUG` env var HOT 2
- `CDREAD` upload files if they exists in the MAPDL working directory
- Bug located in VSEL using KSWP field.
- docs: Update the PyMAPDL documentation page for MPREAD
- Report image cache changes with percentages
- APLOT results in the deletion of areas and area components. HOT 3
- VPLOT does not always clean up its ET definition(s). HOT 1
- Fix PyVista Warnings
- Outdated `CONFIG_FILE` HOT 1
- Set MAPDL memory and CPU limits on CICD
- Image cache randomly updates HOT 2
- Scipy example
- Add server license option to switch between read only and read/write or check in license HOT 5
- Add server exit to python del mapdl HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymapdl.