Hi everyone,
I’m trying to model a 1D wire in 2D space with fenicsx using Euler Bernoulli. Thus I need to have Hermite elements for my wire. I managed to create these elements using basix. Now I am having trouble creating a mesh for the wire with this type of element.
Here’s my code:
from dolfinx import mesh, fem, default_scalar_type
from dolfinx.fem.petsc import LinearProblem
from mpi4py import MPI
import ufl
import basix
import numpy as np
from tools import EI_calc_static, menger_curvature
########## Initial parameters ##########
l_span = 4.
diameter = 31.05e-3
radius = diameter/2
A = np.pi*(radius**2)
V = A*l_span
E = 62e8
EI_max = 2155
EI_min = 28.3
g = 10
rho = 270
chi_0 = 1.
########## Geometry initialization ##########
dim = 2
nb_cells = 200
beam_element = basix.ufl.element(basix.ElementFamily.Hermite, basix.CellType.interval, 3)
# Option 1?
domain_init = ufl.Mesh(beam_element)
# Option 2?
# gdim, shape, degree = dim, "interval", 3
# cell = ufl.Cell(shape, geometric_dimension=gdim)
# domain_init = ufl.Mesh(ufl.VectorElement("CG", cell, degree))
xn = np.linspace(0, l_span, nb_cells+1)
yn = 0.5*((xn-l_span/2)**2-l_span)
x = np.vstack((xn, yn)).T
cs = np.zeros((nb_cells, 2), dtype=np.int64)
for i in range(nb_cells):
cs[i, 0] = i
cs[i, 1] = i + 1
cells = np.array(cs, dtype=np.int64)
########## Mesh and domain ##########
domain = mesh.create_mesh(MPI.COMM_WORLD, cells, x, domain_init)
V = fem.FunctionSpace(domain, beam_element)
fdim = domain.topology.dim - 1
########## Pre-processing bretelle shape ##########
# Curvature
chi_new = menger_curvature(x.T[0], x.T[1])
# Bending stiffness depending on curvature
EI_new = EI_calc_static(domain, EI_max, EI_min, chi_0, chi_new)
##########
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
########## Boundary conditions ##########
ubc = fem.Function(V)
with ubc.vector.localForm() as uloc:
uloc.set(0.)
# locate endpoints
startpt = mesh.locate_entities_boundary(domain, 0, lambda x: np.isclose(x[0], 0))
endpt = mesh.locate_entities_boundary(domain, 0, lambda x: np.isclose(x[0], L))
# locate DOFs from endpoints
startdof = fem.locate_dofs_topological(V, 0, startpt)
enddof = fem.locate_dofs_topological(V, 0, endpt)
# fix displacement of start point and rotation as well
fixed_disp1 = fem.dirichletbc(ubc, [startdof[0]])
fixed_rot1 = fem.dirichletbc(ubc, [startdof[1]])
fixed_disp2 = fem.dirichletbc(ubc, [enddof[0]])
fixed_rot2 = fem.dirichletbc(ubc, [enddof[1]])
bcs = [fixed_disp1, fixed_rot1, fixed_disp2, fixed_rot2]
########## Forces and tensions ##########
# distributed load value (due to weight)
q = fem.Constant(domain, -rho * A * g)
########## Solver ##########
def M(u):
return EI_new * ufl.div(ufl.grad(u))
a = ufl.inner(ufl.div(ufl.grad(u)), M(v)) * ufl.dx
L = q * v * ufl.dx
# Solver
problem = LinearProblem(a, L, bcs=bcs)
uh = problem.solve()
Any help would be greatly appreciated, thank you very much!