-
Hi everyone, x_filtered = (H @ x) # filter element density with neighbour elements
for i in range(num_elem_dd):
mp_num = i + 1
E = E_0 * x_filtered[i,0]**p # change Young's modulus using filtered density
mapdl.mp("EX",mp_num,E)
mapdl.mp("PRXY",mp_num,ni)
mapdl.mp("DENS",mp_num,7850)
mapdl.mpchg(mat = mp_num, elem = int(ID_elem_dd[i])) It is basically a for loop that ranges from the 1st element up to the last. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @derne058 |
Beta Was this translation helpful? Give feedback.
-
Hi @mikerife, E = E_0 * x_filtered[i,0]**p where E_0 is the Young's modulus of solid element (E_0=200 GPa), x_filtered the vector of design variables filtered considering neighboring elements, and p is the penalization parameter (p=3). By calculating the new E, I modify the element material properties using a for loop. |
Beta Was this translation helpful? Give feedback.
-
Hi @derne058 In the loop you mentioned, you are issuing several gRPC calls ( For instance, if you are dealing with a material with variable porosity, you can select all the elements which will have similar porosity (within a range), and apply the material change in all the elements at once. You can try the following pseudocode: grading_steps = [(0, 0.1), (0.1, 0.2), (0.2, 0.3), ...] # surely this can be more elegant.
for lower_bound, upper_bound in grading_steps:
x_filtered__ = lower_bound < x_filtered < upper_bound
# select elements
mapdl.esel( ...)
# Change material properties
mp_num = i + 1
E = E_0 * x_filtered[i,0]**p # change Young's modulus using filtered density
mapdl.mp("EX",mp_num,E)
mapdl.mp("PRXY",mp_num, ni)
mapdl.mp("DENS",mp_num,7850)
mapdl.mpchg(mat = mp_num, elem = "all") The approach should speed up the process. Additionally, if you can do all the python operations outside the loop, then you can put as much gRPC calls inside a |
Beta Was this translation helpful? Give feedback.
Hi @derne058
In the loop you mentioned, you are issuing several gRPC calls (
mapdl.mp
) per each element. That can be quite a lot. To speed up the process, avoid doing a loop per element, and try to do a loop per material.For instance, if you are dealing with a material with variable porosity, you can select all the elements which will have similar porosity (within a range), and apply the material change in all the elements at once. You can try the following pseudocode: