from fenics import *
# Step 1: Define the Problem (Geometry and Material Parameters)
L = 1.0 # Length of the domain in the y direction
K = Constant(1.0) # Splay elastic constant
L = Constant(1.0) # Twist elastic constant
# Step 2: Define Function Space
mesh = RectangleMesh(Point(0, 0), Point(1, L), 50, 50) # Define the rectangular mesh
V = VectorFunctionSpace(mesh, "CG", 1) # Vector function space for the director field
# Step 3: Define Trial and Test Functions
n = Function(V) # The director field
v = TestFunction(V)
# Step 4: Define the Free Energy Functional
F = 0.5 * K * inner(grad(n), grad(n)) * dx
# Step 5: Compute the Derivative of the Free Energy Functional (Variational Problem)
dFdn = derivative(F, n, v)
# Step 6: Apply Boundary Conditions
# Boundary condition at y=0 (linear with respect to x)
bx0 = Expression("x[0]", degree=1)
bc_x0 = DirichletBC(V.sub(0), bx0, "near(x[1], 0)")
# Combine the boundary conditions
bc = bc_x0
# Step 7: Compute the Equilibrium Director Field
n_eq = Function(V) # The equilibrium director field
solve(dFdn == 0, n_eq, bc)
The runtime error is encountered:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
*** fenics-support@googlegroups.com
*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.
*** -------------------------------------------------------------------------
*** Error: Unable to successfully call PETSc function ‘MatSetValuesLocal’.
*** Reason: PETSc error code is: 63 (Argument out of range).
*** Where: This error was encountered inside /Users/runner/miniforge3/conda-bld/fenics-pkgs_1687565360119/work/dolfin/dolfin/la/PETScMatrix.cpp.
*** Process: 0
*** DOLFIN version: 2019.1.0
*** Git changeset:
*** -------------------------------------------------------------------------
I am a beginner in Fenics. Can somebody help?