Hello, I’m trying to do a project for my class. Basically I’m trying to test this program to calculate the max displacement in a beam however the value it exports is different to the one that appears in Paraview and different to the one I calculated.
Max displacements:
Code: 0.0049421492043371365m
Manual: 5.08e-4
Paraview: 2.9e-3
Here’s the code:
from fenics import *
import numpy as np
L = 10 #Longitud de viga en metros
H = 0.5
W = 0.3
malla = BoxMesh(Point(0, 0, 0), Point(L, H, W), 100, 10, 10)
V = VectorFunctionSpace(malla, ‘P’, 1)
def frontera(x, on_boundary):
return on_boundary and near(x[0], 0)
cf = DirichletBC(V, Constant((0, 0, 0)), frontera)
E = 210e9 # Módulo de Young
nu = 0.3 # Relación de Poisson
mu = E / (2 * (1 + nu))
lambda_ = E * nu / ((1 + nu) * (1 - 2 * nu))
u = TrialFunction(V)
d = u.geometric_dimension()
I = Identity(d)
epsilon = lambda u: 0.5 * (grad(u) + grad(u).T)
sigma = lambda u: lambda_ * tr(epsilon(u)) * I + 2 * mu * epsilon(u)
v = TestFunction(V)
T = Constant((0, 1000, 0)) # Carga puntual
a = inner(sigma(u), epsilon(v)) * dx
L = dot(T, v) * ds
u = Function(V)
solve(a == L, u, cf)
vtkfile = File(‘desplazamiento.pvd’)
vtkfile << u
displacement_values = u.compute_vertex_values(malla)
d = u.geometric_dimension()
displacement_magnitude = np.sqrt(sum(displacement_values[i::d]**2 for i in range(d)))
max_displacement = np.max(displacement_magnitude)
print(“Desplazamiento máximo:”, max_displacement)