How can you calculate both forces at the same time in cantilever beam?

from fenics import *
from mshr import *

L = 2
H = 0.067
b = 1

EI = 5e6
Ny = 3
Nx = Ny * 30

beam = RectangleMesh(Point(0, 0), Point(L, H), Nx, Ny)
beam.init()

def eps(v):
return sym(grad(v))

E = Constant(200e9)
nu = Constant(0.3)
model = “plane_stress”

mu = E/(2*(1+nu))
lmbda = Enu/(1+nu)/(1-2nu)
if model == “plane_stress”:
lmbda = 2mulmbda/(lmbda+2*mu)

def sigma(v):
return lmbdatr(eps(v))Identity(2) + 2.0mueps(v)

f = 0
w = 4e3
P = 6e3
f_thernal = Constant((0, -f))
T_plane = Constant((0, -w))
T_point = Constant((0, -P))
V = VectorFunctionSpace(beam, “CG”, 2)
tol = 1E-14

class Top(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], H) and on_boundary
class Left(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0) and on_boundary
class Point(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], L) and near(x[1], H) and on_boundary

boundaries = MeshFunction(“size_t”, beam, 1)

left = Left()
pt = Point()
top = Top()

boundaries.set_all(0)
top.mark(boundaries, 1)
left.mark(boundaries, 2)
pt.mark(boundaries, 3)
ds = Measure(“ds”, domain=beam, subdomain_data=boundaries)

du = TrialFunction(V)
u_ = TestFunction(V)
a = inner(sigma(du), eps(u_))*dx

left_end_displacement = Constant((0.0, 0.0))
bc = [DirichletBC(V, left_end_displacement, boundaries, 2), DirichletBC(V, T_point, pt, method=“pointwise”)]

l = inner(f_thernal, u_)*dx + dot(T_plane, u_)*ds(1) + dot(T_point, u_)*ds(3)

u = Function(V, name=“Displacement”)
solve(a == l, u, bc)

plot(1e3*u, mode=“displacement”)

print(“Maximal deflection:”, -u(L, H/2)[1])
print(“Beam theory deflection:”, float(((PL**3)/(3EI))+((wL**4)/(8EI))))

I want to calculate the deflection amount of cantilever beam given the uniform distribution load and the point load at the same time. But if I execute this code, only the calculation of the uniform distribution load is applied. How can I even calculate the point load?

Please use 3x` encapsulation (markdown syntax) to encapsulate your code. Also make sure that the code is properly indented, as the following example:

```python
def test(x):
    return x
```

Continuing the discussion from How can you calculate both forces at the same time in cantilever beam?:

If I copy and paste code on this site, indentation will not be applied. I’ve already done that. Although there was no error in the code, only the deflection value due to the uniform distribution load was calculated and deflection due to the point load was not included. I want to find the deflection value for the point load at the end of the cantilever beam and the uniform distribution load applied to the top surface.

from fenics import *
from mshr import *

L = 2
H = 0.067
b = 1

EI = 5e6
Ny = 3
Nx = Ny * 30

beam = RectangleMesh(Point(0, 0), Point(L, H), Nx, Ny)
beam.init()

def eps(v):
return sym(grad(v))

E = Constant(200e9)
nu = Constant(0.3)
model = “plane_stress”

mu = E/(2*(1+nu))
lmbda = Enu/(1+nu)/(1-2nu)
if model == “plane_stress”:
lmbda = 2mulmbda/(lmbda+2*mu)

def sigma(v):
return lmbdatr(eps(v))Identity(2) + 2.0mueps(v)

f = 0
w = 4e3
P = 6e3
f_thernal = Constant((0, -f))
T_plane = Constant((0, -w))
T_point = Constant((0, -P))
V = VectorFunctionSpace(beam, “CG”, 2)
tol = 1E-14

class Top(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], H) and on_boundary
class Left(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0) and on_boundary
class Point(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], L) and near(x[1], H) and on_boundary

boundaries = MeshFunction(“size_t”, beam, 1)

left = Left()
pt = Point()
top = Top()

boundaries.set_all(0)
top.mark(boundaries, 1)
left.mark(boundaries, 2)
pt.mark(boundaries, 3)
ds = Measure(“ds”, domain=beam, subdomain_data=boundaries)

du = TrialFunction(V)
u_ = TestFunction(V)
a = inner(sigma(du), eps(u_))*dx

left_end_displacement = Constant((0.0, 0.0))
bc = [DirichletBC(V, left_end_displacement, boundaries, 2), DirichletBC(V, T_point, pt, method=“pointwise”)]

l = inner(f_thernal, u_)*dx + dot(T_plane, u_)*ds(1) + dot(T_point, u_)*ds(3)

u = Function(V, name=“Displacement”)
solve(a == l, u, bc)

plot(1e3*u, mode=“displacement”)

print(“Maximal deflection:”, -u(L, H/2)[1])
print(“Beam theory deflection:”, float(((PL**3)/(3EI))+((wL**4)/(8EI))))

    1. List item

If I copy and paste code on this site, indentation will not be applied. This code does not have a Syntex error but does not apply point load. For example, if this code has a deflection value of 0.0016 due to uniform distribution load and a deflection value of 0.0032 due to point load, the overall deflection value should be 0.0048, but the result value of the code is approximate to 0.0016.

[2d cantilever beam's deflection - Replit]

I will share the code by replit. However, it does not run because the replit does not have the fenics applied.

I would expect that you should remove “on_boundary” from you point class as for instance shown in: Pointsource on specific points python - #2 by kamensky

This works well, but the figures are not correct. I wonder if it’s the right way to simply add l.

like

l = inner(f_thernal, u_)*dx + dot(T_plane, u_)*ds(1) + dot(T_point, u_)*ds(3)