Unable to define nonlinear problem

Hey there,

I just started with FENICS. I copied this program from a tutorial, but it doesn’t work for me:

PROGRAM

from fenics import *
from dolfin import *

dimensiones y numero de puntos en x y en y

L=25.
H=1.
Nx=250
Ny=10

mallado

mesh = RectangleMesh(Point(0., 0.), Point(L,H), Nx, Ny, “crossed”)

desplazamientos en 2d (viga plana) la derivada de los desplazamientos son las deformaciones (eps)

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

parámetros ed la viga

E = Constant(1e5)
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)

consideraremos polinomio de grado 2 para interpolar y una carga distribuida uniformemente de valores (0,-f)

carga = 1e-3
f = Constant((0, -carga))

cálculo de la solución

V = VectorFunctionSpace (mesh, ‘Lagrange’, degree=2)
du = TrialFunction(V)
u_ = TestFunction(V)
a = inner(sigma(du),eps(u_))*dx
l = inner(f,u_)*dx

#cálculo

def left(x, on_boundary):
return near(x[0], 0.)

bc = DirichletBC(V, Constant((0.,0.)), left)

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

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

The error I get is


*** Error: Unable to define nonlinear variational problem F(u; v) = 0 for all v.
*** Reason: Expecting the residual F to be a linear form (not rank 2).
*** Where: This error was encountered inside NonlinearVariationalProblem.cpp.
*** Process: 0

I’ve read the problem is because I’m using a bad trial function, but how to fix it?

Thanks

as far as i can tell, this should be a==l, not a==1.

For any further questions please encapsulate your code with 3x`, such as

```python
solve(a==l, u, bc)
```

Sorry for not using 3x’, I didn’t know it before!

It seems like the problem is solved. Why can it be that I can’t plot the solution?

Object cannot be plotted directly, projecting to piecewise linear

Thanks again.

As the error message states, matplotlib only supports first order functions. To plot higher order functions, like P2, use XDMFFile.write_checkpoint and use paraview to open the resulting file