File size: 1,595 Bytes
4774ecf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fenics import *

def run_fenics_simulation(length, width, thickness, force):
    """
    Executes a FEniCS-based finite element simulation.
    Parameters:
        length (float): Length of the plate/beam.
        width (float): Width of the plate/beam.
        thickness (float): Thickness of the plate/beam.
        force (float): Applied force.
    Returns:
        tuple: (stress, deformation) from the simulation.
    """
    # Geometry and mesh
    mesh = RectangleMesh(Point(0, 0), Point(length, width), 10, 10)
    
    # Define function space
    V = VectorFunctionSpace(mesh, "P", 1)

    # Define boundary conditions
    def clamped_boundary(x, on_boundary):
        return on_boundary and near(x[0], 0)

    bc = DirichletBC(V, Constant((0, 0)), clamped_boundary)

    # Define material properties
    E = 2e11  # Elastic modulus (Pa)
    nu = 0.3  # Poisson's ratio
    mu = E / (2 * (1 + nu))
    lmbda = E * nu / ((1 + nu) * (1 - 2 * nu))

    # Define strain and stress
    def epsilon(u):
        return sym(grad(u))

    def sigma(u):
        return lmbda * div(u) * Identity(2) + 2 * mu * epsilon(u)

    # Define variational problem
    u = TrialFunction(V)
    d = TestFunction(V)
    f = Constant((force / (length * width), 0))
    T = inner(sigma(u), epsilon(d)) * dx - dot(f, d) * dx
    a, L = lhs(T), rhs(T)

    # Solve problem
    u_sol = Function(V)
    solve(a == L, u_sol, bc)

    # Post-process results
    stress = max(project(sigma(u_sol)[0, 0], FunctionSpace(mesh, "P", 1)).vector())
    deformation = max(u_sol.vector())

    return stress, deformation