Cantilever beams with different element types¶
This example showcases the use of different planar element types for a simple cantilever beam.
In [1]:
import torch
from torchfem import Planar
from torchfem.elements import linear_to_quadratic
from torchfem.materials import IsotropicElasticityPlaneStress
from torchfem.mesh import rect_quad, rect_tri
# Set double precision
torch.set_default_dtype(torch.float64)
# Material model (plane stress)
material = IsotropicElasticityPlaneStress(E=1000.0, nu=0.3)
A simple cantilever beam with first order quads¶
In [2]:
# Create mesh
nodes, elements = rect_quad(13, 7, 2.0, 1.0)
# Create model
cantilever = Planar(nodes, elements, material, thickness=0.1)
# Load at tip
tip = (nodes[:, 0] == 2.0) & (nodes[:, 1] == 0.5)
cantilever.forces[tip, 1] = -1.0
# Constrained displacement at left end
left = nodes[:, 0] == 0.0
cantilever.constraints[left, :] = True
# Solve
u, f, σ, F, α = cantilever.solve()
# Plot
cantilever.plot(u, node_property=torch.norm(u, dim=1), node_markers=True)
A simple cantilever beam with second order quads¶
In [3]:
# Upgrade elements to quadratic
nodes, elements = linear_to_quadratic(nodes, elements)
# Create model
cantilever = Planar(nodes, elements, material, thickness=0.1)
# Load at tip
tip = (nodes[:, 0] == 2.0) & (nodes[:, 1] == 0.5)
cantilever.forces[tip, 1] = -1.0
# Constrained displacement at left end
left = nodes[:, 0] == 0.0
cantilever.constraints[left, :] = True
# Solve
u, f, σ, F, α = cantilever.solve()
# Plot
cantilever.plot(u, node_property=torch.norm(u, dim=1), node_markers=True)
A simple cantilever beam with first order triangles¶
In [4]:
# Create mesh
nodes, elements = rect_tri(13, 7, 2.0, 1.0, variant="zigzag")
# Create model
cantilever = Planar(nodes, elements, material, thickness=0.1)
# Load at tip
tip = (nodes[:, 0] == 2.0) & (nodes[:, 1] == 0.5)
cantilever.forces[tip, 1] = -1.0
# Constrained displacement at left end
left = nodes[:, 0] == 0.0
cantilever.constraints[left, :] = True
# Solve
u, f, σ, F, α = cantilever.solve()
# Plot
cantilever.plot(u, node_property=torch.norm(u, dim=1), node_markers=True)
A simple cantilever beam with second order triangles¶
In [5]:
# Upgrade elements to quadratic
nodes, elements = linear_to_quadratic(nodes, elements)
# Create model
cantilever = Planar(nodes, elements, material, thickness=0.1)
# Load at tip
tip = (nodes[:, 0] == 2.0) & (nodes[:, 1] == 0.5)
cantilever.forces[tip, 1] = -1.0
# Constrained displacement at left end
left = nodes[:, 0] == 0.0
cantilever.constraints[left, :] = True
# Solve
u, f, σ, F, α = cantilever.solve()
# Plot
cantilever.plot(u, node_property=torch.norm(u, dim=1), node_markers=True)