-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhsycisSim.py
More file actions
56 lines (43 loc) · 1.58 KB
/
Copy pathPhsycisSim.py
File metadata and controls
56 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from dolfinx import *
import mshr
# Load STL file and create mesh
stl_file = "your_model.stl"
domain = mshr.Mesh3D(stl_file)
mesh = Mesh(domain)
# Define function space (Displacement)
V = VectorFunctionSpace(mesh, "Lagrange", 1)
# Define boundary condition
tol = 1E-14
# Apply zero displacement to a specific region (supports)
def boundary(x, on_boundary):
return on_boundary and x[0] < tol # Adjust this based on your supports
bc = DirichletBC(V, Constant((0.0, 0.0, 0.0)), boundary)
# Define force (load) applied to another region
# You can adjust the coordinates according to your problem
force = Constant((0, 0, -10)) # Example force in the z-direction
# Define the elasticity problem (displacement, stress, strain), we need to calculate these from the material properites of the plastic
mu = Constant(10.0) # Lame's first parameter
lambda_ = Constant(100.0) # Lame's second parameter
def epsilon(u):
return sym(grad(u))
def sigma(u):
return lambda_ * div(u) * Identity(3) + 2 * mu * epsilon(u)
# Define variational problem
u = TrialFunction(V)
d = u.geometric_dimension() # number of space dimensions
v = TestFunction(V)
a = inner(sigma(u), epsilon(v)) * dx
L = dot(force, v) * ds
# Solve the problem
u = Function(V)
solve(a == L, u, bc)
# Post-processing: Compute stress and strain
# Strain
eps = epsilon(u)
# Stress
sig = sigma(u)
# Save the results
File("displacement.pvd") << u
File("strain.pvd") << project(eps, TensorFunctionSpace(mesh, "Lagrange", 1))
File("stress.pvd") << project(sig, TensorFunctionSpace(mesh, "Lagrange", 1))
print("FEM calculation complete. Results saved.")